summaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorLance5057 <Lance5057@gmail.com>2015-02-15 05:38:22 -0600
committerLance5057 <Lance5057@gmail.com>2015-02-15 05:38:22 -0600
commitcb2393221bcd5150d5b777c6673919ce4251d27d (patch)
treed5b15bafee7b26a9b7429fe56665b54d79af6747 /src/main/java
parentb5161d041db1fb3807d32d40579d40306af6da67 (diff)
Crest Mount Attempt 3 Part 1
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/gmail/Lance5057/blocks/CrestMount.java6
-rw-r--r--src/main/java/gmail/Lance5057/blocks/TileEntity_CrestMount.java269
-rw-r--r--src/main/java/gmail/Lance5057/com/mod_TinkersDefense.java5
-rw-r--r--src/main/java/gmail/Lance5057/containers/Container_CrestMount.java18
-rw-r--r--src/main/java/gmail/Lance5057/gui/Container_CrestMount.java88
-rw-r--r--src/main/java/gmail/Lance5057/gui/GuiHandler_CrestMount.java32
-rw-r--r--src/main/java/gmail/Lance5057/gui/Gui_CrestMount.java28
-rw-r--r--src/main/java/gmail/Lance5057/proxy/ClientProxy.java7
-rw-r--r--src/main/java/gmail/Lance5057/proxy/CommonProxy.java7
-rw-r--r--src/main/java/gmail/Lance5057/proxy/Handler_CrestMount.java155
-rw-r--r--src/main/java/gmail/Lance5057/tileentities/TileEntity_CrestMount.java149
11 files changed, 177 insertions, 587 deletions
diff --git a/src/main/java/gmail/Lance5057/blocks/CrestMount.java b/src/main/java/gmail/Lance5057/blocks/CrestMount.java
index 1401057..c2b6326 100644
--- a/src/main/java/gmail/Lance5057/blocks/CrestMount.java
+++ b/src/main/java/gmail/Lance5057/blocks/CrestMount.java
@@ -5,7 +5,7 @@ import static net.minecraftforge.common.util.ForgeDirection.NORTH;
import static net.minecraftforge.common.util.ForgeDirection.SOUTH;
import static net.minecraftforge.common.util.ForgeDirection.WEST;
import gmail.Lance5057.com.mod_TinkersDefense;
-import gmail.Lance5057.gui.Gui_CrestMount;
+import gmail.Lance5057.tileentities.TileEntity_CrestMount;
import java.util.Random;
@@ -45,7 +45,7 @@ public class CrestMount extends BlockContainer {
return false;
}
//code to open gui explained later
- player.openGui(mod_TinkersDefense.instance, 0, world, x, y, z);
+ player.openGui(mod_TinkersDefense.instance, mod_TinkersDefense.GUI_ITEM_INV, world, x, y, z);
return true;
}
@@ -113,7 +113,7 @@ public class CrestMount extends BlockContainer {
}
@Override
- public TileEntity createNewTileEntity(World p_149915_1_, int p_149915_2_) {
+ public TileEntity createNewTileEntity(World w, int md) {
TileEntity_CrestMount te = new TileEntity_CrestMount();
return te;
}
diff --git a/src/main/java/gmail/Lance5057/blocks/TileEntity_CrestMount.java b/src/main/java/gmail/Lance5057/blocks/TileEntity_CrestMount.java
deleted file mode 100644
index c46cfa3..0000000
--- a/src/main/java/gmail/Lance5057/blocks/TileEntity_CrestMount.java
+++ /dev/null
@@ -1,269 +0,0 @@
-package gmail.Lance5057.blocks;
-
-import gmail.Lance5057.com.mod_TinkersDefense;
-import gmail.Lance5057.gui.Container_CrestMount;
-import gmail.Lance5057.proxy.Handler_CrestMount;
-
-import java.util.Iterator;
-import java.util.List;
-
-import net.minecraft.entity.player.EntityPlayer;
-import net.minecraft.inventory.IInventory;
-import net.minecraft.item.Item;
-import net.minecraft.item.ItemStack;
-import net.minecraft.nbt.NBTTagCompound;
-import net.minecraft.nbt.NBTTagList;
-import net.minecraft.network.Packet;
-import net.minecraft.tileentity.TileEntity;
-import net.minecraft.util.AxisAlignedBB;
-
-public class TileEntity_CrestMount extends TileEntity implements IInventory{
-
- private ItemStack[] inventory = new ItemStack[4];
- private String name = "Item";
- private int facing;
- private int numUsingPlayers;
- private int ticksSinceSync;
- private boolean inventoryTouched;
-
- public TileEntity_CrestMount()
- {
- super();
- }
-
- @Override
- public int getSizeInventory() {
- return inventory.length;
- }
-
- @Override
- public ItemStack getStackInSlot(int slot) {
- return inventory[slot];
- }
-
- @Override
- public void markDirty()
- {
- super.markDirty();
- }
-
- @Override
- public ItemStack decrStackSize(int slot, int amount) {
- ItemStack stack = getStackInSlot(slot);
- if(stack != null)
- {
- if(stack.stackSize > amount)
- {
- stack = stack.splitStack(amount);
- markDirty();
- }
- else
- {
- setInventorySlotContents(slot, null);
- }
- }
- return stack;
- }
-
- @Override
- public ItemStack getStackInSlotOnClosing(int slot) {
- ItemStack stack = getStackInSlot(slot);
- if(stack != null)
- {
- setInventorySlotContents(slot, null);
- }
- return stack;
- }
-
- @Override
- public void setInventorySlotContents(int slot, ItemStack itemstack) {
- this.inventory[slot] = itemstack;
-
- if (itemstack != null && itemstack.stackSize > this.getInventoryStackLimit())
- {
- itemstack.stackSize = this.getInventoryStackLimit();
- }
-
- markDirty();
- }
-
- @Override
- public String getInventoryName() {
- return name;
- }
-
- @Override
- public boolean hasCustomInventoryName() {
- return name.length() > 0;
- }
-
- @Override
- public int getInventoryStackLimit() {
- return 1;
- }
-
- @Override
- public boolean isUseableByPlayer(EntityPlayer player) {
- if (worldObj == null)
- {
- return true;
- }
- if (worldObj.getTileEntity(xCoord, yCoord, zCoord) != this)
- {
- return false;
- }
- return player.getDistanceSq((double) xCoord + 0.5D, (double) yCoord + 0.5D, (double) zCoord + 0.5D) <= 64D;
- }
-
- @Override
- public void openInventory() {
- if (worldObj == null) return;
- numUsingPlayers++;
- worldObj.addBlockEvent(xCoord, yCoord, zCoord, mod_TinkersDefense.block_CrestMount, 1, numUsingPlayers);
- }
-
- @Override
- public void closeInventory() {
- if (worldObj == null) return;
- numUsingPlayers--;
- worldObj.addBlockEvent(xCoord, yCoord, zCoord, mod_TinkersDefense.block_CrestMount, 1, numUsingPlayers);
- }
-
- @Override
- public boolean receiveClientEvent(int p_145842_1_, int p_145842_2_)
- {
- if (p_145842_1_ == 1)
- {
- this.numUsingPlayers = p_145842_2_;
- return true;
- }
- else
- {
- return super.receiveClientEvent(p_145842_1_, p_145842_2_);
- }
- }
-
- @Override
- public void updateEntity()
- {
- super.updateEntity();
- // Resynchronize clients with the server state
- if (worldObj != null && !this.worldObj.isRemote && this.numUsingPlayers != 0 && (this.ticksSinceSync + this.xCoord + this.yCoord + this.zCoord) % 200 == 0)
- {
- this.numUsingPlayers = 0;
- float var1 = 5.0F;
- @SuppressWarnings("unchecked")
- List<EntityPlayer> var2 = this.worldObj.getEntitiesWithinAABB(EntityPlayer.class, AxisAlignedBB.getBoundingBox((double)((float)this.xCoord - var1), (double)((float)this.yCoord - var1), (double)((float)this.zCoord - var1), (double)((float)(this.xCoord + 1) + var1), (double)((float)(this.yCoord + 1) + var1), (double)((float)(this.zCoord + 1) + var1)));
- Iterator<EntityPlayer> var3 = var2.iterator();
- while (var3.hasNext())
- {
- EntityPlayer var4 = var3.next();
- if (var4.openContainer instanceof Container_CrestMount)
- {
- ++this.numUsingPlayers;
- }
- }
- }
- if (worldObj != null && !worldObj.isRemote && ticksSinceSync < 0)
- {
- worldObj.addBlockEvent(xCoord, yCoord, zCoord, mod_TinkersDefense.block_CrestMount, 3, ((numUsingPlayers << 3) & 0xF8));
- }
- if (!worldObj.isRemote && inventoryTouched)
- {
- inventoryTouched = false;
- }
- this.ticksSinceSync++;
-
- }
-
- @Override
- public boolean isItemValidForSlot(int p_94041_1_, ItemStack itemstack) {
- return true;
- }
-
- public int getFacing()
- {
- return this.facing;
- }
-
- public void setFacing(int facing_o)
- {
- facing = facing_o;
- }
-
- @Override
- public Packet getDescriptionPacket()
- {
- return Handler_CrestMount.getPacket(this);
- }
-
- public void handlePacketData(int[] intData)
- {
- TileEntity_CrestMount te = this;
- if (intData != null)
- {
- int pos = 0;
- for (int i = 0; i < te.inventory.length; i++)
- {
- if (intData[pos + 2] != 0)
- {
- Item it = Item.getItemById(intData[pos]);
- ItemStack is = new ItemStack(it, intData[pos], intData[pos]);
- te.inventory[i] = is;
- }
- else
- {
- te.inventory[i] = null;
- }
- pos += 3;
- }
- }
- }
-
- public void readFromNBT(NBTTagCompound p_145839_1_)
- {
- super.readFromNBT(p_145839_1_);
- NBTTagList nbttaglist = p_145839_1_.getTagList("Items", 10);
- this.inventory = new ItemStack[this.getSizeInventory()];
-
- if (p_145839_1_.hasKey("CustomName", 8))
- {
- this.name = p_145839_1_.getString("CustomName");
- }
-
- for (int i = 0; i < nbttaglist.tagCount(); ++i)
- {
- NBTTagCompound nbttagcompound1 = nbttaglist.getCompoundTagAt(i);
- int j = nbttagcompound1.getByte("Slot") & 255;
-
- if (j >= 0 && j < this.inventory.length)
- {
- this.inventory[j] = ItemStack.loadItemStackFromNBT(nbttagcompound1);
- }
- }
- }
-
- public void writeToNBT(NBTTagCompound p_145841_1_)
- {
- super.writeToNBT(p_145841_1_);
- NBTTagList nbttaglist = new NBTTagList();
-
- for (int i = 0; i < this.inventory.length; ++i)
- {
- if (this.inventory[i] != null)
- {
- NBTTagCompound nbttagcompound1 = new NBTTagCompound();
- nbttagcompound1.setByte("Slot", (byte)i);
- this.inventory[i].writeToNBT(nbttagcompound1);
- nbttaglist.appendTag(nbttagcompound1);
- }
- }
-
- p_145841_1_.setTag("Items", nbttaglist);
-
- if (this.hasCustomInventoryName())
- {
- p_145841_1_.setString("CustomName", this.name);
- }
- }
-}
diff --git a/src/main/java/gmail/Lance5057/com/mod_TinkersDefense.java b/src/main/java/gmail/Lance5057/com/mod_TinkersDefense.java
index 318e0e8..1c90437 100644
--- a/src/main/java/gmail/Lance5057/com/mod_TinkersDefense.java
+++ b/src/main/java/gmail/Lance5057/com/mod_TinkersDefense.java
@@ -7,12 +7,11 @@ import gmail.Lance5057.blocks.AeonSteelBlock;
import gmail.Lance5057.blocks.CrestMount;
import gmail.Lance5057.blocks.DogbeariumBlock;
import gmail.Lance5057.blocks.QueensGoldBlock;
-import gmail.Lance5057.blocks.TileEntity_CrestMount;
import gmail.Lance5057.items.AeonSteelIngot;
import gmail.Lance5057.items.DogbeariumIngot;
import gmail.Lance5057.items.QueensGoldIngot;
import gmail.Lance5057.proxy.CommonProxy;
-import gmail.Lance5057.proxy.Handler_CrestMount;
+import gmail.Lance5057.tileentities.TileEntity_CrestMount;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
@@ -101,7 +100,7 @@ public void preInit(FMLPreInitializationEvent e)
{
//Network
network = NetworkRegistry.INSTANCE.newSimpleChannel("tDefense");
- Handler_CrestMount.INSTANCE.ordinal();
+ //Handler_CrestMount.INSTANCE.ordinal();
//Renderers
proxy.registerRenderers();
diff --git a/src/main/java/gmail/Lance5057/containers/Container_CrestMount.java b/src/main/java/gmail/Lance5057/containers/Container_CrestMount.java
new file mode 100644
index 0000000..06ecb5e
--- /dev/null
+++ b/src/main/java/gmail/Lance5057/containers/Container_CrestMount.java
@@ -0,0 +1,18 @@
+package gmail.Lance5057.containers;
+
+import gmail.Lance5057.tileentities.TileEntity_CrestMount;
+import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.inventory.Container;
+
+public class Container_CrestMount extends Container
+{
+ private static final int INV_START = TileEntity_CrestMount.invSize, INV_END = INV_START+26,
+ HOTBAR_START = INV_END+1, HOTBAR_END = HOTBAR_START+8;
+
+ @Override
+ public boolean canInteractWith(EntityPlayer p_75145_1_) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+}
diff --git a/src/main/java/gmail/Lance5057/gui/Container_CrestMount.java b/src/main/java/gmail/Lance5057/gui/Container_CrestMount.java
deleted file mode 100644
index 8db0940..0000000
--- a/src/main/java/gmail/Lance5057/gui/Container_CrestMount.java
+++ /dev/null
@@ -1,88 +0,0 @@
-package gmail.Lance5057.gui;
-
-import gmail.Lance5057.blocks.TileEntity_CrestMount;
-import net.minecraft.entity.player.EntityPlayer;
-import net.minecraft.entity.player.InventoryPlayer;
-import net.minecraft.inventory.Container;
-import net.minecraft.inventory.Slot;
-import net.minecraft.item.ItemStack;
-
-public class Container_CrestMount extends Container
-{
- protected TileEntity_CrestMount tileEntity;
-
- public Container_CrestMount (InventoryPlayer inventoryPlayer, TileEntity_CrestMount te){
- tileEntity = te;
- te.openInventory();
-
- //the Slot constructor takes the IInventory and the slot number in that it binds to
- //and the x-y coordinates it resides on-screen
- for (int i = 0; i < 4; i++) {
- addSlotToContainer(new Slot(tileEntity, i, 62 + 18, 17 + i * 18));
- }
-
- //commonly used vanilla code that adds the player's inventory
- bindPlayerInventory(inventoryPlayer);
- }
-
- protected void bindPlayerInventory(InventoryPlayer inventoryPlayer) {
- for (int i = 0; i < 3; i++) {
- for (int j = 0; j < 9; j++) {
- addSlotToContainer(new Slot(inventoryPlayer, j + i * 9 + 9,
- 8 + j * 18, 84 + i * 18));
- }
- }
-
- for (int i = 0; i < 9; i++) {
- addSlotToContainer(new Slot(inventoryPlayer, i, 8 + i * 18, 142));
- }
-}
-
- @Override
- public boolean canInteractWith(EntityPlayer p_75145_1_) {
- return tileEntity.isUseableByPlayer(p_75145_1_);
- }
-
- @Override
- public ItemStack transferStackInSlot(EntityPlayer player, int slot) {
- ItemStack stack = null;
- Slot slotObject = (Slot) inventorySlots.get(slot);
-
- //null checks and checks if the item can be stacked (maxStackSize > 1)
- if (slotObject != null && slotObject.getHasStack()) {
- ItemStack stackInSlot = slotObject.getStack();
- stack = stackInSlot.copy();
-
- //merges the item into player inventory since its in the tileEntity
- if (slot < 4) {
- if (!this.mergeItemStack(stackInSlot, 0, 35, true)) {
- return null;
- }
- }
- //places it into the tileEntity is possible since its in the player inventory
- else if (!this.mergeItemStack(stackInSlot, 0, 4, false)) {
- return null;
- }
-
- if (stackInSlot.stackSize == 0) {
- slotObject.putStack(null);
- } else {
- slotObject.onSlotChanged();
- }
-
- if (stackInSlot.stackSize == stack.stackSize) {
- return null;
- }
- slotObject.onPickupFromSlot(player, stackInSlot);
- }
- return stack;
- }
-
- @Override
- public void onContainerClosed(EntityPlayer entityplayer)
- {
- super.onContainerClosed(entityplayer);
- tileEntity.closeInventory();
- }
-
-}
diff --git a/src/main/java/gmail/Lance5057/gui/GuiHandler_CrestMount.java b/src/main/java/gmail/Lance5057/gui/GuiHandler_CrestMount.java
deleted file mode 100644
index 604f088..0000000
--- a/src/main/java/gmail/Lance5057/gui/GuiHandler_CrestMount.java
+++ /dev/null
@@ -1,32 +0,0 @@
-package gmail.Lance5057.gui;
-
-import gmail.Lance5057.blocks.TileEntity_CrestMount;
-import net.minecraft.entity.player.EntityPlayer;
-import net.minecraft.tileentity.TileEntity;
-import net.minecraft.world.World;
-import cpw.mods.fml.common.network.IGuiHandler;
-
-public class GuiHandler_CrestMount implements IGuiHandler {
- //returns an instance of the Container you made earlier
- @Override
- public Object getServerGuiElement(int id, EntityPlayer player, World world,
- int x, int y, int z) {
- TileEntity tileEntity = world.getTileEntity(x, y, z);
- if(tileEntity instanceof TileEntity_CrestMount){
- return new Container_CrestMount(player.inventory, (TileEntity_CrestMount) tileEntity);
- }
- return null;
- }
-
- //returns an instance of the Gui you made earlier
- @Override
- public Object getClientGuiElement(int id, EntityPlayer player, World world,
- int x, int y, int z) {
- TileEntity tileEntity = world.getTileEntity(x, y, z);
- if(tileEntity instanceof 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/gui/Gui_CrestMount.java b/src/main/java/gmail/Lance5057/gui/Gui_CrestMount.java
deleted file mode 100644
index 221f5c1..0000000
--- a/src/main/java/gmail/Lance5057/gui/Gui_CrestMount.java
+++ /dev/null
@@ -1,28 +0,0 @@
-package gmail.Lance5057.gui;
-
-import org.lwjgl.opengl.GL11;
-
-import gmail.Lance5057.blocks.TileEntity_CrestMount;
-import net.minecraft.client.gui.inventory.GuiContainer;
-import net.minecraft.entity.player.InventoryPlayer;
-import net.minecraft.util.ResourceLocation;
-
-public class Gui_CrestMount extends GuiContainer {
-
- private ResourceLocation RL = new ResourceLocation("tinkersdefense", "textures/gui/inv_crestmount.png");
-
- public Gui_CrestMount(Container_CrestMount container) {
- super(container);
- }
-
- @Override
- protected void drawGuiContainerBackgroundLayer(float p_146976_1_,
- int p_146976_2_, int p_146976_3_) {
- this.mc.renderEngine.bindTexture(RL);
- int x = (width - xSize) / 2;
- int y = (height - ySize) / 2;
- this.drawTexturedModalRect(x, y, 0, 0, xSize, ySize);
-
- }
-
-}
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);
- }
-}
diff --git a/src/main/java/gmail/Lance5057/tileentities/TileEntity_CrestMount.java b/src/main/java/gmail/Lance5057/tileentities/TileEntity_CrestMount.java
new file mode 100644
index 0000000..3a325f7
--- /dev/null
+++ b/src/main/java/gmail/Lance5057/tileentities/TileEntity_CrestMount.java
@@ -0,0 +1,149 @@
+package gmail.Lance5057.tileentities;
+
+import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.inventory.IInventory;
+import net.minecraft.item.ItemStack;
+import net.minecraft.nbt.NBTTagCompound;
+import net.minecraft.nbt.NBTTagList;
+import net.minecraft.tileentity.TileEntity;
+
+public class TileEntity_CrestMount extends TileEntity implements IInventory
+{
+ public static int invSize = 4;
+ private ItemStack[] inventory = new ItemStack[invSize];
+
+
+ private final String name = "Crest Inventory";
+ private final String tagName = "Crest InvTag";
+
+ @Override
+ public int getSizeInventory() {
+ return invSize;
+ }
+
+ @Override
+ public ItemStack getStackInSlot(int slot) {
+ return inventory[slot];
+ }
+
+ @Override
+ public ItemStack decrStackSize(int slot, int amount) {
+ ItemStack stack = getStackInSlot(slot);
+ if (stack != null)
+ {
+ if (stack.stackSize > amount)
+ {
+ stack = stack.splitStack(amount);
+
+ if (stack.stackSize == 0)
+ {
+ setInventorySlotContents(slot, null);
+ }
+ }
+ else
+ {
+ setInventorySlotContents(slot, null);
+ }
+
+ this.markDirty();
+ }
+ return stack;
+ }
+
+ @Override
+ public ItemStack getStackInSlotOnClosing(int slot) {
+ ItemStack stack = getStackInSlot(slot);
+
+ if (stack != null)
+ {
+ setInventorySlotContents(slot, null);
+ }
+ return stack;
+ }
+
+ @Override
+ public void setInventorySlotContents(int slot, ItemStack itemstack) {
+ this.inventory[slot] = itemstack;
+
+ if (itemstack != null && itemstack.stackSize > this.getInventoryStackLimit())
+ {
+ itemstack.stackSize = this.getInventoryStackLimit();
+ }
+
+ this.markDirty();
+ }
+
+ @Override
+ public String getInventoryName() {
+ return name;
+ }
+
+ @Override
+ public boolean hasCustomInventoryName() {
+ return name.length() > 0;
+ }
+
+ @Override
+ public int getInventoryStackLimit() {
+ return 1;
+ }
+
+ @Override
+ public boolean isUseableByPlayer(EntityPlayer p_70300_1_) {
+ return true;
+ }
+
+ @Override
+ public void openInventory() {
+
+ }
+
+ @Override
+ public void closeInventory() {
+
+ }
+
+ @Override
+ public boolean isItemValidForSlot(int p_94041_1_, ItemStack p_94041_2_) {
+ return true;
+ }
+
+
+ public void writeToNBT(NBTTagCompound compound)
+ {
+ NBTTagList items = new NBTTagList();
+
+ for (int i = 0; i < getSizeInventory(); ++i)
+ {
+ if (getStackInSlot(i) != null)
+ {
+ NBTTagCompound item = new NBTTagCompound();
+ item.setByte("Slot", (byte) i);
+ getStackInSlot(i).writeToNBT(item);
+ items.appendTag(item);
+ }
+ }
+
+ // We're storing our items in a custom tag list using our 'tagName' from above
+ // to prevent potential conflicts
+ compound.setTag(tagName, items);
+ }
+
+ public void readFromNBT(NBTTagCompound compound)
+ {
+ // now you must include the NBTBase type ID when getting the list; NBTTagCompound's ID is 10
+ NBTTagList items = compound.getTagList(tagName, compound.getId());
+ for (int i = 0; i < items.tagCount(); ++i)
+ {
+ // tagAt(int) has changed to getCompoundTagAt(int)
+ NBTTagCompound item = items.getCompoundTagAt(i);
+ byte slot = item.getByte("Slot");
+
+ if (slot >= 0 && slot < getSizeInventory())
+ {
+ inventory[slot] = ItemStack.loadItemStackFromNBT(item);
+ }
+ }
+ }
+
+}