Skip to content

Commit

Permalink
Fix block entity serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
gdavid04 committed Mar 13, 2024
1 parent 5a04a56 commit 7b469f4
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 39 deletions.
11 changes: 6 additions & 5 deletions src/main/java/gdavid/phi/block/tile/CADHolderTile.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,20 +140,21 @@ public void load(CompoundTag nbt) {
}

@Override
public CompoundTag serializeNBT() {
var nbt = super.serializeNBT();
public void saveAdditional(CompoundTag nbt) {
super.saveAdditional(nbt);
nbt.put(tagItem, item.save(new CompoundTag()));
return nbt;
}

@Override
public ClientboundBlockEntityDataPacket getUpdatePacket() {
return ClientboundBlockEntityDataPacket.create(this, IForgeBlockEntity::serializeNBT);
return ClientboundBlockEntityDataPacket.create(this);
}

@Override
public CompoundTag getUpdateTag() {
return serializeNBT();
var nbt = new CompoundTag();
saveAdditional(nbt);
return nbt;
}

@Override
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/gdavid/phi/block/tile/CableTile.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,10 @@ public void load(CompoundTag nbt) {
}

@Override
public CompoundTag serializeNBT() {
var nbt = super.serializeNBT();
public void saveAdditional(CompoundTag nbt) {
super.saveAdditional(nbt);
if (connected != null) nbt.putLong(tagConnection, connected.asLong());
else nbt.remove(tagConnection);
return nbt;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ public void load(CompoundTag nbt) {
}

@Override
public CompoundTag serializeNBT() {
var nbt = super.serializeNBT();
public void saveAdditional(CompoundTag nbt) {
super.saveAdditional(nbt);
ListTag list = new ListTag();
for (Pair<ItemStack, Integer> pair : fuel) {
CompoundTag item = new CompoundTag();
Expand All @@ -174,7 +174,6 @@ public CompoundTag serializeNBT() {
}
nbt.put(tagFuel, list);
nbt.putInt(tagPsi, psi);
return nbt;
}

}
5 changes: 2 additions & 3 deletions src/main/java/gdavid/phi/block/tile/InfusionLaserTile.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,9 @@ public void load(CompoundTag nbt) {
}

@Override
public CompoundTag serializeNBT() {
var nbt = super.serializeNBT();
public void saveAdditional(CompoundTag nbt) {
super.saveAdditional(nbt);
nbt.putInt(tagPsi, psi);
return nbt;
}

}
11 changes: 6 additions & 5 deletions src/main/java/gdavid/phi/block/tile/MPUTile.java
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,8 @@ public void load(CompoundTag nbt) {
}

@Override
public CompoundTag serializeNBT() {
var nbt = super.serializeNBT();
public void saveAdditional(CompoundTag nbt) {
super.saveAdditional(nbt);
CompoundTag spellNbt = new CompoundTag();
if (spell != null) spell.writeToNBT(spellNbt);
nbt.put(tagSpell, spellNbt);
Expand All @@ -243,17 +243,18 @@ public CompoundTag serializeNBT() {
nbt.putInt(tagComparatorSignal, comparatorSignal);
nbt.putInt(tagSuccessCount, successCount);
nbt.putInt(tagRedstoneMode, redstoneMode.ordinal());
return nbt;
}

@Override
public ClientboundBlockEntityDataPacket getUpdatePacket() {
return ClientboundBlockEntityDataPacket.create(this, IForgeBlockEntity::serializeNBT);
return ClientboundBlockEntityDataPacket.create(this);
}

@Override
public CompoundTag getUpdateTag() {
return serializeNBT();
var nbt = new CompoundTag();
saveAdditional(nbt);
return nbt;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ private ItemEntity getItemUnder() {

@Override
public ClientboundBlockEntityDataPacket getUpdatePacket() {
return ClientboundBlockEntityDataPacket.create(this, IForgeBlockEntity::serializeNBT);
return ClientboundBlockEntityDataPacket.create(this);
}

@Override
Expand Down
11 changes: 6 additions & 5 deletions src/main/java/gdavid/phi/block/tile/SpellDisplayTile.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,22 +60,23 @@ public void load(CompoundTag nbt) {
}

@Override
public CompoundTag serializeNBT() {
var nbt = super.serializeNBT();
public void saveAdditional(CompoundTag nbt) {
super.saveAdditional(nbt);
CompoundTag spellNbt = new CompoundTag();
if (spell != null) spell.writeToNBT(spellNbt);
nbt.put(tagSpell, spellNbt);
return nbt;
}

@Override
public ClientboundBlockEntityDataPacket getUpdatePacket() {
return ClientboundBlockEntityDataPacket.create(this, IForgeBlockEntity::serializeNBT);
return ClientboundBlockEntityDataPacket.create(this);
}

@Override
public CompoundTag getUpdateTag() {
return serializeNBT();
var nbt = new CompoundTag();
saveAdditional(nbt);
return nbt;
}

@Override
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/gdavid/phi/block/tile/SpellStorageTile.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,14 @@ public void load(CompoundTag nbt) {
}

@Override
public CompoundTag serializeNBT() {
var nbt = super.serializeNBT();
public void saveAdditional(CompoundTag nbt) {
super.saveAdditional(nbt);
for (int i = 0; i < slots; i++) {
CompoundTag spellNbt = new CompoundTag();
if (spells[i] != null) spells[i].writeToNBT(spellNbt);
nbt.put(tagSpell + i, spellNbt);
}
nbt.putInt(tagSelectedSlot, selectedSlot);
return nbt;
}

}
11 changes: 6 additions & 5 deletions src/main/java/gdavid/phi/block/tile/TextDisplayTile.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,24 +91,25 @@ public void load(CompoundTag nbt) {
}

@Override
public CompoundTag serializeNBT() {
var nbt = super.serializeNBT();
public void saveAdditional(CompoundTag nbt) {
super.saveAdditional(nbt);
var list = new ListTag();
for (String line : text) {
list.add(StringTag.valueOf(line));
}
nbt.put(tagText, list);
return nbt;
}

@Override
public ClientboundBlockEntityDataPacket getUpdatePacket() {
return ClientboundBlockEntityDataPacket.create(this, IForgeBlockEntity::serializeNBT);
return ClientboundBlockEntityDataPacket.create(this);
}

@Override
public CompoundTag getUpdateTag() {
return serializeNBT();
var nbt = new CompoundTag();
saveAdditional(nbt);
return nbt;
}

@Override
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/gdavid/phi/block/tile/TextSUTile.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,9 @@ public void load(CompoundTag nbt) {
}

@Override
public CompoundTag serializeNBT() {
var nbt = super.serializeNBT();
public void saveAdditional(CompoundTag nbt) {
super.saveAdditional(nbt);
nbt.putString(tagText, text);
return nbt;
}

@Override
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/gdavid/phi/block/tile/VSUTile.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,13 @@ public void load(CompoundTag nbt) {
}

@Override
public CompoundTag serializeNBT() {
var nbt = super.serializeNBT();
public void saveAdditional(CompoundTag nbt) {
super.saveAdditional(nbt);
ListTag list = new ListTag();
list.add(DoubleTag.valueOf(vector.x));
list.add(DoubleTag.valueOf(vector.y));
list.add(DoubleTag.valueOf(vector.z));
nbt.put(tagVector, list);
return nbt;
}

@Override
Expand Down

0 comments on commit 7b469f4

Please sign in to comment.