Mirror von
https://github.com/IntellectualSites/FastAsyncWorldEdit.git
synchronisiert 2024-12-24 18:10:08 +01:00
Optimize entity get (lazy nbt)
Dieser Commit ist enthalten in:
Ursprung
0781c762e6
Commit
110f782a5c
@ -29,6 +29,7 @@ import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
|||||||
import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter;
|
import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter;
|
||||||
import com.sk89q.worldedit.bukkit.adapter.CachedBukkitAdapter;
|
import com.sk89q.worldedit.bukkit.adapter.CachedBukkitAdapter;
|
||||||
import com.sk89q.worldedit.entity.BaseEntity;
|
import com.sk89q.worldedit.entity.BaseEntity;
|
||||||
|
import com.sk89q.worldedit.entity.LazyBaseEntity;
|
||||||
import com.sk89q.worldedit.internal.Constants;
|
import com.sk89q.worldedit.internal.Constants;
|
||||||
import com.sk89q.worldedit.math.BlockVector3;
|
import com.sk89q.worldedit.math.BlockVector3;
|
||||||
import com.sk89q.worldedit.registry.state.*;
|
import com.sk89q.worldedit.registry.state.*;
|
||||||
@ -36,6 +37,7 @@ import com.sk89q.worldedit.util.Direction;
|
|||||||
import com.sk89q.worldedit.world.biome.BiomeType;
|
import com.sk89q.worldedit.world.biome.BiomeType;
|
||||||
import com.sk89q.worldedit.world.block.BlockState;
|
import com.sk89q.worldedit.world.block.BlockState;
|
||||||
import com.sk89q.worldedit.world.block.*;
|
import com.sk89q.worldedit.world.block.*;
|
||||||
|
import com.sk89q.worldedit.world.entity.EntityType;
|
||||||
import com.sk89q.worldedit.world.registry.BlockMaterial;
|
import com.sk89q.worldedit.world.registry.BlockMaterial;
|
||||||
import net.minecraft.server.v1_13_R2.*;
|
import net.minecraft.server.v1_13_R2.*;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@ -57,6 +59,7 @@ import javax.annotation.Nullable;
|
|||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.function.Supplier;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@ -287,9 +290,16 @@ public final class Spigot_v1_13_R2 extends CachedBukkitAdapter implements Bukkit
|
|||||||
String id = getEntityId(mcEntity);
|
String id = getEntityId(mcEntity);
|
||||||
|
|
||||||
if (id != null) {
|
if (id != null) {
|
||||||
NBTTagCompound tag = new NBTTagCompound();
|
EntityType type = com.sk89q.worldedit.world.entity.EntityTypes.get(id);
|
||||||
readEntityIntoTag(mcEntity, tag);
|
Supplier<CompoundTag> saveTag = new Supplier<CompoundTag>() {
|
||||||
return new BaseEntity(com.sk89q.worldedit.world.entity.EntityTypes.get(id), (CompoundTag) toNative(tag));
|
@Override
|
||||||
|
public CompoundTag get() {
|
||||||
|
NBTTagCompound tag = new NBTTagCompound();
|
||||||
|
readEntityIntoTag(mcEntity, tag);
|
||||||
|
return (CompoundTag) toNative(tag);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
return new LazyBaseEntity(type, saveTag);
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,9 @@ public class BukkitChunk_1_13_Copy extends BukkitChunk_1_13 {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int[][] getCombinedIdArrays() {
|
public int[][] getCombinedIdArrays() {
|
||||||
|
if (this.sectionPalettes == null) {
|
||||||
|
return this.ids;
|
||||||
|
}
|
||||||
for (int i = 0; i < ids.length; i++) {
|
for (int i = 0; i < ids.length; i++) {
|
||||||
getIdArray(i);
|
getIdArray(i);
|
||||||
}
|
}
|
||||||
@ -30,36 +33,39 @@ public class BukkitChunk_1_13_Copy extends BukkitChunk_1_13 {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int[] getIdArray(int layer) {
|
public int[] getIdArray(int layer) {
|
||||||
ChunkSection section = this.sectionPalettes[layer];
|
if (this.sectionPalettes != null) {
|
||||||
int[] idsArray = this.ids[layer];
|
ChunkSection section = this.sectionPalettes[layer];
|
||||||
if (section != null && idsArray == null) {
|
int[] idsArray = this.ids[layer];
|
||||||
idsArray = new int[4096];
|
if (section != null && idsArray == null) {
|
||||||
if (!section.a()) {
|
idsArray = new int[4096];
|
||||||
try {
|
if (!section.a()) {
|
||||||
DataPaletteBlock<IBlockData> blocks = section.getBlocks();
|
try {
|
||||||
DataBits bits = (DataBits) BukkitQueue_1_13.fieldBits.get(blocks);
|
DataPaletteBlock<IBlockData> blocks = section.getBlocks();
|
||||||
DataPalette<IBlockData> palette = (DataPalette<IBlockData>) BukkitQueue_1_13.fieldPalette.get(blocks);
|
DataBits bits = (DataBits) BukkitQueue_1_13.fieldBits.get(blocks);
|
||||||
|
DataPalette<IBlockData> palette = (DataPalette<IBlockData>) BukkitQueue_1_13.fieldPalette.get(blocks);
|
||||||
|
|
||||||
long[] raw = bits.a();
|
long[] raw = bits.a();
|
||||||
int bitsPerEntry = bits.c();
|
int bitsPerEntry = bits.c();
|
||||||
|
|
||||||
new BitArray4096(raw, bitsPerEntry).toRaw(idsArray);
|
new BitArray4096(raw, bitsPerEntry).toRaw(idsArray);
|
||||||
IBlockData defaultBlock = (IBlockData) BukkitQueue_1_13.fieldDefaultBlock.get(blocks);
|
IBlockData defaultBlock = (IBlockData) BukkitQueue_1_13.fieldDefaultBlock.get(blocks);
|
||||||
// TODO optimize away palette.a
|
// TODO optimize away palette.a
|
||||||
for (int i = 0; i < 4096; i++) {
|
for (int i = 0; i < 4096; i++) {
|
||||||
IBlockData ibd = palette.a(idsArray[i]);
|
IBlockData ibd = palette.a(idsArray[i]);
|
||||||
if (ibd == null) {
|
if (ibd == null) {
|
||||||
ibd = defaultBlock;
|
ibd = defaultBlock;
|
||||||
|
}
|
||||||
|
int ordinal = ((Spigot_v1_13_R2) getAdapter()).adaptToInt(ibd);
|
||||||
|
idsArray[i] = BlockTypes.states[ordinal].getInternalId();
|
||||||
}
|
}
|
||||||
int ordinal = ((Spigot_v1_13_R2) getAdapter()).adaptToInt(ibd);
|
} catch (IllegalAccessException e) {
|
||||||
idsArray[i] = BlockTypes.states[ordinal].getInternalId();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
} catch (IllegalAccessException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return idsArray;
|
||||||
}
|
}
|
||||||
return idsArray;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -21,6 +21,7 @@ package com.sk89q.worldedit.bukkit;
|
|||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
|
import com.boydti.fawe.util.TaskManager;
|
||||||
import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter;
|
import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter;
|
||||||
import com.sk89q.worldedit.entity.BaseEntity;
|
import com.sk89q.worldedit.entity.BaseEntity;
|
||||||
import com.sk89q.worldedit.entity.Entity;
|
import com.sk89q.worldedit.entity.Entity;
|
||||||
@ -29,6 +30,8 @@ import com.sk89q.worldedit.entity.metadata.EntityProperties;
|
|||||||
import com.sk89q.worldedit.extent.Extent;
|
import com.sk89q.worldedit.extent.Extent;
|
||||||
import com.sk89q.worldedit.util.Location;
|
import com.sk89q.worldedit.util.Location;
|
||||||
import com.sk89q.worldedit.world.NullWorld;
|
import com.sk89q.worldedit.world.NullWorld;
|
||||||
|
import com.sk89q.worldedit.world.entity.EntityTypes;
|
||||||
|
import org.bukkit.entity.EntityType;
|
||||||
|
|
||||||
import java.lang.ref.WeakReference;
|
import java.lang.ref.WeakReference;
|
||||||
|
|
||||||
@ -40,6 +43,7 @@ import javax.annotation.Nullable;
|
|||||||
public class BukkitEntity implements Entity {
|
public class BukkitEntity implements Entity {
|
||||||
|
|
||||||
private final WeakReference<org.bukkit.entity.Entity> entityRef;
|
private final WeakReference<org.bukkit.entity.Entity> entityRef;
|
||||||
|
private final EntityType type;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new instance.
|
* Create a new instance.
|
||||||
@ -48,6 +52,7 @@ public class BukkitEntity implements Entity {
|
|||||||
*/
|
*/
|
||||||
public BukkitEntity(org.bukkit.entity.Entity entity) {
|
public BukkitEntity(org.bukkit.entity.Entity entity) {
|
||||||
checkNotNull(entity);
|
checkNotNull(entity);
|
||||||
|
this.type = entity.getType();
|
||||||
this.entityRef = new WeakReference<>(entity);
|
this.entityRef = new WeakReference<>(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,6 +86,11 @@ public class BukkitEntity implements Entity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public com.sk89q.worldedit.world.entity.EntityType getType() {
|
||||||
|
return EntityTypes.get(type.getName().toUpperCase());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BaseEntity getState() {
|
public BaseEntity getState() {
|
||||||
org.bukkit.entity.Entity entity = entityRef.get();
|
org.bukkit.entity.Entity entity = entityRef.get();
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
package com.sk89q.worldedit.bukkit;
|
package com.sk89q.worldedit.bukkit;
|
||||||
|
|
||||||
|
import com.boydti.fawe.Fawe;
|
||||||
import com.sk89q.worldedit.EditSession;
|
import com.sk89q.worldedit.EditSession;
|
||||||
import com.sk89q.worldedit.WorldEdit;
|
import com.sk89q.worldedit.WorldEdit;
|
||||||
import com.sk89q.worldedit.WorldEditException;
|
import com.sk89q.worldedit.WorldEditException;
|
||||||
@ -82,6 +83,7 @@ public class BukkitWorld extends AbstractWorld {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<com.sk89q.worldedit.entity.Entity> getEntities(Region region) {
|
public List<com.sk89q.worldedit.entity.Entity> getEntities(Region region) {
|
||||||
|
System.out.println(Fawe.isMainThread());
|
||||||
World world = getWorld();
|
World world = getWorld();
|
||||||
|
|
||||||
List<Entity> ents = world.getEntities();
|
List<Entity> ents = world.getEntities();
|
||||||
@ -96,6 +98,7 @@ public class BukkitWorld extends AbstractWorld {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<com.sk89q.worldedit.entity.Entity> getEntities() {
|
public List<com.sk89q.worldedit.entity.Entity> getEntities() {
|
||||||
|
System.out.println(Fawe.isMainThread());
|
||||||
List<com.sk89q.worldedit.entity.Entity> list = new ArrayList<>();
|
List<com.sk89q.worldedit.entity.Entity> list = new ArrayList<>();
|
||||||
for (Entity entity : getWorld().getEntities()) {
|
for (Entity entity : getWorld().getEntities()) {
|
||||||
list.add(BukkitAdapter.adapt(entity));
|
list.add(BukkitAdapter.adapt(entity));
|
||||||
|
@ -149,11 +149,13 @@ public class FastWorldEditExtent extends AbstractDelegateExtent implements HasFa
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<? extends Entity> getEntities() {
|
public List<? extends Entity> getEntities() {
|
||||||
|
System.out.println("World cp * " + world + " | " + world.getClass());
|
||||||
return world.getEntities();
|
return world.getEntities();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<? extends Entity> getEntities(final Region region) {
|
public List<? extends Entity> getEntities(final Region region) {
|
||||||
|
System.out.println("World cp rg " + world + " | " + world.getClass());
|
||||||
return world.getEntities(region);
|
return world.getEntities(region);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,6 +22,7 @@ package com.sk89q.worldedit.entity;
|
|||||||
import com.sk89q.worldedit.extent.Extent;
|
import com.sk89q.worldedit.extent.Extent;
|
||||||
import com.sk89q.worldedit.util.Faceted;
|
import com.sk89q.worldedit.util.Faceted;
|
||||||
import com.sk89q.worldedit.util.Location;
|
import com.sk89q.worldedit.util.Location;
|
||||||
|
import com.sk89q.worldedit.world.entity.EntityType;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
@ -62,6 +63,11 @@ public interface Entity extends Faceted {
|
|||||||
*/
|
*/
|
||||||
boolean setLocation(Location location);
|
boolean setLocation(Location location);
|
||||||
|
|
||||||
|
default EntityType getType() {
|
||||||
|
BaseEntity state = getState();
|
||||||
|
return state != null ? state.getType() : null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the extent that this entity is on.
|
* 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();
|
||||||
|
}
|
||||||
|
}
|
@ -27,12 +27,14 @@ import com.boydti.fawe.object.function.block.BiomeCopy;
|
|||||||
import com.boydti.fawe.object.function.block.CombinedBlockCopy;
|
import com.boydti.fawe.object.function.block.CombinedBlockCopy;
|
||||||
import com.boydti.fawe.object.function.block.SimpleBlockCopy;
|
import com.boydti.fawe.object.function.block.SimpleBlockCopy;
|
||||||
import com.boydti.fawe.util.MaskTraverser;
|
import com.boydti.fawe.util.MaskTraverser;
|
||||||
|
import com.google.common.base.Predicate;
|
||||||
import com.sk89q.worldedit.EditSession;
|
import com.sk89q.worldedit.EditSession;
|
||||||
import static com.google.common.base.Preconditions.checkArgument;
|
import static com.google.common.base.Preconditions.checkArgument;
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.sk89q.worldedit.WorldEditException;
|
import com.sk89q.worldedit.WorldEditException;
|
||||||
|
import com.sk89q.worldedit.entity.BaseEntity;
|
||||||
import com.sk89q.worldedit.entity.Entity;
|
import com.sk89q.worldedit.entity.Entity;
|
||||||
import com.sk89q.worldedit.extent.Extent;
|
import com.sk89q.worldedit.extent.Extent;
|
||||||
import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard;
|
import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard;
|
||||||
@ -52,6 +54,9 @@ import com.sk89q.worldedit.math.BlockVector3;
|
|||||||
import com.sk89q.worldedit.math.transform.Identity;
|
import com.sk89q.worldedit.math.transform.Identity;
|
||||||
import com.sk89q.worldedit.math.transform.Transform;
|
import com.sk89q.worldedit.math.transform.Transform;
|
||||||
import com.sk89q.worldedit.regions.Region;
|
import com.sk89q.worldedit.regions.Region;
|
||||||
|
import com.sk89q.worldedit.world.entity.EntityTypes;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@ -353,11 +358,15 @@ public class ForwardExtentCopy implements Operation {
|
|||||||
List<? extends Entity> entities;
|
List<? extends Entity> entities;
|
||||||
if (isCopyingEntities()) {
|
if (isCopyingEntities()) {
|
||||||
// filter players since they can't be copied
|
// filter players since they can't be copied
|
||||||
entities = source.getEntities()
|
entities = source.getEntities(region)
|
||||||
.stream()
|
.stream()
|
||||||
.filter(entity -> entity.getState() != null &&
|
.filter(new Predicate<Entity>() {
|
||||||
!entity.getState().getType().getId().equals("minecraft:player") &&
|
@Override
|
||||||
region.contains(entity.getLocation().toBlockPoint()))
|
public boolean apply(@Nullable Entity input) {
|
||||||
|
BaseEntity state = input.getState();
|
||||||
|
return state != null && state.getType() != EntityTypes.PLAYER;
|
||||||
|
}
|
||||||
|
})
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
} else {
|
} else {
|
||||||
entities = new ArrayList<>();
|
entities = new ArrayList<>();
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren