Search in sources :

Example 1 with SnowballEntity

use of net.minecraft.entity.projectile.SnowballEntity in project Magma-1.16.x by magmafoundation.

the class CraftWorld method createEntity.

@SuppressWarnings("unchecked")
public net.minecraft.entity.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.entity.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 BoatEntity(world, x, y, z);
        entity.moveTo(x, y, z, yaw, pitch);
    } else if (FallingBlock.class.isAssignableFrom(clazz)) {
        entity = new FallingBlockEntity(world, x, y, z, world.getBlockState(new BlockPos(x, y, z)));
    } else if (Projectile.class.isAssignableFrom(clazz)) {
        if (Snowball.class.isAssignableFrom(clazz)) {
            entity = new SnowballEntity(world, x, y, z);
        } else if (Egg.class.isAssignableFrom(clazz)) {
            entity = new EggEntity(world, x, y, z);
        } else if (AbstractArrow.class.isAssignableFrom(clazz)) {
            if (TippedArrow.class.isAssignableFrom(clazz)) {
                entity = net.minecraft.entity.EntityType.ARROW.create(world);
                ((ArrowEntity) entity).setType(CraftPotionUtil.fromBukkit(new PotionData(PotionType.WATER, false, false)));
            } else if (SpectralArrow.class.isAssignableFrom(clazz)) {
                entity = net.minecraft.entity.EntityType.SPECTRAL_ARROW.create(world);
            } else if (Trident.class.isAssignableFrom(clazz)) {
                entity = net.minecraft.entity.EntityType.TRIDENT.create(world);
            } else {
                entity = net.minecraft.entity.EntityType.ARROW.create(world);
            }
            entity.moveTo(x, y, z, 0, 0);
        } else if (ThrownExpBottle.class.isAssignableFrom(clazz)) {
            entity = net.minecraft.entity.EntityType.EXPERIENCE_BOTTLE.create(world);
            entity.moveTo(x, y, z, 0, 0);
        } else if (EnderPearl.class.isAssignableFrom(clazz)) {
            entity = net.minecraft.entity.EntityType.ENDER_PEARL.create(world);
            entity.moveTo(x, y, z, 0, 0);
        } else if (ThrownPotion.class.isAssignableFrom(clazz)) {
            if (LingeringPotion.class.isAssignableFrom(clazz)) {
                entity = new PotionEntity(world, x, y, z);
                ((PotionEntity) entity).setItem(CraftItemStack.asNMSCopy(new ItemStack(org.bukkit.Material.LINGERING_POTION, 1)));
            } else {
                entity = new PotionEntity(world, x, y, z);
                ((PotionEntity) entity).setItem(CraftItemStack.asNMSCopy(new ItemStack(org.bukkit.Material.SPLASH_POTION, 1)));
            }
        } else if (Fireball.class.isAssignableFrom(clazz)) {
            if (SmallFireball.class.isAssignableFrom(clazz)) {
                entity = net.minecraft.entity.EntityType.SMALL_FIREBALL.create(world);
            } else if (WitherSkull.class.isAssignableFrom(clazz)) {
                entity = net.minecraft.entity.EntityType.WITHER_SKULL.create(world);
            } else if (DragonFireball.class.isAssignableFrom(clazz)) {
                entity = net.minecraft.entity.EntityType.DRAGON_FIREBALL.create(world);
            } else {
                entity = net.minecraft.entity.EntityType.FIREBALL.create(world);
            }
            entity.moveTo(x, y, z, yaw, pitch);
            Vector direction = location.getDirection().multiply(10);
            ((DamagingProjectileEntity) entity).setDirection(direction.getX(), direction.getY(), direction.getZ());
        } else if (ShulkerBullet.class.isAssignableFrom(clazz)) {
            entity = net.minecraft.entity.EntityType.SHULKER_BULLET.create(world);
            entity.moveTo(x, y, z, yaw, pitch);
        } else if (LlamaSpit.class.isAssignableFrom(clazz)) {
            entity = net.minecraft.entity.EntityType.LLAMA_SPIT.create(world);
            entity.moveTo(x, y, z, yaw, pitch);
        } else if (Firework.class.isAssignableFrom(clazz)) {
            entity = new FireworkRocketEntity(world, x, y, z, net.minecraft.item.ItemStack.EMPTY);
        }
    } else if (Minecart.class.isAssignableFrom(clazz)) {
        if (PoweredMinecart.class.isAssignableFrom(clazz)) {
            entity = new FurnaceMinecartEntity(world, x, y, z);
        } else if (StorageMinecart.class.isAssignableFrom(clazz)) {
            entity = new ChestMinecartEntity(world, x, y, z);
        } else if (ExplosiveMinecart.class.isAssignableFrom(clazz)) {
            entity = new TNTMinecartEntity(world, x, y, z);
        } else if (HopperMinecart.class.isAssignableFrom(clazz)) {
            entity = new HopperMinecartEntity(world, x, y, z);
        } else if (SpawnerMinecart.class.isAssignableFrom(clazz)) {
            entity = new SpawnerMinecartEntity(world, x, y, z);
        } else if (CommandMinecart.class.isAssignableFrom(clazz)) {
            entity = new MinecartEntity(world, x, y, z);
        } else {
            // Default to rideable minecart for pre-rideable compatibility
            entity = new MinecartEntity(world, x, y, z);
        }
    } else if (EnderSignal.class.isAssignableFrom(clazz)) {
        entity = new EyeOfEnderEntity(world, x, y, z);
    } else if (EnderCrystal.class.isAssignableFrom(clazz)) {
        entity = net.minecraft.entity.EntityType.END_CRYSTAL.create(world);
        entity.moveTo(x, y, z, 0, 0);
    } else if (LivingEntity.class.isAssignableFrom(clazz)) {
        if (Chicken.class.isAssignableFrom(clazz)) {
            entity = net.minecraft.entity.EntityType.CHICKEN.create(world);
        } else if (Cow.class.isAssignableFrom(clazz)) {
            if (MushroomCow.class.isAssignableFrom(clazz)) {
                entity = net.minecraft.entity.EntityType.MOOSHROOM.create(world);
            } else {
                entity = net.minecraft.entity.EntityType.COW.create(world);
            }
        } else if (Golem.class.isAssignableFrom(clazz)) {
            if (Snowman.class.isAssignableFrom(clazz)) {
                entity = net.minecraft.entity.EntityType.SNOW_GOLEM.create(world);
            } else if (IronGolem.class.isAssignableFrom(clazz)) {
                entity = net.minecraft.entity.EntityType.IRON_GOLEM.create(world);
            } else if (Shulker.class.isAssignableFrom(clazz)) {
                entity = net.minecraft.entity.EntityType.SHULKER.create(world);
            }
        } else if (Creeper.class.isAssignableFrom(clazz)) {
            entity = net.minecraft.entity.EntityType.CREEPER.create(world);
        } else if (Ghast.class.isAssignableFrom(clazz)) {
            entity = net.minecraft.entity.EntityType.GHAST.create(world);
        } else if (Pig.class.isAssignableFrom(clazz)) {
            entity = net.minecraft.entity.EntityType.PIG.create(world);
        } else if (Player.class.isAssignableFrom(clazz)) {
        // need a net server handler for this one
        } else if (Sheep.class.isAssignableFrom(clazz)) {
            entity = net.minecraft.entity.EntityType.SHEEP.create(world);
        } else if (AbstractHorse.class.isAssignableFrom(clazz)) {
            if (ChestedHorse.class.isAssignableFrom(clazz)) {
                if (Donkey.class.isAssignableFrom(clazz)) {
                    entity = net.minecraft.entity.EntityType.DONKEY.create(world);
                } else if (Mule.class.isAssignableFrom(clazz)) {
                    entity = net.minecraft.entity.EntityType.MULE.create(world);
                } else if (Llama.class.isAssignableFrom(clazz)) {
                    if (TraderLlama.class.isAssignableFrom(clazz)) {
                        entity = net.minecraft.entity.EntityType.TRADER_LLAMA.create(world);
                    } else {
                        entity = net.minecraft.entity.EntityType.LLAMA.create(world);
                    }
                }
            } else if (SkeletonHorse.class.isAssignableFrom(clazz)) {
                entity = net.minecraft.entity.EntityType.SKELETON_HORSE.create(world);
            } else if (ZombieHorse.class.isAssignableFrom(clazz)) {
                entity = net.minecraft.entity.EntityType.ZOMBIE_HORSE.create(world);
            } else {
                entity = net.minecraft.entity.EntityType.HORSE.create(world);
            }
        } else if (Skeleton.class.isAssignableFrom(clazz)) {
            if (Stray.class.isAssignableFrom(clazz)) {
                entity = net.minecraft.entity.EntityType.STRAY.create(world);
            } else if (WitherSkeleton.class.isAssignableFrom(clazz)) {
                entity = net.minecraft.entity.EntityType.WITHER_SKELETON.create(world);
            } else {
                entity = net.minecraft.entity.EntityType.SKELETON.create(world);
            }
        } else if (Slime.class.isAssignableFrom(clazz)) {
            if (MagmaCube.class.isAssignableFrom(clazz)) {
                entity = net.minecraft.entity.EntityType.MAGMA_CUBE.create(world);
            } else {
                entity = net.minecraft.entity.EntityType.SLIME.create(world);
            }
        } else if (Spider.class.isAssignableFrom(clazz)) {
            if (CaveSpider.class.isAssignableFrom(clazz)) {
                entity = net.minecraft.entity.EntityType.CAVE_SPIDER.create(world);
            } else {
                entity = net.minecraft.entity.EntityType.SPIDER.create(world);
            }
        } else if (Squid.class.isAssignableFrom(clazz)) {
            entity = net.minecraft.entity.EntityType.SQUID.create(world);
        } else if (Tameable.class.isAssignableFrom(clazz)) {
            if (Wolf.class.isAssignableFrom(clazz)) {
                entity = net.minecraft.entity.EntityType.WOLF.create(world);
            } else if (Parrot.class.isAssignableFrom(clazz)) {
                entity = net.minecraft.entity.EntityType.PARROT.create(world);
            } else if (Cat.class.isAssignableFrom(clazz)) {
                entity = net.minecraft.entity.EntityType.CAT.create(world);
            }
        } else if (PigZombie.class.isAssignableFrom(clazz)) {
            entity = net.minecraft.entity.EntityType.ZOMBIFIED_PIGLIN.create(world);
        } else if (Zombie.class.isAssignableFrom(clazz)) {
            if (Husk.class.isAssignableFrom(clazz)) {
                entity = net.minecraft.entity.EntityType.HUSK.create(world);
            } else if (ZombieVillager.class.isAssignableFrom(clazz)) {
                entity = net.minecraft.entity.EntityType.ZOMBIE_VILLAGER.create(world);
            } else if (Drowned.class.isAssignableFrom(clazz)) {
                entity = net.minecraft.entity.EntityType.DROWNED.create(world);
            } else {
                entity = new ZombieEntity(world);
            }
        } else if (Giant.class.isAssignableFrom(clazz)) {
            entity = net.minecraft.entity.EntityType.GIANT.create(world);
        } else if (Silverfish.class.isAssignableFrom(clazz)) {
            entity = net.minecraft.entity.EntityType.SILVERFISH.create(world);
        } else if (Enderman.class.isAssignableFrom(clazz)) {
            entity = net.minecraft.entity.EntityType.ENDERMAN.create(world);
        } else if (Blaze.class.isAssignableFrom(clazz)) {
            entity = net.minecraft.entity.EntityType.BLAZE.create(world);
        } else if (AbstractVillager.class.isAssignableFrom(clazz)) {
            if (Villager.class.isAssignableFrom(clazz)) {
                entity = net.minecraft.entity.EntityType.VILLAGER.create(world);
            } else if (WanderingTrader.class.isAssignableFrom(clazz)) {
                entity = net.minecraft.entity.EntityType.WANDERING_TRADER.create(world);
            }
        } else if (Witch.class.isAssignableFrom(clazz)) {
            entity = net.minecraft.entity.EntityType.WITCH.create(world);
        } else if (Wither.class.isAssignableFrom(clazz)) {
            entity = net.minecraft.entity.EntityType.WITHER.create(world);
        } else if (ComplexLivingEntity.class.isAssignableFrom(clazz)) {
            if (EnderDragon.class.isAssignableFrom(clazz)) {
                entity = net.minecraft.entity.EntityType.ENDER_DRAGON.create(world);
            }
        } else if (Ambient.class.isAssignableFrom(clazz)) {
            if (Bat.class.isAssignableFrom(clazz)) {
                entity = net.minecraft.entity.EntityType.BAT.create(world);
            }
        } else if (Rabbit.class.isAssignableFrom(clazz)) {
            entity = net.minecraft.entity.EntityType.RABBIT.create(world);
        } else if (Endermite.class.isAssignableFrom(clazz)) {
            entity = net.minecraft.entity.EntityType.ENDERMITE.create(world);
        } else if (Guardian.class.isAssignableFrom(clazz)) {
            if (ElderGuardian.class.isAssignableFrom(clazz)) {
                entity = net.minecraft.entity.EntityType.ELDER_GUARDIAN.create(world);
            } else {
                entity = net.minecraft.entity.EntityType.GUARDIAN.create(world);
            }
        } else if (ArmorStand.class.isAssignableFrom(clazz)) {
            entity = new ArmorStandEntity(world, x, y, z);
        } else if (PolarBear.class.isAssignableFrom(clazz)) {
            entity = net.minecraft.entity.EntityType.POLAR_BEAR.create(world);
        } else if (Vex.class.isAssignableFrom(clazz)) {
            entity = net.minecraft.entity.EntityType.VEX.create(world);
        } else if (Illager.class.isAssignableFrom(clazz)) {
            if (Spellcaster.class.isAssignableFrom(clazz)) {
                if (Evoker.class.isAssignableFrom(clazz)) {
                    entity = net.minecraft.entity.EntityType.EVOKER.create(world);
                } else if (Illusioner.class.isAssignableFrom(clazz)) {
                    entity = net.minecraft.entity.EntityType.ILLUSIONER.create(world);
                }
            } else if (Vindicator.class.isAssignableFrom(clazz)) {
                entity = net.minecraft.entity.EntityType.VINDICATOR.create(world);
            } else if (Pillager.class.isAssignableFrom(clazz)) {
                entity = net.minecraft.entity.EntityType.PILLAGER.create(world);
            }
        } else if (Turtle.class.isAssignableFrom(clazz)) {
            entity = net.minecraft.entity.EntityType.TURTLE.create(world);
        } else if (Phantom.class.isAssignableFrom(clazz)) {
            entity = net.minecraft.entity.EntityType.PHANTOM.create(world);
        } else if (Fish.class.isAssignableFrom(clazz)) {
            if (Cod.class.isAssignableFrom(clazz)) {
                entity = net.minecraft.entity.EntityType.COD.create(world);
            } else if (PufferFish.class.isAssignableFrom(clazz)) {
                entity = net.minecraft.entity.EntityType.PUFFERFISH.create(world);
            } else if (Salmon.class.isAssignableFrom(clazz)) {
                entity = net.minecraft.entity.EntityType.SALMON.create(world);
            } else if (TropicalFish.class.isAssignableFrom(clazz)) {
                entity = net.minecraft.entity.EntityType.TROPICAL_FISH.create(world);
            }
        } else if (Dolphin.class.isAssignableFrom(clazz)) {
            entity = net.minecraft.entity.EntityType.DOLPHIN.create(world);
        } else if (Ocelot.class.isAssignableFrom(clazz)) {
            entity = net.minecraft.entity.EntityType.OCELOT.create(world);
        } else if (Ravager.class.isAssignableFrom(clazz)) {
            entity = net.minecraft.entity.EntityType.RAVAGER.create(world);
        } else if (Panda.class.isAssignableFrom(clazz)) {
            entity = net.minecraft.entity.EntityType.PANDA.create(world);
        } else if (Fox.class.isAssignableFrom(clazz)) {
            entity = net.minecraft.entity.EntityType.FOX.create(world);
        } else if (Bee.class.isAssignableFrom(clazz)) {
            entity = net.minecraft.entity.EntityType.BEE.create(world);
        } else if (Hoglin.class.isAssignableFrom(clazz)) {
            entity = net.minecraft.entity.EntityType.HOGLIN.create(world);
        } else if (Piglin.class.isAssignableFrom(clazz)) {
            entity = net.minecraft.entity.EntityType.PIGLIN.create(world);
        } else if (PiglinBrute.class.isAssignableFrom(clazz)) {
            entity = net.minecraft.entity.EntityType.PIGLIN_BRUTE.create(world);
        } else if (Strider.class.isAssignableFrom(clazz)) {
            entity = net.minecraft.entity.EntityType.STRIDER.create(world);
        } else if (Zoglin.class.isAssignableFrom(clazz)) {
            entity = net.minecraft.entity.EntityType.ZOGLIN.create(world);
        }
        if (entity != null) {
            entity.absMoveTo(x, y, z, yaw, pitch);
            // SPIGOT-3587
            entity.setYHeadRot(yaw);
        }
    } else if (Hanging.class.isAssignableFrom(clazz)) {
        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, BlockFace.UP, BlockFace.DOWN };
        final BlockPos pos = new BlockPos(x, y, z);
        for (BlockFace dir : faces) {
            net.minecraft.block.BlockState nmsBlock = world.getBlockState(pos.relative(CraftBlock.blockFaceToNotch(dir)));
            if (nmsBlock.getMaterial().isSolid() || RedstoneDiodeBlock.isDiode(nmsBlock)) {
                boolean taken = false;
                AxisAlignedBB bb = (ItemFrame.class.isAssignableFrom(clazz)) ? ItemFrameEntity.calculateBoundingBox(null, pos, CraftBlock.blockFaceToNotch(dir).getOpposite(), width, height) : HangingEntity.calculateBoundingBox(null, pos, CraftBlock.blockFaceToNotch(dir).getOpposite(), width, height);
                List<net.minecraft.entity.Entity> list = (List<net.minecraft.entity.Entity>) world.getEntities(null, bb);
                for (Iterator<net.minecraft.entity.Entity> it = list.iterator(); !taken && it.hasNext(); ) {
                    net.minecraft.entity.Entity e = it.next();
                    if (e instanceof HangingEntity) {
                        // Hanging entities do not like hanging entities which intersect them.
                        taken = true;
                    }
                }
                if (!taken) {
                    face = dir;
                    break;
                }
            }
        }
        if (LeashHitch.class.isAssignableFrom(clazz)) {
            entity = new LeashKnotEntity(world, new BlockPos(x, y, z));
            entity.forcedLoading = 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);
            Direction dir = CraftBlock.blockFaceToNotch(face).getOpposite();
            if (Painting.class.isAssignableFrom(clazz)) {
                entity = new PaintingEntity(world, new BlockPos(x, y, z), dir);
            } else if (ItemFrame.class.isAssignableFrom(clazz)) {
                entity = new ItemFrameEntity(world, new BlockPos(x, y, z), dir);
            }
        }
        if (entity != null && !((HangingEntity) entity).survives()) {
            throw new IllegalArgumentException("Cannot spawn hanging entity for " + clazz.getName() + " at " + location);
        }
    } else if (TNTPrimed.class.isAssignableFrom(clazz)) {
        entity = new TNTEntity(world, x, y, z, null);
    } else if (ExperienceOrb.class.isAssignableFrom(clazz)) {
        entity = new ExperienceOrbEntity(world, x, y, z, 0);
    } else if (LightningStrike.class.isAssignableFrom(clazz)) {
        entity = net.minecraft.entity.EntityType.LIGHTNING_BOLT.create(world);
    } else if (AreaEffectCloud.class.isAssignableFrom(clazz)) {
        entity = new AreaEffectCloudEntity(world, x, y, z);
    } else if (EvokerFangs.class.isAssignableFrom(clazz)) {
        entity = new EvokerFangsEntity(world, x, y, z, (float) Math.toRadians(yaw), 0, null);
    }
    if (entity != null) {
        return entity;
    }
    throw new IllegalArgumentException("Cannot spawn an entity for " + clazz.getName());
}
Also used : SnowballEntity(net.minecraft.entity.projectile.SnowballEntity) Entity(org.bukkit.entity.Entity) DamagingProjectileEntity(net.minecraft.entity.projectile.DamagingProjectileEntity) ChestMinecartEntity(net.minecraft.entity.item.minecart.ChestMinecartEntity) MinecartEntity(net.minecraft.entity.item.minecart.MinecartEntity) AbstractArrowEntity(net.minecraft.entity.projectile.AbstractArrowEntity) LivingEntity(org.bukkit.entity.LivingEntity) ExperienceOrbEntity(net.minecraft.entity.item.ExperienceOrbEntity) ItemFrameEntity(net.minecraft.entity.item.ItemFrameEntity) HangingEntity(net.minecraft.entity.item.HangingEntity) AreaEffectCloudEntity(net.minecraft.entity.AreaEffectCloudEntity) LeashKnotEntity(net.minecraft.entity.item.LeashKnotEntity) SpawnerMinecartEntity(net.minecraft.entity.item.minecart.SpawnerMinecartEntity) PaintingEntity(net.minecraft.entity.item.PaintingEntity) ArrowEntity(net.minecraft.entity.projectile.ArrowEntity) PotionEntity(net.minecraft.entity.projectile.PotionEntity) FallingBlockEntity(net.minecraft.entity.item.FallingBlockEntity) TNTMinecartEntity(net.minecraft.entity.item.minecart.TNTMinecartEntity) EvokerFangsEntity(net.minecraft.entity.projectile.EvokerFangsEntity) TNTEntity(net.minecraft.entity.item.TNTEntity) HopperMinecartEntity(net.minecraft.entity.item.minecart.HopperMinecartEntity) FurnaceMinecartEntity(net.minecraft.entity.item.minecart.FurnaceMinecartEntity) EyeOfEnderEntity(net.minecraft.entity.projectile.EyeOfEnderEntity) ZombieEntity(net.minecraft.entity.monster.ZombieEntity) ArmorStandEntity(net.minecraft.entity.item.ArmorStandEntity) CraftEntity(org.bukkit.craftbukkit.v1_16_R3.entity.CraftEntity) BoatEntity(net.minecraft.entity.item.BoatEntity) EggEntity(net.minecraft.entity.projectile.EggEntity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) FireworkRocketEntity(net.minecraft.entity.projectile.FireworkRocketEntity) LightningBoltEntity(net.minecraft.entity.effect.LightningBoltEntity) ComplexLivingEntity(org.bukkit.entity.ComplexLivingEntity) MobEntity(net.minecraft.entity.MobEntity) HumanEntity(org.bukkit.entity.HumanEntity) ItemEntity(net.minecraft.entity.item.ItemEntity) TNTEntity(net.minecraft.entity.item.TNTEntity) Dolphin(org.bukkit.entity.Dolphin) BlockFace(org.bukkit.block.BlockFace) FireworkRocketEntity(net.minecraft.entity.projectile.FireworkRocketEntity) EnderDragon(org.bukkit.entity.EnderDragon) Phantom(org.bukkit.entity.Phantom) ThrownPotion(org.bukkit.entity.ThrownPotion) ElderGuardian(org.bukkit.entity.ElderGuardian) Guardian(org.bukkit.entity.Guardian) Pillager(org.bukkit.entity.Pillager) SnowballEntity(net.minecraft.entity.projectile.SnowballEntity) Vector(org.bukkit.util.Vector) BoatEntity(net.minecraft.entity.item.BoatEntity) MushroomCow(org.bukkit.entity.MushroomCow) ChestMinecartEntity(net.minecraft.entity.item.minecart.ChestMinecartEntity) MinecartEntity(net.minecraft.entity.item.minecart.MinecartEntity) SpawnerMinecartEntity(net.minecraft.entity.item.minecart.SpawnerMinecartEntity) TNTMinecartEntity(net.minecraft.entity.item.minecart.TNTMinecartEntity) HopperMinecartEntity(net.minecraft.entity.item.minecart.HopperMinecartEntity) FurnaceMinecartEntity(net.minecraft.entity.item.minecart.FurnaceMinecartEntity) ElderGuardian(org.bukkit.entity.ElderGuardian) LingeringPotion(org.bukkit.entity.LingeringPotion) Ravager(org.bukkit.entity.Ravager) ChestMinecartEntity(net.minecraft.entity.item.minecart.ChestMinecartEntity) PaintingEntity(net.minecraft.entity.item.PaintingEntity) ItemFrameEntity(net.minecraft.entity.item.ItemFrameEntity) CaveSpider(org.bukkit.entity.CaveSpider) Firework(org.bukkit.entity.Firework) AreaEffectCloudEntity(net.minecraft.entity.AreaEffectCloudEntity) ItemStack(org.bukkit.inventory.ItemStack) CraftItemStack(org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack) ExplosiveMinecart(org.bukkit.entity.minecart.ExplosiveMinecart) Rabbit(org.bukkit.entity.Rabbit) IronGolem(org.bukkit.entity.IronGolem) LeashKnotEntity(net.minecraft.entity.item.LeashKnotEntity) ShulkerBullet(org.bukkit.entity.ShulkerBullet) Illager(org.bukkit.entity.Illager) Direction(net.minecraft.util.Direction) TNTMinecartEntity(net.minecraft.entity.item.minecart.TNTMinecartEntity) PotionData(org.bukkit.potion.PotionData) TropicalFish(org.bukkit.entity.TropicalFish) DamagingProjectileEntity(net.minecraft.entity.projectile.DamagingProjectileEntity) Hoglin(org.bukkit.entity.Hoglin) Wolf(org.bukkit.entity.Wolf) Witch(org.bukkit.entity.Witch) HangingEntity(net.minecraft.entity.item.HangingEntity) Tameable(org.bukkit.entity.Tameable) Mule(org.bukkit.entity.Mule) Husk(org.bukkit.entity.Husk) MushroomCow(org.bukkit.entity.MushroomCow) Cow(org.bukkit.entity.Cow) ExperienceOrb(org.bukkit.entity.ExperienceOrb) AreaEffectCloud(org.bukkit.entity.AreaEffectCloud) Pig(org.bukkit.entity.Pig) Blaze(org.bukkit.entity.Blaze) WitherSkull(org.bukkit.entity.WitherSkull) Zoglin(org.bukkit.entity.Zoglin) ZombieEntity(net.minecraft.entity.monster.ZombieEntity) EggEntity(net.minecraft.entity.projectile.EggEntity) ExplosiveMinecart(org.bukkit.entity.minecart.ExplosiveMinecart) PoweredMinecart(org.bukkit.entity.minecart.PoweredMinecart) CommandMinecart(org.bukkit.entity.minecart.CommandMinecart) SpawnerMinecart(org.bukkit.entity.minecart.SpawnerMinecart) StorageMinecart(org.bukkit.entity.minecart.StorageMinecart) HopperMinecart(org.bukkit.entity.minecart.HopperMinecart) Minecart(org.bukkit.entity.Minecart) SpectralArrow(org.bukkit.entity.SpectralArrow) ItemFrame(org.bukkit.entity.ItemFrame) FallingBlock(org.bukkit.entity.FallingBlock) Hanging(org.bukkit.entity.Hanging) HopperMinecartEntity(net.minecraft.entity.item.minecart.HopperMinecartEntity) WanderingTrader(org.bukkit.entity.WanderingTrader) BlockPos(net.minecraft.util.math.BlockPos) ImmutableList(com.google.common.collect.ImmutableList) ArrayList(java.util.ArrayList) List(java.util.List) ArmorStandEntity(net.minecraft.entity.item.ArmorStandEntity) Zombie(org.bukkit.entity.Zombie) PigZombie(org.bukkit.entity.PigZombie) PiglinBrute(org.bukkit.entity.PiglinBrute) EnderCrystal(org.bukkit.entity.EnderCrystal) Evoker(org.bukkit.entity.Evoker) FurnaceMinecartEntity(net.minecraft.entity.item.minecart.FurnaceMinecartEntity) Fox(org.bukkit.entity.Fox) Drowned(org.bukkit.entity.Drowned) PoweredMinecart(org.bukkit.entity.minecart.PoweredMinecart) Cat(org.bukkit.entity.Cat) ThrownExpBottle(org.bukkit.entity.ThrownExpBottle) EvokerFangsEntity(net.minecraft.entity.projectile.EvokerFangsEntity) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Stray(org.bukkit.entity.Stray) AbstractArrowEntity(net.minecraft.entity.projectile.AbstractArrowEntity) ArrowEntity(net.minecraft.entity.projectile.ArrowEntity) Creeper(org.bukkit.entity.Creeper) ComplexLivingEntity(org.bukkit.entity.ComplexLivingEntity) Silverfish(org.bukkit.entity.Silverfish) Spellcaster(org.bukkit.entity.Spellcaster) LeashHitch(org.bukkit.entity.LeashHitch) Iterator(java.util.Iterator) Skeleton(org.bukkit.entity.Skeleton) WitherSkeleton(org.bukkit.entity.WitherSkeleton) SkeletonHorse(org.bukkit.entity.SkeletonHorse) FallingBlockEntity(net.minecraft.entity.item.FallingBlockEntity) PolarBear(org.bukkit.entity.PolarBear) SpawnerMinecart(org.bukkit.entity.minecart.SpawnerMinecart) Egg(org.bukkit.entity.Egg) PufferFish(org.bukkit.entity.PufferFish) EyeOfEnderEntity(net.minecraft.entity.projectile.EyeOfEnderEntity) SpawnerMinecartEntity(net.minecraft.entity.item.minecart.SpawnerMinecartEntity) ExperienceOrbEntity(net.minecraft.entity.item.ExperienceOrbEntity) PotionEntity(net.minecraft.entity.projectile.PotionEntity) Painting(org.bukkit.entity.Painting) CraftBlockState(org.bukkit.craftbukkit.v1_16_R3.block.CraftBlockState) CaveSpider(org.bukkit.entity.CaveSpider) Spider(org.bukkit.entity.Spider) Sheep(org.bukkit.entity.Sheep)

