Added Crushing ritual
This commit is contained in:
parent
4edc30db09
commit
c3b21fa223
5 changed files with 457 additions and 2 deletions
|
@ -6,9 +6,12 @@ import net.minecraft.entity.EntityLivingBase;
|
|||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.ISidedInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.potion.Potion;
|
||||
import net.minecraft.util.DamageSource;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import WayofTime.bloodmagic.api.altar.EnumAltarComponent;
|
||||
import WayofTime.bloodmagic.registry.ModBlocks;
|
||||
import WayofTime.bloodmagic.tile.TileInventory;
|
||||
|
@ -171,4 +174,301 @@ public class Utils
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to determine if stack1 can be placed into stack2. If stack2 is null
|
||||
* and stack1 isn't null, returns true. Ignores stack size
|
||||
*
|
||||
* @param stack1
|
||||
* Stack that is placed into a slot
|
||||
* @param stack2
|
||||
* Slot content that stack1 is placed into
|
||||
* @return True if they can be combined
|
||||
*/
|
||||
public static boolean canCombine(ItemStack stack1, ItemStack stack2)
|
||||
{
|
||||
if (stack1 == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (stack2 == null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (stack1.isItemStackDamageable() ^ stack2.isItemStackDamageable())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return stack1.getItem() == stack2.getItem() && stack1.getItemDamage() == stack2.getItemDamage() && ItemStack.areItemStackTagsEqual(stack1, stack2);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param stack1
|
||||
* Stack that is placed into a slot
|
||||
* @param stack2
|
||||
* Slot content that stack1 is placed into
|
||||
* @return Stacks after stacking
|
||||
*/
|
||||
public static ItemStack[] combineStacks(ItemStack stack1, ItemStack stack2, int transferMax)
|
||||
{
|
||||
ItemStack[] returned = new ItemStack[2];
|
||||
|
||||
if (canCombine(stack1, stack2))
|
||||
{
|
||||
int transferedAmount = Math.min(transferMax, stack2 == null ? stack1.stackSize : Math.min(stack2.getMaxStackSize() - stack2.stackSize, stack1.stackSize));
|
||||
if (transferedAmount > 0)
|
||||
{
|
||||
ItemStack copyStack = stack1.splitStack(transferedAmount);
|
||||
if (stack2 == null)
|
||||
{
|
||||
stack2 = copyStack;
|
||||
} else
|
||||
{
|
||||
stack2.stackSize += transferedAmount;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
returned[0] = stack1;
|
||||
returned[1] = stack2;
|
||||
|
||||
return returned;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param stack1
|
||||
* Stack that is placed into a slot
|
||||
* @param stack2
|
||||
* Slot content that stack1 is placed into
|
||||
* @return Stacks after stacking
|
||||
*/
|
||||
public static ItemStack[] combineStacks(ItemStack stack1, ItemStack stack2)
|
||||
{
|
||||
ItemStack[] returned = new ItemStack[2];
|
||||
|
||||
if (canCombine(stack1, stack2))
|
||||
{
|
||||
int transferedAmount = stack2 == null ? stack1.stackSize : Math.min(stack2.getMaxStackSize() - stack2.stackSize, stack1.stackSize);
|
||||
if (transferedAmount > 0)
|
||||
{
|
||||
ItemStack copyStack = stack1.splitStack(transferedAmount);
|
||||
if (stack2 == null)
|
||||
{
|
||||
stack2 = copyStack;
|
||||
} else
|
||||
{
|
||||
stack2.stackSize += transferedAmount;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
returned[0] = stack1;
|
||||
returned[1] = stack2;
|
||||
|
||||
return returned;
|
||||
}
|
||||
|
||||
public static ItemStack insertStackIntoInventory(ItemStack stack, IInventory inventory, EnumFacing dir)
|
||||
{
|
||||
if (stack == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
boolean[] canBeInserted = new boolean[inventory.getSizeInventory()];
|
||||
|
||||
if (inventory instanceof ISidedInventory)
|
||||
{
|
||||
int[] array = ((ISidedInventory) inventory).getSlotsForFace(dir);
|
||||
for (int in : array)
|
||||
{
|
||||
canBeInserted[in] = inventory.isItemValidForSlot(in, stack) && ((ISidedInventory) inventory).canInsertItem(in, stack, dir);
|
||||
}
|
||||
} else
|
||||
{
|
||||
for (int i = 0; i < canBeInserted.length; i++)
|
||||
{
|
||||
canBeInserted[i] = inventory.isItemValidForSlot(i, stack);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < inventory.getSizeInventory(); i++)
|
||||
{
|
||||
if (!canBeInserted[i])
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
ItemStack[] combinedStacks = combineStacks(stack, inventory.getStackInSlot(i));
|
||||
stack = combinedStacks[0];
|
||||
inventory.setInventorySlotContents(i, combinedStacks[1]);
|
||||
|
||||
if (stack.stackSize <= 0)
|
||||
{
|
||||
return stack;
|
||||
}
|
||||
}
|
||||
|
||||
return stack;
|
||||
}
|
||||
|
||||
public static boolean canInsertStackFullyIntoInventory(ItemStack stack, IInventory inventory, EnumFacing dir)
|
||||
{
|
||||
return canInsertStackFullyIntoInventory(stack, inventory, dir, false, 0);
|
||||
}
|
||||
|
||||
public static boolean canInsertStackFullyIntoInventory(ItemStack stack, IInventory inventory, EnumFacing dir, boolean fillToLimit, int limit)
|
||||
{
|
||||
if (stack == null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
int itemsLeft = stack.stackSize;
|
||||
|
||||
boolean[] canBeInserted = new boolean[inventory.getSizeInventory()];
|
||||
|
||||
if (inventory instanceof ISidedInventory)
|
||||
{
|
||||
int[] array = ((ISidedInventory) inventory).getSlotsForFace(dir);
|
||||
for (int in : array)
|
||||
{
|
||||
canBeInserted[in] = inventory.isItemValidForSlot(in, stack) && ((ISidedInventory) inventory).canInsertItem(in, stack, dir);
|
||||
}
|
||||
} else
|
||||
{
|
||||
for (int i = 0; i < canBeInserted.length; i++)
|
||||
{
|
||||
canBeInserted[i] = inventory.isItemValidForSlot(i, stack);
|
||||
}
|
||||
}
|
||||
|
||||
int numberMatching = 0;
|
||||
|
||||
if (fillToLimit)
|
||||
{
|
||||
for (int i = 0; i < inventory.getSizeInventory(); i++)
|
||||
{
|
||||
if (!canBeInserted[i])
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
ItemStack invStack = inventory.getStackInSlot(i);
|
||||
|
||||
if (invStack != null && canCombine(stack, invStack))
|
||||
{
|
||||
numberMatching += invStack.stackSize;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (fillToLimit && limit < stack.stackSize + numberMatching)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int i = 0; i < inventory.getSizeInventory(); i++)
|
||||
{
|
||||
if (!canBeInserted[i])
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
ItemStack invStack = inventory.getStackInSlot(i);
|
||||
boolean canCombine = canCombine(stack, invStack);
|
||||
if (canCombine)
|
||||
{
|
||||
if (invStack == null)
|
||||
{
|
||||
itemsLeft = 0;
|
||||
} else
|
||||
{
|
||||
itemsLeft -= (invStack.getMaxStackSize() - invStack.stackSize);
|
||||
}
|
||||
}
|
||||
|
||||
if (itemsLeft <= 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static ItemStack insertStackIntoInventory(ItemStack stack, IInventory inventory, EnumFacing dir, int limit)
|
||||
{
|
||||
if (stack == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
boolean[] canBeInserted = new boolean[inventory.getSizeInventory()];
|
||||
|
||||
if (inventory instanceof ISidedInventory)
|
||||
{
|
||||
int[] array = ((ISidedInventory) inventory).getSlotsForFace(dir);
|
||||
for (int in : array)
|
||||
{
|
||||
canBeInserted[in] = ((ISidedInventory) inventory).canInsertItem(in, stack, dir);
|
||||
}
|
||||
} else
|
||||
{
|
||||
for (int i = 0; i < canBeInserted.length; i++)
|
||||
{
|
||||
canBeInserted[i] = true;
|
||||
}
|
||||
}
|
||||
|
||||
int numberMatching = 0;
|
||||
|
||||
for (int i = 0; i < inventory.getSizeInventory(); i++)
|
||||
{
|
||||
if (!canBeInserted[i])
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
ItemStack invStack = inventory.getStackInSlot(i);
|
||||
|
||||
if (invStack != null && canCombine(stack, invStack))
|
||||
{
|
||||
numberMatching += invStack.stackSize;
|
||||
}
|
||||
}
|
||||
|
||||
if (numberMatching >= limit)
|
||||
{
|
||||
return stack;
|
||||
}
|
||||
|
||||
int newLimit = limit - numberMatching;
|
||||
|
||||
for (int i = 0; i < inventory.getSizeInventory(); i++)
|
||||
{
|
||||
if (!canBeInserted[i])
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
int prevStackSize = stack.stackSize;
|
||||
|
||||
ItemStack[] combinedStacks = combineStacks(stack, inventory.getStackInSlot(i), newLimit);
|
||||
stack = combinedStacks[0];
|
||||
inventory.setInventorySlotContents(i, combinedStacks[1]);
|
||||
|
||||
newLimit -= (prevStackSize - stack.stackSize);
|
||||
|
||||
if (newLimit <= 0 || stack.stackSize <= 0)
|
||||
{
|
||||
return stack;
|
||||
}
|
||||
}
|
||||
|
||||
return stack;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue