Jump to content

Can you mark a passive entity for removal?


genandnic

Recommended Posts

Hostile mobs usually despawn once the player moves away from them, typically once they're 128 blocks away. But passive mobs won't despawn, not by default anyway. I want to spawn a cow that will dissapear once unloaded.

 

I thought I could do this by spawning a mob with "PersistenceRequired" set to false, but this doesn't seem to work:

 

			List<ResourceLocation> entities = new ArrayList<ResourceLocation>(EntityList.ENTITY_EGGS.keySet());
			ResourceLocation randomResource = entities.get(rand.nextInt(entities.size()));

			Entity randomEntity = EntityList.createEntityByIDFromName(randomResource, entity.world);
			if (!randomEntity.isNonBoss())
				return;

			NBTTagCompound nbt = new NBTTagCompound();
			nbt.setBoolean("PersistenceRequired", false);
			((EntityLiving) randomEntity).readEntityFromNBT(nbt);

			randomEntity.setPositionAndRotation(entity.posX, entity.posY, entity.posZ, entity.rotationYaw, entity.rotationPitch);
			entity.world.spawnEntity(randomEntity);

			entity.setDead();

 

Edited by genandnic
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.

Announcements



×
×
  • Create New...

Important Information

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