Improve IStorage API a bit
This commit is contained in:
@@ -20,20 +20,20 @@ public interface IStorage {
|
||||
/**
|
||||
* Pushes an item to this storage.
|
||||
*
|
||||
* @param stack The stack to push, do NOT modify this stack
|
||||
* @param stack The stack prototype to push, do NOT modify
|
||||
* @param size The amount of that prototype that has to be pushed
|
||||
* @param simulate If we are simulating
|
||||
* @return null if the push was successful, or an ItemStack with the remainder
|
||||
* @todo make it push(stack, size, simulate)
|
||||
*/
|
||||
ItemStack push(ItemStack stack, boolean simulate);
|
||||
ItemStack push(ItemStack stack, int size, boolean simulate);
|
||||
|
||||
/**
|
||||
* Takes an item from storage.
|
||||
* If the stack we found in the system is smaller then the requested size, return the stack anyway.
|
||||
* For example: this function is called for dirt (64x) while there is only dirt (32x), return the dirt (32x) anyway.
|
||||
*
|
||||
* @param stack A prototype of the stack to push, do NOT modify this stack
|
||||
* @param size The amount of that prototype we're taking
|
||||
* @param stack A prototype of the stack to take, do NOT modify
|
||||
* @param size The amount of that prototype that has to be taken
|
||||
* @param flags On what we are comparing to take the item, see {@link CompareFlags}
|
||||
* @return null if we didn't take anything, or an ItemStack with the take result
|
||||
*/
|
||||
|
||||
@@ -104,14 +104,14 @@ public abstract class NBTStorage implements IStorage {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack push(ItemStack stack, boolean simulate) {
|
||||
public ItemStack push(ItemStack stack, int size, boolean simulate) {
|
||||
for (ItemStack otherStack : stacks) {
|
||||
if (RefinedStorageUtils.compareStackNoQuantity(otherStack, stack)) {
|
||||
if (!simulate) {
|
||||
markDirty();
|
||||
}
|
||||
|
||||
if (getStored() + stack.stackSize > getCapacity()) {
|
||||
if (getStored() + size > getCapacity()) {
|
||||
int remainingSpace = getCapacity() - getStored();
|
||||
|
||||
if (remainingSpace <= 0) {
|
||||
@@ -124,12 +124,12 @@ public abstract class NBTStorage implements IStorage {
|
||||
otherStack.stackSize += remainingSpace;
|
||||
}
|
||||
|
||||
return ItemHandlerHelper.copyStackWithSize(otherStack, stack.stackSize - remainingSpace);
|
||||
return ItemHandlerHelper.copyStackWithSize(otherStack, size - remainingSpace);
|
||||
} else {
|
||||
if (!simulate) {
|
||||
tag.setInteger(NBT_STORED, getStored() + stack.stackSize);
|
||||
tag.setInteger(NBT_STORED, getStored() + size);
|
||||
|
||||
otherStack.stackSize += stack.stackSize;
|
||||
otherStack.stackSize += size;
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -141,7 +141,7 @@ public abstract class NBTStorage implements IStorage {
|
||||
markDirty();
|
||||
}
|
||||
|
||||
if (getStored() + stack.stackSize > getCapacity()) {
|
||||
if (getStored() + size > getCapacity()) {
|
||||
int remainingSpace = getCapacity() - getStored();
|
||||
|
||||
if (remainingSpace <= 0) {
|
||||
@@ -154,12 +154,12 @@ public abstract class NBTStorage implements IStorage {
|
||||
stacks.add(ItemHandlerHelper.copyStackWithSize(stack, remainingSpace));
|
||||
}
|
||||
|
||||
return ItemHandlerHelper.copyStackWithSize(stack, stack.stackSize - remainingSpace);
|
||||
return ItemHandlerHelper.copyStackWithSize(stack, size - remainingSpace);
|
||||
} else {
|
||||
tag.setInteger(NBT_STORED, getStored() + stack.stackSize);
|
||||
tag.setInteger(NBT_STORED, getStored() + size);
|
||||
|
||||
if (!simulate) {
|
||||
stacks.add(stack.copy());
|
||||
stacks.add(ItemHandlerHelper.copyStackWithSize(stack, size));
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
@@ -93,12 +93,12 @@ public class BasicCraftingTask implements ICraftingTask {
|
||||
@Override
|
||||
public void onDone(TileController controller) {
|
||||
for (ItemStack output : pattern.getOutputs()) {
|
||||
controller.push(output, false);
|
||||
controller.push(output, output.stackSize, false);
|
||||
}
|
||||
|
||||
if (pattern.getByproducts() != null) {
|
||||
for (ItemStack byproduct : pattern.getByproducts()) {
|
||||
controller.push(byproduct, false);
|
||||
controller.push(byproduct, byproduct.stackSize, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -107,7 +107,7 @@ public class BasicCraftingTask implements ICraftingTask {
|
||||
@Override
|
||||
public void onCancelled(TileController controller) {
|
||||
for (ItemStack took : itemsTook) {
|
||||
controller.push(took, false);
|
||||
controller.push(took, took.stackSize, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ public class ProcessingCraftingTask implements ICraftingTask {
|
||||
|
||||
inserted[i] = true;
|
||||
} else {
|
||||
controller.push(took, false);
|
||||
controller.push(took, took.stackSize, false);
|
||||
}
|
||||
} else if (!childTasks[i]) {
|
||||
CraftingPattern pattern = controller.getPattern(input);
|
||||
|
||||
@@ -50,7 +50,7 @@ public class MessageGridCraftingClear extends MessageHandlerPlayerToServer<Messa
|
||||
ItemStack slot = grid.getMatrix().getStackInSlot(i);
|
||||
|
||||
if (slot != null) {
|
||||
grid.getMatrix().setInventorySlotContents(i, grid.getController().push(slot, false));
|
||||
grid.getMatrix().setInventorySlotContents(i, grid.getController().push(slot, slot.stackSize, false));
|
||||
}
|
||||
}
|
||||
} else if (grid.getType() == EnumGridType.PATTERN) {
|
||||
|
||||
@@ -52,7 +52,7 @@ public class MessageGridCraftingPush extends MessageHandlerPlayerToServer<Messag
|
||||
ItemStack stack = grid.getMatrix().getStackInSlot(message.craftingSlot);
|
||||
|
||||
if (stack != null) {
|
||||
grid.getMatrix().setInventorySlotContents(message.craftingSlot, grid.getController().push(stack, false));
|
||||
grid.getMatrix().setInventorySlotContents(message.craftingSlot, grid.getController().push(stack, stack.stackSize, false));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ public class TileDestructor extends TileMachine implements ICompareConfig, IMode
|
||||
if (controller == null) {
|
||||
InventoryHelper.spawnItemStack(worldObj, front.getX(), front.getY(), front.getZ(), drop);
|
||||
} else {
|
||||
ItemStack remainder = controller.push(drop, false);
|
||||
ItemStack remainder = controller.push(drop, drop.stackSize, false);
|
||||
|
||||
if (remainder != null) {
|
||||
InventoryHelper.spawnItemStack(worldObj, front.getX(), front.getY(), front.getZ(), remainder);
|
||||
|
||||
@@ -36,12 +36,12 @@ public class TileDiskDrive extends TileMachine implements IStorageProvider, ISto
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack push(ItemStack stack, boolean simulate) {
|
||||
public ItemStack push(ItemStack stack, int size, boolean simulate) {
|
||||
if (!ModeFilter.respectsMode(getFilters(), getModeConfig(), getCompare(), stack)) {
|
||||
return stack;
|
||||
}
|
||||
|
||||
return super.push(stack, simulate);
|
||||
return super.push(stack, size, simulate);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ public class TileExporter extends TileMachine implements ICompareConfig {
|
||||
return;
|
||||
}
|
||||
|
||||
controller.push(took, false);
|
||||
controller.push(took, took.stackSize, false);
|
||||
} else if (RefinedStorageUtils.hasUpgrade(upgrades, ItemUpgrade.TYPE_CRAFTING)) {
|
||||
if (scheduler.canSchedule(compare, slot)) {
|
||||
scheduler.schedule(controller, compare, slot);
|
||||
|
||||
@@ -63,8 +63,8 @@ public class TileImporter extends TileMachine implements ICompareConfig, IModeCo
|
||||
|
||||
ItemStack result = handler.extractItem(currentSlot, quantity, true);
|
||||
|
||||
if (result != null && controller.push(result, true) == null) {
|
||||
controller.push(result, false);
|
||||
if (result != null && controller.push(result, result.stackSize, true) == null) {
|
||||
controller.push(result, result.stackSize, false);
|
||||
|
||||
handler.extractItem(currentSlot, quantity, false);
|
||||
} else {
|
||||
|
||||
@@ -8,7 +8,6 @@ import net.minecraft.util.EnumFacing;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.items.CapabilityItemHandler;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
import net.minecraftforge.items.ItemHandlerHelper;
|
||||
import net.minecraftforge.items.wrapper.CombinedInvWrapper;
|
||||
import refinedstorage.RefinedStorageItems;
|
||||
import refinedstorage.RefinedStorageUtils;
|
||||
@@ -53,10 +52,9 @@ public class TileInterface extends TileMachine implements ICompareConfig {
|
||||
} else if (ticks % RefinedStorageUtils.getSpeed(upgrades) == 0) {
|
||||
int size = RefinedStorageUtils.hasUpgrade(upgrades, ItemUpgrade.TYPE_STACK) ? 64 : 1;
|
||||
|
||||
ItemStack pushing = ItemHandlerHelper.copyStackWithSize(slot, size);
|
||||
|
||||
if (controller.push(pushing, true) == null) {
|
||||
controller.push(pushing, false);
|
||||
// @todo: handle remainder better
|
||||
if (controller.push(slot, size, true) == null) {
|
||||
controller.push(slot, size, false);
|
||||
|
||||
importItems.extractItem(currentSlot, size, false);
|
||||
}
|
||||
|
||||
@@ -35,12 +35,12 @@ public class TileStorage extends TileMachine implements IStorageProvider, IStora
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack push(ItemStack stack, boolean simulate) {
|
||||
public ItemStack push(ItemStack stack, int size, boolean simulate) {
|
||||
if (!ModeFilter.respectsMode(filters, TileStorage.this, compare, stack)) {
|
||||
return stack;
|
||||
}
|
||||
|
||||
return super.push(stack, simulate);
|
||||
return super.push(stack, size, simulate);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -77,8 +77,8 @@ public class StorageHandler {
|
||||
if (stack != null) {
|
||||
if (playerSlot == -1) {
|
||||
if (one) {
|
||||
if (controller.push(stack, true) == null) {
|
||||
controller.push(stack, false);
|
||||
if (controller.push(stack, stack.stackSize, true) == null) {
|
||||
controller.push(stack, stack.stackSize, false);
|
||||
|
||||
player.inventory.getItemStack().stackSize--;
|
||||
|
||||
@@ -87,12 +87,12 @@ public class StorageHandler {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
player.inventory.setItemStack(controller.push(stack, false));
|
||||
player.inventory.setItemStack(controller.push(stack, stack.stackSize, false));
|
||||
}
|
||||
|
||||
player.updateHeldItem();
|
||||
} else {
|
||||
player.inventory.setInventorySlotContents(playerSlot, controller.push(stack, false));
|
||||
player.inventory.setInventorySlotContents(playerSlot, controller.push(stack, stack.stackSize, false));
|
||||
}
|
||||
|
||||
controller.getWirelessGridHandler().drainEnergy(player, ItemWirelessGrid.USAGE_PUSH);
|
||||
|
||||
@@ -368,14 +368,16 @@ public class TileController extends TileBase implements IEnergyReceiver, ISynchr
|
||||
RefinedStorage.NETWORK.sendTo(new MessageGridItems(this), player);
|
||||
}
|
||||
|
||||
public ItemStack push(ItemStack stack, boolean simulate) {
|
||||
public ItemStack push(ItemStack stack, int size, boolean simulate) {
|
||||
ItemStack remainder = stack;
|
||||
|
||||
for (IStorage storage : storages) {
|
||||
remainder = storage.push(remainder, simulate);
|
||||
remainder = storage.push(remainder, size, simulate);
|
||||
|
||||
if (remainder == null) {
|
||||
break;
|
||||
} else {
|
||||
size = remainder.stackSize;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -30,10 +30,10 @@ public class DrawerStorage extends ExternalStorage {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack push(ItemStack stack, boolean simulate) {
|
||||
public ItemStack push(ItemStack stack, int size, boolean simulate) {
|
||||
if (ModeFilter.respectsMode(externalStorage.getFilters(), externalStorage, externalStorage.getCompare(), stack) && drawer.canItemBeStored(stack)) {
|
||||
if (!drawer.isEmpty()) {
|
||||
if (getStored() + stack.stackSize > drawer.getMaxCapacity(stack)) {
|
||||
if (getStored() + size > drawer.getMaxCapacity(stack)) {
|
||||
int remainingSpace = getCapacity() - getStored();
|
||||
|
||||
if (remainingSpace <= 0) {
|
||||
@@ -44,16 +44,16 @@ public class DrawerStorage extends ExternalStorage {
|
||||
drawer.setStoredItemCount(drawer.getStoredItemCount() + remainingSpace);
|
||||
}
|
||||
|
||||
return ItemHandlerHelper.copyStackWithSize(stack, stack.stackSize - remainingSpace);
|
||||
return ItemHandlerHelper.copyStackWithSize(stack, size - remainingSpace);
|
||||
} else {
|
||||
if (!simulate) {
|
||||
drawer.setStoredItemCount(drawer.getStoredItemCount() + stack.stackSize);
|
||||
drawer.setStoredItemCount(drawer.getStoredItemCount() + size);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
if (getStored() + stack.stackSize > drawer.getMaxCapacity(stack)) {
|
||||
if (getStored() + size > drawer.getMaxCapacity(stack)) {
|
||||
int remainingSpace = getCapacity() - getStored();
|
||||
|
||||
if (remainingSpace <= 0) {
|
||||
@@ -64,10 +64,10 @@ public class DrawerStorage extends ExternalStorage {
|
||||
drawer.setStoredItem(stack, remainingSpace);
|
||||
}
|
||||
|
||||
return ItemHandlerHelper.copyStackWithSize(stack, stack.stackSize - remainingSpace);
|
||||
return ItemHandlerHelper.copyStackWithSize(stack, size - remainingSpace);
|
||||
} else {
|
||||
if (!simulate) {
|
||||
drawer.setStoredItem(stack, stack.stackSize);
|
||||
drawer.setStoredItem(stack, size);
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
@@ -32,9 +32,9 @@ public class ItemHandlerStorage extends ExternalStorage {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack push(ItemStack stack, boolean simulate) {
|
||||
public ItemStack push(ItemStack stack, int size, boolean simulate) {
|
||||
if (ModeFilter.respectsMode(externalStorage.getFilters(), externalStorage, externalStorage.getCompare(), stack)) {
|
||||
return ItemHandlerHelper.insertItem(handler, stack, simulate);
|
||||
return ItemHandlerHelper.insertItem(handler, ItemHandlerHelper.copyStackWithSize(stack, size), simulate);
|
||||
}
|
||||
|
||||
return stack;
|
||||
|
||||
@@ -228,10 +228,10 @@ public class TileGrid extends TileMachine implements IGrid {
|
||||
|
||||
if (slot != null) {
|
||||
if (getType() == EnumGridType.CRAFTING) {
|
||||
if (controller.push(slot, true) != null) {
|
||||
if (controller.push(slot, slot.stackSize, true) != null) {
|
||||
return;
|
||||
} else {
|
||||
controller.push(slot, false);
|
||||
controller.push(slot, slot.stackSize, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user