Skip to content

Commit

Permalink
feat: change custom model data to a model location
Browse files Browse the repository at this point in the history
  • Loading branch information
andantet committed Oct 28, 2024
1 parent 665bb80 commit 739f490
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/net/mcbrawls/entities/BrawlsAPIEntities.kt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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) }
}
)
}
Expand All @@ -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())) {
Expand All @@ -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"
}
}

0 comments on commit 739f490

Please sign in to comment.