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.

How to make a custom mob such that only one can naturally spawn in the world at a time?

Featured Replies

Posted

I'm trying to make a mob that will only naturally spawn once in a world at a time until it's either killed or it despawns, but for some reason my code isn't working and I'm not sure why.

 

Here is my code, can someone tell me what I'm doing wrong? There are no errors when I load up the world, but it seems that the world.getLoadedEntityList().contains(this) is always returning false, even when one entity already exists, so more than one can spawn in the world. That tells me I'm using the method wrong, but I'm not sure what else to use or what I'm doing wrong with it.

 

public class EntityRumia extends EntityMob {

	public EntityRumia(World worldIn) {
		super(worldIn);
		this.setSize(0.6F, 1.8F);
	}
	
	@Override
	public boolean getCanSpawnHere() {
		return !world.getLoadedEntityList().contains(this) && super.getCanSpawnHere();
	}
}

 

7 minutes ago, NarwhelZhu said:

world.getLoadedEntityList().contains(this)

Unless you override the equals method checking if a list contains an entity whom we will call instance a when instance b is already there will always return false. You need to iterate through the list of entities and check if one is an instance of your entities class. And if it is say it cant spawn. 

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

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.