package micdoodle8.mods.galacticraft.planets.venus.tile; import micdoodle8.mods.galacticraft.core.inventory.IInventoryDefaults; import micdoodle8.mods.galacticraft.core.util.GCCoreUtil; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.BlockPos; import net.minecraft.world.World; public class TileEntityCrashedProbe extends TileEntity implements IInventoryDefaults { private ItemStack[] containingItems = new ItemStack[6]; private boolean hasCoreToDrop; @Override public void readFromNBT(NBTTagCompound nbt) { super.readFromNBT(nbt); if (nbt.hasKey("ctd")) { this.hasCoreToDrop = nbt.getBoolean("ctd"); } else this.hasCoreToDrop = true; //Legacy compatibility with worlds generated before this key used NBTTagList items = nbt.getTagList("Items", 10); this.containingItems = new ItemStack[this.getSizeInventory()]; for (int i = 0; i < items.tagCount(); ++i) { NBTTagCompound tagAt = items.getCompoundTagAt(i); int slot = tagAt.getByte("Slot") & 255; if (slot < this.containingItems.length) { this.containingItems[slot] = ItemStack.loadItemStackFromNBT(tagAt); } } } @Override public void writeToNBT(NBTTagCompound nbt) { super.writeToNBT(nbt); nbt.setBoolean("ctd", this.hasCoreToDrop); final NBTTagList list = new NBTTagList(); for (int i = 0; i < this.containingItems.length; ++i) { if (this.containingItems[i] != null) { final NBTTagCompound tagAt = new NBTTagCompound(); tagAt.setByte("Slot", (byte) i); this.containingItems[i].writeToNBT(tagAt); list.appendTag(tagAt); } } nbt.setTag("Items", list); } @Override public boolean hasCustomName() { return true; } @Override public String getName() { return GCCoreUtil.translate("container.crashed_probe.name"); } @Override public int getSizeInventory() { return this.containingItems.length; } @Override public ItemStack getStackInSlot(int slot) { return this.containingItems[slot]; } @Override public ItemStack decrStackSize(int slot, int amount) { if (this.containingItems[slot] != null) { ItemStack var3; if (this.containingItems[slot].stackSize <= amount) { var3 = this.containingItems[slot]; this.containingItems[slot] = null; return var3; } else { var3 = this.containingItems[slot].splitStack(amount); if (this.containingItems[slot].stackSize == 0) { this.containingItems[slot] = null; } return var3; } } else { return null; } } @Override public ItemStack removeStackFromSlot(int slot) { if (this.containingItems[slot] != null) { final ItemStack var2 = this.containingItems[slot]; this.containingItems[slot] = null; return var2; } else { return null; } } @Override public void setInventorySlotContents(int slot, ItemStack itemStack) { this.containingItems[slot] = itemStack; if (itemStack != null && itemStack.stackSize > this.getInventoryStackLimit()) { itemStack.stackSize = this.getInventoryStackLimit(); } } @Override public int getInventoryStackLimit() { return 64; } @Override public boolean isUseableByPlayer(EntityPlayer player) { return this.worldObj.getTileEntity(this.getPos()) == this && player.getDistanceSq(this.getPos().getX() + 0.5D, this.getPos().getY() + 0.5D, this.getPos().getZ() + 0.5D) <= 64.0D; } @Override public boolean isItemValidForSlot(int slotID, ItemStack itemstack) { return true; } @Override public boolean shouldRefresh(World world, BlockPos pos, IBlockState oldState, IBlockState newSate) { return oldState.getBlock() != newSate.getBlock(); } public void setDropCore() { this.hasCoreToDrop = true; } public boolean getDropCore() { return this.hasCoreToDrop; } }