I don't quite understand how to work with packages. I have buttons in the interface and I don't understand how to correctly link them to an action on the server.
The system itself works (should work) in such a way that when you click on a button, a spell is used.
package freedman.saomod.spell;
import freedman.saomod.component.ModComponents;
import freedman.saomod.component.PlayerDataComponent;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.text.Style;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
public class SpellCasting {
private static final Identifier CUSTOM_FONT = Identifier.of("saomod", "sao_font");
public static void castSpell(PlayerEntity player, int slot) {
PlayerDataComponent data = ModComponents.PLAYER_DATA.get(player);
String spellId = data.getSpellSlot(slot);
if (spellId == null || spellId.isEmpty()) {
player.sendMessage(Text.literal("Нет заклинания в этой ячейке.").setStyle(Style.EMPTY.withFont(CUSTOM_FONT)), true);
return;
}
Spell spell = SpellRegistry.get(spellId);
if (spell == null) {
player.sendMessage(Text.literal("Неизвестное заклинание: " + spellId).setStyle(Style.EMPTY.withFont(CUSTOM_FONT)), true);
return;
}
if (!data.knowsSpell(spellId)) {
player.sendMessage(Text.literal("Вы не знаете это заклинание!").setStyle(Style.EMPTY.withFont(CUSTOM_FONT)), true);
return;
}
if (data.getCurrentMana() >= spell.getManaCost()) {
data.setCurrentMana(data.getCurrentMana() - spell.getManaCost());
spell.cast(player);
} else {
player.sendMessage(Text.literal("Недостаточно маны!").setStyle(Style.EMPTY.withFont(CUSTOM_FONT)), true);
}
}
}