Jump to content

Recommended Posts

Posted

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.

Posted

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?

Posted
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?

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
Posted
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.

  • 3 weeks later...
Posted

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
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.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.