Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Best way to go about creating a Monster List


Recommended Posts

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.

Link to post
Share on other sites

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.

Link to post
Share on other sites

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?

Link to post
Share on other sites
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?

Link to post
Share on other sites
Posted (edited)
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 by poopoodice
  • Like 1
Link to post
Share on other sites
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.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.