aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gregtech/api/net
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/gregtech/api/net')
-rw-r--r--src/main/java/gregtech/api/net/GT_Packet.java59
-rw-r--r--src/main/java/gregtech/api/net/GT_Packet_Block_Event.java63
-rw-r--r--src/main/java/gregtech/api/net/GT_Packet_ClientPreference.java62
-rw-r--r--src/main/java/gregtech/api/net/GT_Packet_GtTileEntityGuiRequest.java122
-rw-r--r--src/main/java/gregtech/api/net/GT_Packet_MultiTileEntity.java254
-rw-r--r--src/main/java/gregtech/api/net/GT_Packet_New.java30
-rw-r--r--src/main/java/gregtech/api/net/GT_Packet_Pollution.java47
-rw-r--r--src/main/java/gregtech/api/net/GT_Packet_RequestCoverData.java113
-rw-r--r--src/main/java/gregtech/api/net/GT_Packet_SendCoverData.java107
-rw-r--r--src/main/java/gregtech/api/net/GT_Packet_SendOregenPattern.java56
-rw-r--r--src/main/java/gregtech/api/net/GT_Packet_SetConfigurationCircuit.java110
-rw-r--r--src/main/java/gregtech/api/net/GT_Packet_Sound.java70
-rw-r--r--src/main/java/gregtech/api/net/GT_Packet_TileEntity.java157
-rw-r--r--src/main/java/gregtech/api/net/GT_Packet_TileEntityCover.java98
-rw-r--r--src/main/java/gregtech/api/net/GT_Packet_TileEntityCoverGUI.java219
-rw-r--r--src/main/java/gregtech/api/net/GT_Packet_TileEntityCoverNew.java119
-rw-r--r--src/main/java/gregtech/api/net/GT_Packet_UpdateItem.java64
-rw-r--r--src/main/java/gregtech/api/net/GT_Packet_WirelessRedstoneCover.java99
-rw-r--r--src/main/java/gregtech/api/net/IGT_NetworkHandler.java18
-rw-r--r--src/main/java/gregtech/api/net/data/CasingData.java53
-rw-r--r--src/main/java/gregtech/api/net/data/CommonData.java50
-rw-r--r--src/main/java/gregtech/api/net/data/CoordinateData.java50
-rw-r--r--src/main/java/gregtech/api/net/data/MultiTileEntityData.java45
-rw-r--r--src/main/java/gregtech/api/net/data/MultiTileEntityProcess.java54
-rw-r--r--src/main/java/gregtech/api/net/data/PacketData.java48
-rw-r--r--src/main/java/gregtech/api/net/data/Process.java6
26 files changed, 2173 insertions, 0 deletions
diff --git a/src/main/java/gregtech/api/net/GT_Packet.java b/src/main/java/gregtech/api/net/GT_Packet.java
new file mode 100644
index 0000000000..d06ea7d0d3
--- /dev/null
+++ b/src/main/java/gregtech/api/net/GT_Packet.java
@@ -0,0 +1,59 @@
+package gregtech.api.net;
+
+import net.minecraft.network.INetHandler;
+import net.minecraft.world.IBlockAccess;
+
+import com.google.common.io.ByteArrayDataInput;
+
+import io.netty.buffer.ByteBuf;
+
+/**
+ * @deprecated Use {@link GT_Packet_New} instead
+ */
+@Deprecated
+public abstract class GT_Packet {
+
+ public GT_Packet(boolean aIsReference) {
+ //
+ }
+
+ /**
+ * I use constant IDs instead of Dynamic ones, since that is much more fail safe
+ *
+ * @return a Packet ID for this Class
+ */
+ public abstract byte getPacketID();
+
+ /**
+ * @return encoded byte Stream
+ * @deprecated Use {@link #encode(ByteBuf)} instead
+ */
+ @Deprecated
+ public abstract byte[] encode();
+
+ /**
+ * Encode the data into given byte buffer without creating an intermediate byte array. Default implementation just
+ * throw {@link UnsupportedOperationException}.
+ */
+ public void encode(ByteBuf aOut) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * @return encoded byte Stream
+ */
+ public abstract GT_Packet decode(ByteArrayDataInput aData);
+
+ /**
+ * Process the packet
+ *
+ * @param aWorld null if message is received on server side, the client world if message is received on client side
+ */
+ public abstract void process(IBlockAccess aWorld);
+
+ /**
+ * This will be called just before {@link #process(IBlockAccess)} to inform the handler about the source and type of
+ * connection
+ */
+ public void setINetHandler(INetHandler aHandler) {}
+}
diff --git a/src/main/java/gregtech/api/net/GT_Packet_Block_Event.java b/src/main/java/gregtech/api/net/GT_Packet_Block_Event.java
new file mode 100644
index 0000000000..98dc8a5c4f
--- /dev/null
+++ b/src/main/java/gregtech/api/net/GT_Packet_Block_Event.java
@@ -0,0 +1,63 @@
+package gregtech.api.net;
+
+import net.minecraft.tileentity.TileEntity;
+import net.minecraft.world.IBlockAccess;
+
+import com.google.common.io.ByteArrayDataInput;
+
+import io.netty.buffer.ByteBuf;
+
+/**
+ * Used to transfer Block Events in a much better fashion
+ */
+public class GT_Packet_Block_Event extends GT_Packet_New {
+
+ private int mX, mZ;
+ private short mY;
+ private byte mID, mValue;
+
+ public GT_Packet_Block_Event() {
+ super(true);
+ }
+
+ public GT_Packet_Block_Event(int aX, short aY, int aZ, byte aID, byte aValue) {
+ super(false);
+ mX = aX;
+ mY = aY;
+ mZ = aZ;
+ mID = aID;
+ mValue = aValue;
+ }
+
+ @Override
+ public void encode(ByteBuf aOut) {
+ aOut.writeInt(mX);
+ aOut.writeShort(mY);
+ aOut.writeInt(mZ);
+ aOut.writeByte(mID);
+ aOut.writeByte(mValue);
+ }
+
+ @Override
+ public GT_Packet_New decode(ByteArrayDataInput aData) {
+ return new GT_Packet_Block_Event(
+ aData.readInt(),
+ aData.readShort(),
+ aData.readInt(),
+ aData.readByte(),
+ aData.readByte());
+ }
+
+ @Override
+ public void process(IBlockAccess aWorld) {
+ if (aWorld != null) {
+ final TileEntity tTileEntity = aWorld.getTileEntity(mX, mY, mZ);
+ if (tTileEntity != null) tTileEntity.receiveClientEvent(mID, mValue);
+ }
+ }
+
+ @Override
+ public byte getPacketID() {
+ return 2;
+ }
+}
diff --git a/src/main/java/gregtech/api/net/GT_Packet_ClientPreference.java b/src/main/java/gregtech/api/net/GT_Packet_ClientPreference.java
new file mode 100644
index 0000000000..0835676c6f
--- /dev/null
+++ b/src/main/java/gregtech/api/net/GT_Packet_ClientPreference.java
@@ -0,0 +1,62 @@
+package gregtech.api.net;
+
+import net.minecraft.entity.player.EntityPlayerMP;
+import net.minecraft.network.INetHandler;
+import net.minecraft.network.NetHandlerPlayServer;
+import net.minecraft.world.IBlockAccess;
+
+import com.google.common.io.ByteArrayDataInput;
+
+import gregtech.GT_Mod;
+import gregtech.api.util.GT_ClientPreference;
+import io.netty.buffer.ByteBuf;
+
+public class GT_Packet_ClientPreference extends GT_Packet_New {
+
+ private GT_ClientPreference mPreference;
+ private EntityPlayerMP mPlayer;
+
+ public GT_Packet_ClientPreference() {
+ super(true);
+ }
+
+ public GT_Packet_ClientPreference(GT_ClientPreference mPreference) {
+ super(false);
+ this.mPreference = mPreference;
+ }
+
+ @Override
+ public byte getPacketID() {
+ return 9;
+ }
+
+ @Override
+ public void setINetHandler(INetHandler aHandler) {
+ if (aHandler instanceof NetHandlerPlayServer) {
+ mPlayer = ((NetHandlerPlayServer) aHandler).playerEntity;
+ }
+ }
+
+ @Override
+ public void process(IBlockAccess aWorld) {
+ if (mPlayer != null) GT_Mod.gregtechproxy.setClientPreference(mPlayer.getUniqueID(), mPreference);
+ }
+
+ @Override
+ public void encode(ByteBuf aOut) {
+ aOut.writeBoolean(mPreference.isSingleBlockInitialFilterEnabled());
+ aOut.writeBoolean(mPreference.isSingleBlockInitialMultiStackEnabled());
+ aOut.writeBoolean(mPreference.isInputBusInitialFilterEnabled());
+ aOut.writeBoolean(mPreference.isWailaAverageNSEnabled());
+ }
+
+ @Override
+ public GT_Packet_New decode(ByteArrayDataInput aData) {
+ return new GT_Packet_ClientPreference(
+ new GT_ClientPreference(
+ aData.readBoolean(),
+ aData.readBoolean(),
+ aData.readBoolean(),
+ aData.readBoolean()));
+ }
+}
diff --git a/src/main/java/gregtech/api/net/GT_Packet_GtTileEntityGuiRequest.java b/src/main/java/gregtech/api/net/GT_Packet_GtTileEntityGuiRequest.java
new file mode 100644
index 0000000000..dc2f88316d
--- /dev/null
+++ b/src/main/java/gregtech/api/net/GT_Packet_GtTileEntityGuiRequest.java
@@ -0,0 +1,122 @@
+package gregtech.api.net;
+
+import net.minecraft.entity.player.EntityPlayerMP;
+import net.minecraft.tileentity.TileEntity;
+import net.minecraft.world.IBlockAccess;
+import net.minecraft.world.World;
+import net.minecraftforge.common.DimensionManager;
+import net.minecraftforge.common.util.ForgeDirection;
+
+import com.google.common.io.ByteArrayDataInput;
+
+import gregtech.api.enums.GT_Values;
+import gregtech.api.gui.modularui.GT_UIInfos;
+import gregtech.api.metatileentity.BaseTileEntity;
+import gregtech.api.metatileentity.CoverableTileEntity;
+import gregtech.common.GT_Proxy;
+import io.netty.buffer.ByteBuf;
+
+/**
+ * Client -> Server: Request that the server opens a Gregtech GUI for us after providing us with the required data.
+ */
+public class GT_Packet_GtTileEntityGuiRequest extends GT_Packet_New {
+
+ protected int mX;
+ protected short mY;
+ protected int mZ;
+
+ protected int guiId;
+ protected int dimId, playerId;
+
+ protected int parentGuiId;
+
+ public GT_Packet_GtTileEntityGuiRequest() {
+ super(true);
+ }
+
+ public GT_Packet_GtTileEntityGuiRequest(int mX, short mY, int mZ, int guiId, int dimID, int playerID,
+ int parentGuiId) {
+ super(false);
+ this.mX = mX;
+ this.mY = mY;
+ this.mZ = mZ;
+
+ this.guiId = guiId;
+
+ this.dimId = dimID;
+ this.playerId = playerID;
+
+ this.parentGuiId = parentGuiId;
+ }
+
+ public GT_Packet_GtTileEntityGuiRequest(int mX, short mY, int mZ, int guiId, int dimID, int playerID) {
+ this(mX, mY, mZ, guiId, dimID, playerID, -1);
+ }
+
+ @Override
+ public void encode(ByteBuf aOut) {
+ aOut.writeInt(mX);
+ aOut.writeShort(mY);
+ aOut.writeInt(mZ);
+
+ aOut.writeInt(guiId);
+
+ aOut.writeInt(dimId);
+ aOut.writeInt(playerId);
+
+ aOut.writeInt(parentGuiId);
+ }
+
+ @Override
+ public GT_Packet_New decode(ByteArrayDataInput aData) {
+ return new GT_Packet_GtTileEntityGuiRequest(
+ aData.readInt(),
+ aData.readShort(),
+ aData.readInt(),
+ aData.readInt(),
+ aData.readInt(),
+ aData.readInt(),
+ aData.readInt());
+ }
+
+ @Override
+ public byte getPacketID() {
+ return 15;
+ }
+
+ @Override
+ public void process(IBlockAccess aWorld) {
+ final World world = DimensionManager.getWorld(this.dimId);
+ if (world == null) return;
+ final TileEntity tile = world.getTileEntity(this.mX, this.mY, this.mZ);
+ if (!(tile instanceof BaseTileEntity baseTile) || baseTile.isDead()) return;
+
+ final EntityPlayerMP player = (EntityPlayerMP) world.getEntityByID(playerId);
+ final CoverableTileEntity coverableTile = (baseTile instanceof CoverableTileEntity)
+ ? (CoverableTileEntity) baseTile
+ : null;
+ // If the requested Gui ID corresponds to a cover, send the cover data to the client so they can open it.
+ if (GT_Proxy.GUI_ID_COVER_SIDE_BASE <= guiId && guiId < GT_Proxy.GUI_ID_COVER_SIDE_BASE + 6
+ && coverableTile != null) {
+ final ForgeDirection coverSide = ForgeDirection
+ .getOrientation((byte) (guiId - GT_Proxy.GUI_ID_COVER_SIDE_BASE));
+ final GT_Packet_TileEntityCoverGUI packet = new GT_Packet_TileEntityCoverGUI(
+ this.mX,
+ this.mY,
+ this.mZ,
+ coverSide,
+ coverableTile.getCoverIDAtSide(coverSide),
+ coverableTile.getComplexCoverDataAtSide(coverSide),
+ this.dimId,
+ this.playerId,
+ parentGuiId);
+ GT_Values.NW.sendToPlayer(packet, player);
+ } else if (guiId == 0) {
+ if (baseTile.useModularUI()) {
+ GT_UIInfos.openGTTileEntityUI(baseTile, player);
+ } else {
+ baseTile.openGUI(player);
+ }
+ }
+ }
+}
diff --git a/src/main/java/gregtech/api/net/GT_Packet_MultiTileEntity.java b/src/main/java/gregtech/api/net/GT_Packet_MultiTileEntity.java
new file mode 100644
index 0000000000..096f21df29
--- /dev/null
+++ b/src/main/java/gregtech/api/net/GT_Packet_MultiTileEntity.java
@@ -0,0 +1,254 @@
+package gregtech.api.net;
+
+import static gregtech.api.enums.GT_Values.B;
+
+import java.util.HashSet;
+import java.util.Objects;
+import java.util.Set;
+
+import net.minecraft.world.IBlockAccess;
+
+import com.google.common.io.ByteArrayDataInput;
+
+import gregtech.api.net.data.CasingData;
+import gregtech.api.net.data.CommonData;
+import gregtech.api.net.data.CoordinateData;
+import gregtech.api.net.data.MultiTileEntityData;
+import gregtech.api.net.data.MultiTileEntityProcess;
+import gregtech.api.net.data.PacketData;
+import io.netty.buffer.ByteBuf;
+
+public class GT_Packet_MultiTileEntity extends GT_Packet_New {
+
+ private final Set<PacketData<MultiTileEntityProcess>> data = new HashSet<>();
+ public static final int COVERS = B[0], REDSTONE = B[1], MODES = B[2], CONTROLLER = B[3], INVENTORY_INDEX = B[4],
+ INVENTORY_NAME_ID = B[5], BOOLEANS = B[6], SOUND = B[7];
+
+ public GT_Packet_MultiTileEntity(boolean reference) {
+ super(reference);
+ }
+
+ @Override
+ public void encode(ByteBuf aOut) {
+ Set<PacketData<MultiTileEntityProcess>> set = data.stream()
+ .sorted()
+ .collect(
+ HashSet<PacketData<MultiTileEntityProcess>>::new,
+ HashSet<PacketData<MultiTileEntityProcess>>::add,
+ HashSet<PacketData<MultiTileEntityProcess>>::addAll);
+ clearData();
+ data.addAll(set);
+ int features = 0;
+ for (PacketData<MultiTileEntityProcess> data : data) {
+ features |= 1 << data.getId();
+ }
+
+ aOut.writeInt(features);
+
+ for (PacketData<MultiTileEntityProcess> data : data) {
+ data.encode(aOut);
+ }
+ /*
+ * TODO Move to new system
+ * if ((features & COVERS) == COVERS) {
+ * aOut.writeInt(mC0);
+ * aOut.writeInt(mC1);
+ * aOut.writeInt(mC2);
+ * aOut.writeInt(mC3);
+ * aOut.writeInt(mC4);
+ * aOut.writeInt(mC5);
+ * }
+ * if ((features & MODES) == MODES) {
+ * aOut.writeInt(mode);
+ * aOut.writeInt(allowedModes);
+ * }
+ * if ((features & CONTROLLER) == CONTROLLER) {
+ * aOut.writeInt(mTargetPos.posX);
+ * aOut.writeShort(mTargetPos.posY);
+ * aOut.writeInt(mTargetPos.posZ);
+ * }
+ * if ((features & INVENTORY_INDEX) == INVENTORY_INDEX) {
+ * aOut.writeInt(mLockedInventoryIndex);
+ * }
+ * if ((features & INVENTORY_NAME_ID) == INVENTORY_NAME_ID) {
+ * if (mInventoryName != null && mInventoryName.length() > 0) {
+ * byte[] bytes = mInventoryName.getBytes();
+ * aOut.writeInt(bytes.length);
+ * aOut.writeBytes(bytes);
+ * } else {
+ * aOut.writeInt(0);
+ * }
+ * if (inventoryID != null && inventoryID.length() > 0) {
+ * byte[] bytes = inventoryID.getBytes();
+ * aOut.writeInt(bytes.length);
+ * aOut.writeBytes(bytes);
+ * } else {
+ * aOut.writeInt(0);
+ * }
+ * }
+ * if ((features & BOOLEANS) == BOOLEANS) {
+ * aOut.writeInt(booleans);
+ * }
+ * if ((features & SOUND) == SOUND) {
+ * aOut.writeByte(soundEvent);
+ * aOut.writeInt(soundEventValue);
+ * }
+ */
+ }
+
+ @Override
+ public GT_Packet_New decode(ByteArrayDataInput in) {
+ Objects.requireNonNull(in);
+ final int packetFeatures = in.readInt();
+
+ final GT_Packet_MultiTileEntity packet = new GT_Packet_MultiTileEntity(false);
+
+ if (containsBit(packetFeatures, CoordinateData.COORDINATE_DATA_ID)) {
+ packet.addData(new CoordinateData());
+ }
+ if (containsBit(packetFeatures, MultiTileEntityData.MULTI_TILE_ENTITY_DATA_ID)) {
+ packet.addData(new MultiTileEntityData());
+ }
+ if (containsBit(packetFeatures, CommonData.COMMON_DATA_ID)) {
+ packet.addData(new CommonData());
+ }
+ if (containsBit(packetFeatures, CasingData.CASING_DATA_ID)) {
+ packet.addData(new CasingData());
+ }
+
+ Set<PacketData<MultiTileEntityProcess>> set = packet.data.stream()
+ .sorted()
+ .collect(
+ HashSet<PacketData<MultiTileEntityProcess>>::new,
+ HashSet<PacketData<MultiTileEntityProcess>>::add,
+ HashSet<PacketData<MultiTileEntityProcess>>::addAll);
+ packet.clearData();
+ packet.data.addAll(set);
+ for (PacketData<MultiTileEntityProcess> data : packet.data) {
+ data.decode(in);
+ }
+ /*
+ * if ((packetFeatures & COVERS) == COVERS) {
+ * packet.setCoverData(
+ * in.readInt(),
+ * in.readInt(),
+ * in.readInt(),
+ * in.readInt(),
+ * in.readInt(),
+ * in.readInt());
+ * }
+ * if ((packetFeatures & INVENTORY_INDEX) == INVENTORY_INDEX) {
+ * packet.setInventoryIndex(aData.readInt());
+ * }
+ * if ((packetFeatures & INVENTORY_NAME_ID) == INVENTORY_NAME_ID) {
+ * int nameLength = aData.readInt();
+ * String inventoryName;
+ * if (nameLength > 0) {
+ * byte[] bytes = new byte[nameLength];
+ * for (int i = 0; i < nameLength; i++) {
+ * bytes[i] = aData.readByte();
+ * }
+ * inventoryName = new String(bytes);
+ * } else {
+ * inventoryName = null;
+ * }
+ * int idLength = aData.readInt();
+ * String inventoryID;
+ * if (idLength > 0) {
+ * byte[] bytes = new byte[idLength];
+ * for (int i = 0; i < idLength; i++) {
+ * bytes[i] = aData.readByte();
+ * }
+ * inventoryID = new String(bytes);
+ * } else {
+ * inventoryID = null;
+ * }
+ * packet.setInventoryName(inventoryName, inventoryID);
+ * }
+ * if ((packetFeatures & BOOLEANS) == BOOLEANS) {
+ * packet.setBooleans(aData.readInt());
+ * }
+ * if ((packetFeatures & SOUND) == SOUND) {
+ * packet.setSoundEvent(aData.readByte(), aData.readInt());
+ * }
+ */
+ return packet;
+ }
+
+ @Override
+ public void process(IBlockAccess aWorld) {
+ if (aWorld == null) return;
+ MultiTileEntityProcess process = new MultiTileEntityProcess(aWorld);
+ for (PacketData<MultiTileEntityProcess> data : data) {
+ data.process(process);
+ }
+ process.process();
+ /*
+ * final TileEntity tTileEntity = aWorld.getTileEntity(mX, mY, mZ);
+ * try {
+ * final Block tBlock = aWorld.getBlock(mX, mY, mZ);
+ * if (tBlock instanceof MultiTileEntityBlock mteBlock) {
+ * final IMultiTileEntity mte = mteBlock.receiveMultiTileEntityData(aWorld, mX, mY, mZ, mRID, mID);
+ * if (mte == null) return;
+ * mte.receiveClientData(GregTechTileClientEvents.CHANGE_COMMON_DATA, mCommonData);
+ * mte.receiveClientData(GregTechTileClientEvents.CHANGE_COLOR, mColor);
+ * if ((features & COVERS) == COVERS) {
+ * mteBlock.receiveCoverData(mte, mC0, mC1, mC2, mC3, mC4, mC5);
+ * }
+ * if ((features & REDSTONE) == REDSTONE) {
+ * mte.receiveClientData(GregTechTileClientEvents.CHANGE_REDSTONE_OUTPUT, mRedstone);
+ * }
+ * if ((features & MODES) == MODES && mte instanceof IMultiTileEntity.IMTE_HasModes mteModes) {
+ * mteModes.setMode(mode);
+ * mteModes.setAllowedModes(allowedModes);
+ * }
+ * if ((features & INVENTORY_NAME_ID) == INVENTORY_NAME_ID && mte instanceof Inventory invUpg) {
+ * invUpg.setInventoryName(mInventoryName);
+ * invUpg.setInventoryId(inventoryID);
+ * }
+ * if ((features & CONTROLLER) == CONTROLLER && mte instanceof IMultiBlockPart) {
+ * final IMultiBlockPart mtePart = (IMultiBlockPart) mte;
+ * mtePart.setTargetPos(mTargetPos);
+ * }
+ * if ((features & INVENTORY_INDEX) == INVENTORY_INDEX && mte instanceof IMultiBlockPart) {
+ * final IMultiBlockPart mtePart = (IMultiBlockPart) mte;
+ * mtePart.setLockedInventoryIndex(mLockedInventoryIndex);
+ * }
+ * if ((features & BOOLEANS) == BOOLEANS && mte instanceof IMultiTileMachine) {
+ * final IMultiTileMachine machine = (IMultiTileMachine) mte;
+ * machine.setBooleans(booleans);
+ * }
+ * if ((features & SOUND) == SOUND && mte instanceof IMultiTileMachine) {
+ * final IMultiTileMachine machine = (IMultiTileMachine) mte;
+ * machine.setSound(soundEvent, soundEventValue);
+ * }
+ * }
+ * } catch (Exception e) {
+ * e.printStackTrace();
+ * GT_Mod.GT_FML_LOGGER.error(
+ * "Exception setting tile entity data for tile entity {} at ({}, {}, {})",
+ * tTileEntity,
+ * mX,
+ * mY,
+ * mZ);
+ * }
+ */
+ }
+
+ @Override
+ public byte getPacketID() {
+ return 18;
+ }
+
+ public void clearData() {
+ data.clear();
+ }
+
+ public void addData(PacketData<MultiTileEntityProcess> data) {
+ this.data.add(data);
+ }
+
+ private static boolean containsBit(int toCheck, int bit) {
+ return (toCheck & (1 << bit)) > 0;
+ }
+}
diff --git a/src/main/java/gregtech/api/net/GT_Packet_New.java b/src/main/java/gregtech/api/net/GT_Packet_New.java
new file mode 100644
index 0000000000..41eb1740b3
--- /dev/null
+++ b/src/main/java/gregtech/api/net/GT_Packet_New.java
@@ -0,0 +1,30 @@
+package gregtech.api.net;
+
+import com.google.common.io.ByteArrayDataInput;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+
+@SuppressWarnings("deprecation")
+public abstract class GT_Packet_New extends GT_Packet {
+
+ public GT_Packet_New(boolean aIsReference) {
+ super(aIsReference);
+ }
+
+ @Override
+ @Deprecated
+ public final byte[] encode() {
+ final ByteBuf tOut = Unpooled.buffer();
+ encode(tOut);
+ final byte[] bytes = new byte[tOut.readableBytes()];
+ tOut.readBytes(bytes);
+ return bytes;
+ }
+
+ @Override
+ public abstract void encode(ByteBuf aOut);
+
+ @Override
+ public abstract GT_Packet_New decode(ByteArrayDataInput aData);
+}
diff --git a/src/main/java/gregtech/api/net/GT_Packet_Pollution.java b/src/main/java/gregtech/api/net/GT_Packet_Pollution.java
new file mode 100644
index 0000000000..c298af2db4
--- /dev/null
+++ b/src/main/java/gregtech/api/net/GT_Packet_Pollution.java
@@ -0,0 +1,47 @@
+package gregtech.api.net;
+
+import net.minecraft.world.ChunkCoordIntPair;
+import net.minecraft.world.IBlockAccess;
+
+import com.google.common.io.ByteArrayDataInput;
+
+import gregtech.common.GT_Client;
+import io.netty.buffer.ByteBuf;
+
+public class GT_Packet_Pollution extends GT_Packet_New {
+
+ private ChunkCoordIntPair chunk;
+ private int pollution;
+
+ public GT_Packet_Pollution() {
+ super(true);
+ }
+
+ public GT_Packet_Pollution(ChunkCoordIntPair chunk, int pollution) {
+ super(false);
+ this.chunk = chunk;
+ this.pollution = pollution;
+ }
+
+ @Override
+ public void encode(ByteBuf aOut) {
+ aOut.writeInt(chunk.chunkXPos)
+ .writeInt(chunk.chunkZPos)
+ .writeInt(pollution);
+ }
+
+ @Override
+ public GT_Packet_New decode(ByteArrayDataInput aData) {
+ return new GT_Packet_Pollution(new ChunkCoordIntPair(aData.readInt(), aData.readInt()), aData.readInt());
+ }
+
+ @Override
+ public void process(IBlockAccess aWorld) {
+ GT_Client.recieveChunkPollutionPacket(chunk, pollution);
+ }
+
+ @Override
+ public byte getPacketID() {
+ return 4;
+ }
+}
diff --git a/src/main/java/gregtech/api/net/GT_Packet_RequestCoverData.java b/src/main/java/gregtech/api/net/GT_Packet_RequestCoverData.java
new file mode 100644
index 0000000000..94ae86c2d9
--- /dev/null
+++ b/src/main/java/gregtech/api/net/GT_Packet_RequestCoverData.java
@@ -0,0 +1,113 @@
+package gregtech.api.net;
+
+import net.minecraft.entity.player.EntityPlayerMP;
+import net.minecraft.network.INetHandler;
+import net.minecraft.network.NetHandlerPlayServer;
+import net.minecraft.tileentity.TileEntity;
+import net.minecraft.world.IBlockAccess;
+import net.minecraft.world.World;
+import net.minecraftforge.common.DimensionManager;
+import net.minecraftforge.common.util.ForgeDirection;
+
+import com.google.common.io.ByteArrayDataInput;
+
+import gregtech.api.interfaces.tileentity.ICoverable;
+import gregtech.api.metatileentity.CoverableTileEntity;
+import gregtech.common.covers.CoverInfo;
+import io.netty.buffer.ByteBuf;
+
+/**
+ * Client -> Server : ask for cover data
+ */
+public class GT_Packet_RequestCoverData extends GT_Packet_New {
+
+ protected int mX;
+ protected short mY;
+ protected int mZ;
+
+ protected ForgeDirection side;
+ protected int coverID;
+
+ protected EntityPlayerMP mPlayer;
+
+ public GT_Packet_RequestCoverData() {
+ super(true);
+ }
+
+ public GT_Packet_RequestCoverData(CoverInfo info, ICoverable tile) {
+ super(false);
+ this.mX = tile.getXCoord();
+ this.mY = tile.getYCoord();
+ this.mZ = tile.getZCoord();
+
+ this.side = info.getSide();
+ this.coverID = info.getCoverID();
+ }
+
+ public GT_Packet_RequestCoverData(int mX, short mY, int mZ, ForgeDirection coverSide, int coverID) {
+ super(false);
+ this.mX = mX;
+ this.mY = mY;
+ this.mZ = mZ;
+
+ this.side = coverSide;
+ this.coverID = coverID;
+ }
+
+ public GT_Packet_RequestCoverData(ForgeDirection coverSide, int coverID, ICoverable tile) {
+ super(false);
+ this.mX = tile.getXCoord();
+ this.mY = tile.getYCoord();
+ this.mZ = tile.getZCoord();
+
+ this.side = coverSide;
+ this.coverID = coverID;
+ }
+
+ @Override
+ public byte getPacketID() {
+ return 17;
+ }
+
+ @Override
+ public void encode(ByteBuf aOut) {
+ aOut.writeInt(mX);
+ aOut.writeShort(mY);
+ aOut.writeInt(mZ);
+
+ aOut.writeByte(side.ordinal());
+ aOut.writeInt(coverID);
+ }
+
+ @Override
+ public GT_Packet_New decode(ByteArrayDataInput aData) {
+ return new GT_Packet_RequestCoverData(
+ aData.readInt(),
+ aData.readShort(),
+ aData.readInt(),
+ ForgeDirection.getOrientation(aData.readByte()),
+ aData.readInt());
+ }
+
+ @Override
+ public void setINetHandler(INetHandler aHandler) {
+ if (aHandler instanceof NetHandlerPlayServer) {
+ mPlayer = ((NetHandlerPlayServer) aHandler).playerEntity;
+ }
+ }
+
+ @Override
+ public void process(IBlockAccess aWorld) {
+ // impossible, but who knows
+ if (mPlayer == null) return;
+ final World world = DimensionManager.getWorld(mPlayer.dimension);
+ if (world != null) {
+ final TileEntity tile = world.getTileEntity(mX, mY, mZ);
+ if (tile instanceof CoverableTileEntity te) {
+ if (!te.isDead() && te.getCoverIDAtSide(side) == coverID) {
+ te.issueCoverUpdate(side);
+ }
+ }
+ }
+ }
+}
diff --git a/src/main/java/gregtech/api/net/GT_Packet_SendCoverData.java b/src/main/java/gregtech/api/net/GT_Packet_SendCoverData.java
new file mode 100644
index 0000000000..47f549b5b4
--- /dev/null
+++ b/src/main/java/gregtech/api/net/GT_Packet_SendCoverData.java
@@ -0,0 +1,107 @@
+package gregtech.api.net;
+
+import net.minecraft.tileentity.TileEntity;
+import net.minecraft.world.IBlockAccess;
+import net.minecraftforge.common.util.ForgeDirection;
+
+import com.google.common.io.ByteArrayDataInput;
+
+import gregtech.api.GregTech_API;
+import gregtech.api.interfaces.tileentity.ICoverable;
+import gregtech.api.metatileentity.CoverableTileEntity;
+import gregtech.api.util.ISerializableObject;
+import gregtech.common.covers.CoverInfo;
+import io.netty.buffer.ByteBuf;
+
+/**
+ * Server -> Client : Update cover data
+ */
+public class GT_Packet_SendCoverData extends GT_Packet_New {
+
+ protected int mX;
+ protected short mY;
+ protected int mZ;
+
+ protected ForgeDirection side;
+ protected int coverID;
+ protected ISerializableObject coverData;
+
+ public GT_Packet_SendCoverData() {
+ super(true);
+ }
+
+ public GT_Packet_SendCoverData(int mX, short mY, int mZ, ForgeDirection coverSide, int coverID,
+ ISerializableObject coverData) {
+ super(false);
+ this.mX = mX;
+ this.mY = mY;
+ this.mZ = mZ;
+
+ this.side = coverSide;
+ this.coverID = coverID;
+ this.coverData = coverData;
+ }
+
+ public GT_Packet_SendCoverData(CoverInfo info, ICoverable tile) {
+ super(false);
+ this.mX = tile.getXCoord();
+ this.mY = tile.getYCoord();
+ this.mZ = tile.getZCoord();
+
+ this.side = info.getSide();
+ this.coverID = info.getCoverID();
+ this.coverData = info.getCoverData();
+ }
+
+ public GT_Packet_SendCoverData(ForgeDirection coverSide, int coverID, ISerializableObject coverData,
+ ICoverable tile) {
+ super(false);
+ this.mX = tile.getXCoord();
+ this.mY = tile.getYCoord();
+ this.mZ = tile.getZCoord();
+
+ this.side = coverSide;
+ this.coverID = coverID;
+ this.coverData = coverData;
+ }
+
+ @Override
+ public byte getPacketID() {
+ return 16;
+ }
+
+ @Override
+ public void encode(ByteBuf aOut) {
+ aOut.writeInt(mX);
+ aOut.writeShort(mY);
+ aOut.writeInt(mZ);
+
+ aOut.writeByte(side.ordinal());
+ aOut.writeInt(coverID);
+ coverData.writeToByteBuf(aOut);
+ }
+
+ @Override
+ public GT_Packet_New decode(ByteArrayDataInput aData) {
+ final int coverId;
+ return new GT_Packet_SendCoverData(
+ aData.readInt(),
+ aData.readShort(),
+ aData.readInt(),
+ ForgeDirection.getOrientation(aData.readByte()),
+ coverId = aData.readInt(),
+ GregTech_API.getCoverBehaviorNew(coverId)
+ .createDataObject()
+ .readFromPacket(aData, null));
+ }
+
+ @Override
+ public void process(IBlockAccess aWorld) {
+ if (aWorld != null) {
+ final TileEntity tile = aWorld.getTileEntity(mX, mY, mZ);
+ if (tile instanceof CoverableTileEntity coverable && !coverable.isDead()) {
+ coverable.receiveCoverData(side, coverID, coverData, null);
+ }
+ }
+ }
+}
diff --git a/src/main/java/gregtech/api/net/GT_Packet_SendOregenPattern.java b/src/main/java/gregtech/api/net/GT_Packet_SendOregenPattern.java
new file mode 100644
index 0000000000..d03fd1d7f0
--- /dev/null
+++ b/src/main/java/gregtech/api/net/GT_Packet_SendOregenPattern.java
@@ -0,0 +1,56 @@
+package gregtech.api.net;
+
+import net.minecraft.world.IBlockAccess;
+
+import com.google.common.io.ByteArrayDataInput;
+
+import gregtech.api.util.GT_Log;
+import gregtech.common.GT_Worldgenerator;
+import gregtech.common.GT_Worldgenerator.OregenPattern;
+import io.netty.buffer.ByteBuf;
+
+public class GT_Packet_SendOregenPattern extends GT_Packet_New {
+
+ protected OregenPattern pattern = OregenPattern.AXISSYMMETRICAL;
+
+ public GT_Packet_SendOregenPattern() {
+ super(true);
+ }
+
+ public GT_Packet_SendOregenPattern(OregenPattern pattern) {
+ super(false);
+ this.pattern = pattern;
+ }
+
+ @Override
+ public void encode(ByteBuf aOut) {
+ aOut.writeInt(this.pattern.ordinal());
+ }
+
+ @Override
+ public GT_Packet_New decode(ByteArrayDataInput aData) {
+ int ordinal = aData.readInt();
+ // make sure we get valid data:
+ if (ordinal >= 0 && ordinal < OregenPattern.values().length) {
+ return new GT_Packet_SendOregenPattern(OregenPattern.values()[ordinal]);
+ }
+ // invalid data, default to AXISSYMMETRICAL:
+ GT_Log.err.println(
+ String.format(
+ "Received invalid data! Received %d but value must be between 0 and %d! Default (0) will be used.",
+ ordinal,
+ OregenPattern.values().length - 1));
+ return new GT_Packet_SendOregenPattern();
+ }
+
+ @Override
+ public byte getPacketID() {
+ return 19;
+ }
+
+ @Override
+ public void process(IBlockAccess aWorld) {
+ GT_Worldgenerator.oregenPattern = this.pattern;
+ }
+
+}
diff --git a/src/main/java/gregtech/api/net/GT_Packet_SetConfigurationCircuit.java b/src/main/java/gregtech/api/net/GT_Packet_SetConfigurationCircuit.java
new file mode 100644
index 0000000000..b2d9a59438
--- /dev/null
+++ b/src/main/java/gregtech/api/net/GT_Packet_SetConfigurationCircuit.java
@@ -0,0 +1,110 @@
+package gregtech.api.net;
+
+import net.minecraft.item.ItemStack;
+import net.minecraft.network.INetHandler;
+import net.minecraft.network.NetHandlerPlayServer;
+import net.minecraft.tileentity.TileEntity;
+import net.minecraft.world.IBlockAccess;
+import net.minecraft.world.World;
+import net.minecraftforge.common.DimensionManager;
+
+import com.google.common.io.ByteArrayDataInput;
+
+import cpw.mods.fml.common.network.ByteBufUtils;
+import gregtech.api.interfaces.IConfigurationCircuitSupport;
+import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
+import gregtech.api.interfaces.tileentity.IHasInventory;
+import gregtech.api.metatileentity.BaseTileEntity;
+import gregtech.api.util.GT_Utility;
+import gregtech.api.util.ISerializableObject;
+import io.netty.buffer.ByteBuf;
+
+/**
+ * Client -> Server: Update machine configuration data
+ */
+public class GT_Packet_SetConfigurationCircuit extends GT_Packet_New {
+
+ protected int mX;
+ protected short mY;
+ protected int mZ;
+ protected int dimId;
+
+ protected ItemStack circuit;
+
+ public GT_Packet_SetConfigurationCircuit() {
+ super(true);
+ }
+
+ public GT_Packet_SetConfigurationCircuit(IGregTechTileEntity tile, ItemStack circuit) {
+ this(tile.getXCoord(), tile.getYCoord(), tile.getZCoord(), circuit);
+ }
+
+ public GT_Packet_SetConfigurationCircuit(BaseTileEntity tile, ItemStack circuit) {
+ this(tile.getXCoord(), tile.getYCoord(), tile.getZCoord(), circuit);
+ }
+
+ public GT_Packet_SetConfigurationCircuit(int x, short y, int z, ItemStack circuit) {
+ super(false);
+
+ this.mX = x;
+ this.mY = y;
+ this.mZ = z;
+
+ this.circuit = circuit;
+ }
+
+ @Override
+ public byte getPacketID() {
+ return 12;
+ }
+
+ @Override
+ public void encode(ByteBuf aOut) {
+ aOut.writeInt(mX);
+ aOut.writeShort(mY);
+ aOut.writeInt(mZ);
+
+ // no null check needed. ByteBufUtils will handle it
+ ByteBufUtils.writeItemStack(aOut, this.circuit);
+ }
+
+ @Override
+ public void setINetHandler(INetHandler aHandler) {
+ if (aHandler instanceof NetHandlerPlayServer) {
+ dimId = ((NetHandlerPlayServer) aHandler).playerEntity.dimension;
+ } else {
+ // packet sent to wrong side, so we need to ignore this one
+ // but there is no way to disrupt packet pipeline
+ // so we will instead go find world -2, which (hopefully) doesn't exist
+ // then we will fail silently in process()
+ dimId = -2;
+ }
+ }
+
+ @Override
+ public GT_Packet_New decode(ByteArrayDataInput aData) {
+ return new GT_Packet_SetConfigurationCircuit(
+ aData.readInt(),
+ aData.readShort(),
+ aData.readInt(),
+ ISerializableObject.readItemStackFromGreggyByteBuf(aData));
+ }
+
+ @Override
+ public void process(IBlockAccess aWorld) {
+ final World world = DimensionManager.getWorld(dimId);
+ if (world == null) return;
+
+ final TileEntity tile = world.getTileEntity(mX, mY, mZ);
+ if (!(tile instanceof BaseTileEntity) || ((BaseTileEntity) tile).isDead()) return;
+
+ final IConfigurationCircuitSupport machine = ((BaseTileEntity) tile).getConfigurationCircuitSupport();
+ if (machine == null) return;
+ if (!machine.allowSelectCircuit()) return;
+ machine.getConfigurationCircuits()
+ .stream()
+ .filter(stack -> GT_Utility.areStacksEqual(stack, circuit))
+ .findFirst()
+ .ifPresent(stack -> ((IHasInventory) tile).setInventorySlotContents(machine.getCircuitSlot(), stack));
+ }
+}
diff --git a/src/main/java/gregtech/api/net/GT_Packet_Sound.java b/src/main/java/gregtech/api/net/GT_Packet_Sound.java
new file mode 100644
index 0000000000..fdaf5b3979
--- /dev/null
+++ b/src/main/java/gregtech/api/net/GT_Packet_Sound.java
@@ -0,0 +1,70 @@
+package gregtech.api.net;
+
+import java.io.IOException;
+
+import net.minecraft.world.IBlockAccess;
+
+import com.google.common.io.ByteArrayDataInput;
+
+import gregtech.api.util.GT_Log;
+import gregtech.api.util.GT_Utility;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.ByteBufOutputStream;
+
+public class GT_Packet_Sound extends GT_Packet_New {
+
+ private int mX, mZ;
+ private short mY;
+ private String mSoundName;
+ private float mSoundStrength, mSoundPitch;
+
+ public GT_Packet_Sound() {
+ super(true);
+ }
+
+ public GT_Packet_Sound(String aSoundName, float aSoundStrength, float aSoundPitch, int aX, short aY, int aZ) {
+ super(false);
+ mX = aX;
+ mY = aY;
+ mZ = aZ;
+ mSoundName = aSoundName;
+ mSoundStrength = aSoundStrength;
+ mSoundPitch = aSoundPitch;
+ }
+
+ @Override
+ public void encode(ByteBuf aOut) {
+ try (ByteBufOutputStream byteOutputStream = new ByteBufOutputStream(aOut)) {
+ byteOutputStream.writeUTF(mSoundName);
+ byteOutputStream.writeFloat(mSoundStrength);
+ byteOutputStream.writeFloat(mSoundPitch);
+ byteOutputStream.writeInt(mX);
+ byteOutputStream.writeShort(mY);
+ byteOutputStream.writeInt(mZ);
+ } catch (IOException e) {
+ // this really shouldn't happen, but whatever
+ e.printStackTrace(GT_Log.err);
+ }
+ }
+
+ @Override
+ public GT_Packet_New decode(ByteArrayDataInput aData) {
+ return new GT_Packet_Sound(
+ aData.readUTF(),
+ aData.readFloat(),
+ aData.readFloat(),
+ aData.readInt(),
+ aData.readShort(),
+ aData.readInt());
+ }
+
+ @Override
+ public void process(IBlockAccess aWorld) {
+ GT_Utility.doSoundAtClient(mSoundName, 1, mSoundStrength, mSoundPitch, mX, mY, mZ);
+ }
+
+ @Override
+ public byte getPacketID() {
+ return 1;
+ }
+}
diff --git a/src/main/java/gregtech/api/net/GT_Packet_TileEntity.java b/src/main/java/gregtech/api/net/GT_Packet_TileEntity.java
new file mode 100644
index 0000000000..29562e9b4d
--- /dev/null
+++ b/src/main/java/gregtech/api/net/GT_Packet_TileEntity.java
@@ -0,0 +1,157 @@
+package gregtech.api.net;
+
+import net.minecraft.block.Block;
+import net.minecraft.tileentity.TileEntity;
+import net.minecraft.world.IBlockAccess;
+
+import com.google.common.io.ByteArrayDataInput;
+
+import gregtech.GT_Mod;
+import gregtech.api.metatileentity.BaseMetaPipeEntity;
+import gregtech.api.metatileentity.BaseMetaTileEntity;
+import io.netty.buffer.ByteBuf;
+
+public class GT_Packet_TileEntity extends GT_Packet_New {
+
+ private int mX, mZ, mC0, mC1, mC2, mC3, mC4, mC5;
+ private short mY, mID, mRID;
+ private byte mTexture, mTexturePage, mUpdate, mRedstone, mColor;
+
+ public GT_Packet_TileEntity() {
+ super(true);
+ }
+
+ // For multi tiles
+ public GT_Packet_TileEntity(int aX, short aY, int aZ, short aRID, short aID, int aC0, int aC1, int aC2, int aC3,
+ int aC4, int aC5, byte aTexture, byte aTexturePage, byte aUpdate, byte aRedstone, byte aColor) {
+ super(false);
+ mX = aX;
+ mY = aY;
+ mZ = aZ;
+ mC0 = aC0;
+ mC1 = aC1;
+ mC2 = aC2;
+ mC3 = aC3;
+ mC4 = aC4;
+ mC5 = aC5;
+ mRID = aRID;
+ mID = aID;
+ mTexture = aTexture;
+ mTexturePage = aTexturePage;
+ mUpdate = aUpdate;
+ mRedstone = aRedstone;
+ mColor = aColor;
+ }
+
+ // For meta tiles
+ public GT_Packet_TileEntity(int aX, short aY, int aZ, short aID, int aC0, int aC1, int aC2, int aC3, int aC4,
+ int aC5, byte aTexture, byte aTexturePage, byte aUpdate, byte aRedstone, byte aColor) {
+ this(
+ aX,
+ aY,
+ aZ,
+ (short) 0,
+ aID,
+ aC0,
+ aC1,
+ aC2,
+ aC3,
+ aC4,
+ aC5,
+ aTexture,
+ aTexturePage,
+ aUpdate,
+ aRedstone,
+ aColor);
+ }
+
+ // For pipes
+ public GT_Packet_TileEntity(int aX, short aY, int aZ, short aID, int aC0, int aC1, int aC2, int aC3, int aC4,
+ int aC5, byte aTexture, byte aUpdate, byte aRedstone, byte aColor) {
+ this(aX, aY, aZ, (short) 0, aID, aC0, aC1, aC2, aC3, aC4, aC5, aTexture, (byte) 0, aUpdate, aRedstone, aColor);
+ }
+
+ @Override
+ public void encode(ByteBuf aOut) {
+ aOut.writeInt(mX);
+ aOut.writeShort(mY);
+ aOut.writeInt(mZ);
+
+ aOut.writeShort(mRID);
+ aOut.writeShort(mID);
+
+ aOut.writeInt(mC0);
+ aOut.writeInt(mC1);
+ aOut.writeInt(mC2);
+ aOut.writeInt(mC3);
+ aOut.writeInt(mC4);
+ aOut.writeInt(mC5);
+
+ aOut.writeByte(mTexture);
+ aOut.writeByte(mTexturePage);
+ aOut.writeByte(mUpdate);
+ aOut.writeByte(mRedstone);
+ aOut.writeByte(mColor);
+ }
+
+ @Override
+ public GT_Packet_New decode(ByteArrayDataInput aData) {
+ return new GT_Packet_TileEntity(
+ // Coords
+ aData.readInt(),
+ aData.readShort(),
+ aData.readInt(),
+ // Registry & ID
+ aData.readShort(),
+ aData.readShort(),
+ // Covers
+ aData.readInt(),
+ aData.readInt(),
+ aData.readInt(),
+ aData.readInt(),
+ aData.readInt(),
+ aData.readInt(),
+ // Everything else
+ aData.readByte(),
+ aData.readByte(),
+ aData.readByte(),
+ aData.readByte(),
+ aData.readByte());
+ }
+
+ @Override
+ public void process(IBlockAccess aWorld) {
+ if (aWorld == null) return;
+ final TileEntity tTileEntity = aWorld.getTileEntity(mX, mY, mZ);
+ try {
+ final Block tBlock;
+ if (tTileEntity instanceof BaseMetaTileEntity) ((BaseMetaTileEntity) tTileEntity).receiveMetaTileEntityData(
+ mID,
+ mC0,
+ mC1,
+ mC2,
+ mC3,
+ mC4,
+ mC5,
+ mTexture,
+ mTexturePage,
+ mUpdate,
+ mRedstone,
+ mColor);
+ else if (tTileEntity instanceof BaseMetaPipeEntity) ((BaseMetaPipeEntity) tTileEntity)
+ .receiveMetaTileEntityData(mID, mC0, mC1, mC2, mC3, mC4, mC5, mTexture, mUpdate, mRedstone, mColor);
+ } catch (Exception e) {
+ GT_Mod.GT_FML_LOGGER.error(
+ "Exception setting tile entity data for tile entity {} at ({}, {}, {})",
+ tTileEntity,
+ mX,
+ mY,
+ mZ);
+ }
+ }
+
+ @Override
+ public byte getPacketID() {
+ return 0;
+ }
+}
diff --git a/src/main/java/gregtech/api/net/GT_Packet_TileEntityCover.java b/src/main/java/gregtech/api/net/GT_Packet_TileEntityCover.java
new file mode 100644
index 0000000000..d3642b62e8
--- /dev/null
+++ b/src/main/java/gregtech/api/net/GT_Packet_TileEntityCover.java
@@ -0,0 +1,98 @@
+package gregtech.api.net;
+
+import net.minecraft.tileentity.TileEntity;
+import net.minecraft.world.IBlockAccess;
+import net.minecraft.world.World;
+import net.minecraftforge.common.DimensionManager;
+import net.minecraftforge.common.util.ForgeDirection;
+
+import com.google.common.io.ByteArrayDataInput;
+
+import gregtech.api.interfaces.tileentity.ICoverable;
+import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
+import io.netty.buffer.ByteBuf;
+
+/**
+ * Client -> Server: Update cover data. use this only if you are using the legacy data storage
+ */
+public class GT_Packet_TileEntityCover extends GT_Packet_New {
+
+ protected int mX;
+ protected short mY;
+ protected int mZ;
+
+ protected ForgeDirection side;
+ protected int coverID, coverData, dimID;
+
+ public GT_Packet_TileEntityCover() {
+ super(true);
+ }
+
+ public GT_Packet_TileEntityCover(int mX, short mY, int mZ, ForgeDirection coverSide, int coverID, int coverData,
+ int dimID) {
+ super(false);
+ this.mX = mX;
+ this.mY = mY;
+ this.mZ = mZ;
+
+ this.side = coverSide;
+ this.coverID = coverID;
+ this.coverData = coverData;
+
+ this.dimID = dimID;
+ }
+
+ public GT_Packet_TileEntityCover(ForgeDirection coverSide, int coverID, int coverData, ICoverable tile) {
+ super(false);
+ this.mX = tile.getXCoord();
+ this.mY = tile.getYCoord();
+ this.mZ = tile.getZCoord();
+
+ this.side = coverSide;
+ this.coverID = coverID;
+ this.coverData = coverData;
+
+ this.dimID = tile.getWorld().provider.dimensionId;
+ }
+
+ @Override
+ public byte getPacketID() {
+ return 6;
+ }
+
+ @Override
+ public void encode(ByteBuf aOut) {
+ aOut.writeInt(mX);
+ aOut.writeShort(mY);
+ aOut.writeInt(mZ);
+
+ aOut.writeByte(side.ordinal());
+ aOut.writeInt(coverID);
+ aOut.writeInt(coverData);
+
+ aOut.writeInt(dimID);
+ }
+
+ @Override
+ public GT_Packet_New decode(ByteArrayDataInput aData) {
+ return new GT_Packet_TileEntityCover(
+ aData.readInt(),
+ aData.readShort(),
+ aData.readInt(),
+ ForgeDirection.getOrientation(aData.readByte()),
+ aData.readInt(),
+ aData.readInt(),
+ aData.readInt());
+ }
+
+ @Override
+ public void process(IBlockAccess aWorld) {
+ World world = DimensionManager.getWorld(dimID);
+ if (world != null) {
+ TileEntity tile = world.getTileEntity(mX, mY, mZ);
+ if (tile instanceof IGregTechTileEntity && !((IGregTechTileEntity) tile).isDead()) {
+ ((IGregTechTileEntity) tile).receiveCoverData(side, coverID, coverData);
+ }
+ }
+ }
+}
diff --git a/src/main/java/gregtech/api/net/GT_Packet_TileEntityCoverGUI.java b/src/main/java/gregtech/api/net/GT_Packet_TileEntityCoverGUI.java
new file mode 100644
index 0000000000..1b61f87541
--- /dev/null
+++ b/src/main/java/gregtech/api/net/GT_Packet_TileEntityCoverGUI.java
@@ -0,0 +1,219 @@
+package gregtech.api.net;
+
+import net.minecraft.client.Minecraft;
+import net.minecraft.client.gui.GuiScreen;
+import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.entity.player.EntityPlayerMP;
+import net.minecraft.tileentity.TileEntity;
+import net.minecraft.world.IBlockAccess;
+import net.minecraft.world.World;
+import net.minecraftforge.common.util.ForgeDirection;
+
+import com.google.common.io.ByteArrayDataInput;
+
+import gregtech.api.GregTech_API;
+import gregtech.api.gui.GT_GUICover;
+import gregtech.api.interfaces.tileentity.ICoverable;
+import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
+import gregtech.api.util.GT_CoverBehaviorBase;
+import gregtech.api.util.ISerializableObject;
+import gregtech.common.covers.CoverInfo;
+import io.netty.buffer.ByteBuf;
+
+/**
+ * Server -> Client: Show GUI
+ */
+public class GT_Packet_TileEntityCoverGUI extends GT_Packet_New {
+
+ protected int mX;
+ protected short mY;
+ protected int mZ;
+
+ protected ForgeDirection side;
+ protected int coverID, dimID, playerID;
+ protected ISerializableObject coverData;
+
+ protected int parentGuiId;
+
+ public GT_Packet_TileEntityCoverGUI() {
+ super(true);
+ }
+
+ public GT_Packet_TileEntityCoverGUI(int mX, short mY, int mZ, ForgeDirection coverSide, int coverID, int coverData,
+ int dimID, int playerID) {
+ super(false);
+ this.mX = mX;
+ this.mY = mY;
+ this.mZ = mZ;
+
+ this.side = coverSide;
+ this.coverID = coverID;
+ this.coverData = new ISerializableObject.LegacyCoverData(coverData);
+
+ this.dimID = dimID;
+ this.playerID = playerID;
+ this.parentGuiId = -1;
+ }
+
+ public GT_Packet_TileEntityCoverGUI(int mX, short mY, int mZ, ForgeDirection coverSide, int coverID,
+ ISerializableObject coverData, int dimID, int playerID) {
+ super(false);
+ this.mX = mX;
+ this.mY = mY;
+ this.mZ = mZ;
+
+ this.side = coverSide;
+ this.coverID = coverID;
+ this.coverData = coverData;
+ this.dimID = dimID;
+ this.playerID = playerID;
+ this.parentGuiId = -1;
+ }
+
+ public GT_Packet_TileEntityCoverGUI(CoverInfo coverInfo, int dimID, int playerID, int parentGuiId) {
+ super(false);
+ final ICoverable tile = coverInfo.getTile();
+ this.mX = tile.getXCoord();
+ this.mY = tile.getYCoord();
+ this.mZ = tile.getZCoord();
+
+ this.side = coverInfo.getSide();
+ this.coverID = coverInfo.getCoverID();
+ this.coverData = coverInfo.getCoverData();
+
+ this.dimID = dimID;
+ this.playerID = playerID;
+ this.parentGuiId = parentGuiId;
+ }
+
+ public GT_Packet_TileEntityCoverGUI(int mX, short mY, int mZ, ForgeDirection coverSide, int coverID,
+ ISerializableObject coverData, int dimID, int playerID, int parentGuiId) {
+ super(false);
+ this.mX = mX;
+ this.mY = mY;
+ this.mZ = mZ;
+
+ this.side = coverSide;
+ this.coverID = coverID;
+ this.coverData = coverData;
+ this.dimID = dimID;
+ this.playerID = playerID;
+ this.parentGuiId = parentGuiId;
+ }
+
+ public GT_Packet_TileEntityCoverGUI(ForgeDirection side, int coverID, int coverData, ICoverable tile,
+ EntityPlayerMP aPlayer) {
+ super(false);
+
+ this.mX = tile.getXCoord();
+ this.mY = tile.getYCoord();
+ this.mZ = tile.getZCoord();
+
+ this.side = side;
+ this.coverID = coverID;
+ this.coverData = new ISerializableObject.LegacyCoverData(coverData);
+
+ this.dimID = tile.getWorld().provider.dimensionId;
+ this.playerID = aPlayer.getEntityId();
+ this.parentGuiId = -1;
+ }
+
+ public GT_Packet_TileEntityCoverGUI(ForgeDirection coverSide, int coverID, int coverData,
+ IGregTechTileEntity tile) {
+ super(false);
+ this.mX = tile.getXCoord();
+ this.mY = tile.getYCoord();
+ this.mZ = tile.getZCoord();
+
+ this.side = coverSide;
+ this.coverID = coverID;
+ this.coverData = new ISerializableObject.LegacyCoverData(coverData);
+
+ this.dimID = tile.getWorld().provider.dimensionId;
+ this.parentGuiId = -1;
+ }
+
+ public GT_Packet_TileEntityCoverGUI(ForgeDirection side, int coverID, ISerializableObject coverData,
+ ICoverable tile, EntityPlayerMP aPlayer) {
+ super(false);
+ this.mX = tile.getXCoord();
+ this.mY = tile.getYCoord();
+ this.mZ = tile.getZCoord();
+
+ this.side = side;
+ this.coverID = coverID;
+ this.coverData = coverData.copy(); // make a copy so we don't get a race condition
+
+ this.dimID = tile.getWorld().provider.dimensionId;
+ this.playerID = aPlayer.getEntityId();
+ this.parentGuiId = -1;
+ }
+
+ @Override
+ public byte getPacketID() {
+ return 7;
+ }
+
+ @Override
+ public void encode(ByteBuf aOut) {
+ aOut.writeInt(mX);
+ aOut.writeShort(mY);
+ aOut.writeInt(mZ);
+
+ aOut.writeByte(side.ordinal());
+ aOut.writeInt(coverID);
+ coverData.writeToByteBuf(aOut);
+
+ aOut.writeInt(dimID);
+ aOut.writeInt(playerID);
+
+ aOut.writeInt(parentGuiId);
+ }
+
+ @Override
+ public GT_Packet_New decode(ByteArrayDataInput aData) {
+ final int coverID;
+ return new GT_Packet_TileEntityCoverGUI(
+ aData.readInt(),
+ aData.readShort(),
+ aData.readInt(),
+ ForgeDirection.getOrientation(aData.readByte()),
+ coverID = aData.readInt(),
+ GregTech_API.getCoverBehaviorNew(coverID)
+ .createDataObject()
+ .readFromPacket(aData, null),
+ aData.readInt(),
+ aData.readInt(),
+ aData.readInt());
+ }
+
+ @Override
+ public void process(IBlockAccess aWorld) {
+ if (aWorld instanceof World) {
+ // Using EntityPlayer instead of EntityClientPlayerMP so both client and server can load this
+ final EntityPlayer thePlayer = ((EntityPlayer) ((World) aWorld).getEntityByID(playerID));
+ final TileEntity tile = aWorld.getTileEntity(mX, mY, mZ);
+ if (tile instanceof IGregTechTileEntity gtTile && !gtTile.isDead()) {
+ gtTile.setCoverDataAtSide(side, coverData); // Set it client side to read later.
+
+ GT_CoverBehaviorBase<?> cover = gtTile.getCoverBehaviorAtSideNew(side);
+ if (cover.hasCoverGUI()) {
+ final GuiScreen gui = (GuiScreen) cover.getClientGUI(
+ side,
+ gtTile.getCoverIDAtSide(side),
+ gtTile.getComplexCoverDataAtSide(side),
+ gtTile,
+ thePlayer,
+ thePlayer.worldObj);
+ // If it's one of this mod's covers, tell it to exit to the GUI with the specified ID (-1 is
+ // ignored)
+ if (gui instanceof GT_GUICover guiCover) {
+ guiCover.setParentGuiId(parentGuiId);
+ }
+ Minecraft.getMinecraft()
+ .displayGuiScreen(gui);
+ }
+ }
+ }
+ }
+}
diff --git a/src/main/java/gregtech/api/net/GT_Packet_TileEntityCoverNew.java b/src/main/java/gregtech/api/net/GT_Packet_TileEntityCoverNew.java
new file mode 100644
index 0000000000..8fd7348b24
--- /dev/null
+++ b/src/main/java/gregtech/api/net/GT_Packet_TileEntityCoverNew.java
@@ -0,0 +1,119 @@
+package gregtech.api.net;
+
+import net.minecraft.entity.player.EntityPlayerMP;
+import net.minecraft.network.INetHandler;
+import net.minecraft.network.NetHandlerPlayServer;
+import net.minecraft.tileentity.TileEntity;
+import net.minecraft.world.IBlockAccess;
+import net.minecraft.world.World;
+import net.minecraftforge.common.DimensionManager;
+import net.minecraftforge.common.util.ForgeDirection;
+
+import com.google.common.io.ByteArrayDataInput;
+
+import gregtech.api.GregTech_API;
+import gregtech.api.interfaces.tileentity.ICoverable;
+import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
+import gregtech.api.util.ISerializableObject;
+import io.netty.buffer.ByteBuf;
+
+/**
+ * Client -> Server: Update cover data
+ */
+public class GT_Packet_TileEntityCoverNew extends GT_Packet_New {
+
+ protected int mX;
+ protected short mY;
+ protected int mZ;
+
+ protected ForgeDirection side;
+ protected int coverID, dimID;
+ protected ISerializableObject coverData;
+
+ protected EntityPlayerMP mPlayer;
+
+ public GT_Packet_TileEntityCoverNew() {
+ super(true);
+ }
+
+ public GT_Packet_TileEntityCoverNew(int mX, short mY, int mZ, ForgeDirection coverSide, int coverID,
+ ISerializableObject coverData, int dimID) {
+ super(false);
+ this.mX = mX;
+ this.mY = mY;
+ this.mZ = mZ;
+
+ this.side = coverSide;
+ this.coverID = coverID;
+ this.coverData = coverData;
+
+ this.dimID = dimID;
+ }
+
+ public GT_Packet_TileEntityCoverNew(ForgeDirection coverSide, int coverID, ISerializableObject coverData,
+ ICoverable tile) {
+ super(false);
+ this.mX = tile.getXCoord();
+ this.mY = tile.getYCoord();
+ this.mZ = tile.getZCoord();
+
+ this.side = coverSide;
+ this.coverID = coverID;
+ this.coverData = coverData;
+
+ this.dimID = tile.getWorld().provider.dimensionId;
+ }
+
+ @Override
+ public byte getPacketID() {
+ return 11;
+ }
+
+ @Override
+ public void setINetHandler(INetHandler aHandler) {
+ if (aHandler instanceof NetHandlerPlayServer) {
+ mPlayer = ((NetHandlerPlayServer) aHandler).playerEntity;
+ }
+ }
+
+ @Override
+ public void encode(ByteBuf aOut) {
+ aOut.writeInt(mX);
+ aOut.writeShort(mY);
+ aOut.writeInt(mZ);
+
+ aOut.writeByte(side.ordinal());
+ aOut.writeInt(coverID);
+ coverData.writeToByteBuf(aOut);
+
+ aOut.writeInt(dimID);
+ }
+
+ @Override
+ public GT_Packet_New decode(ByteArrayDataInput aData) {
+ int coverId;
+ return new GT_Packet_TileEntityCoverNew(
+ aData.readInt(),
+ aData.readShort(),
+ aData.readInt(),
+ ForgeDirection.getOrientation(aData.readByte()),
+ coverId = aData.readInt(),
+ GregTech_API.getCoverBehaviorNew(coverId)
+ .createDataObject()
+ .readFromPacket(aData, mPlayer),
+ aData.readInt());
+ }
+
+ @Override
+ public void process(IBlockAccess aWorld) {
+ if (mPlayer == null) // impossible, but who knows
+ return;
+ World world = DimensionManager.getWorld(dimID);
+ if (world != null) {
+ TileEntity tile = world.getTileEntity(mX, mY, mZ);
+ if (tile instanceof IGregTechTileEntity && !((IGregTechTileEntity) tile).isDead()) {
+ ((IGregTechTileEntity) tile).receiveCoverData(side, coverID, coverData, mPlayer);
+ }
+ }
+ }
+}
diff --git a/src/main/java/gregtech/api/net/GT_Packet_UpdateItem.java b/src/main/java/gregtech/api/net/GT_Packet_UpdateItem.java
new file mode 100644
index 0000000000..e8ec9be80b
--- /dev/null
+++ b/src/main/java/gregtech/api/net/GT_Packet_UpdateItem.java
@@ -0,0 +1,64 @@
+package gregtech.api.net;
+
+import net.minecraft.entity.player.EntityPlayerMP;
+import net.minecraft.item.ItemStack;
+import net.minecraft.nbt.NBTTagCompound;
+import net.minecraft.network.INetHandler;
+import net.minecraft.network.NetHandlerPlayServer;
+import net.minecraft.world.IBlockAccess;
+
+import com.google.common.io.ByteArrayDataInput;
+
+import cpw.mods.fml.common.network.ByteBufUtils;
+import gregtech.api.interfaces.INetworkUpdatableItem;
+import gregtech.api.util.ISerializableObject;
+import io.netty.buffer.ByteBuf;
+
+/**
+ * Client -> Server: send arbitrary data to server and update the currently held item.
+ */
+public class GT_Packet_UpdateItem extends GT_Packet_New {
+
+ private NBTTagCompound tag;
+ private EntityPlayerMP mPlayer;
+
+ public GT_Packet_UpdateItem() {
+ super(true);
+ }
+
+ public GT_Packet_UpdateItem(NBTTagCompound tag) {
+ super(false);
+ this.tag = tag;
+ }
+
+ @Override
+ public byte getPacketID() {
+ return 13;
+ }
+
+ @Override
+ public void setINetHandler(INetHandler aHandler) {
+ if (aHandler instanceof NetHandlerPlayServer) {
+ mPlayer = ((NetHandlerPlayServer) aHandler).playerEntity;
+ }
+ }
+
+ @Override
+ public void encode(ByteBuf aOut) {
+ ByteBufUtils.writeTag(aOut, tag);
+ }
+
+ @Override
+ public GT_Packet_New decode(ByteArrayDataInput aData) {
+ return new GT_Packet_UpdateItem(ISerializableObject.readCompoundTagFromGreggyByteBuf(aData));
+ }
+
+ @Override
+ public void process(IBlockAccess aWorld) {
+ if (mPlayer == null) return;
+ ItemStack stack = mPlayer.inventory.getCurrentItem();
+ if (stack != null && stack.getItem() instanceof INetworkUpdatableItem) {
+ ((INetworkUpdatableItem) stack.getItem()).receive(stack, mPlayer, tag);
+ }
+ }
+}
diff --git a/src/main/java/gregtech/api/net/GT_Packet_WirelessRedstoneCover.java b/src/main/java/gregtech/api/net/GT_Packet_WirelessRedstoneCover.java
new file mode 100644
index 0000000000..08628ace2b
--- /dev/null
+++ b/src/main/java/gregtech/api/net/GT_Packet_WirelessRedstoneCover.java
@@ -0,0 +1,99 @@
+package gregtech.api.net;
+
+import net.minecraft.entity.player.EntityPlayerMP;
+import net.minecraft.network.INetHandler;
+import net.minecraft.network.NetHandlerPlayServer;
+import net.minecraft.tileentity.TileEntity;
+import net.minecraft.world.IBlockAccess;
+import net.minecraft.world.World;
+import net.minecraftforge.common.DimensionManager;
+import net.minecraftforge.common.util.ForgeDirection;
+
+import com.google.common.io.ByteArrayDataInput;
+
+import gregtech.api.interfaces.tileentity.ICoverable;
+import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
+import io.netty.buffer.ByteBuf;
+
+public class GT_Packet_WirelessRedstoneCover extends GT_Packet_TileEntityCover {
+
+ private static final int PRIVATE_MASK = 0xFFFE0000;
+ private static final int PUBLIC_MASK = 0x0000FFFF;
+ private static final int CHECKBOX_MASK = 0x00010000;
+
+ private EntityPlayerMP mPlayer;
+ private int mPublicChannel;
+ private int mCheckBoxValue;
+
+ public GT_Packet_WirelessRedstoneCover() {
+ super();
+ }
+
+ public GT_Packet_WirelessRedstoneCover(int mX, short mY, int mZ, ForgeDirection coverSide, int coverID, int dimID,
+ int publicChannel, int checkBoxValue) {
+ super(mX, mY, mZ, coverSide, coverID, 0, dimID);
+ mPublicChannel = publicChannel;
+ mCheckBoxValue = checkBoxValue;
+ }
+
+ public GT_Packet_WirelessRedstoneCover(ForgeDirection coverSide, int coverID, ICoverable tile, int publicChannel,
+ int checkBoxValue) {
+ super(coverSide, coverID, 0, tile);
+ mPublicChannel = publicChannel;
+ mCheckBoxValue = checkBoxValue;
+ }
+
+ @Override
+ public byte getPacketID() {
+ return 10;
+ }
+
+ @Override
+ public void setINetHandler(INetHandler aHandler) {
+ if (aHandler instanceof NetHandlerPlayServer) {
+ mPlayer = ((NetHandlerPlayServer) aHandler).playerEntity;
+ }
+ }
+
+ @Override
+ public void encode(ByteBuf aOut) {
+ aOut.writeInt(mX);
+ aOut.writeShort(mY);
+ aOut.writeInt(mZ);
+
+ aOut.writeByte(side.ordinal());
+ aOut.writeInt(coverID);
+
+ aOut.writeInt(dimID);
+
+ aOut.writeInt(mPublicChannel);
+ aOut.writeInt(mCheckBoxValue);
+ }
+
+ @Override
+ public GT_Packet_New decode(ByteArrayDataInput aData) {
+ return new GT_Packet_WirelessRedstoneCover(
+ aData.readInt(),
+ aData.readShort(),
+ aData.readInt(),
+ ForgeDirection.getOrientation(aData.readByte()),
+ aData.readInt(),
+ aData.readInt(),
+ aData.readInt(),
+ aData.readInt());
+ }
+
+ @Override
+ public void process(IBlockAccess aWorld) {
+ World world = DimensionManager.getWorld(dimID);
+ if (world != null && world.blockExists(mX, mY, mZ)) {
+ TileEntity tile = world.getTileEntity(mX, mY, mZ);
+ if (tile instanceof IGregTechTileEntity && !((IGregTechTileEntity) tile).isDead()) {
+ int tPrivateChannel = (mCheckBoxValue > 0) ? mPlayer.getUniqueID()
+ .hashCode() & PRIVATE_MASK : 0;
+ int tCoverData = tPrivateChannel | (mCheckBoxValue & CHECKBOX_MASK) | (mPublicChannel & PUBLIC_MASK);
+ ((IGregTechTileEntity) tile).receiveCoverData(side, coverID, tCoverData);
+ }
+ }
+ }
+}
diff --git a/src/main/java/gregtech/api/net/IGT_NetworkHandler.java b/src/main/java/gregtech/api/net/IGT_NetworkHandler.java
new file mode 100644
index 0000000000..07c4a37030
--- /dev/null
+++ b/src/main/java/gregtech/api/net/IGT_NetworkHandler.java
@@ -0,0 +1,18 @@
+package gregtech.api.net;
+
+import net.minecraft.entity.player.EntityPlayerMP;
+import net.minecraft.world.World;
+
+import cpw.mods.fml.common.network.NetworkRegistry.TargetPoint;
+
+@SuppressWarnings("deprecation")
+public interface IGT_NetworkHandler {
+
+ void sendToPlayer(GT_Packet aPacket, EntityPlayerMP aPlayer);
+
+ void sendToAllAround(GT_Packet aPacket, TargetPoint aPosition);
+
+ void sendToServer(GT_Packet aPacket);
+
+ void sendPacketToAllPlayersInRange(World aWorld, GT_Packet aPacket, int aX, int aZ);
+}
diff --git a/src/main/java/gregtech/api/net/data/CasingData.java b/src/main/java/gregtech/api/net/data/CasingData.java
new file mode 100644
index 0000000000..627c1eacf2
--- /dev/null
+++ b/src/main/java/gregtech/api/net/data/CasingData.java
@@ -0,0 +1,53 @@
+package gregtech.api.net.data;
+
+import javax.annotation.Nonnull;
+
+import net.minecraft.util.ChunkCoordinates;
+
+import com.google.common.io.ByteArrayDataInput;
+
+import io.netty.buffer.ByteBuf;
+
+public class CasingData extends PacketData<MultiTileEntityProcess> {
+
+ public static final int CASING_DATA_ID = 4;
+
+ private int currentMode;
+ private int allowedModes;
+ private ChunkCoordinates controllerCoords;
+
+ public CasingData() {}
+
+ public CasingData(int currentMode, int allowedModes, ChunkCoordinates controllerCoords) {
+ this.currentMode = currentMode;
+ this.allowedModes = allowedModes;
+ this.controllerCoords = controllerCoords;
+ }
+
+ @Override
+ public void decode(@Nonnull ByteArrayDataInput in) {
+ currentMode = in.readInt();
+ allowedModes = in.readInt();
+ controllerCoords = new ChunkCoordinates(in.readInt(), in.readInt(), in.readInt());
+ }
+
+ @Override
+ public void encode(@Nonnull ByteBuf out) {
+ out.writeInt(currentMode);
+ out.writeInt(allowedModes);
+ out.writeInt(controllerCoords.posX);
+ out.writeInt(controllerCoords.posY);
+ out.writeInt(controllerCoords.posZ);
+ }
+
+ @Override
+ public int getId() {
+ return CASING_DATA_ID;
+ }
+
+ @Override
+ public void process(MultiTileEntityProcess processData) {
+
+ }
+
+}
diff --git a/src/main/java/gregtech/api/net/data/CommonData.java b/src/main/java/gregtech/api/net/data/CommonData.java
new file mode 100644
index 0000000000..294cca134b
--- /dev/null
+++ b/src/main/java/gregtech/api/net/data/CommonData.java
@@ -0,0 +1,50 @@
+package gregtech.api.net.data;
+
+import javax.annotation.Nonnull;
+
+import com.google.common.io.ByteArrayDataInput;
+
+import io.netty.buffer.ByteBuf;
+
+public class CommonData extends PacketData<MultiTileEntityProcess> {
+
+ public static final int COMMON_DATA_ID = 2;
+
+ private byte redstone;
+ private byte color;
+ private byte commonData;
+
+ public CommonData() {}
+
+ public CommonData(byte redstone, byte color, byte commonData) {
+ this.redstone = redstone;
+ this.color = color;
+ this.commonData = commonData;
+ }
+
+ @Override
+ public void decode(@Nonnull ByteArrayDataInput in) {
+ redstone = in.readByte();
+ color = in.readByte();
+ commonData = in.readByte();
+ }
+
+ @Override
+ public void encode(@Nonnull ByteBuf out) {
+ out.writeByte(redstone);
+ out.writeByte(color);
+ out.writeByte(commonData);
+ }
+
+ @Override
+ public int getId() {
+ return COMMON_DATA_ID;
+ }
+
+ @Override
+ public void process(MultiTileEntityProcess processData) {
+ // TODO Auto-generated method stub
+
+ }
+
+}
diff --git a/src/main/java/gregtech/api/net/data/CoordinateData.java b/src/main/java/gregtech/api/net/data/CoordinateData.java
new file mode 100644
index 0000000000..ad8ebbd210
--- /dev/null
+++ b/src/main/java/gregtech/api/net/data/CoordinateData.java
@@ -0,0 +1,50 @@
+package gregtech.api.net.data;
+
+import javax.annotation.Nonnull;
+
+import net.minecraft.util.ChunkCoordinates;
+
+import com.google.common.io.ByteArrayDataInput;
+
+import io.netty.buffer.ByteBuf;
+
+public class CoordinateData extends PacketData<MultiTileEntityProcess> {
+
+ public final static int COORDINATE_DATA_ID = 0;
+
+ private ChunkCoordinates coords;
+
+ public CoordinateData(ChunkCoordinates coords) {
+ this.coords = coords;
+ }
+
+ public CoordinateData(int x, int y, int z) {
+ this(new ChunkCoordinates(x, y, z));
+ }
+
+ public CoordinateData() {}
+
+ @Override
+ public int getId() {
+ return COORDINATE_DATA_ID;
+ }
+
+ @Override
+ public void encode(@Nonnull ByteBuf out) {
+ out.writeInt(coords.posX);
+ out.writeInt(coords.posY);
+ out.writeInt(coords.posZ);
+ }
+
+ @Override
+ public void decode(@Nonnull ByteArrayDataInput in) {
+ coords = new ChunkCoordinates(in.readInt(), in.readInt(), in.readInt());
+ }
+
+ @Override
+ public void process(MultiTileEntityProcess processData) {
+ if (coords == null) return;
+ processData.giveCoordinates(coords);
+ }
+
+}
diff --git a/src/main/java/gregtech/api/net/data/MultiTileEntityData.java b/src/main/java/gregtech/api/net/data/MultiTileEntityData.java
new file mode 100644
index 0000000000..2bdbf4acc9
--- /dev/null
+++ b/src/main/java/gregtech/api/net/data/MultiTileEntityData.java
@@ -0,0 +1,45 @@
+package gregtech.api.net.data;
+
+import javax.annotation.Nonnull;
+
+import com.google.common.io.ByteArrayDataInput;
+
+import io.netty.buffer.ByteBuf;
+
+public class MultiTileEntityData extends PacketData<MultiTileEntityProcess> {
+
+ public static final int MULTI_TILE_ENTITY_DATA_ID = 1;
+
+ private int registryId;
+ private int metaId;
+
+ public MultiTileEntityData() {}
+
+ public MultiTileEntityData(int registryId, int metaId) {
+ this.registryId = registryId;
+ this.metaId = metaId;
+ }
+
+ @Override
+ public int getId() {
+ return MULTI_TILE_ENTITY_DATA_ID;
+ }
+
+ @Override
+ public void encode(@Nonnull ByteBuf out) {
+ out.writeInt(registryId);
+ out.writeInt(metaId);
+ }
+
+ @Override
+ public void decode(@Nonnull ByteArrayDataInput in) {
+ registryId = in.readInt();
+ metaId = in.readInt();
+ }
+
+ @Override
+ public void process(MultiTileEntityProcess processData) {
+ processData.giveMultiTileEntityData(registryId, metaId);
+ }
+
+}
diff --git a/src/main/java/gregtech/api/net/data/MultiTileEntityProcess.java b/src/main/java/gregtech/api/net/data/MultiTileEntityProcess.java
new file mode 100644
index 0000000000..02e04981c0
--- /dev/null
+++ b/src/main/java/gregtech/api/net/data/MultiTileEntityProcess.java
@@ -0,0 +1,54 @@
+package gregtech.api.net.data;
+
+import javax.annotation.Nonnull;
+
+import net.minecraft.block.Block;
+import net.minecraft.util.ChunkCoordinates;
+import net.minecraft.world.IBlockAccess;
+
+import gregtech.api.multitileentity.MultiTileEntityBlock;
+import gregtech.api.multitileentity.interfaces.IMultiTileEntity;
+
+public class MultiTileEntityProcess extends Process {
+
+ @Nonnull
+ private final IBlockAccess world;
+ private ChunkCoordinates coords;
+ private int registryId;
+ private int metaId;
+ private byte redstone;
+ private byte color;
+ private byte commonData;
+
+ public MultiTileEntityProcess(@Nonnull IBlockAccess world) {
+ this.world = world;
+ }
+
+ @Override
+ public void process() {
+ if (coords == null) return;
+ Block block = world.getBlock(coords.posX, coords.posY, coords.posZ);
+ if (!(block instanceof MultiTileEntityBlock muteBlock)) {
+ return;
+ }
+ IMultiTileEntity mute = muteBlock
+ .receiveMultiTileEntityData(world, coords.posX, coords.posY, coords.posZ, registryId, metaId);
+ if (mute == null) return;
+ mute.setColorization(color);
+ }
+
+ public void giveCoordinates(@Nonnull ChunkCoordinates coords) {
+ this.coords = coords;
+ }
+
+ public void giveMultiTileEntityData(int registryId, int metaId) {
+ this.registryId = registryId;
+ this.metaId = metaId;
+ }
+
+ public void giveCommonData(byte redstone, byte color, byte commonData) {
+ this.redstone = redstone;
+ this.color = color;
+ this.commonData = commonData;
+ }
+}
diff --git a/src/main/java/gregtech/api/net/data/PacketData.java b/src/main/java/gregtech/api/net/data/PacketData.java
new file mode 100644
index 0000000000..bde2b9fb76
--- /dev/null
+++ b/src/main/java/gregtech/api/net/data/PacketData.java
@@ -0,0 +1,48 @@
+package gregtech.api.net.data;
+
+import javax.annotation.Nonnull;
+
+import com.google.common.io.ByteArrayDataInput;
+
+import io.netty.buffer.ByteBuf;
+
+public abstract class PacketData<T extends Process> implements Comparable<PacketData<T>> {
+
+ /**
+ * This should return the Id of the packet. The Id is is used to bit-shift to be added a header for the packet its
+ * used in
+ */
+ public abstract int getId();
+
+ /**
+ * Called by the packet it is held by to store the data it needs
+ */
+ public abstract void encode(@Nonnull ByteBuf out);
+
+ /**
+ * Called by the packet it is held by to decode the data to later be used in {@link #process()}
+ */
+ public abstract void decode(@Nonnull ByteArrayDataInput in);
+
+ /**
+ * Called by the packet it is held by to process the data it decoded.
+ */
+ public abstract void process(T processData);
+
+ @Override
+ public boolean equals(Object other) {
+ if (this == other) return true;
+ if (!(other instanceof PacketData otherData)) return false;
+ return this.getId() == otherData.getId();
+ }
+
+ @Override
+ public int hashCode() {
+ return getId();
+ }
+
+ @Override
+ public int compareTo(PacketData<T> other) {
+ return Integer.compare(this.getId(), other.getId());
+ }
+}
diff --git a/src/main/java/gregtech/api/net/data/Process.java b/src/main/java/gregtech/api/net/data/Process.java
new file mode 100644
index 0000000000..d5bc1317b7
--- /dev/null
+++ b/src/main/java/gregtech/api/net/data/Process.java
@@ -0,0 +1,6 @@
+package gregtech.api.net.data;
+
+public abstract class Process {
+
+ public abstract void process();
+}