-
Notifications
You must be signed in to change notification settings - Fork 89
SpireField
Kiooeht edited this page Jan 10, 2019
·
4 revisions
SpireField is a simple way for mods to add new fields to preexisting classes in the game.
To do so, start by making a SpirePatch like normal, but specify SpirePatch.CLASS
as the method to patch. You can then define any new fields you want added to the class like so:
@SpirePatch(
clz=AbstractCard.class,
method=SpirePatch.CLASS
)
public class ExampleField
{
public static SpireField<String> example = new SpireField<>(() -> "default value");
}
Getting and setting the field can be done like so:
AbstractCard card = ...;
String str = ExampleField.example.get(card);
// str = "default value"
ExampleField.example.set(card, "foo");
str = ExampleField.example.get(card);
// str = "foo"
Note: Primitive types (int, float, boolean, etc.) are not supported in Java generics, use their wrapper types (Integer, Float, Boolean, etc.) when you want to make a SpireField
of a primitive type.