Java Code Examples for com.sk89q.worldedit.blocks.BaseBlock#getId()

The following examples show how to use com.sk89q.worldedit.blocks.BaseBlock#getId() . 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: BundledBlockData.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
public String getName(BaseBlock block) {
    BlockEntry entry = legacyMap[block.getId()];
    if (entry != null) {
        String name = entry.id;
        if (block.getData() == 0) return name;
        StringBuilder append = new StringBuilder();
        Map<String, FaweState> states = entry.states;
        FaweState variants = states.get("variant");
        if (variants == null) variants = states.get("color");
        if (variants == null && !states.isEmpty()) variants = states.entrySet().iterator().next().getValue();
        if (variants != null) {
            for (Map.Entry<String, FaweStateValue> variant : variants.valueMap().entrySet()) {
                FaweStateValue state = variant.getValue();
                if (state.isSet(block)) {
                    append.append(append.length() == 0 ? ":" : "|");
                    append.append(variant.getKey());
                }
            }
        }
        if (append.length() == 0) return name + ":" + block.getData();
        return name + append;
    }
    if (block.getData() == 0) return Integer.toString(block.getId());
    return block.getId() + ":" + block.getData();
}
 
Example 2
Source File: MappedReplacePatternFilter.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void applyBlock(int x, int y, int z, BaseBlock block, MutableLong ignore) {
    int id = block.getId();
    int data = FaweCache.hasData(id) ? block.getData() : 0;
    int combined = FaweCache.getCombined(id, data);
    Pattern p = map[combined];
    if (p != null) {
        BaseBlock newBlock = p.apply(x, y, z);
        int currentId = block.getId();
        if (FaweCache.hasNBT(currentId)) {
            block.setNbtData(null);
        }
        block.setId(newBlock.getId());
        block.setData(newBlock.getData());
    }
}
 
Example 3
Source File: CavesGen.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
protected boolean isSuitableBlock(BaseBlock material, BaseBlock materialAbove) {
    switch (material.getId()) {
        case 0:
        case 8:
        case 9:
        case 10:
        case 11:
        case 7:
            return false;
        default:
            return true;
    }
}
 
Example 4
Source File: BlockMask.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
public void add(BaseBlock block) {
    blockIds[block.getId()] = true;
    if (block.getData() == -1) {
        for (int data = 0; data < 16; data++) {
            blocks[FaweCache.getCombined(block.getId(), data)] = true;
        }
    } else {
        blocks[FaweCache.getCombined(block)] = true;
    }
    computedLegacyList = null;
}
 
Example 5
Source File: EditSession.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
public int fall(final Region region, boolean fullHeight, final BaseBlock replace) {
    FlatRegion flat = asFlatRegion(region);
    final int startPerformY = region.getMinimumPoint().getBlockY();
    final int startCheckY = fullHeight ? 0 : startPerformY;
    final int endY = region.getMaximumPoint().getBlockY();
    RegionVisitor visitor = new RegionVisitor(flat, new RegionFunction() {
        @Override
        public boolean apply(Vector pos) throws WorldEditException {
            int x = pos.getBlockX();
            int z = pos.getBlockZ();
            int freeSpot = startCheckY;
            for (int y = startCheckY; y <= endY; y++) {
                if (y < startPerformY) {
                    if (getLazyBlock(x, y, z).getId() != 0) {
                        freeSpot = y + 1;
                    }
                    continue;
                }
                BaseBlock block = getLazyBlock(x, y, z);
                if (block.getId() != 0) {
                    if (freeSpot != y) {
                        setBlock(x, freeSpot, z, block);
                        setBlock(x, y, z, replace);
                    }
                    freeSpot++;
                }
            }
            return true;
        }
    }, this);
    Operations.completeBlindly(visitor);
    return this.changes;
}
 
