From 06bfc6d760cf56a06ae4be4d0b81a389e6053fe7 Mon Sep 17 00:00:00 2001 From: Sollace Date: Fri, 9 Oct 2020 18:00:55 +0200 Subject: [PATCH] Drinking milk will also clear whatever spell is attached to you (useful if you're an earth pony stuck with a shield) --- .../unicopia/mixin/MixinMilkBucketItem.java | 23 +++++++++++++++++++ src/main/resources/unicopia.mixin.json | 1 + 2 files changed, 24 insertions(+) create mode 100644 src/main/java/com/minelittlepony/unicopia/mixin/MixinMilkBucketItem.java diff --git a/src/main/java/com/minelittlepony/unicopia/mixin/MixinMilkBucketItem.java b/src/main/java/com/minelittlepony/unicopia/mixin/MixinMilkBucketItem.java new file mode 100644 index 00000000..9ce1ad77 --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/mixin/MixinMilkBucketItem.java @@ -0,0 +1,23 @@ +package com.minelittlepony.unicopia.mixin; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +import com.minelittlepony.unicopia.ability.magic.CasterUtils; +import net.minecraft.entity.LivingEntity; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.item.MilkBucketItem; +import net.minecraft.world.World; + +@Mixin(MilkBucketItem.class) +abstract class MixinMilkBucketItem extends Item { + MixinMilkBucketItem() { super(null); } + + @Inject(method = "finishUsing", at = @At("HEAD"), cancellable = true) + private void finishUsing(ItemStack stack, World world, LivingEntity entity, CallbackInfoReturnable info) { + CasterUtils.toCaster(entity).ifPresent(c -> c.setSpell(null)); + } +} diff --git a/src/main/resources/unicopia.mixin.json b/src/main/resources/unicopia.mixin.json index 6ac39693..98adfcbc 100644 --- a/src/main/resources/unicopia.mixin.json +++ b/src/main/resources/unicopia.mixin.json @@ -11,6 +11,7 @@ "MixinItemEntity", "MixinItems", "MixinLivingEntity", + "MixinMilkBucketItem", "MixinPlayerEntity", "MixinProjectileEntity", "MixinServerPlayerEntity",