NarwhelZhu Posted August 17, 2019 Share Posted August 17, 2019 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(); } } Quote Link to comment Share on other sites More sharing options...
Animefan8888 Posted August 17, 2019 Share Posted August 17, 2019 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. 1 Quote 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 More sharing options...
NarwhelZhu Posted August 17, 2019 Author Share Posted August 17, 2019 This seems to work, thank you very much. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.