From 1b820de08a05070909a267e17f033fcf58ac8710 Mon Sep 17 00:00:00 2001 From: NotAPenguin Date: Mon, 2 Sep 2024 23:17:17 +0200 Subject: The Great Renaming (#3014) * move kekztech to a single root dir * move detrav to a single root dir * move gtnh-lanthanides to a single root dir * move tectech and delete some gross reflection in gt++ * remove more reflection inside gt5u * delete more reflection in gt++ * fix imports * move bartworks and bwcrossmod * fix proxies * move galactigreg and ggfab * move gtneioreplugin * try to fix gt++ bee loader * apply the rename rules to BW * apply rename rules to bwcrossmod * apply rename rules to detrav scanner mod * apply rename rules to galacticgreg * apply rename rules to ggfab * apply rename rules to goodgenerator * apply rename rules to gtnh-lanthanides * apply rename rules to gt++ * apply rename rules to kekztech * apply rename rules to kubatech * apply rename rules to tectech * apply rename rules to gt apply the rename rules to gt * fix tt import * fix mui hopefully * fix coremod except intergalactic * rename assline recipe class * fix a class name i stumbled on * rename StructureUtility to GTStructureUtility to prevent conflict with structurelib * temporary rename of GTTooltipDataCache to old name * fix gt client/server proxy names --- src/main/java/gregtech/api/net/GTPacket.java | 59 +++++ .../java/gregtech/api/net/GTPacketBlockEvent.java | 63 +++++ .../gregtech/api/net/GTPacketClientPreference.java | 58 +++++ .../gregtech/api/net/GTPacketMultiTileEntity.java | 254 +++++++++++++++++++++ .../gregtech/api/net/GTPacketMusicSystemData.java | 58 +++++ src/main/java/gregtech/api/net/GTPacketNew.java | 30 +++ .../java/gregtech/api/net/GTPacketPollution.java | 47 ++++ .../gregtech/api/net/GTPacketRequestCoverData.java | 113 +++++++++ .../gregtech/api/net/GTPacketSendCoverData.java | 107 +++++++++ .../api/net/GTPacketSendOregenPattern.java | 56 +++++ .../api/net/GTPacketSetConfigurationCircuit.java | 110 +++++++++ src/main/java/gregtech/api/net/GTPacketSound.java | 73 ++++++ .../java/gregtech/api/net/GTPacketTileEntity.java | 157 +++++++++++++ .../gregtech/api/net/GTPacketToolSwitchMode.java | 52 +++++ src/main/java/gregtech/api/net/GTPacketTypes.java | 64 ++++++ .../java/gregtech/api/net/GTPacketUpdateItem.java | 64 ++++++ src/main/java/gregtech/api/net/GT_Packet.java | 59 ----- src/main/java/gregtech/api/net/GT_PacketTypes.java | 64 ------ .../gregtech/api/net/GT_Packet_Block_Event.java | 63 ----- .../api/net/GT_Packet_ClientPreference.java | 62 ----- .../api/net/GT_Packet_MultiTileEntity.java | 254 --------------------- .../api/net/GT_Packet_MusicSystemData.java | 58 ----- src/main/java/gregtech/api/net/GT_Packet_New.java | 30 --- .../java/gregtech/api/net/GT_Packet_Pollution.java | 47 ---- .../api/net/GT_Packet_RequestCoverData.java | 113 --------- .../gregtech/api/net/GT_Packet_SendCoverData.java | 107 --------- .../api/net/GT_Packet_SendOregenPattern.java | 56 ----- .../api/net/GT_Packet_SetConfigurationCircuit.java | 110 --------- .../java/gregtech/api/net/GT_Packet_Sound.java | 73 ------ .../gregtech/api/net/GT_Packet_TileEntity.java | 157 ------------- .../gregtech/api/net/GT_Packet_ToolSwitchMode.java | 52 ----- .../gregtech/api/net/GT_Packet_UpdateItem.java | 64 ------ .../java/gregtech/api/net/IGT_NetworkHandler.java | 10 +- 33 files changed, 1370 insertions(+), 1374 deletions(-) create mode 100644 src/main/java/gregtech/api/net/GTPacket.java create mode 100644 src/main/java/gregtech/api/net/GTPacketBlockEvent.java create mode 100644 src/main/java/gregtech/api/net/GTPacketClientPreference.java create mode 100644 src/main/java/gregtech/api/net/GTPacketMultiTileEntity.java create mode 100644 src/main/java/gregtech/api/net/GTPacketMusicSystemData.java create mode 100644 src/main/java/gregtech/api/net/GTPacketNew.java create mode 100644 src/main/java/gregtech/api/net/GTPacketPollution.java create mode 100644 src/main/java/gregtech/api/net/GTPacketRequestCoverData.java create mode 100644 src/main/java/gregtech/api/net/GTPacketSendCoverData.java create mode 100644 src/main/java/gregtech/api/net/GTPacketSendOregenPattern.java create mode 100644 src/main/java/gregtech/api/net/GTPacketSetConfigurationCircuit.java create mode 100644 src/main/java/gregtech/api/net/GTPacketSound.java create mode 100644 src/main/java/gregtech/api/net/GTPacketTileEntity.java create mode 100644 src/main/java/gregtech/api/net/GTPacketToolSwitchMode.java create mode 100644 src/main/java/gregtech/api/net/GTPacketTypes.java create mode 100644 src/main/java/gregtech/api/net/GTPacketUpdateItem.java delete mode 100644 src/main/java/gregtech/api/net/GT_Packet.java delete mode 100644 src/main/java/gregtech/api/net/GT_PacketTypes.java delete mode 100644 src/main/java/gregtech/api/net/GT_Packet_Block_Event.java delete mode 100644 src/main/java/gregtech/api/net/GT_Packet_ClientPreference.java delete mode 100644 src/main/java/gregtech/api/net/GT_Packet_MultiTileEntity.java delete mode 100644 src/main/java/gregtech/api/net/GT_Packet_MusicSystemData.java delete mode 100644 src/main/java/gregtech/api/net/GT_Packet_New.java delete mode 100644 src/main/java/gregtech/api/net/GT_Packet_Pollution.java delete mode 100644 src/main/java/gregtech/api/net/GT_Packet_RequestCoverData.java delete mode 100644 src/main/java/gregtech/api/net/GT_Packet_SendCoverData.java delete mode 100644 src/main/java/gregtech/api/net/GT_Packet_SendOregenPattern.java delete mode 100644 src/main/java/gregtech/api/net/GT_Packet_SetConfigurationCircuit.java delete mode 100644 src/main/java/gregtech/api/net/GT_Packet_Sound.java delete mode 100644 src/main/java/gregtech/api/net/GT_Packet_TileEntity.java delete mode 100644 src/main/java/gregtech/api/net/GT_Packet_ToolSwitchMode.java delete mode 100644 src/main/java/gregtech/api/net/GT_Packet_UpdateItem.java (limited to 'src/main/java/gregtech/api/net') diff --git a/src/main/java/gregtech/api/net/GTPacket.java b/src/main/java/gregtech/api/net/GTPacket.java new file mode 100644 index 0000000000..1d2de3303b --- /dev/null +++ b/src/main/java/gregtech/api/net/GTPacket.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 GTPacketNew} instead + */ +@Deprecated +public abstract class GTPacket { + + public GTPacket(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 GTPacket 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/GTPacketBlockEvent.java b/src/main/java/gregtech/api/net/GTPacketBlockEvent.java new file mode 100644 index 0000000000..a2164f4f07 --- /dev/null +++ b/src/main/java/gregtech/api/net/GTPacketBlockEvent.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 GTPacketBlockEvent extends GTPacketNew { + + private int mX, mZ; + private short mY; + private byte mID, mValue; + + public GTPacketBlockEvent() { + super(true); + } + + public GTPacketBlockEvent(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 GTPacketNew decode(ByteArrayDataInput aData) { + return new GTPacketBlockEvent( + 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 GTPacketTypes.BLOCK_EVENT.id; + } +} diff --git a/src/main/java/gregtech/api/net/GTPacketClientPreference.java b/src/main/java/gregtech/api/net/GTPacketClientPreference.java new file mode 100644 index 0000000000..ea5d9ec476 --- /dev/null +++ b/src/main/java/gregtech/api/net/GTPacketClientPreference.java @@ -0,0 +1,58 @@ +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.GTMod; +import gregtech.api.util.GTClientPreference; +import io.netty.buffer.ByteBuf; + +public class GTPacketClientPreference extends GTPacketNew { + + private GTClientPreference mPreference; + private EntityPlayerMP mPlayer; + + public GTPacketClientPreference() { + super(true); + } + + public GTPacketClientPreference(GTClientPreference mPreference) { + super(false); + this.mPreference = mPreference; + } + + @Override + public byte getPacketID() { + return GTPacketTypes.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) GTMod.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 GTPacketNew decode(ByteArrayDataInput aData) { + return new GTPacketClientPreference( + new GTClientPreference(aData.readBoolean(), aData.readBoolean(), aData.readBoolean(), aData.readBoolean())); + } +} diff --git a/src/main/java/gregtech/api/net/GTPacketMultiTileEntity.java b/src/main/java/gregtech/api/net/GTPacketMultiTileEntity.java new file mode 100644 index 0000000000..b151f8eb5f --- /dev/null +++ b/src/main/java/gregtech/api/net/GTPacketMultiTileEntity.java @@ -0,0 +1,254 @@ +package gregtech.api.net; + +import static gregtech.api.enums.GTValues.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 GTPacketMultiTileEntity extends GTPacketNew { + + private final Set> 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 GTPacketMultiTileEntity(boolean reference) { + super(reference); + } + + @Override + public void encode(ByteBuf aOut) { + Set> set = data.stream() + .sorted() + .collect( + HashSet>::new, + HashSet>::add, + HashSet>::addAll); + clearData(); + data.addAll(set); + int features = 0; + for (PacketData data : data) { + features |= 1 << data.getId(); + } + + aOut.writeInt(features); + + for (PacketData 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 GTPacketNew decode(ByteArrayDataInput in) { + Objects.requireNonNull(in); + final int packetFeatures = in.readInt(); + + final GTPacketMultiTileEntity packet = new GTPacketMultiTileEntity(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> set = packet.data.stream() + .sorted() + .collect( + HashSet>::new, + HashSet>::add, + HashSet>::addAll); + packet.clearData(); + packet.data.addAll(set); + for (PacketData 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 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(); + * GTMod.GT_FML_LOGGER.error( + * "Exception setting tile entity data for tile entity {} at ({}, {}, {})", + * tTileEntity, + * mX, + * mY, + * mZ); + * } + */ + } + + @Override + public byte getPacketID() { + return GTPacketTypes.MULTI_TILE_ENTITY.id; + } + + public void clearData() { + data.clear(); + } + + public void addData(PacketData 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/GTPacketMusicSystemData.java b/src/main/java/gregtech/api/net/GTPacketMusicSystemData.java new file mode 100644 index 0000000000..c650188594 --- /dev/null +++ b/src/main/java/gregtech/api/net/GTPacketMusicSystemData.java @@ -0,0 +1,58 @@ +package gregtech.api.net; + +import net.minecraft.world.IBlockAccess; + +import com.google.common.io.ByteArrayDataInput; + +import gregtech.api.util.GTMusicSystem; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.Unpooled; + +public class GTPacketMusicSystemData extends GTPacketNew { + + ByteBuf storedData; + + public GTPacketMusicSystemData() { + super(true); + } + + public GTPacketMusicSystemData(ByteBuf data) { + super(false); + this.storedData = data; + } + + @Override + public byte getPacketID() { + return GTPacketTypes.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 GTPacketNew decode(ByteArrayDataInput aData) { + final int len = aData.readInt(); + final byte[] fullData = new byte[len]; + aData.readFully(fullData); + return new GTPacketMusicSystemData(Unpooled.wrappedBuffer(fullData)); + } + + @Override + public void process(IBlockAccess aWorld) { + if (aWorld == null || storedData == null) { + return; + } + storedData.markReaderIndex(); + GTMusicSystem.ClientSystem.loadUpdatedSources(storedData); + storedData.resetReaderIndex(); + } +} diff --git a/src/main/java/gregtech/api/net/GTPacketNew.java b/src/main/java/gregtech/api/net/GTPacketNew.java new file mode 100644 index 0000000000..d3fee800c6 --- /dev/null +++ b/src/main/java/gregtech/api/net/GTPacketNew.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 GTPacketNew extends GTPacket { + + public GTPacketNew(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 GTPacketNew decode(ByteArrayDataInput aData); +} diff --git a/src/main/java/gregtech/api/net/GTPacketPollution.java b/src/main/java/gregtech/api/net/GTPacketPollution.java new file mode 100644 index 0000000000..2f4805aad8 --- /dev/null +++ b/src/main/java/gregtech/api/net/GTPacketPollution.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.GTClient; +import io.netty.buffer.ByteBuf; + +public class GTPacketPollution extends GTPacketNew { + + private ChunkCoordIntPair chunk; + private int pollution; + + public GTPacketPollution() { + super(true); + } + + public GTPacketPollution(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 GTPacketNew decode(ByteArrayDataInput aData) { + return new GTPacketPollution(new ChunkCoordIntPair(aData.readInt(), aData.readInt()), aData.readInt()); + } + + @Override + public void process(IBlockAccess aWorld) { + GTClient.recieveChunkPollutionPacket(chunk, pollution); + } + + @Override + public byte getPacketID() { + return GTPacketTypes.POLLUTION.id; + } +} diff --git a/src/main/java/gregtech/api/net/GTPacketRequestCoverData.java b/src/main/java/gregtech/api/net/GTPacketRequestCoverData.java new file mode 100644 index 0000000000..4679643624 --- /dev/null +++ b/src/main/java/gregtech/api/net/GTPacketRequestCoverData.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 GTPacketRequestCoverData extends GTPacketNew { + + protected int mX; + protected short mY; + protected int mZ; + + protected ForgeDirection side; + protected int coverID; + + protected EntityPlayerMP mPlayer; + + public GTPacketRequestCoverData() { + super(true); + } + + public GTPacketRequestCoverData(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 GTPacketRequestCoverData(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 GTPacketRequestCoverData(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 GTPacketTypes.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 GTPacketNew decode(ByteArrayDataInput aData) { + return new GTPacketRequestCoverData( + 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/GTPacketSendCoverData.java b/src/main/java/gregtech/api/net/GTPacketSendCoverData.java new file mode 100644 index 0000000000..76adb75d31 --- /dev/null +++ b/src/main/java/gregtech/api/net/GTPacketSendCoverData.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.GregTechAPI; +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 GTPacketSendCoverData extends GTPacketNew { + + protected int mX; + protected short mY; + protected int mZ; + + protected ForgeDirection side; + protected int coverID; + protected ISerializableObject coverData; + + public GTPacketSendCoverData() { + super(true); + } + + public GTPacketSendCoverData(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 GTPacketSendCoverData(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 GTPacketSendCoverData(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 GTPacketTypes.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 GTPacketNew decode(ByteArrayDataInput aData) { + final int coverId; + return new GTPacketSendCoverData( + aData.readInt(), + aData.readShort(), + aData.readInt(), + ForgeDirection.getOrientation(aData.readByte()), + coverId = aData.readInt(), + GregTechAPI.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/GTPacketSendOregenPattern.java b/src/main/java/gregtech/api/net/GTPacketSendOregenPattern.java new file mode 100644 index 0000000000..9db0e9a471 --- /dev/null +++ b/src/main/java/gregtech/api/net/GTPacketSendOregenPattern.java @@ -0,0 +1,56 @@ +package gregtech.api.net; + +import net.minecraft.world.IBlockAccess; + +import com.google.common.io.ByteArrayDataInput; + +import gregtech.api.util.GTLog; +import gregtech.common.GTWorldgenerator; +import gregtech.common.GTWorldgenerator.OregenPattern; +import io.netty.buffer.ByteBuf; + +public class GTPacketSendOregenPattern extends GTPacketNew { + + protected OregenPattern pattern = OregenPattern.AXISSYMMETRICAL; + + public GTPacketSendOregenPattern() { + super(true); + } + + public GTPacketSendOregenPattern(OregenPattern pattern) { + super(false); + this.pattern = pattern; + } + + @Override + public void encode(ByteBuf aOut) { + aOut.writeInt(this.pattern.ordinal()); + } + + @Override + public GTPacketNew decode(ByteArrayDataInput aData) { + int ordinal = aData.readInt(); + // make sure we get valid data: + if (ordinal >= 0 && ordinal < OregenPattern.values().length) { + return new GTPacketSendOregenPattern(OregenPattern.values()[ordinal]); + } + // invalid data, default to AXISSYMMETRICAL: + GTLog.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 GTPacketSendOregenPattern(); + } + + @Override + public byte getPacketID() { + return GTPacketTypes.SEND_OREGEN_PATTERN.id; + } + + @Override + public void process(IBlockAccess aWorld) { + GTWorldgenerator.oregenPattern = this.pattern; + } + +} diff --git a/src/main/java/gregtech/api/net/GTPacketSetConfigurationCircuit.java b/src/main/java/gregtech/api/net/GTPacketSetConfigurationCircuit.java new file mode 100644 index 0000000000..8984cea509 --- /dev/null +++ b/src/main/java/gregtech/api/net/GTPacketSetConfigurationCircuit.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.GTUtility; +import gregtech.api.util.ISerializableObject; +import io.netty.buffer.ByteBuf; + +/** + * Client -> Server: Update machine configuration data + */ +public class GTPacketSetConfigurationCircuit extends GTPacketNew { + + protected int mX; + protected short mY; + protected int mZ; + protected int dimId; + + protected ItemStack circuit; + + public GTPacketSetConfigurationCircuit() { + super(true); + } + + public GTPacketSetConfigurationCircuit(IGregTechTileEntity tile, ItemStack circuit) { + this(tile.getXCoord(), tile.getYCoord(), tile.getZCoord(), circuit); + } + + public GTPacketSetConfigurationCircuit(BaseTileEntity tile, ItemStack circuit) { + this(tile.getXCoord(), tile.getYCoord(), tile.getZCoord(), circuit); + } + + public GTPacketSetConfigurationCircuit(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 GTPacketTypes.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 GTPacketNew decode(ByteArrayDataInput aData) { + return new GTPacketSetConfigurationCircuit( + 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 -> GTUtility.areStacksEqual(stack, circuit)) + .findFirst() + .ifPresent(stack -> ((IHasInventory) tile).setInventorySlotContents(machine.getCircuitSlot(), stack)); + } +} diff --git a/src/main/java/gregtech/api/net/GTPacketSound.java b/src/main/java/gregtech/api/net/GTPacketSound.java new file mode 100644 index 0000000000..95f95e641d --- /dev/null +++ b/src/main/java/gregtech/api/net/GTPacketSound.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.GTLog; +import gregtech.api.util.GTUtility; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.ByteBufOutputStream; + +public class GTPacketSound extends GTPacketNew { + + private int mX, mZ; + private short mY; + private String mSoundName; + private float mSoundStrength, mSoundPitch; + + public GTPacketSound() { + super(true); + } + + public GTPacketSound(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(GTLog.err); + } + } + + @Override + public GTPacketNew decode(ByteArrayDataInput aData) { + return new GTPacketSound( + aData.readUTF(), + aData.readFloat(), + aData.readFloat(), + aData.readInt(), + aData.readShort(), + aData.readInt()); + } + + @Override + public void process(IBlockAccess aWorld) { + if (mSoundName != null) { + GTUtility.doSoundAtClient(new ResourceLocation(mSoundName), 1, mSoundStrength, mSoundPitch, mX, mY, mZ); + } + } + + @Override + public byte getPacketID() { + return GTPacketTypes.SOUND.id; + } +} diff --git a/src/main/java/gregtech/api/net/GTPacketTileEntity.java b/src/main/java/gregtech/api/net/GTPacketTileEntity.java new file mode 100644 index 0000000000..eecb16d6da --- /dev/null +++ b/src/main/java/gregtech/api/net/GTPacketTileEntity.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.GTMod; +import gregtech.api.metatileentity.BaseMetaPipeEntity; +import gregtech.api.metatileentity.BaseMetaTileEntity; +import io.netty.buffer.ByteBuf; + +public class GTPacketTileEntity extends GTPacketNew { + + private int mX, mZ, mC0, mC1, mC2, mC3, mC4, mC5; + private short mY, mID, mRID; + private byte mTexture, mTexturePage, mUpdate, mRedstone, mColor; + + public GTPacketTileEntity() { + super(true); + } + + // For multi tiles + public GTPacketTileEntity(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 GTPacketTileEntity(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 GTPacketTileEntity(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 GTPacketNew decode(ByteArrayDataInput aData) { + return new GTPacketTileEntity( + // 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) { + GTMod.GT_FML_LOGGER.error( + "Exception setting tile entity data for tile entity {} at ({}, {}, {})", + tTileEntity, + mX, + mY, + mZ); + } + } + + @Override + public byte getPacketID() { + return GTPacketTypes.TILE_ENTITY.id; + } +} diff --git a/src/main/java/gregtech/api/net/GTPacketToolSwitchMode.java b/src/main/java/gregtech/api/net/GTPacketToolSwitchMode.java new file mode 100644 index 0000000000..57cabcf2bf --- /dev/null +++ b/src/main/java/gregtech/api/net/GTPacketToolSwitchMode.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.MetaGeneratedTool; +import io.netty.buffer.ByteBuf; + +public class GTPacketToolSwitchMode extends GTPacketNew { + + private EntityPlayerMP player; + + public GTPacketToolSwitchMode() { + super(true); + } + + @Override + public byte getPacketID() { + return GTPacketTypes.TOOL_SWITCH_MODE.id; + } + + @Override + public void encode(ByteBuf aOut) { + + } + + @Override + public GTPacketNew decode(ByteArrayDataInput aData) { + return new GTPacketToolSwitchMode(); + } + + @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 MetaGeneratedTool item))) return; + byte maxMode = item.getToolMaxMode(currentItem); + if (maxMode <= 1) return; + byte newMode = (byte) ((MetaGeneratedTool.getToolMode(currentItem) + 1) % maxMode); + MetaGeneratedTool.setToolMode(currentItem, newMode); + player.sendSlotContents(player.inventoryContainer, player.inventory.currentItem, currentItem); + } +} diff --git a/src/main/java/gregtech/api/net/GTPacketTypes.java b/src/main/java/gregtech/api/net/GTPacketTypes.java new file mode 100644 index 0000000000..d635706e68 --- /dev/null +++ b/src/main/java/gregtech/api/net/GTPacketTypes.java @@ -0,0 +1,64 @@ +package gregtech.api.net; + +import java.util.Arrays; + +import gregtech.common.blocks.PacketOres; +import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; + +/** + * Centralized place to keep all the GT packet ID constants + */ +public enum GTPacketTypes { + + TILE_ENTITY(0, new GTPacketTileEntity()), + SOUND(1, new GTPacketSound()), + BLOCK_EVENT(2, new GTPacketBlockEvent()), + ORES(3, new PacketOres()), + POLLUTION(4, new GTPacketPollution()), + CLIENT_PREFERENCE(9, new GTPacketClientPreference()), + SET_CONFIGURATION_CIRCUIT(12, new GTPacketSetConfigurationCircuit()), + UPDATE_ITEM(13, new GTPacketUpdateItem()), + SEND_COVER_DATA(16, new GTPacketSendCoverData()), + REQUEST_COVER_DATA(17, new GTPacketRequestCoverData()), + MULTI_TILE_ENTITY(18, new GTPacketMultiTileEntity(true)), + SEND_OREGEN_PATTERN(19, new GTPacketSendOregenPattern()), + TOOL_SWITCH_MODE(20, new GTPacketToolSwitchMode()), + MUSIC_SYSTEM_DATA(21, new GTPacketMusicSystemData()), + // merge conflict prevention comment, keep a trailing comma above + ; + + static { + // Validate no duplicate IDs + final GTPacketTypes[] types = values(); + final Int2ObjectOpenHashMap foundIds = new Int2ObjectOpenHashMap<>(types.length); + for (GTPacketTypes type : types) { + final GTPacketNew 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 GTPacketNew referencePacket; + + GTPacketTypes(int id, GTPacketNew 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 GTPacketNew[] referencePackets() { + return Arrays.stream(values()) + .map(p -> p.referencePacket) + .toArray(GTPacketNew[]::new); + } +} diff --git a/src/main/java/gregtech/api/net/GTPacketUpdateItem.java b/src/main/java/gregtech/api/net/GTPacketUpdateItem.java new file mode 100644 index 0000000000..54846cdcc9 --- /dev/null +++ b/src/main/java/gregtech/api/net/GTPacketUpdateItem.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 GTPacketUpdateItem extends GTPacketNew { + + private NBTTagCompound tag; + private EntityPlayerMP mPlayer; + + public GTPacketUpdateItem() { + super(true); + } + + public GTPacketUpdateItem(NBTTagCompound tag) { + super(false); + this.tag = tag; + } + + @Override + public byte getPacketID() { + return GTPacketTypes.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 GTPacketNew decode(ByteArrayDataInput aData) { + return new GTPacketUpdateItem(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.java b/src/main/java/gregtech/api/net/GT_Packet.java deleted file mode 100644 index d06ea7d0d3..0000000000 --- a/src/main/java/gregtech/api/net/GT_Packet.java +++ /dev/null @@ -1,59 +0,0 @@ -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 deleted file mode 100644 index 5907b2176b..0000000000 --- a/src/main/java/gregtech/api/net/GT_PacketTypes.java +++ /dev/null @@ -1,64 +0,0 @@ -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 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 deleted file mode 100644 index 9adf583698..0000000000 --- a/src/main/java/gregtech/api/net/GT_Packet_Block_Event.java +++ /dev/null @@ -1,63 +0,0 @@ -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 deleted file mode 100644 index a5fd8a2e08..0000000000 --- a/src/main/java/gregtech/api/net/GT_Packet_ClientPreference.java +++ /dev/null @@ -1,62 +0,0 @@ -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 deleted file mode 100644 index 33cb4f2dcf..0000000000 --- a/src/main/java/gregtech/api/net/GT_Packet_MultiTileEntity.java +++ /dev/null @@ -1,254 +0,0 @@ -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> 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> set = data.stream() - .sorted() - .collect( - HashSet>::new, - HashSet>::add, - HashSet>::addAll); - clearData(); - data.addAll(set); - int features = 0; - for (PacketData data : data) { - features |= 1 << data.getId(); - } - - aOut.writeInt(features); - - for (PacketData 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> set = packet.data.stream() - .sorted() - .collect( - HashSet>::new, - HashSet>::add, - HashSet>::addAll); - packet.clearData(); - packet.data.addAll(set); - for (PacketData 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 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 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 deleted file mode 100644 index 13ebf49205..0000000000 --- a/src/main/java/gregtech/api/net/GT_Packet_MusicSystemData.java +++ /dev/null @@ -1,58 +0,0 @@ -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 deleted file mode 100644 index 41eb1740b3..0000000000 --- a/src/main/java/gregtech/api/net/GT_Packet_New.java +++ /dev/null @@ -1,30 +0,0 @@ -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 deleted file mode 100644 index 9b4a367dc4..0000000000 --- a/src/main/java/gregtech/api/net/GT_Packet_Pollution.java +++ /dev/null @@ -1,47 +0,0 @@ -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 deleted file mode 100644 index bca97b69a5..0000000000 --- a/src/main/java/gregtech/api/net/GT_Packet_RequestCoverData.java +++ /dev/null @@ -1,113 +0,0 @@ -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 deleted file mode 100644 index 268aaab803..0000000000 --- a/src/main/java/gregtech/api/net/GT_Packet_SendCoverData.java +++ /dev/null @@ -1,107 +0,0 @@ -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 deleted file mode 100644 index 8213ee9c71..0000000000 --- a/src/main/java/gregtech/api/net/GT_Packet_SendOregenPattern.java +++ /dev/null @@ -1,56 +0,0 @@ -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 deleted file mode 100644 index 2bfdbca9d2..0000000000 --- a/src/main/java/gregtech/api/net/GT_Packet_SetConfigurationCircuit.java +++ /dev/null @@ -1,110 +0,0 @@ -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 deleted file mode 100644 index 93bfdfd3aa..0000000000 --- a/src/main/java/gregtech/api/net/GT_Packet_Sound.java +++ /dev/null @@ -1,73 +0,0 @@ -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 deleted file mode 100644 index b07277dc00..0000000000 --- a/src/main/java/gregtech/api/net/GT_Packet_TileEntity.java +++ /dev/null @@ -1,157 +0,0 @@ -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 deleted file mode 100644 index c7984d7434..0000000000 --- a/src/main/java/gregtech/api/net/GT_Packet_ToolSwitchMode.java +++ /dev/null @@ -1,52 +0,0 @@ -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 deleted file mode 100644 index 1b8a453234..0000000000 --- a/src/main/java/gregtech/api/net/GT_Packet_UpdateItem.java +++ /dev/null @@ -1,64 +0,0 @@ -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 index 8436a89e9b..3569317b01 100644 --- a/src/main/java/gregtech/api/net/IGT_NetworkHandler.java +++ b/src/main/java/gregtech/api/net/IGT_NetworkHandler.java @@ -8,15 +8,15 @@ import cpw.mods.fml.common.network.NetworkRegistry.TargetPoint; @SuppressWarnings("deprecation") public interface IGT_NetworkHandler { - void sendToPlayer(GT_Packet aPacket, EntityPlayerMP aPlayer); + void sendToPlayer(GTPacket aPacket, EntityPlayerMP aPlayer); - void sendToAllAround(GT_Packet aPacket, TargetPoint aPosition); + void sendToAllAround(GTPacket aPacket, TargetPoint aPosition); - default void sendToAll(GT_Packet aPacket) { + default void sendToAll(GTPacket aPacket) { throw new UnsupportedOperationException("sendToAll not implemented"); } - void sendToServer(GT_Packet aPacket); + void sendToServer(GTPacket aPacket); - void sendPacketToAllPlayersInRange(World aWorld, GT_Packet aPacket, int aX, int aZ); + void sendPacketToAllPlayersInRange(World aWorld, GTPacket aPacket, int aX, int aZ); } -- cgit