Run formatter

This commit is contained in:
Nicholas Ignoffo 2017-08-15 21:30:48 -07:00
parent 61c44a831b
commit 08258fd6ef
606 changed files with 13464 additions and 22975 deletions

View file

@ -1,54 +1,44 @@
package WayofTime.bloodmagic.api.compress;
import WayofTime.bloodmagic.util.Utils;
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 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.
*/
public class CompressionRegistry
{
public class CompressionRegistry {
public static List<CompressionHandler> compressionRegistry = new ArrayList<CompressionHandler>();
public static Map<ItemStack, Integer> thresholdMap = new HashMap<ItemStack, Integer>();
public static void registerHandler(CompressionHandler handler)
{
public static void registerHandler(CompressionHandler handler) {
compressionRegistry.add(handler);
}
/**
* Registers an item so that it only compresses while above this threshold
*
* @param stack
* item/block to be compressed
* @param threshold
* amount that is to be compressed
*
* @param stack item/block to be compressed
* @param threshold amount that is to be compressed
*/
public static void registerItemThreshold(ItemStack stack, int threshold)
{
public static void registerItemThreshold(ItemStack stack, int threshold) {
thresholdMap.put(stack, threshold);
}
public static ItemStack compressInventory(ItemStack[] inv, World world)
{
for (CompressionHandler handler : compressionRegistry)
{
public static ItemStack compressInventory(ItemStack[] inv, World world) {
for (CompressionHandler handler : compressionRegistry) {
ItemStack stack = handler.compressInventory(inv, world);
if (stack != null)
{
if (stack != null) {
return stack;
}
}
@ -56,32 +46,24 @@ public class CompressionRegistry
return null;
}
public static Pair<ItemStack, Boolean> compressInventory(TileEntity tile, World world)
{
if (tile.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, 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++)
{
for (int slot = 0; slot < itemHandler.getSlots(); slot++) {
inventory[slot] = itemHandler.extractItem(slot, 64, true);
copyInventory[slot] = inventory[slot].copy();
}
for (CompressionHandler handler : compressionRegistry)
{
for (CompressionHandler handler : compressionRegistry) {
ItemStack stack = handler.compressInventory(copyInventory, world);
if (!stack.isEmpty())
{
for (int slot = 0; slot < itemHandler.getSlots(); slot++)
{
if (inventory[slot] != null && !ItemStack.areItemStacksEqual(inventory[slot], copyInventory[slot]))
{
if (!stack.isEmpty()) {
for (int slot = 0; slot < itemHandler.getSlots(); slot++) {
if (inventory[slot] != null && !ItemStack.areItemStacksEqual(inventory[slot], copyInventory[slot])) {
itemHandler.extractItem(slot, inventory[slot].getCount(), false);
if (copyInventory[slot] != null)
{
if (copyInventory[slot] != null) {
itemHandler.insertItem(slot, copyInventory[slot], false);
}
}
@ -95,12 +77,9 @@ public class CompressionRegistry
return Pair.of(ItemStack.EMPTY, false);
}
public static int getItemThreshold(ItemStack stack)
{
for (Map.Entry<ItemStack, Integer> entry : thresholdMap.entrySet())
{
if (areItemStacksEqual(entry.getKey(), stack))
{
public static int getItemThreshold(ItemStack stack) {
for (Map.Entry<ItemStack, Integer> entry : thresholdMap.entrySet()) {
if (areItemStacksEqual(entry.getKey(), stack)) {
return entry.getValue();
}
}
@ -108,8 +87,7 @@ public class CompressionRegistry
return 0;
}
public static boolean areItemStacksEqual(ItemStack stack, ItemStack compressedStack)
{
public static boolean areItemStacksEqual(ItemStack stack, ItemStack compressedStack) {
return stack.isItemEqual(compressedStack) && (stack.getTagCompound() == null ? !compressedStack.hasTagCompound() : stack.getTagCompound().equals(compressedStack.getTagCompound()));
}
}