package com.thebrokenrail.slightlyvanilla.mixin; import com.thebrokenrail.slightlyvanilla.SlightlyVanilla; import com.thebrokenrail.slightlyvanilla.entity.SpawnEggEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; import net.minecraft.item.SpawnEggItem; 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; @SuppressWarnings("unused") @Mixin(SpawnEggItem.class) public class MixinSpawnEggItem { @Inject(at = @At("RETURN"), method = "use", cancellable = true) public void use(World world, PlayerEntity user, Hand hand, CallbackInfoReturnable> info) { if (SlightlyVanilla.getConfig().throwableSpawnEggs.player && info.getReturnValue().getResult() == ActionResult.PASS) { ItemStack stack = user.getStackInHand(hand); SlightlyVanilla.playThrowSound(user); if (!world.isClient()) { SpawnEggEntity entity = new SpawnEggEntity(world, user); entity.setItem(stack); entity.setProperties(user, user.pitch, user.yaw, 0.0f, 1.5f, 1.0f); world.spawnEntity(entity); } info.setReturnValue(new TypedActionResult<>(ActionResult.SUCCESS, stack)); } } }