@Override public void invalidate() { super.invalidate(); if (this.initnal) { MinecraftForge.EVENT_BUS.post(new EnergyTileUnloadEvent(this)); this.initnal = false; } }
@Override public void onReceivePacket(int packetID, ByteArrayDataInput dataStream) throws IOException { super.onReceivePacket(packetID, dataStream); if (this.worldObj.isRemote) { if (packetID == TilePacketType.DESCRIPTION.ordinal() || packetID == TilePacketType.INVENTORY.ordinal()) { this.readFromNBT(PacketManager.readNBTTagCompound(dataStream)); } } }
public void updateEntity() { super.updateEntity(); if (!this.initialized && this.worldObj != null) { this.intialize(); } if (!this.worldObj.isRemote) { if (this.lastX != this.xCoord || this.lastZ != this.yCoord || this.lastY != this.zCoord) { this.lastX = this.xCoord; this.lastY = this.yCoord; this.lastZ = this.zCoord; this.onUnloaded(); this.intialize(); } this.gainFuel(); if (this.generating > 0) { if (this.storage + this.generating <= this.maxStorage) { this.storage += this.generating; } else { this.storage = this.maxStorage; } } boolean needInvUpdate = false; double sentPacket = 0.0D; for (int i = 0; i < this.chargeSlots.length; ++i) { if (this.chargeSlots[i] != null && this.chargeSlots[i].getItem() instanceof IElectricItem && this.storage > 0) { sentPacket = ElectricItem.manager.charge( this.chargeSlots[i], (double) this.storage, Integer.MAX_VALUE, false, false); if (sentPacket > 0.0D) { needInvUpdate = true; } this.storage = (int) ((double) this.storage - sentPacket); } } if (needInvUpdate) { super.markDirty(); } } }
@Override public void readFromNBT(NBTTagCompound tagCompound) { super.readFromNBT(tagCompound); NBTTagList tagList = tagCompound.getTagList("Inventory"); for (int i = 0; i < tagList.tagCount(); i++) { NBTTagCompound tag = (NBTTagCompound) tagList.tagAt(i); byte slot = tag.getByte("Slot"); if (slot >= 0 && slot < inv.length) { inv[slot] = ItemStack.loadItemStackFromNBT(tag); } } this.waitTime = tagCompound.getInteger("waitTime"); this.storage = tagCompound.getInteger("storage"); this.production = tagCompound.getInteger("production"); }
@Override public void writeToNBT(NBTTagCompound nbttagcompound) { super.writeToNBT(nbttagcompound); 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); } } nbttagcompound.setTag("Items", nbtTagList); }
@Override public void readFromNBT(NBTTagCompound nbttagcompound) { super.readFromNBT(nbttagcompound); NBTTagList nbtTagList = nbttagcompound.getTagList("Items"); this.inventory = new ItemStack[this.getSizeInventory()]; for (int i = 0; i < nbtTagList.tagCount(); i++) { NBTTagCompound nbttagcompound1 = (NBTTagCompound) nbtTagList.tagAt(i); byte byte0 = nbttagcompound1.getByte("Slot"); if ((byte0 >= 0) && (byte0 < this.inventory.length)) { this.inventory[byte0] = ItemStack.loadItemStackFromNBT(nbttagcompound1); } } }
public void readFromNBT(NBTTagCompound nbttagcompound) { super.readFromNBT(nbttagcompound); this.storage = nbttagcompound.getInteger("storage"); this.lastX = nbttagcompound.getInteger("lastX"); this.lastY = nbttagcompound.getInteger("lastY"); this.lastZ = nbttagcompound.getInteger("lastZ"); NBTTagList nbttaglist = nbttagcompound.getTagList("Items", 10); this.chargeSlots = new ItemStack[this.getSizeInventory()]; for (int i = 0; i < nbttaglist.tagCount(); ++i) { NBTTagCompound nbttagcompound1 = nbttaglist.getCompoundTagAt(i); int j = nbttagcompound1.getByte("Slot") & 255; if (j >= 0 && j < this.chargeSlots.length) { this.chargeSlots[j] = ItemStack.loadItemStackFromNBT(nbttagcompound1); } } }
public void writeToNBT(NBTTagCompound nbttagcompound) { super.writeToNBT(nbttagcompound); NBTTagList nbttaglist = new NBTTagList(); nbttagcompound.setInteger("storage", this.storage); nbttagcompound.setInteger("lastX", this.lastX); nbttagcompound.setInteger("lastY", this.lastY); nbttagcompound.setInteger("lastZ", this.lastZ); for (int i = 0; i < this.chargeSlots.length; ++i) { if (this.chargeSlots[i] != null) { NBTTagCompound nbttagcompound1 = new NBTTagCompound(); nbttagcompound1.setByte("Slot", (byte) i); this.chargeSlots[i].writeToNBT(nbttagcompound1); nbttaglist.appendTag(nbttagcompound1); } } nbttagcompound.setTag("Items", nbttaglist); }
@Override public void writeToNBT(NBTTagCompound tagCompound) { super.writeToNBT(tagCompound); NBTTagList itemList = new NBTTagList(); for (int i = 0; i < inv.length; i++) { ItemStack stack = inv[i]; if (stack != null) { NBTTagCompound tag = new NBTTagCompound(); tag.setByte("Slot", (byte) i); stack.writeToNBT(tag); itemList.appendTag(tag); } } tagCompound.setTag("Inventory", itemList); tagCompound.setInteger("waitTime", this.waitTime); tagCompound.setInteger("storage", this.storage); tagCompound.setInteger("production", this.production); }
/** invalidates a tile entity */ public void invalidate() { if (this.loaded) { this.onUnloaded(); } super.invalidate(); }
/** validates a tile entity */ public void validate() { super.validate(); if (!this.isInvalid() && this.worldObj.blockExists(this.xCoord, this.yCoord, this.zCoord)) { this.onLoaded(); } }
public void onChunkUnload() { if (this.loaded) { this.onUnloaded(); } super.onChunkUnload(); }