From c592b9e9afdbb575faffbb288781a6ea6fc04354 Mon Sep 17 00:00:00 2001 From: TheBrokenRail Date: Tue, 17 Mar 2020 13:22:49 -0400 Subject: [PATCH] 1.1.13 Update Mappings Improve /spell command --- API.md | 4 +- CHANGELOG.md | 4 ++ README.md | 8 ++- gradle.properties | 4 +- .../client/gui/CastingTableScreen.java | 6 +-- .../sorcerycraft/command/SpellCommand.java | 49 +++++++++++++++---- .../sorcerycraft/spell/api/Spell.java | 22 ++++----- .../spell/registry/SpellRegistry.java | 12 +++++ .../sorcerycraft/spell/util/SpellTag.java | 8 ++- .../assets/sorcerycraft/lang/en_us.json | 6 +-- 10 files changed, 89 insertions(+), 34 deletions(-) diff --git a/API.md b/API.md index 1513daa..f3ddab0 100644 --- a/API.md +++ b/API.md @@ -7,7 +7,7 @@ maven { url 'https://jitpack.io' } } dependencies { - modImplementation 'com.thebrokenrail:sorcerycraft:VERSION' + modImplementation 'com.thebrokenrail:sorcerycraft:1.1.+' } ``` 2. Add Dependency to ```fabric.mod.json``` @@ -54,7 +54,7 @@ } } ``` -4. Register the Spell in your ModInitializer +4. Register the spell in your ModInitializer ```java public class ExampleMod implements ModInitializer { public static final Identifier EXAMPLE_SPELL = SpellRegistry.register(new Identifier("modid", "example_spell"), ExampleSpell.class); diff --git a/CHANGELOG.md b/CHANGELOG.md index 27925fd..7ee1dc5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +**1.1.13** +* Update Mappings +* Improve ```/spell``` command + **1.1.12** * Update Mappings * Add Config Screen diff --git a/README.md b/README.md index efc7019..cb8643d 100644 --- a/README.md +++ b/README.md @@ -65,12 +65,18 @@ You can apply Spells to blank or existing spells in the Casting Table. Doing so ## ```/spell``` Command This command requires OP permissions. -#### ```/spell clear ``` +#### ```/spell forget ``` This command clears all known spells from the given player. +#### ```/spell forget ``` +This command clears the specified spell from the given player. + #### ```/spell list ``` This lists all the spells the given player knows. +#### ```/spell discover ``` +This adds all spells to the specified player's discovered spells list. + #### ```/spell discover ``` This adds the specified spell to the specified player's discovered spells list. diff --git a/gradle.properties b/gradle.properties index f43de54..3bfcab3 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,11 +6,11 @@ org.gradle.jvmargs = -Xmx1G minecraft_version = 20w11a curseforge_id = 365308 simple_minecraft_version = 1.16-Snapshot - yarn_mappings = 20w11a+build.7 + yarn_mappings = 20w11a+build.11 fabric_loader_version = 0.7.8+build.187 # Mod Properties - mod_version = 1.1.12 + mod_version = 1.1.13 maven_group = com.thebrokenrail archives_base_name = sorcerycraft diff --git a/src/main/java/com/thebrokenrail/sorcerycraft/client/gui/CastingTableScreen.java b/src/main/java/com/thebrokenrail/sorcerycraft/client/gui/CastingTableScreen.java index 79edc41..456ee2f 100644 --- a/src/main/java/com/thebrokenrail/sorcerycraft/client/gui/CastingTableScreen.java +++ b/src/main/java/com/thebrokenrail/sorcerycraft/client/gui/CastingTableScreen.java @@ -47,7 +47,7 @@ public class CastingTableScreen extends HandledScreen client.getTextureManager().bindTexture(TEXTURE); int i = (width - backgroundWidth) / 2; int j = (height - backgroundHeight) / 2; - blit(i, j, getZOffset(), 0.0F, 0.0F, backgroundWidth, backgroundHeight, 256, 512); + drawTexture(i, j, getZOffset(), 0.0F, 0.0F, backgroundWidth, backgroundHeight, 256, 512); } @Override @@ -81,9 +81,9 @@ public class CastingTableScreen extends HandledScreen if (k > 0) { int modifier = (int) (((float) indexStartOffset / k) * (1 + 139 - 27)); - blit(i + 94, j + 18 + modifier, getZOffset(), 0.0F, 199.0F, 6, 27, 256, 512); + drawTexture(i + 94, j + 18 + modifier, getZOffset(), 0.0F, 199.0F, 6, 27, 256, 512); } else { - blit(i + 94, j + 18, getZOffset(), 6.0F, 199.0F, 6, 27, 256, 512); + drawTexture(i + 94, j + 18, getZOffset(), 6.0F, 199.0F, 6, 27, 256, 512); } } diff --git a/src/main/java/com/thebrokenrail/sorcerycraft/command/SpellCommand.java b/src/main/java/com/thebrokenrail/sorcerycraft/command/SpellCommand.java index f39c72a..b6613b5 100644 --- a/src/main/java/com/thebrokenrail/sorcerycraft/command/SpellCommand.java +++ b/src/main/java/com/thebrokenrail/sorcerycraft/command/SpellCommand.java @@ -4,6 +4,8 @@ import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.arguments.IntegerArgumentType; import com.mojang.brigadier.exceptions.DynamicCommandExceptionType; import com.thebrokenrail.sorcerycraft.SorceryCraft; +import com.thebrokenrail.sorcerycraft.spell.api.Spell; +import com.thebrokenrail.sorcerycraft.spell.registry.SpellRegistry; import com.thebrokenrail.sorcerycraft.spell.util.SpellPlayerEntity; import com.thebrokenrail.sorcerycraft.spell.util.SpellTag; import net.minecraft.command.arguments.EntityArgumentType; @@ -11,6 +13,7 @@ import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; import net.minecraft.server.command.CommandManager; import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.text.Texts; import net.minecraft.text.TranslatableText; import net.minecraft.util.Formatting; import net.minecraft.util.Identifier; @@ -28,29 +31,53 @@ public class SpellCommand { .then(CommandManager.argument("player", EntityArgumentType.player()) .executes(ctx -> { PlayerEntity player = EntityArgumentType.getPlayer(ctx, "player"); - ctx.getSource().sendFeedback(new TranslatableText("command." + SorceryCraft.NAMESPACE + ".spell.listing_spells", player.getDisplayName()), false); SpellPlayerEntity spellPlayer = (SpellPlayerEntity) player; - Map spells = spellPlayer.getDiscoveredSpells(); - for (Map.Entry entry : spells.entrySet()) { - ctx.getSource().sendFeedback(SpellTag.getTranslatedSpell(entry.getKey(), entry.getValue(), true).formatted(Formatting.YELLOW), false); - } + Map 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); return 0; }) ) ) - .then(CommandManager.literal("clear") + .then(CommandManager.literal("forget") .then(CommandManager.argument("player", EntityArgumentType.player()) .executes(ctx -> { PlayerEntity player = EntityArgumentType.getPlayer(ctx, "player"); SpellPlayerEntity spellPlayer = (SpellPlayerEntity) player; + Map spells = spellPlayer.getDiscoveredSpells(); + for (Map.Entry entry : spells.entrySet()) { + ctx.getSource().sendFeedback(new TranslatableText("command." + SorceryCraft.NAMESPACE + ".spell.forgotten_spell", player.getDisplayName(), SpellTag.getTranslatedSpellChat(entry.getKey(), entry.getValue())), true); + } spellPlayer.setDiscoveredSpells(new HashMap<>()); - ctx.getSource().sendFeedback(new TranslatableText("command." + SorceryCraft.NAMESPACE + ".spell.cleared_spells", player.getDisplayName()), true); return 1; }) + .then(CommandManager.argument("spell", SpellArgumentType.spell()) + .executes(ctx -> { + PlayerEntity player = EntityArgumentType.getPlayer(ctx, "player"); + Identifier spell = SpellArgumentType.getSpell(ctx, "spell"); + SpellPlayerEntity spellPlayer = (SpellPlayerEntity) player; + Map spells = spellPlayer.getDiscoveredSpells(); + if (spells.containsKey(spell)) { + ctx.getSource().sendFeedback(new TranslatableText("command." + SorceryCraft.NAMESPACE + ".spell.forgotten_spell", player.getDisplayName(), SpellTag.getTranslatedSpellChat(spell, spells.get(spell))), true); + spells.remove(spell); + } + spellPlayer.setDiscoveredSpells(spells); + return 1; + }) + ) ) ) .then(CommandManager.literal("discover") .then(CommandManager.argument("player", EntityArgumentType.player()) + .executes(ctx -> { + PlayerEntity player = EntityArgumentType.getPlayer(ctx, "player"); + Map spellMap = new HashMap<>(); + Spell[] maxSpells = SpellRegistry.getMaxSpells(); + for (Spell spell : maxSpells) { + spellMap.put(spell.getID(), spell.getLevel()); + } + SpellTag.learnSpells(player, spellMap); + return 1; + }) .then(CommandManager.argument("spell", SpellArgumentType.spell()) .then(CommandManager.argument("level", IntegerArgumentType.integer()) .executes(ctx -> { @@ -85,7 +112,7 @@ public class SpellCommand { spellMap.put(spell, level); SpellTag.setSpells(stack, spellMap); - ctx.getSource().sendFeedback(new TranslatableText("command.sorcerycraft.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)), true); return 1; }) ) @@ -106,10 +133,12 @@ public class SpellCommand { } Map spellMap = SpellTag.getSpells(stack); - spellMap.remove(spell); + if (spellMap.containsKey(spell)) { + ctx.getSource().sendFeedback(new TranslatableText("command." + SorceryCraft.NAMESPACE + ".spell.removed_spell", SpellTag.getTranslatedSpell(spell, spellMap.get(spell), true)), true); + spellMap.remove(spell); + } SpellTag.setSpells(stack, spellMap); - ctx.getSource().sendFeedback(new TranslatableText("command.sorcerycraft.spell.removed_spell", SpellTag.getTranslatedSpell(spell, 0, false)), true); return 1; }) ) diff --git a/src/main/java/com/thebrokenrail/sorcerycraft/spell/api/Spell.java b/src/main/java/com/thebrokenrail/sorcerycraft/spell/api/Spell.java index 93ebe7c..cc3a2e2 100644 --- a/src/main/java/com/thebrokenrail/sorcerycraft/spell/api/Spell.java +++ b/src/main/java/com/thebrokenrail/sorcerycraft/spell/api/Spell.java @@ -16,7 +16,7 @@ public abstract class Spell { } /** - * Get the ID of this Spell + * Get the ID of this spell * @return The Spell ID */ public Identifier getID() { @@ -24,18 +24,18 @@ public abstract class Spell { } /** - * Get the level of this Spell - * @return The Spell Level + * Get the level of this spell + * @return The Spell's Level */ public int getLevel() { return level; } /** - * Execute this Spell on an Entity + * Execute this spell on an Entity * @param world World * @param source A SpellEntity - * @param attacker The Entity that cast this Spell + * @param attacker The Entity that cast this spell * @param target The Target */ public void execute(World world, Entity source, Entity attacker, Entity target) { @@ -43,10 +43,10 @@ public abstract class Spell { } /** - * Cast this Spell on a block + * Execute this spell on a block * @param world World * @param source A SpellEntity - * @param attacker The Entity that cast this Spell + * @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) { @@ -54,20 +54,20 @@ public abstract class Spell { } /** - * Get the amount of levels required to make this Spell in a Casting Table + * 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 ExampleSpell in a Casting Table, or ItemStack.EMPTY if an item is not required + * 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 Max Level + * Get the maximum level of this spell + * @return The Spell's Max Level */ public abstract int getMaxLevel(); } diff --git a/src/main/java/com/thebrokenrail/sorcerycraft/spell/registry/SpellRegistry.java b/src/main/java/com/thebrokenrail/sorcerycraft/spell/registry/SpellRegistry.java index 32e45dd..03cb25d 100644 --- a/src/main/java/com/thebrokenrail/sorcerycraft/spell/registry/SpellRegistry.java +++ b/src/main/java/com/thebrokenrail/sorcerycraft/spell/registry/SpellRegistry.java @@ -53,6 +53,18 @@ public class SpellRegistry { return out.toArray(new Spell[0]); } + public static Spell[] getMaxSpells() { + List out = new ArrayList<>(); + for (Map.Entry> entry : spells.entrySet()) { + int maxLevel = getMaxLevel(entry.getKey()); + if (maxLevel == -1) { + continue; + } + out.add(getSpell(entry.getKey(), maxLevel - 1)); + } + return out.toArray(new Spell[0]); + } + /** * Register a Spell * @param id The Spell ID diff --git a/src/main/java/com/thebrokenrail/sorcerycraft/spell/util/SpellTag.java b/src/main/java/com/thebrokenrail/sorcerycraft/spell/util/SpellTag.java index e19b07c..fd63c9e 100644 --- a/src/main/java/com/thebrokenrail/sorcerycraft/spell/util/SpellTag.java +++ b/src/main/java/com/thebrokenrail/sorcerycraft/spell/util/SpellTag.java @@ -91,6 +91,10 @@ public class SpellTag { return text; } + public static Text getTranslatedSpellChat(Identifier id, int level) { + return new LiteralText("[").append(SpellTag.getTranslatedSpell(id, level, true).getString()).append("]").formatted(Formatting.GREEN); + } + public static void learnSpells(PlayerEntity player, Map itemSpells) { SpellPlayerEntity spellPlayer = (SpellPlayerEntity) player; World world = player.getEntityWorld(); @@ -111,8 +115,8 @@ public class SpellTag { playerSpells.put(spell.getID(), spell.getLevel()); assert world.getServer() != null; - Text text = new LiteralText("[").append(SpellTag.getTranslatedSpell(spell.getID(), spell.getLevel(), true).getString()).append("]").formatted(Formatting.GREEN); - world.getServer().getPlayerManager().sendToAll(new TranslatableText("chat." + SorceryCraft.NAMESPACE + ".new_spell", player.getDisplayName(), text)); + Text text = getTranslatedSpellChat(spell.getID(), spell.getLevel()); + world.getServer().getPlayerManager().sendToAll(new TranslatableText("chat." + SorceryCraft.NAMESPACE + ".discovered_spell", player.getDisplayName(), text)); } } } diff --git a/src/main/resources/assets/sorcerycraft/lang/en_us.json b/src/main/resources/assets/sorcerycraft/lang/en_us.json index 8ea328a..62dde7f 100644 --- a/src/main/resources/assets/sorcerycraft/lang/en_us.json +++ b/src/main/resources/assets/sorcerycraft/lang/en_us.json @@ -4,10 +4,10 @@ "itemGroup.sorcerycraft.spells": "SorceryCraft", "container.sorcerycraft.casting_table": "Casting Table", "container.sorcerycraft.spells": "Spells", - "chat.sorcerycraft.new_spell": "%s has discovered the spell %s", + "chat.sorcerycraft.discovered_spell": "%s has discovered the spell %s", "entity.sorcerycraft.spell": "Spell", - "command.sorcerycraft.spell.cleared_spells": "All discovered spells cleared from %s", - "command.sorcerycraft.spell.listing_spells": "%s has discovered the following spells:", + "command.sorcerycraft.spell.forgotten_spell": "%s has forgotten the spell %s", + "command.sorcerycraft.spell.listing_spells": "%s has discovered the following spells: %s", "command.sorcerycraft.spell.unknown_spell": "Unknown spell: %s", "command.sorcerycraft.spell.not_holding_spell": "%s is not holding a spell", "command.sorcerycraft.spell.applied_spell": "Applied Spell %s",