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_PacketTypes.java64
-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_MultiTileEntity.java254
-rw-r--r--src/main/java/gregtech/api/net/GT_Packet_MusicSystemData.java58
-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.java73
-rw-r--r--src/main/java/gregtech/api/net/GT_Packet_TileEntity.java157
-rw-r--r--src/main/java/gregtech/api/net/GT_Packet_ToolSwitchMode.java52
-rw-r--r--src/main/java/gregtech/api/net/GT_Packet_UpdateItem.java64
-rw-r--r--src/main/java/gregtech/api/net/IGT_NetworkHandler.java22
-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
24 files changed, 1697 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_PacketTypes.java b/src/main/java/gregtech/api/net/GT_PacketTypes.java
new file mode 100644
index 0000000000..5907b2176b
--- /dev/null
+++ b/src/main/java/gregtech/api/net/GT_PacketTypes.java
@@ -0,0 +1,64 @@
+package gregtech.api.net;
+
+import java.util.Arrays;
+
+import gregtech.common.blocks.GT_Packet_Ores;
+import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
+
+/**
+ * Centralized place to keep all the GT packet ID constants
+ */
+public enum GT_PacketTypes {
+
+ TILE_ENTITY(0, new GT_Packet_TileEntity()),
+ SOUND(1, new GT_Packet_Sound()),
+ BLOCK_EVENT(2, new GT_Packet_Block_Event()),
+ ORES(3, new GT_Packet_Ores()),
+ POLLUTION(4, new GT_Packet_Pollution()),
+ CLIENT_PREFERENCE(9, new GT_Packet_ClientPreference()),
+ SET_CONFIGURATION_CIRCUIT(12, new GT_Packet_SetConfigurationCircuit()),
+ UPDATE_ITEM(13, new GT_Packet_UpdateItem()),
+ SEND_COVER_DATA(16, new GT_Packet_SendCoverData()),
+ REQUEST_COVER_DATA(17, new GT_Packet_RequestCoverData()),
+ MULTI_TILE_ENTITY(18, new GT_Packet_MultiTileEntity(true)),
+ SEND_OREGEN_PATTERN(19, new GT_Packet_SendOregenPattern()),
+ TOOL_SWITCH_MODE(20, new GT_Packet_ToolSwitchMode()),
+ MUSIC_SYSTEM_DATA(21, new GT_Packet_MusicSystemData()),
+ // merge conflict prevention comment, keep a trailing comma above
+ ;
+
+ static {
+ // Validate no duplicate IDs
+ final GT_PacketTypes[] types = values();
+ final Int2ObjectOpenHashMap<GT_Packet_New> foundIds = new Int2ObjectOpenHashMap<>(types.length);
+ for (GT_PacketTypes type : types) {
+ final GT_Packet_New previous = foundIds.get(type.id);
+ if (previous != null) {
+ throw new IllegalStateException(
+ "Duplicate packet IDs defined: " + type.id
+ + " for "
+ + type.getClass()
+ + " and "
+ + previous.getClass());
+ }
+ foundIds.put(type.id, type.referencePacket);
+ }
+ }
+
+ public final byte id;
+ public final GT_Packet_New referencePacket;
+
+ GT_PacketTypes(int id, GT_Packet_New referencePacket) {
+ if (((int) (byte) id) != id) {
+ throw new IllegalArgumentException("Value outside of byte normal range: " + id);
+ }
+ this.id = (byte) id;
+ this.referencePacket = referencePacket;
+ }
+
+ public static GT_Packet_New[] referencePackets() {
+ return Arrays.stream(values())
+ .map(p -> p.referencePacket)
+ .toArray(GT_Packet_New[]::new);
+ }
+}
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..9adf583698
--- /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 GT_PacketTypes.BLOCK_EVENT.id;
+ }
+}
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..a5fd8a2e08
--- /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 GT_PacketTypes.CLIENT_PREFERENCE.id;
+ }
+
+ @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_MultiTileEntity.java b/src/main/java/gregtech/api/net/GT_Packet_MultiTileEntity.java
new file mode 100644
index 0000000000..33cb4f2dcf
--- /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 GT_PacketTypes.MULTI_TILE_ENTITY.id;
+ }
+
+ 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_MusicSystemData.java b/src/main/java/gregtech/api/net/GT_Packet_MusicSystemData.java
new file mode 100644
index 0000000000..13ebf49205
--- /dev/null
+++ b/src/main/java/gregtech/api/net/GT_Packet_MusicSystemData.java
@@ -0,0 +1,58 @@
+package gregtech.api.net;
+
+import net.minecraft.world.IBlockAccess;
+
+import com.google.common.io.ByteArrayDataInput;
+
+import gregtech.api.util.GT_MusicSystem;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+
+public class GT_Packet_MusicSystemData extends GT_Packet_New {
+
+ ByteBuf storedData;
+
+ public GT_Packet_MusicSystemData() {
+ super(true);
+ }
+
+ public GT_Packet_MusicSystemData(ByteBuf data) {
+ super(false);
+ this.storedData = data;
+ }
+
+ @Override
+ public byte getPacketID() {
+ return GT_PacketTypes.MUSIC_SYSTEM_DATA.id;
+ }
+
+ @Override
+ public void encode(ByteBuf aOut) {
+ if (storedData == null) {
+ return;
+ }
+ storedData.markReaderIndex();
+ final int len = storedData.readableBytes();
+ aOut.writeInt(len);
+ aOut.writeBytes(storedData);
+ storedData.resetReaderIndex();
+ }
+
+ @Override
+ public GT_Packet_New decode(ByteArrayDataInput aData) {
+ final int len = aData.readInt();
+ final byte[] fullData = new byte[len];
+ aData.readFully(fullData);
+ return new GT_Packet_MusicSystemData(Unpooled.wrappedBuffer(fullData));
+ }
+
+ @Override
+ public void process(IBlockAccess aWorld) {
+ if (aWorld == null || storedData == null) {
+ return;
+ }
+ storedData.markReaderIndex();
+ GT_MusicSystem.ClientSystem.loadUpdatedSources(storedData);
+ storedData.resetReaderIndex();
+ }
+}
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..9b4a367dc4
--- /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 GT_PacketTypes.POLLUTION.id;
+ }
+}
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..bca97b69a5
--- /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 GT_PacketTypes.REQUEST_COVER_DATA.id;
+ }
+
+ @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..268aaab803
--- /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 GT_PacketTypes.SEND_COVER_DATA.id;
+ }
+
+ @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..8213ee9c71
--- /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 GT_PacketTypes.SEND_OREGEN_PATTERN.id;
+ }
+
+ @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..2bfdbca9d2
--- /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 GT_PacketTypes.SET_CONFIGURATION_CIRCUIT.id;
+ }
+
+ @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..93bfdfd3aa
--- /dev/null
+++ b/src/main/java/gregtech/api/net/GT_Packet_Sound.java
@@ -0,0 +1,73 @@
+package gregtech.api.net;
+
+import java.io.IOException;
+
+import net.minecraft.util.ResourceLocation;
+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) {
+ if (mSoundName != null) {
+ GT_Utility.doSoundAtClient(new ResourceLocation(mSoundName), 1, mSoundStrength, mSoundPitch, mX, mY, mZ);
+ }
+ }
+
+ @Override
+ public byte getPacketID() {
+ return GT_PacketTypes.SOUND.id;
+ }
+}
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..b07277dc00
--- /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 GT_PacketTypes.TILE_ENTITY.id;
+ }
+}
diff --git a/src/main/java/gregtech/api/net/GT_Packet_ToolSwitchMode.java b/src/main/java/gregtech/api/net/GT_Packet_ToolSwitchMode.java
new file mode 100644
index 0000000000..c7984d7434
--- /dev/null
+++ b/src/main/java/gregtech/api/net/GT_Packet_ToolSwitchMode.java
@@ -0,0 +1,52 @@
+package gregtech.api.net;
+
+import net.minecraft.entity.player.EntityPlayerMP;
+import net.minecraft.item.ItemStack;
+import net.minecraft.network.INetHandler;
+import net.minecraft.network.NetHandlerPlayServer;
+import net.minecraft.world.IBlockAccess;
+
+import com.google.common.io.ByteArrayDataInput;
+
+import gregtech.api.items.GT_MetaGenerated_Tool;
+import io.netty.buffer.ByteBuf;
+
+public class GT_Packet_ToolSwitchMode extends GT_Packet_New {
+
+ private EntityPlayerMP player;
+
+ public GT_Packet_ToolSwitchMode() {
+ super(true);
+ }
+
+ @Override
+ public byte getPacketID() {
+ return GT_PacketTypes.TOOL_SWITCH_MODE.id;
+ }
+
+ @Override
+ public void encode(ByteBuf aOut) {
+
+ }
+
+ @Override
+ public GT_Packet_New decode(ByteArrayDataInput aData) {
+ return new GT_Packet_ToolSwitchMode();
+ }
+
+ @Override
+ public void setINetHandler(INetHandler aHandler) {
+ player = ((NetHandlerPlayServer) aHandler).playerEntity;
+ }
+
+ @Override
+ public void process(IBlockAccess aWorld) {
+ ItemStack currentItem = player.inventory.getCurrentItem();
+ if (currentItem == null || (!(currentItem.getItem() instanceof GT_MetaGenerated_Tool item))) return;
+ byte maxMode = item.getToolMaxMode(currentItem);
+ if (maxMode <= 1) return;
+ byte newMode = (byte) ((GT_MetaGenerated_Tool.getToolMode(currentItem) + 1) % maxMode);
+ GT_MetaGenerated_Tool.setToolMode(currentItem, newMode);
+ player.sendSlotContents(player.inventoryContainer, player.inventory.currentItem, currentItem);
+ }
+}
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..1b8a453234
--- /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 GT_PacketTypes.UPDATE_ITEM.id;
+ }
+
+ @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/IGT_NetworkHandler.java b/src/main/java/gregtech/api/net/IGT_NetworkHandler.java
new file mode 100644
index 0000000000..8436a89e9b
--- /dev/null
+++ b/src/main/java/gregtech/api/net/IGT_NetworkHandler.java
@@ -0,0 +1,22 @@
+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);
+
+ default void sendToAll(GT_Packet aPacket) {
+ throw new UnsupportedOperationException("sendToAll not implemented");
+ }
+
+ 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();
+}