diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/MatteryBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/MatteryBlockEntity.kt index b29a1a17e..ec3dc18d8 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/MatteryBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/MatteryBlockEntity.kt @@ -205,7 +205,6 @@ abstract class MatteryBlockEntity(p_155228_: BlockEntityType<*>, p_155229_: Bloc } private val caps = Reference2ObjectArrayMap, Cap<*>>() - private val modeStates = Object2ObjectArrayMap() private val data = Object2ObjectArrayMap>() private val subscriptions = Reference2ObjectArrayMap, SubRef<*>>() private val knownLOs = WeakHashSet>() @@ -283,17 +282,14 @@ abstract class MatteryBlockEntity(p_155228_: BlockEntityType<*>, p_155229_: Bloc } } - val isEmpty get() = caps.isEmpty() && modeStates.isEmpty() + val isEmpty get() = caps.isEmpty() && data.isEmpty() operator fun get(capability: Capability): Cap? { return caps[capability] as Cap? } - operator fun get(index: String): ModeState? { - return modeStates[index] - } - fun addData(index: ResourceLocation, data: INBTSerializable<*>) { + require(!this.data.containsKey(index)) { "Already has data with ID $index on $side!" } this.data[index] = data as INBTSerializable } @@ -313,32 +309,25 @@ abstract class MatteryBlockEntity(p_155228_: BlockEntityType<*>, p_155229_: Bloc override fun serializeNBT(): CompoundTag { return CompoundTag().also { - val modelist = CompoundTag() - - for (cap in modeStates.values) { - modelist[cap.name] = cap.serializeNBT() + for ((k, v) in data) { + it[k.toString()] = v.serializeNBT() } - - it["Modes"] = modelist } } override fun deserializeNBT(nbt: CompoundTag) { - if (nbt.contains("Modes")) { - val caplist = nbt.getCompound("Modes") + for ((k, v) in data) { + val tag = nbt[k.toString()] - for (state in modeStates.values) { - if (state.name in caplist) { - state.deserializeNBT(caplist.getString(state.name)) - } + if (tag != null) { + v.deserializeNBT(tag) } } } inner class ModeState(val name: String, val possibleValues: ImmutableSet = SideMode.BI_SET) : INBTSerializable { init { - check(!modeStates.containsKey(name)) { "Already has config with name $name on side $side" } - modeStates[name] = this + addData(ResourceLocation(name), this) } val side get() = this@Side.side