Package ml.pluto7073.chemicals.handlers
Class ChemicalHandler
java.lang.Object
ml.pluto7073.chemicals.handlers.ChemicalHandler
- Direct Known Subclasses:
HalfLifeChemicalHandler,LinearChemicalHandler,StaticChemicalHandler
The base class representing a Chemical
Three pre-made handlers already exist:
The most realistic of the two. Exponentially ticks down the amount of the chemical in the player's body based on the half life in ticks specified
The simplest handler. Removed a set amount of chemical from the player each tick, until the amount reaches zero
For chemicals that stay persistent in the player until death or a maximum amount is reached, where the latter
will perform an action on the player defined in StaticChemicalHandler.onMaxAmountReached(Player)
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final net.minecraft.network.syncher.EntityDataAccessor<Float> static final ChemicalHandlerprotected final floatprotected final net.minecraft.network.syncher.EntityDataAccessor<Integer> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfloatadd(net.minecraft.world.entity.player.Player player, float amount) Deprecated.voidappendTooltip(List<net.minecraft.network.chat.Component> tooltip, float amount, net.minecraft.world.item.ItemStack stack) Appends a tooltip to an item containing this chemicalvoidbloom(org.joml.Vector4f rgba, net.minecraft.world.entity.player.Player player) voidcontrast(org.joml.Vector4f rgba, net.minecraft.world.entity.player.Player player) @Nullable com.mojang.brigadier.builder.LiteralArgumentBuilder<net.minecraft.commands.CommandSourceStack> Implement this method if you want custom syntax for this chemical's command using/chemicalscreateInstance(ConsumedInstance.AbsorptionType type, float amount) Creates a newConsumedInstanceusing this chemical handler.createInstance(ConsumedInstance.AbsorptionType type, net.minecraft.world.item.ItemStack stack, net.minecraft.world.level.Level level) Creates a newConsumedInstanceusing this chemical handler and the specified item as an instance ofChemicalContaining.voiddefineDataForPlayer(net.minecraft.network.syncher.SynchedEntityData data) abstract voiddoTick(net.minecraft.world.entity.player.Player player) Updates the current amount of the chemical in the specified playerformatAmount(float amount) Appends the units that this amount is tracked in to the amount, e.g.floatget(net.minecraft.world.entity.player.Player player) Gets the current amount of the chemical in the playerabstract Collection<net.minecraft.world.effect.MobEffectInstance> getEffectsForAmount(float amount, net.minecraft.world.level.Level level) Get a list of effects associated with an amount of this chemicalnet.minecraft.resources.ResourceLocationgetId()floatfloatgetStrength(net.minecraft.world.entity.player.Player player) static voidinit()voidloadExtraPlayerData(net.minecraft.world.entity.player.Player player, net.minecraft.nbt.CompoundTag tag) Load any extra data required for the Chemical HandlervoidsaveExtraPlayerData(net.minecraft.world.entity.player.Player player, net.minecraft.nbt.CompoundTag tag) Store any extra data required for the Chemical Handlervoidset(net.minecraft.world.entity.player.Player player, float amount) Sets amount of chemical in a playerfinal voidtickPlayer(net.minecraft.world.entity.player.Player player)
-
Field Details
-
EMPTY
-
accessor
-
ticksAccessor
-
maxRecommendedAmount
protected final float maxRecommendedAmount
-
-
Constructor Details
-
ChemicalHandler
public ChemicalHandler(float maxRecommendedAmount)
-
-
Method Details
-
tickPlayer
public final void tickPlayer(net.minecraft.world.entity.player.Player player) -
doTick
public abstract void doTick(net.minecraft.world.entity.player.Player player) Updates the current amount of the chemical in the specified player- Parameters:
player- The player to update
-
get
public float get(net.minecraft.world.entity.player.Player player) Gets the current amount of the chemical in the player- Parameters:
player- The player to retrieve- Returns:
- Amount of the chemical
-
getStrength
public float getStrength(net.minecraft.world.entity.player.Player player) - Returns:
- The relative strength of the chemical in the specified
playerbetween 0 and 1, usingmaxRecommendedAmount
-
add
public float add(net.minecraft.world.entity.player.Player player, float amount) Deprecated.UseChemicalConsumer.addChemical(ChemicalHandler, AbsorptionType, float)orChemicalConsumer.addChemical(ConsumedInstance)to properly add chemicals to playerAdds the chemical to a player- Parameters:
player- The player to add toamount- The amount of the chemical to add- Returns:
- The new amount of the chemical in the player
-
set
public void set(net.minecraft.world.entity.player.Player player, float amount) Sets amount of chemical in a player -
getEffectsForAmount
public abstract Collection<net.minecraft.world.effect.MobEffectInstance> getEffectsForAmount(float amount, net.minecraft.world.level.Level level) Get a list of effects associated with an amount of this chemical- Parameters:
amount- Amount of the chemicallevel- The current Level, for utility purposes- Returns:
- A list of
MobEffectInstances
-
defineDataForPlayer
public void defineDataForPlayer(net.minecraft.network.syncher.SynchedEntityData data) -
appendTooltip
public void appendTooltip(List<net.minecraft.network.chat.Component> tooltip, float amount, net.minecraft.world.item.ItemStack stack) Appends a tooltip to an item containing this chemical- Parameters:
tooltip- The current list of tooltipsamount- The amount in the stackstack- The current stack, for utility purposes
-
getId
public net.minecraft.resources.ResourceLocation getId() -
getLanguageKey
-
formatAmount
Appends the units that this amount is tracked in to the amount, e.g.amount + "mg"oramount + "L" -
getMaxRecommendedAmount
public float getMaxRecommendedAmount()- Returns:
- the maximum amount of this drug in units that the player should logically have in their system. This shouldn't scale with any settings/game rules and doesn't serve as a hard limit, just a way to assign a percentage to the amount a player has
-
createCustomChemicalCommandExtension
@Nullable public @Nullable com.mojang.brigadier.builder.LiteralArgumentBuilder<net.minecraft.commands.CommandSourceStack> createCustomChemicalCommandExtension()Implement this method if you want custom syntax for this chemical's command using/chemicals- Returns:
- A
LiteralArgumentBuilderrepresenting the entire subcommand for this chemicalNote: It is recommended that this begin with
literal("YOUR_CHEMICAL_ID")
-
saveExtraPlayerData
public void saveExtraPlayerData(net.minecraft.world.entity.player.Player player, net.minecraft.nbt.CompoundTag tag) Store any extra data required for the Chemical Handler- Parameters:
player- The player to store data fromtag- The CompoundTag to store the data in
-
loadExtraPlayerData
public void loadExtraPlayerData(net.minecraft.world.entity.player.Player player, net.minecraft.nbt.CompoundTag tag) Load any extra data required for the Chemical Handler- Parameters:
player- The player to load totag- The tag to load from
-
createInstance
Creates a newConsumedInstanceusing this chemical handler.- Parameters:
type- The desired speed of absorptionamount- The total amount of the chemical to add- Returns:
- The new consumed instance
-
createInstance
public ConsumedInstance createInstance(ConsumedInstance.AbsorptionType type, net.minecraft.world.item.ItemStack stack, net.minecraft.world.level.Level level) Creates a newConsumedInstanceusing this chemical handler and the specified item as an instance ofChemicalContaining.- Parameters:
type- The desired speed of absorptionstack- The item stack to get information fromlevel- The current level- Returns:
- The new consumed instance
-
contrast
public void contrast(org.joml.Vector4f rgba, net.minecraft.world.entity.player.Player player) -
bloom
public void bloom(org.joml.Vector4f rgba, net.minecraft.world.entity.player.Player player) -
init
public static void init()
-
ChemicalConsumer.addChemical(ChemicalHandler, AbsorptionType, float)orChemicalConsumer.addChemical(ConsumedInstance)to properly add chemicals to player