diff --git a/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerCharmTracker.java b/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerCharmTracker.java index c553dc7d..5f564c15 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerCharmTracker.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerCharmTracker.java @@ -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> getSpellInHand(Hand hand) { diff --git a/src/main/java/com/minelittlepony/unicopia/item/GemstoneItem.java b/src/main/java/com/minelittlepony/unicopia/item/GemstoneItem.java index 6c59f578..3fef3ea8 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/GemstoneItem.java +++ b/src/main/java/com/minelittlepony/unicopia/item/GemstoneItem.java @@ -47,13 +47,23 @@ public class GemstoneItem extends Item { CustomisedSpellType existing = charms.getEquippedSpell(hand); - if (existing != null) { - stack = existing.traits().applyTo(enchant(stack, existing.type())); + 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);