Some more upstream merge

This commit is contained in:
Jesse Boyd 2019-04-04 21:28:41 +11:00
parent 8897109dc4
commit 1beea3cd22
No known key found for this signature in database
GPG Key ID: 59F1DE6293AF6E1F
40 changed files with 222 additions and 116 deletions

View File

@ -5,6 +5,7 @@ import com.boydti.fawe.object.FaweChunk;
import com.boydti.fawe.object.FaweQueue;
import com.boydti.fawe.util.MathMan;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BlockTypes;
import java.util.*;
@ -16,7 +17,7 @@ public abstract class IntFaweChunk<T, V extends FaweQueue> extends FaweChunk<T>
public final short[] air;
public final byte[] heightMap;
public byte[] biomes;
public BiomeType[] biomes;
public HashMap<Short, CompoundTag> tiles;
public HashSet<CompoundTag> entities;
public HashSet<UUID> entityRemoves;
@ -129,7 +130,7 @@ public abstract class IntFaweChunk<T, V extends FaweQueue> extends FaweChunk<T>
}
@Override
public byte[] getBiomeArray() {
public BiomeType[] getBiomeArray() {
return this.biomes;
}
@ -216,11 +217,10 @@ public abstract class IntFaweChunk<T, V extends FaweQueue> extends FaweChunk<T>
}
@Override
public void setBiome(final int x, final int z, byte biome) {
public void setBiome(final int x, final int z, BiomeType biome) {
if (this.biomes == null) {
this.biomes = new byte[256];
this.biomes = new BiomeType[256];
}
if (biome == 0) biome = -1;
biomes[((z & 15) << 4) + (x & 15)] = biome;
}

View File

@ -385,7 +385,7 @@ public abstract class MappedFaweQueue<WORLD, CHUNK, CHUNKSECTIONS, SECTION> impl
return getCombinedId4Data(lastSection, x, y, z);
}
public abstract int getBiome(CHUNK chunk, int x, int z);
public abstract BiomeType getBiome(CHUNK chunk, int x, int z);
public abstract CompoundTag getTileEntity(CHUNK chunk, int x, int y, int z);
@ -765,12 +765,12 @@ public abstract class MappedFaweQueue<WORLD, CHUNK, CHUNKSECTIONS, SECTION> impl
lastChunkSections = getSections(lastChunk);
} else {
lastChunkSections = null;
return 0;
return null;
}
} else if (lastChunk == null) {
return 0;
return null;
}
return getBiome(lastChunk, x, z) & 0xFF;
return getBiome(lastChunk, x, z);
}
@Override

View File

