Interface Sprayed

All Superinterfaces:
Custom, net.minecraft.item.ItemConvertible, Registered, Registered.Client, Registered.Common
All Known Implementing Classes:
SprayBottleItem, SprayPotionItem

public interface Sprayed extends Registered.Client, Custom
Provides common functionality for spray items.
Since:
2.0.0
See Also:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static final record 
    Describes and implements a behavior when spraying an object.
    static final record 
    Describes the target block of a spray invocation.
    static final record 
    Describes the target entity of a spray invocation.
    static final record 
    Describes a spray item refilling context.
    static final record 
    Describes the source of a spray item interaction.
    static final record 
    The result of spraying an object.
    static interface 
    Describes the target of a spray invocation.

    Nested classes/interfaces inherited from interface dev.jaxydog.astral.register.Registered

    Registered.All, Registered.Client, Registered.Common, Registered.Generated, Registered.Server
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final net.minecraft.util.Identifier
    The identifier corresponding to a spray item's 'empty' model.
    static final SoundContext
    The sound played when refilling a spray item.
    static final SoundContext
    The sound played when spraying a spray item.
  • Method Summary

    Modifier and Type
    Method
    Description
    <T extends Sprayed.SprayTarget>
    void
    addBehavior(Class<T> type, Sprayed.Behavior<T> behavior)
    Adds a new behavior to this spray item.
    default boolean
    canSpray(Sprayed.Source source, Sprayed.BlockTarget target, int charges)
    Returns whether the given item stack may spray the target block and consume the given charge count.
    default boolean
    canSpray(Sprayed.Source source, Sprayed.EntityTarget target, int charges)
    Returns whether the given item stack may spray the target entity and consume the given charge count.
    Returns a list of behaviors for this spray item.
    default int
    getCharges(net.minecraft.item.ItemStack stack)
    Returns the number of times the given item stack may be sprayed before requiring a refill.
    default int
    getCooldown(net.minecraft.item.ItemStack stack)
    Returns the given item stack's usage cooldown in ticks.
    default int
    getDuration(net.minecraft.item.ItemStack stack)
    Returns the given item stack's spray duration in ticks.
    default float
    getEmptyModelData(net.minecraft.item.ItemStack stack, net.minecraft.world.World world, net.minecraft.entity.LivingEntity entity, int seed)
    Returns the data used within a spray item's model in order to determine its current texture.
    default int
    getMaxCharges(net.minecraft.item.ItemStack stack)
    Returns the maximum number of times the given item stack may be sprayed before requiring a refill.
    default boolean
    isEmpty(net.minecraft.item.ItemStack stack)
    Returns whether the given item stack is empty.
    default boolean
    isFilled(net.minecraft.item.ItemStack stack)
    Returns whether the given item stack is filled.
    default boolean
    isRefillable(net.minecraft.item.ItemStack stack)
    Returns whether the given item stack may be refilled.
    default boolean
    isSprayable(net.minecraft.item.ItemStack stack)
    Returns whether the given item stack contains at least 1 remaining charge and can therefore be sprayed.
    default boolean
    isSprayable(net.minecraft.item.ItemStack stack, int charges)
    Returns whether the given item stack contains at least charges remaining charges and can therefore be sprayed.
    onSpray(Sprayed.Source source, Sprayed.BlockTarget target, boolean silent)
    Runs actions on a sprayed block, returning a result.
    onSpray(Sprayed.Source source, Sprayed.EntityTarget target, boolean silent)
    Runs actions on a sprayed target, returning a result.
    default void
    Refills the spray item using the given context.
    default void
    Registers this value on the client environment.
    default void
    setCharges(net.minecraft.item.ItemStack stack, int charges)
    Sets the number of times the given item stack may be sprayed before requiring a refill.
    default boolean
    spray(Sprayed.Source source, net.minecraft.world.World world, Sprayed.SprayResult result)
    Sprays the item.
    default boolean
    spray(net.minecraft.item.ItemStack stack, @Nullable net.minecraft.entity.LivingEntity actor, net.minecraft.util.math.Vec3d from, net.minecraft.entity.Entity target, boolean silent)
    Sprays a target entity.
    default boolean
    spray(net.minecraft.item.ItemStack stack, @Nullable net.minecraft.entity.LivingEntity actor, net.minecraft.util.math.Vec3d from, net.minecraft.world.World world, net.minecraft.util.math.BlockPos pos, net.minecraft.util.math.Direction side, boolean silent)
    Sprays a block.

    Methods inherited from interface dev.jaxydog.astral.content.item.Custom

    getItemGroup, registerCommon

    Methods inherited from interface net.minecraft.item.ItemConvertible

    asItem

    Methods inherited from interface dev.jaxydog.astral.register.Registered

    getRegistryId, getRegistryPath
  • Field Details

    • EMPTY_MODEL_ID

      static final net.minecraft.util.Identifier EMPTY_MODEL_ID
      The identifier corresponding to a spray item's 'empty' model.

      This is expected to be used only within the ModelPredicateProviderRegistry.

      Since:
      2.0.0
    • SPRAY_SOUND

      static final SoundContext SPRAY_SOUND
      The sound played when spraying a spray item.
      Since:
      2.0.0
    • REFILL_SOUND

      static final SoundContext REFILL_SOUND
      The sound played when refilling a spray item.
      Since:
      2.0.0
  • Method Details

    • addBehavior

      <T extends Sprayed.SprayTarget> void addBehavior(Class<T> type, Sprayed.Behavior<T> behavior)
      Adds a new behavior to this spray item.
      Type Parameters:
      T - The behavior's target type.
      Parameters:
      type - The class of the behavior's target type.
      behavior - The entity behavior.
      Since:
      2.0.0
    • getBehaviors

      <T extends Sprayed.SprayTarget> List<Sprayed.Behavior<T>> getBehaviors(Class<T> type)
      Returns a list of behaviors for this spray item.
      Type Parameters:
      T - The behavior's expected target type.
      Parameters:
      type - The class of the behavior's expected target type.
      Returns:
      A list of behaviors.
      Since:
      2.0.0
    • getEmptyModelData

      default float getEmptyModelData(net.minecraft.item.ItemStack stack, net.minecraft.world.World world, net.minecraft.entity.LivingEntity entity, int seed)
      Returns the data used within a spray item's model in order to determine its current texture.

      If the stack is considered 'empty', this method should return 1F. Otherwise, it should return 0F. This method may be overwritten to allow for additional numbers between [0, 1], however this range should not be exceeded.

      Parameters:
      stack - The item stack.
      world - The current world.
      entity - The entity holding the item.
      seed - The randomness seed.
      Returns:
      A number between 0 and 1.
      Since:
      2.0.0
    • getCooldown

      default int getCooldown(net.minecraft.item.ItemStack stack)
      Returns the given item stack's usage cooldown in ticks.

      A value of less than or equal to 0 should be interpreted as having no cooldown.

      The default implementation returns a duration of 8 ticks.

      Parameters:
      stack - The item stack.
      Returns:
      The cooldown in ticks.
      Since:
      2.0.0
    • getDuration

      default int getDuration(net.minecraft.item.ItemStack stack)
      Returns the given item stack's spray duration in ticks.

      This is used within the implementation of SprayableEntity to determine reactions.

      A value of less than or equal to 0 should be interpreted as the item being unable to spray SprayableEntity instances.

      The default implementation returns a duration of 40 ticks.

      Parameters:
      stack - The item stack.
      Returns:
      The duration in ticks.
      Since:
      2.0.0
    • getMaxCharges

      default int getMaxCharges(net.minecraft.item.ItemStack stack)
      Returns the maximum number of times the given item stack may be sprayed before requiring a refill.

      A value of 0 means that the item may not be sprayed.

      The default implementation returns the stack's maximum damage amount. If this is overridden, getCharges(ItemStack) and setCharges(ItemStack, int) should also be updated.

      Parameters:
      stack - The item stack.
      Returns:
      The number of charges.
      Since:
      2.0.0
    • getCharges

      default int getCharges(net.minecraft.item.ItemStack stack)
      Returns the number of times the given item stack may be sprayed before requiring a refill.

      A value of 0 means that the item may not be sprayed.

      The default implementation returns the stack's remaining durability. If this is overridden, getMaxCharges(ItemStack) and setCharges(ItemStack, int) should also be updated.

      Parameters:
      stack - The item stack.
      Returns:
      The number of charges.
      Since:
      2.0.0
    • setCharges

      default void setCharges(net.minecraft.item.ItemStack stack, int charges)
      Sets the number of times the given item stack may be sprayed before requiring a refill.

      The given value will never be outside [0, getMaxCharges(ItemStack)].

      Parameters:
      stack - The item stack.
      charges - The number of charges.
      Since:
      2.0.0
    • isSprayable

      default boolean isSprayable(net.minecraft.item.ItemStack stack, int charges)
      Returns whether the given item stack contains at least charges remaining charges and can therefore be sprayed.
      Parameters:
      stack - The item stack.
      charges - The required charges.
      Returns:
      Whether the stack may be sprayed.
      Since:
      2.0.0
    • isSprayable

      default boolean isSprayable(net.minecraft.item.ItemStack stack)
      Returns whether the given item stack contains at least 1 remaining charge and can therefore be sprayed.
      Parameters:
      stack - The item stack.
      Returns:
      Whether the stack may be sprayed.
      Since:
      2.0.0
    • isFilled

      default boolean isFilled(net.minecraft.item.ItemStack stack)
      Returns whether the given item stack is filled.

      The default implementation checks whether the current charges are at least the maximum.

      Parameters:
      stack - The item stack.
      Returns:
      Whether the stack may be refilled.
      Since:
      2.0.0
    • isRefillable

      default boolean isRefillable(net.minecraft.item.ItemStack stack)
      Returns whether the given item stack may be refilled.

      The default implementation checks whether the current charges are less than the maximum.

      Parameters:
      stack - The item stack.
      Returns:
      Whether the stack may be refilled.
      Since:
      2.0.0
    • isEmpty

      default boolean isEmpty(net.minecraft.item.ItemStack stack)
      Returns whether the given item stack is empty.

      The default implementation just asserts that the remaining charges are less than or equal to zero.

      Parameters:
      stack - The item stack.
      Returns:
      Whether the stack is empty.
      Since:
      2.0.0
    • canSpray

      default boolean canSpray(Sprayed.Source source, Sprayed.EntityTarget target, int charges)
      Returns whether the given item stack may spray the target entity and consume the given charge count.
      Parameters:
      source - The spray source.
      target - The spray target.
      charges - The number of charges.
      Returns:
      Whether the target may be sprayed.
      Since:
      2.0.0
    • canSpray

      default boolean canSpray(Sprayed.Source source, Sprayed.BlockTarget target, int charges)
      Returns whether the given item stack may spray the target block and consume the given charge count.
      Parameters:
      source - The spray source.
      target - The spray target.
      charges - The number of charges.
      Returns:
      Whether the block may be sprayed.
      Since:
      2.0.0
    • onSpray

      default Sprayed.SprayResult onSpray(Sprayed.Source source, Sprayed.EntityTarget target, boolean silent)
      Runs actions on a sprayed target, returning a result.
      Parameters:
      source - The spray source.
      target - The spray target.
      silent - Whether the spray sound should be skipped.
      Returns:
      The spray result.
      Since:
      2.0.0
    • onSpray

      default Sprayed.SprayResult onSpray(Sprayed.Source source, Sprayed.BlockTarget target, boolean silent)
      Runs actions on a sprayed block, returning a result.
      Parameters:
      source - The spray source.
      target - The spray target.
      silent - Whether the spray sound should be skipped.
      Returns:
      The spray result.
      Since:
      2.0.0
    • spray

      default boolean spray(net.minecraft.item.ItemStack stack, @Nullable @Nullable net.minecraft.entity.LivingEntity actor, net.minecraft.util.math.Vec3d from, net.minecraft.entity.Entity target, boolean silent)
      Sprays a target entity.

      This method should not be overwritten directly, instead you should prefer overwriting onSpray(Source, EntityTarget, boolean).

      Parameters:
      stack - The item stack.
      actor - The actor entity.
      from - The source position.
      target - The target entity.
      silent - Whether the spray sound should be skipped.
      Returns:
      Whether the target was sprayed.
      Since:
      2.0.0
    • spray

      default boolean spray(net.minecraft.item.ItemStack stack, @Nullable @Nullable net.minecraft.entity.LivingEntity actor, net.minecraft.util.math.Vec3d from, net.minecraft.world.World world, net.minecraft.util.math.BlockPos pos, net.minecraft.util.math.Direction side, boolean silent)
      Sprays a block.

      This method should not be overwritten directly, instead you should prefer overwriting onSpray(Source, BlockTarget, boolean).

      Parameters:
      stack - The item stack.
      actor - The actor entity.
      from - The source position.
      world - The current world.
      pos - The block position.
      side - The sprayed side.
      silent - Whether the spray sound should be skipped.
      Returns:
      Whether the target was sprayed.
      Since:
      2.0.0
    • spray

      default boolean spray(Sprayed.Source source, net.minecraft.world.World world, Sprayed.SprayResult result)
      Parameters:
      source - The spray source.
      result - The result of another spray method.
      Returns:
      Whether the result was acted upon.
      Since:
      2.0.0
    • refill

      default void refill(Sprayed.Source source, Sprayed.RefillContext context)
      Refills the spray item using the given context.
      Parameters:
      source - The refill source.
      context - The refill context.
      Since:
      2.0.0
    • registerClient

      default void registerClient()
      Description copied from interface: Registered.Client
      Registers this value on the client environment.

      The contained code will only ever run on the game client. If you only want the server or want both, see its sister interfaces.

      Specified by:
      registerClient in interface Registered.Client
      See Also: