Search in sources :

Example 1 with EntityEgg

use of net.minecraft.server.v1_12_R1.EntityEgg in project PaperDev by Kamillaova.

the class CraftBlockProjectileSource method launchProjectile.

@Override
public <T extends Projectile> T launchProjectile(Class<? extends T> projectile, Vector velocity) {
    Validate.isTrue(getBlock().getType() == Material.DISPENSER, "Block is no longer dispenser");
    // Copied from BlockDispenser.dispense()
    SourceBlock isourceblock = new SourceBlock(dispenserBlock.getWorld(), dispenserBlock.getPosition());
    // Copied from DispenseBehaviorProjectile
    IPosition iposition = BlockDispenser.a(isourceblock);
    EnumDirection enumdirection = (EnumDirection) isourceblock.e().get(BlockDispenser.FACING);
    net.minecraft.server.v1_12_R1.World world = dispenserBlock.getWorld();
    net.minecraft.server.v1_12_R1.Entity launch = null;
    if (Snowball.class.isAssignableFrom(projectile)) {
        launch = new EntitySnowball(world, iposition.getX(), iposition.getY(), iposition.getZ());
    } else if (Egg.class.isAssignableFrom(projectile)) {
        launch = new EntityEgg(world, iposition.getX(), iposition.getY(), iposition.getZ());
    } else if (EnderPearl.class.isAssignableFrom(projectile)) {
        launch = new EntityEnderPearl(world, null);
        launch.setPosition(iposition.getX(), iposition.getY(), iposition.getZ());
    } else if (ThrownExpBottle.class.isAssignableFrom(projectile)) {
        launch = new EntityThrownExpBottle(world, iposition.getX(), iposition.getY(), iposition.getZ());
    } else if (ThrownPotion.class.isAssignableFrom(projectile)) {
        if (LingeringPotion.class.isAssignableFrom(projectile)) {
            launch = new EntityPotion(world, iposition.getX(), iposition.getY(), iposition.getZ(), CraftItemStack.asNMSCopy(new ItemStack(org.bukkit.Material.LINGERING_POTION, 1)));
        } else {
            launch = new EntityPotion(world, iposition.getX(), iposition.getY(), iposition.getZ(), CraftItemStack.asNMSCopy(new ItemStack(org.bukkit.Material.SPLASH_POTION, 1)));
        }
    } else if (Arrow.class.isAssignableFrom(projectile)) {
        if (TippedArrow.class.isAssignableFrom(projectile)) {
            launch = new EntityTippedArrow(world, iposition.getX(), iposition.getY(), iposition.getZ());
            ((EntityTippedArrow) launch).setType(CraftPotionUtil.fromBukkit(new PotionData(PotionType.WATER, false, false)));
        } else if (SpectralArrow.class.isAssignableFrom(projectile)) {
            launch = new EntitySpectralArrow(world, iposition.getX(), iposition.getY(), iposition.getZ());
        } else {
            launch = new EntityTippedArrow(world, iposition.getX(), iposition.getY(), iposition.getZ());
        }
        ((EntityArrow) launch).fromPlayer = EntityArrow.PickupStatus.ALLOWED;
        ((EntityArrow) launch).projectileSource = this;
    } else if (Fireball.class.isAssignableFrom(projectile)) {
        double d0 = iposition.getX() + (double) ((float) enumdirection.getAdjacentX() * 0.3F);
        double d1 = iposition.getY() + (double) ((float) enumdirection.getAdjacentY() * 0.3F);
        double d2 = iposition.getZ() + (double) ((float) enumdirection.getAdjacentZ() * 0.3F);
        Random random = world.random;
        double d3 = random.nextGaussian() * 0.05D + (double) enumdirection.getAdjacentX();
        double d4 = random.nextGaussian() * 0.05D + (double) enumdirection.getAdjacentY();
        double d5 = random.nextGaussian() * 0.05D + (double) enumdirection.getAdjacentZ();
        if (SmallFireball.class.isAssignableFrom(projectile)) {
            launch = new EntitySmallFireball(world, null, d0, d1, d2);
        } else if (WitherSkull.class.isAssignableFrom(projectile)) {
            launch = new EntityWitherSkull(world);
            launch.setPosition(d0, d1, d2);
            double d6 = (double) MathHelper.sqrt(d3 * d3 + d4 * d4 + d5 * d5);
            ((EntityFireball) launch).dirX = d3 / d6 * 0.1D;
            ((EntityFireball) launch).dirY = d4 / d6 * 0.1D;
            ((EntityFireball) launch).dirZ = d5 / d6 * 0.1D;
        } else {
            launch = new EntityLargeFireball(world);
            launch.setPosition(d0, d1, d2);
            double d6 = (double) MathHelper.sqrt(d3 * d3 + d4 * d4 + d5 * d5);
            ((EntityFireball) launch).dirX = d3 / d6 * 0.1D;
            ((EntityFireball) launch).dirY = d4 / d6 * 0.1D;
            ((EntityFireball) launch).dirZ = d5 / d6 * 0.1D;
        }
        ((EntityFireball) launch).projectileSource = this;
    }
    Validate.notNull(launch, "Projectile not supported");
    if (launch instanceof IProjectile) {
        if (launch instanceof EntityProjectile) {
            ((EntityProjectile) launch).projectileSource = this;
        }
        // Values from DispenseBehaviorProjectile
        float a = 6.0F;
        float b = 1.1F;
        if (launch instanceof EntityPotion || launch instanceof ThrownExpBottle) {
            // Values from respective DispenseBehavior classes
            a *= 0.5F;
            b *= 1.25F;
        }
        // Copied from DispenseBehaviorProjectile
        ((IProjectile) launch).shoot((double) enumdirection.getAdjacentX(), (double) ((float) enumdirection.getAdjacentY() + 0.1F), (double) enumdirection.getAdjacentZ(), b, a);
    }
    if (velocity != null) {
        ((T) launch.getBukkitEntity()).setVelocity(velocity);
    }
    world.addEntity(launch);
    return (T) launch.getBukkitEntity();
}
Also used : EntityWitherSkull(net.minecraft.server.v1_12_R1.EntityWitherSkull) EntityTippedArrow(net.minecraft.server.v1_12_R1.EntityTippedArrow) EntityLargeFireball(net.minecraft.server.v1_12_R1.EntityLargeFireball) EntityEnderPearl(net.minecraft.server.v1_12_R1.EntityEnderPearl) EntityEgg(net.minecraft.server.v1_12_R1.EntityEgg) IProjectile(net.minecraft.server.v1_12_R1.IProjectile) SourceBlock(net.minecraft.server.v1_12_R1.SourceBlock) PotionData(org.bukkit.potion.PotionData) EntityTippedArrow(net.minecraft.server.v1_12_R1.EntityTippedArrow) TippedArrow(org.bukkit.entity.TippedArrow) EntitySpectralArrow(net.minecraft.server.v1_12_R1.EntitySpectralArrow) Random(java.util.Random) EntitySmallFireball(net.minecraft.server.v1_12_R1.EntitySmallFireball) EntityPotion(net.minecraft.server.v1_12_R1.EntityPotion) EnumDirection(net.minecraft.server.v1_12_R1.EnumDirection) EntityFireball(net.minecraft.server.v1_12_R1.EntityFireball) EntityProjectile(net.minecraft.server.v1_12_R1.EntityProjectile) EntityTippedArrow(net.minecraft.server.v1_12_R1.EntityTippedArrow) Arrow(org.bukkit.entity.Arrow) EntityArrow(net.minecraft.server.v1_12_R1.EntityArrow) EntitySpectralArrow(net.minecraft.server.v1_12_R1.EntitySpectralArrow) SpectralArrow(org.bukkit.entity.SpectralArrow) TippedArrow(org.bukkit.entity.TippedArrow) EntityArrow(net.minecraft.server.v1_12_R1.EntityArrow) IPosition(net.minecraft.server.v1_12_R1.IPosition) EntityThrownExpBottle(net.minecraft.server.v1_12_R1.EntityThrownExpBottle) EntityEgg(net.minecraft.server.v1_12_R1.EntityEgg) Egg(org.bukkit.entity.Egg) EntitySnowball(net.minecraft.server.v1_12_R1.EntitySnowball) EntityThrownExpBottle(net.minecraft.server.v1_12_R1.EntityThrownExpBottle) ThrownExpBottle(org.bukkit.entity.ThrownExpBottle) CraftItemStack(org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack) ItemStack(org.bukkit.inventory.ItemStack) EntityWitherSkull(net.minecraft.server.v1_12_R1.EntityWitherSkull) WitherSkull(org.bukkit.entity.WitherSkull)

