hollow-cube/editentitymeta_function (#62)

* Add editEntityMeta

* Log entityType instead

* finally

(cherry picked from commit 30699ec3fd)
This commit is contained in:
Samuel 2023-09-26 09:40:52 -04:00 committed by Matt Worzala
parent b1b33b9df8
commit 7174ce2b21
1 changed files with 15 additions and 0 deletions

View File

@ -291,6 +291,21 @@ public class Entity implements Viewable, Tickable, Schedulable, Snapshotable, Ev
return this.entityMeta;
}
/**
* Do a batch edit of this entity's metadata.
*/
public <TMeta extends EntityMeta> void editEntityMeta(Class<TMeta> metaClass, Consumer<TMeta> editor) {
entityMeta.setNotifyAboutChanges(false);
try {
TMeta casted = metaClass.cast(entityMeta);
editor.accept(casted);
} catch (Throwable t) {
throw new RuntimeException("Error editing entity " + id + " " + entityType.name() + " meta", t);
} finally {
entityMeta.setNotifyAboutChanges(true);
}
}
/**
* Teleports the entity only if the chunk at {@code position} is loaded or if
* {@link Instance#hasEnabledAutoChunkLoad()} returns true.