当前位置: 首页>>代码示例>>Java>>正文


Java EditSession.getNearestSurfaceTerrainBlock方法代码示例

本文整理汇总了Java中com.sk89q.worldedit.EditSession.getNearestSurfaceTerrainBlock方法的典型用法代码示例。如果您正苦于以下问题:Java EditSession.getNearestSurfaceTerrainBlock方法的具体用法?Java EditSession.getNearestSurfaceTerrainBlock怎么用?Java EditSession.getNearestSurfaceTerrainBlock使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.sk89q.worldedit.EditSession的用法示例。


在下文中一共展示了EditSession.getNearestSurfaceTerrainBlock方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: build

import com.sk89q.worldedit.EditSession; //导入方法依赖的package包/类
@Override
public void build(EditSession editSession, Vector pos, Pattern pattern, double radius) throws MaxChangedBlocksException {
    int maxY = editSession.getMaxY();
    boolean vis = editSession.getExtent() instanceof VisualExtent;
    if (path.isEmpty() || !pos.equals(path.get(path.size() - 1))) {
        int max = editSession.getNearestSurfaceTerrainBlock(pos.getBlockX(), pos.getBlockZ(), pos.getBlockY(), 0, editSession.getMaxY());
        if (max == -1) return;
        pos.mutY(max);
        path.add(pos);
        editSession.getPlayer().sendMessage(BBC.getPrefix() + BBC.BRUSH_SPLINE_PRIMARY_2.s());
        if (!vis) return;
    }
    LocalBlockVectorSet vset = new LocalBlockVectorSet();
    final List<Node> nodes = new ArrayList<>(path.size());
    final KochanekBartelsInterpolation interpol = new KochanekBartelsInterpolation();

    for (final Vector nodevector : path) {
        final Node n = new Node(nodevector);
        n.setTension(tension);
        n.setBias(bias);
        n.setContinuity(continuity);
        nodes.add(n);
    }
    interpol.setNodes(nodes);
    final double splinelength = interpol.arcLength(0, 1);
    for (double loop = 0; loop <= 1; loop += 1D / splinelength / quality) {
        final Vector tipv = interpol.getPosition(loop);
        final int tipx = MathMan.roundInt(tipv.getX());
        final int tipz = (int) tipv.getZ();
        int tipy = MathMan.roundInt(tipv.getY());
        tipy = editSession.getNearestSurfaceTerrainBlock(tipx, tipz, tipy, 0, maxY);
        if (tipy == -1) continue;
        if (radius == 0) {
            editSession.setBlock(tipx, tipy, tipz, pattern.next(tipx, tipy, tipz));
        } else {
            vset.add(tipx, tipy, tipz);
        }
    }
    if (radius != 0) {
        double radius2 = (radius * radius);
        LocalBlockVectorSet newSet = new LocalBlockVectorSet();
        final int ceilrad = (int) Math.ceil(radius);
        for (final Vector v : vset) {
            final int tipx = v.getBlockX(), tipy = v.getBlockY(), tipz = v.getBlockZ();
            for (int loopx = tipx - ceilrad; loopx <= (tipx + ceilrad); loopx++) {
                for (int loopz = tipz - ceilrad; loopz <= (tipz + ceilrad); loopz++) {
                    if (MathMan.hypot2(loopx - tipx, 0, loopz - tipz) <= radius2) {
                        int y = editSession.getNearestSurfaceTerrainBlock(loopx, loopz, v.getBlockY(), 0, maxY);
                        if (y == -1) continue;
                        newSet.add(loopx, y, loopz);
                    }
                }
            }
        }
        editSession.setBlocks(newSet, pattern);
        if (!vis) path.clear();
    }
    editSession.getPlayer().sendMessage(BBC.getPrefix() + BBC.BRUSH_SPLINE_SECONDARY.s());
}
 
开发者ID:boy0001,项目名称:FastAsyncWorldedit,代码行数:60,代码来源:SurfaceSpline.java

示例2: HeightMap

import com.sk89q.worldedit.EditSession; //导入方法依赖的package包/类
public HeightMap(EditSession session, Region region, boolean naturalOnly, boolean layers) {
    checkNotNull(session);
    checkNotNull(region);

    this.session = session;
    this.region = region;

    this.width = region.getWidth();
    this.height = region.getLength();

    this.layers = layers;

    int minX = region.getMinimumPoint().getBlockX();
    int minY = region.getMinimumPoint().getBlockY();
    int minZ = region.getMinimumPoint().getBlockZ();
    int maxY = region.getMaximumPoint().getBlockY();

    data = new int[width * height];
    invalid = new boolean[data.length];

    if (layers) {
        Vector min = region.getMinimumPoint();
        Vector max = region.getMaximumPoint();
        int bx = min.getBlockX();
        int bz = min.getBlockZ();
        Iterable<Vector2D> flat = Regions.asFlatRegion(region).asFlatRegion();
        Iterator<Vector2D> iter = new Fast2DIterator(flat, session).iterator();
        int y = 0;
        MutableBlockVector mutable = new MutableBlockVector();
        while (iter.hasNext()) {
            Vector2D pos = iter.next();
            int x = pos.getBlockX();
            int z = pos.getBlockZ();
            y = session.getNearestSurfaceLayer(x, z, y, 0, maxY);
            data[(z - bz) * width + (x - bx)] = y;
        }
    } else {
        // Store current heightmap data
        int index = 0;
        if (naturalOnly) {
            for (int z = 0; z < height; ++z) {
                for (int x = 0; x < width; ++x, index++) {
                    data[index] = session.getHighestTerrainBlock(x + minX, z + minZ, minY, maxY, naturalOnly);
                }
            }
        } else {
            int yTmp = 255;
            for (int z = 0; z < height; ++z) {
                for (int x = 0; x < width; ++x, index++) {
                    yTmp = session.getNearestSurfaceTerrainBlock(x + minX, z + minZ, yTmp, minY, maxY, Integer.MIN_VALUE, Integer.MAX_VALUE);
                    switch (yTmp) {
                        case Integer.MIN_VALUE:
                            yTmp = minY;
                            invalid[index] = true;
                            break;
                        case Integer.MAX_VALUE:
                            yTmp = maxY;
                            invalid[index] = true;
                            break;
                    }
                    data[index] = yTmp;
                }
            }
        }
    }
}
 
开发者ID:boy0001,项目名称:FastAsyncWorldedit,代码行数:67,代码来源:HeightMap.java


注:本文中的com.sk89q.worldedit.EditSession.getNearestSurfaceTerrainBlock方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。