2020-03-19 21:33:44 +00:00
|
|
|
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) {
|
2020-03-20 01:26:13 +00:00
|
|
|
if (SlightlyVanilla.getConfig().throwableSpawnEggs.player && info.getReturnValue().getResult() == ActionResult.PASS) {
|
2020-03-19 21:33:44 +00:00
|
|
|
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));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|