Update API Docs Allow Setting Custom Display name for Spell
This commit is contained in:
parent
373f0ad8d3
commit
9d1cad6223
41
API.md
41
API.md
@ -27,30 +27,62 @@
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(Entity target, Entity source, Entity attacker) {
|
public void execute(Entity target, Entity source, Entity attacker) {
|
||||||
|
// OPTIONAL
|
||||||
// Called when ExampleSpell hits an entity
|
// Called when ExampleSpell hits an entity
|
||||||
// Not required to override
|
// Override this if you want the spell to affect entities
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(World world, BlockHitResult hitResult) {
|
public void execute(World world, BlockHitResult hitResult) {
|
||||||
|
// OPTIONAL
|
||||||
// Called when ExampleSpell hits a block
|
// Called when ExampleSpell hits a block
|
||||||
// Not required to override
|
// Override this if you want the spell to affect blocks
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getXPCost() {
|
public int getXPCost() {
|
||||||
|
// REQUIRED
|
||||||
// Return the amount of levels required to make ExampleSpell in a Casting Table
|
// 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
|
@Override
|
||||||
public ItemStack getItemCost() {
|
public ItemStack getItemCost() {
|
||||||
|
// REQUIRED
|
||||||
// Return the item(s) required to make ExampleSpell in a Casting Table
|
// Return the item(s) required to make ExampleSpell in a Casting Table
|
||||||
// Return ItemStack.EMPTY if an item is not required
|
// 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
|
@Override
|
||||||
public int getMaxLevel() {
|
public int getMaxLevel() {
|
||||||
|
// REQUIRED
|
||||||
// Return ExampleSpell's maximum level
|
// 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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@ -60,7 +92,7 @@
|
|||||||
public static final Identifier EXAMPLE_SPELL = SpellRegistry.register(new Identifier("modid", "example_spell"), ExampleSpell.class);
|
public static final Identifier EXAMPLE_SPELL = SpellRegistry.register(new Identifier("modid", "example_spell"), ExampleSpell.class);
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
5. Add Spell Translation
|
5. Add Spell Translation (skip this if you have overridden ```Spell.getTranslation()``)
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"spell.modid.example_spell": "Example"
|
"spell.modid.example_spell": "Example"
|
||||||
@ -72,5 +104,8 @@
|
|||||||
- ```(non-static) Spell.getID()```
|
- ```(non-static) Spell.getID()```
|
||||||
- ```(static) SpellRegistry.register()```
|
- ```(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.
|
||||||
|
|
||||||
## JavaDoc
|
## JavaDoc
|
||||||
[View JavaDoc](https://javadoc.jitpack.io/com/thebrokenrail/sorcerycraft/latest/javadoc/index.html)
|
[View JavaDoc](https://javadoc.jitpack.io/com/thebrokenrail/sorcerycraft/latest/javadoc/index.html)
|
@ -1,5 +1,9 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
**1.1.19**
|
||||||
|
* Update API Docs
|
||||||
|
* Allow Setting Custom Display name for Spell
|
||||||
|
|
||||||
**1.1.18**
|
**1.1.18**
|
||||||
* Fix Crash When Using Dedicated Server
|
* Fix Crash When Using Dedicated Server
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ org.gradle.jvmargs = -Xmx1G
|
|||||||
fabric_loader_version = 0.7.8+build.187
|
fabric_loader_version = 0.7.8+build.187
|
||||||
|
|
||||||
# Mod Properties
|
# Mod Properties
|
||||||
mod_version = 1.1.18
|
mod_version = 1.1.19
|
||||||
maven_group = com.thebrokenrail
|
maven_group = com.thebrokenrail
|
||||||
archives_base_name = sorcerycraft
|
archives_base_name = sorcerycraft
|
||||||
|
|
||||||
|
@ -66,7 +66,7 @@ public class CastingTableScreen extends HandledScreen<CastingTableScreenHandler>
|
|||||||
button.visible = button.index < handler.getRecipes().length;
|
button.visible = button.index < handler.getRecipes().length;
|
||||||
if (button.visible) {
|
if (button.visible) {
|
||||||
Spell spell = handler.getRecipes()[button.getIndex() + indexStartOffset];
|
Spell spell = handler.getRecipes()[button.getIndex() + indexStartOffset];
|
||||||
button.setMessage(SpellTag.getTranslatedSpell(spell.getID(), spell.getLevel(), true).getString());
|
button.setMessage(SpellTag.getTranslatedSpell(spell.getID(), spell.getLevel()).getString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,6 @@ import net.minecraft.server.command.CommandManager;
|
|||||||
import net.minecraft.server.command.ServerCommandSource;
|
import net.minecraft.server.command.ServerCommandSource;
|
||||||
import net.minecraft.text.Texts;
|
import net.minecraft.text.Texts;
|
||||||
import net.minecraft.text.TranslatableText;
|
import net.minecraft.text.TranslatableText;
|
||||||
import net.minecraft.util.Formatting;
|
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -33,7 +32,7 @@ public class SpellCommand {
|
|||||||
PlayerEntity player = EntityArgumentType.getPlayer(ctx, "player");
|
PlayerEntity player = EntityArgumentType.getPlayer(ctx, "player");
|
||||||
SpellPlayerEntity spellPlayer = (SpellPlayerEntity) player;
|
SpellPlayerEntity spellPlayer = (SpellPlayerEntity) player;
|
||||||
Map<Identifier, Integer> spellMap = spellPlayer.getDiscoveredSpells();
|
Map<Identifier, Integer> spellMap = spellPlayer.getDiscoveredSpells();
|
||||||
ctx.getSource().sendFeedback(new TranslatableText("command." + SorceryCraft.NAMESPACE + ".spell.listing_spells", player.getDisplayName(), Texts.join(spellMap.entrySet(), spell -> SpellTag.getTranslatedSpell(spell.getKey(), spell.getValue(), true))), false);
|
ctx.getSource().sendFeedback(new TranslatableText("command." + SorceryCraft.NAMESPACE + ".spell.listing_spells", player.getDisplayName(), Texts.join(spellMap.entrySet(), spell -> SpellTag.getTranslatedSpell(spell.getKey(), spell.getValue()))), false);
|
||||||
return 0;
|
return 0;
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
@ -112,7 +111,7 @@ public class SpellCommand {
|
|||||||
spellMap.put(spell, level);
|
spellMap.put(spell, level);
|
||||||
SpellTag.setSpells(stack, spellMap);
|
SpellTag.setSpells(stack, spellMap);
|
||||||
|
|
||||||
ctx.getSource().sendFeedback(new TranslatableText("command." + SorceryCraft.NAMESPACE + ".spell.applied_spell", SpellTag.getTranslatedSpell(spell, level, true)), true);
|
ctx.getSource().sendFeedback(new TranslatableText("command." + SorceryCraft.NAMESPACE + ".spell.applied_spell", SpellTag.getTranslatedSpell(spell, level)), true);
|
||||||
return 1;
|
return 1;
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
@ -134,7 +133,7 @@ public class SpellCommand {
|
|||||||
|
|
||||||
Map<Identifier, Integer> spellMap = SpellTag.getSpells(stack);
|
Map<Identifier, Integer> spellMap = SpellTag.getSpells(stack);
|
||||||
if (spellMap.containsKey(spell)) {
|
if (spellMap.containsKey(spell)) {
|
||||||
ctx.getSource().sendFeedback(new TranslatableText("command." + SorceryCraft.NAMESPACE + ".spell.removed_spell", SpellTag.getTranslatedSpell(spell, spellMap.get(spell), true)), true);
|
ctx.getSource().sendFeedback(new TranslatableText("command." + SorceryCraft.NAMESPACE + ".spell.removed_spell", SpellTag.getTranslatedSpell(spell, spellMap.get(spell))), true);
|
||||||
spellMap.remove(spell);
|
spellMap.remove(spell);
|
||||||
}
|
}
|
||||||
SpellTag.setSpells(stack, spellMap);
|
SpellTag.setSpells(stack, spellMap);
|
||||||
|
@ -61,7 +61,7 @@ public class SpellItem extends Item {
|
|||||||
public void appendTooltip(ItemStack itemStack, World world, List<Text> tooltip, TooltipContext tooltipContext) {
|
public void appendTooltip(ItemStack itemStack, World world, List<Text> tooltip, TooltipContext tooltipContext) {
|
||||||
Map<Identifier, Integer> spells = SpellTag.getSpells(itemStack);
|
Map<Identifier, Integer> spells = SpellTag.getSpells(itemStack);
|
||||||
for (Map.Entry<Identifier, Integer> entry : spells.entrySet()) {
|
for (Map.Entry<Identifier, Integer> entry : spells.entrySet()) {
|
||||||
tooltip.add(SpellTag.getTranslatedSpell(entry.getKey(), entry.getValue(), true));
|
tooltip.add(SpellTag.getTranslatedSpell(entry.getKey(), entry.getValue()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
package com.thebrokenrail.sorcerycraft.spell.api;
|
package com.thebrokenrail.sorcerycraft.spell.api;
|
||||||
|
|
||||||
|
import com.thebrokenrail.sorcerycraft.spell.registry.SpellRegistry;
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.text.Text;
|
||||||
|
import net.minecraft.text.TranslatableText;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
import net.minecraft.util.hit.BlockHitResult;
|
import net.minecraft.util.hit.BlockHitResult;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
@ -70,4 +73,26 @@ public abstract class Spell {
|
|||||||
* @return The Spell's Max Level
|
* @return The Spell's Max Level
|
||||||
*/
|
*/
|
||||||
public abstract int getMaxLevel();
|
public abstract int getMaxLevel();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default Implementation for Spell.getTranslation()
|
||||||
|
* @param id Spell ID
|
||||||
|
* @param level Spell Level
|
||||||
|
* @return Translated Display Name
|
||||||
|
*/
|
||||||
|
public static Text getDefaultTranslation(Identifier id, int level) {
|
||||||
|
Text text = new TranslatableText("spell." + id.getNamespace() + '.' + id.getPath());
|
||||||
|
if (level != 0 || SpellRegistry.getMaxLevel(id) != 1) {
|
||||||
|
text.append(" ").append(new TranslatableText("enchantment.level." + (level + 1)));
|
||||||
|
}
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Translated Display Name
|
||||||
|
* @return Translated Display Name
|
||||||
|
*/
|
||||||
|
public Text getTranslation() {
|
||||||
|
return getDefaultTranslation(getID(), getLevel());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -83,17 +83,20 @@ public class SpellTag {
|
|||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Text getTranslatedSpell(Identifier id, int level, boolean allowNumber) {
|
public static Text getTranslatedSpell(Identifier id, int level) {
|
||||||
Text text = new TranslatableText("spell." + id.getNamespace() + '.' + id.getPath());
|
Spell spell = SpellRegistry.getSpell(id, level);
|
||||||
text.formatted(Formatting.GRAY);
|
Text text;
|
||||||
if ((level != 0 || SpellRegistry.getMaxLevel(id) != 1) && allowNumber) {
|
if (spell != null) {
|
||||||
text.append(" ").append(new TranslatableText("enchantment.level." + (level + 1)));
|
text = spell.getTranslation();
|
||||||
|
} else {
|
||||||
|
text = Spell.getDefaultTranslation(id, level);
|
||||||
}
|
}
|
||||||
|
text.formatted(Formatting.GRAY);
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Text getTranslatedSpellChat(Identifier id, int level) {
|
public static Text getTranslatedSpellChat(Identifier id, int level) {
|
||||||
return new LiteralText("[").append(SpellTag.getTranslatedSpell(id, level, true).getString()).append("]").formatted(Formatting.GREEN);
|
return new LiteralText("[").append(SpellTag.getTranslatedSpell(id, level).getString()).append("]").formatted(Formatting.GREEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void learnSpells(PlayerEntity player, Map<Identifier, Integer> itemSpells) {
|
public static void learnSpells(PlayerEntity player, Map<Identifier, Integer> itemSpells) {
|
||||||
|
Reference in New Issue
Block a user