TheBrokenRail
9d1cad6223
All checks were successful
SorceryCraft/pipeline/head This commit looks good
Update API Docs Allow Setting Custom Display name for Spell
3.4 KiB
3.4 KiB
API
Getting Started
- Add Dependency to Gradle
repositories { maven { url 'https://jitpack.io' } } dependencies { modImplementation 'com.thebrokenrail:sorcerycraft:1.1.+' }
- Add Dependency to
fabric.mod.json
{ "depends": { "sorcerycraft": "1.1.x" } }
- Create a class extending
com.thebrokenrail.sorcerycraft.spell.api.Spell
public class ExampleSpell extends Spell { public ExampleSpell(Identifier id, int level) { super(id, level); } @Override public void execute(Entity target, Entity source, Entity attacker) { // OPTIONAL // Called when ExampleSpell hits an entity // Override this if you want the spell to affect entities } @Override public void execute(World world, BlockHitResult hitResult) { // OPTIONAL // Called when ExampleSpell hits a block // Override this if you want the spell to affect blocks } @Override public int getXPCost() { // REQUIRED // Return the amount of levels required to make ExampleSpell in a Casting Table switch (getLevel()) { case 0: { return 4; } case 1: { return 8; } } return -1; } @Override public ItemStack getItemCost() { // REQUIRED // Return the item(s) required to make ExampleSpell in a Casting Table // Return ItemStack.EMPTY if an item is not required switch (getLevel()) { case 0: { return new ItemStack(Items.SUGAR_CANE); } case 1: { return new ItemStack(Items.BOOK); } } return ItemStack.EMPTY; } @Override public int getMaxLevel() { // REQUIRED // Return ExampleSpell's maximum level return 2; } @Override public Text getTranslation() { // OPTIONAL // Return a custom display name for ExampleSpell // Override this only if you want a custom display name return new LiteralText("Example " + (getLevel() + 1)); } }
- Register the spell in your ModInitializer
public class ExampleMod implements ModInitializer { public static final Identifier EXAMPLE_SPELL = SpellRegistry.register(new Identifier("modid", "example_spell"), ExampleSpell.class); }
- Add Spell Translation (skip this if you have overridden ```Spell.getTranslation()``)
{ "spell.modid.example_spell": "Example" }
Useful Methods
(non-static) Spell.getLevel()
(non-static) Spell.getID()
(static) SpellRegistry.register()
Note on Spell Levels
Spell levels are 0-indexed, if you have a level 1 Example Spell, Spell.getLevel()
wil return 0, and if it is level 2 Spell.getLevel()
wil return 1, Spell.getMaxSpell()
should be the maximum-acceptable value of Spell.getLevel() + 1
, so if Example Spell has levels 1-2, Spell.getMaxLevel()
should return 2.