Example 2 with EntityEgg

use of net.minecraft.server.v1_12_R1.EntityEgg in project PaperDev by Kamillaova.

the class CraftLivingEntity method launchProjectile.

@SuppressWarnings("unchecked")
public <T extends Projectile> T launchProjectile(Class<? extends T> projectile, Vector velocity) {
    net.minecraft.server.v1_12_R1.World world = ((CraftWorld) getWorld()).getHandle();
    net.minecraft.server.v1_12_R1.Entity launch = null;
    if (Snowball.class.isAssignableFrom(projectile)) {
        launch = new EntitySnowball(world, getHandle());
        // ItemSnowball
        ((EntityProjectile) launch).a(getHandle(), getHandle().pitch, getHandle().yaw, 0.0F, 1.5F, 1.0F);
    } else if (Egg.class.isAssignableFrom(projectile)) {
        launch = new EntityEgg(world, getHandle());
        // ItemEgg
        ((EntityProjectile) launch).a(getHandle(), getHandle().pitch, getHandle().yaw, 0.0F, 1.5F, 1.0F);
    } else if (EnderPearl.class.isAssignableFrom(projectile)) {
        launch = new EntityEnderPearl(world, getHandle());
        // ItemEnderPearl
        ((EntityProjectile) launch).a(getHandle(), getHandle().pitch, getHandle().yaw, 0.0F, 1.5F, 1.0F);
    } else if (Arrow.class.isAssignableFrom(projectile)) {
        if (TippedArrow.class.isAssignableFrom(projectile)) {
            launch = new EntityTippedArrow(world, getHandle());
            ((EntityTippedArrow) launch).setType(CraftPotionUtil.fromBukkit(new PotionData(PotionType.WATER, false, false)));
        } else if (SpectralArrow.class.isAssignableFrom(projectile)) {
            launch = new EntitySpectralArrow(world, getHandle());
        } else {
            launch = new EntityTippedArrow(world, getHandle());
        }
        // ItemBow
        ((EntityArrow) launch).a(getHandle(), getHandle().pitch, getHandle().yaw, 0.0F, 3.0F, 1.0F);
    } else if (ThrownPotion.class.isAssignableFrom(projectile)) {
        if (LingeringPotion.class.isAssignableFrom(projectile)) {
            launch = new EntityPotion(world, getHandle(), CraftItemStack.asNMSCopy(new ItemStack(org.bukkit.Material.LINGERING_POTION, 1)));
        } else {
            launch = new EntityPotion(world, getHandle(), CraftItemStack.asNMSCopy(new ItemStack(org.bukkit.Material.SPLASH_POTION, 1)));
        }
        // ItemSplashPotion
        ((EntityProjectile) launch).a(getHandle(), getHandle().pitch, getHandle().yaw, -20.0F, 0.5F, 1.0F);
    } else if (ThrownExpBottle.class.isAssignableFrom(projectile)) {
        launch = new EntityThrownExpBottle(world, getHandle());
        // ItemExpBottle
        ((EntityProjectile) launch).a(getHandle(), getHandle().pitch, getHandle().yaw, -20.0F, 0.7F, 1.0F);
    } else if (Fish.class.isAssignableFrom(projectile) && getHandle() instanceof EntityHuman) {
        launch = new EntityFishingHook(world, (EntityHuman) getHandle());
    } else if (Fireball.class.isAssignableFrom(projectile)) {
        Location location = getEyeLocation();
        Vector direction = location.getDirection().multiply(10);
        if (SmallFireball.class.isAssignableFrom(projectile)) {
            launch = new EntitySmallFireball(world, getHandle(), direction.getX(), direction.getY(), direction.getZ());
        } else if (WitherSkull.class.isAssignableFrom(projectile)) {
            launch = new EntityWitherSkull(world, getHandle(), direction.getX(), direction.getY(), direction.getZ());
        } else if (DragonFireball.class.isAssignableFrom(projectile)) {
            launch = new EntityDragonFireball(world, getHandle(), direction.getX(), direction.getY(), direction.getZ());
        } else {
            launch = new EntityLargeFireball(world, getHandle(), direction.getX(), direction.getY(), direction.getZ());
        }
        ((EntityFireball) launch).projectileSource = this;
        launch.setPositionRotation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
    } else if (LlamaSpit.class.isAssignableFrom(projectile)) {
        Location location = getEyeLocation();
        Vector direction = location.getDirection();
        launch = new EntityLlamaSpit(world);
        ((EntityLlamaSpit) launch).shooter = getHandle();
        // EntityLlama
        ((EntityLlamaSpit) launch).shoot(direction.getX(), direction.getY(), direction.getZ(), 1.5F, 10.0F);
        launch.setPositionRotation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
    } else if (ShulkerBullet.class.isAssignableFrom(projectile)) {
        Location location = getEyeLocation();
        launch = new EntityShulkerBullet(world, getHandle(), null, null);
        launch.setPositionRotation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
    }
    Validate.notNull(launch, "Projectile not supported");
    if (velocity != null) {
        ((T) launch.getBukkitEntity()).setVelocity(velocity);
    }
    world.addEntity(launch);
    return (T) launch.getBukkitEntity();
}
Also used : EntityShulkerBullet(net.minecraft.server.v1_12_R1.EntityShulkerBullet) EntityWitherSkull(net.minecraft.server.v1_12_R1.EntityWitherSkull) EntityTippedArrow(net.minecraft.server.v1_12_R1.EntityTippedArrow) EntityLargeFireball(net.minecraft.server.v1_12_R1.EntityLargeFireball) EntityEnderPearl(net.minecraft.server.v1_12_R1.EntityEnderPearl) EntityFishingHook(net.minecraft.server.v1_12_R1.EntityFishingHook) EntityShulkerBullet(net.minecraft.server.v1_12_R1.EntityShulkerBullet) ShulkerBullet(org.bukkit.entity.ShulkerBullet) EntityDragonFireball(net.minecraft.server.v1_12_R1.EntityDragonFireball) EntityEgg(net.minecraft.server.v1_12_R1.EntityEgg) PotionData(org.bukkit.potion.PotionData) EntitySmallFireball(net.minecraft.server.v1_12_R1.EntitySmallFireball) DragonFireball(org.bukkit.entity.DragonFireball) EntityDragonFireball(net.minecraft.server.v1_12_R1.EntityDragonFireball) EntityLargeFireball(net.minecraft.server.v1_12_R1.EntityLargeFireball) EntityFireball(net.minecraft.server.v1_12_R1.EntityFireball) Fireball(org.bukkit.entity.Fireball) SmallFireball(org.bukkit.entity.SmallFireball) EntityTippedArrow(net.minecraft.server.v1_12_R1.EntityTippedArrow) TippedArrow(org.bukkit.entity.TippedArrow) EntitySpectralArrow(net.minecraft.server.v1_12_R1.EntitySpectralArrow) DragonFireball(org.bukkit.entity.DragonFireball) EntityDragonFireball(net.minecraft.server.v1_12_R1.EntityDragonFireball) EntityLlamaSpit(net.minecraft.server.v1_12_R1.EntityLlamaSpit) EntitySmallFireball(net.minecraft.server.v1_12_R1.EntitySmallFireball) EntityPotion(net.minecraft.server.v1_12_R1.EntityPotion) Fish(org.bukkit.entity.Fish) EntitySmallFireball(net.minecraft.server.v1_12_R1.EntitySmallFireball) SmallFireball(org.bukkit.entity.SmallFireball) CraftWorld(org.bukkit.craftbukkit.v1_12_R1.CraftWorld) Vector(org.bukkit.util.Vector) EntityFireball(net.minecraft.server.v1_12_R1.EntityFireball) EntityProjectile(net.minecraft.server.v1_12_R1.EntityProjectile) EntityArrow(net.minecraft.server.v1_12_R1.EntityArrow) SpectralArrow(org.bukkit.entity.SpectralArrow) EntityTippedArrow(net.minecraft.server.v1_12_R1.EntityTippedArrow) Arrow(org.bukkit.entity.Arrow) EntitySpectralArrow(net.minecraft.server.v1_12_R1.EntitySpectralArrow) TippedArrow(org.bukkit.entity.TippedArrow) EntityHuman(net.minecraft.server.v1_12_R1.EntityHuman) EntityThrownExpBottle(net.minecraft.server.v1_12_R1.EntityThrownExpBottle) EntityEgg(net.minecraft.server.v1_12_R1.EntityEgg) Egg(org.bukkit.entity.Egg) EntitySnowball(net.minecraft.server.v1_12_R1.EntitySnowball) EntityThrownExpBottle(net.minecraft.server.v1_12_R1.EntityThrownExpBottle) ThrownExpBottle(org.bukkit.entity.ThrownExpBottle) CraftItemStack(org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack) ItemStack(org.bukkit.inventory.ItemStack) Location(org.bukkit.Location)