Example 6
Source File: AbstractPlayerActor.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean ascendLevel() {
    final WorldVector pos = getBlockIn();
    final int x = pos.getBlockX();
    int y = Math.max(0, pos.getBlockY());
    final int z = pos.getBlockZ();
    final World world = pos.getWorld();

    byte free = 0;
    byte spots = 0;

    while (y <= world.getMaxY() + 2) {
        if (BlockType.canPassThrough(world.getBlock(new Vector(x, y, z)))) {
            ++free;
        } else {
            free = 0;
        }

        if (free == 2) {
            ++spots;
            if (spots == 2) {
                final Vector platform = new Vector(x, y - 2, z);
                final BaseBlock block = world.getBlock(platform);
                final int type = block.getId();

                // Don't get put in lava!
                if (type == BlockID.LAVA || type == BlockID.STATIONARY_LAVA) {
                    return false;
                }

                setPosition(platform.add(0.5, BlockType.centralTopLimit(block), 0.5));
                return true;
            }
        }

        ++y;
    }

    return false;
}
 
Example 7
Source File: ReplacePatternFilter.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void applyBlock(int x, int y, int z, BaseBlock block, MutableLong ignore) {
    if (matchFrom.apply(block)) {
        BaseBlock newBlock = to.apply(x, y, z);
        int currentId = block.getId();
        if (FaweCache.hasNBT(currentId)) {
            block.setNbtData(null);
        }
        block.setId(newBlock.getId());
        block.setData(newBlock.getData());
    }
}
 
Example 8
Source File: FaweChangeSet.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
public void add(int x, int y, int z, int combinedFrom, BaseBlock to) {
    try {
        if (to.hasNbtData()) {
            CompoundTag nbt = to.getNbtData();
            MainUtil.setPosition(nbt, x, y, z);
            addTileCreate(nbt);
        }
        int combinedTo = (to.getId() << 4) + to.getData();
        add(x, y, z, combinedFrom, combinedTo);

    } catch (Exception e) {
        MainUtil.handleError(e);
    }
}
 
Example 9
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 10
Source File: CPUOptimizedClipboard.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
public boolean setBlock(int index, BaseBlock block) {
    int id = block.getId();
    setId(index, id);
    setData(index, block.getData());
    if (id >= 256) {
        setAdd(index, (id >> 8));
    }
    CompoundTag tile = block.getNbtData();
    if (tile != null) {
        setTile(index, tile);
    }
    return true;
}
 
Example 11
Source File: CuboidClipboard.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Get the block distribution inside a clipboard.
 *
 * @return a block distribution
 */
public List<Countable<Integer>> getBlockDistribution() {
    List<Countable<Integer>> distribution = new ArrayList<Countable<Integer>>();
    Map<Integer, Countable<Integer>> map = new HashMap<Integer, Countable<Integer>>();

    int maxX = getWidth();
    int maxY = getHeight();
    int maxZ = getLength();

    for (int x = 0; x < maxX; ++x) {
        for (int y = 0; y < maxY; ++y) {
            for (int z = 0; z < maxZ; ++z) {
                final BaseBlock block = getBlock(x, y, z);
                if (block == null) {
                    continue;
                }

                int id = block.getId();

                if (map.containsKey(id)) {
                    map.get(id).increment();
                } else {
                    Countable<Integer> c = new Countable<Integer>(id, 1);
                    map.put(id, c);
                    distribution.add(c);
                }
            }
        }
    }

    Collections.sort(distribution);
    // Collections.reverse(distribution);

    return distribution;
}
 
Example 12
Source File: Functions.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Dynamic
public static double queryAbs(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.getBlockAbs(xp, yp, zp);
    int typeId = block.getId();
    int dataValue = block.getData();

    return queryInternal(type, data, typeId, dataValue);
}
 
