diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/decorative/CargoCrateBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/decorative/CargoCrateBlockEntity.kt index ec7e9a5ac..7c1cfcbda 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/decorative/CargoCrateBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/decorative/CargoCrateBlockEntity.kt @@ -5,8 +5,6 @@ import net.minecraft.core.BlockPos import net.minecraft.core.HolderLookup import net.minecraft.core.registries.Registries import net.minecraft.nbt.CompoundTag -import net.minecraft.nbt.LongTag -import net.minecraft.nbt.StringTag import net.minecraft.network.chat.Component import net.minecraft.resources.ResourceKey import net.minecraft.resources.ResourceLocation @@ -33,8 +31,6 @@ import ru.dbotthepony.mc.otm.block.entity.MatteryDeviceBlockEntity import ru.dbotthepony.mc.otm.container.MatteryContainer import ru.dbotthepony.mc.otm.container.HandlerFilter import ru.dbotthepony.mc.otm.core.TranslatableComponent -import ru.dbotthepony.mc.otm.core.nbt.map -import ru.dbotthepony.mc.otm.core.nbt.set import ru.dbotthepony.mc.otm.core.otmRandom import ru.dbotthepony.mc.otm.menu.decorative.CargoCrateMenu import ru.dbotthepony.mc.otm.registry.game.MBlockEntities @@ -95,14 +91,20 @@ class CargoCrateBlockEntity( override fun saveLevel(nbt: CompoundTag, registry: HolderLookup.Provider) { super.saveLevel(nbt, registry) - lootTable?.let { nbt[LOOT_TABLE_KEY] = it.toString() } - lootTableSeed?.let { nbt[LOOT_TABLE_SEED_KEY] = it } + + if (lootTable != null) { + nbt.putString(LOOT_TABLE_KEY, lootTable!!.location().toString()) + nbt.putLong(LOOT_TABLE_SEED_KEY, lootTableSeed ?: 0L) + } } override fun loadAdditional(nbt: CompoundTag, registry: HolderLookup.Provider) { super.loadAdditional(nbt, registry) - lootTable = nbt.map(LOOT_TABLE_KEY) { it: StringTag -> ResourceLocation.tryParse(it.asString)?.let { ResourceKey.create(Registries.LOOT_TABLE, it) } } - lootTableSeed = (nbt[LOOT_TABLE_SEED_KEY] as LongTag?)?.asLong + + if (nbt.contains(LOOT_TABLE_KEY, 8)) { + lootTable = ResourceKey.create(Registries.LOOT_TABLE, ResourceLocation.parse(nbt.getString(LOOT_TABLE_KEY))) + lootTableSeed = if (nbt.contains(LOOT_TABLE_SEED_KEY, 4)) nbt.getLong(LOOT_TABLE_SEED_KEY) else 0L + } } fun unpackLootTable(ply: Player? = null) {