Quick Entity Question

So I’m working with entities, and comparing them, and I was wondering if an Entity instance is ever changed or re-created for an entity. Simply put, can I use “==” to check if one Entity is the exact same entity as another Entity variable? (I know == does ‘is same object’ comparison, but I don’t know if sponge ever re-creates an Entity instance for the same represented mob)

Unless you try compare an entity to an entity snapshot, the objects should be identical. That’s not to say that Vanilla minecraft preserve the objects - teleporting across worlds may recreate the entity for example, I’m not sure.

But Sponge, unlike Bukkit, directly edits the “vanilla” classes, so you don’t end up with a wrapper around a vanilla object representing that object.

I just realized I could compare UUID’s… thank you for the help though!

1 Like

An entity object will always point to the same underlying entity. The Sponge implementation does some tweaks to vanilla in places where vanilla would otherwise recreate the object (e.g. when a player respawns).