Search in sources :

Example 46 with Location

use of com.sk89q.worldedit.util.Location in project FastAsyncWorldEdit by IntellectualSites.

the class SpongeSchematicWriter method writeEntities.

private void writeEntities(Clipboard clipboard, Map<String, Tag> schematic) {
    List<CompoundTag> entities = clipboard.getEntities().stream().map(e -> {
        BaseEntity state = e.getState();
        if (state == null) {
            return null;
        }
        Map<String, Tag> values = Maps.newHashMap();
        CompoundTag rawData = state.getNbtData();
        if (rawData != null) {
            values.putAll(rawData.getValue());
        }
        values.remove("id");
        values.put("Id", new StringTag(state.getType().getId()));
        final Location location = e.getLocation();
        values.put("Pos", writeVector(location.toVector()));
        values.put("Rotation", writeRotation(location));
        return new CompoundTag(values);
    }).filter(Objects::nonNull).collect(Collectors.toList());
    if (entities.isEmpty()) {
        return;
    }
    schematic.put("Entities", new ListTag(CompoundTag.class, entities));
}
Also used : StringTag(com.sk89q.jnbt.StringTag) BaseEntity(com.sk89q.worldedit.entity.BaseEntity) StringTag(com.sk89q.jnbt.StringTag) ShortTag(com.sk89q.jnbt.ShortTag) IntArrayTag(com.sk89q.jnbt.IntArrayTag) ListTag(com.sk89q.jnbt.ListTag) IntTag(com.sk89q.jnbt.IntTag) ByteArrayTag(com.sk89q.jnbt.ByteArrayTag) CompoundTag(com.sk89q.jnbt.CompoundTag) Tag(com.sk89q.jnbt.Tag) ListTag(com.sk89q.jnbt.ListTag) CompoundTag(com.sk89q.jnbt.CompoundTag) Location(com.sk89q.worldedit.util.Location)

Example 47 with Location

use of com.sk89q.worldedit.util.Location in project FastAsyncWorldEdit by IntellectualSites.

the class ExtentEntityCopy method transformNbtData.

/**
 * Transform NBT data in the given entity state and return a new instance
 * if the NBT data needs to be transformed.
 *
 * @param state the existing state
 * @return a new state or the existing one
 */
private BaseEntity transformNbtData(BaseEntity state) {
    CompoundTag tag = state.getNbtData();
    if (tag != null) {
        // Handle leashed entities
        Tag leashTag = tag.getValue().get("Leash");
        if (leashTag instanceof CompoundTag) {
            CompoundTag leashCompound = (CompoundTag) leashTag;
            if (leashCompound.containsKey("X")) {
                // leashed to a fence
                Vector3 tilePosition = Vector3.at(leashCompound.asInt("X"), leashCompound.asInt("Y"), leashCompound.asInt("Z"));
                BlockVector3 newLeash = transform.apply(tilePosition.subtract(from)).add(to).toBlockPoint();
                return new BaseEntity(state.getType(), tag.createBuilder().put("Leash", leashCompound.createBuilder().putInt("X", newLeash.getBlockX()).putInt("Y", newLeash.getBlockY()).putInt("Z", newLeash.getBlockZ()).build()).build());
            }
        }
        // Handle hanging entities (paintings, item frames, etc.)
        boolean hasTilePosition = tag.containsKey("TileX") && tag.containsKey("TileY") && tag.containsKey("TileZ");
        boolean hasFacing = tag.containsKey("Facing");
        // FAWE Start
        boolean hasRotation = tag.containsKey("Rotation");
        if (hasTilePosition) {
            Vector3 tilePosition = Vector3.at(tag.asInt("TileX"), tag.asInt("TileY"), tag.asInt("TileZ"));
            BlockVector3 newTilePosition = transform.apply(tilePosition.subtract(from)).add(to).toBlockPoint();
            CompoundTagBuilder builder = tag.createBuilder().putInt("TileX", newTilePosition.getBlockX()).putInt("TileY", newTilePosition.getBlockY()).putInt("TileZ", newTilePosition.getBlockZ());
            if (hasFacing) {
                // Paintings have different facing values
                boolean isPainting = state.getType() == EntityTypes.PAINTING;
                Direction direction = isPainting ? MCDirections.fromHorizontalHanging(tag.asInt("Facing")) : MCDirections.fromHanging(tag.asInt("Facing"));
                if (direction != null) {
                    Vector3 vector = transform.apply(direction.toVector()).subtract(transform.apply(Vector3.ZERO)).normalize();
                    Direction newDirection = Direction.findClosest(vector, Flag.CARDINAL);
                    if (newDirection != null) {
                        builder.putByte("Facing", (byte) (isPainting ? MCDirections.toHorizontalHanging(newDirection) : MCDirections.toHanging(newDirection)));
                    }
                }
            }
            // FAWE start
            if (hasRotation) {
                ListTag orgrot = state.getNbtData().getListTag("Rotation");
                Vector3 orgDirection = new Location(source, 0, 0, 0, orgrot.getFloat(0), orgrot.getFloat(1)).getDirection();
                Vector3 newDirection = transform.apply(orgDirection).subtract(transform.apply(Vector3.ZERO)).normalize();
                builder.put("Rotation", new ListTag(FloatTag.class, Arrays.asList(new FloatTag((float) newDirection.toYaw()), new FloatTag((float) newDirection.toPitch()))));
            }
            return new BaseEntity(state.getType(), builder.build());
        } else if (hasRotation) {
            // armor stands do not have a tile pos
            CompoundTagBuilder builder = tag.createBuilder();
            ListTag orgrot = state.getNbtData().getListTag("Rotation");
            Vector3 orgDirection = new Location(source, 0, 0, 0, orgrot.getFloat(0), orgrot.getFloat(1)).getDirection();
            Vector3 newDirection = transform.apply(orgDirection).subtract(transform.apply(Vector3.ZERO)).normalize();
            builder.put("Rotation", new ListTag(FloatTag.class, Arrays.asList(new FloatTag((float) newDirection.toYaw()), new FloatTag((float) newDirection.toPitch()))));
            return new BaseEntity(state.getType(), builder.build());
        // FAWE end
        }
    }
    return state;
}
Also used : FloatTag(com.sk89q.jnbt.FloatTag) BaseEntity(com.sk89q.worldedit.entity.BaseEntity) BlockVector3(com.sk89q.worldedit.math.BlockVector3) Vector3(com.sk89q.worldedit.math.Vector3) ListTag(com.sk89q.jnbt.ListTag) FloatTag(com.sk89q.jnbt.FloatTag) CompoundTag(com.sk89q.jnbt.CompoundTag) Tag(com.sk89q.jnbt.Tag) BlockVector3(com.sk89q.worldedit.math.BlockVector3) Direction(com.sk89q.worldedit.util.Direction) ListTag(com.sk89q.jnbt.ListTag) CompoundTag(com.sk89q.jnbt.CompoundTag) CompoundTagBuilder(com.sk89q.jnbt.CompoundTagBuilder) Location(com.sk89q.worldedit.util.Location)

