Jump to content

[1.8] ¿Entities what happend to entityes when setDead();


perromercenary00

Recommended Posts

 

 

thats the question

 

in mi mod i spawn entities like crazy, every bullet you shoot is an entity, every ghost to launch an action in a gun is an entity.

soo is posible for the game to lag or freeze if it is to many dead() Entities store in the database of whatever is called 

 

or beter said  can I fuckUp a world if not carefull whith the amounts of custome entities Dead() mi mod generates ?

Link to comment
Share on other sites

Each tick,

World#updateEntities

updates any loaded entities that aren't dead and removes any dead entities from the loaded entity list. Once there are no more references to the

Entity

, it should simply be garbage collected.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

soo they are delete

 

lets say i wanna create an entity for the sole proposite of storing data from an item and for some reason i don't wanna use directly the nbt in the item, but the datawacher in the entity,  and ad the same i only want this storingEntity to be alive when the item is held if is not this must remain dead or i gona have a trouble of excess of ghost entityes over the head of the player

 

but in the other hand ? is way to store a whole entitie in an item ? 

Link to comment
Share on other sites

No, trust me that's a terrible way of doing it. You'd be surprised at how terrible minecraft is at unloading entities. Trying to run the finalize command for any entity will instantly cause the game to crash, so it doesn't delete the entity instance from the game. What setDead does it it changes isDead=true , which tells everything in the game from collision to rendering to networking to ignore the entity, but it doesn't delete it from memory.

 

I know this too well because I have some entities that can store megabytes of information, and its extremely annoying that they never get deleted from ram until the chunk is unloaded.

 

Overall setDead doesn't delete anything, it just tells many parts of the game to ignore an entity.

"you seem to be THE best modder I've seen imo."

~spynathan

 

