2023-11-27 17:02:38 +01:00
|
|
|
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;
|
|
|
|
|
2023-12-03 03:39:55 +01:00
|
|
|
import com.minelittlepony.unicopia.diet.DietView;
|
2023-11-27 17:02:38 +01:00
|
|
|
import net.minecraft.entity.LivingEntity;
|
|
|
|
import net.minecraft.entity.player.PlayerEntity;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.util.ActionResult;
|
|
|
|
import net.minecraft.util.Hand;
|
|
|
|
import net.minecraft.util.TypedActionResult;
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
|
|
|
|
@Mixin(ItemStack.class)
|
|
|
|
abstract class MixinItemStack {
|
|
|
|
@Inject(method = "use", at = @At("HEAD"), cancellable = true)
|
|
|
|
private void onUse(World world, PlayerEntity user, Hand hand, CallbackInfoReturnable<TypedActionResult<ItemStack>> info) {
|
|
|
|
ItemStack self = (ItemStack)(Object)this;
|
2023-12-03 03:39:55 +01:00
|
|
|
TypedActionResult<ItemStack> result = ((DietView.Holder)self.getItem()).getDiets(self).startUsing(self, world, user, hand);
|
2023-11-27 17:02:38 +01:00
|
|
|
if (result.getResult() != ActionResult.PASS) {
|
|
|
|
info.setReturnValue(result);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Inject(method = "finishUsing", at = @At("HEAD"))
|
|
|
|
private void onFinishUsing(World world, LivingEntity user, CallbackInfoReturnable<ItemStack> info) {
|
|
|
|
ItemStack self = (ItemStack)(Object)this;
|
2023-12-03 03:39:55 +01:00
|
|
|
((DietView.Holder)self.getItem()).getDiets(self).finishUsing(self, world, user);
|
2023-11-27 17:02:38 +01:00
|
|
|
}
|
|
|
|
}
|