Fix item voiding
This commit is contained in:
@@ -24,4 +24,9 @@ public interface IStorage<T> {
|
||||
default AccessType getAccessType() {
|
||||
return AccessType.INSERT_EXTRACT;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if this storage voids incoming items or fluids
|
||||
*/
|
||||
boolean isVoiding();
|
||||
}
|
||||
|
||||
@@ -56,6 +56,11 @@ public class ItemFluidStorageDisk extends ItemBase {
|
||||
public int getPriority() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVoiding() {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
for (Fluid fluid : FluidRegistry.getRegisteredFluids().values()) {
|
||||
|
||||
@@ -67,6 +67,11 @@ public class ItemStorageDisk extends ItemBase {
|
||||
public int getPriority() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVoiding() {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
Iterator<Item> it = REGISTRY.iterator();
|
||||
|
||||
@@ -580,26 +580,33 @@ public class TileController extends TileBase implements INetworkMaster, IRedston
|
||||
return ItemHandlerHelper.copyStackWithSize(stack, size);
|
||||
}
|
||||
|
||||
int orginalSize = size;
|
||||
int originalSize = size;
|
||||
|
||||
ItemStack remainder = stack;
|
||||
int externalStorageInserted = 0;
|
||||
int insertOnlyInserted = 0;
|
||||
|
||||
int insertedExternally = 0;
|
||||
int insertedToIgnore = 0;
|
||||
|
||||
for (IItemStorage storage : this.itemStorage.getStorages()) {
|
||||
if (storage.getAccessType() != AccessType.EXTRACT) {
|
||||
remainder = storage.insertItem(remainder, size, simulate);
|
||||
|
||||
// if this storage is in insert-only mode, we can disregard this item from the cache
|
||||
if (storage.getAccessType() == AccessType.INSERT && !simulate) {
|
||||
insertOnlyInserted += size - (remainder != null ? remainder.getCount() : 0);
|
||||
if (!simulate) {
|
||||
if (remainder != null && storage.isVoiding()) {
|
||||
insertedToIgnore += remainder.getCount();
|
||||
|
||||
remainder = null;
|
||||
} else if (storage.getAccessType() == AccessType.INSERT) {
|
||||
insertedToIgnore += size - (remainder != null ? remainder.getCount() : 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (remainder == null || remainder.getCount() <= 0) {
|
||||
if (remainder == null) {
|
||||
if (storage instanceof ItemStorageExternal && !simulate) {
|
||||
((ItemStorageExternal) storage).detectChanges(this);
|
||||
// the external storage will send the change, we don't need to anymore
|
||||
externalStorageInserted += size;
|
||||
insertedExternally += size;
|
||||
}
|
||||
|
||||
break;
|
||||
@@ -607,32 +614,22 @@ public class TileController extends TileBase implements INetworkMaster, IRedston
|
||||
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
|
||||
externalStorageInserted += size - remainder.getCount();
|
||||
insertedExternally += size - remainder.getCount();
|
||||
}
|
||||
|
||||
size = remainder.getCount();
|
||||
}
|
||||
}
|
||||
|
||||
// If the stack size of the remainder is negative, it means of the original size abs(remainder.getCount()) items have been voided
|
||||
int inserted;
|
||||
|
||||
if (remainder == null) {
|
||||
inserted = orginalSize;
|
||||
} else if (remainder.getCount() < 0) {
|
||||
inserted = orginalSize + remainder.getCount();
|
||||
remainder = null;
|
||||
} else {
|
||||
inserted = orginalSize - remainder.getCount();
|
||||
}
|
||||
|
||||
if (!simulate) {
|
||||
if (inserted - externalStorageInserted - insertOnlyInserted > 0) {
|
||||
itemStorage.add(stack, inserted - externalStorageInserted - insertOnlyInserted, false);
|
||||
int inserted = remainder == null ? originalSize : (originalSize - remainder.getCount());
|
||||
|
||||
if (inserted - insertedExternally - insertedToIgnore > 0) {
|
||||
itemStorage.add(stack, inserted - insertedExternally - insertedToIgnore, false);
|
||||
}
|
||||
|
||||
if (inserted - insertOnlyInserted > 0) {
|
||||
ItemStack checkSteps = ItemHandlerHelper.copyStackWithSize(stack, inserted - insertOnlyInserted);
|
||||
if (inserted - insertedToIgnore > 0) {
|
||||
ItemStack checkSteps = ItemHandlerHelper.copyStackWithSize(stack, inserted - insertedToIgnore);
|
||||
|
||||
for (ICraftingTask task : craftingTasks) {
|
||||
for (ICraftingStep processable : task.getSteps()) {
|
||||
|
||||
@@ -60,14 +60,7 @@ public class TileDiskDrive extends TileNode implements IItemStorageProvider, IFl
|
||||
return ItemHandlerHelper.copyStackWithSize(stack, size);
|
||||
}
|
||||
|
||||
ItemStack result = super.insertItem(stack, size, simulate);
|
||||
|
||||
if (voidExcess && result != null) {
|
||||
// Simulate should not matter as the items are voided anyway
|
||||
result.setCount(-result.getCount());
|
||||
}
|
||||
|
||||
return result;
|
||||
return super.insertItem(stack, size, simulate);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -75,6 +68,11 @@ public class TileDiskDrive extends TileNode implements IItemStorageProvider, IFl
|
||||
return accessType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVoiding() {
|
||||
return voidExcess;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStorageChanged() {
|
||||
super.onStorageChanged();
|
||||
@@ -109,14 +107,7 @@ public class TileDiskDrive extends TileNode implements IItemStorageProvider, IFl
|
||||
return RSUtils.copyStackWithSize(stack, size);
|
||||
}
|
||||
|
||||
FluidStack result = super.insertFluid(stack, size, simulate);
|
||||
|
||||
if (voidExcess && result != null) {
|
||||
// Simulate should not matter as the fluids are voided anyway
|
||||
result.amount = -result.amount;
|
||||
}
|
||||
|
||||
return result;
|
||||
return super.insertFluid(stack, size, simulate);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -124,6 +115,11 @@ public class TileDiskDrive extends TileNode implements IItemStorageProvider, IFl
|
||||
return accessType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVoiding() {
|
||||
return voidExcess;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStorageChanged() {
|
||||
super.onStorageChanged();
|
||||
|
||||
@@ -126,6 +126,11 @@ public class TileDiskManipulator extends TileNode implements IComparable, IFilte
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVoiding() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack insertItem(ItemStack stack, int size, boolean simulate) {
|
||||
if (!IFilterable.canTake(itemFilters, mode, getCompare(), stack)) {
|
||||
@@ -172,6 +177,11 @@ public class TileDiskManipulator extends TileNode implements IComparable, IFilte
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVoiding() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidStack insertFluid(FluidStack stack, int size, boolean simulate) {
|
||||
if (!IFilterable.canTakeFluids(fluidFilters, mode, getCompare(), stack)) {
|
||||
|
||||
@@ -50,20 +50,18 @@ public class TileFluidStorage extends TileNode implements IFluidStorageProvider,
|
||||
return RSUtils.copyStackWithSize(stack, size);
|
||||
}
|
||||
|
||||
FluidStack result = super.insertFluid(stack, size, simulate);
|
||||
|
||||
if (voidExcess && result != null) {
|
||||
// Simulate should not matter as the fluids are voided anyway
|
||||
result.amount = -result.amount;
|
||||
}
|
||||
|
||||
return result;
|
||||
return super.insertFluid(stack, size, simulate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AccessType getAccessType() {
|
||||
return accessType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVoiding() {
|
||||
return voidExcess;
|
||||
}
|
||||
}
|
||||
|
||||
public static final String NBT_STORAGE = "Storage";
|
||||
|
||||
@@ -51,20 +51,18 @@ public class TileStorage extends TileNode implements IItemStorageProvider, IStor
|
||||
return ItemHandlerHelper.copyStackWithSize(stack, size);
|
||||
}
|
||||
|
||||
ItemStack result = super.insertItem(stack, size, simulate);
|
||||
|
||||
if (voidExcess && result != null) {
|
||||
// Simulate should not matter as the items are voided anyway
|
||||
result.setCount(-result.getCount());
|
||||
}
|
||||
|
||||
return result;
|
||||
return super.insertItem(stack, size, simulate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AccessType getAccessType() {
|
||||
return accessType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVoiding() {
|
||||
return voidExcess;
|
||||
}
|
||||
}
|
||||
|
||||
public static final String NBT_STORAGE = "Storage";
|
||||
|
||||
@@ -84,6 +84,11 @@ public class FluidStorageExternal implements IFluidStorage {
|
||||
return externalStorage.getAccessType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVoiding() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean updateCache() {
|
||||
FluidStack stack = getContents();
|
||||
|
||||
|
||||
@@ -76,4 +76,9 @@ public abstract class ItemStorageExternal implements IItemStorage {
|
||||
|
||||
this.cache = newStacks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVoiding() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user