Posted May 5, 20214 yr I was wondering what was the best way to go about making a list of just the monster entities? Essentially, I want to randomly spawn a monster type enemy from a list. After looking through, I saw that monsters had an EntityClassification, but wasn't sure if I could use that to compile a list of just monsters.
May 5, 20214 yr I think you should be able to get all entitytypes from ForgeRegistries.ENTITIES, and then cache them by filtering out the ones with EntityClassification.MONSTER.
May 6, 20214 yr Author Hmm, I see. I've been searching for the spawning the method to spawn an Entity in the overworld too, but I'm not sure how to find that if someone could point me in the right direction?
May 6, 20214 yr Create an instance of the entity (iirc there's a method in EntityType called create() or something), and then add it through world.addEntity.
May 11, 20214 yr Author On 5/5/2021 at 5:41 PM, poopoodice said: Create an instance of the entity (iirc there's a method in EntityType called create() or something), and then add it through world.addEntity. Hmm, any chance you can provide or are aware of an example for how this works?
May 11, 20214 yr List<EntityType<?>> MONSTERS = new ArrayList<>(); void summonRandomMonster() { if (MONSTERS.isEmpty()) MONSTERS.addAll(ForgeRegistries.ENTITIES.getValues().filter((type) -> is type classification monster)) Entity entity = (random EntityType from MONSTERS).create(world); if (entity != null) { entity.setPosition(x, y, z); world.addEntity(entity); } } Edited May 11, 20214 yr by poopoodice
May 15, 20214 yr Author On 5/10/2021 at 7:38 PM, poopoodice said: List<EntityType<?>> MONSTERS = new ArrayList<>(); void summonRandomMonster() { if (MONSTERS.isEmpty()) MONSTERS.addAll(ForgeRegistries.ENTITIES.getValues().filter((type) -> is type classification monster)) Entity entity = (random EntityType from MONSTERS).create(world); if (entity != null) { entity.setPosition(x, y, z); world.addEntity(entity); } } Appreciated, got it working. Just realized I need to filter out the big bosses now as I didn't consider it until the Ender Dragon was spawned, but that is simply just doing another filter over the list.
June 3, 20214 yr Author Just to add on this - if I wanted to add a cooldown to the enemy spawning (since I'm doing the enemy spawning based on an enchantment being on an armor piece) - would it be best to do through NBT on the armor piece for a cooldown?
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.