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 classstatic interface -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ItemUseAnimationThe field for theanimationrecord component.static final com.mojang.serialization.Codec<Consumable> private static final intprivate static final floatprivate final floatThe field for theconsumeSecondsrecord component.static final floatprivate final booleanThe field for thehasConsumeParticlesrecord component.private final List<ConsumeEffect> The field for theonConsumeEffectsrecord component.private final Holder<SoundEvent> The field for thesoundrecord 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 aConsumablerecord class. -
Method Summary
Modifier and TypeMethodDescriptionReturns the value of theanimationrecord component.static Consumable.Builderbuilder()booleancanConsume(LivingEntity pEntity, ItemStack pStack) floatReturns the value of theconsumeSecondsrecord component.intvoidemitParticlesAndSounds(RandomSource pRandom, LivingEntity pEntity, ItemStack pStack, int pAmount) final booleanIndicates whether some other object is "equal to" this one.booleanReturns the value of thehasConsumeParticlesrecord component.final inthashCode()Returns a hash code value for this object.onConsume(Level pLevel, LivingEntity pEntity, ItemStack pStack) Returns the value of theonConsumeEffectsrecord component.booleanshouldEmitParticlesAndSounds(int pRemainingUseDuration) sound()Returns the value of thesoundrecord component.startConsuming(LivingEntity pEntity, ItemStack pStack, InteractionHand pHand) final StringtoString()Returns a string representation of this record class.
-
Field Details
-
consumeSeconds
private final float consumeSecondsThe field for theconsumeSecondsrecord component. -
animation
The field for theanimationrecord component. -
sound
The field for thesoundrecord component. -
hasConsumeParticles
private final boolean hasConsumeParticlesThe field for thehasConsumeParticlesrecord component. -
onConsumeEffects
The field for theonConsumeEffectsrecord 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 aConsumablerecord class.- Parameters:
consumeSeconds- the value for theconsumeSecondsrecord componentanimation- the value for theanimationrecord componentsound- the value for thesoundrecord componenthasConsumeParticles- the value for thehasConsumeParticlesrecord componentonConsumeEffects- the value for theonConsumeEffectsrecord component
-
-
Method Details
-
startConsuming
public InteractionResult startConsuming(LivingEntity pEntity, ItemStack pStack, InteractionHand pHand) -
onConsume
-
canConsume
-
consumeTicks
public int consumeTicks() -
emitParticlesAndSounds
public void emitParticlesAndSounds(RandomSource pRandom, LivingEntity pEntity, ItemStack pStack, int pAmount) -
shouldEmitParticlesAndSounds
public boolean shouldEmitParticlesAndSounds(int pRemainingUseDuration) -
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 theconsumeSecondsrecord component.- Returns:
- the value of the
consumeSecondsrecord component
-
animation
Returns the value of theanimationrecord component.- Returns:
- the value of the
animationrecord component
-
sound
Returns the value of thesoundrecord component.- Returns:
- the value of the
soundrecord component
-
hasConsumeParticles
public boolean hasConsumeParticles()Returns the value of thehasConsumeParticlesrecord component.- Returns:
- the value of the
hasConsumeParticlesrecord component
-
onConsumeEffects
Returns the value of theonConsumeEffectsrecord component.- Returns:
- the value of the
onConsumeEffectsrecord component
-