Class WeightedFluidVolume<T>
java.lang.Object
alexiil.mc.lib.attributes.fluid.volume.FluidVolume
alexiil.mc.lib.attributes.fluid.volume.WeightedFluidVolume<T>
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
static interface
-
Field Summary
Fields inherited from class alexiil.mc.lib.attributes.fluid.volume.FluidVolume
BASE_UNIT, BOTTLE, BUCKET, DESERIALIZER, fluidKey
-
Constructor Summary
ConstructorDescriptionWeightedFluidVolume
(WeightedFluidKey<T> key, com.google.gson.JsonObject json, WeightedFluidVolume.WeightedJsonGetter<T> keyGetter) Json deserialiser that assumes the values are complicated, and so need a more complex json element than just a string to deserialise.WeightedFluidVolume
(WeightedFluidKey<T> key, com.google.gson.JsonObject json, WeightedFluidVolume.WeightedStringGetter<T> keyGetter) Json deserialiser that assumes the values are simple and require just a string to deserialise.WeightedFluidVolume
(WeightedFluidKey<T> key, net.minecraft.nbt.NbtCompound tag) WeightedFluidVolume
(WeightedFluidKey<T> key, T value, int amount) Deprecated, for removal: This API element is subject to removal in a future version.WeightedFluidVolume
(WeightedFluidKey<T> key, T value, FluidAmount amount) -
Method Summary
Modifier and TypeMethodDescriptionvoid
addAmount
(T value, FluidAmount amount) void
addAmount
(T value, FluidAmount amount, FluidAmount.FluidMergeRounding rounding) void
addAmounts
(Map<T, FluidAmount> sources) protected abstract boolean
protected WeightedFluidVolume<T>
copy0()
protected final T
protected void
fromMcBufferInternal
(net.minecraft.network.PacketByteBuf buffer) protected net.minecraft.text.Text
getTextFor
(T value) List<net.minecraft.text.Text>
getTooltipText
(net.minecraft.client.item.TooltipContext ctx) protected void
mergeInternal
(FluidVolume vol, FluidAmount.FluidMergeResult result) Actually merges twoFluidVolume
's together.protected final void
protected abstract T
readValue
(net.minecraft.nbt.NbtCompound holder) Inverse ofwriteValue(NbtCompound, Object)
.protected T
readValueFromMcBuffer
(net.minecraft.network.PacketByteBuf buffer) protected void
readValuesFromMcBuffer
(net.minecraft.network.PacketByteBuf buffer, Map<T, FluidAmount> map) protected abstract String
saveName()
protected WeightedFluidVolume<T>
split0
(FluidAmount toTake, RoundingMode rounding) com.google.gson.JsonObject
toJson()
protected abstract com.google.gson.JsonElement
protected void
toMcBufferInternal
(net.minecraft.network.PacketByteBuf buffer) net.minecraft.nbt.NbtCompound
toTag
(net.minecraft.nbt.NbtCompound tag) protected abstract void
writeValue
(net.minecraft.nbt.NbtCompound holder, T value) protected void
writeValuesToMcBuffer
(net.minecraft.network.PacketByteBuf buffer, Map<T, FluidAmount> map) protected void
writeValueToMcBuffer
(net.minecraft.network.PacketByteBuf buffer, T value) Methods inherited from class alexiil.mc.lib.attributes.fluid.volume.FluidVolume
addFullTooltip, addFullTooltip, addFullTooltip, addTooltipExtras, addTooltipNameAmount, addTooltipProperties, addTooltipTemperature, amount, areEqualExceptAmounts, areFullyEqual, canMerge, copy, create, create, create, equals, fromJson, fromMcBuffer, fromTag, getAmount, getAmount_F, getFlowingSprite, getFullTooltip, getFullTooltip, getFullTooltip, getName, getProperty, getRawAmount, getRawAmount_F, getRawFluid, getRenderColor, getRenderer, getSprite, getStillSprite, hashCode, isEmpty, localizeAmount, localizeAmount, localizeInTank, localizeInTank, merge, merge, merge, merge, merge0, mergeInto, mergeInto, mergeInto, multiplyAmount, parseAmount, render, renderGuiRect, setAmount, setAmount, setProperty, split, split, split, toMcBuffer, toString, toTag, withAmount
-
Constructor Details
-
WeightedFluidVolume
-
WeightedFluidVolume
@Deprecated(since="0.6.4", forRemoval=true) public WeightedFluidVolume(WeightedFluidKey<T> key, T value, int amount) Deprecated, for removal: This API element is subject to removal in a future version. -
WeightedFluidVolume
-
WeightedFluidVolume
public WeightedFluidVolume(WeightedFluidKey<T> key, com.google.gson.JsonObject json, WeightedFluidVolume.WeightedStringGetter<T> keyGetter) throws com.google.gson.JsonSyntaxException Json deserialiser that assumes the values are simple and require just a string to deserialise. It is only ever necessary for subclasses to call one of these constructors.- Throws:
com.google.gson.JsonSyntaxException
- See Also:
-
WeightedFluidVolume
public WeightedFluidVolume(WeightedFluidKey<T> key, com.google.gson.JsonObject json, WeightedFluidVolume.WeightedJsonGetter<T> keyGetter) throws com.google.gson.JsonSyntaxException Json deserialiser that assumes the values are complicated, and so need a more complex json element than just a string to deserialise. It is only ever necessary for subclasses to call one of these constructors.- Throws:
com.google.gson.JsonSyntaxException
- See Also:
-
-
Method Details
-
toJson
public com.google.gson.JsonObject toJson()- Overrides:
toJson
in classFluidVolume
-
toMcBufferInternal
protected void toMcBufferInternal(net.minecraft.network.PacketByteBuf buffer) - Overrides:
toMcBufferInternal
in classFluidVolume
-
fromMcBufferInternal
protected void fromMcBufferInternal(net.minecraft.network.PacketByteBuf buffer) - Overrides:
fromMcBufferInternal
in classFluidVolume
-
normalize
protected final void normalize() -
toTag
public net.minecraft.nbt.NbtCompound toTag(net.minecraft.nbt.NbtCompound tag) - Overrides:
toTag
in classFluidVolume
-
saveName
- Returns:
- The name to use when saving/loading the
values
map to/from disk. This is only used intoTag(NbtCompound)
,WeightedFluidVolume(WeightedFluidKey, NbtCompound)
,toJson()
,WeightedFluidVolume(WeightedFluidKey, JsonObject, WeightedStringGetter)
, andWeightedFluidVolume(WeightedFluidKey, JsonObject, WeightedJsonGetter)
, so you can move things around before these are called.
-
defaultValue
- Returns:
- The default value to use if none is present.
-
readValue
Inverse ofwriteValue(NbtCompound, Object)
. -
writeValue
- Parameters:
holder
- TheNbtCompound
to store the key in. Either "Amount" or "AmountF" might be overwritten by this class. (If in doubt it is better to use an embedded compound to store all of the data, using a key like "Name" or "Value").
-
areJsonValuesCompact
protected abstract boolean areJsonValuesCompact()- Returns:
- True if the weights should be serialised to json in "compact" form (where the value is serialised into a
single string, and read back with
WeightedFluidVolume.WeightedStringGetter
), or "full" form (and read back withWeightedFluidVolume.WeightedJsonGetter
).
-
toJson
- Returns:
- The value, turned into a
JsonElement
. If the subclass callsWeightedFluidVolume(WeightedFluidKey, JsonObject, WeightedStringGetter)
(and thus returns true fromareJsonValuesCompact()
) then this must be aJsonPrimitive
with a string, that can read back with theWeightedFluidVolume.WeightedStringGetter
. Otherwise there are no limits on what this can return, other than that theWeightedFluidVolume.WeightedJsonGetter
should be able to read back the given value from the returned json.
-
writeValuesToMcBuffer
protected void writeValuesToMcBuffer(net.minecraft.network.PacketByteBuf buffer, Map<T, FluidAmount> map) -
readValuesFromMcBuffer
protected void readValuesFromMcBuffer(net.minecraft.network.PacketByteBuf buffer, Map<T, FluidAmount> map) -
readValueFromMcBuffer
-
writeValueToMcBuffer
-
getTextFor
-
getFluidKey
- Overrides:
getFluidKey
in classFluidVolume
- Returns:
- The
FluidKey
for this volume. Subclasses may override this to use a return type for their key class.
-
getValues
- Returns:
- An unmodifiable view of the values map.
-
copy0
- Overrides:
copy0
in classFluidVolume
-
split0
- Overrides:
split0
in classFluidVolume
- Parameters:
toTake
- A valid subtractable amount.- Returns:
- A new
FluidVolume
with the given amount that has been removed from this.
-
mergeInternal
Description copied from class:FluidVolume
Actually merges twoFluidVolume
's together. OnlyFluidVolume.merge(FluidVolume, FluidMergeRounding, Simulation)
should call this. (Except for subclasses that override this method).- Overrides:
mergeInternal
in classFluidVolume
- Parameters:
vol
- The other fluid volume. This will always be the same class as this. This should change the amount of the other fluid toFluidAmount.FluidMergeResult.excess
.
-
addAmount
-
addAmount
-
addAmounts
-
getTooltipText
- Overrides:
getTooltipText
in classFluidVolume
-