Example 2 with SnowballEntity

use of net.minecraft.entity.projectile.SnowballEntity in project Magma-1.16.x by magmafoundation.

the class CraftLivingEntity method launchProjectile.

@Override
@SuppressWarnings("unchecked")
public <T extends Projectile> T launchProjectile(Class<? extends T> projectile, Vector velocity) {
    net.minecraft.world.World world = ((CraftWorld) getWorld()).getHandle();
    net.minecraft.entity.Entity launch = null;
    if (Snowball.class.isAssignableFrom(projectile)) {
        launch = new SnowballEntity(world, getHandle());
        // ItemSnowball
        ((ThrowableEntity) launch).shootFromRotation(getHandle(), getHandle().xRot, getHandle().yRot, 0.0F, 1.5F, 1.0F);
    } else if (Egg.class.isAssignableFrom(projectile)) {
        launch = new EggEntity(world, getHandle());
        // ItemEgg
        ((ThrowableEntity) launch).shootFromRotation(getHandle(), getHandle().xRot, getHandle().yRot, 0.0F, 1.5F, 1.0F);
    } else if (EnderPearl.class.isAssignableFrom(projectile)) {
        launch = new EnderPearlEntity(world, getHandle());
        // EnderPearlItem
        ((ThrowableEntity) launch).shootFromRotation(getHandle(), getHandle().xRot, getHandle().yRot, 0.0F, 1.5F, 1.0F);
    } else if (AbstractArrow.class.isAssignableFrom(projectile)) {
        if (TippedArrow.class.isAssignableFrom(projectile)) {
            launch = new ArrowEntity(world, getHandle());
            ((ArrowEntity) launch).setType(CraftPotionUtil.fromBukkit(new PotionData(PotionType.WATER, false, false)));
        } else if (SpectralArrow.class.isAssignableFrom(projectile)) {
            launch = new SpectralArrowEntity(world, getHandle());
        } else if (Trident.class.isAssignableFrom(projectile)) {
            launch = new TridentEntity(world, getHandle(), new net.minecraft.item.ItemStack(net.minecraft.item.Items.TRIDENT));
        } else {
            launch = new ArrowEntity(world, getHandle());
        }
        // ItemBow
        ((AbstractArrowEntity) launch).shootFromRotation(getHandle(), getHandle().xRot, getHandle().yRot, 0.0F, 3.0F, 1.0F);
    } else if (ThrownPotion.class.isAssignableFrom(projectile)) {
        if (LingeringPotion.class.isAssignableFrom(projectile)) {
            launch = new PotionEntity(world, getHandle());
            ((PotionEntity) launch).setItem(CraftItemStack.asNMSCopy(new ItemStack(org.bukkit.Material.LINGERING_POTION, 1)));
        } else {
            launch = new PotionEntity(world, getHandle());
            ((PotionEntity) launch).setItem(CraftItemStack.asNMSCopy(new ItemStack(org.bukkit.Material.SPLASH_POTION, 1)));
        }
        // SplashPotionItem
        ((ThrowableEntity) launch).shootFromRotation(getHandle(), getHandle().xRot, getHandle().yRot, -20.0F, 0.5F, 1.0F);
    } else if (ThrownExpBottle.class.isAssignableFrom(projectile)) {
        launch = new ExperienceBottleEntity(world, getHandle());
        // ExperienceBottleItem
        ((ThrowableEntity) launch).shootFromRotation(getHandle(), getHandle().xRot, getHandle().yRot, -20.0F, 0.7F, 1.0F);
    } else if (FishHook.class.isAssignableFrom(projectile) && getHandle() instanceof PlayerEntity) {
        launch = new FishingBobberEntity((PlayerEntity) getHandle(), world, 0, 0);
    } else if (Fireball.class.isAssignableFrom(projectile)) {
        Location location = getEyeLocation();
        Vector direction = location.getDirection().multiply(10);
        if (SmallFireball.class.isAssignableFrom(projectile)) {
            launch = new SmallFireballEntity(world, getHandle(), direction.getX(), direction.getY(), direction.getZ());
        } else if (WitherSkull.class.isAssignableFrom(projectile)) {
            launch = new WitherSkullEntity(world, getHandle(), direction.getX(), direction.getY(), direction.getZ());
        } else if (DragonFireball.class.isAssignableFrom(projectile)) {
            launch = new DragonFireballEntity(world, getHandle(), direction.getX(), direction.getY(), direction.getZ());
        } else {
            launch = new FireballEntity(world, getHandle(), direction.getX(), direction.getY(), direction.getZ());
        }
        ((DamagingProjectileEntity) launch).projectileSource = this;
        launch.moveTo(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
    } else if (LlamaSpit.class.isAssignableFrom(projectile)) {
        Location location = getEyeLocation();
        Vector direction = location.getDirection();
        launch = net.minecraft.entity.EntityType.LLAMA_SPIT.create(world);
        ((LlamaSpitEntity) launch).setOwner(getHandle());
        // LlamaEntity
        ((LlamaSpitEntity) launch).shoot(direction.getX(), direction.getY(), direction.getZ(), 1.5F, 10.0F);
        launch.moveTo(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
    } else if (ShulkerBullet.class.isAssignableFrom(projectile)) {
        Location location = getEyeLocation();
        launch = new ShulkerBulletEntity(world, getHandle(), null, null);
        launch.moveTo(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
    } else if (Firework.class.isAssignableFrom(projectile)) {
        Location location = getEyeLocation();
        launch = new FireworkRocketEntity(world, net.minecraft.item.ItemStack.EMPTY, getHandle());
        launch.moveTo(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.addFreshEntity(launch);
    return (T) launch.getBukkitEntity();
}
Also used : ArrowEntity(net.minecraft.entity.projectile.ArrowEntity) AbstractArrowEntity(net.minecraft.entity.projectile.AbstractArrowEntity) SpectralArrowEntity(net.minecraft.entity.projectile.SpectralArrowEntity) SmallFireballEntity(net.minecraft.entity.projectile.SmallFireballEntity) ThrowableEntity(net.minecraft.entity.projectile.ThrowableEntity) EggEntity(net.minecraft.entity.projectile.EggEntity) SpectralArrowEntity(net.minecraft.entity.projectile.SpectralArrowEntity) FireworkRocketEntity(net.minecraft.entity.projectile.FireworkRocketEntity) ShulkerBullet(org.bukkit.entity.ShulkerBullet) PlayerEntity(net.minecraft.entity.player.PlayerEntity) EnderPearlEntity(net.minecraft.entity.item.EnderPearlEntity) PotionData(org.bukkit.potion.PotionData) DragonFireball(org.bukkit.entity.DragonFireball) Fireball(org.bukkit.entity.Fireball) SmallFireball(org.bukkit.entity.SmallFireball) TippedArrow(org.bukkit.entity.TippedArrow) DragonFireball(org.bukkit.entity.DragonFireball) DamagingProjectileEntity(net.minecraft.entity.projectile.DamagingProjectileEntity) LlamaSpitEntity(net.minecraft.entity.projectile.LlamaSpitEntity) Trident(org.bukkit.entity.Trident) SmallFireball(org.bukkit.entity.SmallFireball) SnowballEntity(net.minecraft.entity.projectile.SnowballEntity) CraftWorld(org.bukkit.craftbukkit.v1_16_R3.CraftWorld) Vector(org.bukkit.util.Vector) FishingBobberEntity(net.minecraft.entity.projectile.FishingBobberEntity) FishHook(org.bukkit.entity.FishHook) DragonFireballEntity(net.minecraft.entity.projectile.DragonFireballEntity) Egg(org.bukkit.entity.Egg) ShulkerBulletEntity(net.minecraft.entity.projectile.ShulkerBulletEntity) PotionEntity(net.minecraft.entity.projectile.PotionEntity) WitherSkullEntity(net.minecraft.entity.projectile.WitherSkullEntity) ThrownExpBottle(org.bukkit.entity.ThrownExpBottle) ExperienceBottleEntity(net.minecraft.entity.item.ExperienceBottleEntity) TridentEntity(net.minecraft.entity.projectile.TridentEntity) ItemStack(org.bukkit.inventory.ItemStack) CraftItemStack(org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack) AbstractArrow(org.bukkit.entity.AbstractArrow) Location(org.bukkit.Location) FireballEntity(net.minecraft.entity.projectile.FireballEntity) SmallFireballEntity(net.minecraft.entity.projectile.SmallFireballEntity) DragonFireballEntity(net.minecraft.entity.projectile.DragonFireballEntity)

Example 3 with SnowballEntity

use of net.minecraft.entity.projectile.SnowballEntity in project LoliServer by Loli-Server.

the class CraftLivingEntity method launchProjectile.

@Override
@SuppressWarnings("unchecked")
public <T extends Projectile> T launchProjectile(Class<? extends T> projectile, Vector velocity) {
    net.minecraft.world.World world = ((CraftWorld) getWorld()).getHandle();
    net.minecraft.entity.Entity launch = null;
    if (Snowball.class.isAssignableFrom(projectile)) {
        launch = new SnowballEntity(world, getHandle());
        // ItemSnowball
        ((ThrowableEntity) launch).shootFromRotation(getHandle(), getHandle().xRot, getHandle().yRot, 0.0F, 1.5F, 1.0F);
    } else if (Egg.class.isAssignableFrom(projectile)) {
        launch = new EggEntity(world, getHandle());
        // ItemEgg
        ((ThrowableEntity) launch).shootFromRotation(getHandle(), getHandle().xRot, getHandle().yRot, 0.0F, 1.5F, 1.0F);
    } else if (EnderPearl.class.isAssignableFrom(projectile)) {
        launch = new EnderPearlEntity(world, getHandle());
        // EnderPearlItem
        ((ThrowableEntity) launch).shootFromRotation(getHandle(), getHandle().xRot, getHandle().yRot, 0.0F, 1.5F, 1.0F);
    } else if (AbstractArrow.class.isAssignableFrom(projectile)) {
        if (TippedArrow.class.isAssignableFrom(projectile)) {
            launch = new ArrowEntity(world, getHandle());
            ((ArrowEntity) launch).setType(CraftPotionUtil.fromBukkit(new PotionData(PotionType.WATER, false, false)));
        } else if (SpectralArrow.class.isAssignableFrom(projectile)) {
            launch = new SpectralArrowEntity(world, getHandle());
        } else if (Trident.class.isAssignableFrom(projectile)) {
            launch = new TridentEntity(world, getHandle(), new net.minecraft.item.ItemStack(net.minecraft.item.Items.TRIDENT));
        } else {
            launch = new ArrowEntity(world, getHandle());
        }
        // ItemBow
        ((AbstractArrowEntity) launch).shootFromRotation(getHandle(), getHandle().xRot, getHandle().yRot, 0.0F, 3.0F, 1.0F);
    } else if (ThrownPotion.class.isAssignableFrom(projectile)) {
        if (LingeringPotion.class.isAssignableFrom(projectile)) {
            launch = new PotionEntity(world, getHandle());
            ((PotionEntity) launch).setItem(CraftItemStack.asNMSCopy(new ItemStack(org.bukkit.Material.LINGERING_POTION, 1)));
        } else {
            launch = new PotionEntity(world, getHandle());
            ((PotionEntity) launch).setItem(CraftItemStack.asNMSCopy(new ItemStack(org.bukkit.Material.SPLASH_POTION, 1)));
        }
        // SplashPotionItem
        ((ThrowableEntity) launch).shootFromRotation(getHandle(), getHandle().xRot, getHandle().yRot, -20.0F, 0.5F, 1.0F);
    } else if (ThrownExpBottle.class.isAssignableFrom(projectile)) {
        launch = new ExperienceBottleEntity(world, getHandle());
        // ExperienceBottleItem
        ((ThrowableEntity) launch).shootFromRotation(getHandle(), getHandle().xRot, getHandle().yRot, -20.0F, 0.7F, 1.0F);
    } else if (FishHook.class.isAssignableFrom(projectile) && getHandle() instanceof PlayerEntity) {
        launch = new FishingBobberEntity((PlayerEntity) getHandle(), world, 0, 0);
    } else if (Fireball.class.isAssignableFrom(projectile)) {
        Location location = getEyeLocation();
        Vector direction = location.getDirection().multiply(10);
        if (SmallFireball.class.isAssignableFrom(projectile)) {
            launch = new SmallFireballEntity(world, getHandle(), direction.getX(), direction.getY(), direction.getZ());
        } else if (WitherSkull.class.isAssignableFrom(projectile)) {
            launch = new WitherSkullEntity(world, getHandle(), direction.getX(), direction.getY(), direction.getZ());
        } else if (DragonFireball.class.isAssignableFrom(projectile)) {
            launch = new DragonFireballEntity(world, getHandle(), direction.getX(), direction.getY(), direction.getZ());
        } else {
            launch = new FireballEntity(world, getHandle(), direction.getX(), direction.getY(), direction.getZ());
        }
        ((DamagingProjectileEntity) launch).projectileSource = this;
        launch.moveTo(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
    } else if (LlamaSpit.class.isAssignableFrom(projectile)) {
        Location location = getEyeLocation();
        Vector direction = location.getDirection();
        launch = net.minecraft.entity.EntityType.LLAMA_SPIT.create(world);
        ((LlamaSpitEntity) launch).setOwner(getHandle());
        // LlamaEntity
        ((LlamaSpitEntity) launch).shoot(direction.getX(), direction.getY(), direction.getZ(), 1.5F, 10.0F);
        launch.moveTo(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
    } else if (ShulkerBullet.class.isAssignableFrom(projectile)) {
        Location location = getEyeLocation();
        launch = new ShulkerBulletEntity(world, getHandle(), null, null);
        launch.moveTo(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
    } else if (Firework.class.isAssignableFrom(projectile)) {
        Location location = getEyeLocation();
        launch = new FireworkRocketEntity(world, net.minecraft.item.ItemStack.EMPTY, getHandle());
        launch.moveTo(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.addFreshEntity(launch);
    return (T) launch.getBukkitEntity();
}
Also used : ArrowEntity(net.minecraft.entity.projectile.ArrowEntity) AbstractArrowEntity(net.minecraft.entity.projectile.AbstractArrowEntity) SpectralArrowEntity(net.minecraft.entity.projectile.SpectralArrowEntity) SmallFireballEntity(net.minecraft.entity.projectile.SmallFireballEntity) ThrowableEntity(net.minecraft.entity.projectile.ThrowableEntity) EggEntity(net.minecraft.entity.projectile.EggEntity) SpectralArrowEntity(net.minecraft.entity.projectile.SpectralArrowEntity) FireworkRocketEntity(net.minecraft.entity.projectile.FireworkRocketEntity) ShulkerBullet(org.bukkit.entity.ShulkerBullet) PlayerEntity(net.minecraft.entity.player.PlayerEntity) EnderPearlEntity(net.minecraft.entity.item.EnderPearlEntity) PotionData(org.bukkit.potion.PotionData) DragonFireball(org.bukkit.entity.DragonFireball) Fireball(org.bukkit.entity.Fireball) SmallFireball(org.bukkit.entity.SmallFireball) TippedArrow(org.bukkit.entity.TippedArrow) DragonFireball(org.bukkit.entity.DragonFireball) DamagingProjectileEntity(net.minecraft.entity.projectile.DamagingProjectileEntity) LlamaSpitEntity(net.minecraft.entity.projectile.LlamaSpitEntity) Trident(org.bukkit.entity.Trident) SmallFireball(org.bukkit.entity.SmallFireball) SnowballEntity(net.minecraft.entity.projectile.SnowballEntity) CraftWorld(org.bukkit.craftbukkit.v1_16_R3.CraftWorld) Vector(org.bukkit.util.Vector) FishingBobberEntity(net.minecraft.entity.projectile.FishingBobberEntity) FishHook(org.bukkit.entity.FishHook) DragonFireballEntity(net.minecraft.entity.projectile.DragonFireballEntity) Egg(org.bukkit.entity.Egg) ShulkerBulletEntity(net.minecraft.entity.projectile.ShulkerBulletEntity) PotionEntity(net.minecraft.entity.projectile.PotionEntity) WitherSkullEntity(net.minecraft.entity.projectile.WitherSkullEntity) ThrownExpBottle(org.bukkit.entity.ThrownExpBottle) ExperienceBottleEntity(net.minecraft.entity.item.ExperienceBottleEntity) TridentEntity(net.minecraft.entity.projectile.TridentEntity) ItemStack(org.bukkit.inventory.ItemStack) CraftItemStack(org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack) AbstractArrow(org.bukkit.entity.AbstractArrow) Location(org.bukkit.Location) FireballEntity(net.minecraft.entity.projectile.FireballEntity) SmallFireballEntity(net.minecraft.entity.projectile.SmallFireballEntity) DragonFireballEntity(net.minecraft.entity.projectile.DragonFireballEntity)

Example 4 with SnowballEntity

use of net.minecraft.entity.projectile.SnowballEntity in project Magma-1.16.x by magmafoundation.

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 DispenserBlock.dispense()
    ProxyBlockSource isourceblock = new ProxyBlockSource(dispenserBlock.getLevel().getMinecraftWorld(), dispenserBlock.getBlockPos());
    // Copied from DispenseTaskProjectile
    IPosition iposition = DispenserBlock.getDispensePosition(isourceblock);
    Direction enumdirection = (Direction) isourceblock.getBlockState().getValue(DispenserBlock.FACING);
    net.minecraft.world.World world = dispenserBlock.getLevel();
    net.minecraft.entity.Entity launch = null;
    if (Snowball.class.isAssignableFrom(projectile)) {
        launch = new SnowballEntity(world, iposition.x(), iposition.y(), iposition.z());
    } else if (Egg.class.isAssignableFrom(projectile)) {
        launch = new EggEntity(world, iposition.x(), iposition.y(), iposition.z());
    } else if (EnderPearl.class.isAssignableFrom(projectile)) {
        launch = new EnderPearlEntity(world, null);
        launch.setPos(iposition.x(), iposition.y(), iposition.z());
    } else if (ThrownExpBottle.class.isAssignableFrom(projectile)) {
        launch = new ExperienceBottleEntity(world, iposition.x(), iposition.y(), iposition.z());
    } else if (ThrownPotion.class.isAssignableFrom(projectile)) {
        if (LingeringPotion.class.isAssignableFrom(projectile)) {
            launch = new PotionEntity(world, iposition.x(), iposition.y(), iposition.z());
            ((PotionEntity) launch).setItem(CraftItemStack.asNMSCopy(new ItemStack(org.bukkit.Material.LINGERING_POTION, 1)));
        } else {
            launch = new PotionEntity(world, iposition.x(), iposition.y(), iposition.z());
            ((PotionEntity) launch).setItem(CraftItemStack.asNMSCopy(new ItemStack(org.bukkit.Material.SPLASH_POTION, 1)));
        }
    } else if (AbstractArrow.class.isAssignableFrom(projectile)) {
        if (TippedArrow.class.isAssignableFrom(projectile)) {
            launch = new ArrowEntity(world, iposition.x(), iposition.y(), iposition.z());
            ((ArrowEntity) launch).setType(CraftPotionUtil.fromBukkit(new PotionData(PotionType.WATER, false, false)));
        } else if (SpectralArrow.class.isAssignableFrom(projectile)) {
            launch = new SpectralArrowEntity(world, iposition.x(), iposition.y(), iposition.z());
        } else {
            launch = new ArrowEntity(world, iposition.x(), iposition.y(), iposition.z());
        }
        ((AbstractArrowEntity) launch).pickup = AbstractArrowEntity.PickupStatus.ALLOWED;
        ((AbstractArrowEntity) launch).projectileSource = this;
    } else if (Fireball.class.isAssignableFrom(projectile)) {
        double d0 = iposition.x() + (double) ((float) enumdirection.getStepX() * 0.3F);
        double d1 = iposition.y() + (double) ((float) enumdirection.getStepY() * 0.3F);
        double d2 = iposition.z() + (double) ((float) enumdirection.getStepZ() * 0.3F);
        Random random = world.random;
        double d3 = random.nextGaussian() * 0.05D + (double) enumdirection.getStepX();
        double d4 = random.nextGaussian() * 0.05D + (double) enumdirection.getStepY();
        double d5 = random.nextGaussian() * 0.05D + (double) enumdirection.getStepZ();
        if (SmallFireball.class.isAssignableFrom(projectile)) {
            launch = new SmallFireballEntity(world, null, d0, d1, d2);
        } else if (WitherSkull.class.isAssignableFrom(projectile)) {
            launch = EntityType.WITHER_SKULL.create(world);
            launch.setPos(d0, d1, d2);
            double d6 = (double) MathHelper.sqrt(d3 * d3 + d4 * d4 + d5 * d5);
            ((DamagingProjectileEntity) launch).xPower = d3 / d6 * 0.1D;
            ((DamagingProjectileEntity) launch).yPower = d4 / d6 * 0.1D;
            ((DamagingProjectileEntity) launch).zPower = d5 / d6 * 0.1D;
        } else {
            launch = EntityType.FIREBALL.create(world);
            launch.setPos(d0, d1, d2);
            double d6 = (double) MathHelper.sqrt(d3 * d3 + d4 * d4 + d5 * d5);
            ((DamagingProjectileEntity) launch).xPower = d3 / d6 * 0.1D;
            ((DamagingProjectileEntity) launch).yPower = d4 / d6 * 0.1D;
            ((DamagingProjectileEntity) launch).zPower = d5 / d6 * 0.1D;
        }
        ((DamagingProjectileEntity) launch).projectileSource = this;
    }
    Validate.notNull(launch, "Projectile not supported");
    if (launch instanceof ProjectileEntity) {
        if (launch instanceof ThrowableEntity) {
            ((ThrowableEntity) launch).projectileSource = this;
        }
        // Values from DispenseTaskProjectile
        float a = 6.0F;
        float b = 1.1F;
        if (launch instanceof PotionEntity || launch instanceof ThrownExpBottle) {
            // Values from respective DispenseTask classes
            a *= 0.5F;
            b *= 1.25F;
        }
        // Copied from DispenseTaskProjectile
        ((ProjectileEntity) launch).shoot((double) enumdirection.getStepX(), (double) ((float) enumdirection.getStepY() + 0.1F), (double) enumdirection.getStepZ(), b, a);
    }
    if (velocity != null) {
        ((T) launch.getBukkitEntity()).setVelocity(velocity);
    }
    world.addFreshEntity(launch);
    return (T) launch.getBukkitEntity();
}
Also used : SpectralArrowEntity(net.minecraft.entity.projectile.SpectralArrowEntity) ArrowEntity(net.minecraft.entity.projectile.ArrowEntity) AbstractArrowEntity(net.minecraft.entity.projectile.AbstractArrowEntity) SmallFireballEntity(net.minecraft.entity.projectile.SmallFireballEntity) EggEntity(net.minecraft.entity.projectile.EggEntity) SpectralArrowEntity(net.minecraft.entity.projectile.SpectralArrowEntity) ThrowableEntity(net.minecraft.entity.projectile.ThrowableEntity) Direction(net.minecraft.util.Direction) EnderPearlEntity(net.minecraft.entity.item.EnderPearlEntity) PotionData(org.bukkit.potion.PotionData) TippedArrow(org.bukkit.entity.TippedArrow) Random(java.util.Random) DamagingProjectileEntity(net.minecraft.entity.projectile.DamagingProjectileEntity) SnowballEntity(net.minecraft.entity.projectile.SnowballEntity) DamagingProjectileEntity(net.minecraft.entity.projectile.DamagingProjectileEntity) ProjectileEntity(net.minecraft.entity.projectile.ProjectileEntity) IPosition(net.minecraft.dispenser.IPosition) ProxyBlockSource(net.minecraft.dispenser.ProxyBlockSource) Egg(org.bukkit.entity.Egg) PotionEntity(net.minecraft.entity.projectile.PotionEntity) ThrownExpBottle(org.bukkit.entity.ThrownExpBottle) ExperienceBottleEntity(net.minecraft.entity.item.ExperienceBottleEntity) CraftItemStack(org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack) ItemStack(org.bukkit.inventory.ItemStack) WitherSkull(org.bukkit.entity.WitherSkull) AbstractArrow(org.bukkit.entity.AbstractArrow) AbstractArrowEntity(net.minecraft.entity.projectile.AbstractArrowEntity)

Example 5 with SnowballEntity

use of net.minecraft.entity.projectile.SnowballEntity in project LoliServer by Loli-Server.

the class CraftWorld method createEntity.

@SuppressWarnings("unchecked")
public net.minecraft.entity.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.entity.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 BoatEntity(world, x, y, z);
        entity.moveTo(x, y, z, yaw, pitch);
    } else if (FallingBlock.class.isAssignableFrom(clazz)) {
        entity = new FallingBlockEntity(world, x, y, z, world.getBlockState(new BlockPos(x, y, z)));
    } else if (Projectile.class.isAssignableFrom(clazz)) {
        if (Snowball.class.isAssignableFrom(clazz)) {
            entity = new SnowballEntity(world, x, y, z);
        } else if (Egg.class.isAssignableFrom(clazz)) {
            entity = new EggEntity(world, x, y, z);
        } else if (AbstractArrow.class.isAssignableFrom(clazz)) {
            if (TippedArrow.class.isAssignableFrom(clazz)) {
                entity = net.minecraft.entity.EntityType.ARROW.create(world);
                ((ArrowEntity) entity).setType(CraftPotionUtil.fromBukkit(new PotionData(PotionType.WATER, false, false)));
            } else if (SpectralArrow.class.isAssignableFrom(clazz)) {
                entity = net.minecraft.entity.EntityType.SPECTRAL_ARROW.create(world);
            } else if (Trident.class.isAssignableFrom(clazz)) {
                entity = net.minecraft.entity.EntityType.TRIDENT.create(world);
            } else {
                entity = net.minecraft.entity.EntityType.ARROW.create(world);
            }
            entity.moveTo(x, y, z, 0, 0);
        } else if (ThrownExpBottle.class.isAssignableFrom(clazz)) {
            entity = net.minecraft.entity.EntityType.EXPERIENCE_BOTTLE.create(world);
            entity.moveTo(x, y, z, 0, 0);
        } else if (EnderPearl.class.isAssignableFrom(clazz)) {
            entity = net.minecraft.entity.EntityType.ENDER_PEARL.create(world);
            entity.moveTo(x, y, z, 0, 0);
        } else if (ThrownPotion.class.isAssignableFrom(clazz)) {
            if (LingeringPotion.class.isAssignableFrom(clazz)) {
                entity = new PotionEntity(world, x, y, z);
                ((PotionEntity) entity).setItem(CraftItemStack.asNMSCopy(new ItemStack(org.bukkit.Material.LINGERING_POTION, 1)));
            } else {
                entity = new PotionEntity(world, x, y, z);
                ((PotionEntity) entity).setItem(CraftItemStack.asNMSCopy(new ItemStack(org.bukkit.Material.SPLASH_POTION, 1)));
            }
        } else if (Fireball.class.isAssignableFrom(clazz)) {
            if (SmallFireball.class.isAssignableFrom(clazz)) {
                entity = net.minecraft.entity.EntityType.SMALL_FIREBALL.create(world);
            } else if (WitherSkull.class.isAssignableFrom(clazz)) {
                entity = net.minecraft.entity.EntityType.WITHER_SKULL.create(world);
            } else if (DragonFireball.class.isAssignableFrom(clazz)) {
                entity = net.minecraft.entity.EntityType.DRAGON_FIREBALL.create(world);
            } else {
                entity = net.minecraft.entity.EntityType.FIREBALL.create(world);
            }
            entity.moveTo(x, y, z, yaw, pitch);
            Vector direction = location.getDirection().multiply(10);
            ((DamagingProjectileEntity) entity).setDirection(direction.getX(), direction.getY(), direction.getZ());
        } else if (ShulkerBullet.class.isAssignableFrom(clazz)) {
            entity = net.minecraft.entity.EntityType.SHULKER_BULLET.create(world);
            entity.moveTo(x, y, z, yaw, pitch);
        } else if (LlamaSpit.class.isAssignableFrom(clazz)) {
            entity = net.minecraft.entity.EntityType.LLAMA_SPIT.create(world);
            entity.moveTo(x, y, z, yaw, pitch);
        } else if (Firework.class.isAssignableFrom(clazz)) {
            entity = new FireworkRocketEntity(world, x, y, z, net.minecraft.item.ItemStack.EMPTY);
        }
    } else if (Minecart.class.isAssignableFrom(clazz)) {
        if (PoweredMinecart.class.isAssignableFrom(clazz)) {
            entity = new FurnaceMinecartEntity(world, x, y, z);
        } else if (StorageMinecart.class.isAssignableFrom(clazz)) {
            entity = new ChestMinecartEntity(world, x, y, z);
        } else if (ExplosiveMinecart.class.isAssignableFrom(clazz)) {
            entity = new TNTMinecartEntity(world, x, y, z);
        } else if (HopperMinecart.class.isAssignableFrom(clazz)) {
            entity = new HopperMinecartEntity(world, x, y, z);
        } else if (SpawnerMinecart.class.isAssignableFrom(clazz)) {
            entity = new SpawnerMinecartEntity(world, x, y, z);
        } else if (CommandMinecart.class.isAssignableFrom(clazz)) {
            entity = new MinecartEntity(world, x, y, z);
        } else {
            // Default to rideable minecart for pre-rideable compatibility
            entity = new MinecartEntity(world, x, y, z);
        }
    } else if (EnderSignal.class.isAssignableFrom(clazz)) {
        entity = new EyeOfEnderEntity(world, x, y, z);
    } else if (EnderCrystal.class.isAssignableFrom(clazz)) {
        entity = net.minecraft.entity.EntityType.END_CRYSTAL.create(world);
        entity.moveTo(x, y, z, 0, 0);
    } else if (LivingEntity.class.isAssignableFrom(clazz)) {
        if (Chicken.class.isAssignableFrom(clazz)) {
            entity = net.minecraft.entity.EntityType.CHICKEN.create(world);
        } else if (Cow.class.isAssignableFrom(clazz)) {
            if (MushroomCow.class.isAssignableFrom(clazz)) {
                entity = net.minecraft.entity.EntityType.MOOSHROOM.create(world);
            } else {
                entity = net.minecraft.entity.EntityType.COW.create(world);
            }
        } else if (Golem.class.isAssignableFrom(clazz)) {
            if (Snowman.class.isAssignableFrom(clazz)) {
                entity = net.minecraft.entity.EntityType.SNOW_GOLEM.create(world);
            } else if (IronGolem.class.isAssignableFrom(clazz)) {
                entity = net.minecraft.entity.EntityType.IRON_GOLEM.create(world);
            } else if (Shulker.class.isAssignableFrom(clazz)) {
                entity = net.minecraft.entity.EntityType.SHULKER.create(world);
            }
        } else if (Creeper.class.isAssignableFrom(clazz)) {
            entity = net.minecraft.entity.EntityType.CREEPER.create(world);
        } else if (Ghast.class.isAssignableFrom(clazz)) {
            entity = net.minecraft.entity.EntityType.GHAST.create(world);
        } else if (Pig.class.isAssignableFrom(clazz)) {
            entity = net.minecraft.entity.EntityType.PIG.create(world);
        } else if (Player.class.isAssignableFrom(clazz)) {
        // need a net server handler for this one
        } else if (Sheep.class.isAssignableFrom(clazz)) {
            entity = net.minecraft.entity.EntityType.SHEEP.create(world);
        } else if (AbstractHorse.class.isAssignableFrom(clazz)) {
            if (ChestedHorse.class.isAssignableFrom(clazz)) {
                if (Donkey.class.isAssignableFrom(clazz)) {
                    entity = net.minecraft.entity.EntityType.DONKEY.create(world);
                } else if (Mule.class.isAssignableFrom(clazz)) {
                    entity = net.minecraft.entity.EntityType.MULE.create(world);
                } else if (Llama.class.isAssignableFrom(clazz)) {
                    if (TraderLlama.class.isAssignableFrom(clazz)) {
                        entity = net.minecraft.entity.EntityType.TRADER_LLAMA.create(world);
                    } else {
                        entity = net.minecraft.entity.EntityType.LLAMA.create(world);
                    }
                }
            } else if (SkeletonHorse.class.isAssignableFrom(clazz)) {
                entity = net.minecraft.entity.EntityType.SKELETON_HORSE.create(world);
            } else if (ZombieHorse.class.isAssignableFrom(clazz)) {
                entity = net.minecraft.entity.EntityType.ZOMBIE_HORSE.create(world);
            } else {
                entity = net.minecraft.entity.EntityType.HORSE.create(world);
            }
        } else if (Skeleton.class.isAssignableFrom(clazz)) {
            if (Stray.class.isAssignableFrom(clazz)) {
                entity = net.minecraft.entity.EntityType.STRAY.create(world);
            } else if (WitherSkeleton.class.isAssignableFrom(clazz)) {
                entity = net.minecraft.entity.EntityType.WITHER_SKELETON.create(world);
            } else {
                entity = net.minecraft.entity.EntityType.SKELETON.create(world);
            }
        } else if (Slime.class.isAssignableFrom(clazz)) {
            if (MagmaCube.class.isAssignableFrom(clazz)) {
                entity = net.minecraft.entity.EntityType.MAGMA_CUBE.create(world);
            } else {
                entity = net.minecraft.entity.EntityType.SLIME.create(world);
            }
        } else if (Spider.class.isAssignableFrom(clazz)) {
            if (CaveSpider.class.isAssignableFrom(clazz)) {
                entity = net.minecraft.entity.EntityType.CAVE_SPIDER.create(world);
            } else {
                entity = net.minecraft.entity.EntityType.SPIDER.create(world);
            }
        } else if (Squid.class.isAssignableFrom(clazz)) {
            entity = net.minecraft.entity.EntityType.SQUID.create(world);
        } else if (Tameable.class.isAssignableFrom(clazz)) {
            if (Wolf.class.isAssignableFrom(clazz)) {
                entity = net.minecraft.entity.EntityType.WOLF.create(world);
            } else if (Parrot.class.isAssignableFrom(clazz)) {
                entity = net.minecraft.entity.EntityType.PARROT.create(world);
            } else if (Cat.class.isAssignableFrom(clazz)) {
                entity = net.minecraft.entity.EntityType.CAT.create(world);
            }
        } else if (PigZombie.class.isAssignableFrom(clazz)) {
            entity = net.minecraft.entity.EntityType.ZOMBIFIED_PIGLIN.create(world);
        } else if (Zombie.class.isAssignableFrom(clazz)) {
            if (Husk.class.isAssignableFrom(clazz)) {
                entity = net.minecraft.entity.EntityType.HUSK.create(world);
            } else if (ZombieVillager.class.isAssignableFrom(clazz)) {
                entity = net.minecraft.entity.EntityType.ZOMBIE_VILLAGER.create(world);
            } else if (Drowned.class.isAssignableFrom(clazz)) {
                entity = net.minecraft.entity.EntityType.DROWNED.create(world);
            } else {
                entity = new ZombieEntity(world);
            }
        } else if (Giant.class.isAssignableFrom(clazz)) {
            entity = net.minecraft.entity.EntityType.GIANT.create(world);
        } else if (Silverfish.class.isAssignableFrom(clazz)) {
            entity = net.minecraft.entity.EntityType.SILVERFISH.create(world);
        } else if (Enderman.class.isAssignableFrom(clazz)) {
            entity = net.minecraft.entity.EntityType.ENDERMAN.create(world);
        } else if (Blaze.class.isAssignableFrom(clazz)) {
            entity = net.minecraft.entity.EntityType.BLAZE.create(world);
        } else if (AbstractVillager.class.isAssignableFrom(clazz)) {
            if (Villager.class.isAssignableFrom(clazz)) {
                entity = net.minecraft.entity.EntityType.VILLAGER.create(world);
            } else if (WanderingTrader.class.isAssignableFrom(clazz)) {
                entity = net.minecraft.entity.EntityType.WANDERING_TRADER.create(world);
            }
        } else if (Witch.class.isAssignableFrom(clazz)) {
            entity = net.minecraft.entity.EntityType.WITCH.create(world);
        } else if (Wither.class.isAssignableFrom(clazz)) {
            entity = net.minecraft.entity.EntityType.WITHER.create(world);
        } else if (ComplexLivingEntity.class.isAssignableFrom(clazz)) {
            if (EnderDragon.class.isAssignableFrom(clazz)) {
                entity = net.minecraft.entity.EntityType.ENDER_DRAGON.create(world);
            }
        } else if (Ambient.class.isAssignableFrom(clazz)) {
            if (Bat.class.isAssignableFrom(clazz)) {
                entity = net.minecraft.entity.EntityType.BAT.create(world);
            }
        } else if (Rabbit.class.isAssignableFrom(clazz)) {
            entity = net.minecraft.entity.EntityType.RABBIT.create(world);
        } else if (Endermite.class.isAssignableFrom(clazz)) {
            entity = net.minecraft.entity.EntityType.ENDERMITE.create(world);
        } else if (Guardian.class.isAssignableFrom(clazz)) {
            if (ElderGuardian.class.isAssignableFrom(clazz)) {
                entity = net.minecraft.entity.EntityType.ELDER_GUARDIAN.create(world);
            } else {
                entity = net.minecraft.entity.EntityType.GUARDIAN.create(world);
            }
        } else if (ArmorStand.class.isAssignableFrom(clazz)) {
            entity = new ArmorStandEntity(world, x, y, z);
        } else if (PolarBear.class.isAssignableFrom(clazz)) {
            entity = net.minecraft.entity.EntityType.POLAR_BEAR.create(world);
        } else if (Vex.class.isAssignableFrom(clazz)) {
            entity = net.minecraft.entity.EntityType.VEX.create(world);
        } else if (Illager.class.isAssignableFrom(clazz)) {
            if (Spellcaster.class.isAssignableFrom(clazz)) {
                if (Evoker.class.isAssignableFrom(clazz)) {
                    entity = net.minecraft.entity.EntityType.EVOKER.create(world);
                } else if (Illusioner.class.isAssignableFrom(clazz)) {
                    entity = net.minecraft.entity.EntityType.ILLUSIONER.create(world);
                }
            } else if (Vindicator.class.isAssignableFrom(clazz)) {
                entity = net.minecraft.entity.EntityType.VINDICATOR.create(world);
            } else if (Pillager.class.isAssignableFrom(clazz)) {
                entity = net.minecraft.entity.EntityType.PILLAGER.create(world);
            }
        } else if (Turtle.class.isAssignableFrom(clazz)) {
            entity = net.minecraft.entity.EntityType.TURTLE.create(world);
        } else if (Phantom.class.isAssignableFrom(clazz)) {
            entity = net.minecraft.entity.EntityType.PHANTOM.create(world);
        } else if (Fish.class.isAssignableFrom(clazz)) {
            if (Cod.class.isAssignableFrom(clazz)) {
                entity = net.minecraft.entity.EntityType.COD.create(world);
            } else if (PufferFish.class.isAssignableFrom(clazz)) {
                entity = net.minecraft.entity.EntityType.PUFFERFISH.create(world);
            } else if (Salmon.class.isAssignableFrom(clazz)) {
                entity = net.minecraft.entity.EntityType.SALMON.create(world);
            } else if (TropicalFish.class.isAssignableFrom(clazz)) {
                entity = net.minecraft.entity.EntityType.TROPICAL_FISH.create(world);
            }
        } else if (Dolphin.class.isAssignableFrom(clazz)) {
            entity = net.minecraft.entity.EntityType.DOLPHIN.create(world);
        } else if (Ocelot.class.isAssignableFrom(clazz)) {
            entity = net.minecraft.entity.EntityType.OCELOT.create(world);
        } else if (Ravager.class.isAssignableFrom(clazz)) {
            entity = net.minecraft.entity.EntityType.RAVAGER.create(world);
        } else if (Panda.class.isAssignableFrom(clazz)) {
            entity = net.minecraft.entity.EntityType.PANDA.create(world);
        } else if (Fox.class.isAssignableFrom(clazz)) {
            entity = net.minecraft.entity.EntityType.FOX.create(world);
        } else if (Bee.class.isAssignableFrom(clazz)) {
            entity = net.minecraft.entity.EntityType.BEE.create(world);
        } else if (Hoglin.class.isAssignableFrom(clazz)) {
            entity = net.minecraft.entity.EntityType.HOGLIN.create(world);
        } else if (Piglin.class.isAssignableFrom(clazz)) {
            entity = net.minecraft.entity.EntityType.PIGLIN.create(world);
        } else if (PiglinBrute.class.isAssignableFrom(clazz)) {
            entity = net.minecraft.entity.EntityType.PIGLIN_BRUTE.create(world);
        } else if (Strider.class.isAssignableFrom(clazz)) {
            entity = net.minecraft.entity.EntityType.STRIDER.create(world);
        } else if (Zoglin.class.isAssignableFrom(clazz)) {
            entity = net.minecraft.entity.EntityType.ZOGLIN.create(world);
        }
        if (entity != null) {
            entity.absMoveTo(x, y, z, yaw, pitch);
            // SPIGOT-3587
            entity.setYHeadRot(yaw);
        }
    } else if (Hanging.class.isAssignableFrom(clazz)) {
        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;
        }
        // Paper start - In addition to d65a2576e40e58c8e446b330febe6799d13a604f do not check UP/DOWN for non item frames
        // BlockFace[] faces = new BlockFace[]{BlockFace.EAST, BlockFace.NORTH, BlockFace.WEST, BlockFace.SOUTH, BlockFace.UP, BlockFace.DOWN};
        BlockFace[] faces = (ItemFrame.class.isAssignableFrom(clazz)) ? new BlockFace[] { BlockFace.EAST, BlockFace.NORTH, BlockFace.WEST, BlockFace.SOUTH, BlockFace.UP, BlockFace.DOWN } : new BlockFace[] { BlockFace.EAST, BlockFace.NORTH, BlockFace.WEST, BlockFace.SOUTH };
        // Paper end
        final BlockPos pos = new BlockPos(x, y, z);
        for (BlockFace dir : faces) {
            net.minecraft.block.BlockState nmsBlock = world.getBlockState(pos.relative(CraftBlock.blockFaceToNotch(dir)));
            if (nmsBlock.getMaterial().isSolid() || RedstoneDiodeBlock.isDiode(nmsBlock)) {
                boolean taken = false;
                AxisAlignedBB bb = (ItemFrame.class.isAssignableFrom(clazz)) ? ItemFrameEntity.calculateBoundingBox(null, pos, CraftBlock.blockFaceToNotch(dir).getOpposite(), width, height) : HangingEntity.calculateBoundingBox(null, pos, CraftBlock.blockFaceToNotch(dir).getOpposite(), width, height);
                List<net.minecraft.entity.Entity> list = (List<net.minecraft.entity.Entity>) world.getEntities(null, bb);
                for (Iterator<net.minecraft.entity.Entity> it = list.iterator(); !taken && it.hasNext(); ) {
                    net.minecraft.entity.Entity e = it.next();
                    if (e instanceof HangingEntity) {
                        // Hanging entities do not like hanging entities which intersect them.
                        taken = true;
                    }
                }
                if (!taken) {
                    face = dir;
                    break;
                }
            }
        }
        if (LeashHitch.class.isAssignableFrom(clazz)) {
            entity = new LeashKnotEntity(world, new BlockPos(x, y, z));
            entity.forcedLoading = 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);
            Direction dir = CraftBlock.blockFaceToNotch(face).getOpposite();
            if (Painting.class.isAssignableFrom(clazz)) {
                entity = new PaintingEntity(world, new BlockPos(x, y, z), dir);
            } else if (ItemFrame.class.isAssignableFrom(clazz)) {
                entity = new ItemFrameEntity(world, new BlockPos(x, y, z), dir);
            }
        }
        if (entity != null && !((HangingEntity) entity).survives()) {
            throw new IllegalArgumentException("Cannot spawn hanging entity for " + clazz.getName() + " at " + location);
        }
    } else if (TNTPrimed.class.isAssignableFrom(clazz)) {
        entity = new TNTEntity(world, x, y, z, null);
    } else if (ExperienceOrb.class.isAssignableFrom(clazz)) {
        entity = new ExperienceOrbEntity(world, x, y, z, 0);
    } else if (LightningStrike.class.isAssignableFrom(clazz)) {
        entity = net.minecraft.entity.EntityType.LIGHTNING_BOLT.create(world);
    } else if (AreaEffectCloud.class.isAssignableFrom(clazz)) {
        entity = new AreaEffectCloudEntity(world, x, y, z);
    } else if (EvokerFangs.class.isAssignableFrom(clazz)) {
        entity = new EvokerFangsEntity(world, x, y, z, (float) Math.toRadians(yaw), 0, null);
    }
    if (entity != null) {
        return entity;
    }
    throw new IllegalArgumentException("Cannot spawn an entity for " + clazz.getName());
}
Also used : SnowballEntity(net.minecraft.entity.projectile.SnowballEntity) Entity(org.bukkit.entity.Entity) DamagingProjectileEntity(net.minecraft.entity.projectile.DamagingProjectileEntity) ChestMinecartEntity(net.minecraft.entity.item.minecart.ChestMinecartEntity) MinecartEntity(net.minecraft.entity.item.minecart.MinecartEntity) AbstractArrowEntity(net.minecraft.entity.projectile.AbstractArrowEntity) LivingEntity(org.bukkit.entity.LivingEntity) ExperienceOrbEntity(net.minecraft.entity.item.ExperienceOrbEntity) ItemFrameEntity(net.minecraft.entity.item.ItemFrameEntity) HangingEntity(net.minecraft.entity.item.HangingEntity) AreaEffectCloudEntity(net.minecraft.entity.AreaEffectCloudEntity) LeashKnotEntity(net.minecraft.entity.item.LeashKnotEntity) SpawnerMinecartEntity(net.minecraft.entity.item.minecart.SpawnerMinecartEntity) PaintingEntity(net.minecraft.entity.item.PaintingEntity) ArrowEntity(net.minecraft.entity.projectile.ArrowEntity) PotionEntity(net.minecraft.entity.projectile.PotionEntity) FallingBlockEntity(net.minecraft.entity.item.FallingBlockEntity) TNTMinecartEntity(net.minecraft.entity.item.minecart.TNTMinecartEntity) EvokerFangsEntity(net.minecraft.entity.projectile.EvokerFangsEntity) TNTEntity(net.minecraft.entity.item.TNTEntity) HopperMinecartEntity(net.minecraft.entity.item.minecart.HopperMinecartEntity) FurnaceMinecartEntity(net.minecraft.entity.item.minecart.FurnaceMinecartEntity) EyeOfEnderEntity(net.minecraft.entity.projectile.EyeOfEnderEntity) TileEntity(net.minecraft.tileentity.TileEntity) ZombieEntity(net.minecraft.entity.monster.ZombieEntity) ArmorStandEntity(net.minecraft.entity.item.ArmorStandEntity) CraftEntity(org.bukkit.craftbukkit.v1_16_R3.entity.CraftEntity) BoatEntity(net.minecraft.entity.item.BoatEntity) EggEntity(net.minecraft.entity.projectile.EggEntity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) FireworkRocketEntity(net.minecraft.entity.projectile.FireworkRocketEntity) LightningBoltEntity(net.minecraft.entity.effect.LightningBoltEntity) ComplexLivingEntity(org.bukkit.entity.ComplexLivingEntity) MobEntity(net.minecraft.entity.MobEntity) HumanEntity(org.bukkit.entity.HumanEntity) ItemEntity(net.minecraft.entity.item.ItemEntity) TNTEntity(net.minecraft.entity.item.TNTEntity) Dolphin(org.bukkit.entity.Dolphin) BlockFace(org.bukkit.block.BlockFace) FireworkRocketEntity(net.minecraft.entity.projectile.FireworkRocketEntity) EnderDragon(org.bukkit.entity.EnderDragon) Phantom(org.bukkit.entity.Phantom) ThrownPotion(org.bukkit.entity.ThrownPotion) ElderGuardian(org.bukkit.entity.ElderGuardian) Guardian(org.bukkit.entity.Guardian) Pillager(org.bukkit.entity.Pillager) SnowballEntity(net.minecraft.entity.projectile.SnowballEntity) Vector(org.bukkit.util.Vector) BoatEntity(net.minecraft.entity.item.BoatEntity) MushroomCow(org.bukkit.entity.MushroomCow) ChestMinecartEntity(net.minecraft.entity.item.minecart.ChestMinecartEntity) MinecartEntity(net.minecraft.entity.item.minecart.MinecartEntity) SpawnerMinecartEntity(net.minecraft.entity.item.minecart.SpawnerMinecartEntity) TNTMinecartEntity(net.minecraft.entity.item.minecart.TNTMinecartEntity) HopperMinecartEntity(net.minecraft.entity.item.minecart.HopperMinecartEntity) FurnaceMinecartEntity(net.minecraft.entity.item.minecart.FurnaceMinecartEntity) ElderGuardian(org.bukkit.entity.ElderGuardian) LingeringPotion(org.bukkit.entity.LingeringPotion) Ravager(org.bukkit.entity.Ravager) ChestMinecartEntity(net.minecraft.entity.item.minecart.ChestMinecartEntity) PaintingEntity(net.minecraft.entity.item.PaintingEntity) ItemFrameEntity(net.minecraft.entity.item.ItemFrameEntity) CaveSpider(org.bukkit.entity.CaveSpider) Firework(org.bukkit.entity.Firework) AreaEffectCloudEntity(net.minecraft.entity.AreaEffectCloudEntity) ItemStack(org.bukkit.inventory.ItemStack) CraftItemStack(org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack) ExplosiveMinecart(org.bukkit.entity.minecart.ExplosiveMinecart) Rabbit(org.bukkit.entity.Rabbit) IronGolem(org.bukkit.entity.IronGolem) LeashKnotEntity(net.minecraft.entity.item.LeashKnotEntity) ShulkerBullet(org.bukkit.entity.ShulkerBullet) Illager(org.bukkit.entity.Illager) Direction(net.minecraft.util.Direction) TNTMinecartEntity(net.minecraft.entity.item.minecart.TNTMinecartEntity) PotionData(org.bukkit.potion.PotionData) TropicalFish(org.bukkit.entity.TropicalFish) DamagingProjectileEntity(net.minecraft.entity.projectile.DamagingProjectileEntity) Hoglin(org.bukkit.entity.Hoglin) Wolf(org.bukkit.entity.Wolf) Witch(org.bukkit.entity.Witch) HangingEntity(net.minecraft.entity.item.HangingEntity) Tameable(org.bukkit.entity.Tameable) Mule(org.bukkit.entity.Mule) Husk(org.bukkit.entity.Husk) MushroomCow(org.bukkit.entity.MushroomCow) Cow(org.bukkit.entity.Cow) ExperienceOrb(org.bukkit.entity.ExperienceOrb) AreaEffectCloud(org.bukkit.entity.AreaEffectCloud) Pig(org.bukkit.entity.Pig) Blaze(org.bukkit.entity.Blaze) WitherSkull(org.bukkit.entity.WitherSkull) Zoglin(org.bukkit.entity.Zoglin) ZombieEntity(net.minecraft.entity.monster.ZombieEntity) EggEntity(net.minecraft.entity.projectile.EggEntity) ExplosiveMinecart(org.bukkit.entity.minecart.ExplosiveMinecart) PoweredMinecart(org.bukkit.entity.minecart.PoweredMinecart) CommandMinecart(org.bukkit.entity.minecart.CommandMinecart) SpawnerMinecart(org.bukkit.entity.minecart.SpawnerMinecart) StorageMinecart(org.bukkit.entity.minecart.StorageMinecart) HopperMinecart(org.bukkit.entity.minecart.HopperMinecart) Minecart(org.bukkit.entity.Minecart) SpectralArrow(org.bukkit.entity.SpectralArrow) ItemFrame(org.bukkit.entity.ItemFrame) FallingBlock(org.bukkit.entity.FallingBlock) Hanging(org.bukkit.entity.Hanging) HopperMinecartEntity(net.minecraft.entity.item.minecart.HopperMinecartEntity) WanderingTrader(org.bukkit.entity.WanderingTrader) BlockPos(net.minecraft.util.math.BlockPos) ImmutableList(com.google.common.collect.ImmutableList) ArrayList(java.util.ArrayList) List(java.util.List) ArmorStandEntity(net.minecraft.entity.item.ArmorStandEntity) Zombie(org.bukkit.entity.Zombie) PigZombie(org.bukkit.entity.PigZombie) PiglinBrute(org.bukkit.entity.PiglinBrute) EnderCrystal(org.bukkit.entity.EnderCrystal) Evoker(org.bukkit.entity.Evoker) FurnaceMinecartEntity(net.minecraft.entity.item.minecart.FurnaceMinecartEntity) Fox(org.bukkit.entity.Fox) Drowned(org.bukkit.entity.Drowned) PoweredMinecart(org.bukkit.entity.minecart.PoweredMinecart) Cat(org.bukkit.entity.Cat) ThrownExpBottle(org.bukkit.entity.ThrownExpBottle) EvokerFangsEntity(net.minecraft.entity.projectile.EvokerFangsEntity) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Stray(org.bukkit.entity.Stray) AbstractArrowEntity(net.minecraft.entity.projectile.AbstractArrowEntity) ArrowEntity(net.minecraft.entity.projectile.ArrowEntity) Creeper(org.bukkit.entity.Creeper) ComplexLivingEntity(org.bukkit.entity.ComplexLivingEntity) Silverfish(org.bukkit.entity.Silverfish) Spellcaster(org.bukkit.entity.Spellcaster) LeashHitch(org.bukkit.entity.LeashHitch) Iterator(java.util.Iterator) Skeleton(org.bukkit.entity.Skeleton) WitherSkeleton(org.bukkit.entity.WitherSkeleton) SkeletonHorse(org.bukkit.entity.SkeletonHorse) FallingBlockEntity(net.minecraft.entity.item.FallingBlockEntity) PolarBear(org.bukkit.entity.PolarBear) SpawnerMinecart(org.bukkit.entity.minecart.SpawnerMinecart) Egg(org.bukkit.entity.Egg) PufferFish(org.bukkit.entity.PufferFish) EyeOfEnderEntity(net.minecraft.entity.projectile.EyeOfEnderEntity) SpawnerMinecartEntity(net.minecraft.entity.item.minecart.SpawnerMinecartEntity) ExperienceOrbEntity(net.minecraft.entity.item.ExperienceOrbEntity) PotionEntity(net.minecraft.entity.projectile.PotionEntity) Painting(org.bukkit.entity.Painting) CraftBlockState(org.bukkit.craftbukkit.v1_16_R3.block.CraftBlockState) CaveSpider(org.bukkit.entity.CaveSpider) Spider(org.bukkit.entity.Spider) Sheep(org.bukkit.entity.Sheep)

Aggregations

SnowballEntity (net.minecraft.entity.projectile.SnowballEntity)7 AbstractArrowEntity (net.minecraft.entity.projectile.AbstractArrowEntity)6 ArrowEntity (net.minecraft.entity.projectile.ArrowEntity)6 DamagingProjectileEntity (net.minecraft.entity.projectile.DamagingProjectileEntity)6 EggEntity (net.minecraft.entity.projectile.EggEntity)6 PotionEntity (net.minecraft.entity.projectile.PotionEntity)6 CraftItemStack (org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack)6 Egg (org.bukkit.entity.Egg)6 ThrownExpBottle (org.bukkit.entity.ThrownExpBottle)6 ItemStack (org.bukkit.inventory.ItemStack)6 PotionData (org.bukkit.potion.PotionData)6 EnderPearlEntity (net.minecraft.entity.item.EnderPearlEntity)4 ExperienceBottleEntity (net.minecraft.entity.item.ExperienceBottleEntity)4 PlayerEntity (net.minecraft.entity.player.PlayerEntity)4 FireworkRocketEntity (net.minecraft.entity.projectile.FireworkRocketEntity)4 SmallFireballEntity (net.minecraft.entity.projectile.SmallFireballEntity)4 SpectralArrowEntity (net.minecraft.entity.projectile.SpectralArrowEntity)4 ThrowableEntity (net.minecraft.entity.projectile.ThrowableEntity)4 Direction (net.minecraft.util.Direction)4 AbstractArrow (org.bukkit.entity.AbstractArrow)4