Finished the Augments for the Ritual of the Crusher.
This commit is contained in:
parent
655c2880dc
commit
da4de55c2e
6 changed files with 206 additions and 10 deletions
|
@ -1,13 +1,20 @@
|
|||
package WayofTime.bloodmagic.api.compress;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.items.CapabilityItemHandler;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import WayofTime.bloodmagic.util.Utils;
|
||||
|
||||
/**
|
||||
* A registry aimed to help compress items in an inventory into its compressible
|
||||
* form.
|
||||
|
@ -49,6 +56,45 @@ public class CompressionRegistry
|
|||
return null;
|
||||
}
|
||||
|
||||
public static Pair<ItemStack, Boolean> compressInventory(TileEntity tile, World world)
|
||||
{
|
||||
if (tile.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null))
|
||||
{
|
||||
IItemHandler itemHandler = tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
|
||||
ItemStack[] inventory = new ItemStack[itemHandler.getSlots()]; //THIS MUST NOT BE EDITED!
|
||||
ItemStack[] copyInventory = new ItemStack[itemHandler.getSlots()];
|
||||
|
||||
for (int slot = 0; slot < itemHandler.getSlots(); slot++)
|
||||
{
|
||||
inventory[slot] = itemHandler.extractItem(slot, 64, true);
|
||||
copyInventory[slot] = ItemStack.copyItemStack(inventory[slot]);
|
||||
}
|
||||
|
||||
for (CompressionHandler handler : compressionRegistry)
|
||||
{
|
||||
ItemStack stack = handler.compressInventory(copyInventory, world);
|
||||
if (stack != null)
|
||||
{
|
||||
for (int slot = 0; slot < itemHandler.getSlots(); slot++)
|
||||
{
|
||||
if (inventory[slot] != null && !ItemStack.areItemStacksEqual(inventory[slot], copyInventory[slot]))
|
||||
{
|
||||
itemHandler.extractItem(slot, inventory[slot].stackSize, false);
|
||||
if (copyInventory[slot] != null)
|
||||
{
|
||||
itemHandler.insertItem(slot, copyInventory[slot], false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Pair.of(Utils.insertStackIntoTile(stack, itemHandler), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Pair.of(null, false);
|
||||
}
|
||||
|
||||
public static int getItemThreshold(ItemStack stack)
|
||||
{
|
||||
for (Map.Entry<ItemStack, Integer> entry : thresholdMap.entrySet())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue