Untested itemstack remainder handling
This commit is contained in:
51
src/main/java/refinedstorage/api/storage/IStorage.java
Executable file
51
src/main/java/refinedstorage/api/storage/IStorage.java
Executable file
@@ -0,0 +1,51 @@
|
||||
package refinedstorage.api.storage;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Represents a storage sink for the storage network.
|
||||
* Provide this through an {@link IStorageProvider}.
|
||||
*/
|
||||
public interface IStorage {
|
||||
/**
|
||||
* Adds the items to the storage network.
|
||||
* This is called every 20 ticks or when the storage changes.
|
||||
*
|
||||
* @param items A list of previously added items
|
||||
*/
|
||||
void addItems(List<ItemStack> items);
|
||||
|
||||
/**
|
||||
* Pushes an item to this storage.
|
||||
*
|
||||
* @param stack The stack to push, do NOT modify this stack
|
||||
* @param simulate If we are simulating
|
||||
* @return null if the push was successful, or an ItemStack with the remainder
|
||||
*/
|
||||
ItemStack push(ItemStack stack, 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 pushing
|
||||
* @param flags The comparison flags, see {@link refinedstorage.RefinedStorageUtils}
|
||||
* @return The ItemStack we took from the system, or null if we didn't take anything
|
||||
* @todo Move the comparison flags to the API package
|
||||
*/
|
||||
ItemStack take(ItemStack stack, int size, int flags);
|
||||
|
||||
/**
|
||||
* @return The amount of items stored in this storage
|
||||
*/
|
||||
int getStored();
|
||||
|
||||
/**
|
||||
* @return The priority of this storage
|
||||
*/
|
||||
int getPriority();
|
||||
}
|
||||
@@ -1,7 +1,5 @@
|
||||
package refinedstorage.api.storage;
|
||||
|
||||
import refinedstorage.storage.IStorage;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package refinedstorage.storage;
|
||||
package refinedstorage.api.storage;
|
||||
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -10,6 +10,9 @@ import refinedstorage.RefinedStorageUtils;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A implementation of {@link IStorage} that stores storage items in NBT.
|
||||
*/
|
||||
public abstract class NBTStorage implements IStorage {
|
||||
public static final String NBT_ITEMS = "Items";
|
||||
public static final String NBT_STORED = "Stored";
|
||||
@@ -18,7 +21,6 @@ public abstract class NBTStorage implements IStorage {
|
||||
public static final String NBT_ITEM_QUANTITY = "Quantity";
|
||||
public static final String NBT_ITEM_DAMAGE = "Damage";
|
||||
public static final String NBT_ITEM_NBT = "NBT";
|
||||
public static final String NBT_CAPS = "Caps";
|
||||
|
||||
private NBTTagCompound tag;
|
||||
private int capacity;
|
||||
@@ -80,22 +82,64 @@ public abstract class NBTStorage implements IStorage {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void push(ItemStack stack) {
|
||||
tag.setInteger(NBT_STORED, getStored() + stack.stackSize);
|
||||
|
||||
public ItemStack push(ItemStack stack, boolean simulate) {
|
||||
for (ItemStack s : stacks) {
|
||||
if (RefinedStorageUtils.compareStackNoQuantity(s, stack)) {
|
||||
s.stackSize += stack.stackSize;
|
||||
if (!simulate) {
|
||||
markDirty();
|
||||
}
|
||||
|
||||
markDirty();
|
||||
if (getStored() + stack.stackSize > getCapacity()) {
|
||||
int overflow = getCapacity() - s.stackSize;
|
||||
|
||||
return;
|
||||
if (overflow == 0) {
|
||||
return stack;
|
||||
}
|
||||
|
||||
if (!simulate) {
|
||||
tag.setInteger(NBT_STORED, getStored() + overflow);
|
||||
|
||||
s.stackSize += overflow;
|
||||
}
|
||||
|
||||
return ItemHandlerHelper.copyStackWithSize(s, stack.stackSize - overflow);
|
||||
} else {
|
||||
if (!simulate) {
|
||||
tag.setInteger(NBT_STORED, getStored() + stack.stackSize);
|
||||
|
||||
s.stackSize += stack.stackSize;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stacks.add(stack.copy());
|
||||
if (!simulate) {
|
||||
markDirty();
|
||||
}
|
||||
|
||||
markDirty();
|
||||
if (getStored() + stack.stackSize > getCapacity()) {
|
||||
int overflow = getCapacity() - stack.stackSize;
|
||||
|
||||
if (overflow == 0) {
|
||||
return stack;
|
||||
}
|
||||
|
||||
if (!simulate) {
|
||||
tag.setInteger(NBT_STORED, getStored() + overflow);
|
||||
|
||||
stacks.add(ItemHandlerHelper.copyStackWithSize(stack, overflow));
|
||||
}
|
||||
|
||||
return ItemHandlerHelper.copyStackWithSize(stack, stack.stackSize - overflow);
|
||||
} else {
|
||||
tag.setInteger(NBT_STORED, getStored() + stack.stackSize);
|
||||
|
||||
stacks.add(stack.copy());
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -123,11 +167,6 @@ public abstract class NBTStorage implements IStorage {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mayPush(ItemStack stack) {
|
||||
return capacity == -1 || (getStored() + stack.stackSize) <= capacity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStored() {
|
||||
return getStoredFromNBT(tag);
|
||||
@@ -89,23 +89,25 @@ public class BasicCraftingTask implements ICraftingTask {
|
||||
return done;
|
||||
}
|
||||
|
||||
// @todo: handle no space
|
||||
@Override
|
||||
public void onDone(TileController controller) {
|
||||
for (ItemStack output : pattern.getOutputs()) {
|
||||
controller.push(output);
|
||||
controller.push(output, false);
|
||||
}
|
||||
|
||||
if (pattern.getByproducts() != null) {
|
||||
for (ItemStack byproduct : pattern.getByproducts()) {
|
||||
controller.push(byproduct);
|
||||
controller.push(byproduct, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// @todo: handle no space
|
||||
@Override
|
||||
public void onCancelled(TileController controller) {
|
||||
for (ItemStack took : itemsTook) {
|
||||
controller.push(took);
|
||||
controller.push(took, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ public class ProcessingCraftingTask implements ICraftingTask {
|
||||
|
||||
inserted[i] = true;
|
||||
} else {
|
||||
controller.push(took);
|
||||
controller.push(took, false);
|
||||
}
|
||||
} else if (!childTasks[i]) {
|
||||
CraftingPattern pattern = controller.getPattern(input);
|
||||
|
||||
@@ -11,8 +11,8 @@ import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.world.World;
|
||||
import refinedstorage.RefinedStorageBlocks;
|
||||
import refinedstorage.RefinedStorageItems;
|
||||
import refinedstorage.api.storage.NBTStorage;
|
||||
import refinedstorage.block.EnumStorageType;
|
||||
import refinedstorage.storage.NBTStorage;
|
||||
import refinedstorage.tile.TileStorage;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -11,8 +11,8 @@ import net.minecraft.util.EnumActionResult;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.world.World;
|
||||
import refinedstorage.RefinedStorageItems;
|
||||
import refinedstorage.api.storage.NBTStorage;
|
||||
import refinedstorage.block.EnumStorageType;
|
||||
import refinedstorage.storage.NBTStorage;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import refinedstorage.RefinedStorageBlocks;
|
||||
import refinedstorage.RefinedStorageItems;
|
||||
import refinedstorage.storage.DiskStorage;
|
||||
import refinedstorage.api.storage.NBTStorage;
|
||||
import refinedstorage.tile.TileStorage;
|
||||
|
||||
@JEIPlugin
|
||||
@@ -31,7 +31,7 @@ public class RefinedStorageJEIPlugin implements IModPlugin {
|
||||
|
||||
registry.addRecipeCategoryCraftingItem(new ItemStack(RefinedStorageBlocks.SOLDERER), SoldererRecipeCategory.ID);
|
||||
|
||||
registry.getJeiHelpers().getNbtIgnoreList().ignoreNbtTagNames(RefinedStorageItems.STORAGE_DISK, DiskStorage.NBT_ITEMS, DiskStorage.NBT_STORED);
|
||||
registry.getJeiHelpers().getNbtIgnoreList().ignoreNbtTagNames(RefinedStorageItems.STORAGE_DISK, NBTStorage.NBT_ITEMS, NBTStorage.NBT_STORED);
|
||||
registry.getJeiHelpers().getNbtIgnoreList().ignoreNbtTagNames(Item.getItemFromBlock(RefinedStorageBlocks.STORAGE), TileStorage.NBT_STORAGE);
|
||||
}
|
||||
|
||||
|
||||
@@ -50,9 +50,7 @@ public class MessageGridCraftingClear extends MessageHandlerPlayerToServer<Messa
|
||||
ItemStack slot = grid.getMatrix().getStackInSlot(i);
|
||||
|
||||
if (slot != null) {
|
||||
if (grid.getController().push(slot)) {
|
||||
grid.getMatrix().setInventorySlotContents(i, null);
|
||||
}
|
||||
grid.getMatrix().setInventorySlotContents(i, grid.getController().push(slot, false));
|
||||
}
|
||||
}
|
||||
} else if (grid.getType() == EnumGridType.PATTERN) {
|
||||
|
||||
@@ -52,9 +52,7 @@ public class MessageGridCraftingPush extends MessageHandlerPlayerToServer<Messag
|
||||
ItemStack stack = grid.getMatrix().getStackInSlot(message.craftingSlot);
|
||||
|
||||
if (stack != null) {
|
||||
if (grid.getController().push(stack)) {
|
||||
grid.getMatrix().setInventorySlotContents(message.craftingSlot, null);
|
||||
}
|
||||
grid.getMatrix().setInventorySlotContents(message.craftingSlot, grid.getController().push(stack, false));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ import refinedstorage.RefinedStorageBlocks;
|
||||
import refinedstorage.RefinedStorageItems;
|
||||
import refinedstorage.api.solderer.SoldererRecipeBasic;
|
||||
import refinedstorage.api.solderer.SoldererRegistry;
|
||||
import refinedstorage.api.storage.NBTStorage;
|
||||
import refinedstorage.block.BlockBase;
|
||||
import refinedstorage.block.EnumControllerType;
|
||||
import refinedstorage.block.EnumGridType;
|
||||
@@ -29,7 +30,6 @@ import refinedstorage.solderer.SoldererRecipePrintedProcessor;
|
||||
import refinedstorage.solderer.SoldererRecipeProcessor;
|
||||
import refinedstorage.solderer.SoldererRecipeStorage;
|
||||
import refinedstorage.solderer.SoldererRecipeUpgrade;
|
||||
import refinedstorage.storage.NBTStorage;
|
||||
import refinedstorage.tile.*;
|
||||
import refinedstorage.tile.controller.TileController;
|
||||
import refinedstorage.tile.grid.TileGrid;
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
package refinedstorage.storage;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import refinedstorage.block.EnumStorageType;
|
||||
import refinedstorage.tile.TileDiskDrive;
|
||||
import refinedstorage.tile.config.ModeFilter;
|
||||
|
||||
public class DiskStorage extends NBTStorage {
|
||||
private TileDiskDrive diskDrive;
|
||||
|
||||
public DiskStorage(ItemStack disk, TileDiskDrive diskDrive) {
|
||||
super(disk.getTagCompound(), EnumStorageType.getById(disk.getItemDamage()).getCapacity());
|
||||
|
||||
this.diskDrive = diskDrive;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPriority() {
|
||||
return diskDrive.getPriority();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mayPush(ItemStack stack) {
|
||||
return ModeFilter.respectsMode(diskDrive.getFilters(), diskDrive.getModeConfig(), diskDrive.getCompare(), stack) && super.mayPush(stack);
|
||||
}
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
package refinedstorage.storage;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface IStorage {
|
||||
void addItems(List<ItemStack> items);
|
||||
|
||||
void push(ItemStack stack);
|
||||
|
||||
ItemStack take(ItemStack stack, int size, int flags);
|
||||
|
||||
boolean mayPush(ItemStack stack);
|
||||
|
||||
int getStored();
|
||||
|
||||
int getPriority();
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
package refinedstorage.storage;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import refinedstorage.tile.TileStorage;
|
||||
import refinedstorage.tile.config.ModeFilter;
|
||||
|
||||
public class StorageBlockStorage extends NBTStorage {
|
||||
private TileStorage storage;
|
||||
|
||||
public StorageBlockStorage(TileStorage storage) {
|
||||
super(storage.getStorageTag(), storage.getCapacity());
|
||||
|
||||
this.storage = storage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPriority() {
|
||||
return storage.getPriority();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mayPush(ItemStack stack) {
|
||||
return ModeFilter.respectsMode(storage.getFilters(), storage, storage.getCompare(), stack) && super.mayPush(stack);
|
||||
}
|
||||
}
|
||||
@@ -64,8 +64,14 @@ public class TileDestructor extends TileMachine implements ICompareConfig, IMode
|
||||
for (ItemStack drop : drops) {
|
||||
// We check if the controller isn't null here because when a destructor faces a machine block and removes it
|
||||
// it will essentially remove this block itself from the network without knowing
|
||||
if (controller == null || !controller.push(drop)) {
|
||||
if (controller == null) {
|
||||
InventoryHelper.spawnItemStack(worldObj, front.getX(), front.getY(), front.getZ(), drop);
|
||||
} else {
|
||||
ItemStack remainder = controller.push(drop, false);
|
||||
|
||||
if (remainder != null) {
|
||||
InventoryHelper.spawnItemStack(worldObj, front.getX(), front.getY(), front.getZ(), remainder);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,24 +12,40 @@ import refinedstorage.RefinedStorage;
|
||||
import refinedstorage.RefinedStorageItems;
|
||||
import refinedstorage.RefinedStorageUtils;
|
||||
import refinedstorage.api.RefinedStorageCapabilities;
|
||||
import refinedstorage.api.storage.IStorage;
|
||||
import refinedstorage.api.storage.IStorageProvider;
|
||||
import refinedstorage.api.storage.NBTStorage;
|
||||
import refinedstorage.block.EnumStorageType;
|
||||
import refinedstorage.container.ContainerDiskDrive;
|
||||
import refinedstorage.inventory.BasicItemHandler;
|
||||
import refinedstorage.inventory.BasicItemValidator;
|
||||
import refinedstorage.network.MessagePriorityUpdate;
|
||||
import refinedstorage.storage.DiskStorage;
|
||||
import refinedstorage.storage.IStorage;
|
||||
import refinedstorage.storage.IStorageGui;
|
||||
import refinedstorage.storage.NBTStorage;
|
||||
import refinedstorage.tile.config.ICompareConfig;
|
||||
import refinedstorage.tile.config.IModeConfig;
|
||||
import refinedstorage.tile.config.IRedstoneModeConfig;
|
||||
import refinedstorage.tile.config.ModeConstants;
|
||||
import refinedstorage.tile.config.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class TileDiskDrive extends TileMachine implements IStorageProvider, IStorageGui, ICompareConfig, IModeConfig {
|
||||
public class DiskStorage extends NBTStorage {
|
||||
public DiskStorage(ItemStack disk) {
|
||||
super(disk.getTagCompound(), EnumStorageType.getById(disk.getItemDamage()).getCapacity());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPriority() {
|
||||
return TileDiskDrive.this.getPriority();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack push(ItemStack stack, boolean simulate) {
|
||||
if (!ModeFilter.respectsMode(getFilters(), getModeConfig(), getCompare(), stack)) {
|
||||
return stack;
|
||||
}
|
||||
|
||||
return super.push(stack, simulate);
|
||||
}
|
||||
}
|
||||
|
||||
public static final String NBT_PRIORITY = "Priority";
|
||||
public static final String NBT_COMPARE = "Compare";
|
||||
public static final String NBT_MODE = "Mode";
|
||||
@@ -47,7 +63,7 @@ public class TileDiskDrive extends TileMachine implements IStorageProvider, ISto
|
||||
if (disks.getStackInSlot(slot) == null) {
|
||||
storages[slot] = null;
|
||||
} else if (storages[slot] == null) {
|
||||
storages[slot] = new DiskStorage(disks.getStackInSlot(slot), this);
|
||||
storages[slot] = new DiskStorage(disks.getStackInSlot(slot));
|
||||
}
|
||||
|
||||
return storages[slot];
|
||||
|
||||
@@ -61,7 +61,7 @@ public class TileExporter extends TileMachine implements ICompareConfig {
|
||||
return;
|
||||
}
|
||||
|
||||
controller.push(took);
|
||||
controller.push(took, false);
|
||||
} else if (RefinedStorageUtils.hasUpgrade(upgrades, ItemUpgrade.TYPE_CRAFTING)) {
|
||||
if (scheduler.canSchedule(compare, slot)) {
|
||||
scheduler.schedule(controller, compare, slot);
|
||||
|
||||
@@ -12,13 +12,16 @@ import powercrystals.minefactoryreloaded.api.IDeepStorageUnit;
|
||||
import refinedstorage.RefinedStorage;
|
||||
import refinedstorage.RefinedStorageUtils;
|
||||
import refinedstorage.api.RefinedStorageCapabilities;
|
||||
import refinedstorage.api.storage.IStorage;
|
||||
import refinedstorage.api.storage.IStorageProvider;
|
||||
import refinedstorage.container.ContainerStorage;
|
||||
import refinedstorage.inventory.BasicItemHandler;
|
||||
import refinedstorage.network.MessagePriorityUpdate;
|
||||
import refinedstorage.storage.IStorage;
|
||||
import refinedstorage.storage.IStorageGui;
|
||||
import refinedstorage.tile.config.*;
|
||||
import refinedstorage.tile.config.ICompareConfig;
|
||||
import refinedstorage.tile.config.IModeConfig;
|
||||
import refinedstorage.tile.config.IRedstoneModeConfig;
|
||||
import refinedstorage.tile.config.ModeConstants;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -66,9 +69,10 @@ public class TileExternalStorage extends TileMachine implements IStorageProvider
|
||||
}
|
||||
|
||||
@Override
|
||||
public void push(ItemStack stack) {
|
||||
public ItemStack push(ItemStack stack, boolean simulate) {
|
||||
IDeepStorageUnit storageUnit = getStorageUnit();
|
||||
|
||||
// @todo: fix push for deep storage units
|
||||
if (storageUnit != null) {
|
||||
if (storageUnit.getStoredItemType() == null) {
|
||||
storageUnit.setStoredItemType(stack.copy(), stack.stackSize);
|
||||
@@ -79,9 +83,11 @@ public class TileExternalStorage extends TileMachine implements IStorageProvider
|
||||
IItemHandler handler = getItemHandler();
|
||||
|
||||
if (handler != null) {
|
||||
ItemHandlerHelper.insertItem(handler, stack.copy(), false);
|
||||
return ItemHandlerHelper.insertItem(handler, stack.copy(), simulate);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -121,6 +127,7 @@ public class TileExternalStorage extends TileMachine implements IStorageProvider
|
||||
return null;
|
||||
}
|
||||
|
||||
/*
|
||||
@Override
|
||||
public boolean mayPush(ItemStack stack) {
|
||||
if (ModeFilter.respectsMode(filters, this, compare, stack)) {
|
||||
@@ -143,6 +150,7 @@ public class TileExternalStorage extends TileMachine implements IStorageProvider
|
||||
|
||||
return false;
|
||||
}
|
||||
*/
|
||||
|
||||
public IDeepStorageUnit getStorageUnit() {
|
||||
return getFacingTile() instanceof IDeepStorageUnit ? (IDeepStorageUnit) getFacingTile() : null;
|
||||
|
||||
@@ -63,7 +63,9 @@ public class TileImporter extends TileMachine implements ICompareConfig, IModeCo
|
||||
|
||||
ItemStack result = handler.extractItem(currentSlot, quantity, true);
|
||||
|
||||
if (result != null && controller.push(result)) {
|
||||
if (result != null && controller.push(result, true) == null) {
|
||||
controller.push(result, false);
|
||||
|
||||
handler.extractItem(currentSlot, quantity, false);
|
||||
} else {
|
||||
currentSlot++;
|
||||
|
||||
@@ -47,9 +47,7 @@ public class TileInterface extends TileMachine implements ICompareConfig {
|
||||
currentSlot++;
|
||||
} else {
|
||||
if (ticks % RefinedStorageUtils.getSpeed(upgrades) == 0) {
|
||||
if (controller.push(ItemHandlerHelper.copyStackWithSize(slot, 1))) {
|
||||
importItems.extractItem(currentSlot, 1, false);
|
||||
}
|
||||
importItems.setStackInSlot(currentSlot, controller.push(ItemHandlerHelper.copyStackWithSize(slot, 1), false));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,9 +60,7 @@ public class TileInterface extends TileMachine implements ICompareConfig {
|
||||
|
||||
if (got != null) {
|
||||
if (!RefinedStorageUtils.compareStack(wanted, got, compare)) {
|
||||
if (controller.push(got)) {
|
||||
exportItems.setStackInSlot(i, null);
|
||||
}
|
||||
exportItems.setStackInSlot(i, controller.push(got, false));
|
||||
} else {
|
||||
mayTake = true;
|
||||
}
|
||||
@@ -90,9 +86,7 @@ public class TileInterface extends TileMachine implements ICompareConfig {
|
||||
}
|
||||
}
|
||||
} else if (got != null) {
|
||||
if (controller.push(got)) {
|
||||
exportItems.setStackInSlot(i, null);
|
||||
}
|
||||
exportItems.setStackInSlot(i, controller.push(got, false));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package refinedstorage.tile;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
@@ -10,24 +11,40 @@ import refinedstorage.RefinedStorage;
|
||||
import refinedstorage.RefinedStorageBlocks;
|
||||
import refinedstorage.RefinedStorageUtils;
|
||||
import refinedstorage.api.RefinedStorageCapabilities;
|
||||
import refinedstorage.api.storage.IStorage;
|
||||
import refinedstorage.api.storage.IStorageProvider;
|
||||
import refinedstorage.api.storage.NBTStorage;
|
||||
import refinedstorage.block.BlockStorage;
|
||||
import refinedstorage.block.EnumStorageType;
|
||||
import refinedstorage.container.ContainerStorage;
|
||||
import refinedstorage.inventory.BasicItemHandler;
|
||||
import refinedstorage.network.MessagePriorityUpdate;
|
||||
import refinedstorage.storage.IStorage;
|
||||
import refinedstorage.storage.IStorageGui;
|
||||
import refinedstorage.storage.NBTStorage;
|
||||
import refinedstorage.storage.StorageBlockStorage;
|
||||
import refinedstorage.tile.config.ICompareConfig;
|
||||
import refinedstorage.tile.config.IModeConfig;
|
||||
import refinedstorage.tile.config.IRedstoneModeConfig;
|
||||
import refinedstorage.tile.config.ModeConstants;
|
||||
import refinedstorage.tile.config.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class TileStorage extends TileMachine implements IStorageProvider, IStorageGui, ICompareConfig, IModeConfig {
|
||||
class StorageBlockStorage extends NBTStorage {
|
||||
public StorageBlockStorage() {
|
||||
super(TileStorage.this.getStorageTag(), TileStorage.this.getCapacity());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPriority() {
|
||||
return storage.getPriority();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack push(ItemStack stack, boolean simulate) {
|
||||
if (!ModeFilter.respectsMode(filters, TileStorage.this, compare, stack)) {
|
||||
return stack;
|
||||
}
|
||||
|
||||
return super.push(stack, simulate);
|
||||
}
|
||||
}
|
||||
|
||||
public static final String NBT_STORAGE = "Storage";
|
||||
public static final String NBT_PRIORITY = "Priority";
|
||||
public static final String NBT_COMPARE = "Compare";
|
||||
@@ -54,7 +71,7 @@ public class TileStorage extends TileMachine implements IStorageProvider, IStora
|
||||
@Override
|
||||
public void updateMachine() {
|
||||
if (storage == null && storageTag != null) {
|
||||
storage = new StorageBlockStorage(this);
|
||||
storage = new StorageBlockStorage();
|
||||
}
|
||||
|
||||
if (storage != null && storage.isDirty()) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package refinedstorage.tile.controller;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.inventory.InventoryHelper;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import refinedstorage.RefinedStorageUtils;
|
||||
import refinedstorage.autocrafting.CraftingPattern;
|
||||
@@ -49,7 +50,7 @@ public class StorageHandler {
|
||||
if (took != null) {
|
||||
if (GridPullFlags.isPullingWithShift(flags)) {
|
||||
if (!player.inventory.addItemStackToInventory(took.copy())) {
|
||||
controller.push(took);
|
||||
InventoryHelper.spawnItemStack(player.worldObj, player.getPosition().getX(), player.getPosition().getY(), player.getPosition().getZ(), took);
|
||||
}
|
||||
} else {
|
||||
player.inventory.setItemStack(took);
|
||||
@@ -74,24 +75,24 @@ public class StorageHandler {
|
||||
}
|
||||
|
||||
if (stack != null) {
|
||||
boolean success = controller.push(stack);
|
||||
if (playerSlot == -1) {
|
||||
if (one) {
|
||||
if (controller.push(stack, true) == null) {
|
||||
controller.push(stack, false);
|
||||
|
||||
if (success) {
|
||||
if (playerSlot == -1) {
|
||||
if (one) {
|
||||
player.inventory.getItemStack().stackSize--;
|
||||
|
||||
if (player.inventory.getItemStack().stackSize == 0) {
|
||||
player.inventory.setItemStack(null);
|
||||
}
|
||||
} else {
|
||||
player.inventory.setItemStack(null);
|
||||
}
|
||||
|
||||
player.updateHeldItem();
|
||||
} else {
|
||||
player.inventory.setInventorySlotContents(playerSlot, null);
|
||||
player.inventory.setItemStack(controller.push(stack, false));
|
||||
}
|
||||
|
||||
player.updateHeldItem();
|
||||
} else {
|
||||
player.inventory.setInventorySlotContents(playerSlot, controller.push(stack, false));
|
||||
}
|
||||
|
||||
controller.getWirelessGridHandler().drainEnergy(player, ItemWirelessGrid.USAGE_PUSH);
|
||||
|
||||
@@ -17,6 +17,7 @@ import refinedstorage.RefinedStorage;
|
||||
import refinedstorage.RefinedStorageBlocks;
|
||||
import refinedstorage.RefinedStorageUtils;
|
||||
import refinedstorage.api.RefinedStorageCapabilities;
|
||||
import refinedstorage.api.storage.IStorage;
|
||||
import refinedstorage.autocrafting.CraftingPattern;
|
||||
import refinedstorage.autocrafting.task.BasicCraftingTask;
|
||||
import refinedstorage.autocrafting.task.ICraftingTask;
|
||||
@@ -27,7 +28,6 @@ import refinedstorage.container.ContainerController;
|
||||
import refinedstorage.container.ContainerGrid;
|
||||
import refinedstorage.item.ItemPattern;
|
||||
import refinedstorage.network.MessageGridItems;
|
||||
import refinedstorage.storage.IStorage;
|
||||
import refinedstorage.tile.*;
|
||||
import refinedstorage.tile.config.IRedstoneModeConfig;
|
||||
import refinedstorage.tile.config.RedstoneMode;
|
||||
@@ -367,29 +367,39 @@ public class TileController extends TileBase implements IEnergyReceiver, ISynchr
|
||||
RefinedStorage.NETWORK.sendTo(new MessageGridItems(this), player);
|
||||
}
|
||||
|
||||
public boolean push(ItemStack stack) {
|
||||
public ItemStack push(ItemStack stack, boolean simulate) {
|
||||
ItemStack remainder = stack;
|
||||
|
||||
for (IStorage storage : storages) {
|
||||
if (storage.mayPush(stack)) {
|
||||
storage.push(stack);
|
||||
remainder = storage.push(remainder, simulate);
|
||||
|
||||
syncItems();
|
||||
syncItemsWithClients();
|
||||
|
||||
for (int i = 0; i < stack.stackSize; ++i) {
|
||||
if (!craftingTasks.empty()) {
|
||||
ICraftingTask top = craftingTasks.peek();
|
||||
|
||||
if (top instanceof ProcessingCraftingTask) {
|
||||
((ProcessingCraftingTask) top).onPushed(stack);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
if (remainder == null) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
if (!simulate) {
|
||||
syncItems();
|
||||
syncItemsWithClients();
|
||||
|
||||
int sizePushed = stack.stackSize;
|
||||
|
||||
if (remainder != null) {
|
||||
sizePushed = stack.stackSize - remainder.stackSize;
|
||||
}
|
||||
|
||||
for (int i = 0; i < sizePushed; ++i) {
|
||||
if (!craftingTasks.empty()) {
|
||||
ICraftingTask top = craftingTasks.peek();
|
||||
|
||||
if (top instanceof ProcessingCraftingTask) {
|
||||
((ProcessingCraftingTask) top).onPushed(stack);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return remainder;
|
||||
}
|
||||
|
||||
public ItemStack take(ItemStack stack, int size) {
|
||||
|
||||
@@ -182,11 +182,7 @@ public class TileGrid extends TileMachine implements IGrid {
|
||||
|
||||
for (ItemStack craftedItem : craftedItemsList) {
|
||||
if (!player.inventory.addItemStackToInventory(craftedItem.copy())) {
|
||||
if (controller != null && controller.push(craftedItem)) {
|
||||
// NO OP
|
||||
} else {
|
||||
InventoryHelper.spawnItemStack(player.worldObj, player.getPosition().getX(), player.getPosition().getY(), player.getPosition().getZ(), craftedItem);
|
||||
}
|
||||
InventoryHelper.spawnItemStack(player.worldObj, player.getPosition().getX(), player.getPosition().getY(), player.getPosition().getZ(), craftedItem);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -232,8 +228,10 @@ public class TileGrid extends TileMachine implements IGrid {
|
||||
|
||||
if (slot != null) {
|
||||
if (getType() == EnumGridType.CRAFTING) {
|
||||
if (!controller.push(slot)) {
|
||||
if (controller.push(slot, true) != null) {
|
||||
return;
|
||||
} else {
|
||||
controller.push(slot, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user