Added AartBluestoke's PR for RoundRobin transactor. Closes #234

This commit is contained in:
SirSengir 2012-09-09 18:59:05 +02:00
parent 30aef0704c
commit 1131a8d661
4 changed files with 61 additions and 43 deletions

View file

@ -18,7 +18,7 @@
<property name="mcp.version" value="72"/> <property name="mcp.version" value="72"/>
<property name="forge.version" value="4.0.0.232"/> <property name="forge.version" value="4.0.0.232"/>
<property name="bc.version" value="3.2.0"/> <property name="bc.version" value="3.2.0"/>
<property name="bc.version.full" value="${bc.version}pre4"/> <property name="bc.version.full" value="${bc.version}pre5"/>
<echo message="Starting build for ${bc.version.full}"/> <echo message="Starting build for ${bc.version.full}"/>
@ -77,7 +77,7 @@
<exclude name="**/buildcraft/devel"/> <exclude name="**/buildcraft/devel"/>
</fileset> </fileset>
<filterset> <filterset>
<filter token="VERSION" value="${bc.version}" /> <filter token="VERSION" value="${bc.version.full}" />
<filter token="BUILD_NUMBER" value="${build.number}" /> <filter token="BUILD_NUMBER" value="${build.number}" />
</filterset> </filterset>
</copy> </copy>

View file

@ -0,0 +1,53 @@
package buildcraft.core.inventory;
import net.minecraft.src.IInventory;
import net.minecraft.src.ItemStack;
import buildcraft.api.core.Orientations;
public class TransactorRoundRobin extends TransactorSimple {
public TransactorRoundRobin(IInventory inventory) {
super(inventory);
}
@Override
public int inject(ItemStack stack, Orientations orientation, boolean doAdd) {
int oneLessThanStackSize = stack.stackSize - 1;
int added = 0;
for (int itemLoop = 0; itemLoop < stack.stackSize; ++itemLoop) { // add 1 item n times.
int minSimilar = Integer.MAX_VALUE;
int minSlot = -1;
for (int j = 0; j < inventory.getSizeInventory() && minSlot > 1; ++j) {
ItemStack stackInInventory = inventory.getStackInSlot(j);
if(stackInInventory == null)
continue;
if(stackInInventory.stackSize >= stackInInventory.getMaxStackSize())
continue;
if(stackInInventory.stackSize >= inventory.getInventoryStackLimit())
continue;
if (stackInInventory.stackSize > 0 && stackInInventory.itemID == stack.itemID
&& stackInInventory.getItemDamage() == stack.getItemDamage() && stackInInventory.stackSize < minSimilar) {
minSimilar = stackInInventory.stackSize;
minSlot = j;
}
}
if (minSlot != -1) {
added += addToSlot(minSlot, stack, oneLessThanStackSize, doAdd); // add 1 item n times, into the selected slot
} else // nowhere to add this
break;
}
return added;
}
}

View file

@ -6,7 +6,7 @@ import buildcraft.api.core.Orientations;
public class TransactorSimple extends Transactor { public class TransactorSimple extends Transactor {
private IInventory inventory; protected IInventory inventory;
public TransactorSimple(IInventory inventory) { public TransactorSimple(IInventory inventory) {
this.inventory = inventory; this.inventory = inventory;

View file

@ -14,8 +14,7 @@ import java.util.LinkedList;
import buildcraft.api.core.Orientations; import buildcraft.api.core.Orientations;
import buildcraft.api.core.Position; import buildcraft.api.core.Position;
import buildcraft.api.inventory.ISpecialInventory; import buildcraft.api.inventory.ISpecialInventory;
import buildcraft.core.inventory.ITransactor; import buildcraft.core.inventory.TransactorRoundRobin;
import buildcraft.core.inventory.TransactorSimple;
import buildcraft.core.utils.Utils; import buildcraft.core.utils.Utils;
import net.minecraft.src.Container; import net.minecraft.src.Container;
@ -271,47 +270,13 @@ public class TileAutoWorkbench extends TileEntity implements ISpecialInventory {
return null; return null;
} }
@Override @Override public void openChest() {}
public void openChest() { @Override public void closeChest() {}
}
@Override
public void closeChest() {
}
/* ISPECIALINVENTORY */ /* ISPECIALINVENTORY */
@Override @Override
public int addItem(ItemStack stack, boolean doAdd, Orientations from) { public int addItem(ItemStack stack, boolean doAdd, Orientations from) {
return new TransactorRoundRobin(this).add(stack, from, doAdd).stackSize;
ITransactor transactor = new TransactorSimple(this);
int minSimilar = Integer.MAX_VALUE;
int minSlot = -1;
for (int j = 0; j < getSizeInventory(); ++j) {
ItemStack stackInInventory = getStackInSlot(j);
if (stackInInventory != null && stackInInventory.stackSize > 0 && stackInInventory.itemID == stack.itemID
&& stackInInventory.getItemDamage() == stack.getItemDamage() && stackInInventory.stackSize < minSimilar) {
minSimilar = stackInInventory.stackSize;
minSlot = j;
}
}
if (minSlot != -1) {
ItemStack added = transactor.add(stack, from, doAdd);
ItemStack remaining = stack.copy();
remaining.stackSize -= added.stackSize;
if(doAdd && remaining.stackSize >= 0)
added.stackSize += addItem(remaining, doAdd, from);
return added.stackSize;
} else
return 0;
} }
@Override @Override