diff --git a/common/src/main/java/muramasa/gregtech/blockentity/single/BlockEntityNuclearReactorCore.java b/common/src/main/java/muramasa/gregtech/blockentity/single/BlockEntityNuclearReactorCore.java index bf99c634c..01ebb0ca5 100644 --- a/common/src/main/java/muramasa/gregtech/blockentity/single/BlockEntityNuclearReactorCore.java +++ b/common/src/main/java/muramasa/gregtech/blockentity/single/BlockEntityNuclearReactorCore.java @@ -4,6 +4,7 @@ import io.github.gregtechintergalactical.gtcore.blockentity.IInventorySyncTile; import io.github.gregtechintergalactical.gtcore.network.MessageInventorySync; import io.github.gregtechintergalactical.gtcore.network.MessageTriggerInventorySync; +import muramasa.antimatter.Ref; import muramasa.antimatter.blockentity.BlockEntityMachine; import muramasa.antimatter.blockentity.IPostTickTile; import muramasa.antimatter.capability.IFilterableHandler; @@ -52,6 +53,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import tesseract.TesseractGraphWrappers; +import tesseract.api.item.ExtendedItemContainer; import static muramasa.antimatter.Ref.B; import static muramasa.gregtech.data.Materials.*; @@ -122,14 +124,7 @@ public boolean wrenchMachine(Player player, BlockHitResult res, boolean crouch) public void syncSlots(){ if (getLevel() != null && isServerSide()){ - itemHandler.ifPresent(i -> { - i.getAll().keySet().forEach(s -> { - var handler = i.getHandler(s); - for (int i1 = 0; i1 < handler.getSlots(); i1++) { - AntimatterNetwork.NETWORK.sendToAllLoaded(new MessageInventorySync(this.getBlockPos(), s, i1, i.getHandler(s).getItem(i1)), this.getLevel(), this.getBlockPos()); - } - }); - }); + sidedSync(true); } } @@ -416,11 +411,6 @@ public void onServerTickPost(Level level, BlockPos pos, boolean aFirst) { @Override public void onMachineEvent(IMachineEvent event, Object... data) { if (event == SlotType.STORAGE){ - if (data.length > 0 && data[0] instanceof Integer integer){ - if (isServerSide() && getLevel() != null){ - AntimatterNetwork.NETWORK.sendToAllLoaded(new MessageInventorySync(this.getBlockPos(), SlotType.STORAGE, integer, getRod(integer)), this.getLevel(), this.getBlockPos()); - } - } sidedSync(true); } super.onMachineEvent(event, data); @@ -441,6 +431,35 @@ public void saveAdditional(CompoundTag tag) { tag.put("oldNeutronCounts", oldNeutronCountTag); } + @Override + public @NotNull CompoundTag getUpdateTag() { + CompoundTag nbt = super.getUpdateTag(); + itemHandler.ifPresent(e -> { + CompoundTag in = new CompoundTag(); + e.getAll().forEach((f,i) -> { + in.put(f.getId(), serializeWithEmpty(i, new CompoundTag())); + }); + nbt.put(Ref.KEY_MACHINE_ITEMS, in); + }); + return nbt; + } + + public CompoundTag serializeWithEmpty(ExtendedItemContainer container, CompoundTag nbt) { + ListTag nbtTagList = new ListTag(); + + + for(int i = 0; i < container.getSlots(); ++i) { + CompoundTag itemTag = new CompoundTag(); + itemTag.putInt("Slot", i); + container.getItem(i).save(itemTag); + itemTag.putInt("count", container.getItem(i).getCount()); + nbtTagList.add(itemTag); + } + + nbt.put("Items", nbtTagList); + return nbt; + } + @Override public void load(CompoundTag tag) { super.load(tag);