mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-06-13 04:53:55 +00:00
Optimize entity get (lazy nbt)
This commit is contained in:
@ -29,6 +29,7 @@ import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||
import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter;
|
||||
import com.sk89q.worldedit.bukkit.adapter.CachedBukkitAdapter;
|
||||
import com.sk89q.worldedit.entity.BaseEntity;
|
||||
import com.sk89q.worldedit.entity.LazyBaseEntity;
|
||||
import com.sk89q.worldedit.internal.Constants;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
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.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.*;
|
||||
import com.sk89q.worldedit.world.entity.EntityType;
|
||||
import com.sk89q.worldedit.world.registry.BlockMaterial;
|
||||
import net.minecraft.server.v1_13_R2.*;
|
||||
import org.bukkit.Bukkit;
|
||||
@ -57,6 +59,7 @@ import javax.annotation.Nullable;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.*;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.logging.Level;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@ -287,9 +290,16 @@ public final class Spigot_v1_13_R2 extends CachedBukkitAdapter implements Bukkit
|
||||
String id = getEntityId(mcEntity);
|
||||
|
||||
if (id != null) {
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
readEntityIntoTag(mcEntity, tag);
|
||||
return new BaseEntity(com.sk89q.worldedit.world.entity.EntityTypes.get(id), (CompoundTag) toNative(tag));
|
||||
EntityType type = com.sk89q.worldedit.world.entity.EntityTypes.get(id);
|
||||
Supplier<CompoundTag> saveTag = new Supplier<CompoundTag>() {
|
||||
@Override
|
||||
public CompoundTag get() {
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
readEntityIntoTag(mcEntity, tag);
|
||||
return (CompoundTag) toNative(tag);
|
||||
}
|
||||
};
|
||||
return new LazyBaseEntity(type, saveTag);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
@ -22,6 +22,9 @@ public class BukkitChunk_1_13_Copy extends BukkitChunk_1_13 {
|
||||
|
||||
@Override
|
||||
public int[][] getCombinedIdArrays() {
|
||||
if (this.sectionPalettes == null) {
|
||||
return this.ids;
|
||||
}
|
||||
for (int i = 0; i < ids.length; i++) {
|
||||
getIdArray(i);
|
||||
}
|
||||
@ -30,36 +33,39 @@ public class BukkitChunk_1_13_Copy extends BukkitChunk_1_13 {
|
||||
|
||||
@Override
|
||||
public int[] getIdArray(int layer) {
|
||||
ChunkSection section = this.sectionPalettes[layer];
|
||||
int[] idsArray = this.ids[layer];
|
||||
if (section != null && idsArray == null) {
|
||||
idsArray = new int[4096];
|
||||
if (!section.a()) {
|
||||
try {
|
||||
DataPaletteBlock<IBlockData> blocks = section.getBlocks();
|
||||
DataBits bits = (DataBits) BukkitQueue_1_13.fieldBits.get(blocks);
|
||||
DataPalette<IBlockData> palette = (DataPalette<IBlockData>) BukkitQueue_1_13.fieldPalette.get(blocks);
|
||||
if (this.sectionPalettes != null) {
|
||||
ChunkSection section = this.sectionPalettes[layer];
|
||||
int[] idsArray = this.ids[layer];
|
||||
if (section != null && idsArray == null) {
|
||||
idsArray = new int[4096];
|
||||
if (!section.a()) {
|
||||
try {
|
||||
DataPaletteBlock<IBlockData> blocks = section.getBlocks();
|
||||
DataBits bits = (DataBits) BukkitQueue_1_13.fieldBits.get(blocks);
|
||||
DataPalette<IBlockData> palette = (DataPalette<IBlockData>) BukkitQueue_1_13.fieldPalette.get(blocks);
|
||||
|
||||
long[] raw = bits.a();
|
||||
int bitsPerEntry = bits.c();
|
||||
long[] raw = bits.a();
|
||||
int bitsPerEntry = bits.c();
|
||||
|
||||
new BitArray4096(raw, bitsPerEntry).toRaw(idsArray);
|
||||
IBlockData defaultBlock = (IBlockData) BukkitQueue_1_13.fieldDefaultBlock.get(blocks);
|
||||
// TODO optimize away palette.a
|
||||
for (int i = 0; i < 4096; i++) {
|
||||
IBlockData ibd = palette.a(idsArray[i]);
|
||||
if (ibd == null) {
|
||||
ibd = defaultBlock;
|
||||
new BitArray4096(raw, bitsPerEntry).toRaw(idsArray);
|
||||
IBlockData defaultBlock = (IBlockData) BukkitQueue_1_13.fieldDefaultBlock.get(blocks);
|
||||
// TODO optimize away palette.a
|
||||
for (int i = 0; i < 4096; i++) {
|
||||
IBlockData ibd = palette.a(idsArray[i]);
|
||||
if (ibd == null) {
|
||||
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);
|
||||
idsArray[i] = BlockTypes.states[ordinal].getInternalId();
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return idsArray;
|
||||
}
|
||||
return idsArray;
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Reference in New Issue
Block a user