use of com.sk89q.worldedit.util.Location in project FastAsyncWorldEdit by IntellectualSites.
the class SpongeAdapter method adapt.
/**
* Create a WorldEdit location from a Sponge location.
*
* @param location the Sponge location
* @return a WorldEdit location
*/
public static Location adapt(org.spongepowered.api.world.Location<org.spongepowered.api.world.World> location, Vector3d rotation) {
checkNotNull(location);
Vector3 position = asVector(location);
return new Location(adapt(location.getExtent()), position, (float) rotation.getX(), (float) rotation.getY());
}
use of com.sk89q.worldedit.util.Location in project FastAsyncWorldEdit by IntellectualSites.
the class MutableEntityChange method create.
public void create(UndoContext context) {
Map<String, Tag> map = tag.getValue();
Tag posTag = map.get("Pos");
if (posTag == null) {
LOGGER.warn("Missing pos tag: {}", tag);
return;
}
List<DoubleTag> pos = (List<DoubleTag>) posTag.getValue();
double x = pos.get(0).getValue();
double y = pos.get(1).getValue();
double z = pos.get(2).getValue();
Extent extent = context.getExtent();
Location location = new Location(extent, x, y, z, 0, 0);
String id = tag.getString("Id");
EntityType type = EntityTypes.parse(id);
BaseEntity entity = new BaseEntity(type, tag);
context.getExtent().createEntity(location, entity);
}
use of com.sk89q.worldedit.util.Location in project FastAsyncWorldEdit by IntellectualSites.
the class MaskedTargetBlock method getMaskedTargetBlock.
public Location getMaskedTargetBlock(boolean useLastBlock) {
boolean searchForLastBlock = true;
Location lastBlock = null;
while (getNextBlock() != null) {
Location current = getCurrentBlock();
if (!mask.test(current.toBlockPoint())) {
if (searchForLastBlock) {
lastBlock = current;
if (lastBlock.getBlockY() <= world.getMinY() || lastBlock.getBlockY() >= world.getMaxY()) {
searchForLastBlock = false;
}
} else if (current.getBlockY() <= world.getMinY()) {
break;
}
} else {
break;
}
}
Location currentBlock = getCurrentBlock();
return currentBlock != null || !useLastBlock ? currentBlock : lastBlock;
}
use of com.sk89q.worldedit.util.Location in project FastAsyncWorldEdit by IntellectualSites.
the class FabricWorldEdit method onRightClickBlock.
private ActionResult onRightClickBlock(PlayerEntity playerEntity, World world, Hand hand, BlockHitResult blockHitResult) {
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, blockHitResult.getBlockPos().getX(), blockHitResult.getBlockPos().getY(), blockHitResult.getBlockPos().getZ());
com.sk89q.worldedit.util.Direction direction = FabricAdapter.adaptEnumFacing(blockHitResult.getSide());
if (we.handleBlockRightClick(player, pos, direction)) {
return ActionResult.SUCCESS;
}
if (we.handleRightClick(player)) {
return ActionResult.SUCCESS;
}
return ActionResult.PASS;
}
use of com.sk89q.worldedit.util.Location in project FastAsyncWorldEdit by IntellectualSites.
the class SnapshotRestore method restore.
/**
* Restores to world.
*
* @throws MaxChangedBlocksException if the max block change limit is exceeded
*/
public void restore() throws MaxChangedBlocksException {
missingChunks = new ArrayList<>();
errorChunks = new ArrayList<>();
// Now let's start restoring!
for (Map.Entry<BlockVector2, ArrayList<BlockVector3>> entry : neededChunks.entrySet()) {
BlockVector2 chunkPos = entry.getKey();
Chunk chunk;
try {
// This will need to be changed if we start officially supporting 3d snapshots.
chunk = snapshot.getChunk(chunkPos.toBlockVector3());
// Now just copy blocks!
for (BlockVector3 pos : entry.getValue()) {
try {
editSession.setBlock(pos, chunk.getBlock(pos));
// FAWE start - biome and entity restore
if (restoreBiomes && (pos.getX() & 3) == 0 && (pos.getY() & 3) == 0 && (pos.getZ() & 3) == 0) {
editSession.setBiome(pos, chunk.getBiome(pos));
}
// FAWE end
} catch (DataException e) {
// this is a workaround: just ignore for now
}
}
// FAWE start - biome and entity restore
if (restoreEntities) {
try {
for (BaseEntity entity : chunk.getEntities()) {
CompoundBinaryTag tag = entity.getNbtReference().getValue();
ListBinaryTag pos = tag.getList("Pos", BinaryTagTypes.LIST);
ListBinaryTag rotation = tag.getList("Rotation", BinaryTagTypes.LIST);
double x = pos.getDouble(0);
double y = pos.getDouble(1);
double z = pos.getDouble(2);
float yRot = rotation.getFloat(0);
float xRot = rotation.getFloat(1);
Location location = new Location(editSession.getWorld(), x, y, z, yRot, xRot);
editSession.createEntity(location, entity);
}
} catch (DataException e) {
// this is a workaround: just ignore for now
}
}
// FAWE end
} catch (MissingChunkException me) {
missingChunks.add(chunkPos);
} catch (IOException | DataException me) {
errorChunks.add(chunkPos);
lastErrorMessage = me.getMessage();
}
}
}
Aggregations