fix to addToRandomInventory not providing the correct side
fixed some space/tabs things (exactly eclipse did it for me...) fixes #875
This commit is contained in:
parent
3e2a232f47
commit
3cf2ff96d0
5 changed files with 43 additions and 50 deletions
|
@ -55,37 +55,33 @@ public class Utils {
|
|||
|
||||
/**
|
||||
* Tries to add the passed stack to any valid inventories around the given coordinates.
|
||||
*
|
||||
*
|
||||
* @param stack
|
||||
* @param world
|
||||
* @param x
|
||||
* @param y
|
||||
* @param z
|
||||
* @param from
|
||||
* @return ItemStack representing what was added.
|
||||
*/
|
||||
public static ItemStack addToRandomInventory(ItemStack stack, World world, int x, int y, int z, ForgeDirection from) {
|
||||
LinkedList<ITransactor> possibleInventories = new LinkedList<ITransactor>();
|
||||
public static ItemStack addToRandomInventory(ItemStack stack, World world, int x, int y, int z) {
|
||||
LinkedList<Object[]> possibleInventories = new LinkedList<Object[]>();
|
||||
|
||||
// Determine inventories which can accept (at least part of) this stack.
|
||||
for (ForgeDirection orientation : ForgeDirection.values()) {
|
||||
if (from.getOpposite() == orientation) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Position pos = new Position(x, y, z, orientation);
|
||||
pos.moveForwards(1.0);
|
||||
|
||||
TileEntity tileInventory = world.getBlockTileEntity((int) pos.x, (int) pos.y, (int) pos.z);
|
||||
ITransactor transactor = Transactor.getTransactorFor(tileInventory);
|
||||
if (transactor != null && !(tileInventory instanceof TileEngine) && transactor.add(stack, from, false).stackSize > 0) {
|
||||
possibleInventories.add(transactor);
|
||||
if (transactor != null && !(tileInventory instanceof TileEngine) && transactor.add(stack, orientation.getOpposite(), false).stackSize > 0) {
|
||||
possibleInventories.add(new Object[] { orientation, transactor });
|
||||
}
|
||||
}
|
||||
|
||||
if (possibleInventories.size() > 0) {
|
||||
int choice = world.rand.nextInt(possibleInventories.size());
|
||||
return possibleInventories.get(choice).add(stack, from, true);
|
||||
Object[] chosen = possibleInventories.get(choice);
|
||||
return ((ITransactor) chosen[0]).add(stack, ((ForgeDirection) chosen[1]).getOpposite(), true);
|
||||
}
|
||||
|
||||
ItemStack added = stack.copy();
|
||||
|
@ -219,7 +215,7 @@ public class Utils {
|
|||
|
||||
/**
|
||||
* Ensures that the given inventory is the full inventory, i.e. takes double chests into account.
|
||||
*
|
||||
*
|
||||
* @param inv
|
||||
* @return Modified inventory if double chest, unmodified otherwise.
|
||||
*/
|
||||
|
@ -518,12 +514,12 @@ public class Utils {
|
|||
System.arraycopy(second, 0, result, first.length, second.length);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
public static int[] createSlotArray(int first, int count) {
|
||||
int[] slots = new int[count];
|
||||
for(int k = first; k < first + count; k++)
|
||||
for (int k = first; k < first + count; k++)
|
||||
slots[k - first] = k;
|
||||
return slots;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -71,7 +71,7 @@ public class TileMiningWell extends TileMachine implements IMachine, IPowerRecep
|
|||
|
||||
for (ItemStack stack : stacks) {
|
||||
|
||||
ItemStack added = Utils.addToRandomInventory(stack, worldObj, xCoord, yCoord, zCoord, ForgeDirection.UNKNOWN);
|
||||
ItemStack added = Utils.addToRandomInventory(stack, worldObj, xCoord, yCoord, zCoord);
|
||||
stack.stackSize -= added.stackSize;
|
||||
if (stack.stackSize <= 0) {
|
||||
continue;
|
||||
|
|
|
@ -444,7 +444,7 @@ public class TileQuarry extends TileMachine implements IMachine, IPowerReceptor,
|
|||
|
||||
private void mineStack(ItemStack stack) {
|
||||
// First, try to add to a nearby chest
|
||||
ItemStack added = Utils.addToRandomInventory(stack, worldObj, xCoord, yCoord, zCoord, ForgeDirection.UNKNOWN);
|
||||
ItemStack added = Utils.addToRandomInventory(stack, worldObj, xCoord, yCoord, zCoord);
|
||||
stack.stackSize -= added.stackSize;
|
||||
|
||||
// Second, try to add to adjacent pipes
|
||||
|
|
|
@ -39,7 +39,7 @@ public class TileAssemblyAdvancedWorkbench extends TileEntity implements IInvent
|
|||
int[] bindings = new int[9];
|
||||
ItemStack[] tempStacks;
|
||||
public int[] hitCount;
|
||||
private boolean useRecipeStack;
|
||||
private boolean useRecipeStack;
|
||||
|
||||
private InternalInventoryCrafting() {
|
||||
super(new InternalInventoryCraftingContainer(), 3, 3);
|
||||
|
@ -48,8 +48,8 @@ public class TileAssemblyAdvancedWorkbench extends TileEntity implements IInvent
|
|||
@Override
|
||||
public ItemStack getStackInSlot(int par1) {
|
||||
if (par1 >= 0 && par1 < 9) {
|
||||
if (useRecipeStack || tempStacks == null) {
|
||||
return craftingSlots.getStackInSlot(par1);
|
||||
if (useRecipeStack || tempStacks == null) {
|
||||
return craftingSlots.getStackInSlot(par1);
|
||||
} else {
|
||||
|
||||
if (bindings[par1] >= 0) {
|
||||
|
@ -77,10 +77,9 @@ public class TileAssemblyAdvancedWorkbench extends TileEntity implements IInvent
|
|||
return null;
|
||||
}
|
||||
|
||||
public void recipeUpdate(boolean flag)
|
||||
{
|
||||
useRecipeStack = flag;
|
||||
}
|
||||
public void recipeUpdate(boolean flag) {
|
||||
useRecipeStack = flag;
|
||||
}
|
||||
}
|
||||
|
||||
private final class InternalPlayer extends EntityPlayer {
|
||||
|
@ -284,10 +283,10 @@ public class TileAssemblyAdvancedWorkbench extends TileEntity implements IInvent
|
|||
internalInventoryCrafting.tempStacks = tempStorage;
|
||||
internalInventoryCrafting.hitCount = new int[27];
|
||||
for (int j = 0; j < craftingSlots.getSizeInventory(); j++) {
|
||||
if (craftingSlots.getStackInSlot(j) == null) {
|
||||
internalInventoryCrafting.bindings[j] = -1;
|
||||
continue;
|
||||
}
|
||||
if (craftingSlots.getStackInSlot(j) == null) {
|
||||
internalInventoryCrafting.bindings[j] = -1;
|
||||
continue;
|
||||
}
|
||||
boolean matchedStorage = false;
|
||||
for (int i = 0; i < tempStorage.length; i++) {
|
||||
if (tempStorage[i] != null && craftingSlots.getStackInSlot(j).isItemEqual(tempStorage[i])
|
||||
|
@ -342,7 +341,7 @@ public class TileAssemblyAdvancedWorkbench extends TileEntity implements IInvent
|
|||
}
|
||||
}
|
||||
if (output.stackSize > 0) {
|
||||
output = Utils.addToRandomInventory(output, worldObj, xCoord, yCoord, zCoord, ForgeDirection.UNKNOWN);
|
||||
output = Utils.addToRandomInventory(output, worldObj, xCoord, yCoord, zCoord);
|
||||
}
|
||||
if (output.stackSize > 0) {
|
||||
Utils.dropItems(worldObj, output, xCoord, yCoord, zCoord);
|
||||
|
@ -362,20 +361,19 @@ public class TileAssemblyAdvancedWorkbench extends TileEntity implements IInvent
|
|||
}
|
||||
|
||||
private void updateCraftingResults() {
|
||||
if (internalInventoryCrafting == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
internalInventoryCrafting.recipeUpdate(true);
|
||||
if(this.currentRecipe == null || !this.currentRecipe.matches(internalInventoryCrafting, worldObj))
|
||||
if (internalInventoryCrafting == null) {
|
||||
return;
|
||||
}
|
||||
internalInventoryCrafting.recipeUpdate(true);
|
||||
if (this.currentRecipe == null || !this.currentRecipe.matches(internalInventoryCrafting, worldObj))
|
||||
currentRecipe = CraftingHelper.findMatchingRecipe(internalInventoryCrafting, worldObj);
|
||||
|
||||
ItemStack resultStack = null;
|
||||
if(currentRecipe != null) {
|
||||
if (currentRecipe != null) {
|
||||
resultStack = currentRecipe.getCraftingResult(internalInventoryCrafting);
|
||||
}
|
||||
craftResult.setInventorySlotContents(0, resultStack);
|
||||
internalInventoryCrafting.recipeUpdate(false);
|
||||
internalInventoryCrafting.recipeUpdate(false);
|
||||
onInventoryChanged();
|
||||
}
|
||||
|
||||
|
|
|
@ -74,6 +74,7 @@ public class TileAssemblyTable extends TileEntity implements IMachine, IInventor
|
|||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receiveLaserEnergy(float energy) {
|
||||
energyStored += energy;
|
||||
recentEnergy[tick] += energy;
|
||||
|
@ -130,7 +131,7 @@ public class TileAssemblyTable extends TileEntity implements IMachine, IInventor
|
|||
}
|
||||
|
||||
ItemStack remaining = currentRecipe.output.copy();
|
||||
ItemStack added = Utils.addToRandomInventory(remaining, worldObj, xCoord, yCoord, zCoord, ForgeDirection.UNKNOWN);
|
||||
ItemStack added = Utils.addToRandomInventory(remaining, worldObj, xCoord, yCoord, zCoord);
|
||||
remaining.stackSize -= added.stackSize;
|
||||
|
||||
if (remaining.stackSize > 0) {
|
||||
|
@ -493,17 +494,15 @@ public class TileAssemblyTable extends TileEntity implements IMachine, IInventor
|
|||
return zCoord;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInvNameLocalized()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean isInvNameLocalized() {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isStackValidForSlot(int i, ItemStack itemstack)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean isStackValidForSlot(int i, ItemStack itemstack) {
|
||||
// TODO Auto-generated method stub
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue