diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/decorative/GrillBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/decorative/GrillBlockEntity.kt index b909c6932..529c4aaa6 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/decorative/GrillBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/decorative/GrillBlockEntity.kt @@ -38,7 +38,6 @@ import ru.dbotthepony.mc.otm.core.math.component2 import ru.dbotthepony.mc.otm.core.math.component3 import ru.dbotthepony.mc.otm.core.set import ru.dbotthepony.mc.otm.core.util.countingLazy -import ru.dbotthepony.mc.otm.data.codec.KOptionalCodec import ru.dbotthepony.mc.otm.data.codec.minRange import ru.dbotthepony.mc.otm.menu.decorative.GrillMenu import ru.dbotthepony.mc.otm.registry.game.MBlockEntities @@ -54,7 +53,7 @@ class GrillBlockEntity(blockPos: BlockPos, blockState: BlockState) : MatteryBloc private fun clearSlot() { inputProgress[slot] = 0 outputs[slot] = null - outputsRecipeNames[slot] = KOptional.empty() + outputsRecipeNames[slot] = null activeSlots.rem(slot) } @@ -79,10 +78,10 @@ class GrillBlockEntity(blockPos: BlockPos, blockState: BlockState) : MatteryBloc if (result == null) { clearSlot() } else { - if (outputsRecipeNames[slot].orNull() != result.id) + if (outputsRecipeNames[slot] != result.id) inputProgress[slot] = 0 - outputsRecipeNames[slot] = KOptional.of(result.id) + outputsRecipeNames[slot] = result.id outputs[slot] = result.value activeSlots.add(slot) } @@ -101,7 +100,7 @@ class GrillBlockEntity(blockPos: BlockPos, blockState: BlockState) : MatteryBloc return customDisplayName ?: level?.getBlockState(blockPos)?.block?.name ?: TextComponent("null at $blockPos") } - private val outputsRecipeNames = Array>(SLOTS) { KOptional.empty() } + private val outputsRecipeNames = arrayOfNulls(SLOTS) private val outputs = arrayOfNulls(SLOTS) private val activeSlots = IntArrayList() private val inputProgress = IntArray(SLOTS) @@ -138,12 +137,12 @@ class GrillBlockEntity(blockPos: BlockPos, blockState: BlockState) : MatteryBloc savetables.stateful(::fuelSlot) savetables.stateful(::experience) - outputsRecipeNames.fill(KOptional()) + outputsRecipeNames.fill(null) // TODO: could have been done as list (and get more space efficient storage), but we use an array, oh well for (i in inputProgress.indices) { savetables.codec(Delegate.Of({ inputProgress[i] }, { inputProgress[i] = it }), progressCodec, "inputProgress${i}") - savetables.codec(Delegate.Of({ outputsRecipeNames[i] }, { outputsRecipeNames[i] = it }), recipeNameCodec, "recipeName${i}") + savetables.codecNullable(Delegate.Of({ outputsRecipeNames[i] }, { outputsRecipeNames[i] = it }), ResourceLocation.CODEC, "recipeName${i}") } // addDroppableContainer(inputSlots) @@ -216,7 +215,6 @@ class GrillBlockEntity(blockPos: BlockPos, blockState: BlockState) : MatteryBloc const val SLOTS = 6 private val progressCodec = Codec.INT.minRange(0) - private val recipeNameCodec = KOptionalCodec(ResourceLocation.CODEC) val FUEL_SLOT_PROVIDER = ContainerSlot.Simple(maxStackSize = 4, filter = AutomationFilters.CHEMICAL_FUEL) } } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/core/util/Savetables.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/core/util/Savetables.kt index 238f42d84..9f2e734b6 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/core/util/Savetables.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/core/util/Savetables.kt @@ -7,6 +7,7 @@ import net.minecraft.core.HolderLookup.Provider import net.minecraft.nbt.ByteTag import net.minecraft.nbt.CompoundTag import net.minecraft.nbt.DoubleTag +import net.minecraft.nbt.EndTag import net.minecraft.nbt.FloatTag import net.minecraft.nbt.IntTag import net.minecraft.nbt.LongTag @@ -297,7 +298,7 @@ class Savetables : INBTSerializable { for (entry in entries) { val value = entry.serializeNBT(registry) - if (value != null) + if (value != null && value !is EndTag) nbt[entry.name] = value } } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/data/codec/KOptionalCodec.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/data/codec/KOptionalCodec.kt deleted file mode 100644 index d83207062..000000000 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/data/codec/KOptionalCodec.kt +++ /dev/null @@ -1,21 +0,0 @@ -package ru.dbotthepony.mc.otm.data.codec - -import com.mojang.datafixers.util.Pair -import com.mojang.serialization.Codec -import com.mojang.serialization.DataResult -import com.mojang.serialization.DynamicOps -import ru.dbotthepony.kommons.util.KOptional - -class KOptionalCodec(val parent: Codec) : Codec> { - override fun encode(input: KOptional, ops: DynamicOps, prefix: T): DataResult { - return input.map { parent.encode(it, ops, prefix) }.orElse { DataResult.success(ops.empty()) } - } - - override fun decode(ops: DynamicOps, input: T): DataResult, T>> { - if (input == ops.empty()) { - return DataResult.success(Pair(KOptional(), ops.empty())) - } else { - return parent.decode(ops, input).map { Pair(KOptional(it.first), it.second) } - } - } -}