improve registries, block break particles, world events

This commit is contained in:
Bixilon 2022-04-16 00:32:13 +02:00
parent 45c353133a
commit d6713951e9
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
22 changed files with 223 additions and 79 deletions

View File

@ -21,10 +21,10 @@ import de.bixilon.minosoft.data.entities.EntityObjectType
import de.bixilon.minosoft.data.entities.block.BlockEntityMetaType
import de.bixilon.minosoft.data.entities.meta.EntityData
import de.bixilon.minosoft.data.registries.other.containers.ContainerType
import de.bixilon.minosoft.data.registries.other.game.event.GameEvent
import de.bixilon.minosoft.data.registries.registries.registry.PerVersionEnumRegistry
import de.bixilon.minosoft.data.registries.registries.registry.PerVersionRegistry
import de.bixilon.minosoft.data.registries.registries.registry.Registry
import de.bixilon.minosoft.data.registries.registries.registry.ResourceLocationRegistry
import de.bixilon.minosoft.protocol.packets.c2s.play.entity.EntityActionC2SP
import de.bixilon.minosoft.protocol.packets.s2c.play.entity.EntityAnimationS2CP
import de.bixilon.minosoft.protocol.packets.s2c.play.title.TitleS2CF
@ -49,12 +49,14 @@ object DefaultRegistries {
val ENTITY_OBJECT_REGISTRY: Registry<EntityObjectType> = Registry()
val BLOCK_ENTITY_META_TYPE_REGISTRY: PerVersionRegistry<BlockEntityMetaType> = PerVersionRegistry()
val BLOCK_ENTITY_META_TYPE_REGISTRY: PerVersionRegistry<BlockEntityMetaType, Registry<BlockEntityMetaType>> = PerVersionRegistry { Registry() }
val DEFAULT_PLUGIN_CHANNELS_REGISTRY: PerVersionRegistry<PluginChannel> = PerVersionRegistry()
val DEFAULT_PLUGIN_CHANNELS_REGISTRY: PerVersionRegistry<PluginChannel, Registry<PluginChannel>> = PerVersionRegistry { Registry() }
val CONTAINER_TYPE_REGISTRY: PerVersionRegistry<ContainerType> = PerVersionRegistry()
val GAME_EVENT_REGISTRY: PerVersionRegistry<GameEvent> = PerVersionRegistry()
val CONTAINER_TYPE_REGISTRY: PerVersionRegistry<ContainerType, Registry<ContainerType>> = PerVersionRegistry { Registry() }
val GAME_EVENT_REGISTRY: PerVersionRegistry<ResourceLocation, ResourceLocationRegistry> = PerVersionRegistry { ResourceLocationRegistry() }
val WORLD_EVENT_REGISTRY: PerVersionRegistry<ResourceLocation, ResourceLocationRegistry> = PerVersionRegistry { ResourceLocationRegistry() }
fun load() {
@ -84,7 +86,9 @@ object DefaultRegistries {
BLOCK_ENTITY_META_TYPE_REGISTRY.initialize(registriesJson[ResourceLocation("block_entity_meta_data_types")].asJsonObject(), BlockEntityMetaType)
CONTAINER_TYPE_REGISTRY.initialize(registriesJson[ResourceLocation("container_types")].asJsonObject(), ContainerType)
GAME_EVENT_REGISTRY.initialize(registriesJson[ResourceLocation("game_events")].asJsonObject(), GameEvent)
GAME_EVENT_REGISTRY.initialize(registriesJson[ResourceLocation("game_events")].asJsonObject(), null)
WORLD_EVENT_REGISTRY.initialize(registriesJson[ResourceLocation("world_events")].asJsonObject(), null)
initialized = true
}

View File

@ -16,6 +16,7 @@ package de.bixilon.minosoft.data.registries.blocks.entites
import de.bixilon.minosoft.data.registries.ResourceLocation
import de.bixilon.minosoft.data.registries.blocks.types.Block
import de.bixilon.minosoft.data.registries.registries.Registries
import de.bixilon.minosoft.data.registries.registries.registry.AbstractRegistry
import de.bixilon.minosoft.data.registries.registries.registry.Registry
import de.bixilon.minosoft.data.registries.registries.registry.ResourceLocationDeserializer
@ -29,7 +30,7 @@ class BlockEntityTypeRegistry(
return blockTypeMap[block] ?: parentRegistry?.get(block)
}
override fun initialize(data: Map<ResourceLocation, Any>?, registries: Registries?, deserializer: ResourceLocationDeserializer<BlockEntityType<*>>, flattened: Boolean, metaType: MetaTypes, alternative: Registry<BlockEntityType<*>>?): Registry<BlockEntityType<*>> {
override fun initialize(data: Map<ResourceLocation, Any>?, registries: Registries?, deserializer: ResourceLocationDeserializer<BlockEntityType<*>>?, flattened: Boolean, metaType: MetaTypes, alternative: AbstractRegistry<BlockEntityType<*>>?): Registry<BlockEntityType<*>> {
super.initialize(data, registries, deserializer, flattened, metaType, alternative)
for ((_, type) in resourceLocationMap) {

View File

@ -1,6 +1,6 @@
/*
* Minosoft
* Copyright (C) 2021 Moritz Zwerger
* Copyright (C) 2020-2022 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
@ -15,6 +15,7 @@ package de.bixilon.minosoft.data.registries.items
import de.bixilon.minosoft.data.registries.ResourceLocation
import de.bixilon.minosoft.data.registries.registries.Registries
import de.bixilon.minosoft.data.registries.registries.registry.AbstractRegistry
import de.bixilon.minosoft.data.registries.registries.registry.Registry
import de.bixilon.minosoft.data.registries.registries.registry.ResourceLocationDeserializer
@ -42,7 +43,7 @@ class ItemRegistry(
}
}
override fun initialize(data: Map<ResourceLocation, Any>?, registries: Registries?, deserializer: ResourceLocationDeserializer<Item>, flattened: Boolean, metaType: MetaTypes, alternative: Registry<Item>?): Registry<Item> {
override fun initialize(data: Map<ResourceLocation, Any>?, registries: Registries?, deserializer: ResourceLocationDeserializer<Item>?, flattened: Boolean, metaType: MetaTypes, alternative: AbstractRegistry<Item>?): Registry<Item> {
this.flattened = flattened
return super.initialize(data, registries, deserializer, flattened, metaType, alternative)
}

View File

@ -1,35 +0,0 @@
/*
* Minosoft
* Copyright (C) 2021 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/
package de.bixilon.minosoft.data.registries.other.game.event
import de.bixilon.minosoft.data.registries.ResourceLocation
import de.bixilon.minosoft.data.registries.registries.Registries
import de.bixilon.minosoft.data.registries.registries.registry.RegistryItem
import de.bixilon.minosoft.data.registries.registries.registry.ResourceLocationDeserializer
data class GameEvent(
override val resourceLocation: ResourceLocation,
) : RegistryItem() {
override fun toString(): String {
return resourceLocation.toString()
}
companion object : ResourceLocationDeserializer<GameEvent> {
override fun deserialize(registries: Registries?, resourceLocation: ResourceLocation, data: Map<String, Any>): GameEvent {
return GameEvent(
resourceLocation = resourceLocation,
)
}
}
}

View File

@ -0,0 +1,21 @@
/*
* Minosoft
* Copyright (C) 2020-2022 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/
package de.bixilon.minosoft.data.registries.other.world.event
import de.bixilon.minosoft.data.registries.factory.DefaultFactory
import de.bixilon.minosoft.data.registries.other.world.event.handlers.BlockDestroyedHandler
object DefaultWorldEventHandlers : DefaultFactory<WorldEventHandler>(
BlockDestroyedHandler,
)

View File

@ -0,0 +1,23 @@
/*
* Minosoft
* Copyright (C) 2020-2022 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/
package de.bixilon.minosoft.data.registries.other.world.event
import de.bixilon.minosoft.data.registries.CompanionResourceLocation
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
import glm_.vec3.Vec3i
interface WorldEventHandler : CompanionResourceLocation {
fun handle(connection: PlayConnection, position: Vec3i, data: Int, isGlobal: Boolean)
}

View File

@ -0,0 +1,66 @@
/*
* Minosoft
* Copyright (C) 2020-2022 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/
package de.bixilon.minosoft.data.registries.other.world.event.handlers
import de.bixilon.minosoft.data.registries.ResourceLocation
import de.bixilon.minosoft.data.registries.blocks.BlockState
import de.bixilon.minosoft.data.registries.other.world.event.WorldEventHandler
import de.bixilon.minosoft.data.registries.particle.data.BlockParticleData
import de.bixilon.minosoft.gui.rendering.particle.types.render.texture.advanced.block.BlockDustParticle
import de.bixilon.minosoft.gui.rendering.util.vec.vec3.Vec3dUtil.ceil
import de.bixilon.minosoft.gui.rendering.util.vec.vec3.Vec3dUtil.min
import de.bixilon.minosoft.gui.rendering.util.vec.vec3.Vec3iUtil.max
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
import de.bixilon.minosoft.util.KUtil.toResourceLocation
import glm_.vec3.Vec3d
import glm_.vec3.Vec3i
object BlockDestroyedHandler : WorldEventHandler {
override val RESOURCE_LOCATION: ResourceLocation = "minecraft:block_destroyed".toResourceLocation()
override fun handle(connection: PlayConnection, position: Vec3i, data: Int, isGlobal: Boolean) {
val state = connection.registries.blockStateRegistry[data] ?: return
handleDestroy(connection, position, state)
}
fun handleDestroy(connection: PlayConnection, position: Vec3i, state: BlockState) {
state.breakSoundEvent?.let {
connection.world.playSoundEvent(it, position, volume = state.soundEventVolume, pitch = state.soundEventPitch)
}
addBlockBreakParticles(connection, position, state)
}
private fun addBlockBreakParticles(connection: PlayConnection, position: Vec3i, state: BlockState) {
val particleRenderer = connection.world.particleRenderer ?: return
val type = connection.registries.particleTypeRegistry[BlockDustParticle] ?: return
val shape = state.outlineShape
val particleData = BlockParticleData(state, type)
for (aabb in shape) {
val delta = (aabb.max - aabb.min).min(1.0)
val max = (delta * 4.0).ceil().max(2)
for (x in 0 until max.x) {
for (y in 0 until max.y) {
for (z in 0 until max.z) {
val center = (Vec3d(x, y, z) + 0.5) / max
val particlePosition = center * delta + aabb.min
particleRenderer.add(BlockDustParticle(connection, particlePosition + position, particlePosition - 0.5, particleData))
}
}
}
}
}
}

View File

@ -37,7 +37,6 @@ import de.bixilon.minosoft.data.registries.items.Item
import de.bixilon.minosoft.data.registries.items.ItemRegistry
import de.bixilon.minosoft.data.registries.materials.Material
import de.bixilon.minosoft.data.registries.other.containers.ContainerType
import de.bixilon.minosoft.data.registries.other.game.event.GameEvent
import de.bixilon.minosoft.data.registries.particle.ParticleType
import de.bixilon.minosoft.data.registries.registries.registry.*
import de.bixilon.minosoft.data.registries.statistics.Statistic
@ -94,7 +93,8 @@ class Registries {
val blockEntityMetaDataTypeRegistry: Registry<BlockEntityMetaType> = Registry()
val containerTypeRegistry: Registry<ContainerType> = Registry()
val gameEventRegistry: Registry<GameEvent> = Registry()
val gameEventRegistry: ResourceLocationRegistry = ResourceLocationRegistry()
val worldEventRegistry: ResourceLocationRegistry = ResourceLocationRegistry()
var isFullyLoaded = false
private set
@ -148,7 +148,8 @@ class Registries {
// id resource location stuff
containerTypeRegistry.rawInitialize(pixlyzerData["container_types"]?.toJsonObject(), this, ContainerType, alternative = DefaultRegistries.CONTAINER_TYPE_REGISTRY.forVersion(version))
gameEventRegistry.rawInitialize(pixlyzerData["game_events"]?.toJsonObject(), this, GameEvent, alternative = DefaultRegistries.GAME_EVENT_REGISTRY.forVersion(version))
gameEventRegistry.rawInitialize(pixlyzerData["game_events"]?.toJsonObject(), this, null, alternative = DefaultRegistries.GAME_EVENT_REGISTRY.forVersion(version))
worldEventRegistry.rawInitialize(pixlyzerData["world_events"]?.toJsonObject(), this, null, alternative = DefaultRegistries.WORLD_EVENT_REGISTRY.forVersion(version))
entityTypeRegistry.rawInitialize(pixlyzerData["entities"]?.toJsonObject(), this, EntityType)

View File

@ -1,6 +1,6 @@
/*
* Minosoft
* Copyright (C) 2021 Moritz Zwerger
* Copyright (C) 2020-2022 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
@ -13,7 +13,10 @@
package de.bixilon.minosoft.data.registries.registries.registry
import de.bixilon.minosoft.data.registries.ResourceLocation
import de.bixilon.minosoft.data.registries.registries.Registries
import de.bixilon.minosoft.util.collections.Clearable
import de.bixilon.minosoft.util.json.ResourceLocationJsonMap.toResourceLocationMap
interface AbstractRegistry<T> : Iterable<T>, Clearable, Parentable<AbstractRegistry<T>> {
val size: Int
@ -24,6 +27,12 @@ interface AbstractRegistry<T> : Iterable<T>, Clearable, Parentable<AbstractRegis
fun getId(value: T): Int
fun rawInitialize(data: Map<String, Any>?, registries: Registries?, deserializer: ResourceLocationDeserializer<T>?, flattened: Boolean = true, metaType: Registry.MetaTypes = Registry.MetaTypes.NONE, alternative: AbstractRegistry<T>? = null): AbstractRegistry<T> {
return initialize(data?.toResourceLocationMap(), registries, deserializer, flattened, metaType, alternative)
}
fun initialize(data: Map<ResourceLocation, Any>?, registries: Registries?, deserializer: ResourceLocationDeserializer<T>?, flattened: Boolean = true, metaType: Registry.MetaTypes = Registry.MetaTypes.NONE, alternative: AbstractRegistry<T>? = null): AbstractRegistry<T>
fun noParentIterator(): Iterator<T>
override fun iterator(): Iterator<T> {

View File

@ -1,6 +1,6 @@
/*
* Minosoft
* Copyright (C) 2021 Moritz Zwerger
* Copyright (C) 2020-2022 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
@ -13,7 +13,9 @@
package de.bixilon.minosoft.data.registries.registries.registry
import de.bixilon.minosoft.data.registries.ResourceLocation
import de.bixilon.minosoft.data.registries.blocks.BlockState
import de.bixilon.minosoft.data.registries.registries.Registries
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap
@ -66,6 +68,10 @@ class BlockStateRegistry(var flattened: Boolean) : AbstractRegistry<BlockState?>
return forceGet(id)
}
override fun initialize(data: Map<ResourceLocation, Any>?, registries: Registries?, deserializer: ResourceLocationDeserializer<BlockState?>?, flattened: Boolean, metaType: Registry.MetaTypes, alternative: AbstractRegistry<BlockState?>?): AbstractRegistry<BlockState?> {
TODO("Not yet implemented")
}
override fun getId(value: BlockState?): Int {
TODO("Not yet implemented")
}

View File

@ -1,6 +1,6 @@
/*
* Minosoft
* Copyright (C) 2021 Moritz Zwerger
* Copyright (C) 2020-2022 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
@ -24,7 +24,7 @@ class PerVersionEnumRegistry<T : Enum<*>>(
fun forVersion(version: Version): EnumRegistry<T>? {
// must loop from highest version to lowest!
// must loop from the highest version to lowest!
for ((versionId, registry) in versions) {
if (version.versionId < versionId) {
continue
@ -40,7 +40,7 @@ class PerVersionEnumRegistry<T : Enum<*>>(
val versions: SortedMap<Int, EnumRegistry<T>> = sortedMapOf({ t, t2 -> t2 - t })
for ((versionId, json) in data) {
versions[Integer.parseInt(versionId)] = EnumRegistry(values = values, mutable = false).initialize(json)
versions[versionId.toInt()] = EnumRegistry(values = values, mutable = false).initialize(json)
}
this.versions = versions.toMap()
}

View File

@ -1,6 +1,6 @@
/*
* Minosoft
* Copyright (C) 2021 Moritz Zwerger
* Copyright (C) 2020-2022 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
@ -17,11 +17,11 @@ import de.bixilon.kutil.json.JsonUtil.toJsonObject
import de.bixilon.minosoft.data.registries.versions.Version
import java.util.*
class PerVersionRegistry<T : RegistryItem> {
private lateinit var versions: Map<Int, Registry<T>>
class PerVersionRegistry<E, R : AbstractRegistry<E>>(private val registryCreator: () -> R) {
private lateinit var versions: Map<Int, R>
fun forVersion(version: Version): Registry<T> {
// must loop from highest version to lowest!
fun forVersion(version: Version): R {
// must loop from the highest version to lowest!
for ((versionId, registry) in versions) {
if (version.versionId < versionId) {
continue
@ -31,12 +31,14 @@ class PerVersionRegistry<T : RegistryItem> {
throw IllegalArgumentException("Can not find a registry for version $version")
}
fun initialize(data: Map<String, Any>, deserializer: ResourceLocationDeserializer<T>) {
fun initialize(data: Map<String, Any>, deserializer: ResourceLocationDeserializer<E>?) {
check(!this::versions.isInitialized) { "Already initialized!" }
val versions: SortedMap<Int, Registry<T>> = sortedMapOf({ t, t2 -> t2 - t })
val versions: SortedMap<Int, R> = sortedMapOf({ t, t2 -> t2 - t })
for ((versionId, json) in data) {
versions[Integer.parseInt(versionId)] = Registry<T>().rawInitialize(json.toJsonObject(), null, deserializer)
val registry = registryCreator()
registry.rawInitialize(json.toJsonObject(), null, deserializer)
versions[Integer.parseInt(versionId)] = registry
}
this.versions = versions.toMap()
}

View File

@ -1,6 +1,6 @@
/*
* Minosoft
* Copyright (C) 2021 Moritz Zwerger
* Copyright (C) 2020-2022 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
@ -22,7 +22,6 @@ import de.bixilon.minosoft.data.registries.ResourceLocation
import de.bixilon.minosoft.data.registries.ResourceLocationAble
import de.bixilon.minosoft.data.registries.registries.Registries
import de.bixilon.minosoft.util.KUtil.toResourceLocation
import de.bixilon.minosoft.util.json.ResourceLocationJsonMap.toResourceLocationMap
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap
@ -110,8 +109,11 @@ open class Registry<T : RegistryItem>(
return valueIdMap[value] ?: parent?.getId(value)!!
}
open fun initialize(data: Map<ResourceLocation, Any>?, registries: Registries?, deserializer: ResourceLocationDeserializer<T>, flattened: Boolean = true, metaType: MetaTypes = MetaTypes.NONE, alternative: Registry<T>? = null): Registry<T> {
override fun initialize(data: Map<ResourceLocation, Any>?, registries: Registries?, deserializer: ResourceLocationDeserializer<T>?, flattened: Boolean, metaType: MetaTypes, alternative: AbstractRegistry<T>?): Registry<T> {
check(!initialized) { "Already initialized" }
if (deserializer == null) {
throw NullPointerException("Deserializer can not be null!")
}
if (data == null) {
if (alternative != null) {
@ -152,10 +154,6 @@ open class Registry<T : RegistryItem>(
return this
}
open fun rawInitialize(data: Map<String, Any>?, registries: Registries?, deserializer: ResourceLocationDeserializer<T>, flattened: Boolean = true, metaType: MetaTypes = MetaTypes.NONE, alternative: Registry<T>? = null): Registry<T> {
return initialize(data?.toResourceLocationMap(), registries, deserializer, flattened, metaType, alternative)
}
open fun postInit(registries: Registries) {
for ((_, value) in resourceLocationMap) {
value.inject(registries)

View File

@ -13,8 +13,10 @@
package de.bixilon.minosoft.data.registries.registries.registry
import de.bixilon.kutil.cast.CastUtil.unsafeCast
import de.bixilon.kutil.primitive.IntUtil.toInt
import de.bixilon.minosoft.data.registries.ResourceLocation
import de.bixilon.minosoft.data.registries.registries.Registries
import de.bixilon.minosoft.util.json.ResourceLocationJsonMap.toResourceLocationMap
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap
@ -54,6 +56,10 @@ class ResourceLocationRegistry(
return valueIdMap[value] ?: parent?.getId(value) ?: -1
}
override fun initialize(data: Map<ResourceLocation, Any>?, registries: Registries?, deserializer: ResourceLocationDeserializer<ResourceLocation>?, flattened: Boolean, metaType: Registry.MetaTypes, alternative: AbstractRegistry<ResourceLocation>?): AbstractRegistry<ResourceLocation> {
return initialize(data, alternative.unsafeCast())
}
fun initialize(data: Map<ResourceLocation, Any>?, alternative: ResourceLocationRegistry? = null): ResourceLocationRegistry {
check(!initialized) { "Already initialized" }

View File

@ -25,6 +25,7 @@ import de.bixilon.minosoft.data.registries.effects.DefaultStatusEffects
import de.bixilon.minosoft.data.registries.enchantment.DefaultEnchantments
import de.bixilon.minosoft.data.registries.fluid.DefaultFluids
import de.bixilon.minosoft.data.registries.items.tools.MiningToolItem
import de.bixilon.minosoft.data.registries.other.world.event.handlers.BlockDestroyedHandler
import de.bixilon.minosoft.gui.rendering.RenderWindow
import de.bixilon.minosoft.gui.rendering.camera.target.targets.BlockTarget
import de.bixilon.minosoft.modding.event.events.LegacyBlockBreakAckEvent
@ -134,9 +135,7 @@ class BreakInteractionHandler(
clearDigging()
connection.world[target.blockPosition] = null
target.blockState.breakSoundEvent?.let {
connection.world.playSoundEvent(it, target.blockPosition, volume = target.blockState.soundEventVolume, pitch = target.blockState.soundEventPitch)
}
BlockDestroyedHandler.handleDestroy(connection, target.blockPosition, target.blockState)
}
val canStartBreaking = currentTime - breakSent >= ProtocolDefinition.TICK_TIME

View File

@ -15,8 +15,10 @@ package de.bixilon.minosoft.gui.rendering.util.vec.vec3
import de.bixilon.kutil.math.interpolation.DoubleInterpolation.interpolateLinear
import de.bixilon.kutil.math.interpolation.DoubleInterpolation.interpolateSine
import de.bixilon.kutil.math.simple.DoubleMath.ceil
import glm_.vec3.Vec3
import glm_.vec3.Vec3d
import glm_.vec3.Vec3i
object Vec3dUtil {
@ -58,4 +60,16 @@ object Vec3dUtil {
}
return Vec3d(interpolateSine(delta, start.x, end.x), interpolateSine(delta, start.y, end.y), interpolateSine(delta, start.z, end.z))
}
fun Vec3d.min(value: Double): Vec3d {
return Vec3d(minOf(value, x), minOf(value, y), minOf(value, z))
}
fun Vec3d.max(value: Double): Vec3d {
return Vec3d(maxOf(value, x), maxOf(value, y), maxOf(value, z))
}
fun Vec3d.ceil(): Vec3i {
return Vec3i(x.ceil, y.ceil, z.ceil)
}
}

View File

@ -1,6 +1,6 @@
/*
* Minosoft
* Copyright (C) 2021 Moritz Zwerger
* Copyright (C) 2020-2022 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
@ -46,4 +46,8 @@ object Vec3iUtil {
else -> null
}
}
fun Vec3i.max(value: Int): Vec3i {
return Vec3i(maxOf(value, x), maxOf(value, y), maxOf(value, z))
}
}

View File

@ -1,6 +1,6 @@
/*
* Minosoft
* Copyright (C) 2020 Moritz Zwerger
* Copyright (C) 2020-2022 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
@ -12,7 +12,7 @@
*/
package de.bixilon.minosoft.modding.event.events
import de.bixilon.minosoft.data.registries.other.game.event.GameEvent
import de.bixilon.minosoft.data.registries.ResourceLocation
import de.bixilon.minosoft.modding.event.EventInitiators
import de.bixilon.minosoft.modding.event.events.connection.play.PlayConnectionEvent
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
@ -21,7 +21,7 @@ import de.bixilon.minosoft.protocol.packets.s2c.play.GameEventS2CP
class GameEventChangeEvent(
connection: PlayConnection,
initiator: EventInitiators,
val event: GameEvent,
val event: ResourceLocation?,
val data: Float,
) : PlayConnectionEvent(connection, initiator) {

View File

@ -13,7 +13,6 @@
package de.bixilon.minosoft.protocol.packets.s2c.play
import de.bixilon.minosoft.data.registries.other.game.event.DefaultGameEventHandlers
import de.bixilon.minosoft.data.registries.other.game.event.GameEvent
import de.bixilon.minosoft.modding.event.events.GameEventChangeEvent
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
import de.bixilon.minosoft.protocol.packets.factory.LoadPacket
@ -25,16 +24,19 @@ import de.bixilon.minosoft.util.logging.LogMessageType
@LoadPacket
class GameEventS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket {
val event: GameEvent = buffer.connection.registries.gameEventRegistry[buffer.readUnsignedByte()]
val event = buffer.connection.registries.gameEventRegistry[buffer.readUnsignedByte()]
val data: Float = buffer.readFloat()
override fun handle(connection: PlayConnection) {
if (event == null) {
return
}
val event = GameEventChangeEvent(connection, this)
if (connection.fireEvent(event)) {
return
}
DefaultGameEventHandlers[this.event.resourceLocation]?.handle(data, connection)
DefaultGameEventHandlers[this.event]?.handle(data, connection)
}
override fun log(reducedLog: Boolean) {

View File

@ -12,6 +12,8 @@
*/
package de.bixilon.minosoft.protocol.packets.s2c.play
import de.bixilon.minosoft.data.registries.other.world.event.DefaultWorldEventHandlers
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
import de.bixilon.minosoft.protocol.packets.factory.LoadPacket
import de.bixilon.minosoft.protocol.packets.s2c.PlayS2CPacket
import de.bixilon.minosoft.protocol.protocol.PlayInByteBuffer
@ -23,7 +25,8 @@ import glm_.vec3.Vec3i
@LoadPacket
class WorldEventS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket {
private val eventId: Int = buffer.readInt()
val eventId: Int = buffer.readInt()
val event = buffer.connection.registries.worldEventRegistry[eventId]
var position: Vec3i = if (buffer.versionId < ProtocolVersions.V_14W03B) {
buffer.readByteBlockPosition()
} else {
@ -32,7 +35,12 @@ class WorldEventS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket {
val data: Int = buffer.readInt()
val isGlobal: Boolean = buffer.readBoolean()
override fun handle(connection: PlayConnection) {
val handler = DefaultWorldEventHandlers[event ?: return] ?: return
handler.handle(connection, position, data, isGlobal)
}
override fun log(reducedLog: Boolean) {
Log.log(LogMessageType.NETWORK_PACKETS_IN, level = LogLevels.VERBOSE) { "World event packet (position=$position, eventId=$eventId, data=$data, isGlobal=$isGlobal)" }
Log.log(LogMessageType.NETWORK_PACKETS_IN, level = LogLevels.VERBOSE) { "World event packet (position=$position, event=${event ?: eventId}, data=$data, isGlobal=$isGlobal)" }
}
}

View File

@ -15,7 +15,10 @@ package de.bixilon.minosoft.recipes
import de.bixilon.minosoft.data.registries.ResourceLocation
import de.bixilon.minosoft.data.registries.ResourceLocationAble
import de.bixilon.minosoft.data.registries.registries.Registries
import de.bixilon.minosoft.data.registries.registries.registry.AbstractRegistry
import de.bixilon.minosoft.data.registries.registries.registry.Registry
import de.bixilon.minosoft.data.registries.registries.registry.ResourceLocationDeserializer
import de.bixilon.minosoft.util.KUtil.toResourceLocation
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap
@ -46,6 +49,10 @@ class RecipeRegistry(
return idValueMap[id] ?: parent?.get(id)
}
override fun initialize(data: Map<ResourceLocation, Any>?, registries: Registries?, deserializer: ResourceLocationDeserializer<Recipe>?, flattened: Boolean, metaType: Registry.MetaTypes, alternative: AbstractRegistry<Recipe>?): AbstractRegistry<Recipe> {
TODO("Not yet implemented")
}
override fun getId(value: Recipe): Int {
return valueIdMap[value] ?: parent?.getId(value) ?: throw IllegalArgumentException("No id available for $value")
}

View File

@ -587,5 +587,12 @@
"id": 11
}
}
},
"minecraft:world_events": {
"0": {
"minecraft:block_destroyed": {
"id": 2001
}
}
}
}