Example 3 with EntityEgg

use of net.minecraft.server.v1_12_R1.EntityEgg in project PaperDev by Kamillaova.

the class CraftWorld method createEntity.

@SuppressWarnings("unchecked")
public net.minecraft.server.v1_12_R1.Entity createEntity(Location location, Class<? extends Entity> clazz) throws IllegalArgumentException {
    if (location == null || clazz == null) {
        throw new IllegalArgumentException("Location or entity class cannot be null");
    }
    net.minecraft.server.v1_12_R1.Entity entity = null;
    double x = location.getX();
    double y = location.getY();
    double z = location.getZ();
    float pitch = location.getPitch();
    float yaw = location.getYaw();
    // order is important for some of these
    if (Boat.class.isAssignableFrom(clazz)) {
        entity = new EntityBoat(world, x, y, z);
        entity.setPositionRotation(x, y, z, yaw, pitch);
    // Paper start
    } else if (org.bukkit.entity.Item.class.isAssignableFrom(clazz)) {
        entity = new EntityItem(world, x, y, z, new net.minecraft.server.v1_12_R1.ItemStack(net.minecraft.server.v1_12_R1.Item.getItemOf(net.minecraft.server.v1_12_R1.Blocks.DIRT)));
    // Paper end
    } else if (FallingBlock.class.isAssignableFrom(clazz)) {
        entity = new EntityFallingBlock(world, x, y, z, world.getType(new BlockPosition(x, y, z)));
    } else if (Projectile.class.isAssignableFrom(clazz)) {
        if (Snowball.class.isAssignableFrom(clazz)) {
            entity = new EntitySnowball(world, x, y, z);
        } else if (Egg.class.isAssignableFrom(clazz)) {
            entity = new EntityEgg(world, x, y, z);
        } else if (Arrow.class.isAssignableFrom(clazz)) {
            if (TippedArrow.class.isAssignableFrom(clazz)) {
                entity = new EntityTippedArrow(world);
                ((EntityTippedArrow) entity).setType(CraftPotionUtil.fromBukkit(new PotionData(PotionType.WATER, false, false)));
            } else if (SpectralArrow.class.isAssignableFrom(clazz)) {
                entity = new EntitySpectralArrow(world);
            } else {
                entity = new EntityTippedArrow(world);
            }
            entity.setPositionRotation(x, y, z, 0, 0);
        } else if (ThrownExpBottle.class.isAssignableFrom(clazz)) {
            entity = new EntityThrownExpBottle(world);
            entity.setPositionRotation(x, y, z, 0, 0);
        } else if (EnderPearl.class.isAssignableFrom(clazz)) {
            entity = new EntityEnderPearl(world);
            entity.setPositionRotation(x, y, z, 0, 0);
        } else if (ThrownPotion.class.isAssignableFrom(clazz)) {
            if (LingeringPotion.class.isAssignableFrom(clazz)) {
                entity = new EntityPotion(world, x, y, z, CraftItemStack.asNMSCopy(new ItemStack(org.bukkit.Material.LINGERING_POTION, 1)));
            } else {
                entity = new EntityPotion(world, x, y, z, CraftItemStack.asNMSCopy(new ItemStack(org.bukkit.Material.SPLASH_POTION, 1)));
            }
        } else if (Fireball.class.isAssignableFrom(clazz)) {
            if (SmallFireball.class.isAssignableFrom(clazz)) {
                entity = new EntitySmallFireball(world);
            } else if (WitherSkull.class.isAssignableFrom(clazz)) {
                entity = new EntityWitherSkull(world);
            } else if (DragonFireball.class.isAssignableFrom(clazz)) {
                entity = new EntityDragonFireball(world);
            } else {
                entity = new EntityLargeFireball(world);
            }
            entity.setPositionRotation(x, y, z, yaw, pitch);
            Vector direction = location.getDirection().multiply(10);
            ((EntityFireball) entity).setDirection(direction.getX(), direction.getY(), direction.getZ());
        } else if (ShulkerBullet.class.isAssignableFrom(clazz)) {
            entity = new EntityShulkerBullet(world);
            entity.setPositionRotation(x, y, z, yaw, pitch);
        } else if (LlamaSpit.class.isAssignableFrom(clazz)) {
            entity = new EntityLlamaSpit(world);
            entity.setPositionRotation(x, y, z, yaw, pitch);
        }
    } else if (Minecart.class.isAssignableFrom(clazz)) {
        if (PoweredMinecart.class.isAssignableFrom(clazz)) {
            entity = new EntityMinecartFurnace(world, x, y, z);
        } else if (StorageMinecart.class.isAssignableFrom(clazz)) {
            entity = new EntityMinecartChest(world, x, y, z);
        } else if (ExplosiveMinecart.class.isAssignableFrom(clazz)) {
            entity = new EntityMinecartTNT(world, x, y, z);
        } else if (HopperMinecart.class.isAssignableFrom(clazz)) {
            entity = new EntityMinecartHopper(world, x, y, z);
        } else if (SpawnerMinecart.class.isAssignableFrom(clazz)) {
            entity = new EntityMinecartMobSpawner(world, x, y, z);
        } else if (CommandMinecart.class.isAssignableFrom(clazz)) {
            entity = new EntityMinecartCommandBlock(world, x, y, z);
        } else {
            // Default to rideable minecart for pre-rideable compatibility
            entity = new EntityMinecartRideable(world, x, y, z);
        }
    } else if (EnderSignal.class.isAssignableFrom(clazz)) {
        entity = new EntityEnderSignal(world, x, y, z);
    } else if (EnderCrystal.class.isAssignableFrom(clazz)) {
        entity = new EntityEnderCrystal(world);
        entity.setPositionRotation(x, y, z, 0, 0);
    } else if (LivingEntity.class.isAssignableFrom(clazz)) {
        if (Chicken.class.isAssignableFrom(clazz)) {
            entity = new EntityChicken(world);
        } else if (Cow.class.isAssignableFrom(clazz)) {
            if (MushroomCow.class.isAssignableFrom(clazz)) {
                entity = new EntityMushroomCow(world);
            } else {
                entity = new EntityCow(world);
            }
        } else if (Golem.class.isAssignableFrom(clazz)) {
            if (Snowman.class.isAssignableFrom(clazz)) {
                entity = new EntitySnowman(world);
            } else if (IronGolem.class.isAssignableFrom(clazz)) {
                entity = new EntityIronGolem(world);
            } else if (Shulker.class.isAssignableFrom(clazz)) {
                entity = new EntityShulker(world);
            }
        } else if (Creeper.class.isAssignableFrom(clazz)) {
            entity = new EntityCreeper(world);
        } else if (Ghast.class.isAssignableFrom(clazz)) {
            entity = new EntityGhast(world);
        } else if (Pig.class.isAssignableFrom(clazz)) {
            entity = new EntityPig(world);
        } else if (Player.class.isAssignableFrom(clazz)) {
        // need a net server handler for this one
        } else if (Sheep.class.isAssignableFrom(clazz)) {
            entity = new EntitySheep(world);
        } else if (AbstractHorse.class.isAssignableFrom(clazz)) {
            if (ChestedHorse.class.isAssignableFrom(clazz)) {
                if (Donkey.class.isAssignableFrom(clazz)) {
                    entity = new EntityHorseDonkey(world);
                } else if (Mule.class.isAssignableFrom(clazz)) {
                    entity = new EntityHorseMule(world);
                } else if (Llama.class.isAssignableFrom(clazz)) {
                    entity = new EntityLlama(world);
                }
            } else if (SkeletonHorse.class.isAssignableFrom(clazz)) {
                entity = new EntityHorseSkeleton(world);
            } else if (ZombieHorse.class.isAssignableFrom(clazz)) {
                entity = new EntityHorseZombie(world);
            } else {
                entity = new EntityHorse(world);
            }
        } else if (Skeleton.class.isAssignableFrom(clazz)) {
            if (Stray.class.isAssignableFrom(clazz)) {
                entity = new EntitySkeletonStray(world);
            } else if (WitherSkeleton.class.isAssignableFrom(clazz)) {
                entity = new EntitySkeletonWither(world);
            } else {
                entity = new EntitySkeleton(world);
            }
        } else if (Slime.class.isAssignableFrom(clazz)) {
            if (MagmaCube.class.isAssignableFrom(clazz)) {
                entity = new EntityMagmaCube(world);
            } else {
                entity = new EntitySlime(world);
            }
        } else if (Spider.class.isAssignableFrom(clazz)) {
            if (CaveSpider.class.isAssignableFrom(clazz)) {
                entity = new EntityCaveSpider(world);
            } else {
                entity = new EntitySpider(world);
            }
        } else if (Squid.class.isAssignableFrom(clazz)) {
            entity = new EntitySquid(world);
        } else if (Tameable.class.isAssignableFrom(clazz)) {
            if (Wolf.class.isAssignableFrom(clazz)) {
                entity = new EntityWolf(world);
            } else if (Ocelot.class.isAssignableFrom(clazz)) {
                entity = new EntityOcelot(world);
            } else if (Parrot.class.isAssignableFrom(clazz)) {
                entity = new EntityParrot(world);
            }
        } else if (PigZombie.class.isAssignableFrom(clazz)) {
            entity = new EntityPigZombie(world);
        } else if (Zombie.class.isAssignableFrom(clazz)) {
            if (Husk.class.isAssignableFrom(clazz)) {
                entity = new EntityZombieHusk(world);
            } else if (ZombieVillager.class.isAssignableFrom(clazz)) {
                entity = new EntityZombieVillager(world);
            } else {
                entity = new EntityZombie(world);
            }
        } else if (Giant.class.isAssignableFrom(clazz)) {
            entity = new EntityGiantZombie(world);
        } else if (Silverfish.class.isAssignableFrom(clazz)) {
            entity = new EntitySilverfish(world);
        } else if (Enderman.class.isAssignableFrom(clazz)) {
            entity = new EntityEnderman(world);
        } else if (Blaze.class.isAssignableFrom(clazz)) {
            entity = new EntityBlaze(world);
        } else if (Villager.class.isAssignableFrom(clazz)) {
            entity = new EntityVillager(world);
        } else if (Witch.class.isAssignableFrom(clazz)) {
            entity = new EntityWitch(world);
        } else if (Wither.class.isAssignableFrom(clazz)) {
            entity = new EntityWither(world);
        } else if (ComplexLivingEntity.class.isAssignableFrom(clazz)) {
            if (EnderDragon.class.isAssignableFrom(clazz)) {
                entity = new EntityEnderDragon(world);
            }
        } else if (Ambient.class.isAssignableFrom(clazz)) {
            if (Bat.class.isAssignableFrom(clazz)) {
                entity = new EntityBat(world);
            }
        } else if (Rabbit.class.isAssignableFrom(clazz)) {
            entity = new EntityRabbit(world);
        } else if (Endermite.class.isAssignableFrom(clazz)) {
            entity = new EntityEndermite(world);
        } else if (Guardian.class.isAssignableFrom(clazz)) {
            if (ElderGuardian.class.isAssignableFrom(clazz)) {
                entity = new EntityGuardianElder(world);
            } else {
                entity = new EntityGuardian(world);
            }
        } else if (ArmorStand.class.isAssignableFrom(clazz)) {
            entity = new EntityArmorStand(world, x, y, z);
        } else if (PolarBear.class.isAssignableFrom(clazz)) {
            entity = new EntityPolarBear(world);
        } else if (Vex.class.isAssignableFrom(clazz)) {
            entity = new EntityVex(world);
        } else if (Illager.class.isAssignableFrom(clazz)) {
            if (Spellcaster.class.isAssignableFrom(clazz)) {
                if (Evoker.class.isAssignableFrom(clazz)) {
                    entity = new EntityEvoker(world);
                } else if (Illusioner.class.isAssignableFrom(clazz)) {
                    entity = new EntityIllagerIllusioner(world);
                }
            } else if (Vindicator.class.isAssignableFrom(clazz)) {
                entity = new EntityVindicator(world);
            }
        }
        if (entity != null) {
            entity.setLocation(x, y, z, yaw, pitch);
            // SPIGOT-3587
            entity.setHeadRotation(yaw);
        }
    } else if (Hanging.class.isAssignableFrom(clazz)) {
        Block block = getBlockAt(location);
        BlockFace face = BlockFace.SELF;
        // 1 full block, also painting smallest size.
        int width = 16;
        // 1 full block, also painting smallest size.
        int height = 16;
        if (ItemFrame.class.isAssignableFrom(clazz)) {
            width = 12;
            height = 12;
        } else if (LeashHitch.class.isAssignableFrom(clazz)) {
            width = 9;
            height = 9;
        }
        BlockFace[] faces = new BlockFace[] { BlockFace.EAST, BlockFace.NORTH, BlockFace.WEST, BlockFace.SOUTH };
        final BlockPosition pos = new BlockPosition((int) x, (int) y, (int) z);
        for (BlockFace dir : faces) {
            net.minecraft.server.v1_12_R1.Block nmsBlock = CraftMagicNumbers.getBlock(block.getRelative(dir));
            if (nmsBlock.getBlockData().getMaterial().isBuildable() || BlockDiodeAbstract.isDiode(nmsBlock.getBlockData())) {
                boolean taken = false;
                AxisAlignedBB bb = EntityHanging.calculateBoundingBox(null, pos, CraftBlock.blockFaceToNotch(dir).opposite(), width, height);
                List<net.minecraft.server.v1_12_R1.Entity> list = (List<net.minecraft.server.v1_12_R1.Entity>) world.getEntities(null, bb);
                for (Iterator<net.minecraft.server.v1_12_R1.Entity> it = list.iterator(); !taken && it.hasNext(); ) {
                    net.minecraft.server.v1_12_R1.Entity e = it.next();
                    if (e instanceof EntityHanging) {
                        // Hanging entities do not like hanging entities which intersect them.
                        taken = true;
                    }
                }
                if (!taken) {
                    face = dir;
                    break;
                }
            }
        }
        if (LeashHitch.class.isAssignableFrom(clazz)) {
            entity = new EntityLeash(world, new BlockPosition((int) x, (int) y, (int) z));
            entity.attachedToPlayer = true;
        } else {
            // No valid face found
            Preconditions.checkArgument(face != BlockFace.SELF, "Cannot spawn hanging entity for %s at %s (no free face)", clazz.getName(), location);
            EnumDirection dir = CraftBlock.blockFaceToNotch(face).opposite();
            if (Painting.class.isAssignableFrom(clazz)) {
                entity = new EntityPainting(world, new BlockPosition((int) x, (int) y, (int) z), dir);
            } else if (ItemFrame.class.isAssignableFrom(clazz)) {
                entity = new EntityItemFrame(world, new BlockPosition((int) x, (int) y, (int) z), dir);
            }
        }
        if (entity != null && !((EntityHanging) entity).survives()) {
            throw new IllegalArgumentException("Cannot spawn hanging entity for " + clazz.getName() + " at " + location);
        }
    } else if (TNTPrimed.class.isAssignableFrom(clazz)) {
        entity = new EntityTNTPrimed(world, x, y, z, null);
    } else if (ExperienceOrb.class.isAssignableFrom(clazz)) {
        // Paper
        entity = new EntityExperienceOrb(world, x, y, z, 0, org.bukkit.entity.ExperienceOrb.SpawnReason.CUSTOM, null, null);
    } else if (Weather.class.isAssignableFrom(clazz)) {
        // not sure what this can do
        if (LightningStrike.class.isAssignableFrom(clazz)) {
            entity = new EntityLightning(world, x, y, z, false);
        // what is this, I don't even
        }
    } else if (Firework.class.isAssignableFrom(clazz)) {
        entity = new EntityFireworks(world, x, y, z, net.minecraft.server.v1_12_R1.ItemStack.a);
    } else if (AreaEffectCloud.class.isAssignableFrom(clazz)) {
        entity = new EntityAreaEffectCloud(world, x, y, z);
    } else if (EvokerFangs.class.isAssignableFrom(clazz)) {
        entity = new EntityEvokerFangs(world, x, y, z, (float) Math.toRadians(yaw), 0, null);
    }
    if (entity != null) {
        // Spigot start
        if (entity instanceof EntityOcelot) {
            ((EntityOcelot) entity).spawnBonus = false;
        }
        // Spigot end
        return entity;
    }
    throw new IllegalArgumentException("Cannot spawn an entity for " + clazz.getName());
}
Also used : Entity(org.bukkit.entity.Entity) BlockFace(org.bukkit.block.BlockFace) Vector(org.bukkit.util.Vector) StorageMinecart(org.bukkit.entity.minecart.StorageMinecart) CraftItemStack(org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack) ItemStack(org.bukkit.inventory.ItemStack) PotionData(org.bukkit.potion.PotionData) HopperMinecart(org.bukkit.entity.minecart.HopperMinecart) List(java.util.List) ArrayList(java.util.ArrayList) CommandMinecart(org.bukkit.entity.minecart.CommandMinecart) Block(org.bukkit.block.Block) CraftBlock(org.bukkit.craftbukkit.v1_12_R1.block.CraftBlock) net.minecraft.server.v1_12_R1(net.minecraft.server.v1_12_R1)

