diff --git a/gradle.properties b/gradle.properties index e30bc3a..239db5e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -12,7 +12,7 @@ kotlin_version=2.0.21 fabric_kotlin_version=1.12.3 # Mod Properties -mod_version=1.3 +mod_version=1.4 maven_group=net.mcbrawls mod_id=brawls-entities diff --git a/src/main/kotlin/net/mcbrawls/entities/BrawlsAPIEntities.kt b/src/main/kotlin/net/mcbrawls/entities/BrawlsAPIEntities.kt index 7e34b3a..64a2d54 100644 --- a/src/main/kotlin/net/mcbrawls/entities/BrawlsAPIEntities.kt +++ b/src/main/kotlin/net/mcbrawls/entities/BrawlsAPIEntities.kt @@ -1,7 +1,7 @@ package net.mcbrawls.entities import eu.pb4.polymer.core.api.entity.PolymerEntityUtils -import net.mcbrawls.entities.entity.DisplayedBlockEntity +import net.mcbrawls.entities.entity.DisplayedModelEntity import net.mcbrawls.entities.entity.PlayerAttachedTextDisplayEntity import net.mcbrawls.entities.entity.TemporaryTextDisplayEntity import net.minecraft.entity.Entity @@ -16,7 +16,7 @@ import net.minecraft.util.Identifier object BrawlsAPIEntities { val DISPLAYED_BLOCK = register( "displayed_block", - EntityType.Builder.create(::DisplayedBlockEntity, SpawnGroup.MISC) + EntityType.Builder.create(::DisplayedModelEntity, SpawnGroup.MISC) .dimensions(0.0f, 0.0f) .maxTrackingRange(2) .trackingTickInterval(10) diff --git a/src/main/kotlin/net/mcbrawls/entities/entity/DisplayedBlockEntity.kt b/src/main/kotlin/net/mcbrawls/entities/entity/DisplayedModelEntity.kt similarity index 75% rename from src/main/kotlin/net/mcbrawls/entities/entity/DisplayedBlockEntity.kt rename to src/main/kotlin/net/mcbrawls/entities/entity/DisplayedModelEntity.kt index 51080cb..ac276be 100644 --- a/src/main/kotlin/net/mcbrawls/entities/entity/DisplayedBlockEntity.kt +++ b/src/main/kotlin/net/mcbrawls/entities/entity/DisplayedModelEntity.kt @@ -2,20 +2,20 @@ package net.mcbrawls.entities.entity import eu.pb4.polymer.core.api.entity.PolymerEntity import net.minecraft.component.DataComponentTypes -import net.minecraft.component.type.CustomModelDataComponent import net.minecraft.entity.EntityType import net.minecraft.entity.decoration.DisplayEntity.ItemDisplayEntity import net.minecraft.item.ItemStack import net.minecraft.item.Items import net.minecraft.nbt.NbtCompound import net.minecraft.nbt.NbtElement +import net.minecraft.util.Identifier import net.minecraft.util.math.AffineTransformation import net.minecraft.world.World import org.joml.Vector3f import xyz.nucleoid.packettweaker.PacketContext -open class DisplayedBlockEntity(type: EntityType<*>, world: World) : ItemDisplayEntity(type, world), PolymerEntity { - var customModelData: Int = 0 +open class DisplayedModelEntity(type: EntityType<*>, world: World) : ItemDisplayEntity(type, world), PolymerEntity { + var model: Identifier? = null set(value) { field = value updateItem() @@ -35,7 +35,7 @@ open class DisplayedBlockEntity(type: EntityType<*>, world: World) : ItemDisplay private fun updateItem() { setItemStack( ItemStack(Items.WHITE_DYE).apply { - set(DataComponentTypes.CUSTOM_MODEL_DATA, CustomModelDataComponent(customModelData)) + model?.also { set(DataComponentTypes.ITEM_MODEL, it) } } ) } @@ -47,13 +47,13 @@ open class DisplayedBlockEntity(type: EntityType<*>, world: World) : ItemDisplay } override fun writeCustomDataToNbt(nbt: NbtCompound) { - nbt.putInt(CUSTOM_MODEL_DATA_KEY, customModelData) + model?.also { nbt.putString(MODEL_KEY, it.toString()) } nbt.putFloat(SCALE_KEY, scale) } override fun readCustomDataFromNbt(nbt: NbtCompound) { - if (nbt.contains(CUSTOM_MODEL_DATA_KEY, NbtElement.INT_TYPE.toInt())) { - customModelData = nbt.getInt(CUSTOM_MODEL_DATA_KEY) + if (nbt.contains(MODEL_KEY, NbtElement.STRING_TYPE.toInt())) { + model = Identifier.tryParse(nbt.getString(MODEL_KEY)) } if (nbt.contains(SCALE_KEY, NbtElement.FLOAT_TYPE.toInt())) { @@ -66,7 +66,7 @@ open class DisplayedBlockEntity(type: EntityType<*>, world: World) : ItemDisplay } companion object { - private const val CUSTOM_MODEL_DATA_KEY = "custom_model_data" + private const val MODEL_KEY = "model" private const val SCALE_KEY = "scale" } }