From 144ea2ef34c0bc348ae13610ce6ad6f5aa9df691 Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Wed, 20 Nov 2019 03:40:52 +0000 Subject: [PATCH] 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. --- .../adapter/mc1_14/BukkitGetBlocks_1_14.java | 41 +++++++----- .../mc1_14/nbt/LazyCompoundTag_1_14.java | 53 ++++++++++------ .../worldedit/bukkit/WorldEditPlugin.java | 2 +- .../bukkit/adapter/BukkitImplLoader.java | 1 - .../adapter/impl}/FAWE_Spigot_v1_14_R4.java | 31 ++++++--- .../java/com/boydti/fawe/beta/IChunkGet.java | 3 +- .../java/com/boydti/fawe/beta/ITileInput.java | 7 +++ .../implementation/blocks/CharGetBlocks.java | 4 +- .../implementation/blocks/CharSetBlocks.java | 2 +- .../cfi/HeightMapMCAGenerator.java | 2 - .../fawe/object/collection/MutablePair.java | 4 +- .../function/block/SimpleBlockCopy.java | 1 + .../java/com/sk89q/jnbt/ByteArrayTag.java | 9 +++ .../src/main/java/com/sk89q/jnbt/ByteTag.java | 8 +++ .../main/java/com/sk89q/jnbt/CompoundTag.java | 9 +++ .../main/java/com/sk89q/jnbt/DoubleTag.java | 8 +++ .../src/main/java/com/sk89q/jnbt/EndTag.java | 9 +++ .../main/java/com/sk89q/jnbt/FloatTag.java | 8 +++ .../main/java/com/sk89q/jnbt/IntArrayTag.java | 9 +++ .../src/main/java/com/sk89q/jnbt/IntTag.java | 8 +++ .../src/main/java/com/sk89q/jnbt/ListTag.java | 11 +++- .../java/com/sk89q/jnbt/LongArrayTag.java | 9 +++ .../src/main/java/com/sk89q/jnbt/LongTag.java | 8 +++ .../java/com/sk89q/jnbt/NBTOutputStream.java | 8 +-- .../main/java/com/sk89q/jnbt/NBTUtils.java | 4 +- .../main/java/com/sk89q/jnbt/ShortTag.java | 8 +++ .../main/java/com/sk89q/jnbt/StringTag.java | 9 +++ .../src/main/java/com/sk89q/jnbt/Tag.java | 4 ++ .../worldedit/command/BrushCommands.java | 63 ++----------------- .../worldedit/command/RegionCommands.java | 53 +++++----------- .../worldedit/command/ToolUtilCommands.java | 6 +- .../worldedit/command/WorldEditCommands.java | 2 +- .../extension/platform/Capability.java | 2 + .../internal/block/BlockStateIdAccess.java | 11 +++- .../worldedit/world/block/BaseBlock.java | 6 +- .../worldedit/world/block/BlockState.java | 21 ++++++- .../world/block/BlockStateHolder.java | 6 ++ .../worldedit/world/block/CompoundInput.java | 18 ++++++ .../world/block/ImmutableBaseBlock.java | 1 + .../sk89q/worldedit/world/item/ItemTypes.java | 1 - 40 files changed, 298 insertions(+), 172 deletions(-) rename worldedit-bukkit/src/main/java/com/{boydti/fawe/bukkit/adapter/mc1_14 => sk89q/worldedit/bukkit/adapter/impl}/FAWE_Spigot_v1_14_R4.java (94%) create mode 100644 worldedit-core/src/main/java/com/boydti/fawe/beta/ITileInput.java create mode 100644 worldedit-core/src/main/java/com/sk89q/worldedit/world/block/CompoundInput.java diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_14/BukkitGetBlocks_1_14.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_14/BukkitGetBlocks_1_14.java index cfbe4f81e..86e443c09 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_14/BukkitGetBlocks_1_14.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_14/BukkitGetBlocks_1_14.java @@ -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 posNms2We = new Function() { @@ -116,8 +118,7 @@ public class BukkitGetBlocks_1_14 extends CharGetBlocks { private final static Function nmsTile2We = new Function() { @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 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 chain = new Callable() { @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; } } }; diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_14/nbt/LazyCompoundTag_1_14.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_14/nbt/LazyCompoundTag_1_14.java index 9674013f0..6c26166f3 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_14/nbt/LazyCompoundTag_1_14.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_14/nbt/LazyCompoundTag_1_14.java @@ -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 nmsTag; - public LazyCompoundTag_1_14(NBTTagCompound tag) { + public LazyCompoundTag_1_14(Supplier tag) { super(null); this.nmsTag = tag; } + public LazyCompoundTag_1_14(NBTTagCompound tag) { + this(() -> tag); + } + + public NBTTagCompound get() { + return nmsTag.get(); + } + @Override public Map getValue() { Map 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 getList(String key) { - NBTBase tag = nmsTag.get(key); + NBTBase tag = nmsTag.get().get(key); if (tag instanceof NBTTagList) { ArrayList 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(); } } diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java index 1b4ab8472..743026306 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java @@ -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; diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/BukkitImplLoader.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/BukkitImplLoader.java index 7b8aac09a..5b5e2a852 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/BukkitImplLoader.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/BukkitImplLoader.java @@ -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; diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_14/FAWE_Spigot_v1_14_R4.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/FAWE_Spigot_v1_14_R4.java similarity index 94% rename from worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_14/FAWE_Spigot_v1_14_R4.java rename to worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/FAWE_Spigot_v1_14_R4.java index 84cb23d8b..c1d4844bc 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_14/FAWE_Spigot_v1_14_R4.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/FAWE_Spigot_v1_14_R4.java @@ -17,11 +17,17 @@ * along with this program. If not, see . */ -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 { - private final BukkitImplAdapter 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> getProperties(BlockType blockType) { - Map> 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); + } } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/IChunkGet.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/IChunkGet.java index 73e993da2..073f660c2 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/IChunkGet.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/IChunkGet.java @@ -15,7 +15,7 @@ import java.util.concurrent.Future; /** * An interface for getting blocks. */ -public interface IChunkGet extends IBlocks, Trimable, InputExtent { +public interface IChunkGet extends IBlocks, Trimable, InputExtent, ITileInput { @Override BaseBlock getFullBlock(int x, int y, int z); @@ -26,6 +26,7 @@ public interface IChunkGet extends IBlocks, Trimable, InputExtent { @Override BlockState getBlock(int x, int y, int z); + @Override CompoundTag getTag(int x, int y, int z); @Override diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/ITileInput.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/ITileInput.java new file mode 100644 index 000000000..99bf4644e --- /dev/null +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/ITileInput.java @@ -0,0 +1,7 @@ +package com.boydti.fawe.beta; + +import com.sk89q.jnbt.CompoundTag; + +public interface ITileInput { + CompoundTag getTag(int x, int y, int z); +} diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/blocks/CharGetBlocks.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/blocks/CharGetBlocks.java index 9304969f3..e9a76c986 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/blocks/CharGetBlocks.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/blocks/CharGetBlocks.java @@ -2,6 +2,7 @@ package com.boydti.fawe.beta.implementation.blocks; import com.boydti.fawe.beta.IChunkGet; import com.boydti.fawe.beta.IChunkSet; +import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockTypes; @@ -11,7 +12,8 @@ public abstract class CharGetBlocks extends CharBlocks implements IChunkGet { @Override public BaseBlock getFullBlock(int x, int y, int z) { - return BlockTypesCache.states[get(x, y, z)].toBaseBlock(); + BlockState state = BlockTypesCache.states[get(x, y, z)]; + return state.toBaseBlock(this, x, y, z); } @Override diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/blocks/CharSetBlocks.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/blocks/CharSetBlocks.java index 18d3c26cd..353f22cb7 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/blocks/CharSetBlocks.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/blocks/CharSetBlocks.java @@ -101,7 +101,7 @@ public class CharSetBlocks extends CharBlocks implements IChunkSet { @Override public boolean setTile(int x, int y, int z, CompoundTag tile) { if (tiles == null) { - tiles = new BlockVector3ChunkMap(); + tiles = new BlockVector3ChunkMap<>(); } tiles.put(x, y, z, tile); return true; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/visualization/cfi/HeightMapMCAGenerator.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/visualization/cfi/HeightMapMCAGenerator.java index 14b7d8d98..235c54b41 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/visualization/cfi/HeightMapMCAGenerator.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/visualization/cfi/HeightMapMCAGenerator.java @@ -1213,8 +1213,6 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr char combined = block.getDefaultState().getOrdinalChar(); mainArr[index] = combined; floorArr[index] = combined; - } else { - System.out.println("Block is null " + color + " | " + textureUtil.getClass()); } index++; } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/collection/MutablePair.java b/worldedit-core/src/main/java/com/boydti/fawe/object/collection/MutablePair.java index 6dc405979..e0196a6e6 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/collection/MutablePair.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/collection/MutablePair.java @@ -7,12 +7,12 @@ public class MutablePair implements Map.Entry { private V value; @Override public K getKey() { - return null; + return key; } @Override public V getValue() { - return null; + return value; } @Override diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/function/block/SimpleBlockCopy.java b/worldedit-core/src/main/java/com/boydti/fawe/object/function/block/SimpleBlockCopy.java index 9f3e40af5..261303402 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/function/block/SimpleBlockCopy.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/function/block/SimpleBlockCopy.java @@ -4,6 +4,7 @@ import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.RegionFunction; import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.world.block.BaseBlock; public class SimpleBlockCopy implements RegionFunction { diff --git a/worldedit-core/src/main/java/com/sk89q/jnbt/ByteArrayTag.java b/worldedit-core/src/main/java/com/sk89q/jnbt/ByteArrayTag.java index 791ee97ea..98fe8256f 100644 --- a/worldedit-core/src/main/java/com/sk89q/jnbt/ByteArrayTag.java +++ b/worldedit-core/src/main/java/com/sk89q/jnbt/ByteArrayTag.java @@ -25,6 +25,15 @@ import java.util.Locale; * The {@code TAG_Byte_Array} tag. */ public final class ByteArrayTag extends Tag { + @Override + public String getTypeName() { + return "TAG_Byte_Array"; + } + + @Override + public int getTypeCode() { + return NBTConstants.TYPE_BYTE_ARRAY; + } private final byte[] value; diff --git a/worldedit-core/src/main/java/com/sk89q/jnbt/ByteTag.java b/worldedit-core/src/main/java/com/sk89q/jnbt/ByteTag.java index 6ea46c1b0..e25d97f7e 100644 --- a/worldedit-core/src/main/java/com/sk89q/jnbt/ByteTag.java +++ b/worldedit-core/src/main/java/com/sk89q/jnbt/ByteTag.java @@ -23,6 +23,14 @@ package com.sk89q.jnbt; * The {@code TAG_Byte} tag. */ public final class ByteTag extends NumberTag { + @Override + public int getTypeCode() { + return NBTConstants.TYPE_BYTE; + } + @Override + public String getTypeName() { + return "TAG_Byte"; + } private final byte value; diff --git a/worldedit-core/src/main/java/com/sk89q/jnbt/CompoundTag.java b/worldedit-core/src/main/java/com/sk89q/jnbt/CompoundTag.java index 8768a3b39..fa65f39c7 100644 --- a/worldedit-core/src/main/java/com/sk89q/jnbt/CompoundTag.java +++ b/worldedit-core/src/main/java/com/sk89q/jnbt/CompoundTag.java @@ -32,6 +32,15 @@ import java.util.UUID; * The {@code TAG_Compound} tag. */ public class CompoundTag extends Tag { + @Override + public String getTypeName() { + return "TAG_Compound"; + } + + @Override + public int getTypeCode() { + return NBTConstants.TYPE_COMPOUND; + } private Map value; diff --git a/worldedit-core/src/main/java/com/sk89q/jnbt/DoubleTag.java b/worldedit-core/src/main/java/com/sk89q/jnbt/DoubleTag.java index 447aa44fd..5b0b67e00 100644 --- a/worldedit-core/src/main/java/com/sk89q/jnbt/DoubleTag.java +++ b/worldedit-core/src/main/java/com/sk89q/jnbt/DoubleTag.java @@ -24,6 +24,14 @@ package com.sk89q.jnbt; * */ public final class DoubleTag extends NumberTag { + @Override + public int getTypeCode() { + return NBTConstants.TYPE_DOUBLE; + } + @Override + public String getTypeName() { + return "TAG_Double"; + } private final double value; diff --git a/worldedit-core/src/main/java/com/sk89q/jnbt/EndTag.java b/worldedit-core/src/main/java/com/sk89q/jnbt/EndTag.java index 02da93f18..7731a0858 100644 --- a/worldedit-core/src/main/java/com/sk89q/jnbt/EndTag.java +++ b/worldedit-core/src/main/java/com/sk89q/jnbt/EndTag.java @@ -23,6 +23,15 @@ package com.sk89q.jnbt; * The {@code TAG_End} tag. */ public final class EndTag extends Tag { + @Override + public String getTypeName() { + return "TAG_End"; + } + + @Override + public int getTypeCode() { + return NBTConstants.TYPE_END; + } @Override public Object getValue() { diff --git a/worldedit-core/src/main/java/com/sk89q/jnbt/FloatTag.java b/worldedit-core/src/main/java/com/sk89q/jnbt/FloatTag.java index 7a4895810..17c400274 100644 --- a/worldedit-core/src/main/java/com/sk89q/jnbt/FloatTag.java +++ b/worldedit-core/src/main/java/com/sk89q/jnbt/FloatTag.java @@ -23,6 +23,14 @@ package com.sk89q.jnbt; * The {@code TAG_Float} tag. */ public final class FloatTag extends NumberTag { + @Override + public int getTypeCode() { + return NBTConstants.TYPE_FLOAT; + } + @Override + public String getTypeName() { + return "TAG_Float"; + } private final float value; diff --git a/worldedit-core/src/main/java/com/sk89q/jnbt/IntArrayTag.java b/worldedit-core/src/main/java/com/sk89q/jnbt/IntArrayTag.java index 584fd92f0..eb1f045d9 100644 --- a/worldedit-core/src/main/java/com/sk89q/jnbt/IntArrayTag.java +++ b/worldedit-core/src/main/java/com/sk89q/jnbt/IntArrayTag.java @@ -29,6 +29,15 @@ import java.util.Locale; * The {@code TAG_Int_Array} tag. */ public final class IntArrayTag extends Tag { + @Override + public String getTypeName() { + return "TAG_Int_Array"; + } + + @Override + public int getTypeCode() { + return NBTConstants.TYPE_INT_ARRAY; + } private final int[] value; diff --git a/worldedit-core/src/main/java/com/sk89q/jnbt/IntTag.java b/worldedit-core/src/main/java/com/sk89q/jnbt/IntTag.java index 1fa374cce..b3eb4e5c8 100644 --- a/worldedit-core/src/main/java/com/sk89q/jnbt/IntTag.java +++ b/worldedit-core/src/main/java/com/sk89q/jnbt/IntTag.java @@ -23,6 +23,14 @@ package com.sk89q.jnbt; * The {@code TAG_Int} tag. */ public final class IntTag extends NumberTag { + @Override + public int getTypeCode() { + return NBTConstants.TYPE_INT; + } + @Override + public String getTypeName() { + return "TAG_Int"; + } private final int value; diff --git a/worldedit-core/src/main/java/com/sk89q/jnbt/ListTag.java b/worldedit-core/src/main/java/com/sk89q/jnbt/ListTag.java index a13d01dec..8ad7590be 100644 --- a/worldedit-core/src/main/java/com/sk89q/jnbt/ListTag.java +++ b/worldedit-core/src/main/java/com/sk89q/jnbt/ListTag.java @@ -31,6 +31,15 @@ import javax.annotation.Nullable; * The {@code TAG_List} tag. */ public class ListTag extends Tag { + @Override + public String getTypeName() { + return "TAG_List"; + } + + @Override + public int getTypeCode() { + return NBTConstants.TYPE_LIST; + } private final Class type; private final List value; @@ -432,7 +441,7 @@ public class ListTag extends Tag { @Override public String toString() { StringBuilder bldr = new StringBuilder(); - bldr.append("TAG_List").append(": ").append(value.size()).append(" entries of type ").append(NBTUtils.getTypeName(type)).append("\r\n{\r\n"); + bldr.append("TAG_List").append(": ").append(value.size()).append(" entries of type ").append(type.getTypeName()).append("\r\n{\r\n"); for (Tag t : value) { bldr.append(" ").append(t.toString().replaceAll("\r\n", "\r\n ")).append("\r\n"); } diff --git a/worldedit-core/src/main/java/com/sk89q/jnbt/LongArrayTag.java b/worldedit-core/src/main/java/com/sk89q/jnbt/LongArrayTag.java index 88b7ff4d9..f368f70d8 100644 --- a/worldedit-core/src/main/java/com/sk89q/jnbt/LongArrayTag.java +++ b/worldedit-core/src/main/java/com/sk89q/jnbt/LongArrayTag.java @@ -29,6 +29,15 @@ import java.util.Locale; * The {@code TAG_Long_Array} tag. */ public class LongArrayTag extends Tag { + @Override + public String getTypeName() { + return "TAG_Long_Array"; + } + + @Override + public int getTypeCode() { + return NBTConstants.TYPE_LONG_ARRAY; + } private final long[] value; diff --git a/worldedit-core/src/main/java/com/sk89q/jnbt/LongTag.java b/worldedit-core/src/main/java/com/sk89q/jnbt/LongTag.java index efb8ec3d0..9608ef540 100644 --- a/worldedit-core/src/main/java/com/sk89q/jnbt/LongTag.java +++ b/worldedit-core/src/main/java/com/sk89q/jnbt/LongTag.java @@ -24,6 +24,14 @@ package com.sk89q.jnbt; * */ public final class LongTag extends NumberTag { + @Override + public int getTypeCode() { + return NBTConstants.TYPE_LONG; + } + @Override + public String getTypeName() { + return "TAG_Long"; + } private final long value; diff --git a/worldedit-core/src/main/java/com/sk89q/jnbt/NBTOutputStream.java b/worldedit-core/src/main/java/com/sk89q/jnbt/NBTOutputStream.java index 107cbaae6..15c9f2a04 100644 --- a/worldedit-core/src/main/java/com/sk89q/jnbt/NBTOutputStream.java +++ b/worldedit-core/src/main/java/com/sk89q/jnbt/NBTOutputStream.java @@ -90,7 +90,7 @@ public final class NBTOutputStream extends OutputStream implements Closeable, Da checkNotNull(name); checkNotNull(tag); - int type = NBTUtils.getTypeCode(tag.getClass()); + int type = tag.getTypeCode(); writeNamedTagName(name, type); if (type == NBTConstants.TYPE_END) { @@ -189,7 +189,7 @@ public final class NBTOutputStream extends OutputStream implements Closeable, Da } public void writeTag(Tag tag) throws IOException { - int type = NBTUtils.getTypeCode(tag.getClass()); + int type = tag.getTypeCode(); os.writeByte(type); writeTagPayload(tag); } @@ -207,7 +207,7 @@ public final class NBTOutputStream extends OutputStream implements Closeable, Da * if an I/O error occurs. */ public void writeTagPayload(Tag tag) throws IOException { - int type = NBTUtils.getTypeCode(tag.getClass()); + int type = tag.getTypeCode(); switch (type) { case NBTConstants.TYPE_END: writeEndTagPayload((EndTag) tag); @@ -311,7 +311,7 @@ public final class NBTOutputStream extends OutputStream implements Closeable, Da int size = tags.size(); if (!tags.isEmpty()) { Tag tag0 = tags.get(0); - os.writeByte(NBTUtils.getTypeCode(tag0.getClass())); + os.writeByte(tag0.getTypeCode()); } else { os.writeByte(NBTUtils.getTypeCode(clazz)); } diff --git a/worldedit-core/src/main/java/com/sk89q/jnbt/NBTUtils.java b/worldedit-core/src/main/java/com/sk89q/jnbt/NBTUtils.java index d35626ed9..0199ad04b 100644 --- a/worldedit-core/src/main/java/com/sk89q/jnbt/NBTUtils.java +++ b/worldedit-core/src/main/java/com/sk89q/jnbt/NBTUtils.java @@ -49,7 +49,7 @@ public final class NBTUtils { return "TAG_Byte_Array"; } else if (clazz.equals(ByteTag.class)) { return "TAG_Byte"; - } else if (clazz.equals(CompoundTag.class)) { + } else if (CompoundTag.class.isAssignableFrom(clazz)) { return "TAG_Compound"; } else if (clazz.equals(DoubleTag.class)) { return "TAG_Double"; @@ -89,7 +89,7 @@ public final class NBTUtils { return NBTConstants.TYPE_BYTE_ARRAY; } else if (clazz.equals(ByteTag.class)) { return NBTConstants.TYPE_BYTE; - } else if (clazz.equals(CompoundTag.class)) { + } else if (CompoundTag.class.isAssignableFrom(clazz)) { return NBTConstants.TYPE_COMPOUND; } else if (clazz.equals(DoubleTag.class)) { return NBTConstants.TYPE_DOUBLE; diff --git a/worldedit-core/src/main/java/com/sk89q/jnbt/ShortTag.java b/worldedit-core/src/main/java/com/sk89q/jnbt/ShortTag.java index 212958ef4..8b6474efc 100644 --- a/worldedit-core/src/main/java/com/sk89q/jnbt/ShortTag.java +++ b/worldedit-core/src/main/java/com/sk89q/jnbt/ShortTag.java @@ -23,6 +23,14 @@ package com.sk89q.jnbt; * The {@code TAG_Short} tag. */ public final class ShortTag extends NumberTag { + @Override + public int getTypeCode() { + return NBTConstants.TYPE_SHORT; + } + @Override + public String getTypeName() { + return "TAG_Short"; + } private final short value; diff --git a/worldedit-core/src/main/java/com/sk89q/jnbt/StringTag.java b/worldedit-core/src/main/java/com/sk89q/jnbt/StringTag.java index 5a2c504a8..b78be1699 100644 --- a/worldedit-core/src/main/java/com/sk89q/jnbt/StringTag.java +++ b/worldedit-core/src/main/java/com/sk89q/jnbt/StringTag.java @@ -25,6 +25,15 @@ import static com.google.common.base.Preconditions.checkNotNull; * The {@code TAG_String} tag. */ public final class StringTag extends Tag { + @Override + public String getTypeName() { + return "TAG_String"; + } + + @Override + public int getTypeCode() { + return NBTConstants.TYPE_STRING; + } private final String value; diff --git a/worldedit-core/src/main/java/com/sk89q/jnbt/Tag.java b/worldedit-core/src/main/java/com/sk89q/jnbt/Tag.java index d7c273b17..02881d9d7 100644 --- a/worldedit-core/src/main/java/com/sk89q/jnbt/Tag.java +++ b/worldedit-core/src/main/java/com/sk89q/jnbt/Tag.java @@ -35,4 +35,8 @@ public abstract class Tag { return getValue(); } + public abstract int getTypeCode(); + + public abstract String getTypeName(); + } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/BrushCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/BrushCommands.java index 3aa230beb..cab68fa5e 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/BrushCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/BrushCommands.java @@ -154,15 +154,6 @@ public class BrushCommands { this.worldEdit = worldEdit; } - @Command( - name = "none", - aliases = "unbind", - desc = "Unbind a bound brush from your current item" - ) - void none(Player player, LocalSession session) throws WorldEditException { - ToolCommands.setToolNone(player, session, "Brush"); - } - @Command( name = "blendball", aliases = {"bb", "blend"}, @@ -959,52 +950,6 @@ public class BrushCommands { return process(player, arguments, bs); } - @Command( - name = "forest", - desc = "Forest brush, creates a forest in the area" - ) - @CommandPermissions("worldedit.brush.forest") - public void forest(Player player, LocalSession localSession, - @Arg(desc = "The shape of the region") - RegionFactory shape, - @Arg(desc = "The size of the brush", def = "5") - Expression radius, - @Arg(desc = "The density of the brush", def = "20") - double density, - @Arg(desc = "The type of tree to use") - TreeGenerator.TreeType type) throws WorldEditException, EvaluationException { - setOperationBasedBrush(player, localSession, radius, - new Paint(new TreeGeneratorFactory(type), density / 100), shape, "worldedit.brush.forest"); - } - - @Command( - name = "raise", - desc = "Raise brush, raise all blocks by one" - ) - @CommandPermissions("worldedit.brush.raise") - public void raise(Player player, LocalSession localSession, - @Arg(desc = "The shape of the region") - RegionFactory shape, - @Arg(desc = "The size of the brush", def = "5") - Expression radius) throws WorldEditException, EvaluationException { - setOperationBasedBrush(player, localSession, radius, - new Deform("y-=1"), shape, "worldedit.brush.raise"); - } - - @Command( - name = "lower", - desc = "Lower brush, lower all blocks by one" - ) - @CommandPermissions("worldedit.brush.lower") - public void lower(Player player, LocalSession localSession, - @Arg(desc = "The shape of the region") - RegionFactory shape, - @Arg(desc = "The size of the brush", def = "5") - Expression radius) throws WorldEditException, EvaluationException { - setOperationBasedBrush(player, localSession, radius, - new Deform("y+=1"), shape, "worldedit.brush.lower"); - } - @Command( name = "savebrush", aliases = {"save"}, @@ -1139,7 +1084,7 @@ public class BrushCommands { @Arg(desc = "The shape of the region") RegionFactory shape, @Arg(desc = "The size of the brush", def = "5") - double radius, + Expression radius, @Arg(desc = "The pattern of blocks to set") Pattern pattern) throws WorldEditException { setOperationBasedBrush(player, localSession, radius, @@ -1155,7 +1100,7 @@ public class BrushCommands { @Arg(desc = "The shape of the region") RegionFactory shape, @Arg(desc = "The size of the brush", def = "5") - double radius, + Expression radius, @Arg(desc = "The density of the brush", def = "20") double density, @Arg(desc = "The type of tree to use") @@ -1173,7 +1118,7 @@ public class BrushCommands { @Arg(desc = "The shape of the region") RegionFactory shape, @Arg(desc = "The size of the brush", def = "5") - double radius) throws WorldEditException { + Expression radius) throws WorldEditException { setOperationBasedBrush(player, localSession, radius, new Deform("y-=1"), shape, "worldedit.brush.raise"); } @@ -1187,7 +1132,7 @@ public class BrushCommands { @Arg(desc = "The shape of the region") RegionFactory shape, @Arg(desc = "The size of the brush", def = "5") - double radius) throws WorldEditException { + Expression radius) throws WorldEditException { setOperationBasedBrush(player, localSession, radius, new Deform("y+=1"), shape, "worldedit.brush.lower"); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/RegionCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/RegionCommands.java index 1b0cfda34..9b785c15c 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/RegionCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/RegionCommands.java @@ -110,28 +110,26 @@ public class RegionCommands { } @Command( - name = "/set", - desc = "Sets all the blocks in the region" + name = "/set", + aliases = {"/"}, + desc = "Sets all the blocks in the region" ) @CommandPermissions("worldedit.region.set") @Logging(REGION) public int set(Actor actor, EditSession editSession, @Selection Region region, @Arg(desc = "The pattern of blocks to set") - Pattern pattern) { - RegionFunction set = new BlockReplace(editSession, pattern); - RegionVisitor visitor = new RegionVisitor(region, set); - - Operations.completeBlindly(visitor); - List messages = Lists.newArrayList(); - visitor.addStatusMessages(messages); - if (messages.isEmpty()) { - actor.print("Operation completed."); - } else { - actor.print("Operation completed (" + Joiner.on(", ").join(messages) + ")."); - } - - return visitor.getAffected(); + Pattern pattern, + InjectedValueAccess context) { + actor.checkConfirmationRegion(() -> { + int affected = editSession.setBlocks(region, pattern); + if (affected != 0) { + BBC.OPERATION.send(actor, affected); + if (!actor.hasPermission("fawe.tips")) + BBC.TIP_FAST.or(BBC.TIP_CANCEL, BBC.TIP_MASK, BBC.TIP_MASK_ANGLE, BBC.TIP_SET_LINEAR, BBC.TIP_SURFACE_SPREAD, BBC.TIP_SET_HAND).send(actor); + } + }, getArguments(context), region, context); + return 0; } @Command( @@ -147,27 +145,6 @@ public class RegionCommands { set(actor, editSession, region, BlockTypes.AIR, context); } - @Command( - name = "/set", - aliases = {"/"}, - desc = "Sets all the blocks in the region" - ) - @CommandPermissions("worldedit.region.set") - @Logging(REGION) - public void set(Actor actor, EditSession editSession, - @Selection Region region, - @Arg(desc = "The pattern of blocks to set") - Pattern pattern, InjectedValueAccess context) throws WorldEditException { - actor.checkConfirmationRegion(() -> { - int affected = editSession.setBlocks(region, pattern); - if (affected != 0) { - BBC.OPERATION.send(actor, affected); - if (!actor.hasPermission("fawe.tips")) - BBC.TIP_FAST.or(BBC.TIP_CANCEL, BBC.TIP_MASK, BBC.TIP_MASK_ANGLE, BBC.TIP_SET_LINEAR, BBC.TIP_SURFACE_SPREAD, BBC.TIP_SET_HAND).send(actor); - } - }, getArguments(context), region, context); - } - @Command( name = "/test", desc = "test region" @@ -175,13 +152,11 @@ public class RegionCommands { @CommandPermissions("worldedit.region.test") @Logging(REGION) public void test(Player player, EditSession editSession, @Selection Region region, @Arg(desc = "hello there") BiomeType biome) throws WorldEditException { - System.out.println("Test start"); editSession.addProcessor(new ChunkSendProcessor(editSession.getWorld(), () -> Collections.singleton(player))); editSession.addProcessor(NullProcessor.INSTANCE); FlatRegionFunction replace = new BiomeReplace(editSession, biome); FlatRegionVisitor visitor = new FlatRegionVisitor(Regions.asFlatRegion(region), replace); Operations.completeLegacy(visitor); - System.out.println("Test end"); } @Command( diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/ToolUtilCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/ToolUtilCommands.java index 39b5e502c..b65211bf0 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/ToolUtilCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/ToolUtilCommands.java @@ -179,9 +179,9 @@ public class ToolUtilCommands { } @Command( - name = "/", - aliases = { "," }, - desc = "Toggle the super pickaxe function" + name = "/superpickaxe", + aliases = {",", "/sp", "/pickaxe"}, + desc = "Toggle the super pickaxe function" ) @CommandPermissions("worldedit.superpickaxe") public void togglePickaxe(Player player, LocalSession session, diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/WorldEditCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/WorldEditCommands.java index b6b3bd828..5ba3612f3 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/WorldEditCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/WorldEditCommands.java @@ -56,7 +56,7 @@ import org.enginehub.piston.annotation.param.Arg; import org.enginehub.piston.annotation.param.ArgFlag; import org.enginehub.piston.annotation.param.Switch; -@CommandContainer(superTypes = CommandPermissionsConditionGenerator.Registration.class) +@CommandContainer(superTypes = {CommandPermissionsConditionGenerator.Registration.class, CommandQueuedConditionGenerator.Registration.class}) public class WorldEditCommands { private static final DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss z"); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/Capability.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/Capability.java index 94f5115ec..0e43e960a 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/Capability.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/Capability.java @@ -79,6 +79,7 @@ public enum Capability { * The capability of a platform to perform modifications to a world. */ WORLD_EDITING { + /* @Override void initialize(PlatformManager platformManager, Platform platform) { BlockRegistry blockRegistry = platform.getRegistries().getBlockRegistry(); @@ -93,6 +94,7 @@ public enum Capability { void unload(PlatformManager platformManager, Platform platform) { BlockStateIdAccess.clear(); } + */ }; void initialize(PlatformManager platformManager, Platform platform) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/block/BlockStateIdAccess.java b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/block/BlockStateIdAccess.java index c62b96225..8a3d988f9 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/block/BlockStateIdAccess.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/block/BlockStateIdAccess.java @@ -31,7 +31,7 @@ import java.util.OptionalInt; import static com.google.common.base.Preconditions.checkState; public final class BlockStateIdAccess { - + /* private static final BiMap ASSIGNED_IDS = HashBiMap.create(2 << 13); public static OptionalInt getBlockStateId(BlockState holder) { @@ -49,7 +49,7 @@ public final class BlockStateIdAccess { * {@link OptionalInt#empty()}. In those cases, we will use our own ID system, * since it's useful for other entries as well. * @return an unused ID in WorldEdit's ID tracker - */ + / private static int provideUnusedWorldEditId() { return usedIds.nextClearBit(0); } @@ -73,5 +73,12 @@ public final class BlockStateIdAccess { private BlockStateIdAccess() { } + */ + public static OptionalInt getBlockStateId(BlockState holder) { + return OptionalInt.of(holder.getOrdinal()); + } + public static @Nullable BlockState getBlockStateById(int id) { + return BlockState.getFromOrdinal(id); + } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BaseBlock.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BaseBlock.java index 7bd73161a..631cc8204 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BaseBlock.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BaseBlock.java @@ -21,6 +21,7 @@ package com.sk89q.worldedit.world.block; import static com.google.common.base.Preconditions.checkNotNull; +import com.boydti.fawe.beta.ITileInput; import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.StringTag; import com.sk89q.jnbt.Tag; @@ -162,11 +163,6 @@ public class BaseBlock implements BlockStateHolder, TileEntityBlock { return this.nbtData; } - @Override - public void setNbtData(@Nullable CompoundTag nbtData) { - throw new UnsupportedOperationException("This class is immutable."); - } - /** * Checks whether the type ID and data value are equal. */ diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockState.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockState.java index ba10d1e30..ea2924cf9 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockState.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockState.java @@ -19,6 +19,7 @@ package com.sk89q.worldedit.world.block; +import com.boydti.fawe.beta.ITileInput; import com.boydti.fawe.command.SuggestInputParseException; import com.boydti.fawe.object.string.MutableCharSequence; import com.boydti.fawe.util.StringMan; @@ -53,7 +54,8 @@ public class BlockState implements BlockStateHolder, FawePattern { private final char ordinalChar; private final BlockType blockType; private BlockMaterial material; - private BaseBlock emptyBaseBlock; + private final BaseBlock emptyBaseBlock; + private CompoundInput compoundInput = CompoundInput.NULL; protected BlockState(BlockType blockType, int internalId, int ordinal) { this.blockType = blockType; @@ -196,7 +198,6 @@ public class BlockState implements BlockStateHolder, FawePattern { case '=': { charSequence.setSubstring(last, i); property = (AbstractProperty) type.getPropertyMap().get(charSequence); - if (property == null) System.out.println("No prop " + charSequence + " | " + type.getPropertyMap()); last = i + 1; break; } @@ -356,6 +357,9 @@ public class BlockState implements BlockStateHolder, FawePattern { return this.material = blockType.getMaterial(); } this.material = WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.GAME_HOOKS).getRegistries().getBlockRegistry().getMaterial(this); + if (this.material.hasContainer()) { + this.compoundInput = CompoundInput.CONTAINER; + } } return material; } @@ -388,4 +392,17 @@ public class BlockState implements BlockStateHolder, FawePattern { public int hashCode() { return getOrdinal(); } + + public boolean isAir() { + try { + return material.isAir(); + } catch (NullPointerException ignore) { + return getMaterial().isAir(); + } + } + + @Override + public BaseBlock toBaseBlock(ITileInput input, int x, int y, int z) { + return compoundInput.get(this, input, x, y, z); + } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockStateHolder.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockStateHolder.java index a1d6e28d4..93c85be90 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockStateHolder.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockStateHolder.java @@ -19,7 +19,9 @@ package com.sk89q.worldedit.world.block; +import com.boydti.fawe.beta.ITileInput; import com.sk89q.jnbt.CompoundTag; +import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.blocks.TileEntityBlock; import com.sk89q.worldedit.extent.OutputExtent; @@ -203,6 +205,10 @@ public interface BlockStateHolder> extends FawePat throw new UnsupportedOperationException("State is immutable"); } + default BaseBlock toBaseBlock(ITileInput input, int x, int y, int z) { + throw new UnsupportedOperationException("State is immutable"); + } + default String getAsString() { if (getStates().isEmpty()) { return this.getBlockType().getId(); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/CompoundInput.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/CompoundInput.java new file mode 100644 index 000000000..a6556a3db --- /dev/null +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/CompoundInput.java @@ -0,0 +1,18 @@ +package com.sk89q.worldedit.world.block; + +import com.boydti.fawe.beta.ITileInput; + +public enum CompoundInput { + NULL, + CONTAINER() { + @Override + public BaseBlock get(BlockState state, ITileInput input, int x, int y, int z) { + return state.toBaseBlock(input.getTag(x, y, z)); + } + } + + ; + public BaseBlock get(BlockState state, ITileInput input, int x, int y, int z) { + return state.toBaseBlock(); + } +} \ No newline at end of file diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/ImmutableBaseBlock.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/ImmutableBaseBlock.java index 08469e2c6..fcc6c1945 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/ImmutableBaseBlock.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/ImmutableBaseBlock.java @@ -1,5 +1,6 @@ package com.sk89q.worldedit.world.block; +import com.boydti.fawe.beta.ITileInput; import com.sk89q.jnbt.CompoundTag; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.extent.Extent; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/item/ItemTypes.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/item/ItemTypes.java index 40ca7fc86..e74990435 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/item/ItemTypes.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/item/ItemTypes.java @@ -934,7 +934,6 @@ public final class ItemTypes { } String name = fieldsTmp[initIndex++].getName().toLowerCase(Locale.ROOT); CharSequence fullName = joined.init(ItemType.REGISTRY.getDefaultNamespace(), ':', name); - System.out.println("Name " + fullName + " | " + ItemType.REGISTRY.getMap().get(fullName)); return ItemType.REGISTRY.getMap().get(fullName); } catch (Throwable e) { e.printStackTrace();