Bin inventory management works! I have no idea how I managed this...
This commit is contained in:
parent
2a4a1cd291
commit
42fe1f3d69
|
@ -37,6 +37,11 @@ public class BinRecipe implements IRecipe, ICraftingHandler
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack getCraftingResult(InventoryCrafting inv)
|
public ItemStack getCraftingResult(InventoryCrafting inv)
|
||||||
|
{
|
||||||
|
return getResult(inv);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemStack getResult(IInventory inv)
|
||||||
{
|
{
|
||||||
ItemStack bin = null;
|
ItemStack bin = null;
|
||||||
|
|
||||||
|
@ -60,7 +65,6 @@ public class BinRecipe implements IRecipe, ICraftingHandler
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
int slotLoc = -1;
|
|
||||||
ItemStack addStack = null;
|
ItemStack addStack = null;
|
||||||
|
|
||||||
for(int i = 0; i < 9; i++)
|
for(int i = 0; i < 9; i++)
|
||||||
|
@ -75,7 +79,6 @@ public class BinRecipe implements IRecipe, ICraftingHandler
|
||||||
}
|
}
|
||||||
|
|
||||||
addStack = stack.copy();
|
addStack = stack.copy();
|
||||||
slotLoc = i;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,7 +91,7 @@ public class BinRecipe implements IRecipe, ICraftingHandler
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemStack remain = binInv.add(addStack);
|
binInv.add(addStack);
|
||||||
|
|
||||||
return bin;
|
return bin;
|
||||||
}
|
}
|
||||||
|
@ -112,28 +115,57 @@ public class BinRecipe implements IRecipe, ICraftingHandler
|
||||||
@Override
|
@Override
|
||||||
public void onCrafting(EntityPlayer player, ItemStack item, IInventory craftMatrix)
|
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);
|
if(isBin(craftMatrix.getStackInSlot(i)))
|
||||||
InventoryBin inv = new InventoryBin(bin);
|
{
|
||||||
|
ItemStack bin = craftMatrix.getStackInSlot(i);
|
||||||
bin.stackTagCompound.setInteger("newCount", inv.getItemCount()-item.stackSize);
|
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);
|
ItemStack proxy = new ItemStack(Mekanism.ItemProxy);
|
||||||
((ItemProxy)proxy.getItem()).setSavedItem(proxy, craftMatrix.getStackInSlot(i));
|
((ItemProxy)proxy.getItem()).setSavedItem(proxy, testRemain.copy());
|
||||||
|
craftMatrix.setInventorySlotContents(other, proxy);
|
||||||
craftMatrix.setInventorySlotContents(i, proxy);
|
|
||||||
}
|
}
|
||||||
else if(isBin(item) && isBin(craftMatrix.getStackInSlot(i)))
|
else {
|
||||||
{
|
craftMatrix.setInventorySlotContents(other, null);
|
||||||
craftMatrix.setInventorySlotContents(i, null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
craftMatrix.setInventorySlotContents(bin, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -218,6 +218,18 @@ public class BlockBasic extends Block
|
||||||
|
|
||||||
if(filled != null)
|
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)
|
if(itemStack.stackSize > 1)
|
||||||
{
|
{
|
||||||
for(int i = 0; i < player.inventory.mainInventory.length; i++)
|
for(int i = 0; i < player.inventory.mainInventory.length; i++)
|
||||||
|
|
|
@ -88,6 +88,12 @@ public class InventoryBin
|
||||||
int id = bin.stackTagCompound.getInteger("itemID");
|
int id = bin.stackTagCompound.getInteger("itemID");
|
||||||
int meta = bin.stackTagCompound.getInteger("itemMeta");
|
int meta = bin.stackTagCompound.getInteger("itemMeta");
|
||||||
|
|
||||||
|
if(getItemCount() == 0 || id == 0)
|
||||||
|
{
|
||||||
|
setItemType(null);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
return new ItemStack(id, 1, meta);
|
return new ItemStack(id, 1, meta);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -75,21 +75,15 @@ public class ItemBlockBasic extends ItemBlock
|
||||||
{
|
{
|
||||||
if(itemstack.getItemDamage() == 6)
|
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 {
|
else {
|
||||||
InventoryBin inv = new InventoryBin(itemstack);
|
list.add(EnumColor.DARK_RED + "Empty");
|
||||||
|
|
||||||
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");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -108,7 +102,7 @@ public class ItemBlockBasic extends ItemBlock
|
||||||
return true;
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue