mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-16 03:14:04 +00:00
Merge remote-tracking branch 'upstream/master' into breaking
This commit is contained in:
@@ -6,6 +6,9 @@ import com.sk89q.worldedit.LocalSession;
|
||||
import com.sk89q.worldedit.entity.Player;
|
||||
import com.sk89q.worldedit.extension.platform.Actor;
|
||||
import com.sk89q.worldedit.extension.platform.Platform;
|
||||
import com.sk89q.worldedit.MaxChangedBlocksException;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
import com.sk89q.worldedit.world.block.BlockType;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
|
||||
@@ -40,33 +43,21 @@ public class AreaPickaxe implements BlockTool {
|
||||
return true;
|
||||
}
|
||||
|
||||
EditSession editSession = session.createEditSession(player);
|
||||
editSession.getSurvivalExtent().setToolUse(config.superPickaxeManyDrop);
|
||||
try (EditSession editSession = session.createEditSession(player)) {
|
||||
editSession.getSurvivalExtent().setToolUse(config.superPickaxeManyDrop);
|
||||
|
||||
for (int x = ox - range; x <= ox + range; ++x) {
|
||||
for (int z = oz - range; z <= oz + range; ++z) {
|
||||
for (int y = oy + range; y >= oy - range; --y) {
|
||||
if (initialType.equals(editSession.getLazyBlock(x, y, z))) {
|
||||
continue;
|
||||
// try (EditSession editSession = session.createEditSession(player)) {
|
||||
// editSession.getSurvivalExtent().setToolUse(config.superPickaxeManyDrop);
|
||||
//
|
||||
// try {
|
||||
// for (int x = ox - range; x <= ox + range; ++x) {
|
||||
// for (int y = oy - range; y <= oy + range; ++y) {
|
||||
// for (int z = oz - range; z <= oz + range; ++z) {
|
||||
// BlockVector3 pos = new BlockVector3(x, y, z);
|
||||
// if (editSession.getBlock(pos).getBlockType() != initialType) {
|
||||
// continue;
|
||||
// }
|
||||
//
|
||||
// ((World) clicked.getExtent()).queueBlockBreakEffect(server, pos, initialType, clicked.toBlockPoint().distanceSq(pos));
|
||||
//
|
||||
// editSession.setBlock(pos, BlockTypes.AIR.getDefaultState());
|
||||
// }
|
||||
}
|
||||
editSession.setBlock(x, y, z, BlockTypes.AIR.getDefaultState());
|
||||
}
|
||||
} catch (MaxChangedBlocksException e) {
|
||||
player.printError("Max blocks change limit reached.");
|
||||
} finally {
|
||||
session.remember(editSession);
|
||||
}
|
||||
}
|
||||
editSession.flushQueue();
|
||||
|
@@ -25,13 +25,15 @@ import com.sk89q.worldedit.world.block.BlockType;
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.LocalConfiguration;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
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.extent.inventory.BlockBag;
|
||||
import com.sk89q.worldedit.function.pattern.BlockPattern;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
|
||||
/**
|
||||
* A mode that replaces one block.
|
||||
*/
|
||||
public class BlockReplacer implements DoubleActionBlockTool {
|
||||
|
||||
@@ -58,7 +60,6 @@ public class BlockReplacer implements DoubleActionBlockTool {
|
||||
if (bag != null) {
|
||||
bag.flushChanges();
|
||||
}
|
||||
session.remember(editSession);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@@ -472,14 +472,6 @@ public class BrushTool implements DoubleActionTraceTool, ScrollTool, MovableTool
|
||||
MaskIntersection newMask = new MaskIntersection(existingMask);
|
||||
newMask.add(mask);
|
||||
editSession.setMask(newMask);
|
||||
//=======
|
||||
// try {
|
||||
// brush.build(editSession, target.toBlockPoint(), material, size);
|
||||
// } catch (MaxChangedBlocksException e) {
|
||||
// player.printError("Max blocks change limit reached.");
|
||||
// } finally {
|
||||
// session.remember(editSession);
|
||||
//>>>>>>> 399e0ad5... Refactor vector system to be cleaner
|
||||
}
|
||||
}
|
||||
Mask sourceMask = current.getSourceMask();
|
||||
|
@@ -19,6 +19,7 @@
|
||||
|
||||
package com.sk89q.worldedit.command.tool;
|
||||
|
||||
import com.boydti.fawe.object.collection.BlockVectorSet;
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.LocalConfiguration;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
@@ -75,80 +76,26 @@ public class FloatingTreeRemover implements BlockTool {
|
||||
player.printError("That's not a tree.");
|
||||
return true;
|
||||
}
|
||||
final EditSession editSession = session.createEditSession(player);
|
||||
try /*(EditSession editSession = session.createEditSession(player))*/ {
|
||||
final Set<BlockVector3> blockSet = bfs(world, clicked.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);
|
||||
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);
|
||||
} finally {
|
||||
session.remember(editSession);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
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 Set<BlockVector3> visited = new HashSet<>();
|
||||
final LinkedList<BlockVector3> queue = new LinkedList<>();
|
||||
|
||||
queue.addLast(origin);
|
||||
visited.add(origin);
|
||||
|
||||
while (!queue.isEmpty()) {
|
||||
final BlockVector3 current = queue.removeFirst();
|
||||
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.addLast(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;
|
||||
}
|
||||
}
|
||||
|
@@ -69,17 +69,16 @@ public class FloodFillTool implements BlockTool {
|
||||
return true;
|
||||
}
|
||||
|
||||
EditSession editSession = session.createEditSession(player);
|
||||
try {
|
||||
recurse(editSession, origin, origin, range, initialType, new HashSet<>());
|
||||
} catch (MaxChangedBlocksException e) {
|
||||
player.printError("Max blocks change limit reached.");
|
||||
} finally {
|
||||
session.remember(editSession);
|
||||
try (EditSession editSession = session.createEditSession(player)) {
|
||||
try {
|
||||
TODO fillDirection (but replace)
|
||||
recurse(editSession, origin, origin, range, initialType, new HashSet<>());
|
||||
} catch (MaxChangedBlocksException e) {
|
||||
player.printError("Max blocks change limit reached.");
|
||||
} finally {
|
||||
session.remember(editSession);
|
||||
}
|
||||
}
|
||||
|
||||
editSession.flushQueue();
|
||||
session.remember(editSession);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@@ -55,10 +55,8 @@ public class LongRangeBuildTool extends BrushTool implements DoubleActionTraceTo
|
||||
public boolean actSecondary(Platform server, LocalConfiguration config, Player player, LocalSession session) {
|
||||
Location pos = getTargetFace(player);
|
||||
if (pos == null) return false;
|
||||
EditSession eS = session.createEditSession(player);
|
||||
try {
|
||||
// eS.disableBuffering();
|
||||
BlockVector3 blockPoint = pos.toBlockPoint();
|
||||
try (EditSession eS = session.createEditSession(player)) {
|
||||
BlockVector3 blockPoint = pos.toVector().toBlockPoint();
|
||||
BaseBlock applied = secondary.apply(blockPoint);
|
||||
if (applied.getBlockType().getMaterial().isAir()) {
|
||||
eS.setBlock(blockPoint, secondary);
|
||||
@@ -74,12 +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);
|
||||
if (pos == null) return false;
|
||||
EditSession eS = session.createEditSession(player);
|
||||
|
||||
try {
|
||||
// eS.disableBuffering();
|
||||
try (EditSession eS = session.createEditSession(player)) {
|
||||
BlockVector3 blockPoint = pos.toBlockPoint();
|
||||
BaseBlock applied = primary.apply(blockPoint);
|
||||
if (applied.getBlockType().getMaterial().isAir()) {
|
||||
|
@@ -53,7 +53,6 @@ public class RecursivePickaxe implements BlockTool {
|
||||
|
||||
editSession.getSurvivalExtent().setToolUse(config.superPickaxeManyDrop);
|
||||
|
||||
//<<<<<<< HEAD
|
||||
final int radius = (int) range;
|
||||
final BlockReplace replace = new BlockReplace(editSession, (editSession.nullBlock));
|
||||
editSession.setMask((Mask) null);
|
||||
@@ -63,51 +62,6 @@ public class RecursivePickaxe implements BlockTool {
|
||||
|
||||
editSession.flushQueue();
|
||||
session.remember(editSession);
|
||||
//=======
|
||||
// try {
|
||||
// recurse(server, editSession, world, clicked.toBlockPoint(),
|
||||
// clicked.toBlockPoint(), range, initialType, new HashSet<>());
|
||||
// } catch (MaxChangedBlocksException e) {
|
||||
// player.printError("Max blocks change limit reached.");
|
||||
// } finally {
|
||||
// session.remember(editSession);
|
||||
// }
|
||||
// }
|
||||
//>>>>>>> 399e0ad5... Refactor vector system to be cleaner
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// private static void recurse(Platform server, EditSession editSession, World world, BlockVector3 pos,
|
||||
// BlockVector3 origin, double size, BlockType initialType, Set<BlockVector3> visited) throws MaxChangedBlocksException {
|
||||
//
|
||||
// final double distanceSq = origin.distanceSq(pos);
|
||||
// if (distanceSq > size*size || visited.contains(pos)) {
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// visited.add(pos);
|
||||
//
|
||||
// if (editSession.getBlock(pos).getBlockType() != initialType) {
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// world.queueBlockBreakEffect(server, pos, initialType, distanceSq);
|
||||
//
|
||||
// editSession.setBlock(pos, BlockTypes.AIR.getDefaultState());
|
||||
//
|
||||
// recurse(server, editSession, world, pos.add(1, 0, 0),
|
||||
// origin, size, initialType, visited);
|
||||
// recurse(server, editSession, world, pos.add(-1, 0, 0),
|
||||
// origin, size, initialType, visited);
|
||||
// recurse(server, editSession, world, pos.add(0, 0, 1),
|
||||
// origin, size, initialType, visited);
|
||||
// recurse(server, editSession, world, pos.add(0, 0, -1),
|
||||
// origin, size, initialType, visited);
|
||||
// recurse(server, editSession, world, pos.add(0, 1, 0),
|
||||
// origin, size, initialType, visited);
|
||||
// recurse(server, editSession, world, pos.add(0, -1, 0),
|
||||
// origin, size, initialType, visited);
|
||||
// }
|
||||
|
||||
}
|
@@ -50,24 +50,12 @@ public class SinglePickaxe implements BlockTool {
|
||||
&& !player.canDestroyBedrock()) {
|
||||
return true;
|
||||
}
|
||||
final EditSession editSession = session.createEditSession(player);
|
||||
try {
|
||||
|
||||
try (EditSession editSession = session.createEditSession(player)) {
|
||||
editSession.getSurvivalExtent().setToolUse(config.superPickaxeDrop);
|
||||
editSession.setBlock(blockPoint, BlockTypes.AIR.getDefaultState());
|
||||
} catch (MaxChangedBlocksException e) {
|
||||
player.printError("Max blocks change limit reached.");
|
||||
}
|
||||
|
||||
try {
|
||||
if (editSession.setBlock(clicked.getBlockX(), clicked.getBlockY(), clicked.getBlockZ(), EditSession.nullBlock)) {
|
||||
// TODO FIXME play effect
|
||||
// world.playEffect(clicked, 2001, blockType);
|
||||
}
|
||||
} finally {
|
||||
editSession.flushQueue();
|
||||
session.remember(editSession);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@@ -48,16 +48,15 @@ public class TreePlanter implements BlockTool {
|
||||
@Override
|
||||
public boolean actPrimary(Platform server, LocalConfiguration config, Player player, LocalSession session, Location clicked) {
|
||||
|
||||
EditSession editSession = session.createEditSession(player);
|
||||
|
||||
try {
|
||||
try (EditSession editSession = session.createEditSession(player)) {
|
||||
boolean successful = false;
|
||||
for (int i = 0; i < 10; i++) {
|
||||
if (treeType.generate(editSession, clicked.add(0, 1, 0).toBlockPoint())) {
|
||||
successful = true;
|
||||
break;
|
||||
}
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
if (treeType.generate(editSession, clicked.add(0, 1, 0).toBlockPoint())) {
|
||||
successful = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!successful) {
|
||||
player.printError("A tree can't go there.");
|
||||
|
@@ -21,10 +21,10 @@ package com.sk89q.worldedit.command.tool.brush;
|
||||
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.MaxChangedBlocksException;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
import com.sk89q.worldedit.function.pattern.BlockPattern;
|
||||
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
|
||||
public class CylinderBrush implements Brush {
|
||||
|
||||
|
@@ -21,12 +21,14 @@ package com.sk89q.worldedit.command.tool.brush;
|
||||
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.MaxChangedBlocksException;
|
||||
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
import com.sk89q.worldedit.function.mask.Masks;
|
||||
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class GravityBrush implements Brush {
|
||||
|
||||
|
@@ -24,6 +24,7 @@ import com.sk89q.worldedit.MaxChangedBlocksException;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.function.pattern.BlockPattern;
|
||||
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
|
||||
public class HollowCylinderBrush implements Brush {
|
||||
|
@@ -24,6 +24,7 @@ import com.sk89q.worldedit.MaxChangedBlocksException;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.function.pattern.BlockPattern;
|
||||
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
|
||||
public class HollowSphereBrush implements Brush {
|
||||
|
@@ -20,6 +20,7 @@
|
||||
package com.sk89q.worldedit.command.tool.brush;
|
||||
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
import com.sk89q.worldedit.MaxChangedBlocksException;
|
||||
import com.sk89q.worldedit.function.Contextual;
|
||||
import com.sk89q.worldedit.function.EditContext;
|
||||
@@ -33,10 +34,16 @@ public class OperationFactoryBrush implements Brush {
|
||||
|
||||
private final Contextual<? extends Operation> operationFactory;
|
||||
private final RegionFactory regionFactory;
|
||||
private final LocalSession session;
|
||||
|
||||
public OperationFactoryBrush(Contextual<? extends Operation> operationFactory, RegionFactory regionFactory) {
|
||||
this(operationFactory, regionFactory, null);
|
||||
}
|
||||
|
||||
public OperationFactoryBrush(Contextual<? extends Operation> operationFactory, RegionFactory regionFactory, LocalSession session) {
|
||||
this.operationFactory = operationFactory;
|
||||
this.regionFactory = regionFactory;
|
||||
this.session = session;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -45,6 +52,7 @@ public class OperationFactoryBrush implements Brush {
|
||||
context.setDestination(editSession);
|
||||
context.setRegion(regionFactory.createCenteredAt(position, size));
|
||||
context.setFill(pattern);
|
||||
context.setSession(session);
|
||||
Operation operation = operationFactory.createFromContext(context);
|
||||
Operations.completeLegacy(operation);
|
||||
}
|
||||
|
@@ -21,9 +21,10 @@ package com.sk89q.worldedit.command.tool.brush;
|
||||
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.MaxChangedBlocksException;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.math.Vector3;
|
||||
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
import com.sk89q.worldedit.math.convolution.GaussianKernel;
|
||||
import com.sk89q.worldedit.math.convolution.HeightMap;
|
||||
import com.sk89q.worldedit.math.convolution.HeightMapFilter;
|
||||
@@ -31,12 +32,20 @@ import com.sk89q.worldedit.regions.CuboidRegion;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
import com.sk89q.worldedit.util.Location;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class SmoothBrush implements Brush {
|
||||
|
||||
private final Mask mask;
|
||||
private int iterations;
|
||||
|
||||
public SmoothBrush(int iterations) {
|
||||
this(iterations, null);
|
||||
}
|
||||
|
||||
public SmoothBrush(int iterations, @Nullable Mask mask) {
|
||||
this.iterations = iterations;
|
||||
this.mask = mask;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -45,7 +54,7 @@ public class SmoothBrush implements Brush {
|
||||
Location min = new Location(editSession.getWorld(), posDouble.subtract(size, size, size));
|
||||
BlockVector3 max = posDouble.add(size, size + 10, size).toBlockPoint();
|
||||
Region region = new CuboidRegion(editSession.getWorld(), min.toBlockPoint(), max);
|
||||
HeightMap heightMap = new HeightMap(editSession, region);
|
||||
HeightMap heightMap = new HeightMap(editSession, region, mask);
|
||||
HeightMapFilter filter = new HeightMapFilter(new GaussianKernel(5, 1.0));
|
||||
heightMap.applyFilter(filter, iterations);
|
||||
}
|
||||
|
@@ -21,9 +21,9 @@ package com.sk89q.worldedit.command.tool.brush;
|
||||
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.MaxChangedBlocksException;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.function.pattern.BlockPattern;
|
||||
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
|
||||
public class SphereBrush implements Brush {
|
||||
|
Reference in New Issue
Block a user