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; package com.raoulvdberge.refinedstorage.api.energy;
import com.raoulvdberge.refinedstorage.api.util.Action;
import java.util.UUID; import java.util.UUID;
public interface IEnergy { public interface IEnergy {
void decreaseCapacity(UUID id, int amount); void decreaseCapacity(UUID id, int amount);
int extract(int amount, boolean simulate); int extract(int amount, Action action);
int getCapacity(); int getCapacity();
@@ -13,7 +15,7 @@ public interface IEnergy {
void increaseCapacity(UUID id, int amount); void increaseCapacity(UUID id, int amount);
int insert(int amount, boolean simulate); int insert(int amount, Action action);
void setStored(int energyAmount); 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.IStorage;
import com.raoulvdberge.refinedstorage.api.storage.IStorageCache; import com.raoulvdberge.refinedstorage.api.storage.IStorageCache;
import com.raoulvdberge.refinedstorage.api.storage.IStorageTracker; import com.raoulvdberge.refinedstorage.api.storage.IStorageTracker;
import com.raoulvdberge.refinedstorage.api.util.Action;
import com.raoulvdberge.refinedstorage.api.util.IComparer; import com.raoulvdberge.refinedstorage.api.util.IComparer;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
@@ -53,7 +54,7 @@ public interface INetwork {
* @return the {@link ICraftingManager} of this network * @return the {@link ICraftingManager} of this network
*/ */
ICraftingManager getCraftingManager(); ICraftingManager getCraftingManager();
/** /**
* @return the {@link IEnergy} of this network * @return the {@link IEnergy} of this network
*/ */
@@ -92,13 +93,13 @@ public interface INetwork {
/** /**
* Inserts an item in this network. * Inserts an item in this network.
* *
* @param stack the stack prototype to insert, do NOT modify * @param stack the stack prototype to insert, do NOT modify
* @param size the amount of that prototype that has to be inserted * @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 * @return null if the insert was successful, or a stack with the remainder
*/ */
@Nullable @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. * 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 * @return null if the insert was successful, or a stack with the remainder
*/ */
default ItemStack insertItemTracked(@Nonnull ItemStack stack, int size) { 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()); int inserted = remainder == null ? size : (size - remainder.getCount());
@@ -120,74 +121,74 @@ public interface INetwork {
/** /**
* Extracts an item from this network. * Extracts an item from this network.
* *
* @param stack the prototype of the stack to extract, do NOT modify * @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 size the amount of that prototype that has to be extracted
* @param flags the flags to compare on, see {@link IComparer} * @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 * @param filter a filter for the storage
* @return null if we didn't extract anything, or a stack with the result * @return null if we didn't extract anything, or a stack with the result
*/ */
@Nullable @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. * Extracts an item from this network.
* *
* @param stack the prototype of the stack to extract, do NOT modify * @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 size the amount of that prototype that has to be extracted
* @param flags the flags to compare on, see {@link IComparer} * @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 * @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) { default ItemStack extractItem(@Nonnull ItemStack stack, int size, int flags, Action action) {
return extractItem(stack, size, flags, simulate, s -> true); return extractItem(stack, size, flags, action, s -> true);
} }
/** /**
* Extracts an item from this network. * Extracts an item from this network.
* *
* @param stack the prototype of the stack to extract, do NOT modify * @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 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 * @return null if we didn't extract anything, or a stack with the result
*/ */
default ItemStack extractItem(@Nonnull ItemStack stack, int size, boolean simulate) { default ItemStack extractItem(@Nonnull ItemStack stack, int size, Action action) {
return extractItem(stack, size, IComparer.COMPARE_DAMAGE | IComparer.COMPARE_NBT, simulate); return extractItem(stack, size, IComparer.COMPARE_DAMAGE | IComparer.COMPARE_NBT, action);
} }
/** /**
* Inserts a fluid in this network. * Inserts a fluid in this network.
* *
* @param stack the stack prototype to insert, do NOT modify * @param stack the stack prototype to insert, do NOT modify
* @param size the amount of that prototype that has to be inserted * @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 * @return null if the insert was successful, or a stack with the remainder
*/ */
@Nullable @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. * Extracts a fluid from this network.
* *
* @param stack the prototype of the stack to extract, do NOT modify * @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 size the amount of that prototype that has to be extracted
* @param flags the flags to compare on, see {@link IComparer} * @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 * @return null if we didn't extract anything, or a stack with the result
*/ */
@Nullable @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. * Extracts a fluid from this network.
* *
* @param stack the prototype of the stack to extract, do NOT modify * @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 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 * @return null if we didn't extract anything, or a stack with the result
*/ */
default FluidStack extractFluid(FluidStack stack, int size, boolean simulate) { default FluidStack extractFluid(FluidStack stack, int size, Action action) {
return extractFluid(stack, size, IComparer.COMPARE_NBT, simulate); return extractFluid(stack, size, IComparer.COMPARE_NBT, action);
} }
/** /**

View File

@@ -1,5 +1,6 @@
package com.raoulvdberge.refinedstorage.api.storage; package com.raoulvdberge.refinedstorage.api.storage;
import com.raoulvdberge.refinedstorage.api.util.Action;
import com.raoulvdberge.refinedstorage.api.util.IComparer; import com.raoulvdberge.refinedstorage.api.util.IComparer;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
@@ -22,27 +23,27 @@ public interface IStorage<T> {
/** /**
* Inserts a stack to this storage. * Inserts a stack to this storage.
* *
* @param stack the stack prototype to insert, do NOT modify * @param stack the stack prototype to insert, do NOT modify
* @param size the amount of that prototype that has to be inserted * @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 * @return null if the insert was successful, or a stack with the remainder
*/ */
@Nullable @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. * Extracts a stack from this storage.
* <p> * <p>
* If the stack we found in the system is smaller than the requested size, return that stack anyway. * If the stack we found in the system is smaller than the requested size, return that stack anyway.
* *
* @param stack a prototype of the stack to extract, do NOT modify * @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 size the amount of that prototype that has to be extracted
* @param flags the flags to compare on, see {@link IComparer} * @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 * @return null if we didn't extract anything, or a stack with the result
*/ */
@Nullable @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 * @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.autocrafting.task.CraftingTaskReadException;
import com.raoulvdberge.refinedstorage.api.network.INetwork; 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.apiimpl.autocrafting.task.CraftingTask;
import com.raoulvdberge.refinedstorage.util.StackUtils; import com.raoulvdberge.refinedstorage.util.StackUtils;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
@@ -70,7 +71,7 @@ public class CraftingExtractor {
if (status.get(i) != CraftingExtractorItemStatus.EXTRACTED) { if (status.get(i) != CraftingExtractorItemStatus.EXTRACTED) {
ItemStack stack = items.get(i); 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); CraftingExtractorItemStatus previousStatus = status.get(i);
@@ -112,7 +113,7 @@ public class CraftingExtractor {
for (int i = 0; i < items.size(); ++i) { for (int i = 0; i < items.size(); ++i) {
if (status.get(i) == CraftingExtractorItemStatus.AVAILABLE) { 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) { if (extracted == null) {
throw new IllegalStateException("Did not extract anything while available"); 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.autocrafting.task.CraftingTaskReadException;
import com.raoulvdberge.refinedstorage.api.network.INetwork; import com.raoulvdberge.refinedstorage.api.network.INetwork;
import com.raoulvdberge.refinedstorage.api.util.Action;
import com.raoulvdberge.refinedstorage.util.StackUtils; import com.raoulvdberge.refinedstorage.util.StackUtils;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
@@ -52,8 +53,8 @@ public class CraftingInserter {
if (item != null) { if (item != null) {
CraftingInserterItemStatus currentStatus = item.getStatus(); CraftingInserterItemStatus currentStatus = item.getStatus();
if (network.insertItem(item.getStack(), item.getStack().getCount(), true) == null) { if (network.insertItem(item.getStack(), item.getStack().getCount(), Action.SIMULATE) == null) {
ItemStack inserted = network.insertItem(item.getStack(), item.getStack().getCount(), false); ItemStack inserted = network.insertItem(item.getStack(), item.getStack().getCount(), Action.PERFORM);
if (inserted != null) { if (inserted != null) {
throw new IllegalStateException("Could not insert item"); throw new IllegalStateException("Could not insert item");
} }
@@ -73,7 +74,7 @@ public class CraftingInserter {
while (!items.isEmpty()) { while (!items.isEmpty()) {
CraftingInserterItem item = items.pop(); CraftingInserterItem item = items.pop();
network.insertItem(item.getStack(), item.getStack().getCount(), false); network.insertItem(item.getStack(), item.getStack().getCount(), Action.PERFORM);
} }
network.getCraftingManager().onTaskChanged(); network.getCraftingManager().onTaskChanged();

View File

@@ -1,14 +1,14 @@
package com.raoulvdberge.refinedstorage.apiimpl.energy; 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.Map;
import java.util.UUID; import java.util.UUID;
import com.raoulvdberge.refinedstorage.api.energy.IEnergy;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
public final class Energy implements IEnergy { 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 capacity;
protected int energy; protected int energy;
@@ -16,35 +16,41 @@ public final class Energy implements IEnergy {
private final Map<UUID, Integer> energyStorages; private final Map<UUID, Integer> energyStorages;
public Energy(int controllerCapacity) { public Energy(int controllerCapacity) {
this.energyStorages = new Object2ObjectOpenHashMap<UUID, Integer>(); this.energyStorages = new Object2ObjectOpenHashMap<>();
this.energyStorages.put(UUID_EMPTY, controllerCapacity); this.energyStorages.put(DEFAULT_UUID, controllerCapacity);
calculateCapacity(); calculateCapacity();
} }
private void calculateCapacity() { private void calculateCapacity() {
long newCapacity = energyStorages.values().stream().mapToLong(Long::valueOf).sum(); long newCapacity = energyStorages.values().stream().mapToLong(Long::valueOf).sum();
this.capacity = (int) Math.min(newCapacity, Integer.MAX_VALUE); this.capacity = (int) Math.min(newCapacity, Integer.MAX_VALUE);
} }
@Override @Override
public void decreaseCapacity(UUID id, int amount) { public void decreaseCapacity(UUID id, int amount) {
if (id.equals(UUID_EMPTY)) { if (id.equals(DEFAULT_UUID)) {
return; return;
} }
this.energyStorages.remove(id); this.energyStorages.remove(id);
calculateCapacity(); calculateCapacity();
} }
@Override @Override
public int extract(int maxExtract, boolean simulate) { public int extract(int maxExtract, Action action) {
if (maxExtract <= 0) { if (maxExtract <= 0) {
return 0; return 0;
} }
int energyExtracted = Math.min(energy, maxExtract); int energyExtracted = Math.min(energy, maxExtract);
if (!simulate) {
if (action == Action.PERFORM) {
energy -= energyExtracted; energy -= energyExtracted;
} }
return energyExtracted; return energyExtracted;
} }
@@ -60,23 +66,27 @@ public final class Energy implements IEnergy {
@Override @Override
public void increaseCapacity(UUID id, int amount) { public void increaseCapacity(UUID id, int amount) {
if (id.equals(UUID_EMPTY) || amount <= 0) { if (id.equals(DEFAULT_UUID) || amount <= 0) {
return; return;
} }
this.energyStorages.merge(id, amount, (k, v) -> amount); this.energyStorages.merge(id, amount, (k, v) -> amount);
calculateCapacity(); calculateCapacity();
} }
@Override @Override
public int insert (int maxReceive, boolean simulate) { public int insert(int maxReceive, Action action) {
if (maxReceive <= 0) { if (maxReceive <= 0) {
return 0; return 0;
} }
int energyReceived = Math.min(capacity - energy, maxReceive); int energyReceived = Math.min(capacity - energy, maxReceive);
if (!simulate) {
if (action == Action.PERFORM) {
energy += energyReceived; energy += energyReceived;
} }
return 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.INetworkItem;
import com.raoulvdberge.refinedstorage.api.network.item.NetworkItemAction; import com.raoulvdberge.refinedstorage.api.network.item.NetworkItemAction;
import com.raoulvdberge.refinedstorage.api.network.security.Permission; 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.apiimpl.API;
import com.raoulvdberge.refinedstorage.util.StackUtils; import com.raoulvdberge.refinedstorage.util.StackUtils;
import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.entity.player.EntityPlayerMP;
@@ -49,7 +50,7 @@ public class FluidGridHandler implements IFluidGridHandler {
} }
if (bucket == null) { if (bucket == null) {
bucket = network.extractItem(StackUtils.EMPTY_BUCKET, 1, false); bucket = network.extractItem(StackUtils.EMPTY_BUCKET, 1, Action.PERFORM);
} }
if (bucket != null) { if (bucket != null) {
@@ -57,7 +58,7 @@ public class FluidGridHandler implements IFluidGridHandler {
network.getFluidStorageTracker().changed(player, stack.copy()); 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 (shift) {
if (!player.inventory.addItemStackToInventory(fluidHandler.getContainer().copy())) { if (!player.inventory.addItemStackToInventory(fluidHandler.getContainer().copy())) {
@@ -86,12 +87,12 @@ public class FluidGridHandler implements IFluidGridHandler {
Pair<ItemStack, FluidStack> result = StackUtils.getFluid(container, true); 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()); network.getFluidStorageTracker().changed(player, result.getValue().copy());
result = StackUtils.getFluid(container, false); 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); 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.INetworkItem;
import com.raoulvdberge.refinedstorage.api.network.item.NetworkItemAction; import com.raoulvdberge.refinedstorage.api.network.item.NetworkItemAction;
import com.raoulvdberge.refinedstorage.api.network.security.Permission; 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.api.util.IStackList;
import com.raoulvdberge.refinedstorage.apiimpl.API; import com.raoulvdberge.refinedstorage.apiimpl.API;
import com.raoulvdberge.refinedstorage.apiimpl.autocrafting.preview.CraftingPreviewElementError; 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) // 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()); 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 (took != null) {
if ((flags & EXTRACT_SHIFT) == EXTRACT_SHIFT) { if ((flags & EXTRACT_SHIFT) == EXTRACT_SHIFT) {
IItemHandler playerInventory = player.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.UP); IItemHandler playerInventory = player.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.UP);
if (ItemHandlerHelper.insertItem(playerInventory, took, true).isEmpty()) { 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); ItemHandlerHelper.insertItem(playerInventory, took, false);
} }
} else { } else {
took = network.extractItem(item, size, false); took = network.extractItem(item, size, Action.PERFORM);
if (single && !held.isEmpty()) { if (single && !held.isEmpty()) {
held.grow(1); held.grow(1);
@@ -119,7 +120,7 @@ public class ItemGridHandler implements IItemGridHandler {
network.getItemStorageTracker().changed(player, stack.copy()); 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); INetworkItem networkItem = network.getNetworkItemHandler().getItem(player);
@@ -142,8 +143,8 @@ public class ItemGridHandler implements IItemGridHandler {
network.getItemStorageTracker().changed(player, stack.copy()); network.getItemStorageTracker().changed(player, stack.copy());
if (single) { if (single) {
if (network.insertItem(stack, size, true) == null) { if (network.insertItem(stack, size, Action.SIMULATE) == null) {
network.insertItem(stack, size, false); network.insertItem(stack, size, Action.PERFORM);
stack.shrink(size); stack.shrink(size);
@@ -152,7 +153,7 @@ public class ItemGridHandler implements IItemGridHandler {
} }
} }
} else { } else {
player.inventory.setItemStack(StackUtils.nullToEmpty(network.insertItem(stack, size, false))); player.inventory.setItemStack(StackUtils.nullToEmpty(network.insertItem(stack, size, Action.PERFORM)));
} }
player.updateHeldItem(); 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.RS;
import com.raoulvdberge.refinedstorage.api.network.grid.IGrid; import com.raoulvdberge.refinedstorage.api.network.grid.IGrid;
import com.raoulvdberge.refinedstorage.api.network.grid.handler.IItemGridHandler; 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.api.util.IComparer;
import com.raoulvdberge.refinedstorage.apiimpl.API; import com.raoulvdberge.refinedstorage.apiimpl.API;
import com.raoulvdberge.refinedstorage.tile.grid.portable.IPortableGrid; 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) // 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()); 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 (took != null) {
if ((flags & EXTRACT_SHIFT) == EXTRACT_SHIFT) { if ((flags & EXTRACT_SHIFT) == EXTRACT_SHIFT) {
IItemHandler playerInventory = player.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.UP); IItemHandler playerInventory = player.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.UP);
if (ItemHandlerHelper.insertItem(playerInventory, took, true).isEmpty()) { 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); ItemHandlerHelper.insertItem(playerInventory, took, false);
} }
} else { } 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()) { if (single && !held.isEmpty()) {
held.grow(1); held.grow(1);
@@ -113,7 +114,7 @@ public class ItemGridHandlerPortable implements IItemGridHandler {
portableGrid.getStorageTracker().changed(player, stack.copy()); 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); portableGrid.drainEnergy(RS.INSTANCE.config.portableGridInsertUsage);
@@ -132,8 +133,8 @@ public class ItemGridHandlerPortable implements IItemGridHandler {
portableGrid.getStorageTracker().changed(player, stack.copy()); portableGrid.getStorageTracker().changed(player, stack.copy());
if (single) { if (single) {
if (portableGrid.getStorage().insert(stack, size, true) == null) { if (portableGrid.getStorage().insert(stack, size, Action.SIMULATE) == null) {
portableGrid.getStorage().insert(stack, size, false); portableGrid.getStorage().insert(stack, size, Action.PERFORM);
stack.shrink(size); stack.shrink(size);
@@ -142,7 +143,7 @@ public class ItemGridHandlerPortable implements IItemGridHandler {
} }
} }
} else { } 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(); player.updateHeldItem();

View File

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

View File

@@ -1,6 +1,7 @@
package com.raoulvdberge.refinedstorage.apiimpl.network.node; package com.raoulvdberge.refinedstorage.apiimpl.network.node;
import com.raoulvdberge.refinedstorage.RS; import com.raoulvdberge.refinedstorage.RS;
import com.raoulvdberge.refinedstorage.api.util.Action;
import com.raoulvdberge.refinedstorage.api.util.IComparer; import com.raoulvdberge.refinedstorage.api.util.IComparer;
import com.raoulvdberge.refinedstorage.apiimpl.util.OneSixMigrationHelper; import com.raoulvdberge.refinedstorage.apiimpl.util.OneSixMigrationHelper;
import com.raoulvdberge.refinedstorage.inventory.ItemHandlerBase; import com.raoulvdberge.refinedstorage.inventory.ItemHandlerBase;
@@ -92,7 +93,7 @@ public class NetworkNodeDestructor extends NetworkNode implements IComparable, I
if (entity instanceof EntityItem) { if (entity instanceof EntityItem) {
ItemStack droppedItem = ((EntityItem) entity).getItem(); 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()); network.insertItemTracked(droppedItem.copy(), droppedItem.getCount());
world.removeEntity(entity); world.removeEntity(entity);
@@ -134,7 +135,7 @@ public class NetworkNodeDestructor extends NetworkNode implements IComparable, I
} }
for (ItemStack drop : drops) { for (ItemStack drop : drops) {
if (network.insertItem(drop, drop.getCount(), true) != null) { if (network.insertItem(drop, drop.getCount(), Action.SIMULATE) != null) {
return; return;
} }
} }
@@ -171,10 +172,10 @@ public class NetworkNodeDestructor extends NetworkNode implements IComparable, I
if (handler != null) { if (handler != null) {
FluidStack stack = handler.drain(Fluid.BUCKET_VOLUME, false); 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); 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; package com.raoulvdberge.refinedstorage.apiimpl.network.node;
import com.raoulvdberge.refinedstorage.RS; import com.raoulvdberge.refinedstorage.RS;
import com.raoulvdberge.refinedstorage.api.util.Action;
import com.raoulvdberge.refinedstorage.api.util.IComparer; import com.raoulvdberge.refinedstorage.api.util.IComparer;
import com.raoulvdberge.refinedstorage.inventory.ItemHandlerBase; import com.raoulvdberge.refinedstorage.inventory.ItemHandlerBase;
import com.raoulvdberge.refinedstorage.inventory.ItemHandlerFluid; import com.raoulvdberge.refinedstorage.inventory.ItemHandlerFluid;
@@ -73,14 +74,14 @@ public class NetworkNodeExporter extends NetworkNode implements IComparable, ITy
if (!slot.isEmpty()) { if (!slot.isEmpty()) {
int stackSize = upgrades.getItemInteractCount(); 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 (took == null) {
if (upgrades.hasUpgrade(ItemUpgrade.TYPE_CRAFTING)) { if (upgrades.hasUpgrade(ItemUpgrade.TYPE_CRAFTING)) {
network.getCraftingManager().schedule(slot, stackSize); network.getCraftingManager().schedule(slot, stackSize);
} }
} else if (ItemHandlerHelper.insertItem(handler, took, true).isEmpty()) { } 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) { if (took != null) {
ItemHandlerHelper.insertItem(handler, took, false); ItemHandlerHelper.insertItem(handler, took, false);
@@ -116,13 +117,13 @@ public class NetworkNodeExporter extends NetworkNode implements IComparable, ITy
if (stackInStorage != null) { if (stackInStorage != null) {
int toExtract = Math.min(Fluid.BUCKET_VOLUME * upgrades.getItemInteractCount(), stackInStorage.amount); 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) { if (took != null) {
int filled = handler.fill(took, false); int filled = handler.fill(took, false);
if (filled > 0) { if (filled > 0) {
took = network.extractFluid(stack, filled, compare, false); took = network.extractFluid(stack, filled, compare, Action.PERFORM);
handler.fill(took, true); handler.fill(took, true);
} }

View File

@@ -1,6 +1,7 @@
package com.raoulvdberge.refinedstorage.apiimpl.network.node; package com.raoulvdberge.refinedstorage.apiimpl.network.node;
import com.raoulvdberge.refinedstorage.RS; import com.raoulvdberge.refinedstorage.RS;
import com.raoulvdberge.refinedstorage.api.util.Action;
import com.raoulvdberge.refinedstorage.api.util.IComparer; import com.raoulvdberge.refinedstorage.api.util.IComparer;
import com.raoulvdberge.refinedstorage.inventory.*; import com.raoulvdberge.refinedstorage.inventory.*;
import com.raoulvdberge.refinedstorage.item.ItemUpgrade; import com.raoulvdberge.refinedstorage.item.ItemUpgrade;
@@ -95,7 +96,7 @@ public class NetworkNodeFluidInterface extends NetworkNode implements IComparabl
// Drain in tank // Drain in tank
if (drained != null) { if (drained != null) {
FluidStack remainder = network.insertFluid(drained, drained.amount, false); FluidStack remainder = network.insertFluid(drained, drained.amount, Action.PERFORM);
if (remainder != null) { if (remainder != null) {
tankIn.fillInternal(remainder, true); 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); FluidStack remainder = tankOut.drainInternal(Fluid.BUCKET_VOLUME * upgrades.getItemInteractCount(), true);
if (remainder != null) { if (remainder != null) {
network.insertFluid(remainder, remainder.amount, false); network.insertFluid(remainder, remainder.amount, Action.PERFORM);
} }
} else if (stack != null) { } else if (stack != null) {
// Fill the out fluid // Fill the out fluid
@@ -128,10 +129,10 @@ public class NetworkNodeFluidInterface extends NetworkNode implements IComparabl
return; 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) { 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); 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.network.security.Permission;
import com.raoulvdberge.refinedstorage.api.storage.IStorageCache; import com.raoulvdberge.refinedstorage.api.storage.IStorageCache;
import com.raoulvdberge.refinedstorage.api.storage.IStorageCacheListener; 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.IComparer;
import com.raoulvdberge.refinedstorage.api.util.IFilter; import com.raoulvdberge.refinedstorage.api.util.IFilter;
import com.raoulvdberge.refinedstorage.apiimpl.API; import com.raoulvdberge.refinedstorage.apiimpl.API;
@@ -212,7 +213,7 @@ public class NetworkNodeGrid extends NetworkNode implements IGridNetworkAware {
if (type == null) { if (type == null) {
IBlockState state = world.getBlockState(pos); IBlockState state = world.getBlockState(pos);
if (state.getBlock() == RSBlocks.GRID) { if (state.getBlock() == RSBlocks.GRID) {
type = (GridType) state.getValue(BlockGrid.TYPE); type = (GridType) state.getValue(BlockGrid.TYPE);
} }
} }
@@ -327,10 +328,10 @@ public class NetworkNodeGrid extends NetworkNode implements IGridNetworkAware {
if (grid.getType() == GridType.CRAFTING) { if (grid.getType() == GridType.CRAFTING) {
// If we are connected, try to insert into network. If it fails, stop. // If we are connected, try to insert into network. If it fails, stop.
if (network != null) { if (network != null) {
if (network.insertItem(slot, slot.getCount(), true) != null) { if (network.insertItem(slot, slot.getCount(), Action.SIMULATE) != null) {
return; return;
} else { } else {
network.insertItem(slot, slot.getCount(), false); network.insertItem(slot, slot.getCount(), Action.PERFORM);
} }
} else { } else {
// If we aren't connected, try to insert into player inventory. If it fails, stop. // 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 we are connected, first try to get the possibilities from the network
if (network != null) { if (network != null) {
for (ItemStack possibility : possibilities) { 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) { if (took != null) {
grid.getCraftingMatrix().setInventorySlotContents(i, StackUtils.nullToEmpty(took)); 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 there is no space for the remainder, dump it in the player inventory
if (!slot.isEmpty() && slot.getCount() > 1) { if (!slot.isEmpty() && slot.getCount() > 1) {
if (!player.inventory.addItemStackToInventory(remainder.get(i).copy())) { 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) { if (remainderStack != null) {
InventoryHelper.spawnItemStack(player.getEntityWorld(), player.getPosition().getX(), player.getPosition().getY(), player.getPosition().getZ(), remainderStack); 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()) { } else if (!slot.isEmpty()) {
if (slot.getCount() == 1 && network != null) { 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 { } else {
matrix.decrStackSize(i, 1); matrix.decrStackSize(i, 1);
} }
@@ -487,7 +488,7 @@ public class NetworkNodeGrid extends NetworkNode implements IGridNetworkAware {
for (ItemStack craftedItem : craftedItemsList) { for (ItemStack craftedItem : craftedItemsList) {
if (!player.inventory.addItemStackToInventory(craftedItem.copy())) { 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) { if (remainder != null) {
InventoryHelper.spawnItemStack(player.getEntityWorld(), player.getPosition().getX(), player.getPosition().getY(), player.getPosition().getZ(), remainder); 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; package com.raoulvdberge.refinedstorage.apiimpl.network.node;
import com.raoulvdberge.refinedstorage.RS; import com.raoulvdberge.refinedstorage.RS;
import com.raoulvdberge.refinedstorage.api.util.Action;
import com.raoulvdberge.refinedstorage.api.util.IComparer; import com.raoulvdberge.refinedstorage.api.util.IComparer;
import com.raoulvdberge.refinedstorage.apiimpl.util.OneSixMigrationHelper; import com.raoulvdberge.refinedstorage.apiimpl.util.OneSixMigrationHelper;
import com.raoulvdberge.refinedstorage.inventory.ItemHandlerBase; import com.raoulvdberge.refinedstorage.inventory.ItemHandlerBase;
@@ -84,7 +85,7 @@ public class NetworkNodeImporter extends NetworkNode implements IComparable, IFi
} else if (ticks % upgrades.getSpeed() == 0) { } else if (ticks % upgrades.getSpeed() == 0) {
ItemStack result = handler.extractItem(currentSlot, upgrades.getItemInteractCount(), true); 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); result = handler.extractItem(currentSlot, upgrades.getItemInteractCount(), false);
if (!result.isEmpty()) { if (!result.isEmpty()) {
@@ -101,11 +102,11 @@ public class NetworkNodeImporter extends NetworkNode implements IComparable, IFi
if (handler != null) { if (handler != null) {
FluidStack stack = handler.drain(Fluid.BUCKET_VOLUME, false); 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); FluidStack toDrain = handler.drain(Fluid.BUCKET_VOLUME * upgrades.getItemInteractCount(), false);
if (toDrain != null) { if (toDrain != null) {
FluidStack remainder = network.insertFluid(toDrain, toDrain.amount, false); FluidStack remainder = network.insertFluid(toDrain, toDrain.amount, Action.PERFORM);
if (remainder != null) { if (remainder != null) {
toDrain.amount -= remainder.amount; toDrain.amount -= remainder.amount;
} }

View File

@@ -1,6 +1,7 @@
package com.raoulvdberge.refinedstorage.apiimpl.network.node; package com.raoulvdberge.refinedstorage.apiimpl.network.node;
import com.raoulvdberge.refinedstorage.RS; import com.raoulvdberge.refinedstorage.RS;
import com.raoulvdberge.refinedstorage.api.util.Action;
import com.raoulvdberge.refinedstorage.api.util.IComparer; import com.raoulvdberge.refinedstorage.api.util.IComparer;
import com.raoulvdberge.refinedstorage.apiimpl.API; import com.raoulvdberge.refinedstorage.apiimpl.API;
import com.raoulvdberge.refinedstorage.apiimpl.autocrafting.CraftingRequester; 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()); int delta = got.isEmpty() ? wanted.getCount() : (wanted.getCount() - got.getCount());
if (delta > 0) { 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 (result != null) {
if (exportItems.getStackInSlot(i).isEmpty()) { if (exportItems.getStackInSlot(i).isEmpty()) {

View File

@@ -1,6 +1,7 @@
package com.raoulvdberge.refinedstorage.apiimpl.network.node; package com.raoulvdberge.refinedstorage.apiimpl.network.node;
import com.raoulvdberge.refinedstorage.api.network.security.Permission; 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.api.util.IComparer;
import com.raoulvdberge.refinedstorage.apiimpl.API; import com.raoulvdberge.refinedstorage.apiimpl.API;
import com.raoulvdberge.refinedstorage.inventory.ItemHandlerBase; import com.raoulvdberge.refinedstorage.inventory.ItemHandlerBase;
@@ -144,7 +145,7 @@ public class NetworkNodeStorageMonitor extends NetworkNode implements IComparabl
int toExtract = player.isSneaking() ? 1 : 64; int toExtract = player.isSneaking() ? 1 : 64;
if (!filter.isEmpty()) { if (!filter.isEmpty()) {
ItemStack result = network.extractItem(filter, toExtract, compare, false); ItemStack result = network.extractItem(filter, toExtract, compare, Action.PERFORM);
if (result != null) { if (result != null) {
if (!player.inventory.addItemStackToInventory(result.copy())) { 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.IStorageDisk;
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskContainerContext; import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskContainerContext;
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskListener; 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.TileDiskDrive;
import com.raoulvdberge.refinedstorage.tile.config.IFilterable; import com.raoulvdberge.refinedstorage.tile.config.IFilterable;
import com.raoulvdberge.refinedstorage.util.StackUtils; import com.raoulvdberge.refinedstorage.util.StackUtils;
@@ -55,18 +56,18 @@ public class StorageDiskFluidDriveWrapper implements IStorageDisk<FluidStack> {
@Override @Override
@Nullable @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)) { if (!IFilterable.acceptsFluid(diskDrive.getFluidFilters(), diskDrive.getMode(), diskDrive.getCompare(), stack)) {
return StackUtils.copy(stack, size); return StackUtils.copy(stack, size);
} }
return parent.insert(stack, size, simulate); return parent.insert(stack, size, action);
} }
@Nullable @Nullable
@Override @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) {
return parent.extract(stack, size, flags, simulate); return parent.extract(stack, size, flags, action);
} }
@Override @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.IStorageDisk;
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskContainerContext; import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskContainerContext;
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskListener; 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.TileDiskDrive;
import com.raoulvdberge.refinedstorage.tile.config.IFilterable; import com.raoulvdberge.refinedstorage.tile.config.IFilterable;
import com.raoulvdberge.refinedstorage.util.WorldUtils; import com.raoulvdberge.refinedstorage.util.WorldUtils;
@@ -55,18 +56,18 @@ public class StorageDiskItemDriveWrapper implements IStorageDisk<ItemStack> {
@Override @Override
@Nullable @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)) { if (!IFilterable.acceptsItem(diskDrive.getItemFilters(), diskDrive.getMode(), diskDrive.getCompare(), stack)) {
return ItemHandlerHelper.copyStackWithSize(stack, size); return ItemHandlerHelper.copyStackWithSize(stack, size);
} }
return parent.insert(stack, size, simulate); return parent.insert(stack, size, action);
} }
@Nullable @Nullable
@Override @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) {
return parent.extract(stack, size, flags, simulate); return parent.extract(stack, size, flags, action);
} }
@Override @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.AccessType;
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDisk; import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDisk;
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskContainerContext; 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.api.util.IComparer;
import com.raoulvdberge.refinedstorage.apiimpl.API; import com.raoulvdberge.refinedstorage.apiimpl.API;
import com.raoulvdberge.refinedstorage.apiimpl.network.node.NetworkNode; import com.raoulvdberge.refinedstorage.apiimpl.network.node.NetworkNode;
@@ -134,7 +135,7 @@ public class NetworkNodeDiskManipulator extends NetworkNode implements IComparab
int slot = 0; int slot = 0;
if (type == IType.ITEMS) { 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++; slot++;
} }
@@ -150,7 +151,7 @@ public class NetworkNodeDiskManipulator extends NetworkNode implements IComparab
extractItemFromNetwork(storage, slot); extractItemFromNetwork(storage, slot);
} }
} else if (type == IType.FLUIDS) { } 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++; slot++;
} }
@@ -173,29 +174,29 @@ public class NetworkNodeDiskManipulator extends NetworkNode implements IComparab
for (int i = 0; i < stacks.size(); ++i) { for (int i = 0; i < stacks.size(); ++i) {
ItemStack stack = stacks.get(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) { if (extracted == null) {
continue; continue;
} }
ItemStack remainder = network.insertItem(extracted, extracted.getCount(), false); ItemStack remainder = network.insertItem(extracted, extracted.getCount(), Action.PERFORM);
if (remainder == null) { if (remainder == null) {
break; break;
} }
// We need to check if the stack was inserted // 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. // 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) { if (ioMode == IO_MODE_INSERT && storage.getStored() == 0) {
moveDriveToOutput(slot); moveDriveToOutput(slot);
return true; return true;
} }
//In Extract mode, we just need to check if the disk is full or not. // In Extract mode, we just need to check if the disk is full or not.
if (ioMode == IO_MODE_EXTRACT) if (ioMode == IO_MODE_EXTRACT)
if (storage.getStored() == storage.getCapacity()) { if (storage.getStored() == storage.getCapacity()) {
moveDriveToOutput(slot); moveDriveToOutput(slot);
@@ -208,12 +209,12 @@ public class NetworkNodeDiskManipulator extends NetworkNode implements IComparab
for (int i = 0; i < stacks.size(); ++i) { for (int i = 0; i < stacks.size(); ++i) {
ItemStack stack = stacks.get(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) { if (extracted == null) {
continue; 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. if (remainder == null) { //An item could be inserted (no remainders when trying to). This disk isn't done.
return false; return false;
} }
@@ -236,7 +237,7 @@ public class NetworkNodeDiskManipulator extends NetworkNode implements IComparab
} }
if (toExtract != null) { if (toExtract != null) {
extracted = network.extractItem(toExtract, upgrades.getItemInteractCount(), compare, false); extracted = network.extractItem(toExtract, upgrades.getItemInteractCount(), compare, Action.PERFORM);
} }
} else { } else {
while (itemFilters.getSlots() > i && extracted == null) { while (itemFilters.getSlots() > i && extracted == null) {
@@ -247,7 +248,7 @@ public class NetworkNodeDiskManipulator extends NetworkNode implements IComparab
} }
if (!filterStack.isEmpty()) { 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; return;
} }
ItemStack remainder = storage.insert(extracted, extracted.getCount(), false); ItemStack remainder = storage.insert(extracted, extracted.getCount(), Action.PERFORM);
if (remainder != null) { 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) { while (extracted == null && stacks.size() > i) {
FluidStack stack = stacks.get(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) { if (extracted == null) {
@@ -281,14 +282,14 @@ public class NetworkNodeDiskManipulator extends NetworkNode implements IComparab
return; return;
} }
FluidStack remainder = network.insertFluid(extracted, extracted.amount, false); FluidStack remainder = network.insertFluid(extracted, extracted.amount, Action.PERFORM);
if (remainder != null) { 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) { if (ioMode == IO_MODE_INSERT && storage.getStored() == 0) {
moveDriveToOutput(slot); moveDriveToOutput(slot);
return true; return true;
@@ -307,13 +308,13 @@ public class NetworkNodeDiskManipulator extends NetworkNode implements IComparab
for (int i = 0; i < stacks.size(); ++i) { for (int i = 0; i < stacks.size(); ++i) {
FluidStack stack = stacks.get(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) { if (extracted == null) {
continue; 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. if (remainder == null) { // A fluid could be inserted (no remainders when trying to). This disk isn't done.
return false; return false;
} }
} }
@@ -335,7 +336,7 @@ public class NetworkNodeDiskManipulator extends NetworkNode implements IComparab
} }
if (toExtract != null) { if (toExtract != null) {
extracted = network.extractFluid(toExtract, upgrades.getItemInteractCount(), compare, false); extracted = network.extractFluid(toExtract, upgrades.getItemInteractCount(), compare, Action.PERFORM);
} }
} else { } else {
while (fluidFilters.getSlots() > i && extracted == null) { while (fluidFilters.getSlots() > i && extracted == null) {
@@ -346,7 +347,7 @@ public class NetworkNodeDiskManipulator extends NetworkNode implements IComparab
} }
if (filterStack != null) { 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; return;
} }
FluidStack remainder = storage.insert(extracted, extracted.amount, false); FluidStack remainder = storage.insert(extracted, extracted.amount, Action.PERFORM);
if (remainder != null) { 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.IStorageDisk;
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskContainerContext; import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskContainerContext;
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskListener; 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.TileDiskDrive;
import com.raoulvdberge.refinedstorage.tile.config.IFilterable; import com.raoulvdberge.refinedstorage.tile.config.IFilterable;
import com.raoulvdberge.refinedstorage.util.StackUtils; import com.raoulvdberge.refinedstorage.util.StackUtils;
@@ -65,22 +66,22 @@ public class StorageDiskFluidManipulatorWrapper implements IStorageDisk<FluidSta
@Override @Override
@Nullable @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)) { if (!IFilterable.acceptsFluid(diskManipulator.getFluidFilters(), diskManipulator.getMode(), diskManipulator.getCompare(), stack)) {
return StackUtils.copy(stack, size); return StackUtils.copy(stack, size);
} }
return parent.insert(stack, size, simulate); return parent.insert(stack, size, action);
} }
@Override @Override
@Nullable @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)) { if (!IFilterable.acceptsFluid(diskManipulator.getFluidFilters(), diskManipulator.getMode(), diskManipulator.getCompare(), stack)) {
return null; return null;
} }
return parent.extract(stack, size, flags, simulate); return parent.extract(stack, size, flags, action);
} }
@Override @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.IStorageDisk;
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskContainerContext; import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskContainerContext;
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskListener; 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.TileDiskDrive;
import com.raoulvdberge.refinedstorage.tile.config.IFilterable; import com.raoulvdberge.refinedstorage.tile.config.IFilterable;
import com.raoulvdberge.refinedstorage.util.WorldUtils; import com.raoulvdberge.refinedstorage.util.WorldUtils;
@@ -60,22 +61,22 @@ public class StorageDiskItemManipulatorWrapper implements IStorageDisk<ItemStack
@Override @Override
@Nullable @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)) { if (!IFilterable.acceptsItem(diskManipulator.getItemFilters(), diskManipulator.getMode(), diskManipulator.getCompare(), stack)) {
return ItemHandlerHelper.copyStackWithSize(stack, size); return ItemHandlerHelper.copyStackWithSize(stack, size);
} }
return parent.insert(stack, size, simulate); return parent.insert(stack, size, action);
} }
@Override @Override
@Nullable @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)) { if (!IFilterable.acceptsItem(diskManipulator.getItemFilters(), diskManipulator.getMode(), diskManipulator.getCompare(), stack)) {
return null; return null;
} }
return parent.extract(stack, size, flags, simulate); return parent.extract(stack, size, flags, action);
} }
@Override @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.IStorageDisk;
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskContainerContext; import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskContainerContext;
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskListener; 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.tile.config.IFilterable;
import com.raoulvdberge.refinedstorage.util.StackUtils; import com.raoulvdberge.refinedstorage.util.StackUtils;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
@@ -40,18 +41,18 @@ public class StorageDiskFluidStorageWrapper implements IStorageDisk<FluidStack>
@Override @Override
@Nullable @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)) { if (!IFilterable.acceptsFluid(storage.getFilters(), storage.getMode(), storage.getCompare(), stack)) {
return StackUtils.copy(stack, size); return StackUtils.copy(stack, size);
} }
return parent.insert(stack, size, simulate); return parent.insert(stack, size, action);
} }
@Nullable @Nullable
@Override @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) {
return parent.extract(stack, size, flags, simulate); return parent.extract(stack, size, flags, action);
} }
@Override @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.IStorageDisk;
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskContainerContext; import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskContainerContext;
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskListener; 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.tile.config.IFilterable;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
@@ -40,18 +41,18 @@ public class StorageDiskItemStorageWrapper implements IStorageDisk<ItemStack> {
@Override @Override
@Nullable @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)) { if (!IFilterable.acceptsItem(storage.getFilters(), storage.getMode(), storage.getCompare(), stack)) {
return ItemHandlerHelper.copyStackWithSize(stack, size); return ItemHandlerHelper.copyStackWithSize(stack, size);
} }
return parent.insert(stack, size, simulate); return parent.insert(stack, size, action);
} }
@Nullable @Nullable
@Override @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) {
return parent.extract(stack, size, flags, simulate); return parent.extract(stack, size, flags, action);
} }
@Override @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.IStorageDisk;
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskContainerContext; import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskContainerContext;
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskListener; 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.apiimpl.API;
import com.raoulvdberge.refinedstorage.util.StackUtils; import com.raoulvdberge.refinedstorage.util.StackUtils;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
@@ -65,7 +66,7 @@ public class StorageDiskFluid implements IStorageDisk<FluidStack> {
@Override @Override
@Nullable @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())) { for (FluidStack otherStack : stacks.get(stack.getFluid())) {
if (otherStack.isFluidEqual(stack)) { if (otherStack.isFluidEqual(stack)) {
if (getCapacity() != -1 && getStored() + size > getCapacity()) { if (getCapacity() != -1 && getStored() + size > getCapacity()) {
@@ -75,7 +76,7 @@ public class StorageDiskFluid implements IStorageDisk<FluidStack> {
return StackUtils.copy(stack, size); return StackUtils.copy(stack, size);
} }
if (!simulate) { if (action == Action.PERFORM) {
otherStack.amount += remainingSpace; otherStack.amount += remainingSpace;
onChanged(); onChanged();
@@ -83,7 +84,7 @@ public class StorageDiskFluid implements IStorageDisk<FluidStack> {
return StackUtils.copy(otherStack, size - remainingSpace); return StackUtils.copy(otherStack, size - remainingSpace);
} else { } else {
if (!simulate) { if (action == Action.PERFORM) {
otherStack.amount += size; otherStack.amount += size;
onChanged(); onChanged();
@@ -101,7 +102,7 @@ public class StorageDiskFluid implements IStorageDisk<FluidStack> {
return StackUtils.copy(stack, size); return StackUtils.copy(stack, size);
} }
if (!simulate) { if (action == Action.PERFORM) {
stacks.put(stack.getFluid(), StackUtils.copy(stack, remainingSpace)); stacks.put(stack.getFluid(), StackUtils.copy(stack, remainingSpace));
onChanged(); onChanged();
@@ -109,7 +110,7 @@ public class StorageDiskFluid implements IStorageDisk<FluidStack> {
return StackUtils.copy(stack, size - remainingSpace); return StackUtils.copy(stack, size - remainingSpace);
} else { } else {
if (!simulate) { if (action == Action.PERFORM) {
stacks.put(stack.getFluid(), StackUtils.copy(stack, size)); stacks.put(stack.getFluid(), StackUtils.copy(stack, size));
onChanged(); onChanged();
@@ -121,14 +122,14 @@ public class StorageDiskFluid implements IStorageDisk<FluidStack> {
@Override @Override
@Nullable @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())) { for (FluidStack otherStack : stacks.get(stack.getFluid())) {
if (API.instance().getComparer().isEqual(otherStack, stack, flags)) { if (API.instance().getComparer().isEqual(otherStack, stack, flags)) {
if (size > otherStack.amount) { if (size > otherStack.amount) {
size = otherStack.amount; size = otherStack.amount;
} }
if (!simulate) { if (action == Action.PERFORM) {
if (otherStack.amount - size == 0) { if (otherStack.amount - size == 0) {
stacks.remove(otherStack.getFluid(), otherStack); stacks.remove(otherStack.getFluid(), otherStack);
} else { } 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.IStorageDisk;
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskContainerContext; import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskContainerContext;
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskListener; 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.api.util.IComparer;
import com.raoulvdberge.refinedstorage.apiimpl.API; import com.raoulvdberge.refinedstorage.apiimpl.API;
import com.raoulvdberge.refinedstorage.util.StackUtils; import com.raoulvdberge.refinedstorage.util.StackUtils;
@@ -73,7 +74,7 @@ public class StorageDiskItem implements IStorageDisk<ItemStack> {
@Override @Override
@Nullable @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())) { for (ItemStack otherStack : stacks.get(stack.getItem())) {
if (API.instance().getComparer().isEqualNoQuantity(otherStack, stack)) { if (API.instance().getComparer().isEqualNoQuantity(otherStack, stack)) {
if (getCapacity() != -1 && getStored() + size > getCapacity()) { if (getCapacity() != -1 && getStored() + size > getCapacity()) {
@@ -83,7 +84,7 @@ public class StorageDiskItem implements IStorageDisk<ItemStack> {
return ItemHandlerHelper.copyStackWithSize(stack, size); return ItemHandlerHelper.copyStackWithSize(stack, size);
} }
if (!simulate) { if (action == Action.PERFORM) {
otherStack.grow(remainingSpace); otherStack.grow(remainingSpace);
onChanged(); onChanged();
@@ -91,7 +92,7 @@ public class StorageDiskItem implements IStorageDisk<ItemStack> {
return ItemHandlerHelper.copyStackWithSize(otherStack, size - remainingSpace); return ItemHandlerHelper.copyStackWithSize(otherStack, size - remainingSpace);
} else { } else {
if (!simulate) { if (action == Action.PERFORM) {
otherStack.grow(size); otherStack.grow(size);
onChanged(); onChanged();
@@ -109,7 +110,7 @@ public class StorageDiskItem implements IStorageDisk<ItemStack> {
return ItemHandlerHelper.copyStackWithSize(stack, size); return ItemHandlerHelper.copyStackWithSize(stack, size);
} }
if (!simulate) { if (action == Action.PERFORM) {
stacks.put(stack.getItem(), ItemHandlerHelper.copyStackWithSize(stack, remainingSpace)); stacks.put(stack.getItem(), ItemHandlerHelper.copyStackWithSize(stack, remainingSpace));
onChanged(); onChanged();
@@ -117,7 +118,7 @@ public class StorageDiskItem implements IStorageDisk<ItemStack> {
return ItemHandlerHelper.copyStackWithSize(stack, size - remainingSpace); return ItemHandlerHelper.copyStackWithSize(stack, size - remainingSpace);
} else { } else {
if (!simulate) { if (action == Action.PERFORM) {
stacks.put(stack.getItem(), ItemHandlerHelper.copyStackWithSize(stack, size)); stacks.put(stack.getItem(), ItemHandlerHelper.copyStackWithSize(stack, size));
onChanged(); onChanged();
@@ -129,7 +130,7 @@ public class StorageDiskItem implements IStorageDisk<ItemStack> {
@Override @Override
@Nullable @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; Collection<ItemStack> toAttempt = null;
if ((flags & IComparer.COMPARE_OREDICT) == IComparer.COMPARE_OREDICT) { if ((flags & IComparer.COMPARE_OREDICT) == IComparer.COMPARE_OREDICT) {
@@ -152,7 +153,7 @@ public class StorageDiskItem implements IStorageDisk<ItemStack> {
size = otherStack.getCount(); size = otherStack.getCount();
} }
if (!simulate) { if (action == Action.PERFORM) {
if (otherStack.getCount() - size == 0) { if (otherStack.getCount() - size == 0) {
stacks.remove(otherStack.getItem(), otherStack); stacks.remove(otherStack.getItem(), otherStack);
} else { } 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.IStorageDisk;
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskContainerContext; import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskContainerContext;
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskListener; import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskListener;
import com.raoulvdberge.refinedstorage.api.util.Action;
import com.raoulvdberge.refinedstorage.tile.grid.portable.IPortableGrid; import com.raoulvdberge.refinedstorage.tile.grid.portable.IPortableGrid;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
@@ -43,12 +44,12 @@ public class StorageDiskItemPortable implements IStorageDisk<ItemStack> {
@Nullable @Nullable
@Override @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(); 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); int inserted = parent.getCacheDelta(storedPre, size, remainder);
if (inserted > 0) { if (inserted > 0) {
@@ -61,10 +62,10 @@ public class StorageDiskItemPortable implements IStorageDisk<ItemStack> {
@Nullable @Nullable
@Override @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) {
ItemStack extracted = parent.extract(stack, size, flags, simulate); 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); 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.AccessType;
import com.raoulvdberge.refinedstorage.api.storage.externalstorage.IExternalStorageContext; import com.raoulvdberge.refinedstorage.api.storage.externalstorage.IExternalStorageContext;
import com.raoulvdberge.refinedstorage.api.storage.externalstorage.IStorageExternal; 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.api.util.IComparer;
import com.raoulvdberge.refinedstorage.apiimpl.API; import com.raoulvdberge.refinedstorage.apiimpl.API;
import com.raoulvdberge.refinedstorage.util.StackUtils; import com.raoulvdberge.refinedstorage.util.StackUtils;
@@ -156,9 +157,9 @@ public class StorageExternalFluid implements IStorageExternal<FluidStack> {
@Nullable @Nullable
@Override @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)) { 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) { if (filled == size) {
return null; return null;
@@ -172,14 +173,14 @@ public class StorageExternalFluid implements IStorageExternal<FluidStack> {
@Nullable @Nullable
@Override @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(); IFluidHandler handler = handlerSupplier.get();
if (handler == null) { if (handler == null) {
return null; return null;
} }
return handler.drain(StackUtils.copy(stack, size), !simulate); return handler.drain(StackUtils.copy(stack, size), action == Action.PERFORM);
} }
@Override @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.AccessType;
import com.raoulvdberge.refinedstorage.api.storage.externalstorage.IExternalStorageContext; import com.raoulvdberge.refinedstorage.api.storage.externalstorage.IExternalStorageContext;
import com.raoulvdberge.refinedstorage.api.storage.externalstorage.IStorageExternal; 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.apiimpl.API;
import com.raoulvdberge.refinedstorage.util.StackUtils; import com.raoulvdberge.refinedstorage.util.StackUtils;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
@@ -143,11 +144,11 @@ public class StorageExternalItem implements IStorageExternal<ItemStack> {
@Nullable @Nullable
@Override @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(); IItemHandler handler = handlerSupplier.get();
if (handler != null && context.acceptsItem(stack)) { 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); return ItemHandlerHelper.copyStackWithSize(stack, size);
@@ -155,7 +156,7 @@ public class StorageExternalItem implements IStorageExternal<ItemStack> {
@Nullable @Nullable
@Override @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; int remaining = size;
ItemStack received = null; ItemStack received = null;
@@ -170,7 +171,7 @@ public class StorageExternalItem implements IStorageExternal<ItemStack> {
ItemStack slot = handler.getStackInSlot(i); ItemStack slot = handler.getStackInSlot(i);
if (!slot.isEmpty() && API.instance().getComparer().isEqual(slot, stack, flags)) { 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 (!got.isEmpty()) {
if (received == null) { 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.IStorageDisk;
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskProvider; 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.IFilter;
import com.raoulvdberge.refinedstorage.api.util.IOneSixMigrationHelper; import com.raoulvdberge.refinedstorage.api.util.IOneSixMigrationHelper;
import com.raoulvdberge.refinedstorage.apiimpl.API; 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); stack.setTagCompound(tag.hasKey(NBT_ITEM_NBT) ? tag.getCompoundTag(NBT_ITEM_NBT) : null);
if (!stack.isEmpty()) { 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)); FluidStack stack = FluidStack.loadFluidStackFromNBT(list.getCompoundTagAt(i));
if (stack != null) { 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; import net.minecraftforge.energy.IEnergyStorage;
public final class EnergyProxy implements IEnergyStorage { public final class EnergyProxy implements IEnergyStorage {
@@ -19,12 +21,12 @@ public final class EnergyProxy implements IEnergyStorage {
@Override @Override
public int receiveEnergy(int maxReceive, boolean simulate) { 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 @Override
public int extractEnergy(int maxExtract, boolean simulate) { 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 @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.network.node.INetworkNode;
import com.raoulvdberge.refinedstorage.api.storage.IStorage; import com.raoulvdberge.refinedstorage.api.storage.IStorage;
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDisk; 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.api.util.IComparer;
import com.raoulvdberge.refinedstorage.apiimpl.API; import com.raoulvdberge.refinedstorage.apiimpl.API;
import li.cil.oc.api.Network; 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"); 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) { if (extractedSim == null || extractedSim.amount <= 0) {
return new Object[]{null, "could not extract the specified fluid"}; 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 // 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); handler.fill(extracted, true);
return new Object[]{filledAmountSim}; 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 // 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) { if (extractedSim.isEmpty() || extractedSim.getCount() == 0) {
return new Object[]{null, "could not extract the specified item"}; 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 // 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); ItemHandlerHelper.insertItemStacked(handler, extracted, false);
return new Object[]{transferableAmount}; 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.GridType;
import com.raoulvdberge.refinedstorage.api.network.grid.IGridNetworkAware; import com.raoulvdberge.refinedstorage.api.network.grid.IGridNetworkAware;
import com.raoulvdberge.refinedstorage.api.network.security.Permission; 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.apiimpl.network.node.NetworkNodeGrid;
import com.raoulvdberge.refinedstorage.container.ContainerGrid; import com.raoulvdberge.refinedstorage.container.ContainerGrid;
import com.raoulvdberge.refinedstorage.util.StackUtils; import com.raoulvdberge.refinedstorage.util.StackUtils;
@@ -41,7 +42,7 @@ public class MessageGridClear extends MessageHandlerPlayerToServer<MessageGridCl
ItemStack slot = matrix.getStackInSlot(i); ItemStack slot = matrix.getStackInSlot(i);
if (!slot.isEmpty()) { 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) { } 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.RS;
import com.raoulvdberge.refinedstorage.RSBlocks; import com.raoulvdberge.refinedstorage.RSBlocks;
import com.raoulvdberge.refinedstorage.api.autocrafting.ICraftingManager; 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.energy.IEnergy;
import com.raoulvdberge.refinedstorage.api.network.INetwork; import com.raoulvdberge.refinedstorage.api.network.INetwork;
import com.raoulvdberge.refinedstorage.api.network.INetworkNodeGraph; 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.IStorageCache;
import com.raoulvdberge.refinedstorage.api.storage.IStorageTracker; import com.raoulvdberge.refinedstorage.api.storage.IStorageTracker;
import com.raoulvdberge.refinedstorage.api.storage.externalstorage.IStorageExternal; 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.autocrafting.CraftingManager;
import com.raoulvdberge.refinedstorage.apiimpl.energy.Energy; import com.raoulvdberge.refinedstorage.apiimpl.energy.Energy;
import com.raoulvdberge.refinedstorage.apiimpl.network.NetworkNodeGraph; 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.ControllerEnergyType;
import com.raoulvdberge.refinedstorage.block.ControllerType; import com.raoulvdberge.refinedstorage.block.ControllerType;
import com.raoulvdberge.refinedstorage.capability.CapabilityNetworkNodeProxy; 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.IRedstoneConfigurable;
import com.raoulvdberge.refinedstorage.tile.config.RedstoneMode; import com.raoulvdberge.refinedstorage.tile.config.RedstoneMode;
import com.raoulvdberge.refinedstorage.tile.data.RSSerializers; 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 (getType() == ControllerType.NORMAL) {
if (!RS.INSTANCE.config.controllerUsesEnergy) { if (!RS.INSTANCE.config.controllerUsesEnergy) {
this.energy.setStored(this.energy.getCapacity()); this.energy.setStored(this.energy.getCapacity());
} else if (this.energy.extract(getEnergyUsage(), true) >= 0) { } else if (this.energy.extract(getEnergyUsage(), Action.SIMULATE) >= 0) {
this.energy.extract(getEnergyUsage(), false); this.energy.extract(getEnergyUsage(), Action.PERFORM);
} else { } else {
this.energy.setStored(0); this.energy.setStored(0);
} }
@@ -292,7 +293,7 @@ public class TileController extends TileBase implements ITickable, INetwork, IRe
} }
@Override @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()) { if (stack.isEmpty() || itemStorage.getStorages().isEmpty()) {
return ItemHandlerHelper.copyStackWithSize(stack, size); return ItemHandlerHelper.copyStackWithSize(stack, size);
} }
@@ -309,15 +310,15 @@ public class TileController extends TileBase implements ITickable, INetwork, IRe
int storedPre = storage.getStored(); 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); inserted += storage.getCacheDelta(storedPre, size, remainder);
} }
if (remainder == null) { if (remainder == null) {
// The external storage is responsible for sending changes, we don't need to anymore // 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); ((IStorageExternal) storage).update(this);
insertedExternally += size; insertedExternally += size;
@@ -326,7 +327,7 @@ public class TileController extends TileBase implements ITickable, INetwork, IRe
break; break;
} else { } else {
// The external storage is responsible for sending changes, we don't need to anymore // 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); ((IStorageExternal) storage).update(this);
insertedExternally += size - remainder.getCount(); 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); itemStorage.add(stack, inserted - insertedExternally, false, false);
} }
@@ -344,7 +345,7 @@ public class TileController extends TileBase implements ITickable, INetwork, IRe
} }
@Override @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 requested = size;
int received = 0; int received = 0;
@@ -356,12 +357,12 @@ public class TileController extends TileBase implements ITickable, INetwork, IRe
ItemStack took = null; ItemStack took = null;
if (filter.test(storage) && storage.getAccessType() != AccessType.INSERT) { 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) { if (took != null) {
// The external storage is responsible for sending changes, we don't need to anymore // 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); ((IStorageExternal) storage).update(this);
extractedExternally += took.getCount(); 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); itemStorage.remove(newStack, newStack.getCount() - extractedExternally, false);
} }
@@ -390,7 +391,7 @@ public class TileController extends TileBase implements ITickable, INetwork, IRe
@Override @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()) { if (stack == null || fluidStorage.getStorages().isEmpty()) {
return StackUtils.copy(stack, size); return StackUtils.copy(stack, size);
} }
@@ -407,15 +408,15 @@ public class TileController extends TileBase implements ITickable, INetwork, IRe
int storedPre = storage.getStored(); 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); inserted += storage.getCacheDelta(storedPre, size, remainder);
} }
if (remainder == null) { if (remainder == null) {
// The external storage is responsible for sending changes, we don't need to anymore // 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); ((IStorageExternal) storage).update(this);
insertedExternally += size; insertedExternally += size;
@@ -424,7 +425,7 @@ public class TileController extends TileBase implements ITickable, INetwork, IRe
break; break;
} else { } else {
// The external storage is responsible for sending changes, we don't need to anymore // 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); ((IStorageExternal) storage).update(this);
insertedExternally += size - remainder.amount; 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); fluidStorage.add(stack, inserted - insertedExternally, false, false);
} }
@@ -442,7 +443,7 @@ public class TileController extends TileBase implements ITickable, INetwork, IRe
} }
@Override @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 requested = size;
int received = 0; int received = 0;
@@ -454,12 +455,12 @@ public class TileController extends TileBase implements ITickable, INetwork, IRe
FluidStack took = null; FluidStack took = null;
if (storage.getAccessType() != AccessType.INSERT) { if (storage.getAccessType() != AccessType.INSERT) {
took = storage.extract(stack, requested - received, flags, simulate); took = storage.extract(stack, requested - received, flags, action);
} }
if (took != null) { if (took != null) {
// The external storage is responsible for sending changes, we don't need to anymore // 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); ((IStorageExternal) storage).update(this);
extractedExternally += took.amount; 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); fluidStorage.remove(newStack, newStack.amount - extractedExternally, false);
} }