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 interfaceWeightedFluidVolume.WeightedJsonGetter<T>static interfaceWeightedFluidVolume.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 voidaddAmount(T value, FluidAmount amount)voidaddAmount(T value, FluidAmount amount, FluidAmount.FluidMergeRounding rounding)voidaddAmounts(java.util.Map<T,FluidAmount> sources)protected abstract booleanareJsonValuesCompact()protected WeightedFluidVolume<T>copy0()protected TdefaultValue()protected voidfromMcBufferInternal(net.minecraft.network.PacketByteBuf buffer)WeightedFluidKey<T>getFluidKey()protected net.minecraft.text.TextgetTextFor(T value)java.util.List<net.minecraft.text.Text>getTooltipText(net.minecraft.client.item.TooltipContext ctx)java.util.Map<T,FluidAmount>getValues()protected voidmergeInternal(FluidVolume vol, FluidAmount.FluidMergeResult result)Actually merges twoFluidVolume's together.protected voidnormalize()protected abstract TreadValue(net.minecraft.nbt.CompoundTag holder)Inverse ofwriteValue(CompoundTag, Object).protected TreadValueFromMcBuffer(net.minecraft.network.PacketByteBuf buffer)protected voidreadValuesFromMcBuffer(net.minecraft.network.PacketByteBuf buffer, java.util.Map<T,FluidAmount> map)protected abstract java.lang.StringsaveName()protected WeightedFluidVolume<T>split0(FluidAmount toTake, java.math.RoundingMode rounding)com.google.gson.JsonObjecttoJson()protected abstract com.google.gson.JsonElementtoJson(T value)protected voidtoMcBufferInternal(net.minecraft.network.PacketByteBuf buffer)net.minecraft.nbt.CompoundTagtoTag(net.minecraft.nbt.CompoundTag tag)protected abstract voidwriteValue(net.minecraft.nbt.CompoundTag holder, T value)protected voidwriteValuesToMcBuffer(net.minecraft.network.PacketByteBuf buffer, java.util.Map<T,FluidAmount> map)protected voidwriteValueToMcBuffer(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:
toJsonin classFluidVolume
-
toMcBufferInternal
protected void toMcBufferInternal(net.minecraft.network.PacketByteBuf buffer)- Overrides:
toMcBufferInternalin classFluidVolume
-
fromMcBufferInternal
protected void fromMcBufferInternal(net.minecraft.network.PacketByteBuf buffer)- Overrides:
fromMcBufferInternalin classFluidVolume
-
normalize
protected final void normalize() -
toTag
public net.minecraft.nbt.CompoundTag toTag(net.minecraft.nbt.CompoundTag tag)- Overrides:
toTagin classFluidVolume
-
saveName
protected abstract java.lang.String saveName()- Returns:
- The name to use when saving/loading the
valuesmap 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- TheCompoundTagto 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 aJsonPrimitivewith a string, that can read back with theWeightedFluidVolume.WeightedStringGetter. Otherwise there are no limits on what this can return, other than that theWeightedFluidVolume.WeightedJsonGettershould 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:
getFluidKeyin classFluidVolume- Returns:
- The
FluidKeyfor 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:
copy0in classFluidVolume
-
split0
- Overrides:
split0in classFluidVolume- Parameters:
toTake- A valid subtractable amount.- Returns:
- A new
FluidVolumewith the given amount that has been removed from this.
-
mergeInternal
Description copied from class:FluidVolumeActually merges twoFluidVolume's together. OnlyFluidVolume.merge(FluidVolume, FluidMergeRounding, Simulation)should call this. (Except for subclasses that override this method).- Overrides:
mergeInternalin 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:
getTooltipTextin classFluidVolume
-