Skip to content
This repository has been archived by the owner on Nov 5, 2024. It is now read-only.

Commit

Permalink
fixed rod syncing
Browse files Browse the repository at this point in the history
  • Loading branch information
Trinsdar committed Aug 11, 2024
1 parent bb3deb9 commit 2806ac0
Showing 1 changed file with 32 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.*;
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit 2806ac0

Please sign in to comment.