2020-03-10 00:49:40 +00:00
# API
## Getting Started
1. Add Dependency to Gradle
```gradle
repositories {
2020-05-02 18:42:16 +00:00
maven { url 'https://maven.thebrokenrail.com' }
2020-03-10 00:49:40 +00:00
}
dependencies {
2020-03-22 19:25:34 +00:00
modImplementation 'com.thebrokenrail:sorcerycraft:VERSION'
2020-03-24 13:37:44 +00:00
// VERSION = "< Mod Version > +< MC Version > ", for example "1.2.4+20w12a"
2020-03-10 00:49:40 +00:00
}
```
2. Add Dependency to ```fabric.mod.json```
```json
{
"depends": {
2020-03-21 02:05:32 +00:00
"sorcerycraft": "1.2.x"
2020-03-10 00:49:40 +00: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 15:56:25 +00:00
2020-03-10 00:49:40 +00:00
@Override
public void execute(Entity target, Entity source, Entity attacker) {
2020-03-18 15:56:25 +00:00
// OPTIONAL
2020-03-10 00:49:40 +00:00
// Called when ExampleSpell hits an entity
2020-03-18 15:56:25 +00:00
// Override this if you want the spell to affect entities
2020-03-10 00:49:40 +00:00
}
2020-03-18 15:56:25 +00:00
2020-03-10 00:49:40 +00:00
@Override
public void execute(World world, BlockHitResult hitResult) {
2020-03-18 15:56:25 +00:00
// OPTIONAL
2020-03-10 00:49:40 +00:00
// Called when ExampleSpell hits a block
2020-03-18 15:56:25 +00:00
// Override this if you want the spell to affect blocks
2020-03-10 00:49:40 +00:00
}
2020-03-18 15:56:25 +00:00
2020-03-10 00:49:40 +00:00
@Override
public int getXPCost() {
2020-03-18 15:56:25 +00:00
// REQUIRED
2020-03-10 00:49:40 +00:00
// Return the amount of levels required to make ExampleSpell in a Casting Table
2020-03-18 15:56:25 +00:00
switch (getLevel()) {
case 0: {
return 4;
}
case 1: {
return 8;
}
}
return -1;
2020-03-10 00:49:40 +00:00
}
2020-03-18 15:56:25 +00:00
2020-03-10 00:49:40 +00:00
@Override
public ItemStack getItemCost() {
2020-03-18 15:56:25 +00:00
// REQUIRED
2020-03-10 00:49:40 +00: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 15:56:25 +00:00
switch (getLevel()) {
case 0: {
return new ItemStack(Items.SUGAR_CANE);
}
case 1: {
return new ItemStack(Items.BOOK);
}
}
return ItemStack.EMPTY;
2020-03-10 00:49:40 +00:00
}
2020-03-18 15:56:25 +00:00
2020-03-10 00:49:40 +00:00
@Override
public int getMaxLevel() {
2020-03-18 15:56:25 +00:00
// REQUIRED
2020-03-10 00:49:40 +00:00
// Return ExampleSpell's maximum level
2020-03-18 15:56:25 +00: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-10 00:49:40 +00:00
}
}
```
2020-03-17 17:22:49 +00:00
4. Register the spell in your ModInitializer
2020-03-10 00:49:40 +00: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 15:56:25 +00:00
5. Add Spell Translation (skip this if you have overridden ```Spell.getTranslation()``)
2020-03-10 00:49:40 +00:00
```json
{
"spell.modid.example_spell": "Example"
}
```
## Useful Methods
2020-03-17 18:34:42 +00:00
- ```(non-static) Spell.getLevel()```
- ```(non-static) Spell.getID()```
- ```(static) SpellRegistry.register()```
2020-03-21 02:05:32 +00: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 15:56:25 +00: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 18:34:42 +00:00
## JavaDoc
2020-05-02 18:42:16 +00:00
[View JavaDoc ](https://jenkins.thebrokenrail.com/job/SorceryCraft/job/master/JavaDoc/ )