Record Class Consumable
java.lang.Object
java.lang.Record
net.minecraft.world.item.component.Consumable
public record Consumable(float consumeSeconds, ItemUseAnimation animation, Holder<SoundEvent> sound, boolean hasConsumeParticles, List<ConsumeEffect> onConsumeEffects)
extends Record
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
static interface
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ItemUseAnimation
The field for theanimation
record component.static final com.mojang.serialization.Codec
<Consumable> private static final int
private static final float
private final float
The field for theconsumeSeconds
record component.static final float
private final boolean
The field for thehasConsumeParticles
record component.private final List
<ConsumeEffect> The field for theonConsumeEffects
record component.private final Holder
<SoundEvent> The field for thesound
record component.static final StreamCodec
<RegistryFriendlyByteBuf, Consumable> -
Constructor Summary
ConstructorsConstructorDescriptionConsumable
(float consumeSeconds, ItemUseAnimation animation, Holder<SoundEvent> sound, boolean hasConsumeParticles, List<ConsumeEffect> onConsumeEffects) Creates an instance of aConsumable
record class. -
Method Summary
Modifier and TypeMethodDescriptionReturns the value of theanimation
record component.static Consumable.Builder
builder()
boolean
canConsume
(LivingEntity p_366522_, ItemStack p_366908_) float
Returns the value of theconsumeSeconds
record component.int
void
emitParticlesAndSounds
(RandomSource p_366511_, LivingEntity p_366794_, ItemStack p_366479_, int p_366619_) final boolean
Indicates whether some other object is "equal to" this one.boolean
Returns the value of thehasConsumeParticles
record component.final int
hashCode()
Returns a hash code value for this object.onConsume
(Level p_366638_, LivingEntity p_366573_, ItemStack p_366688_) Returns the value of theonConsumeEffects
record component.boolean
shouldEmitParticlesAndSounds
(int p_366816_) sound()
Returns the value of thesound
record component.startConsuming
(LivingEntity p_366412_, ItemStack p_366449_, InteractionHand p_366742_) final String
toString()
Returns a string representation of this record class.
-
Field Details
-
consumeSeconds
private final float consumeSecondsThe field for theconsumeSeconds
record component. -
animation
The field for theanimation
record component. -
sound
The field for thesound
record component. -
hasConsumeParticles
private final boolean hasConsumeParticlesThe field for thehasConsumeParticles
record component. -
onConsumeEffects
The field for theonConsumeEffects
record component. -
DEFAULT_CONSUME_SECONDS
public static final float DEFAULT_CONSUME_SECONDS- See Also:
-
CONSUME_EFFECTS_INTERVAL
private static final int CONSUME_EFFECTS_INTERVAL- See Also:
-
CONSUME_EFFECTS_START_FRACTION
private static final float CONSUME_EFFECTS_START_FRACTION- See Also:
-
CODEC
-
STREAM_CODEC
-
-
Constructor Details
-
Consumable
public Consumable(float consumeSeconds, ItemUseAnimation animation, Holder<SoundEvent> sound, boolean hasConsumeParticles, List<ConsumeEffect> onConsumeEffects) Creates an instance of aConsumable
record class.- Parameters:
consumeSeconds
- the value for theconsumeSeconds
record componentanimation
- the value for theanimation
record componentsound
- the value for thesound
record componenthasConsumeParticles
- the value for thehasConsumeParticles
record componentonConsumeEffects
- the value for theonConsumeEffects
record component
-
-
Method Details
-
startConsuming
public InteractionResult startConsuming(LivingEntity p_366412_, ItemStack p_366449_, InteractionHand p_366742_) -
onConsume
-
canConsume
-
consumeTicks
public int consumeTicks() -
emitParticlesAndSounds
public void emitParticlesAndSounds(RandomSource p_366511_, LivingEntity p_366794_, ItemStack p_366479_, int p_366619_) -
shouldEmitParticlesAndSounds
public boolean shouldEmitParticlesAndSounds(int p_366816_) -
builder
-
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared withObjects::equals(Object,Object)
; primitive components are compared with '=='. -
consumeSeconds
public float consumeSeconds()Returns the value of theconsumeSeconds
record component.- Returns:
- the value of the
consumeSeconds
record component
-
animation
Returns the value of theanimation
record component.- Returns:
- the value of the
animation
record component
-
sound
Returns the value of thesound
record component.- Returns:
- the value of the
sound
record component
-
hasConsumeParticles
public boolean hasConsumeParticles()Returns the value of thehasConsumeParticles
record component.- Returns:
- the value of the
hasConsumeParticles
record component
-
onConsumeEffects
Returns the value of theonConsumeEffects
record component.- Returns:
- the value of the
onConsumeEffects
record component
-