mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-06-11 20:13:55 +00:00
Lazy tags + get / set tiles
Lazy tags means tiles/ents are not translated into the nms NBTBase until it is needed. Should be faster in cases where getFullBlock is called, but nbt is not always needed. Commands like Copy and Paste, where the input/output are both nms worlds, can entirely bypass WorldEdit translating to and from the WorldEdit JNBT classes.
This commit is contained in:
@ -9,9 +9,11 @@ import com.boydti.fawe.beta.IChunkSet;
|
||||
import com.boydti.fawe.beta.implementation.blocks.CharGetBlocks;
|
||||
import com.boydti.fawe.beta.implementation.queue.QueueHandler;
|
||||
import com.boydti.fawe.bukkit.adapter.DelegateLock;
|
||||
import com.boydti.fawe.bukkit.adapter.mc1_14.nbt.LazyCompoundTag_1_14;
|
||||
import com.boydti.fawe.object.collection.AdaptedMap;
|
||||
import com.boydti.fawe.object.collection.BitArray4096;
|
||||
import com.boydti.fawe.util.ReflectionUtils;
|
||||
import com.google.common.base.Suppliers;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.jnbt.ListTag;
|
||||
@ -21,6 +23,7 @@ import com.sk89q.jnbt.Tag;
|
||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
|
||||
import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter;
|
||||
import com.sk89q.worldedit.bukkit.adapter.impl.FAWE_Spigot_v1_14_R4;
|
||||
import com.sk89q.worldedit.internal.Constants;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.world.biome.BiomeType;
|
||||
@ -101,9 +104,8 @@ public class BukkitGetBlocks_1_14 extends CharGetBlocks {
|
||||
|
||||
@Override
|
||||
public CompoundTag getTag(int x, int y, int z) {
|
||||
TileEntity tile = getChunk().getTileEntity(new BlockPosition((x & 15) + (X << 4), y, (z & 15) + (Z << 4)));
|
||||
BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter();
|
||||
return (CompoundTag) adapter.toNative(tile);
|
||||
TileEntity tileEntity = getChunk().getTileEntity(new BlockPosition((x & 15) + (X << 4), y, (z & 15) + (Z << 4)));
|
||||
return new LazyCompoundTag_1_14(Suppliers.memoize(() -> tileEntity.save(new NBTTagCompound())));
|
||||
}
|
||||
|
||||
private static final Function<BlockPosition, BlockVector3> posNms2We = new Function<BlockPosition, BlockVector3>() {
|
||||
@ -116,8 +118,7 @@ public class BukkitGetBlocks_1_14 extends CharGetBlocks {
|
||||
private final static Function<TileEntity, CompoundTag> nmsTile2We = new Function<TileEntity, CompoundTag>() {
|
||||
@Override
|
||||
public CompoundTag apply(TileEntity tileEntity) {
|
||||
BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter();
|
||||
return (CompoundTag) adapter.toNative(tileEntity.b());
|
||||
return new LazyCompoundTag_1_14(Suppliers.memoize(() -> tileEntity.save(new NBTTagCompound())));
|
||||
}
|
||||
};
|
||||
|
||||
@ -419,10 +420,11 @@ public class BukkitGetBlocks_1_14 extends CharGetBlocks {
|
||||
for (final Map.Entry<BlockVector3, CompoundTag> entry : tiles.entrySet()) {
|
||||
final CompoundTag nativeTag = entry.getValue();
|
||||
final BlockVector3 blockHash = entry.getKey();
|
||||
final int x = blockHash.getX()+ bx;
|
||||
final int x = blockHash.getX() + bx;
|
||||
final int y = blockHash.getY();
|
||||
final int z = blockHash.getZ() + bz;
|
||||
final BlockPosition pos = new BlockPosition(x, y, z);
|
||||
|
||||
synchronized (nmsWorld) {
|
||||
TileEntity tileEntity = nmsWorld.getTileEntity(pos);
|
||||
if (tileEntity == null || tileEntity.isRemoved()) {
|
||||
@ -473,18 +475,23 @@ public class BukkitGetBlocks_1_14 extends CharGetBlocks {
|
||||
Callable<Future> chain = new Callable<Future>() {
|
||||
@Override
|
||||
public Future call() {
|
||||
// Run the sync tasks
|
||||
for (int i = 1; i < finalSyncTasks.length; i++) {
|
||||
Runnable task = finalSyncTasks[i];
|
||||
if (task != null) {
|
||||
task.run();
|
||||
try {
|
||||
// Run the sync tasks
|
||||
for (int i = 0; i < finalSyncTasks.length; i++) {
|
||||
Runnable task = finalSyncTasks[i];
|
||||
if (task != null) {
|
||||
task.run();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (callback == null) {
|
||||
if (finalizer != null) finalizer.run();
|
||||
return null;
|
||||
} else {
|
||||
return queueHandler.async(callback, null);
|
||||
if (callback == null) {
|
||||
if (finalizer != null) finalizer.run();
|
||||
return null;
|
||||
} else {
|
||||
return queueHandler.async(callback, null);
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.boydti.fawe.bukkit.adapter.mc1_14.nbt;
|
||||
|
||||
import com.google.common.base.Suppliers;
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.jnbt.ListTag;
|
||||
import com.sk89q.jnbt.StringTag;
|
||||
@ -14,43 +15,52 @@ import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class LazyCompoundTag_1_14 extends CompoundTag {
|
||||
private final NBTTagCompound nmsTag;
|
||||
private final Supplier<NBTTagCompound> nmsTag;
|
||||
|
||||
public LazyCompoundTag_1_14(NBTTagCompound tag) {
|
||||
public LazyCompoundTag_1_14(Supplier<NBTTagCompound> tag) {
|
||||
super(null);
|
||||
this.nmsTag = tag;
|
||||
}
|
||||
|
||||
public LazyCompoundTag_1_14(NBTTagCompound tag) {
|
||||
this(() -> tag);
|
||||
}
|
||||
|
||||
public NBTTagCompound get() {
|
||||
return nmsTag.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Tag> getValue() {
|
||||
Map<String, Tag> value = super.getValue();
|
||||
if (value == null) {
|
||||
Tag tag = WorldEditPlugin.getInstance().getBukkitImplAdapter().toNative(nmsTag);
|
||||
Tag tag = WorldEditPlugin.getInstance().getBukkitImplAdapter().toNative(nmsTag.get());
|
||||
setValue(((CompoundTag) tag).getValue());
|
||||
}
|
||||
return super.getValue();
|
||||
}
|
||||
|
||||
public boolean containsKey(String key) {
|
||||
return nmsTag.hasKey(key);
|
||||
return nmsTag.get().hasKey(key);
|
||||
}
|
||||
|
||||
public byte[] getByteArray(String key) {
|
||||
return nmsTag.getByteArray(key);
|
||||
return nmsTag.get().getByteArray(key);
|
||||
}
|
||||
|
||||
public byte getByte(String key) {
|
||||
return nmsTag.getByte(key);
|
||||
return nmsTag.get().getByte(key);
|
||||
}
|
||||
|
||||
public double getDouble(String key) {
|
||||
return nmsTag.getDouble(key);
|
||||
return nmsTag.get().getDouble(key);
|
||||
}
|
||||
|
||||
public double asDouble(String key) {
|
||||
NBTBase value = nmsTag.get(key);
|
||||
NBTBase value = nmsTag.get().get(key);
|
||||
if (value instanceof NBTNumber) {
|
||||
return ((NBTNumber) value).asDouble();
|
||||
}
|
||||
@ -58,19 +68,19 @@ public class LazyCompoundTag_1_14 extends CompoundTag {
|
||||
}
|
||||
|
||||
public float getFloat(String key) {
|
||||
return nmsTag.getFloat(key);
|
||||
return nmsTag.get().getFloat(key);
|
||||
}
|
||||
|
||||
public int[] getIntArray(String key) {
|
||||
return nmsTag.getIntArray(key);
|
||||
return nmsTag.get().getIntArray(key);
|
||||
}
|
||||
|
||||
public int getInt(String key) {
|
||||
return nmsTag.getInt(key);
|
||||
return nmsTag.get().getInt(key);
|
||||
}
|
||||
|
||||
public int asInt(String key) {
|
||||
NBTBase value = nmsTag.get(key);
|
||||
NBTBase value = nmsTag.get().get(key);
|
||||
if (value instanceof NBTNumber) {
|
||||
return ((NBTNumber) value).asInt();
|
||||
}
|
||||
@ -78,7 +88,7 @@ public class LazyCompoundTag_1_14 extends CompoundTag {
|
||||
}
|
||||
|
||||
public List<Tag> getList(String key) {
|
||||
NBTBase tag = nmsTag.get(key);
|
||||
NBTBase tag = nmsTag.get().get(key);
|
||||
if (tag instanceof NBTTagList) {
|
||||
ArrayList<Tag> list = new ArrayList<>();
|
||||
NBTTagList nbtList = (NBTTagList) tag;
|
||||
@ -95,7 +105,7 @@ public class LazyCompoundTag_1_14 extends CompoundTag {
|
||||
}
|
||||
|
||||
public ListTag getListTag(String key) {
|
||||
NBTBase tag = nmsTag.get(key);
|
||||
NBTBase tag = nmsTag.get().get(key);
|
||||
if (tag instanceof NBTTagList) {
|
||||
return (ListTag) WorldEditPlugin.getInstance().getBukkitImplAdapter().toNative(tag);
|
||||
}
|
||||
@ -113,15 +123,15 @@ public class LazyCompoundTag_1_14 extends CompoundTag {
|
||||
}
|
||||
|
||||
public long[] getLongArray(String key) {
|
||||
return nmsTag.getLongArray(key);
|
||||
return nmsTag.get().getLongArray(key);
|
||||
}
|
||||
|
||||
public long getLong(String key) {
|
||||
return nmsTag.getLong(key);
|
||||
return nmsTag.get().getLong(key);
|
||||
}
|
||||
|
||||
public long asLong(String key) {
|
||||
NBTBase value = nmsTag.get(key);
|
||||
NBTBase value = nmsTag.get().get(key);
|
||||
if (value instanceof NBTNumber) {
|
||||
return ((NBTNumber) value).asLong();
|
||||
}
|
||||
@ -129,10 +139,15 @@ public class LazyCompoundTag_1_14 extends CompoundTag {
|
||||
}
|
||||
|
||||
public short getShort(String key) {
|
||||
return nmsTag.getShort(key);
|
||||
return nmsTag.get().getShort(key);
|
||||
}
|
||||
|
||||
public String getString(String key) {
|
||||
return nmsTag.getString(key);
|
||||
return nmsTag.get().getString(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return nmsTag.get().toString();
|
||||
}
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ import static com.sk89q.worldedit.internal.anvil.ChunkDeleter.DELCHUNKS_FILE_NAM
|
||||
|
||||
import com.boydti.fawe.Fawe;
|
||||
import com.boydti.fawe.bukkit.FaweBukkit;
|
||||
import com.boydti.fawe.bukkit.adapter.mc1_14.FAWE_Spigot_v1_14_R4;
|
||||
import com.sk89q.worldedit.bukkit.adapter.impl.FAWE_Spigot_v1_14_R4;
|
||||
import com.boydti.fawe.util.MainUtil;
|
||||
import com.google.common.base.Joiner;
|
||||
import com.sk89q.util.yaml.YAMLProcessor;
|
||||
|
@ -155,7 +155,6 @@ public class BukkitImplLoader {
|
||||
*/
|
||||
public BukkitImplAdapter loadAdapter() throws AdapterLoadException {
|
||||
for (String className : adapterCandidates) {
|
||||
System.out.println("Try load " + className);
|
||||
try {
|
||||
Class<?> cls = Class.forName(className);
|
||||
if (cls.isSynthetic()) continue;
|
||||
|
@ -17,11 +17,17 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.boydti.fawe.bukkit.adapter.mc1_14;
|
||||
package com.sk89q.worldedit.bukkit.adapter.impl;
|
||||
|
||||
import com.bekvon.bukkit.residence.commands.material;
|
||||
import com.boydti.fawe.FaweCache;
|
||||
import com.boydti.fawe.beta.implementation.packet.ChunkPacket;
|
||||
import com.boydti.fawe.bukkit.adapter.mc1_14.BlockMaterial_1_14;
|
||||
import com.boydti.fawe.bukkit.adapter.mc1_14.BukkitAdapter_1_14;
|
||||
import com.boydti.fawe.bukkit.adapter.mc1_14.MapChunkUtil_1_14;
|
||||
import com.boydti.fawe.bukkit.adapter.mc1_14.nbt.LazyCompoundTag_1_14;
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.jnbt.Tag;
|
||||
import com.sk89q.worldedit.blocks.BaseItemStack;
|
||||
import com.sk89q.worldedit.blocks.TileEntityBlock;
|
||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||
@ -74,6 +80,7 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.OptionalInt;
|
||||
import java.util.function.Supplier;
|
||||
@ -82,7 +89,7 @@ import java.util.stream.Stream;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
public final class FAWE_Spigot_v1_14_R4 extends CachedBukkitAdapter implements IDelegateBukkitImplAdapter<NBTBase> {
|
||||
private final BukkitImplAdapter<NBTBase> parent;
|
||||
private final Spigot_v1_14_R4 parent;
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Code that may break between versions of Minecraft
|
||||
@ -242,9 +249,6 @@ public final class FAWE_Spigot_v1_14_R4 extends CachedBukkitAdapter implements I
|
||||
@Override
|
||||
public OptionalInt getInternalBlockStateId(BlockState state) {
|
||||
BlockMaterial_1_14 material = (BlockMaterial_1_14) state.getMaterial();
|
||||
if (material.isAir()) {
|
||||
return OptionalInt.empty();
|
||||
}
|
||||
IBlockData mcState = material.getCraftBlockData().getState();
|
||||
return OptionalInt.of(Block.REGISTRY_ID.getId(mcState));
|
||||
}
|
||||
@ -324,9 +328,7 @@ public final class FAWE_Spigot_v1_14_R4 extends CachedBukkitAdapter implements I
|
||||
|
||||
@Override
|
||||
public Map<String, ? extends Property<?>> getProperties(BlockType blockType) {
|
||||
Map<String, ? extends Property<?>> result = getParent().getProperties(blockType);
|
||||
System.out.println("Result " + result);
|
||||
return result;
|
||||
return getParent().getProperties(blockType);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -343,4 +345,17 @@ public final class FAWE_Spigot_v1_14_R4 extends CachedBukkitAdapter implements I
|
||||
weStack.setNbtData(((CompoundTag) toNative(nmsStack.getTag())));
|
||||
return weStack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tag toNative(NBTBase foreign) {
|
||||
return parent.toNative(foreign);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTBase fromNative(Tag foreign) {
|
||||
if (foreign instanceof LazyCompoundTag_1_14) {
|
||||
return ((LazyCompoundTag_1_14) foreign).get();
|
||||
}
|
||||
return parent.fromNative(foreign);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user