diff options
Diffstat (limited to 'src/main/java/gregtech/api/net')
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 |
