Class WeightedFluidVolume<T>
java.lang.Object
alexiil.mc.lib.attributes.fluid.volume.FluidVolume
alexiil.mc.lib.attributes.fluid.volume.WeightedFluidVolume<T>
public abstract class WeightedFluidVolume<T> extends FluidVolume
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
WeightedFluidVolume.WeightedJsonGetter<T>
static interface
WeightedFluidVolume.WeightedStringGetter<T>
-
Field Summary
Fields inherited from class alexiil.mc.lib.attributes.fluid.volume.FluidVolume
BASE_UNIT, BOTTLE, BUCKET, DESERIALIZER, fluidKey
-
Constructor Summary
Constructors Constructor Description WeightedFluidVolume(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.CompoundTag tag)
WeightedFluidVolume(WeightedFluidKey<T> key, T value, int amount)
Deprecated.WeightedFluidVolume(WeightedFluidKey<T> key, T value, FluidAmount amount)
-
Method Summary
Modifier and Type Method Description void
addAmount(T value, FluidAmount amount)
void
addAmount(T value, FluidAmount amount, FluidAmount.FluidMergeRounding rounding)
void
addAmounts(java.util.Map<T,FluidAmount> sources)
protected abstract boolean
areJsonValuesCompact()
protected WeightedFluidVolume<T>
copy0()
protected T
defaultValue()
protected void
fromMcBufferInternal(net.minecraft.network.PacketByteBuf buffer)
WeightedFluidKey<T>
getFluidKey()
protected net.minecraft.text.Text
getTextFor(T value)
java.util.List<net.minecraft.text.Text>
getTooltipText(net.minecraft.client.item.TooltipContext ctx)
java.util.Map<T,FluidAmount>
getValues()
protected void
mergeInternal(FluidVolume vol, FluidAmount.FluidMergeResult result)
Actually merges twoFluidVolume
's together.protected void
normalize()
protected abstract T
readValue(net.minecraft.nbt.CompoundTag holder)
Inverse ofwriteValue(CompoundTag, Object)
.protected T
readValueFromMcBuffer(net.minecraft.network.PacketByteBuf buffer)
protected void
readValuesFromMcBuffer(net.minecraft.network.PacketByteBuf buffer, java.util.Map<T,FluidAmount> map)
protected abstract java.lang.String
saveName()
protected WeightedFluidVolume<T>
split0(FluidAmount toTake, java.math.RoundingMode rounding)
com.google.gson.JsonObject
toJson()
protected abstract com.google.gson.JsonElement
toJson(T value)
protected void
toMcBufferInternal(net.minecraft.network.PacketByteBuf buffer)
net.minecraft.nbt.CompoundTag
toTag(net.minecraft.nbt.CompoundTag tag)
protected abstract void
writeValue(net.minecraft.nbt.CompoundTag holder, T value)
protected void
writeValuesToMcBuffer(net.minecraft.network.PacketByteBuf buffer, java.util.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. -
WeightedFluidVolume
-
WeightedFluidVolume
public WeightedFluidVolume(WeightedFluidKey<T> key, com.google.gson.JsonObject json, WeightedFluidVolume.WeightedStringGetter<T> keyGetter) throws com.google.gson.JsonSyntaxExceptionJson 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(WeightedFluidKey, JsonObject, WeightedJsonGetter)
-
WeightedFluidVolume
public WeightedFluidVolume(WeightedFluidKey<T> key, com.google.gson.JsonObject json, WeightedFluidVolume.WeightedJsonGetter<T> keyGetter) throws com.google.gson.JsonSyntaxExceptionJson 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:
WeightedFluidVolume(WeightedFluidKey, JsonObject, WeightedStringGetter)
-
-
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.CompoundTag toTag(net.minecraft.nbt.CompoundTag tag)- Overrides:
toTag
in classFluidVolume
-
saveName
protected abstract java.lang.String saveName()- Returns:
- The name to use when saving/loading the
values
map to/from disk. This is only used intoTag(CompoundTag)
,WeightedFluidVolume(WeightedFluidKey, CompoundTag)
,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(CompoundTag, Object)
. -
writeValue
- Parameters:
holder
- TheCompoundTag
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, java.util.Map<T,FluidAmount> map) -
readValuesFromMcBuffer
protected void readValuesFromMcBuffer(net.minecraft.network.PacketByteBuf buffer, java.util.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
public java.util.List<net.minecraft.text.Text> getTooltipText(net.minecraft.client.item.TooltipContext ctx)- Overrides:
getTooltipText
in classFluidVolume
-