Fixed imprinter outputing only stacks of one

This commit is contained in:
Henry Mao 2013-01-06 00:03:41 +08:00
parent 23e432ac23
commit 589290c463
4 changed files with 75 additions and 22 deletions

View file

@ -0,0 +1,41 @@
package assemblyline.common;
public class Pair<L, R>
{
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());
}
}

View file

@ -111,28 +111,30 @@ public class BlockConveyorBelt extends BlockMachine
if (tileEntity.isRunning()) if (tileEntity.isRunning())
{ {
float acceleration = tileEntity.acceleration;
float maxSpeed = tileEntity.maxSpeed;
SlantType slantType = tileEntity.getSlant(); SlantType slantType = tileEntity.getSlant();
ForgeDirection direction = tileEntity.getDirection(); ForgeDirection direction = tileEntity.getDirection();
float modifier = 1;
if (entity instanceof EntityLiving) if (entity instanceof EntityLiving)
{ {
modifier = 10; acceleration *= 5;
maxSpeed *= 10;
} }
// Move the entity based on the conveyor belt's direction. // 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; 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; entity.motionX = 0;
} }

View file

@ -16,6 +16,7 @@ import net.minecraft.world.World;
import net.minecraftforge.oredict.ShapedOreRecipe; import net.minecraftforge.oredict.ShapedOreRecipe;
import net.minecraftforge.oredict.ShapelessOreRecipe; import net.minecraftforge.oredict.ShapelessOreRecipe;
import universalelectricity.core.vector.Vector3; import universalelectricity.core.vector.Vector3;
import assemblyline.common.Pair;
import cpw.mods.fml.relauncher.ReflectionHelper; import cpw.mods.fml.relauncher.ReflectionHelper;
public class ContainerImprinter extends Container implements IInventory, ISlotWatcher public class ContainerImprinter extends Container implements IInventory, ISlotWatcher
@ -79,8 +80,8 @@ public class ContainerImprinter extends Container implements IInventory, ISlotWa
if (slot == 2) if (slot == 2)
{ {
setInventorySlotContents(0, null); // Prevents filter from being // Prevents filter from being duplicated
// duplicated this.setInventorySlotContents(0, null);
} }
if (slot > 4) if (slot > 4)
@ -245,9 +246,12 @@ public class ContainerImprinter extends Container implements IInventory, ISlotWa
if (outputStack != null) if (outputStack != null)
{ {
if (this.getIdealRecipe(outputStack) != null) Pair<ItemStack, ItemStack[]> idealRecipe = this.getIdealRecipe(outputStack);
if (idealRecipe != null)
{ {
this.setInventorySlotContents(4, outputStack); System.out.println(idealRecipe.getKey().stackSize);
this.setInventorySlotContents(4, idealRecipe.getKey());
didCraft = true; didCraft = true;
} }
} }
@ -267,7 +271,7 @@ public class ContainerImprinter extends Container implements IInventory, ISlotWa
* *
* @return Required Items * @return Required Items
*/ */
public ItemStack[] getIdealRecipe(ItemStack outputItem) public Pair<ItemStack, ItemStack[]> getIdealRecipe(ItemStack outputItem)
{ {
for (Object object : CraftingManager.getInstance().getRecipeList()) for (Object object : CraftingManager.getInstance().getRecipeList())
{ {
@ -279,17 +283,17 @@ public class ContainerImprinter extends Container implements IInventory, ISlotWa
{ {
if (object instanceof ShapedRecipes) if (object instanceof ShapedRecipes)
{ {
if (this.doesMatch(((ShapedRecipes) object).recipeItems, outputItem)) { return ((ShapedRecipes) object).recipeItems; } if (this.hasResource(((ShapedRecipes) object).recipeItems)) { return new Pair<ItemStack, ItemStack[]>(((ShapedRecipes) object).getRecipeOutput().copy(), ((ShapedRecipes) object).recipeItems); }
} }
else if (object instanceof ShapelessRecipes) 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<ItemStack, ItemStack[]>(((ShapedRecipes) object).getRecipeOutput().copy(), (ItemStack[]) ((ShapelessRecipes) object).recipeItems.toArray(new ItemStack[1])); }
} }
else if (object instanceof ShapedOreRecipe) else if (object instanceof ShapedOreRecipe)
{ {
ShapedOreRecipe oreRecipe = (ShapedOreRecipe) object; ShapedOreRecipe oreRecipe = (ShapedOreRecipe) object;
Object[] oreRecipeInput = (Object[]) ReflectionHelper.getPrivateValue(ShapedOreRecipe.class, oreRecipe, "input"); Object[] oreRecipeInput = (Object[]) ReflectionHelper.getPrivateValue(ShapedOreRecipe.class, oreRecipe, "input");
if (doesMatch(oreRecipeInput, outputItem)) if (hasResource(oreRecipeInput))
{ {
ArrayList<ItemStack> finalRecipe = new ArrayList<ItemStack>(); ArrayList<ItemStack> finalRecipe = new ArrayList<ItemStack>();
for (Object ingredientListObject : oreRecipeInput) 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<ItemStack, ItemStack[]>(((ShapedRecipes) object).getRecipeOutput().copy(), finalRecipe.toArray(new ItemStack[1])); }
} }
} }
else if (object instanceof ShapelessOreRecipe) else if (object instanceof ShapelessOreRecipe)
{ {
ShapelessOreRecipe oreRecipe = (ShapelessOreRecipe) object; ShapelessOreRecipe oreRecipe = (ShapelessOreRecipe) object;
ArrayList oreRecipeInput = (ArrayList) ReflectionHelper.getPrivateValue(ShapelessOreRecipe.class, oreRecipe, "input"); ArrayList oreRecipeInput = (ArrayList) ReflectionHelper.getPrivateValue(ShapelessOreRecipe.class, oreRecipe, "input");
if (doesMatch(oreRecipeInput.toArray(), outputItem)) if (hasResource(oreRecipeInput.toArray()))
{ {
ArrayList<ItemStack> finalRecipe = new ArrayList<ItemStack>(); ArrayList<ItemStack> finalRecipe = new ArrayList<ItemStack>();
for (Object ingredientListObject : oreRecipeInput) 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<ItemStack, ItemStack[]>(((ShapedRecipes) object).getRecipeOutput().copy(), finalRecipe.toArray(new ItemStack[1])); }
} }
} }
} }
@ -359,7 +363,12 @@ public class ContainerImprinter extends Container implements IInventory, ISlotWa
return null; 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; int itemMatch = 0;
@ -381,6 +390,7 @@ public class ContainerImprinter extends Container implements IInventory, ISlotWa
{ {
// TODO Do NBT CHecking // TODO Do NBT CHecking
itemMatch++; itemMatch++;
break;
} }
} }
} }

View file

@ -35,7 +35,7 @@ public class SlotCraftingResult extends Slot
if (this.getStack() != null) if (this.getStack() != null)
{ {
ItemStack[] requiredItems = this.container.getIdealRecipe(this.getStack()).clone(); ItemStack[] requiredItems = this.container.getIdealRecipe(this.getStack()).getValue().clone();
if (requiredItems != null) if (requiredItems != null)
{ {
@ -63,7 +63,7 @@ public class SlotCraftingResult extends Slot
{ {
if (this.getStack() != null) if (this.getStack() != null)
{ {
ItemStack[] idealRecipe = this.container.getIdealRecipe(this.getStack()); ItemStack[] idealRecipe = this.container.getIdealRecipe(this.getStack()).getValue();
if (idealRecipe != null) if (idealRecipe != null)
{ {
ItemStack[] requiredItems = idealRecipe.clone(); ItemStack[] requiredItems = idealRecipe.clone();