Posted July 23, 20187 yr 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 July 23, 20187 yr by genandnic
July 23, 20187 yr Author 1 hour ago, diesieben07 said: LivingSpawnEvent.AllowDespawn can be used for this purpose. Thank you, this works perfectly!
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.