Class ItemBasedSingleFluidInv
java.lang.Object
alexiil.mc.lib.attributes.misc.AbstractItemBasedAttribute
alexiil.mc.lib.attributes.fluid.item.ItemBasedSingleFluidInv
- All Implemented Interfaces:
FluidExtractable
,FluidInsertable
,FluidTransferable
,GroupedFluidInv
,GroupedFluidInvView
,LimitedConsumer<FluidVolume>
public abstract class ItemBasedSingleFluidInv
extends AbstractItemBasedAttribute
implements GroupedFluidInv
An abstract
GroupedFluidInv
for an AbstractItemBasedAttribute
which only ever contains a single
fluid, and can contain any amount of said fluid between 0 and it's capacity.-
Nested Class Summary
Nested classes/interfaces inherited from interface alexiil.mc.lib.attributes.fluid.GroupedFluidInvView
GroupedFluidInvView.FluidInvStatistic
-
Field Summary
Fields inherited from class alexiil.mc.lib.attributes.misc.AbstractItemBasedAttribute
excessStacks, stackRef
-
Constructor Summary
ModifierConstructorDescriptionprotected
ItemBasedSingleFluidInv
(Reference<net.minecraft.item.ItemStack> stackRef, LimitedConsumer<net.minecraft.item.ItemStack> excessStacks) -
Method Summary
Modifier and TypeMethodDescriptionattemptExtraction
(FluidFilter filter, FluidAmount maxAmount, Simulation simulation) attemptInsertion
(FluidVolume fluid, Simulation simulation) Inserts the given stack into this insertable, and returns the excess.protected abstract ItemBasedSingleFluidInv.HeldFluidInfo
getInfo
(net.minecraft.item.ItemStack stack) TheFluidFilter
to limit what may be inserted.getStatistics
(FluidFilter filter) protected abstract boolean
isInvalid
(net.minecraft.item.ItemStack stack) protected abstract net.minecraft.item.ItemStack
writeToStack
(net.minecraft.item.ItemStack stack, FluidVolume fluid) Methods inherited from class alexiil.mc.lib.attributes.misc.AbstractItemBasedAttribute
setStacks, toString
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface alexiil.mc.lib.attributes.fluid.FluidExtractable
attemptAnyExtraction, attemptAnyExtraction, attemptExtraction, couldExtractAnything, extract, extract, extract, extract, extract, extract, getPureExtractable
Methods inherited from interface alexiil.mc.lib.attributes.fluid.FluidInsertable
getMinimumAcceptedAmount, getPureInsertable, insert, offer, offer, wouldAccept
Methods inherited from interface alexiil.mc.lib.attributes.fluid.GroupedFluidInv
createLimitedGroupedInv, filtered
Methods inherited from interface alexiil.mc.lib.attributes.fluid.GroupedFluidInvView
addListener, addListener_F, getAmount, getAmount, getAmount_F, getAmount_F, getCapacity, getCapacity_F, getGroupedView, getSpace, getSpace_F, getStatistics, getTotalCapacity, getTotalCapacity_F
-
Constructor Details
-
ItemBasedSingleFluidInv
protected ItemBasedSingleFluidInv(Reference<net.minecraft.item.ItemStack> stackRef, LimitedConsumer<net.minecraft.item.ItemStack> excessStacks)
-
-
Method Details
-
isInvalid
protected abstract boolean isInvalid(net.minecraft.item.ItemStack stack) - Parameters:
stack
- TheItemStack
to test. This will never be empty.- Returns:
- True if the given stack is not a valid target.
-
getInfo
protected abstract ItemBasedSingleFluidInv.HeldFluidInfo getInfo(net.minecraft.item.ItemStack stack) - Parameters:
stack
- TheItemStack
of which to look at. This will have already been passed toisInvalid(ItemStack)
and returned false. You should ignore theItemStack.getCount()
, and treat it as 1.- Returns:
- The information for a given stack.
-
writeToStack
@Nullable protected abstract net.minecraft.item.ItemStack writeToStack(net.minecraft.item.ItemStack stack, FluidVolume fluid) - Parameters:
stack
- The stack to modify. However it is not required that this stack is actually modified, instead you could create a new stack and return it.- Returns:
- Either the newly modified stack (if the given fluid was valid), or null if this couldn't write the given fluid to the stack.
-
getStoredFluids
- Specified by:
getStoredFluids
in interfaceGroupedFluidInvView
- Returns:
- a set containing all of the
FluidKey
's that are stored in the inventory.
-
getStatistics
- Specified by:
getStatistics
in interfaceGroupedFluidInvView
- Parameters:
filter
- The filter to check on.- Returns:
- Statistics about the currently stored amount, capacity, and space for everything that matches the given filter.
-
getInsertionFilter
TheFluidFilter
to limit what may be inserted. NOTE: subclasses must never callattemptInsertion(FluidVolume, Simulation)
from inside this method, or return aFluidFilter
whosematches
method calls attemptInsertion as this is used by attemptInsertion in order to filter incoming fluids.- Specified by:
getInsertionFilter
in interfaceFluidInsertable
- Returns:
- A filter to determine if the given fluid could ever be inserted.
-
attemptInsertion
Description copied from interface:FluidInsertable
Inserts the given stack into this insertable, and returns the excess.- Specified by:
attemptInsertion
in interfaceFluidInsertable
- Parameters:
fluid
- The incoming fluid. Must not be modified by this call.simulation
- IfSimulation.SIMULATE
then this shouldn't modify anything.- Returns:
- the excess
FluidVolume
that wasn't accepted. This will be independent of this insertable, however it might be the given object instead of a completely new object.
-
attemptExtraction
public FluidVolume attemptExtraction(FluidFilter filter, FluidAmount maxAmount, Simulation simulation) Description copied from interface:FluidExtractable
- Specified by:
attemptExtraction
in interfaceFluidExtractable
maxAmount
- The maximum amount of fluid that can be extracted. Negative numbers throw an exception.simulation
- IfSimulation.SIMULATE
then this should return the same result that the exact same call withSimulation.ACTION
would do, except that the filter can be made more specific between calls if the previously simulated extracted fluid is used as a filter.For example the following code snippet should never throw an exception:
FluidExtractable
from = // Some extractable
FluidVolume
attempted = from.attemptAnyExtraction
(Integer.MAX_VALUE
,Simulation.SIMULATE
);
if (attempted.isEmpty()
) return;
FluidVolume
extracted = from.extract
(attempted.getFluidKey()
, attempted.getAmount()
);
assert !extracted.isEmpty
;
assert attempted.getAmount()
== extracted.getAmount()
;
assert attempted.getFluidKet()
== extracted.getFluidKet()
;
assert attempted.equals
(extracted);- Returns:
- A new, independent
FluidVolume
that was extracted.
-