From db6677248a04820daa403377fbce0c0a2950c4e0 Mon Sep 17 00:00:00 2001 From: Arthur Uzulin Date: Tue, 28 Jan 2014 23:06:27 +1100 Subject: [PATCH] PacketToolStation(WIP) --- .../network/packet/PacketToolStation.java | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 src/main/java/tconstruct/util/network/packet/PacketToolStation.java diff --git a/src/main/java/tconstruct/util/network/packet/PacketToolStation.java b/src/main/java/tconstruct/util/network/packet/PacketToolStation.java new file mode 100644 index 00000000000..e23a582b4d7 --- /dev/null +++ b/src/main/java/tconstruct/util/network/packet/PacketToolStation.java @@ -0,0 +1,60 @@ +package tconstruct.util.network.packet; + +import mantle.util.network.StringEncoder; + +import io.netty.buffer.ByteBuf; +import io.netty.channel.ChannelHandlerContext; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; +import tconstruct.blocks.logic.*; + +public class PacketToolStation extends AbstractPacket { + + private int x, y, z; + private String toolName; + + public PacketToolStation(){} + + public PacketToolStation(int x, int y, int z, String toolName){ + this.x = x; + this.y = y; + this.z = z; + this.toolName = toolName; + } + + @Override + public void encodeInto(ChannelHandlerContext ctx, ByteBuf buffer) { + buffer.writeInt(x); + buffer.writeInt(y); + buffer.writeInt(z); + StringEncoder.encodeString(buffer, toolName); + } + + @Override + public void decodeInto(ChannelHandlerContext ctx, ByteBuf buffer) { + x = buffer.readInt(); + y = buffer.readInt(); + z = buffer.readInt(); + toolName = StringEncoder.decodeString(buffer); + } + + @Override + public void handleClientSide(EntityPlayer player) {} + + @Override + public void handleServerSide(EntityPlayer player) { + World world = player.worldObj; + TileEntity te = world.func_147438_o(x, y, z); + + if (te instanceof ToolStationLogic) + { + ((ToolStationLogic) te).setToolname(toolName); + } + if (te instanceof ToolForgeLogic) + { + ((ToolForgeLogic) te).setToolname(toolName); + } + } + +}