Changed formatting to have bracing on a new line
This commit is contained in:
parent
e5eddd6c45
commit
e48eedb874
189 changed files with 6092 additions and 4041 deletions
|
@ -8,27 +8,35 @@ 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 == null) {
|
||||
public ItemStack test(ItemStack[] inv, boolean doDrain, World world)
|
||||
{
|
||||
for (ItemStack invStack : inv)
|
||||
{
|
||||
if (invStack == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
for (int i = 2; i <= 3; i++) {
|
||||
for (int i = 2; i <= 3; i++)
|
||||
{
|
||||
ItemStack stacky = getRecipe(invStack, world, i);
|
||||
if (stacky != null) {
|
||||
if (stacky != null)
|
||||
{
|
||||
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 stacky;
|
||||
}
|
||||
|
@ -39,31 +47,39 @@ public class AdvancedCompressionHandler extends CompressionHandler {
|
|||
return null;
|
||||
}
|
||||
|
||||
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 == null) {
|
||||
if (invStack == null)
|
||||
{
|
||||
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.stackSize;
|
||||
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.stackSize = remainingFromStack + used;
|
||||
if (invStack.stackSize <= 0) {
|
||||
if (invStack.stackSize <= 0)
|
||||
{
|
||||
inv[i] = null;
|
||||
}
|
||||
}
|
||||
|
@ -71,7 +87,8 @@ public class AdvancedCompressionHandler extends CompressionHandler {
|
|||
needed -= (stackSize - used - remainingFromStack);
|
||||
}
|
||||
|
||||
if (needed <= 0) {
|
||||
if (needed <= 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@ -80,12 +97,16 @@ public class AdvancedCompressionHandler extends CompressionHandler {
|
|||
return needed;
|
||||
}
|
||||
|
||||
public static boolean isResultStackReversible(ItemStack stack, int gridSize, World world) {
|
||||
if (stack == null) {
|
||||
public static boolean isResultStackReversible(ItemStack stack, int gridSize, World world)
|
||||
{
|
||||
if (stack == null)
|
||||
{
|
||||
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);
|
||||
|
@ -93,49 +114,59 @@ public class AdvancedCompressionHandler extends CompressionHandler {
|
|||
inventory.setInventorySlotContents(0, stack);
|
||||
|
||||
ItemStack returnStack = StorageBlockCraftingManager.getInstance().findMatchingRecipe(inventory, world);
|
||||
if (returnStack == null) {
|
||||
if (returnStack == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
ItemStack compressedStack = null;
|
||||
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 != null && 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) != null;
|
||||
}
|
||||
|
||||
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) != null;
|
||||
}
|
||||
|
||||
public static ItemStack get33Recipe(ItemStack stack, World world) {
|
||||
public static ItemStack get33Recipe(ItemStack stack, World world)
|
||||
{
|
||||
return getRecipe(stack, world, 3);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,31 +4,37 @@ 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();
|
||||
}
|
||||
|
@ -36,41 +42,51 @@ public class BaseCompressionHandler extends CompressionHandler {
|
|||
return null;
|
||||
}
|
||||
|
||||
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.stackSize;
|
||||
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.stackSize;
|
||||
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.stackSize = remainingFromStack + used;
|
||||
if (invStack.stackSize <= 0) {
|
||||
if (invStack.stackSize <= 0)
|
||||
{
|
||||
inv[i] = null;
|
||||
}
|
||||
}
|
||||
|
@ -78,7 +94,8 @@ public class BaseCompressionHandler extends CompressionHandler {
|
|||
needed -= (stackSize - used - remainingFromStack);
|
||||
}
|
||||
|
||||
if (needed <= 0) {
|
||||
if (needed <= 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@ -87,7 +104,8 @@ public class BaseCompressionHandler extends CompressionHandler {
|
|||
return needed;
|
||||
}
|
||||
|
||||
public int getLeftover() {
|
||||
public int getLeftover()
|
||||
{
|
||||
return this.leftover;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,27 +13,34 @@ 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() {
|
||||
public static StorageBlockCraftingManager getInstance()
|
||||
{
|
||||
return instance;
|
||||
}
|
||||
|
||||
public void addStorageBlockRecipes() {
|
||||
public void addStorageBlockRecipes()
|
||||
{
|
||||
this.recipes = new StorageBlockCraftingRecipeAssimilator().getPackingRecipes();
|
||||
|
||||
BloodMagic.instance.getLogger().info("Total number of compression recipes: " + this.recipes.size());
|
||||
}
|
||||
|
||||
private static boolean isResultStackReversible(ItemStack stack, int gridSize, World world, List list) {
|
||||
if (stack == null) {
|
||||
private static boolean isResultStackReversible(ItemStack stack, int gridSize, World world, List list)
|
||||
{
|
||||
if (stack == null)
|
||||
{
|
||||
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);
|
||||
|
@ -41,71 +48,87 @@ public class StorageBlockCraftingManager {
|
|||
inventory.setInventorySlotContents(0, stack);
|
||||
|
||||
ItemStack returnStack = StorageBlockCraftingManager.getInstance().findMatchingRecipe(inventory, world, list);
|
||||
if (returnStack == null || returnStack.getItem() == null) {
|
||||
if (returnStack == null || returnStack.getItem() == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
ItemStack compressedStack = null;
|
||||
switch (gridSize) {
|
||||
case 2:
|
||||
compressedStack = get22Recipe(returnStack, world, list);
|
||||
break;
|
||||
case 3:
|
||||
compressedStack = get33Recipe(returnStack, world, list);
|
||||
break;
|
||||
switch (gridSize)
|
||||
{
|
||||
case 2:
|
||||
compressedStack = get22Recipe(returnStack, world, list);
|
||||
break;
|
||||
case 3:
|
||||
compressedStack = get33Recipe(returnStack, world, list);
|
||||
break;
|
||||
}
|
||||
|
||||
return compressedStack != null && 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) {
|
||||
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++) {
|
||||
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) {
|
||||
private static boolean has22Recipe(ItemStack stack, World world, List list)
|
||||
{
|
||||
return get22Recipe(stack, world, list) != null;
|
||||
}
|
||||
|
||||
private static ItemStack get22Recipe(ItemStack stack, World world, List list) {
|
||||
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) {
|
||||
private static boolean has33Recipe(ItemStack stack, World world, List list)
|
||||
{
|
||||
return get33Recipe(stack, world, list) != null;
|
||||
}
|
||||
|
||||
private static ItemStack get33Recipe(ItemStack stack, World world, List list) {
|
||||
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 = null;
|
||||
ItemStack itemstack1 = null;
|
||||
int j;
|
||||
|
||||
for (j = 0; j < craftingInventory.getSizeInventory(); ++j) {
|
||||
for (j = 0; j < craftingInventory.getSizeInventory(); ++j)
|
||||
{
|
||||
ItemStack itemstack2 = craftingInventory.getStackInSlot(j);
|
||||
|
||||
if (itemstack2 != null) {
|
||||
if (i == 0) {
|
||||
if (itemstack2 != null)
|
||||
{
|
||||
if (i == 0)
|
||||
{
|
||||
itemstack = itemstack2;
|
||||
}
|
||||
|
||||
if (i == 1) {
|
||||
if (i == 1)
|
||||
{
|
||||
itemstack1 = itemstack2;
|
||||
}
|
||||
|
||||
|
@ -113,23 +136,28 @@ public class StorageBlockCraftingManager {
|
|||
}
|
||||
}
|
||||
|
||||
if (i == 2 && itemstack.getItem() == itemstack1.getItem() && itemstack.stackSize == 1 && itemstack1.stackSize == 1 && itemstack.getItem().isRepairable()) {
|
||||
if (i == 2 && itemstack.getItem() == itemstack1.getItem() && itemstack.stackSize == 1 && itemstack1.stackSize == 1 && itemstack.getItem().isRepairable())
|
||||
{
|
||||
Item item = itemstack.getItem();
|
||||
int j1 = item.getMaxDamage() - itemstack.getItemDamage();
|
||||
int k = item.getMaxDamage() - itemstack1.getItemDamage();
|
||||
int l = j1 + k + item.getMaxDamage() * 5 / 100;
|
||||
int i1 = item.getMaxDamage() - 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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,30 +16,38 @@ import net.minecraftforge.oredict.ShapelessOreRecipe;
|
|||
|
||||
import java.util.*;
|
||||
|
||||
public class StorageBlockCraftingRecipeAssimilator {
|
||||
public class StorageBlockCraftingRecipeAssimilator
|
||||
{
|
||||
|
||||
public List<IRecipe> getPackingRecipes() {
|
||||
public List<IRecipe> getPackingRecipes()
|
||||
{
|
||||
// grab all recipes potentially suitable for packing or unpacking
|
||||
|
||||
List<PackingRecipe> packingRecipes = new LinkedList<PackingRecipe>();
|
||||
List<IRecipe> unpackingRecipes = new ArrayList<IRecipe>();
|
||||
|
||||
for (IRecipe recipe : getCraftingRecipes()) {
|
||||
for (IRecipe recipe : getCraftingRecipes())
|
||||
{
|
||||
ItemStack output = recipe.getRecipeOutput();
|
||||
if (output == null || output.getItem() == null) continue;
|
||||
if (output == null || output.getItem() == null)
|
||||
continue;
|
||||
|
||||
if (output.stackSize == 1) {
|
||||
if (output.stackSize == 1)
|
||||
{
|
||||
PackingRecipe packingRecipe = getPackingRecipe(recipe);
|
||||
|
||||
if (packingRecipe != null) {
|
||||
if (packingRecipe != null)
|
||||
{
|
||||
packingRecipes.add(packingRecipe);
|
||||
}
|
||||
} else if ((output.stackSize == 4 || output.stackSize == 9) && recipe.getRecipeSize() == 1) {
|
||||
} else if ((output.stackSize == 4 || output.stackSize == 9) && recipe.getRecipeSize() == 1)
|
||||
{
|
||||
unpackingRecipes.add(recipe);
|
||||
}
|
||||
}
|
||||
|
||||
// grab all packing recipes which accept the output of any of the unpacking recipes
|
||||
// grab all packing recipes which accept the output of any of the
|
||||
// unpacking recipes
|
||||
|
||||
Container container = makeDummyContainer();
|
||||
InventoryCrafting inventoryUnpack = new InventoryCrafting(container, 2, 2);
|
||||
|
@ -49,61 +57,82 @@ public class StorageBlockCraftingRecipeAssimilator {
|
|||
|
||||
List<IRecipe> ret = new ArrayList<IRecipe>();
|
||||
|
||||
for (IRecipe recipeUnpack : unpackingRecipes) {
|
||||
for (IRecipe recipeUnpack : unpackingRecipes)
|
||||
{
|
||||
ItemStack unpacked = recipeUnpack.getRecipeOutput();
|
||||
InventoryCrafting inventory = null;
|
||||
|
||||
for (Iterator<PackingRecipe> it = packingRecipes.iterator(); it.hasNext(); ) {
|
||||
for (Iterator<PackingRecipe> it = packingRecipes.iterator(); it.hasNext();)
|
||||
{
|
||||
PackingRecipe recipePack = it.next();
|
||||
|
||||
// check if the packing recipe accepts the unpacking recipe's output
|
||||
// check if the packing recipe accepts the unpacking recipe's
|
||||
// output
|
||||
|
||||
boolean matched = false;
|
||||
|
||||
if (recipePack.possibleInputs != null) { // the recipe could be parsed, use its inputs directly since that's faster
|
||||
// verify recipe size
|
||||
if (recipePack.possibleInputs != null)
|
||||
{ // the recipe could be parsed, use its inputs directly since
|
||||
// that's faster
|
||||
// verify recipe size
|
||||
|
||||
if (recipePack.inputCount != unpacked.stackSize) continue;
|
||||
if (recipePack.inputCount != unpacked.stackSize)
|
||||
continue;
|
||||
|
||||
// check if any of the input options matches the unpacked item stack
|
||||
// check if any of the input options matches the unpacked
|
||||
// item stack
|
||||
|
||||
for (ItemStack stack : recipePack.possibleInputs) {
|
||||
if (areInputsIdentical(unpacked, stack)) {
|
||||
for (ItemStack stack : recipePack.possibleInputs)
|
||||
{
|
||||
if (areInputsIdentical(unpacked, stack))
|
||||
{
|
||||
matched = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else { // unknown IRecipe, check through the recipe conventionally
|
||||
// verify recipe size for 3x3 to skip anything smaller quickly
|
||||
} else
|
||||
{ // unknown IRecipe, check through the recipe conventionally
|
||||
// verify recipe size for 3x3 to skip anything smaller
|
||||
// quickly
|
||||
|
||||
if (unpacked.stackSize == 9 && recipePack.recipe.getRecipeSize() < 9) continue;
|
||||
if (unpacked.stackSize == 9 && recipePack.recipe.getRecipeSize() < 9)
|
||||
continue;
|
||||
|
||||
// initialize inventory late, but only once per unpack recipe
|
||||
// initialize inventory late, but only once per unpack
|
||||
// recipe
|
||||
|
||||
if (inventory == null) {
|
||||
if (unpacked.stackSize == 4) {
|
||||
if (inventory == null)
|
||||
{
|
||||
if (unpacked.stackSize == 4)
|
||||
{
|
||||
inventory = inventory2x2;
|
||||
} else {
|
||||
} else
|
||||
{
|
||||
inventory = inventory3x3;
|
||||
}
|
||||
|
||||
for (int i = 0; i < unpacked.stackSize; i++) {
|
||||
for (int i = 0; i < unpacked.stackSize; i++)
|
||||
{
|
||||
inventory.setInventorySlotContents(i, unpacked.copy());
|
||||
}
|
||||
}
|
||||
|
||||
// check if the packing recipe accepts the unpacked item stack
|
||||
// check if the packing recipe accepts the unpacked item
|
||||
// stack
|
||||
|
||||
matched = recipePack.recipe.matches(inventory, world);
|
||||
}
|
||||
|
||||
if (matched) {
|
||||
// check if the unpacking recipe accepts the packing recipe's output
|
||||
if (matched)
|
||||
{
|
||||
// check if the unpacking recipe accepts the packing
|
||||
// recipe's output
|
||||
|
||||
ItemStack packOutput = recipePack.recipe.getRecipeOutput();
|
||||
inventoryUnpack.setInventorySlotContents(0, packOutput.copy());
|
||||
|
||||
if (recipeUnpack.matches(inventoryUnpack, world)) {
|
||||
if (recipeUnpack.matches(inventoryUnpack, world))
|
||||
{
|
||||
ret.add(recipePack.recipe);
|
||||
BloodMagic.instance.getLogger().info("Adding the following recipe to the Compression Handler: " + packOutput);
|
||||
it.remove();
|
||||
|
@ -116,33 +145,44 @@ public class StorageBlockCraftingRecipeAssimilator {
|
|||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private List<IRecipe> getCraftingRecipes() {
|
||||
private List<IRecipe> getCraftingRecipes()
|
||||
{
|
||||
return CraftingManager.getInstance().getRecipeList();
|
||||
}
|
||||
|
||||
private Container makeDummyContainer() {
|
||||
return new Container() {
|
||||
private Container makeDummyContainer()
|
||||
{
|
||||
return new Container()
|
||||
{
|
||||
@Override
|
||||
public boolean canInteractWith(EntityPlayer player) {
|
||||
public boolean canInteractWith(EntityPlayer player)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private PackingRecipe getPackingRecipe(IRecipe recipe) {
|
||||
if (recipe.getRecipeSize() < 4) return null;
|
||||
private PackingRecipe getPackingRecipe(IRecipe recipe)
|
||||
{
|
||||
if (recipe.getRecipeSize() < 4)
|
||||
return null;
|
||||
|
||||
List<?> inputs;
|
||||
|
||||
if (recipe instanceof ShapedRecipes) {
|
||||
if (recipe instanceof ShapedRecipes)
|
||||
{
|
||||
inputs = Arrays.asList(((ShapedRecipes) recipe).recipeItems);
|
||||
} else if (recipe instanceof ShapelessRecipes) {
|
||||
} else if (recipe instanceof ShapelessRecipes)
|
||||
{
|
||||
inputs = ((ShapelessRecipes) recipe).recipeItems;
|
||||
} else if (recipe instanceof ShapedOreRecipe) {
|
||||
} else if (recipe instanceof ShapedOreRecipe)
|
||||
{
|
||||
inputs = Arrays.asList(((ShapedOreRecipe) recipe).getInput());
|
||||
} else if (recipe instanceof ShapelessOreRecipe) {
|
||||
} else if (recipe instanceof ShapelessOreRecipe)
|
||||
{
|
||||
inputs = ((ShapelessOreRecipe) recipe).getInput();
|
||||
} else {
|
||||
} else
|
||||
{
|
||||
return new PackingRecipe(recipe, null, -1);
|
||||
}
|
||||
|
||||
|
@ -150,65 +190,84 @@ public class StorageBlockCraftingRecipeAssimilator {
|
|||
|
||||
int count = 0;
|
||||
|
||||
for (Object o : inputs) {
|
||||
if (o != null) count++;
|
||||
for (Object o : inputs)
|
||||
{
|
||||
if (o != null)
|
||||
count++;
|
||||
}
|
||||
|
||||
if (count != 4 && count != 9) return null;
|
||||
if (count != 4 && count != 9)
|
||||
return null;
|
||||
|
||||
// grab identical inputs
|
||||
|
||||
List<ItemStack> identicalInputs = getIdenticalInputs(inputs);
|
||||
if (identicalInputs == null) return null;
|
||||
if (identicalInputs == null)
|
||||
return null;
|
||||
|
||||
return new PackingRecipe(recipe, identicalInputs, count);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine the item stacks from the provided inputs which are suitable for every input element.
|
||||
*
|
||||
* @param inputs List of all inputs, null elements are being ignored.
|
||||
* Determine the item stacks from the provided inputs which are suitable for
|
||||
* every input element.
|
||||
*
|
||||
* @param inputs
|
||||
* List of all inputs, null elements are being ignored.
|
||||
* @return List List of all options.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private List<ItemStack> getIdenticalInputs(List<?> inputs) {
|
||||
private List<ItemStack> getIdenticalInputs(List<?> inputs)
|
||||
{
|
||||
List<ItemStack> options = null;
|
||||
|
||||
for (Object input : inputs) {
|
||||
if (input == null) continue;
|
||||
for (Object input : inputs)
|
||||
{
|
||||
if (input == null)
|
||||
continue;
|
||||
|
||||
List<ItemStack> offers;
|
||||
|
||||
if (input instanceof ItemStack) {
|
||||
if (input instanceof ItemStack)
|
||||
{
|
||||
offers = Collections.singletonList((ItemStack) input);
|
||||
} else if (input instanceof List) {
|
||||
} else if (input instanceof List)
|
||||
{
|
||||
offers = (List<ItemStack>) input;
|
||||
|
||||
if (offers.isEmpty()) return null;
|
||||
} else {
|
||||
throw new RuntimeException("invalid input: "+input.getClass());
|
||||
if (offers.isEmpty())
|
||||
return null;
|
||||
} else
|
||||
{
|
||||
throw new RuntimeException("invalid input: " + input.getClass());
|
||||
}
|
||||
|
||||
if (options == null) {
|
||||
if (options == null)
|
||||
{
|
||||
options = new ArrayList<ItemStack>(offers);
|
||||
continue;
|
||||
}
|
||||
|
||||
for (Iterator<ItemStack> it = options.iterator(); it.hasNext(); ) {
|
||||
for (Iterator<ItemStack> it = options.iterator(); it.hasNext();)
|
||||
{
|
||||
ItemStack stackReq = it.next();
|
||||
boolean found = false;
|
||||
|
||||
for (ItemStack stackCmp : offers) {
|
||||
if (areInputsIdentical(stackReq, stackCmp)) {
|
||||
for (ItemStack stackCmp : offers)
|
||||
{
|
||||
if (areInputsIdentical(stackReq, stackCmp))
|
||||
{
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
if (!found)
|
||||
{
|
||||
it.remove();
|
||||
|
||||
if (options.isEmpty()) return null;
|
||||
if (options.isEmpty())
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -216,9 +275,11 @@ public class StorageBlockCraftingRecipeAssimilator {
|
|||
return options;
|
||||
}
|
||||
|
||||
private boolean areInputsIdentical(ItemStack a, ItemStack b) {
|
||||
private boolean areInputsIdentical(ItemStack a, ItemStack b)
|
||||
{
|
||||
|
||||
try {
|
||||
try
|
||||
{
|
||||
if (a.getItem() != b.getItem())
|
||||
return false;
|
||||
|
||||
|
@ -226,21 +287,24 @@ public class StorageBlockCraftingRecipeAssimilator {
|
|||
int dmgB = b.getItemDamage();
|
||||
|
||||
return dmgA == dmgB || dmgA == OreDictionary.WILDCARD_VALUE || dmgB == OreDictionary.WILDCARD_VALUE;
|
||||
} catch (NullPointerException e) {
|
||||
} catch (NullPointerException e)
|
||||
{
|
||||
|
||||
BloodMagic.instance.getLogger().error("A mod in this instance has registered an item with a null input. Known problem mods are:");
|
||||
|
||||
// String err = "";
|
||||
// for (String problem : problemMods)
|
||||
// err += (err.length() > 0 ? ", " : "") + problem;
|
||||
// BloodMagic.instance.getLogger().error(err);
|
||||
// String err = "";
|
||||
// for (String problem : problemMods)
|
||||
// err += (err.length() > 0 ? ", " : "") + problem;
|
||||
// BloodMagic.instance.getLogger().error(err);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static class PackingRecipe {
|
||||
PackingRecipe(IRecipe recipe, List<ItemStack> possibleInputs, int inputCount) {
|
||||
private static class PackingRecipe
|
||||
{
|
||||
PackingRecipe(IRecipe recipe, List<ItemStack> possibleInputs, int inputCount)
|
||||
{
|
||||
this.recipe = recipe;
|
||||
this.possibleInputs = possibleInputs;
|
||||
this.inputCount = inputCount;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue