Avoid unnecessary ItemStack allocations

This commit is contained in:
Raoul Van den Berge
2016-06-03 23:19:10 +02:00
parent 937e0815eb
commit 3f0f990857
8 changed files with 16 additions and 17 deletions

View File

@@ -71,7 +71,7 @@ public class TileConstructor extends TileMachine implements ICompareConfig {
}
if (block != null && block.canPlaceBlockAt(worldObj, front)) {
ItemStack took = controller.take(filter.getStackInSlot(0), compare);
ItemStack took = controller.take(filter.getStackInSlot(0), 1, compare);
if (took != null) {
scheduler.resetSchedule();

View File

@@ -48,9 +48,9 @@ public class TileExporter extends TileMachine implements ICompareConfig {
ItemStack slot = filters.getStackInSlot(i);
if (slot != null) {
int quantity = RefinedStorageUtils.hasUpgrade(upgrades, ItemUpgrade.TYPE_STACK) ? 64 : 1;
int size = RefinedStorageUtils.hasUpgrade(upgrades, ItemUpgrade.TYPE_STACK) ? 64 : 1;
ItemStack took = controller.take(ItemHandlerHelper.copyStackWithSize(slot, quantity), compare);
ItemStack took = controller.take(slot, size, compare);
if (took != null) {
scheduler.resetSchedule();

View File

@@ -78,7 +78,7 @@ public class TileInterface extends TileMachine implements ICompareConfig {
int needed = got == null ? wanted.stackSize : wanted.stackSize - got.stackSize;
if (needed > 0) {
ItemStack took = controller.take(ItemHandlerHelper.copyStackWithSize(wanted, needed), compare);
ItemStack took = controller.take(wanted, needed, compare);
if (took != null) {
if (got == null) {

View File

@@ -64,7 +64,7 @@ public class BasicCraftingTask implements ICraftingTask {
if (!satisfied[i]) {
done = false;
ItemStack took = controller.take(input);
ItemStack took = controller.take(input, 1);
if (took != null) {
itemsTook.add(took);

View File

@@ -53,7 +53,7 @@ public class ProcessingCraftingTask implements ICraftingTask {
for (int i = 0; i < inserted.length; ++i) {
if (!inserted[i]) {
ItemStack input = pattern.getInputs()[i];
ItemStack took = controller.take(input);
ItemStack took = controller.take(input, 1);
if (took != null) {
if (ItemHandlerHelper.insertItem(handler, took, true) == null) {

View File

@@ -2,7 +2,6 @@ package refinedstorage.tile.controller;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
import net.minecraftforge.items.ItemHandlerHelper;
import refinedstorage.RefinedStorageUtils;
import refinedstorage.item.ItemWirelessGrid;
import refinedstorage.network.GridPullFlags;
@@ -45,7 +44,7 @@ public class StorageHandler {
size = Math.min(size, stack.getItem().getItemStackLimit(stack));
ItemStack took = controller.take(ItemHandlerHelper.copyStackWithSize(stack, size));
ItemStack took = controller.take(stack, size);
if (took != null) {
if (GridPullFlags.isPullingWithShift(flags)) {

View File

@@ -385,13 +385,13 @@ public class TileController extends TileBase implements IEnergyReceiver, ISynchr
return false;
}
public ItemStack take(ItemStack stack) {
return take(stack, RefinedStorageUtils.COMPARE_DAMAGE | RefinedStorageUtils.COMPARE_NBT);
public ItemStack take(ItemStack stack, int size) {
return take(stack, size, RefinedStorageUtils.COMPARE_DAMAGE | RefinedStorageUtils.COMPARE_NBT);
}
public ItemStack take(ItemStack stack, int flags) {
int requested = stack.stackSize;
int receiving = 0;
public ItemStack take(ItemStack stack, int size, int flags) {
int requested = size;
int received = 0;
ItemStack newStack = null;
@@ -405,10 +405,10 @@ public class TileController extends TileBase implements IEnergyReceiver, ISynchr
newStack.stackSize += took.stackSize;
}
receiving += took.stackSize;
received += took.stackSize;
}
if (requested == receiving) {
if (requested == received) {
break;
}
}

View File

@@ -149,7 +149,7 @@ public class TileGrid extends TileMachine implements IGrid {
if (slot != null) {
if (slot.stackSize == 1 && isConnected()) {
matrix.setInventorySlotContents(i, controller.take(slot));
matrix.setInventorySlotContents(i, controller.take(slot, 1));
} else {
matrix.decrStackSize(i, 1);
}
@@ -247,7 +247,7 @@ public class TileGrid extends TileMachine implements IGrid {
if (getType() == EnumGridType.CRAFTING) {
for (ItemStack possibility : possibilities) {
ItemStack took = controller.take(possibility);
ItemStack took = controller.take(possibility, 1);
if (took != null) {
matrix.setInventorySlotContents(i, possibility);