mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-16 03:14:04 +00:00
Copy paste/merge FAWE classes to this WorldEdit fork
- so certain people can look at the diff and complain about my sloppy code :( Signed-off-by: Jesse Boyd <jessepaleg@gmail.com>
This commit is contained in:
@@ -1,33 +1,11 @@
|
||||
/*
|
||||
* WorldEdit, a Minecraft world manipulation toolkit
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.command.tool;
|
||||
|
||||
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.world.World;
|
||||
import com.sk89q.worldedit.world.block.BlockType;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
|
||||
@@ -54,7 +32,7 @@ public class AreaPickaxe implements BlockTool {
|
||||
int oz = clicked.getBlockZ();
|
||||
BlockType initialType = clicked.getExtent().getBlock(clicked.toVector()).getBlockType();
|
||||
|
||||
if (initialType == BlockTypes.AIR) {
|
||||
if (initialType.getMaterial().isAir()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -65,29 +43,23 @@ public class AreaPickaxe implements BlockTool {
|
||||
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) {
|
||||
Vector pos = new Vector(x, y, z);
|
||||
if (editSession.getBlock(pos).getBlockType() != initialType) {
|
||||
continue;
|
||||
}
|
||||
|
||||
((World) clicked.getExtent()).queueBlockBreakEffect(server, pos, initialType, clicked.toVector().distanceSq(pos));
|
||||
|
||||
editSession.setBlock(pos, BlockTypes.AIR.getDefaultState());
|
||||
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;
|
||||
}
|
||||
editSession.setBlock(x, y, z, BlockTypes.AIR.getDefaultState());
|
||||
}
|
||||
}
|
||||
} catch (MaxChangedBlocksException e) {
|
||||
player.printError("Max blocks change limit reached.");
|
||||
} finally {
|
||||
editSession.flushQueue();
|
||||
session.remember(editSession);
|
||||
}
|
||||
editSession.flushQueue();
|
||||
session.remember(editSession);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
public static Class<?> inject() {
|
||||
return AreaPickaxe.class;
|
||||
}
|
||||
}
|
@@ -19,7 +19,6 @@
|
||||
|
||||
package com.sk89q.worldedit.command.tool;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.LocalConfiguration;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
@@ -27,15 +26,9 @@ 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.registry.state.Property;
|
||||
import com.sk89q.worldedit.util.Location;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
|
||||
/**
|
||||
* A mode that cycles the data values of supported blocks.
|
||||
@@ -47,14 +40,12 @@ public class BlockDataCyler implements DoubleActionBlockTool {
|
||||
return player.hasPermission("worldedit.tool.data-cycler");
|
||||
}
|
||||
|
||||
private Map<UUID, Property<?>> selectedProperties = new HashMap<>();
|
||||
|
||||
private boolean handleCycle(Platform server, LocalConfiguration config,
|
||||
Player player, LocalSession session, Location clicked, boolean forward) {
|
||||
|
||||
World world = (World) clicked.getExtent();
|
||||
|
||||
BlockState block = world.getBlock(clicked.toVector());
|
||||
BlockStateHolder block = world.getBlock(clicked.toVector());
|
||||
|
||||
if (!config.allowedDataCycleBlocks.isEmpty()
|
||||
&& !player.hasPermission("worldedit.override.data-cycler")
|
||||
@@ -63,39 +54,22 @@ public class BlockDataCyler implements DoubleActionBlockTool {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (block.getStates().keySet().isEmpty()) {
|
||||
if (block.getBlockType().getProperties().isEmpty()) {
|
||||
player.printError("That block's data cannot be cycled!");
|
||||
} else {
|
||||
Property currentProperty = selectedProperties.get(player.getUniqueId());
|
||||
BlockStateHolder newBlock = block;
|
||||
|
||||
if (currentProperty == null || (forward && block.getState(currentProperty) == null)) {
|
||||
currentProperty = block.getStates().keySet().stream().findFirst().get();
|
||||
selectedProperties.put(player.getUniqueId(), currentProperty);
|
||||
}
|
||||
// TODO Forward = cycle value, Backward = Next property
|
||||
// int increment = forward ? 1 : -1;
|
||||
// BaseBlock newBlock = new BaseBlock(type, BlockData.cycle(type, data, increment));
|
||||
EditSession editSession = session.createEditSession(player);
|
||||
|
||||
if (forward) {
|
||||
block.getState(currentProperty);
|
||||
int index = currentProperty.getValues().indexOf(block.getState(currentProperty));
|
||||
index = (index + 1) % currentProperty.getValues().size();
|
||||
BlockState newBlock = block.with(currentProperty, currentProperty.getValues().get(index));
|
||||
|
||||
EditSession editSession = session.createEditSession(player);
|
||||
|
||||
try {
|
||||
editSession.setBlock(clicked.toVector(), newBlock);
|
||||
player.print("Value of " + currentProperty.getName() + " is now " + currentProperty.getValues().get(index).toString());
|
||||
} catch (MaxChangedBlocksException e) {
|
||||
player.printError("Max blocks change limit reached.");
|
||||
} finally {
|
||||
session.remember(editSession);
|
||||
}
|
||||
} else {
|
||||
List<Property<?>> properties = Lists.newArrayList(block.getStates().keySet());
|
||||
int index = properties.indexOf(currentProperty);
|
||||
index = (index + 1) % properties.size();
|
||||
currentProperty = properties.get(index);
|
||||
selectedProperties.put(player.getUniqueId(), currentProperty);
|
||||
player.print("Now cycling " + currentProperty.getName());
|
||||
try {
|
||||
editSession.setBlock(clicked.toVector(), newBlock);
|
||||
} catch (MaxChangedBlocksException e) {
|
||||
player.printError("Max blocks change limit reached.");
|
||||
} finally {
|
||||
session.remember(editSession);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -19,26 +19,26 @@
|
||||
|
||||
package com.sk89q.worldedit.command.tool;
|
||||
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.LocalConfiguration;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
import com.sk89q.worldedit.MaxChangedBlocksException;
|
||||
import com.boydti.fawe.object.extent.PatternTransform;
|
||||
import com.sk89q.worldedit.*;
|
||||
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.BlockType;
|
||||
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.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,8 +53,7 @@ public class BlockReplacer implements DoubleActionBlockTool {
|
||||
EditSession editSession = session.createEditSession(player);
|
||||
|
||||
try {
|
||||
editSession.setBlock(clicked.toVector(), targetBlock);
|
||||
} catch (MaxChangedBlocksException ignored) {
|
||||
editSession.setBlock(clicked.toVector(), pattern);
|
||||
} finally {
|
||||
if (bag != null) {
|
||||
bag.flushChanges();
|
||||
@@ -69,10 +68,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());
|
||||
BlockStateHolder targetBlock = (editSession).getBlock(clicked.toVector());
|
||||
BlockType type = targetBlock.getBlockType();
|
||||
|
||||
if (type != null) {
|
||||
this.pattern = targetBlock;
|
||||
player.print("Replacer tool switched to: " + type.getName());
|
||||
}
|
||||
|
||||
|
@@ -1,118 +1,326 @@
|
||||
/*
|
||||
* WorldEdit, a Minecraft world manipulation toolkit
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.command.tool;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.LocalConfiguration;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
import com.sk89q.worldedit.MaxChangedBlocksException;
|
||||
import com.boydti.fawe.Fawe;
|
||||
import com.boydti.fawe.FaweCache;
|
||||
import com.boydti.fawe.config.BBC;
|
||||
import com.boydti.fawe.object.FawePlayer;
|
||||
import com.boydti.fawe.object.RunnableVal;
|
||||
import com.boydti.fawe.object.brush.BrushSettings;
|
||||
import com.boydti.fawe.object.brush.MovableTool;
|
||||
import com.boydti.fawe.object.brush.ResettableTool;
|
||||
import com.boydti.fawe.object.brush.TargetMode;
|
||||
import com.boydti.fawe.object.brush.scroll.ScrollAction;
|
||||
import com.boydti.fawe.object.brush.scroll.ScrollTool;
|
||||
import com.boydti.fawe.object.brush.visualization.VisualChunk;
|
||||
import com.boydti.fawe.object.brush.visualization.VisualExtent;
|
||||
import com.boydti.fawe.object.brush.visualization.VisualMode;
|
||||
import com.boydti.fawe.object.extent.ResettableExtent;
|
||||
import com.boydti.fawe.object.mask.MaskedTargetBlock;
|
||||
import com.boydti.fawe.object.pattern.PatternTraverser;
|
||||
import com.boydti.fawe.util.*;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.sk89q.minecraft.util.commands.CommandException;
|
||||
import com.sk89q.worldedit.*;
|
||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.blocks.BaseItem;
|
||||
import com.sk89q.worldedit.command.tool.brush.Brush;
|
||||
import com.sk89q.worldedit.command.tool.brush.SphereBrush;
|
||||
import com.sk89q.worldedit.entity.Player;
|
||||
import com.sk89q.worldedit.extension.input.InputParseException;
|
||||
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.mask.Mask;
|
||||
import com.sk89q.worldedit.function.mask.MaskIntersection;
|
||||
import com.sk89q.worldedit.function.mask.SolidBlockMask;
|
||||
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
import com.sk89q.worldedit.session.request.Request;
|
||||
import com.sk89q.worldedit.util.Location;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
import com.sk89q.worldedit.world.block.BlockType;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Serializable;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* Builds a shape at the place being looked at.
|
||||
*/
|
||||
public class BrushTool implements TraceTool {
|
||||
|
||||
import static com.boydti.fawe.object.brush.TargetMode.TARGET_FACE_RANGE;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
public class BrushTool implements DoubleActionTraceTool, ScrollTool, MovableTool, ResettableTool, Serializable {
|
||||
// TODO:
|
||||
// Serialize methods
|
||||
// serialize BrushSettings (primary and secondary only if different)
|
||||
// set transient values e.g. context
|
||||
|
||||
public enum BrushAction {
|
||||
PRIMARY,
|
||||
SECONDARY
|
||||
}
|
||||
|
||||
protected static int MAX_RANGE = 500;
|
||||
protected int range = -1;
|
||||
private Mask mask = null;
|
||||
private Brush brush = new SphereBrush();
|
||||
@Nullable
|
||||
private Pattern material;
|
||||
private double size = 1;
|
||||
private String permission;
|
||||
protected int range = 240;
|
||||
private VisualMode visualMode = VisualMode.NONE;
|
||||
private TargetMode targetMode = TargetMode.TARGET_BLOCK_RANGE;
|
||||
private Mask targetMask = null;
|
||||
private int targetOffset;
|
||||
|
||||
private transient BrushSettings primary = new BrushSettings();
|
||||
private transient BrushSettings secondary = new BrushSettings();
|
||||
private transient BrushSettings context = primary;
|
||||
|
||||
private transient VisualExtent visualExtent;
|
||||
private transient Lock lock = new ReentrantLock();
|
||||
|
||||
private transient BaseItem holder;
|
||||
|
||||
/**
|
||||
* Construct the tool.
|
||||
*
|
||||
* @param permission the permission to check before use is allowed
|
||||
*/
|
||||
public BrushTool(String permission) {
|
||||
checkNotNull(permission);
|
||||
this.permission = permission;
|
||||
getContext().addPermission(permission);
|
||||
}
|
||||
|
||||
public BrushTool() {
|
||||
}
|
||||
|
||||
public static BrushTool fromString(Player player, LocalSession session, String json) throws CommandException, InputParseException {
|
||||
Gson gson = new Gson();
|
||||
Type type = new TypeToken<Map<String, Object>>() {
|
||||
}.getType();
|
||||
Map<String, Object> root = gson.fromJson(json, type);
|
||||
if (root == null) {
|
||||
Fawe.debug("Failed to load " + json);
|
||||
return new BrushTool();
|
||||
}
|
||||
Map<String, Object> primary = (Map<String, Object>) root.get("primary");
|
||||
Map<String, Object> secondary = (Map<String, Object>) root.getOrDefault("secondary", primary);
|
||||
|
||||
VisualMode visual = VisualMode.valueOf((String) root.getOrDefault("visual", "NONE"));
|
||||
TargetMode target = TargetMode.valueOf((String) root.getOrDefault("target", "TARGET_BLOCK_RANGE"));
|
||||
int range = ((Number) root.getOrDefault("range", -1)).intValue();
|
||||
int offset = ((Number) root.getOrDefault("offset", 0)).intValue();
|
||||
|
||||
BrushTool tool = new BrushTool();
|
||||
tool.visualMode = visual;
|
||||
tool.targetMode = target;
|
||||
tool.range = range;
|
||||
tool.targetOffset = offset;
|
||||
|
||||
BrushSettings primarySettings = BrushSettings.get(tool, player, session, primary);
|
||||
tool.setPrimary(primarySettings);
|
||||
if (primary != secondary) {
|
||||
BrushSettings secondarySettings = BrushSettings.get(tool, player, session, secondary);
|
||||
tool.setSecondary(secondarySettings);
|
||||
}
|
||||
|
||||
return tool;
|
||||
}
|
||||
|
||||
public void setHolder(BaseItem holder) {
|
||||
this.holder = holder;
|
||||
}
|
||||
|
||||
public boolean isSet() {
|
||||
return primary.getBrush() != null || secondary.getBrush() != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return toString(new Gson());
|
||||
}
|
||||
|
||||
public String toString(Gson gson) {
|
||||
HashMap<String, Object> map = new HashMap<>();
|
||||
map.put("primary", primary.getSettings());
|
||||
if (primary != secondary) {
|
||||
map.put("secondary", secondary.getSettings());
|
||||
}
|
||||
if (visualMode != null && visualMode != VisualMode.NONE) {
|
||||
map.put("visual", visualMode);
|
||||
}
|
||||
if (targetMode != TargetMode.TARGET_BLOCK_RANGE) {
|
||||
map.put("target", targetMode);
|
||||
}
|
||||
if (range != -1 && range != 240) {
|
||||
map.put("range", range);
|
||||
}
|
||||
if (targetOffset != 0) {
|
||||
map.put("offset", targetOffset);
|
||||
}
|
||||
return gson.toJson(map);
|
||||
}
|
||||
|
||||
public void update() {
|
||||
if (holder != null) {
|
||||
BrushCache.setTool(holder, this);
|
||||
}
|
||||
}
|
||||
|
||||
private void writeObject(java.io.ObjectOutputStream stream) throws IOException {
|
||||
stream.defaultWriteObject();
|
||||
stream.writeBoolean(primary == secondary);
|
||||
stream.writeObject(primary);
|
||||
if (primary != secondary) {
|
||||
stream.writeObject(secondary);
|
||||
}
|
||||
}
|
||||
|
||||
private void readObject(java.io.ObjectInputStream stream) throws IOException, ClassNotFoundException {
|
||||
lock = new ReentrantLock();
|
||||
boolean multi = stream.readBoolean();
|
||||
primary = (BrushSettings) stream.readObject();
|
||||
if (multi) {
|
||||
secondary = (BrushSettings) stream.readObject();
|
||||
} else {
|
||||
secondary = primary;
|
||||
}
|
||||
context = primary;
|
||||
}
|
||||
|
||||
public BrushSettings getContext() {
|
||||
BrushSettings tmp = context;
|
||||
if (tmp == null) {
|
||||
context = tmp = primary;
|
||||
}
|
||||
return tmp;
|
||||
}
|
||||
|
||||
public void setContext(BrushSettings context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUse(Actor player) {
|
||||
return player.hasPermission(permission);
|
||||
if (primary == secondary) {
|
||||
return primary.canUse(player);
|
||||
}
|
||||
return primary.canUse(player) && secondary.canUse(player);
|
||||
}
|
||||
|
||||
public ResettableExtent getTransform() {
|
||||
return getContext().getTransform();
|
||||
}
|
||||
|
||||
public BrushSettings getPrimary() {
|
||||
return primary;
|
||||
}
|
||||
|
||||
public BrushSettings getSecondary() {
|
||||
return secondary;
|
||||
}
|
||||
|
||||
public BrushSettings getOffHand() {
|
||||
return context == primary ? secondary : primary;
|
||||
}
|
||||
|
||||
public void setPrimary(BrushSettings primary) {
|
||||
checkNotNull(primary);
|
||||
this.primary = primary;
|
||||
this.context = primary;
|
||||
update();
|
||||
}
|
||||
|
||||
public void setSecondary(BrushSettings secondary) {
|
||||
checkNotNull(secondary);
|
||||
this.secondary = secondary;
|
||||
this.context = secondary;
|
||||
update();
|
||||
}
|
||||
|
||||
public void setTransform(ResettableExtent transform) {
|
||||
getContext().setTransform(transform);
|
||||
update();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the filter.
|
||||
*
|
||||
*
|
||||
* @return the filter
|
||||
*/
|
||||
public Mask getMask() {
|
||||
return mask;
|
||||
return getContext().getMask();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the filter.
|
||||
*
|
||||
* @return the filter
|
||||
*/
|
||||
public Mask getSourceMask() {
|
||||
return getContext().getSourceMask();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean reset() {
|
||||
Brush br = getBrush();
|
||||
if (br instanceof ResettableTool) {
|
||||
return ((ResettableTool) br).reset();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the block filter used for identifying blocks to replace.
|
||||
*
|
||||
*
|
||||
* @param filter the filter to set
|
||||
*/
|
||||
public void setMask(Mask filter) {
|
||||
this.mask = filter;
|
||||
this.getContext().setMask(filter);
|
||||
update();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the block filter used for identifying blocks to replace.
|
||||
*
|
||||
* @param filter the filter to set
|
||||
*/
|
||||
public void setSourceMask(Mask filter) {
|
||||
this.getContext().setSourceMask(filter);
|
||||
update();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the brush.
|
||||
*
|
||||
* @param brush tbe brush
|
||||
*
|
||||
* @param brush tbe brush
|
||||
* @param permission the permission
|
||||
*/
|
||||
@Deprecated
|
||||
public void setBrush(Brush brush, String permission) {
|
||||
this.brush = brush;
|
||||
this.permission = permission;
|
||||
setBrush(brush, permission, null);
|
||||
update();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setBrush(Brush brush, String permission, Player player) {
|
||||
if (player != null) clear(player);
|
||||
BrushSettings current = getContext();
|
||||
current.clearPerms();
|
||||
current.setBrush(brush);
|
||||
current.addPermission(permission);
|
||||
update();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current brush.
|
||||
*
|
||||
*
|
||||
* @return the current brush
|
||||
*/
|
||||
public Brush getBrush() {
|
||||
return brush;
|
||||
return getContext().getBrush();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the material.
|
||||
*
|
||||
*
|
||||
* @param material the material
|
||||
*/
|
||||
public void setFill(@Nullable Pattern material) {
|
||||
this.material = material;
|
||||
this.getContext().setFill(material);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -120,31 +328,32 @@ public class BrushTool implements TraceTool {
|
||||
*
|
||||
* @return the material
|
||||
*/
|
||||
@Nullable public Pattern getMaterial() {
|
||||
return material;
|
||||
@Nullable
|
||||
public Pattern getMaterial() {
|
||||
return getContext().getMaterial();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the set brush size.
|
||||
*
|
||||
*
|
||||
* @return a radius
|
||||
*/
|
||||
public double getSize() {
|
||||
return size;
|
||||
return getContext().getSize();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the set brush size.
|
||||
*
|
||||
*
|
||||
* @param radius a radius
|
||||
*/
|
||||
public void setSize(double radius) {
|
||||
this.size = radius;
|
||||
this.getContext().setSize(radius);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the set brush range.
|
||||
*
|
||||
*
|
||||
* @return the range of the brush in blocks
|
||||
*/
|
||||
public int getRange() {
|
||||
@@ -153,27 +362,97 @@ public class BrushTool implements TraceTool {
|
||||
|
||||
/**
|
||||
* Set the set brush range.
|
||||
*
|
||||
*
|
||||
* @param range the range of the brush in blocks
|
||||
*/
|
||||
public void setRange(int range) {
|
||||
this.range = range;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean actPrimary(Platform server, LocalConfiguration config, Player player, LocalSession session) {
|
||||
Location target = null;
|
||||
target = player.getBlockTrace(getRange(), true);
|
||||
public Vector getPosition(EditSession editSession, Player player) {
|
||||
Location loc = player.getLocation();
|
||||
switch (targetMode) {
|
||||
case TARGET_BLOCK_RANGE:
|
||||
return offset(new MutableBlockVector(trace(editSession, player, getRange(), true)), loc.toVector());
|
||||
case FOWARD_POINT_PITCH: {
|
||||
int d = 0;
|
||||
float pitch = loc.getPitch();
|
||||
pitch = 23 - (pitch / 4);
|
||||
d += (int) (Math.sin(Math.toRadians(pitch)) * 50);
|
||||
final Vector vector = loc.getDirection().setY(0).normalize().multiply(d);
|
||||
vector.add(loc.getX(), loc.getY(), loc.getZ()).toBlockVector();
|
||||
return offset(new MutableBlockVector(vector), loc.toVector());
|
||||
}
|
||||
case TARGET_POINT_HEIGHT: {
|
||||
final int height = loc.getBlockY();
|
||||
final int x = loc.getBlockX();
|
||||
final int z = loc.getBlockZ();
|
||||
int y;
|
||||
for (y = height; y > 0; y--) {
|
||||
BlockType block = editSession.getBlockType(x, y, z);
|
||||
if (block.getMaterial().isMovementBlocker()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
final int distance = (height - y) + 8;
|
||||
return offset(new MutableBlockVector(trace(editSession, player, distance, true)), loc.toVector());
|
||||
}
|
||||
case TARGET_FACE_RANGE:
|
||||
return offset(new MutableBlockVector(trace(editSession, player, getRange(), true)), loc.toVector());
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
if (target == null) {
|
||||
player.printError("No block in sight!");
|
||||
return true;
|
||||
private Vector offset(Vector target, Vector playerPos) {
|
||||
if (targetOffset == 0) return target;
|
||||
return target.subtract(target.subtract(playerPos).normalize().multiply(targetOffset));
|
||||
}
|
||||
|
||||
private Vector trace(EditSession editSession, Player player, int range, boolean useLastBlock) {
|
||||
Mask mask = targetMask == null ? new SolidBlockMask(editSession) : targetMask;
|
||||
new MaskTraverser(mask).reset(editSession);
|
||||
MaskedTargetBlock tb = new MaskedTargetBlock(mask, player, range, 0.2);
|
||||
return TaskManager.IMP.sync(new RunnableVal<Vector>() {
|
||||
@Override
|
||||
public void run(Vector value) {
|
||||
Location result = tb.getMaskedTargetBlock(useLastBlock);
|
||||
this.value = result.toVector();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public boolean act(BrushAction action, Platform server, LocalConfiguration config, Player player, LocalSession session) {
|
||||
switch (action) {
|
||||
case PRIMARY:
|
||||
setContext(primary);
|
||||
break;
|
||||
case SECONDARY:
|
||||
setContext(secondary);
|
||||
break;
|
||||
}
|
||||
|
||||
BlockBag bag = session.getBlockBag(player);
|
||||
|
||||
BrushSettings current = getContext();
|
||||
Brush brush = current.getBrush();
|
||||
if (brush == null) return false;
|
||||
|
||||
EditSession editSession = session.createEditSession(player);
|
||||
if (current.setWorld(editSession.getWorld().getName()) && !current.canUse(player)) {
|
||||
BBC.NO_PERM.send(player, StringMan.join(current.getPermissions(), ","));
|
||||
return false;
|
||||
}
|
||||
|
||||
Vector target = getPosition(editSession, player);
|
||||
|
||||
if (target == null) {
|
||||
editSession.cancel();
|
||||
BBC.NO_BLOCK.send(player);
|
||||
return false;
|
||||
}
|
||||
BlockBag bag = session.getBlockBag(player);
|
||||
Request.request().setEditSession(editSession);
|
||||
Mask mask = current.getMask();
|
||||
if (mask != null) {
|
||||
Mask existingMask = editSession.getMask();
|
||||
|
||||
@@ -187,19 +466,180 @@ public class BrushTool implements TraceTool {
|
||||
editSession.setMask(newMask);
|
||||
}
|
||||
}
|
||||
|
||||
Mask sourceMask = current.getSourceMask();
|
||||
if (sourceMask != null) {
|
||||
editSession.addSourceMask(sourceMask);
|
||||
}
|
||||
ResettableExtent transform = current.getTransform();
|
||||
if (transform != null) {
|
||||
editSession.addTransform(transform);
|
||||
}
|
||||
try {
|
||||
brush.build(editSession, target.toVector(), material, size);
|
||||
} catch (MaxChangedBlocksException e) {
|
||||
player.printError("Max blocks change limit reached.");
|
||||
new PatternTraverser(current).reset(editSession);
|
||||
brush.build(editSession, target, current.getMaterial(), current.getSize());
|
||||
} catch (WorldEditException e) {
|
||||
player.printError("Max blocks change limit reached."); // Never happens
|
||||
} finally {
|
||||
if (bag != null) {
|
||||
bag.flushChanges();
|
||||
}
|
||||
session.remember(editSession);
|
||||
Request.reset();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean actPrimary(Platform server, LocalConfiguration config, Player player, LocalSession session) {
|
||||
return act(BrushAction.PRIMARY, server, config, player, session);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean actSecondary(Platform server, LocalConfiguration config, Player player, LocalSession session) {
|
||||
return act(BrushAction.SECONDARY, server, config, player, session);
|
||||
}
|
||||
|
||||
public static Class<?> inject() {
|
||||
return BrushTool.class;
|
||||
}
|
||||
|
||||
public void setScrollAction(ScrollAction scrollAction) {
|
||||
this.getContext().setScrollAction(scrollAction);
|
||||
update();
|
||||
}
|
||||
|
||||
public void setTargetOffset(int targetOffset) {
|
||||
this.targetOffset = targetOffset;
|
||||
update();
|
||||
}
|
||||
|
||||
public void setTargetMode(TargetMode targetMode) {
|
||||
this.targetMode = targetMode != null ? targetMode : TargetMode.TARGET_BLOCK_RANGE;
|
||||
update();
|
||||
}
|
||||
|
||||
public void setTargetMask(Mask mask) {
|
||||
this.targetMask = mask;
|
||||
update();
|
||||
}
|
||||
|
||||
public void setVisualMode(Player player, VisualMode visualMode) {
|
||||
if (visualMode == null) visualMode = VisualMode.NONE;
|
||||
if (this.visualMode != visualMode) {
|
||||
if (this.visualMode != VisualMode.NONE) {
|
||||
clear(player);
|
||||
}
|
||||
this.visualMode = visualMode != null ? visualMode : VisualMode.NONE;
|
||||
if (visualMode != VisualMode.NONE) {
|
||||
try {
|
||||
queueVisualization(FawePlayer.wrap(player));
|
||||
} catch (Throwable e) {
|
||||
WorldEdit.getInstance().getPlatformManager().handleThrowable(e, player);
|
||||
}
|
||||
}
|
||||
}
|
||||
update();
|
||||
}
|
||||
|
||||
public TargetMode getTargetMode() {
|
||||
return targetMode;
|
||||
}
|
||||
|
||||
public int getTargetOffset() {
|
||||
return targetOffset;
|
||||
}
|
||||
|
||||
public Mask getTargetMask() {
|
||||
return targetMask;
|
||||
}
|
||||
|
||||
public VisualMode getVisualMode() {
|
||||
return visualMode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean increment(Player player, int amount) {
|
||||
BrushSettings current = getContext();
|
||||
ScrollAction tmp = current.getScrollAction();
|
||||
if (tmp != null) {
|
||||
tmp.setTool(this);
|
||||
if (tmp.increment(player, amount)) {
|
||||
if (visualMode != VisualMode.NONE) {
|
||||
try {
|
||||
queueVisualization(FawePlayer.wrap(player));
|
||||
} catch (Throwable e) {
|
||||
WorldEdit.getInstance().getPlatformManager().handleThrowable(e, player);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (visualMode != VisualMode.NONE) {
|
||||
clear(player);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void queueVisualization(FawePlayer player) {
|
||||
Fawe.get().getVisualQueue().queue(player);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public synchronized void visualize(BrushTool.BrushAction action, Player player) throws WorldEditException {
|
||||
VisualMode mode = getVisualMode();
|
||||
if (mode == VisualMode.NONE) {
|
||||
return;
|
||||
}
|
||||
BrushSettings current = getContext();
|
||||
Brush brush = current.getBrush();
|
||||
if (brush == null) return;
|
||||
FawePlayer<Object> fp = FawePlayer.wrap(player);
|
||||
EditSession editSession = new EditSessionBuilder(player.getWorld())
|
||||
.player(fp)
|
||||
.allowedRegionsEverywhere()
|
||||
.autoQueue(false)
|
||||
.blockBag(null)
|
||||
.changeSetNull()
|
||||
.combineStages(false)
|
||||
.build();
|
||||
VisualExtent newVisualExtent = new VisualExtent(editSession.getExtent(), editSession.getQueue());
|
||||
Vector position = getPosition(editSession, player);
|
||||
if (position != null) {
|
||||
editSession.setExtent(newVisualExtent);
|
||||
switch (mode) {
|
||||
case POINT: {
|
||||
editSession.setBlock(position, VisualChunk.VISUALIZE_BLOCK);
|
||||
break;
|
||||
}
|
||||
case OUTLINE: {
|
||||
new PatternTraverser(current).reset(editSession);
|
||||
brush.build(editSession, position, current.getMaterial(), current.getSize());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (visualExtent != null) {
|
||||
// clear old data
|
||||
visualExtent.clear(newVisualExtent, fp);
|
||||
}
|
||||
visualExtent = newVisualExtent;
|
||||
newVisualExtent.visualize(fp);
|
||||
}
|
||||
|
||||
public void clear(Player player) {
|
||||
FawePlayer<Object> fp = FawePlayer.wrap(player);
|
||||
Fawe.get().getVisualQueue().dequeue(fp);
|
||||
if (visualExtent != null) {
|
||||
visualExtent.clear(null, fp);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean move(Player player) {
|
||||
if (visualMode != VisualMode.NONE) {
|
||||
queueVisualization(FawePlayer.wrap(player));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@@ -19,8 +19,7 @@
|
||||
|
||||
package com.sk89q.worldedit.command.tool;
|
||||
|
||||
import com.sk89q.worldedit.LocalConfiguration;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
import com.sk89q.worldedit.*;
|
||||
import com.sk89q.worldedit.entity.Player;
|
||||
import com.sk89q.worldedit.extension.platform.Actor;
|
||||
import com.sk89q.worldedit.extension.platform.Platform;
|
||||
|
@@ -24,16 +24,16 @@ import com.sk89q.worldedit.LocalConfiguration;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
import com.sk89q.worldedit.MaxChangedBlocksException;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.world.block.BlockCategories;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
import com.sk89q.worldedit.world.block.BlockType;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
import com.sk89q.worldedit.entity.Player;
|
||||
import com.sk89q.worldedit.extension.platform.Actor;
|
||||
import com.sk89q.worldedit.extension.platform.Platform;
|
||||
import com.sk89q.worldedit.util.Direction;
|
||||
import com.sk89q.worldedit.util.Location;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
import com.sk89q.worldedit.world.block.BlockCategories;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.BlockType;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
@@ -44,6 +44,7 @@ import java.util.Set;
|
||||
* to anything else)
|
||||
*/
|
||||
public class FloatingTreeRemover implements BlockTool {
|
||||
private static final BlockStateHolder AIR = BlockTypes.AIR.getDefaultState();
|
||||
private int rangeSq;
|
||||
|
||||
public FloatingTreeRemover() {
|
||||
@@ -69,7 +70,7 @@ public class FloatingTreeRemover implements BlockTool {
|
||||
Player player, LocalSession session, Location clicked) {
|
||||
|
||||
final World world = (World) clicked.getExtent();
|
||||
final BlockState state = world.getBlock(clicked.toVector());
|
||||
final BlockStateHolder state = world.getBlock(clicked.toVector());
|
||||
|
||||
if (!isTreeBlock(state.getBlockType())) {
|
||||
player.printError("That's not a tree.");
|
||||
@@ -86,9 +87,9 @@ public class FloatingTreeRemover implements BlockTool {
|
||||
}
|
||||
|
||||
for (Vector blockVector : blockSet) {
|
||||
final BlockState otherState = editSession.getBlock(blockVector);
|
||||
final BlockStateHolder otherState = editSession.getBlock(blockVector);
|
||||
if (isTreeBlock(otherState.getBlockType())) {
|
||||
editSession.setBlock(blockVector, BlockTypes.AIR.getDefaultState());
|
||||
editSession.setBlock(blockVector, AIR);
|
||||
}
|
||||
}
|
||||
} catch (MaxChangedBlocksException e) {
|
||||
@@ -133,7 +134,7 @@ public class FloatingTreeRemover implements BlockTool {
|
||||
}
|
||||
|
||||
if (visited.add(next)) {
|
||||
BlockState state = world.getBlock(next);
|
||||
BlockStateHolder state = world.getBlock(next);
|
||||
if (state.getBlockType() == BlockTypes.AIR || state.getBlockType() == BlockTypes.SNOW) {
|
||||
continue;
|
||||
}
|
||||
|
@@ -19,12 +19,7 @@
|
||||
|
||||
package com.sk89q.worldedit.command.tool;
|
||||
|
||||
import com.sk89q.worldedit.BlockVector;
|
||||
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.*;
|
||||
import com.sk89q.worldedit.entity.Player;
|
||||
import com.sk89q.worldedit.extension.platform.Actor;
|
||||
import com.sk89q.worldedit.extension.platform.Platform;
|
||||
@@ -59,9 +54,9 @@ public class FloodFillTool implements BlockTool {
|
||||
public boolean actPrimary(Platform server, LocalConfiguration config, Player player, LocalSession session, Location clicked) {
|
||||
World world = (World) clicked.getExtent();
|
||||
|
||||
BlockType initialType = world.getBlock(clicked.toVector()).getBlockType();
|
||||
BlockType initialType = world.getLazyBlock(clicked.toVector()).getBlockType();
|
||||
|
||||
if (initialType == BlockTypes.AIR) {
|
||||
if (initialType.getMaterial().isAir()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -72,19 +67,18 @@ public class FloodFillTool implements BlockTool {
|
||||
EditSession editSession = session.createEditSession(player);
|
||||
|
||||
try {
|
||||
recurse(editSession, clicked.toVector().toBlockVector(),
|
||||
clicked.toVector(), range, initialType, new HashSet<>());
|
||||
} catch (MaxChangedBlocksException e) {
|
||||
player.printError("Max blocks change limit reached.");
|
||||
} finally {
|
||||
session.remember(editSession);
|
||||
recurse(server, editSession, world, clicked.toVector().toBlockVector(),
|
||||
clicked.toVector(), range, initialType, new HashSet<BlockVector>());
|
||||
} catch (WorldEditException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
editSession.flushQueue();
|
||||
session.remember(editSession);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void recurse(EditSession editSession, BlockVector pos, Vector origin, int size, BlockType initialType,
|
||||
Set<BlockVector> visited) throws MaxChangedBlocksException {
|
||||
private void recurse(Platform server, EditSession editSession, World world, BlockVector pos, Vector origin, int size, BlockType initialType,
|
||||
Set<BlockVector> visited) throws WorldEditException {
|
||||
|
||||
if (origin.distance(pos) > size || visited.contains(pos)) {
|
||||
return;
|
||||
@@ -98,18 +92,21 @@ public class FloodFillTool implements BlockTool {
|
||||
return;
|
||||
}
|
||||
|
||||
recurse(editSession, pos.add(1, 0, 0).toBlockVector(),
|
||||
recurse(server, editSession, world, pos.add(1, 0, 0).toBlockVector(),
|
||||
origin, size, initialType, visited);
|
||||
recurse(editSession, pos.add(-1, 0, 0).toBlockVector(),
|
||||
recurse(server, editSession, world, pos.add(-1, 0, 0).toBlockVector(),
|
||||
origin, size, initialType, visited);
|
||||
recurse(editSession, pos.add(0, 0, 1).toBlockVector(),
|
||||
recurse(server, editSession, world, pos.add(0, 0, 1).toBlockVector(),
|
||||
origin, size, initialType, visited);
|
||||
recurse(editSession, pos.add(0, 0, -1).toBlockVector(),
|
||||
recurse(server, editSession, world, pos.add(0, 0, -1).toBlockVector(),
|
||||
origin, size, initialType, visited);
|
||||
recurse(editSession, pos.add(0, 1, 0).toBlockVector(),
|
||||
recurse(server, editSession, world, pos.add(0, 1, 0).toBlockVector(),
|
||||
origin, size, initialType, visited);
|
||||
recurse(editSession, pos.add(0, -1, 0).toBlockVector(),
|
||||
recurse(server, editSession, world, pos.add(0, -1, 0).toBlockVector(),
|
||||
origin, size, initialType, visited);
|
||||
}
|
||||
|
||||
}
|
||||
public static Class<?> inject() {
|
||||
return FloodFillTool.class;
|
||||
}
|
||||
}
|
@@ -19,26 +19,27 @@
|
||||
|
||||
package com.sk89q.worldedit.command.tool;
|
||||
|
||||
import com.boydti.fawe.config.BBC;
|
||||
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.function.pattern.Pattern;
|
||||
import com.sk89q.worldedit.util.Location;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
|
||||
/**
|
||||
* A tool that can place (or remove) blocks at a distance.
|
||||
*/
|
||||
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 primary, Pattern secondary) {
|
||||
super("worldedit.tool.lrbuild");
|
||||
this.primary = primary;
|
||||
this.secondary = secondary;
|
||||
@@ -54,18 +55,12 @@ public class LongRangeBuildTool extends BrushTool implements DoubleActionTraceTo
|
||||
Location pos = getTargetFace(player);
|
||||
if (pos == null) return false;
|
||||
EditSession eS = session.createEditSession(player);
|
||||
try {
|
||||
if (secondary.getBlockType() == BlockTypes.AIR) {
|
||||
eS.setBlock(pos.toVector(), secondary);
|
||||
} else {
|
||||
eS.setBlock(pos.getDirection(), secondary);
|
||||
}
|
||||
return true;
|
||||
} catch (MaxChangedBlocksException e) {
|
||||
// one block? eat it
|
||||
if (secondary instanceof BlockStateHolder && ((BlockStateHolder) secondary).getBlockType().getMaterial().isAir()) {
|
||||
eS.setBlock(pos.toVector(), secondary);
|
||||
} else {
|
||||
eS.setBlock(pos.getDirection(), secondary);
|
||||
}
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -73,28 +68,23 @@ public class LongRangeBuildTool extends BrushTool implements DoubleActionTraceTo
|
||||
Location pos = getTargetFace(player);
|
||||
if (pos == null) return false;
|
||||
EditSession eS = session.createEditSession(player);
|
||||
try {
|
||||
if (primary.getBlockType() == BlockTypes.AIR) {
|
||||
eS.setBlock(pos.toVector(), primary);
|
||||
} else {
|
||||
eS.setBlock(pos.getDirection(), primary);
|
||||
}
|
||||
return true;
|
||||
} catch (MaxChangedBlocksException e) {
|
||||
// one block? eat it
|
||||
if (primary instanceof BlockStateHolder && ((BlockStateHolder) primary).getBlockType().getMaterial().isAir()) {
|
||||
eS.setBlock(pos.toVector(), primary);
|
||||
} else {
|
||||
eS.setBlock(pos.getDirection(), primary);
|
||||
}
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public Location getTargetFace(Player player) {
|
||||
Location target = player.getBlockTraceFace(getRange(), true);
|
||||
|
||||
if (target == null) {
|
||||
player.printError("No block in sight!");
|
||||
BBC.NO_BLOCK.send(player);
|
||||
return null;
|
||||
}
|
||||
|
||||
return target;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -23,11 +23,11 @@ import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.LocalConfiguration;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
import com.sk89q.worldedit.blocks.MobSpawnerBlock;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
import com.sk89q.worldedit.entity.Player;
|
||||
import com.sk89q.worldedit.extension.platform.Actor;
|
||||
import com.sk89q.worldedit.extension.platform.Platform;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
|
||||
/**
|
||||
* Looks up information about a block.
|
||||
|
@@ -1,46 +1,26 @@
|
||||
/*
|
||||
* WorldEdit, a Minecraft world manipulation toolkit
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.command.tool;
|
||||
|
||||
import com.sk89q.worldedit.BlockVector;
|
||||
import com.boydti.fawe.object.mask.IdMask;
|
||||
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.function.block.BlockReplace;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
import com.sk89q.worldedit.function.operation.Operations;
|
||||
import com.sk89q.worldedit.function.visitor.RecursiveVisitor;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
import com.sk89q.worldedit.world.block.BlockType;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* A pickaxe mode that recursively finds adjacent blocks within range of
|
||||
* an initial block and of the same type.
|
||||
*/
|
||||
public class RecursivePickaxe implements BlockTool {
|
||||
|
||||
private double range;
|
||||
|
||||
public RecursivePickaxe(double range) {
|
||||
@@ -55,63 +35,35 @@ public class RecursivePickaxe implements BlockTool {
|
||||
@Override
|
||||
public boolean actPrimary(Platform server, LocalConfiguration config, Player player, LocalSession session, com.sk89q.worldedit.util.Location clicked) {
|
||||
World world = (World) clicked.getExtent();
|
||||
|
||||
BlockType initialType = world.getBlock(clicked.toVector()).getBlockType();
|
||||
|
||||
if (initialType == BlockTypes.AIR) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (initialType == BlockTypes.BEDROCK && !player.canDestroyBedrock()) {
|
||||
return true;
|
||||
}
|
||||
final Vector pos = clicked.toVector();
|
||||
|
||||
EditSession editSession = session.createEditSession(player);
|
||||
|
||||
BlockStateHolder block = editSession.getBlock(pos);
|
||||
if (block.getBlockType().getMaterial().isAir()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (block.getBlockType() == BlockTypes.BEDROCK && !player.canDestroyBedrock()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
editSession.getSurvivalExtent().setToolUse(config.superPickaxeManyDrop);
|
||||
|
||||
try {
|
||||
recurse(server, editSession, world, clicked.toVector().toBlockVector(),
|
||||
clicked.toVector(), range, initialType, new HashSet<>());
|
||||
} catch (MaxChangedBlocksException e) {
|
||||
player.printError("Max blocks change limit reached.");
|
||||
} finally {
|
||||
editSession.flushQueue();
|
||||
session.remember(editSession);
|
||||
}
|
||||
final int radius = (int) range;
|
||||
final BlockReplace replace = new BlockReplace(editSession, (editSession.nullBlock));
|
||||
editSession.setMask((Mask) null);
|
||||
RecursiveVisitor visitor = new RecursiveVisitor(new IdMask(editSession), replace, radius, editSession);
|
||||
visitor.visit(pos);
|
||||
Operations.completeBlindly(visitor);
|
||||
|
||||
editSession.flushQueue();
|
||||
session.remember(editSession);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static void recurse(Platform server, EditSession editSession, World world, BlockVector pos,
|
||||
Vector origin, double size, BlockType initialType, Set<BlockVector> 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).toBlockVector(),
|
||||
origin, size, initialType, visited);
|
||||
recurse(server, editSession, world, pos.add(-1, 0, 0).toBlockVector(),
|
||||
origin, size, initialType, visited);
|
||||
recurse(server, editSession, world, pos.add(0, 0, 1).toBlockVector(),
|
||||
origin, size, initialType, visited);
|
||||
recurse(server, editSession, world, pos.add(0, 0, -1).toBlockVector(),
|
||||
origin, size, initialType, visited);
|
||||
recurse(server, editSession, world, pos.add(0, 1, 0).toBlockVector(),
|
||||
origin, size, initialType, visited);
|
||||
recurse(server, editSession, world, pos.add(0, -1, 0).toBlockVector(),
|
||||
origin, size, initialType, visited);
|
||||
public static Class<?> inject() {
|
||||
return RecursivePickaxe.class;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -22,7 +22,6 @@ package com.sk89q.worldedit.command.tool;
|
||||
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;
|
||||
@@ -43,9 +42,8 @@ public class SinglePickaxe implements BlockTool {
|
||||
@Override
|
||||
public boolean actPrimary(Platform server, LocalConfiguration config, Player player, LocalSession session, com.sk89q.worldedit.util.Location clicked) {
|
||||
World world = (World) clicked.getExtent();
|
||||
final BlockType blockType = world.getBlock(clicked.toVector()).getBlockType();
|
||||
if (blockType == BlockTypes.BEDROCK
|
||||
&& !player.canDestroyBedrock()) {
|
||||
final BlockType blockType = world.getLazyBlock(clicked.toVector()).getBlockType();
|
||||
if (blockType == BlockTypes.BEDROCK && !player.canDestroyBedrock()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -53,16 +51,19 @@ public class SinglePickaxe implements BlockTool {
|
||||
editSession.getSurvivalExtent().setToolUse(config.superPickaxeDrop);
|
||||
|
||||
try {
|
||||
editSession.setBlock(clicked.toVector(), BlockTypes.AIR.getDefaultState());
|
||||
} catch (MaxChangedBlocksException e) {
|
||||
player.printError("Max blocks change limit reached.");
|
||||
if (editSession.setBlock(clicked.getBlockX(), clicked.getBlockY(), clicked.getBlockZ(), EditSession.nullBlock)) {
|
||||
// TODO FIXME play effect
|
||||
// world.playEffect(clicked.toVector(), 2001, blockType);
|
||||
}
|
||||
} finally {
|
||||
editSession.flushQueue();
|
||||
session.remember(editSession);
|
||||
}
|
||||
|
||||
world.playEffect(clicked.toVector(), 2001, blockType.getLegacyId());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static Class<?> inject() {
|
||||
return SinglePickaxe.class;
|
||||
}
|
||||
}
|
||||
|
@@ -19,15 +19,11 @@
|
||||
|
||||
package com.sk89q.worldedit.command.tool;
|
||||
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.LocalConfiguration;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
import com.sk89q.worldedit.MaxChangedBlocksException;
|
||||
import com.sk89q.worldedit.*;
|
||||
import com.sk89q.worldedit.entity.Player;
|
||||
import com.sk89q.worldedit.extension.platform.Actor;
|
||||
import com.sk89q.worldedit.extension.platform.Platform;
|
||||
import com.sk89q.worldedit.util.Location;
|
||||
import com.sk89q.worldedit.util.TreeGenerator;
|
||||
import com.sk89q.worldedit.util.*;
|
||||
|
||||
/**
|
||||
* Plants a tree.
|
||||
|
@@ -22,6 +22,7 @@ package com.sk89q.worldedit.command.tool.brush;
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.MaxChangedBlocksException;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
|
||||
/**
|
||||
@@ -38,6 +39,6 @@ public interface Brush {
|
||||
* @param size the size of the brush
|
||||
* @throws MaxChangedBlocksException
|
||||
*/
|
||||
public void build(EditSession editSession, Vector position, Pattern pattern, double size) throws MaxChangedBlocksException;
|
||||
public void build(EditSession editSession, Vector position, Pattern pattern, double size) throws WorldEditException;
|
||||
|
||||
}
|
||||
|
@@ -22,9 +22,9 @@ package com.sk89q.worldedit.command.tool.brush;
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.MaxChangedBlocksException;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
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.world.block.BlockTypes;
|
||||
|
||||
public class CylinderBrush implements Brush {
|
||||
|
||||
|
@@ -22,47 +22,51 @@ package com.sk89q.worldedit.command.tool.brush;
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.MaxChangedBlocksException;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
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.world.block.BlockStateHolder;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class GravityBrush implements Brush {
|
||||
|
||||
private final boolean fullHeight;
|
||||
|
||||
|
||||
public GravityBrush(boolean fullHeight) {
|
||||
this.fullHeight = fullHeight;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void build(EditSession editSession, Vector position, Pattern pattern, double size) throws MaxChangedBlocksException {
|
||||
final double startY = fullHeight ? editSession.getWorld().getMaxY() : position.getBlockY() + size;
|
||||
for (double x = position.getBlockX() + size; x > position.getBlockX() - size; --x) {
|
||||
for (double z = position.getBlockZ() + size; z > position.getBlockZ() - size; --z) {
|
||||
double y = startY;
|
||||
final List<BlockStateHolder> blockTypes = new ArrayList<>();
|
||||
for (; y > position.getBlockY() - size; --y) {
|
||||
final Vector pt = new Vector(x, y, z);
|
||||
final BlockStateHolder block = editSession.getBlock(pt);
|
||||
if (block.getBlockType() != BlockTypes.AIR) {
|
||||
blockTypes.add(block);
|
||||
editSession.setBlock(pt, BlockTypes.AIR.getDefaultState());
|
||||
public void build(EditSession editSession, Vector position, Pattern pattern, double sizeDouble) throws MaxChangedBlocksException {
|
||||
Mask mask = editSession.getMask();
|
||||
if (mask == Masks.alwaysTrue() || mask == Masks.alwaysTrue2D()) {
|
||||
mask = null;
|
||||
}
|
||||
int size = (int) sizeDouble;
|
||||
int endY = position.getBlockY() + size;
|
||||
int startPerformY = Math.max(0, position.getBlockY() - size);
|
||||
int startCheckY = fullHeight ? 0 : startPerformY;
|
||||
Vector mutablePos = new Vector(0, 0, 0);
|
||||
for (int x = position.getBlockX() + size; x > position.getBlockX() - size; --x) {
|
||||
for (int z = position.getBlockZ() + size; z > position.getBlockZ() - size; --z) {
|
||||
int freeSpot = startCheckY;
|
||||
for (int y = startCheckY; y <= endY; y++) {
|
||||
BlockStateHolder block = editSession.getLazyBlock(x, y, z);
|
||||
if (!block.getBlockType().getMaterial().isAir()) {
|
||||
if (y != freeSpot) {
|
||||
editSession.setBlock(x, y, z, EditSession.nullBlock);
|
||||
editSession.setBlock(x, freeSpot, z, block);
|
||||
}
|
||||
freeSpot = y + 1;
|
||||
}
|
||||
}
|
||||
Vector pt = new Vector(x, y, z);
|
||||
Collections.reverse(blockTypes);
|
||||
for (int i = 0; i < blockTypes.size();) {
|
||||
if (editSession.getBlock(pt).getBlockType() == BlockTypes.AIR) {
|
||||
editSession.setBlock(pt, blockTypes.get(i++));
|
||||
}
|
||||
pt = pt.add(0, 1, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Class<?> inject() {
|
||||
return GravityBrush.class;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -22,9 +22,11 @@ package com.sk89q.worldedit.command.tool.brush;
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.MaxChangedBlocksException;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
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.world.block.BlockTypes;
|
||||
|
||||
public class HollowCylinderBrush implements Brush {
|
||||
|
||||
@@ -37,7 +39,7 @@ public class HollowCylinderBrush implements Brush {
|
||||
@Override
|
||||
public void build(EditSession editSession, Vector position, Pattern pattern, double size) throws MaxChangedBlocksException {
|
||||
if (pattern == null) {
|
||||
pattern = new BlockPattern(BlockTypes.COBBLESTONE.getDefaultState());
|
||||
pattern = new BlockPattern(new BaseBlock(BlockTypes.COBBLESTONE));
|
||||
}
|
||||
editSession.makeCylinder(position, pattern, size, size, height, false);
|
||||
}
|
||||
|
@@ -22,16 +22,18 @@ package com.sk89q.worldedit.command.tool.brush;
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.MaxChangedBlocksException;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
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.world.block.BlockTypes;
|
||||
|
||||
public class HollowSphereBrush implements Brush {
|
||||
|
||||
@Override
|
||||
public void build(EditSession editSession, Vector position, Pattern pattern, double size) throws MaxChangedBlocksException {
|
||||
if (pattern == null) {
|
||||
pattern = new BlockPattern(BlockTypes.COBBLESTONE.getDefaultState());
|
||||
pattern = new BlockPattern(new BaseBlock(BlockTypes.COBBLESTONE));
|
||||
}
|
||||
editSession.makeSphere(position, pattern, size, size, size, false);
|
||||
}
|
||||
|
@@ -20,11 +20,11 @@
|
||||
package com.sk89q.worldedit.command.tool.brush;
|
||||
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
import com.sk89q.worldedit.math.convolution.HeightMap;
|
||||
import com.sk89q.worldedit.MaxChangedBlocksException;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
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;
|
||||
import com.sk89q.worldedit.regions.CuboidRegion;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
|
@@ -22,16 +22,18 @@ package com.sk89q.worldedit.command.tool.brush;
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.MaxChangedBlocksException;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
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.world.block.BlockTypes;
|
||||
|
||||
public class SphereBrush implements Brush {
|
||||
|
||||
@Override
|
||||
public void build(EditSession editSession, Vector position, Pattern pattern, double size) throws MaxChangedBlocksException {
|
||||
if (pattern == null) {
|
||||
pattern = new BlockPattern(BlockTypes.COBBLESTONE.getDefaultState());
|
||||
pattern = new BlockPattern(new BaseBlock(BlockTypes.COBBLESTONE));
|
||||
}
|
||||
editSession.makeSphere(position, pattern, size, size, size, true);
|
||||
}
|
||||
|
Reference in New Issue
Block a user