Make importer less fast
This commit is contained in:
@@ -15,11 +15,15 @@ public class TileImporter extends TileMachine implements ICompareSetting, IModeS
|
|||||||
public static final String NBT_COMPARE = "Compare";
|
public static final String NBT_COMPARE = "Compare";
|
||||||
public static final String NBT_MODE = "Mode";
|
public static final String NBT_MODE = "Mode";
|
||||||
|
|
||||||
|
public static final int SPEED = 3;
|
||||||
|
|
||||||
private InventorySimple inventory = new InventorySimple("importer", 9, this);
|
private InventorySimple inventory = new InventorySimple("importer", 9, this);
|
||||||
|
|
||||||
private int compare = 0;
|
private int compare = 0;
|
||||||
private int mode = 0;
|
private int mode = 0;
|
||||||
|
|
||||||
|
private int currentSlot;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getEnergyUsage() {
|
public int getEnergyUsage() {
|
||||||
return 2;
|
return 2;
|
||||||
@@ -27,38 +31,64 @@ public class TileImporter extends TileMachine implements ICompareSetting, IModeS
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateMachine() {
|
public void updateMachine() {
|
||||||
if (ticks % 5 == 0) {
|
TileEntity connectedTile = worldObj.getTileEntity(pos.offset(getDirection()));
|
||||||
TileEntity connectedTile = worldObj.getTileEntity(pos.offset(getDirection()));
|
|
||||||
|
|
||||||
if (connectedTile instanceof ISidedInventory) {
|
if (connectedTile instanceof ISidedInventory) {
|
||||||
ISidedInventory sided = (ISidedInventory) connectedTile;
|
ISidedInventory sided = (ISidedInventory) connectedTile;
|
||||||
|
|
||||||
int[] availableSlots = sided.getSlotsForFace(getDirection().getOpposite());
|
int[] availableSlots = sided.getSlotsForFace(getDirection().getOpposite());
|
||||||
|
|
||||||
for (int availableSlot : availableSlots) {
|
if (currentSlot >= availableSlots.length) {
|
||||||
ItemStack stack = sided.getStackInSlot(availableSlot);
|
currentSlot = 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (stack != null && canImport(stack) && sided.canExtractItem(availableSlot, stack, getDirection().getOpposite())) {
|
if (availableSlots.length > 0) {
|
||||||
if (getController().push(stack.copy())) {
|
int availableSlot = availableSlots[currentSlot];
|
||||||
sided.setInventorySlotContents(availableSlot, null);
|
|
||||||
sided.markDirty();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (connectedTile instanceof IInventory) {
|
|
||||||
IInventory inventory = (IInventory) connectedTile;
|
|
||||||
|
|
||||||
for (int i = 0; i < inventory.getSizeInventory(); ++i) {
|
ItemStack stack = sided.getStackInSlot(availableSlot);
|
||||||
ItemStack stack = inventory.getStackInSlot(i);
|
|
||||||
|
|
||||||
if (stack != null && canImport(stack)) {
|
if (stack == null) {
|
||||||
if (getController().push(stack.copy())) {
|
currentSlot++;
|
||||||
inventory.setInventorySlotContents(i, null);
|
} else {
|
||||||
inventory.markDirty();
|
if (ticks % SPEED == 0) {
|
||||||
|
ItemStack toTake = stack.copy();
|
||||||
|
toTake.stackSize = 1;
|
||||||
|
|
||||||
|
if (canImport(toTake) && sided.canExtractItem(availableSlot, toTake, getDirection().getOpposite())) {
|
||||||
|
if (getController().push(toTake)) {
|
||||||
|
sided.decrStackSize(availableSlot, 1);
|
||||||
|
sided.markDirty();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if (connectedTile instanceof IInventory) {
|
||||||
|
IInventory inventory = (IInventory) connectedTile;
|
||||||
|
|
||||||
|
if (currentSlot >= inventory.getSizeInventory()) {
|
||||||
|
currentSlot = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
ItemStack stack = inventory.getStackInSlot(currentSlot);
|
||||||
|
|
||||||
|
if (stack != null) {
|
||||||
|
if (ticks % SPEED == 0) {
|
||||||
|
ItemStack toTake = stack.copy();
|
||||||
|
toTake.stackSize = 1;
|
||||||
|
|
||||||
|
if (canImport(toTake)) {
|
||||||
|
if (getController().push(toTake)) {
|
||||||
|
inventory.decrStackSize(currentSlot, 1);
|
||||||
|
inventory.markDirty();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
currentSlot++;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
currentSlot = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user