Update API (More Consistent Package Names) Fix Bug When Casting Spell
This commit is contained in:
parent
3fe89d2d95
commit
4ebae792ac
9
API.md
9
API.md
@ -7,14 +7,14 @@
|
|||||||
maven { url 'https://jitpack.io' }
|
maven { url 'https://jitpack.io' }
|
||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
modImplementation 'com.thebrokenrail:sorcerycraft:1.1.+'
|
modImplementation 'com.thebrokenrail:sorcerycraft:1.2.+'
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
2. Add Dependency to ```fabric.mod.json```
|
2. Add Dependency to ```fabric.mod.json```
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"depends": {
|
"depends": {
|
||||||
"sorcerycraft": "1.1.x"
|
"sorcerycraft": "1.2.x"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@ -104,7 +104,10 @@
|
|||||||
- ```(non-static) Spell.getID()```
|
- ```(non-static) Spell.getID()```
|
||||||
- ```(static) SpellRegistry.register()```
|
- ```(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.
|
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
|
||||||
|
@ -1,5 +1,10 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
**1.2**
|
||||||
|
* Update Mappings
|
||||||
|
* Update API (More Consistent Package Names)
|
||||||
|
* Fix Bug When Casting Spell
|
||||||
|
|
||||||
**1.1.21**
|
**1.1.21**
|
||||||
* Update Mappings
|
* Update Mappings
|
||||||
* Tweak Teleport and Flame Spells
|
* Tweak Teleport and Flame Spells
|
||||||
|
@ -6,11 +6,11 @@ org.gradle.jvmargs = -Xmx1G
|
|||||||
minecraft_version = 20w12a
|
minecraft_version = 20w12a
|
||||||
curseforge_id = 365308
|
curseforge_id = 365308
|
||||||
simple_minecraft_version = 1.16-Snapshot
|
simple_minecraft_version = 1.16-Snapshot
|
||||||
yarn_build = 14
|
yarn_build = 18
|
||||||
fabric_loader_version = 0.7.8+build.189
|
fabric_loader_version = 0.7.8+build.189
|
||||||
|
|
||||||
# Mod Properties
|
# Mod Properties
|
||||||
mod_version = 1.1.21
|
mod_version = 1.2.0
|
||||||
maven_group = com.thebrokenrail
|
maven_group = com.thebrokenrail
|
||||||
archives_base_name = sorcerycraft
|
archives_base_name = sorcerycraft
|
||||||
|
|
||||||
@ -19,4 +19,4 @@ org.gradle.jvmargs = -Xmx1G
|
|||||||
fabric_api_version = 0.5.5+build.311-1.16
|
fabric_api_version = 0.5.5+build.311-1.16
|
||||||
cloth_config_version = 3.1.0-unstable
|
cloth_config_version = 3.1.0-unstable
|
||||||
auto_config_version = 1.2.4
|
auto_config_version = 1.2.4
|
||||||
mod_menu_version = 1.10.2+build.1
|
mod_menu_version = 1.11.0+build.2
|
||||||
|
@ -9,7 +9,7 @@ import com.thebrokenrail.sorcerycraft.item.SpellItem;
|
|||||||
import com.thebrokenrail.sorcerycraft.mixin.CriterionRegistryHook;
|
import com.thebrokenrail.sorcerycraft.mixin.CriterionRegistryHook;
|
||||||
import com.thebrokenrail.sorcerycraft.packet.SelectSpellC2SPacket;
|
import com.thebrokenrail.sorcerycraft.packet.SelectSpellC2SPacket;
|
||||||
import com.thebrokenrail.sorcerycraft.spell.util.RandomSpellLootTableFunction;
|
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.AutoConfig;
|
||||||
import me.sargunvohra.mcmods.autoconfig1u.serializer.GsonConfigSerializer;
|
import me.sargunvohra.mcmods.autoconfig1u.serializer.GsonConfigSerializer;
|
||||||
import net.fabricmc.api.ModInitializer;
|
import net.fabricmc.api.ModInitializer;
|
||||||
|
@ -4,7 +4,7 @@ import com.google.gson.JsonDeserializationContext;
|
|||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import com.thebrokenrail.sorcerycraft.SorceryCraft;
|
import com.thebrokenrail.sorcerycraft.SorceryCraft;
|
||||||
import com.thebrokenrail.sorcerycraft.spell.api.Spell;
|
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 com.thebrokenrail.sorcerycraft.spell.util.SpellPlayerEntity;
|
||||||
import net.minecraft.advancement.criterion.AbstractCriterion;
|
import net.minecraft.advancement.criterion.AbstractCriterion;
|
||||||
import net.minecraft.advancement.criterion.AbstractCriterionConditions;
|
import net.minecraft.advancement.criterion.AbstractCriterionConditions;
|
||||||
|
@ -5,7 +5,7 @@ import com.thebrokenrail.sorcerycraft.SorceryCraft;
|
|||||||
import com.thebrokenrail.sorcerycraft.gui.CastingTableScreenHandler;
|
import com.thebrokenrail.sorcerycraft.gui.CastingTableScreenHandler;
|
||||||
import com.thebrokenrail.sorcerycraft.packet.SelectSpellC2SPacket;
|
import com.thebrokenrail.sorcerycraft.packet.SelectSpellC2SPacket;
|
||||||
import com.thebrokenrail.sorcerycraft.spell.api.Spell;
|
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.EnvType;
|
||||||
import net.fabricmc.api.Environment;
|
import net.fabricmc.api.Environment;
|
||||||
import net.minecraft.client.font.TextRenderer;
|
import net.minecraft.client.font.TextRenderer;
|
||||||
@ -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()).getString());
|
button.setMessage(SpellHelper.getTranslatedSpell(spell.getID(), spell.getLevel()).getString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ import com.mojang.brigadier.suggestion.Suggestions;
|
|||||||
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
|
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
|
||||||
import com.thebrokenrail.sorcerycraft.SorceryCraft;
|
import com.thebrokenrail.sorcerycraft.SorceryCraft;
|
||||||
import com.thebrokenrail.sorcerycraft.spell.api.Spell;
|
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.CommandSource;
|
||||||
import net.minecraft.server.command.ServerCommandSource;
|
import net.minecraft.server.command.ServerCommandSource;
|
||||||
import net.minecraft.text.TranslatableText;
|
import net.minecraft.text.TranslatableText;
|
||||||
|
@ -5,9 +5,9 @@ import com.mojang.brigadier.arguments.IntegerArgumentType;
|
|||||||
import com.mojang.brigadier.exceptions.DynamicCommandExceptionType;
|
import com.mojang.brigadier.exceptions.DynamicCommandExceptionType;
|
||||||
import com.thebrokenrail.sorcerycraft.SorceryCraft;
|
import com.thebrokenrail.sorcerycraft.SorceryCraft;
|
||||||
import com.thebrokenrail.sorcerycraft.spell.api.Spell;
|
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.SpellPlayerEntity;
|
||||||
import com.thebrokenrail.sorcerycraft.spell.util.SpellTag;
|
|
||||||
import net.minecraft.command.arguments.EntityArgumentType;
|
import net.minecraft.command.arguments.EntityArgumentType;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
@ -32,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()))), 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;
|
return 0;
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
@ -44,7 +44,7 @@ public class SpellCommand {
|
|||||||
SpellPlayerEntity spellPlayer = (SpellPlayerEntity) player;
|
SpellPlayerEntity spellPlayer = (SpellPlayerEntity) player;
|
||||||
Map<Identifier, Integer> spells = spellPlayer.getDiscoveredSpells();
|
Map<Identifier, Integer> spells = spellPlayer.getDiscoveredSpells();
|
||||||
for (Map.Entry<Identifier, Integer> entry : spells.entrySet()) {
|
for (Map.Entry<Identifier, Integer> 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<>());
|
spellPlayer.setDiscoveredSpells(new HashMap<>());
|
||||||
return 1;
|
return 1;
|
||||||
@ -56,7 +56,7 @@ public class SpellCommand {
|
|||||||
SpellPlayerEntity spellPlayer = (SpellPlayerEntity) player;
|
SpellPlayerEntity spellPlayer = (SpellPlayerEntity) player;
|
||||||
Map<Identifier, Integer> spells = spellPlayer.getDiscoveredSpells();
|
Map<Identifier, Integer> spells = spellPlayer.getDiscoveredSpells();
|
||||||
if (spells.containsKey(spell)) {
|
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);
|
spells.remove(spell);
|
||||||
}
|
}
|
||||||
spellPlayer.setDiscoveredSpells(spells);
|
spellPlayer.setDiscoveredSpells(spells);
|
||||||
@ -74,7 +74,7 @@ public class SpellCommand {
|
|||||||
for (Spell spell : maxSpells) {
|
for (Spell spell : maxSpells) {
|
||||||
spellMap.put(spell.getID(), spell.getLevel());
|
spellMap.put(spell.getID(), spell.getLevel());
|
||||||
}
|
}
|
||||||
SpellTag.learnSpells(player, spellMap);
|
SpellHelper.learnSpells(player, spellMap);
|
||||||
return 1;
|
return 1;
|
||||||
})
|
})
|
||||||
.then(CommandManager.argument("spell", SpellArgumentType.spell())
|
.then(CommandManager.argument("spell", SpellArgumentType.spell())
|
||||||
@ -85,7 +85,7 @@ public class SpellCommand {
|
|||||||
int level = IntegerArgumentType.getInteger(ctx, "level") - 1;
|
int level = IntegerArgumentType.getInteger(ctx, "level") - 1;
|
||||||
Map<Identifier, Integer> spellMap = new HashMap<>();
|
Map<Identifier, Integer> spellMap = new HashMap<>();
|
||||||
spellMap.put(spell, level);
|
spellMap.put(spell, level);
|
||||||
SpellTag.learnSpells(player, spellMap);
|
SpellHelper.learnSpells(player, spellMap);
|
||||||
return 1;
|
return 1;
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
@ -107,11 +107,11 @@ public class SpellCommand {
|
|||||||
throw NOT_HOLDING_SPELL_EXCEPTION.create(player);
|
throw NOT_HOLDING_SPELL_EXCEPTION.create(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<Identifier, Integer> spellMap = SpellTag.getSpells(stack);
|
Map<Identifier, Integer> spellMap = SpellHelper.getSpells(stack);
|
||||||
spellMap.put(spell, level);
|
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;
|
return 1;
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
@ -131,12 +131,12 @@ public class SpellCommand {
|
|||||||
throw NOT_HOLDING_SPELL_EXCEPTION.create(player);
|
throw NOT_HOLDING_SPELL_EXCEPTION.create(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<Identifier, Integer> spellMap = SpellTag.getSpells(stack);
|
Map<Identifier, Integer> spellMap = SpellHelper.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);
|
ctx.getSource().sendFeedback(new TranslatableText("command." + SorceryCraft.NAMESPACE + ".spell.removed_spell", SpellHelper.getTranslatedSpell(spell, spellMap.get(spell))), true);
|
||||||
spellMap.remove(spell);
|
spellMap.remove(spell);
|
||||||
}
|
}
|
||||||
SpellTag.setSpells(stack, spellMap);
|
SpellHelper.setSpells(stack, spellMap);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
})
|
})
|
||||||
|
@ -2,9 +2,9 @@ package com.thebrokenrail.sorcerycraft.entity;
|
|||||||
|
|
||||||
import com.thebrokenrail.sorcerycraft.SorceryCraft;
|
import com.thebrokenrail.sorcerycraft.SorceryCraft;
|
||||||
import com.thebrokenrail.sorcerycraft.spell.api.Spell;
|
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.SpellTag;
|
import com.thebrokenrail.sorcerycraft.spell.util.SpellHelper;
|
||||||
import com.thebrokenrail.sorcerycraft.spell.registry.Spells;
|
import com.thebrokenrail.sorcerycraft.spell.api.registry.Spells;
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
import net.minecraft.entity.EntityType;
|
import net.minecraft.entity.EntityType;
|
||||||
import net.minecraft.entity.LivingEntity;
|
import net.minecraft.entity.LivingEntity;
|
||||||
@ -48,7 +48,7 @@ public class SpellEntity extends ThrownItemEntity {
|
|||||||
@Override
|
@Override
|
||||||
protected void onCollision(HitResult hitResult) {
|
protected void onCollision(HitResult hitResult) {
|
||||||
if (!getEntityWorld().isClient()) {
|
if (!getEntityWorld().isClient()) {
|
||||||
Map<Identifier, Integer> spells = SpellTag.getSpells(getItem());
|
Map<Identifier, Integer> spells = SpellHelper.getSpells(getItem());
|
||||||
if (!spells.containsKey(Spells.INWARD_SPELL)) {
|
if (!spells.containsKey(Spells.INWARD_SPELL)) {
|
||||||
boolean success = didSpellSucceed(spells);
|
boolean success = didSpellSucceed(spells);
|
||||||
for (Map.Entry<Identifier, Integer> entry : spells.entrySet()) {
|
for (Map.Entry<Identifier, Integer> entry : spells.entrySet()) {
|
||||||
@ -80,7 +80,7 @@ public class SpellEntity extends ThrownItemEntity {
|
|||||||
public void tick() {
|
public void tick() {
|
||||||
super.tick();
|
super.tick();
|
||||||
if (!getEntityWorld().isClient()) {
|
if (!getEntityWorld().isClient()) {
|
||||||
Map<Identifier, Integer> spells = SpellTag.getSpells(getItem());
|
Map<Identifier, Integer> spells = SpellHelper.getSpells(getItem());
|
||||||
if (spells.containsKey(Spells.INWARD_SPELL)) {
|
if (spells.containsKey(Spells.INWARD_SPELL)) {
|
||||||
if (getOwner() != null) {
|
if (getOwner() != null) {
|
||||||
boolean success = didSpellSucceed(spells);
|
boolean success = didSpellSucceed(spells);
|
||||||
|
@ -3,8 +3,8 @@ package com.thebrokenrail.sorcerycraft.gui;
|
|||||||
import com.thebrokenrail.sorcerycraft.SorceryCraft;
|
import com.thebrokenrail.sorcerycraft.SorceryCraft;
|
||||||
import com.thebrokenrail.sorcerycraft.spell.api.Spell;
|
import com.thebrokenrail.sorcerycraft.spell.api.Spell;
|
||||||
import com.thebrokenrail.sorcerycraft.spell.util.SpellPlayerEntity;
|
import com.thebrokenrail.sorcerycraft.spell.util.SpellPlayerEntity;
|
||||||
import com.thebrokenrail.sorcerycraft.spell.registry.SpellRegistry;
|
import com.thebrokenrail.sorcerycraft.spell.api.registry.SpellRegistry;
|
||||||
import com.thebrokenrail.sorcerycraft.spell.util.SpellTag;
|
import com.thebrokenrail.sorcerycraft.spell.util.SpellHelper;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
import net.minecraft.entity.player.PlayerInventory;
|
import net.minecraft.entity.player.PlayerInventory;
|
||||||
import net.minecraft.inventory.BasicInventory;
|
import net.minecraft.inventory.BasicInventory;
|
||||||
@ -196,11 +196,11 @@ public class CastingTableScreenHandler extends ScreenHandler {
|
|||||||
cost.getItem() == spells[index].getItemCost().getItem() &&
|
cost.getItem() == spells[index].getItemCost().getItem() &&
|
||||||
cost.getCount() >= spells[index].getItemCost().getCount()) {
|
cost.getCount() >= spells[index].getItemCost().getCount()) {
|
||||||
ItemStack resultItem = item.copy();
|
ItemStack resultItem = item.copy();
|
||||||
Map<Identifier, Integer> resultSpells = SpellTag.getSpells(resultItem);
|
Map<Identifier, Integer> resultSpells = SpellHelper.getSpells(resultItem);
|
||||||
if (!resultSpells.containsKey(spells[index].getID()) || resultSpells.get(spells[index].getID()) <= spells[index].getLevel()) {
|
if (!resultSpells.containsKey(spells[index].getID()) || resultSpells.get(spells[index].getID()) <= spells[index].getLevel()) {
|
||||||
resultSpells.put(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);
|
result.setInvStack(2, resultItem);
|
||||||
} else {
|
} else {
|
||||||
result.setInvStack(2, ItemStack.EMPTY);
|
result.setInvStack(2, ItemStack.EMPTY);
|
||||||
|
@ -3,10 +3,11 @@ package com.thebrokenrail.sorcerycraft.item;
|
|||||||
import com.thebrokenrail.sorcerycraft.SorceryCraft;
|
import com.thebrokenrail.sorcerycraft.SorceryCraft;
|
||||||
import com.thebrokenrail.sorcerycraft.entity.SpellEntity;
|
import com.thebrokenrail.sorcerycraft.entity.SpellEntity;
|
||||||
import com.thebrokenrail.sorcerycraft.spell.api.Spell;
|
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.SpellTag;
|
import com.thebrokenrail.sorcerycraft.spell.util.SpellHelper;
|
||||||
import net.minecraft.client.item.TooltipContext;
|
import net.minecraft.client.item.TooltipContext;
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
|
import net.minecraft.entity.LivingEntity;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemGroup;
|
import net.minecraft.item.ItemGroup;
|
||||||
@ -51,17 +52,23 @@ public class SpellItem extends Item {
|
|||||||
return new TypedActionResult<>(ActionResult.SUCCESS, itemStack);
|
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
|
@Override
|
||||||
public boolean hasEnchantmentGlint(ItemStack stack) {
|
public boolean hasEnchantmentGlint(ItemStack stack) {
|
||||||
Map<Identifier, Integer> spells = SpellTag.getSpells(stack);
|
Map<Identifier, Integer> spells = SpellHelper.getSpells(stack);
|
||||||
return spells.size() > 0 || super.hasEnchantmentGlint(stack);
|
return spells.size() > 0 || super.hasEnchantmentGlint(stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
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 = SpellHelper.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()));
|
tooltip.add(SpellHelper.getTranslatedSpell(entry.getKey(), entry.getValue()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -74,7 +81,7 @@ public class SpellItem extends Item {
|
|||||||
ItemStack item = new ItemStack(this);
|
ItemStack item = new ItemStack(this);
|
||||||
Map<Identifier, Integer> spell = new HashMap<>();
|
Map<Identifier, Integer> spell = new HashMap<>();
|
||||||
spell.put(value.getID(), value.getLevel());
|
spell.put(value.getID(), value.getLevel());
|
||||||
SpellTag.setSpells(item, spell);
|
SpellHelper.setSpells(item, spell);
|
||||||
stacks.add(item);
|
stacks.add(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -90,9 +97,9 @@ public class SpellItem extends Item {
|
|||||||
super.inventoryTick(stack, world, entity, slot, selected);
|
super.inventoryTick(stack, world, entity, slot, selected);
|
||||||
if (!world.isClient() && entity instanceof PlayerEntity) {
|
if (!world.isClient() && entity instanceof PlayerEntity) {
|
||||||
PlayerEntity player = (PlayerEntity) entity;
|
PlayerEntity player = (PlayerEntity) entity;
|
||||||
Map<Identifier, Integer> itemSpells = SpellTag.getSpells(player.inventory.getInvStack(slot));
|
Map<Identifier, Integer> itemSpells = SpellHelper.getSpells(player.inventory.getInvStack(slot));
|
||||||
|
|
||||||
SpellTag.learnSpells(player, itemSpells);
|
SpellHelper.learnSpells(player, itemSpells);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package com.thebrokenrail.sorcerycraft.mixin;
|
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.SpellPlayerEntity;
|
||||||
import com.thebrokenrail.sorcerycraft.spell.util.SpellTag;
|
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
@ -21,12 +21,12 @@ public class MixinPlayerEntity implements SpellPlayerEntity {
|
|||||||
|
|
||||||
@Inject(at = @At("HEAD"), method = "readCustomDataFromTag")
|
@Inject(at = @At("HEAD"), method = "readCustomDataFromTag")
|
||||||
public void readCustomDataFromTag(CompoundTag tag, CallbackInfo info) {
|
public void readCustomDataFromTag(CompoundTag tag, CallbackInfo info) {
|
||||||
sorceryCraftDiscoveredSpells = SpellTag.getSpells(tag);
|
sorceryCraftDiscoveredSpells = SpellHelper.getSpells(tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject(at = @At("HEAD"), method = "writeCustomDataToTag")
|
@Inject(at = @At("HEAD"), method = "writeCustomDataToTag")
|
||||||
public void writeCustomDataToTag(CompoundTag tag, CallbackInfo info) {
|
public void writeCustomDataToTag(CompoundTag tag, CallbackInfo info) {
|
||||||
tag.put(SpellTag.SPELL_TAG, SpellTag.createSpellsTag(sorceryCraftDiscoveredSpells));
|
tag.put(SpellHelper.SPELL_TAG, SpellHelper.createSpellsTag(sorceryCraftDiscoveredSpells));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package com.thebrokenrail.sorcerycraft.mixin;
|
package com.thebrokenrail.sorcerycraft.mixin;
|
||||||
|
|
||||||
import com.thebrokenrail.sorcerycraft.packet.UpdateKnownSpellsS2CPacket;
|
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.SpellPlayerEntity;
|
||||||
import com.thebrokenrail.sorcerycraft.spell.util.SpellTag;
|
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
import net.minecraft.server.network.ServerPlayerEntity;
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
@ -24,7 +24,7 @@ public abstract class MixinServerPlayerEntity implements SpellPlayerEntity {
|
|||||||
@Inject(at = @At("HEAD"), method = "playerTick")
|
@Inject(at = @At("HEAD"), method = "playerTick")
|
||||||
public void playerTick(CallbackInfo info) {
|
public void playerTick(CallbackInfo info) {
|
||||||
CompoundTag tag = new CompoundTag();
|
CompoundTag tag = new CompoundTag();
|
||||||
tag.put(SpellTag.SPELL_TAG, SpellTag.createSpellsTag(getDiscoveredSpells()));
|
tag.put(SpellHelper.SPELL_TAG, SpellHelper.createSpellsTag(getDiscoveredSpells()));
|
||||||
//noinspection ConstantConditions
|
//noinspection ConstantConditions
|
||||||
UpdateKnownSpellsS2CPacket.send((ServerPlayerEntity) (Object) this, tag);
|
UpdateKnownSpellsS2CPacket.send((ServerPlayerEntity) (Object) this, tag);
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@ package com.thebrokenrail.sorcerycraft.packet;
|
|||||||
|
|
||||||
import com.thebrokenrail.sorcerycraft.SorceryCraft;
|
import com.thebrokenrail.sorcerycraft.SorceryCraft;
|
||||||
import com.thebrokenrail.sorcerycraft.spell.util.SpellPlayerEntity;
|
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 io.netty.buffer.Unpooled;
|
||||||
import net.fabricmc.fabric.api.network.PacketContext;
|
import net.fabricmc.fabric.api.network.PacketContext;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
@ -16,7 +16,7 @@ public class UpdateKnownSpellsS2CPacket {
|
|||||||
CompoundTag tag = bytes.readCompoundTag();
|
CompoundTag tag = bytes.readCompoundTag();
|
||||||
if (context.getPlayer() != null) {
|
if (context.getPlayer() != null) {
|
||||||
SpellPlayerEntity spellPlayer = (SpellPlayerEntity) context.getPlayer();
|
SpellPlayerEntity spellPlayer = (SpellPlayerEntity) context.getPlayer();
|
||||||
spellPlayer.setDiscoveredSpells(SpellTag.getSpells(tag));
|
spellPlayer.setDiscoveredSpells(SpellHelper.getSpells(tag));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package com.thebrokenrail.sorcerycraft.spell.api;
|
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.entity.Entity;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.text.Text;
|
import net.minecraft.text.Text;
|
||||||
@ -9,6 +9,9 @@ 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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Spell Implementation Base Class
|
||||||
|
*/
|
||||||
public abstract class Spell {
|
public abstract class Spell {
|
||||||
private final Identifier id;
|
private final Identifier id;
|
||||||
private final int level;
|
private final int level;
|
||||||
|
@ -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 com.thebrokenrail.sorcerycraft.spell.api.Spell;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
@ -9,13 +9,28 @@ import java.util.HashMap;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Spell Implementation Registry
|
||||||
|
*/
|
||||||
public class SpellRegistry {
|
public class SpellRegistry {
|
||||||
private static final Map<Identifier, Class<?>> spells = new HashMap<>();
|
private static final Map<Identifier, Class<?>> spells = new HashMap<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Spell Implementation
|
||||||
|
* @param entry Map Entry
|
||||||
|
* @return Spell Implementation
|
||||||
|
*/
|
||||||
public static Spell getSpell(Map.Entry<Identifier, Integer> entry) {
|
public static Spell getSpell(Map.Entry<Identifier, Integer> entry) {
|
||||||
return getSpell(entry.getKey(), entry.getValue());
|
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) {
|
public static Spell getSpell(Identifier id, int level) {
|
||||||
if (!spells.containsKey(id)) {
|
if (!spells.containsKey(id)) {
|
||||||
return null;
|
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) {
|
public static int getMaxLevel(Identifier id) {
|
||||||
Spell tempSpell = getSpell(id, 0);
|
Spell tempSpell = getSpell(id, 0);
|
||||||
if (tempSpell == null) {
|
if (tempSpell == null) {
|
||||||
@ -36,6 +56,10 @@ public class SpellRegistry {
|
|||||||
return tempSpell.getMaxLevel();
|
return tempSpell.getMaxLevel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get All Spell Implementations
|
||||||
|
* @return List of Spell Implementations
|
||||||
|
*/
|
||||||
public static Spell[] getSpells() {
|
public static Spell[] getSpells() {
|
||||||
List<Spell> out = new ArrayList<>();
|
List<Spell> out = new ArrayList<>();
|
||||||
for (Map.Entry<Identifier, Class<?>> entry : spells.entrySet()) {
|
for (Map.Entry<Identifier, Class<?>> entry : spells.entrySet()) {
|
||||||
@ -53,6 +77,10 @@ public class SpellRegistry {
|
|||||||
return out.toArray(new Spell[0]);
|
return out.toArray(new Spell[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get All Max Level Spell Implementations
|
||||||
|
* @return List of Spell Implementations
|
||||||
|
*/
|
||||||
public static Spell[] getMaxSpells() {
|
public static Spell[] getMaxSpells() {
|
||||||
List<Spell> out = new ArrayList<>();
|
List<Spell> out = new ArrayList<>();
|
||||||
for (Map.Entry<Identifier, Class<?>> entry : spells.entrySet()) {
|
for (Map.Entry<Identifier, Class<?>> entry : spells.entrySet()) {
|
||||||
@ -76,6 +104,10 @@ public class SpellRegistry {
|
|||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gat All Spell IDs
|
||||||
|
* @return List of Spell IDs
|
||||||
|
*/
|
||||||
public static Identifier[] getSpellsID() {
|
public static Identifier[] getSpellsID() {
|
||||||
return spells.keySet().toArray(new Identifier[0]);
|
return spells.keySet().toArray(new Identifier[0]);
|
||||||
}
|
}
|
@ -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.SorceryCraft;
|
||||||
import com.thebrokenrail.sorcerycraft.spell.CoolingSpell;
|
import com.thebrokenrail.sorcerycraft.spell.CoolingSpell;
|
||||||
@ -13,6 +13,9 @@ import com.thebrokenrail.sorcerycraft.spell.SteadfastSpell;
|
|||||||
import com.thebrokenrail.sorcerycraft.spell.TeleportSpell;
|
import com.thebrokenrail.sorcerycraft.spell.TeleportSpell;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* All Builtin Spells
|
||||||
|
*/
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public class Spells {
|
public class Spells {
|
||||||
public static final Identifier HEAL_SPELL;
|
public static final Identifier HEAL_SPELL;
|
@ -1,7 +1,7 @@
|
|||||||
package com.thebrokenrail.sorcerycraft.spell.util;
|
package com.thebrokenrail.sorcerycraft.spell.util;
|
||||||
|
|
||||||
import com.thebrokenrail.sorcerycraft.spell.api.Spell;
|
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.item.ItemStack;
|
||||||
import net.minecraft.loot.condition.LootCondition;
|
import net.minecraft.loot.condition.LootCondition;
|
||||||
import net.minecraft.loot.context.LootContext;
|
import net.minecraft.loot.context.LootContext;
|
||||||
@ -21,9 +21,9 @@ public class RandomSpellLootTableFunction extends ConditionalLootFunction {
|
|||||||
while (!(context.getRandom().nextDouble() > chance)) {
|
while (!(context.getRandom().nextDouble() > chance)) {
|
||||||
Spell[] spells = SpellRegistry.getSpells();
|
Spell[] spells = SpellRegistry.getSpells();
|
||||||
int index = context.getRandom().nextInt(spells.length);
|
int index = context.getRandom().nextInt(spells.length);
|
||||||
Map<Identifier, Integer> spell = SpellTag.getSpells(stack);
|
Map<Identifier, Integer> spell = SpellHelper.getSpells(stack);
|
||||||
spell.put(spells[index].getID(), spells[index].getLevel());
|
spell.put(spells[index].getID(), spells[index].getLevel());
|
||||||
SpellTag.setSpells(stack, spell);
|
SpellHelper.setSpells(stack, spell);
|
||||||
chance = chance * 0.25d;
|
chance = chance * 0.25d;
|
||||||
}
|
}
|
||||||
return stack;
|
return stack;
|
||||||
|
@ -2,7 +2,7 @@ package com.thebrokenrail.sorcerycraft.spell.util;
|
|||||||
|
|
||||||
import com.thebrokenrail.sorcerycraft.SorceryCraft;
|
import com.thebrokenrail.sorcerycraft.SorceryCraft;
|
||||||
import com.thebrokenrail.sorcerycraft.spell.api.Spell;
|
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.entity.player.PlayerEntity;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
@ -19,7 +19,7 @@ import net.minecraft.world.World;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class SpellTag {
|
public class SpellHelper {
|
||||||
public static final String SPELL_TAG = "Spells";
|
public static final String SPELL_TAG = "Spells";
|
||||||
|
|
||||||
public static void setSpells(ItemStack itemStack, Map<Identifier, Integer> map) {
|
public static void setSpells(ItemStack itemStack, Map<Identifier, Integer> map) {
|
||||||
@ -96,7 +96,7 @@ public class SpellTag {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Text getTranslatedSpellChat(Identifier id, int level) {
|
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<Identifier, Integer> itemSpells) {
|
public static void learnSpells(PlayerEntity player, Map<Identifier, Integer> itemSpells) {
|
Reference in New Issue
Block a user