Example 48 with Location

use of com.sk89q.worldedit.util.Location in project FastAsyncWorldEdit by IntellectualSites.

the class DiskOptimizedClipboard method removeEntity.

@Override
public void removeEntity(Entity entity) {
    if (!(entity instanceof BlockArrayClipboard.ClipboardEntity)) {
        Location loc = entity.getLocation();
        removeEntity(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), entity.getState().getNbtData().getUUID());
    } else {
        this.entities.remove(entity);
    }
}
Also used : Location(com.sk89q.worldedit.util.Location)

Example 49 with Location

use of com.sk89q.worldedit.util.Location in project FastAsyncWorldEdit by IntellectualSites.

the class SelectionCommands method pos2.

@Command(name = "/pos2", aliases = "/2", desc = "Set position 2")
@Logging(POSITION)
@CommandPermissions("worldedit.selection.pos")
public void pos2(Actor actor, World world, LocalSession session, @Arg(desc = "Coordinates to set position 2 to", def = "") BlockVector3 coordinates) throws WorldEditException {
    Location pos;
    if (coordinates != null) {
        // FAWE start - clamp
        pos = new Location(world, coordinates.toVector3().clampY(world.getMinY(), world.getMaxY()));
    } else if (actor instanceof Locatable) {
        pos = ((Locatable) actor).getBlockLocation().clampY(world.getMinY(), world.getMaxY());
    // Fawe end
    } else {
        actor.print(Caption.of("worldedit.pos.console-require-coords"));
        return;
    }
    if (!session.getRegionSelector(world).selectSecondary(pos.toVector().toBlockPoint(), ActorSelectorLimits.forActor(actor))) {
        actor.print(Caption.of("worldedit.pos.already-set"));
        return;
    }
    session.getRegionSelector(world).explainSecondarySelection(actor, session, pos.toVector().toBlockPoint());
}
Also used : Location(com.sk89q.worldedit.util.Location) Locatable(com.sk89q.worldedit.extension.platform.Locatable) Logging(com.sk89q.worldedit.command.util.Logging) Command(org.enginehub.piston.annotation.Command) CommandPermissions(com.sk89q.worldedit.command.util.CommandPermissions)

Example 50 with Location

use of com.sk89q.worldedit.util.Location in project FastAsyncWorldEdit by IntellectualSites.

the class LongRangeBuildTool method getTargetFace.

private Location getTargetFace(Player player) {
    Location target;
    Mask mask = getTraceMask();
    if (this.range > -1) {
        target = player.getBlockTrace(getRange(), true, mask);
    } else {
        target = player.getBlockTrace(MAX_RANGE, false, mask);
    }
    if (target == null) {
        player.print(Caption.of("worldedit.tool.no-block"));
        return null;
    }
    return target;
}
Also used : Mask(com.sk89q.worldedit.function.mask.Mask) 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