summaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorLance5057 <Lance5057@gmail.com>2015-02-10 23:41:15 -0600
committerLance5057 <Lance5057@gmail.com>2015-02-10 23:41:15 -0600
commitb5161d041db1fb3807d32d40579d40306af6da67 (patch)
tree3dae11610cb15622474b5c0b129f32667f1d8515 /src/main
parent0fe568fc1800274fa3f0c68a09e0ad8d6b5e3e62 (diff)
Crest Mount Attempt 2
Crash on placement of crest mount
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/gmail/Lance5057/blocks/TileEntity_CrestMount.java111
-rw-r--r--src/main/java/gmail/Lance5057/proxy/ClientProxy.java19
-rw-r--r--src/main/java/gmail/Lance5057/proxy/Handler_CrestMount.java13
3 files changed, 100 insertions, 43 deletions
diff --git a/src/main/java/gmail/Lance5057/blocks/TileEntity_CrestMount.java b/src/main/java/gmail/Lance5057/blocks/TileEntity_CrestMount.java
index 2e9d848..c46cfa3 100644
--- a/src/main/java/gmail/Lance5057/blocks/TileEntity_CrestMount.java
+++ b/src/main/java/gmail/Lance5057/blocks/TileEntity_CrestMount.java
@@ -1,21 +1,21 @@
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 gmail.Lance5057.com.mod_TinkersDefense;
-import gmail.Lance5057.proxy.Handler_CrestMount;
import net.minecraft.entity.player.EntityPlayer;
-import net.minecraft.inventory.ContainerChest;
import net.minecraft.inventory.IInventory;
-import net.minecraft.inventory.InventoryLargeChest;
+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;
-import net.minecraft.world.World;
public class TileEntity_CrestMount extends TileEntity implements IInventory{
@@ -24,6 +24,12 @@ public class TileEntity_CrestMount extends TileEntity implements IInventory{
private int facing;
private int numUsingPlayers;
private int ticksSinceSync;
+ private boolean inventoryTouched;
+
+ public TileEntity_CrestMount()
+ {
+ super();
+ }
@Override
public int getSizeInventory() {
@@ -34,6 +40,12 @@ public class TileEntity_CrestMount extends TileEntity implements IInventory{
public ItemStack getStackInSlot(int slot) {
return inventory[slot];
}
+
+ @Override
+ public void markDirty()
+ {
+ super.markDirty();
+ }
@Override
public ItemStack decrStackSize(int slot, int amount) {
@@ -92,7 +104,15 @@ public class TileEntity_CrestMount extends TileEntity implements IInventory{
@Override
public boolean isUseableByPlayer(EntityPlayer player) {
- return true;
+ 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
@@ -126,33 +146,35 @@ public class TileEntity_CrestMount extends TileEntity implements IInventory{
@Override
public void updateEntity()
{
- super.updateEntity();
- ++this.ticksSinceSync;
- float f;
-
- if (!this.worldObj.isRemote && this.numUsingPlayers != 0 && (this.ticksSinceSync + this.xCoord + this.yCoord + this.zCoord) % 200 == 0)
- {
- this.numUsingPlayers = 0;
- f = 5.0F;
- List list = this.worldObj.getEntitiesWithinAABB(EntityPlayer.class, AxisAlignedBB.getBoundingBox((double)((float)this.xCoord - f), (double)((float)this.yCoord - f), (double)((float)this.zCoord - f), (double)((float)(this.xCoord + 1) + f), (double)((float)(this.yCoord + 1) + f), (double)((float)(this.zCoord + 1) + f)));
- Iterator iterator = list.iterator();
-
- while (iterator.hasNext())
- {
- EntityPlayer entityplayer = (EntityPlayer)iterator.next();
-
- if (entityplayer.openContainer instanceof ContainerChest)
- {
- IInventory iinventory = ((ContainerChest)entityplayer.openContainer).getLowerChestInventory();
-
- if (iinventory == this || iinventory instanceof InventoryLargeChest && ((InventoryLargeChest)iinventory).isPartOfLargeChest(this))
- {
- ++this.numUsingPlayers;
- }
- }
- }
- }
- }
+ 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) {
@@ -175,6 +197,29 @@ public class TileEntity_CrestMount extends TileEntity implements IInventory{
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_);
diff --git a/src/main/java/gmail/Lance5057/proxy/ClientProxy.java b/src/main/java/gmail/Lance5057/proxy/ClientProxy.java
index 32c768d..3a0f2f9 100644
--- a/src/main/java/gmail/Lance5057/proxy/ClientProxy.java
+++ b/src/main/java/gmail/Lance5057/proxy/ClientProxy.java
@@ -2,8 +2,12 @@ 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 net.minecraft.client.model.ModelBiped;
+import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.fml.client.registry.ClientRegistry;
@@ -38,4 +42,17 @@ public class ClientProxy extends CommonProxy {
return tutChest; //default, if whenever you should have passed on a wrong id
}
-} \ No newline at end of file
+ @Override
+ public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z)
+ {
+ 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()));
+ }
+ else
+ {
+ return null;
+ }
+ }
+ } \ No newline at end of file
diff --git a/src/main/java/gmail/Lance5057/proxy/Handler_CrestMount.java b/src/main/java/gmail/Lance5057/proxy/Handler_CrestMount.java
index 7923c94..85b740e 100644
--- a/src/main/java/gmail/Lance5057/proxy/Handler_CrestMount.java
+++ b/src/main/java/gmail/Lance5057/proxy/Handler_CrestMount.java
@@ -19,11 +19,6 @@ import cpw.mods.fml.common.network.internal.FMLProxyPacket;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
-/**
-* Handles the packet wrangling for CrestMount
-* @author cpw
-*
-*/
public enum Handler_CrestMount {
INSTANCE;
/**
@@ -58,10 +53,10 @@ protected void channelRead0(ChannelHandlerContext ctx, Message_CrestMount msg) t
{
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.type, msg.items);
-// }
+ if (te instanceof TileEntity_CrestMount)
+ {
+ ((TileEntity_CrestMount) te).handlePacketData(msg.items);
+ }
}
}
/**