1.17.x Help with EntityTypes

Discussion in 'Spigot Plugin Development' started by GamingCuber, Jul 10, 2021.

  1. I'm attempting to spawn an array of Entitytypes with EntityType.values();. However, when I try to spawn this array, it doesn't allow me to as you need specifically EntityType, not EntityType[]. How should I do this.

    Player p = e.getPlayer();
    Location loc = e.getPlayer().getLocation().clone();
    World w = p.getWorld();
    EntityType ET[] = EntityType.values();
    Random rand = new Random();
    int upperbound = ET.length;
    int Random = rand.nextInt(upperbound);
    EntityType NET[] = {EntityType.AREA_EFFECT_CLOUD, EntityType.ARMOR_STAND, EntityType.ARROW, EntityType.BOAT, EntityType.DRAGON_FIREBALL, EntityType.DROPPED_ITEM, EntityType.EGG, EntityType.ENDER_CRYSTAL, EntityType.ENDER_DRAGON, EntityType.ENDER_PEARL, EntityType.ENDER_SIGNAL, EntityType.EVOKER, EntityType.EVOKER_FANGS, EntityType.EXPERIENCE_ORB, EntityType.FALLING_BLOCK, EntityType.FIREBALL, EntityType.FIREWORK, EntityType.FISHING_HOOK, EntityType.GIANT, EntityType.GLOW_ITEM_FRAME, EntityType.HOGLIN, EntityType.ILLUSIONER, EntityType.ITEM_FRAME, EntityType.LEASH_HITCH, EntityType.LIGHTNING, EntityType.LLAMA_SPIT, EntityType.MARKER, EntityType.MINECART, EntityType.MINECART_CHEST, EntityType.MINECART_COMMAND, EntityType.MINECART_FURNACE, EntityType.MINECART_HOPPER, EntityType.MINECART_MOB_SPAWNER, EntityType.MINECART_TNT, EntityType.PAINTING, EntityType.PHANTOM, EntityType.PIGLIN_BRUTE, EntityType.PRIMED_TNT, EntityType.RAVAGER, EntityType.SHULKER_BULLET, EntityType.SMALL_FIREBALL, EntityType.SNOWBALL, EntityType.SPECTRAL_ARROW, EntityType.SPLASH_POTION, EntityType.THROWN_EXP_BOTTLE, EntityType.TRIDENT, EntityType.UNKNOWN, EntityType.VEX, EntityType.VINDICATOR, EntityType.WITHER, EntityType.WITHER_SKULL, EntityType.ZOGLIN};

    while (ET.equals(NET)) {
    return;
    }
    w.spawnEntity(loc, ET);
     
  2. A simple "how to iterate array" google search would lead you to a solution
    Code (Text):
    for(EntityType type : ET) {
        w.spawnEntity(loc, type);
    }
     
    #2 wand555, Jul 11, 2021
    Last edited: Jul 12, 2021
  3. Thanks, I figured it out