Extending FM: New EffectTypes - FlansMods/FlansModReloaded GitHub Wiki
Guns perform Actions, as specified in their .json definition, and these Actions trigger Effects
Note: "Doing something" with a gun has two stages; first the Action (such as Raycast) and then the Effect (such as DamageEntity).
You can add new Effects, as follows:
Create a class extending IEffect, such as ExampleEffect.java
public class ExampleEffect implements IEffect
{
public ExampleEffect (@Nonnull AbilityEffectDefinition def)
{
}
@Override
public void TriggerServer(@Nonnull ActionGroupContext actionGroup, @Nonnull TriggerContext trigger, @Nonnull TargetsContext targets, @Nullable AbilityStack stacks)
{
FlansMod.LOGGER.info("Hello Effect!");
}
}
Create a DeferredRegister in your mod for EffectTypes, similar to how you would create a DeferredRegister for Blocks or Items
public static final DeferredRegister<EffectType<?>> EFFECT_TYPES = DeferredRegister.create(FlansRegistries.EFFECT_TYPES, "examplemod");
Register a new EffectType (this is the object that tells Flan's Mod how to create one of your ExampleEffect instances when the effect is triggered by a gun)
public static final RegistryObject<EffectType<?>> EFFECT_TYPE_EXAMPLE = EFFECT_TYPES.register("example", () -> new EffectType<>(ExampleEffect::new));
Make sure to add your DeferredRegister to the mod event bus (you probably already do this for BLOCKS and ITEMS registers)
public ExampleMod()
{
IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();
// Other init ...
EFFECT_TYPES.register(modEventBus);
}
Now you can put "examplemod:example" in a Gun definition .json and it will use your ExampleEffect.class. For more examples, check out the included Effects in the base mod: https://github.com/FlansMods/FlansModReloaded/tree/1.20/src/main/java/com/flansmod/common/effects