Avoid unnecessary ItemStack allocations #2
This commit is contained in:
@@ -9,7 +9,7 @@ public interface IStorage {
|
|||||||
|
|
||||||
void push(ItemStack stack);
|
void push(ItemStack stack);
|
||||||
|
|
||||||
ItemStack take(ItemStack stack, int flags);
|
ItemStack take(ItemStack stack, int size, int flags);
|
||||||
|
|
||||||
boolean mayPush(ItemStack stack);
|
boolean mayPush(ItemStack stack);
|
||||||
|
|
||||||
|
|||||||
@@ -96,9 +96,7 @@ public abstract class NBTStorage implements IStorage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack take(ItemStack stack, int flags) {
|
public ItemStack take(ItemStack stack, int size, int flags) {
|
||||||
int size = stack.stackSize;
|
|
||||||
|
|
||||||
for (ItemStack s : stacks) {
|
for (ItemStack s : stacks) {
|
||||||
if (RefinedStorageUtils.compareStack(s, stack, flags)) {
|
if (RefinedStorageUtils.compareStack(s, stack, flags)) {
|
||||||
if (size > s.stackSize) {
|
if (size > s.stackSize) {
|
||||||
|
|||||||
@@ -82,21 +82,16 @@ public class TileExternalStorage extends TileMachine implements IStorageProvider
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack take(ItemStack stack, int flags) {
|
public ItemStack take(ItemStack stack, int size, int flags) {
|
||||||
int quantity = stack.stackSize;
|
|
||||||
|
|
||||||
IDeepStorageUnit storageUnit = getStorageUnit();
|
IDeepStorageUnit storageUnit = getStorageUnit();
|
||||||
|
|
||||||
if (storageUnit != null) {
|
if (storageUnit != null) {
|
||||||
if (storageUnit.getStoredItemType() != null && RefinedStorageUtils.compareStackNoQuantity(storageUnit.getStoredItemType(), stack)) {
|
if (storageUnit.getStoredItemType() != null && RefinedStorageUtils.compareStackNoQuantity(storageUnit.getStoredItemType(), stack)) {
|
||||||
if (quantity > storageUnit.getStoredItemType().stackSize) {
|
size = Math.min(size, storageUnit.getStoredItemType().stackSize);
|
||||||
quantity = storageUnit.getStoredItemType().stackSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
ItemStack took = storageUnit.getStoredItemType().copy();
|
ItemStack took = ItemHandlerHelper.copyStackWithSize(storageUnit.getStoredItemType(), size);
|
||||||
took.stackSize = quantity;
|
|
||||||
|
|
||||||
storageUnit.setStoredItemCount(storageUnit.getStoredItemType().stackSize - quantity);
|
storageUnit.setStoredItemCount(storageUnit.getStoredItemType().stackSize - size);
|
||||||
|
|
||||||
return took;
|
return took;
|
||||||
}
|
}
|
||||||
@@ -108,13 +103,13 @@ public class TileExternalStorage extends TileMachine implements IStorageProvider
|
|||||||
ItemStack slot = handler.getStackInSlot(i);
|
ItemStack slot = handler.getStackInSlot(i);
|
||||||
|
|
||||||
if (slot != null && RefinedStorageUtils.compareStack(slot, stack, flags)) {
|
if (slot != null && RefinedStorageUtils.compareStack(slot, stack, flags)) {
|
||||||
if (quantity > slot.stackSize) {
|
size = Math.min(size, slot.stackSize);
|
||||||
quantity = slot.stackSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
handler.extractItem(i, quantity, false);
|
ItemStack took = ItemHandlerHelper.copyStackWithSize(slot, size);
|
||||||
|
|
||||||
return ItemHandlerHelper.copyStackWithSize(slot, quantity);
|
handler.extractItem(i, size, false);
|
||||||
|
|
||||||
|
return took;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -396,7 +396,7 @@ public class TileController extends TileBase implements IEnergyReceiver, ISynchr
|
|||||||
ItemStack newStack = null;
|
ItemStack newStack = null;
|
||||||
|
|
||||||
for (IStorage storage : storages) {
|
for (IStorage storage : storages) {
|
||||||
ItemStack took = storage.take(stack, flags);
|
ItemStack took = storage.take(stack, requested, flags);
|
||||||
|
|
||||||
if (took != null) {
|
if (took != null) {
|
||||||
if (newStack == null) {
|
if (newStack == null) {
|
||||||
|
|||||||
Reference in New Issue
Block a user