Class ConsumableChemicalHandler

java.lang.Object
ml.pluto7073.chemicals.handlers.ConsumableChemicalHandler
Direct Known Subclasses:
HalfLifeChemicalHandler, LinearChemicalHandler, StaticChemicalHandler

public abstract class ConsumableChemicalHandler extends Object
The base class representing a Chemical

Three pre-made handlers already exist:

HalfLifeChemicalHandler

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

LinearChemicalHandler

The simplest handler. Removed a set amount of chemical from the player each tick, until the amount reaches zero

StaticChemicalHandler

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

    Fields
    Modifier and Type
    Field
    Description
    protected final net.minecraft.network.syncher.EntityDataAccessor<Float>
     
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    float
    add(net.minecraft.world.entity.player.Player player, float amount)
    Adds the chemical to a player
    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
    @Nullable com.mojang.brigadier.builder.LiteralArgumentBuilder<net.minecraft.commands.CommandSourceStack>
    Implement this method if you want custom syntax for this chemical's command using /chemicals
    void
    defineDataForPlayer(net.minecraft.network.syncher.SynchedEntityData.Builder data)
     
    formatAmount(float amount)
    Appends the units that this amount is tracked in to the amount, e.g.
    float
    get(net.minecraft.world.entity.player.Player player)
    Gets the current amount of the chemical in the player
    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
    net.minecraft.resources.ResourceLocation
     
     
    void
    loadExtraPlayerData(net.minecraft.world.entity.player.Player player, net.minecraft.nbt.CompoundTag tag)
    Load any extra data required for the Chemical Handler
    void
    saveExtraPlayerData(net.minecraft.world.entity.player.Player player, net.minecraft.nbt.CompoundTag tag)
    Store any extra data required for the Chemical Handler
    void
    set(net.minecraft.world.entity.player.Player player, float amount)
    Sets amount of chemical in a player
    abstract void
    tickPlayer(net.minecraft.world.entity.player.Player player)
    Updates the current amount of the chemical in the specified player

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • EMPTY

      public static final ConsumableChemicalHandler EMPTY
    • accessor

      protected final net.minecraft.network.syncher.EntityDataAccessor<Float> accessor
  • Constructor Details

    • ConsumableChemicalHandler

      public ConsumableChemicalHandler()
  • Method Details

    • tickPlayer

      public abstract void tickPlayer(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
    • add

      public float add(net.minecraft.world.entity.player.Player player, float amount)
      Adds the chemical to a player
      Parameters:
      player - The player to add to
      amount - 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
      Parameters:
      player - The player to set
      amount - Amount of chemical
    • 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 chemical
      level - The current Level, for utility purposes
      Returns:
      A list of MobEffectInstances
    • defineDataForPlayer

      public void defineDataForPlayer(net.minecraft.network.syncher.SynchedEntityData.Builder 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 tooltips
      amount - The amount in the stack
      stack - The current stack, for utility purposes
    • getId

      public net.minecraft.resources.ResourceLocation getId()
    • getLanguageKey

      public String getLanguageKey()
    • formatAmount

      public String formatAmount(float amount)
      Appends the units that this amount is tracked in to the amount, e.g. amount + "mg" or amount + "L"
    • 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 LiteralArgumentBuilder representing the entire subcommand for this chemical

      Note: 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 from
      tag - 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 to
      tag - The tag to load from