package com.thebrokenrail.slightlyvanilla.mixin; import com.thebrokenrail.slightlyvanilla.SlightlyVanilla; import com.thebrokenrail.slightlyvanilla.entity.SlimeballEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; import net.minecraft.util.ActionResult; import net.minecraft.util.Hand; import net.minecraft.util.TypedActionResult; import net.minecraft.world.World; 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; @Mixin(Item.class) public class MixinItem { @Inject(at = @At("HEAD"), method = "use", cancellable = true) public void use(World world, PlayerEntity playerEntity, Hand hand, CallbackInfoReturnable> info) { ItemStack stack = playerEntity.getStackInHand(hand); if (stack.getItem() == Items.SLIME_BALL && SlightlyVanilla.getConfig().throwableSlimeballs) { if (!world.isClient()) { SlimeballEntity entity = new SlimeballEntity(world, playerEntity); entity.setItem(stack); entity.setProperties(playerEntity, playerEntity.pitch, playerEntity.yaw, 0.0f, 1.5f, 1.0f); world.spawnEntity(entity); } if (!playerEntity.isCreative()) { stack.decrement(1); } info.setReturnValue(new TypedActionResult<>(ActionResult.SUCCESS, stack)); } } }