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;
|
package refinedstorage.api.storage;
|
||||||
|
|
||||||
import refinedstorage.storage.IStorage;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package refinedstorage.storage;
|
package refinedstorage.api.storage;
|
||||||
|
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
@@ -10,6 +10,9 @@ import refinedstorage.RefinedStorageUtils;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A implementation of {@link IStorage} that stores storage items in NBT.
|
||||||
|
*/
|
||||||
public abstract class NBTStorage implements IStorage {
|
public abstract class NBTStorage implements IStorage {
|
||||||
public static final String NBT_ITEMS = "Items";
|
public static final String NBT_ITEMS = "Items";
|
||||||
public static final String NBT_STORED = "Stored";
|
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_QUANTITY = "Quantity";
|
||||||
public static final String NBT_ITEM_DAMAGE = "Damage";
|
public static final String NBT_ITEM_DAMAGE = "Damage";
|
||||||
public static final String NBT_ITEM_NBT = "NBT";
|
public static final String NBT_ITEM_NBT = "NBT";
|
||||||
public static final String NBT_CAPS = "Caps";
|
|
||||||
|
|
||||||
private NBTTagCompound tag;
|
private NBTTagCompound tag;
|
||||||
private int capacity;
|
private int capacity;
|
||||||
@@ -80,22 +82,64 @@ public abstract class NBTStorage implements IStorage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void push(ItemStack stack) {
|
public ItemStack push(ItemStack stack, boolean simulate) {
|
||||||
tag.setInteger(NBT_STORED, getStored() + stack.stackSize);
|
|
||||||
|
|
||||||
for (ItemStack s : stacks) {
|
for (ItemStack s : stacks) {
|
||||||
if (RefinedStorageUtils.compareStackNoQuantity(s, stack)) {
|
if (RefinedStorageUtils.compareStackNoQuantity(s, stack)) {
|
||||||
s.stackSize += stack.stackSize;
|
if (!simulate) {
|
||||||
|
|
||||||
markDirty();
|
markDirty();
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
if (getStored() + stack.stackSize > getCapacity()) {
|
||||||
|
int overflow = getCapacity() - s.stackSize;
|
||||||
|
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!simulate) {
|
||||||
|
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());
|
stacks.add(stack.copy());
|
||||||
|
|
||||||
markDirty();
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -123,11 +167,6 @@ public abstract class NBTStorage implements IStorage {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean mayPush(ItemStack stack) {
|
|
||||||
return capacity == -1 || (getStored() + stack.stackSize) <= capacity;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getStored() {
|
public int getStored() {
|
||||||
return getStoredFromNBT(tag);
|
return getStoredFromNBT(tag);
|
||||||
@@ -89,23 +89,25 @@ public class BasicCraftingTask implements ICraftingTask {
|
|||||||
return done;
|
return done;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @todo: handle no space
|
||||||
@Override
|
@Override
|
||||||
public void onDone(TileController controller) {
|
public void onDone(TileController controller) {
|
||||||
for (ItemStack output : pattern.getOutputs()) {
|
for (ItemStack output : pattern.getOutputs()) {
|
||||||
controller.push(output);
|
controller.push(output, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pattern.getByproducts() != null) {
|
if (pattern.getByproducts() != null) {
|
||||||
for (ItemStack byproduct : pattern.getByproducts()) {
|
for (ItemStack byproduct : pattern.getByproducts()) {
|
||||||
controller.push(byproduct);
|
controller.push(byproduct, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @todo: handle no space
|
||||||
@Override
|
@Override
|
||||||
public void onCancelled(TileController controller) {
|
public void onCancelled(TileController controller) {
|
||||||
for (ItemStack took : itemsTook) {
|
for (ItemStack took : itemsTook) {
|
||||||
controller.push(took);
|
controller.push(took, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ public class ProcessingCraftingTask implements ICraftingTask {
|
|||||||
|
|
||||||
inserted[i] = true;
|
inserted[i] = true;
|
||||||
} else {
|
} else {
|
||||||
controller.push(took);
|
controller.push(took, false);
|
||||||
}
|
}
|
||||||
} else if (!childTasks[i]) {
|
} else if (!childTasks[i]) {
|
||||||
CraftingPattern pattern = controller.getPattern(input);
|
CraftingPattern pattern = controller.getPattern(input);
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ import net.minecraft.util.EnumHand;
|
|||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import refinedstorage.RefinedStorageBlocks;
|
import refinedstorage.RefinedStorageBlocks;
|
||||||
import refinedstorage.RefinedStorageItems;
|
import refinedstorage.RefinedStorageItems;
|
||||||
|
import refinedstorage.api.storage.NBTStorage;
|
||||||
import refinedstorage.block.EnumStorageType;
|
import refinedstorage.block.EnumStorageType;
|
||||||
import refinedstorage.storage.NBTStorage;
|
|
||||||
import refinedstorage.tile.TileStorage;
|
import refinedstorage.tile.TileStorage;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ import net.minecraft.util.EnumActionResult;
|
|||||||
import net.minecraft.util.EnumHand;
|
import net.minecraft.util.EnumHand;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import refinedstorage.RefinedStorageItems;
|
import refinedstorage.RefinedStorageItems;
|
||||||
|
import refinedstorage.api.storage.NBTStorage;
|
||||||
import refinedstorage.block.EnumStorageType;
|
import refinedstorage.block.EnumStorageType;
|
||||||
import refinedstorage.storage.NBTStorage;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import net.minecraft.item.Item;
|
|||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import refinedstorage.RefinedStorageBlocks;
|
import refinedstorage.RefinedStorageBlocks;
|
||||||
import refinedstorage.RefinedStorageItems;
|
import refinedstorage.RefinedStorageItems;
|
||||||
import refinedstorage.storage.DiskStorage;
|
import refinedstorage.api.storage.NBTStorage;
|
||||||
import refinedstorage.tile.TileStorage;
|
import refinedstorage.tile.TileStorage;
|
||||||
|
|
||||||
@JEIPlugin
|
@JEIPlugin
|
||||||
@@ -31,7 +31,7 @@ public class RefinedStorageJEIPlugin implements IModPlugin {
|
|||||||
|
|
||||||
registry.addRecipeCategoryCraftingItem(new ItemStack(RefinedStorageBlocks.SOLDERER), SoldererRecipeCategory.ID);
|
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);
|
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);
|
ItemStack slot = grid.getMatrix().getStackInSlot(i);
|
||||||
|
|
||||||
if (slot != null) {
|
if (slot != null) {
|
||||||
if (grid.getController().push(slot)) {
|
grid.getMatrix().setInventorySlotContents(i, grid.getController().push(slot, false));
|
||||||
grid.getMatrix().setInventorySlotContents(i, null);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (grid.getType() == EnumGridType.PATTERN) {
|
} else if (grid.getType() == EnumGridType.PATTERN) {
|
||||||
|
|||||||
@@ -52,9 +52,7 @@ public class MessageGridCraftingPush extends MessageHandlerPlayerToServer<Messag
|
|||||||
ItemStack stack = grid.getMatrix().getStackInSlot(message.craftingSlot);
|
ItemStack stack = grid.getMatrix().getStackInSlot(message.craftingSlot);
|
||||||
|
|
||||||
if (stack != null) {
|
if (stack != null) {
|
||||||
if (grid.getController().push(stack)) {
|
grid.getMatrix().setInventorySlotContents(message.craftingSlot, grid.getController().push(stack, false));
|
||||||
grid.getMatrix().setInventorySlotContents(message.craftingSlot, null);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import refinedstorage.RefinedStorageBlocks;
|
|||||||
import refinedstorage.RefinedStorageItems;
|
import refinedstorage.RefinedStorageItems;
|
||||||
import refinedstorage.api.solderer.SoldererRecipeBasic;
|
import refinedstorage.api.solderer.SoldererRecipeBasic;
|
||||||
import refinedstorage.api.solderer.SoldererRegistry;
|
import refinedstorage.api.solderer.SoldererRegistry;
|
||||||
|
import refinedstorage.api.storage.NBTStorage;
|
||||||
import refinedstorage.block.BlockBase;
|
import refinedstorage.block.BlockBase;
|
||||||
import refinedstorage.block.EnumControllerType;
|
import refinedstorage.block.EnumControllerType;
|
||||||
import refinedstorage.block.EnumGridType;
|
import refinedstorage.block.EnumGridType;
|
||||||
@@ -29,7 +30,6 @@ import refinedstorage.solderer.SoldererRecipePrintedProcessor;
|
|||||||
import refinedstorage.solderer.SoldererRecipeProcessor;
|
import refinedstorage.solderer.SoldererRecipeProcessor;
|
||||||
import refinedstorage.solderer.SoldererRecipeStorage;
|
import refinedstorage.solderer.SoldererRecipeStorage;
|
||||||
import refinedstorage.solderer.SoldererRecipeUpgrade;
|
import refinedstorage.solderer.SoldererRecipeUpgrade;
|
||||||
import refinedstorage.storage.NBTStorage;
|
|
||||||
import refinedstorage.tile.*;
|
import refinedstorage.tile.*;
|
||||||
import refinedstorage.tile.controller.TileController;
|
import refinedstorage.tile.controller.TileController;
|
||||||
import refinedstorage.tile.grid.TileGrid;
|
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) {
|
for (ItemStack drop : drops) {
|
||||||
// We check if the controller isn't null here because when a destructor faces a machine block and removes it
|
// 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
|
// 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);
|
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.RefinedStorageItems;
|
||||||
import refinedstorage.RefinedStorageUtils;
|
import refinedstorage.RefinedStorageUtils;
|
||||||
import refinedstorage.api.RefinedStorageCapabilities;
|
import refinedstorage.api.RefinedStorageCapabilities;
|
||||||
|
import refinedstorage.api.storage.IStorage;
|
||||||
import refinedstorage.api.storage.IStorageProvider;
|
import refinedstorage.api.storage.IStorageProvider;
|
||||||
|
import refinedstorage.api.storage.NBTStorage;
|
||||||
import refinedstorage.block.EnumStorageType;
|
import refinedstorage.block.EnumStorageType;
|
||||||
import refinedstorage.container.ContainerDiskDrive;
|
import refinedstorage.container.ContainerDiskDrive;
|
||||||
import refinedstorage.inventory.BasicItemHandler;
|
import refinedstorage.inventory.BasicItemHandler;
|
||||||
import refinedstorage.inventory.BasicItemValidator;
|
import refinedstorage.inventory.BasicItemValidator;
|
||||||
import refinedstorage.network.MessagePriorityUpdate;
|
import refinedstorage.network.MessagePriorityUpdate;
|
||||||
import refinedstorage.storage.DiskStorage;
|
|
||||||
import refinedstorage.storage.IStorage;
|
|
||||||
import refinedstorage.storage.IStorageGui;
|
import refinedstorage.storage.IStorageGui;
|
||||||
import refinedstorage.storage.NBTStorage;
|
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;
|
import java.util.List;
|
||||||
|
|
||||||
public class TileDiskDrive extends TileMachine implements IStorageProvider, IStorageGui, ICompareConfig, IModeConfig {
|
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_PRIORITY = "Priority";
|
||||||
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";
|
||||||
@@ -47,7 +63,7 @@ public class TileDiskDrive extends TileMachine implements IStorageProvider, ISto
|
|||||||
if (disks.getStackInSlot(slot) == null) {
|
if (disks.getStackInSlot(slot) == null) {
|
||||||
storages[slot] = null;
|
storages[slot] = null;
|
||||||
} else if (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];
|
return storages[slot];
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ public class TileExporter extends TileMachine implements ICompareConfig {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
controller.push(took);
|
controller.push(took, false);
|
||||||
} else if (RefinedStorageUtils.hasUpgrade(upgrades, ItemUpgrade.TYPE_CRAFTING)) {
|
} else if (RefinedStorageUtils.hasUpgrade(upgrades, ItemUpgrade.TYPE_CRAFTING)) {
|
||||||
if (scheduler.canSchedule(compare, slot)) {
|
if (scheduler.canSchedule(compare, slot)) {
|
||||||
scheduler.schedule(controller, compare, slot);
|
scheduler.schedule(controller, compare, slot);
|
||||||
|
|||||||
@@ -12,13 +12,16 @@ import powercrystals.minefactoryreloaded.api.IDeepStorageUnit;
|
|||||||
import refinedstorage.RefinedStorage;
|
import refinedstorage.RefinedStorage;
|
||||||
import refinedstorage.RefinedStorageUtils;
|
import refinedstorage.RefinedStorageUtils;
|
||||||
import refinedstorage.api.RefinedStorageCapabilities;
|
import refinedstorage.api.RefinedStorageCapabilities;
|
||||||
|
import refinedstorage.api.storage.IStorage;
|
||||||
import refinedstorage.api.storage.IStorageProvider;
|
import refinedstorage.api.storage.IStorageProvider;
|
||||||
import refinedstorage.container.ContainerStorage;
|
import refinedstorage.container.ContainerStorage;
|
||||||
import refinedstorage.inventory.BasicItemHandler;
|
import refinedstorage.inventory.BasicItemHandler;
|
||||||
import refinedstorage.network.MessagePriorityUpdate;
|
import refinedstorage.network.MessagePriorityUpdate;
|
||||||
import refinedstorage.storage.IStorage;
|
|
||||||
import refinedstorage.storage.IStorageGui;
|
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;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -66,9 +69,10 @@ public class TileExternalStorage extends TileMachine implements IStorageProvider
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void push(ItemStack stack) {
|
public ItemStack push(ItemStack stack, boolean simulate) {
|
||||||
IDeepStorageUnit storageUnit = getStorageUnit();
|
IDeepStorageUnit storageUnit = getStorageUnit();
|
||||||
|
|
||||||
|
// @todo: fix push for deep storage units
|
||||||
if (storageUnit != null) {
|
if (storageUnit != null) {
|
||||||
if (storageUnit.getStoredItemType() == null) {
|
if (storageUnit.getStoredItemType() == null) {
|
||||||
storageUnit.setStoredItemType(stack.copy(), stack.stackSize);
|
storageUnit.setStoredItemType(stack.copy(), stack.stackSize);
|
||||||
@@ -79,9 +83,11 @@ public class TileExternalStorage extends TileMachine implements IStorageProvider
|
|||||||
IItemHandler handler = getItemHandler();
|
IItemHandler handler = getItemHandler();
|
||||||
|
|
||||||
if (handler != null) {
|
if (handler != null) {
|
||||||
ItemHandlerHelper.insertItem(handler, stack.copy(), false);
|
return ItemHandlerHelper.insertItem(handler, stack.copy(), simulate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -121,6 +127,7 @@ public class TileExternalStorage extends TileMachine implements IStorageProvider
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
@Override
|
@Override
|
||||||
public boolean mayPush(ItemStack stack) {
|
public boolean mayPush(ItemStack stack) {
|
||||||
if (ModeFilter.respectsMode(filters, this, compare, stack)) {
|
if (ModeFilter.respectsMode(filters, this, compare, stack)) {
|
||||||
@@ -143,6 +150,7 @@ public class TileExternalStorage extends TileMachine implements IStorageProvider
|
|||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
public IDeepStorageUnit getStorageUnit() {
|
public IDeepStorageUnit getStorageUnit() {
|
||||||
return getFacingTile() instanceof IDeepStorageUnit ? (IDeepStorageUnit) getFacingTile() : null;
|
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);
|
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);
|
handler.extractItem(currentSlot, quantity, false);
|
||||||
} else {
|
} else {
|
||||||
currentSlot++;
|
currentSlot++;
|
||||||
|
|||||||
@@ -47,9 +47,7 @@ public class TileInterface extends TileMachine implements ICompareConfig {
|
|||||||
currentSlot++;
|
currentSlot++;
|
||||||
} else {
|
} else {
|
||||||
if (ticks % RefinedStorageUtils.getSpeed(upgrades) == 0) {
|
if (ticks % RefinedStorageUtils.getSpeed(upgrades) == 0) {
|
||||||
if (controller.push(ItemHandlerHelper.copyStackWithSize(slot, 1))) {
|
importItems.setStackInSlot(currentSlot, controller.push(ItemHandlerHelper.copyStackWithSize(slot, 1), false));
|
||||||
importItems.extractItem(currentSlot, 1, false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,9 +60,7 @@ public class TileInterface extends TileMachine implements ICompareConfig {
|
|||||||
|
|
||||||
if (got != null) {
|
if (got != null) {
|
||||||
if (!RefinedStorageUtils.compareStack(wanted, got, compare)) {
|
if (!RefinedStorageUtils.compareStack(wanted, got, compare)) {
|
||||||
if (controller.push(got)) {
|
exportItems.setStackInSlot(i, controller.push(got, false));
|
||||||
exportItems.setStackInSlot(i, null);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
mayTake = true;
|
mayTake = true;
|
||||||
}
|
}
|
||||||
@@ -90,9 +86,7 @@ public class TileInterface extends TileMachine implements ICompareConfig {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (got != null) {
|
} else if (got != null) {
|
||||||
if (controller.push(got)) {
|
exportItems.setStackInSlot(i, controller.push(got, false));
|
||||||
exportItems.setStackInSlot(i, null);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package refinedstorage.tile;
|
|||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import net.minecraft.inventory.Container;
|
import net.minecraft.inventory.Container;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.util.EnumFacing;
|
import net.minecraft.util.EnumFacing;
|
||||||
import net.minecraftforge.common.capabilities.Capability;
|
import net.minecraftforge.common.capabilities.Capability;
|
||||||
@@ -10,24 +11,40 @@ import refinedstorage.RefinedStorage;
|
|||||||
import refinedstorage.RefinedStorageBlocks;
|
import refinedstorage.RefinedStorageBlocks;
|
||||||
import refinedstorage.RefinedStorageUtils;
|
import refinedstorage.RefinedStorageUtils;
|
||||||
import refinedstorage.api.RefinedStorageCapabilities;
|
import refinedstorage.api.RefinedStorageCapabilities;
|
||||||
|
import refinedstorage.api.storage.IStorage;
|
||||||
import refinedstorage.api.storage.IStorageProvider;
|
import refinedstorage.api.storage.IStorageProvider;
|
||||||
|
import refinedstorage.api.storage.NBTStorage;
|
||||||
import refinedstorage.block.BlockStorage;
|
import refinedstorage.block.BlockStorage;
|
||||||
import refinedstorage.block.EnumStorageType;
|
import refinedstorage.block.EnumStorageType;
|
||||||
import refinedstorage.container.ContainerStorage;
|
import refinedstorage.container.ContainerStorage;
|
||||||
import refinedstorage.inventory.BasicItemHandler;
|
import refinedstorage.inventory.BasicItemHandler;
|
||||||
import refinedstorage.network.MessagePriorityUpdate;
|
import refinedstorage.network.MessagePriorityUpdate;
|
||||||
import refinedstorage.storage.IStorage;
|
|
||||||
import refinedstorage.storage.IStorageGui;
|
import refinedstorage.storage.IStorageGui;
|
||||||
import refinedstorage.storage.NBTStorage;
|
import refinedstorage.tile.config.*;
|
||||||
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 java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class TileStorage extends TileMachine implements IStorageProvider, IStorageGui, ICompareConfig, IModeConfig {
|
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_STORAGE = "Storage";
|
||||||
public static final String NBT_PRIORITY = "Priority";
|
public static final String NBT_PRIORITY = "Priority";
|
||||||
public static final String NBT_COMPARE = "Compare";
|
public static final String NBT_COMPARE = "Compare";
|
||||||
@@ -54,7 +71,7 @@ public class TileStorage extends TileMachine implements IStorageProvider, IStora
|
|||||||
@Override
|
@Override
|
||||||
public void updateMachine() {
|
public void updateMachine() {
|
||||||
if (storage == null && storageTag != null) {
|
if (storage == null && storageTag != null) {
|
||||||
storage = new StorageBlockStorage(this);
|
storage = new StorageBlockStorage();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (storage != null && storage.isDirty()) {
|
if (storage != null && storage.isDirty()) {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package refinedstorage.tile.controller;
|
package refinedstorage.tile.controller;
|
||||||
|
|
||||||
import net.minecraft.entity.player.EntityPlayerMP;
|
import net.minecraft.entity.player.EntityPlayerMP;
|
||||||
|
import net.minecraft.inventory.InventoryHelper;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import refinedstorage.RefinedStorageUtils;
|
import refinedstorage.RefinedStorageUtils;
|
||||||
import refinedstorage.autocrafting.CraftingPattern;
|
import refinedstorage.autocrafting.CraftingPattern;
|
||||||
@@ -49,7 +50,7 @@ public class StorageHandler {
|
|||||||
if (took != null) {
|
if (took != null) {
|
||||||
if (GridPullFlags.isPullingWithShift(flags)) {
|
if (GridPullFlags.isPullingWithShift(flags)) {
|
||||||
if (!player.inventory.addItemStackToInventory(took.copy())) {
|
if (!player.inventory.addItemStackToInventory(took.copy())) {
|
||||||
controller.push(took);
|
InventoryHelper.spawnItemStack(player.worldObj, player.getPosition().getX(), player.getPosition().getY(), player.getPosition().getZ(), took);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
player.inventory.setItemStack(took);
|
player.inventory.setItemStack(took);
|
||||||
@@ -74,24 +75,24 @@ public class StorageHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (stack != null) {
|
if (stack != null) {
|
||||||
boolean success = controller.push(stack);
|
|
||||||
|
|
||||||
if (success) {
|
|
||||||
if (playerSlot == -1) {
|
if (playerSlot == -1) {
|
||||||
if (one) {
|
if (one) {
|
||||||
|
if (controller.push(stack, true) == null) {
|
||||||
|
controller.push(stack, false);
|
||||||
|
|
||||||
player.inventory.getItemStack().stackSize--;
|
player.inventory.getItemStack().stackSize--;
|
||||||
|
|
||||||
if (player.inventory.getItemStack().stackSize == 0) {
|
if (player.inventory.getItemStack().stackSize == 0) {
|
||||||
player.inventory.setItemStack(null);
|
player.inventory.setItemStack(null);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
player.inventory.setItemStack(null);
|
player.inventory.setItemStack(controller.push(stack, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
player.updateHeldItem();
|
player.updateHeldItem();
|
||||||
} else {
|
} else {
|
||||||
player.inventory.setInventorySlotContents(playerSlot, null);
|
player.inventory.setInventorySlotContents(playerSlot, controller.push(stack, false));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
controller.getWirelessGridHandler().drainEnergy(player, ItemWirelessGrid.USAGE_PUSH);
|
controller.getWirelessGridHandler().drainEnergy(player, ItemWirelessGrid.USAGE_PUSH);
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import refinedstorage.RefinedStorage;
|
|||||||
import refinedstorage.RefinedStorageBlocks;
|
import refinedstorage.RefinedStorageBlocks;
|
||||||
import refinedstorage.RefinedStorageUtils;
|
import refinedstorage.RefinedStorageUtils;
|
||||||
import refinedstorage.api.RefinedStorageCapabilities;
|
import refinedstorage.api.RefinedStorageCapabilities;
|
||||||
|
import refinedstorage.api.storage.IStorage;
|
||||||
import refinedstorage.autocrafting.CraftingPattern;
|
import refinedstorage.autocrafting.CraftingPattern;
|
||||||
import refinedstorage.autocrafting.task.BasicCraftingTask;
|
import refinedstorage.autocrafting.task.BasicCraftingTask;
|
||||||
import refinedstorage.autocrafting.task.ICraftingTask;
|
import refinedstorage.autocrafting.task.ICraftingTask;
|
||||||
@@ -27,7 +28,6 @@ import refinedstorage.container.ContainerController;
|
|||||||
import refinedstorage.container.ContainerGrid;
|
import refinedstorage.container.ContainerGrid;
|
||||||
import refinedstorage.item.ItemPattern;
|
import refinedstorage.item.ItemPattern;
|
||||||
import refinedstorage.network.MessageGridItems;
|
import refinedstorage.network.MessageGridItems;
|
||||||
import refinedstorage.storage.IStorage;
|
|
||||||
import refinedstorage.tile.*;
|
import refinedstorage.tile.*;
|
||||||
import refinedstorage.tile.config.IRedstoneModeConfig;
|
import refinedstorage.tile.config.IRedstoneModeConfig;
|
||||||
import refinedstorage.tile.config.RedstoneMode;
|
import refinedstorage.tile.config.RedstoneMode;
|
||||||
@@ -367,15 +367,28 @@ public class TileController extends TileBase implements IEnergyReceiver, ISynchr
|
|||||||
RefinedStorage.NETWORK.sendTo(new MessageGridItems(this), player);
|
RefinedStorage.NETWORK.sendTo(new MessageGridItems(this), player);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean push(ItemStack stack) {
|
public ItemStack push(ItemStack stack, boolean simulate) {
|
||||||
for (IStorage storage : storages) {
|
ItemStack remainder = stack;
|
||||||
if (storage.mayPush(stack)) {
|
|
||||||
storage.push(stack);
|
|
||||||
|
|
||||||
|
for (IStorage storage : storages) {
|
||||||
|
remainder = storage.push(remainder, simulate);
|
||||||
|
|
||||||
|
if (remainder == null) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!simulate) {
|
||||||
syncItems();
|
syncItems();
|
||||||
syncItemsWithClients();
|
syncItemsWithClients();
|
||||||
|
|
||||||
for (int i = 0; i < stack.stackSize; ++i) {
|
int sizePushed = stack.stackSize;
|
||||||
|
|
||||||
|
if (remainder != null) {
|
||||||
|
sizePushed = stack.stackSize - remainder.stackSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < sizePushed; ++i) {
|
||||||
if (!craftingTasks.empty()) {
|
if (!craftingTasks.empty()) {
|
||||||
ICraftingTask top = craftingTasks.peek();
|
ICraftingTask top = craftingTasks.peek();
|
||||||
|
|
||||||
@@ -384,12 +397,9 @@ public class TileController extends TileBase implements IEnergyReceiver, ISynchr
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return remainder;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemStack take(ItemStack stack, int size) {
|
public ItemStack take(ItemStack stack, int size) {
|
||||||
|
|||||||
@@ -182,13 +182,9 @@ public class TileGrid extends TileMachine implements IGrid {
|
|||||||
|
|
||||||
for (ItemStack craftedItem : craftedItemsList) {
|
for (ItemStack craftedItem : craftedItemsList) {
|
||||||
if (!player.inventory.addItemStackToInventory(craftedItem.copy())) {
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
container.detectAndSendChanges();
|
container.detectAndSendChanges();
|
||||||
}
|
}
|
||||||
@@ -232,8 +228,10 @@ public class TileGrid extends TileMachine implements IGrid {
|
|||||||
|
|
||||||
if (slot != null) {
|
if (slot != null) {
|
||||||
if (getType() == EnumGridType.CRAFTING) {
|
if (getType() == EnumGridType.CRAFTING) {
|
||||||
if (!controller.push(slot)) {
|
if (controller.push(slot, true) != null) {
|
||||||
return;
|
return;
|
||||||
|
} else {
|
||||||
|
controller.push(slot, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user