Aggregations

CraftItemStack (org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack)3 ItemStack (org.bukkit.inventory.ItemStack)3 PotionData (org.bukkit.potion.PotionData)3 EntityArrow (net.minecraft.server.v1_12_R1.EntityArrow)2 EntityEgg (net.minecraft.server.v1_12_R1.EntityEgg)2 EntityEnderPearl (net.minecraft.server.v1_12_R1.EntityEnderPearl)2 EntityFireball (net.minecraft.server.v1_12_R1.EntityFireball)2 EntityLargeFireball (net.minecraft.server.v1_12_R1.EntityLargeFireball)2 EntityPotion (net.minecraft.server.v1_12_R1.EntityPotion)2 EntityProjectile (net.minecraft.server.v1_12_R1.EntityProjectile)2 EntitySmallFireball (net.minecraft.server.v1_12_R1.EntitySmallFireball)2 EntitySnowball (net.minecraft.server.v1_12_R1.EntitySnowball)2 EntitySpectralArrow (net.minecraft.server.v1_12_R1.EntitySpectralArrow)2 EntityThrownExpBottle (net.minecraft.server.v1_12_R1.EntityThrownExpBottle)2 EntityTippedArrow (net.minecraft.server.v1_12_R1.EntityTippedArrow)2 EntityWitherSkull (net.minecraft.server.v1_12_R1.EntityWitherSkull)2 Arrow (org.bukkit.entity.Arrow)2 Egg (org.bukkit.entity.Egg)2 SpectralArrow (org.bukkit.entity.SpectralArrow)2 ThrownExpBottle (org.bukkit.entity.ThrownExpBottle)2