use of com.sk89q.worldedit.util.Location in project FastAsyncWorldEdit by IntellectualSites.
the class BlockArrayClipboard method getEntities.
@Override
public List<? extends Entity> getEntities(Region region) {
region = region.clone();
region.shift(BlockVector3.ZERO.subtract(offset));
return getParent().getEntities(region).stream().map(e -> {
if (e instanceof ClipboardEntity) {
ClipboardEntity ce = (ClipboardEntity) e;
Location oldloc = ce.getLocation();
Location loc = new Location(oldloc.getExtent(), oldloc.getX() + offset.getBlockX(), oldloc.getY() + offset.getBlockY(), oldloc.getZ() + offset.getBlockZ(), oldloc.getYaw(), oldloc.getPitch());
return new ClipboardEntity(loc, ce.entity);
}
return e;
}).collect(Collectors.toList());
}
use of com.sk89q.worldedit.util.Location in project FastAsyncWorldEdit by IntellectualSites.
the class PlatformManager method handleBlockInteract.
@Subscribe
public void handleBlockInteract(BlockInteractEvent event) {
// Create a proxy actor with a potentially different world for
// making changes to the world
Actor actor = createProxyActor(event.getCause());
Location location = event.getLocation();
// At this time, only handle interaction from players
if (!(actor instanceof Player)) {
return;
}
Player player = (Player) actor;
LocalSession session = worldEdit.getSessionManager().get(actor);
Request.reset();
Request.request().setSession(session);
Request.request().setWorld(player.getWorld());
try {
if (event.getType() == Interaction.HIT) {
// in addition, it is implicitly bound to all pickaxe items, not just a single tool item
if (session.hasSuperPickAxe() && player.isHoldingPickAxe()) {
final BlockTool superPickaxe = session.getSuperPickaxe();
if (superPickaxe != null && superPickaxe.canUse(player)) {
// FAWE start - run async
player.runAction(() -> reset(superPickaxe).actPrimary(queryCapability(Capability.WORLD_EDITING), getConfiguration(), player, session, location, event.getFace()), false, true);
// FAWE end
event.setCancelled(true);
return;
}
}
Tool tool = session.getTool(player);
if (tool instanceof DoubleActionBlockTool && tool.canUse(player)) {
// FAWE start - run async
player.runAction(() -> reset((DoubleActionBlockTool) tool).actSecondary(queryCapability(Capability.WORLD_EDITING), getConfiguration(), player, session, location, event.getFace()), false, true);
// FAWE end
event.setCancelled(true);
}
} else if (event.getType() == Interaction.OPEN) {
// FAWE start - get general tool over item in main hand & run async
Tool tool = session.getTool(player);
if (tool instanceof BlockTool && tool.canUse(player)) {
if (player.checkAction()) {
// FAWE run async
player.runAction(() -> {
BlockTool blockTool = (BlockTool) tool;
if (!(tool instanceof BrushTool)) {
blockTool = reset(blockTool);
}
blockTool.actPrimary(queryCapability(Capability.WORLD_EDITING), getConfiguration(), player, session, location, event.getFace());
}, false, true);
// FAWE end
event.setCancelled(true);
}
}
}
} catch (Throwable e) {
handleThrowable(e, actor);
} finally {
Request.reset();
}
}
use of com.sk89q.worldedit.util.Location in project FastAsyncWorldEdit by IntellectualSites.
the class FabricWorldEdit method onLeftClickBlock.
private ActionResult onLeftClickBlock(PlayerEntity playerEntity, World world, Hand hand, BlockPos blockPos, Direction direction) {
if (shouldSkip() || hand == Hand.OFF_HAND || world.isClient) {
return ActionResult.PASS;
}
WorldEdit we = WorldEdit.getInstance();
FabricPlayer player = adaptPlayer((ServerPlayerEntity) playerEntity);
FabricWorld localWorld = getWorld(world);
Location pos = new Location(localWorld, blockPos.getX(), blockPos.getY(), blockPos.getZ());
com.sk89q.worldedit.util.Direction weDirection = FabricAdapter.adaptEnumFacing(direction);
if (we.handleBlockLeftClick(player, pos, weDirection)) {
return ActionResult.SUCCESS;
}
if (we.handleArmSwing(player)) {
return ActionResult.SUCCESS;
}
return ActionResult.PASS;
}
use of com.sk89q.worldedit.util.Location in project FastAsyncWorldEdit by IntellectualSites.
the class FabricEntity method getLocation.
@Override
public Location getLocation() {
net.minecraft.entity.Entity entity = entityRef.get();
if (entity != null) {
Vector3 position = Vector3.at(entity.x, entity.y, entity.z);
float yaw = entity.yaw;
float pitch = entity.pitch;
return new Location(FabricAdapter.adapt(entity.world), position, yaw, pitch);
} else {
return new Location(NullWorld.getInstance());
}
}
use of com.sk89q.worldedit.util.Location in project FastAsyncWorldEdit by IntellectualSites.
the class CopyPastaBrush method build.
@Override
public void build(EditSession editSession, BlockVector3 position, Pattern pattern, double size) throws MaxChangedBlocksException {
Actor actor = editSession.getActor();
if (!(actor instanceof Player)) {
throw FaweCache.PLAYER_ONLY;
}
Player player = (Player) actor;
ClipboardHolder clipboard = session.getExistingClipboard();
if (clipboard == null) {
Mask mask = editSession.getMask();
if (mask == null) {
mask = Masks.alwaysTrue();
}
final ResizableClipboardBuilder builder = new ResizableClipboardBuilder(editSession.getWorld());
final int minY = position.getBlockY();
mask = new AbstractDelegateMask(mask) {
@Override
public boolean test(BlockVector3 vector) {
if (super.test(vector) && vector.getBlockY() >= minY) {
BaseBlock block = editSession.getFullBlock(vector);
if (!block.getBlockType().getMaterial().isAir()) {
builder.add(vector, BlockTypes.AIR.getDefaultState().toBaseBlock(), block);
return true;
}
}
return false;
}
};
// Add origin
mask.test(position);
RecursiveVisitor visitor = new RecursiveVisitor(mask, new NullRegionFunction(), (int) size, editSession.getMinY(), editSession.getMaxY());
visitor.visit(position);
Operations.completeBlindly(visitor);
// Build the clipboard
Clipboard newClipboard = builder.build();
newClipboard.setOrigin(position);
ClipboardHolder holder = new ClipboardHolder(newClipboard);
session.setClipboard(holder);
int blocks = builder.size();
player.print(Caption.of("fawe.worldedit.copy.command.copy", blocks));
} else {
AffineTransform transform = null;
if (randomRotate) {
transform = new AffineTransform();
int rotate = 90 * ThreadLocalRandom.current().nextInt(4);
transform = transform.rotateY(rotate);
}
if (autoRotate) {
if (transform == null) {
transform = new AffineTransform();
}
Location loc = player.getLocation();
float yaw = loc.getYaw();
float pitch = loc.getPitch();
transform = transform.rotateY(-yaw % 360);
transform = transform.rotateX(pitch - 90);
}
if (transform != null && !transform.isIdentity()) {
clipboard.setTransform(transform);
}
Operation operation = clipboard.createPaste(editSession).to(position.add(0, 1, 0)).ignoreAirBlocks(true).build();
Operations.completeLegacy(operation);
editSession.flushQueue();
}
}
Aggregations