Add IStorage#getCacheDelta, makes "void excess items" feature work again on 1.11
This commit is contained in:
@@ -2,6 +2,8 @@ package com.raoulvdberge.refinedstorage.api.storage;
|
||||
|
||||
import net.minecraft.util.NonNullList;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public interface IStorage<T> {
|
||||
/**
|
||||
* @return stacks stored in this storage
|
||||
@@ -26,7 +28,12 @@ public interface IStorage<T> {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if this storage voids incoming items or fluids
|
||||
* Returns the delta that needs to be added to the item or fluid storage cache AFTER insertion of the stack.
|
||||
*
|
||||
* @param storedPreInsertion the amount stored pre insertion
|
||||
* @param size the size of the stack being inserted
|
||||
* @param remainder the remainder that we got back, or null if no remainder was there
|
||||
* @return the amount to increase the cache with
|
||||
*/
|
||||
boolean isVoiding();
|
||||
int getCacheDelta(int storedPreInsertion, int size, @Nullable T remainder);
|
||||
}
|
||||
|
@@ -1,6 +1,7 @@
|
||||
package com.raoulvdberge.refinedstorage.apiimpl.storage.fluid;
|
||||
|
||||
import com.raoulvdberge.refinedstorage.RSUtils;
|
||||
import com.raoulvdberge.refinedstorage.api.storage.AccessType;
|
||||
import com.raoulvdberge.refinedstorage.api.storage.fluid.IFluidStorage;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.API;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -85,6 +86,10 @@ public abstract class FluidStorageNBT implements IFluidStorage {
|
||||
int remainingSpace = getCapacity() - getStored();
|
||||
|
||||
if (remainingSpace <= 0) {
|
||||
if (isVoiding()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return RSUtils.copyStackWithSize(stack, size);
|
||||
}
|
||||
|
||||
@@ -96,7 +101,7 @@ public abstract class FluidStorageNBT implements IFluidStorage {
|
||||
onStorageChanged();
|
||||
}
|
||||
|
||||
return RSUtils.copyStackWithSize(otherStack, size - remainingSpace);
|
||||
return isVoiding() ? null : RSUtils.copyStackWithSize(otherStack, size - remainingSpace);
|
||||
} else {
|
||||
if (!simulate) {
|
||||
tag.setInteger(NBT_STORED, getStored() + size);
|
||||
@@ -115,6 +120,10 @@ public abstract class FluidStorageNBT implements IFluidStorage {
|
||||
int remainingSpace = getCapacity() - getStored();
|
||||
|
||||
if (remainingSpace <= 0) {
|
||||
if (isVoiding()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return RSUtils.copyStackWithSize(stack, size);
|
||||
}
|
||||
|
||||
@@ -126,7 +135,7 @@ public abstract class FluidStorageNBT implements IFluidStorage {
|
||||
onStorageChanged();
|
||||
}
|
||||
|
||||
return RSUtils.copyStackWithSize(stack, size - remainingSpace);
|
||||
return isVoiding() ? null : RSUtils.copyStackWithSize(stack, size - remainingSpace);
|
||||
} else {
|
||||
if (!simulate) {
|
||||
tag.setInteger(NBT_STORED, getStored() + size);
|
||||
@@ -182,8 +191,23 @@ public abstract class FluidStorageNBT implements IFluidStorage {
|
||||
return capacity;
|
||||
}
|
||||
|
||||
public boolean isFull() {
|
||||
return getStored() == getCapacity();
|
||||
protected boolean isVoiding() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCacheDelta(int storedPreInsertion, int size, @Nullable FluidStack remainder) {
|
||||
if (getAccessType() == AccessType.INSERT) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int inserted = remainder == null ? size : (size - remainder.amount);
|
||||
|
||||
if (isVoiding() && storedPreInsertion + inserted > getCapacity()) {
|
||||
inserted = getCapacity() - storedPreInsertion;
|
||||
}
|
||||
|
||||
return inserted;
|
||||
}
|
||||
|
||||
public NBTTagCompound getTag() {
|
||||
|
@@ -1,5 +1,6 @@
|
||||
package com.raoulvdberge.refinedstorage.apiimpl.storage.item;
|
||||
|
||||
import com.raoulvdberge.refinedstorage.api.storage.AccessType;
|
||||
import com.raoulvdberge.refinedstorage.api.storage.item.IItemStorage;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.API;
|
||||
import net.minecraft.item.Item;
|
||||
@@ -122,6 +123,10 @@ public abstract class ItemStorageNBT implements IItemStorage {
|
||||
int remainingSpace = getCapacity() - getStored();
|
||||
|
||||
if (remainingSpace <= 0) {
|
||||
if (isVoiding()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return ItemHandlerHelper.copyStackWithSize(stack, size);
|
||||
}
|
||||
|
||||
@@ -133,7 +138,7 @@ public abstract class ItemStorageNBT implements IItemStorage {
|
||||
onStorageChanged();
|
||||
}
|
||||
|
||||
return ItemHandlerHelper.copyStackWithSize(otherStack, size - remainingSpace);
|
||||
return isVoiding() ? null : ItemHandlerHelper.copyStackWithSize(otherStack, size - remainingSpace);
|
||||
} else {
|
||||
if (!simulate) {
|
||||
tag.setInteger(NBT_STORED, getStored() + size);
|
||||
@@ -152,6 +157,10 @@ public abstract class ItemStorageNBT implements IItemStorage {
|
||||
int remainingSpace = getCapacity() - getStored();
|
||||
|
||||
if (remainingSpace <= 0) {
|
||||
if (isVoiding()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return ItemHandlerHelper.copyStackWithSize(stack, size);
|
||||
}
|
||||
|
||||
@@ -163,7 +172,7 @@ public abstract class ItemStorageNBT implements IItemStorage {
|
||||
onStorageChanged();
|
||||
}
|
||||
|
||||
return ItemHandlerHelper.copyStackWithSize(stack, size - remainingSpace);
|
||||
return isVoiding() ? null : ItemHandlerHelper.copyStackWithSize(stack, size - remainingSpace);
|
||||
} else {
|
||||
if (!simulate) {
|
||||
tag.setInteger(NBT_STORED, getStored() + size);
|
||||
@@ -219,8 +228,23 @@ public abstract class ItemStorageNBT implements IItemStorage {
|
||||
return capacity;
|
||||
}
|
||||
|
||||
public boolean isFull() {
|
||||
return getStored() == getCapacity();
|
||||
protected boolean isVoiding() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCacheDelta(int storedPreInsertion, int size, @Nullable ItemStack remainder) {
|
||||
if (getAccessType() == AccessType.INSERT) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int inserted = remainder == null ? size : (size - remainder.getCount());
|
||||
|
||||
if (isVoiding() && storedPreInsertion + inserted > getCapacity()) {
|
||||
inserted = getCapacity() - storedPreInsertion;
|
||||
}
|
||||
|
||||
return inserted;
|
||||
}
|
||||
|
||||
public NBTTagCompound getTag() {
|
||||
|
@@ -580,40 +580,34 @@ public class TileController extends TileBase implements INetworkMaster, IRedston
|
||||
return ItemHandlerHelper.copyStackWithSize(stack, size);
|
||||
}
|
||||
|
||||
int originalSize = size;
|
||||
|
||||
ItemStack remainder = stack;
|
||||
|
||||
int inserted = 0;
|
||||
int insertedExternally = 0;
|
||||
int insertedToIgnore = 0;
|
||||
|
||||
for (IItemStorage storage : this.itemStorage.getStorages()) {
|
||||
if (storage.getAccessType() != AccessType.EXTRACT) {
|
||||
remainder = storage.insertItem(remainder, size, simulate);
|
||||
int storedPre = storage.getStored();
|
||||
|
||||
if (!simulate) {
|
||||
if (remainder != null && storage.isVoiding()) {
|
||||
insertedToIgnore += remainder.getCount();
|
||||
remainder = storage.insertItem(remainder, size, simulate);
|
||||
|
||||
remainder = null;
|
||||
} else if (storage.getAccessType() == AccessType.INSERT) {
|
||||
insertedToIgnore += size - (remainder != null ? remainder.getCount() : 0);
|
||||
}
|
||||
}
|
||||
if (!simulate) {
|
||||
inserted += storage.getCacheDelta(storedPre, size, remainder);
|
||||
}
|
||||
|
||||
if (remainder == null) {
|
||||
// The external storage is responsible for sending changes, we don't need to anymore
|
||||
if (storage instanceof ItemStorageExternal && !simulate) {
|
||||
((ItemStorageExternal) storage).detectChanges(this);
|
||||
// the external storage will send the change, we don't need to anymore
|
||||
|
||||
insertedExternally += size;
|
||||
}
|
||||
|
||||
break;
|
||||
} else {
|
||||
// The external storage is responsible for sending changes, we don't need to anymore
|
||||
if (size != remainder.getCount() && storage instanceof ItemStorageExternal && !simulate) {
|
||||
((ItemStorageExternal) storage).detectChanges(this);
|
||||
// the external storage will send the change, we don't need to anymore
|
||||
|
||||
insertedExternally += size - remainder.getCount();
|
||||
}
|
||||
|
||||
@@ -622,14 +616,12 @@ public class TileController extends TileBase implements INetworkMaster, IRedston
|
||||
}
|
||||
|
||||
if (!simulate) {
|
||||
int inserted = remainder == null ? originalSize : (originalSize - remainder.getCount());
|
||||
|
||||
if (inserted - insertedExternally - insertedToIgnore > 0) {
|
||||
itemStorage.add(stack, inserted - insertedExternally - insertedToIgnore, false);
|
||||
if (inserted - insertedExternally > 0) {
|
||||
itemStorage.add(stack, inserted - insertedExternally, false);
|
||||
}
|
||||
|
||||
if (inserted - insertedToIgnore > 0) {
|
||||
ItemStack checkSteps = ItemHandlerHelper.copyStackWithSize(stack, inserted - insertedToIgnore);
|
||||
if (inserted > 0) {
|
||||
ItemStack checkSteps = ItemHandlerHelper.copyStackWithSize(stack, inserted);
|
||||
|
||||
for (ICraftingTask task : craftingTasks) {
|
||||
for (ICraftingStep processable : task.getSteps()) {
|
||||
@@ -648,7 +640,9 @@ public class TileController extends TileBase implements INetworkMaster, IRedston
|
||||
public ItemStack extractItem(@Nonnull ItemStack stack, int size, int flags, boolean simulate) {
|
||||
int requested = size;
|
||||
int received = 0;
|
||||
int externalStorageExtracted = 0;
|
||||
|
||||
int extractedExternally = 0;
|
||||
|
||||
ItemStack newStack = null;
|
||||
|
||||
for (IItemStorage storage : this.itemStorage.getStorages()) {
|
||||
@@ -659,10 +653,11 @@ public class TileController extends TileBase implements INetworkMaster, IRedston
|
||||
}
|
||||
|
||||
if (took != null) {
|
||||
// The external storage is responsible for sending changes, we don't need to anymore
|
||||
if (storage instanceof ItemStorageExternal && !simulate) {
|
||||
((ItemStorageExternal) storage).detectChanges(this);
|
||||
// the external storage will send the change, we don't need to anymore
|
||||
externalStorageExtracted += took.getCount();
|
||||
|
||||
extractedExternally += took.getCount();
|
||||
}
|
||||
|
||||
if (newStack == null) {
|
||||
@@ -679,8 +674,8 @@ public class TileController extends TileBase implements INetworkMaster, IRedston
|
||||
}
|
||||
}
|
||||
|
||||
if (newStack != null && newStack.getCount() - externalStorageExtracted > 0 && !simulate) {
|
||||
itemStorage.remove(newStack, newStack.getCount() - externalStorageExtracted);
|
||||
if (newStack != null && newStack.getCount() - extractedExternally > 0 && !simulate) {
|
||||
itemStorage.remove(newStack, newStack.getCount() - extractedExternally);
|
||||
}
|
||||
|
||||
return newStack;
|
||||
@@ -693,23 +688,17 @@ public class TileController extends TileBase implements INetworkMaster, IRedston
|
||||
return RSUtils.copyStackWithSize(stack, size);
|
||||
}
|
||||
|
||||
int originalSize = size;
|
||||
AccessType accessType = AccessType.INSERT_EXTRACT;
|
||||
FluidStack remainder = stack;
|
||||
|
||||
int insertedToIgnore = 0;
|
||||
int inserted = 0;
|
||||
|
||||
for (IFluidStorage storage : this.fluidStorage.getStorages()) {
|
||||
accessType = storage.getAccessType();
|
||||
int storedPre = storage.getStored();
|
||||
|
||||
if (accessType != AccessType.EXTRACT) {
|
||||
remainder = storage.insertFluid(remainder, size, simulate);
|
||||
remainder = storage.insertFluid(remainder, size, simulate);
|
||||
|
||||
if (remainder != null && storage.isVoiding() && !simulate) {
|
||||
insertedToIgnore += remainder.amount;
|
||||
|
||||
remainder = null;
|
||||
}
|
||||
if (!simulate) {
|
||||
inserted += storage.getCacheDelta(storedPre, size, remainder);
|
||||
}
|
||||
|
||||
if (storage instanceof FluidStorageExternal && !simulate) {
|
||||
@@ -723,14 +712,8 @@ public class TileController extends TileBase implements INetworkMaster, IRedston
|
||||
}
|
||||
}
|
||||
|
||||
if (!simulate) {
|
||||
int inserted = remainder == null ? originalSize : (originalSize - remainder.amount);
|
||||
|
||||
inserted -= insertedToIgnore;
|
||||
|
||||
if (inserted > 0 && accessType != AccessType.INSERT) {
|
||||
fluidStorage.add(RSUtils.copyStackWithSize(stack, inserted), false);
|
||||
}
|
||||
if (inserted > 0) {
|
||||
fluidStorage.add(RSUtils.copyStackWithSize(stack, inserted), false);
|
||||
}
|
||||
|
||||
return remainder;
|
||||
@@ -741,6 +724,7 @@ public class TileController extends TileBase implements INetworkMaster, IRedston
|
||||
public FluidStack extractFluid(@Nonnull FluidStack stack, int size, int flags, boolean simulate) {
|
||||
int requested = size;
|
||||
int received = 0;
|
||||
|
||||
FluidStack newStack = null;
|
||||
|
||||
for (IFluidStorage storage : this.fluidStorage.getStorages()) {
|
||||
|
@@ -85,8 +85,8 @@ public class FluidStorageExternal implements IFluidStorage {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVoiding() {
|
||||
return false;
|
||||
public int getCacheDelta(int storedPreInsertion, int size, @Nullable FluidStack remainder) {
|
||||
return remainder == null ? size : (size - remainder.amount);
|
||||
}
|
||||
|
||||
public boolean updateCache() {
|
||||
|
@@ -6,6 +6,7 @@ import com.raoulvdberge.refinedstorage.api.storage.item.IItemStorage;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.API;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class ItemStorageExternal implements IItemStorage {
|
||||
@@ -78,7 +79,7 @@ public abstract class ItemStorageExternal implements IItemStorage {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVoiding() {
|
||||
return false;
|
||||
public int getCacheDelta(int storedPreInsertion, int size, @Nullable ItemStack remainder) {
|
||||
return remainder == null ? size : (size - remainder.getCount());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user