From 1b820de08a05070909a267e17f033fcf58ac8710 Mon Sep 17 00:00:00 2001 From: NotAPenguin Date: Mon, 2 Sep 2024 23:17:17 +0200 Subject: The Great Renaming (#3014) * move kekztech to a single root dir * move detrav to a single root dir * move gtnh-lanthanides to a single root dir * move tectech and delete some gross reflection in gt++ * remove more reflection inside gt5u * delete more reflection in gt++ * fix imports * move bartworks and bwcrossmod * fix proxies * move galactigreg and ggfab * move gtneioreplugin * try to fix gt++ bee loader * apply the rename rules to BW * apply rename rules to bwcrossmod * apply rename rules to detrav scanner mod * apply rename rules to galacticgreg * apply rename rules to ggfab * apply rename rules to goodgenerator * apply rename rules to gtnh-lanthanides * apply rename rules to gt++ * apply rename rules to kekztech * apply rename rules to kubatech * apply rename rules to tectech * apply rename rules to gt apply the rename rules to gt * fix tt import * fix mui hopefully * fix coremod except intergalactic * rename assline recipe class * fix a class name i stumbled on * rename StructureUtility to GTStructureUtility to prevent conflict with structurelib * temporary rename of GTTooltipDataCache to old name * fix gt client/server proxy names --- src/main/java/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 +++++++++ .../java/bartworks/common/net/RendererPacket.java | 99 ++++++++++++ .../bartworks/common/net/ServerJoinedPacket.java | 61 ++++++++ 7 files changed, 657 insertions(+) create mode 100644 src/main/java/bartworks/common/net/BWNetwork.java create mode 100644 src/main/java/bartworks/common/net/CircuitProgrammerPacket.java create mode 100644 src/main/java/bartworks/common/net/EICPacket.java create mode 100644 src/main/java/bartworks/common/net/MetaBlockPacket.java create mode 100644 src/main/java/bartworks/common/net/OreDictCachePacket.java create mode 100644 src/main/java/bartworks/common/net/RendererPacket.java create mode 100644 src/main/java/bartworks/common/net/ServerJoinedPacket.java (limited to 'src/main/java/bartworks/common/net') diff --git a/src/main/java/bartworks/common/net/BWNetwork.java b/src/main/java/bartworks/common/net/BWNetwork.java new file mode 100644 index 0000000000..78ab09e367 --- /dev/null +++ b/src/main/java/bartworks/common/net/BWNetwork.java @@ -0,0 +1,170 @@ +/* + * 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 new file mode 100644 index 0000000000..998d10cbfa --- /dev/null +++ b/src/main/java/bartworks/common/net/CircuitProgrammerPacket.java @@ -0,0 +1,88 @@ +/* + * 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 new file mode 100644 index 0000000000..9d2414a0e0 --- /dev/null +++ b/src/main/java/bartworks/common/net/EICPacket.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.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 new file mode 100644 index 0000000000..ee8ab8231a --- /dev/null +++ b/src/main/java/bartworks/common/net/MetaBlockPacket.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.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 new file mode 100644 index 0000000000..b8cda117ac --- /dev/null +++ b/src/main/java/bartworks/common/net/OreDictCachePacket.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.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/RendererPacket.java b/src/main/java/bartworks/common/net/RendererPacket.java new file mode 100644 index 0000000000..f4f03c3584 --- /dev/null +++ b/src/main/java/bartworks/common/net/RendererPacket.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.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 new file mode 100644 index 0000000000..e686d56182 --- /dev/null +++ b/src/main/java/bartworks/common/net/ServerJoinedPacket.java @@ -0,0 +1,61 @@ +/* + * 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 bartworks.common.configs.ConfigHandler; +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 = (byte) (ConfigHandler.classicMode && ConfigHandler.disableExtraGassesForEBF ? 3 + : ConfigHandler.classicMode ? 2 : ConfigHandler.disableExtraGassesForEBF ? 1 : 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) { + boolean gas = (this.config & 1) != 0; + boolean classic = (this.config & 0b10) != 0; + MainMod.runOnPlayerJoined(classic, gas); + } +} -- cgit