com.sk89q.worldedit.blocks.BaseBlock Java Examples

The following examples show how to use com.sk89q.worldedit.blocks.BaseBlock. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FaweAdapter_1_9.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
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;
}
 
Example #2
Source File: HeightMapMCAGenerator.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
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());
                }
            }
        }
    }
}
 
Example #3
Source File: TextureUtil.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
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];
}
 
Example #4
Source File: MCAWorld.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
@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;
}
 
Example #5
Source File: FaweQueue.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
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);
                }
            }
        }
    }
}
 
Example #6
Source File: AngleColorPattern.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
@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;
}
 
Example #7
Source File: TextureUtil.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
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];
}
 
Example #8
Source File: HeightMapMCAGenerator.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
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);
                }
            }
        }
    }
}
 
Example #9
Source File: HeightMapMCAGenerator.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
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();
                }
            }
        });
    }
}
 
Example #10
Source File: FaweClipboard.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
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;
}
 
Example #11
Source File: HeightMapMCAGenerator.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
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();
                }
            }
        });
    }
}
 
Example #12
Source File: DiskOptimizedClipboard.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
@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);
    }
}
 
Example #13
Source File: MemoryCheckingExtent.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
@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;
}
 
Example #14
Source File: CFICommands.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@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);
}
 
Example #15
Source File: RecursivePickaxe.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean actPrimary(Platform server, LocalConfiguration config, Player player, LocalSession session, com.sk89q.worldedit.util.Location clicked) {
    World world = (World) clicked.getExtent();
    final Vector pos = clicked.toVector();

    EditSession editSession = session.createEditSession(player);

    BaseBlock block = editSession.getBlock(pos);
    int initialType = block.getType();

    if (initialType == BlockID.AIR || (initialType == BlockID.BEDROCK && !player.canDestroyBedrock())) {
        editSession.flushQueue();
        return true;
    }

    editSession.getSurvivalExtent().setToolUse(config.superPickaxeManyDrop);

    final int radius = (int) range;
    final BlockReplace replace = new BlockReplace(editSession, (editSession.nullBlock));
    editSession.setMask((Mask) null);
    RecursiveVisitor visitor = new RecursiveVisitor(new IdMask(editSession), replace, radius, editSession);
    visitor.visit(pos);
    Operations.completeBlindly(visitor);

    editSession.flushQueue();
    session.remember(editSession);

    return true;
}
 
Example #16
Source File: EditSession.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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);
}
 
Example #17
Source File: EditSession.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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");
}
 
Example #18
Source File: BlockBagChangeSet.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@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);
}
 
Example #19
Source File: LocalSession.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
public BrushTool getBrushTool(BaseBlock item, Player player, boolean create) throws InvalidToolBindException {
    Tool tool = getTool(item, player);
    if ((tool == null || !(tool instanceof BrushTool))) {
        if (create) {
            tool = new BrushTool();
            setTool(item, tool, player);
        } else {
            return null;
        }
    }

    return (BrushTool) tool;
}
 
Example #20
Source File: SimpleWorld.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@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));
}
 
Example #21
Source File: Functions.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@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);
}
 
Example #22
Source File: NukkitUtil.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
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;

}
 
Example #23
Source File: AngleColorPattern.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@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);
}
 
Example #24
Source File: HistoryExtent.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@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);
}
 
Example #25
Source File: IdDataMaskPattern.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@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);
}
 
Example #26
Source File: SimpleWorld.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
default boolean setTypeIdAndData(Vector position, int type, int data) {
    try {
        return setBlock(position, new BaseBlock(type, data));
    } catch (WorldEditException ignored) {
        return false;
    }
}
 
Example #27
Source File: SaturatePattern.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@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);
}
 
Example #28
Source File: HeightMapMCAGenerator.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
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;
                    }
                }
            }
        }));
    }
}
 
Example #29
Source File: LinearBlockPattern.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public BaseBlock apply(Vector position) {
    if (index == patternsArray.length) {
        index = 0;
    }
    return patternsArray[index++].apply(position);
}
 
Example #30
Source File: Linear3DBlockPattern.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@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);
}