From ef3642d521e15905dea261ea0e9e9b06367d5cc3 Mon Sep 17 00:00:00 2001 From: MattBDev <4009945+MattBDev@users.noreply.github.com> Date: Thu, 30 Apr 2020 16:26:52 -0400 Subject: [PATCH] Small spring cleaning I changed really small bits and pieces of code. If you have questions just comment and I'll answer them. --- .../adapter/mc1_14/BukkitAdapter_1_14.java | 13 +-- .../adapter/mc1_14/BukkitGetBlocks_1_14.java | 4 +- .../adapter/mc1_15/BukkitAdapter_1_15.java | 5 +- .../adapter/mc1_15/BukkitGetBlocks_1_15.java | 12 ++- .../mc1_15_2/BukkitAdapter_1_15_2.java | 6 +- .../mc1_15_2/BukkitGetBlocks_1_15_2.java | 4 +- .../main/java/com/boydti/fawe/FaweCache.java | 4 +- .../com/boydti/fawe/command/MaskBinding.java | 29 ------- .../boydti/fawe/command/PatternBinding.java | 26 ------ .../com/boydti/fawe/jnbt/anvil/MCAChunk.java | 6 +- .../java/com/boydti/fawe/object/BytePair.java | 42 --------- .../boydti/fawe/object/DataAnglePattern.java | 7 +- .../object/{IntegerPair.java => IntPair.java} | 8 +- .../com/boydti/fawe/object/IntTriple.java | 45 ++++++++++ .../com/boydti/fawe/object/IntegerTrio.java | 60 ------------- .../brush/heightmap/ScalableHeightMap.java | 6 +- .../object/changeset/DiskStorageHistory.java | 8 +- .../clipboard/CPUOptimizedClipboard.java | 10 +-- .../clipboard/DiskOptimizedClipboard.java | 14 +-- .../clipboard/MemoryOptimizedClipboard.java | 12 +-- .../{BitArray4096.java => BitArray.java} | 67 +++++---------- .../object/extent/BlockTranslateExtent.java | 11 ++- .../object/extent/ExtentHeightCacher.java | 13 ++- .../fawe/object/extent/FaweRegionExtent.java | 4 +- .../fawe/object/extent/HeightBoundExtent.java | 4 +- .../object/extent/MemoryCheckingExtent.java | 1 + .../fawe/object/extent/MultiRegionExtent.java | 3 +- .../fawe/object/extent/MultiTransform.java | 28 ++++-- .../boydti/fawe/object/extent/NullExtent.java | 1 + .../fawe/object/extent/OffsetExtent.java | 14 ++- .../fawe/object/extent/PatternTransform.java | 5 +- .../extent/PositionTransformExtent.java | 7 +- .../fawe/object/extent/ProcessedWEExtent.java | 8 +- .../object/extent/RandomOffsetTransform.java | 12 +-- .../fawe/object/extent/RandomTransform.java | 13 ++- .../fawe/object/extent/ResettableExtent.java | 10 ++- .../fawe/object/extent/ScaleTransform.java | 31 ++++--- .../fawe/object/extent/SelectTransform.java | 10 ++- .../fawe/object/extent/TemporalExtent.java | 2 +- .../fawe/object/extent/TransformExtent.java | 6 +- .../fawe/object/function/block/BiomeCopy.java | 1 + .../fawe/object/visitor/AboveVisitor.java | 28 +++--- .../object/visitor/DFSRecursiveVisitor.java | 20 ++--- .../fawe/object/visitor/DFSVisitor.java | 86 +++++++++---------- .../com/boydti/fawe/util/TextureUtil.java | 8 +- 45 files changed, 305 insertions(+), 409 deletions(-) delete mode 100644 worldedit-core/src/main/java/com/boydti/fawe/command/MaskBinding.java delete mode 100644 worldedit-core/src/main/java/com/boydti/fawe/command/PatternBinding.java delete mode 100644 worldedit-core/src/main/java/com/boydti/fawe/object/BytePair.java rename worldedit-core/src/main/java/com/boydti/fawe/object/{IntegerPair.java => IntPair.java} (73%) create mode 100644 worldedit-core/src/main/java/com/boydti/fawe/object/IntTriple.java delete mode 100644 worldedit-core/src/main/java/com/boydti/fawe/object/IntegerTrio.java rename worldedit-core/src/main/java/com/boydti/fawe/object/collection/{BitArray4096.java => BitArray.java} (76%) diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_14/BukkitAdapter_1_14.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_14/BukkitAdapter_1_14.java index 841525974..20c634358 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_14/BukkitAdapter_1_14.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_14/BukkitAdapter_1_14.java @@ -5,7 +5,7 @@ import com.boydti.fawe.FaweCache; import com.boydti.fawe.bukkit.adapter.NMSAdapter; import com.boydti.fawe.bukkit.adapter.DelegateLock; import com.boydti.fawe.config.Settings; -import com.boydti.fawe.object.collection.BitArray4096; +import com.boydti.fawe.object.collection.BitArray; import com.boydti.fawe.util.MathMan; import com.boydti.fawe.util.ReflectionUtils; import com.boydti.fawe.util.TaskManager; @@ -34,10 +34,8 @@ import org.bukkit.craftbukkit.v1_14_R1.CraftWorld; import sun.misc.Unsafe; import java.lang.reflect.Field; -import java.lang.reflect.Modifier; import java.util.Arrays; import java.util.concurrent.CompletableFuture; -import java.util.concurrent.locks.Lock; import java.util.function.Function; public final class BukkitAdapter_1_14 extends NMSAdapter { @@ -88,12 +86,7 @@ public final class BukkitAdapter_1_14 extends NMSAdapter { methodGetVisibleChunk = MethodHandles.lookup().unreflect(declaredGetVisibleChunk); { - Field tmp; - try { - tmp = DataPaletteBlock.class.getDeclaredField("writeLock"); - } catch (NoSuchFieldException paper) { - tmp = DataPaletteBlock.class.getDeclaredField("j"); - } + Field tmp = DataPaletteBlock.class.getDeclaredField("j"); ReflectionUtils.setAccessibleNonFinal(tmp); fieldLock = tmp; fieldLock.setAccessible(true); @@ -236,7 +229,7 @@ public final class BukkitAdapter_1_14 extends NMSAdapter { if (num_palette == 1) { for (int i = 0; i < blockBitArrayEnd; i++) blockStates[i] = 0; } else { - final BitArray4096 bitArray = new BitArray4096(blockStates, bitsPerEntry); + final BitArray bitArray = new BitArray(bitsPerEntry, 4096, blockStates); bitArray.fromRaw(blocksCopy); } 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 4e585f2ae..dd21b6429 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 @@ -10,7 +10,7 @@ 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.object.collection.BitArray; import com.google.common.base.Suppliers; import com.google.common.collect.Iterables; import com.sk89q.jnbt.CompoundTag; @@ -509,7 +509,7 @@ public class BukkitGetBlocks_1_14 extends CharGetBlocks { final int bitsPerEntry = bits.c(); final long[] blockStates = bits.a(); - new BitArray4096(blockStates, bitsPerEntry).toRaw(data); + new BitArray(bitsPerEntry, 4096, blockStates).toRaw(data); int num_palette; if (palette instanceof DataPaletteLinear) { diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_15/BukkitAdapter_1_15.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_15/BukkitAdapter_1_15.java index 98c8acac2..5e21201aa 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_15/BukkitAdapter_1_15.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_15/BukkitAdapter_1_15.java @@ -5,7 +5,7 @@ import com.boydti.fawe.FaweCache; import com.boydti.fawe.bukkit.adapter.DelegateLock; import com.boydti.fawe.bukkit.adapter.NMSAdapter; import com.boydti.fawe.config.Settings; -import com.boydti.fawe.object.collection.BitArray4096; +import com.boydti.fawe.object.collection.BitArray; import com.boydti.fawe.util.MathMan; import com.boydti.fawe.util.ReflectionUtils; import com.boydti.fawe.util.TaskManager; @@ -25,7 +25,6 @@ import sun.misc.Unsafe; import java.lang.reflect.Field; import java.util.Arrays; import java.util.concurrent.CompletableFuture; -import java.util.concurrent.locks.Lock; import java.util.function.Function; public final class BukkitAdapter_1_15 extends NMSAdapter { @@ -217,7 +216,7 @@ public final class BukkitAdapter_1_15 extends NMSAdapter { if (num_palette == 1) { for (int i = 0; i < blockBitArrayEnd; i++) blockStates[i] = 0; } else { - final BitArray4096 bitArray = new BitArray4096(blockStates, bitsPerEntry); + final BitArray bitArray = new BitArray(bitsPerEntry, 4096, blockStates); bitArray.fromRaw(blocksCopy); } diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_15/BukkitGetBlocks_1_15.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_15/BukkitGetBlocks_1_15.java index 4a399655d..79cb25569 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_15/BukkitGetBlocks_1_15.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_15/BukkitGetBlocks_1_15.java @@ -10,7 +10,7 @@ import com.boydti.fawe.beta.implementation.queue.QueueHandler; import com.boydti.fawe.bukkit.adapter.DelegateLock; import com.boydti.fawe.bukkit.adapter.mc1_15.nbt.LazyCompoundTag_1_15; import com.boydti.fawe.object.collection.AdaptedMap; -import com.boydti.fawe.object.collection.BitArray4096; +import com.boydti.fawe.object.collection.BitArray; import com.google.common.base.Suppliers; import com.google.common.collect.Iterables; import com.sk89q.jnbt.CompoundTag; @@ -439,6 +439,7 @@ public class BukkitGetBlocks_1_15 extends CharGetBlocks { //Lighting // TODO optimize, cause this is really slow LightEngineThreaded engine = (LightEngineThreaded) nmsChunk.e(); + //lightChunk() engine.a(nmsChunk, false); Runnable callback; @@ -448,6 +449,7 @@ public class BukkitGetBlocks_1_15 extends CharGetBlocks { int finalMask = bitMask; callback = () -> { // Set Modified + //setLastSaveHadEntities nmsChunk.d(true); // Set Modified nmsChunk.mustNotSave = false; nmsChunk.markDirty(); @@ -518,15 +520,19 @@ public class BukkitGetBlocks_1_15 extends CharGetBlocks { final DataBits bits = (DataBits) BukkitAdapter_1_15.fieldBits.get(blocks); final DataPalette palette = (DataPalette) BukkitAdapter_1_15.fieldPalette.get(blocks); + //getBits() final int bitsPerEntry = bits.c(); + //getRaw() final long[] blockStates = bits.a(); - new BitArray4096(blockStates, bitsPerEntry).toRaw(data); + new BitArray(bitsPerEntry, 4096, blockStates).toRaw(data); int num_palette; if (palette instanceof DataPaletteLinear) { + //Get the size of the palette num_palette = ((DataPaletteLinear) palette).b(); } else if (palette instanceof DataPaletteHash) { + //Get the size of the palette num_palette = ((DataPaletteHash) palette).b(); } else { num_palette = 0; @@ -538,6 +544,7 @@ public class BukkitGetBlocks_1_15 extends CharGetBlocks { char ordinal = paletteToBlockChars[paletteVal]; if (ordinal == Character.MAX_VALUE) { paletteToBlockInts[num_palette++] = paletteVal; + //palette.a(Object) is palette.idFor(Object) IBlockData ibd = palette.a(data[i]); if (ibd == null) { ordinal = BlockTypes.AIR.getDefaultState().getOrdinalChar(); @@ -561,6 +568,7 @@ public class BukkitGetBlocks_1_15 extends CharGetBlocks { try { if (num_palette != 1) { for (int i = 0; i < num_palette; i++) { + //palette.a(Object) is palette.idFor(Object) char ordinal = ordinal(palette.a(i), adapter); paletteToOrdinal[i] = ordinal; } diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_15_2/BukkitAdapter_1_15_2.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_15_2/BukkitAdapter_1_15_2.java index e5153bcad..2112942d5 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_15_2/BukkitAdapter_1_15_2.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_15_2/BukkitAdapter_1_15_2.java @@ -5,7 +5,7 @@ import com.boydti.fawe.FaweCache; import com.boydti.fawe.bukkit.adapter.DelegateLock; import com.boydti.fawe.bukkit.adapter.NMSAdapter; import com.boydti.fawe.config.Settings; -import com.boydti.fawe.object.collection.BitArray4096; +import com.boydti.fawe.object.collection.BitArray; import com.boydti.fawe.util.MathMan; import com.boydti.fawe.util.ReflectionUtils; import com.boydti.fawe.util.TaskManager; @@ -14,7 +14,6 @@ import com.sk89q.worldedit.world.block.BlockTypesCache; import io.papermc.lib.PaperLib; import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; -import java.lang.invoke.MethodType; import java.lang.reflect.Method; import java.util.concurrent.locks.ReentrantLock; import net.jpountz.util.UnsafeUtils; @@ -26,7 +25,6 @@ import sun.misc.Unsafe; import java.lang.reflect.Field; import java.util.Arrays; import java.util.concurrent.CompletableFuture; -import java.util.concurrent.locks.Lock; import java.util.function.Function; public final class BukkitAdapter_1_15_2 extends NMSAdapter { @@ -219,7 +217,7 @@ public final class BukkitAdapter_1_15_2 extends NMSAdapter { if (num_palette == 1) { for (int i = 0; i < blockBitArrayEnd; i++) blockStates[i] = 0; } else { - final BitArray4096 bitArray = new BitArray4096(blockStates, bitsPerEntry); + final BitArray bitArray = new BitArray(bitsPerEntry, 4096, blockStates); bitArray.fromRaw(blocksCopy); } diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_15_2/BukkitGetBlocks_1_15_2.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_15_2/BukkitGetBlocks_1_15_2.java index 3578a5549..cd4d6bc2a 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_15_2/BukkitGetBlocks_1_15_2.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_15_2/BukkitGetBlocks_1_15_2.java @@ -8,7 +8,7 @@ import com.boydti.fawe.beta.implementation.queue.QueueHandler; import com.boydti.fawe.bukkit.adapter.DelegateLock; import com.boydti.fawe.bukkit.adapter.mc1_15_2.nbt.LazyCompoundTag_1_15_2; import com.boydti.fawe.object.collection.AdaptedMap; -import com.boydti.fawe.object.collection.BitArray4096; +import com.boydti.fawe.object.collection.BitArray; import com.google.common.base.Suppliers; import com.google.common.collect.Iterables; import com.sk89q.jnbt.CompoundTag; @@ -530,7 +530,7 @@ public class BukkitGetBlocks_1_15_2 extends CharGetBlocks { final int bitsPerEntry = bits.c(); final long[] blockStates = bits.a(); - new BitArray4096(blockStates, bitsPerEntry).toRaw(data); + new BitArray(bitsPerEntry, 4096, blockStates).toRaw(data); int num_palette; if (palette instanceof DataPaletteLinear) { 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 da9874e40..ee43fdc36 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/FaweCache.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/FaweCache.java @@ -8,7 +8,7 @@ import com.boydti.fawe.beta.Trimable; import com.boydti.fawe.beta.implementation.queue.Pool; import com.boydti.fawe.beta.implementation.queue.QueuePool; import com.boydti.fawe.config.Settings; -import com.boydti.fawe.object.collection.BitArray4096; +import com.boydti.fawe.object.collection.BitArray; import com.boydti.fawe.object.collection.CleanableThreadLocal; import com.boydti.fawe.object.collection.VariableThreadLocal; import com.boydti.fawe.object.exception.FaweBlockBagException; @@ -278,7 +278,7 @@ public enum FaweCache implements Trimable { blockStates[0] = 0; blockBitArrayEnd = 1; } else { - BitArray4096 bitArray = new BitArray4096(blockStates, bitsPerEntry); + BitArray bitArray = new BitArray(bitsPerEntry, 4096, blockStates); bitArray.fromRaw(blocksCopy); } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/command/MaskBinding.java b/worldedit-core/src/main/java/com/boydti/fawe/command/MaskBinding.java deleted file mode 100644 index 64f119ee8..000000000 --- a/worldedit-core/src/main/java/com/boydti/fawe/command/MaskBinding.java +++ /dev/null @@ -1,29 +0,0 @@ -//package com.boydti.fawe.command; -// -//import com.sk89q.worldedit.WorldEdit; -//import com.sk89q.worldedit.util.command.parametric.ParameterData; -//import com.sk89q.worldedit.world.block.BlockTypes; -// -//import java.util.ArrayList; -//import java.util.HashSet; -//import java.util.List; -//import java.util.Set; -//import java.util.stream.Collectors; -//import java.util.stream.Stream; -// -//public class MaskBinding extends FaweBinding { -// private final WorldEdit worldEdit; -// -// public MaskBinding(WorldEdit worldEdit) { -// super(worldEdit); -// this.worldEdit = worldEdit; -// } -// -// @Override -// public List getSuggestions(ParameterData parameter, String prefix) { -// if (prefix.isEmpty()) { -// return Stream.concat(Stream.of("#"), BlockTypes.getNameSpaces().stream().map(n -> n + ":")).collect(Collectors.toList()); -// } -// return super.getSuggestions(parameter, prefix); -// } -//} diff --git a/worldedit-core/src/main/java/com/boydti/fawe/command/PatternBinding.java b/worldedit-core/src/main/java/com/boydti/fawe/command/PatternBinding.java deleted file mode 100644 index d3fbc7897..000000000 --- a/worldedit-core/src/main/java/com/boydti/fawe/command/PatternBinding.java +++ /dev/null @@ -1,26 +0,0 @@ -//package com.boydti.fawe.command; -// -//import com.sk89q.worldedit.WorldEdit; -//import com.sk89q.worldedit.util.command.parametric.ParameterData; -//import com.sk89q.worldedit.world.block.BlockTypes; -// -//import java.util.List; -//import java.util.stream.Collectors; -//import java.util.stream.Stream; -// -//public class PatternBinding extends FaweBinding { -// private final WorldEdit worldEdit; -// -// public PatternBinding(WorldEdit worldEdit) { -// super(worldEdit); -// this.worldEdit = worldEdit; -// } -// -// @Override -// public List getSuggestions(ParameterData parameter, String prefix) { -// if (prefix.isEmpty()) { -// return Stream.concat(Stream.of("#"), BlockTypes.getNameSpaces().stream()).collect(Collectors.toList()); -// } -// return super.getSuggestions(parameter, prefix); -// } -//} diff --git a/worldedit-core/src/main/java/com/boydti/fawe/jnbt/anvil/MCAChunk.java b/worldedit-core/src/main/java/com/boydti/fawe/jnbt/anvil/MCAChunk.java index 3978abb41..66f60ac69 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/jnbt/anvil/MCAChunk.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/jnbt/anvil/MCAChunk.java @@ -8,7 +8,7 @@ import com.boydti.fawe.beta.IQueueExtent; import com.boydti.fawe.beta.implementation.filter.block.ChunkFilterBlock; import com.boydti.fawe.jnbt.streamer.StreamDelegate; import com.boydti.fawe.jnbt.streamer.ValueReader; -import com.boydti.fawe.object.collection.BitArray4096; +import com.boydti.fawe.object.collection.BitArray; import com.boydti.fawe.object.collection.BlockVector3ChunkMap; import com.boydti.fawe.util.MathMan; import com.sk89q.jnbt.CompoundTag; @@ -71,7 +71,7 @@ public class MCAChunk implements IChunk { } int bitsPerEntry = MathMan.log2nlz(section.palette.length - 1); - BitArray4096 bitArray = new BitArray4096(section.blocks, bitsPerEntry); + BitArray bitArray = new BitArray(bitsPerEntry, 4096, section.blocks); char[] buffer = FaweCache.IMP.SECTION_BITS_TO_CHAR.get(); bitArray.toRaw(buffer); int offset = section.layer << 12; @@ -324,7 +324,7 @@ public class MCAChunk implements IChunk { blockstates[0] = 0; blockBitArrayEnd = 1; } else { - BitArray4096 bitArray = new BitArray4096(blockstates, bitsPerEntry); + BitArray bitArray = new BitArray(bitsPerEntry, 4096, blockstates); bitArray.fromRaw(blocksCopy); } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/BytePair.java b/worldedit-core/src/main/java/com/boydti/fawe/object/BytePair.java deleted file mode 100644 index ccb56666e..000000000 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/BytePair.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.boydti.fawe.object; - -import com.boydti.fawe.util.MathMan; - -public class BytePair { - public short pair; - - public BytePair(final byte x, final byte z) { - this.pair = MathMan.pairByte(x, z); - } - - public int get0x() { - return MathMan.unpair16x((byte) get0()); - } - - public int get0y() { - return MathMan.unpair16y((byte) get0()); - } - - public int get0() { - return MathMan.unpairShortX(pair); - } - - public int get1() { - return MathMan.unpairShortY(pair); - } - - @Override - public int hashCode() { - return pair; - } - - @Override - public String toString() { - return pair + ""; - } - - @Override - public boolean equals(final Object obj) { - return obj.hashCode() == pair; - } -} diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/DataAnglePattern.java b/worldedit-core/src/main/java/com/boydti/fawe/object/DataAnglePattern.java index cb927b5ac..fc4016206 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/DataAnglePattern.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/DataAnglePattern.java @@ -29,8 +29,9 @@ public class DataAnglePattern extends AbstractPattern { if (!block.getBlockType().getMaterial().isMovementBlocker()) { return -1; } - int slope; - slope = Math.abs(extent.getNearestSurfaceTerrainBlock(x + distance, z, y, 0, maxY) - extent.getNearestSurfaceTerrainBlock(x - distance, z, y, 0, maxY)) * 7; + int slope = Math.abs( + extent.getNearestSurfaceTerrainBlock(x + distance, z, y, 0, maxY) - extent + .getNearestSurfaceTerrainBlock(x - distance, z, y, 0, maxY)) * 7; slope += Math.abs(extent.getNearestSurfaceTerrainBlock(x, z + distance, y, 0, maxY) - extent.getNearestSurfaceTerrainBlock(x, z - distance, y, 0, maxY)) * 7; slope += Math.abs(extent.getNearestSurfaceTerrainBlock(x + distance, z + distance, y, 0, maxY) - extent.getNearestSurfaceTerrainBlock(x - distance, z - distance, y, 0, maxY)) * 5; slope += Math.abs(extent.getNearestSurfaceTerrainBlock(x - distance, z + distance, y, 0, maxY) - extent.getNearestSurfaceTerrainBlock(x + distance, z - distance, y, 0, maxY)) * 5; @@ -42,7 +43,7 @@ public class DataAnglePattern extends AbstractPattern { BlockState block = extent.getBlock(position); int slope = getSlope(block, position, extent); if (slope == -1) return block.toBaseBlock(); - int data = (Math.min(slope, 255)) >> 4; + int data = Math.min(slope, 255) >> 4; return block.withPropertyId(data).toBaseBlock(); } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/IntegerPair.java b/worldedit-core/src/main/java/com/boydti/fawe/object/IntPair.java similarity index 73% rename from worldedit-core/src/main/java/com/boydti/fawe/object/IntegerPair.java rename to worldedit-core/src/main/java/com/boydti/fawe/object/IntPair.java index 902848f9c..e7746664a 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/IntegerPair.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/IntPair.java @@ -1,10 +1,10 @@ package com.boydti.fawe.object; -public class IntegerPair { +public final class IntPair { public int x; public int z; - public IntegerPair(final int x, final int z) { + public IntPair(final int x, final int z) { this.x = x; this.z = z; } @@ -27,7 +27,7 @@ public class IntegerPair { if ((obj == null) || (this.getClass() != obj.getClass())) { return false; } - final IntegerPair other = (IntegerPair) obj; - return ((this.x == other.x) && (this.z == other.z)); + final IntPair other = (IntPair) obj; + return (this.x == other.x) && (this.z == other.z); } } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/IntTriple.java b/worldedit-core/src/main/java/com/boydti/fawe/object/IntTriple.java new file mode 100644 index 000000000..42bd767fc --- /dev/null +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/IntTriple.java @@ -0,0 +1,45 @@ +package com.boydti.fawe.object; + +public final class IntTriple { + + public int x; + public int y; + public int z; + + public IntTriple(int x, int y, int z) { + this.x = x; + this.y = y; + this.z = z; + } + + @Override + public final int hashCode() { + return x ^ (z << 12) ^ (y << 24); + } + + public final int getX() { + return x; + } + + public final int getY() { + return y; + } + + public final int getZ() { + return z; + } + + @Override + public String toString() { + return x + "," + y + "," + z; + } + + @Override + public boolean equals(Object obj) { + if (obj instanceof IntTriple) { + IntTriple other = (IntTriple) obj; + return other.x == x && other.z == z && other.y == y; + } + return false; + } +} diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/IntegerTrio.java b/worldedit-core/src/main/java/com/boydti/fawe/object/IntegerTrio.java deleted file mode 100644 index b328836a0..000000000 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/IntegerTrio.java +++ /dev/null @@ -1,60 +0,0 @@ -package com.boydti.fawe.object; - -public class IntegerTrio { - public int x, y, z; - - public IntegerTrio(int x, int y, int z) { - this.x = x; - this.y = y; - this.z = z; - } - - public IntegerTrio(IntegerTrio node) { - this.x = node.x; - this.y = node.y; - this.z = node.z; - } - - public IntegerTrio() { - } - - public final void set(int x, int y, int z) { - this.x = x; - this.y = y; - this.z = z; - } - - public final void set(IntegerTrio node) { - this.x = node.x; - this.y = node.y; - this.z = node.z; - } - - @Override - public final int hashCode() { - return (x ^ (z << 12)) ^ (y << 24); - } - - public final int getX() { - return x; - } - - public final int getY() { - return y; - } - - public final int getZ() { - return z; - } - - @Override - public String toString() { - return x + "," + y + "," + z; - } - - @Override - public boolean equals(Object obj) { - IntegerTrio other = (IntegerTrio) obj; - return other.x == x && other.z == z && other.y == y; - } -} diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/heightmap/ScalableHeightMap.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/heightmap/ScalableHeightMap.java index dae06fbf0..7b2c2f4cd 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/heightmap/ScalableHeightMap.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/heightmap/ScalableHeightMap.java @@ -1,6 +1,6 @@ package com.boydti.fawe.object.brush.heightmap; -import com.boydti.fawe.object.IntegerPair; +import com.boydti.fawe.object.IntPair; import com.boydti.fawe.util.MainUtil; import com.boydti.fawe.util.MathMan; import com.sk89q.worldedit.extent.clipboard.Clipboard; @@ -65,9 +65,9 @@ public class ScalableHeightMap implements HeightMap { int minY = clipboard.getMinimumPoint().getBlockY(); int maxY = clipboard.getMaximumPoint().getBlockY(); int clipHeight = maxY - minY + 1; - HashSet visited = new HashSet<>(); + HashSet visited = new HashSet<>(); for (BlockVector3 pos : clipboard.getRegion()) { - IntegerPair pair = new IntegerPair(pos.getBlockX(), pos.getBlockZ()); + IntPair pair = new IntPair(pos.getBlockX(), pos.getBlockZ()); if (visited.contains(pair)) { continue; } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/DiskStorageHistory.java b/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/DiskStorageHistory.java index 90b738790..edc368509 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/DiskStorageHistory.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/DiskStorageHistory.java @@ -6,8 +6,7 @@ import com.boydti.fawe.database.DBHandler; import com.boydti.fawe.database.RollbackDatabase; import com.boydti.fawe.object.FaweInputStream; import com.boydti.fawe.object.FaweOutputStream; -import com.boydti.fawe.object.IntegerPair; -import com.boydti.fawe.object.change.MutableFullBlockChange; +import com.boydti.fawe.object.IntPair; import com.boydti.fawe.util.MainUtil; import com.sk89q.jnbt.NBTInputStream; import com.sk89q.jnbt.NBTOutputStream; @@ -16,7 +15,6 @@ import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.world.World; -import java.io.EOFException; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; @@ -386,7 +384,7 @@ public class DiskStorageHistory extends FaweStreamChangeSet { return null; } - public IntegerPair readHeader() { + public IntPair readHeader() { int ox = getOriginX(); int oz = getOriginZ(); if (ox == 0 && oz == 0 && bdFile.exists()) { @@ -404,7 +402,7 @@ public class DiskStorageHistory extends FaweStreamChangeSet { e.printStackTrace(); } } - return new IntegerPair(ox, oz); + return new IntPair(ox, oz); } @Override 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 83fa495ca..671e4b351 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 @@ -1,7 +1,7 @@ package com.boydti.fawe.object.clipboard; import com.boydti.fawe.jnbt.streamer.IntValueReader; -import com.boydti.fawe.object.IntegerTrio; +import com.boydti.fawe.object.IntTriple; import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.IntTag; import com.sk89q.jnbt.Tag; @@ -28,7 +28,7 @@ public class CPUOptimizedClipboard extends LinearClipboard { private BiomeType[] biomes = null; private char[] states; - private final HashMap nbtMapLoc; + private final HashMap nbtMapLoc; private final HashMap nbtMapIndex; @@ -91,8 +91,8 @@ public class CPUOptimizedClipboard extends LinearClipboard { if (nbtMapLoc.isEmpty()) { return; } - for (Map.Entry entry : nbtMapLoc.entrySet()) { - IntegerTrio key = entry.getKey(); + for (Map.Entry entry : nbtMapLoc.entrySet()) { + IntTriple key = entry.getKey(); setTile(getIndex(key.x, key.y, key.z), entry.getValue()); } nbtMapLoc.clear(); @@ -164,7 +164,7 @@ public class CPUOptimizedClipboard extends LinearClipboard { @Override public boolean setTile(int x, int y, int z, CompoundTag tag) { - nbtMapLoc.put(new IntegerTrio(x, y, z), tag); + nbtMapLoc.put(new IntTriple(x, y, z), tag); return true; } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/DiskOptimizedClipboard.java b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/DiskOptimizedClipboard.java index c223c58f2..2b1c613fd 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/DiskOptimizedClipboard.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/DiskOptimizedClipboard.java @@ -3,7 +3,7 @@ package com.boydti.fawe.object.clipboard; import com.boydti.fawe.Fawe; import com.boydti.fawe.config.Settings; import com.boydti.fawe.jnbt.streamer.IntValueReader; -import com.boydti.fawe.object.IntegerTrio; +import com.boydti.fawe.object.IntTriple; import com.boydti.fawe.util.MainUtil; import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.IntTag; @@ -56,7 +56,7 @@ public class DiskOptimizedClipboard extends LinearClipboard implements Closeable private static int HEADER_SIZE = 14; private static final int MAX_SIZE = Short.MAX_VALUE - Short.MIN_VALUE; - private final HashMap nbtMap; + private final HashMap nbtMap; private final File file; private RandomAccessFile braf; @@ -322,8 +322,8 @@ public class DiskOptimizedClipboard extends LinearClipboard implements Closeable CompoundTag nbt; if (nbtMap.size() < 4) { nbt = null; - for (Map.Entry entry : nbtMap.entrySet()) { - IntegerTrio key = entry.getKey(); + for (Map.Entry entry : nbtMap.entrySet()) { + IntTriple key = entry.getKey(); int index = getIndex(key.x, key.y, key.z); if (index == i) { nbt = entry.getValue(); @@ -335,7 +335,7 @@ public class DiskOptimizedClipboard extends LinearClipboard implements Closeable int newI = i - y * getArea(); int z = newI / getWidth(); int x = newI - z * getWidth(); - nbt = nbtMap.get(new IntegerTrio(x, y, z)); + nbt = nbtMap.get(new IntTriple(x, y, z)); } return state.toBaseBlock(nbt); } @@ -344,7 +344,7 @@ public class DiskOptimizedClipboard extends LinearClipboard implements Closeable private BaseBlock toBaseBlock(BlockState state, int x, int y, int z) { if (state.getMaterial().hasContainer() && !nbtMap.isEmpty()) { - CompoundTag nbt = nbtMap.get(new IntegerTrio(x, y, z)); + CompoundTag nbt = nbtMap.get(new IntTriple(x, y, z)); return state.toBaseBlock(nbt); } return state.toBaseBlock(); @@ -375,7 +375,7 @@ public class DiskOptimizedClipboard extends LinearClipboard implements Closeable @Override public boolean setTile(int x, int y, int z, CompoundTag tag) { - nbtMap.put(new IntegerTrio(x, y, z), tag); + nbtMap.put(new IntTriple(x, y, z), tag); Map values = tag.getValue(); values.put("x", new IntTag(x)); values.put("y", new IntTag(y)); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/MemoryOptimizedClipboard.java b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/MemoryOptimizedClipboard.java index 5a95779a4..825415310 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/MemoryOptimizedClipboard.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/MemoryOptimizedClipboard.java @@ -2,7 +2,7 @@ package com.boydti.fawe.object.clipboard; import com.boydti.fawe.config.Settings; import com.boydti.fawe.jnbt.streamer.IntValueReader; -import com.boydti.fawe.object.IntegerTrio; +import com.boydti.fawe.object.IntTriple; import com.boydti.fawe.util.MainUtil; import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.IntTag; @@ -39,7 +39,7 @@ public class MemoryOptimizedClipboard extends LinearClipboard { private byte[] buffer = new byte[MainUtil.getMaxCompressedLength(BLOCK_SIZE)]; private byte[] biomes = null; - private final HashMap nbtMap; + private final HashMap nbtMap; private int lastOrdinalsI = -1; @@ -198,8 +198,8 @@ public class MemoryOptimizedClipboard extends LinearClipboard { CompoundTag nbt; if (nbtMap.size() < 4) { nbt = null; - for (Map.Entry entry : nbtMap.entrySet()) { - IntegerTrio trio = entry.getKey(); + for (Map.Entry entry : nbtMap.entrySet()) { + IntTriple trio = entry.getKey(); int index = getIndex(trio.x, trio.y, trio.z); if (index == i) { nbt = entry.getValue(); @@ -211,7 +211,7 @@ public class MemoryOptimizedClipboard extends LinearClipboard { int newI = i - y * getArea(); int z = newI / getWidth(); int x = newI - z * getWidth(); - nbt = nbtMap.get(new IntegerTrio(x, y, z)); + nbt = nbtMap.get(new IntTriple(x, y, z)); } return state.toBaseBlock(nbt); } @@ -247,7 +247,7 @@ public class MemoryOptimizedClipboard extends LinearClipboard { @Override public boolean setTile(int x, int y, int z, CompoundTag tag) { - nbtMap.put(new IntegerTrio(x, y, z), tag); + nbtMap.put(new IntTriple(x, y, z), tag); Map values = tag.getValue(); values.put("x", new IntTag(x)); values.put("y", new IntTag(y)); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/collection/BitArray4096.java b/worldedit-core/src/main/java/com/boydti/fawe/object/collection/BitArray.java similarity index 76% rename from worldedit-core/src/main/java/com/boydti/fawe/object/collection/BitArray4096.java rename to worldedit-core/src/main/java/com/boydti/fawe/object/collection/BitArray.java index 689c7985f..7717382d0 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/collection/BitArray4096.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/collection/BitArray.java @@ -1,18 +1,18 @@ package com.boydti.fawe.object.collection; -public final class BitArray4096 { +public final class BitArray { private final long[] data; private final int bitsPerEntry; private final int maxSeqLocIndex; - private final int maxEntryValue; + private final long mask; private final int longLen; - public BitArray4096(long[] buffer, int bitsPerEntry) { + public BitArray(int bitsPerEntry, int arraySize, long[] buffer) { this.bitsPerEntry = bitsPerEntry; this.maxSeqLocIndex = 64 - bitsPerEntry; - maxEntryValue = (1 << bitsPerEntry) - 1; - this.longLen = (this.bitsPerEntry << 12) >> 6; + this.mask = (1L << bitsPerEntry) - 1L; + this.longLen = (arraySize * bitsPerEntry) >> 6; if (buffer.length < longLen) { this.data = new long[longLen]; } else { @@ -20,11 +20,11 @@ public final class BitArray4096 { } } - public BitArray4096(int bitsPerEntry) { + public BitArray(int bitsPerEntry, int arraySize) { this.bitsPerEntry = bitsPerEntry; this.maxSeqLocIndex = 64 - bitsPerEntry; - maxEntryValue = (1 << bitsPerEntry) - 1; - this.longLen = (this.bitsPerEntry * 4096) >> 6; + this.mask = (1L << bitsPerEntry) - 1L; + this.longLen = (arraySize * bitsPerEntry) >> 6; this.data = new long[longLen]; } @@ -37,13 +37,13 @@ public final class BitArray4096 { int bitIndexStart = index * bitsPerEntry; int longIndexStart = bitIndexStart >> 6; int localBitIndexStart = bitIndexStart & 63; - this.data[longIndexStart] = this.data[longIndexStart] & ~((long) maxEntryValue << localBitIndexStart) | ((long) value) << localBitIndexStart; + this.data[longIndexStart] = this.data[longIndexStart] & ~(mask << localBitIndexStart) | (long) value << localBitIndexStart; if(localBitIndexStart > maxSeqLocIndex) { int longIndexEnd = longIndexStart + 1; int localShiftStart = 64 - localBitIndexStart; int localShiftEnd = bitsPerEntry - localShiftStart; - this.data[longIndexEnd] = this.data[longIndexEnd] >>> localShiftEnd << localShiftEnd | (((long) value) >> localShiftStart); + this.data[longIndexEnd] = this.data[longIndexEnd] >>> localShiftEnd << localShiftEnd | ((long) value >> localShiftStart); } } @@ -55,34 +55,27 @@ public final class BitArray4096 { int localBitIndexStart = bitIndexStart & 63; if(localBitIndexStart <= maxSeqLocIndex) { - return (int)(this.data[longIndexStart] >>> localBitIndexStart & maxEntryValue); + return (int)(this.data[longIndexStart] >>> localBitIndexStart & mask); } else { int localShift = 64 - localBitIndexStart; - return (int) ((this.data[longIndexStart] >>> localBitIndexStart | this.data[longIndexStart + 1] << localShift) & maxEntryValue); + return (int) ((this.data[longIndexStart] >>> localBitIndexStart | this.data[longIndexStart + 1] << localShift) & mask); } } public int getLength() { return longLen; } - - public final void fromRawSlow(char[] arr) { - for (int i = 0; i < arr.length; i++) { - set(i, arr[i]); - } - } - + public final void fromRaw(int[] arr) { final long[] data = this.data; final int bitsPerEntry = this.bitsPerEntry; final int maxSeqLocIndex = this.maxSeqLocIndex; int localStart = 0; - int lastVal; int arrI = 0; long l = 0; - long nextVal; for (int i = 0; i < longLen; i++) { + int lastVal; for (; localStart <= maxSeqLocIndex; localStart += bitsPerEntry) { lastVal = arr[arrI++]; l |= ((long) lastVal << localStart); @@ -92,7 +85,7 @@ public final class BitArray4096 { lastVal = arr[arrI++]; int shift = 64 - localStart; - nextVal = lastVal >> shift; + long nextVal = lastVal >> shift; l |= ((lastVal - (nextVal << shift)) << localStart); @@ -109,22 +102,6 @@ public final class BitArray4096 { } } - public BitArray4096 growSlow(int bitsPerEntry) { - BitArray4096 newBitArray = new BitArray4096(bitsPerEntry); - for (int i = 0; i < 4096; i++) { - newBitArray.set(i, get(i)); - } - return newBitArray; - } - - public final char[] toRawSlow() { - char[] arr = new char[4096]; - for (int i = 0; i < arr.length; i++) { - arr[i] = (char) get(i); - } - return arr; - } - public final int[] toRaw() { return toRaw(new int[4096]); } @@ -133,15 +110,14 @@ public final class BitArray4096 { final long[] data = this.data; final int dataLength = longLen; final int bitsPerEntry = this.bitsPerEntry; - final int maxEntryValue = this.maxEntryValue; + final long maxEntryValue = this.mask; final int maxSeqLocIndex = this.maxSeqLocIndex; int localStart = 0; - char lastVal; int arrI = 0; - long l; for (int i = 0; i < dataLength; i++) { - l = data[i]; + long l = data[i]; + char lastVal; for (; localStart <= maxSeqLocIndex; localStart += bitsPerEntry) { lastVal = (char) (l >>> localStart & maxEntryValue); buffer[arrI++] = lastVal; @@ -167,15 +143,14 @@ public final class BitArray4096 { final long[] data = this.data; final int dataLength = longLen; final int bitsPerEntry = this.bitsPerEntry; - final int maxEntryValue = this.maxEntryValue; + final long maxEntryValue = this.mask; final int maxSeqLocIndex = this.maxSeqLocIndex; int localStart = 0; - char lastVal; int arrI = 0; - long l; for (int i = 0; i < dataLength; i++) { - l = data[i]; + long l = data[i]; + char lastVal; for (; localStart <= maxSeqLocIndex; localStart += bitsPerEntry) { lastVal = (char) (l >>> localStart & maxEntryValue); buffer[arrI++] = lastVal; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/BlockTranslateExtent.java b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/BlockTranslateExtent.java index c88416df8..ea2f736b7 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/BlockTranslateExtent.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/BlockTranslateExtent.java @@ -1,15 +1,14 @@ package com.boydti.fawe.object.extent; import com.sk89q.worldedit.WorldEditException; -import com.sk89q.worldedit.extent.PassthroughExtent; -import com.sk89q.worldedit.world.block.BaseBlock; -import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.extent.AbstractDelegateExtent; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.math.BlockVector2; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.MutableBlockVector3; import com.sk89q.worldedit.world.biome.BiomeType; +import com.sk89q.worldedit.world.block.BaseBlock; +import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockStateHolder; public class BlockTranslateExtent extends AbstractDelegateExtent { @@ -25,9 +24,9 @@ public class BlockTranslateExtent extends AbstractDelegateExtent { @Override public > boolean setBlock(BlockVector3 location, T block) throws WorldEditException { - mutable.mutX((location.getX() + dx)); - mutable.mutY((location.getY() + dy)); - mutable.mutZ((location.getZ() + dz)); + mutable.mutX(location.getX() + dx); + mutable.mutY(location.getY() + dy); + mutable.mutZ(location.getZ() + dz); return getExtent().setBlock(mutable, block); } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/ExtentHeightCacher.java b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/ExtentHeightCacher.java index b658d630b..f4d871c68 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/ExtentHeightCacher.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/ExtentHeightCacher.java @@ -2,11 +2,14 @@ package com.boydti.fawe.object.extent; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.extent.PassthroughExtent; - import java.util.Arrays; public class ExtentHeightCacher extends PassthroughExtent { + private transient int cacheBotX = Integer.MIN_VALUE; + private transient int cacheBotZ = Integer.MIN_VALUE; + private transient byte[] cacheHeights; + private transient int lastY; public ExtentHeightCacher(Extent extent) { super(extent); } @@ -19,11 +22,6 @@ public class ExtentHeightCacher extends PassthroughExtent { } } - private transient int cacheBotX = Integer.MIN_VALUE; - private transient int cacheBotZ = Integer.MIN_VALUE; - private transient byte[] cacheHeights; - private transient int lastY; - @Override public int getNearestSurfaceTerrainBlock(int x, int z, int y, int minY, int maxY) { int rx = x - cacheBotX + 16; @@ -46,7 +44,8 @@ public class ExtentHeightCacher extends PassthroughExtent { } int result = cacheHeights[index] & 0xFF; if (result == 0) { - cacheHeights[index] = (byte) (result = lastY = super.getNearestSurfaceTerrainBlock(x, z, lastY, minY, maxY)); + cacheHeights[index] = (byte) (result = lastY = super + .getNearestSurfaceTerrainBlock(x, z, lastY, minY, maxY)); } return result; } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/FaweRegionExtent.java b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/FaweRegionExtent.java index d43c38f14..a6b494cde 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/FaweRegionExtent.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/FaweRegionExtent.java @@ -22,6 +22,7 @@ import java.util.Collection; import javax.annotation.Nullable; public abstract class FaweRegionExtent extends ResettableExtent implements IBatchProcessor { + private final FaweLimit limit; /** @@ -68,7 +69,8 @@ public abstract class FaweRegionExtent extends ResettableExtent implements IBatc } @Override - public > boolean setBlock(int x, int y, int z, B block) throws WorldEditException { + public > boolean setBlock(int x, int y, int z, B block) + throws WorldEditException { if (!contains(x, y, z)) { if (!limit.MAX_FAILS()) { WEManager.IMP.cancelEditSafe(this, FaweCache.OUTSIDE_REGION); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/HeightBoundExtent.java b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/HeightBoundExtent.java index 87b467e16..888b7a923 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/HeightBoundExtent.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/HeightBoundExtent.java @@ -38,7 +38,9 @@ public class HeightBoundExtent extends FaweRegionExtent { @Override public Collection getRegions() { - return Collections.singletonList(new RegionWrapper(Integer.MIN_VALUE, Integer.MAX_VALUE, min, max, Integer.MIN_VALUE, Integer.MAX_VALUE)); + return Collections.singletonList( + new RegionWrapper(Integer.MIN_VALUE, Integer.MAX_VALUE, min, max, Integer.MIN_VALUE, + Integer.MAX_VALUE)); } @Override diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/MemoryCheckingExtent.java b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/MemoryCheckingExtent.java index 29f73f8cc..337425da1 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/MemoryCheckingExtent.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/MemoryCheckingExtent.java @@ -10,6 +10,7 @@ import com.sk89q.worldedit.extent.PassthroughExtent; import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; public class MemoryCheckingExtent extends PassthroughExtent { + private final Player player; public MemoryCheckingExtent(Player player, Extent extent) { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/MultiRegionExtent.java b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/MultiRegionExtent.java index e4b36a1db..a36cea3f9 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/MultiRegionExtent.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/MultiRegionExtent.java @@ -7,15 +7,14 @@ import com.boydti.fawe.object.FaweLimit; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.regions.RegionIntersection; - import java.util.Arrays; import java.util.Collection; public class MultiRegionExtent extends FaweRegionExtent { private final RegionIntersection intersection; - private Region region; private final Region[] regions; + private Region region; private int index; /** diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/MultiTransform.java b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/MultiTransform.java index b5be6b9e1..f09c895ae 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/MultiTransform.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/MultiTransform.java @@ -9,15 +9,17 @@ import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.block.BlockStateHolder; -import java.util.Arrays; import java.util.Collection; import javax.annotation.Nullable; public class MultiTransform extends RandomTransform { + private ResettableExtent[] extents; public MultiTransform(Collection extents) { - for (ResettableExtent extent : extents) add(extent, 1); + for (ResettableExtent extent : extents) { + add(extent, 1); + } } public MultiTransform() { @@ -31,18 +33,24 @@ public class MultiTransform extends RandomTransform { } @Override - public > boolean setBlock(int x, int y, int z, T block) throws WorldEditException { + public > boolean setBlock(int x, int y, int z, T block) + throws WorldEditException { // don't use streams for each block place, it'd be incredibly slow boolean result = false; - for (AbstractDelegateExtent extent : extents) result |= extent.setBlock(x, y, z, block); + for (AbstractDelegateExtent extent : extents) { + result |= extent.setBlock(x, y, z, block); + } return result; } @Override - public > boolean setBlock(BlockVector3 location, T block) throws WorldEditException { + public > boolean setBlock(BlockVector3 location, T block) + throws WorldEditException { // don't use streams for each block place, it'd be incredibly slow boolean result = false; - for (AbstractDelegateExtent extent : extents) result |= extent.setBlock(location, block); + for (AbstractDelegateExtent extent : extents) { + result |= extent.setBlock(location, block); + } return result; } @@ -50,7 +58,9 @@ public class MultiTransform extends RandomTransform { public boolean setBiome(BlockVector2 position, BiomeType biome) { // don't use streams for each block place, it'd be incredibly slow boolean result = false; - for (AbstractDelegateExtent extent : extents) result |= extent.setBiome(position, biome); + for (AbstractDelegateExtent extent : extents) { + result |= extent.setBiome(position, biome); + } return result; } @@ -58,7 +68,9 @@ public class MultiTransform extends RandomTransform { @Override public Entity createEntity(Location location, BaseEntity entity) { Entity created = null; - for (AbstractDelegateExtent extent : extents) created = extent.createEntity(location, entity); + for (AbstractDelegateExtent extent : extents) { + created = extent.createEntity(location, entity); + } return created; } } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/NullExtent.java b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/NullExtent.java index 6146faac8..0f5fa61f6 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/NullExtent.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/NullExtent.java @@ -39,6 +39,7 @@ import java.util.List; import java.util.Set; import javax.annotation.Nullable; +//todo This should be removed in favor of com.sk89q.worldedit.extent.NullExtent public class NullExtent extends FaweRegionExtent implements IBatchProcessor { private final FaweException reason; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/OffsetExtent.java b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/OffsetExtent.java index 2071b2762..7eff78973 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/OffsetExtent.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/OffsetExtent.java @@ -9,6 +9,7 @@ import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.block.BlockStateHolder; public class OffsetExtent extends ResettableExtent { + private final int dx, dy, dz; private transient MutableBlockVector2 mutable = new MutableBlockVector2(); @@ -21,7 +22,9 @@ public class OffsetExtent extends ResettableExtent { @Override public boolean setBiome(BlockVector2 position, BiomeType biome) { - return getExtent().setBiome(mutable.setComponents(position.getBlockX() + dx, position.getBlockZ() + dz), biome); + return getExtent() + .setBiome(mutable.setComponents(position.getBlockX() + dx, position.getBlockZ() + dz), + biome); } @Override @@ -30,12 +33,15 @@ public class OffsetExtent extends ResettableExtent { } @Override - public > boolean setBlock(BlockVector3 location, T block) throws WorldEditException { - return getExtent().setBlock(location.getBlockX() + dx, location.getBlockY() + dy, location.getBlockZ() + dz, block); + public > boolean setBlock(BlockVector3 location, T block) + throws WorldEditException { + return getExtent().setBlock(location.getBlockX() + dx, location.getBlockY() + dy, + location.getBlockZ() + dz, block); } @Override - public > boolean setBlock(int x, int y, int z, T block) throws WorldEditException { + public > boolean setBlock(int x, int y, int z, T block) + throws WorldEditException { return getExtent().setBlock(x + dx, y + dy, z + dz, block); } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/PatternTransform.java b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/PatternTransform.java index 664070641..e65e35d4a 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/PatternTransform.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/PatternTransform.java @@ -1,13 +1,13 @@ package com.boydti.fawe.object.extent; import com.sk89q.worldedit.WorldEditException; - import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BlockStateHolder; public class PatternTransform extends ResettableExtent { + private final Pattern pattern; public PatternTransform(Extent parent, Pattern pattern) { @@ -16,7 +16,8 @@ public class PatternTransform extends ResettableExtent { } @Override - public > boolean setBlock(BlockVector3 location, B block) throws WorldEditException { + public > boolean setBlock(BlockVector3 location, B block) + throws WorldEditException { return pattern.apply(getExtent(), location, location); } } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/PositionTransformExtent.java b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/PositionTransformExtent.java index 627a74198..4a4963adb 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/PositionTransformExtent.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/PositionTransformExtent.java @@ -30,6 +30,7 @@ public class PositionTransformExtent extends ResettableExtent { return super.setExtent(extent); } + @Override public void setOrigin(BlockVector3 pos) { this.min = pos; } @@ -38,9 +39,9 @@ public class PositionTransformExtent extends ResettableExtent { if (min == null) { min = pos; } - mutable.mutX(((pos.getX() - min.getX()))); - mutable.mutY(((pos.getY() - min.getY()))); - mutable.mutZ(((pos.getZ() - min.getZ()))); + mutable.mutX(pos.getX() - min.getX()); + mutable.mutY(pos.getY() - min.getY()); + mutable.mutZ(pos.getZ() - min.getZ()); MutableVector3 tmp = new MutableVector3(transform.apply(mutable.toVector3())); return min.add(tmp.toBlockPoint()); } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/ProcessedWEExtent.java b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/ProcessedWEExtent.java index 948bd3fd1..a1ff5f79a 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/ProcessedWEExtent.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/ProcessedWEExtent.java @@ -2,7 +2,6 @@ package com.boydti.fawe.object.extent; import com.boydti.fawe.FaweCache; import com.boydti.fawe.object.FaweLimit; -import com.boydti.fawe.object.exception.FaweException; import com.boydti.fawe.util.WEManager; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.entity.BaseEntity; @@ -19,6 +18,7 @@ import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockTypes; public class ProcessedWEExtent extends AbstractDelegateExtent { + private final FaweLimit limit; private final Extent extent; @@ -65,7 +65,8 @@ public class ProcessedWEExtent extends AbstractDelegateExtent { } @Override - public > boolean setBlock(BlockVector3 location, B block) throws WorldEditException { + public > boolean setBlock(BlockVector3 location, B block) + throws WorldEditException { return setBlock(location.getBlockX(), location.getBlockY(), location.getBlockZ(), block); } @@ -75,7 +76,8 @@ public class ProcessedWEExtent extends AbstractDelegateExtent { } @Override - public > boolean setBlock(int x, int y, int z, B block) throws WorldEditException { + public > boolean setBlock(int x, int y, int z, B block) + throws WorldEditException { boolean hasNbt = block instanceof BaseBlock && block.hasNbtData(); if (hasNbt) { if (!limit.MAX_BLOCKSTATES()) { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/RandomOffsetTransform.java b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/RandomOffsetTransform.java index e4d3d0372..e9c578664 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/RandomOffsetTransform.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/RandomOffsetTransform.java @@ -1,21 +1,19 @@ package com.boydti.fawe.object.extent; import com.sk89q.worldedit.WorldEditException; - import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.math.BlockVector2; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.MutableBlockVector2; import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.block.BlockStateHolder; - import java.util.SplittableRandom; public class RandomOffsetTransform extends ResettableExtent { - private transient SplittableRandom random; - private transient MutableBlockVector2 mutable = new MutableBlockVector2(); private final int dx, dy, dz; + private transient SplittableRandom random; + private transient MutableBlockVector2 mutable = new MutableBlockVector2(); public RandomOffsetTransform(Extent parent, int dx, int dy, int dz) { super(parent); @@ -33,7 +31,8 @@ public class RandomOffsetTransform extends ResettableExtent { } @Override - public > boolean setBlock(BlockVector3 pos, T block) throws WorldEditException { + public > boolean setBlock(BlockVector3 pos, T block) + throws WorldEditException { int x = pos.getBlockX() + random.nextInt(1 + (dx << 1)) - dx; int y = pos.getBlockY() + random.nextInt(1 + (dy << 1)) - dy; int z = pos.getBlockZ() + random.nextInt(1 + (dz << 1)) - dz; @@ -41,7 +40,8 @@ public class RandomOffsetTransform extends ResettableExtent { } @Override - public > boolean setBlock(int x, int y, int z, T block) throws WorldEditException { + public > boolean setBlock(int x, int y, int z, T block) + throws WorldEditException { x = x + random.nextInt(1 + (dx << 1)) - dx; y = y + random.nextInt(1 + (dy << 1)) - dy; z = z + random.nextInt(1 + (dz << 1)) - dz; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/RandomTransform.java b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/RandomTransform.java index f9807e129..08e7d4950 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/RandomTransform.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/RandomTransform.java @@ -1,5 +1,7 @@ package com.boydti.fawe.object.extent; +import static com.google.common.base.Preconditions.checkNotNull; + import com.boydti.fawe.object.collection.RandomCollection; import com.boydti.fawe.object.random.SimpleRandom; import com.boydti.fawe.object.random.TrueRandom; @@ -10,9 +12,6 @@ import java.util.LinkedHashSet; import java.util.Map; import java.util.Set; - -import static com.google.common.base.Preconditions.checkNotNull; - /** * Uses a random pattern of a weighted list of patterns. */ @@ -28,6 +27,10 @@ public class RandomTransform extends SelectTransform { this(new TrueRandom()); } + public RandomTransform(SimpleRandom random) { + this.random = random; + } + @Override public AbstractDelegateExtent getExtent(int x, int y, int z) { return collection.next(x, y, z); @@ -38,10 +41,6 @@ public class RandomTransform extends SelectTransform { return collection.next(x, 0, z); } - public RandomTransform(SimpleRandom random) { - this.random = random; - } - @Override public ResettableExtent setExtent(Extent extent) { if (collection == null) { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/ResettableExtent.java b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/ResettableExtent.java index b806c004e..c5275ea80 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/ResettableExtent.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/ResettableExtent.java @@ -14,6 +14,7 @@ import java.io.Serializable; import java.lang.reflect.Field; public class ResettableExtent extends AbstractDelegateExtent implements Serializable { + public ResettableExtent(Extent parent) { super(parent); } @@ -26,12 +27,14 @@ public class ResettableExtent extends AbstractDelegateExtent implements Serializ setOrigin(pos); } - protected void setOrigin(BlockVector3 pos) {} + protected void setOrigin(BlockVector3 pos) { + } public ResettableExtent setExtent(Extent extent) { checkNotNull(extent); Extent next = getExtent(); - if (!(next instanceof NullExtent) && !(next instanceof World) && next instanceof ResettableExtent) { + if (!(next instanceof NullExtent) && !(next instanceof World) + && next instanceof ResettableExtent) { ((ResettableExtent) next).setExtent(extent); } else { new ExtentTraverser(this).setNext(new AbstractDelegateExtent(extent)); @@ -49,7 +52,8 @@ public class ResettableExtent extends AbstractDelegateExtent implements Serializ } } - private void readObject(java.io.ObjectInputStream stream) throws IOException, ClassNotFoundException { + private void readObject(java.io.ObjectInputStream stream) + throws IOException, ClassNotFoundException { stream.defaultReadObject(); if (stream.readBoolean()) { try { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/ScaleTransform.java b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/ScaleTransform.java index 874b635f3..76129bc48 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/ScaleTransform.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/ScaleTransform.java @@ -1,7 +1,6 @@ package com.boydti.fawe.object.extent; import com.sk89q.worldedit.WorldEditException; - import com.sk89q.worldedit.entity.BaseEntity; import com.sk89q.worldedit.entity.Entity; import com.sk89q.worldedit.extent.Extent; @@ -11,16 +10,15 @@ import com.sk89q.worldedit.math.MutableBlockVector3; import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.block.BlockStateHolder; - import javax.annotation.Nullable; public class ScaleTransform extends ResettableExtent { + + private final double dx, dy, dz; private transient MutableBlockVector3 mutable = new MutableBlockVector3(); private transient int maxy; private transient BlockVector3 min; - private final double dx, dy, dz; - public ScaleTransform(Extent parent, double dx, double dy, double dz) { super(parent); @@ -42,9 +40,9 @@ public class ScaleTransform extends ResettableExtent { if (min == null) { min = pos; } - mutable.mutX((min.getX() + (pos.getX() - min.getX()) * dx)); - mutable.mutY((min.getY() + (pos.getY() - min.getY()) * dy)); - mutable.mutZ((min.getZ() + (pos.getZ() - min.getZ()) * dz)); + mutable.mutX(min.getX() + (pos.getX() - min.getX()) * dx); + mutable.mutY(min.getY() + (pos.getY() - min.getY()) * dy); + mutable.mutZ(min.getZ() + (pos.getZ() - min.getZ()) * dz); return mutable; } @@ -52,15 +50,16 @@ public class ScaleTransform extends ResettableExtent { if (min == null) { min = BlockVector3.at(x, y, z); } - mutable.mutX((min.getX() + (x - min.getX()) * dx)); - mutable.mutY((min.getY() + (y - min.getY()) * dy)); - mutable.mutZ((min.getZ() + (z - min.getZ()) * dz)); + mutable.mutX(min.getX() + (x - min.getX()) * dx); + mutable.mutY(min.getY() + (y - min.getY()) * dy); + mutable.mutZ(min.getZ() + (z - min.getZ()) * dz); return mutable; } @Override - public > boolean setBlock(BlockVector3 location, B block) throws WorldEditException { + public > boolean setBlock(BlockVector3 location, B block) + throws WorldEditException { boolean result = false; MutableBlockVector3 pos = new MutableBlockVector3(getPos(location)); double sx = pos.getX(); @@ -82,7 +81,8 @@ public class ScaleTransform extends ResettableExtent { @Override public boolean setBiome(BlockVector2 position, BiomeType biome) { boolean result = false; - MutableBlockVector3 pos = new MutableBlockVector3(getPos(position.getBlockX(), 0, position.getBlockZ())); + MutableBlockVector3 pos = new MutableBlockVector3( + getPos(position.getBlockX(), 0, position.getBlockZ())); double sx = pos.getX(); double sz = pos.getZ(); double ex = pos.getX() + dx; @@ -96,7 +96,8 @@ public class ScaleTransform extends ResettableExtent { } @Override - public > boolean setBlock(int x1, int y1, int z1, B block) throws WorldEditException { + public > boolean setBlock(int x1, int y1, int z1, B block) + throws WorldEditException { boolean result = false; MutableBlockVector3 pos = new MutableBlockVector3(getPos(x1, y1, z1)); double sx = pos.getX(); @@ -118,7 +119,9 @@ public class ScaleTransform extends ResettableExtent { @Nullable @Override public Entity createEntity(Location location, BaseEntity entity) { - Location newLoc = new Location(location.getExtent(), getPos(location.getBlockX(), location.getBlockY(), location.getBlockZ()).toVector3(), location.getYaw(), location.getPitch()); + Location newLoc = new Location(location.getExtent(), + getPos(location.getBlockX(), location.getBlockY(), location.getBlockZ()).toVector3(), + location.getYaw(), location.getPitch()); return super.createEntity(newLoc, entity); } } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/SelectTransform.java b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/SelectTransform.java index f9817c0d4..108083a1f 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/SelectTransform.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/SelectTransform.java @@ -14,6 +14,7 @@ import com.sk89q.worldedit.world.block.BlockStateHolder; import javax.annotation.Nullable; public abstract class SelectTransform extends ResettableExtent { + public SelectTransform() { super(new NullExtent()); } @@ -31,19 +32,22 @@ public abstract class SelectTransform extends ResettableExtent { } @Override - public > boolean setBlock(int x, int y, int z, T block) throws WorldEditException { + public > boolean setBlock(int x, int y, int z, T block) + throws WorldEditException { return getExtent(x, y, z).setBlock(x, y, z, block); } @Override - public > boolean setBlock(BlockVector3 position, T block) throws WorldEditException { + public > boolean setBlock(BlockVector3 position, T block) + throws WorldEditException { return getExtent(position).setBlock(position, block); } @Nullable @Override public Entity createEntity(Location position, BaseEntity entity) { - return getExtent(position.getBlockX(), position.getBlockY(), position.getBlockZ()).createEntity(position, entity); + return getExtent(position.getBlockX(), position.getBlockY(), position.getBlockZ()) + .createEntity(position, entity); } @Override diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/TemporalExtent.java b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/TemporalExtent.java index c7d0cc2bd..3a58f2a36 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/TemporalExtent.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/TemporalExtent.java @@ -61,7 +61,7 @@ public class TemporalExtent extends PassthroughExtent { if (position.getX() == x && position.getY() == y && position.getZ() == z) { if(block instanceof BaseBlock) { return (BaseBlock)block; - }else { + } else { return block.toBaseBlock(); } } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/TransformExtent.java b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/TransformExtent.java index 958005b3e..4dddc4bed 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/TransformExtent.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/TransformExtent.java @@ -93,13 +93,15 @@ public class TransformExtent extends BlockTransformExtent { } @Override - public > boolean setBlock(int x, int y, int z, T block) throws WorldEditException { + public > boolean setBlock(int x, int y, int z, T block) + throws WorldEditException { return super.setBlock(getPos(x, y, z), transformInverse(block)); } @Override - public > boolean setBlock(BlockVector3 location, B block) throws WorldEditException { + public > boolean setBlock(BlockVector3 location, B block) + throws WorldEditException { return super.setBlock(getPos(location), transformInverse(block)); } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/function/block/BiomeCopy.java b/worldedit-core/src/main/java/com/boydti/fawe/object/function/block/BiomeCopy.java index 57ea2ff45..78153e4c9 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/function/block/BiomeCopy.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/function/block/BiomeCopy.java @@ -8,6 +8,7 @@ import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.MutableBlockVector2; public class BiomeCopy implements RegionFunction { + protected final Extent source; protected final Extent destination; private final MutableBlockVector2 mPos2d; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/visitor/AboveVisitor.java b/worldedit-core/src/main/java/com/boydti/fawe/object/visitor/AboveVisitor.java index 6421601f6..d5a69f048 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/visitor/AboveVisitor.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/visitor/AboveVisitor.java @@ -1,17 +1,15 @@ package com.boydti.fawe.object.visitor; +import static com.google.common.base.Preconditions.checkNotNull; + import com.sk89q.worldedit.function.RegionFunction; import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.function.visitor.RecursiveVisitor; import com.sk89q.worldedit.math.BlockVector3; - -import static com.google.common.base.Preconditions.checkNotNull; - /** - * Visits adjacent points on the same X-Z plane as long as the points - * pass the given mask, and then executes the provided region - * function on the entire column. + * Visits adjacent points on the same X-Z plane as long as the points pass the given mask, and then + * executes the provided region function on the entire column. *

