This repository has been archived on 2023-11-26. You can view files and clone it, but cannot push or open issues or pull requests.
SlightlyVanilla/src/main/java/com/thebrokenrail/slightlyvanilla/mixin/MixinSpawnEggItem.java

34 lines
1.5 KiB
Java

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<TypedActionResult<ItemStack>> info) {
if (SlightlyVanilla.getConfig().throwableSpawnEggs.player && info.getReturnValue().getResult() == ActionResult.PASS) {
ItemStack stack = user.getStackInHand(hand);
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));
}
}
}