Jump to content

[1.8] Container Not Working Properly


Tikaji

Recommended Posts

Ok so first of I'm assuming its the container that's not working correctly. I've been updating to 1.8 and this is the first major issue I've run into. Well more like two problems.

 

One of my Tile Entities will accept an item however it will immediately spit it back out but create a copy of the item in the correct slot with a stack size of zero.

 

The other Tile Entity just eats the item and nothing happens.

 

I copied my code over from 1.7.10, and using TheGreyGhost's MinecraftByExample updated it to 1.8. I'm not entirely sure where exactly my issue is so if you need anything to help just let me know.

 

Any help is much appreciated.

 

Container that spits item out:

 

 

public class ContainerCrusher extends ContainerHC

{

private int lastCrushTime;

private TileEntityCrusher tileEntity;

 

public ContainerCrusher(InventoryPlayer inventoryPlayer, TileEntityCrusher te)

{

this.addSlotToContainer(new Slot(te, 0, 56, 34));

this.addSlotToContainer(new Slot(te, 1, 116, 34));

this.addSlotToContainer(new Slot(te, 2, 8, 62));

this.addPlayerSlots(inventoryPlayer, 8, 84);

 

this.tileEntity = te;

}

 

@Override

public void addCraftingToCrafters(ICrafting p_75132_1_)

{

super.addCraftingToCrafters(p_75132_1_);

p_75132_1_.sendProgressBarUpdate(this, 0, this.tileEntity.getCrushTime());

p_75132_1_.sendProgressBarUpdate(this, 1, this.tileEntity.getCrushTime());

 

p_75132_1_.func_175173_a(this, this.tileEntity);

}

 

@Override

public boolean canInteractWith(EntityPlayer playerIn)

{

return tileEntity.isUseableByPlayer(playerIn);

}

 

@Override

public void detectAndSendChanges()

{

super.detectAndSendChanges();

 

for (Object crafter : this.crafters)

{

ICrafting icrafting = (ICrafting) crafter;

 

if (this.lastCrushTime != this.tileEntity.getCrushTime())

{

icrafting.sendProgressBarUpdate(this, 0, this.tileEntity.getCrushTime());

}

}

 

this.lastCrushTime = this.tileEntity.getField(0);

}

 

@Override

public ItemStack transferStackInSlot(EntityPlayer player, int slotIndex)

{

ItemStack itemstack = null;

Slot slot = (Slot) this.inventorySlots.get(slotIndex);

 

if (slot != null && slot.getHasStack())

{

ItemStack itemstack1 = slot.getStack();

itemstack = itemstack1.copy();

 

//Change accordingly from here...

if (slotIndex < 3)

{

if (!this.mergeItemStack(itemstack1, 3, 39, true))

{

return null;

}

}

else

{

if (itemstack1.stackSize == 1)

{

for (int i = 0; i < 3; i++)

{

//Shift click single items only

Slot shiftedInSlot = ((Slot) inventorySlots.get(i));

if (!shiftedInSlot.getHasStack() && shiftedInSlot.isItemValid(itemstack1))

{

mergeItemStack(itemstack1, i, i + 1, false);

}

}

return null;

}

}

//..to here.

 

if (itemstack1.stackSize == 0)

{

slot.putStack((ItemStack) null);

}

else

{

slot.onSlotChanged();

}

 

if (itemstack1.stackSize == itemstack.stackSize)

{

return null;

}

 

slot.onPickupFromSlot(player, itemstack1);

}

 

return itemstack;

}

 

@SideOnly(Side.CLIENT)

public void updateProgressBar(int p_75137_1_, int p_75137_2_)

{

if (p_75137_1_ == 0)

{

this.tileEntity.setCrushTime(p_75137_2_);

}

}

}

 

 

 

Container that eats items

 

 

public class ContainerLaserFurnace extends ContainerHC

{

private int lastCookTime;

private TileEntityLaserFurnace te;

 

public ContainerLaserFurnace(InventoryPlayer inventoryPlayer, TileEntityLaserFurnace te)

{

this.addSlotToContainer(new Slot(te, 0, 56, 17));

this.addSlotToContainer(new Slot(te, 1, 116, 35));

this.addSlotToContainer(new Slot(te, 2, 8, 62));

 

this.addPlayerSlots(inventoryPlayer, 8, 84);

this.te = te;

}

 

@Override

public void addCraftingToCrafters(ICrafting p_75132_1_)

{

super.addCraftingToCrafters(p_75132_1_);

p_75132_1_.sendProgressBarUpdate(this, 0, this.te.getFurnaceCookTime());

p_75132_1_.sendProgressBarUpdate(this, 1, this.te.getFurnaceCookTime());

 

p_75132_1_.func_175173_a(this, te);

}

 

@Override

public boolean canInteractWith(EntityPlayer p_75145_1_)

{

return te.isUseableByPlayer(p_75145_1_);

}

 

@Override

public void detectAndSendChanges()

{

super.detectAndSendChanges();

 

for (int i = 0; i < this.crafters.size(); ++i)

{

ICrafting icrafting = (ICrafting) this.crafters.get(i);

 

if (this.lastCookTime != this.te.getFurnaceCookTime())

{

icrafting.sendProgressBarUpdate(this, 0, this.te.getFurnaceCookTime());

}

}

 

this.lastCookTime = this.te.getFurnaceCookTime();

}

 

@Override

public ItemStack transferStackInSlot(EntityPlayer player, int slotIndex)

{

ItemStack itemstack = null;

Slot slot = (Slot) this.inventorySlots.get(slotIndex);

 

if (slot != null && slot.getHasStack())

{

ItemStack itemstack1 = slot.getStack();

itemstack = itemstack1.copy();

 

//Change accordingly from here...

if (slotIndex < 3)

{

if (!this.mergeItemStack(itemstack1, 3, 39, true))

{

return null;

}

}

else

{

if (itemstack1.stackSize == 1)

{

for (int i = 0; i < 3; i++)

{

//Shift click single items only

Slot shiftedInSlot = ((Slot) inventorySlots.get(i));

if (!shiftedInSlot.getHasStack() && shiftedInSlot.isItemValid(itemstack1))

{

mergeItemStack(itemstack1, i, i + 1, false);

}

}

return null;

}

}

//..to here.

 

if (itemstack1.stackSize == 0)

{

slot.putStack((ItemStack) null);

}

else

{

slot.onSlotChanged();

}

 

if (itemstack1.stackSize == itemstack.stackSize)

{

return null;

}

 

slot.onPickupFromSlot(player, itemstack1);

}

 

return itemstack;

}

 

@SideOnly(Side.CLIENT)

public void updateProgressBar(int p_75137_1_, int p_75137_2_)

{

if (p_75137_1_ == 0)

{

this.te.setFurnaceCookTime(p_75137_2_);

}

}

}

 

 

 

Base Container

 

 

public abstract class ContainerHC extends Container

{

protected void addPlayerSlots(InventoryPlayer playerInventory, int x, int y)

{

for (int i = 0; i < 3; ++i)

{

for (int j = 0; j < 9; ++j)

{

addSlotToContainer(new Slot(playerInventory, j + i * 9 + 9, x + j * 18, y + i * 18));

}

}

 

for (int i = 0; i < 9; ++i)

{

addSlotToContainer(new Slot(playerInventory, i, x + i * 18, y + 58));

}

}

}

 

 

Link to comment
Share on other sites

Did you open the Gui and Container on the client or server side?

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.