diff --git a/src/main/java/bartworks/MainMod.java b/src/main/java/bartworks/MainMod.java index 66eec8469bd..a321718b17f 100644 --- a/src/main/java/bartworks/MainMod.java +++ b/src/main/java/bartworks/MainMod.java @@ -45,7 +45,6 @@ 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 7f178f63982..00000000000 --- a/src/main/java/bartworks/common/net/BWNetwork.java +++ /dev/null @@ -1,172 +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.IGT_NetworkHandler; -import io.netty.buffer.ByteBuf; -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 GTPacket[] mSubChannels; - - public BWNetwork() { - this.mChannel = NetworkRegistry.INSTANCE.newChannel("BartWorks", this, new BWNetwork.HandlerShared()); - this.mSubChannels = new GTPacket[] { new RendererPacket(), new CircuitProgrammerPacket(), - new MetaBlockPacket(), new OreDictCachePacket(), new ServerJoinedPacket(), new EICPacket() }; - } - - @Override - protected void encode(ChannelHandlerContext aContext, GTPacket aPacket, List aOutput) throws Exception { - final ByteBuf tBuf = Unpooled.buffer() - .writeByte(aPacket.getPacketID()); - aPacket.encode(tBuf); - aOutput.add( - new FMLProxyPacket( - tBuf, - aContext.channel() - .attr(NetworkRegistry.FML_CHANNEL) - .get())); - } - - @Override - protected void decode(ChannelHandlerContext aContext, FMLProxyPacket aPacket, List aOutput) - throws Exception { - final ByteArrayDataInput aData = ByteStreams.newDataInput( - aPacket.payload() - .array()); - final GTPacket tPacket = this.mSubChannels[aData.readByte()].decode(aData); - tPacket.setINetHandler(aPacket.handler()); - aOutput.add(tPacket); - } - - @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, GTPacket 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 b453b5abedf..00000000000 --- 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.GTPacket; -import io.netty.buffer.ByteBuf; - -public class CircuitProgrammerPacket extends GTPacket { - - private int dimID, playerID; - private byte chipCfg; - private boolean hasChip; - - public CircuitProgrammerPacket() { - super(); - } - - public CircuitProgrammerPacket(int dimID, int playerID, boolean hasChip, byte chipCfg) { - super(); - 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 GTPacket 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 index cfbe8e35b2c..5fcfe5187d2 100644 --- a/src/main/java/bartworks/common/net/EICPacket.java +++ b/src/main/java/bartworks/common/net/EICPacket.java @@ -30,7 +30,7 @@ public EICPacket(Coords coords, boolean bool) { @Override public byte getPacketID() { - return 5; + return 27; } @Override diff --git a/src/main/java/bartworks/common/net/MetaBlockPacket.java b/src/main/java/bartworks/common/net/MetaBlockPacket.java index 07920748ec7..c740404f7c1 100644 --- a/src/main/java/bartworks/common/net/MetaBlockPacket.java +++ b/src/main/java/bartworks/common/net/MetaBlockPacket.java @@ -48,7 +48,7 @@ public MetaBlockPacket() { @Override public byte getPacketID() { - return 2; + return 24; } @Override diff --git a/src/main/java/bartworks/common/net/OreDictCachePacket.java b/src/main/java/bartworks/common/net/OreDictCachePacket.java index 713c3f61327..8296f042369 100644 --- a/src/main/java/bartworks/common/net/OreDictCachePacket.java +++ b/src/main/java/bartworks/common/net/OreDictCachePacket.java @@ -39,7 +39,7 @@ public OreDictCachePacket(HashSet> set) { @Override public byte getPacketID() { - return 3; + return 25; } @Override diff --git a/src/main/java/bartworks/common/net/RendererPacket.java b/src/main/java/bartworks/common/net/RendererPacket.java index 82e998532ff..32008ae406a 100644 --- a/src/main/java/bartworks/common/net/RendererPacket.java +++ b/src/main/java/bartworks/common/net/RendererPacket.java @@ -44,7 +44,7 @@ public RendererPacket(Coords coords, int integer, boolean removal) { @Override public byte getPacketID() { - return 0; + return 23; } @Override diff --git a/src/main/java/bartworks/common/net/ServerJoinedPacket.java b/src/main/java/bartworks/common/net/ServerJoinedPacket.java index 17313e0be0f..7a704ac2e6d 100644 --- a/src/main/java/bartworks/common/net/ServerJoinedPacket.java +++ b/src/main/java/bartworks/common/net/ServerJoinedPacket.java @@ -25,7 +25,7 @@ public class ServerJoinedPacket extends GTPacket { private byte config; - ServerJoinedPacket() { + public ServerJoinedPacket() { super(); } @@ -36,7 +36,7 @@ public ServerJoinedPacket(Object obj) { @Override public byte getPacketID() { - return 4; + return 26; } @Override diff --git a/src/main/java/bartworks/common/tileentities/multis/MTEBioVat.java b/src/main/java/bartworks/common/tileentities/multis/MTEBioVat.java index b3d4347616c..c68a5fde113 100644 --- a/src/main/java/bartworks/common/tileentities/multis/MTEBioVat.java +++ b/src/main/java/bartworks/common/tileentities/multis/MTEBioVat.java @@ -57,7 +57,6 @@ 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; @@ -69,6 +68,7 @@ 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,7 +390,7 @@ private void sendPackagesOrRenewRenderer(int x, int y, int z, BioCulture lCultur lCulture == null ? BioCulture.NULLCULTURE.getColorRGB() : lCulture.getColorRGB()); if (SideReference.Side.Server) { - MainMod.BW_Network_instance.sendPacketToAllPlayersInRange( + GTValues.NW.sendPacketToAllPlayersInRange( this.getBaseMetaTileEntity() .getWorld(), new RendererPacket( @@ -411,7 +411,7 @@ private void sendPackagesOrRenewRenderer(int x, int y, int z, BioCulture lCultur .getXCoord(), this.getBaseMetaTileEntity() .getZCoord()); - MainMod.BW_Network_instance.sendPacketToAllPlayersInRange( + GTValues.NW.sendPacketToAllPlayersInRange( this.getBaseMetaTileEntity() .getWorld(), new RendererPacket( @@ -703,7 +703,7 @@ private void sendRenderPackets(int xDir, int zDir) { 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( diff --git a/src/main/java/bartworks/common/tileentities/multis/MTEElectricImplosionCompressor.java b/src/main/java/bartworks/common/tileentities/multis/MTEElectricImplosionCompressor.java index 1339c11095c..fd9118f643e 100644 --- a/src/main/java/bartworks/common/tileentities/multis/MTEElectricImplosionCompressor.java +++ b/src/main/java/bartworks/common/tileentities/multis/MTEElectricImplosionCompressor.java @@ -65,7 +65,6 @@ 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; @@ -74,6 +73,7 @@ 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,7 +352,7 @@ public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { 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 Coords( diff --git a/src/main/java/bartworks/server/EventHandler/ServerEventHandler.java b/src/main/java/bartworks/server/EventHandler/ServerEventHandler.java index 2a1ba2b6269..27c4197f9dc 100644 --- a/src/main/java/bartworks/server/EventHandler/ServerEventHandler.java +++ b/src/main/java/bartworks/server/EventHandler/ServerEventHandler.java @@ -19,7 +19,6 @@ import net.minecraftforge.oredict.OreDictionary; import bartworks.API.SideReference; -import bartworks.MainMod; import bartworks.common.net.OreDictCachePacket; import bartworks.common.net.ServerJoinedPacket; import bartworks.system.material.Werkstoff; @@ -27,6 +26,7 @@ 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 OreDictCachePacket(OreDictHandler.getNonBWCache()), (EntityPlayerMP) event.entity); + GTValues.NW.sendToPlayer(new ServerJoinedPacket(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 c37613aa174..6f93a41988f 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.network.Packet; import net.minecraft.tileentity.TileEntity; -import bartworks.MainMod; import bartworks.common.net.MetaBlockPacket; +import gregtech.api.enums.GTValues; import gregtech.api.interfaces.tileentity.ITexturedTileEntity; public abstract class TileEntityMetaGeneratedBlock extends TileEntity implements ITexturedTileEntity { @@ -49,7 +49,7 @@ public void writeToNBT(NBTTagCompound aNBT) { @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), this.xCoord, diff --git a/src/main/java/gregtech/api/net/GTPacketTypes.java b/src/main/java/gregtech/api/net/GTPacketTypes.java index 211bf1647bc..bc3ac6f6fdd 100644 --- a/src/main/java/gregtech/api/net/GTPacketTypes.java +++ b/src/main/java/gregtech/api/net/GTPacketTypes.java @@ -2,6 +2,11 @@ import java.util.Arrays; +import bartworks.common.net.EICPacket; +import bartworks.common.net.MetaBlockPacket; +import bartworks.common.net.OreDictCachePacket; +import bartworks.common.net.RendererPacket; +import bartworks.common.net.ServerJoinedPacket; import gregtech.common.blocks.PacketOres; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; @@ -25,6 +30,11 @@ public enum GTPacketTypes { TOOL_SWITCH_MODE(20, new GTPacketToolSwitchMode()), MUSIC_SYSTEM_DATA(21, new GTPacketMusicSystemData()), INFINITE_SPRAYCAN(22, new GTPacketInfiniteSpraycan()), + BIO_VAT_RENDERER(23, new RendererPacket()), + BW_META_BLOCK(24, new MetaBlockPacket()), + ORE_DICT_CACHE(25, new OreDictCachePacket()), + SERVER_JOINED(26, new ServerJoinedPacket()), + EIC(27, new EICPacket()), // merge conflict prevention comment, keep a trailing comma above ;