From 589290c463a6a3d1d299788c0c1494a8bced83e4 Mon Sep 17 00:00:00 2001 From: Henry Mao Date: Sun, 6 Jan 2013 00:03:41 +0800 Subject: [PATCH] Fixed imprinter outputing only stacks of one --- src/minecraft/assemblyline/common/Pair.java | 41 +++++++++++++++++++ .../machine/belt/BlockConveyorBelt.java | 18 ++++---- .../machine/imprinter/ContainerImprinter.java | 34 +++++++++------ .../machine/imprinter/SlotCraftingResult.java | 4 +- 4 files changed, 75 insertions(+), 22 deletions(-) create mode 100644 src/minecraft/assemblyline/common/Pair.java diff --git a/src/minecraft/assemblyline/common/Pair.java b/src/minecraft/assemblyline/common/Pair.java new file mode 100644 index 00000000..beac0591 --- /dev/null +++ b/src/minecraft/assemblyline/common/Pair.java @@ -0,0 +1,41 @@ +package assemblyline.common; + +public class Pair +{ + private final L left; + private final R right; + + public Pair(L left, R right) + { + this.left = left; + this.right = right; + } + + public L getKey() + { + return left; + } + + public R getValue() + { + return right; + } + + @Override + public int hashCode() + { + return left.hashCode() ^ right.hashCode(); + } + + @Override + public boolean equals(Object o) + { + if (o == null) + return false; + if (!(o instanceof Pair)) + return false; + Pair pairo = (Pair) o; + return this.left.equals(pairo.getKey()) && this.right.equals(pairo.getValue()); + } + +} \ No newline at end of file diff --git a/src/minecraft/assemblyline/common/machine/belt/BlockConveyorBelt.java b/src/minecraft/assemblyline/common/machine/belt/BlockConveyorBelt.java index 026698ba..3fed4668 100644 --- a/src/minecraft/assemblyline/common/machine/belt/BlockConveyorBelt.java +++ b/src/minecraft/assemblyline/common/machine/belt/BlockConveyorBelt.java @@ -111,28 +111,30 @@ public class BlockConveyorBelt extends BlockMachine if (tileEntity.isRunning()) { + float acceleration = tileEntity.acceleration; + float maxSpeed = tileEntity.maxSpeed; + SlantType slantType = tileEntity.getSlant(); ForgeDirection direction = tileEntity.getDirection(); - float modifier = 1; - if (entity instanceof EntityLiving) { - modifier = 10; + acceleration *= 5; + maxSpeed *= 10; } // Move the entity based on the conveyor belt's direction. - entity.addVelocity(direction.offsetX * tileEntity.acceleration * modifier, 0, direction.offsetZ * tileEntity.acceleration * modifier); + entity.addVelocity(direction.offsetX * acceleration, 0, direction.offsetZ * acceleration); - if (direction.offsetX != 0 && Math.abs(entity.motionX) > tileEntity.maxSpeed) + if (direction.offsetX != 0 && Math.abs(entity.motionX) > maxSpeed) { - entity.motionX = direction.offsetX * tileEntity.maxSpeed; + entity.motionX = direction.offsetX * maxSpeed; entity.motionZ = 0; } - if (direction.offsetZ != 0 && Math.abs(entity.motionZ) > tileEntity.maxSpeed) + if (direction.offsetZ != 0 && Math.abs(entity.motionZ) > maxSpeed) { - entity.motionZ = direction.offsetZ * tileEntity.maxSpeed; + entity.motionZ = direction.offsetZ * maxSpeed; entity.motionX = 0; } diff --git a/src/minecraft/assemblyline/common/machine/imprinter/ContainerImprinter.java b/src/minecraft/assemblyline/common/machine/imprinter/ContainerImprinter.java index d9c6c47f..946fd122 100644 --- a/src/minecraft/assemblyline/common/machine/imprinter/ContainerImprinter.java +++ b/src/minecraft/assemblyline/common/machine/imprinter/ContainerImprinter.java @@ -16,6 +16,7 @@ import net.minecraft.world.World; import net.minecraftforge.oredict.ShapedOreRecipe; import net.minecraftforge.oredict.ShapelessOreRecipe; import universalelectricity.core.vector.Vector3; +import assemblyline.common.Pair; import cpw.mods.fml.relauncher.ReflectionHelper; public class ContainerImprinter extends Container implements IInventory, ISlotWatcher @@ -79,8 +80,8 @@ public class ContainerImprinter extends Container implements IInventory, ISlotWa if (slot == 2) { - setInventorySlotContents(0, null); // Prevents filter from being - // duplicated + // Prevents filter from being duplicated + this.setInventorySlotContents(0, null); } if (slot > 4) @@ -245,9 +246,12 @@ public class ContainerImprinter extends Container implements IInventory, ISlotWa if (outputStack != null) { - if (this.getIdealRecipe(outputStack) != null) + Pair idealRecipe = this.getIdealRecipe(outputStack); + + if (idealRecipe != null) { - this.setInventorySlotContents(4, outputStack); + System.out.println(idealRecipe.getKey().stackSize); + this.setInventorySlotContents(4, idealRecipe.getKey()); didCraft = true; } } @@ -267,7 +271,7 @@ public class ContainerImprinter extends Container implements IInventory, ISlotWa * * @return Required Items */ - public ItemStack[] getIdealRecipe(ItemStack outputItem) + public Pair getIdealRecipe(ItemStack outputItem) { for (Object object : CraftingManager.getInstance().getRecipeList()) { @@ -279,17 +283,17 @@ public class ContainerImprinter extends Container implements IInventory, ISlotWa { if (object instanceof ShapedRecipes) { - if (this.doesMatch(((ShapedRecipes) object).recipeItems, outputItem)) { return ((ShapedRecipes) object).recipeItems; } + if (this.hasResource(((ShapedRecipes) object).recipeItems)) { return new Pair(((ShapedRecipes) object).getRecipeOutput().copy(), ((ShapedRecipes) object).recipeItems); } } else if (object instanceof ShapelessRecipes) { - if (this.doesMatch(((ShapelessRecipes) object).recipeItems.toArray(new ItemStack[1]), outputItem)) { return (ItemStack[]) ((ShapelessRecipes) object).recipeItems.toArray(new ItemStack[1]); } + if (this.hasResource(((ShapelessRecipes) object).recipeItems.toArray(new ItemStack[1]))) { return new Pair(((ShapedRecipes) object).getRecipeOutput().copy(), (ItemStack[]) ((ShapelessRecipes) object).recipeItems.toArray(new ItemStack[1])); } } else if (object instanceof ShapedOreRecipe) { ShapedOreRecipe oreRecipe = (ShapedOreRecipe) object; Object[] oreRecipeInput = (Object[]) ReflectionHelper.getPrivateValue(ShapedOreRecipe.class, oreRecipe, "input"); - if (doesMatch(oreRecipeInput, outputItem)) + if (hasResource(oreRecipeInput)) { ArrayList finalRecipe = new ArrayList(); for (Object ingredientListObject : oreRecipeInput) @@ -312,14 +316,14 @@ public class ContainerImprinter extends Container implements IInventory, ISlotWa } } } - if (finalRecipe.size() == oreRecipeInput.length) { return finalRecipe.toArray(new ItemStack[1]); } + if (finalRecipe.size() == oreRecipeInput.length) { return new Pair(((ShapedRecipes) object).getRecipeOutput().copy(), finalRecipe.toArray(new ItemStack[1])); } } } else if (object instanceof ShapelessOreRecipe) { ShapelessOreRecipe oreRecipe = (ShapelessOreRecipe) object; ArrayList oreRecipeInput = (ArrayList) ReflectionHelper.getPrivateValue(ShapelessOreRecipe.class, oreRecipe, "input"); - if (doesMatch(oreRecipeInput.toArray(), outputItem)) + if (hasResource(oreRecipeInput.toArray())) { ArrayList finalRecipe = new ArrayList(); for (Object ingredientListObject : oreRecipeInput) @@ -348,7 +352,7 @@ public class ContainerImprinter extends Container implements IInventory, ISlotWa } } } - if (finalRecipe.size() == oreRecipeInput.size()) { return finalRecipe.toArray(new ItemStack[1]); } + if (finalRecipe.size() == oreRecipeInput.size()) { return new Pair(((ShapedRecipes) object).getRecipeOutput().copy(), finalRecipe.toArray(new ItemStack[1])); } } } } @@ -359,7 +363,12 @@ public class ContainerImprinter extends Container implements IInventory, ISlotWa return null; } - private boolean doesMatch(Object[] recipeItems, ItemStack outputItem) + /** + * Returns if players has the following resource required. + * + * @param recipeItems - The items to be checked for the recipes. + */ + private boolean hasResource(Object[] recipeItems) { int itemMatch = 0; @@ -381,6 +390,7 @@ public class ContainerImprinter extends Container implements IInventory, ISlotWa { // TODO Do NBT CHecking itemMatch++; + break; } } } diff --git a/src/minecraft/assemblyline/common/machine/imprinter/SlotCraftingResult.java b/src/minecraft/assemblyline/common/machine/imprinter/SlotCraftingResult.java index 52c43374..985d02f7 100644 --- a/src/minecraft/assemblyline/common/machine/imprinter/SlotCraftingResult.java +++ b/src/minecraft/assemblyline/common/machine/imprinter/SlotCraftingResult.java @@ -35,7 +35,7 @@ public class SlotCraftingResult extends Slot if (this.getStack() != null) { - ItemStack[] requiredItems = this.container.getIdealRecipe(this.getStack()).clone(); + ItemStack[] requiredItems = this.container.getIdealRecipe(this.getStack()).getValue().clone(); if (requiredItems != null) { @@ -63,7 +63,7 @@ public class SlotCraftingResult extends Slot { if (this.getStack() != null) { - ItemStack[] idealRecipe = this.container.getIdealRecipe(this.getStack()); + ItemStack[] idealRecipe = this.container.getIdealRecipe(this.getStack()).getValue(); if (idealRecipe != null) { ItemStack[] requiredItems = idealRecipe.clone();