Fix duplication bug when equipping/unequipping spells

This commit is contained in:
Sollace 2022-09-12 19:53:02 +02:00
parent 4b8b5ba78b
commit 22f28c098c
2 changed files with 13 additions and 3 deletions

View file

@ -55,7 +55,7 @@ public class PlayerCharmTracker implements Tickable, NbtSerialisable {
}
public CustomisedSpellType<?> getEquippedSpell(Hand hand) {
return handSpells[hand.ordinal()];
return handSpells[hand.ordinal()] == null ? SpellType.EMPTY_KEY.withTraits() : handSpells[hand.ordinal()];
}
public TypedActionResult<CustomisedSpellType<?>> getSpellInHand(Hand hand) {

View file

@ -47,13 +47,23 @@ public class GemstoneItem extends Item {
CustomisedSpellType<?> existing = charms.getEquippedSpell(hand);
if (existing != null) {
if (!existing.isEmpty()) {
if (stack.getCount() == 1) {
stack = existing.traits().applyTo(enchant(stack, existing.type()));
} else {
user.giveItemStack(existing.traits().applyTo(enchant(stack.split(1), existing.type())));
}
}
if (spell.getResult().isAccepted()) {
charms.equipSpell(hand, spell.getValue());
} else {
if (existing.isEmpty()) {
return result;
}
charms.equipSpell(hand, SpellType.EMPTY_KEY.withTraits());
}
return TypedActionResult.success(stack, true);