package com.thebrokenrail.slightlyvanilla.entity; import com.thebrokenrail.slightlyvanilla.SlightlyVanilla; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.entity.EntityType; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.SpawnType; import net.minecraft.entity.projectile.thrown.ThrownItemEntity; import net.minecraft.item.Item; import net.minecraft.item.Items; import net.minecraft.item.SpawnEggItem; import net.minecraft.network.Packet; import net.minecraft.network.packet.s2c.play.EntitySpawnS2CPacket; import net.minecraft.particle.ItemStackParticleEffect; import net.minecraft.particle.ParticleEffect; import net.minecraft.particle.ParticleTypes; import net.minecraft.util.hit.HitResult; import net.minecraft.world.World; public class SpawnEggEntity extends ThrownItemEntity { public SpawnEggEntity(EntityType entityType, World world) { super(entityType, world); } public SpawnEggEntity(World world, LivingEntity owner) { super(SlightlyVanilla.SPAWN_EGG_ENTITY, owner, world); } public SpawnEggEntity(World world, double x, double y, double z) { super(SlightlyVanilla.SPAWN_EGG_ENTITY, x, y, z, world); } @Override protected Item getDefaultItem() { return Items.PIG_SPAWN_EGG; } @Environment(EnvType.CLIENT) private ParticleEffect getParticleParameters() { return new ItemStackParticleEffect(ParticleTypes.ITEM, getStack()); } @Environment(EnvType.CLIENT) public void handleStatus(byte status) { if (status == 3) { ParticleEffect particleEffect = getParticleParameters(); for (int i = 0; i < 8; ++i) { world.addParticle(particleEffect, getX(), getY(), getZ(), 0.0D, 0.0D, 0.0D); } } } @Override protected void onCollision(HitResult hitResult) { super.onCollision(hitResult); if (!world.isClient()) { world.sendEntityStatus(this, (byte) 3); EntityType entityType = ((SpawnEggItem) getStack().getItem()).getEntityType(getStack().getTag()); entityType.spawnFromItemStack(world, getItem(), null, getBlockPos(), SpawnType.SPAWN_EGG, false, false); remove(); } } @Override public Packet createSpawnPacket() { return new EntitySpawnS2CPacket(this); } }