diff --git a/API.md b/API.md index 6a8c42d..8f7c895 100644 --- a/API.md +++ b/API.md @@ -7,14 +7,14 @@ maven { url 'https://jitpack.io' } } dependencies { - modImplementation 'com.thebrokenrail:sorcerycraft:1.1.+' + modImplementation 'com.thebrokenrail:sorcerycraft:1.2.+' } ``` 2. Add Dependency to ```fabric.mod.json``` ```json { "depends": { - "sorcerycraft": "1.1.x" + "sorcerycraft": "1.2.x" } } ``` @@ -104,7 +104,10 @@ - ```(non-static) Spell.getID()``` - ```(static) SpellRegistry.register()``` -## Note on Spell Levels +## 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. ## JavaDoc diff --git a/CHANGELOG.md b/CHANGELOG.md index e7606ed..8940f24 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +**1.2** +* Update Mappings +* Update API (More Consistent Package Names) +* Fix Bug When Casting Spell + **1.1.21** * Update Mappings * Tweak Teleport and Flame Spells diff --git a/gradle.properties b/gradle.properties index 980bf0f..34816e2 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,11 +6,11 @@ org.gradle.jvmargs = -Xmx1G minecraft_version = 20w12a curseforge_id = 365308 simple_minecraft_version = 1.16-Snapshot - yarn_build = 14 + yarn_build = 18 fabric_loader_version = 0.7.8+build.189 # Mod Properties - mod_version = 1.1.21 + mod_version = 1.2.0 maven_group = com.thebrokenrail archives_base_name = sorcerycraft @@ -19,4 +19,4 @@ org.gradle.jvmargs = -Xmx1G fabric_api_version = 0.5.5+build.311-1.16 cloth_config_version = 3.1.0-unstable auto_config_version = 1.2.4 - mod_menu_version = 1.10.2+build.1 + mod_menu_version = 1.11.0+build.2 diff --git a/src/main/java/com/thebrokenrail/sorcerycraft/SorceryCraft.java b/src/main/java/com/thebrokenrail/sorcerycraft/SorceryCraft.java index a8c9b68..a64ad61 100644 --- a/src/main/java/com/thebrokenrail/sorcerycraft/SorceryCraft.java +++ b/src/main/java/com/thebrokenrail/sorcerycraft/SorceryCraft.java @@ -9,7 +9,7 @@ import com.thebrokenrail.sorcerycraft.item.SpellItem; import com.thebrokenrail.sorcerycraft.mixin.CriterionRegistryHook; import com.thebrokenrail.sorcerycraft.packet.SelectSpellC2SPacket; import com.thebrokenrail.sorcerycraft.spell.util.RandomSpellLootTableFunction; -import com.thebrokenrail.sorcerycraft.spell.registry.Spells; +import com.thebrokenrail.sorcerycraft.spell.api.registry.Spells; import me.sargunvohra.mcmods.autoconfig1u.AutoConfig; import me.sargunvohra.mcmods.autoconfig1u.serializer.GsonConfigSerializer; import net.fabricmc.api.ModInitializer; diff --git a/src/main/java/com/thebrokenrail/sorcerycraft/advancement/DiscoverAllSpellsCriterion.java b/src/main/java/com/thebrokenrail/sorcerycraft/advancement/DiscoverAllSpellsCriterion.java index e0bc01e..c1e7ded 100644 --- a/src/main/java/com/thebrokenrail/sorcerycraft/advancement/DiscoverAllSpellsCriterion.java +++ b/src/main/java/com/thebrokenrail/sorcerycraft/advancement/DiscoverAllSpellsCriterion.java @@ -4,7 +4,7 @@ import com.google.gson.JsonDeserializationContext; import com.google.gson.JsonObject; import com.thebrokenrail.sorcerycraft.SorceryCraft; import com.thebrokenrail.sorcerycraft.spell.api.Spell; -import com.thebrokenrail.sorcerycraft.spell.registry.SpellRegistry; +import com.thebrokenrail.sorcerycraft.spell.api.registry.SpellRegistry; import com.thebrokenrail.sorcerycraft.spell.util.SpellPlayerEntity; import net.minecraft.advancement.criterion.AbstractCriterion; import net.minecraft.advancement.criterion.AbstractCriterionConditions; 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 35a0d01..7e4144f 100644 --- a/src/main/java/com/thebrokenrail/sorcerycraft/client/gui/CastingTableScreen.java +++ b/src/main/java/com/thebrokenrail/sorcerycraft/client/gui/CastingTableScreen.java @@ -5,7 +5,7 @@ import com.thebrokenrail.sorcerycraft.SorceryCraft; import com.thebrokenrail.sorcerycraft.gui.CastingTableScreenHandler; import com.thebrokenrail.sorcerycraft.packet.SelectSpellC2SPacket; import com.thebrokenrail.sorcerycraft.spell.api.Spell; -import com.thebrokenrail.sorcerycraft.spell.util.SpellTag; +import com.thebrokenrail.sorcerycraft.spell.util.SpellHelper; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.font.TextRenderer; @@ -66,7 +66,7 @@ public class CastingTableScreen extends HandledScreen button.visible = button.index < handler.getRecipes().length; if (button.visible) { Spell spell = handler.getRecipes()[button.getIndex() + indexStartOffset]; - button.setMessage(SpellTag.getTranslatedSpell(spell.getID(), spell.getLevel()).getString()); + button.setMessage(SpellHelper.getTranslatedSpell(spell.getID(), spell.getLevel()).getString()); } } } diff --git a/src/main/java/com/thebrokenrail/sorcerycraft/command/SpellArgumentType.java b/src/main/java/com/thebrokenrail/sorcerycraft/command/SpellArgumentType.java index 61f91df..8a18c7b 100644 --- a/src/main/java/com/thebrokenrail/sorcerycraft/command/SpellArgumentType.java +++ b/src/main/java/com/thebrokenrail/sorcerycraft/command/SpellArgumentType.java @@ -13,7 +13,7 @@ import com.mojang.brigadier.suggestion.Suggestions; import com.mojang.brigadier.suggestion.SuggestionsBuilder; import com.thebrokenrail.sorcerycraft.SorceryCraft; import com.thebrokenrail.sorcerycraft.spell.api.Spell; -import com.thebrokenrail.sorcerycraft.spell.registry.SpellRegistry; +import com.thebrokenrail.sorcerycraft.spell.api.registry.SpellRegistry; import net.minecraft.server.command.CommandSource; import net.minecraft.server.command.ServerCommandSource; import net.minecraft.text.TranslatableText; diff --git a/src/main/java/com/thebrokenrail/sorcerycraft/command/SpellCommand.java b/src/main/java/com/thebrokenrail/sorcerycraft/command/SpellCommand.java index 17be3fd..c6b0d85 100644 --- a/src/main/java/com/thebrokenrail/sorcerycraft/command/SpellCommand.java +++ b/src/main/java/com/thebrokenrail/sorcerycraft/command/SpellCommand.java @@ -5,9 +5,9 @@ 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.api.registry.SpellRegistry; +import com.thebrokenrail.sorcerycraft.spell.util.SpellHelper; import com.thebrokenrail.sorcerycraft.spell.util.SpellPlayerEntity; -import com.thebrokenrail.sorcerycraft.spell.util.SpellTag; import net.minecraft.command.arguments.EntityArgumentType; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; @@ -32,7 +32,7 @@ public class SpellCommand { PlayerEntity player = EntityArgumentType.getPlayer(ctx, "player"); SpellPlayerEntity spellPlayer = (SpellPlayerEntity) player; 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()))), false); + ctx.getSource().sendFeedback(new TranslatableText("command." + SorceryCraft.NAMESPACE + ".spell.listing_spells", player.getDisplayName(), Texts.join(spellMap.entrySet(), spell -> SpellHelper.getTranslatedSpell(spell.getKey(), spell.getValue()))), false); return 0; }) ) @@ -44,7 +44,7 @@ public class SpellCommand { 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); + ctx.getSource().sendFeedback(new TranslatableText("command." + SorceryCraft.NAMESPACE + ".spell.forgotten_spell", player.getDisplayName(), SpellHelper.getTranslatedSpellChat(entry.getKey(), entry.getValue())), true); } spellPlayer.setDiscoveredSpells(new HashMap<>()); return 1; @@ -56,7 +56,7 @@ public class SpellCommand { 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); + ctx.getSource().sendFeedback(new TranslatableText("command." + SorceryCraft.NAMESPACE + ".spell.forgotten_spell", player.getDisplayName(), SpellHelper.getTranslatedSpellChat(spell, spells.get(spell))), true); spells.remove(spell); } spellPlayer.setDiscoveredSpells(spells); @@ -74,7 +74,7 @@ public class SpellCommand { for (Spell spell : maxSpells) { spellMap.put(spell.getID(), spell.getLevel()); } - SpellTag.learnSpells(player, spellMap); + SpellHelper.learnSpells(player, spellMap); return 1; }) .then(CommandManager.argument("spell", SpellArgumentType.spell()) @@ -85,7 +85,7 @@ public class SpellCommand { int level = IntegerArgumentType.getInteger(ctx, "level") - 1; Map spellMap = new HashMap<>(); spellMap.put(spell, level); - SpellTag.learnSpells(player, spellMap); + SpellHelper.learnSpells(player, spellMap); return 1; }) ) @@ -107,11 +107,11 @@ public class SpellCommand { throw NOT_HOLDING_SPELL_EXCEPTION.create(player); } - Map spellMap = SpellTag.getSpells(stack); + Map spellMap = SpellHelper.getSpells(stack); spellMap.put(spell, level); - SpellTag.setSpells(stack, spellMap); + SpellHelper.setSpells(stack, spellMap); - ctx.getSource().sendFeedback(new TranslatableText("command." + SorceryCraft.NAMESPACE + ".spell.applied_spell", SpellTag.getTranslatedSpell(spell, level)), true); + ctx.getSource().sendFeedback(new TranslatableText("command." + SorceryCraft.NAMESPACE + ".spell.applied_spell", SpellHelper.getTranslatedSpell(spell, level)), true); return 1; }) ) @@ -131,12 +131,12 @@ public class SpellCommand { throw NOT_HOLDING_SPELL_EXCEPTION.create(player); } - Map spellMap = SpellTag.getSpells(stack); + Map spellMap = SpellHelper.getSpells(stack); if (spellMap.containsKey(spell)) { - ctx.getSource().sendFeedback(new TranslatableText("command." + SorceryCraft.NAMESPACE + ".spell.removed_spell", SpellTag.getTranslatedSpell(spell, spellMap.get(spell))), true); + ctx.getSource().sendFeedback(new TranslatableText("command." + SorceryCraft.NAMESPACE + ".spell.removed_spell", SpellHelper.getTranslatedSpell(spell, spellMap.get(spell))), true); spellMap.remove(spell); } - SpellTag.setSpells(stack, spellMap); + SpellHelper.setSpells(stack, spellMap); return 1; }) diff --git a/src/main/java/com/thebrokenrail/sorcerycraft/entity/SpellEntity.java b/src/main/java/com/thebrokenrail/sorcerycraft/entity/SpellEntity.java index 7df7ad7..210f978 100644 --- a/src/main/java/com/thebrokenrail/sorcerycraft/entity/SpellEntity.java +++ b/src/main/java/com/thebrokenrail/sorcerycraft/entity/SpellEntity.java @@ -2,9 +2,9 @@ package com.thebrokenrail.sorcerycraft.entity; 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.SpellTag; -import com.thebrokenrail.sorcerycraft.spell.registry.Spells; +import com.thebrokenrail.sorcerycraft.spell.api.registry.SpellRegistry; +import com.thebrokenrail.sorcerycraft.spell.util.SpellHelper; +import com.thebrokenrail.sorcerycraft.spell.api.registry.Spells; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityType; import net.minecraft.entity.LivingEntity; @@ -48,7 +48,7 @@ public class SpellEntity extends ThrownItemEntity { @Override protected void onCollision(HitResult hitResult) { if (!getEntityWorld().isClient()) { - Map spells = SpellTag.getSpells(getItem()); + Map spells = SpellHelper.getSpells(getItem()); if (!spells.containsKey(Spells.INWARD_SPELL)) { boolean success = didSpellSucceed(spells); for (Map.Entry entry : spells.entrySet()) { @@ -80,7 +80,7 @@ public class SpellEntity extends ThrownItemEntity { public void tick() { super.tick(); if (!getEntityWorld().isClient()) { - Map spells = SpellTag.getSpells(getItem()); + Map spells = SpellHelper.getSpells(getItem()); if (spells.containsKey(Spells.INWARD_SPELL)) { if (getOwner() != null) { boolean success = didSpellSucceed(spells); diff --git a/src/main/java/com/thebrokenrail/sorcerycraft/gui/CastingTableScreenHandler.java b/src/main/java/com/thebrokenrail/sorcerycraft/gui/CastingTableScreenHandler.java index ca9f1bc..9010756 100644 --- a/src/main/java/com/thebrokenrail/sorcerycraft/gui/CastingTableScreenHandler.java +++ b/src/main/java/com/thebrokenrail/sorcerycraft/gui/CastingTableScreenHandler.java @@ -3,8 +3,8 @@ package com.thebrokenrail.sorcerycraft.gui; import com.thebrokenrail.sorcerycraft.SorceryCraft; import com.thebrokenrail.sorcerycraft.spell.api.Spell; import com.thebrokenrail.sorcerycraft.spell.util.SpellPlayerEntity; -import com.thebrokenrail.sorcerycraft.spell.registry.SpellRegistry; -import com.thebrokenrail.sorcerycraft.spell.util.SpellTag; +import com.thebrokenrail.sorcerycraft.spell.api.registry.SpellRegistry; +import com.thebrokenrail.sorcerycraft.spell.util.SpellHelper; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerInventory; import net.minecraft.inventory.BasicInventory; @@ -196,11 +196,11 @@ public class CastingTableScreenHandler extends ScreenHandler { cost.getItem() == spells[index].getItemCost().getItem() && cost.getCount() >= spells[index].getItemCost().getCount()) { ItemStack resultItem = item.copy(); - Map resultSpells = SpellTag.getSpells(resultItem); + Map resultSpells = SpellHelper.getSpells(resultItem); if (!resultSpells.containsKey(spells[index].getID()) || resultSpells.get(spells[index].getID()) <= spells[index].getLevel()) { resultSpells.put(spells[index].getID(), spells[index].getLevel()); } - SpellTag.setSpells(resultItem, resultSpells); + SpellHelper.setSpells(resultItem, resultSpells); result.setInvStack(2, resultItem); } else { result.setInvStack(2, ItemStack.EMPTY); diff --git a/src/main/java/com/thebrokenrail/sorcerycraft/item/SpellItem.java b/src/main/java/com/thebrokenrail/sorcerycraft/item/SpellItem.java index b24ec8c..9d28131 100644 --- a/src/main/java/com/thebrokenrail/sorcerycraft/item/SpellItem.java +++ b/src/main/java/com/thebrokenrail/sorcerycraft/item/SpellItem.java @@ -3,10 +3,11 @@ package com.thebrokenrail.sorcerycraft.item; import com.thebrokenrail.sorcerycraft.SorceryCraft; import com.thebrokenrail.sorcerycraft.entity.SpellEntity; import com.thebrokenrail.sorcerycraft.spell.api.Spell; -import com.thebrokenrail.sorcerycraft.spell.registry.SpellRegistry; -import com.thebrokenrail.sorcerycraft.spell.util.SpellTag; +import com.thebrokenrail.sorcerycraft.spell.api.registry.SpellRegistry; +import com.thebrokenrail.sorcerycraft.spell.util.SpellHelper; import net.minecraft.client.item.TooltipContext; import net.minecraft.entity.Entity; +import net.minecraft.entity.LivingEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.Item; import net.minecraft.item.ItemGroup; @@ -51,17 +52,23 @@ public class SpellItem extends Item { return new TypedActionResult<>(ActionResult.SUCCESS, itemStack); } + @Override + public boolean useOnEntity(ItemStack stack, PlayerEntity user, LivingEntity entity, Hand hand) { + use(user.getEntityWorld(), user, hand); + return true; + } + @Override public boolean hasEnchantmentGlint(ItemStack stack) { - Map spells = SpellTag.getSpells(stack); + Map spells = SpellHelper.getSpells(stack); return spells.size() > 0 || super.hasEnchantmentGlint(stack); } @Override public void appendTooltip(ItemStack itemStack, World world, List tooltip, TooltipContext tooltipContext) { - Map spells = SpellTag.getSpells(itemStack); + Map spells = SpellHelper.getSpells(itemStack); for (Map.Entry entry : spells.entrySet()) { - tooltip.add(SpellTag.getTranslatedSpell(entry.getKey(), entry.getValue())); + tooltip.add(SpellHelper.getTranslatedSpell(entry.getKey(), entry.getValue())); } } @@ -74,7 +81,7 @@ public class SpellItem extends Item { ItemStack item = new ItemStack(this); Map spell = new HashMap<>(); spell.put(value.getID(), value.getLevel()); - SpellTag.setSpells(item, spell); + SpellHelper.setSpells(item, spell); stacks.add(item); } } @@ -90,9 +97,9 @@ public class SpellItem extends Item { super.inventoryTick(stack, world, entity, slot, selected); if (!world.isClient() && entity instanceof PlayerEntity) { PlayerEntity player = (PlayerEntity) entity; - Map itemSpells = SpellTag.getSpells(player.inventory.getInvStack(slot)); + Map itemSpells = SpellHelper.getSpells(player.inventory.getInvStack(slot)); - SpellTag.learnSpells(player, itemSpells); + SpellHelper.learnSpells(player, itemSpells); } } } diff --git a/src/main/java/com/thebrokenrail/sorcerycraft/mixin/MixinPlayerEntity.java b/src/main/java/com/thebrokenrail/sorcerycraft/mixin/MixinPlayerEntity.java index 6b8505e..d1f2628 100644 --- a/src/main/java/com/thebrokenrail/sorcerycraft/mixin/MixinPlayerEntity.java +++ b/src/main/java/com/thebrokenrail/sorcerycraft/mixin/MixinPlayerEntity.java @@ -1,7 +1,7 @@ package com.thebrokenrail.sorcerycraft.mixin; +import com.thebrokenrail.sorcerycraft.spell.util.SpellHelper; import com.thebrokenrail.sorcerycraft.spell.util.SpellPlayerEntity; -import com.thebrokenrail.sorcerycraft.spell.util.SpellTag; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.nbt.CompoundTag; import net.minecraft.util.Identifier; @@ -21,12 +21,12 @@ public class MixinPlayerEntity implements SpellPlayerEntity { @Inject(at = @At("HEAD"), method = "readCustomDataFromTag") public void readCustomDataFromTag(CompoundTag tag, CallbackInfo info) { - sorceryCraftDiscoveredSpells = SpellTag.getSpells(tag); + sorceryCraftDiscoveredSpells = SpellHelper.getSpells(tag); } @Inject(at = @At("HEAD"), method = "writeCustomDataToTag") public void writeCustomDataToTag(CompoundTag tag, CallbackInfo info) { - tag.put(SpellTag.SPELL_TAG, SpellTag.createSpellsTag(sorceryCraftDiscoveredSpells)); + tag.put(SpellHelper.SPELL_TAG, SpellHelper.createSpellsTag(sorceryCraftDiscoveredSpells)); } @Override diff --git a/src/main/java/com/thebrokenrail/sorcerycraft/mixin/MixinServerPlayerEntity.java b/src/main/java/com/thebrokenrail/sorcerycraft/mixin/MixinServerPlayerEntity.java index e943e74..bd5e0c4 100644 --- a/src/main/java/com/thebrokenrail/sorcerycraft/mixin/MixinServerPlayerEntity.java +++ b/src/main/java/com/thebrokenrail/sorcerycraft/mixin/MixinServerPlayerEntity.java @@ -1,8 +1,8 @@ package com.thebrokenrail.sorcerycraft.mixin; import com.thebrokenrail.sorcerycraft.packet.UpdateKnownSpellsS2CPacket; +import com.thebrokenrail.sorcerycraft.spell.util.SpellHelper; import com.thebrokenrail.sorcerycraft.spell.util.SpellPlayerEntity; -import com.thebrokenrail.sorcerycraft.spell.util.SpellTag; import net.minecraft.nbt.CompoundTag; import net.minecraft.server.network.ServerPlayerEntity; import org.spongepowered.asm.mixin.Mixin; @@ -24,7 +24,7 @@ public abstract class MixinServerPlayerEntity implements SpellPlayerEntity { @Inject(at = @At("HEAD"), method = "playerTick") public void playerTick(CallbackInfo info) { CompoundTag tag = new CompoundTag(); - tag.put(SpellTag.SPELL_TAG, SpellTag.createSpellsTag(getDiscoveredSpells())); + tag.put(SpellHelper.SPELL_TAG, SpellHelper.createSpellsTag(getDiscoveredSpells())); //noinspection ConstantConditions UpdateKnownSpellsS2CPacket.send((ServerPlayerEntity) (Object) this, tag); } diff --git a/src/main/java/com/thebrokenrail/sorcerycraft/packet/UpdateKnownSpellsS2CPacket.java b/src/main/java/com/thebrokenrail/sorcerycraft/packet/UpdateKnownSpellsS2CPacket.java index 56c8dc8..5ff6e8b 100644 --- a/src/main/java/com/thebrokenrail/sorcerycraft/packet/UpdateKnownSpellsS2CPacket.java +++ b/src/main/java/com/thebrokenrail/sorcerycraft/packet/UpdateKnownSpellsS2CPacket.java @@ -2,7 +2,7 @@ package com.thebrokenrail.sorcerycraft.packet; import com.thebrokenrail.sorcerycraft.SorceryCraft; import com.thebrokenrail.sorcerycraft.spell.util.SpellPlayerEntity; -import com.thebrokenrail.sorcerycraft.spell.util.SpellTag; +import com.thebrokenrail.sorcerycraft.spell.util.SpellHelper; import io.netty.buffer.Unpooled; import net.fabricmc.fabric.api.network.PacketContext; import net.minecraft.nbt.CompoundTag; @@ -16,7 +16,7 @@ public class UpdateKnownSpellsS2CPacket { CompoundTag tag = bytes.readCompoundTag(); if (context.getPlayer() != null) { SpellPlayerEntity spellPlayer = (SpellPlayerEntity) context.getPlayer(); - spellPlayer.setDiscoveredSpells(SpellTag.getSpells(tag)); + spellPlayer.setDiscoveredSpells(SpellHelper.getSpells(tag)); } } 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 7f0dd17..117ba7f 100644 --- a/src/main/java/com/thebrokenrail/sorcerycraft/spell/api/Spell.java +++ b/src/main/java/com/thebrokenrail/sorcerycraft/spell/api/Spell.java @@ -1,6 +1,6 @@ package com.thebrokenrail.sorcerycraft.spell.api; -import com.thebrokenrail.sorcerycraft.spell.registry.SpellRegistry; +import com.thebrokenrail.sorcerycraft.spell.api.registry.SpellRegistry; import net.minecraft.entity.Entity; import net.minecraft.item.ItemStack; import net.minecraft.text.Text; @@ -9,6 +9,9 @@ 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; diff --git a/src/main/java/com/thebrokenrail/sorcerycraft/spell/registry/SpellRegistry.java b/src/main/java/com/thebrokenrail/sorcerycraft/spell/api/registry/SpellRegistry.java similarity index 77% rename from src/main/java/com/thebrokenrail/sorcerycraft/spell/registry/SpellRegistry.java rename to src/main/java/com/thebrokenrail/sorcerycraft/spell/api/registry/SpellRegistry.java index 03cb25d..6329599 100644 --- a/src/main/java/com/thebrokenrail/sorcerycraft/spell/registry/SpellRegistry.java +++ b/src/main/java/com/thebrokenrail/sorcerycraft/spell/api/registry/SpellRegistry.java @@ -1,4 +1,4 @@ -package com.thebrokenrail.sorcerycraft.spell.registry; +package com.thebrokenrail.sorcerycraft.spell.api.registry; import com.thebrokenrail.sorcerycraft.spell.api.Spell; import net.minecraft.util.Identifier; @@ -9,13 +9,28 @@ import java.util.HashMap; import java.util.List; import java.util.Map; + +/** + * Spell Implementation Registry + */ public class SpellRegistry { private static final Map> spells = new HashMap<>(); + /** + * Get Spell Implementation + * @param entry Map Entry + * @return Spell Implementation + */ public static Spell getSpell(Map.Entry entry) { return getSpell(entry.getKey(), entry.getValue()); } + /** + * Get Spell Implementation + * @param id Spell ID + * @param level Spell Level + * @return Spell Implementation + */ public static Spell getSpell(Identifier id, int level) { if (!spells.containsKey(id)) { return null; @@ -28,6 +43,11 @@ public class SpellRegistry { } } + /** + * Get Max Level of a Spell + * @param id Spell ID + * @return Max Level + */ public static int getMaxLevel(Identifier id) { Spell tempSpell = getSpell(id, 0); if (tempSpell == null) { @@ -36,6 +56,10 @@ public class SpellRegistry { return tempSpell.getMaxLevel(); } + /** + * Get All Spell Implementations + * @return List of Spell Implementations + */ public static Spell[] getSpells() { List out = new ArrayList<>(); for (Map.Entry> entry : spells.entrySet()) { @@ -53,6 +77,10 @@ public class SpellRegistry { return out.toArray(new Spell[0]); } + /** + * Get All Max Level Spell Implementations + * @return List of Spell Implementations + */ public static Spell[] getMaxSpells() { List out = new ArrayList<>(); for (Map.Entry> entry : spells.entrySet()) { @@ -76,6 +104,10 @@ public class SpellRegistry { return id; } + /** + * Gat All Spell IDs + * @return List of Spell IDs + */ public static Identifier[] getSpellsID() { return spells.keySet().toArray(new Identifier[0]); } diff --git a/src/main/java/com/thebrokenrail/sorcerycraft/spell/registry/Spells.java b/src/main/java/com/thebrokenrail/sorcerycraft/spell/api/registry/Spells.java similarity index 96% rename from src/main/java/com/thebrokenrail/sorcerycraft/spell/registry/Spells.java rename to src/main/java/com/thebrokenrail/sorcerycraft/spell/api/registry/Spells.java index 9e9fae5..c93fa3a 100644 --- a/src/main/java/com/thebrokenrail/sorcerycraft/spell/registry/Spells.java +++ b/src/main/java/com/thebrokenrail/sorcerycraft/spell/api/registry/Spells.java @@ -1,4 +1,4 @@ -package com.thebrokenrail.sorcerycraft.spell.registry; +package com.thebrokenrail.sorcerycraft.spell.api.registry; import com.thebrokenrail.sorcerycraft.SorceryCraft; import com.thebrokenrail.sorcerycraft.spell.CoolingSpell; @@ -13,6 +13,9 @@ import com.thebrokenrail.sorcerycraft.spell.SteadfastSpell; import com.thebrokenrail.sorcerycraft.spell.TeleportSpell; import net.minecraft.util.Identifier; +/** + * All Builtin Spells + */ @SuppressWarnings("unused") public class Spells { public static final Identifier HEAL_SPELL; diff --git a/src/main/java/com/thebrokenrail/sorcerycraft/spell/util/RandomSpellLootTableFunction.java b/src/main/java/com/thebrokenrail/sorcerycraft/spell/util/RandomSpellLootTableFunction.java index 015ad96..fd0758f 100644 --- a/src/main/java/com/thebrokenrail/sorcerycraft/spell/util/RandomSpellLootTableFunction.java +++ b/src/main/java/com/thebrokenrail/sorcerycraft/spell/util/RandomSpellLootTableFunction.java @@ -1,7 +1,7 @@ package com.thebrokenrail.sorcerycraft.spell.util; import com.thebrokenrail.sorcerycraft.spell.api.Spell; -import com.thebrokenrail.sorcerycraft.spell.registry.SpellRegistry; +import com.thebrokenrail.sorcerycraft.spell.api.registry.SpellRegistry; import net.minecraft.item.ItemStack; import net.minecraft.loot.condition.LootCondition; import net.minecraft.loot.context.LootContext; @@ -21,9 +21,9 @@ public class RandomSpellLootTableFunction extends ConditionalLootFunction { while (!(context.getRandom().nextDouble() > chance)) { Spell[] spells = SpellRegistry.getSpells(); int index = context.getRandom().nextInt(spells.length); - Map spell = SpellTag.getSpells(stack); + Map spell = SpellHelper.getSpells(stack); spell.put(spells[index].getID(), spells[index].getLevel()); - SpellTag.setSpells(stack, spell); + SpellHelper.setSpells(stack, spell); chance = chance * 0.25d; } return stack; diff --git a/src/main/java/com/thebrokenrail/sorcerycraft/spell/util/SpellTag.java b/src/main/java/com/thebrokenrail/sorcerycraft/spell/util/SpellHelper.java similarity index 95% rename from src/main/java/com/thebrokenrail/sorcerycraft/spell/util/SpellTag.java rename to src/main/java/com/thebrokenrail/sorcerycraft/spell/util/SpellHelper.java index 282da3b..484c5c1 100644 --- a/src/main/java/com/thebrokenrail/sorcerycraft/spell/util/SpellTag.java +++ b/src/main/java/com/thebrokenrail/sorcerycraft/spell/util/SpellHelper.java @@ -2,7 +2,7 @@ package com.thebrokenrail.sorcerycraft.spell.util; import com.thebrokenrail.sorcerycraft.SorceryCraft; import com.thebrokenrail.sorcerycraft.spell.api.Spell; -import com.thebrokenrail.sorcerycraft.spell.registry.SpellRegistry; +import com.thebrokenrail.sorcerycraft.spell.api.registry.SpellRegistry; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompoundTag; @@ -19,7 +19,7 @@ import net.minecraft.world.World; import java.util.HashMap; import java.util.Map; -public class SpellTag { +public class SpellHelper { public static final String SPELL_TAG = "Spells"; public static void setSpells(ItemStack itemStack, Map map) { @@ -96,7 +96,7 @@ public class SpellTag { } public static Text getTranslatedSpellChat(Identifier id, int level) { - return new LiteralText("[").append(SpellTag.getTranslatedSpell(id, level).getString()).append("]").formatted(Formatting.GREEN); + return new LiteralText("[").append(SpellHelper.getTranslatedSpell(id, level).getString()).append("]").formatted(Formatting.GREEN); } public static void learnSpells(PlayerEntity player, Map itemSpells) {