package com.thebrokenrail.sorcerycraft.spell.api; import com.thebrokenrail.sorcerycraft.spell.api.registry.SpellRegistry; import net.minecraft.entity.Entity; import net.minecraft.item.ItemStack; import net.minecraft.text.MutableText; import net.minecraft.text.TranslatableText; import net.minecraft.util.Identifier; import net.minecraft.util.hit.BlockHitResult; import net.minecraft.world.World; /** * Spell Implementation Base Class */ public abstract class Spell { private final Identifier id; private final int level; public Spell(Identifier id, int level) { this.id = id; this.level = level; } /** * Get the ID of this spell * @return The Spell ID */ public Identifier getID() { return id; } /** * Get the level of this spell * @return The Spell's Level */ public int getLevel() { return level; } /** * Execute this spell on an Entity * @param world World * @param source A SpellEntity * @param attacker The Entity that cast this spell * @param target The Target */ public void execute(World world, Entity source, Entity attacker, Entity target) { // NOOP } /** * Execute this spell on a block * @param world World * @param source A SpellEntity * @param attacker The Entity that cast this spell * @param hitResult The block's HitResult */ public void execute(World world, Entity source, Entity attacker, BlockHitResult hitResult) { // NOOP } /** * Get the amount of levels required to make this spell in a Casting Table * @return The XP cost */ public abstract int getXPCost(); /** * Get the item(s) required to make this spell in a Casting Table, or ItemStack.EMPTY if an item is not required * @return The item cost */ public abstract ItemStack getItemCost(); /** * Get the maximum level of this spell * @return The Spell's Max Level */ public abstract int getMaxLevel(); /** * Default Implementation for Spell.getTranslation() * @param id Spell ID * @param level Spell Level * @return Translated Display Name */ public static MutableText getDefaultTranslation(Identifier id, int level) { MutableText 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 MutableText getTranslation() { return getDefaultTranslation(getID(), getLevel()); } }