Implement biomes to filter blocks and use in Clipboard pasting (#1743)

- Fixes #1741
This commit is contained in:
Jordan 2022-06-05 19:52:14 +01:00 committed by GitHub
parent 02eea35c3f
commit 8228b798e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 110 additions and 7 deletions

View File

@ -117,6 +117,16 @@ public abstract class LinearClipboard extends SimpleClipboard {
LinearClipboard.this.setBlock(index, block); 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 @Override
public BlockVector3 getPosition() { public BlockVector3 getPosition() {
return position; return position;

View File

@ -19,6 +19,12 @@ public abstract class AbstractFilterBlock extends FilterBlock {
@Override @Override
public abstract void setFullBlock(BaseBlock block); public abstract void setFullBlock(BaseBlock block);
@Override
public abstract BiomeType getBiome();
@Override
public abstract void setBiome(BiomeType type);
public abstract BlockVector3 getPosition(); public abstract BlockVector3 getPosition();
@Override @Override
@ -91,6 +97,10 @@ public abstract class AbstractFilterBlock extends FilterBlock {
@Override @Override
public boolean setBiome(int x, int y, int z, BiomeType biome) { 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); return getExtent().setBiome(x, y, z, biome);
} }

View File

@ -14,12 +14,18 @@ import javax.annotation.Nullable;
public abstract class AbstractSingleFilterBlock extends FilterBlock { public abstract class AbstractSingleFilterBlock extends FilterBlock {
private BaseBlock block; private BaseBlock block;
private BiomeType biome;
public AbstractSingleFilterBlock init(BaseBlock block) { public AbstractSingleFilterBlock init(BaseBlock block) {
this.block = block; this.block = block;
return this; return this;
} }
public AbstractSingleFilterBlock init(BiomeType type) {
this.biome = type;
return this;
}
@Override @Override
public Extent getExtent() { public Extent getExtent() {
return this; return this;
@ -55,6 +61,16 @@ public abstract class AbstractSingleFilterBlock extends FilterBlock {
this.block = block; this.block = block;
} }
@Override
public void setBiome(BiomeType type) {
this.biome = type;
}
@Override
public BiomeType getBiome() {
return biome;
}
@Override @Override
public CompoundTag getNbtData() { public CompoundTag getNbtData() {
return block.getNbtData(); return block.getNbtData();

View File

@ -11,6 +11,10 @@ import com.sk89q.worldedit.world.block.BlockTypesCache;
import javax.annotation.Nullable; import javax.annotation.Nullable;
/**
* @deprecated Unused internally
*/
@Deprecated(forRemoval = true, since = "TODO")
public class ArrayFilterBlock extends AbstractExtentFilterBlock { public class ArrayFilterBlock extends AbstractExtentFilterBlock {
private final char[] blocks; private final char[] blocks;
@ -106,4 +110,14 @@ public class ArrayFilterBlock extends AbstractExtentFilterBlock {
return getExtent().setBiome(x, y, z, biome); 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());
}
} }

View File

@ -184,6 +184,11 @@ public class CharFilterBlock extends ChunkFilterBlock {
set.setBiome(x, y, z, biome); set.setBiome(x, y, z, biome);
} }
@Override
public BiomeType getBiome() {
return get.getBiomeType(x, y, z);
}
@Override @Override
public final int getX() { public final int getX() {
return xx + x; return xx + x;

View File

@ -2,6 +2,7 @@ package com.fastasyncworldedit.core.extent.filter.block;
import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BaseBlock;
public class ExtentFilterBlock extends AbstractFilterBlock { public class ExtentFilterBlock extends AbstractFilterBlock {
@ -29,6 +30,16 @@ public class ExtentFilterBlock extends AbstractFilterBlock {
pos.setFullBlock(extent, block); pos.setFullBlock(extent, block);
} }
@Override
public BiomeType getBiome() {
return pos.getBiome(extent);
}
@Override
public void setBiome(final BiomeType type) {
pos.setBiome(extent, type);
}
@Override @Override
public BlockVector3 getPosition() { public BlockVector3 getPosition() {
return pos; return pos;

View File

@ -19,10 +19,6 @@ public abstract class FilterBlock extends BlockVector3 implements Extent, TileEn
public abstract Extent getExtent(); public abstract Extent getExtent();
public void setBiome(BiomeType biome) {
setBiome(getX(), getY(), getZ(), biome);
}
public abstract int getOrdinal(); public abstract int getOrdinal();
public abstract void setOrdinal(int ordinal); 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 setFullBlock(BaseBlock block);
public abstract void setBiome(BiomeType biome);
public abstract BiomeType getBiome();
@Override @Override
public abstract CompoundTag getNbtData(); public abstract CompoundTag getNbtData();
@ -165,6 +165,17 @@ public abstract class FilterBlock extends BlockVector3 implements Extent, TileEn
return getFullBlock(); return getFullBlock();
} }
@Override
public boolean setBiome(Extent orDefault, BiomeType type) {
setBiome(type);
return true;
}
@Override
public BiomeType getBiome(Extent orDefault) {
return getBiome();
}
@Override @Override
public CompoundTag getNbtData(Extent orDefault) { public CompoundTag getNbtData(Extent orDefault) {
return getNbtData(); return getNbtData();

View File

@ -5,6 +5,7 @@ import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.math.BlockVector2; import com.sk89q.worldedit.math.BlockVector2;
import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.Vector3; 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.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockState;
@ -348,6 +349,16 @@ public class DelegateBlockVector3 extends BlockVector3 {
return parent.getFullBlock(orDefault); 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 @Override
public CompoundTag getNbtData(Extent orDefault) { public CompoundTag getNbtData(Extent orDefault) {
return parent.getNbtData(orDefault); return parent.getNbtData(orDefault);

View File

@ -227,8 +227,13 @@ public class BlockArrayClipboard implements Clipboard {
@Override @Override
public BiomeType getBiome(BlockVector3 position) { public BiomeType getBiome(BlockVector3 position) {
BlockVector3 v = position.subtract(offset); if (!region.contains(position)) {
return getParent().getBiomeType(v.getX(), v.getY(), v.getZ()); 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 @Override
@ -326,6 +331,7 @@ public class BlockArrayClipboard implements Clipboard {
@Override @Override
public BiomeType getBiomeType(int x, int y, int z) { public BiomeType getBiomeType(int x, int y, int z) {
x -= offset.getX(); x -= offset.getX();
y -= offset.getY();
z -= offset.getZ(); z -= offset.getZ();
return getParent().getBiomeType(x, y, z); return getParent().getBiomeType(x, y, z);
} }

View File

@ -386,7 +386,7 @@ public interface Clipboard extends Extent, Iterable<BlockVector3>, Closeable, Fl
int yy = pos.getY() + rely; int yy = pos.getY() + rely;
int zz = pos.getZ() + relz; int zz = pos.getZ() + relz;
if (pasteBiomes) { 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()) { if (!pasteAir && block.getBlockType().getMaterial().isAir()) {
continue; continue;

View File

@ -23,6 +23,7 @@ import com.fastasyncworldedit.core.math.MutableBlockVector3;
import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.math.transform.AffineTransform; 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.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockState;
@ -805,6 +806,14 @@ public abstract class BlockVector3 {
return orDefault.getFullBlock(this); 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) { public CompoundTag getNbtData(Extent orDefault) {
return orDefault.getFullBlock(getX(), getY(), getZ()).getNbtData(); return orDefault.getFullBlock(getX(), getY(), getZ()).getNbtData();
} }