fix draining items having weird behavior if passed a stack it can drain from

This commit is contained in:
yrsegal@gmail.com 2022-10-24 12:37:31 -04:00
parent 5193a20a0a
commit a8ec68a846
2 changed files with 4 additions and 3 deletions

View file

@ -154,11 +154,13 @@ data class CastingContext(
fun withdrawItem(item: ItemStack, count: Int, actuallyRemove: Boolean): Boolean {
if (this.caster.isCreative) return true
val operativeItem = item.copy()
// TODO: withdraw from ender chest given a specific ender charm?
val stacksToExamine = DiscoveryHandlers.collectItemSlots(this)
fun matches(stack: ItemStack): Boolean =
!stack.isEmpty && ItemStack.isSameItemSameTags(item, stack)
!stack.isEmpty && ItemStack.isSameItemSameTags(operativeItem, stack)
val presentCount = stacksToExamine.fold(0) { acc, stack ->
acc + if (matches(stack)) stack.count else 0

View file

@ -36,8 +36,7 @@ object OpColorize : SpellOperator {
private data class Spell(val stack: ItemStack) : RenderedSpell {
override fun cast(ctx: CastingContext) {
val copy = stack.copy()
copy.count = 1
if (ctx.withdrawItem(stack, 1, true)) {
if (ctx.withdrawItem(copy, 1, true)) {
IXplatAbstractions.INSTANCE.setColorizer(
ctx.caster,
FrozenColorizer(copy, ctx.caster.uuid)