From f67a4599861ccf1efd0707413cb6b69e63e49f75 Mon Sep 17 00:00:00 2001 From: Lance5057 Date: Wed, 11 Mar 2015 17:35:41 -0500 Subject: Flipping in Crest Mount works. Sorta glitchy still. --- .../gmail/Lance5057/com/mod_TinkersDefense.java | 4 +- .../java/gmail/Lance5057/gui/Gui_CrestMount.java | 28 +++-------- .../Lance5057/network/Handler_CrestMount.java | 24 ++++++++++ .../Lance5057/network/Message_CrestMount.java | 55 ++++++++++++++++++++++ .../gmail/Lance5057/network/PacketHandler.java | 14 ++++++ .../tileentities/TileEntity_CrestMount.java | 15 +++--- 6 files changed, 112 insertions(+), 28 deletions(-) create mode 100644 src/main/java/gmail/Lance5057/network/Handler_CrestMount.java create mode 100644 src/main/java/gmail/Lance5057/network/Message_CrestMount.java create mode 100644 src/main/java/gmail/Lance5057/network/PacketHandler.java (limited to 'src/main/java/gmail') diff --git a/src/main/java/gmail/Lance5057/com/mod_TinkersDefense.java b/src/main/java/gmail/Lance5057/com/mod_TinkersDefense.java index 47dae73..3c3c1c6 100644 --- a/src/main/java/gmail/Lance5057/com/mod_TinkersDefense.java +++ b/src/main/java/gmail/Lance5057/com/mod_TinkersDefense.java @@ -10,6 +10,7 @@ import gmail.Lance5057.blocks.QueensGoldBlock; import gmail.Lance5057.items.AeonSteelIngot; import gmail.Lance5057.items.DogbeariumIngot; import gmail.Lance5057.items.QueensGoldIngot; +import gmail.Lance5057.network.PacketHandler; import gmail.Lance5057.proxy.CommonProxy; import gmail.Lance5057.tileentities.TileEntity_CrestMount; import net.minecraft.block.Block; @@ -59,7 +60,7 @@ public Item getTabIconItem() { return Items.arrow; } }; -public static SimpleNetworkWrapper network; +public static final SimpleNetworkWrapper INSTANCE = NetworkRegistry.INSTANCE.newSimpleChannel(Reference.MOD_ID); public static Item item_AeonSteelIngot; public static Block block_AeonSteelBlock; @@ -95,6 +96,7 @@ public static CommonProxy proxy; @EventHandler public void preInit(FMLPreInitializationEvent e) { + PacketHandler.init(); //Renderers proxy.registerRenderers(); diff --git a/src/main/java/gmail/Lance5057/gui/Gui_CrestMount.java b/src/main/java/gmail/Lance5057/gui/Gui_CrestMount.java index 4824a39..72b876b 100644 --- a/src/main/java/gmail/Lance5057/gui/Gui_CrestMount.java +++ b/src/main/java/gmail/Lance5057/gui/Gui_CrestMount.java @@ -1,6 +1,8 @@ package gmail.Lance5057.gui; +import gmail.Lance5057.com.mod_TinkersDefense; import gmail.Lance5057.containers.Container_CrestMount; +import gmail.Lance5057.network.Message_CrestMount; import gmail.Lance5057.tileentities.TileEntity_CrestMount; import javax.swing.plaf.basic.BasicComboBoxUI.KeyHandler; @@ -21,16 +23,11 @@ import org.lwjgl.opengl.GL12; public class Gui_CrestMount extends GuiContainer { -/** x and y size of the inventory window in pixels. Defined as float, passed as int -* These are used for drawing the player model. */ private float xSize_lo; private float ySize_lo; -/** ResourceLocation takes 2 parameters: ModId, path to texture at the location: -* "src/minecraft/assets/modid/" */ private static final ResourceLocation iconLocation = new ResourceLocation("tinkersdefense", "textures/gui/crest_mount.png"); -/** The inventory to render on screen */ private final TileEntity_CrestMount inventory; public Gui_CrestMount(InventoryPlayer invPlayer, TileEntity_CrestMount te_crest) @@ -45,11 +42,10 @@ this.inventory = te_crest; public void initGui() { super.initGui(); - //ScaledResolution resolution = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight); - this.buttonList.add(new GuiButton(1,this.guiLeft + 61, this.guiTop + 10, 16, 16,"Flip")); - this.buttonList.add(new GuiButton(2,this.guiLeft + 16, this.guiTop + 16, 16, 16,"Flip")); - this.buttonList.add(new GuiButton(3,this.guiLeft + 16, this.guiTop + 32, 16, 16,"Flip")); - this.buttonList.add(new GuiButton(4,this.guiLeft + 16, this.guiTop + 48, 16, 16,"Flip")); + this.buttonList.add(new GuiButton(1,this.guiLeft + 60, this.guiTop + 10, 18, 18,"Flip")); + this.buttonList.add(new GuiButton(2,this.guiLeft + 94, this.guiTop + 10, 18, 18,"Flip")); + this.buttonList.add(new GuiButton(3,this.guiLeft + 78, this.guiTop + 10, 18, 18,"Flip")); + this.buttonList.add(new GuiButton(4,this.guiLeft + 77, this.guiTop + 64, 18, 18,"Flip")); } @Override @@ -64,15 +60,11 @@ protected void actionPerformed(GuiButton button) else inventory.flip[i-1]=false; - inventory.getWorldObj().markBlockForUpdate(inventory.xCoord, inventory.yCoord, inventory.zCoord); - inventory.markDirty(); + mod_TinkersDefense.INSTANCE.sendToServer(new Message_CrestMount(inventory.xCoord, inventory.yCoord, inventory.zCoord, inventory.flip)); } } } -/** -* Draws the screen and all the components in it. -*/ public void drawScreen(int par1, int par2, float par3) { super.drawScreen(par1, par2, par3); @@ -80,17 +72,11 @@ this.xSize_lo = (float)par1; this.ySize_lo = (float)par2; } -/** -* Draw the foreground layer for the GuiContainer (everything in front of the items) -*/ protected void drawGuiContainerForegroundLayer(int par1, int par2) { } -/** -* Draw the background layer for the GuiContainer (everything behind the items) -*/ protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3) { GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); diff --git a/src/main/java/gmail/Lance5057/network/Handler_CrestMount.java b/src/main/java/gmail/Lance5057/network/Handler_CrestMount.java new file mode 100644 index 0000000..fa1a89c --- /dev/null +++ b/src/main/java/gmail/Lance5057/network/Handler_CrestMount.java @@ -0,0 +1,24 @@ +package gmail.Lance5057.network; + +import ibxm.Player; +import gmail.Lance5057.tileentities.TileEntity_CrestMount; +import net.minecraft.client.Minecraft; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.tileentity.TileEntity; +import cpw.mods.fml.common.network.simpleimpl.IMessage; +import cpw.mods.fml.common.network.simpleimpl.IMessageHandler; +import cpw.mods.fml.common.network.simpleimpl.MessageContext; + +public class Handler_CrestMount implements IMessageHandler +{ + @Override + public IMessage onMessage(Message_CrestMount message, MessageContext ctx) + { + TileEntity te = ctx.getServerHandler().playerEntity.worldObj.getTileEntity(message.x, message.y, message.z); + if (te instanceof TileEntity_CrestMount) { + ((TileEntity_CrestMount) te).flip = message.flip; + } + return null; + } +} + diff --git a/src/main/java/gmail/Lance5057/network/Message_CrestMount.java b/src/main/java/gmail/Lance5057/network/Message_CrestMount.java new file mode 100644 index 0000000..6034726 --- /dev/null +++ b/src/main/java/gmail/Lance5057/network/Message_CrestMount.java @@ -0,0 +1,55 @@ +package gmail.Lance5057.network; + +import gmail.Lance5057.tileentities.TileEntity_CrestMount; +import io.netty.buffer.ByteBuf; +import net.minecraft.client.Minecraft; +import net.minecraft.tileentity.TileEntity; +import cpw.mods.fml.common.network.simpleimpl.IMessage; +import cpw.mods.fml.common.network.simpleimpl.IMessageHandler; +import cpw.mods.fml.common.network.simpleimpl.MessageContext; + +public class Message_CrestMount implements IMessage +{ + public int x, y, z; + public boolean[] flip = new boolean[4]; + + public Message_CrestMount() + { + + } + + public Message_CrestMount(int x, int y, int z, boolean[] flip) + { + this.x = x; + this.y = y; + this.z = z; + System.arraycopy(flip, 0, this.flip, 0, flip.length); + + } + + + + + @Override + public void fromBytes(ByteBuf buf) { + this.x = buf.readInt(); + this.y = buf.readInt(); + this.z = buf.readInt(); + for(int i = 0; i