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