Bin inventory management works! I have no idea how I managed this...
This commit is contained in:
parent
2a4a1cd291
commit
42fe1f3d69
4 changed files with 74 additions and 30 deletions
|
@ -37,6 +37,11 @@ public class BinRecipe implements IRecipe, ICraftingHandler
|
|||
|
||||
@Override
|
||||
public ItemStack getCraftingResult(InventoryCrafting inv)
|
||||
{
|
||||
return getResult(inv);
|
||||
}
|
||||
|
||||
public ItemStack getResult(IInventory inv)
|
||||
{
|
||||
ItemStack bin = null;
|
||||
|
||||
|
@ -60,7 +65,6 @@ public class BinRecipe implements IRecipe, ICraftingHandler
|
|||
return null;
|
||||
}
|
||||
|
||||
int slotLoc = -1;
|
||||
ItemStack addStack = null;
|
||||
|
||||
for(int i = 0; i < 9; i++)
|
||||
|
@ -75,7 +79,6 @@ public class BinRecipe implements IRecipe, ICraftingHandler
|
|||
}
|
||||
|
||||
addStack = stack.copy();
|
||||
slotLoc = i;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -88,7 +91,7 @@ public class BinRecipe implements IRecipe, ICraftingHandler
|
|||
return null;
|
||||
}
|
||||
|
||||
ItemStack remain = binInv.add(addStack);
|
||||
binInv.add(addStack);
|
||||
|
||||
return bin;
|
||||
}
|
||||
|
@ -112,28 +115,57 @@ public class BinRecipe implements IRecipe, ICraftingHandler
|
|||
@Override
|
||||
public void onCrafting(EntityPlayer player, ItemStack item, IInventory craftMatrix)
|
||||
{
|
||||
if(getCraftingResult((InventoryCrafting)craftMatrix) != null)
|
||||
if(getResult(craftMatrix) != null)
|
||||
{
|
||||
for(int i = 0; i < craftMatrix.getSizeInventory(); i++)
|
||||
if(!isBin(item))
|
||||
{
|
||||
if(!isBin(item) && isBin(craftMatrix.getStackInSlot(i)))
|
||||
for(int i = 0; i < craftMatrix.getSizeInventory(); i++)
|
||||
{
|
||||
ItemStack bin = craftMatrix.getStackInSlot(i);
|
||||
InventoryBin inv = new InventoryBin(bin);
|
||||
|
||||
bin.stackTagCompound.setInteger("newCount", inv.getItemCount()-item.stackSize);
|
||||
if(isBin(craftMatrix.getStackInSlot(i)))
|
||||
{
|
||||
ItemStack bin = craftMatrix.getStackInSlot(i);
|
||||
InventoryBin inv = new InventoryBin(bin.copy());
|
||||
|
||||
int size = inv.getItemCount();
|
||||
|
||||
ItemStack testRemove = inv.removeStack();
|
||||
|
||||
bin.stackTagCompound.setInteger("newCount", size-(testRemove != null ? testRemove.stackSize : 0));
|
||||
}
|
||||
}
|
||||
else if(isBin(item) && craftMatrix.getStackInSlot(i) != null && !isBin(craftMatrix.getStackInSlot(i)))
|
||||
}
|
||||
else {
|
||||
int bin = -1;
|
||||
int other = -1;
|
||||
|
||||
for(int i = 0; i < craftMatrix.getSizeInventory(); i++)
|
||||
{
|
||||
if(isBin(craftMatrix.getStackInSlot(i)))
|
||||
{
|
||||
bin = i;
|
||||
}
|
||||
else if(!isBin(craftMatrix.getStackInSlot(i)) && craftMatrix.getStackInSlot(i) != null)
|
||||
{
|
||||
other = i;
|
||||
}
|
||||
}
|
||||
|
||||
ItemStack binStack = craftMatrix.getStackInSlot(bin);
|
||||
ItemStack otherStack = craftMatrix.getStackInSlot(other);
|
||||
|
||||
ItemStack testRemain = new InventoryBin(binStack.copy()).add(otherStack.copy());
|
||||
|
||||
if(testRemain != null && testRemain.stackSize > 0)
|
||||
{
|
||||
ItemStack proxy = new ItemStack(Mekanism.ItemProxy);
|
||||
((ItemProxy)proxy.getItem()).setSavedItem(proxy, craftMatrix.getStackInSlot(i));
|
||||
|
||||
craftMatrix.setInventorySlotContents(i, proxy);
|
||||
((ItemProxy)proxy.getItem()).setSavedItem(proxy, testRemain.copy());
|
||||
craftMatrix.setInventorySlotContents(other, proxy);
|
||||
}
|
||||
else if(isBin(item) && isBin(craftMatrix.getStackInSlot(i)))
|
||||
{
|
||||
craftMatrix.setInventorySlotContents(i, null);
|
||||
else {
|
||||
craftMatrix.setInventorySlotContents(other, null);
|
||||
}
|
||||
|
||||
craftMatrix.setInventorySlotContents(bin, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -218,6 +218,18 @@ public class BlockBasic extends Block
|
|||
|
||||
if(filled != null)
|
||||
{
|
||||
if(player.capabilities.isCreativeMode)
|
||||
{
|
||||
tileEntity.structure.fluidStored.amount -= FluidContainerRegistry.getFluidForFilledItem(filled).amount;
|
||||
|
||||
if(tileEntity.structure.fluidStored.amount == 0)
|
||||
{
|
||||
tileEntity.structure.fluidStored = null;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if(itemStack.stackSize > 1)
|
||||
{
|
||||
for(int i = 0; i < player.inventory.mainInventory.length; i++)
|
||||
|
|
|
@ -88,6 +88,12 @@ public class InventoryBin
|
|||
int id = bin.stackTagCompound.getInteger("itemID");
|
||||
int meta = bin.stackTagCompound.getInteger("itemMeta");
|
||||
|
||||
if(getItemCount() == 0 || id == 0)
|
||||
{
|
||||
setItemType(null);
|
||||
return null;
|
||||
}
|
||||
|
||||
return new ItemStack(id, 1, meta);
|
||||
}
|
||||
|
||||
|
|
|
@ -75,21 +75,15 @@ public class ItemBlockBasic extends ItemBlock
|
|||
{
|
||||
if(itemstack.getItemDamage() == 6)
|
||||
{
|
||||
if(!Keyboard.isKeyDown(Keyboard.KEY_LSHIFT))
|
||||
InventoryBin inv = new InventoryBin(itemstack);
|
||||
|
||||
if(inv.getItemCount() > 0)
|
||||
{
|
||||
list.add("Hold " + EnumColor.AQUA + "shift" + EnumColor.GREY + " for more details.");
|
||||
list.add(EnumColor.BRIGHT_GREEN + inv.getItemType().getDisplayName());
|
||||
list.add(EnumColor.INDIGO + "Item amount: " + EnumColor.GREY + inv.getItemCount());
|
||||
}
|
||||
else {
|
||||
InventoryBin inv = new InventoryBin(itemstack);
|
||||
|
||||
if(inv.getItemCount() > 0)
|
||||
{
|
||||
list.add(EnumColor.BRIGHT_GREEN + inv.getItemType().getDisplayName());
|
||||
list.add(EnumColor.INDIGO + "Item amount: " + EnumColor.GREY + inv.getItemCount());
|
||||
}
|
||||
else {
|
||||
list.add(EnumColor.DARK_RED + "Empty");
|
||||
}
|
||||
list.add(EnumColor.DARK_RED + "Empty");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -108,7 +102,7 @@ public class ItemBlockBasic extends ItemBlock
|
|||
return true;
|
||||
}
|
||||
|
||||
if(stack.stackTagCompound == null || !stack.stackTagCompound.hasKey("newCount") || stack.stackTagCompound.getInteger("newCount") == 0)
|
||||
if(stack.stackTagCompound == null || !stack.stackTagCompound.hasKey("newCount"))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue