From 64d458cb2bb4b805fc90b256018b49eda3cf2fc1 Mon Sep 17 00:00:00 2001 From: miozune Date: Sat, 28 Sep 2024 20:36:46 +0900 Subject: Refactor packets (#3295) Co-authored-by: boubou19 --- src/main/java/bartworks/MainMod.java | 3 - src/main/java/bartworks/common/net/BWNetwork.java | 170 --------------------- .../common/net/CircuitProgrammerPacket.java | 88 ----------- src/main/java/bartworks/common/net/EICPacket.java | 60 -------- .../java/bartworks/common/net/MetaBlockPacket.java | 108 ------------- .../bartworks/common/net/OreDictCachePacket.java | 71 --------- .../bartworks/common/net/PacketBWMetaBlock.java | 108 +++++++++++++ .../bartworks/common/net/PacketBioVatRenderer.java | 99 ++++++++++++ src/main/java/bartworks/common/net/PacketEIC.java | 60 ++++++++ .../bartworks/common/net/PacketOreDictCache.java | 71 +++++++++ .../bartworks/common/net/PacketServerJoined.java | 57 +++++++ .../java/bartworks/common/net/RendererPacket.java | 99 ------------ .../bartworks/common/net/ServerJoinedPacket.java | 57 ------- .../common/tileentities/multis/MTEBioVat.java | 16 +- .../multis/MTEElectricImplosionCompressor.java | 8 +- .../server/EventHandler/ServerEventHandler.java | 11 +- .../material/TileEntityMetaGeneratedBlock.java | 8 +- .../api/multitileentity/base/MultiTileEntity.java | 12 +- src/main/java/gregtech/api/net/GTPacket.java | 40 ++--- .../java/gregtech/api/net/GTPacketBlockEvent.java | 8 +- .../gregtech/api/net/GTPacketClientPreference.java | 8 +- .../gregtech/api/net/GTPacketInfiniteSpraycan.java | 10 +- .../gregtech/api/net/GTPacketMultiTileEntity.java | 10 +- .../gregtech/api/net/GTPacketMusicSystemData.java | 8 +- src/main/java/gregtech/api/net/GTPacketNew.java | 30 ---- .../java/gregtech/api/net/GTPacketPollution.java | 8 +- .../gregtech/api/net/GTPacketRequestCoverData.java | 12 +- .../gregtech/api/net/GTPacketSendCoverData.java | 12 +- .../api/net/GTPacketSendOregenPattern.java | 8 +- .../api/net/GTPacketSetConfigurationCircuit.java | 8 +- src/main/java/gregtech/api/net/GTPacketSound.java | 8 +- .../java/gregtech/api/net/GTPacketTileEntity.java | 8 +- .../gregtech/api/net/GTPacketToolSwitchMode.java | 6 +- src/main/java/gregtech/api/net/GTPacketTypes.java | 24 ++- .../java/gregtech/api/net/GTPacketUpdateItem.java | 8 +- .../java/gregtech/api/net/IGT_NetworkHandler.java | 5 +- src/main/java/gregtech/common/GTNetwork.java | 4 +- .../java/gregtech/common/blocks/PacketOres.java | 10 +- 38 files changed, 518 insertions(+), 823 deletions(-) delete mode 100644 src/main/java/bartworks/common/net/BWNetwork.java delete mode 100644 src/main/java/bartworks/common/net/CircuitProgrammerPacket.java delete mode 100644 src/main/java/bartworks/common/net/EICPacket.java delete mode 100644 src/main/java/bartworks/common/net/MetaBlockPacket.java delete mode 100644 src/main/java/bartworks/common/net/OreDictCachePacket.java create mode 100644 src/main/java/bartworks/common/net/PacketBWMetaBlock.java create mode 100644 src/main/java/bartworks/common/net/PacketBioVatRenderer.java create mode 100644 src/main/java/bartworks/common/net/PacketEIC.java create mode 100644 src/main/java/bartworks/common/net/PacketOreDictCache.java create mode 100644 src/main/java/bartworks/common/net/PacketServerJoined.java delete mode 100644 src/main/java/bartworks/common/net/RendererPacket.java delete mode 100644 src/main/java/bartworks/common/net/ServerJoinedPacket.java delete mode 100644 src/main/java/gregtech/api/net/GTPacketNew.java diff --git a/src/main/java/bartworks/MainMod.java b/src/main/java/bartworks/MainMod.java index 66eec8469b..a321718b17 100644 --- a/src/main/java/bartworks/MainMod.java +++ b/src/main/java/bartworks/MainMod.java @@ -45,7 +45,6 @@ import bartworks.common.loaders.RecipeLoader; import bartworks.common.loaders.RegisterGlassTiers; import bartworks.common.loaders.RegisterServerCommands; import bartworks.common.loaders.StaticRecipeChangeLoaders; -import bartworks.common.net.BWNetwork; import bartworks.server.EventHandler.ServerEventHandler; import bartworks.system.material.CircuitGeneration.CircuitImprintLoader; import bartworks.system.material.CircuitGeneration.CircuitPartLoader; @@ -106,8 +105,6 @@ public final class MainMod { @Mod.Instance(MainMod.MOD_ID) public static MainMod instance; - public static BWNetwork BW_Network_instance = new BWNetwork(); - public MainMod() { } diff --git a/src/main/java/bartworks/common/net/BWNetwork.java b/src/main/java/bartworks/common/net/BWNetwork.java deleted file mode 100644 index 78ab09e367..0000000000 --- a/src/main/java/bartworks/common/net/BWNetwork.java +++ /dev/null @@ -1,170 +0,0 @@ -/* - * Copyright (c) 2018-2020 bartimaeusnek Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in the Software without restriction, - * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following - * conditions: The above copyright notice and this permission notice shall be included in all copies or substantial - * portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, - * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - */ - -package bartworks.common.net; - -import java.util.EnumMap; -import java.util.List; - -import javax.annotation.Nonnull; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.world.World; -import net.minecraft.world.chunk.Chunk; - -import com.google.common.io.ByteArrayDataInput; -import com.google.common.io.ByteStreams; - -import cpw.mods.fml.common.network.FMLEmbeddedChannel; -import cpw.mods.fml.common.network.FMLOutboundHandler; -import cpw.mods.fml.common.network.NetworkRegistry; -import cpw.mods.fml.common.network.internal.FMLProxyPacket; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.server.FMLServerHandler; -import gregtech.api.enums.GTValues; -import gregtech.api.net.GTPacket; -import gregtech.api.net.GTPacketNew; -import gregtech.api.net.IGT_NetworkHandler; -import io.netty.buffer.Unpooled; -import io.netty.channel.ChannelHandler; -import io.netty.channel.ChannelHandlerContext; -import io.netty.channel.SimpleChannelInboundHandler; -import io.netty.handler.codec.MessageToMessageCodec; - -/* - * Original GT File slightly Modified - */ -@SuppressWarnings("deprecation") -@ChannelHandler.Sharable -public class BWNetwork extends MessageToMessageCodec implements IGT_NetworkHandler { - - private final EnumMap mChannel; - private final GTPacketNew[] mSubChannels; - - public BWNetwork() { - this.mChannel = NetworkRegistry.INSTANCE.newChannel("BartWorks", this, new BWNetwork.HandlerShared()); - this.mSubChannels = new GTPacketNew[] { new RendererPacket(), new CircuitProgrammerPacket(), - new MetaBlockPacket(), new OreDictCachePacket(), new ServerJoinedPacket(), new EICPacket() }; - } - - @Override - protected void encode(ChannelHandlerContext aContext, GTPacketNew aPacket, List aOutput) throws Exception { - aOutput.add( - new FMLProxyPacket( - Unpooled.buffer() - .writeByte(aPacket.getPacketID()) - .writeBytes(aPacket.encode()) - .copy(), - aContext.channel() - .attr(NetworkRegistry.FML_CHANNEL) - .get())); - } - - @Override - protected void decode(ChannelHandlerContext aContext, FMLProxyPacket aPacket, List aOutput) - throws Exception { - ByteArrayDataInput aData = ByteStreams.newDataInput( - aPacket.payload() - .array()); - aOutput.add(this.mSubChannels[aData.readByte()].decode(aData)); - } - - @Override - public void sendToPlayer(@Nonnull GTPacket aPacket, @Nonnull EntityPlayerMP aPlayer) { - this.mChannel.get(Side.SERVER) - .attr(FMLOutboundHandler.FML_MESSAGETARGET) - .set(FMLOutboundHandler.OutboundTarget.PLAYER); - this.mChannel.get(Side.SERVER) - .attr(FMLOutboundHandler.FML_MESSAGETARGETARGS) - .set(aPlayer); - this.mChannel.get(Side.SERVER) - .writeAndFlush(aPacket); - } - - public void sendToAllPlayersinWorld(@Nonnull GTPacket aPacket, World world) { - for (String name : FMLServerHandler.instance() - .getServer() - .getAllUsernames()) { - this.mChannel.get(Side.SERVER) - .attr(FMLOutboundHandler.FML_MESSAGETARGET) - .set(FMLOutboundHandler.OutboundTarget.PLAYER); - this.mChannel.get(Side.SERVER) - .attr(FMLOutboundHandler.FML_MESSAGETARGETARGS) - .set(world.getPlayerEntityByName(name)); - this.mChannel.get(Side.SERVER) - .writeAndFlush(aPacket); - } - } - - @Override - public void sendToAllAround(@Nonnull GTPacket aPacket, NetworkRegistry.TargetPoint aPosition) { - this.mChannel.get(Side.SERVER) - .attr(FMLOutboundHandler.FML_MESSAGETARGET) - .set(FMLOutboundHandler.OutboundTarget.ALLAROUNDPOINT); - this.mChannel.get(Side.SERVER) - .attr(FMLOutboundHandler.FML_MESSAGETARGETARGS) - .set(aPosition); - this.mChannel.get(Side.SERVER) - .writeAndFlush(aPacket); - } - - @Override - public void sendToAll(@Nonnull GTPacket aPacket) { - this.mChannel.get(Side.SERVER) - .attr(FMLOutboundHandler.FML_MESSAGETARGET) - .set(FMLOutboundHandler.OutboundTarget.ALL); - this.mChannel.get(Side.SERVER) - .writeAndFlush(aPacket); - } - - @Override - public void sendToServer(@Nonnull GTPacket aPacket) { - this.mChannel.get(Side.CLIENT) - .attr(FMLOutboundHandler.FML_MESSAGETARGET) - .set(FMLOutboundHandler.OutboundTarget.TOSERVER); - this.mChannel.get(Side.CLIENT) - .writeAndFlush(aPacket); - } - - @Override - public void sendPacketToAllPlayersInRange(World aWorld, @Nonnull GTPacket aPacket, int aX, int aZ) { - if (!aWorld.isRemote) { - - for (Object tObject : aWorld.playerEntities) { - if (!(tObject instanceof EntityPlayerMP tPlayer)) { - break; - } - - Chunk tChunk = aWorld.getChunkFromBlockCoords(aX, aZ); - if (tPlayer.getServerForPlayer() - .getPlayerManager() - .isPlayerWatchingChunk(tPlayer, tChunk.xPosition, tChunk.zPosition)) { - this.sendToPlayer(aPacket, tPlayer); - } - } - } - } - - @Sharable - static final class HandlerShared extends SimpleChannelInboundHandler { - - HandlerShared() {} - - @Override - protected void channelRead0(ChannelHandlerContext ctx, GTPacketNew aPacket) throws Exception { - EntityPlayer aPlayer = GTValues.GT.getThePlayer(); - aPacket.process(aPlayer == null ? null : GTValues.GT.getThePlayer().worldObj); - } - } -} diff --git a/src/main/java/bartworks/common/net/CircuitProgrammerPacket.java b/src/main/java/bartworks/common/net/CircuitProgrammerPacket.java deleted file mode 100644 index 998d10cbfa..0000000000 --- a/src/main/java/bartworks/common/net/CircuitProgrammerPacket.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright (c) 2018-2020 bartimaeusnek Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in the Software without restriction, - * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following - * conditions: The above copyright notice and this permission notice shall be included in all copies or substantial - * portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, - * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - */ - -package bartworks.common.net; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.world.IBlockAccess; -import net.minecraft.world.World; -import net.minecraftforge.common.DimensionManager; - -import com.google.common.io.ByteArrayDataInput; - -import bartworks.common.items.ItemCircuitProgrammer; -import gregtech.api.net.GTPacketNew; -import io.netty.buffer.ByteBuf; - -public class CircuitProgrammerPacket extends GTPacketNew { - - private int dimID, playerID; - private byte chipCfg; - private boolean hasChip; - - public CircuitProgrammerPacket() { - super(true); - } - - public CircuitProgrammerPacket(int dimID, int playerID, boolean hasChip, byte chipCfg) { - super(false); - this.dimID = dimID; - this.playerID = playerID; - this.hasChip = hasChip; - this.chipCfg = chipCfg; - } - - @Override - public byte getPacketID() { - return 1; - } - - @Override - public void encode(ByteBuf aOut) { - aOut.writeInt(this.dimID) - .writeInt(this.playerID) - .writeByte(this.hasChip ? this.chipCfg : -1); - } - - @Override - public GTPacketNew decode(ByteArrayDataInput byteArrayDataInput) { - return new CircuitProgrammerPacket( - byteArrayDataInput.readInt(), - byteArrayDataInput.readInt(), - byteArrayDataInput.readByte() > -1, - byteArrayDataInput.readByte()); - } - - @Override - public void process(IBlockAccess iBlockAccess) { - World w = DimensionManager.getWorld(this.dimID); - if (w != null && w.getEntityByID(this.playerID) instanceof EntityPlayer) { - ItemStack stack = ((EntityPlayer) w.getEntityByID(this.playerID)).getHeldItem(); - if (stack != null && stack.stackSize > 0) { - Item item = stack.getItem(); - if (item instanceof ItemCircuitProgrammer) { - NBTTagCompound nbt = stack.getTagCompound(); - nbt.setBoolean("HasChip", this.hasChip); - if (this.hasChip) nbt.setByte("ChipConfig", this.chipCfg); - stack.setTagCompound(nbt); - ((EntityPlayer) w.getEntityByID(this.playerID)).inventory.setInventorySlotContents( - ((EntityPlayer) w.getEntityByID(this.playerID)).inventory.currentItem, - stack); - } - } - } - } -} diff --git a/src/main/java/bartworks/common/net/EICPacket.java b/src/main/java/bartworks/common/net/EICPacket.java deleted file mode 100644 index 9d2414a0e0..0000000000 --- a/src/main/java/bartworks/common/net/EICPacket.java +++ /dev/null @@ -1,60 +0,0 @@ -package bartworks.common.net; - -import net.minecraft.tileentity.TileEntity; -import net.minecraft.world.IBlockAccess; - -import com.google.common.io.ByteArrayDataInput; - -import bartworks.API.SideReference; -import bartworks.common.tileentities.multis.MTEElectricImplosionCompressor; -import bartworks.util.Coords; -import gregtech.api.interfaces.metatileentity.IMetaTileEntity; -import gregtech.api.interfaces.tileentity.IGregTechTileEntity; -import gregtech.api.net.GTPacketNew; -import io.netty.buffer.ByteBuf; - -public class EICPacket extends GTPacketNew { - - private Coords coords; - private boolean bool; - - public EICPacket() { - super(true); - } - - public EICPacket(Coords coords, boolean bool) { - super(false); - this.coords = coords; - this.bool = bool; - } - - @Override - public byte getPacketID() { - return 5; - } - - @Override - public void encode(ByteBuf aOut) { - aOut.writeInt(this.coords.x); - aOut.writeInt(this.coords.y); - aOut.writeInt(this.coords.z); - aOut.writeBoolean(this.bool); - } - - @Override - public GTPacketNew decode(ByteArrayDataInput aData) { - return new EICPacket(new Coords(aData.readInt(), aData.readInt(), aData.readInt()), aData.readBoolean()); - } - - @Override - public void process(IBlockAccess aWorld) { - if (SideReference.Side.Client) { - TileEntity te = aWorld.getTileEntity(this.coords.x, this.coords.y, this.coords.z); - if (!(te instanceof IGregTechTileEntity)) return; - IMetaTileEntity mte = ((IGregTechTileEntity) te).getMetaTileEntity(); - if (!(mte instanceof MTEElectricImplosionCompressor)) return; - if (this.bool && !((IGregTechTileEntity) te).hasMufflerUpgrade()) - ((IGregTechTileEntity) te).addMufflerUpgrade(); - } - } -} diff --git a/src/main/java/bartworks/common/net/MetaBlockPacket.java b/src/main/java/bartworks/common/net/MetaBlockPacket.java deleted file mode 100644 index ee8ab8231a..0000000000 --- a/src/main/java/bartworks/common/net/MetaBlockPacket.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Copyright (c) 2018-2020 bartimaeusnek Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in the Software without restriction, - * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following - * conditions: The above copyright notice and this permission notice shall be included in all copies or substantial - * portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, - * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - */ - -package bartworks.common.net; - -import java.nio.ByteBuffer; - -import net.minecraft.tileentity.TileEntity; -import net.minecraft.world.IBlockAccess; -import net.minecraft.world.World; - -import com.google.common.io.ByteArrayDataInput; - -import bartworks.MainMod; -import bartworks.system.material.TileEntityMetaGeneratedBlock; -import bartworks.util.MurmurHash3; -import gregtech.api.net.GTPacketNew; -import io.netty.buffer.ByteBuf; - -public class MetaBlockPacket extends GTPacketNew { - - int x; - short y; - int z; - short meta; - - public MetaBlockPacket(int x, int y, int z, int meta) { - super(false); - this.x = x; - this.y = (short) y; - this.z = z; - this.meta = (short) meta; - } - - public MetaBlockPacket() { - super(true); - } - - @Override - public byte getPacketID() { - return 2; - } - - @Override - public void encode(ByteBuf aOut) { - int hash = MurmurHash3.murmurhash3_x86_32( - ByteBuffer.allocate(12) - .putInt(this.x) - .putInt(this.z) - .putShort(this.y) - .putShort(this.meta) - .array(), - 0, - 12, - 31); - aOut.writeInt(this.x) - .writeInt(this.z) - .writeShort(this.y) - .writeShort(this.meta) - .writeInt(hash); - } - - @Override - public GTPacketNew decode(ByteArrayDataInput byteArrayDataInput) { - this.x = byteArrayDataInput.readInt(); - this.z = byteArrayDataInput.readInt(); - this.y = byteArrayDataInput.readShort(); - this.meta = byteArrayDataInput.readShort(); - MetaBlockPacket todecode = new MetaBlockPacket(this.x, this.y, this.z, this.meta); - if (byteArrayDataInput.readInt() != MurmurHash3.murmurhash3_x86_32( - ByteBuffer.allocate(12) - .putInt(this.x) - .putInt(this.z) - .putShort(this.y) - .putShort(this.meta) - .array(), - 0, - 12, - 31)) { - MainMod.LOGGER.error("PACKET HASH DOES NOT MATCH!"); - return null; - } - return todecode; - } - - @Override - public void process(IBlockAccess iBlockAccess) { - if (iBlockAccess != null) { - TileEntity tTileEntity = iBlockAccess.getTileEntity(this.x, this.y, this.z); - if (tTileEntity instanceof TileEntityMetaGeneratedBlock) { - ((TileEntityMetaGeneratedBlock) tTileEntity).mMetaData = this.meta; - } - if (iBlockAccess instanceof World && ((World) iBlockAccess).isRemote) { - ((World) iBlockAccess).markBlockForUpdate(this.x, this.y, this.z); - } - } - } -} diff --git a/src/main/java/bartworks/common/net/OreDictCachePacket.java b/src/main/java/bartworks/common/net/OreDictCachePacket.java deleted file mode 100644 index b8cda117ac..0000000000 --- a/src/main/java/bartworks/common/net/OreDictCachePacket.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (c) 2018-2020 bartimaeusnek Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in the Software without restriction, - * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following - * conditions: The above copyright notice and this permission notice shall be included in all copies or substantial - * portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, - * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - */ - -package bartworks.common.net; - -import java.util.HashSet; - -import net.minecraft.world.IBlockAccess; - -import com.google.common.io.ByteArrayDataInput; - -import bartworks.system.oredict.OreDictHandler; -import bartworks.util.Pair; -import gregtech.api.net.GTPacketNew; -import io.netty.buffer.ByteBuf; - -public class OreDictCachePacket extends GTPacketNew { - - private HashSet> hashSet = new HashSet<>(); - - public OreDictCachePacket() { - super(true); - } - - public OreDictCachePacket(HashSet> set) { - super(false); - this.hashSet = set; - } - - @Override - public byte getPacketID() { - return 3; - } - - @Override - public void encode(ByteBuf aOut) { - int size = this.hashSet.size(); - aOut.writeInt(size); - for (Pair p : this.hashSet) { - aOut.writeInt(p.getKey()) - .writeShort(p.getValue()); - } - } - - @Override - public GTPacketNew decode(ByteArrayDataInput byteArrayDataInput) { - int size = byteArrayDataInput.readInt(); - for (int i = 0; i < size; i++) { - this.hashSet.add(new Pair<>(byteArrayDataInput.readInt(), byteArrayDataInput.readShort())); - } - return new OreDictCachePacket(this.hashSet); - } - - @Override - public void process(IBlockAccess iBlockAccess) { - OreDictHandler.getNonBWCache() - .clear(); - OreDictHandler.getNonBWCache() - .addAll(this.hashSet); - } -} diff --git a/src/main/java/bartworks/common/net/PacketBWMetaBlock.java b/src/main/java/bartworks/common/net/PacketBWMetaBlock.java new file mode 100644 index 0000000000..15af82903d --- /dev/null +++ b/src/main/java/bartworks/common/net/PacketBWMetaBlock.java @@ -0,0 +1,108 @@ +/* + * Copyright (c) 2018-2020 bartimaeusnek Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following + * conditions: The above copyright notice and this permission notice shall be included in all copies or substantial + * portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +package bartworks.common.net; + +import java.nio.ByteBuffer; + +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.IBlockAccess; +import net.minecraft.world.World; + +import com.google.common.io.ByteArrayDataInput; + +import bartworks.MainMod; +import bartworks.system.material.TileEntityMetaGeneratedBlock; +import bartworks.util.MurmurHash3; +import gregtech.api.net.GTPacket; +import io.netty.buffer.ByteBuf; + +public class PacketBWMetaBlock extends GTPacket { + + int x; + short y; + int z; + short meta; + + public PacketBWMetaBlock(int x, int y, int z, int meta) { + super(); + this.x = x; + this.y = (short) y; + this.z = z; + this.meta = (short) meta; + } + + public PacketBWMetaBlock() { + super(); + } + + @Override + public byte getPacketID() { + return 24; + } + + @Override + public void encode(ByteBuf aOut) { + int hash = MurmurHash3.murmurhash3_x86_32( + ByteBuffer.allocate(12) + .putInt(this.x) + .putInt(this.z) + .putShort(this.y) + .putShort(this.meta) + .array(), + 0, + 12, + 31); + aOut.writeInt(this.x) + .writeInt(this.z) + .writeShort(this.y) + .writeShort(this.meta) + .writeInt(hash); + } + + @Override + public GTPacket decode(ByteArrayDataInput byteArrayDataInput) { + this.x = byteArrayDataInput.readInt(); + this.z = byteArrayDataInput.readInt(); + this.y = byteArrayDataInput.readShort(); + this.meta = byteArrayDataInput.readShort(); + PacketBWMetaBlock todecode = new PacketBWMetaBlock(this.x, this.y, this.z, this.meta); + if (byteArrayDataInput.readInt() != MurmurHash3.murmurhash3_x86_32( + ByteBuffer.allocate(12) + .putInt(this.x) + .putInt(this.z) + .putShort(this.y) + .putShort(this.meta) + .array(), + 0, + 12, + 31)) { + MainMod.LOGGER.error("PACKET HASH DOES NOT MATCH!"); + return null; + } + return todecode; + } + + @Override + public void process(IBlockAccess iBlockAccess) { + if (iBlockAccess != null) { + TileEntity tTileEntity = iBlockAccess.getTileEntity(this.x, this.y, this.z); + if (tTileEntity instanceof TileEntityMetaGeneratedBlock) { + ((TileEntityMetaGeneratedBlock) tTileEntity).mMetaData = this.meta; + } + if (iBlockAccess instanceof World && ((World) iBlockAccess).isRemote) { + ((World) iBlockAccess).markBlockForUpdate(this.x, this.y, this.z); + } + } + } +} diff --git a/src/main/java/bartworks/common/net/PacketBioVatRenderer.java b/src/main/java/bartworks/common/net/PacketBioVatRenderer.java new file mode 100644 index 0000000000..936ee6fc4f --- /dev/null +++ b/src/main/java/bartworks/common/net/PacketBioVatRenderer.java @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2018-2020 bartimaeusnek Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following + * conditions: The above copyright notice and this permission notice shall be included in all copies or substantial + * portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +package bartworks.common.net; + +import net.minecraft.world.IBlockAccess; + +import com.google.common.io.ByteArrayDataInput; + +import bartworks.API.SideReference; +import bartworks.MainMod; +import bartworks.common.tileentities.multis.MTEBioVat; +import bartworks.util.BWColorUtil; +import bartworks.util.Coords; +import gregtech.api.net.GTPacket; +import io.netty.buffer.ByteBuf; + +public class PacketBioVatRenderer extends GTPacket { + + private Coords coords; + private int integer; + private byte removal; + + public PacketBioVatRenderer() { + super(); + } + + public PacketBioVatRenderer(Coords coords, int integer, boolean removal) { + super(); + this.coords = coords; + this.integer = integer; + this.removal = (byte) (removal ? 1 : 0); + } + + @Override + public byte getPacketID() { + return 23; + } + + @Override + public void encode(ByteBuf aOut) { + byte r = (byte) (this.integer >> 16 & 0xFF); + byte g = (byte) (this.integer >> 8 & 0xFF); + byte b = (byte) (this.integer & 0xFF); + byte checksum = (byte) (this.coords.x % 25 + this.coords.y % 25 + + this.coords.z % 25 + + this.coords.wID % 25 + + this.integer % 25 + + this.removal); + aOut.writeInt(this.coords.x) + .writeShort(this.coords.y) + .writeInt(this.coords.z) + .writeInt(this.coords.wID) + .writeByte(r) + .writeByte(g) + .writeByte(b) + .writeByte(this.removal) + .writeByte(checksum); + } + + @Override + public GTPacket decode(ByteArrayDataInput dataInput) { + this.coords = new Coords(dataInput.readInt(), dataInput.readShort(), dataInput.readInt(), dataInput.readInt()); + this.integer = BWColorUtil + .getColorFromRGBArray(new int[] { dataInput.readByte(), dataInput.readByte(), dataInput.readByte() }); + this.removal = dataInput.readByte(); + + byte checksum = (byte) (this.coords.x % 25 + this.coords.y % 25 + + this.coords.z % 25 + + this.coords.wID % 25 + + this.integer % 25 + + this.removal); + + if (checksum != dataInput.readByte()) { + MainMod.LOGGER.error("BW Packet was corrupted or modified!"); + return null; + } + + return new PacketBioVatRenderer(this.coords, this.integer, this.removal == 1); + } + + @Override + public void process(IBlockAccess iBlockAccess) { + if (SideReference.Side.Client) { + if (this.removal == 0) MTEBioVat.staticColorMap.put(this.coords, this.integer); + else MTEBioVat.staticColorMap.remove(this.coords); + } + } +} diff --git a/src/main/java/bartworks/common/net/PacketEIC.java b/src/main/java/bartworks/common/net/PacketEIC.java new file mode 100644 index 0000000000..813cc1a07d --- /dev/null +++ b/src/main/java/bartworks/common/net/PacketEIC.java @@ -0,0 +1,60 @@ +package bartworks.common.net; + +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.IBlockAccess; + +import com.google.common.io.ByteArrayDataInput; + +import bartworks.API.SideReference; +import bartworks.common.tileentities.multis.MTEElectricImplosionCompressor; +import bartworks.util.Coords; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.net.GTPacket; +import io.netty.buffer.ByteBuf; + +public class PacketEIC extends GTPacket { + + private Coords coords; + private boolean bool; + + public PacketEIC() { + super(); + } + + public PacketEIC(Coords coords, boolean bool) { + super(); + this.coords = coords; + this.bool = bool; + } + + @Override + public byte getPacketID() { + return 27; + } + + @Override + public void encode(ByteBuf aOut) { + aOut.writeInt(this.coords.x); + aOut.writeInt(this.coords.y); + aOut.writeInt(this.coords.z); + aOut.writeBoolean(this.bool); + } + + @Override + public GTPacket decode(ByteArrayDataInput aData) { + return new PacketEIC(new Coords(aData.readInt(), aData.readInt(), aData.readInt()), aData.readBoolean()); + } + + @Override + public void process(IBlockAccess aWorld) { + if (SideReference.Side.Client) { + TileEntity te = aWorld.getTileEntity(this.coords.x, this.coords.y, this.coords.z); + if (!(te instanceof IGregTechTileEntity)) return; + IMetaTileEntity mte = ((IGregTechTileEntity) te).getMetaTileEntity(); + if (!(mte instanceof MTEElectricImplosionCompressor)) return; + if (this.bool && !((IGregTechTileEntity) te).hasMufflerUpgrade()) + ((IGregTechTileEntity) te).addMufflerUpgrade(); + } + } +} diff --git a/src/main/java/bartworks/common/net/PacketOreDictCache.java b/src/main/java/bartworks/common/net/PacketOreDictCache.java new file mode 100644 index 0000000000..14b58faae7 --- /dev/null +++ b/src/main/java/bartworks/common/net/PacketOreDictCache.java @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2018-2020 bartimaeusnek Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following + * conditions: The above copyright notice and this permission notice shall be included in all copies or substantial + * portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +package bartworks.common.net; + +import java.util.HashSet; + +import net.minecraft.world.IBlockAccess; + +import com.google.common.io.ByteArrayDataInput; + +import bartworks.system.oredict.OreDictHandler; +import bartworks.util.Pair; +import gregtech.api.net.GTPacket; +import io.netty.buffer.ByteBuf; + +public class PacketOreDictCache extends GTPacket { + + private HashSet> hashSet = new HashSet<>(); + + public PacketOreDictCache() { + super(); + } + + public PacketOreDictCache(HashSet> set) { + super(); + this.hashSet = set; + } + + @Override + public byte getPacketID() { + return 25; + } + + @Override + public void encode(ByteBuf aOut) { + int size = this.hashSet.size(); + aOut.writeInt(size); + for (Pair p : this.hashSet) { + aOut.writeInt(p.getKey()) + .writeShort(p.getValue()); + } + } + + @Override + public GTPacket decode(ByteArrayDataInput byteArrayDataInput) { + int size = byteArrayDataInput.readInt(); + for (int i = 0; i < size; i++) { + this.hashSet.add(new Pair<>(byteArrayDataInput.readInt(), byteArrayDataInput.readShort())); + } + return new PacketOreDictCache(this.hashSet); + } + + @Override + public void process(IBlockAccess iBlockAccess) { + OreDictHandler.getNonBWCache() + .clear(); + OreDictHandler.getNonBWCache() + .addAll(this.hashSet); + } +} diff --git a/src/main/java/bartworks/common/net/PacketServerJoined.java b/src/main/java/bartworks/common/net/PacketServerJoined.java new file mode 100644 index 0000000000..1c20996552 --- /dev/null +++ b/src/main/java/bartworks/common/net/PacketServerJoined.java @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2018-2020 bartimaeusnek Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following + * conditions: The above copyright notice and this permission notice shall be included in all copies or substantial + * portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +package bartworks.common.net; + +import net.minecraft.world.IBlockAccess; + +import com.google.common.io.ByteArrayDataInput; + +import bartworks.MainMod; +import gregtech.api.net.GTPacket; +import io.netty.buffer.ByteBuf; + +public class PacketServerJoined extends GTPacket { + + private byte config; + + public PacketServerJoined() { + super(); + } + + public PacketServerJoined(Object obj) { + super(); + this.config = 0; + } + + @Override + public byte getPacketID() { + return 26; + } + + @Override + public void encode(ByteBuf aOut) { + aOut.writeByte(this.config); + } + + @Override + public GTPacket decode(ByteArrayDataInput byteArrayDataInput) { + this.config = byteArrayDataInput.readByte(); + return this; + } + + @Override + public void process(IBlockAccess iBlockAccess) { + MainMod.runOnPlayerJoined(false, false); + } +} diff --git a/src/main/java/bartworks/common/net/RendererPacket.java b/src/main/java/bartworks/common/net/RendererPacket.java deleted file mode 100644 index f4f03c3584..0000000000 --- a/src/main/java/bartworks/common/net/RendererPacket.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright (c) 2018-2020 bartimaeusnek Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in the Software without restriction, - * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following - * conditions: The above copyright notice and this permission notice shall be included in all copies or substantial - * portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, - * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - */ - -package bartworks.common.net; - -import net.minecraft.world.IBlockAccess; - -import com.google.common.io.ByteArrayDataInput; - -import bartworks.API.SideReference; -import bartworks.MainMod; -import bartworks.common.tileentities.multis.MTEBioVat; -import bartworks.util.BWColorUtil; -import bartworks.util.Coords; -import gregtech.api.net.GTPacketNew; -import io.netty.buffer.ByteBuf; - -public class RendererPacket extends GTPacketNew { - - private Coords coords; - private int integer; - private byte removal; - - public RendererPacket() { - super(true); - } - - public RendererPacket(Coords coords, int integer, boolean removal) { - super(false); - this.coords = coords; - this.integer = integer; - this.removal = (byte) (removal ? 1 : 0); - } - - @Override - public byte getPacketID() { - return 0; - } - - @Override - public void encode(ByteBuf aOut) { - byte r = (byte) (this.integer >> 16 & 0xFF); - byte g = (byte) (this.integer >> 8 & 0xFF); - byte b = (byte) (this.integer & 0xFF); - byte checksum = (byte) (this.coords.x % 25 + this.coords.y % 25 - + this.coords.z % 25 - + this.coords.wID % 25 - + this.integer % 25 - + this.removal); - aOut.writeInt(this.coords.x) - .writeShort(this.coords.y) - .writeInt(this.coords.z) - .writeInt(this.coords.wID) - .writeByte(r) - .writeByte(g) - .writeByte(b) - .writeByte(this.removal) - .writeByte(checksum); - } - - @Override - public GTPacketNew decode(ByteArrayDataInput dataInput) { - this.coords = new Coords(dataInput.readInt(), dataInput.readShort(), dataInput.readInt(), dataInput.readInt()); - this.integer = BWColorUtil - .getColorFromRGBArray(new int[] { dataInput.readByte(), dataInput.readByte(), dataInput.readByte() }); - this.removal = dataInput.readByte(); - - byte checksum = (byte) (this.coords.x % 25 + this.coords.y % 25 - + this.coords.z % 25 - + this.coords.wID % 25 - + this.integer % 25 - + this.removal); - - if (checksum != dataInput.readByte()) { - MainMod.LOGGER.error("BW Packet was corrupted or modified!"); - return null; - } - - return new RendererPacket(this.coords, this.integer, this.removal == 1); - } - - @Override - public void process(IBlockAccess iBlockAccess) { - if (SideReference.Side.Client) { - if (this.removal == 0) MTEBioVat.staticColorMap.put(this.coords, this.integer); - else MTEBioVat.staticColorMap.remove(this.coords); - } - } -} diff --git a/src/main/java/bartworks/common/net/ServerJoinedPacket.java b/src/main/java/bartworks/common/net/ServerJoinedPacket.java deleted file mode 100644 index 8c6b89f28f..0000000000 --- a/src/main/java/bartworks/common/net/ServerJoinedPacket.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (c) 2018-2020 bartimaeusnek Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in the Software without restriction, - * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following - * conditions: The above copyright notice and this permission notice shall be included in all copies or substantial - * portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, - * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - */ - -package bartworks.common.net; - -import net.minecraft.world.IBlockAccess; - -import com.google.common.io.ByteArrayDataInput; - -import bartworks.MainMod; -import gregtech.api.net.GTPacketNew; -import io.netty.buffer.ByteBuf; - -public class ServerJoinedPacket extends GTPacketNew { - - private byte config; - - ServerJoinedPacket() { - super(true); - } - - public ServerJoinedPacket(Object obj) { - super(false); - this.config = 0; - } - - @Override - public byte getPacketID() { - return 4; - } - - @Override - public void encode(ByteBuf aOut) { - aOut.writeByte(this.config); - } - - @Override - public GTPacketNew decode(ByteArrayDataInput byteArrayDataInput) { - this.config = byteArrayDataInput.readByte(); - return this; - } - - @Override - public void process(IBlockAccess iBlockAccess) { - MainMod.runOnPlayerJoined(false, false); - } -} diff --git a/src/main/java/bartworks/common/tileentities/multis/MTEBioVat.java b/src/main/java/bartworks/common/tileentities/multis/MTEBioVat.java index b3d4347616..88c5888878 100644 --- a/src/main/java/bartworks/common/tileentities/multis/MTEBioVat.java +++ b/src/main/java/bartworks/common/tileentities/multis/MTEBioVat.java @@ -57,11 +57,10 @@ import com.gtnewhorizon.structurelib.structure.StructureDefinition; import bartworks.API.SideReference; import bartworks.API.recipe.BartWorksRecipeMaps; -import bartworks.MainMod; import bartworks.common.configs.Configuration; import bartworks.common.items.ItemLabParts; import bartworks.common.loaders.FluidLoader; -import bartworks.common.net.RendererPacket; +import bartworks.common.net.PacketBioVatRenderer; import bartworks.common.tileentities.tiered.GT_MetaTileEntity_RadioHatch; import bartworks.util.BWUtil; import bartworks.util.BioCulture; @@ -69,6 +68,7 @@ import bartworks.util.Coords; import bartworks.util.MathUtils; import bartworks.util.ResultWrongSievert; import gregtech.api.GregTechAPI; +import gregtech.api.enums.GTValues; import gregtech.api.enums.Textures; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; @@ -390,10 +390,10 @@ public class MTEBioVat extends MTEEnhancedMultiBlockBase implements I lCulture == null ? BioCulture.NULLCULTURE.getColorRGB() : lCulture.getColorRGB()); if (SideReference.Side.Server) { - MainMod.BW_Network_instance.sendPacketToAllPlayersInRange( + GTValues.NW.sendPacketToAllPlayersInRange( this.getBaseMetaTileEntity() .getWorld(), - new RendererPacket( + new PacketBioVatRenderer( new Coords( xDir + x + this.getBaseMetaTileEntity() @@ -411,10 +411,10 @@ public class MTEBioVat extends MTEEnhancedMultiBlockBase implements I .getXCoord(), this.getBaseMetaTileEntity() .getZCoord()); - MainMod.BW_Network_instance.sendPacketToAllPlayersInRange( + GTValues.NW.sendPacketToAllPlayersInRange( this.getBaseMetaTileEntity() .getWorld(), - new RendererPacket( + new PacketBioVatRenderer( new Coords( xDir + x + this.getBaseMetaTileEntity() @@ -703,10 +703,10 @@ public class MTEBioVat extends MTEEnhancedMultiBlockBase implements I for (int x = -1; x < 2; x++) { for (int y = 1; y < 3; y++) { for (int z = -1; z < 2; z++) { - MainMod.BW_Network_instance.sendPacketToAllPlayersInRange( + GTValues.NW.sendPacketToAllPlayersInRange( this.getBaseMetaTileEntity() .getWorld(), - new RendererPacket( + new PacketBioVatRenderer( new Coords( xDir + x + this.getBaseMetaTileEntity() diff --git a/src/main/java/bartworks/common/tileentities/multis/MTEElectricImplosionCompressor.java b/src/main/java/bartworks/common/tileentities/multis/MTEElectricImplosionCompressor.java index 1339c11095..76cf946f85 100644 --- a/src/main/java/bartworks/common/tileentities/multis/MTEElectricImplosionCompressor.java +++ b/src/main/java/bartworks/common/tileentities/multis/MTEElectricImplosionCompressor.java @@ -65,15 +65,15 @@ import com.gtnewhorizon.structurelib.structure.StructureDefinition; import com.gtnewhorizon.structurelib.structure.StructureUtility; import bartworks.API.recipe.BartWorksRecipeMaps; -import bartworks.MainMod; import bartworks.client.renderer.EICPistonVisualizer; import bartworks.common.configs.Configuration; -import bartworks.common.net.EICPacket; +import bartworks.common.net.PacketEIC; import bartworks.util.Coords; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import fox.spiteful.avaritia.blocks.LudicrousBlocks; import gregtech.api.GregTechAPI; +import gregtech.api.enums.GTValues; import gregtech.api.enums.Mods; import gregtech.api.enums.SoundResource; import gregtech.api.enums.Textures; @@ -352,9 +352,9 @@ public class MTEElectricImplosionCompressor extends MTEExtendedPowerMultiBlockBa if (pistonEnabled && aBaseMetaTileEntity.isActive() && aTick % 20 == 0) { if (aBaseMetaTileEntity.isClientSide()) this.animatePiston(aBaseMetaTileEntity); - else if (aBaseMetaTileEntity.hasMufflerUpgrade()) MainMod.BW_Network_instance.sendPacketToAllPlayersInRange( + else if (aBaseMetaTileEntity.hasMufflerUpgrade()) GTValues.NW.sendPacketToAllPlayersInRange( aBaseMetaTileEntity.getWorld(), - new EICPacket( + new PacketEIC( new Coords( aBaseMetaTileEntity.getXCoord(), aBaseMetaTileEntity.getYCoord(), diff --git a/src/main/java/bartworks/server/EventHandler/ServerEventHandler.java b/src/main/java/bartworks/server/EventHandler/ServerEventHandler.java index 2a1ba2b626..5351824c7c 100644 --- a/src/main/java/bartworks/server/EventHandler/ServerEventHandler.java +++ b/src/main/java/bartworks/server/EventHandler/ServerEventHandler.java @@ -19,14 +19,14 @@ import net.minecraftforge.event.entity.EntityJoinWorldEvent; import net.minecraftforge.oredict.OreDictionary; import bartworks.API.SideReference; -import bartworks.MainMod; -import bartworks.common.net.OreDictCachePacket; -import bartworks.common.net.ServerJoinedPacket; +import bartworks.common.net.PacketOreDictCache; +import bartworks.common.net.PacketServerJoined; import bartworks.system.material.Werkstoff; import bartworks.system.oredict.OreDictHandler; import cpw.mods.fml.common.eventhandler.EventPriority; import cpw.mods.fml.common.eventhandler.SubscribeEvent; import cpw.mods.fml.common.gameevent.TickEvent; +import gregtech.api.enums.GTValues; import gregtech.api.enums.OrePrefixes; import gregtech.api.util.GTOreDictUnificator; @@ -36,9 +36,8 @@ public class ServerEventHandler { @SubscribeEvent(priority = EventPriority.LOWEST) public void EntityJoinWorldEvent(EntityJoinWorldEvent event) { if (event == null || !(event.entity instanceof EntityPlayerMP) || !SideReference.Side.Server) return; - MainMod.BW_Network_instance - .sendToPlayer(new OreDictCachePacket(OreDictHandler.getNonBWCache()), (EntityPlayerMP) event.entity); - MainMod.BW_Network_instance.sendToPlayer(new ServerJoinedPacket(null), (EntityPlayerMP) event.entity); + GTValues.NW.sendToPlayer(new PacketOreDictCache(OreDictHandler.getNonBWCache()), (EntityPlayerMP) event.entity); + GTValues.NW.sendToPlayer(new PacketServerJoined(null), (EntityPlayerMP) event.entity); } // FMLCommonHandler.instance().bus() diff --git a/src/main/java/bartworks/system/material/TileEntityMetaGeneratedBlock.java b/src/main/java/bartworks/system/material/TileEntityMetaGeneratedBlock.java index c37613aa17..5fe9a70599 100644 --- a/src/main/java/bartworks/system/material/TileEntityMetaGeneratedBlock.java +++ b/src/main/java/bartworks/system/material/TileEntityMetaGeneratedBlock.java @@ -22,8 +22,8 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.Packet; import net.minecraft.tileentity.TileEntity; -import bartworks.MainMod; -import bartworks.common.net.MetaBlockPacket; +import bartworks.common.net.PacketBWMetaBlock; +import gregtech.api.enums.GTValues; import gregtech.api.interfaces.tileentity.ITexturedTileEntity; public abstract class TileEntityMetaGeneratedBlock extends TileEntity implements ITexturedTileEntity { @@ -49,9 +49,9 @@ public abstract class TileEntityMetaGeneratedBlock extends TileEntity implements @Override public Packet getDescriptionPacket() { - if (!this.worldObj.isRemote) MainMod.BW_Network_instance.sendPacketToAllPlayersInRange( + if (!this.worldObj.isRemote) GTValues.NW.sendPacketToAllPlayersInRange( this.worldObj, - new MetaBlockPacket(this.xCoord, (short) this.yCoord, this.zCoord, this.mMetaData), + new PacketBWMetaBlock(this.xCoord, (short) this.yCoord, this.zCoord, this.mMetaData), this.xCoord, this.zCoord); return null; diff --git a/src/main/java/gregtech/api/multitileentity/base/MultiTileEntity.java b/src/main/java/gregtech/api/multitileentity/base/MultiTileEntity.java index 24163f9c20..5ca30b6df6 100644 --- a/src/main/java/gregtech/api/multitileentity/base/MultiTileEntity.java +++ b/src/main/java/gregtech/api/multitileentity/base/MultiTileEntity.java @@ -52,8 +52,8 @@ import gregtech.api.multitileentity.MultiTileEntityClassContainer; import gregtech.api.multitileentity.MultiTileEntityRegistry; import gregtech.api.multitileentity.interfaces.IMultiTileEntity; import gregtech.api.multitileentity.interfaces.SyncedMultiTileEntity; +import gregtech.api.net.GTPacket; import gregtech.api.net.GTPacketMultiTileEntity; -import gregtech.api.net.GTPacketNew; import gregtech.api.net.data.CommonData; import gregtech.api.net.data.CoordinateData; import gregtech.api.net.data.MultiTileEntityData; @@ -105,9 +105,9 @@ public abstract class MultiTileEntity extends CoverableTileEntity private UUID ownerUUID = GTUtility.defaultUuid; private boolean lockUpgrade = false; - private final GTPacketMultiTileEntity fullPacket = new GTPacketMultiTileEntity(false); - private final GTPacketMultiTileEntity timedPacket = new GTPacketMultiTileEntity(false); - private final GTPacketMultiTileEntity graphicPacket = new GTPacketMultiTileEntity(false); + private final GTPacketMultiTileEntity fullPacket = new GTPacketMultiTileEntity(); + private final GTPacketMultiTileEntity timedPacket = new GTPacketMultiTileEntity(); + private final GTPacketMultiTileEntity graphicPacket = new GTPacketMultiTileEntity(); public MultiTileEntity(boolean isTicking) { this.isTicking = isTicking; @@ -1035,14 +1035,14 @@ public abstract class MultiTileEntity extends CoverableTileEntity */ public GTPacketMultiTileEntity getClientDataPacket() { - final GTPacketMultiTileEntity packet = new GTPacketMultiTileEntity(false); + final GTPacketMultiTileEntity packet = new GTPacketMultiTileEntity(); return packet; } @Override public void sendClientData(EntityPlayerMP aPlayer) { if (worldObj == null || worldObj.isRemote) return; - final GTPacketNew tPacket = getClientDataPacket(); + final GTPacket tPacket = getClientDataPacket(); if (aPlayer == null) { GTValues.NW.sendPacketToAllPlayersInRange(worldObj, tPacket, getXCoord(), getZCoord()); } else { diff --git a/src/main/java/gregtech/api/net/GTPacket.java b/src/main/java/gregtech/api/net/GTPacket.java index 1d2de3303b..68e08ab304 100644 --- a/src/main/java/gregtech/api/net/GTPacket.java +++ b/src/main/java/gregtech/api/net/GTPacket.java @@ -7,53 +7,35 @@ 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) { - // - } + public GTPacket() {} /** - * I use constant IDs instead of Dynamic ones, since that is much more fail safe - * - * @return a Packet ID for this Class + * Unique ID of this packet. */ 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}. + * Encode the data into given byte buffer. */ - public void encode(ByteBuf aOut) { - throw new UnsupportedOperationException(); - } + public abstract void encode(ByteBuf buffer); /** - * @return encoded byte Stream + * Decode byte buffer into packet object. */ - public abstract GTPacket decode(ByteArrayDataInput aData); + public abstract GTPacket decode(ByteArrayDataInput buffer); /** - * Process the packet + * Process the received packet. * - * @param aWorld null if message is received on server side, the client world if message is received on client side + * @param world null if message is received on server side, the client world if message is received on client side */ - public abstract void process(IBlockAccess aWorld); + public abstract void process(IBlockAccess world); /** * This will be called just before {@link #process(IBlockAccess)} to inform the handler about the source and type of - * connection + * connection. */ - public void setINetHandler(INetHandler aHandler) {} + public void setINetHandler(INetHandler handler) {} } diff --git a/src/main/java/gregtech/api/net/GTPacketBlockEvent.java b/src/main/java/gregtech/api/net/GTPacketBlockEvent.java index a2164f4f07..1e4e942bf2 100644 --- a/src/main/java/gregtech/api/net/GTPacketBlockEvent.java +++ b/src/main/java/gregtech/api/net/GTPacketBlockEvent.java @@ -10,18 +10,18 @@ import io.netty.buffer.ByteBuf; /** * Used to transfer Block Events in a much better fashion */ -public class GTPacketBlockEvent extends GTPacketNew { +public class GTPacketBlockEvent extends GTPacket { private int mX, mZ; private short mY; private byte mID, mValue; public GTPacketBlockEvent() { - super(true); + super(); } public GTPacketBlockEvent(int aX, short aY, int aZ, byte aID, byte aValue) { - super(false); + super(); mX = aX; mY = aY; mZ = aZ; @@ -39,7 +39,7 @@ public class GTPacketBlockEvent extends GTPacketNew { } @Override - public GTPacketNew decode(ByteArrayDataInput aData) { + public GTPacket decode(ByteArrayDataInput aData) { return new GTPacketBlockEvent( aData.readInt(), aData.readShort(), diff --git a/src/main/java/gregtech/api/net/GTPacketClientPreference.java b/src/main/java/gregtech/api/net/GTPacketClientPreference.java index ea5d9ec476..28a5a83f2e 100644 --- a/src/main/java/gregtech/api/net/GTPacketClientPreference.java +++ b/src/main/java/gregtech/api/net/GTPacketClientPreference.java @@ -11,17 +11,17 @@ import gregtech.GTMod; import gregtech.api.util.GTClientPreference; import io.netty.buffer.ByteBuf; -public class GTPacketClientPreference extends GTPacketNew { +public class GTPacketClientPreference extends GTPacket { private GTClientPreference mPreference; private EntityPlayerMP mPlayer; public GTPacketClientPreference() { - super(true); + super(); } public GTPacketClientPreference(GTClientPreference mPreference) { - super(false); + super(); this.mPreference = mPreference; } @@ -51,7 +51,7 @@ public class GTPacketClientPreference extends GTPacketNew { } @Override - public GTPacketNew decode(ByteArrayDataInput aData) { + public GTPacket 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/GTPacketInfiniteSpraycan.java b/src/main/java/gregtech/api/net/GTPacketInfiniteSpraycan.java index 302937f6ba..c12dc7d02a 100644 --- a/src/main/java/gregtech/api/net/GTPacketInfiniteSpraycan.java +++ b/src/main/java/gregtech/api/net/GTPacketInfiniteSpraycan.java @@ -16,24 +16,24 @@ import gregtech.api.util.GTUtility; import gregtech.common.items.behaviors.BehaviourSprayColorInfinite; import io.netty.buffer.ByteBuf; -public class GTPacketInfiniteSpraycan extends GTPacketNew { +public class GTPacketInfiniteSpraycan extends GTPacket { private Action action; private int newColor; private EntityPlayerMP player; public GTPacketInfiniteSpraycan() { - super(true); + super(); } public GTPacketInfiniteSpraycan(Action action) { - super(false); + super(); this.action = action; this.newColor = -1; } public GTPacketInfiniteSpraycan(Action action, int newColor) { - super(false); + super(); this.action = action; this.newColor = newColor; } @@ -53,7 +53,7 @@ public class GTPacketInfiniteSpraycan extends GTPacketNew { } @Override - public GTPacketNew decode(final ByteArrayDataInput aData) { + public GTPacket decode(final ByteArrayDataInput aData) { final int newColor = aData.readInt(); final int length = aData.readInt(); final byte[] name = new byte[length]; diff --git a/src/main/java/gregtech/api/net/GTPacketMultiTileEntity.java b/src/main/java/gregtech/api/net/GTPacketMultiTileEntity.java index b151f8eb5f..1b9fab34d4 100644 --- a/src/main/java/greg