diff --git a/Common/src/main/java/at/petrak/hexcasting/api/spell/mishaps/MishapNoSpellCircle.kt b/Common/src/main/java/at/petrak/hexcasting/api/spell/mishaps/MishapNoSpellCircle.kt index b5f3e8b9..54fe1cbc 100644 --- a/Common/src/main/java/at/petrak/hexcasting/api/spell/mishaps/MishapNoSpellCircle.kt +++ b/Common/src/main/java/at/petrak/hexcasting/api/spell/mishaps/MishapNoSpellCircle.kt @@ -3,14 +3,31 @@ package at.petrak.hexcasting.api.spell.mishaps import at.petrak.hexcasting.api.misc.FrozenColorizer import at.petrak.hexcasting.api.spell.SpellDatum import at.petrak.hexcasting.api.spell.casting.CastingContext +import net.minecraft.world.entity.player.Player import net.minecraft.world.item.DyeColor +import net.minecraft.world.item.ItemStack +import net.minecraft.world.item.enchantment.EnchantmentHelper class MishapNoSpellCircle : Mishap() { override fun accentColor(ctx: CastingContext, errorCtx: Context): FrozenColorizer = dyeColor(DyeColor.LIGHT_BLUE) + private inline fun dropAll(player: Player, stacks: MutableList, filter: (ItemStack) -> Boolean = { true }) { + for (index in stacks.indices) { + val item = stacks[index] + if (!item.isEmpty && filter(item)) { + player.drop(item, true, false) + stacks[index] = ItemStack.EMPTY + } + } + } + override fun execute(ctx: CastingContext, errorCtx: Context, stack: MutableList>) { - ctx.caster.inventory.dropAll() + dropAll(ctx.caster, ctx.caster.inventory.items) + dropAll(ctx.caster, ctx.caster.inventory.offhand) + dropAll(ctx.caster, ctx.caster.inventory.armor) { + !EnchantmentHelper.hasBindingCurse(it) + } } override fun errorMessage(ctx: CastingContext, errorCtx: Context) =