Skip to content

Commit 17691d5

Browse files
committed
replace instanceof cast with overridable method
1 parent 8eae4e8 commit 17691d5

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed

src/main/java/gregtech/api/metatileentity/GTBaseTileEntity.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,14 @@ public double[] getTimeStatistics() {
206206
return null;
207207
}
208208

209+
@Override
210+
protected void addAdditionalData(NBTTagCompound updateTag) {
211+
updateTag.setString("MetaId", getMetaID().toString());
212+
updateTag.setInteger("x", getPos().getX());
213+
updateTag.setInteger("y", getPos().getY());
214+
updateTag.setInteger("z", getPos().getZ());
215+
}
216+
209217
@Override
210218
public void writeInitialSyncData(@NotNull PacketBuffer buf) {
211219
buf.writeString(getName());

src/main/java/gregtech/api/metatileentity/SyncedTileEntityBase.java

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package gregtech.api.metatileentity;
22

33
import gregtech.api.block.BlockStateTileEntity;
4-
import gregtech.api.metatileentity.interfaces.IGregTechTileEntity;
54
import gregtech.api.metatileentity.interfaces.ISyncedTileEntity;
65
import gregtech.api.network.PacketDataList;
76

@@ -89,15 +88,12 @@ private boolean canNotifyWorld() {
8988
}
9089
NBTTagCompound updateTag = new NBTTagCompound();
9190
updateTag.setTag("d", this.updates.dumpToNbt());
92-
if (this instanceof IGregTechTileEntity gregTechTile) {
93-
updateTag.setString("MetaId", gregTechTile.getMetaTileEntity().getMetaID().toString());
94-
updateTag.setInteger("x", getPos().getX());
95-
updateTag.setInteger("y", getPos().getY());
96-
updateTag.setInteger("z", getPos().getZ());
97-
}
91+
addAdditionalData(updateTag);
9892
return new SPacketUpdateTileEntity(getPos(), 0, updateTag);
9993
}
10094

95+
protected void addAdditionalData(NBTTagCompound updateTag) {}
96+
10197
@Override
10298
public final void onDataPacket(@NotNull NetworkManager net, @NotNull SPacketUpdateTileEntity pkt) {
10399
NBTTagCompound updateTag = pkt.getNbtCompound();
@@ -121,12 +117,7 @@ public final void onDataPacket(@NotNull NetworkManager net, @NotNull SPacketUpda
121117
writeInitialSyncData(new PacketBuffer(backedBuffer));
122118
byte[] updateData = Arrays.copyOfRange(backedBuffer.array(), 0, backedBuffer.writerIndex());
123119
updateTag.setByteArray("d", updateData);
124-
if (this instanceof IGregTechTileEntity gregTechTile) {
125-
updateTag.setString("MetaId", gregTechTile.getMetaTileEntity().getMetaID().toString());
126-
updateTag.setInteger("x", getPos().getX());
127-
updateTag.setInteger("y", getPos().getY());
128-
updateTag.setInteger("z", getPos().getZ());
129-
}
120+
addAdditionalData(updateTag);
130121
return updateTag;
131122
}
132123

0 commit comments

Comments
 (0)