Run formatter
This commit is contained in:
parent
61c44a831b
commit
08258fd6ef
606 changed files with 13464 additions and 22975 deletions
|
@ -8,34 +8,26 @@ import net.minecraft.inventory.InventoryCrafting;
|
|||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class AdvancedCompressionHandler extends CompressionHandler
|
||||
{
|
||||
public class AdvancedCompressionHandler extends CompressionHandler {
|
||||
@Override
|
||||
public ItemStack compressInventory(ItemStack[] inv, World world)
|
||||
{
|
||||
public ItemStack compressInventory(ItemStack[] inv, World world) {
|
||||
return test(inv, true, world);
|
||||
}
|
||||
|
||||
public ItemStack test(ItemStack[] inv, boolean doDrain, World world)
|
||||
{
|
||||
for (ItemStack invStack : inv)
|
||||
{
|
||||
if (invStack.isEmpty())
|
||||
{
|
||||
public ItemStack test(ItemStack[] inv, boolean doDrain, World world) {
|
||||
for (ItemStack invStack : inv) {
|
||||
if (invStack.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (int i = 2; i <= 3; i++)
|
||||
{
|
||||
for (int i = 2; i <= 3; i++) {
|
||||
ItemStack stack = getRecipe(invStack, world, i);
|
||||
if (!stack.isEmpty())
|
||||
{
|
||||
if (!stack.isEmpty()) {
|
||||
int threshold = CompressionRegistry.getItemThreshold(invStack);
|
||||
|
||||
int needed = i * i;
|
||||
int neededLeft = iterateThroughInventory(invStack, threshold + invStack.getMaxStackSize() - needed, inv, needed, false);
|
||||
if (neededLeft <= 0)
|
||||
{
|
||||
if (neededLeft <= 0) {
|
||||
iterateThroughInventory(invStack, 0, inv, needed, true);
|
||||
return stack;
|
||||
}
|
||||
|
@ -46,39 +38,31 @@ public class AdvancedCompressionHandler extends CompressionHandler
|
|||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
public int iterateThroughInventory(ItemStack required, int kept, ItemStack[] inv, int needed, boolean doDrain)
|
||||
{
|
||||
public int iterateThroughInventory(ItemStack required, int kept, ItemStack[] inv, int needed, boolean doDrain) {
|
||||
int i = -1;
|
||||
|
||||
for (ItemStack invStack : inv)
|
||||
{
|
||||
for (ItemStack invStack : inv) {
|
||||
i++;
|
||||
|
||||
if (invStack.isEmpty())
|
||||
{
|
||||
if (invStack.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (invStack.isItemEqual(required) && (invStack.getTagCompound() == null ? required.getTagCompound() == null : invStack.getTagCompound().equals(required.getTagCompound())))
|
||||
{
|
||||
if (invStack.isItemEqual(required) && (invStack.getTagCompound() == null ? required.getTagCompound() == null : invStack.getTagCompound().equals(required.getTagCompound()))) {
|
||||
int stackSize = invStack.getCount();
|
||||
int used = 0;
|
||||
if (kept > 0)
|
||||
{
|
||||
if (kept > 0) {
|
||||
int remainingFromStack = Math.max(stackSize - kept, 0);
|
||||
used += stackSize - remainingFromStack;
|
||||
}
|
||||
|
||||
kept -= used;
|
||||
|
||||
if (kept <= 0 && needed > 0)
|
||||
{
|
||||
if (kept <= 0 && needed > 0) {
|
||||
int remainingFromStack = Math.max(stackSize - used - needed, 0);
|
||||
if (doDrain)
|
||||
{
|
||||
if (doDrain) {
|
||||
invStack.setCount(remainingFromStack + used);
|
||||
if (invStack.isEmpty())
|
||||
{
|
||||
if (invStack.isEmpty()) {
|
||||
inv[i] = ItemStack.EMPTY;
|
||||
}
|
||||
}
|
||||
|
@ -86,8 +70,7 @@ public class AdvancedCompressionHandler extends CompressionHandler
|
|||
needed -= (stackSize - used - remainingFromStack);
|
||||
}
|
||||
|
||||
if (needed <= 0)
|
||||
{
|
||||
if (needed <= 0) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@ -96,16 +79,12 @@ public class AdvancedCompressionHandler extends CompressionHandler
|
|||
return needed;
|
||||
}
|
||||
|
||||
public static boolean isResultStackReversible(ItemStack stack, int gridSize, World world)
|
||||
{
|
||||
if (stack.isEmpty())
|
||||
{
|
||||
public static boolean isResultStackReversible(ItemStack stack, int gridSize, World world) {
|
||||
if (stack.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
InventoryCrafting inventory = new InventoryCrafting(new Container()
|
||||
{
|
||||
public boolean canInteractWith(EntityPlayer player)
|
||||
{
|
||||
InventoryCrafting inventory = new InventoryCrafting(new Container() {
|
||||
public boolean canInteractWith(EntityPlayer player) {
|
||||
return false;
|
||||
}
|
||||
}, 2, 2);
|
||||
|
@ -113,59 +92,49 @@ public class AdvancedCompressionHandler extends CompressionHandler
|
|||
inventory.setInventorySlotContents(0, stack);
|
||||
|
||||
ItemStack returnStack = StorageBlockCraftingManager.getInstance().findMatchingRecipe(inventory, world);
|
||||
if (returnStack.isEmpty())
|
||||
{
|
||||
if (returnStack.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ItemStack compressedStack = ItemStack.EMPTY;
|
||||
switch (gridSize)
|
||||
{
|
||||
case 2:
|
||||
compressedStack = get22Recipe(returnStack, world);
|
||||
break;
|
||||
case 3:
|
||||
compressedStack = get33Recipe(returnStack, world);
|
||||
break;
|
||||
switch (gridSize) {
|
||||
case 2:
|
||||
compressedStack = get22Recipe(returnStack, world);
|
||||
break;
|
||||
case 3:
|
||||
compressedStack = get33Recipe(returnStack, world);
|
||||
break;
|
||||
}
|
||||
|
||||
return !compressedStack.isEmpty() && CompressionRegistry.areItemStacksEqual(stack, compressedStack);
|
||||
}
|
||||
|
||||
public static ItemStack getRecipe(ItemStack stack, World world, int gridSize)
|
||||
{
|
||||
InventoryCrafting inventory = new InventoryCrafting(new Container()
|
||||
{
|
||||
public boolean canInteractWith(EntityPlayer player)
|
||||
{
|
||||
public static ItemStack getRecipe(ItemStack stack, World world, int gridSize) {
|
||||
InventoryCrafting inventory = new InventoryCrafting(new Container() {
|
||||
public boolean canInteractWith(EntityPlayer player) {
|
||||
return false;
|
||||
}
|
||||
}, gridSize, gridSize);
|
||||
for (int i = 0; i < inventory.getSizeInventory(); i++)
|
||||
{
|
||||
for (int i = 0; i < inventory.getSizeInventory(); i++) {
|
||||
inventory.setInventorySlotContents(i, stack);
|
||||
}
|
||||
|
||||
return StorageBlockCraftingManager.getInstance().findMatchingRecipe(inventory, world);
|
||||
}
|
||||
|
||||
public static boolean has22Recipe(ItemStack stack, World world)
|
||||
{
|
||||
public static boolean has22Recipe(ItemStack stack, World world) {
|
||||
return !get22Recipe(stack, world).isEmpty();
|
||||
}
|
||||
|
||||
public static ItemStack get22Recipe(ItemStack stack, World world)
|
||||
{
|
||||
public static ItemStack get22Recipe(ItemStack stack, World world) {
|
||||
return getRecipe(stack, world, 2);
|
||||
}
|
||||
|
||||
public static boolean has33Recipe(ItemStack stack, World world)
|
||||
{
|
||||
public static boolean has33Recipe(ItemStack stack, World world) {
|
||||
return !get33Recipe(stack, world).isEmpty();
|
||||
}
|
||||
|
||||
public static ItemStack get33Recipe(ItemStack stack, World world)
|
||||
{
|
||||
public static ItemStack get33Recipe(ItemStack stack, World world) {
|
||||
return getRecipe(stack, world, 3);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,36 +4,30 @@ import WayofTime.bloodmagic.api.compress.CompressionHandler;
|
|||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class BaseCompressionHandler extends CompressionHandler
|
||||
{
|
||||
public class BaseCompressionHandler extends CompressionHandler {
|
||||
private final ItemStack required;
|
||||
private final ItemStack result;
|
||||
private final int leftover;
|
||||
|
||||
public BaseCompressionHandler(ItemStack requested, ItemStack result, int leftover)
|
||||
{
|
||||
public BaseCompressionHandler(ItemStack requested, ItemStack result, int leftover) {
|
||||
super();
|
||||
this.required = requested;
|
||||
this.result = result;
|
||||
this.leftover = leftover;
|
||||
}
|
||||
|
||||
public ItemStack getResultStack()
|
||||
{
|
||||
public ItemStack getResultStack() {
|
||||
return this.result.copy();
|
||||
}
|
||||
|
||||
public ItemStack getRequiredStack()
|
||||
{
|
||||
public ItemStack getRequiredStack() {
|
||||
return this.required.copy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack compressInventory(ItemStack[] inv, World world)
|
||||
{
|
||||
public ItemStack compressInventory(ItemStack[] inv, World world) {
|
||||
int remaining = this.getRemainingNeeded(inv);
|
||||
if (remaining <= 0)
|
||||
{
|
||||
if (remaining <= 0) {
|
||||
this.drainInventory(inv);
|
||||
return this.getResultStack();
|
||||
}
|
||||
|
@ -41,51 +35,41 @@ public class BaseCompressionHandler extends CompressionHandler
|
|||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
public int getRemainingNeeded(ItemStack[] inv)
|
||||
{
|
||||
public int getRemainingNeeded(ItemStack[] inv) {
|
||||
return iterateThroughInventory(inv, false);
|
||||
}
|
||||
|
||||
public int drainInventory(ItemStack[] inv)
|
||||
{
|
||||
public int drainInventory(ItemStack[] inv) {
|
||||
return iterateThroughInventory(inv, true);
|
||||
}
|
||||
|
||||
public int iterateThroughInventory(ItemStack[] inv, boolean doDrain)
|
||||
{
|
||||
public int iterateThroughInventory(ItemStack[] inv, boolean doDrain) {
|
||||
int needed = this.required.getCount();
|
||||
int kept = this.getLeftover();
|
||||
int i = -1;
|
||||
|
||||
for (ItemStack invStack : inv)
|
||||
{
|
||||
for (ItemStack invStack : inv) {
|
||||
i++;
|
||||
|
||||
if (invStack == null)
|
||||
{
|
||||
if (invStack == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (invStack.isItemEqual(this.required) && (invStack.getTagCompound() == null ? this.required.getTagCompound() == null : invStack.getTagCompound().equals(this.required.getTagCompound())))
|
||||
{
|
||||
if (invStack.isItemEqual(this.required) && (invStack.getTagCompound() == null ? this.required.getTagCompound() == null : invStack.getTagCompound().equals(this.required.getTagCompound()))) {
|
||||
int stackSize = invStack.getCount();
|
||||
int used = 0;
|
||||
if (kept > 0)
|
||||
{
|
||||
if (kept > 0) {
|
||||
int remainingFromStack = Math.max(stackSize - kept, 0);
|
||||
used += stackSize - remainingFromStack;
|
||||
}
|
||||
|
||||
kept -= used;
|
||||
|
||||
if (kept <= 0 && needed > 0)
|
||||
{
|
||||
if (kept <= 0 && needed > 0) {
|
||||
int remainingFromStack = Math.max(stackSize - used - needed, 0);
|
||||
if (doDrain)
|
||||
{
|
||||
if (doDrain) {
|
||||
invStack.setCount(remainingFromStack + used);
|
||||
if (invStack.isEmpty())
|
||||
{
|
||||
if (invStack.isEmpty()) {
|
||||
inv[i] = ItemStack.EMPTY;
|
||||
}
|
||||
}
|
||||
|
@ -93,8 +77,7 @@ public class BaseCompressionHandler extends CompressionHandler
|
|||
needed -= (stackSize - used - remainingFromStack);
|
||||
}
|
||||
|
||||
if (needed <= 0)
|
||||
{
|
||||
if (needed <= 0) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@ -103,8 +86,7 @@ public class BaseCompressionHandler extends CompressionHandler
|
|||
return needed;
|
||||
}
|
||||
|
||||
public int getLeftover()
|
||||
{
|
||||
public int getLeftover() {
|
||||
return this.leftover;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,121 +13,35 @@ import net.minecraft.world.World;
|
|||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
public class StorageBlockCraftingManager
|
||||
{
|
||||
public class StorageBlockCraftingManager {
|
||||
private static final StorageBlockCraftingManager instance = new StorageBlockCraftingManager();
|
||||
private List recipes = new LinkedList();
|
||||
|
||||
public static StorageBlockCraftingManager getInstance()
|
||||
{
|
||||
return instance;
|
||||
}
|
||||
|
||||
public void addStorageBlockRecipes()
|
||||
{
|
||||
public void addStorageBlockRecipes() {
|
||||
// this.recipes = new StorageBlockCraftingRecipeAssimilator().getPackingRecipes();
|
||||
|
||||
BloodMagic.instance.logger.info("Total number of compression recipes: " + this.recipes.size());
|
||||
}
|
||||
|
||||
private static boolean isResultStackReversible(ItemStack stack, int gridSize, World world, List list)
|
||||
{
|
||||
if (stack.isEmpty())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
InventoryCrafting inventory = new InventoryCrafting(new Container()
|
||||
{
|
||||
public boolean canInteractWith(EntityPlayer player)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}, 2, 2);
|
||||
|
||||
inventory.setInventorySlotContents(0, stack);
|
||||
|
||||
ItemStack returnStack = StorageBlockCraftingManager.getInstance().findMatchingRecipe(inventory, world, list);
|
||||
if (returnStack.isEmpty())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
ItemStack compressedStack = ItemStack.EMPTY;
|
||||
switch (gridSize)
|
||||
{
|
||||
case 2:
|
||||
compressedStack = get22Recipe(returnStack, world, list);
|
||||
break;
|
||||
case 3:
|
||||
compressedStack = get33Recipe(returnStack, world, list);
|
||||
break;
|
||||
}
|
||||
|
||||
return !compressedStack.isEmpty() && CompressionRegistry.areItemStacksEqual(stack, compressedStack);
|
||||
}
|
||||
|
||||
private static ItemStack getRecipe(ItemStack stack, World world, int gridSize, List list)
|
||||
{
|
||||
InventoryCrafting inventory = new InventoryCrafting(new Container()
|
||||
{
|
||||
public boolean canInteractWith(EntityPlayer player)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}, gridSize, gridSize);
|
||||
for (int i = 0; i < inventory.getSizeInventory(); i++)
|
||||
{
|
||||
inventory.setInventorySlotContents(i, stack);
|
||||
}
|
||||
|
||||
return StorageBlockCraftingManager.getInstance().findMatchingRecipe(inventory, world, list);
|
||||
}
|
||||
|
||||
private static boolean has22Recipe(ItemStack stack, World world, List list)
|
||||
{
|
||||
return !get22Recipe(stack, world, list).isEmpty();
|
||||
}
|
||||
|
||||
private static ItemStack get22Recipe(ItemStack stack, World world, List list)
|
||||
{
|
||||
return getRecipe(stack, world, 2, list);
|
||||
}
|
||||
|
||||
private static boolean has33Recipe(ItemStack stack, World world, List list)
|
||||
{
|
||||
return !get33Recipe(stack, world, list).isEmpty();
|
||||
}
|
||||
|
||||
private static ItemStack get33Recipe(ItemStack stack, World world, List list)
|
||||
{
|
||||
return getRecipe(stack, world, 3, list);
|
||||
}
|
||||
|
||||
public ItemStack findMatchingRecipe(InventoryCrafting craftingInventory, World world)
|
||||
{
|
||||
public ItemStack findMatchingRecipe(InventoryCrafting craftingInventory, World world) {
|
||||
return this.findMatchingRecipe(craftingInventory, world, this.recipes);
|
||||
}
|
||||
|
||||
private ItemStack findMatchingRecipe(InventoryCrafting craftingInventory, World world, List list)
|
||||
{
|
||||
private ItemStack findMatchingRecipe(InventoryCrafting craftingInventory, World world, List list) {
|
||||
int i = 0;
|
||||
ItemStack itemstack = ItemStack.EMPTY;
|
||||
ItemStack itemstack1 = ItemStack.EMPTY;
|
||||
int j;
|
||||
|
||||
for (j = 0; j < craftingInventory.getSizeInventory(); ++j)
|
||||
{
|
||||
for (j = 0; j < craftingInventory.getSizeInventory(); ++j) {
|
||||
ItemStack itemstack2 = craftingInventory.getStackInSlot(j);
|
||||
|
||||
if (!itemstack2.isEmpty())
|
||||
{
|
||||
if (i == 0)
|
||||
{
|
||||
if (!itemstack2.isEmpty()) {
|
||||
if (i == 0) {
|
||||
itemstack = itemstack2;
|
||||
}
|
||||
|
||||
if (i == 1)
|
||||
{
|
||||
if (i == 1) {
|
||||
itemstack1 = itemstack2;
|
||||
}
|
||||
|
||||
|
@ -135,28 +49,23 @@ public class StorageBlockCraftingManager
|
|||
}
|
||||
}
|
||||
|
||||
if (i == 2 && itemstack.getItem() == itemstack1.getItem() && itemstack.getCount() == 1 && itemstack1.getCount() == 1 && itemstack.getItem().isRepairable())
|
||||
{
|
||||
if (i == 2 && itemstack.getItem() == itemstack1.getItem() && itemstack.getCount() == 1 && itemstack1.getCount() == 1 && itemstack.getItem().isRepairable()) {
|
||||
Item item = itemstack.getItem();
|
||||
int j1 = item.getMaxDamage(itemstack) - itemstack.getItemDamage();
|
||||
int k = item.getMaxDamage(itemstack) - itemstack1.getItemDamage();
|
||||
int l = j1 + k + item.getMaxDamage(itemstack) * 5 / 100;
|
||||
int i1 = item.getMaxDamage(itemstack) - l;
|
||||
|
||||
if (i1 < 0)
|
||||
{
|
||||
if (i1 < 0) {
|
||||
i1 = 0;
|
||||
}
|
||||
|
||||
return new ItemStack(itemstack.getItem(), 1, i1);
|
||||
} else
|
||||
{
|
||||
for (j = 0; j < list.size(); ++j)
|
||||
{
|
||||
} else {
|
||||
for (j = 0; j < list.size(); ++j) {
|
||||
IRecipe irecipe = (IRecipe) list.get(j);
|
||||
|
||||
if (irecipe.matches(craftingInventory, world))
|
||||
{
|
||||
if (irecipe.matches(craftingInventory, world)) {
|
||||
return irecipe.getCraftingResult(craftingInventory);
|
||||
}
|
||||
}
|
||||
|
@ -164,4 +73,67 @@ public class StorageBlockCraftingManager
|
|||
return ItemStack.EMPTY;
|
||||
}
|
||||
}
|
||||
|
||||
public static StorageBlockCraftingManager getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
private static boolean isResultStackReversible(ItemStack stack, int gridSize, World world, List list) {
|
||||
if (stack.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
InventoryCrafting inventory = new InventoryCrafting(new Container() {
|
||||
public boolean canInteractWith(EntityPlayer player) {
|
||||
return false;
|
||||
}
|
||||
}, 2, 2);
|
||||
|
||||
inventory.setInventorySlotContents(0, stack);
|
||||
|
||||
ItemStack returnStack = StorageBlockCraftingManager.getInstance().findMatchingRecipe(inventory, world, list);
|
||||
if (returnStack.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ItemStack compressedStack = ItemStack.EMPTY;
|
||||
switch (gridSize) {
|
||||
case 2:
|
||||
compressedStack = get22Recipe(returnStack, world, list);
|
||||
break;
|
||||
case 3:
|
||||
compressedStack = get33Recipe(returnStack, world, list);
|
||||
break;
|
||||
}
|
||||
|
||||
return !compressedStack.isEmpty() && CompressionRegistry.areItemStacksEqual(stack, compressedStack);
|
||||
}
|
||||
|
||||
private static ItemStack getRecipe(ItemStack stack, World world, int gridSize, List list) {
|
||||
InventoryCrafting inventory = new InventoryCrafting(new Container() {
|
||||
public boolean canInteractWith(EntityPlayer player) {
|
||||
return false;
|
||||
}
|
||||
}, gridSize, gridSize);
|
||||
for (int i = 0; i < inventory.getSizeInventory(); i++) {
|
||||
inventory.setInventorySlotContents(i, stack);
|
||||
}
|
||||
|
||||
return StorageBlockCraftingManager.getInstance().findMatchingRecipe(inventory, world, list);
|
||||
}
|
||||
|
||||
private static boolean has22Recipe(ItemStack stack, World world, List list) {
|
||||
return !get22Recipe(stack, world, list).isEmpty();
|
||||
}
|
||||
|
||||
private static ItemStack get22Recipe(ItemStack stack, World world, List list) {
|
||||
return getRecipe(stack, world, 2, list);
|
||||
}
|
||||
|
||||
private static boolean has33Recipe(ItemStack stack, World world, List list) {
|
||||
return !get33Recipe(stack, world, list).isEmpty();
|
||||
}
|
||||
|
||||
private static ItemStack get33Recipe(ItemStack stack, World world, List list) {
|
||||
return getRecipe(stack, world, 3, list);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,21 +1,6 @@
|
|||
package WayofTime.bloodmagic.compress;
|
||||
|
||||
import WayofTime.bloodmagic.BloodMagic;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.*;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.common.registry.ForgeRegistries;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
import net.minecraftforge.oredict.ShapedOreRecipe;
|
||||
import net.minecraftforge.oredict.ShapelessOreRecipe;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class StorageBlockCraftingRecipeAssimilator
|
||||
{
|
||||
public class StorageBlockCraftingRecipeAssimilator {
|
||||
// public static final List<Class> ignore = new ArrayList<Class>();
|
||||
//
|
||||
// public List<IRecipe> getPackingRecipes()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue