Jump to content

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


NarwhelZhu

Recommended Posts

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();
	}
}

 

Link to comment
Share on other sites

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. 

  • Like 1

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.

Link to comment
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.
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.

×
×
  • Create New...

Important Information

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