Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactored Tater Effect registration and updated docs #224

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions develop/entities/effects.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,31 @@
}
```

### 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: <br/>
`/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<StatusEffect>` - a registry entry that represents our effect. <br/>
`duration`: `int` - the duration of the effect **in ticks**; not seconds. <br/>
`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` <br/>

Check failure on line 81 in develop/entities/effects.md

View workflow job for this annotation

GitHub Actions / markdownlint

Trailing spaces

develop/entities/effects.md:81:1 MD009/no-trailing-spaces Trailing spaces [Expected: 0; Actual: 1] https://github.com/DavidAnson/markdownlint/blob/v0.34.0/doc/md009.md
`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. <br/>
`particles`: `boolean` - whether to show particles. <br/>
`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. <br/>

::: info
To create a potion that uses this effect, please see the [Potions](../items/potions) guide.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<StatusEffect> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
import net.minecraft.entity.player.PlayerEntity;

// :::1
public class TaterEffect extends StatusEffect {

Check failure on line 9 in reference/latest/src/main/java/com/example/docs/effect/TaterEffect.java

View workflow job for this annotation

GitHub Actions / mod

blank line after {

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)
Expand All @@ -25,8 +26,7 @@
public boolean applyUpdateEffect(LivingEntity entity, int amplifier) {
if (entity instanceof PlayerEntity) {
((PlayerEntity) entity).addExperience(1 << amplifier); // Higher amplifier gives you experience faster
}

Check failure on line 29 in reference/latest/src/main/java/com/example/docs/effect/TaterEffect.java

View workflow job for this annotation

GitHub Actions / mod

missing blank line after block at same indentation level

return super.applyUpdateEffect(entity, amplifier);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)));

Expand Down
Loading