mirror of
https://github.com/boy0001/FastAsyncWorldedit.git
synced 2025-02-17 21:11:26 +01:00
Close #529
This commit is contained in:
parent
2483b9fb5e
commit
2f8543b25e
@ -114,6 +114,7 @@ public enum BBC {
|
||||
BRUSH_SCROLL_ACTION_UNSET("Removed scrol action", "WorldEdit.Brush"),
|
||||
BRUSH_VISUAL_MODE_SET("Set visual mode to %s0", "WorldEdit.Brush"),
|
||||
BRUSH_TARGET_MODE_SET("Set target mode to %s0", "WorldEdit.Brush"),
|
||||
BRUSH_TARGET_MASK_SET("Set target mask to %s0", "WorldEdit.Brush"),
|
||||
BRUSH_EQUIPPED("Equipped brush %s0", "WorldEdit.Brush"),
|
||||
BRUSH_TRY_OTHER("&cThere are other more suitable brushes e.g.\n&8 - &7//br height [radius=5] [#clipboard|file=null] [rotation=0] [yscale=1.00]", "WorldEdit.Brush"),
|
||||
BRUSH_COPY("Left click the base of an object to copy, right click to paste. Increase the brush radius if necessary.", "WorldEdit.Brush"),
|
||||
|
@ -0,0 +1,38 @@
|
||||
package com.boydti.fawe.object.mask;
|
||||
|
||||
import com.sk89q.worldedit.BlockWorldVector;
|
||||
import com.sk89q.worldedit.blocks.BlockID;
|
||||
import com.sk89q.worldedit.entity.Player;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
import com.sk89q.worldedit.util.TargetBlock;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
|
||||
public class MaskedTargetBlock extends TargetBlock {
|
||||
private final Mask mask;
|
||||
private final World world;
|
||||
|
||||
public MaskedTargetBlock(Mask mask, Player player, int maxDistance, double checkDistance) {
|
||||
super(player, maxDistance, checkDistance);
|
||||
this.mask = mask;
|
||||
this.world = player.getWorld();
|
||||
}
|
||||
|
||||
public BlockWorldVector getMaskedTargetBlock(boolean useLastBlock) {
|
||||
boolean searchForLastBlock = true;
|
||||
BlockWorldVector lastBlock = null;
|
||||
while (getNextBlock() != null) {
|
||||
if (mask == null ? world.getBlockType(getCurrentBlock()) == BlockID.AIR : !mask.test(getCurrentBlock())) {
|
||||
if (searchForLastBlock) {
|
||||
lastBlock = getCurrentBlock();
|
||||
if (lastBlock.getBlockY() <= 0 || lastBlock.getBlockY() >= world.getMaxY()) {
|
||||
searchForLastBlock = false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
BlockWorldVector currentBlock = getCurrentBlock();
|
||||
return (currentBlock != null || !useLastBlock ? currentBlock : lastBlock);
|
||||
}
|
||||
}
|
@ -309,6 +309,28 @@ public class BrushOptionsCommands extends MethodCommands {
|
||||
BBC.BRUSH_TARGET_MODE_SET.send(player, newMode);
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = { "targetmask", "tarmask", "tm" },
|
||||
usage = "[mask]",
|
||||
desc = "Set the targeting mask",
|
||||
min = 1,
|
||||
max = -1
|
||||
)
|
||||
public void targetMask(Player player, EditSession editSession, LocalSession session, CommandContext context) throws WorldEditException {
|
||||
BrushTool tool = session.getBrushTool(player, false);
|
||||
if (tool == null) {
|
||||
BBC.BRUSH_NONE.send(player);
|
||||
return;
|
||||
}
|
||||
ParserContext parserContext = new ParserContext();
|
||||
parserContext.setActor(player);
|
||||
parserContext.setWorld(player.getWorld());
|
||||
parserContext.setSession(session);
|
||||
parserContext.setExtent(editSession);
|
||||
Mask mask = worldEdit.getMaskFactory().parseFromInput(context.getJoinedStrings(0), parserContext);
|
||||
tool.setTargetMask(mask);
|
||||
BBC.BRUSH_TARGET_MASK_SET.send(player, context.getJoinedStrings(0));
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = { "scroll" },
|
||||
|
@ -5,6 +5,7 @@ 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.RunnableVal2;
|
||||
import com.boydti.fawe.object.brush.BrushSettings;
|
||||
import com.boydti.fawe.object.brush.MovableTool;
|
||||
import com.boydti.fawe.object.brush.ResettableTool;
|
||||
@ -15,9 +16,13 @@ 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.EditSessionBuilder;
|
||||
import com.boydti.fawe.util.MainUtil;
|
||||
import com.boydti.fawe.util.MaskTraverser;
|
||||
import com.boydti.fawe.util.TaskManager;
|
||||
import com.google.common.io.Files;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.sk89q.minecraft.util.commands.CommandException;
|
||||
@ -41,12 +46,16 @@ import com.sk89q.worldedit.function.mask.MaskIntersection;
|
||||
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
import com.sk89q.worldedit.session.request.Request;
|
||||
import com.sk89q.worldedit.util.Location;
|
||||
import com.sk89q.worldedit.util.TargetBlock;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.Serializable;
|
||||
import java.lang.reflect.Type;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.attribute.BasicFileAttributes;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
import javax.annotation.Nullable;
|
||||
@ -69,6 +78,7 @@ public class BrushTool implements DoubleActionTraceTool, ScrollTool, MovableTool
|
||||
protected int range = -1;
|
||||
private VisualMode visualMode = VisualMode.NONE;
|
||||
private TargetMode targetMode = TargetMode.TARGET_BLOCK_RANGE;
|
||||
private Mask targetMask = null;
|
||||
|
||||
private transient BrushSettings context = new BrushSettings();
|
||||
private transient BrushSettings primary = context;
|
||||
@ -335,7 +345,7 @@ public class BrushTool implements DoubleActionTraceTool, ScrollTool, MovableTool
|
||||
public Vector getPosition(EditSession editSession, Player player) {
|
||||
switch (targetMode) {
|
||||
case TARGET_BLOCK_RANGE:
|
||||
return new MutableBlockVector(trace(player, getRange(), true));
|
||||
return new MutableBlockVector(trace(editSession, player, getRange(), true));
|
||||
case FOWARD_POINT_PITCH: {
|
||||
int d = 0;
|
||||
Location loc = player.getLocation();
|
||||
@ -359,24 +369,51 @@ public class BrushTool implements DoubleActionTraceTool, ScrollTool, MovableTool
|
||||
}
|
||||
}
|
||||
final int distance = (height - y) + 8;
|
||||
return new MutableBlockVector(trace(player, distance, true));
|
||||
return new MutableBlockVector(trace(editSession, player, distance, true));
|
||||
}
|
||||
case TARGET_FACE_RANGE:
|
||||
return new MutableBlockVector(trace(player, getRange(), true));
|
||||
return new MutableBlockVector(trace(editSession, player, getRange(), true));
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private Vector trace(Player player, int range, boolean useLastBlock) {
|
||||
TargetBlock tb = new TargetBlock(player, range, 0.2);
|
||||
public static void main(String[] args) throws IOException {
|
||||
File folder = new File("C:\\Users\\Jesse\\Desktop\\OTHER\\Music".replace("\\", "/"));
|
||||
File bad = new File(folder, "Bad");
|
||||
File all = new File(folder, "All");
|
||||
File good = new File(folder, "Good");
|
||||
final Set<String> s = new HashSet<>();
|
||||
MainUtil.traverse(all.toPath(), new RunnableVal2<Path, BasicFileAttributes>() {
|
||||
@Override
|
||||
public void run(Path value1, BasicFileAttributes value2) {
|
||||
s.add(value1.getFileName().toString());
|
||||
}
|
||||
});
|
||||
MainUtil.traverse(good.toPath(), new RunnableVal2<Path, BasicFileAttributes>() {
|
||||
@Override
|
||||
public void run(Path value1, BasicFileAttributes value2) {
|
||||
s.remove(value1.getFileName().toString());
|
||||
}
|
||||
});
|
||||
int i = 0;
|
||||
for (String name : s) {
|
||||
Files.copy(new File(all, name), new File(bad, name));
|
||||
System.out.println(name + " | " + ((i * 100) / s.size()));
|
||||
i++;
|
||||
}
|
||||
System.out.println(s.size());
|
||||
}
|
||||
|
||||
private Vector trace(EditSession editSession, Player player, int range, boolean useLastBlock) {
|
||||
if (targetMask != null) {
|
||||
new MaskTraverser(targetMask).reset(editSession);
|
||||
}
|
||||
MaskedTargetBlock tb = new MaskedTargetBlock(targetMask, player, range, 0.2);
|
||||
return TaskManager.IMP.sync(new RunnableVal<Vector>() {
|
||||
@Override
|
||||
public void run(Vector value) {
|
||||
BlockWorldVector result = tb.getSolidTargetBlock();
|
||||
if (result == null && useLastBlock) {
|
||||
result = tb.getPreviousBlock();
|
||||
}
|
||||
BlockWorldVector result = tb.getMaskedTargetBlock(useLastBlock);
|
||||
this.value = result;
|
||||
}
|
||||
});
|
||||
@ -465,6 +502,10 @@ public class BrushTool implements DoubleActionTraceTool, ScrollTool, MovableTool
|
||||
this.targetMode = targetMode != null ? targetMode : TargetMode.TARGET_BLOCK_RANGE;
|
||||
}
|
||||
|
||||
public void setTargetMask(Mask mask) {
|
||||
this.targetMask = mask;
|
||||
}
|
||||
|
||||
public void setVisualMode(VisualMode visualMode) {
|
||||
this.visualMode = visualMode != null ? visualMode : VisualMode.NONE;
|
||||
}
|
||||
@ -473,6 +514,10 @@ public class BrushTool implements DoubleActionTraceTool, ScrollTool, MovableTool
|
||||
return targetMode;
|
||||
}
|
||||
|
||||
public Mask getTargetMask() {
|
||||
return targetMask;
|
||||
}
|
||||
|
||||
public VisualMode getVisualMode() {
|
||||
return visualMode;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user