@ -37,8 +37,8 @@ public class NullFaweChunk extends FaweChunk<Void> {
}
@Override
public byte[] getBiomeArray() {
return new byte[256];
public BiomeType[] getBiomeArray() {
return new BiomeType[256];
}
@Override
@ -101,11 +101,6 @@ public class NullFaweChunk extends FaweChunk<Void> {
}
@Override
public void setBiome(int x, int z, byte biome) {
}
@Override
public FaweChunk<Void> copy(boolean shallow) {
return this;

View File

@ -22,6 +22,7 @@ import com.sk89q.worldedit.math.Vector3;
import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.registry.state.PropertyKey;
import com.sk89q.worldedit.util.Direction;
import com.sk89q.worldedit.world.biome.BiomeTypes;
import com.sk89q.worldedit.world.block.*;
import com.sk89q.worldedit.world.entity.EntityType;
import com.sk89q.worldedit.world.entity.EntityTypes;
@ -118,7 +119,7 @@ public class SchematicStreamer extends NBTStreamer {
ByteReader biomeReader = new ByteReader() {
@Override
public void run(int index, int value) {
fc.setBiome(index, value);
fc.setBiome(index, BiomeTypes.get(value));
}
};
NBTStreamReader<Integer, Integer> initializer23 = new NBTStreamReader<Integer, Integer>() {

View File

@ -923,7 +923,7 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr
public BiomeType getBiomeType(int x, int z) throws FaweException.FaweChunkLoadException {
int index = z * getWidth() + x;
if (index < 0 || index >= getArea()) index = Math.floorMod(index, getArea());
return biomes.getByte(index) & 0xFF;
return BiomeTypes.get(biomes.getByte(index));
}
@Override
@ -1011,7 +1011,7 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr
@Override
public BiomeType getBiome(BlockVector2 position) {
return BiomeTypes.get(getBiomeType(position.getBlockX(), position.getBlockZ()));
return getBiomeType(position.getBlockX(), position.getBlockZ());
}
@Override

View File

@ -11,6 +11,8 @@ import com.boydti.fawe.util.MainUtil;
import com.boydti.fawe.util.MathMan;
import com.boydti.fawe.util.ReflectionUtils;
import com.sk89q.jnbt.*;
import com.sk89q.worldedit.world.biome.BiomeType;
import java.io.DataOutput;
import java.io.DataOutputStream;
import java.io.IOException;
@ -590,9 +592,9 @@ public class MCAChunk extends FaweChunk<Void> {
}
@Override
public void setBiome(int x, int z, byte biome) {
public void setBiome(int x, int z, BiomeType biome) {
setModified();
biomes[x + (z << 4)] = biome;
biomes[x + (z << 4)] = (byte) biome.getInternalId();
}
@Override
@ -644,8 +646,8 @@ public class MCAChunk extends FaweChunk<Void> {
}
@Override
public byte[] getBiomeArray() {
return this.biomes;
public BiomeType[] getBiomeArray() {
return null;
}
@Override
@ -771,8 +773,8 @@ public class MCAChunk extends FaweChunk<Void> {
}
@Override
public void setBiome(byte biome) {
Arrays.fill(biomes, biome);
public void setBiome(BiomeType biome) {
Arrays.fill(biomes, (byte) biome.getInternalId());
}
@Override

View File

@ -86,13 +86,13 @@ public class MCAQueue extends NMSMappedFaweQueue<FaweQueue, FaweChunk, FaweChunk
}
@Override
public int getBiome(FaweChunk faweChunk, int x, int z) {
public BiomeType getBiome(FaweChunk faweChunk, int x, int z) {
if (faweChunk instanceof MCAChunk) {
return ((MCAChunk) faweChunk).getBiomeArray()[((z & 0xF) << 4 | x & 0xF)];
} else if (parent != null) {
return parent.getBiomeType(x, z);
} else {
return 0;
return null;
}
}

View File

@ -289,13 +289,9 @@ public abstract class FaweChunk<T> implements Callable<FaweChunk> {
*/
public abstract CompoundTag getTile(int x, int y, int z);
public void setBiome(final int x, final int z, final BiomeType biome) {
setBiome(x, z, biome);
}
public abstract void setBiome(final int x, final int z, final BiomeType biome);
public abstract void setBiome(final int x, final int z, final byte biome);
public void setBiome(final byte biome) {
public void setBiome(final BiomeType biome) {
for (int z = 0; z < 16; z++) {
for (int x = 0; x < 16; x++) {
setBiome(x, z, biome);

View File

@ -5,6 +5,7 @@ import com.boydti.fawe.object.collection.SparseBitSet;
import com.boydti.fawe.object.visitor.FaweChunkVisitor;
import com.boydti.fawe.util.MathMan;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockTypes;
@ -87,8 +88,8 @@ public class VisualChunk extends FaweChunk<FaweChunk> {
}
@Override
public byte[] getBiomeArray() {
return new byte[256];
public BiomeType[] getBiomeArray() {
return new BiomeType[256];
}
@Override
@ -154,7 +155,7 @@ public class VisualChunk extends FaweChunk<FaweChunk> {
}
@Override
public void setBiome(int x, int z, byte biome) {
public void setBiome(int x, int z, BiomeType biome) {
// Unsupported
}

View File

@ -42,7 +42,7 @@ public class AbstractDelegateFaweClipboard extends FaweClipboard {
}
@Override
public boolean setBiome(int x, int z, int biome) {
public boolean setBiome(int x, int z, BiomeType biome) {
return parent.setBiome(x, z, biome);
}
@ -62,7 +62,7 @@ public class AbstractDelegateFaweClipboard extends FaweClipboard {
}
@Override
public void setBiome(int index, int biome) {
public void setBiome(int index, BiomeType biome) {
parent.setBiome(index, biome);
}

View File

@ -59,7 +59,7 @@ public class CPUOptimizedClipboard extends FaweClipboard {
}
@Override
public boolean setBiome(int x, int z, int biome) {
public boolean setBiome(int x, int z, BiomeType biome) {
setBiome(getIndex(x, 0, z), biome);
return true;
}
@ -78,7 +78,7 @@ public class CPUOptimizedClipboard extends FaweClipboard {
int index = 0;
for (int z = 0; z < length; z++) {
for (int x = 0; x < width; x++, index++) {
task.run(index, biomes[index] & 0xFF);
task.run(index, biomes[index].getInternalId());
}
}
}

View File

@ -11,6 +11,7 @@ import com.sk89q.jnbt.CompoundTag;
import com.sk89q.jnbt.IntTag;
import com.sk89q.jnbt.Tag;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.world.biome.BiomeTypes;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.entity.BaseEntity;
@ -127,15 +128,15 @@ public class DiskOptimizedClipboard extends FaweClipboard implements Closeable {
}
@Override
public boolean setBiome(int x, int z, int biome) {
public boolean setBiome(int x, int z, BiomeType biome) {
setBiome(getIndex(x, 0, z), biome);
return true;
}
@Override
public void setBiome(int index, int biome) {
public void setBiome(int index, BiomeType biome) {
if (initBiome()) {
mbb.put(HEADER_SIZE + (volume << 2) + index, (byte) biome);
mbb.put(HEADER_SIZE + (volume << 2) + index, (byte) biome.getInternalId());
}
}
@ -145,7 +146,7 @@ public class DiskOptimizedClipboard extends FaweClipboard implements Closeable {
return null;
}
int biomeId = mbb.get(HEADER_SIZE + (volume << 2) + index) & 0xFF;
return FaweCache.CACHE_BIOME[biomeId];
return BiomeTypes.get(biomeId);
}
@Override

View File

@ -33,7 +33,7 @@ public abstract class FaweClipboard {
public abstract boolean hasBiomes();
public abstract boolean setBiome(int x, int z, int biome);
public abstract boolean setBiome(int x, int z, BiomeType biome);
public abstract BiomeType getBiome(int x, int z);
@ -41,7 +41,7 @@ public abstract class FaweClipboard {
public abstract BaseBlock getBlock(int index);
public abstract void setBiome(int index, int biome);
public abstract void setBiome(int index, BiomeType biome);
public abstract boolean setTile(int x, int y, int z, CompoundTag tag);

View File

@ -10,6 +10,7 @@ import com.sk89q.jnbt.CompoundTag;
import com.sk89q.jnbt.IntTag;
import com.sk89q.jnbt.Tag;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.world.biome.BiomeTypes;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.entity.BaseEntity;
@ -92,17 +93,17 @@ public class MemoryOptimizedClipboard extends FaweClipboard {
}
@Override
public boolean setBiome(int x, int z, int biome) {
public boolean setBiome(int x, int z, BiomeType biome) {
setBiome(getIndex(x, 0, z), biome);
return true;
}
@Override
public void setBiome(int index, int biome) {
public void setBiome(int index, BiomeType biome) {
if (biomes == null) {
biomes = new byte[area];
}
biomes[index] = (byte) biome;
biomes[index] = (byte) biome.getInternalId();
}
@Override
@ -121,7 +122,7 @@ public class MemoryOptimizedClipboard extends FaweClipboard {
if (!hasBiomes()) {
return null;
}
return FaweCache.CACHE_BIOME[biomes[index] & 0xFF];
return BiomeTypes.get(biomes[index]);
}
@Override

View File

@ -56,12 +56,12 @@ public abstract class ReadOnlyClipboard extends FaweClipboard {
}
@Override
public boolean setBiome(int x, int z, int biome) {
public boolean setBiome(int x, int z, BiomeType biome) {
throw new UnsupportedOperationException("Clipboard is immutable");
}
@Override
public void setBiome(int index, int biome) {
public void setBiome(int index, BiomeType biome) {
throw new UnsupportedOperationException("Clipboard is immutable");
}
@ -71,7 +71,7 @@ public abstract class ReadOnlyClipboard extends FaweClipboard {
int index = 0;
for (int z = 0; z <= dim.getBlockZ(); z++) {
for (int x = 0; x <= dim.getBlockX(); x++, index++) {
task.run(index, getBiome(x, z));
task.run(index, getBiome(x, z).getInternalId());
}
}
}

View File

@ -105,7 +105,7 @@ public class FastWorldEditExtent extends AbstractDelegateExtent implements HasFa
@Override
public BiomeType getBiome(final BlockVector2 position) {
return BiomeTypes.get(queue.getBiomeType(position.getBlockX(), position.getBlockZ()));
return queue.getBiomeType(position.getBlockX(), position.getBlockZ());
}
@Override

View File

@ -91,7 +91,7 @@ public abstract class LazyFaweChunk<T extends FaweChunk> extends FaweChunk {
}
@Override
public byte[] getBiomeArray() {
public BiomeType[] getBiomeArray() {
return internalGetOrCacheChunk().getBiomeArray();
}
@ -176,12 +176,7 @@ public abstract class LazyFaweChunk<T extends FaweChunk> extends FaweChunk {
}
@Override
public void setBiome(int x, int z, byte biome) {
internalGetOrCacheChunk().setBiome(x, z, biome);
}
@Override
public void setBiome(byte biome) {
public void setBiome(BiomeType biome) {
internalGetOrCacheChunk().setBiome(biome);
}

View File

@ -184,7 +184,7 @@ public class NullFaweQueue implements FaweQueue {
@Override
public BiomeType getBiomeType(int x, int z) throws FaweException.FaweChunkLoadException {
return 0;
return null;
}
@Override

View File

@ -33,6 +33,7 @@ import com.sk89q.worldedit.session.ClipboardHolder;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.util.TargetBlock;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.biome.BiomeTypes;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockTypes;
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
@ -580,7 +581,7 @@ public class SchemVis extends ImmutableVirtualWorld {
@Override
public BiomeType getBiomeType(int x, int z) throws FaweException.FaweChunkLoadException {
// TODO later (currently not used)
return 0;
return BiomeTypes.FOREST;
}
@Override

View File

@ -24,6 +24,7 @@ import com.sk89q.worldedit.extension.platform.Capability;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.biome.BiomeTypes;
import com.sk89q.worldedit.world.biome.Biomes;
import com.sk89q.worldedit.world.registry.BiomeRegistry;
import java.util.HashSet;
@ -55,7 +56,7 @@ public class PlotSetBiome extends Command {
checkTrue(args.length == 1, Captions.COMMAND_SYNTAX, getUsage());
final HashSet<RegionWrapper> regions = plot.getRegions();
BiomeRegistry biomeRegistry = WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.GAME_HOOKS).getRegistries().getBiomeRegistry();
List<BiomeType> knownBiomes = biomeRegistry.getBiomes();
List<BiomeType> knownBiomes = BiomeTypes.values();
final BiomeType biome = Biomes.findBiomeByName(knownBiomes, args[0], biomeRegistry);
if (biome == null) {
String biomes = StringMan.join(WorldUtil.IMP.getBiomeList(), Captions.BLOCK_LIST_SEPARATER.s());

View File

@ -457,8 +457,8 @@ public class CuboidClipboard {
*/
public List<Countable<Integer>> getBlockDistribution() {
List<Countable<Integer>> distribution = new ArrayList<>();
List<Countable<BlockStateHolder>> distr = clipboard.getBlockDistributionWithData(clipboard.getRegion());
for (Countable<BlockStateHolder> item : distr) {
List<Countable<BlockState>> distr = clipboard.getBlockDistributionWithData(clipboard.getRegion());
for (Countable<BlockState> item : distr) {
BlockStateHolder state = item.getID();
int[] legacyId = LegacyMapper.getInstance().getLegacyFromBlock(state.toImmutableState());
if (legacyId[0] != 0) distribution.add(new Countable<>(legacyId[0], item.getAmount()));
@ -473,8 +473,8 @@ public class CuboidClipboard {
*/
public List<Countable<BaseBlock>> getBlockDistributionWithData() {
List<Countable<BaseBlock>> distribution = new ArrayList<>();
List<Countable<BlockStateHolder>> distr = clipboard.getBlockDistributionWithData(clipboard.getRegion());
for (Countable<BlockStateHolder> item : distr) {
List<Countable<BlockState>> distr = clipboard.getBlockDistributionWithData(clipboard.getRegion());
for (Countable<BlockState> item : distr) {
distribution.add(new Countable<>(item.getID().toBaseBlock(), item.getAmount()));
}
return distribution;

View File

@ -38,10 +38,12 @@ import com.sk89q.minecraft.util.commands.CommandContext;
import com.sk89q.minecraft.util.commands.CommandPermissions;
import com.sk89q.minecraft.util.commands.Step;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.EmptyClipboardException;
import com.sk89q.worldedit.LocalConfiguration;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.command.tool.brush.Brush;
import com.sk89q.worldedit.command.tool.brush.ButcherBrush;
import com.sk89q.worldedit.command.tool.brush.ClipboardBrush;
import com.sk89q.worldedit.command.tool.brush.CylinderBrush;

View File

@ -21,6 +21,7 @@ package com.sk89q.worldedit.command;
import com.boydti.fawe.config.BBC;
import com.sk89q.minecraft.util.commands.Command;
import com.sk89q.minecraft.util.commands.CommandContext;
import com.sk89q.minecraft.util.commands.CommandPermissions;
import com.sk89q.minecraft.util.commands.Logging;
import com.sk89q.worldedit.EditSession;

View File

@ -26,6 +26,7 @@ import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.extent.transform.BlockTransformExtent;
import com.sk89q.worldedit.function.operation.ForwardExtentCopy;
import com.sk89q.worldedit.function.operation.Operation;
import com.sk89q.worldedit.math.MutableVector3;
import com.sk89q.worldedit.math.Vector3;
import com.sk89q.worldedit.math.transform.AffineTransform;
import com.sk89q.worldedit.math.transform.CombinedTransform;
@ -92,12 +93,12 @@ public class FlattenedClipboardTransform {
corners[i] = transformAround.apply(corners[i]);
}
MutableVector3 newMinimum = new MutableVector3(corners[0]);
MutableVector3 newMaximum = new MutableVector3(corners[0]);
Vector3 newMinimum = corners[0];
Vector3 newMaximum = corners[0];
for (int i = 1; i < corners.length; i++) {
Vector3 cbv = corners[i];
newMinimum = newMinimum.setComponents(newMinimum.getMinimum(cbv));
newMaximum = newMaximum.setComponents(newMaximum.getMaximum(cbv));
newMinimum = newMinimum.getMinimum(cbv);
newMaximum = newMaximum.getMaximum(cbv);
}
// After transformation, the points may not really sit on a block,

View File

@ -27,6 +27,7 @@ import com.sk89q.minecraft.util.commands.CommandContext;
import com.sk89q.minecraft.util.commands.CommandPermissions;
import com.sk89q.minecraft.util.commands.Logging;
import com.sk89q.worldedit.LocalConfiguration;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.entity.Player;

View File

@ -24,6 +24,7 @@ import com.boydti.fawe.object.brush.InspectBrush;
import com.sk89q.minecraft.util.commands.Command;
import com.sk89q.minecraft.util.commands.CommandContext;
import com.sk89q.minecraft.util.commands.CommandPermissions;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.LocalConfiguration;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.WorldEdit;

View File

@ -20,6 +20,7 @@
package com.sk89q.worldedit.command.tool;
import com.boydti.fawe.object.collection.BlockVectorSet;
import com.boydti.fawe.object.collection.LocalBlockVectorSet;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.LocalConfiguration;
import com.sk89q.worldedit.LocalSession;
@ -27,10 +28,6 @@ import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extension.platform.Platform;
import com.sk89q.worldedit.function.mask.BlockMask;
import com.sk89q.worldedit.function.operation.Operations;
import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.function.visitor.RecursiveVisitor;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.util.Direction;
import com.sk89q.worldedit.util.Location;
@ -41,6 +38,7 @@ import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.block.BlockTypes;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Set;
@ -74,8 +72,7 @@ public class FloatingTreeRemover implements BlockTool {
Player player, LocalSession session, Location clicked) {
final World world = (World) clicked.getExtent();
BlockVector3 pos = clicked.toBlockPoint();
final BlockState state = world.getBlock(pos);
final BlockState state = world.getBlock(clicked.toVector().toBlockPoint());
if (!isTreeBlock(state.getBlockType())) {
player.printError("That's not a tree.");
@ -84,10 +81,20 @@ public class FloatingTreeRemover implements BlockTool {
try (EditSession editSession = session.createEditSession(player)) {
try {
Pattern replace = BlockTypes.AIR;
RecursiveVisitor visitor = new RecursiveVisitor(new BlockMask(editSession, logs, leaves), replace, 64, editSession);
visitor.visit(pos);
Operations.completeBlindly(visitor);
final Set<BlockVector3> blockSet = bfs(world, clicked.toVector().toBlockPoint());
if (blockSet == null) {
player.printError("That's not a floating tree.");
return true;
}
for (BlockVector3 blockVector : blockSet) {
final BlockState otherState = editSession.getBlock(blockVector);
if (isTreeBlock(otherState.getBlockType())) {
editSession.setBlock(blockVector, BlockTypes.AIR.getDefaultState());
}
}
} catch (MaxChangedBlocksException e) {
player.printError("Max blocks change limit reached.");
} finally {
session.remember(editSession);
}
@ -97,10 +104,60 @@ public class FloatingTreeRemover implements BlockTool {
}
private BlockVector3[] recurseDirections = {
Direction.NORTH.toBlockVector(),
Direction.EAST.toBlockVector(),
Direction.SOUTH.toBlockVector(),
Direction.WEST.toBlockVector(),
Direction.UP.toBlockVector(),
Direction.DOWN.toBlockVector(),
};
/**
* Helper method.
*
* @param world the world that contains the tree
* @param origin any point contained in the floating tree
* @return a set containing all blocks in the tree/shroom or null if this is not a floating tree/shroom.
*/
private Set<BlockVector3> bfs(World world, BlockVector3 origin) throws MaxChangedBlocksException {
final LocalBlockVectorSet visited = new LocalBlockVectorSet();
final LocalBlockVectorSet queue = new LocalBlockVectorSet();
queue.add(origin);
visited.add(origin);
while (!queue.isEmpty()) {
Iterator<BlockVector3> iter = queue.iterator();
while (iter.hasNext()) {
final BlockVector3 current = iter.next();
iter.remove();
for (BlockVector3 recurseDirection : recurseDirections) {
final BlockVector3 next = current.add(recurseDirection);
if (origin.distanceSq(next) > rangeSq) {
// Maximum range exceeded => stop walking
continue;
}
if (visited.add(next)) {
BlockState state = world.getBlock(next);
if (state.getBlockType().getMaterial().isAir() || state.getBlockType() == BlockTypes.SNOW) {
continue;
}
if (isTreeBlock(state.getBlockType())) {
queue.add(next);
} else {
// we hit something solid - evaluate where we came from
final BlockType currentType = world.getBlock(current).getBlockType();
if (!BlockCategories.LEAVES.contains(currentType) && currentType != BlockTypes.VINE) {
// log/shroom touching a wall/the ground => this is not a floating tree, bail out
return null;
}
}
}
}
}
}
return visited;
}
}

View File

@ -72,6 +72,7 @@ public class LongRangeBuildTool extends BrushTool implements DoubleActionTraceTo
@Override
public boolean actPrimary(Platform server, LocalConfiguration config, Player player, LocalSession session) {
Location pos = getTargetFace(player);
try (EditSession eS = session.createEditSession(player)) {
BlockVector3 blockPoint = pos.toBlockPoint();
BaseBlock applied = primary.apply(blockPoint);

View File

@ -48,7 +48,7 @@ public class QueryTool implements BlockTool {
BlockVector3 blockPoint = clicked.toBlockPoint();
BaseBlock block = editSession.getFullBlock(blockPoint);
player.print("\u00A79@" + clicked + ": " + "\u00A7e"
player.print("\u00A79@" + blockPoint + ": " + "\u00A7e"
+ block.getBlockType().getName() + "\u00A77" + " ("
+ block.toString() + ") "
+ "\u00A7f"

View File

@ -49,6 +49,7 @@ public class TreePlanter implements BlockTool {
public boolean actPrimary(Platform server, LocalConfiguration config, Player player, LocalSession session, Location clicked) {
try (EditSession editSession = session.createEditSession(player)) {
try {
boolean successful = false;
for (int i = 0; i < 10; i++) {
@ -66,6 +67,7 @@ public class TreePlanter implements BlockTool {
} finally {
session.remember(editSession);
}
}
return true;
}

View File

@ -24,10 +24,12 @@ import com.boydti.fawe.jnbt.JSON2NBT;
import com.boydti.fawe.jnbt.NBTException;
import com.boydti.fawe.util.MathMan;
import com.boydti.fawe.util.StringMan;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.IncompleteRegionException;
import com.sk89q.worldedit.NotABlockException;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.blocks.BaseItem;
import com.sk89q.worldedit.blocks.MobSpawnerBlock;
import com.sk89q.worldedit.blocks.SignBlock;
import com.sk89q.worldedit.blocks.SkullBlock;
@ -39,6 +41,7 @@ import com.sk89q.worldedit.extension.input.NoMatchException;
import com.sk89q.worldedit.extension.input.ParserContext;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extension.platform.Capability;
import com.sk89q.worldedit.extension.platform.Platform;
import com.sk89q.worldedit.extent.inventory.BlockBag;
import com.sk89q.worldedit.extent.inventory.SlottableBlockBag;
import com.sk89q.worldedit.internal.registry.InputParser;

View File

@ -204,6 +204,11 @@ public class AbstractDelegateExtent implements LightingExtent {
return extent.getNearestSurfaceLayer(x, z, y, minY, maxY);
}
@Override
public int getHighestTerrainBlock(int x, int z, int minY, int maxY, Mask filter) {
return extent.getHighestTerrainBlock(x, z, minY, maxY, filter);
}
@Override
public int getNearestSurfaceTerrainBlock(int x, int z, int y, int minY, int maxY, boolean ignoreAir) {
return extent.getNearestSurfaceTerrainBlock(x, z, y, minY, maxY, ignoreAir);
@ -219,6 +224,10 @@ public class AbstractDelegateExtent implements LightingExtent {
return extent.getNearestSurfaceTerrainBlock(x, z, y, minY, maxY, failedMin, failedMax);
}
public int getNearestSurfaceTerrainBlock(int x, int z, int y, int minY, int maxY, int failedMin, int failedMax, Mask mask) {
return extent.getNearestSurfaceTerrainBlock(x, z, y, minY, maxY, failedMin, failedMax, mask);
}
@Override
public int getNearestSurfaceTerrainBlock(int x, int z, int y, int minY, int maxY, int failedMin, int failedMax, boolean ignoreAir) {
return extent.getNearestSurfaceTerrainBlock(x, z, y, minY, maxY, failedMin, failedMax, ignoreAir);

View File

@ -40,6 +40,7 @@ import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.List;

View File

@ -31,6 +31,8 @@ import com.sk89q.worldedit.function.operation.Operation;
import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.math.BlockVector2;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.MutableBlockVector3;
import com.sk89q.worldedit.math.MutableVector3;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.registry.state.PropertyGroup;
import com.sk89q.worldedit.session.ClipboardHolder;
@ -149,6 +151,17 @@ public interface Extent extends InputExtent, OutputExtent {
return minY;
}
default int getHighestTerrainBlock(final int x, final int z, int minY, int maxY, Mask filter) {
maxY = Math.min(maxY, Math.max(0, maxY));
minY = Math.max(0, minY);
for (int y = maxY; y >= minY; --y) {
if (filter.test(MutableBlockVector3.get(x, y, z))) {
return y;
}
}
return minY;
}
default int getNearestSurfaceLayer(int x, int z, int y, int minY, int maxY) {
int clearanceAbove = maxY - y;
int clearanceBelow = y - minY;
@ -178,10 +191,6 @@ public interface Extent extends InputExtent, OutputExtent {
for (int layer = y - clearance - 1; layer >= minY; layer--) {
block = getLazyBlock(x, layer, z);
if (!block.getBlockType().getMaterial().isMovementBlocker() != state) {
// int blockHeight = (newHeight) >> 3;
// int layerHeight = (newHeight) & 0x7;
int data = (state ? PropertyGroup.LEVEL.get(block) : data1);
return ((layer + offset) << 4) + 0;
}
@ -212,6 +221,34 @@ public interface Extent extends InputExtent, OutputExtent {
return getNearestSurfaceTerrainBlock(x, z, y, minY, maxY, failedMin, failedMax, true);
}
default int getNearestSurfaceTerrainBlock(int x, int z, int y, int minY, int maxY, int failedMin, int failedMax, Mask mask) {
y = Math.max(minY, Math.min(maxY, y));
int clearanceAbove = maxY - y;
int clearanceBelow = y - minY;
int clearance = Math.min(clearanceAbove, clearanceBelow);
boolean state = !mask.test(MutableBlockVector3.get(x, y, z));
int offset = state ? 0 : 1;
for (int d = 0; d <= clearance; d++) {
int y1 = y + d;
if (mask.test(MutableBlockVector3.get(x, y1, z)) != state) return y1 - offset;
int y2 = y - d;
if (mask.test(MutableBlockVector3.get(x, y2, z)) != state) return y2 + offset;
}
if (clearanceAbove != clearanceBelow) {
if (clearanceAbove < clearanceBelow) {
for (int layer = y - clearance - 1; layer >= minY; layer--) {
if (mask.test(MutableBlockVector3.get(x, layer, z)) != state) return layer + offset;
}
} else {
for (int layer = y + clearance + 1; layer <= maxY; layer++) {
if (mask.test(MutableBlockVector3.get(x, layer, z)) != state) return layer - offset;
}
}
}
int result = state ? failedMin : failedMax;
return result;
}
default int getNearestSurfaceTerrainBlock(int x, int z, int y, int minY, int maxY, int failedMin, int failedMax, boolean ignoreAir) {
y = Math.max(minY, Math.min(maxY, y));
int clearanceAbove = maxY - y;

View File

@ -23,6 +23,8 @@ import static com.google.common.base.Preconditions.checkNotNull;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.math.BlockVector2;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.math.BlockVector3;

View File

@ -29,6 +29,7 @@ import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BlockState;
import static com.google.common.base.Preconditions.checkNotNull;

View File

@ -45,6 +45,7 @@ import com.sk89q.jnbt.Tag;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.world.biome.BiomeTypes;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.extension.input.InputParseException;
import com.sk89q.worldedit.extension.input.ParserContext;
@ -60,6 +61,8 @@ import com.sk89q.worldedit.world.entity.EntityType;
import com.sk89q.worldedit.world.entity.EntityTypes;
import net.jpountz.lz4.LZ4BlockInputStream;
import net.jpountz.lz4.LZ4BlockOutputStream;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.DataInputStream;
import java.io.IOException;
@ -70,7 +73,6 @@ import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.function.BiConsumer;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import static com.google.common.base.Preconditions.checkNotNull;
@ -238,7 +240,7 @@ public class SpongeSchematicReader extends NBTSchematicReader {
try (FaweInputStream fis = new FaweInputStream(new LZ4BlockInputStream(new FastByteArraysInputStream(biomesOut.toByteArrays())))) {
int volume = width * length;
for (int index = 0; index < volume; index++) {
fc.setBiome(index, fis.read());
fc.setBiome(index, BiomeTypes.get(fis.read()));
}
}
}

View File

@ -44,7 +44,7 @@ public class HeightMap {
* @param region the region
*/
public HeightMap(EditSession session, Region region) {
this(session, region, false);
this(session, region, (Mask) null, false);
}
public HeightMap(EditSession session, Region region, Mask mask) {
@ -83,7 +83,7 @@ public class HeightMap {
BlockVector2 pos = iter.next();
int x = pos.getBlockX();
int z = pos.getBlockZ();
layer = session.getNearestSurfaceLayer(x, z, (layer + 7) >> 3, 0, maxY, mask);
layer = session.getNearestSurfaceLayer(x, z, (layer + 7) >> 3, 0, maxY);
data[(z - bz) * width + (x - bx)] = layer;
}
} else {

View File

@ -129,7 +129,7 @@ public class EllipsoidRegion extends AbstractRegion {
@Override
public void expand(BlockVector3... changes) throws RegionOperationException {
center = center.add(calculateDiff(changes));
setRadius(radius.add(calculateChanges(changes).toVector3()));
setRadius(radius.add(calculateChanges(changes)));
}
@Override

View File

@ -27,15 +27,6 @@ import java.util.Collections;
public interface ItemRegistry {
/**
* Gets the name for the given item.
*
* @param itemType the item
* @return The name, or null if it's unknown
*/
@Nullable
String getName(ItemType itemType);
/**
* Register all items
*/