aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gregtech/api/multitileentity/base/NonTickableMultiTileEntity.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/gregtech/api/multitileentity/base/NonTickableMultiTileEntity.java')
-rw-r--r--src/main/java/gregtech/api/multitileentity/base/NonTickableMultiTileEntity.java58
1 files changed, 58 insertions, 0 deletions
diff --git a/src/main/java/gregtech/api/multitileentity/base/NonTickableMultiTileEntity.java b/src/main/java/gregtech/api/multitileentity/base/NonTickableMultiTileEntity.java
new file mode 100644
index 0000000000..a4007ec85e
--- /dev/null
+++ b/src/main/java/gregtech/api/multitileentity/base/NonTickableMultiTileEntity.java
@@ -0,0 +1,58 @@
+package gregtech.api.multitileentity.base;
+
+import static gregtech.api.enums.GT_Values.NW;
+
+import net.minecraft.entity.player.EntityPlayerMP;
+import net.minecraft.network.Packet;
+
+import gregtech.api.net.GT_Packet_SendCoverData;
+import gregtech.api.util.ISerializableObject;
+import gregtech.common.covers.CoverInfo;
+
+public abstract class NonTickableMultiTileEntity extends MultiTileEntity {
+
+ boolean mConstructed = false; // Keeps track of whether this TE has been constructed and placed in the world
+
+ public NonTickableMultiTileEntity() {
+ super(false);
+ }
+
+ @Override
+ public void issueClientUpdate() {
+ if (worldObj != null && !worldObj.isRemote) sendClientData(null);
+ }
+
+ @Override
+ public Packet getDescriptionPacket() {
+ // We should have a world object and have been constructed by this point
+ mConstructed = true;
+
+ super.getDescriptionPacket();
+ // We don't get ticked, so if we have any cover data that needs to be sent, send it now
+ sendCoverDataIfNeeded();
+ return null;
+ }
+
+ @Override
+ public void issueCoverUpdate(byte aSide) {
+ if (!mConstructed) {
+ // Queue these up and send them with the description packet
+ super.issueCoverUpdate(aSide);
+ } else {
+ // Otherwise, send the data right away
+ final CoverInfo coverInfo = getCoverInfoAtSide(aSide);
+ NW.sendPacketToAllPlayersInRange(worldObj, new GT_Packet_SendCoverData(coverInfo, this), xCoord, zCoord);
+
+ // Just in case
+ coverInfo.setNeedsUpdate(false);
+ }
+ }
+
+ @Override
+ public void receiveCoverData(byte aCoverSide, int aCoverID, ISerializableObject aCoverData,
+ EntityPlayerMP aPlayer) {
+ super.receiveCoverData(aCoverSide, aCoverID, aCoverData, aPlayer);
+ // We don't get ticked so issue the texture update right away
+ issueTextureUpdate();
+ }
+}