diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/MatteryWorkerBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/MatteryWorkerBlockEntity.kt index 56ac3b958..4ddaf9721 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/MatteryWorkerBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/MatteryWorkerBlockEntity.kt @@ -15,7 +15,7 @@ abstract class MatteryWorkerBlockEntity( type: BlockEntityType<*>, blockPos: BlockPos, blockState: BlockState, - val jobDeserializer: (tag: CompoundTag) -> JobType + val jobDeserializer: (tag: CompoundTag) -> JobType? ) : MatteryPoweredBlockEntity(type, blockPos, blockState) { open class Job( open val ticks: Double, diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterReplicatorBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterReplicatorBlockEntity.kt index edffdc60d..062b19d50 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterReplicatorBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterReplicatorBlockEntity.kt @@ -31,7 +31,13 @@ import ru.dbotthepony.mc.otm.container.set import ru.dbotthepony.mc.otm.core.* class MatterReplicatorBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : - MatteryWorkerBlockEntity(MBlockEntities.MATTER_REPLICATOR, p_155229_, p_155230_, ::ReplicatorJob), IMatterGraphNode { + MatteryWorkerBlockEntity(MBlockEntities.MATTER_REPLICATOR, p_155229_, p_155230_, { + try { + ReplicatorJob(it) + } catch(err: NoSuchElementException) { + null + } + }), IMatterGraphNode { class ReplicatorJob : ItemJob { val matterPerTick: ImpreciseFraction @@ -41,11 +47,11 @@ class MatterReplicatorBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : val asDust: Boolean constructor(tag: CompoundTag) : super(tag) { - matterPerTick = tag.getImpreciseFraction("matter_per_tick") - matterValue = tag.getImpreciseFraction("value") + matterPerTick = tag.getImpreciseFraction("matterPerTick") + matterValue = tag.getImpreciseFraction("matterValue") pattern = tag.map("pattern", PatternState::deserializeNBT) - asDust = tag.getBoolean("as_dust") - task = tag.map("task", ReplicationTask::deserializeNBT) ?: throw NullPointerException("Unable to deserialize matter task") + asDust = tag.getBoolean("asDust") + task = tag.map("task", ReplicationTask::deserializeNBT) ?: throw NoSuchElementException("Unable to deserialize matter task") } constructor( @@ -63,6 +69,19 @@ class MatterReplicatorBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : this.pattern = pattern this.asDust = asDust } + + override fun serializeNBT(): CompoundTag { + return super.serializeNBT().also { + it["matterPerTick"] = this.matterPerTick + it["task"] = this.task.serializeNBT() + it["matterValue"] = this.matterValue + + if (this.pattern != null) + it["pattern"] = this.pattern.serializeNBT() + + it["asDust"] = this.asDust + } + } } override val energy = WorkerEnergyStorage(this::powerLevelUpdated, STORAGE, MAX_IO)