p455w0rd Posted June 16, 2016 Posted June 16, 2016 gif of what is happening: Reveal hidden contents I had this working in 1.9 and somewhere along the way after updating to 1.9.4 it started doing this stuff. I'm assuming this is due to my lack of knowledge of TileEntities as I have no issues when I do this using a normal IInventory. I have been racking my brain for over a week on this. I don't know where I'm going wrong. ContainerCompressor public class ContainerCompressor extends Container { public TileEntityCompressor tileEntity; private final InventoryPlayer inventoryPlayer; public ContainerCompressor(InventoryPlayer inventoryPlayer, TileEntityCompressor te) { this.tileEntity = te; this.inventoryPlayer = inventoryPlayer; int xbase = 8; int ybase = 70; for (int i = 0; i < 9; i++) { addSlotToContainer(new Slot(this.inventoryPlayer, i, xbase + i * 18, ybase + 58)); } for (int i = 0; i < 3; i++) { for (int j = 0; j < 9; j++) { addSlotToContainer(new Slot(this.inventoryPlayer, j + i * 9 + 9, xbase + j * 18, ybase + i * 18)); } } // Input Slot addSlotToContainer(new CompressorSlot(this.tileEntity, 0, 49, 18)); // Output Slot addSlotToContainer(new CompressorSlot(this.tileEntity, 1, 106, 18)); } @Override public boolean canInteractWith(EntityPlayer player) { return true; } @Override public ItemStack slotClick(int slotId, int dragType, ClickType clickTypeIn, EntityPlayer player) { System.out.println("Slot: "+slotId); ItemStack itemstack = null; InventoryPlayer inventoryplayer = player.inventory; if (slotId > 35) { return null; } return super.slotClick(slotId, dragType, clickTypeIn, player); } @Override public ItemStack transferStackInSlot(EntityPlayer player, int slot) { ItemStack stack = null; try { 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(); // Block->Player Inventory if (slot > 35) { if (!this.mergeItemStack(stackInSlot, 0, 36, true)) { return null; } // Player->Block Inventory } else if (!this.mergeItemStack(stackInSlot, 36, 37, false)) { return null; } if (stackInSlot.stackSize <= 0) { slotObject.putStack(null); } else { slotObject.onSlotChanged(); } if (stackInSlot.stackSize == stack.stackSize) { return null; } slotObject.onPickupFromSlot(player, stackInSlot); } } catch (Exception e) { } return stack; } } TileEntityCompressor public class TileEntityCompressor extends TileEntity implements IPEnergyBlock, ISidedInventory, IPEnergyBlock.Receiver { protected ItemStack[] compressorInv; protected int capacity; protected int maxReceive; protected int maxExtract; protected EnergyStorage energyStorage; private boolean isProcessing; private float pctCompleted; public float ticks = 0; public float rotation = 0; public boolean rev = false; public TileEntityCompressor() { capacity = 1600000; maxReceive = 2000; maxExtract = 2000; compressorInv = new ItemStack[2]; energyStorage = new EnergyStorage(capacity, maxReceive); } @Override public SPacketUpdateTileEntity getUpdatePacket() { NBTTagCompound nbtTag = new NBTTagCompound(); this.writeToNBT(nbtTag); return new SPacketUpdateTileEntity(getPos(), 0, nbtTag); } @Override public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity packet) { this.readFromNBT(packet.getNbtCompound()); } @Override public NBTTagCompound getUpdateTag() { NBTTagCompound updateTag = super.getUpdateTag(); writeToNBT(updateTag); return updateTag; } public boolean isProcessing() { return isProcessing; } public void setProcessing(boolean t) { this.isProcessing = t; } public String getName() { return "compressorBlock"; } @Override public int getSizeInventory() { return 2; } @Override public ItemStack getStackInSlot(int index) { return compressorInv[index]; } @Override public ItemStack decrStackSize(int index, int count) { ItemStack stack = ((ItemStack) compressorInv[index]); if (stack.stackSize >= count) { setInventorySlotContents(index, null); } else { setInventorySlotContents(index, new ItemStack(stack.getItem(), count)); stack.stackSize -= count; } markDirty(); return stack; } @Override public ItemStack removeStackFromSlot(int index) { ItemStack itemStack = getStackInSlot(index); if (itemStack != null) { setInventorySlotContents(index, null); } markDirty(); return itemStack; } public static boolean isSameItem(@Nullable final ItemStack left, @Nullable final ItemStack right) { return left != null && right != null && left.isItemEqual(right); } @Override public void setInventorySlotContents(final int slot, final ItemStack newItemStack) { final ItemStack oldStack = this.compressorInv[slot]; this.compressorInv[slot] = newItemStack; ItemStack removed = oldStack; ItemStack added = newItemStack; if (oldStack != null && newItemStack != null && isSameItem(oldStack, newItemStack)) { if (oldStack.stackSize > newItemStack.stackSize) { removed = removed.copy(); removed.stackSize -= newItemStack.stackSize; added = null; } else if (oldStack.stackSize < newItemStack.stackSize) { added = added.copy(); added.stackSize -= oldStack.stackSize; removed = null; } else { removed = added = null; } } this.markDirty(); } @Override public int getInventoryStackLimit() { return 64; } @Override public boolean isUseableByPlayer(EntityPlayer player) { return true; } @Override public void openInventory(EntityPlayer player) { } @Override public void closeInventory(EntityPlayer player) { } @Override public int getField(int id) { return 0; } @Override public void setField(int id, int value) { } @Override public int getFieldCount() { return 0; } @Override public void clear() { } @Override public boolean hasCustomName() { return false; } @Override public ITextComponent getDisplayName() { return new TextComponentString(getName()); } @Override public boolean canConnectEnergy(EnumFacing from) { return true; } @Override public int getEnergyStored(EnumFacing from) { return this.energyStorage.getEnergyStored(); } public int getEnergy() { return getEnergyStored(EnumFacing.DOWN); } @Override public int getMaxEnergyStored(EnumFacing from) { return energyStorage.getMaxEnergyStored(); } public int getMaxExtract() { return maxExtract; } @Override public int[] getSlotsForFace(EnumFacing side) { int[] validSlots = { 0, 1 }; return validSlots; } @Override public boolean canInsertItem(int index, ItemStack itemStackIn, EnumFacing direction) { if (index == 0) { return true; } return false; } @Override public boolean canExtractItem(int index, ItemStack stack, EnumFacing direction) { if (index == 1) { return true; } return false; } @Override public int receiveEnergy(EnumFacing from, int maxExtract, boolean simulate) { int tosend = energyStorage.receiveEnergy(maxExtract, simulate); if (tosend > 0 && !simulate) { this.markDirty(); } return tosend; } @Override public void setEnergyStored(int energy) { this.energyStorage.setEnergyStored(energy); this.markDirty(); } public EnergyStorage getEnergyStorage() { return this.energyStorage; } public int getMaxCapacity() { return getMaxEnergyStored(EnumFacing.DOWN); } public boolean hasEnergy() { return getEnergy() > 0; } private void handleProcessing() { if (hasEnergy()) { if (getOutputSlotStack() == null || getOutputSlotStack().stackSize < getOutputSlotStack().getMaxStackSize()) { } } } public ItemStack getInputSlotStack() { return compressorInv[0]; } public ItemStack getOutputSlotStack() { return compressorInv[1]; } @Override public void readFromNBT(NBTTagCompound tagCompound) { super.readFromNBT(tagCompound); NBTTagCompound energyTag = tagCompound.getCompoundTag("Energy"); this.energyStorage.readFromNBT(energyTag); NBTTagList nbtTL = tagCompound.getTagList(this.getName(), 10); for (int i = 0; i < nbtTL.tagCount(); i++) { NBTTagCompound nbtTC = (NBTTagCompound) nbtTL.getCompoundTagAt(i); if (nbtTC == null) { continue; } int slot = nbtTC.getInteger("Slot"); this.compressorInv[slot] = ItemStack.loadItemStackFromNBT(nbtTC); } } @Override public NBTTagCompound writeToNBT(NBTTagCompound tagCompound) { tagCompound = super.writeToNBT(tagCompound); NBTTagCompound energyTag = new NBTTagCompound(); this.energyStorage.writeToNBT(energyTag); tagCompound.setTag("Energy", energyTag); NBTTagList nbtTL = new NBTTagList(); for (int i = 0; i < this.compressorInv.length; i++) { if (compressorInv[i] == null) { continue; } NBTTagCompound nbtTC = new NBTTagCompound(); nbtTC.setInteger("Slot", i); compressorInv[i].writeToNBT(nbtTC); nbtTL.appendTag(nbtTC); } tagCompound.setTag(this.getName(), nbtTL); return tagCompound; } @Override public boolean isItemValidForSlot(int index, ItemStack stack) { /* if (index == 0 && CompressorRecipeRegistry.INSTANCE.getInputList() != null) { List<ItemStack> inputList = CompressorRecipeRegistry.INSTANCE.getInputList(); for (int i = 0; i < inputList.size(); i++) { if (ItemUtils.areItemsEqual(stack, inputList.get(i))) { return true; } } } return false; */ return true; } @Override public void update() { if (getWorld().isRemote) { return; } handleReceivingEnergy(); getWorld().markAndNotifyBlock(getPos(), getWorld().getChunkFromBlockCoords(getPos()), getWorld().getBlockState(getPos()), getWorld().getBlockState(getPos()), 3); } private void handleReceivingEnergy() { if (!worldObj.isRemote) { if (getEnergy() >= getMaxCapacity()) { return; } for (EnumFacing dir : EnumFacing.values()) { BlockPos targetBlock = getPos().add(dir.getDirectionVec()); TileEntity tile = worldObj.getTileEntity(targetBlock); if (tile instanceof IEnergyProvider) { IEnergyProvider provider = (IEnergyProvider) tile; if (provider.canConnectEnergy(dir.getOpposite())) { int toget = energyStorage.receiveEnergy(this.maxReceive, true); int received = ((IEnergyProvider) tile).extractEnergy(dir.getOpposite(), toget, false); if (received > 0) { this.markDirty(); } energyStorage.receiveEnergy(received, false); } } } } } } CompressorSlot public class CompressorSlot extends Slot { public final int xDisplayPosition; public final int yDisplayPosition; private final int slotIndex; public int slotNumber; public final IInventory inventory; public CompressorSlot(final IInventory inv, final int idx, final int x, final int y) { super(inv, idx, x, y); this.slotIndex = idx; this.xDisplayPosition = x; this.yDisplayPosition = y; this.inventory = inv; } public String getTooltip() { return null; } public void clearStack() { putStack(null); } @Override public boolean isItemValid(final ItemStack itemStackIn) { return inventory.isItemValidForSlot(getSlotIndex(), itemStackIn); } @Override public ItemStack getStack() { if (this.inventory.getSizeInventory() <= this.getSlotIndex()) { return null; } return this.inventory.getStackInSlot(this.slotIndex); } @Override public int getSlotIndex() { return this.slotIndex; } @Override public void onPickupFromSlot(EntityPlayer playerIn, ItemStack stack) { this.onSlotChanged(); } @SideOnly(Side.CLIENT) public boolean canBeHovered() { return true; } @Override public boolean getHasStack() { return this.getStack() != null; } @Override public void putStack(ItemStack stack) { this.inventory.setInventorySlotContents(this.slotIndex, stack); this.onSlotChanged(); } @Override public void onSlotChanged() { if (this.inventory instanceof InventoryDankNull) { this.inventory.markDirty(); } } @Override public int getSlotStackLimit() { return this.inventory.getInventoryStackLimit(); } @Override public int getItemStackLimit(ItemStack stack) { return this.getSlotStackLimit(); } @Override public ItemStack decrStackSize(int amount) { return this.inventory.decrStackSize(this.slotIndex, amount); } @Override public boolean canTakeStack(EntityPlayer playerIn) { return true; } public int getX() { return this.xDisplayPosition; } public int getY() { return this.yDisplayPosition; } } GuiHandler public class GuiHandler implements IGuiHandler { @Override public Object getServerGuiElement(int ID, EntityPlayer playerIn, World worldIn, int x, int y, int z) { if (ID == Globals.GUINUM_DANKNULL) { return new ContainerDankNull(playerIn); } else { TileEntity te = worldIn.getTileEntity(new BlockPos(x, y, z)); if (te == null) { return null; } if (ID == Globals.GUINUM_COMPRESSOR) { return new ContainerCompressor(playerIn.inventory, (TileEntityCompressor) te); } else if (ID == Globals.GUINUM_FURNACE) { return new ContainerFurnace(playerIn.inventory, (TileEntityFurnace) te); } else if (ID == Globals.GUINUM_BATTERY) { return new ContainerBattery(playerIn.inventory, (TileEntityBattery) te); } } return null; } @Override public Object getClientGuiElement(int ID, EntityPlayer playerIn, World worldIn, int x, int y, int z) { if (ID == Globals.GUINUM_DANKNULL) { return new GuiDankNull(new ContainerDankNull(playerIn), playerIn.inventory); } else { TileEntity te = worldIn.getTileEntity(new BlockPos(x, y, z)); if (te == null) { return null; } if (ID == Globals.GUINUM_COMPRESSOR) { return new GuiCompressor(new ContainerCompressor(playerIn.inventory, (TileEntityCompressor) te)); } else if (ID == Globals.GUINUM_FURNACE) { return new GuiFurnace(new ContainerFurnace(playerIn.inventory, (TileEntityFurnace) te)); } else if (ID == Globals.GUINUM_BATTERY) { return new GuiBattery(new ContainerBattery(playerIn.inventory, (TileEntityBattery) te)); } else if (ID == Globals.GUINUM_SOLARPANEL) { return new GuiSolarPanel((TileEntitySolarPanel) te); } } return null; } public static void launchGui(final int ID, final EntityPlayer playerIn, final World worldIn, final int x, final int y, final int z) { playerIn.openGui(P455w0rdsThings.INSTANCE, ID, worldIn, x, y, z); } } Quote http://p455w0rd.net/images/forumsignature.png[/img]
CreativeMD Posted June 16, 2016 Posted June 16, 2016 One of your problems is caused by id duplicates. // Input Slot addSlotToContainer(new CompressorSlot(this.tileEntity, 0, 49, 18)); // Output Slot addSlotToContainer(new CompressorSlot(this.tileEntity, 1, 106, 18)); slot id 0 and 1 are already taken by your player inventory. You have to change it above 36 (if i'm not mistaken). Quote
p455w0rd Posted June 16, 2016 Author Posted June 16, 2016 I wish this were true, but those id's are setting the ID of the referenced inventory (TileEntity in this case), where the player inventory is a separate inventory with it's own set of IDs. The slot number of the container is set as slots are added (via the inventorySlots list in net.minecraft.inventory.Container). Quote http://p455w0rd.net/images/forumsignature.png[/img]
Draco18s Posted June 16, 2016 Posted June 16, 2016 On 6/16/2016 at 9:54 PM, p455w0rd said: I wish this were true, but those id's are setting the ID of the referenced inventory (TileEntity in this case), where the player inventory is a separate inventory with it's own set of IDs. The slot number of the container is set as slots are added (via the inventorySlots list in net.minecraft.inventory.Container). Both of the quoted lines refer to your TE's inventory. Quote Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
p455w0rd Posted June 16, 2016 Author Posted June 16, 2016 In my Wireless Crafting Terminal mod, as well as my /dank/null item and BedrockMiner's tutorial on the subject @ http://bedrockminer.jimdo.com/modding-tutorials/advanced-modding/gui-container/ , there are multiple slots assigned with same ID's and they work perfectly. (slots 0-8 in BRM's tutorial are assigned IDs 0-8..slots 36-44 are also assigned ID's of 0-...I'm lost... Quote http://p455w0rd.net/images/forumsignature.png[/img]
Draco18s Posted June 16, 2016 Posted June 16, 2016 Yeah...of two different inventories. Quote Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
p455w0rd Posted June 17, 2016 Author Posted June 17, 2016 Well, my TE implements ISidedInventory which extends IInventory which is a separate inventory from InventoryPlayer, no? Are these not two different inventories? Quote http://p455w0rd.net/images/forumsignature.png[/img]
p455w0rd Posted June 18, 2016 Author Posted June 18, 2016 Okay, so I converted to IItemHandler (via Choonster's Examples)..same thing persists. (And I figured as much would be the case). So I'm stumped still. I've tried all sorts of combinations of ordering the slots in the container with the only positive result being that when I add hotbar slots, followed by the 27 player inv slots, followed by the 2 custom slots, the player inv slots function correctly..still can't pick up hotbar items and when I click either of the 2 custom slots, it acts as if I'm clicking slots 0/1 on the hotbar. I am able to successfully insert items via a hopper. Updates to code can be found on github @ https://github.com/p455w0rd/p455w0rds1.9Things Quote http://p455w0rd.net/images/forumsignature.png[/img]
p455w0rd Posted June 18, 2016 Author Posted June 18, 2016 While I had forgotten to do that, it isn't the problem. I tried using the default texture/sizes from GuiContainer and I tried using custom xSize/ySize (set in constructor) to no avail. Quote http://p455w0rd.net/images/forumsignature.png[/img]
p455w0rd Posted June 18, 2016 Author Posted June 18, 2016 Updated GuiCompressor to have actual dimensions set (xSize is 176): https://github.com/p455w0rd/p455w0rds1.9Things/blob/master/src/java/p455w0rd/p455w0rdsthings/client/gui/GuiCompressor.java Also all other code related to compressor machine is now using IItemHandler: ContainerCompressor: https://github.com/p455w0rd/p455w0rds1.9Things/blob/master/src/java/p455w0rd/p455w0rdsthings/container/ContainerCompressor.java TileEntityCompressor: https://github.com/p455w0rd/p455w0rds1.9Things/blob/master/src/java/p455w0rd/p455w0rdsthings/blocks/tileentities/TileEntityCompressor.java It definitely reminds of the issue I had a good while back when working on the Wireless Crafting Terminal when I had forgotten to set the dimensions of the GUI. The difference is that setting that info did nothing for the issue I'm experiencing currently. Quote http://p455w0rd.net/images/forumsignature.png[/img]
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.