Change simulate arg to Action enum.

This commit is contained in:
raoulvdberge
2018-07-01 19:20:02 +02:00
parent 2265bf5d6b
commit b40fe6d360
35 changed files with 283 additions and 223 deletions

View File

@@ -1,11 +1,13 @@
package com.raoulvdberge.refinedstorage.api.energy;
import com.raoulvdberge.refinedstorage.api.util.Action;
import java.util.UUID;
public interface IEnergy {
void decreaseCapacity(UUID id, int amount);
int extract(int amount, boolean simulate);
int extract(int amount, Action action);
int getCapacity();
@@ -13,7 +15,7 @@ public interface IEnergy {
void increaseCapacity(UUID id, int amount);
int insert(int amount, boolean simulate);
int insert(int amount, Action action);
void setStored(int energyAmount);
}

View File

@@ -10,6 +10,7 @@ import com.raoulvdberge.refinedstorage.api.network.security.ISecurityManager;
import com.raoulvdberge.refinedstorage.api.storage.IStorage;
import com.raoulvdberge.refinedstorage.api.storage.IStorageCache;
import com.raoulvdberge.refinedstorage.api.storage.IStorageTracker;
import com.raoulvdberge.refinedstorage.api.util.Action;
import com.raoulvdberge.refinedstorage.api.util.IComparer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
@@ -94,11 +95,11 @@ public interface INetwork {
*
* @param stack the stack prototype to insert, do NOT modify
* @param size the amount of that prototype that has to be inserted
* @param simulate true if we are simulating, false otherwise
* @param action the action
* @return null if the insert was successful, or a stack with the remainder
*/
@Nullable
ItemStack insertItem(@Nonnull ItemStack stack, int size, boolean simulate);
ItemStack insertItem(@Nonnull ItemStack stack, int size, Action action);
/**
* Inserts an item and notifies the crafting manager of the incoming item.
@@ -108,7 +109,7 @@ public interface INetwork {
* @return null if the insert was successful, or a stack with the remainder
*/
default ItemStack insertItemTracked(@Nonnull ItemStack stack, int size) {
ItemStack remainder = insertItem(stack, size, false);
ItemStack remainder = insertItem(stack, size, Action.PERFORM);
int inserted = remainder == null ? size : (size - remainder.getCount());
@@ -123,12 +124,12 @@ public interface INetwork {
* @param stack the prototype of the stack to extract, do NOT modify
* @param size the amount of that prototype that has to be extracted
* @param flags the flags to compare on, see {@link IComparer}
* @param simulate true if we are simulating, false otherwise
* @param action the action
* @param filter a filter for the storage
* @return null if we didn't extract anything, or a stack with the result
*/
@Nullable
ItemStack extractItem(@Nonnull ItemStack stack, int size, int flags, boolean simulate, Predicate<IStorage<ItemStack>> filter);
ItemStack extractItem(@Nonnull ItemStack stack, int size, int flags, Action action, Predicate<IStorage<ItemStack>> filter);
/**
* Extracts an item from this network.
@@ -136,11 +137,11 @@ public interface INetwork {
* @param stack the prototype of the stack to extract, do NOT modify
* @param size the amount of that prototype that has to be extracted
* @param flags the flags to compare on, see {@link IComparer}
* @param simulate true if we are simulating, false otherwise
* @param action the action
* @return null if we didn't extract anything, or a stack with the result
*/
default ItemStack extractItem(@Nonnull ItemStack stack, int size, int flags, boolean simulate) {
return extractItem(stack, size, flags, simulate, s -> true);
default ItemStack extractItem(@Nonnull ItemStack stack, int size, int flags, Action action) {
return extractItem(stack, size, flags, action, s -> true);
}
/**
@@ -148,11 +149,11 @@ public interface INetwork {
*
* @param stack the prototype of the stack to extract, do NOT modify
* @param size the amount of that prototype that has to be extracted
* @param simulate true if we are simulating, false otherwise
* @param action the action
* @return null if we didn't extract anything, or a stack with the result
*/
default ItemStack extractItem(@Nonnull ItemStack stack, int size, boolean simulate) {
return extractItem(stack, size, IComparer.COMPARE_DAMAGE | IComparer.COMPARE_NBT, simulate);
default ItemStack extractItem(@Nonnull ItemStack stack, int size, Action action) {
return extractItem(stack, size, IComparer.COMPARE_DAMAGE | IComparer.COMPARE_NBT, action);
}
/**
@@ -160,11 +161,11 @@ public interface INetwork {
*
* @param stack the stack prototype to insert, do NOT modify
* @param size the amount of that prototype that has to be inserted
* @param simulate true if we are simulating, false otherwise
* @param action the action
* @return null if the insert was successful, or a stack with the remainder
*/
@Nullable
FluidStack insertFluid(@Nonnull FluidStack stack, int size, boolean simulate);
FluidStack insertFluid(@Nonnull FluidStack stack, int size, Action action);
/**
* Extracts a fluid from this network.
@@ -172,22 +173,22 @@ public interface INetwork {
* @param stack the prototype of the stack to extract, do NOT modify
* @param size the amount of that prototype that has to be extracted
* @param flags the flags to compare on, see {@link IComparer}
* @param simulate true if we are simulating, false otherwise
* @param action the action
* @return null if we didn't extract anything, or a stack with the result
*/
@Nullable
FluidStack extractFluid(@Nonnull FluidStack stack, int size, int flags, boolean simulate);
FluidStack extractFluid(@Nonnull FluidStack stack, int size, int flags, Action action);
/**
* Extracts a fluid from this network.
*
* @param stack the prototype of the stack to extract, do NOT modify
* @param size the amount of that prototype that has to be extracted
* @param simulate true if we are simulating, false otherwise
* @param action the action
* @return null if we didn't extract anything, or a stack with the result
*/
default FluidStack extractFluid(FluidStack stack, int size, boolean simulate) {
return extractFluid(stack, size, IComparer.COMPARE_NBT, simulate);
default FluidStack extractFluid(FluidStack stack, int size, Action action) {
return extractFluid(stack, size, IComparer.COMPARE_NBT, action);
}
/**

View File

@@ -1,5 +1,6 @@
package com.raoulvdberge.refinedstorage.api.storage;
import com.raoulvdberge.refinedstorage.api.util.Action;
import com.raoulvdberge.refinedstorage.api.util.IComparer;
import javax.annotation.Nonnull;
@@ -24,11 +25,11 @@ public interface IStorage<T> {
*
* @param stack the stack prototype to insert, do NOT modify
* @param size the amount of that prototype that has to be inserted
* @param simulate true if we are simulating, false otherwise
* @param action the action
* @return null if the insert was successful, or a stack with the remainder
*/
@Nullable
T insert(@Nonnull T stack, int size, boolean simulate);
T insert(@Nonnull T stack, int size, Action action);
/**
* Extracts a stack from this storage.
@@ -38,11 +39,11 @@ public interface IStorage<T> {
* @param stack a prototype of the stack to extract, do NOT modify
* @param size the amount of that prototype that has to be extracted
* @param flags the flags to compare on, see {@link IComparer}
* @param simulate true if we are simulating, false otherwise
* @param action the action
* @return null if we didn't extract anything, or a stack with the result
*/
@Nullable
T extract(@Nonnull T stack, int size, int flags, boolean simulate);
T extract(@Nonnull T stack, int size, int flags, Action action);
/**
* @return the amount stored in this storage

View File

@@ -0,0 +1,15 @@
package com.raoulvdberge.refinedstorage.api.util;
/**
* Defines how an action is performed.
*/
public enum Action {
/**
* Performs the action.
*/
PERFORM,
/**
* Gives back the same return as called with PERFORM, but doesn't mutate the underlying structure.
*/
SIMULATE
}

View File

@@ -2,6 +2,7 @@ package com.raoulvdberge.refinedstorage.apiimpl.autocrafting.task.extractor;
import com.raoulvdberge.refinedstorage.api.autocrafting.task.CraftingTaskReadException;
import com.raoulvdberge.refinedstorage.api.network.INetwork;
import com.raoulvdberge.refinedstorage.api.util.Action;
import com.raoulvdberge.refinedstorage.apiimpl.autocrafting.task.CraftingTask;
import com.raoulvdberge.refinedstorage.util.StackUtils;
import net.minecraft.item.ItemStack;
@@ -70,7 +71,7 @@ public class CraftingExtractor {
if (status.get(i) != CraftingExtractorItemStatus.EXTRACTED) {
ItemStack stack = items.get(i);
ItemStack inNetwork = network.extractItem(stack, stack.getCount(), CraftingTask.getFlags(stack), true);
ItemStack inNetwork = network.extractItem(stack, stack.getCount(), CraftingTask.getFlags(stack), Action.SIMULATE);
CraftingExtractorItemStatus previousStatus = status.get(i);
@@ -112,7 +113,7 @@ public class CraftingExtractor {
for (int i = 0; i < items.size(); ++i) {
if (status.get(i) == CraftingExtractorItemStatus.AVAILABLE) {
ItemStack extracted = network.extractItem(items.get(i), items.get(i).getCount(), CraftingTask.getFlags(items.get(i)), false);
ItemStack extracted = network.extractItem(items.get(i), items.get(i).getCount(), CraftingTask.getFlags(items.get(i)), Action.PERFORM);
if (extracted == null) {
throw new IllegalStateException("Did not extract anything while available");
}

View File

@@ -2,6 +2,7 @@ package com.raoulvdberge.refinedstorage.apiimpl.autocrafting.task.inserter;
import com.raoulvdberge.refinedstorage.api.autocrafting.task.CraftingTaskReadException;
import com.raoulvdberge.refinedstorage.api.network.INetwork;
import com.raoulvdberge.refinedstorage.api.util.Action;
import com.raoulvdberge.refinedstorage.util.StackUtils;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
@@ -52,8 +53,8 @@ public class CraftingInserter {
if (item != null) {
CraftingInserterItemStatus currentStatus = item.getStatus();
if (network.insertItem(item.getStack(), item.getStack().getCount(), true) == null) {
ItemStack inserted = network.insertItem(item.getStack(), item.getStack().getCount(), false);
if (network.insertItem(item.getStack(), item.getStack().getCount(), Action.SIMULATE) == null) {
ItemStack inserted = network.insertItem(item.getStack(), item.getStack().getCount(), Action.PERFORM);
if (inserted != null) {
throw new IllegalStateException("Could not insert item");
}
@@ -73,7 +74,7 @@ public class CraftingInserter {
while (!items.isEmpty()) {
CraftingInserterItem item = items.pop();
network.insertItem(item.getStack(), item.getStack().getCount(), false);
network.insertItem(item.getStack(), item.getStack().getCount(), Action.PERFORM);
}
network.getCraftingManager().onTaskChanged();

View File

@@ -1,14 +1,14 @@
package com.raoulvdberge.refinedstorage.apiimpl.energy;
import com.raoulvdberge.refinedstorage.api.energy.IEnergy;
import com.raoulvdberge.refinedstorage.api.util.Action;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import java.util.Map;
import java.util.UUID;
import com.raoulvdberge.refinedstorage.api.energy.IEnergy;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
public final class Energy implements IEnergy {
private static final UUID UUID_EMPTY = new UUID(0l, 0l);
private static final UUID DEFAULT_UUID = new UUID(0L, 0L);
protected int capacity;
protected int energy;
@@ -16,35 +16,41 @@ public final class Energy implements IEnergy {
private final Map<UUID, Integer> energyStorages;
public Energy(int controllerCapacity) {
this.energyStorages = new Object2ObjectOpenHashMap<UUID, Integer>();
this.energyStorages.put(UUID_EMPTY, controllerCapacity);
this.energyStorages = new Object2ObjectOpenHashMap<>();
this.energyStorages.put(DEFAULT_UUID, controllerCapacity);
calculateCapacity();
}
private void calculateCapacity() {
long newCapacity = energyStorages.values().stream().mapToLong(Long::valueOf).sum();
this.capacity = (int) Math.min(newCapacity, Integer.MAX_VALUE);
}
@Override
public void decreaseCapacity(UUID id, int amount) {
if (id.equals(UUID_EMPTY)) {
if (id.equals(DEFAULT_UUID)) {
return;
}
this.energyStorages.remove(id);
calculateCapacity();
}
@Override
public int extract(int maxExtract, boolean simulate) {
public int extract(int maxExtract, Action action) {
if (maxExtract <= 0) {
return 0;
}
int energyExtracted = Math.min(energy, maxExtract);
if (!simulate) {
if (action == Action.PERFORM) {
energy -= energyExtracted;
}
return energyExtracted;
}
@@ -60,23 +66,27 @@ public final class Energy implements IEnergy {
@Override
public void increaseCapacity(UUID id, int amount) {
if (id.equals(UUID_EMPTY) || amount <= 0) {
if (id.equals(DEFAULT_UUID) || amount <= 0) {
return;
}
this.energyStorages.merge(id, amount, (k, v) -> amount);
calculateCapacity();
}
@Override
public int insert (int maxReceive, boolean simulate) {
public int insert(int maxReceive, Action action) {
if (maxReceive <= 0) {
return 0;
}
int energyReceived = Math.min(capacity - energy, maxReceive);
if (!simulate) {
if (action == Action.PERFORM) {
energy += energyReceived;
}
return energyReceived;
}

View File

@@ -5,6 +5,7 @@ import com.raoulvdberge.refinedstorage.api.network.grid.handler.IFluidGridHandle
import com.raoulvdberge.refinedstorage.api.network.item.INetworkItem;
import com.raoulvdberge.refinedstorage.api.network.item.NetworkItemAction;
import com.raoulvdberge.refinedstorage.api.network.security.Permission;
import com.raoulvdberge.refinedstorage.api.util.Action;
import com.raoulvdberge.refinedstorage.apiimpl.API;
import com.raoulvdberge.refinedstorage.util.StackUtils;
import net.minecraft.entity.player.EntityPlayerMP;
@@ -49,7 +50,7 @@ public class FluidGridHandler implements IFluidGridHandler {
}
if (bucket == null) {
bucket = network.extractItem(StackUtils.EMPTY_BUCKET, 1, false);
bucket = network.extractItem(StackUtils.EMPTY_BUCKET, 1, Action.PERFORM);
}
if (bucket != null) {
@@ -57,7 +58,7 @@ public class FluidGridHandler implements IFluidGridHandler {
network.getFluidStorageTracker().changed(player, stack.copy());
fluidHandler.fill(network.extractFluid(stack, Fluid.BUCKET_VOLUME, false), true);
fluidHandler.fill(network.extractFluid(stack, Fluid.BUCKET_VOLUME, Action.PERFORM), true);
if (shift) {
if (!player.inventory.addItemStackToInventory(fluidHandler.getContainer().copy())) {
@@ -86,12 +87,12 @@ public class FluidGridHandler implements IFluidGridHandler {
Pair<ItemStack, FluidStack> result = StackUtils.getFluid(container, true);
if (result.getValue() != null && network.insertFluid(result.getValue(), result.getValue().amount, true) == null) {
if (result.getValue() != null && network.insertFluid(result.getValue(), result.getValue().amount, Action.SIMULATE) == null) {
network.getFluidStorageTracker().changed(player, result.getValue().copy());
result = StackUtils.getFluid(container, false);
network.insertFluid(result.getValue(), result.getValue().amount, false);
network.insertFluid(result.getValue(), result.getValue().amount, Action.PERFORM);
INetworkItem networkItem = network.getNetworkItemHandler().getItem(player);

View File

@@ -9,6 +9,7 @@ import com.raoulvdberge.refinedstorage.api.network.grid.handler.IItemGridHandler
import com.raoulvdberge.refinedstorage.api.network.item.INetworkItem;
import com.raoulvdberge.refinedstorage.api.network.item.NetworkItemAction;
import com.raoulvdberge.refinedstorage.api.network.security.Permission;
import com.raoulvdberge.refinedstorage.api.util.Action;
import com.raoulvdberge.refinedstorage.api.util.IStackList;
import com.raoulvdberge.refinedstorage.apiimpl.API;
import com.raoulvdberge.refinedstorage.apiimpl.autocrafting.preview.CraftingPreviewElementError;
@@ -80,19 +81,19 @@ public class ItemGridHandler implements IItemGridHandler {
// Do this before actually extracting, since external storage sends updates as soon as a change happens (so before the storage tracker used to track)
network.getItemStorageTracker().changed(player, item.copy());
ItemStack took = network.extractItem(item, size, true);
ItemStack took = network.extractItem(item, size, Action.SIMULATE);
if (took != null) {
if ((flags & EXTRACT_SHIFT) == EXTRACT_SHIFT) {
IItemHandler playerInventory = player.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.UP);
if (ItemHandlerHelper.insertItem(playerInventory, took, true).isEmpty()) {
took = network.extractItem(item, size, false);
took = network.extractItem(item, size, Action.PERFORM);
ItemHandlerHelper.insertItem(playerInventory, took, false);
}
} else {
took = network.extractItem(item, size, false);
took = network.extractItem(item, size, Action.PERFORM);
if (single && !held.isEmpty()) {
held.grow(1);
@@ -119,7 +120,7 @@ public class ItemGridHandler implements IItemGridHandler {
network.getItemStorageTracker().changed(player, stack.copy());
ItemStack remainder = network.insertItem(stack, stack.getCount(), false);
ItemStack remainder = network.insertItem(stack, stack.getCount(), Action.PERFORM);
INetworkItem networkItem = network.getNetworkItemHandler().getItem(player);
@@ -142,8 +143,8 @@ public class ItemGridHandler implements IItemGridHandler {
network.getItemStorageTracker().changed(player, stack.copy());
if (single) {
if (network.insertItem(stack, size, true) == null) {
network.insertItem(stack, size, false);
if (network.insertItem(stack, size, Action.SIMULATE) == null) {
network.insertItem(stack, size, Action.PERFORM);
stack.shrink(size);
@@ -152,7 +153,7 @@ public class ItemGridHandler implements IItemGridHandler {
}
}
} else {
player.inventory.setItemStack(StackUtils.nullToEmpty(network.insertItem(stack, size, false)));
player.inventory.setItemStack(StackUtils.nullToEmpty(network.insertItem(stack, size, Action.PERFORM)));
}
player.updateHeldItem();

View File

@@ -3,6 +3,7 @@ package com.raoulvdberge.refinedstorage.apiimpl.network.grid.handler;
import com.raoulvdberge.refinedstorage.RS;
import com.raoulvdberge.refinedstorage.api.network.grid.IGrid;
import com.raoulvdberge.refinedstorage.api.network.grid.handler.IItemGridHandler;
import com.raoulvdberge.refinedstorage.api.util.Action;
import com.raoulvdberge.refinedstorage.api.util.IComparer;
import com.raoulvdberge.refinedstorage.apiimpl.API;
import com.raoulvdberge.refinedstorage.tile.grid.portable.IPortableGrid;
@@ -77,19 +78,19 @@ public class ItemGridHandlerPortable implements IItemGridHandler {
// Do this before actually extracting, since portable grid sends updates as soon as a change happens (so before the storage tracker used to track)
portableGrid.getStorageTracker().changed(player, item.copy());
ItemStack took = portableGrid.getStorage().extract(item, size, IComparer.COMPARE_DAMAGE | IComparer.COMPARE_NBT, true);
ItemStack took = portableGrid.getStorage().extract(item, size, IComparer.COMPARE_DAMAGE | IComparer.COMPARE_NBT, Action.SIMULATE);
if (took != null) {
if ((flags & EXTRACT_SHIFT) == EXTRACT_SHIFT) {
IItemHandler playerInventory = player.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.UP);
if (ItemHandlerHelper.insertItem(playerInventory, took, true).isEmpty()) {
took = portableGrid.getStorage().extract(item, size, IComparer.COMPARE_DAMAGE | IComparer.COMPARE_NBT, false);
took = portableGrid.getStorage().extract(item, size, IComparer.COMPARE_DAMAGE | IComparer.COMPARE_NBT, Action.PERFORM);
ItemHandlerHelper.insertItem(playerInventory, took, false);
}
} else {
took = portableGrid.getStorage().extract(item, size, IComparer.COMPARE_DAMAGE | IComparer.COMPARE_NBT, false);
took = portableGrid.getStorage().extract(item, size, IComparer.COMPARE_DAMAGE | IComparer.COMPARE_NBT, Action.PERFORM);
if (single && !held.isEmpty()) {
held.grow(1);
@@ -113,7 +114,7 @@ public class ItemGridHandlerPortable implements IItemGridHandler {
portableGrid.getStorageTracker().changed(player, stack.copy());
ItemStack remainder = portableGrid.getStorage().insert(stack, stack.getCount(), false);
ItemStack remainder = portableGrid.getStorage().insert(stack, stack.getCount(), Action.PERFORM);
portableGrid.drainEnergy(RS.INSTANCE.config.portableGridInsertUsage);
@@ -132,8 +133,8 @@ public class ItemGridHandlerPortable implements IItemGridHandler {
portableGrid.getStorageTracker().changed(player, stack.copy());
if (single) {
if (portableGrid.getStorage().insert(stack, size, true) == null) {
portableGrid.getStorage().insert(stack, size, false);
if (portableGrid.getStorage().insert(stack, size, Action.SIMULATE) == null) {
portableGrid.getStorage().insert(stack, size, Action.PERFORM);
stack.shrink(size);
@@ -142,7 +143,7 @@ public class ItemGridHandlerPortable implements IItemGridHandler {
}
}
} else {
player.inventory.setItemStack(StackUtils.nullToEmpty(portableGrid.getStorage().insert(stack, size, false)));
player.inventory.setItemStack(StackUtils.nullToEmpty(portableGrid.getStorage().insert(stack, size, Action.PERFORM)));
}
player.updateHeldItem();

View File

@@ -2,6 +2,7 @@ package com.raoulvdberge.refinedstorage.apiimpl.network.node;
import com.mojang.authlib.GameProfile;
import com.raoulvdberge.refinedstorage.RS;
import com.raoulvdberge.refinedstorage.api.util.Action;
import com.raoulvdberge.refinedstorage.api.util.IComparer;
import com.raoulvdberge.refinedstorage.container.slot.SlotFilter;
import com.raoulvdberge.refinedstorage.inventory.ItemHandlerBase;
@@ -87,7 +88,7 @@ public class NetworkNodeConstructor extends NetworkNode implements IComparable,
}
} else {
if (item.getItem() == Items.FIREWORKS && !drop) {
ItemStack took = network.extractItem(item, 1, false);
ItemStack took = network.extractItem(item, 1, Action.PERFORM);
if (took != null) {
world.spawnEntity(new EntityFireworkRocket(world, getDispensePositionX(), getDispensePositionY(), getDispensePositionZ(), took));
@@ -108,7 +109,7 @@ public class NetworkNodeConstructor extends NetworkNode implements IComparable,
FluidStack stored = network.getFluidStorageCache().getList().get(stack, compare);
if (stored != null && stored.amount >= Fluid.BUCKET_VOLUME) {
FluidStack took = network.extractFluid(stack, Fluid.BUCKET_VOLUME, compare, false);
FluidStack took = network.extractFluid(stack, Fluid.BUCKET_VOLUME, compare, Action.PERFORM);
if (took != null) {
IBlockState state = block.getDefaultState();
@@ -143,7 +144,7 @@ public class NetworkNodeConstructor extends NetworkNode implements IComparable,
ItemStack item = itemFilters.getStackInSlot(0);
ItemStack took = network.extractItem(item, 1, compare, true);
ItemStack took = network.extractItem(item, 1, compare, Action.SIMULATE);
if (took != null) {
IBlockState state = SlotFilter.getBlockState(world, front, took);
@@ -155,7 +156,7 @@ public class NetworkNodeConstructor extends NetworkNode implements IComparable,
return;
}
took = network.extractItem(item, 1, compare, false);
took = network.extractItem(item, 1, compare, Action.PERFORM);
if (took != null) {
if (item.getItem() instanceof ItemBlock) {
@@ -219,7 +220,7 @@ public class NetworkNodeConstructor extends NetworkNode implements IComparable,
}
private void dropItem() {
ItemStack took = network.extractItem(itemFilters.getStackInSlot(0), upgrades.getItemInteractCount(), false);
ItemStack took = network.extractItem(itemFilters.getStackInSlot(0), upgrades.getItemInteractCount(), Action.PERFORM);
if (took != null) {
BehaviorDefaultDispenseItem.doDispense(world, took, 6, getDirection(), new PositionImpl(getDispensePositionX(), getDispensePositionY(), getDispensePositionZ()));

View File

@@ -1,6 +1,7 @@
package com.raoulvdberge.refinedstorage.apiimpl.network.node;
import com.raoulvdberge.refinedstorage.RS;
import com.raoulvdberge.refinedstorage.api.util.Action;
import com.raoulvdberge.refinedstorage.api.util.IComparer;
import com.raoulvdberge.refinedstorage.apiimpl.util.OneSixMigrationHelper;
import com.raoulvdberge.refinedstorage.inventory.ItemHandlerBase;
@@ -92,7 +93,7 @@ public class NetworkNodeDestructor extends NetworkNode implements IComparable, I
if (entity instanceof EntityItem) {
ItemStack droppedItem = ((EntityItem) entity).getItem();
if (IFilterable.acceptsItem(itemFilters, mode, compare, droppedItem) && network.insertItem(droppedItem, droppedItem.getCount(), true) == null) {
if (IFilterable.acceptsItem(itemFilters, mode, compare, droppedItem) && network.insertItem(droppedItem, droppedItem.getCount(), Action.SIMULATE) == null) {
network.insertItemTracked(droppedItem.copy(), droppedItem.getCount());
world.removeEntity(entity);
@@ -134,7 +135,7 @@ public class NetworkNodeDestructor extends NetworkNode implements IComparable, I
}
for (ItemStack drop : drops) {
if (network.insertItem(drop, drop.getCount(), true) != null) {
if (network.insertItem(drop, drop.getCount(), Action.SIMULATE) != null) {
return;
}
}
@@ -171,10 +172,10 @@ public class NetworkNodeDestructor extends NetworkNode implements IComparable, I
if (handler != null) {
FluidStack stack = handler.drain(Fluid.BUCKET_VOLUME, false);
if (stack != null && IFilterable.acceptsFluid(fluidFilters, mode, compare, stack) && network.insertFluid(stack, stack.amount, true) == null) {
if (stack != null && IFilterable.acceptsFluid(fluidFilters, mode, compare, stack) && network.insertFluid(stack, stack.amount, Action.SIMULATE) == null) {
FluidStack drained = handler.drain(Fluid.BUCKET_VOLUME, true);
network.insertFluid(drained, drained.amount, false);
network.insertFluid(drained, drained.amount, Action.PERFORM);
}
}
}

View File

@@ -1,6 +1,7 @@
package com.raoulvdberge.refinedstorage.apiimpl.network.node;
import com.raoulvdberge.refinedstorage.RS;
import com.raoulvdberge.refinedstorage.api.util.Action;
import com.raoulvdberge.refinedstorage.api.util.IComparer;
import com.raoulvdberge.refinedstorage.inventory.ItemHandlerBase;
import com.raoulvdberge.refinedstorage.inventory.ItemHandlerFluid;
@@ -73,14 +74,14 @@ public class NetworkNodeExporter extends NetworkNode implements IComparable, ITy
if (!slot.isEmpty()) {
int stackSize = upgrades.getItemInteractCount();
ItemStack took = network.extractItem(slot, Math.min(slot.getMaxStackSize(), stackSize), compare, true);
ItemStack took = network.extractItem(slot, Math.min(slot.getMaxStackSize(), stackSize), compare, Action.SIMULATE);
if (took == null) {
if (upgrades.hasUpgrade(ItemUpgrade.TYPE_CRAFTING)) {
network.getCraftingManager().schedule(slot, stackSize);
}
} else if (ItemHandlerHelper.insertItem(handler, took, true).isEmpty()) {
took = network.extractItem(slot, Math.min(slot.getMaxStackSize(), stackSize), compare, false);
took = network.extractItem(slot, Math.min(slot.getMaxStackSize(), stackSize), compare, Action.PERFORM);
if (took != null) {
ItemHandlerHelper.insertItem(handler, took, false);
@@ -116,13 +117,13 @@ public class NetworkNodeExporter extends NetworkNode implements IComparable, ITy
if (stackInStorage != null) {
int toExtract = Math.min(Fluid.BUCKET_VOLUME * upgrades.getItemInteractCount(), stackInStorage.amount);
FluidStack took = network.extractFluid(stack, toExtract, compare, true);
FluidStack took = network.extractFluid(stack, toExtract, compare, Action.SIMULATE);
if (took != null) {
int filled = handler.fill(took, false);
if (filled > 0) {
took = network.extractFluid(stack, filled, compare, false);
took = network.extractFluid(stack, filled, compare, Action.PERFORM);
handler.fill(took, true);
}

View File

@@ -1,6 +1,7 @@
package com.raoulvdberge.refinedstorage.apiimpl.network.node;
import com.raoulvdberge.refinedstorage.RS;
import com.raoulvdberge.refinedstorage.api.util.Action;
import com.raoulvdberge.refinedstorage.api.util.IComparer;
import com.raoulvdberge.refinedstorage.inventory.*;
import com.raoulvdberge.refinedstorage.item.ItemUpgrade;
@@ -95,7 +96,7 @@ public class NetworkNodeFluidInterface extends NetworkNode implements IComparabl
// Drain in tank
if (drained != null) {
FluidStack remainder = network.insertFluid(drained, drained.amount, false);
FluidStack remainder = network.insertFluid(drained, drained.amount, Action.PERFORM);
if (remainder != null) {
tankIn.fillInternal(remainder, true);
@@ -111,7 +112,7 @@ public class NetworkNodeFluidInterface extends NetworkNode implements IComparabl
FluidStack remainder = tankOut.drainInternal(Fluid.BUCKET_VOLUME * upgrades.getItemInteractCount(), true);
if (remainder != null) {
network.insertFluid(remainder, remainder.amount, false);
network.insertFluid(remainder, remainder.amount, Action.PERFORM);
}
} else if (stack != null) {
// Fill the out fluid
@@ -128,10 +129,10 @@ public class NetworkNodeFluidInterface extends NetworkNode implements IComparabl
return;
}
FluidStack took = network.extractFluid(stack, toExtract, compare, true);
FluidStack took = network.extractFluid(stack, toExtract, compare, Action.SIMULATE);
if (took != null && (toExtract - tankOut.fillInternal(took, false)) == 0) {
took = network.extractFluid(stack, toExtract, compare, false);
took = network.extractFluid(stack, toExtract, compare, Action.PERFORM);
tankOut.fillInternal(took, true);
}

View File

@@ -15,6 +15,7 @@ import com.raoulvdberge.refinedstorage.api.network.item.NetworkItemAction;
import com.raoulvdberge.refinedstorage.api.network.security.Permission;
import com.raoulvdberge.refinedstorage.api.storage.IStorageCache;
import com.raoulvdberge.refinedstorage.api.storage.IStorageCacheListener;
import com.raoulvdberge.refinedstorage.api.util.Action;
import com.raoulvdberge.refinedstorage.api.util.IComparer;
import com.raoulvdberge.refinedstorage.api.util.IFilter;
import com.raoulvdberge.refinedstorage.apiimpl.API;
@@ -327,10 +328,10 @@ public class NetworkNodeGrid extends NetworkNode implements IGridNetworkAware {
if (grid.getType() == GridType.CRAFTING) {
// If we are connected, try to insert into network. If it fails, stop.
if (network != null) {
if (network.insertItem(slot, slot.getCount(), true) != null) {
if (network.insertItem(slot, slot.getCount(), Action.SIMULATE) != null) {
return;
} else {
network.insertItem(slot, slot.getCount(), false);
network.insertItem(slot, slot.getCount(), Action.PERFORM);
}
} else {
// If we aren't connected, try to insert into player inventory. If it fails, stop.
@@ -356,7 +357,7 @@ public class NetworkNodeGrid extends NetworkNode implements IGridNetworkAware {
// If we are connected, first try to get the possibilities from the network
if (network != null) {
for (ItemStack possibility : possibilities) {
ItemStack took = network.extractItem(possibility, 1, IComparer.COMPARE_NBT | (possibility.getItem().isDamageable() ? 0 : IComparer.COMPARE_DAMAGE), false);
ItemStack took = network.extractItem(possibility, 1, IComparer.COMPARE_NBT | (possibility.getItem().isDamageable() ? 0 : IComparer.COMPARE_DAMAGE), Action.PERFORM);
if (took != null) {
grid.getCraftingMatrix().setInventorySlotContents(i, StackUtils.nullToEmpty(took));
@@ -430,7 +431,7 @@ public class NetworkNodeGrid extends NetworkNode implements IGridNetworkAware {
// If there is no space for the remainder, dump it in the player inventory
if (!slot.isEmpty() && slot.getCount() > 1) {
if (!player.inventory.addItemStackToInventory(remainder.get(i).copy())) {
ItemStack remainderStack = network == null ? remainder.get(i).copy() : network.insertItem(remainder.get(i).copy(), remainder.get(i).getCount(), false);
ItemStack remainderStack = network == null ? remainder.get(i).copy() : network.insertItem(remainder.get(i).copy(), remainder.get(i).getCount(), Action.PERFORM);
if (remainderStack != null) {
InventoryHelper.spawnItemStack(player.getEntityWorld(), player.getPosition().getX(), player.getPosition().getY(), player.getPosition().getZ(), remainderStack);
@@ -443,7 +444,7 @@ public class NetworkNodeGrid extends NetworkNode implements IGridNetworkAware {
}
} else if (!slot.isEmpty()) {
if (slot.getCount() == 1 && network != null) {
matrix.setInventorySlotContents(i, StackUtils.nullToEmpty(network.extractItem(slot, 1, false)));
matrix.setInventorySlotContents(i, StackUtils.nullToEmpty(network.extractItem(slot, 1, Action.PERFORM)));
} else {
matrix.decrStackSize(i, 1);
}
@@ -487,7 +488,7 @@ public class NetworkNodeGrid extends NetworkNode implements IGridNetworkAware {
for (ItemStack craftedItem : craftedItemsList) {
if (!player.inventory.addItemStackToInventory(craftedItem.copy())) {
ItemStack remainder = network == null ? craftedItem : network.insertItem(craftedItem, craftedItem.getCount(), false);
ItemStack remainder = network == null ? craftedItem : network.insertItem(craftedItem, craftedItem.getCount(), Action.PERFORM);
if (remainder != null) {
InventoryHelper.spawnItemStack(player.getEntityWorld(), player.getPosition().getX(), player.getPosition().getY(), player.getPosition().getZ(), remainder);

View File

@@ -1,6 +1,7 @@
package com.raoulvdberge.refinedstorage.apiimpl.network.node;
import com.raoulvdberge.refinedstorage.RS;
import com.raoulvdberge.refinedstorage.api.util.Action;
import com.raoulvdberge.refinedstorage.api.util.IComparer;
import com.raoulvdberge.refinedstorage.apiimpl.util.OneSixMigrationHelper;
import com.raoulvdberge.refinedstorage.inventory.ItemHandlerBase;
@@ -84,7 +85,7 @@ public class NetworkNodeImporter extends NetworkNode implements IComparable, IFi
} else if (ticks % upgrades.getSpeed() == 0) {
ItemStack result = handler.extractItem(currentSlot, upgrades.getItemInteractCount(), true);
if (!result.isEmpty() && network.insertItem(result, result.getCount(), true) == null) {
if (!result.isEmpty() && network.insertItem(result, result.getCount(), Action.SIMULATE) == null) {
result = handler.extractItem(currentSlot, upgrades.getItemInteractCount(), false);
if (!result.isEmpty()) {
@@ -101,11 +102,11 @@ public class NetworkNodeImporter extends NetworkNode implements IComparable, IFi
if (handler != null) {
FluidStack stack = handler.drain(Fluid.BUCKET_VOLUME, false);
if (stack != null && IFilterable.acceptsFluid(fluidFilters, mode, compare, stack) && network.insertFluid(stack, stack.amount, true) == null) {
if (stack != null && IFilterable.acceptsFluid(fluidFilters, mode, compare, stack) && network.insertFluid(stack, stack.amount, Action.SIMULATE) == null) {
FluidStack toDrain = handler.drain(Fluid.BUCKET_VOLUME * upgrades.getItemInteractCount(), false);
if (toDrain != null) {
FluidStack remainder = network.insertFluid(toDrain, toDrain.amount, false);
FluidStack remainder = network.insertFluid(toDrain, toDrain.amount, Action.PERFORM);
if (remainder != null) {
toDrain.amount -= remainder.amount;
}

View File

@@ -1,6 +1,7 @@
package com.raoulvdberge.refinedstorage.apiimpl.network.node;
import com.raoulvdberge.refinedstorage.RS;
import com.raoulvdberge.refinedstorage.api.util.Action;
import com.raoulvdberge.refinedstorage.api.util.IComparer;
import com.raoulvdberge.refinedstorage.apiimpl.API;
import com.raoulvdberge.refinedstorage.apiimpl.autocrafting.CraftingRequester;
@@ -93,7 +94,7 @@ public class NetworkNodeInterface extends NetworkNode implements IComparable {
int delta = got.isEmpty() ? wanted.getCount() : (wanted.getCount() - got.getCount());
if (delta > 0) {
ItemStack result = network.extractItem(wanted, delta, compare, false, s -> !(s instanceof StorageExternalItem) || !((StorageExternalItem) s).isConnectedToInterface());
ItemStack result = network.extractItem(wanted, delta, compare, Action.PERFORM, s -> !(s instanceof StorageExternalItem) || !((StorageExternalItem) s).isConnectedToInterface());
if (result != null) {
if (exportItems.getStackInSlot(i).isEmpty()) {

View File

@@ -1,6 +1,7 @@
package com.raoulvdberge.refinedstorage.apiimpl.network.node;
import com.raoulvdberge.refinedstorage.api.network.security.Permission;
import com.raoulvdberge.refinedstorage.api.util.Action;
import com.raoulvdberge.refinedstorage.api.util.IComparer;
import com.raoulvdberge.refinedstorage.apiimpl.API;
import com.raoulvdberge.refinedstorage.inventory.ItemHandlerBase;
@@ -144,7 +145,7 @@ public class NetworkNodeStorageMonitor extends NetworkNode implements IComparabl
int toExtract = player.isSneaking() ? 1 : 64;
if (!filter.isEmpty()) {
ItemStack result = network.extractItem(filter, toExtract, compare, false);
ItemStack result = network.extractItem(filter, toExtract, compare, Action.PERFORM);
if (result != null) {
if (!player.inventory.addItemStackToInventory(result.copy())) {

View File

@@ -4,6 +4,7 @@ import com.raoulvdberge.refinedstorage.api.storage.AccessType;
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDisk;
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskContainerContext;
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskListener;
import com.raoulvdberge.refinedstorage.api.util.Action;
import com.raoulvdberge.refinedstorage.tile.TileDiskDrive;
import com.raoulvdberge.refinedstorage.tile.config.IFilterable;
import com.raoulvdberge.refinedstorage.util.StackUtils;
@@ -55,18 +56,18 @@ public class StorageDiskFluidDriveWrapper implements IStorageDisk<FluidStack> {
@Override
@Nullable
public FluidStack insert(@Nonnull FluidStack stack, int size, boolean simulate) {
public FluidStack insert(@Nonnull FluidStack stack, int size, Action action) {
if (!IFilterable.acceptsFluid(diskDrive.getFluidFilters(), diskDrive.getMode(), diskDrive.getCompare(), stack)) {
return StackUtils.copy(stack, size);
}
return parent.insert(stack, size, simulate);
return parent.insert(stack, size, action);
}
@Nullable
@Override
public FluidStack extract(@Nonnull FluidStack stack, int size, int flags, boolean simulate) {
return parent.extract(stack, size, flags, simulate);
public FluidStack extract(@Nonnull FluidStack stack, int size, int flags, Action action) {
return parent.extract(stack, size, flags, action);
}
@Override

View File

@@ -4,6 +4,7 @@ import com.raoulvdberge.refinedstorage.api.storage.AccessType;
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDisk;
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskContainerContext;
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskListener;
import com.raoulvdberge.refinedstorage.api.util.Action;
import com.raoulvdberge.refinedstorage.tile.TileDiskDrive;
import com.raoulvdberge.refinedstorage.tile.config.IFilterable;
import com.raoulvdberge.refinedstorage.util.WorldUtils;
@@ -55,18 +56,18 @@ public class StorageDiskItemDriveWrapper implements IStorageDisk<ItemStack> {
@Override
@Nullable
public ItemStack insert(@Nonnull ItemStack stack, int size, boolean simulate) {
public ItemStack insert(@Nonnull ItemStack stack, int size, Action action) {
if (!IFilterable.acceptsItem(diskDrive.getItemFilters(), diskDrive.getMode(), diskDrive.getCompare(), stack)) {
return ItemHandlerHelper.copyStackWithSize(stack, size);
}
return parent.insert(stack, size, simulate);
return parent.insert(stack, size, action);
}
@Nullable
@Override
public ItemStack extract(@Nonnull ItemStack stack, int size, int flags, boolean simulate) {
return parent.extract(stack, size, flags, simulate);
public ItemStack extract(@Nonnull ItemStack stack, int size, int flags, Action action) {
return parent.extract(stack, size, flags, action);
}
@Override

View File

@@ -4,6 +4,7 @@ import com.raoulvdberge.refinedstorage.RS;
import com.raoulvdberge.refinedstorage.api.storage.AccessType;
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDisk;
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskContainerContext;
import com.raoulvdberge.refinedstorage.api.util.Action;
import com.raoulvdberge.refinedstorage.api.util.IComparer;
import com.raoulvdberge.refinedstorage.apiimpl.API;
import com.raoulvdberge.refinedstorage.apiimpl.network.node.NetworkNode;
@@ -134,7 +135,7 @@ public class NetworkNodeDiskManipulator extends NetworkNode implements IComparab
int slot = 0;
if (type == IType.ITEMS) {
while (slot < 3 && (itemDisks[slot] == null || checkItemDiskDone(itemDisks[slot], slot))) {
while (slot < 3 && (itemDisks[slot] == null || isItemDiskDone(itemDisks[slot], slot))) {
slot++;
}
@@ -150,7 +151,7 @@ public class NetworkNodeDiskManipulator extends NetworkNode implements IComparab
extractItemFromNetwork(storage, slot);
}
} else if (type == IType.FLUIDS) {
while (slot < 3 && (fluidDisks[slot] == null || checkFluidDiskDone(fluidDisks[slot], slot))) {
while (slot < 3 && (fluidDisks[slot] == null || isFluidDiskDone(fluidDisks[slot], slot))) {
slot++;
}
@@ -173,23 +174,23 @@ public class NetworkNodeDiskManipulator extends NetworkNode implements IComparab
for (int i = 0; i < stacks.size(); ++i) {
ItemStack stack = stacks.get(i);
ItemStack extracted = storage.extract(stack, upgrades.getItemInteractCount(), compare, false);
ItemStack extracted = storage.extract(stack, upgrades.getItemInteractCount(), compare, Action.PERFORM);
if (extracted == null) {
continue;
}
ItemStack remainder = network.insertItem(extracted, extracted.getCount(), false);
ItemStack remainder = network.insertItem(extracted, extracted.getCount(), Action.PERFORM);
if (remainder == null) {
break;
}
// We need to check if the stack was inserted
storage.insert(((extracted == remainder) ? remainder.copy() : remainder), remainder.getCount(), false);
storage.insert(((extracted == remainder) ? remainder.copy() : remainder), remainder.getCount(), Action.PERFORM);
}
}
// Iterate through disk stacks, if none can be inserted, return that it is done processing and can be output.
private boolean checkItemDiskDone(IStorageDisk<ItemStack> storage, int slot) {
private boolean isItemDiskDone(IStorageDisk<ItemStack> storage, int slot) {
if (ioMode == IO_MODE_INSERT && storage.getStored() == 0) {
moveDriveToOutput(slot);
return true;
@@ -208,12 +209,12 @@ public class NetworkNodeDiskManipulator extends NetworkNode implements IComparab
for (int i = 0; i < stacks.size(); ++i) {
ItemStack stack = stacks.get(i);
ItemStack extracted = storage.extract(stack, upgrades.getItemInteractCount(), compare, true);
ItemStack extracted = storage.extract(stack, upgrades.getItemInteractCount(), compare, Action.SIMULATE);
if (extracted == null) {
continue;
}
ItemStack remainder = network.insertItem(extracted, extracted.getCount(), true);
ItemStack remainder = network.insertItem(extracted, extracted.getCount(), Action.SIMULATE);
if (remainder == null) { //An item could be inserted (no remainders when trying to). This disk isn't done.
return false;
}
@@ -236,7 +237,7 @@ public class NetworkNodeDiskManipulator extends NetworkNode implements IComparab
}
if (toExtract != null) {
extracted = network.extractItem(toExtract, upgrades.getItemInteractCount(), compare, false);
extracted = network.extractItem(toExtract, upgrades.getItemInteractCount(), compare, Action.PERFORM);
}
} else {
while (itemFilters.getSlots() > i && extracted == null) {
@@ -247,7 +248,7 @@ public class NetworkNodeDiskManipulator extends NetworkNode implements IComparab
}
if (!filterStack.isEmpty()) {
extracted = network.extractItem(filterStack, upgrades.getItemInteractCount(), compare, false);
extracted = network.extractItem(filterStack, upgrades.getItemInteractCount(), compare, Action.PERFORM);
}
}
}
@@ -257,10 +258,10 @@ public class NetworkNodeDiskManipulator extends NetworkNode implements IComparab
return;
}
ItemStack remainder = storage.insert(extracted, extracted.getCount(), false);
ItemStack remainder = storage.insert(extracted, extracted.getCount(), Action.PERFORM);
if (remainder != null) {
network.insertItem(remainder, remainder.getCount(), false);
network.insertItem(remainder, remainder.getCount(), Action.PERFORM);
}
}
@@ -273,7 +274,7 @@ public class NetworkNodeDiskManipulator extends NetworkNode implements IComparab
while (extracted == null && stacks.size() > i) {
FluidStack stack = stacks.get(i++);
extracted = storage.extract(stack, upgrades.getItemInteractCount(), compare, false);
extracted = storage.extract(stack, upgrades.getItemInteractCount(), compare, Action.PERFORM);
}
if (extracted == null) {
@@ -281,14 +282,14 @@ public class NetworkNodeDiskManipulator extends NetworkNode implements IComparab
return;
}
FluidStack remainder = network.insertFluid(extracted, extracted.amount, false);
FluidStack remainder = network.insertFluid(extracted, extracted.amount, Action.PERFORM);
if (remainder != null) {
storage.insert(remainder, remainder.amount, false);
storage.insert(remainder, remainder.amount, Action.PERFORM);
}
}
private boolean checkFluidDiskDone(IStorageDisk<FluidStack> storage, int slot) {
private boolean isFluidDiskDone(IStorageDisk<FluidStack> storage, int slot) {
if (ioMode == IO_MODE_INSERT && storage.getStored() == 0) {
moveDriveToOutput(slot);
return true;
@@ -307,12 +308,12 @@ public class NetworkNodeDiskManipulator extends NetworkNode implements IComparab
for (int i = 0; i < stacks.size(); ++i) {
FluidStack stack = stacks.get(i);
FluidStack extracted = storage.extract(stack, upgrades.getItemInteractCount(), compare, true);
FluidStack extracted = storage.extract(stack, upgrades.getItemInteractCount(), compare, Action.SIMULATE);
if (extracted == null) {
continue;
}
FluidStack remainder = network.insertFluid(extracted, extracted.amount, true);
FluidStack remainder = network.insertFluid(extracted, extracted.amount, Action.SIMULATE);
if (remainder == null) { // A fluid could be inserted (no remainders when trying to). This disk isn't done.
return false;
}
@@ -335,7 +336,7 @@ public class NetworkNodeDiskManipulator extends NetworkNode implements IComparab
}
if (toExtract != null) {
extracted = network.extractFluid(toExtract, upgrades.getItemInteractCount(), compare, false);
extracted = network.extractFluid(toExtract, upgrades.getItemInteractCount(), compare, Action.PERFORM);
}
} else {
while (fluidFilters.getSlots() > i && extracted == null) {
@@ -346,7 +347,7 @@ public class NetworkNodeDiskManipulator extends NetworkNode implements IComparab
}
if (filterStack != null) {
extracted = network.extractFluid(filterStack, upgrades.getItemInteractCount(), compare, false);
extracted = network.extractFluid(filterStack, upgrades.getItemInteractCount(), compare, Action.PERFORM);
}
}
}
@@ -356,10 +357,10 @@ public class NetworkNodeDiskManipulator extends NetworkNode implements IComparab
return;
}
FluidStack remainder = storage.insert(extracted, extracted.amount, false);
FluidStack remainder = storage.insert(extracted, extracted.amount, Action.PERFORM);
if (remainder != null) {
network.insertFluid(remainder, remainder.amount, false);
network.insertFluid(remainder, remainder.amount, Action.PERFORM);
}
}

View File

@@ -4,6 +4,7 @@ import com.raoulvdberge.refinedstorage.api.storage.AccessType;
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDisk;
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskContainerContext;
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskListener;
import com.raoulvdberge.refinedstorage.api.util.Action;
import com.raoulvdberge.refinedstorage.tile.TileDiskDrive;
import com.raoulvdberge.refinedstorage.tile.config.IFilterable;
import com.raoulvdberge.refinedstorage.util.StackUtils;
@@ -65,22 +66,22 @@ public class StorageDiskFluidManipulatorWrapper implements IStorageDisk<FluidSta
@Override
@Nullable
public FluidStack insert(@Nonnull FluidStack stack, int size, boolean simulate) {
public FluidStack insert(@Nonnull FluidStack stack, int size, Action action) {
if (!IFilterable.acceptsFluid(diskManipulator.getFluidFilters(), diskManipulator.getMode(), diskManipulator.getCompare(), stack)) {
return StackUtils.copy(stack, size);
}
return parent.insert(stack, size, simulate);
return parent.insert(stack, size, action);
}
@Override
@Nullable
public FluidStack extract(@Nonnull FluidStack stack, int size, int flags, boolean simulate) {
public FluidStack extract(@Nonnull FluidStack stack, int size, int flags, Action action) {
if (!IFilterable.acceptsFluid(diskManipulator.getFluidFilters(), diskManipulator.getMode(), diskManipulator.getCompare(), stack)) {
return null;
}
return parent.extract(stack, size, flags, simulate);
return parent.extract(stack, size, flags, action);
}
@Override

View File

@@ -4,6 +4,7 @@ import com.raoulvdberge.refinedstorage.api.storage.AccessType;
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDisk;
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskContainerContext;
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskListener;
import com.raoulvdberge.refinedstorage.api.util.Action;
import com.raoulvdberge.refinedstorage.tile.TileDiskDrive;
import com.raoulvdberge.refinedstorage.tile.config.IFilterable;
import com.raoulvdberge.refinedstorage.util.WorldUtils;
@@ -60,22 +61,22 @@ public class StorageDiskItemManipulatorWrapper implements IStorageDisk<ItemStack
@Override
@Nullable
public ItemStack insert(@Nonnull ItemStack stack, int size, boolean simulate) {
public ItemStack insert(@Nonnull ItemStack stack, int size, Action action) {
if (!IFilterable.acceptsItem(diskManipulator.getItemFilters(), diskManipulator.getMode(), diskManipulator.getCompare(), stack)) {
return ItemHandlerHelper.copyStackWithSize(stack, size);
}
return parent.insert(stack, size, simulate);
return parent.insert(stack, size, action);
}
@Override
@Nullable
public ItemStack extract(@Nonnull ItemStack stack, int size, int flags, boolean simulate) {
public ItemStack extract(@Nonnull ItemStack stack, int size, int flags, Action action) {
if (!IFilterable.acceptsItem(diskManipulator.getItemFilters(), diskManipulator.getMode(), diskManipulator.getCompare(), stack)) {
return null;
}
return parent.extract(stack, size, flags, simulate);
return parent.extract(stack, size, flags, action);
}
@Override

View File

@@ -4,6 +4,7 @@ import com.raoulvdberge.refinedstorage.api.storage.AccessType;
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDisk;
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskContainerContext;
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskListener;
import com.raoulvdberge.refinedstorage.api.util.Action;
import com.raoulvdberge.refinedstorage.tile.config.IFilterable;
import com.raoulvdberge.refinedstorage.util.StackUtils;
import net.minecraft.nbt.NBTTagCompound;
@@ -40,18 +41,18 @@ public class StorageDiskFluidStorageWrapper implements IStorageDisk<FluidStack>
@Override
@Nullable
public FluidStack insert(@Nonnull FluidStack stack, int size, boolean simulate) {
public FluidStack insert(@Nonnull FluidStack stack, int size, Action action) {
if (!IFilterable.acceptsFluid(storage.getFilters(), storage.getMode(), storage.getCompare(), stack)) {
return StackUtils.copy(stack, size);
}
return parent.insert(stack, size, simulate);
return parent.insert(stack, size, action);
}
@Nullable
@Override
public FluidStack extract(@Nonnull FluidStack stack, int size, int flags, boolean simulate) {
return parent.extract(stack, size, flags, simulate);
public FluidStack extract(@Nonnull FluidStack stack, int size, int flags, Action action) {
return parent.extract(stack, size, flags, action);
}
@Override

View File

@@ -4,6 +4,7 @@ import com.raoulvdberge.refinedstorage.api.storage.AccessType;
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDisk;
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskContainerContext;
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskListener;
import com.raoulvdberge.refinedstorage.api.util.Action;
import com.raoulvdberge.refinedstorage.tile.config.IFilterable;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
@@ -40,18 +41,18 @@ public class StorageDiskItemStorageWrapper implements IStorageDisk<ItemStack> {
@Override
@Nullable
public ItemStack insert(@Nonnull ItemStack stack, int size, boolean simulate) {
public ItemStack insert(@Nonnull ItemStack stack, int size, Action action) {
if (!IFilterable.acceptsItem(storage.getFilters(), storage.getMode(), storage.getCompare(), stack)) {
return ItemHandlerHelper.copyStackWithSize(stack, size);
}
return parent.insert(stack, size, simulate);
return parent.insert(stack, size, action);
}
@Nullable
@Override
public ItemStack extract(@Nonnull ItemStack stack, int size, int flags, boolean simulate) {
return parent.extract(stack, size, flags, simulate);
public ItemStack extract(@Nonnull ItemStack stack, int size, int flags, Action action) {
return parent.extract(stack, size, flags, action);
}
@Override

View File

@@ -7,6 +7,7 @@ import com.raoulvdberge.refinedstorage.api.storage.AccessType;
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDisk;
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskContainerContext;
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskListener;
import com.raoulvdberge.refinedstorage.api.util.Action;
import com.raoulvdberge.refinedstorage.apiimpl.API;
import com.raoulvdberge.refinedstorage.util.StackUtils;
import net.minecraft.nbt.NBTTagCompound;
@@ -65,7 +66,7 @@ public class StorageDiskFluid implements IStorageDisk<FluidStack> {
@Override
@Nullable
public FluidStack insert(@Nonnull FluidStack stack, int size, boolean simulate) {
public FluidStack insert(@Nonnull FluidStack stack, int size, Action action) {
for (FluidStack otherStack : stacks.get(stack.getFluid())) {
if (otherStack.isFluidEqual(stack)) {
if (getCapacity() != -1 && getStored() + size > getCapacity()) {
@@ -75,7 +76,7 @@ public class StorageDiskFluid implements IStorageDisk<FluidStack> {
return StackUtils.copy(stack, size);
}
if (!simulate) {
if (action == Action.PERFORM) {
otherStack.amount += remainingSpace;
onChanged();
@@ -83,7 +84,7 @@ public class StorageDiskFluid implements IStorageDisk<FluidStack> {
return StackUtils.copy(otherStack, size - remainingSpace);
} else {
if (!simulate) {
if (action == Action.PERFORM) {
otherStack.amount += size;
onChanged();
@@ -101,7 +102,7 @@ public class StorageDiskFluid implements IStorageDisk<FluidStack> {
return StackUtils.copy(stack, size);
}
if (!simulate) {
if (action == Action.PERFORM) {
stacks.put(stack.getFluid(), StackUtils.copy(stack, remainingSpace));
onChanged();
@@ -109,7 +110,7 @@ public class StorageDiskFluid implements IStorageDisk<FluidStack> {
return StackUtils.copy(stack, size - remainingSpace);
} else {
if (!simulate) {
if (action == Action.PERFORM) {
stacks.put(stack.getFluid(), StackUtils.copy(stack, size));
onChanged();
@@ -121,14 +122,14 @@ public class StorageDiskFluid implements IStorageDisk<FluidStack> {
@Override
@Nullable
public FluidStack extract(@Nonnull FluidStack stack, int size, int flags, boolean simulate) {
public FluidStack extract(@Nonnull FluidStack stack, int size, int flags, Action action) {
for (FluidStack otherStack : stacks.get(stack.getFluid())) {
if (API.instance().getComparer().isEqual(otherStack, stack, flags)) {
if (size > otherStack.amount) {
size = otherStack.amount;
}
if (!simulate) {
if (action == Action.PERFORM) {
if (otherStack.amount - size == 0) {
stacks.remove(otherStack.getFluid(), otherStack);
} else {

View File

@@ -7,6 +7,7 @@ import com.raoulvdberge.refinedstorage.api.storage.AccessType;
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDisk;
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskContainerContext;
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskListener;
import com.raoulvdberge.refinedstorage.api.util.Action;
import com.raoulvdberge.refinedstorage.api.util.IComparer;
import com.raoulvdberge.refinedstorage.apiimpl.API;
import com.raoulvdberge.refinedstorage.util.StackUtils;
@@ -73,7 +74,7 @@ public class StorageDiskItem implements IStorageDisk<ItemStack> {
@Override
@Nullable
public ItemStack insert(@Nonnull ItemStack stack, int size, boolean simulate) {
public ItemStack insert(@Nonnull ItemStack stack, int size, Action action) {
for (ItemStack otherStack : stacks.get(stack.getItem())) {
if (API.instance().getComparer().isEqualNoQuantity(otherStack, stack)) {
if (getCapacity() != -1 && getStored() + size > getCapacity()) {
@@ -83,7 +84,7 @@ public class StorageDiskItem implements IStorageDisk<ItemStack> {
return ItemHandlerHelper.copyStackWithSize(stack, size);
}
if (!simulate) {
if (action == Action.PERFORM) {
otherStack.grow(remainingSpace);
onChanged();
@@ -91,7 +92,7 @@ public class StorageDiskItem implements IStorageDisk<ItemStack> {
return ItemHandlerHelper.copyStackWithSize(otherStack, size - remainingSpace);
} else {
if (!simulate) {
if (action == Action.PERFORM) {
otherStack.grow(size);
onChanged();
@@ -109,7 +110,7 @@ public class StorageDiskItem implements IStorageDisk<ItemStack> {
return ItemHandlerHelper.copyStackWithSize(stack, size);
}
if (!simulate) {
if (action == Action.PERFORM) {
stacks.put(stack.getItem(), ItemHandlerHelper.copyStackWithSize(stack, remainingSpace));
onChanged();
@@ -117,7 +118,7 @@ public class StorageDiskItem implements IStorageDisk<ItemStack> {
return ItemHandlerHelper.copyStackWithSize(stack, size - remainingSpace);
} else {
if (!simulate) {
if (action == Action.PERFORM) {
stacks.put(stack.getItem(), ItemHandlerHelper.copyStackWithSize(stack, size));
onChanged();
@@ -129,7 +130,7 @@ public class StorageDiskItem implements IStorageDisk<ItemStack> {
@Override
@Nullable
public ItemStack extract(@Nonnull ItemStack stack, int size, int flags, boolean simulate) {
public ItemStack extract(@Nonnull ItemStack stack, int size, int flags, Action action) {
Collection<ItemStack> toAttempt = null;
if ((flags & IComparer.COMPARE_OREDICT) == IComparer.COMPARE_OREDICT) {
@@ -152,7 +153,7 @@ public class StorageDiskItem implements IStorageDisk<ItemStack> {
size = otherStack.getCount();
}
if (!simulate) {
if (action == Action.PERFORM) {
if (otherStack.getCount() - size == 0) {
stacks.remove(otherStack.getItem(), otherStack);
} else {

View File

@@ -4,6 +4,7 @@ import com.raoulvdberge.refinedstorage.api.storage.AccessType;
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDisk;
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskContainerContext;
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskListener;
import com.raoulvdberge.refinedstorage.api.util.Action;
import com.raoulvdberge.refinedstorage.tile.grid.portable.IPortableGrid;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
@@ -43,12 +44,12 @@ public class StorageDiskItemPortable implements IStorageDisk<ItemStack> {
@Nullable
@Override
public ItemStack insert(@Nonnull ItemStack stack, int size, boolean simulate) {
public ItemStack insert(@Nonnull ItemStack stack, int size, Action action) {
int storedPre = parent.getStored();
ItemStack remainder = parent.insert(stack, size, simulate);
ItemStack remainder = parent.insert(stack, size, action);
if (!simulate) {
if (action == Action.PERFORM) {
int inserted = parent.getCacheDelta(storedPre, size, remainder);
if (inserted > 0) {
@@ -61,10 +62,10 @@ public class StorageDiskItemPortable implements IStorageDisk<ItemStack> {
@Nullable
@Override
public ItemStack extract(@Nonnull ItemStack stack, int size, int flags, boolean simulate) {
ItemStack extracted = parent.extract(stack, size, flags, simulate);
public ItemStack extract(@Nonnull ItemStack stack, int size, int flags, Action action) {
ItemStack extracted = parent.extract(stack, size, flags, action);
if (!simulate && extracted != null) {
if (action == Action.PERFORM && extracted != null) {
portableGrid.getCache().remove(extracted, extracted.getCount(), false);
}

View File

@@ -4,6 +4,7 @@ import com.raoulvdberge.refinedstorage.api.network.INetwork;
import com.raoulvdberge.refinedstorage.api.storage.AccessType;
import com.raoulvdberge.refinedstorage.api.storage.externalstorage.IExternalStorageContext;
import com.raoulvdberge.refinedstorage.api.storage.externalstorage.IStorageExternal;
import com.raoulvdberge.refinedstorage.api.util.Action;
import com.raoulvdberge.refinedstorage.api.util.IComparer;
import com.raoulvdberge.refinedstorage.apiimpl.API;
import com.raoulvdberge.refinedstorage.util.StackUtils;
@@ -156,9 +157,9 @@ public class StorageExternalFluid implements IStorageExternal<FluidStack> {
@Nullable
@Override
public FluidStack insert(@Nonnull FluidStack stack, int size, boolean simulate) {
public FluidStack insert(@Nonnull FluidStack stack, int size, Action action) {
if (context.acceptsFluid(stack)) {
int filled = handlerSupplier.get().fill(StackUtils.copy(stack, size), !simulate);
int filled = handlerSupplier.get().fill(StackUtils.copy(stack, size), action == Action.PERFORM);
if (filled == size) {
return null;
@@ -172,14 +173,14 @@ public class StorageExternalFluid implements IStorageExternal<FluidStack> {
@Nullable
@Override
public FluidStack extract(@Nonnull FluidStack stack, int size, int flags, boolean simulate) {
public FluidStack extract(@Nonnull FluidStack stack, int size, int flags, Action action) {
IFluidHandler handler = handlerSupplier.get();
if (handler == null) {
return null;
}
return handler.drain(StackUtils.copy(stack, size), !simulate);
return handler.drain(StackUtils.copy(stack, size), action == Action.PERFORM);
}
@Override

View File

@@ -4,6 +4,7 @@ import com.raoulvdberge.refinedstorage.api.network.INetwork;
import com.raoulvdberge.refinedstorage.api.storage.AccessType;
import com.raoulvdberge.refinedstorage.api.storage.externalstorage.IExternalStorageContext;
import com.raoulvdberge.refinedstorage.api.storage.externalstorage.IStorageExternal;
import com.raoulvdberge.refinedstorage.api.util.Action;
import com.raoulvdberge.refinedstorage.apiimpl.API;
import com.raoulvdberge.refinedstorage.util.StackUtils;
import net.minecraft.item.ItemStack;
@@ -143,11 +144,11 @@ public class StorageExternalItem implements IStorageExternal<ItemStack> {
@Nullable
@Override
public ItemStack insert(@Nonnull ItemStack stack, int size, boolean simulate) {
public ItemStack insert(@Nonnull ItemStack stack, int size, Action action) {
IItemHandler handler = handlerSupplier.get();
if (handler != null && context.acceptsItem(stack)) {
return StackUtils.emptyToNull(ItemHandlerHelper.insertItem(handler, ItemHandlerHelper.copyStackWithSize(stack, size), simulate));
return StackUtils.emptyToNull(ItemHandlerHelper.insertItem(handler, ItemHandlerHelper.copyStackWithSize(stack, size), action == Action.SIMULATE));
}
return ItemHandlerHelper.copyStackWithSize(stack, size);
@@ -155,7 +156,7 @@ public class StorageExternalItem implements IStorageExternal<ItemStack> {
@Nullable
@Override
public ItemStack extract(@Nonnull ItemStack stack, int size, int flags, boolean simulate) {
public ItemStack extract(@Nonnull ItemStack stack, int size, int flags, Action action) {
int remaining = size;
ItemStack received = null;
@@ -170,7 +171,7 @@ public class StorageExternalItem implements IStorageExternal<ItemStack> {
ItemStack slot = handler.getStackInSlot(i);
if (!slot.isEmpty() && API.instance().getComparer().isEqual(slot, stack, flags)) {
ItemStack got = handler.extractItem(i, remaining, simulate);
ItemStack got = handler.extractItem(i, remaining, action == Action.SIMULATE);
if (!got.isEmpty()) {
if (received == null) {

View File

@@ -2,6 +2,7 @@ package com.raoulvdberge.refinedstorage.apiimpl.util;
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDisk;
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskProvider;
import com.raoulvdberge.refinedstorage.api.util.Action;
import com.raoulvdberge.refinedstorage.api.util.IFilter;
import com.raoulvdberge.refinedstorage.api.util.IOneSixMigrationHelper;
import com.raoulvdberge.refinedstorage.apiimpl.API;
@@ -55,7 +56,7 @@ public class OneSixMigrationHelper implements IOneSixMigrationHelper {
stack.setTagCompound(tag.hasKey(NBT_ITEM_NBT) ? tag.getCompoundTag(NBT_ITEM_NBT) : null);
if (!stack.isEmpty()) {
newDisk.insert(stack, stack.getCount(), false);
newDisk.insert(stack, stack.getCount(), Action.PERFORM);
}
}
@@ -76,7 +77,7 @@ public class OneSixMigrationHelper implements IOneSixMigrationHelper {
FluidStack stack = FluidStack.loadFluidStackFromNBT(list.getCompoundTagAt(i));
if (stack != null) {
newDisk.insert(stack, stack.amount, false);
newDisk.insert(stack, stack.amount, Action.PERFORM);
}
}

View File

@@ -1,5 +1,7 @@
package com.raoulvdberge.refinedstorage.api.energy;
package com.raoulvdberge.refinedstorage.integration.forgeenergy;
import com.raoulvdberge.refinedstorage.api.energy.IEnergy;
import com.raoulvdberge.refinedstorage.api.util.Action;
import net.minecraftforge.energy.IEnergyStorage;
public final class EnergyProxy implements IEnergyStorage {
@@ -19,12 +21,12 @@ public final class EnergyProxy implements IEnergyStorage {
@Override
public int receiveEnergy(int maxReceive, boolean simulate) {
return !canReceive() ? 0 : this.energy.insert(Math.min(this.maxReceive, maxReceive), simulate);
return !canReceive() ? 0 : this.energy.insert(Math.min(this.maxReceive, maxReceive), simulate ? Action.SIMULATE : Action.PERFORM);
}
@Override
public int extractEnergy(int maxExtract, boolean simulate) {
return !canExtract() ? 0 : this.energy.extract(Math.min(this.maxExtract, maxExtract), simulate);
return !canExtract() ? 0 : this.energy.extract(Math.min(this.maxExtract, maxExtract), simulate ? Action.SIMULATE : Action.PERFORM);
}
@Override

View File

@@ -6,6 +6,7 @@ import com.raoulvdberge.refinedstorage.api.autocrafting.task.ICraftingTaskError;
import com.raoulvdberge.refinedstorage.api.network.node.INetworkNode;
import com.raoulvdberge.refinedstorage.api.storage.IStorage;
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDisk;
import com.raoulvdberge.refinedstorage.api.util.Action;
import com.raoulvdberge.refinedstorage.api.util.IComparer;
import com.raoulvdberge.refinedstorage.apiimpl.API;
import li.cil.oc.api.Network;
@@ -191,7 +192,7 @@ public class EnvironmentNetwork extends AbstractManagedEnvironment {
throw new IllegalArgumentException("No fluid tank on the given side");
}
FluidStack extractedSim = node.getNetwork().extractFluid(stack, amount, true);
FluidStack extractedSim = node.getNetwork().extractFluid(stack, amount, Action.SIMULATE);
if (extractedSim == null || extractedSim.amount <= 0) {
return new Object[]{null, "could not extract the specified fluid"};
}
@@ -204,7 +205,7 @@ public class EnvironmentNetwork extends AbstractManagedEnvironment {
}
// Actually do it and return how much fluid we've inserted
FluidStack extracted = node.getNetwork().extractFluid(stack, amount, false);
FluidStack extracted = node.getNetwork().extractFluid(stack, amount, Action.PERFORM);
handler.fill(extracted, true);
return new Object[]{filledAmountSim};
@@ -266,7 +267,7 @@ public class EnvironmentNetwork extends AbstractManagedEnvironment {
}
// Simulate extracting the item and get the amount of items that can be extracted
ItemStack extractedSim = node.getNetwork().extractItem(stack, count, true);
ItemStack extractedSim = node.getNetwork().extractItem(stack, count, Action.SIMULATE);
if (extractedSim.isEmpty() || extractedSim.getCount() == 0) {
return new Object[]{null, "could not extract the specified item"};
}
@@ -286,7 +287,7 @@ public class EnvironmentNetwork extends AbstractManagedEnvironment {
}
// Actually do it and return how many items we've inserted
ItemStack extracted = node.getNetwork().extractItem(stack, count, false);
ItemStack extracted = node.getNetwork().extractItem(stack, count, Action.PERFORM);
ItemHandlerHelper.insertItemStacked(handler, extracted, false);
return new Object[]{transferableAmount};

View File

@@ -3,6 +3,7 @@ package com.raoulvdberge.refinedstorage.network;
import com.raoulvdberge.refinedstorage.api.network.grid.GridType;
import com.raoulvdberge.refinedstorage.api.network.grid.IGridNetworkAware;
import com.raoulvdberge.refinedstorage.api.network.security.Permission;
import com.raoulvdberge.refinedstorage.api.util.Action;
import com.raoulvdberge.refinedstorage.apiimpl.network.node.NetworkNodeGrid;
import com.raoulvdberge.refinedstorage.container.ContainerGrid;
import com.raoulvdberge.refinedstorage.util.StackUtils;
@@ -41,7 +42,7 @@ public class MessageGridClear extends MessageHandlerPlayerToServer<MessageGridCl
ItemStack slot = matrix.getStackInSlot(i);
if (!slot.isEmpty()) {
matrix.setInventorySlotContents(i, StackUtils.nullToEmpty(grid.getNetwork().insertItem(slot, slot.getCount(), false)));
matrix.setInventorySlotContents(i, StackUtils.nullToEmpty(grid.getNetwork().insertItem(slot, slot.getCount(), Action.PERFORM)));
}
}
} else if (grid.getType() == GridType.PATTERN) {

View File

@@ -4,7 +4,6 @@ import com.google.common.base.Preconditions;
import com.raoulvdberge.refinedstorage.RS;
import com.raoulvdberge.refinedstorage.RSBlocks;
import com.raoulvdberge.refinedstorage.api.autocrafting.ICraftingManager;
import com.raoulvdberge.refinedstorage.api.energy.EnergyProxy;
import com.raoulvdberge.refinedstorage.api.energy.IEnergy;
import com.raoulvdberge.refinedstorage.api.network.INetwork;
import com.raoulvdberge.refinedstorage.api.network.INetworkNodeGraph;
@@ -21,6 +20,7 @@ import com.raoulvdberge.refinedstorage.api.storage.IStorage;
import com.raoulvdberge.refinedstorage.api.storage.IStorageCache;
import com.raoulvdberge.refinedstorage.api.storage.IStorageTracker;
import com.raoulvdberge.refinedstorage.api.storage.externalstorage.IStorageExternal;
import com.raoulvdberge.refinedstorage.api.util.Action;
import com.raoulvdberge.refinedstorage.apiimpl.autocrafting.CraftingManager;
import com.raoulvdberge.refinedstorage.apiimpl.energy.Energy;
import com.raoulvdberge.refinedstorage.apiimpl.network.NetworkNodeGraph;
@@ -37,6 +37,7 @@ import com.raoulvdberge.refinedstorage.block.BlockController;
import com.raoulvdberge.refinedstorage.block.ControllerEnergyType;
import com.raoulvdberge.refinedstorage.block.ControllerType;
import com.raoulvdberge.refinedstorage.capability.CapabilityNetworkNodeProxy;
import com.raoulvdberge.refinedstorage.integration.forgeenergy.EnergyProxy;
import com.raoulvdberge.refinedstorage.tile.config.IRedstoneConfigurable;
import com.raoulvdberge.refinedstorage.tile.config.RedstoneMode;
import com.raoulvdberge.refinedstorage.tile.data.RSSerializers;
@@ -211,8 +212,8 @@ public class TileController extends TileBase implements ITickable, INetwork, IRe
if (getType() == ControllerType.NORMAL) {
if (!RS.INSTANCE.config.controllerUsesEnergy) {
this.energy.setStored(this.energy.getCapacity());
} else if (this.energy.extract(getEnergyUsage(), true) >= 0) {
this.energy.extract(getEnergyUsage(), false);
} else if (this.energy.extract(getEnergyUsage(), Action.SIMULATE) >= 0) {
this.energy.extract(getEnergyUsage(), Action.PERFORM);
} else {
this.energy.setStored(0);
}
@@ -292,7 +293,7 @@ public class TileController extends TileBase implements ITickable, INetwork, IRe
}
@Override
public ItemStack insertItem(@Nonnull ItemStack stack, int size, boolean simulate) {
public ItemStack insertItem(@Nonnull ItemStack stack, int size, Action action) {
if (stack.isEmpty() || itemStorage.getStorages().isEmpty()) {
return ItemHandlerHelper.copyStackWithSize(stack, size);
}
@@ -309,15 +310,15 @@ public class TileController extends TileBase implements ITickable, INetwork, IRe
int storedPre = storage.getStored();
remainder = storage.insert(remainder, size, simulate);
remainder = storage.insert(remainder, size, action);
if (!simulate) {
if (action == Action.PERFORM) {
inserted += storage.getCacheDelta(storedPre, size, remainder);
}
if (remainder == null) {
// The external storage is responsible for sending changes, we don't need to anymore
if (storage instanceof IStorageExternal && !simulate) {
if (storage instanceof IStorageExternal && action == Action.PERFORM) {
((IStorageExternal) storage).update(this);
insertedExternally += size;
@@ -326,7 +327,7 @@ public class TileController extends TileBase implements ITickable, INetwork, IRe
break;
} else {
// The external storage is responsible for sending changes, we don't need to anymore
if (size != remainder.getCount() && storage instanceof IStorageExternal && !simulate) {
if (size != remainder.getCount() && storage instanceof IStorageExternal && action == Action.PERFORM) {
((IStorageExternal) storage).update(this);
insertedExternally += size - remainder.getCount();
@@ -336,7 +337,7 @@ public class TileController extends TileBase implements ITickable, INetwork, IRe
}
}
if (!simulate && inserted - insertedExternally > 0) {
if (action == Action.PERFORM && inserted - insertedExternally > 0) {
itemStorage.add(stack, inserted - insertedExternally, false, false);
}
@@ -344,7 +345,7 @@ public class TileController extends TileBase implements ITickable, INetwork, IRe
}
@Override
public ItemStack extractItem(@Nonnull ItemStack stack, int size, int flags, boolean simulate, Predicate<IStorage<ItemStack>> filter) {
public ItemStack extractItem(@Nonnull ItemStack stack, int size, int flags, Action action, Predicate<IStorage<ItemStack>> filter) {
int requested = size;
int received = 0;
@@ -356,12 +357,12 @@ public class TileController extends TileBase implements ITickable, INetwork, IRe
ItemStack took = null;
if (filter.test(storage) && storage.getAccessType() != AccessType.INSERT) {
took = storage.extract(stack, requested - received, flags, simulate);
took = storage.extract(stack, requested - received, flags, action);
}
if (took != null) {
// The external storage is responsible for sending changes, we don't need to anymore
if (storage instanceof IStorageExternal && !simulate) {
if (storage instanceof IStorageExternal && action == Action.PERFORM) {
((IStorageExternal) storage).update(this);
extractedExternally += took.getCount();
@@ -381,7 +382,7 @@ public class TileController extends TileBase implements ITickable, INetwork, IRe
}
}
if (newStack != null && newStack.getCount() - extractedExternally > 0 && !simulate) {
if (newStack != null && newStack.getCount() - extractedExternally > 0 && action == Action.PERFORM) {
itemStorage.remove(newStack, newStack.getCount() - extractedExternally, false);
}
@@ -390,7 +391,7 @@ public class TileController extends TileBase implements ITickable, INetwork, IRe
@Override
public FluidStack insertFluid(@Nonnull FluidStack stack, int size, boolean simulate) {
public FluidStack insertFluid(@Nonnull FluidStack stack, int size, Action action) {
if (stack == null || fluidStorage.getStorages().isEmpty()) {
return StackUtils.copy(stack, size);
}
@@ -407,15 +408,15 @@ public class TileController extends TileBase implements ITickable, INetwork, IRe
int storedPre = storage.getStored();
remainder = storage.insert(remainder, size, simulate);
remainder = storage.insert(remainder, size, action);
if (!simulate) {
if (action == Action.PERFORM) {
inserted += storage.getCacheDelta(storedPre, size, remainder);
}
if (remainder == null) {
// The external storage is responsible for sending changes, we don't need to anymore
if (storage instanceof IStorageExternal && !simulate) {
if (storage instanceof IStorageExternal && action == Action.PERFORM) {
((IStorageExternal) storage).update(this);
insertedExternally += size;
@@ -424,7 +425,7 @@ public class TileController extends TileBase implements ITickable, INetwork, IRe
break;
} else {
// The external storage is responsible for sending changes, we don't need to anymore
if (size != remainder.amount && storage instanceof IStorageExternal && !simulate) {
if (size != remainder.amount && storage instanceof IStorageExternal && action == Action.PERFORM) {
((IStorageExternal) storage).update(this);
insertedExternally += size - remainder.amount;
@@ -434,7 +435,7 @@ public class TileController extends TileBase implements ITickable, INetwork, IRe
}
}
if (!simulate && inserted - insertedExternally > 0) {
if (action == Action.PERFORM && inserted - insertedExternally > 0) {
fluidStorage.add(stack, inserted - insertedExternally, false, false);
}
@@ -442,7 +443,7 @@ public class TileController extends TileBase implements ITickable, INetwork, IRe
}
@Override
public FluidStack extractFluid(@Nonnull FluidStack stack, int size, int flags, boolean simulate) {
public FluidStack extractFluid(@Nonnull FluidStack stack, int size, int flags, Action action) {
int requested = size;
int received = 0;
@@ -454,12 +455,12 @@ public class TileController extends TileBase implements ITickable, INetwork, IRe
FluidStack took = null;
if (storage.getAccessType() != AccessType.INSERT) {
took = storage.extract(stack, requested - received, flags, simulate);
took = storage.extract(stack, requested - received, flags, action);
}
if (took != null) {
// The external storage is responsible for sending changes, we don't need to anymore
if (storage instanceof IStorageExternal && !simulate) {
if (storage instanceof IStorageExternal && action == Action.PERFORM) {
((IStorageExternal) storage).update(this);
extractedExternally += took.amount;
@@ -479,7 +480,7 @@ public class TileController extends TileBase implements ITickable, INetwork, IRe
}
}
if (newStack != null && newStack.amount - extractedExternally > 0 && !simulate) {
if (newStack != null && newStack.amount - extractedExternally > 0 && action == Action.PERFORM) {
fluidStorage.remove(newStack, newStack.amount - extractedExternally, false);
}