Adding Booster Types
Here, you can learn how to add custom booster types. When custom booster types are registered, NeoExtras will automatically make the config for you with the common configuration. For adding more configuration options to your booster, see here.
Getting Started
To start, create a class extending dev.neovitalism.neoextras.api.boosters.types.NeoExtrasBooster<T, C>
.
T
is the object that tests against your context. C
is the context object.
Required Overrides
There's a few methods you'll need to override, found below.
Method | Description |
---|---|
String getName() |
The name of the booster type. Names should be <= 50 characters, and all lowercase. This is the name used to get the booster from the booster registry and some lang messages on config generation. Dashes will get turned to spaces in lang messages. |
String getDisplayName() |
The display name of the booster type. This is only used in some lang messages on config generation. Use proper capitalization and spacing. |
String getColor() |
The general color of the booster type. Colors are only used in generating lang. This should return a hex code in "<#RRGGBB>" format. |
Context Methods
These methods are still required, but deal with contexts. If you plan for T
to be Pokemon
, and C
be PokemonProperties
, I suggest extending dev.neovitalism.neoextras.api.boosters.types.simplified.PokemonBooster
. This will automatically handle contexts, and not require you to extend these methods. Extending PokemonBooster
also adds and handles the unaffected-specs
config option.
Method | Description |
---|---|
C parseContext(String) |
The method to parse a String from the command into your context object.This method will not be called if no context string has been provided. |
boolean matchesContext(T, C) |
The method to see whether your object (T ) matches your context (C ).C can be null, and should return true if it is. |
Adding Config Settings
To add config settings, you must override 2 methods. Firstly, override void reloadConfig(Configuration)
, being sure to start with a super call. Afterwards, you can get your setting from the config object. Like so:
private String setting;
@Override
protected void reloadConfig(Configuration config) {
super.reloadConfig(config);
// this.setting = config.getString("example-config-setting", "default");
}
Secondly, you need to override Configuration getDefaults()
. This is used in generating the config for your booster, and supplying default values to NeoExtras should a config key be missing. This method also requires a super call to function properly. Following the previous example, this can be done like so:
@Override
protected Configuration getDefaults() {
Configuration defaults = super.getDefaults();
defaults.set("example-config-setting", "default");
return defaults;
}
And just like that, your config setting is availble to be used in any method the NeoExtrasBooster
class supplies.
Applying Your Booster
This is where a lot of boosters will differ. You'll need to find a location where a rate or value is visible, has a ServerPlayerEntity
(or some way to collect it), and a way to change that rate or value. This is typically found in the form of events. Before performing the booster logic, you should check this.isEnabled()
and return immediately if it's false. For registering events that use the player's boost, override void init()
, which is run on server start. The method double getCurrentPlayerBoost(ServerPlayerEntity, T)
is used to get the player's total boost. Below, I provide an example utilizing the player's boost using a hypothetical event.
@Override
public void init() {
MadeUpEvents.EXAMPLE_RATE.register(event -> {
if (!this.isEnabled()) return;
ServerPlayerEntity player = event.getPlayer();
double boost = this.getCurrentPlayerBoost(player, event.getHypotheticalObject());
event.setRate((float) (event.getRate() * boost));
});
}
Registering Your Booster
Finally, all you need to do is call BoosterRegistry.register(NeoExtrasBooster<T, C>)
with your booster object in your mod initialization. For a soft depend, you can check FabricLoader.getInstance().isModLoaded("neoextras")
before registering your booster. Upon loading your booster with NeoExtras, it'll generate a new config under /config/NeoExtras/boosters/configs/
with the name of your booster as the file name. You've now created your custom booster type! Good job!