mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-06-11 20:13:55 +00:00
This commit is contained in:
@ -153,4 +153,9 @@ public class FuzzyRegionSelector extends AbstractDelegateExtent implements Regio
|
||||
}
|
||||
return lines;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BlockVector3> getVerticies() {
|
||||
return positions;
|
||||
}
|
||||
}
|
||||
|
@ -229,4 +229,8 @@ public class PolyhedralRegionSelector implements RegionSelector, CUIRegion {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BlockVector3> getVerticies() {
|
||||
return new ArrayList<>(region.getVertices());
|
||||
}
|
||||
}
|
||||
|
@ -205,7 +205,6 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
|
||||
}
|
||||
|
||||
@SuppressWarnings("ProtectedField")
|
||||
protected final World world;
|
||||
private String worldName;
|
||||
private FaweQueue queue;
|
||||
private boolean wrapped;
|
||||
|
@ -31,6 +31,7 @@ import com.sk89q.worldedit.IncompleteRegionException;
|
||||
import com.sk89q.worldedit.NotABlockException;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.blocks.BaseItem;
|
||||
import com.sk89q.worldedit.blocks.MobSpawnerBlock;
|
||||
import com.sk89q.worldedit.blocks.SignBlock;
|
||||
import com.sk89q.worldedit.blocks.SkullBlock;
|
||||
@ -42,6 +43,8 @@ import com.sk89q.worldedit.extension.input.NoMatchException;
|
||||
import com.sk89q.worldedit.extension.input.ParserContext;
|
||||
import com.sk89q.worldedit.extension.platform.Actor;
|
||||
import com.sk89q.worldedit.extension.platform.Capability;
|
||||
import com.sk89q.worldedit.extent.inventory.BlockBag;
|
||||
import com.sk89q.worldedit.extent.inventory.SlottableBlockBag;
|
||||
import com.sk89q.worldedit.internal.registry.InputParser;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.registry.state.Property;
|
||||
@ -107,8 +110,6 @@ public class DefaultBlockParser extends InputParser<BaseBlock> {
|
||||
}
|
||||
}
|
||||
|
||||
private static String[] EMPTY_STRING_ARRAY = new String[]{};
|
||||
|
||||
/**
|
||||
* Backwards compatibility for wool colours in block syntax.
|
||||
*
|
||||
@ -214,18 +215,37 @@ public class DefaultBlockParser extends InputParser<BaseBlock> {
|
||||
final World world = context.requireWorld();
|
||||
final BlockVector3 primaryPosition;
|
||||
try {
|
||||
primaryPosition = context.requireSession().getRegionSelector(world).getPrimaryPosition();
|
||||
primaryPosition = context.requireSession().getRegionSelector(world).getVerticies().get(index - 1);
|
||||
} catch (IncompleteRegionException e) {
|
||||
throw new InputParseException("Your selection is not complete.");
|
||||
}
|
||||
state = world.getBlock(primaryPosition);
|
||||
} else {
|
||||
if ("hand".equalsIgnoreCase(typeString)) {
|
||||
// Get the block type from the item in the user's hand.
|
||||
state = getBlockInHand(context.requireActor(), HandSide.MAIN_HAND);
|
||||
} else if ("offhand".equalsIgnoreCase(typeString)) {
|
||||
// Get the block type from the item in the user's off hand.
|
||||
state = getBlockInHand(context.requireActor(), HandSide.OFF_HAND);
|
||||
// Get the block type from the item in the user's hand.
|
||||
state = getBlockInHand(context.requireActor(), HandSide.MAIN_HAND);
|
||||
} else if ("offhand".equalsIgnoreCase(typeString)) {
|
||||
// Get the block type from the item in the user's off hand.
|
||||
state = getBlockInHand(context.requireActor(), HandSide.OFF_HAND);
|
||||
} else if (typeString.matches("slot[0-9]+")) {
|
||||
int slot = Integer.parseInt(typeString.substring(4)) - 1;
|
||||
Actor actor = context.requireActor();
|
||||
if (!(actor instanceof Player)) {
|
||||
throw new InputParseException("The user is not a player!");
|
||||
}
|
||||
Player player = (Player) actor;
|
||||
BlockBag bag = player.getInventoryBlockBag();
|
||||
if (bag == null || !(bag instanceof SlottableBlockBag)) {
|
||||
throw new InputParseException("Unsupported!");
|
||||
}
|
||||
SlottableBlockBag slottable = (SlottableBlockBag) bag;
|
||||
BaseItem item = slottable.getItem(slot);
|
||||
|
||||
if (!item.getType().hasBlockType()) {
|
||||
throw new InputParseException("You're not holding a block!");
|
||||
}
|
||||
state = item.getType().getBlockType().getDefaultState();
|
||||
nbt = item.getNbtData();
|
||||
} else {
|
||||
BlockType type = BlockTypes.parse(typeString.toLowerCase());
|
||||
|
||||
|
@ -0,0 +1,17 @@
|
||||
package com.sk89q.worldedit.extent.inventory;
|
||||
|
||||
import com.sk89q.worldedit.blocks.BaseItem;
|
||||
|
||||
public interface SlottableBlockBag {
|
||||
BaseItem getItem(int slot);
|
||||
|
||||
void setItem(int slot, BaseItem block);
|
||||
|
||||
default int size() {
|
||||
return 36;
|
||||
}
|
||||
|
||||
default int getSelectedSlot() {
|
||||
return -1;
|
||||
}
|
||||
}
|
@ -34,7 +34,7 @@ import java.util.List;
|
||||
*/
|
||||
public class CombinedRegionFunction implements RegionFunction {
|
||||
|
||||
private final List<RegionFunction> functions = new ArrayList<>();
|
||||
private RegionFunction[] functions;
|
||||
|
||||
/**
|
||||
* Create a combined region function.
|
||||
@ -49,7 +49,7 @@ public class CombinedRegionFunction implements RegionFunction {
|
||||
*/
|
||||
public CombinedRegionFunction(Collection<RegionFunction> functions) {
|
||||
checkNotNull(functions);
|
||||
this.functions.addAll(functions);
|
||||
this.functions = functions.toArray(new RegionFunction[functions.size()]);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -58,7 +58,7 @@ public class CombinedRegionFunction implements RegionFunction {
|
||||
* @param function an array of functions to match
|
||||
*/
|
||||
public CombinedRegionFunction(RegionFunction... function) {
|
||||
this(Arrays.asList(checkNotNull(function)));
|
||||
this.functions = function;
|
||||
}
|
||||
|
||||
public static CombinedRegionFunction combine(RegionFunction function, RegionFunction add) {
|
||||
@ -82,7 +82,9 @@ public class CombinedRegionFunction implements RegionFunction {
|
||||
*/
|
||||
public void add(Collection<RegionFunction> functions) {
|
||||
checkNotNull(functions);
|
||||
this.functions.addAll(functions);
|
||||
ArrayList<RegionFunction> functionsList = new ArrayList<>(Arrays.asList(this.functions));
|
||||
functionsList.addAll(functions);
|
||||
this.functions = functionsList.toArray(new RegionFunction[functionsList.size()]);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -98,9 +100,7 @@ public class CombinedRegionFunction implements RegionFunction {
|
||||
public boolean apply(BlockVector3 position) throws WorldEditException {
|
||||
boolean ret = false;
|
||||
for (RegionFunction function : functions) {
|
||||
if (function.apply(position)) {
|
||||
ret = true;
|
||||
}
|
||||
ret |= (function.apply(position));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
@ -69,12 +69,11 @@ public class ExtentBlockCopy implements RegionFunction {
|
||||
|
||||
@Override
|
||||
public boolean apply(BlockVector3 position) throws WorldEditException {
|
||||
BaseBlock block = source.getFullBlock(position);
|
||||
BlockVector3 orig = position.subtract(from);
|
||||
BlockVector3 transformed = transform.apply(orig.toVector3()).toBlockPoint();
|
||||
|
||||
// Apply transformations to NBT data if necessary
|
||||
block = transformNbtData(block);
|
||||
BaseBlock block = transformNbtData(source.getFullBlock(position));
|
||||
|
||||
return destination.setBlock(transformed.add(to), block);
|
||||
}
|
||||
|
@ -91,7 +91,9 @@ public class BlockTypeMask extends AbstractExtentMask {
|
||||
* @param block an array of blocks
|
||||
*/
|
||||
public void add(BlockType... block) {
|
||||
add(Arrays.asList(checkNotNull(block)));
|
||||
for (BlockType type : block) {
|
||||
this.types[type.getInternalId()] = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -68,15 +68,15 @@ public class ChangeSetExecutor implements Operation {
|
||||
|
||||
@Override
|
||||
public Operation resume(RunContext run) throws WorldEditException {
|
||||
while (iterator.hasNext()) {
|
||||
Change change = iterator.next();
|
||||
if (type == Type.UNDO) {
|
||||
change.undo(context);
|
||||
} else {
|
||||
change.redo(context);
|
||||
if (type == Type.UNDO) {
|
||||
while (iterator.hasNext()) {
|
||||
iterator.next().undo(context);
|
||||
}
|
||||
} else {
|
||||
while (iterator.hasNext()) {
|
||||
iterator.next().redo(context);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -27,6 +27,8 @@ import com.sk89q.worldedit.WorldEditException;
|
||||
*/
|
||||
public final class Operations {
|
||||
|
||||
private static final RunContext context = new RunContext();
|
||||
|
||||
private Operations() {
|
||||
}
|
||||
|
||||
@ -38,7 +40,7 @@ public final class Operations {
|
||||
*/
|
||||
public static void complete(Operation op) throws WorldEditException {
|
||||
while (op != null) {
|
||||
op = op.resume(new RunContext());
|
||||
op = op.resume(context);
|
||||
}
|
||||
}
|
||||
|
||||
@ -52,7 +54,7 @@ public final class Operations {
|
||||
public static void completeLegacy(Operation op) throws MaxChangedBlocksException {
|
||||
while (op != null) {
|
||||
try {
|
||||
op = op.resume(new RunContext());
|
||||
op = op.resume(context);
|
||||
} catch (MaxChangedBlocksException e) {
|
||||
throw e;
|
||||
} catch (WorldEditException e) {
|
||||
@ -71,7 +73,7 @@ public final class Operations {
|
||||
public static void completeBlindly(Operation op) {
|
||||
while (op != null) {
|
||||
try {
|
||||
op = op.resume(new RunContext());
|
||||
op = op.resume(context);
|
||||
} catch (WorldEditException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
@ -184,8 +184,8 @@ public abstract class BreadthFirstSearch implements Operation {
|
||||
* @param position the position
|
||||
*/
|
||||
public void visit(BlockVector3 position) {
|
||||
BlockVector3 blockVector = position;
|
||||
if (!visited.contains(blockVector)) {
|
||||
if (!visited.contains(position)) {
|
||||
BlockVector3 blockVector = position;
|
||||
isVisitable(blockVector, blockVector); // Ignore this, just to initialize mask on this point
|
||||
queue.add(blockVector);
|
||||
visited.add(blockVector);
|
||||
@ -314,7 +314,8 @@ public abstract class BreadthFirstSearch implements Operation {
|
||||
|
||||
@Override
|
||||
public void cancel() {
|
||||
queue.clear();
|
||||
visited.clear();
|
||||
affected = 0;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -156,4 +156,12 @@ public interface RegionSelector {
|
||||
*/
|
||||
List<String> getInformationLines();
|
||||
|
||||
/**
|
||||
* Get the verticies
|
||||
* @return
|
||||
* @throws IncompleteRegionException
|
||||
*/
|
||||
default List<BlockVector3> getVerticies() throws IncompleteRegionException {
|
||||
return Collections.singletonList(getPrimaryPosition());
|
||||
}
|
||||
}
|
||||
|
@ -276,4 +276,8 @@ public class ConvexPolyhedralRegionSelector implements RegionSelector, CUIRegion
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BlockVector3> getVerticies() {
|
||||
return new ArrayList<>(region.getVertices());
|
||||
}
|
||||
}
|
||||
|
@ -40,6 +40,7 @@ import com.sk89q.worldedit.world.World;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@ -308,4 +309,9 @@ public class CuboidRegionSelector implements RegionSelector, CUIRegion {
|
||||
return "cuboid";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BlockVector3> getVerticies() {
|
||||
return Arrays.asList(position1, position2);
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user