From 8228b798e506b3cb71a73f9764231ec5bc4459b8 Mon Sep 17 00:00:00 2001 From: Jordan Date: Sun, 5 Jun 2022 19:52:14 +0100 Subject: [PATCH] Implement biomes to filter blocks and use in Clipboard pasting (#1743) - Fixes #1741 --- .../extent/clipboard/LinearClipboard.java | 10 ++++++++++ .../filter/block/AbstractFilterBlock.java | 10 ++++++++++ .../block/AbstractSingleFilterBlock.java | 16 ++++++++++++++++ .../extent/filter/block/ArrayFilterBlock.java | 14 ++++++++++++++ .../extent/filter/block/CharFilterBlock.java | 5 +++++ .../filter/block/ExtentFilterBlock.java | 11 +++++++++++ .../core/extent/filter/block/FilterBlock.java | 19 +++++++++++++++---- .../core/math/DelegateBlockVector3.java | 11 +++++++++++ .../extent/clipboard/BlockArrayClipboard.java | 10 ++++++++-- .../worldedit/extent/clipboard/Clipboard.java | 2 +- .../sk89q/worldedit/math/BlockVector3.java | 9 +++++++++ 11 files changed, 110 insertions(+), 7 deletions(-) diff --git a/worldedit-core/src/main/java/com/fastasyncworldedit/core/extent/clipboard/LinearClipboard.java b/worldedit-core/src/main/java/com/fastasyncworldedit/core/extent/clipboard/LinearClipboard.java index 491ef5687..16d8acbf1 100644 --- a/worldedit-core/src/main/java/com/fastasyncworldedit/core/extent/clipboard/LinearClipboard.java +++ b/worldedit-core/src/main/java/com/fastasyncworldedit/core/extent/clipboard/LinearClipboard.java @@ -117,6 +117,16 @@ public abstract class LinearClipboard extends SimpleClipboard { LinearClipboard.this.setBlock(index, block); } + @Override + public BiomeType getBiome() { + return LinearClipboard.this.getBiome(position); + } + + @Override + public void setBiome(final BiomeType type) { + LinearClipboard.this.setBiome(position, type); + } + @Override public BlockVector3 getPosition() { return position; diff --git a/worldedit-core/src/main/java/com/fastasyncworldedit/core/extent/filter/block/AbstractFilterBlock.java b/worldedit-core/src/main/java/com/fastasyncworldedit/core/extent/filter/block/AbstractFilterBlock.java index 2d916e37f..b91ef08b0 100644 --- a/worldedit-core/src/main/java/com/fastasyncworldedit/core/extent/filter/block/AbstractFilterBlock.java +++ b/worldedit-core/src/main/java/com/fastasyncworldedit/core/extent/filter/block/AbstractFilterBlock.java @@ -19,6 +19,12 @@ public abstract class AbstractFilterBlock extends FilterBlock { @Override public abstract void setFullBlock(BaseBlock block); + @Override + public abstract BiomeType getBiome(); + + @Override + public abstract void setBiome(BiomeType type); + public abstract BlockVector3 getPosition(); @Override @@ -91,6 +97,10 @@ public abstract class AbstractFilterBlock extends FilterBlock { @Override public boolean setBiome(int x, int y, int z, BiomeType biome) { + if (x == this.getX() && y == this.getY() && z == this.getZ()) { + setBiome(biome); + return true; + } return getExtent().setBiome(x, y, z, biome); } diff --git a/worldedit-core/src/main/java/com/fastasyncworldedit/core/extent/filter/block/AbstractSingleFilterBlock.java b/worldedit-core/src/main/java/com/fastasyncworldedit/core/extent/filter/block/AbstractSingleFilterBlock.java index 07fd9ee1a..95e50dc76 100644 --- a/worldedit-core/src/main/java/com/fastasyncworldedit/core/extent/filter/block/AbstractSingleFilterBlock.java +++ b/worldedit-core/src/main/java/com/fastasyncworldedit/core/extent/filter/block/AbstractSingleFilterBlock.java @@ -14,12 +14,18 @@ import javax.annotation.Nullable; public abstract class AbstractSingleFilterBlock extends FilterBlock { private BaseBlock block; + private BiomeType biome; public AbstractSingleFilterBlock init(BaseBlock block) { this.block = block; return this; } + public AbstractSingleFilterBlock init(BiomeType type) { + this.biome = type; + return this; + } + @Override public Extent getExtent() { return this; @@ -55,6 +61,16 @@ public abstract class AbstractSingleFilterBlock extends FilterBlock { this.block = block; } + @Override + public void setBiome(BiomeType type) { + this.biome = type; + } + + @Override + public BiomeType getBiome() { + return biome; + } + @Override public CompoundTag getNbtData() { return block.getNbtData(); diff --git a/worldedit-core/src/main/java/com/fastasyncworldedit/core/extent/filter/block/ArrayFilterBlock.java b/worldedit-core/src/main/java/com/fastasyncworldedit/core/extent/filter/block/ArrayFilterBlock.java index 572c085ea..ffc7dc499 100644 --- a/worldedit-core/src/main/java/com/fastasyncworldedit/core/extent/filter/block/ArrayFilterBlock.java +++ b/worldedit-core/src/main/java/com/fastasyncworldedit/core/extent/filter/block/ArrayFilterBlock.java @@ -11,6 +11,10 @@ import com.sk89q.worldedit.world.block.BlockTypesCache; import javax.annotation.Nullable; +/** + * @deprecated Unused internally + */ +@Deprecated(forRemoval = true, since = "TODO") public class ArrayFilterBlock extends AbstractExtentFilterBlock { private final char[] blocks; @@ -106,4 +110,14 @@ public class ArrayFilterBlock extends AbstractExtentFilterBlock { return getExtent().setBiome(x, y, z, biome); } + @Override + public void setBiome(final BiomeType biome) { + getExtent().setBiome(getX(), getY(), getZ(), biome); + } + + @Override + public BiomeType getBiome() { + return getExtent().getBiomeType(getX(), getY(), getZ()); + } + } diff --git a/worldedit-core/src/main/java/com/fastasyncworldedit/core/extent/filter/block/CharFilterBlock.java b/worldedit-core/src/main/java/com/fastasyncworldedit/core/extent/filter/block/CharFilterBlock.java index 1a2e4705e..9a339826a 100644 --- a/worldedit-core/src/main/java/com/fastasyncworldedit/core/extent/filter/block/CharFilterBlock.java +++ b/worldedit-core/src/main/java/com/fastasyncworldedit/core/extent/filter/block/CharFilterBlock.java @@ -184,6 +184,11 @@ public class CharFilterBlock extends ChunkFilterBlock { set.setBiome(x, y, z, biome); } + @Override + public BiomeType getBiome() { + return get.getBiomeType(x, y, z); + } + @Override public final int getX() { return xx + x; diff --git a/worldedit-core/src/main/java/com/fastasyncworldedit/core/extent/filter/block/ExtentFilterBlock.java b/worldedit-core/src/main/java/com/fastasyncworldedit/core/extent/filter/block/ExtentFilterBlock.java index d2b63970c..8aff6aa67 100644 --- a/worldedit-core/src/main/java/com/fastasyncworldedit/core/extent/filter/block/ExtentFilterBlock.java +++ b/worldedit-core/src/main/java/com/fastasyncworldedit/core/extent/filter/block/ExtentFilterBlock.java @@ -2,6 +2,7 @@ package com.fastasyncworldedit.core.extent.filter.block; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.block.BaseBlock; public class ExtentFilterBlock extends AbstractFilterBlock { @@ -29,6 +30,16 @@ public class ExtentFilterBlock extends AbstractFilterBlock { pos.setFullBlock(extent, block); } + @Override + public BiomeType getBiome() { + return pos.getBiome(extent); + } + + @Override + public void setBiome(final BiomeType type) { + pos.setBiome(extent, type); + } + @Override public BlockVector3 getPosition() { return pos; diff --git a/worldedit-core/src/main/java/com/fastasyncworldedit/core/extent/filter/block/FilterBlock.java b/worldedit-core/src/main/java/com/fastasyncworldedit/core/extent/filter/block/FilterBlock.java index 4aab008f1..c27d3770a 100644 --- a/worldedit-core/src/main/java/com/fastasyncworldedit/core/extent/filter/block/FilterBlock.java +++ b/worldedit-core/src/main/java/com/fastasyncworldedit/core/extent/filter/block/FilterBlock.java @@ -19,10 +19,6 @@ public abstract class FilterBlock extends BlockVector3 implements Extent, TileEn public abstract Extent getExtent(); - public void setBiome(BiomeType biome) { - setBiome(getX(), getY(), getZ(), biome); - } - public abstract int getOrdinal(); public abstract void setOrdinal(int ordinal); @@ -35,6 +31,10 @@ public abstract class FilterBlock extends BlockVector3 implements Extent, TileEn public abstract void setFullBlock(BaseBlock block); + public abstract void setBiome(BiomeType biome); + + public abstract BiomeType getBiome(); + @Override public abstract CompoundTag getNbtData(); @@ -165,6 +165,17 @@ public abstract class FilterBlock extends BlockVector3 implements Extent, TileEn return getFullBlock(); } + @Override + public boolean setBiome(Extent orDefault, BiomeType type) { + setBiome(type); + return true; + } + + @Override + public BiomeType getBiome(Extent orDefault) { + return getBiome(); + } + @Override public CompoundTag getNbtData(Extent orDefault) { return getNbtData(); diff --git a/worldedit-core/src/main/java/com/fastasyncworldedit/core/math/DelegateBlockVector3.java b/worldedit-core/src/main/java/com/fastasyncworldedit/core/math/DelegateBlockVector3.java index 84ac1d542..b75e157b2 100644 --- a/worldedit-core/src/main/java/com/fastasyncworldedit/core/math/DelegateBlockVector3.java +++ b/worldedit-core/src/main/java/com/fastasyncworldedit/core/math/DelegateBlockVector3.java @@ -5,6 +5,7 @@ import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.math.BlockVector2; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.Vector3; +import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; @@ -348,6 +349,16 @@ public class DelegateBlockVector3 extends BlockVector3 { return parent.getFullBlock(orDefault); } + @Override + public boolean setBiome(Extent orDefault, BiomeType type) { + return parent.setBiome(orDefault, type); + } + + @Override + public BiomeType getBiome(Extent orDefault) { + return parent.getBiome(orDefault); + } + @Override public CompoundTag getNbtData(Extent orDefault) { return parent.getNbtData(orDefault); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/BlockArrayClipboard.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/BlockArrayClipboard.java index d0d71a3cb..3625fed4a 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/BlockArrayClipboard.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/BlockArrayClipboard.java @@ -227,8 +227,13 @@ public class BlockArrayClipboard implements Clipboard { @Override public BiomeType getBiome(BlockVector3 position) { - BlockVector3 v = position.subtract(offset); - return getParent().getBiomeType(v.getX(), v.getY(), v.getZ()); + if (!region.contains(position)) { + return null; + } + int x = position.getBlockX() - offset.getX(); + int y = position.getBlockY() - offset.getY(); + int z = position.getBlockZ() - offset.getZ(); + return getParent().getBiomeType(x, y, z); } @Override @@ -326,6 +331,7 @@ public class BlockArrayClipboard implements Clipboard { @Override public BiomeType getBiomeType(int x, int y, int z) { x -= offset.getX(); + y -= offset.getY(); z -= offset.getZ(); return getParent().getBiomeType(x, y, z); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/Clipboard.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/Clipboard.java index b2472d9c2..bf88ef9d8 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/Clipboard.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/Clipboard.java @@ -386,7 +386,7 @@ public interface Clipboard extends Extent, Iterable, Closeable, Fl int yy = pos.getY() + rely; int zz = pos.getZ() + relz; if (pasteBiomes) { - extent.setBiome(xx, yy, zz, Clipboard.this.getBiome(pos)); + extent.setBiome(xx, yy, zz, pos.getBiome(this)); } if (!pasteAir && block.getBlockType().getMaterial().isAir()) { continue; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/math/BlockVector3.java b/worldedit-core/src/main/java/com/sk89q/worldedit/math/BlockVector3.java index 03d4c4930..5f1c14842 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/math/BlockVector3.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/math/BlockVector3.java @@ -23,6 +23,7 @@ import com.fastasyncworldedit.core.math.MutableBlockVector3; import com.sk89q.jnbt.CompoundTag; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.math.transform.AffineTransform; +import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; @@ -805,6 +806,14 @@ public abstract class BlockVector3 { return orDefault.getFullBlock(this); } + public boolean setBiome(Extent orDefault, BiomeType type) { + return orDefault.setBiome(this, type); + } + + public BiomeType getBiome(Extent orDefault) { + return orDefault.getBiome(this); + } + public CompoundTag getNbtData(Extent orDefault) { return orDefault.getFullBlock(getX(), getY(), getZ()).getNbtData(); }