From 8897109dc4f942dcf94edff6730d9606f88fda7a Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Thu, 4 Apr 2019 00:25:16 +1100 Subject: [PATCH] wip upstream merge --- .../adapter/v1_13_1/Spigot_v1_13_R2.java | 2 +- .../fawe/bukkit/v0/FaweAdapter_All.java | 2 +- .../fawe/bukkit/wrapper/AsyncBlock.java | 2 +- .../fawe/bukkit/wrapper/AsyncWorld.java | 3 +- .../main/java/com/boydti/fawe/FaweCache.java | 17 ---- .../com/boydti/fawe/command/CFICommands.java | 6 +- .../boydti/fawe/example/MappedFaweQueue.java | 2 +- .../jnbt/anvil/HeightMapMCAGenerator.java | 22 +++-- .../com/boydti/fawe/jnbt/anvil/MCAQueue.java | 2 +- .../filters/DeleteBiomeFilterSimple.java | 2 +- .../fawe/object/ChangeSetFaweQueue.java | 6 +- .../com/boydti/fawe/object/FaweChunk.java | 4 +- .../com/boydti/fawe/object/FaweQueue.java | 2 +- .../visualization/ImmutableVirtualWorld.java | 3 +- .../object/change/MutableBiomeChange.java | 17 ++-- .../fawe/object/changeset/FaweChangeSet.java | 12 +-- .../object/changeset/FaweStreamChangeSet.java | 8 +- .../clipboard/CPUOptimizedClipboard.java | 10 +- .../object/clipboard/ReadOnlyClipboard.java | 2 +- .../object/extent/FastWorldEditExtent.java | 6 +- .../fawe/object/pattern/PatternExtent.java | 2 +- .../object/queue/FaweQueueDelegateExtent.java | 4 +- .../fawe/object/queue/IDelegateFaweQueue.java | 4 +- .../fawe/object/queue/NullFaweQueue.java | 2 +- .../object/schematic/visualizer/SchemVis.java | 2 +- .../general/plot/FaweLocalBlockQueue.java | 3 +- .../com/boydti/fawe/util/ReflectionUtils.java | 3 + .../com/sk89q/worldedit/LocalSession.java | 34 +++---- .../java/com/sk89q/worldedit/WorldEdit.java | 5 +- .../worldedit/command/BiomeCommands.java | 14 ++- .../worldedit/command/GeneralCommands.java | 1 + .../worldedit/command/GenerationCommands.java | 13 ++- .../worldedit/command/RegionCommands.java | 8 +- .../worldedit/command/SchematicCommands.java | 6 +- .../worldedit/command/SelectionCommands.java | 7 +- .../command/tool/FloatingTreeRemover.java | 7 +- .../command/tool/brush/GravityBrush.java | 9 +- .../event/extent/EditSessionEvent.java | 1 + .../extension/factory/PatternFactory.java | 1 + .../extension/platform/CommandManager.java | 5 +- .../extent/clipboard/io/ClipboardFormats.java | 2 + .../transform/BlockTransformExtent.java | 5 +- .../worldedit/function/factory/Deform.java | 5 +- .../function/pattern/RandomPattern.java | 5 + .../worldedit/world/biome/BiomeTypes.java | 6 ++ .../worldedit/world/block/BlockState.java | 44 ++++----- .../worldedit/world/block/BlockType.java | 94 ++++++++++--------- .../worldedit/world/block/BlockTypeEnum.java | 5 + .../sk89q/worldedit/world/item/ItemType.java | 1 + .../sk89q/worldedit/world/item/ItemTypes.java | 4 + .../world/registry/BundledItemRegistry.java | 7 -- .../world/registry/LegacyMapper.java | 6 +- 52 files changed, 236 insertions(+), 209 deletions(-) create mode 100644 worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockTypeEnum.java diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/v1_13_1/Spigot_v1_13_R2.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/v1_13_1/Spigot_v1_13_R2.java index 628956cdf..87dc52811 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/v1_13_1/Spigot_v1_13_R2.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/v1_13_1/Spigot_v1_13_R2.java @@ -189,7 +189,7 @@ public final class Spigot_v1_13_R2 extends CachedBukkitAdapter implements Bukkit // ------------------------------------------------------------------------ @Override - public int getBiomeId(Biome biome) { + public BiomeType getBiomeId(Biome biome) { BiomeBase mcBiome = CraftBlock.biomeToBiomeBase(biome); return mcBiome != null ? IRegistry.BIOME.a(mcBiome) : 0; } diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/v0/FaweAdapter_All.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/v0/FaweAdapter_All.java index 6c8dbb19b..05b1ad04c 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/v0/FaweAdapter_All.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/v0/FaweAdapter_All.java @@ -352,7 +352,7 @@ // } // // @Override -// public int getBiomeId(Biome biome) { +// public BiomeType getBiomeType(Biome biome) { // try { // Object biomeBase = biomeToBiomeBase.invoke(null, biome); // if (biomeBase != null) return (int) biomeBaseToTypeId.invoke(null, biomeBase); diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/wrapper/AsyncBlock.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/wrapper/AsyncBlock.java index a41583620..9a1d6dee3 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/wrapper/AsyncBlock.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/wrapper/AsyncBlock.java @@ -232,7 +232,7 @@ public class AsyncBlock implements Block { @Override public Biome getBiome() { - return world.getAdapter().getBiome(queue.getBiomeId(x, z)); + return world.getAdapter().getBiome(queue.getBiomeType(x, z)); } @Override diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/wrapper/AsyncWorld.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/wrapper/AsyncWorld.java index 5a3b87c54..381a13700 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/wrapper/AsyncWorld.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/wrapper/AsyncWorld.java @@ -20,7 +20,6 @@ import java.util.Set; import java.util.UUID; import java.util.concurrent.CompletableFuture; import java.util.function.Predicate; -import java.util.function.Supplier; import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockTypes; @@ -859,7 +858,7 @@ public class AsyncWorld extends DelegateFaweQueue implements World, HasFaweQueue @Override public Biome getBiome(int x, int z) { - return adapter.getBiome(queue.getBiomeId(x, z)); + return adapter.getBiome(queue.getBiomeType(x, z)); } @Override diff --git a/worldedit-core/src/main/java/com/boydti/fawe/FaweCache.java b/worldedit-core/src/main/java/com/boydti/fawe/FaweCache.java index b9b1d572f..c48e4035e 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/FaweCache.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/FaweCache.java @@ -29,24 +29,7 @@ public class FaweCache { */ public final static byte[][] CACHE_Z = new byte[16][]; - /** - * Immutable biome cache - */ - public final static BiomeType[] CACHE_BIOME = new BiomeType[256]; - - public static final BiomeType getBiome(int id) { - return CACHE_BIOME[id]; - } - static { - for (int i = 0; i < 256; i++) { - CACHE_BIOME[i] = new BiomeType(i) { - @Override - public void setId(int id) { - throw new IllegalStateException("Cannot set id"); - } - }; - } CACHE_X[0] = new byte[4096]; CACHE_Z[0] = new byte[4096]; for (int y = 0; y < 16; y++) { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/command/CFICommands.java b/worldedit-core/src/main/java/com/boydti/fawe/command/CFICommands.java index e6f4450fd..67247737a 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/command/CFICommands.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/command/CFICommands.java @@ -529,9 +529,9 @@ public class CFICommands extends MethodCommands { @CommandPermissions("worldedit.anvil.cfi") public void biome(FawePlayer fp, BiomeType biome, @Optional FawePrimitiveBinding.ImageUri image, @Optional Mask mask, @Switch('w') boolean disableWhiteOnly) throws ParameterException{ HeightMapMCAGenerator gen = assertSettings(fp).getGenerator(); - if (image != null) gen.setBiome(load(image), (byte) biome.getId(), !disableWhiteOnly); - else if (mask != null) gen.setBiome(mask, (byte) biome.getId()); - else gen.setBiome((byte) biome.getId()); + if (image != null) gen.setBiome(load(image), biome, !disableWhiteOnly); + else if (mask != null) gen.setBiome(mask, biome); + else gen.setBiome(biome); msg("Set biome!").send(fp); assertSettings(fp).resetComponent(); component(fp); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/example/MappedFaweQueue.java b/worldedit-core/src/main/java/com/boydti/fawe/example/MappedFaweQueue.java index 7d74a622d..81f5cf836 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/example/MappedFaweQueue.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/example/MappedFaweQueue.java @@ -753,7 +753,7 @@ public abstract class MappedFaweQueue impl } @Override - public int getBiomeId(int x, int z) throws FaweException.FaweChunkLoadException { + public BiomeType getBiomeType(int x, int z) throws FaweException.FaweChunkLoadException { int cx = x >> 4; int cz = z >> 4; lastSectionY = -1; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/jnbt/anvil/HeightMapMCAGenerator.java b/worldedit-core/src/main/java/com/boydti/fawe/jnbt/anvil/HeightMapMCAGenerator.java index 2ef575d45..23cc02cf6 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/jnbt/anvil/HeightMapMCAGenerator.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/jnbt/anvil/HeightMapMCAGenerator.java @@ -1,7 +1,6 @@ package com.boydti.fawe.jnbt.anvil; import com.boydti.fawe.Fawe; -import com.boydti.fawe.FaweCache; import com.boydti.fawe.example.SimpleIntFaweChunk; import com.boydti.fawe.object.*; import com.boydti.fawe.object.brush.visualization.VirtualWorld; @@ -17,6 +16,7 @@ import com.boydti.fawe.util.image.ImageViewer; import com.sk89q.jnbt.CompoundTag; import com.sk89q.worldedit.*; import com.sk89q.worldedit.math.MutableBlockVector3; +import com.sk89q.worldedit.world.biome.BiomeTypes; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.blocks.BaseItemStack; import com.sk89q.worldedit.extent.clipboard.Clipboard; @@ -744,7 +744,7 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr public boolean setBiome(int x, int z, BiomeType biome) { int index = z * getWidth() + x; if (index < 0 || index >= getArea()) return false; - biomes.setByte(index, (byte) biome.getId()); + biomes.setByte(index, (byte) biome.getInternalId()); return true; } @@ -920,7 +920,7 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr } @Override - public int getBiomeId(int x, int z) throws FaweException.FaweChunkLoadException { + public BiomeType getBiomeType(int x, int z) throws FaweException.FaweChunkLoadException { int index = z * getWidth() + x; if (index < 0 || index >= getArea()) index = Math.floorMod(index, getArea()); return biomes.getByte(index) & 0xFF; @@ -1011,7 +1011,7 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr @Override public BiomeType getBiome(BlockVector2 position) { - return FaweCache.CACHE_BIOME[getBiomeId(position.getBlockX(), position.getBlockZ())]; + return BiomeTypes.get(getBiomeType(position.getBlockX(), position.getBlockZ())); } @Override @@ -1069,9 +1069,10 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr return heights.getByte(index) & 0xFF; } - public void setBiome(BufferedImage img, byte biome, boolean white) { + public void setBiome(BufferedImage img, BiomeType biome, boolean white) { if (img.getWidth() != getWidth() || img.getHeight() != getLength()) throw new IllegalArgumentException("Input image dimensions do not match the current height map!"); + byte biomeByte = (byte) biome.getInternalId(); biomes.record(new Runnable() { @Override public void run() { @@ -1082,7 +1083,7 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr int height = img.getRGB(x, z) & 0xFF; if (height == 255 || height > 0 && !white && ThreadLocalRandom.current() .nextInt(256) <= height) { - biomeArr[index] = biome; + biomeArr[index] = biomeByte; } } } @@ -1317,8 +1318,9 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr })); } - public void setBiome(Mask mask, byte biome) { + public void setBiome(Mask mask, BiomeType biome) { int index = 0; + byte biomeByte = (byte) biome.getInternalId(); for (int z = 0; z < getLength(); z++) { mutable.mutZ(z); for (int x = 0; x < getWidth(); x++, index++) { @@ -1326,7 +1328,7 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr mutable.mutX(x); mutable.mutY(y); if (mask.test(mutable)) { - biomes.setByte(index, biome); + biomes.setByte(index, biomeByte); } } } @@ -1528,8 +1530,8 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr } } - public void setBiome(int biome) { - biomes.record(() -> Arrays.fill(biomes.get(), (byte) biome)); + public void setBiome(BiomeType biome) { + biomes.record(() -> Arrays.fill(biomes.get(), (byte) biome.getInternalId())); } public void setFloor(Pattern value) { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/jnbt/anvil/MCAQueue.java b/worldedit-core/src/main/java/com/boydti/fawe/jnbt/anvil/MCAQueue.java index a7094e00f..7010e0aa2 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/jnbt/anvil/MCAQueue.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/jnbt/anvil/MCAQueue.java @@ -90,7 +90,7 @@ public class MCAQueue extends NMSMappedFaweQueue implements Callable { return null; } - public abstract byte[] getBiomeArray(); + public abstract BiomeType[] getBiomeArray(); public void forEachQueuedBlock(FaweChunkVisitor onEach) { for (int y = 0; y < HEIGHT; y++) { @@ -290,7 +290,7 @@ public abstract class FaweChunk implements Callable { public abstract CompoundTag getTile(int x, int y, int z); public void setBiome(final int x, final int z, final BiomeType biome) { - setBiome(x, z, (byte) biome.getId()); + setBiome(x, z, biome); } public abstract void setBiome(final int x, final int z, final byte biome); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/FaweQueue.java b/worldedit-core/src/main/java/com/boydti/fawe/object/FaweQueue.java index af269ec9a..f8c079625 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/FaweQueue.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/FaweQueue.java @@ -400,7 +400,7 @@ public interface FaweQueue extends HasFaweQueue, Extent { return getCombinedId4Data(x, y, z) != 0; } - int getBiomeId(int x, int z) throws FaweException.FaweChunkLoadException; + BiomeType getBiomeType(int x, int z) throws FaweException.FaweChunkLoadException; int getCombinedId4Data(int x, int y, int z) throws FaweException.FaweChunkLoadException; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/visualization/ImmutableVirtualWorld.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/visualization/ImmutableVirtualWorld.java index e68a756ab..adec43732 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/visualization/ImmutableVirtualWorld.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/visualization/ImmutableVirtualWorld.java @@ -9,6 +9,7 @@ import com.boydti.fawe.object.exception.FaweException; import com.boydti.fawe.util.SetQueue; import com.sk89q.jnbt.CompoundTag; import com.sk89q.worldedit.*; +import com.sk89q.worldedit.world.biome.BiomeTypes; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.blocks.BaseItemStack; import com.sk89q.worldedit.function.operation.Operation; @@ -62,7 +63,7 @@ public abstract class ImmutableVirtualWorld implements VirtualWorld { @Override public BiomeType getBiome(BlockVector2 position) { - return FaweCache.getBiome(0); + return BiomeTypes.FOREST; } @Override diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/change/MutableBiomeChange.java b/worldedit-core/src/main/java/com/boydti/fawe/object/change/MutableBiomeChange.java index a0775bf47..599c0fca5 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/change/MutableBiomeChange.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/change/MutableBiomeChange.java @@ -5,31 +5,32 @@ import com.sk89q.worldedit.history.UndoContext; import com.sk89q.worldedit.history.change.Change; import com.sk89q.worldedit.math.MutableBlockVector2; import com.sk89q.worldedit.world.biome.BiomeType; +import com.sk89q.worldedit.world.biome.BiomeTypes; public class MutableBiomeChange implements Change { private MutableBlockVector2 mutable = new MutableBlockVector2(); - private BiomeType from; - private BiomeType to; + private int from; + private int to; public MutableBiomeChange() { - this.from = new BiomeType(0); - this.to = new BiomeType(0); + this.from = 0; + this.to = 0; } public void setBiome(int x, int z, int from, int to) { mutable.setComponents(x, z); - this.from.setId(from); - this.to.setId(to); + this.from = from; + this.to = to; } @Override public void undo(UndoContext context) throws WorldEditException { - context.getExtent().setBiome(mutable, from); + context.getExtent().setBiome(mutable, BiomeTypes.get(from)); } @Override public void redo(UndoContext context) throws WorldEditException { - context.getExtent().setBiome(mutable, to); + context.getExtent().setBiome(mutable, BiomeTypes.get(to)); } } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/FaweChangeSet.java b/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/FaweChangeSet.java index 5e439e2d5..bd9edd915 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/FaweChangeSet.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/FaweChangeSet.java @@ -268,16 +268,16 @@ public abstract class FaweChangeSet implements ChangeSet { synchronized (FaweChangeSet.this) { // Biome changes if (previous.getBiomeArray() != null) { - byte[] previousBiomes = previous.getBiomeArray(); - byte[] nextBiomes = next.getBiomeArray(); + BiomeType[] previousBiomes = previous.getBiomeArray(); + BiomeType[] nextBiomes = next.getBiomeArray(); int index = 0; for (int z = 0; z < 16; z++) { int zz = bz + z; for (int x = 0; x < 16; x++) { - byte idFrom = previousBiomes[index]; - byte idTo = nextBiomes[index]; - if (idFrom != idTo && idTo != 0) { - addBiomeChange(bx + x, zz, FaweCache.getBiome(idFrom & 0xFF), FaweCache.getBiome(idTo & 0xFF)); + BiomeType idFrom = previousBiomes[index]; + BiomeType idTo = nextBiomes[index]; + if (idFrom != idTo && idTo != null) { + addBiomeChange(bx + x, zz, idFrom, idTo); } index++; } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/FaweStreamChangeSet.java b/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/FaweStreamChangeSet.java index 1863f8797..631fe0d36 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/FaweStreamChangeSet.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/FaweStreamChangeSet.java @@ -337,8 +337,8 @@ public abstract class FaweStreamChangeSet extends FaweChangeSet { os.write((byte) (z >> 16)); os.write((byte) (z >> 8)); os.write((byte) (z)); - os.write(from.getId()); - os.write(to.getId()); + ((FaweOutputStream) os).writeVarInt(from.getInternalId()); + ((FaweOutputStream) os).writeVarInt(to.getInternalId()); } catch (Throwable e) { MainUtil.handleError(e); } @@ -462,8 +462,8 @@ public abstract class FaweStreamChangeSet extends FaweChangeSet { if (int1 != -1) { int x = ((int1 << 24) + (is.read() << 16) + (is.read() << 8) + (is.read() << 0)); int z = ((is.read() << 24) + (is.read() << 16) + (is.read() << 8) + (is.read() << 0)); - int from = is.read(); - int to = is.read(); + int from = ((FaweInputStream) is).readVarInt(); + int to = ((FaweInputStream) is).readVarInt(); change.setBiome(x, z, from, to); return change; } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/CPUOptimizedClipboard.java b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/CPUOptimizedClipboard.java index 25d399052..77281d639 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/CPUOptimizedClipboard.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/CPUOptimizedClipboard.java @@ -33,7 +33,7 @@ public class CPUOptimizedClipboard extends FaweClipboard { private int area; private int volume; - private byte[] biomes = null; + private BiomeType[] biomes = null; private int[] states; private final HashMap nbtMapLoc; @@ -65,11 +65,11 @@ public class CPUOptimizedClipboard extends FaweClipboard { } @Override - public void setBiome(int index, int biome) { + public void setBiome(int index, BiomeType biome) { if (biomes == null) { - biomes = new byte[area]; + biomes = new BiomeType[area]; } - biomes[index] = (byte) biome; + biomes[index] = biome; } @Override @@ -88,7 +88,7 @@ public class CPUOptimizedClipboard extends FaweClipboard { if (!hasBiomes()) { return null; } - return FaweCache.CACHE_BIOME[biomes[index] & 0xFF]; + return biomes[index]; } @Override diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/ReadOnlyClipboard.java b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/ReadOnlyClipboard.java index 916373b5e..3c3a4a3c3 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/ReadOnlyClipboard.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/ReadOnlyClipboard.java @@ -71,7 +71,7 @@ public abstract class ReadOnlyClipboard extends FaweClipboard { int index = 0; for (int z = 0; z <= dim.getBlockZ(); z++) { for (int x = 0; x <= dim.getBlockX(); x++, index++) { - task.run(index, getBiome(x, z).getId()); + task.run(index, getBiome(x, z)); } } } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/FastWorldEditExtent.java b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/FastWorldEditExtent.java index 7394d9d7f..8cf582179 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/FastWorldEditExtent.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/FastWorldEditExtent.java @@ -1,12 +1,11 @@ package com.boydti.fawe.object.extent; -import com.boydti.fawe.FaweCache; import com.boydti.fawe.object.FaweQueue; import com.boydti.fawe.object.HasFaweQueue; -import com.boydti.fawe.util.MainUtil; import com.boydti.fawe.util.ReflectionUtils; import com.sk89q.jnbt.*; import com.sk89q.worldedit.WorldEditException; +import com.sk89q.worldedit.world.biome.BiomeTypes; import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.entity.BaseEntity; @@ -18,7 +17,6 @@ import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.biome.BiomeType; -import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockTypes; @@ -107,7 +105,7 @@ public class FastWorldEditExtent extends AbstractDelegateExtent implements HasFa @Override public BiomeType getBiome(final BlockVector2 position) { - return FaweCache.CACHE_BIOME[queue.getBiomeId(position.getBlockX(), position.getBlockZ())]; + return BiomeTypes.get(queue.getBiomeType(position.getBlockX(), position.getBlockZ())); } @Override diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/PatternExtent.java b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/PatternExtent.java index 1f7a46f6b..534c9c694 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/PatternExtent.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/PatternExtent.java @@ -103,7 +103,7 @@ public class PatternExtent extends AbstractPattern implements Extent { @Override public BiomeType getBiome(BlockVector2 position) { - return new BiomeType(0); + return null; } @Override diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/queue/FaweQueueDelegateExtent.java b/worldedit-core/src/main/java/com/boydti/fawe/object/queue/FaweQueueDelegateExtent.java index 8e6d63dd6..0eed3a025 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/queue/FaweQueueDelegateExtent.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/queue/FaweQueueDelegateExtent.java @@ -58,8 +58,8 @@ public class FaweQueueDelegateExtent extends DelegateFaweQueue { } @Override - public int getBiomeId(int x, int z) throws FaweException.FaweChunkLoadException { - return parentExtent.getBiome(BlockVector2.at(x, z)).getId(); + public BiomeType getBiomeType(int x, int z) throws FaweException.FaweChunkLoadException { + return parentExtent.getBiome(BlockVector2.at(x, z)); } @Override diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/queue/IDelegateFaweQueue.java b/worldedit-core/src/main/java/com/boydti/fawe/object/queue/IDelegateFaweQueue.java index f009393e0..748043afa 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/queue/IDelegateFaweQueue.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/queue/IDelegateFaweQueue.java @@ -343,8 +343,8 @@ public interface IDelegateFaweQueue extends FaweQueue { } @Override - default int getBiomeId(int x, int z) throws FaweException.FaweChunkLoadException { - return getQueue().getBiomeId(x, z); + default BiomeType getBiomeType(int x, int z) throws FaweException.FaweChunkLoadException { + return getQueue().getBiomeType(x, z); } @Override diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/queue/NullFaweQueue.java b/worldedit-core/src/main/java/com/boydti/fawe/object/queue/NullFaweQueue.java index d78733ce6..221b79d2c 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/queue/NullFaweQueue.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/queue/NullFaweQueue.java @@ -183,7 +183,7 @@ public class NullFaweQueue implements FaweQueue { } @Override - public int getBiomeId(int x, int z) throws FaweException.FaweChunkLoadException { + public BiomeType getBiomeType(int x, int z) throws FaweException.FaweChunkLoadException { return 0; } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/schematic/visualizer/SchemVis.java b/worldedit-core/src/main/java/com/boydti/fawe/object/schematic/visualizer/SchemVis.java index 37e6fd785..f089cbc19 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/schematic/visualizer/SchemVis.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/schematic/visualizer/SchemVis.java @@ -578,7 +578,7 @@ public class SchemVis extends ImmutableVirtualWorld { public void sendChunk(int x, int z, int bitMask) { /* do nothing - never used*/ } @Override - public int getBiomeId(int x, int z) throws FaweException.FaweChunkLoadException { + public BiomeType getBiomeType(int x, int z) throws FaweException.FaweChunkLoadException { // TODO later (currently not used) return 0; } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/regions/general/plot/FaweLocalBlockQueue.java b/worldedit-core/src/main/java/com/boydti/fawe/regions/general/plot/FaweLocalBlockQueue.java index ded2d4b7a..363ff35c5 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/regions/general/plot/FaweLocalBlockQueue.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/regions/general/plot/FaweLocalBlockQueue.java @@ -12,6 +12,7 @@ import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.extension.platform.Capability; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.biome.BiomeType; +import com.sk89q.worldedit.world.biome.BiomeTypes; import com.sk89q.worldedit.world.biome.Biomes; import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockTypes; @@ -94,7 +95,7 @@ public class FaweLocalBlockQueue extends LocalBlockQueue { if (reg == null) { reg = WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.USER_COMMANDS).getRegistries().getBiomeRegistry(); } - List biomes = reg.getBiomes(); + List biomes = BiomeTypes.values(); lastBiome = biome; this.biome = Biomes.findBiomeByName(biomes, biome, reg); } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/util/ReflectionUtils.java b/worldedit-core/src/main/java/com/boydti/fawe/util/ReflectionUtils.java index 50e66803d..c6670e19a 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/util/ReflectionUtils.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/util/ReflectionUtils.java @@ -12,6 +12,9 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Map; + +import jdk.internal.reflect.ConstructorAccessor; +import jdk.internal.reflect.FieldAccessor; import sun.reflect.ConstructorAccessor; import sun.reflect.FieldAccessor; import sun.reflect.ReflectionFactory; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/LocalSession.java b/worldedit-core/src/main/java/com/sk89q/worldedit/LocalSession.java index fd9f4788f..ad9eae94e 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/LocalSession.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/LocalSession.java @@ -1409,23 +1409,23 @@ public class LocalSession implements TextureHolder { this.fastMode = fastMode; } - /** - * Gets the reorder mode of the session. - * - * @return The reorder mode - */ - public EditSession.ReorderMode getReorderMode() { - return reorderMode; - } - - /** - * Sets the reorder mode of the session. - * - * @param reorderMode The reorder mode - */ - public void setReorderMode(EditSession.ReorderMode reorderMode) { - this.reorderMode = reorderMode; - } +// /** +// * Gets the reorder mode of the session. +// * +// * @return The reorder mode +// */ +// public EditSession.ReorderMode getReorderMode() { +// return reorderMode; +// } +// +// /** +// * Sets the reorder mode of the session. +// * +// * @param reorderMode The reorder mode +// */ +// public void setReorderMode(EditSession.ReorderMode reorderMode) { +// this.reorderMode = reorderMode; +// } /** * Get the mask. diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/WorldEdit.java b/worldedit-core/src/main/java/com/sk89q/worldedit/WorldEdit.java index 2404d8f2a..9c98f2ea5 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/WorldEdit.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/WorldEdit.java @@ -37,6 +37,9 @@ import com.sk89q.worldedit.extension.platform.PlatformManager; import com.sk89q.worldedit.extent.inventory.BlockBag; import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.function.pattern.Pattern; +import com.sk89q.worldedit.internal.expression.Expression; +import com.sk89q.worldedit.internal.expression.runtime.Constant; +import com.sk89q.worldedit.internal.expression.runtime.RValue; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.scripting.CraftScriptContext; import com.sk89q.worldedit.scripting.CraftScriptEngine; @@ -73,8 +76,6 @@ import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; -import java.util.logging.Level; -import java.util.logging.Logger; import static com.sk89q.worldedit.event.platform.Interaction.HIT; import static com.sk89q.worldedit.event.platform.Interaction.OPEN; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/BiomeCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/BiomeCommands.java index 2bffb1ac6..c0d4174ee 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/BiomeCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/BiomeCommands.java @@ -56,6 +56,7 @@ import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.biome.BiomeData; import com.sk89q.worldedit.world.biome.BiomeType; +import com.sk89q.worldedit.world.biome.BiomeTypes; import com.sk89q.worldedit.world.registry.BiomeRegistry; import java.util.ArrayList; @@ -65,6 +66,8 @@ import java.util.HashSet; import java.util.List; import java.util.Set; +import static com.sk89q.minecraft.util.commands.Logging.LogMode.REGION; + /** * Implements biome-related commands such as "/biomelist". */ @@ -104,7 +107,7 @@ public class BiomeCommands extends MethodCommands { } BiomeRegistry biomeRegistry = getBiomeRegistry(); - List biomes = biomeRegistry.getBiomes(); + List biomes = BiomeTypes.values(); int totalPages = biomes.size() / 19 + 1; Message msg = BBC.BIOME_LIST_HEADER.m(page, totalPages); String setBiome = Commands.getAlias(BiomeCommands.class, "/setbiome"); @@ -141,7 +144,8 @@ public class BiomeCommands extends MethodCommands { @CommandPermissions("worldedit.biome.info") public void biomeInfo(Player player, LocalSession session, final EditSession editSession, CommandContext args) throws WorldEditException { BiomeRegistry biomeRegistry = getBiomeRegistry(); - final int[] biomes = new int[256]; + List values = BiomeTypes.values(); + final int[] biomes = new int[values.size()]; final String qualifier; int size = 0; @@ -165,14 +169,14 @@ public class BiomeCommands extends MethodCommands { if (region instanceof FlatRegion) { for (BlockVector2 pt : new Fast2DIterator(((FlatRegion) region).asFlatRegion(), editSession)) { - biomes[editSession.getBiome(pt).getId()]++; + biomes[editSession.getBiome(pt).getInternalId()]++; size++; } } else { RegionVisitor visitor = new RegionVisitor(region, new RegionFunction() { @Override public boolean apply(BlockVector3 position) throws WorldEditException { - biomes[editSession.getBiome(position.toBlockVector2()).getId()]++; + biomes[editSession.getBiome(position.toBlockVector2()).getInternalId()]++; return true; } }, editSession); @@ -187,7 +191,7 @@ public class BiomeCommands extends MethodCommands { for (int i = 0; i < biomes.length; i++) { int count = biomes[i]; if (count != 0) { - distribution.add(new Countable<>(new BiomeType(i), count)); + distribution.add(new Countable<>(BiomeTypes.get(i), count)); } } Collections.sort(distribution); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/GeneralCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/GeneralCommands.java index acb8e4970..4899ad812 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/GeneralCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/GeneralCommands.java @@ -25,6 +25,7 @@ import com.sk89q.minecraft.util.commands.Command; import com.sk89q.minecraft.util.commands.CommandContext; import com.sk89q.minecraft.util.commands.CommandPermissions; import com.sk89q.worldedit.*; +import com.sk89q.worldedit.extension.input.DisallowedUsageException; import com.sk89q.worldedit.world.item.ItemType; import com.sk89q.worldedit.world.item.ItemTypes; import com.sk89q.worldedit.entity.Player; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/GenerationCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/GenerationCommands.java index de77d60bb..a92f3cd2a 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/GenerationCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/GenerationCommands.java @@ -54,7 +54,17 @@ import com.sk89q.worldedit.util.command.binding.Range; import com.sk89q.worldedit.util.command.binding.Switch; import com.sk89q.worldedit.util.command.binding.Text; import com.sk89q.worldedit.util.command.parametric.Optional; +import com.sk89q.worldedit.util.command.parametric.ParameterException; import com.sk89q.worldedit.world.biome.BiomeType; +import com.sk89q.worldedit.world.block.BlockType; + +import java.awt.*; +import java.awt.image.BufferedImage; +import java.io.IOException; +import java.net.URL; + +import static com.sk89q.minecraft.util.commands.Logging.LogMode.*; + /** * Commands for the generation of shapes and other objects. @@ -427,7 +437,8 @@ public class GenerationCommands extends MethodCommands { @Switch('h') boolean hollow, @Switch('r') boolean useRawCoords, @Switch('o') boolean offset, - @Switch('c') boolean offsetCenter) throws WorldEditException { + @Switch('c') boolean offsetCenter, + CommandContext context) throws WorldEditException { final Vector3 zero; Vector3 unit; 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 5d6774da6..724e78c09 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 @@ -53,6 +53,7 @@ import com.sk89q.worldedit.function.visitor.LayerVisitor; import com.sk89q.worldedit.internal.annotation.Direction; import com.sk89q.worldedit.internal.annotation.Selection; import com.sk89q.worldedit.internal.expression.ExpressionException; +import com.sk89q.worldedit.math.BlockVector2; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.math.convolution.GaussianKernel; @@ -66,6 +67,11 @@ import com.sk89q.worldedit.util.command.binding.Range; import com.sk89q.worldedit.util.command.binding.Switch; import com.sk89q.worldedit.util.command.binding.Text; import com.sk89q.worldedit.util.command.parametric.Optional; +import com.sk89q.worldedit.world.biome.BiomeType; +import com.sk89q.worldedit.world.biome.BiomeTypes; +import com.sk89q.worldedit.world.biome.Biomes; +import com.sk89q.worldedit.world.block.BlockStateHolder; +import com.sk89q.worldedit.world.registry.BiomeRegistry; import java.util.ArrayList; import java.util.Iterator; @@ -704,7 +710,7 @@ public class RegionCommands extends MethodCommands { BiomeType biome = null; if (context.argsLength() >= 1) { BiomeRegistry biomeRegistry = worldEdit.getPlatformManager().queryCapability(Capability.GAME_HOOKS).getRegistries().getBiomeRegistry(); - List knownBiomes = biomeRegistry.getBiomes(); + List knownBiomes = BiomeTypes.values(); biome = Biomes.findBiomeByName(knownBiomes, context.getString(0), biomeRegistry); } Long seed = context.argsLength() != 2 || !MathMan.isInteger(context.getString(1)) ? null : Long.parseLong(context.getString(1)); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/SchematicCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/SchematicCommands.java index 1392e22af..6b27ccf1a 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/SchematicCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/SchematicCommands.java @@ -65,8 +65,10 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; +import java.io.InputStream; import java.net.URI; import java.net.URISyntaxException; +import java.net.URL; import java.nio.channels.Channels; import java.nio.channels.ReadableByteChannel; import java.nio.file.Files; @@ -79,6 +81,7 @@ import java.util.UUID; import java.util.concurrent.atomic.LongAdder; import java.util.regex.Pattern; +import static com.boydti.fawe.util.ReflectionUtils.as; import static com.google.common.base.Preconditions.checkNotNull; /** @@ -92,7 +95,6 @@ public class SchematicCommands extends MethodCommands { */ private static final int SCHEMATICS_PER_PAGE = 9; private static final Logger log = LoggerFactory.getLogger(SchematicCommands.class); - private final WorldEdit worldEdit; /** * Create a new instance. @@ -279,7 +281,7 @@ public class SchematicCommands extends MethodCommands { player.printError("Unknown filename: " + filename); } catch (URISyntaxException | IOException e) { player.printError("File could not be read or it does not exist: " + e.getMessage()); - log.log(Level.WARNING, "Failed to load a saved clipboard", e); + log.warn("Failed to load a saved clipboard", e); } finally { if (in != null) { try { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/SelectionCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/SelectionCommands.java index 40669c6bc..f32c823be 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/SelectionCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/SelectionCommands.java @@ -60,6 +60,7 @@ import com.sk89q.worldedit.regions.selector.RegionSelectorType; import com.sk89q.worldedit.regions.selector.SphereRegionSelector; import com.sk89q.worldedit.session.ClipboardHolder; import com.sk89q.worldedit.util.Countable; +import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.util.command.binding.Switch; import com.sk89q.worldedit.util.formatting.ColorCodeBuilder; import com.sk89q.worldedit.util.formatting.Style; @@ -103,7 +104,7 @@ public class SelectionCommands { @CommandPermissions("worldedit.selection.pos") public void pos1(Player player, LocalSession session, CommandContext args) throws WorldEditException { - Location pos; + BlockVector3 pos; if (args.argsLength() == 1) { if (args.getString(0).matches("-?\\d+,-?\\d+,-?\\d+")) { @@ -136,7 +137,7 @@ public class SelectionCommands { @CommandPermissions("worldedit.selection.pos") public void pos2(Player player, LocalSession session, CommandContext args) throws WorldEditException { - Location pos; + BlockVector3 pos; if (args.argsLength() == 1) { if (args.getString(0).matches("-?\\d+,-?\\d+,-?\\d+")) { String[] coords = args.getString(0).split(","); @@ -735,7 +736,7 @@ public class SelectionCommands { min = 0, max = 1 ) - public void select(Player player, LocalSession session, CommandContext args) throws WorldEditException { + public void select(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException { final World world = player.getWorld(); if (args.argsLength() == 0) { session.getRegionSelector(world).clear(); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/FloatingTreeRemover.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/FloatingTreeRemover.java index 3d12dc1d7..3f21e2b13 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/FloatingTreeRemover.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/FloatingTreeRemover.java @@ -27,6 +27,10 @@ import com.sk89q.worldedit.MaxChangedBlocksException; import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.extension.platform.Platform; +import com.sk89q.worldedit.function.mask.BlockMask; +import com.sk89q.worldedit.function.operation.Operations; +import com.sk89q.worldedit.function.pattern.Pattern; +import com.sk89q.worldedit.function.visitor.RecursiveVisitor; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.util.Direction; import com.sk89q.worldedit.util.Location; @@ -70,7 +74,8 @@ public class FloatingTreeRemover implements BlockTool { Player player, LocalSession session, Location clicked) { final World world = (World) clicked.getExtent(); - final BlockState state = world.getBlock(clicked.toBlockPoint()); + BlockVector3 pos = clicked.toBlockPoint(); + final BlockState state = world.getBlock(pos); if (!isTreeBlock(state.getBlockType())) { player.printError("That's not a tree."); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/GravityBrush.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/GravityBrush.java index aaafefdc7..646915f30 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/GravityBrush.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/GravityBrush.java @@ -21,14 +21,11 @@ package com.sk89q.worldedit.command.tool.brush; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.MaxChangedBlocksException; +import com.sk89q.worldedit.function.mask.Mask; +import com.sk89q.worldedit.function.mask.Masks; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.math.BlockVector3; -import com.sk89q.worldedit.world.block.BlockState; -import com.sk89q.worldedit.world.block.BlockTypes; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; +import com.sk89q.worldedit.world.block.BlockStateHolder; public class GravityBrush implements Brush { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/event/extent/EditSessionEvent.java b/worldedit-core/src/main/java/com/sk89q/worldedit/event/extent/EditSessionEvent.java index c58ae7ce1..c94ba677a 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/event/extent/EditSessionEvent.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/event/extent/EditSessionEvent.java @@ -20,6 +20,7 @@ package com.sk89q.worldedit.event.extent; import com.sk89q.worldedit.EditSession; +import com.sk89q.worldedit.event.Cancellable; import com.sk89q.worldedit.event.Event; import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.extent.Extent; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/PatternFactory.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/PatternFactory.java index c9d43f011..8f7ead81a 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/PatternFactory.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/PatternFactory.java @@ -22,6 +22,7 @@ package com.sk89q.worldedit.extension.factory; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.extension.factory.parser.pattern.BlockCategoryPatternParser; import com.sk89q.worldedit.extension.factory.parser.pattern.ClipboardPatternParser; +import com.sk89q.worldedit.extension.factory.parser.pattern.DefaultPatternParser; import com.sk89q.worldedit.extension.factory.parser.pattern.RandomPatternParser; import com.sk89q.worldedit.extension.factory.parser.pattern.RandomStatePatternParser; import com.sk89q.worldedit.extension.factory.parser.pattern.SingleBlockPatternParser; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/CommandManager.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/CommandManager.java index 4a65ccd30..f89b628e2 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/CommandManager.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/CommandManager.java @@ -44,6 +44,7 @@ import com.sk89q.worldedit.command.composition.DeformCommand; import com.sk89q.worldedit.command.composition.PaintCommand; import com.sk89q.worldedit.command.composition.ShapedBrushCommand; import com.sk89q.worldedit.entity.Entity; +import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.event.platform.CommandEvent; import com.sk89q.worldedit.event.platform.CommandSuggestionEvent; import com.sk89q.worldedit.extent.Extent; @@ -486,7 +487,7 @@ public final class CommandManager { actor.printError(BBC.getPrefix() + e.getMessage()); } else { actor.printError(BBC.getPrefix() + "An unknown FAWE error has occurred! Please see console."); - log.log(Level.SEVERE, "An unknown FAWE error occurred", e); + log.error("An unknown FAWE error occurred", e); } } catch (Throwable e) { Exception faweException = FaweException.get(e); @@ -496,7 +497,7 @@ public final class CommandManager { } else { actor.printError(BBC.getPrefix() + "There was an error handling a FAWE command: [See console]"); actor.printRaw(e.getClass().getName() + ": " + e.getMessage()); - log.log(Level.SEVERE, "An unexpected error occurred while handling a FAWE command", e); + log.error("An unexpected error occurred while handling a FAWE command", e); } } finally { final EditSession editSession = locals.get(EditSession.class); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/ClipboardFormats.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/ClipboardFormats.java index 4336a16f3..ad98f88ad 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/ClipboardFormats.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/ClipboardFormats.java @@ -36,6 +36,8 @@ import com.google.common.io.Files; import com.sk89q.worldedit.LocalConfiguration; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.extension.platform.Actor; + +import javax.annotation.Nullable; import java.io.File; import java.io.IOException; import java.io.InputStream; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/transform/BlockTransformExtent.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/transform/BlockTransformExtent.java index 0d7e4393c..a8cb69008 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/transform/BlockTransformExtent.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/transform/BlockTransformExtent.java @@ -61,7 +61,7 @@ import javax.annotation.Nullable; */ public class BlockTransformExtent extends ResettableExtent { - private final Transform transform; + private Transform transform; public BlockTransformExtent(Extent parent) { @@ -138,9 +138,6 @@ public class BlockTransformExtent extends ResettableExtent { return super.setBlock(location, transformBlock(block, true)); } - private static final Set directionNames = Sets.newHashSet("north", "south", "east", "west"); - - private static final Set directionNames = Sets.newHashSet("north", "south", "east", "west"); /** diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/factory/Deform.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/factory/Deform.java index 8793ae00d..6a32edb23 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/factory/Deform.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/factory/Deform.java @@ -150,8 +150,7 @@ public class Deform implements Contextual { } LocalSession session = context.getSession(); - return new DeformOperation(context.getDestination(), region, zero, unit, expression, - session == null ? WorldEdit.getInstance().getConfiguration().calculationTimeout : session.getTimeout()); + return new DeformOperation(context.getDestination(), region, zero, unit, expression); } private static final class DeformOperation implements Operation { @@ -160,7 +159,6 @@ public class Deform implements Contextual { private final Vector3 zero; private final Vector3 unit; private final String expression; - private final int timeout; private DeformOperation(Extent destination, Region region, Vector3 zero, Vector3 unit, String expression) { this.destination = destination; @@ -168,7 +166,6 @@ public class Deform implements Contextual { this.zero = zero; this.unit = unit; this.expression = expression; - this.timeout = timeout; } @Override diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/pattern/RandomPattern.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/pattern/RandomPattern.java index 18b7b8033..083dbee10 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/pattern/RandomPattern.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/pattern/RandomPattern.java @@ -12,6 +12,11 @@ import static com.google.common.base.Preconditions.checkNotNull; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BaseBlock; +import java.util.HashMap; +import java.util.LinkedHashSet; +import java.util.Map; +import java.util.Set; + import static com.google.common.base.Preconditions.checkNotNull; /** diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/biome/BiomeTypes.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/biome/BiomeTypes.java index f4e10fa76..0c9a4c0d7 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/biome/BiomeTypes.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/biome/BiomeTypes.java @@ -20,6 +20,8 @@ package com.sk89q.worldedit.world.biome; import javax.annotation.Nullable; +import java.util.List; +import java.util.Set; /** * Stores a list of common Biome String IDs. @@ -121,4 +123,8 @@ public class BiomeTypes { public static BiomeType get(int parseInt) { // TODO } + + public static List values() { + + } } 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 ab5b18197..d12942805 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 @@ -29,6 +29,7 @@ import com.sk89q.jnbt.CompoundTag; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.extension.input.InputParseException; +import com.sk89q.worldedit.extension.platform.Capability; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.pattern.FawePattern; import com.sk89q.worldedit.math.BlockVector3; @@ -52,31 +53,17 @@ import java.util.Set; */ @SuppressWarnings("unchecked") public class BlockState implements BlockStateHolder, FawePattern { - private final BlockType blockType; + private BlockMaterial material; + private BlockType blockType; + private int internalId, ordinal; private BaseBlock emptyBaseBlock; - BlockState(BlockType blockType) { + BlockState(BlockType blockType, int internalId, int ordinal) { this.blockType = blockType; - this.emptyBaseBlock = new BaseBlock(this); + this.internalId = internalId; + this.ordinal = ordinal; } - - BlockState(BlockType blockType, BaseBlock baseBlock){ - this.blockType = blockType; - this.emptyBaseBlock = baseBlock; - } - - /** - * Creates a fuzzy BlockState. This can be used for partial matching. - * - * @param blockType The block type - * @param values The block state values - */ - private BlockState(BlockType blockType, Map, Object> values) { - this.blockType = blockType; -// this.values = values; -// this.fuzzy = true; - } - + /** * Returns a temporary BlockState for a given internal id * @param combinedId @@ -364,13 +351,22 @@ public class BlockState implements BlockStateHolder, FawePattern { @Override public BlockMaterial getMaterial() { - return blockType.getMaterial(); + if (this.material == null) { + if (blockType == BlockTypes.__RESERVED__) { + return this.material = blockType.getMaterial(); + } + if (this.material == null) { + this.material = WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.GAME_HOOKS).getRegistries().getBlockRegistry().getMaterial(this); + } + } + return material; } @Override public int getOrdinal() { - get ordinal + return this.ordinal; } + /** * Internal method used for creating the initial BlockState. * @@ -399,8 +395,6 @@ public class BlockState implements BlockStateHolder, FawePattern { return equalsFuzzy((BlockState) obj); } - private Integer hashCodeCache = null; - @Override public int hashCode() { return getOrdinal(); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockType.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockType.java index 1c6645d2d..16adc6db8 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockType.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockType.java @@ -21,14 +21,13 @@ package com.sk89q.worldedit.world.block; import static com.google.common.base.Preconditions.checkArgument; -import com.google.common.collect.ImmutableList; +import com.boydti.fawe.util.ReflectionUtils; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.function.mask.SingleBlockTypeMask; import com.sk89q.worldedit.function.pattern.FawePattern; import com.sk89q.worldedit.math.BlockVector3; -import com.google.common.collect.ImmutableMap; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.world.registry.BlockMaterial; import com.sk89q.worldedit.extension.platform.Capability; @@ -37,16 +36,11 @@ import com.sk89q.worldedit.registry.state.AbstractProperty; import com.sk89q.worldedit.registry.state.Property; import com.sk89q.worldedit.registry.state.PropertyKey; import com.sk89q.worldedit.world.item.ItemType; -import com.sk89q.worldedit.world.item.ItemTypes; -import com.sk89q.worldedit.world.registry.BundledBlockData; -import com.sk89q.worldedit.world.registry.BlockMaterial; import com.sk89q.worldedit.world.registry.LegacyMapper; import javax.annotation.Nonnull; import javax.annotation.Nullable; import java.util.*; -import java.util.concurrent.atomic.AtomicReference; -import java.util.function.Function; import java.util.stream.Collectors; import java.util.stream.IntStream; @@ -55,33 +49,50 @@ public class BlockType implements FawePattern { public static final NamespacedRegistry REGISTRY = new NamespacedRegistry<>("block type"); private final @Nonnull String id; - private ArrayList states; - public final Function defaultValue; - private BlockTypes.Settings settings; - private BlockMaterial material; + private final BlockTypeEnum typeEnum; + private BlockTypes.Settings settings; - public BlockType(@Nonnull String id) { - this(id, null); +// private ArrayList states; +// public final Function defaultValue; +// +// private BlockMaterial material; + + public BlockType(@Nonnull BlockTypeEnum typeEnum) { + this.typeEnum = typeEnum; } - - public BlockType(@Nonnull String id, Function defaultValue) { - this.id = id; - this.defaultValue = defaultValue; - } - - public void setStates(ArrayList states) { + + public BlockTypeEnum getTypeEnum() { + return typeEnum; + } + + private void init(String id, int internalId, List states) { + try { + if (getId() == null) { + String name = (name().indexOf(':') == -1 ? "minecraft:" : "") + name().toLowerCase(); + ReflectionUtils.setFailsafeFieldValue(BlockTypes.class.getDeclaredField("id"), this, name); + } + Settings settings = new Settings(this, id, internalId, states); + ReflectionUtils.setFailsafeFieldValue(BlockTypes.class.getDeclaredField("settings"), this, settings); + } catch (Throwable e) { + e.printStackTrace(); + throw new RuntimeException(e); + } + } + + + public void setStates(ArrayList states) { // this.states = states; } - public void setSettings(BlockTypes.Settings settings) { + public void setSettings(BlockTypes.Settings settings) { // this.settings = settings; } - public BlockTypes.Settings getSettings(){ + public BlockTypes.Settings getSettings(){ // return settings; } - public ArrayList updateStates(){ + public ArrayList updateStates(){ // if(settings != null) { return settings.localStates = new ArrayList<>(settings.localStates.stream() .map(state -> new BlockStateImpl(this, state.getInternalId(), state.getOrdinal())).collect(Collectors.toList())); @@ -130,13 +141,13 @@ public class BlockType implements FawePattern { } @Deprecated - public BlockState withPropertyId(int propertyId) { - if (settings.stateOrdinals == null) return settings.defaultState; - return states.get(settings.stateOrdinals[propertyId]); + public BlockState withPropertyId(int internalPropertiesId) { + if (internalPropertiesId == 0) return getDefaultState(); + return BlockState.getFromInternalId(getInternalId() + (internalPropertiesId << BlockTypes.BIT_OFFSET)); } @Deprecated - public BlockState withStateId(int internalStateId) { + public BlockState withStateId(int internalStateId) { // return this.withPropertyId(internalStateId >> BlockTypes.BIT_OFFSET); } @@ -145,7 +156,7 @@ public class BlockType implements FawePattern { * @param properties * @return */ - public BlockState withProperties(String properties) { + public BlockState withProperties(String properties) { // int id = getInternalId(); for (String keyPair : properties.split(",")) { String[] split = keyPair.split("="); @@ -190,7 +201,6 @@ public class BlockType implements FawePattern { */ @Deprecated public Property getProperty(String name) { - checkArgument(this.settings.propertiesMap.get(name) != null, "%s has no property named %s", this, name); return (Property) this.settings.propertiesMap.get(name); } @@ -213,18 +223,14 @@ public class BlockType implements FawePattern { * @return The default state */ public BlockState getDefaultState() { - BlockState defaultState = this.settings.defaultState; - if (defaultValue != null) { - defaultState = defaultValue.apply(defaultState); - } - return defaultState; + return this.settings.defaultState; } - public FuzzyBlockState getFuzzyMatcher() { + public FuzzyBlockState getFuzzyMatcher() { // return new FuzzyBlockState(this); } - public FuzzyBlockState getFuzzyMatcher() { + public FuzzyBlockState getFuzzyMatcher() { // return updateField(emptyFuzzy, () -> new FuzzyBlockState(this)); } @@ -235,7 +241,7 @@ public class BlockType implements FawePattern { @Deprecated public List getAllStates() { if (settings.stateOrdinals == null) return Collections.singletonList(getDefaultState()); - return IntStream.of(settings.stateOrdinals).filter(i -> i != -1).mapToObj(i -> states.get(i)).collect(Collectors.toList()); + return IntStream.of(settings.stateOrdinals).filter(i -> i != -1).mapToObj(i -> BlockTypes.states[i]).collect(Collectors.toList()); } /** @@ -243,7 +249,7 @@ public class BlockType implements FawePattern { * * @return The state, if it exists */ - public BlockState getState(Map, Object> key) { + public BlockState getState(Map, Object> key) { // int id = getInternalId(); for (Map.Entry, Object> iter : key.entrySet()) { Property prop = iter.getKey(); @@ -278,7 +284,7 @@ public class BlockType implements FawePattern { */ @Nullable public ItemType getItemType() { - return ItemTypes.get(this); + return settings.itemType; } /** @@ -287,9 +293,7 @@ public class BlockType implements FawePattern { * @return The material */ public BlockMaterial getMaterial() { - return this.material == null ? - WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.GAME_HOOKS).getRegistries().getBlockRegistry().getMaterial(this) - : this.material; + return this.settings.blockMaterial; } /** @@ -317,12 +321,12 @@ public class BlockType implements FawePattern { @Override public int hashCode() { - return this.getSettings().defaultState.ordinal(); + return settings.internalId; } @Override public boolean equals(Object obj) { - return obj instanceof BlockType && this.id.equals(((BlockType) obj).id); + return obj == this; } @Override @@ -347,7 +351,7 @@ public class BlockType implements FawePattern { @Deprecated - public int getLegacyId() { + public int getLegacyId() { // Integer id = LegacyMapper.getInstance().getLegacyCombined(this.getDefaultState()); if (id != null) { return id >> 4; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockTypeEnum.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockTypeEnum.java new file mode 100644 index 000000000..8e7b46314 --- /dev/null +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockTypeEnum.java @@ -0,0 +1,5 @@ +package com.sk89q.worldedit.world.block; + +public enum BlockTypeEnum { + +} diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/item/ItemType.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/item/ItemType.java index be59950cb..b68db45b4 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/item/ItemType.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/item/ItemType.java @@ -20,6 +20,7 @@ package com.sk89q.worldedit.world.item; import com.sk89q.worldedit.WorldEdit; +import com.sk89q.worldedit.blocks.BaseItem; import com.sk89q.worldedit.extension.platform.Capability; import com.sk89q.worldedit.registry.NamespacedRegistry; import com.sk89q.worldedit.world.block.BlockType; 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 92d1a2f00..d53c6b36c 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 @@ -872,6 +872,10 @@ public final class ItemTypes { return ItemType.REGISTRY.register(type.getId(), type); } + public static final @Nullable ItemType get(String id) { + + } + public static final @Nullable ItemType get(BlockType type) { ItemType item = get(type.getId()); if (item != null && item.getBlockType() == null) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BundledItemRegistry.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BundledItemRegistry.java index 3d6b4c72d..ae7cb2b2b 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BundledItemRegistry.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BundledItemRegistry.java @@ -51,11 +51,4 @@ public class BundledItemRegistry implements ItemRegistry { public Collection registerItems() { return Collections.emptyList(); } - - @Nullable - @Override - public String getName(ItemType itemType) { - BundledItemData.ItemEntry itemEntry = BundledItemData.getInstance().findById(itemType.getId()); - return itemEntry != null ? itemEntry.localizedName : null; - } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/LegacyMapper.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/LegacyMapper.java index 49bea4045..80b3a846a 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/LegacyMapper.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/LegacyMapper.java @@ -233,7 +233,7 @@ public class LegacyMapper { try { return BlockTypes.get(plotBlock.toString()).getDefaultState().toBaseBlock(); }catch(Throwable failed) { - log.severe("Unable to convert StringPlotBlock " + plotBlock + " to BaseBlock!"); + log.error("Unable to convert StringPlotBlock " + plotBlock + " to BaseBlock!"); failed.printStackTrace(); return null; } @@ -241,12 +241,12 @@ public class LegacyMapper { try { return new BaseBlock(((LegacyPlotBlock)plotBlock).getId(), ((LegacyPlotBlock)plotBlock).getData()); }catch(Throwable failed) { - log.severe("Unable to convert LegacyPlotBlock " + plotBlock + " to BaseBlock!"); + log.error("Unable to convert LegacyPlotBlock " + plotBlock + " to BaseBlock!"); failed.printStackTrace(); return null; } }else { - log.severe("Unable to convert LegacyPlotBlock " + plotBlock + " to BaseBlock!"); + log.error("Unable to convert LegacyPlotBlock " + plotBlock + " to BaseBlock!"); return null; } }