Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

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.

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.

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

Create an instance of the entity (iirc there's a method in EntityType called create() or something), and then add it through world.addEntity.

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

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

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

  • 3 weeks later...
  • 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.

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.