mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-12 10:28:35 +00:00
Optimize entity get (lazy nbt)
This commit is contained in:
@ -22,6 +22,7 @@ package com.sk89q.worldedit.entity;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.util.Faceted;
|
||||
import com.sk89q.worldedit.util.Location;
|
||||
import com.sk89q.worldedit.world.entity.EntityType;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
@ -62,6 +63,11 @@ public interface Entity extends Faceted {
|
||||
*/
|
||||
boolean setLocation(Location location);
|
||||
|
||||
default EntityType getType() {
|
||||
BaseEntity state = getState();
|
||||
return state != null ? state.getType() : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the extent that this entity is on.
|
||||
*
|
||||
|
@ -0,0 +1,32 @@
|
||||
package com.sk89q.worldedit.entity;
|
||||
|
||||
import com.boydti.fawe.Fawe;
|
||||
import com.boydti.fawe.util.TaskManager;
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.worldedit.world.entity.EntityType;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class LazyBaseEntity extends BaseEntity {
|
||||
private Supplier<CompoundTag> saveTag;
|
||||
public LazyBaseEntity(EntityType type, Supplier<CompoundTag> saveTag) {
|
||||
super(type, null);
|
||||
this.saveTag = saveTag;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public CompoundTag getNbtData() {
|
||||
Supplier<CompoundTag> tmp = saveTag;
|
||||
if (tmp != null) {
|
||||
saveTag = null;
|
||||
if (Fawe.isMainThread()) {
|
||||
setNbtData(tmp.get());
|
||||
} else {
|
||||
setNbtData(TaskManager.IMP.sync(tmp));
|
||||
}
|
||||
}
|
||||
return super.getNbtData();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user