ლ(́◉◞౪◟◉‵ლ

Link to comment
Share on other sites

i du not know wath are fiting for

 

been doing some test and can't not return an entity from dead,

 

i been using entity id coz  there is no method in the world class to call an entity for the uuid aparently thats only for EntityPlayer

 

// ###################################################################################3
fantasmaMercenarioMarkLancer getFantasma(World worldIn,EntityLivingBase entidad, ItemStack pistola) {

	int fantasmaID = util.getInttag(pistola, "fantasmaID");
	String fantasmaUUID = util.getStringtag(pistola, "fantasmaUUID");

	boolean createFantasma = true;

	if ( fantasmaID > 0 ) 
	//if (fantasmaUUID.length() > 0)
	{
		createFantasma = false;

		System.out.println( "\n\nFantasma Conjurado id  =("+fantasmaID+")\n"  );
		System.out.println( "\n\nFantasma Conjurado uuid=("+fantasmaUUID+")\n"  );

		Entity entidad2 = worldIn.getEntityByID(fantasmaID);
		//Entity entidad2 = worldIn.getPlayerEntityByUUID(UUID.fromString(fantasmaUUID));

		if (entidad2 == null)
		{
                                //here it return a pretty java.lang.NullPointerException for the entidad2.isDead 
                                //so it is absolutly null	
		System.out.println( "\nEl Fantasma es Nulo="+entidad2.isDead  );  
			//createFantasma = true;
		}
		else
		{
		System.out.println( "\nEntidad="+entidad2.getName()+"\n");
		}


		/*
		if ( !entidad2.isDead ) {
			System.out.println( "\n00 el Fantasma("+fantasmaID+") esta Vivo"  );
		}
		else 
		{	
			System.out.println( "\n00 el Fantasma("+fantasmaID+") esta Muerto"  );
			entidad2.isDead = false;
		}


		if ( !entidad2.isDead ) {
			System.out.println( "\n01 el Fantasma("+fantasmaID+") esta Vivo"  );
		}

		*/



		if (entidad2 != null) {

			if (entidad2 instanceof fantasmaMercenarioMarkLancer) {

				System.out.println( "\ninstanceof fantasmaMercenarioMarkLancer\n"  );

				if (entidad2.isEntityAlive()) {

					System.out.println( "\n is Alive fantasmaMercenarioMarkLancer\n"  );

					crearFantasma = false;
					return (fantasmaMercenarioMarkLancer)entidad2; 


				}

			}
			else 
			{
				crearFantasma = true;
				System.out.println( "\nla entidad "+fantasmaID+" No Es un fantasma mercenario\n"  );
			}	
		}
		else
		{
			crearFantasma = true;
			System.out.println( "\nla entidad "+fantasmaID+" No existe\n"  );
		}	


	}


	if (crearFantasma){
		return conjurar(worldIn, entidad, pistola);
	}


	return null;

}

// ###################################################################################3
fantasmaMercenarioMarkLancer conjurar(World worldIn, EntityLivingBase shootingEntity, ItemStack pistola) {

fantasmaMercenarioMarkLancer entidad = null;



if (!worldIn.isRemote)
	{
		mercenarymod.entidades.fantasmaMercenarioMarkLancer fantasma = new mercenarymod.entidades.fantasmaMercenarioMarkLancer(worldIn);

		fantasma.setPistola(pistola);
		fantasma.setShootingEntity(shootingEntity);
		// fantasma.setTargetEntity(entidad.getAITarget());

		double x = shootingEntity.posX;
		double y = shootingEntity.posY + shootingEntity.getEyeHeight();
		double z = shootingEntity.posZ;

		float yaw = shootingEntity.rotationYaw; // getRotationYawHead(); rotationYaw;
		float pitch = shootingEntity.rotationPitch;

		fantasma.setPositionAndRotation(x, y, z, yaw, pitch);

		int fantasmaID = fantasma.getEntityId();
		String fantasmaUUID = fantasma.getUniqueID().toString();

		util.setInttag(pistola, "fantasmaID", fantasmaID);
		util.setStringtag(pistola, "fantasmaUUID", fantasmaUUID);

		System.out.println( "\n\nFantasma Conjurado id  =("+fantasmaID+")\n"  );
		System.out.println( "\n\nFantasma Conjurado uuid=("+fantasmaUUID+")\n"  );


		worldIn.spawnEntityInWorld(fantasma);

		fantasma.setShootingEntity(shootingEntity);
		fantasma.setPistola(pistola);

		entidad = fantasma;
	}




	return entidad;		

}
// ########################################################################3

 

this test was done

first i use the gun once to create the entity fantasma and load the values in the nbttag for the gun

i close all minecraft

i reopen minecraft the entity dies coz has not all the values neede to work

 

then i use again the gun to recall the dead fantasma using its ID, but fails the entity returned is absolutly null 

 

Link to comment
Share on other sites

 

ñaaa

i frustate whith UUID

 

i found't not  any method to get back the entity using the uuid

 

only  this

worldIn.getPlayerEntityByUUID(UUID.fromString(fantasmaUUID))

but this is only for EntityPlayer, and i need to recall most of the time EntityLivingBase

 

so anyway i tried this whith the uuid from an entityLivingBase

Entity temp00 = worldIn.getPlayerEntityByUUID(UUID.fromString(fantasmaUUID));

an it returns  Null, and no errors

 

the other thing i notice is that the entityID change when i close/save the world and then reload the saved world, but not the uuid thats has no changes

 

soo recall a deadEntity by ID won't gonna works  coze its changes

 

and can't recall an entity by storing their ID number in an item,  after close minecraft not gonna works coze its change the ID

 

####

At the point

¿¿  is way to recall an EntityLivingBase(notDead) using their UUID in both remote and local world ??

 

 

 

Link to comment
Share on other sites

the other thing i notice is that the entityID change when i close/save the world and then reload the saved world, but not the uuid thats has no changes

 

You cannot store entityID in NBT. It changes whenever the entity is saved and loaded. You have to use UUID.

 

entityID is something generated by "next iteration of global entityID", in simple words: "++entityId". It is generated by server whenever server spawns an entity, and then send to client (along with other data) inside spawn packet. That is how MC enstablishes connection between client- and server-side entities.

 

Again: entityID is NOT persistent.

 

And yes: UUIDs are persistent. UUID will be same for both client and server for all entities EXCEPT for EntityPlayer - UUIDs of players work properly on server-side only (at least from what I remember, correct me if this is false).

 

i found't not  any method to get back the entity using the uuid

 

Just because you can't find something doesn't mean you cannot make it. I could swear there was method for that in 1.8, but if not:

Iterate over world.entityList and simply compare their UUID with input one until you find right entity. Note that comparing uuids is not super-cheap so you should try not using it milion times every tick.

 

Conclusion: The ONLY was to store persistent link to some entity is to save its UUID.

1.7.10 is no longer supported by forge, you are on your own.

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.