Fixed some bugs and cleanup some code.

This commit is contained in:
Matthew Miller
2018-08-13 22:18:12 +10:00
parent f96487a2d1
commit e0e7778536
22 changed files with 92 additions and 394 deletions

View File

@@ -23,22 +23,24 @@ import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.LocalConfiguration;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.Vector;
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.function.pattern.Pattern;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockType;
/**
* A mode that replaces one block.
*/
public class BlockReplacer implements DoubleActionBlockTool {
private BlockStateHolder targetBlock;
private Pattern pattern;
public BlockReplacer(BlockStateHolder targetBlock) {
this.targetBlock = targetBlock;
public BlockReplacer(Pattern pattern) {
this.pattern = pattern;
}
@Override
@@ -53,7 +55,8 @@ public class BlockReplacer implements DoubleActionBlockTool {
EditSession editSession = session.createEditSession(player);
try {
editSession.setBlock(clicked.toVector(), targetBlock);
Vector position = clicked.toVector();
editSession.setBlock(position, pattern.apply(position));
} catch (MaxChangedBlocksException ignored) {
} finally {
if (bag != null) {
@@ -69,11 +72,11 @@ public class BlockReplacer implements DoubleActionBlockTool {
@Override
public boolean actSecondary(Platform server, LocalConfiguration config, Player player, LocalSession session, com.sk89q.worldedit.util.Location clicked) {
EditSession editSession = session.createEditSession(player);
targetBlock = (editSession).getBlock(clicked.toVector());
BlockType type = targetBlock.getBlockType();
BlockStateHolder targetBlock = editSession.getBlock(clicked.toVector());
if (type != null) {
player.print("Replacer tool switched to: " + type.getName());
if (targetBlock != null) {
pattern = new BlockPattern(targetBlock);
player.print("Replacer tool switched to: " + targetBlock.getBlockType().getName());
}
return true;

View File

@@ -26,6 +26,7 @@ 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.pattern.Pattern;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockTypes;
@@ -35,10 +36,10 @@ import com.sk89q.worldedit.world.block.BlockTypes;
*/
public class LongRangeBuildTool extends BrushTool implements DoubleActionTraceTool {
private BlockStateHolder primary;
private BlockStateHolder secondary;
private Pattern primary;
private Pattern secondary;
public LongRangeBuildTool(BlockStateHolder primary, BlockStateHolder secondary) {
public LongRangeBuildTool(Pattern secondary, Pattern primary) {
super("worldedit.tool.lrbuild");
this.primary = primary;
this.secondary = secondary;
@@ -55,7 +56,8 @@ public class LongRangeBuildTool extends BrushTool implements DoubleActionTraceTo
if (pos == null) return false;
EditSession eS = session.createEditSession(player);
try {
if (secondary.getBlockType() == BlockTypes.AIR) {
BlockStateHolder applied = secondary.apply(pos.toVector());
if (applied.getBlockType() == BlockTypes.AIR) {
eS.setBlock(pos.toVector(), secondary);
} else {
eS.setBlock(pos.getDirection(), secondary);
@@ -74,7 +76,8 @@ public class LongRangeBuildTool extends BrushTool implements DoubleActionTraceTo
if (pos == null) return false;
EditSession eS = session.createEditSession(player);
try {
if (primary.getBlockType() == BlockTypes.AIR) {
BlockStateHolder applied = primary.apply(pos.toVector());
if (applied.getBlockType() == BlockTypes.AIR) {
eS.setBlock(pos.toVector(), primary);
} else {
eS.setBlock(pos.getDirection(), primary);