Search in sources :

Example 31 with Location

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());
}
Also used : BlockVector3(com.sk89q.worldedit.math.BlockVector3) Vector3(com.sk89q.worldedit.math.Vector3) Location(com.sk89q.worldedit.util.Location)

Example 32 with Location

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);
}
Also used : EntityType(com.sk89q.worldedit.world.entity.EntityType) Extent(com.sk89q.worldedit.extent.Extent) BaseEntity(com.sk89q.worldedit.entity.BaseEntity) List(java.util.List) DoubleTag(com.sk89q.jnbt.DoubleTag) CompoundTag(com.sk89q.jnbt.CompoundTag) Tag(com.sk89q.jnbt.Tag) LongTag(com.sk89q.jnbt.LongTag) DoubleTag(com.sk89q.jnbt.DoubleTag) Location(com.sk89q.worldedit.util.Location)

Example 33 with Location

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;
}
Also used : Location(com.sk89q.worldedit.util.Location)

Example 34 with Location

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;
}
Also used : WorldEdit(com.sk89q.worldedit.WorldEdit) Location(com.sk89q.worldedit.util.Location)

Example 35 with Location

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();
        }
    }
}
Also used : ListBinaryTag(com.sk89q.worldedit.util.nbt.ListBinaryTag) ArrayList(java.util.ArrayList) BaseEntity(com.sk89q.worldedit.entity.BaseEntity) IOException(java.io.IOException) Chunk(com.sk89q.worldedit.world.chunk.Chunk) BlockVector3(com.sk89q.worldedit.math.BlockVector3) BlockVector2(com.sk89q.worldedit.math.BlockVector2) MissingChunkException(com.sk89q.worldedit.world.storage.MissingChunkException) DataException(com.sk89q.worldedit.world.DataException) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) CompoundBinaryTag(com.sk89q.worldedit.util.nbt.CompoundBinaryTag) Location(com.sk89q.worldedit.util.Location)

Aggregations

Location (com.sk89q.worldedit.util.Location)75 BlockVector3 (com.sk89q.worldedit.math.BlockVector3)26 BaseEntity (com.sk89q.worldedit.entity.BaseEntity)12 World (com.sk89q.worldedit.world.World)12 CompoundTag (com.sk89q.jnbt.CompoundTag)11 Region (com.sk89q.worldedit.regions.Region)10 CommandPermissions (com.sk89q.worldedit.command.util.CommandPermissions)9 Command (org.enginehub.piston.annotation.Command)9 MutableBlockVector3 (com.fastasyncworldedit.core.math.MutableBlockVector3)8 Tag (com.sk89q.jnbt.Tag)8 CuboidRegion (com.sk89q.worldedit.regions.CuboidRegion)8 RegionContainer (com.sk89q.worldguard.protection.regions.RegionContainer)8 List (java.util.List)8 ListTag (com.sk89q.jnbt.ListTag)7 Player (com.sk89q.worldedit.entity.Player)7 Vector3 (com.sk89q.worldedit.math.Vector3)7 BaseBlock (com.sk89q.worldedit.world.block.BaseBlock)7 LocalPlayer (com.sk89q.worldguard.LocalPlayer)7 StringTag (com.sk89q.jnbt.StringTag)6 BlockVector2 (com.sk89q.worldedit.math.BlockVector2)6