This repository has been archived on 2023-11-26. You can view files and clone it, but cannot push or open issues or pull requests.
SorceryCraft/API.md

115 lines
3.7 KiB
Markdown
Raw Normal View History

2020-03-10 00:49:40 +00:00
# API
## Getting Started
1. Add Dependency to Gradle
```gradle
repositories {
maven { url 'https://jitpack.io' }
}
dependencies {
modImplementation 'com.thebrokenrail:sorcerycraft:VERSION'
// VERSION = "<Mod Version>+<MC Version>", for example "1.2.3+20w12a"
2020-03-10 00:49:40 +00:00
}
```
2. Add Dependency to ```fabric.mod.json```
```json
{
"depends": {
"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-10 00:49:40 +00:00
@Override
public void execute(Entity target, Entity source, Entity attacker) {
// OPTIONAL
2020-03-10 00:49:40 +00:00
// Called when ExampleSpell hits an entity
// Override this if you want the spell to affect entities
2020-03-10 00:49:40 +00:00
}
2020-03-10 00:49:40 +00:00
@Override
public void execute(World world, BlockHitResult hitResult) {
// OPTIONAL
2020-03-10 00:49:40 +00:00
// Called when ExampleSpell hits a block
// Override this if you want the spell to affect blocks
2020-03-10 00:49:40 +00:00
}
2020-03-10 00:49:40 +00:00
@Override
public int getXPCost() {
// REQUIRED
2020-03-10 00:49:40 +00:00
// 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;
2020-03-10 00:49:40 +00:00
}
2020-03-10 00:49:40 +00:00
@Override
public ItemStack getItemCost() {
// 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
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-10 00:49:40 +00:00
@Override
public int getMaxLevel() {
// REQUIRED
2020-03-10 00:49:40 +00:00
// 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));
2020-03-10 00:49:40 +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);
}
```
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()```
## 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
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
[View JavaDoc](https://javadoc.jitpack.io/com/thebrokenrail/sorcerycraft/latest/javadoc/index.html)