diff --git a/develop/entities/effects.md b/develop/entities/effects.md index a20ebc411..c853664b5 100644 --- a/develop/entities/effects.md +++ b/develop/entities/effects.md @@ -57,10 +57,31 @@ language file. } ``` -### Testing {#testing} +### Applying The Effect {#applying-the-effect} -Use the command `/effect give @p fabric-docs-reference:tater` to give the player our Tater effect. -Use `/effect clear @p fabric-docs-reference:tater` to remove the effect. +It's worth taking a look at how you'd typically apply an effect to an entity. + +::: tip +For a quick test, it might be a better idea to use the previously mentioned `/effect` command:
+`/effect give @p fabric-docs-reference:tater` +::: + +To apply an effect internally, you'd want to use the `LivingEntity#addStatusEffect` method, that takes in +a `StatusEffectInstance`, and returns a boolean, specifying whether the effect was applied successfully. + +Let's create a `StatusEffectInstance` by using its 6-Argument constructor: + +```java +var instance = new StatusEffectInstance(FabricDocsReferenceEffects.TATER, 5 * 20, 0, false, true, true); +``` + +`effect`: `RegistryEntry` - a registry entry that represents our effect.
+`duration`: `int` - the duration of the effect **in ticks**; not seconds.
+`amplifier`: `int` - the amplifier to the level of the effect. It doesn't correspond to **the level** of the effect, but is rather added on top. Hence, `amplifier` of `4` => level of `5`
+ +`ambient`: `boolean` - this is a tricky one. It basically specifies that the effect was added by the environment (e.g. **Beacon**) and doesn't have a direct cause. If `true`, the icon of the effect in the HUD will appear with an aqua overlay.
+`particles`: `boolean` - whether to show particles.
+`icon`: `boolean` - whether to display an icon of the effect in the HUD. The effect will be displayed in the inventory regardless of this flag.
::: info To create a potion that uses this effect, please see the [Potions](../items/potions) guide. diff --git a/reference/latest/src/main/java/com/example/docs/effect/FabricDocsReferenceEffects.java b/reference/latest/src/main/java/com/example/docs/effect/FabricDocsReferenceEffects.java index c9b10fc22..61b9d319d 100644 --- a/reference/latest/src/main/java/com/example/docs/effect/FabricDocsReferenceEffects.java +++ b/reference/latest/src/main/java/com/example/docs/effect/FabricDocsReferenceEffects.java @@ -3,16 +3,17 @@ import net.minecraft.entity.effect.StatusEffect; import net.minecraft.registry.Registries; import net.minecraft.registry.Registry; +import net.minecraft.registry.entry.RegistryEntry; import net.minecraft.util.Identifier; import net.fabricmc.api.ModInitializer; // :::1 public class FabricDocsReferenceEffects implements ModInitializer { - public static final StatusEffect TATER_EFFECT; + public static final RegistryEntry TATER; static { - TATER_EFFECT = Registry.register(Registries.STATUS_EFFECT, Identifier.of("fabric-docs-reference", "tater"), new TaterEffect()); + TATER = Registry.registerReference(Registries.STATUS_EFFECT, Identifier.of("fabric-docs-reference", "tater"), new TaterEffect()); } @Override diff --git a/reference/latest/src/main/java/com/example/docs/effect/TaterEffect.java b/reference/latest/src/main/java/com/example/docs/effect/TaterEffect.java index eb0a705b5..04901bab8 100644 --- a/reference/latest/src/main/java/com/example/docs/effect/TaterEffect.java +++ b/reference/latest/src/main/java/com/example/docs/effect/TaterEffect.java @@ -7,6 +7,7 @@ // :::1 public class TaterEffect extends StatusEffect { + protected TaterEffect() { // category: StatusEffectCategory - describes if the effect is helpful (BENEFICIAL), harmful (HARMFUL) or useless (NEUTRAL) // color: int - Color is the color assigned to the effect (in RGB) @@ -26,7 +27,6 @@ public boolean applyUpdateEffect(LivingEntity entity, int amplifier) { if (entity instanceof PlayerEntity) { ((PlayerEntity) entity).addExperience(1 << amplifier); // Higher amplifier gives you experience faster } - return super.applyUpdateEffect(entity, amplifier); } } diff --git a/reference/latest/src/main/java/com/example/docs/potion/FabricDocsReferencePotions.java b/reference/latest/src/main/java/com/example/docs/potion/FabricDocsReferencePotions.java index dd6264317..3431e8596 100644 --- a/reference/latest/src/main/java/com/example/docs/potion/FabricDocsReferencePotions.java +++ b/reference/latest/src/main/java/com/example/docs/potion/FabricDocsReferencePotions.java @@ -21,7 +21,7 @@ public class FabricDocsReferencePotions implements ModInitializer { Identifier.of("fabric-docs-reference", "tater"), new Potion( new StatusEffectInstance( - Registries.STATUS_EFFECT.getEntry(FabricDocsReferenceEffects.TATER_EFFECT), + FabricDocsReferenceEffects.TATER, 3600, 0)));