Too lazy to write a commit message

Dieser Commit ist enthalten in:
matt 2019-04-02 23:36:32 -04:00
Ursprung 29692f3fbe
Commit 122236f6c7
5 geänderte Dateien mit 111 neuen und 145 gelöschten Zeilen

Datei anzeigen

@ -1221,20 +1221,12 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
@Override @Override
public BlockVector3 getMinimumPoint() { public BlockVector3 getMinimumPoint() {
if (extent != null) { return getWorld().getMinimumPoint();
return this.extent.getMinimumPoint();
} else {
return BlockVector3.at(-30000000, 0, -30000000);
}
} }
@Override @Override
public BlockVector3 getMaximumPoint() { public BlockVector3 getMaximumPoint() {
if (extent != null) { return getWorld().getMaximumPoint();
return this.extent.getMaximumPoint();
} else {
return BlockVector3.at(30000000, 255, 30000000);
}
} }
@Override @Override
@ -1364,7 +1356,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
* @return the number of blocks that matched the pattern * @return the number of blocks that matched the pattern
*/ */
public int countBlocks(final Region region, final Set<BlockStateHolder> searchBlocks) { public int countBlocks(final Region region, final Set<BlockStateHolder> searchBlocks) {
final Mask mask = new BlockMaskBuilder().addBlocks(searchBlocks).build(extent); Mask mask = new BlockMaskBuilder().addBlocks(searchBlocks).build(extent);
RegionVisitor visitor = new RegionVisitor(region, new RegionFunction() { RegionVisitor visitor = new RegionVisitor(region, new RegionFunction() {
@Override @Override
public boolean apply(BlockVector3 position) throws WorldEditException { public boolean apply(BlockVector3 position) throws WorldEditException {
@ -1516,10 +1508,11 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
checkArgument(apothem >= 1, "apothem >= 1"); checkArgument(apothem >= 1, "apothem >= 1");
checkArgument(height >= 1, "height >= 1"); checkArgument(height >= 1, "height >= 1");
final Region region = new CuboidRegion(this.getWorld(), // Causes clamping of Y range Region region = new CuboidRegion(
getWorld(), // Causes clamping of Y range
position.add(-apothem + 1, 0, -apothem + 1), position.add(apothem - 1, height - 1, apothem - 1)); position.add(-apothem + 1, 0, -apothem + 1), position.add(apothem - 1, height - 1, apothem - 1));
final Pattern pattern = BlockTypes.AIR.getDefaultState(); Pattern pattern = new BlockPattern(BlockTypes.AIR.getDefaultState());
return this.setBlocks(region, pattern); return setBlocks(region, pattern);
} }
/** /**
@ -1536,10 +1529,10 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
checkArgument(apothem >= 1, "apothem >= 1"); checkArgument(apothem >= 1, "apothem >= 1");
checkArgument(height >= 1, "height >= 1"); checkArgument(height >= 1, "height >= 1");
final Region region = new CuboidRegion(this.getWorld(), // Causes clamping of Y range Region region = new CuboidRegion(getWorld(), // Causes clamping of Y range
position.add(-apothem + 1, 0, -apothem + 1), position.add(apothem - 1, -height + 1, apothem - 1)); position.add(-apothem + 1, 0, -apothem + 1), position.add(apothem - 1, -height + 1, apothem - 1));
final Pattern pattern = BlockTypes.AIR.getDefaultState(); Pattern pattern = new BlockPattern(BlockTypes.AIR.getDefaultState());
return this.setBlocks(region, pattern); return setBlocks(region, pattern);
} }
/** /**
@ -1629,9 +1622,8 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
Operations.completeBlindly(visitor); Operations.completeBlindly(visitor);
this.changes += visitor.getAffected(); this.changes += visitor.getAffected();
} else { } else {
Iterator<BlockVector3> iter = region.iterator(); for (BlockVector3 blockVector3 : region) {
while (iter.hasNext()) { if (this.extent.setBlock(blockVector3, block)) {
if (this.extent.setBlock(iter.next(), block)) {
changes++; changes++;
} }
} }
@ -1704,8 +1696,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
* @return number of blocks affected * @return number of blocks affected
* @throws MaxChangedBlocksException thrown if too many blocks are changed * @throws MaxChangedBlocksException thrown if too many blocks are changed
*/ */
@SuppressWarnings("deprecation") public int replaceBlocks(Region region, Mask mask, Pattern pattern) throws MaxChangedBlocksException {
public int replaceBlocks(final Region region, final Mask mask, final Pattern pattern) {
checkNotNull(region); checkNotNull(region);
checkNotNull(mask); checkNotNull(mask);
checkNotNull(pattern); checkNotNull(pattern);
@ -3363,9 +3354,9 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
} }
private void setExistingBlocks(BlockVector3 pos1, BlockVector3 pos2) { private void setExistingBlocks(BlockVector3 pos1, BlockVector3 pos2) {
for (int x = (int) pos1.getX(); x <= (int) pos2.getX(); x++) { for (int x = pos1.getX(); x <= pos2.getX(); x++) {
for (int z = pos1.getBlockZ(); z <= pos2.getBlockZ(); z++) { for (int z = pos1.getBlockZ(); z <= pos2.getBlockZ(); z++) {
for (int y = (int) pos1.getY(); y <= (int) pos2.getY(); y++) { for (int y = pos1.getY(); y <= pos2.getY(); y++) {
int from = queue.getCombinedId4Data(x, y, z); int from = queue.getCombinedId4Data(x, y, z);
queue.setBlock(x, y, z, from); queue.setBlock(x, y, z, from);
if (BlockTypes.getFromStateId(from).getMaterial().hasContainer()) { if (BlockTypes.getFromStateId(from).getMaterial().hasContainer()) {

Datei anzeigen

@ -43,6 +43,7 @@ import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.event.platform.*; import com.sk89q.worldedit.event.platform.*;
import com.sk89q.worldedit.extension.platform.permission.ActorSelectorLimits; import com.sk89q.worldedit.extension.platform.permission.ActorSelectorLimits;
import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.Vector3;
import com.sk89q.worldedit.regions.RegionSelector; import com.sk89q.worldedit.regions.RegionSelector;
import com.sk89q.worldedit.session.request.Request; import com.sk89q.worldedit.session.request.Request;
import com.sk89q.worldedit.util.HandSide; import com.sk89q.worldedit.util.HandSide;
@ -276,7 +277,7 @@ public class PlatformManager {
/** /**
* Get the current configuration. * Get the current configuration.
* <p> *
* <p>If no platform has been registered yet, then a default configuration * <p>If no platform has been registered yet, then a default configuration
* will be returned.</p> * will be returned.</p>
* *
@ -304,142 +305,113 @@ public class PlatformManager {
public void handleBlockInteract(BlockInteractEvent event) { public void handleBlockInteract(BlockInteractEvent event) {
// Create a proxy actor with a potentially different world for // Create a proxy actor with a potentially different world for
// making changes to the world // making changes to the world
Request.reset(); Actor actor = createProxyActor(event.getCause());
final Actor actor = createProxyActor(event.getCause());
Location location = event.getLocation();
try { try {
final Location location = event.getLocation(); Vector3 vector = location.toVector();
final BlockVector3 vector = location.toBlockPoint();
// At this time, only handle interaction from players // At this time, only handle interaction from players
if (actor instanceof Player) { if (actor instanceof Player) {
final LocalSession session = worldEdit.getSessionManager().get(actor); Player player = (Player) actor;
Player playerActor = (Player) actor; LocalSession session = worldEdit.getSessionManager().get(actor);
Request.reset();
VirtualWorld virtual = session.getVirtualWorld(); VirtualWorld virtual = session.getVirtualWorld();
if (virtual != null) { if (virtual != null) {
virtual.handleBlockInteract(playerActor, vector, event); virtual.handleBlockInteract(player, vector.toBlockPoint(), event);
if (event.isCancelled()) return; if (event.isCancelled()) return;
} }
if (event.getType() == Interaction.HIT) { if (event.getType() == Interaction.HIT) {
if (session.isToolControlEnabled() && playerActor.getItemInHand(HandSide.MAIN_HAND).getType().getId().equals(getConfiguration().wandItem)) { if (player.getItemInHand(HandSide.MAIN_HAND).getType().getId().equals(getConfiguration().wandItem)) {
FawePlayer<?> fp = FawePlayer.wrap(playerActor); if (!session.isToolControlEnabled()) {
return;
}
if (!actor.hasPermission("worldedit.selection.pos")) { if (!actor.hasPermission("worldedit.selection.pos")) {
return; return;
} }
final RegionSelector selector = session.getRegionSelector(playerActor.getWorld()); FawePlayer<?> fp = FawePlayer.wrap(player);
final Player player = new LocationMaskedPlayerWrapper(PlayerWrapper.wrap((Player) actor), ((Player) actor).getLocation()); RegionSelector selector = session.getRegionSelector(player.getWorld());
fp.runAction(new Runnable() { final Player maskedPlayerWrapper =
@Override new LocationMaskedPlayerWrapper(PlayerWrapper.wrap((Player) actor),
public void run() { ((Player) actor).getLocation());
if (selector.selectPrimary(vector, ActorSelectorLimits.forActor(player))) { BlockVector3 blockPoint = vector.toBlockPoint();
selector.explainPrimarySelection(actor, session, vector); fp.runAction(() -> {
} if (selector.selectPrimary(blockPoint,
ActorSelectorLimits.forActor(maskedPlayerWrapper))) {
selector
.explainPrimarySelection(actor, session, blockPoint);
} }
}, false, true); }, false, true);
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
if (session.hasSuperPickAxe() && playerActor.isHoldingPickAxe()) { if (player.isHoldingPickAxe() && session.hasSuperPickAxe()) {
final BlockTool superPickaxe = session.getSuperPickaxe(); final BlockTool superPickaxe = session.getSuperPickaxe();
if (superPickaxe != null && superPickaxe.canUse(playerActor)) { if (superPickaxe != null && superPickaxe.canUse(player)) {
FawePlayer<?> fp = FawePlayer.wrap(playerActor); FawePlayer<?> fp = FawePlayer.wrap(player);
final Player player = new LocationMaskedPlayerWrapper(PlayerWrapper.wrap((Player) actor), ((Player) actor).getLocation()); final Player maskedPlayerWrapper = new LocationMaskedPlayerWrapper(PlayerWrapper.wrap((Player) actor), ((Player) actor).getLocation());
fp.runAction(new Runnable() { fp.runAction(() -> reset(superPickaxe).actPrimary(queryCapability(Capability.WORLD_EDITING), getConfiguration(), maskedPlayerWrapper, session, location), false, true);
@Override
public void run() {
reset(superPickaxe).actPrimary(queryCapability(Capability.WORLD_EDITING), getConfiguration(), player, session, location);
}
}, false, true);
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
} }
//<<<<<<< HEAD Tool tool = session.getTool(player.getItemInHand(HandSide.MAIN_HAND).getType());
final Tool tool = session.getTool(playerActor); if (tool instanceof DoubleActionBlockTool) {
if (tool != null && tool instanceof DoubleActionBlockTool) { if (tool.canUse(player)) {
if (tool.canUse(playerActor)) { FawePlayer<?> fp = FawePlayer.wrap(player);
FawePlayer<?> fp = FawePlayer.wrap(playerActor); final Player maskedPlayerWrapper = new LocationMaskedPlayerWrapper(PlayerWrapper.wrap((Player) actor), ((Player) actor).getLocation());
final Player player = new LocationMaskedPlayerWrapper(PlayerWrapper.wrap((Player) actor), ((Player) actor).getLocation()); fp.runAction(() -> reset(((DoubleActionBlockTool) tool)).actSecondary(queryCapability(Capability.WORLD_EDITING), getConfiguration(), maskedPlayerWrapper, session, location), false, true);
fp.runAction(new Runnable() {
@Override
public void run() {
reset(((DoubleActionBlockTool) tool)).actSecondary(queryCapability(Capability.WORLD_EDITING), getConfiguration(), player, session, location);
}
}, false, true);
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
//=======
//
// RegionSelector selector = session.getRegionSelector(player.getWorld());
//
// BlockVector3 blockPoint = vector.toBlockPoint();
// if (selector.selectPrimary(blockPoint, ActorSelectorLimits.forActor(player))) {
// selector.explainPrimarySelection(actor, session, blockPoint);
//>>>>>>> 399e0ad5... Refactor vector system to be cleaner
} }
} else if (event.getType() == Interaction.OPEN) { } else if (event.getType() == Interaction.OPEN) {
if (session.isToolControlEnabled() && playerActor.getItemInHand(HandSide.MAIN_HAND).getType().getId().equals(getConfiguration().wandItem)) { if (player.getItemInHand(HandSide.MAIN_HAND).getType().getId().equals(getConfiguration().wandItem)) {
FawePlayer<?> fp = FawePlayer.wrap(playerActor); if (!session.isToolControlEnabled()) {
return;
}
if (!actor.hasPermission("worldedit.selection.pos")) { if (!actor.hasPermission("worldedit.selection.pos")) {
return; return;
} }
FawePlayer<?> fp = FawePlayer.wrap(player);
if (fp.checkAction()) { if (fp.checkAction()) {
final RegionSelector selector = session.getRegionSelector(playerActor.getWorld()); RegionSelector selector = session.getRegionSelector(player.getWorld());
final Player player = new LocationMaskedPlayerWrapper(PlayerWrapper.wrap((Player) actor), ((Player) actor).getLocation()); Player maskedPlayerWrapper = new LocationMaskedPlayerWrapper(
fp.runAction(new Runnable() { PlayerWrapper.wrap((Player) actor),
@Override ((Player) actor).getLocation());
public void run() { BlockVector3 blockPoint = vector.toBlockPoint();
if (selector.selectSecondary(vector, ActorSelectorLimits.forActor(player))) { fp.runAction(() -> {
selector.explainSecondarySelection(actor, session, vector); if (selector.selectSecondary(blockPoint,
} ActorSelectorLimits.forActor(maskedPlayerWrapper))) {
selector.explainSecondarySelection(actor, session,
blockPoint);
} }
}, false, true); }, false, true);
} }
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
Tool tool = session.getTool(player.getItemInHand(HandSide.MAIN_HAND).getType());
//<<<<<<< HEAD if (tool instanceof BlockTool) {
final Tool tool = session.getTool(playerActor); if (tool.canUse(player)) {
if (tool != null && tool instanceof BlockTool) { FawePlayer<?> fp = FawePlayer.wrap(player);
if (tool.canUse(playerActor)) {
FawePlayer<?> fp = FawePlayer.wrap(playerActor);
if (fp.checkAction()) { if (fp.checkAction()) {
final Player player = new LocationMaskedPlayerWrapper(PlayerWrapper.wrap((Player) actor), ((Player) actor).getLocation()); final Player maskedPlayerWrapper = new LocationMaskedPlayerWrapper(PlayerWrapper.wrap((Player) actor), ((Player) actor).getLocation());
fp.runAction(new Runnable() { fp.runAction(() -> {
@Override
public void run() {
if (tool instanceof BrushTool) { if (tool instanceof BrushTool) {
((BlockTool) tool).actPrimary(queryCapability(Capability.WORLD_EDITING), getConfiguration(), player, session, location); ((BlockTool) tool).actPrimary(queryCapability(Capability.WORLD_EDITING), getConfiguration(), maskedPlayerWrapper, session, location);
} else { } else {
reset((BlockTool) tool).actPrimary(queryCapability(Capability.WORLD_EDITING), getConfiguration(), player, session, location); reset((BlockTool) tool).actPrimary(queryCapability(Capability.WORLD_EDITING), getConfiguration(), maskedPlayerWrapper, session, location);
}
} }
}, false, true); }, false, true);
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
} }
//=======
// RegionSelector selector = session.getRegionSelector(player.getWorld());
// BlockVector3 blockPoint = vector.toBlockPoint();
// if (selector.selectSecondary(blockPoint, ActorSelectorLimits.forActor(player))) {
// selector.explainSecondarySelection(actor, session, blockPoint);
// }
//
// event.setCancelled(true);
// return;
// }
//
// Tool tool = session.getTool(player.getItemInHand(HandSide.MAIN_HAND).getType());
// if (tool instanceof BlockTool) {
// if (tool.canUse(player)) {
// ((BlockTool) tool).actPrimary(queryCapability(Capability.WORLD_EDITING), getConfiguration(), player, session, location);
// event.setCancelled(true);
//>>>>>>> 399e0ad5... Refactor vector system to be cleaner
} }
} }
} }
@ -459,7 +431,6 @@ public class PlatformManager {
} }
} }
@SuppressWarnings("deprecation")
@Subscribe @Subscribe
public void handlePlayerInput(PlayerInputEvent event) { public void handlePlayerInput(PlayerInputEvent event) {
// Create a proxy actor with a potentially different world for // Create a proxy actor with a potentially different world for
@ -477,7 +448,7 @@ public class PlatformManager {
try { try {
switch (event.getInputType()) { switch (event.getInputType()) {
case PRIMARY: { case PRIMARY: {
if (player.getItemInHand(HandSide.MAIN_HAND).getType().equals(getConfiguration().navigationWand)) { if (player.getItemInHand(HandSide.MAIN_HAND).getType().getId().equals(getConfiguration().navigationWand)) {
if (getConfiguration().navigationWandMaxDistance <= 0) { if (getConfiguration().navigationWandMaxDistance <= 0) {
return; return;
} }
@ -497,16 +468,11 @@ public class PlatformManager {
return; return;
} }
Tool tool = session.getTool(player); Tool tool = session.getTool(player.getItemInHand(HandSide.MAIN_HAND).getType());
if (tool != null && tool instanceof DoubleActionTraceTool) { if (tool instanceof DoubleActionTraceTool) {
if (tool.canUse(player)) { if (tool.canUse(player)) {
FawePlayer<?> fp = FawePlayer.wrap(player); FawePlayer<?> fp = FawePlayer.wrap(player);
fp.runAsyncIfFree(new Runnable() { fp.runAsyncIfFree(() -> reset((DoubleActionTraceTool) tool).actSecondary(queryCapability(Capability.WORLD_EDITING), getConfiguration(), player, session));
@Override
public void run() {
reset((DoubleActionTraceTool) tool).actSecondary(queryCapability(Capability.WORLD_EDITING), getConfiguration(), player, session);
}
});
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
@ -515,7 +481,7 @@ public class PlatformManager {
} }
case SECONDARY: { case SECONDARY: {
if (player.getItemInHand(HandSide.MAIN_HAND).getType().equals(getConfiguration().navigationWand)) { if (player.getItemInHand(HandSide.MAIN_HAND).getType().getId().equals(getConfiguration().navigationWand)) {
if (getConfiguration().navigationWandMaxDistance <= 0) { if (getConfiguration().navigationWandMaxDistance <= 0) {
return; return;
} }
@ -532,16 +498,11 @@ public class PlatformManager {
return; return;
} }
Tool tool = session.getTool(player); Tool tool = session.getTool(player.getItemInHand(HandSide.MAIN_HAND).getType());
if (tool != null && tool instanceof TraceTool) { if (tool instanceof TraceTool) {
if (tool.canUse(player)) { if (tool.canUse(player)) {
FawePlayer<?> fp = FawePlayer.wrap(player); FawePlayer<?> fp = FawePlayer.wrap(player);
fp.runAction(new Runnable() { fp.runAction(() -> reset((TraceTool) tool).actPrimary(queryCapability(Capability.WORLD_EDITING), getConfiguration(), player, session), false, true);
@Override
public void run() {
reset((TraceTool) tool).actPrimary(queryCapability(Capability.WORLD_EDITING), getConfiguration(), player, session);
}
}, false, true);
event.setCancelled(true); event.setCancelled(true);
return; return;
} }

Datei anzeigen

@ -27,8 +27,7 @@ import com.sk89q.worldedit.world.block.BlockStateHolder;
/** /**
* A pattern that returns the same {@link BaseBlock} each time. * A pattern that returns the same {@link BaseBlock} each time.
*/ */
@Deprecated public class BlockPattern extends AbstractPattern {
public class BlockPattern implements Pattern {
private BaseBlock block; private BaseBlock block;

Datei anzeigen

@ -29,7 +29,7 @@ import java.util.Comparator;
/** /**
* An immutable 3-dimensional vector. * An immutable 3-dimensional vector.
*/ */
public class BlockVector3 { public final class BlockVector3 {
public static final BlockVector3 ZERO = new BlockVector3(0, 0, 0); public static final BlockVector3 ZERO = new BlockVector3(0, 0, 0);
public static final BlockVector3 UNIT_X = new BlockVector3(1, 0, 0); public static final BlockVector3 UNIT_X = new BlockVector3(1, 0, 0);

Datei anzeigen

@ -31,7 +31,7 @@ import java.util.Comparator;
/** /**
* An immutable 3-dimensional vector. * An immutable 3-dimensional vector.
*/ */
public class Vector3 { public final class Vector3 {
public static final Vector3 ZERO = new Vector3(0, 0, 0); public static final Vector3 ZERO = new Vector3(0, 0, 0);
public static final Vector3 UNIT_X = new Vector3(1, 0, 0); public static final Vector3 UNIT_X = new Vector3(1, 0, 0);
@ -40,6 +40,21 @@ public class Vector3 {
public static final Vector3 ONE = new Vector3(1, 1, 1); public static final Vector3 ONE = new Vector3(1, 1, 1);
public static Vector3 at(double x, double y, double z) { public static Vector3 at(double x, double y, double z) {
// switch for efficiency on typical cases
// in MC y is rarely 0/1 on selections
int yTrunc = (int) y;
switch (yTrunc) {
case 0:
if (x == 0 && y == 0 && z == 0) {
return ZERO;
}
break;
case 1:
if (x == 1 && y == 1 && z == 1) {
return ONE;
}
break;
}
return new Vector3(x, y, z); return new Vector3(x, y, z);
} }
@ -622,25 +637,25 @@ public class Vector3 {
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (obj == this) return true;
if (!(obj instanceof Vector3)) { if (!(obj instanceof Vector3)) {
return false; return false;
} }
Vector3 other = (Vector3) obj; Vector3 other = (Vector3) obj;
return other.getX() == this.getX() && other.getZ() == this.getZ() && other.getY() == this.getY(); return other.x == this.x && other.y == this.y && other.z == this.z;
} }
@Override @Override
public int hashCode() { public int hashCode() {
return ((int) getX() ^ ((int) getZ() << 16)) ^ ((int) getY() << 30); int hash = 17;
hash = 31 * hash + Double.hashCode(x);
hash = 31 * hash + Double.hashCode(y);
hash = 31 * hash + Double.hashCode(z);
return hash;
} }
@Override @Override
public String toString() { public String toString() {
String x = (getX() == getBlockX() ? "" + getBlockX() : "" + getX());
String y = (getY() == getBlockY() ? "" + getBlockY() : "" + getY());
String z = (getZ() == getBlockZ() ? "" + getBlockZ() : "" + getZ());
return "(" + x + ", " + y + ", " + z + ")"; return "(" + x + ", " + y + ", " + z + ")";
} }