Skip to content

Effetti di Stato

Effetti di stato, conosciuti anche anche come effetti, sone una condizione comune che interessa un'entità. Possono essere positivi, negativi o neutrali in natura. Il gioco base applica questi effetti in vari modi, come cibi, pozioni ecc.

Il comando /effect può essere usato per applicare effetti su un'entità.

Effetti di stato Custom

In questo tutorial aggiungeremo un nuovo effetto custom chiamto Tater che darà un punto esperienza ogni game tick.

Estendere StatusEffect

Creiamo una classe per il nostro effetto custom estendedo StatusEffect, che è la classe base per tutt gli effetti.

java
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)
		super(StatusEffectCategory.BENEFICIAL, 0xe9b8b3);
	}

	// Called every tick to check if the effect can be applied or not
	@Override
	public boolean canApplyUpdateEffect(int duration, int amplifier) {
		// In our case, we just make it return true so that it applies the effect every tick
		return true;
	}

	// Called when the effect is applied
	@Override
	public void applyUpdateEffect(LivingEntity entity, int amplifier) {
		if (entity instanceof PlayerEntity) {
			((PlayerEntity) entity).addExperience(1 << amplifier); // Higher amplifier gives you experience faster
		}
	}
}

Registrare il tuo Effetto Custom

Similarmente a registrazioni di blocchi e oggetti, usiamo Registry.register per registrare i nostri effetti custom nel registro STATUS_EFFECT. Ciò può essere fatto nel nostro initializer.

java
public class FabricDocsReferenceEffects implements ModInitializer {
	public static final StatusEffect TATER_EFFECT = new TaterEffect();

	@Override
	public void onInitialize() {
		Registry.register(Registries.STATUS_EFFECT, new Identifier("fabric-docs-reference", "tater"), TATER_EFFECT);
	}
}

Traduzione e Texture

Puoi assegnare un nome al tuo effetto di stato e fornire una texture per un icona che apparirà nello schermo dell'inventario del giocatore.

Texture

L'icona dell'effetto è un PNG 18x18. Posiziona la tua icona custom in:

resources/assets/fabric-docs-reference/textures/mob_effect/tater.png

Effetto nell'inventario del giocatore

Traduzioni

Come ogni altra tarduzione, puoi aggiungere una voce con formato ID "effect.<mod-id>.<effect-identifier>": "Valore" ai file di lingua.

json
{
  "effect.fabric-docs-reference.tater": "Tater"
}

Testing

Usa il comando /effect give @p fabric-docs-reference:tater per dare al giocatore il nostro effetto Tater. Usa /effect clear per rimuovere l'effetto.

INFO

Per creare una pozione che usa questo effetto, per favore vedi la guida Pozioni.