From 96c3daeca4c73897ea936e93ac77cb1ed304db68 Mon Sep 17 00:00:00 2001 From: "yrsegal@gmail.com" Date: Sat, 15 Oct 2022 21:12:13 -0400 Subject: [PATCH] fix #264 --- .../api/spell/mishaps/MishapNoSpellCircle.kt | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) 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) =