Example 13
Source File: ScalableHeightMap.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
public static ScalableHeightMap fromClipboard(Clipboard clipboard) {
    Vector dim = clipboard.getDimensions();
    byte[][] heightArray = new byte[dim.getBlockX()][dim.getBlockZ()];
    int minX = clipboard.getMinimumPoint().getBlockX();
    int minZ = clipboard.getMinimumPoint().getBlockZ();
    int minY = clipboard.getMinimumPoint().getBlockY();
    int maxY = clipboard.getMaximumPoint().getBlockY();
    int clipHeight = maxY - minY + 1;
    HashSet<IntegerPair> visited = new HashSet<>();
    for (Vector pos : clipboard.getRegion()) {
        IntegerPair pair = new IntegerPair(pos.getBlockX(), pos.getBlockZ());
        if (visited.contains(pair)) {
            continue;
        }
        visited.add(pair);
        int xx = pos.getBlockX();
        int zz = pos.getBlockZ();
        int highestY = minY;
        for (int y = minY; y <= maxY; y++) {
            pos.mutY(y);
            BaseBlock block = clipboard.getBlock(pos);
            if (block.getId() != 0) {
                highestY = y + 1;
            }
        }
        int pointHeight = Math.min(255, (256 * (highestY - minY)) / clipHeight);
        int x = xx - minX;
        int z = zz - minZ;
        heightArray[x][z] = (byte) pointHeight;
    }
    return new ArrayHeightMap(heightArray);
}
 
Example 14
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 15
Source File: CuboidClipboard.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Get the block distribution inside a clipboard with data values.
 *
 * @return a block distribution
 */
// TODO reduce code duplication
public List<Countable<BaseBlock>> getBlockDistributionWithData() {
    List<Countable<BaseBlock>> distribution = new ArrayList<Countable<BaseBlock>>();
    Map<BaseBlock, Countable<BaseBlock>> map = new HashMap<BaseBlock, Countable<BaseBlock>>();

    int maxX = getWidth();
    int maxY = getHeight();
    int maxZ = getLength();

    for (int x = 0; x < maxX; ++x) {
        for (int y = 0; y < maxY; ++y) {
            for (int z = 0; z < maxZ; ++z) {
                final BaseBlock block = getBlock(x, y, z);
                if (block == null) {
                    continue;
                }

                // Strip the block from metadata that is not part of our key
                final BaseBlock bareBlock = new BaseBlock(block.getId(), block.getData());

                if (map.containsKey(bareBlock)) {
                    map.get(bareBlock).increment();
                } else {
                    Countable<BaseBlock> c = new Countable<BaseBlock>(bareBlock, 1);
                    map.put(bareBlock, c);
                    distribution.add(c);
                }
            }
        }
    }

    Collections.sort(distribution);
    // Collections.reverse(distribution);

    return distribution;
}
 
Example 16
Source File: CountIdFilter.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
public CountIdFilter addBlock(BaseBlock block) {
    allowedId[block.getId()] = true;
    return this;
}
 
Example 17
Source File: EditSession.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Make dirt green.
 *
 * @param position       a position
 * @param radius         a radius
 * @param onlyNormalDirt only affect normal dirt (data value 0)
 * @return number of blocks affected
 * @throws MaxChangedBlocksException thrown if too many blocks are changed
 */
public int green(final Vector position, final double radius, final boolean onlyNormalDirt) {

    final double radiusSq = radius * radius;

    final int ox = position.getBlockX();
    final int oy = position.getBlockY();
    final int oz = position.getBlockZ();

    final BaseBlock grass = new BaseBlock(BlockID.GRASS);

    final int ceilRadius = (int) Math.ceil(radius);
    for (int x = ox - ceilRadius; x <= (ox + ceilRadius); ++x) {
        int dx = x - ox;
        int dx2 = dx * dx;
        for (int z = oz - ceilRadius; z <= (oz + ceilRadius); ++z) {
            int dz = z - oz;
            int dz2 = dz * dz;
            if (dx2 + dz2 > radiusSq) {
                continue;
            }
            loop:
            for (int y = maxY; y >= 1; --y) {
                BaseBlock block = getLazyBlock(x, y, z);
                final int id = block.getId();
                final int data = block.getData();

                switch (id) {
                    case BlockID.DIRT:
                        if (onlyNormalDirt && (data != 0)) {
                            break loop;
                        }
                        this.setBlock(x, y, z, grass);
                        break loop;

                    case BlockID.WATER:
                    case BlockID.STATIONARY_WATER:
                    case BlockID.LAVA:
                    case BlockID.STATIONARY_LAVA:
                        // break on liquids...
                        break loop;

                    default:
                        // ...and all non-passable blocks
                        if (!BlockType.canPassThrough(id, data)) {
                            break loop;
                        }
                }
            }
        }
    }

    return changes;
}
 
