Extending FM: New ActionTypes - FlansMods/FlansModReloaded GitHub Wiki
Guns perform Actions, as specified in their .json definition
Note: "Doing something" with a gun has two stages; first the Action (such as Raycast) and then the Effect (such as DamageEntity). If you want to do something different when a bullet hits something, you should instead look at Effects and use it with the "flansmod:shoot" Action
You can add new Actions, as follows:
Create an ActionInstance class, such as ExampleAction.java
public class ExampleAction extends ActionInstance
{
public ExampleAction(@NotNull ActionGroupInstance group, @NotNull ActionDefinition def)
{
super(group, def);
}
@Override
public void OnTriggerClient(int triggerIndex)
{
}
@Override
public void OnTriggerServer(int triggerIndex)
{
FlansMod.LOGGER.info("Hello Action!");
}
}
Create a DeferredRegister in your mod for ActionTypes, similar to how you would create a DeferredRegister for Blocks or Items
public static final DeferredRegister<ActionType<?>> ACTION_TYPES = DeferredRegister.create(FlansRegistries.ACTION_TYPES, "examplemod");
Register a new ActionType (this is the object that tells Flan's Mod how to create one of your ExampleAction instances when the action is triggered by a gun)
public static final RegistryObject<ActionType<?>> ACTION_TYPE_EXAMPLE = ACTION_TYPES.register("example", () -> new ActionType<>(ExampleAction::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 ...
ACTION_TYPES.register(modEventBus);
}
Now you can put "examplemod:example" in a Gun definition .json and it will use your ExampleAction class. For more examples, check out the included ActionInstances in the base mod: https://github.com/FlansMods/FlansModReloaded/tree/1.20/src/main/java/com/flansmod/common/actions/nodes