2020-03-09 20:49:40 -04:00
# API
## Getting Started
1. Add Dependency to Gradle
```gradle
repositories {
maven { url 'https://jitpack.io' }
}
dependencies {
2020-03-22 15:25:34 -04:00
modImplementation 'com.thebrokenrail:sorcerycraft:VERSION'
// VERSION = "< Mod Version > +< MC Version > ", for example "1.2.3+20w12a"
2020-03-09 20:49:40 -04:00
}
```
2. Add Dependency to ```fabric.mod.json` ``
```json
{
"depends": {
2020-03-20 22:05:32 -04:00
"sorcerycraft": "1.2.x"
2020-03-09 20:49:40 -04:00
}
}
```
3. Create a class extending ```com.thebrokenrail.sorcerycraft.spell.api.Spell` ``
```java
public class ExampleSpell extends Spell {
public ExampleSpell(Identifier id, int level) {
super(id, level);
}
2020-03-18 11:56:25 -04:00
2020-03-09 20:49:40 -04:00
@Override
public void execute(Entity target, Entity source, Entity attacker) {
2020-03-18 11:56:25 -04:00
// OPTIONAL
2020-03-09 20:49:40 -04:00
// Called when ExampleSpell hits an entity
2020-03-18 11:56:25 -04:00
// Override this if you want the spell to affect entities
2020-03-09 20:49:40 -04:00
}
2020-03-18 11:56:25 -04:00
2020-03-09 20:49:40 -04:00
@Override
public void execute(World world, BlockHitResult hitResult) {
2020-03-18 11:56:25 -04:00
// OPTIONAL
2020-03-09 20:49:40 -04:00
// Called when ExampleSpell hits a block
2020-03-18 11:56:25 -04:00
// Override this if you want the spell to affect blocks
2020-03-09 20:49:40 -04:00
}
2020-03-18 11:56:25 -04:00
2020-03-09 20:49:40 -04:00
@Override
public int getXPCost() {
2020-03-18 11:56:25 -04:00
// REQUIRED
2020-03-09 20:49:40 -04:00
// Return the amount of levels required to make ExampleSpell in a Casting Table
2020-03-18 11:56:25 -04:00
switch (getLevel()) {
case 0: {
return 4;
}
case 1: {
return 8;
}
}
return -1;
2020-03-09 20:49:40 -04:00
}
2020-03-18 11:56:25 -04:00
2020-03-09 20:49:40 -04:00
@Override
public ItemStack getItemCost() {
2020-03-18 11:56:25 -04:00
// REQUIRED
2020-03-09 20:49:40 -04:00
// Return the item(s) required to make ExampleSpell in a Casting Table
// Return ItemStack.EMPTY if an item is not required
2020-03-18 11:56:25 -04:00
switch (getLevel()) {
case 0: {
return new ItemStack(Items.SUGAR_CANE);
}
case 1: {
return new ItemStack(Items.BOOK);
}
}
return ItemStack.EMPTY;
2020-03-09 20:49:40 -04:00
}
2020-03-18 11:56:25 -04:00
2020-03-09 20:49:40 -04:00
@Override
public int getMaxLevel() {
2020-03-18 11:56:25 -04:00
// REQUIRED
2020-03-09 20:49:40 -04:00
// Return ExampleSpell's maximum level
2020-03-18 11:56:25 -04:00
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));
2020-03-09 20:49:40 -04:00
}
}
```
2020-03-17 13:22:49 -04:00
4. Register the spell in your ModInitializer
2020-03-09 20:49:40 -04:00
```java
public class ExampleMod implements ModInitializer {
public static final Identifier EXAMPLE_SPELL = SpellRegistry.register(new Identifier("modid", "example_spell"), ExampleSpell.class);
}
```
2020-03-18 11:56:25 -04:00
5. Add Spell Translation (skip this if you have overridden ```Spell.getTranslation()` `)
2020-03-09 20:49:40 -04:00
```json
{
"spell.modid.example_spell": "Example"
}
```
## Useful Methods
2020-03-17 14:34:42 -04:00
- ```(non-static) Spell.getLevel()` ``
- ```(non-static) Spell.getID()` ``
- ```(static) SpellRegistry.register()` ``
2020-03-20 22:05:32 -04:00
## API Stability
APIs are only guaranteed to be stable in the ```com.thebrokenrail.sorcerycraft.api` `` package, it is unrecommended to rely on any SorceryCraft classes outside of this package.
## Spell Levels
2020-03-18 11:56:25 -04:00
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.
2020-03-17 14:34:42 -04:00
## JavaDoc
[View JavaDoc ](https://javadoc.jitpack.io/com/thebrokenrail/sorcerycraft/latest/javadoc/index.html )