Crate Item Insert Improvement
This commit is contained in:
parent
d8f3f065be
commit
1be7f7c403
2 changed files with 84 additions and 55 deletions
|
@ -3,9 +3,9 @@ package assemblyline.common;
|
|||
import universalelectricity.prefab.UETab;
|
||||
import net.minecraft.item.Item;
|
||||
|
||||
public class ItemBlueprint extends Item
|
||||
public class ItemFilter extends Item
|
||||
{
|
||||
public ItemBlueprint(int id)
|
||||
public ItemFilter(int id)
|
||||
{
|
||||
super(id);
|
||||
this.setIconIndex(Item.paper.getIconFromDamage(0));
|
|
@ -31,18 +31,50 @@ public class BlockCrate extends BlockMachine
|
|||
* Placed the item the player is holding into the crate.
|
||||
*/
|
||||
@Override
|
||||
public boolean onMachineActivated(World world, int x, int y, int z, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9)
|
||||
public boolean onMachineActivated(World world, int x, int y, int z, EntityPlayer player, int par6, float par7, float par8, float par9)
|
||||
{
|
||||
if (!world.isRemote && world.getBlockTileEntity(x, y, z) != null)
|
||||
if (world.getBlockTileEntity(x, y, z) instanceof TileEntityCrate)
|
||||
{
|
||||
TileEntityCrate tileEntity = (TileEntityCrate) world.getBlockTileEntity(x, y, z);
|
||||
ItemStack containingStack = tileEntity.getStackInSlot(0);
|
||||
ItemStack itemStack = par5EntityPlayer.getCurrentEquippedItem();
|
||||
ItemStack requestStack = player.getCurrentEquippedItem();
|
||||
|
||||
if (itemStack != null)
|
||||
if (requestStack != null)
|
||||
{
|
||||
if (itemStack.isStackable())
|
||||
if (requestStack.isStackable())
|
||||
{
|
||||
for (int i = 0; i < player.inventory.getSizeInventory(); i++)
|
||||
{
|
||||
ItemStack currentStack = player.inventory.getStackInSlot(i);
|
||||
|
||||
if (currentStack != null)
|
||||
{
|
||||
if (requestStack != currentStack && requestStack.isItemEqual(currentStack))
|
||||
{
|
||||
player.inventory.setInventorySlotContents(i, this.putIn(tileEntity, currentStack));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
player.inventory.setInventorySlotContents(player.inventory.currentItem, this.putIn(tileEntity, requestStack));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Puts an itemStack into the crate.
|
||||
*
|
||||
* @param tileEntity
|
||||
* @param itemStack
|
||||
*/
|
||||
private ItemStack putIn(TileEntityCrate tileEntity, ItemStack itemStack)
|
||||
{
|
||||
ItemStack containingStack = tileEntity.getStackInSlot(0);
|
||||
|
||||
if (containingStack != null)
|
||||
{
|
||||
if (containingStack.isStackable() && containingStack.isItemEqual(itemStack))
|
||||
|
@ -69,15 +101,9 @@ public class BlockCrate extends BlockMachine
|
|||
itemStack.stackSize = 0;
|
||||
}
|
||||
|
||||
if (itemStack.stackSize <= 0)
|
||||
{
|
||||
par5EntityPlayer.inventory.setInventorySlotContents(par5EntityPlayer.inventory.currentItem, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (itemStack.stackSize <= 0) { return null; }
|
||||
|
||||
return true;
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -87,6 +113,8 @@ public class BlockCrate extends BlockMachine
|
|||
public boolean onSneakMachineActivated(World world, int x, int y, int z, EntityPlayer par5EntityPlayer, int side, float hitX, float hitY, float hitZ)
|
||||
{
|
||||
if (!world.isRemote && world.getBlockTileEntity(x, y, z) != null)
|
||||
{
|
||||
if (par5EntityPlayer.getCurrentEquippedItem() == null)
|
||||
{
|
||||
TileEntityCrate tileEntity = (TileEntityCrate) world.getBlockTileEntity(x, y, z);
|
||||
ItemStack containingStack = tileEntity.getStackInSlot(0);
|
||||
|
@ -119,6 +147,7 @@ public class BlockCrate extends BlockMachine
|
|||
tileEntity.setInventorySlotContents(0, containingStack);
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue