diff options
| author | Lance5057 <Lance5057@gmail.com> | 2015-02-15 05:38:22 -0600 |
|---|---|---|
| committer | Lance5057 <Lance5057@gmail.com> | 2015-02-15 05:38:22 -0600 |
| commit | cb2393221bcd5150d5b777c6673919ce4251d27d (patch) | |
| tree | d5b15bafee7b26a9b7429fe56665b54d79af6747 /src/main/java/gmail/Lance5057/proxy | |
| parent | b5161d041db1fb3807d32d40579d40306af6da67 (diff) | |
Crest Mount Attempt 3 Part 1
Diffstat (limited to 'src/main/java/gmail/Lance5057/proxy')
3 files changed, 5 insertions, 164 deletions
diff --git a/src/main/java/gmail/Lance5057/proxy/ClientProxy.java b/src/main/java/gmail/Lance5057/proxy/ClientProxy.java index 3a0f2f9..0ddabce 100644 --- a/src/main/java/gmail/Lance5057/proxy/ClientProxy.java +++ b/src/main/java/gmail/Lance5057/proxy/ClientProxy.java @@ -1,10 +1,8 @@ package gmail.Lance5057.proxy; import gmail.Lance5057.blocks.Renderer_CrestMount; -import gmail.Lance5057.blocks.TileEntity_CrestMount; -import gmail.Lance5057.gui.Container_CrestMount; -import gmail.Lance5057.gui.Gui_CrestMount; import gmail.Lance5057.items.ModelTinkerArmor; +import gmail.Lance5057.tileentities.TileEntity_CrestMount; import net.minecraft.client.model.ModelBiped; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.tileentity.TileEntity; @@ -48,7 +46,8 @@ public class ClientProxy extends CommonProxy { TileEntity te = world.getTileEntity(x, y, z); if (te != null && te instanceof TileEntity_CrestMount) { - return new Gui_CrestMount((Container_CrestMount) new Container_CrestMount(player.inventory, new TileEntity_CrestMount())); + return null; + //return new Gui_CrestMount((Container_CrestMount) new Container_CrestMount(player.inventory, new TileEntity_CrestMount())); } else { diff --git a/src/main/java/gmail/Lance5057/proxy/CommonProxy.java b/src/main/java/gmail/Lance5057/proxy/CommonProxy.java index 1b2ff1e..69d30cc 100644 --- a/src/main/java/gmail/Lance5057/proxy/CommonProxy.java +++ b/src/main/java/gmail/Lance5057/proxy/CommonProxy.java @@ -1,9 +1,6 @@ package gmail.Lance5057.proxy; -import gmail.Lance5057.blocks.TileEntity_CrestMount; import gmail.Lance5057.com.mod_TinkersDefense; -import gmail.Lance5057.gui.Container_CrestMount; -import gmail.Lance5057.gui.Gui_CrestMount; import net.minecraft.client.model.ModelBiped; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.world.World; @@ -38,7 +35,7 @@ public class CommonProxy implements IGuiHandler { if (ID == mod_TinkersDefense.GUI_ITEM_INV) { // Use the player's held item to create the inventory - return new Container_CrestMount(player.inventory, new TileEntity_CrestMount()); + //return new Container_CrestMount(player.inventory, new TileEntity_CrestMount()); } return null; } @@ -50,7 +47,7 @@ public class CommonProxy implements IGuiHandler { { // We have to cast the new container as our custom class // and pass in currently held item for the inventory - return new Gui_CrestMount((Container_CrestMount) new Container_CrestMount(player.inventory, new TileEntity_CrestMount())); + //return new Gui_CrestMount((Container_CrestMount) new Container_CrestMount(player.inventory, new TileEntity_CrestMount())); } return null; } diff --git a/src/main/java/gmail/Lance5057/proxy/Handler_CrestMount.java b/src/main/java/gmail/Lance5057/proxy/Handler_CrestMount.java deleted file mode 100644 index 85b740e..0000000 --- a/src/main/java/gmail/Lance5057/proxy/Handler_CrestMount.java +++ /dev/null @@ -1,155 +0,0 @@ -package gmail.Lance5057.proxy; - -import gmail.Lance5057.blocks.TileEntity_CrestMount; -import gmail.Lance5057.com.mod_TinkersDefense; -import io.netty.buffer.ByteBuf; -import io.netty.channel.ChannelHandlerContext; -import io.netty.channel.SimpleChannelInboundHandler; - -import java.util.EnumMap; - -import net.minecraft.network.Packet; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.world.World; -import cpw.mods.fml.common.FMLCommonHandler; -import cpw.mods.fml.common.network.FMLEmbeddedChannel; -import cpw.mods.fml.common.network.FMLIndexedMessageToMessageCodec; -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.relauncher.SideOnly; - -public enum Handler_CrestMount { -INSTANCE; -/** -* Our channel "pair" from {@link NetworkRegistry} -*/ -private EnumMap<Side, FMLEmbeddedChannel> channels; -/** -* Make our packet handler, and add an {@link CrestMountCodec} always -*/ -private Handler_CrestMount() -{ -this.channels = NetworkRegistry.INSTANCE.newChannel("tDefense", new CrestMountCodec()); - if (FMLCommonHandler.instance().getSide() == Side.CLIENT) - { - addClientHandler(); - } -} - - -@SideOnly(Side.CLIENT) -private void addClientHandler() { -FMLEmbeddedChannel clientChannel = this.channels.get(Side.CLIENT); - -String codec = clientChannel.findChannelHandlerNameForType(CrestMountCodec.class); -clientChannel.pipeline().addAfter(codec, "ClientHandler", new Message_CrestMountHandler()); -} - -private static class Message_CrestMountHandler extends SimpleChannelInboundHandler<Message_CrestMount> -{ -@Override -protected void channelRead0(ChannelHandlerContext ctx, Message_CrestMount msg) throws Exception -{ - World world = mod_TinkersDefense.proxy.getClientWorld(); - TileEntity te = world.getTileEntity(msg.x, msg.y, msg.z); - if (te instanceof TileEntity_CrestMount) - { - ((TileEntity_CrestMount) te).handlePacketData(msg.items); - } - } -} -/** -* This is our "message". In fact, {@link FMLIndexedMessageToMessageCodec} -* can handle many messages on the same channel at once, using a -* discriminator byte. But for CrestMount, we only need the one message, so -* we have just this. -* -* @author cpw -* -*/ -public static class Message_CrestMount -{ -int x; -int y; -int z; -int[] items; -} -/** -* This is the codec that automatically transforms the -* {@link FMLProxyPacket} which wraps the client and server custom payload -* packets into a message we care about. -* -* @author cpw -* -*/ -private class CrestMountCodec extends FMLIndexedMessageToMessageCodec<Message_CrestMount> -{ -/** -* We register our discriminator bytes here. We only have the one type, so we only -* register one. -*/ -public CrestMountCodec() -{ -addDiscriminator(0, Message_CrestMount.class); -} -@Override -public void encodeInto(ChannelHandlerContext ctx, Message_CrestMount msg, ByteBuf target) throws Exception -{ -target.writeInt(msg.x); -target.writeInt(msg.y); -target.writeInt(msg.z); -target.writeBoolean(msg.items != null); -if (msg.items != null) -{ -int[] items = msg.items; -for (int j = 0; j < items.length; j++) -{ -int i = items[j]; -target.writeInt(i); -} -} -} -@Override -public void decodeInto(ChannelHandlerContext ctx, ByteBuf dat, Message_CrestMount msg) -{ -msg.x = dat.readInt(); -msg.y = dat.readInt(); -msg.z = dat.readInt(); -boolean hasStacks = dat.readBoolean(); -msg.items = new int[0]; -if (hasStacks) -{ -msg.items = new int[4]; -for (int i = 0; i < msg.items.length; i++) -{ -msg.items[i] = dat.readInt(); -} -} -} -} -/** -* This is a utility method called to transform a packet from a custom -* packet into a "system packet". We're called from -* {@link TileEntity#getDescriptionPacket()} in this case, but there are -* others. All network packet methods in minecraft have been adapted to -* handle {@link FMLProxyPacket} but general purpose objects can't be -* handled sadly. -* -* This method uses the {@link CrestMountCodec} to transform a custom packet -* {@link Message_CrestMount} into an {@link FMLProxyPacket} by using the -* utility method {@link FMLEmbeddedChannel#generatePacketFrom(Object)} on -* the channel to do exactly that. -* -* @param tileEntityCrestMount -* @return -*/ - public static Packet getPacket(TileEntity_CrestMount te) - { - Message_CrestMount msg = new Message_CrestMount(); - msg.x = te.xCoord; - msg.y = te.yCoord; - msg.z = te.zCoord; - return INSTANCE.channels.get(Side.SERVER).generatePacketFrom(msg); - } -} |