*

This is used by {@code //fill}.

*/ @@ -22,9 +20,9 @@ public class AboveVisitor extends RecursiveVisitor { /** * Create a new visitor. * - * @param mask the mask + * @param mask the mask * @param function the function - * @param baseY the base Y + * @param baseY the base Y */ public AboveVisitor(Mask mask, RegionFunction function, int baseY) { this(mask, function, baseY, Integer.MAX_VALUE); @@ -37,12 +35,12 @@ public class AboveVisitor extends RecursiveVisitor { this.baseY = baseY; setDirections( - BlockVector3.UNIT_MINUS_X, - BlockVector3.UNIT_MINUS_Y, - BlockVector3.UNIT_MINUS_Z, - BlockVector3.UNIT_X, - BlockVector3.UNIT_Y, - BlockVector3.UNIT_Z + BlockVector3.UNIT_MINUS_X, + BlockVector3.UNIT_MINUS_Y, + BlockVector3.UNIT_MINUS_Z, + BlockVector3.UNIT_X, + BlockVector3.UNIT_Y, + BlockVector3.UNIT_Z ); } @@ -50,4 +48,4 @@ public class AboveVisitor extends RecursiveVisitor { public boolean isVisitable(BlockVector3 from, BlockVector3 to) { return (from.getBlockY() >= baseY) && super.isVisitable(from, to); } -} \ No newline at end of file +} diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/visitor/DFSRecursiveVisitor.java b/worldedit-core/src/main/java/com/boydti/fawe/object/visitor/DFSRecursiveVisitor.java index 1ed62df9e..6b9506184 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/visitor/DFSRecursiveVisitor.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/visitor/DFSRecursiveVisitor.java @@ -1,15 +1,14 @@ package com.boydti.fawe.object.visitor; -import com.sk89q.worldedit.function.RegionFunction; -import com.sk89q.worldedit.function.mask.Mask; -import com.sk89q.worldedit.function.visitor.RecursiveVisitor; -import com.sk89q.worldedit.math.BlockVector3; - import static com.google.common.base.Preconditions.checkNotNull; +import com.sk89q.worldedit.function.RegionFunction; +import com.sk89q.worldedit.function.mask.Mask; +import com.sk89q.worldedit.math.BlockVector3; + /** - * An implementation of an {@link com.sk89q.worldedit.function.visitor.BreadthFirstSearch} that uses a mask to - * determine where a block should be visited. + * An implementation of an {@link com.sk89q.worldedit.function.visitor.BreadthFirstSearch} that uses + * a mask to determine where a block should be visited. */ public class DFSRecursiveVisitor extends DFSVisitor { @@ -22,10 +21,11 @@ public class DFSRecursiveVisitor extends DFSVisitor { /** * Create a new recursive visitor. * - * @param mask the mask + * @param mask the mask * @param function the function */ - public DFSRecursiveVisitor(final Mask mask, final RegionFunction function, int maxDepth, int maxBranching) { + public DFSRecursiveVisitor(final Mask mask, final RegionFunction function, int maxDepth, + int maxBranching) { super(function, maxDepth, maxBranching); checkNotNull(mask); this.mask = mask; @@ -35,4 +35,4 @@ public class DFSRecursiveVisitor extends DFSVisitor { public boolean isVisitable(final BlockVector3 from, final BlockVector3 to) { return this.mask.test(to); } -} \ No newline at end of file +} diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/visitor/DFSVisitor.java b/worldedit-core/src/main/java/com/boydti/fawe/object/visitor/DFSVisitor.java index 89f5634de..aff85f1fb 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/visitor/DFSVisitor.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/visitor/DFSVisitor.java @@ -1,17 +1,16 @@ package com.boydti.fawe.object.visitor; +import com.boydti.fawe.object.IntTriple; import com.google.common.collect.Lists; -import com.sk89q.worldedit.util.formatting.text.Component; -import com.sk89q.worldedit.util.formatting.text.TextComponent; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; -import com.boydti.fawe.object.IntegerTrio; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.function.RegionFunction; import com.sk89q.worldedit.function.operation.Operation; import com.sk89q.worldedit.function.operation.RunContext; import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.util.formatting.text.Component; +import com.sk89q.worldedit.util.formatting.text.TextComponent; +import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; import com.sk89q.worldedit.util.formatting.text.format.TextColor; - import java.util.ArrayDeque; import java.util.ArrayList; import java.util.HashSet; @@ -57,11 +56,11 @@ public abstract class DFSVisitor implements Operation { return this.directions; } - private IntegerTrio[] getIntDirections() { - IntegerTrio[] array = new IntegerTrio[directions.size()]; + private IntTriple[] getIntDirections() { + IntTriple[] array = new IntTriple[directions.size()]; for (int i = 0; i < array.length; i++) { BlockVector3 dir = directions.get(i); - array[i] = new IntegerTrio(dir.getBlockX(), dir.getBlockY(), dir.getBlockZ()); + array[i] = new IntTriple(dir.getBlockX(), dir.getBlockY(), dir.getBlockZ()); } return array; } @@ -77,17 +76,13 @@ public abstract class DFSVisitor implements Operation { @Override public Operation resume(RunContext run) throws WorldEditException { - NodePair current; - Node from; - Node adjacent; -// MutableBlockVector3 mutable = new MutableBlockVector3(); + // MutableBlockVector3 mutable = new MutableBlockVector3(); // MutableBlockVector3 mutable2 = new MutableBlockVector3(); - int countAdd, countAttempt; - IntegerTrio[] dirs = getIntDirections(); + IntTriple[] dirs = getIntDirections(); - for (int layer = 0; !queue.isEmpty(); layer++) { - current = queue.poll(); - from = current.to; + while (!queue.isEmpty()) { + NodePair current = queue.poll(); + Node from = current.to; hashQueue.remove(from); if (visited.containsKey(from)) { continue; @@ -97,16 +92,18 @@ public abstract class DFSVisitor implements Operation { // mutable.mutZ(from.getZ()); BlockVector3 bv = BlockVector3.at(from.getX(), from.getY(), from.getZ()); function.apply(bv); - countAdd = 0; - countAttempt = 0; - for (IntegerTrio direction : dirs) { + int countAdd = 0; + int countAttempt = 0; + for (IntTriple direction : dirs) { // mutable2.mutX(from.getX() + direction.x); // mutable2.mutY(from.getY() + direction.y); // mutable2.mutZ(from.getZ() + direction.z); - BlockVector3 bv2 = BlockVector3.at(from.getX() + direction.x, from.getY() + direction.y, from.getZ() + direction.z); + BlockVector3 bv2 = BlockVector3 + .at(from.getX() + direction.x, from.getY() + direction.y, + from.getZ() + direction.z); if (isVisitable(bv, bv2)) { - adjacent = new Node(bv2.getBlockX(), bv2.getBlockY(), bv2.getBlockZ()); - if ((!adjacent.equals(current.from))) { + Node adjacent = new Node(bv2.getBlockX(), bv2.getBlockY(), bv2.getBlockZ()); + if (!adjacent.equals(current.from)) { AtomicInteger adjacentCount = visited.get(adjacent); if (adjacentCount == null) { if (countAdd++ < maxBranch) { @@ -115,7 +112,8 @@ public abstract class DFSVisitor implements Operation { countAttempt++; } else { hashQueue.add(adjacent); - queue.addFirst(new NodePair(from, adjacent, current.depth + 1)); + queue.addFirst( + new NodePair(from, adjacent, current.depth + 1)); } } else { countAttempt++; @@ -146,8 +144,8 @@ public abstract class DFSVisitor implements Operation { public Iterable getStatusMessages() { return Lists.newArrayList(TranslatableComponent.of( - "fawe.worldedit.visitor.visitor.block", - TextComponent.of(getAffected()) + "fawe.worldedit.visitor.visitor.block", + TextComponent.of(getAffected()) ).color(TextColor.GRAY)); } @@ -155,19 +153,8 @@ public abstract class DFSVisitor implements Operation { return this.affected; } - public class NodePair { - public final Node to; - public final Node from; - private final int depth; - - public NodePair(Node from, Node to, int depth) { - this.from = from; - this.to = to; - this.depth = depth; - } - } - public static final class Node { + private int x, y, z; public Node(int x, int y, int z) { @@ -176,13 +163,13 @@ public abstract class DFSVisitor implements Operation { this.z = z; } - private final void set(int x, int y, int z) { + private void set(int x, int y, int z) { this.x = x; this.y = y; this.z = z; } - private final void set(Node node) { + private void set(Node node) { this.x = node.x; this.y = node.y; this.z = node.z; @@ -193,15 +180,15 @@ public abstract class DFSVisitor implements Operation { return (x ^ (z << 12)) ^ (y << 24); } - private final int getX() { + private int getX() { return x; } - private final int getY() { + private int getY() { return y; } - private final int getZ() { + private int getZ() { return z; } @@ -216,4 +203,17 @@ public abstract class DFSVisitor implements Operation { return other.x == x && other.z == z && other.y == y; } } + + public static class NodePair { + + public final Node to; + public final Node from; + private final int depth; + + NodePair(Node from, Node to, int depth) { + this.from = from; + this.to = to; + this.depth = depth; + } + } } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/util/TextureUtil.java b/worldedit-core/src/main/java/com/boydti/fawe/util/TextureUtil.java index 40609ff24..c92afc2f8 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/util/TextureUtil.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/util/TextureUtil.java @@ -248,10 +248,10 @@ public class TextureUtil implements TextureHolder { new BiomeColor(167, "modified_badlands_plateau", 2.0f, 0.0f, 0x92BD59, 0x77AB2F), new BiomeColor(168, "bamboo_jungle", 0.95f, 0.9f, 0x92BD59, 0x77AB2F), new BiomeColor(169, "bamboo_jungle_hills", 0.8f, 0.4f, 0x92BD59, 0x77AB2F), - new BiomeColor(170, "Unknown Biome", 0.8f, 0.4f, 0x92BD59, 0x77AB2F), - new BiomeColor(171, "Unknown Biome", 0.8f, 0.4f, 0x92BD59, 0x77AB2F), - new BiomeColor(172, "Unknown Biome", 0.8f, 0.4f, 0x92BD59, 0x77AB2F), - new BiomeColor(173, "Unknown Biome", 0.8f, 0.4f, 0x92BD59, 0x77AB2F), + new BiomeColor(170, "Unknown Biome", 2.0f, 0.0f, 0x92BD59, 0x77AB2F), + new BiomeColor(171, "Unknown Biome", 2.0f, 0.0f, 0x92BD59, 0x77AB2F), + new BiomeColor(172, "Unknown Biome", 2.0f, 0.0f, 0x92BD59, 0x77AB2F), + new BiomeColor(173, "Unknown Biome", 2.0f, 0.0f, 0x92BD59, 0x77AB2F), new BiomeColor(174, "Unknown Biome", 0.8f, 0.4f, 0x92BD59, 0x77AB2F), new BiomeColor(175, "Unknown Biome", 0.8f, 0.4f, 0x92BD59, 0x77AB2F), new BiomeColor(176, "Unknown Biome", 0.8f, 0.4f, 0x92BD59, 0x77AB2F),