org.bukkit.craftbukkit.v1_12_R1.CraftWorld#com.sk89q.worldedit.blocks.BaseBlock源码实例Demo

下面列出了org.bukkit.craftbukkit.v1_12_R1.CraftWorld#com.sk89q.worldedit.blocks.BaseBlock 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

@Override
public boolean setBlock(int x, int y, int z, BaseBlock block) {
    try {
        int index = (HEADER_SIZE) + (getIndex(x, y, z) << 1);
        final int id = block.getId();
        final int data = block.getData();
        int combined = (id << 4) + data;
        mbb.putChar(index, (char) combined);
        CompoundTag tile = block.getNbtData();
        if (tile != null) {
            setTile(x, y, z, tile);
        }
        return true;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
源代码2 项目: FastAsyncWorldedit   文件: FaweClipboard.java
public List<CompoundTag> getTileEntities() {
    final List<CompoundTag> tiles = new ArrayList<>();
    forEach(new BlockReader() {
        private int index = 0;

        @Override
        public void run(int x, int y, int z, BaseBlock block) {
            CompoundTag tag = block.getNbtData();
            if (tag != null) {
                Map<String, Tag> values = ReflectionUtils.getMap(tag.getValue());
                values.put("x", new IntTag(x));
                values.put("y", new IntTag(y));
                values.put("z", new IntTag(z));
                tiles.add(tag);
            }
        }
    }, false);
    return tiles;
}
 
public void setMain(Pattern value) {
    if (value instanceof BaseBlock) {
        setMain(((BaseBlock) value).getCombined());
    } else {
        main.record(() -> {
            char[] mainArr = main.get();
            int index = 0;
            for (int z = 0; z < getLength(); z++) {
                mutable.mutZ(z);
                for (int x = 0; x < getWidth(); x++, index++) {
                    int y = heights.getByte(index) & 0xFF;
                    mutable.mutX(x);
                    mutable.mutY(y);
                    mainArr[index] = (char) value.apply(mutable).getCombined();
                }
            }
        });
    }
}
 
源代码4 项目: FastAsyncWorldedit   文件: FaweAdapter_1_9.java
public BaseBlock getBlock(Location location)
{
    Preconditions.checkNotNull(location);

    CraftWorld craftWorld = (CraftWorld)location.getWorld();
    int x = location.getBlockX();
    int y = location.getBlockY();
    int z = location.getBlockZ();

    Block bukkitBlock = location.getBlock();
    BaseBlock block = new BaseBlock(bukkitBlock.getTypeId(), bukkitBlock.getData());

    TileEntity te = craftWorld.getHandle().getTileEntity(new BlockPosition(x, y, z));
    if (te != null)
    {
        NBTTagCompound tag = new NBTTagCompound();
        readTileEntityIntoTag(te, tag);
        block.setNbtData((CompoundTag)toNative(tag));
    }
    return block;
}
 
源代码5 项目: FastAsyncWorldedit   文件: FaweQueue.java
default void forEachTileInChunk(int cx, int cz, RunnableVal2<Vector, BaseBlock> onEach) {
    int bx = cx << 4;
    int bz = cz << 4;
    MutableBlockVector mutable = new MutableBlockVector(0, 0, 0);
    for (int x = 0; x < 16; x++) {
        int xx = x + bx;
        for (int z = 0; z < 16; z++) {
            int zz = z + bz;
            for (int y = 0; y < getMaxY(); y++) {
                int combined = getCombinedId4Data(xx, y, zz);
                if (combined == 0) {
                    continue;
                }
                int id = FaweCache.getId(combined);
                if (FaweCache.hasNBT(id)) {
                    mutable.mutX(xx);
                    mutable.mutZ(zz);
                    mutable.mutY(y);
                    CompoundTag tile = getTileEntity(x, y, z);
                    BaseBlock block = new BaseBlock(id, FaweCache.getData(combined), tile);
                    onEach.run(mutable, block);
                }
            }
        }
    }
}
 
public void setOverlay(Mask mask, Pattern pattern) {
    if (pattern instanceof BaseBlock) {
        setOverlay(mask, (char) ((BaseBlock) pattern).getCombined());
    } else {
        int index = 0;
        if (overlay == null) overlay = new DifferentialArray<>(new char[getArea()]);
        for (int z = 0; z < getLength(); z++) {
            mutable.mutZ(z);
            for (int x = 0; x < getWidth(); x++, index++) {
                int y = heights.getByte(index) & 0xFF;
                mutable.mutX(x);
                mutable.mutY(y);
                if (mask.test(mutable)) {
                    overlay.setChar(index, (char) pattern.apply(mutable).getCombined());
                }
            }
        }
    }
}
 
源代码7 项目: FastAsyncWorldedit   文件: TextureUtil.java
public BaseBlock getNearestBlock(int color) {
    long min = Long.MAX_VALUE;
    int closest = 0;
    int red1 = (color >> 16) & 0xFF;
    int green1 = (color >> 8) & 0xFF;
    int blue1 = (color >> 0) & 0xFF;
    int alpha = (color >> 24) & 0xFF;
    for (int i = 0; i < validColors.length; i++) {
        int other = validColors[i];
        if (((other >> 24) & 0xFF) == alpha) {
            long distance = colorDistance(red1, green1, blue1, other);
            if (distance < min) {
                min = distance;
                closest = validBlockIds[i];
            }
        }
    }
    if (min == Long.MAX_VALUE) return null;
    return FaweCache.CACHE_BLOCK[closest];
}
 
源代码8 项目: FastAsyncWorldedit   文件: MCAWorld.java
@Override
public boolean clearContainerBlockContents(Vector position) {
    BaseBlock block = extent.getLazyBlock(position);
    if (block.hasNbtData()) {
        Map<String, Tag> nbt = ReflectionUtils.getMap(block.getNbtData().getValue());
        if (nbt.containsKey("Items")) {
            nbt.put("Items", new ListTag(CompoundTag.class, new ArrayList<CompoundTag>()));
            try {
                extent.setBlock(position, block);
            } catch (WorldEditException e) {
                e.printStackTrace();
            }
        }
    }
    return true;
}
 
public void setFloor(Pattern value) {
    if (value instanceof BaseBlock) {
        setFloor(((BaseBlock) value).getCombined());
    } else {
        floor.record(() -> {
            char[] floorArr = floor.get();
            int index = 0;
            for (int z = 0; z < getLength(); z++) {
                mutable.mutZ(z);
                for (int x = 0; x < getWidth(); x++, index++) {
                    int y = heights.getByte(index) & 0xFF;
                    mutable.mutX(x);
                    mutable.mutY(y);
                    floorArr[index] = (char) value.apply(mutable).getCombined();
                }
            }
        });
    }
}
 
源代码10 项目: FastAsyncWorldedit   文件: AngleColorPattern.java
@Override
public int getSlope(BaseBlock block, Vector vector) {
    int slope = super.getSlope(block, vector);
    if (slope != -1) {
        int x = vector.getBlockX();
        int y = vector.getBlockY();
        int z = vector.getBlockZ();
        int height = extent.getNearestSurfaceTerrainBlock(x, z, y, 0, maxY);
        if (height > 0) {
            BaseBlock below = extent.getLazyBlock(x, height - 1, z);
            if (FaweCache.canPassThrough(below.getId(), below.getData())) {
                return Integer.MAX_VALUE;
            }
        }
    }
    return slope;
}
 
源代码11 项目: FastAsyncWorldedit   文件: TextureUtil.java
public BaseBlock getNextNearestBlock(int color) {
    long min = Long.MAX_VALUE;
    int closest = 0;
    int red1 = (color >> 16) & 0xFF;
    int green1 = (color >> 8) & 0xFF;
    int blue1 = (color >> 0) & 0xFF;
    int alpha = (color >> 24) & 0xFF;
    for (int i = 0; i < validColors.length; i++) {
        int other = validColors[i];
        if (other != color && ((other >> 24) & 0xFF) == alpha) {
            long distance = colorDistance(red1, green1, blue1, other);
            if (distance < min) {
                min = distance;
                closest = validBlockIds[i];
            }
        }
    }
    if (min == Long.MAX_VALUE) return null;
    return FaweCache.CACHE_BLOCK[closest];
}
 
源代码12 项目: FastAsyncWorldedit   文件: HeightMapMCAGenerator.java
public void setColumn(Mask mask, Pattern pattern) {
    if (pattern instanceof BaseBlock) {
        setColumn(mask, (char) ((BaseBlock) pattern).getCombined());
    } else {
        primtives.modifiedMain = true;
        int index = 0;
        for (int z = 0; z < getLength(); z++) {
            mutable.mutZ(z);
            for (int x = 0; x < getWidth(); x++, index++) {
                int y = heights.getByte(index) & 0xFF;
                mutable.mutX(x);
                mutable.mutY(y);
                if (mask.test(mutable)) {
                    char combined = (char) pattern.apply(mutable).getCombined();
                    floor.setChar(index, combined);
                    main.setChar(index, combined);
                }
            }
        }
    }
}
 
源代码13 项目: FastAsyncWorldedit   文件: MemoryCheckingExtent.java
@Override
public boolean setBlock(final Vector location, final BaseBlock block) throws WorldEditException {
    if (super.setBlock(location, block)) {
        if (MemUtil.isMemoryLimited()) {
            if (this.player != null) {
                player.sendMessage(BBC.WORLDEDIT_CANCEL_REASON.format(BBC.WORLDEDIT_CANCEL_REASON_LOW_MEMORY.s()));
                if (Perm.hasPermission(this.player, "worldedit.fast")) {
                    BBC.WORLDEDIT_OOM_ADMIN.send(this.player);
                }
            }
            WEManager.IMP.cancelEdit(this, BBC.WORLDEDIT_CANCEL_REASON_LOW_MEMORY);
            return false;
        }
        return true;
    }
    return false;
}
 
源代码14 项目: FastAsyncWorldedit   文件: SimpleWorld.java
@Override
default Mask createLiquidMask() {
    return new BlockMask(this,
            new BaseBlock(BlockID.STATIONARY_LAVA, -1),
            new BaseBlock(BlockID.LAVA, -1),
            new BaseBlock(BlockID.STATIONARY_WATER, -1),
            new BaseBlock(BlockID.WATER, -1));
}
 
源代码15 项目: FastAsyncWorldedit   文件: EditSession.java
/**
 * Set a block, bypassing both history and block re-ordering.
 *
 * @param position the position to set the block at
 * @param block    the block
 * @param stage    the level
 * @return whether the block changed
 * @throws WorldEditException thrown on a set error
 */
public boolean setBlock(final Vector position, final BaseBlock block, final Stage stage) throws WorldEditException {
    this.changes++;
    switch (stage) {
        case BEFORE_HISTORY:
            return this.extent.setBlock(position, block);
        case BEFORE_CHANGE:
            return this.bypassHistory.setBlock(position, block);
        case BEFORE_REORDER:
            return this.bypassAll.setBlock(position, block);
    }

    throw new RuntimeException("New enum entry added that is unhandled here");
}
 
源代码16 项目: FastAsyncWorldedit   文件: BlockBagChangeSet.java
@Override
public void add(Vector loc, BaseBlock from, BaseBlock to) {
    int x = loc.getBlockX();
    int y = loc.getBlockY();
    int z = loc.getBlockZ();
    add(x, y, z, from, to);
}
 
源代码17 项目: FastAsyncWorldedit   文件: CFICommands.java
@Command(
        aliases = {"baseid", "bedrockid"},
        usage = "<block>",
        desc = "Change the block used for the base\n" +
                "e.g. Bedrock"
)
@CommandPermissions("worldedit.anvil.cfi")
public void baseId(FawePlayer fp, BaseBlock block) throws ParameterException, WorldEditException {
    CFISettings settings = assertSettings(fp);
    settings.getGenerator().setBedrockId(block.getId());
    msg("Set base id!").send(fp);
    settings.resetComponent();
    component(fp);
}
 
源代码18 项目: FastAsyncWorldedit   文件: EditSession.java
/**
 * Remove a cuboid below the given position with a given apothem and a given height.
 *
 * @param position base position
 * @param apothem  an apothem of the cuboid (on the XZ plane), where the minimum is 1
 * @param height   the height of the cuboid, where the minimum is 1
 * @return number of blocks affected
 * @throws MaxChangedBlocksException thrown if too many blocks are changed
 */
@SuppressWarnings("deprecation")
public int removeBelow(final Vector position, final int apothem, final int height) {
    checkNotNull(position);
    checkArgument(apothem >= 1, "apothem >= 1");
    checkArgument(height >= 1, "height >= 1");

    final Region region = new CuboidRegion(this.getWorld(), // Causes clamping of Y range
            position.add(-apothem + 1, 0, -apothem + 1), position.add(apothem - 1, -height + 1, apothem - 1));
    final Pattern pattern = (new BaseBlock(BlockID.AIR));
    return this.setBlocks(region, pattern);
}
 
源代码19 项目: FastAsyncWorldedit   文件: BukkitWorld.java
@Override
public boolean setBlock(Vector position, BaseBlock block, boolean notifyAndLight) throws WorldEditException {
    BukkitImplAdapter adapter = BukkitQueue_0.getAdapter();
    if (adapter != null) {
        return adapter.setBlock(adapt(getWorld(), position), block, notifyAndLight);
    } else {
        Block bukkitBlock = getWorld().getBlockAt(position.getBlockX(), position.getBlockY(), position.getBlockZ());
        return bukkitBlock.setTypeIdAndData(block.getType(), (byte) block.getData(), notifyAndLight);
    }
}
 
源代码20 项目: FastAsyncWorldedit   文件: BundledBlockData.java
@Override
public boolean set(BaseBlock block) {
    if (data != null) {
        block.setData((block.getData() & ~state.getDataMask()) | data);
        return true;
    } else {
        return false;
    }
}
 
源代码21 项目: FastAsyncWorldedit   文件: Functions.java
@Dynamic
public static double query(RValue x, RValue y, RValue z, RValue type, RValue data) throws EvaluationException {
    final double xp = x.getValue();
    final double yp = y.getValue();
    final double zp = z.getValue();

    final ExpressionEnvironment environment = Expression.getInstance().getEnvironment();

    // Read values from world
    BaseBlock block = environment.getBlock(xp, yp, zp);
    int typeId = block.getId();
    int dataValue = block.getData();

    return queryInternal(type, data, typeId, dataValue);
}
 
源代码22 项目: FastAsyncWorldedit   文件: NukkitUtil.java
public static boolean setBlock(Level level, Vector pos, BaseBlock block) {
    int x = pos.getBlockX();
    int y = pos.getBlockY();
    int z = pos.getBlockZ();
    level.setBlockIdAt(x, y, z, block.getId());
    level.setBlockDataAt(x, y, z, block.getData());
    return true;

}
 
源代码23 项目: FastAsyncWorldedit   文件: IdDataMaskPattern.java
@Override
public BaseBlock apply(Vector position) {
    BaseBlock oldBlock = getExtent().getBlock(position);
    BaseBlock newBlock = pattern.apply(position);
    int oldData = oldBlock.getData();
    int newData = newBlock.getData() + oldData - (oldData & bitMask);
    return FaweCache.getBlock(newBlock.getId(), newData);
}
 
源代码24 项目: FastAsyncWorldedit   文件: SimpleWorld.java
@Override
default boolean setTypeIdAndData(Vector position, int type, int data) {
    try {
        return setBlock(position, new BaseBlock(type, data));
    } catch (WorldEditException ignored) {
        return false;
    }
}
 
源代码25 项目: FastAsyncWorldedit   文件: HeightMapMCAGenerator.java
public void setColumn(BufferedImage img, Pattern pattern, boolean white) {
    if (pattern instanceof BaseBlock) {
        setColumn(img, (char) ((BaseBlock) pattern).getCombined(), white);
    } else {
        if (img.getWidth() != getWidth() || img.getHeight() != getLength())
            throw new IllegalArgumentException("Input image dimensions do not match the current height map!");
        primtives.modifiedMain = true;

        main.record(() -> floor.record(() -> {
            char[] floorArr = floor.get();
            char[] mainArr = main.get();
            int index = 0;
            for (int z = 0; z < getLength(); z++) {
                mutable.mutZ(z);
                for (int x = 0; x < getWidth(); x++, index++) {
                    int height = img.getRGB(x, z) & 0xFF;
                    if (height == 255 || height > 0 && !white && PseudoRandom.random.nextInt(256) <= height) {
                        mutable.mutX(x);
                        mutable.mutY(height);
                        char combined = (char) pattern.apply(mutable).getCombined();
                        mainArr[index] = combined;
                        floorArr[index] = combined;
                    }
                }
            }
        }));
    }
}
 
源代码26 项目: FastAsyncWorldedit   文件: Linear3DBlockPattern.java
@Override
public BaseBlock apply(Vector position) {
    int index = (position.getBlockX() + position.getBlockY() + position.getBlockZ()) % patternsArray.length;
    if (index < 0) {
        index += patternsArray.length;
    }
    return patternsArray[index].apply(position);
}
 
源代码27 项目: FastAsyncWorldedit   文件: LinearBlockPattern.java
@Override
public BaseBlock apply(Vector position) {
    if (index == patternsArray.length) {
        index = 0;
    }
    return patternsArray[index++].apply(position);
}
 
源代码28 项目: FastAsyncWorldedit   文件: SaturatePattern.java
@Override
public boolean apply(Extent extent, Vector setPosition, Vector getPosition) throws WorldEditException {
    BaseBlock block = extent.getBlock(getPosition);
    TextureUtil util = holder.getTextureUtil();
    int currentColor = util.getColor(block);
    if (currentColor == 0) return false;
    int newColor = util.multiplyColor(currentColor, color);
    BaseBlock newBlock = util.getNearestBlock(newColor);
    if (newBlock.equals(block)) return false;
    return extent.setBlock(setPosition, newBlock);
}
 
源代码29 项目: FastAsyncWorldedit   文件: HistoryExtent.java
@Override
public boolean setBlock(int x, int y, int z, BaseBlock block) throws WorldEditException {
    int combined = queue.getCombinedId4DataDebug(x, y, z, 0, session);
    int id = (combined >> 4);
    if (id == block.getId()) {
        if (!FaweCache.hasData(id)) {
            if (!block.hasNbtData()) {
                return false;
            }
        } else if (!block.hasNbtData()) {
            int data = combined & 0xF;
            if (data == block.getData()) {
                return false;
            }
        }
    }
    try {
        if (!FaweCache.hasNBT(id)) {
            if (block.canStoreNBTData()) {
                this.changeSet.add(x, y, z, combined, block);
            } else {
                this.changeSet.add(x, y, z, combined, (block.getId() << 4) + block.getData());
            }
        } else {
            try {
                CompoundTag tag = queue.getTileEntity(x, y, z);
                this.changeSet.add(x, y, z, new BaseBlock(id, combined & 0xF, tag), block);
            } catch (Throwable e) {
                e.printStackTrace();
                this.changeSet.add(x, y, z, combined, block);
            }
        }
    } catch (FaweException ignore) {
        return false;
    }
    return getExtent().setBlock(x, y, z, block);
}
 
源代码30 项目: FastAsyncWorldedit   文件: AngleColorPattern.java
@Override
public boolean apply(Extent extent, Vector setPosition, Vector getPosition) throws WorldEditException {
    BaseBlock block = extent.getBlock(getPosition);
    int slope = getSlope(block, getPosition);
    if (slope == -1) return false;
    int color = util.getTextureUtil().getColor(block);
    if (color == 0) return false;
    int newColor = getColor(color, slope);
    BaseBlock newBlock = util.getTextureUtil().getNearestBlock(newColor);
    if (newBlock == null) return false;
    return extent.setBlock(setPosition, newBlock);
}