Voidable fluid (#448)

* Voidable fluid

* Negative value so FluidCache update fluid count

* Rename variable

* Consistency

* Syntax Again
This commit is contained in:
InusualZ
2016-10-09 13:16:16 -04:00
committed by Raoul
parent 1e6312fd17
commit d8e40952d3

View File

@@ -15,6 +15,7 @@ import refinedstorage.block.BlockFluidStorage;
import refinedstorage.block.EnumFluidStorageType;
import refinedstorage.inventory.ItemHandlerFluid;
import refinedstorage.tile.config.IComparable;
import refinedstorage.tile.config.IExcessVoidable;
import refinedstorage.tile.config.IFilterable;
import refinedstorage.tile.config.IPrioritizable;
import refinedstorage.tile.data.ITileDataProducer;
@@ -22,9 +23,10 @@ import refinedstorage.tile.data.TileDataParameter;
import java.util.List;
public class TileFluidStorage extends TileNode implements IFluidStorageProvider, IStorageGui, IComparable, IFilterable, IPrioritizable {
public class TileFluidStorage extends TileNode implements IFluidStorageProvider, IStorageGui, IComparable, IFilterable, IPrioritizable, IExcessVoidable {
public static final TileDataParameter<Integer> PRIORITY = IPrioritizable.createParameter();
public static final TileDataParameter<Integer> COMPARE = IComparable.createParameter();
public static final TileDataParameter<Boolean> VOID_EXCESS = IExcessVoidable.createParameter();
public static final TileDataParameter<Integer> MODE = IFilterable.createParameter();
public static final TileDataParameter<Integer> STORED = new TileDataParameter<>(DataSerializers.VARINT, 0, new ITileDataProducer<Integer, TileFluidStorage>() {
@Override
@@ -48,8 +50,14 @@ public class TileFluidStorage extends TileNode implements IFluidStorageProvider,
if (!IFilterable.canTakeFluids(filters, mode, compare, stack)) {
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 super.insertFluid(stack, size, simulate);
return result;
}
}
@@ -58,6 +66,7 @@ public class TileFluidStorage extends TileNode implements IFluidStorageProvider,
private static final String NBT_PRIORITY = "Priority";
private static final String NBT_COMPARE = "Compare";
private static final String NBT_MODE = "Mode";
private static final String NBT_VOID_EXCESS = "VoidExcess";
private ItemHandlerFluid filters = new ItemHandlerFluid(9, this);
@@ -70,12 +79,14 @@ public class TileFluidStorage extends TileNode implements IFluidStorageProvider,
private int priority = 0;
private int compare = IComparer.COMPARE_NBT;
private int mode = IFilterable.WHITELIST;
private boolean voidExcess = false;
public TileFluidStorage() {
dataManager.addWatchedParameter(PRIORITY);
dataManager.addWatchedParameter(COMPARE);
dataManager.addWatchedParameter(MODE);
dataManager.addWatchedParameter(STORED);
dataManager.addWatchedParameter(VOID_EXCESS);
}
@Override
@@ -141,6 +152,10 @@ public class TileFluidStorage extends TileNode implements IFluidStorageProvider,
if (tag.hasKey(NBT_MODE)) {
mode = tag.getInteger(NBT_MODE);
}
if (tag.hasKey(NBT_VOID_EXCESS)) {
voidExcess = tag.getBoolean(NBT_VOID_EXCESS);
}
}
@Override
@@ -158,6 +173,7 @@ public class TileFluidStorage extends TileNode implements IFluidStorageProvider,
tag.setTag(NBT_STORAGE, storageTag);
tag.setInteger(NBT_COMPARE, compare);
tag.setInteger(NBT_MODE, mode);
tag.setBoolean(NBT_VOID_EXCESS, voidExcess);
return tag;
}
@@ -226,7 +242,7 @@ public class TileFluidStorage extends TileNode implements IFluidStorageProvider,
@Override
public TileDataParameter<Boolean> getVoidExcessParameter() {
return null;
return VOID_EXCESS;
}
@Override
@@ -271,5 +287,17 @@ public class TileFluidStorage extends TileNode implements IFluidStorageProvider,
public int getCapacity() {
return getType().getCapacity();
}
@Override
public boolean getVoidExcess() {
return voidExcess;
}
@Override
public void setVoidExcess(boolean value) {
this.voidExcess = value;
markDirty();
}
}