Example 18
Source File: BrushCommands.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
@Command(
        aliases = {"sphere", "s"},
        usage = "<pattern> [radius=2]",
        flags = "hf",
        desc = "Creates a sphere",
        help =
                "Creates a sphere.\n" +
                        "The -h flag creates hollow spheres instead." +
                        "The -f flag creates falling spheres.",
        min = 1,
        max = 2
)
@CommandPermissions("worldedit.brush.sphere")
public BrushSettings sphereBrush(Player player, EditSession editSession, LocalSession session, Pattern fill, @Optional("2") @Range(min=0) Expression radius, @Switch('h') boolean hollow, @Switch('f') boolean falling, CommandContext context) throws WorldEditException {
    checkMaxBrushRadius(radius);

    Brush brush;
    if (hollow) {
        brush = new HollowSphereBrush();
    } else {
        if (fill instanceof BaseBlock) {
            BaseBlock block = (BaseBlock) fill;
            switch (block.getId()) {
                case BlockID.SAND:
                case BlockID.GRAVEL:
                    BBC.BRUSH_TRY_OTHER.send(player);
                    falling = true;
                    break;
            }
        }
        if (falling) {
            brush = new FallingSphere();
        } else {
            brush = new SphereBrush();
        }

    }
    return set(session, context,
            brush)
            .setSize(radius)
            .setFill(fill);
}
 
Example 19
Source File: FlagRegenPercentage.java    From HeavySpleef with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void regenerate(Floor floor, EditSession session, RegenerationCause cause) {
	if (cause == RegenerationCause.COUNTDOWN) {
		return;
	}
	
	Region region = floor.getRegion();
	
	double percentage = getValue() / 100D;
	int area = region.getArea();
	
	int notRegenerating = area - (int) (percentage * area);
	
	Iterator<BlockVector> iterator = region.iterator();
	List<BlockVector> vectors = Lists.newArrayList();
	Map<BlockVector, BaseBlock> clipboardBlockCache = Maps.newHashMap();
	Clipboard clipboard = floor.getClipboard();
	
	while (iterator.hasNext()) {
		BlockVector vector = iterator.next();
		BaseBlock block = clipboard.getLazyBlock(vector);
		clipboardBlockCache.put(vector, block);
		
		if (block.getType() == AIR_ID) {
			continue;
		}
		
		vectors.add(vector);
	}
	
	for (int i = 0; i < notRegenerating; i++) {
		int rnd = random.nextInt(vectors.size());
		vectors.remove(rnd);
	}
	
	World world = region.getWorld();
	
	try {
		//Iterate over all remaining block vectors and regenerate these blocks
		for (BlockVector regeneratingBlock : vectors) {
			BaseBlock clipboardBlock = clipboardBlockCache.get(regeneratingBlock);
			BaseBlock worldBlock = world.getBlock(regeneratingBlock);
			
			int id = clipboardBlock.getId();
			int data = clipboardBlock.getData();
			
			worldBlock.setIdAndData(id, data);
			world.setBlock(regeneratingBlock, worldBlock);
		}
	} catch (WorldEditException e) {
		getHeavySpleef().getLogger().log(Level.SEVERE, "Failed to regenerate floor " + floor.getName() + " for game " + game.getName(), e);
	}
}
 
Example 20
Source File: FaweBlockMatcher.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean apply(BaseBlock block) {
    return block.getId() != 0;
}