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

The following examples show how to use com.sk89q.worldedit.blocks.BaseBlock#getType() . 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: ArbitraryShape.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
private BaseBlock getMaterialCached(int x, int y, int z, Pattern pattern) {
    final int index = (y - cacheOffsetY) + (z - cacheOffsetZ) * cacheSizeY + (x - cacheOffsetX) * cacheSizeY * cacheSizeZ;

    final short cacheEntry = cache[index];
    switch (cacheEntry) {
        case 0:
            // unknown, fetch material
            final BaseBlock material = getMaterial(x, y, z, pattern.apply(new BlockVector(x, y, z)));
            if (material == null) {
                // outside
                cache[index] = -1;
                return null;
            }

            short newCacheEntry = (short) (material.getType() | ((material.getData() + 1) << 8));
            if (newCacheEntry == 0) {
                // type and data 0
                newCacheEntry = -2;
            }

            cache[index] = newCacheEntry;
            return material;

        case -1:
            // outside
            return null;

        case -2:
            // type and data 0
            return new BaseBlock(0, 0);
    }

    return new BaseBlock(cacheEntry & 255, ((cacheEntry >> 8) - 1) & 15);
}
 
Example 2
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 3
Source File: ErodeBrush.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
public void fillIteration(int brushSize, int brushSizeSquared, int fillFaces, FaweClipboard current, FaweClipboard target) {
    int[] frequency = null;
    for (int x = -brushSize; x <= brushSize; x++) {
        int x2 = x * x;
        for (int z = -brushSize; z <= brushSize; z++) {
            int x2y2 = x2 + z * z;
            for (int y = -brushSize; y <= brushSize; y++) {
                int cube = x2y2 + y * y;
                target.setBlock(x, y, z, current.getBlock(x, y, z));
                if (cube >= brushSizeSquared) {
                    continue;
                }
                BaseBlock state = current.getBlock(x, y, z);
                if (!FaweCache.isLiquidOrGas(state.getId())) {
                    continue;
                }
                int total = 0;
                int highest = 1;
                BaseBlock highestState = state;
                if (frequency == null) {
                    frequency = new int[4096];
                } else {
                    Arrays.fill(frequency, 0);
                }
                for (Vector offs : FACES_TO_CHECK) {
                    BaseBlock next = current.getBlock(x + offs.getBlockX(), y + offs.getBlockY(), z + offs.getBlockZ());
                    if (FaweCache.isLiquidOrGas(next.getId())) {
                        continue;
                    }
                    total++;
                    int count = ++frequency[next.getType()];
                    if (count >= highest) {
                        highest = count;
                        highestState = next;
                    }
                }
                if (total >= fillFaces) {
                    target.setBlock(x, y, z, highestState);
                }
            }
        }
    }
}
 
Example 4
Source File: ErodeBrush.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
public void erosionIteration(int brushSize, int brushSizeSquared, int erodeFaces, FaweClipboard current, FaweClipboard target) {
    int[] frequency = null;
    for (int x = -brushSize; x <= brushSize; x++) {
        int x2 = x * x;
        for (int z = -brushSize; z <= brushSize; z++) {
            int x2y2 = x2 + z * z;
            for (int y = -brushSize; y <= brushSize; y++) {
                int cube = x2y2 + y * y;
                target.setBlock(x, y, z, current.getBlock(x, y, z));
                if (cube >= brushSizeSquared) {
                    continue;
                }
                BaseBlock state = current.getBlock(x, y, z);
                if (FaweCache.isLiquidOrGas(state.getId())) {
                    continue;
                }
                int total = 0;
                int highest = 1;
                int highestState = state.getType();
                if (frequency == null) {
                    frequency = new int[4096];
                } else {
                    Arrays.fill(frequency, 0);
                }
                for (Vector offs : FACES_TO_CHECK) {
                    BaseBlock next = current.getBlock(x + offs.getBlockX(), y + offs.getBlockY(), z + offs.getBlockZ());
                    if (!FaweCache.isLiquidOrGas(next.getId())) {
                        continue;
                    }
                    total++;
                    int count = ++frequency[next.getType()];
                    if (count > highest) {
                        highest = count;
                        highestState = next.getType();
                    }
                }
                if (total >= erodeFaces) {
                    target.setBlock(x, y, z, FaweCache.CACHE_BLOCK[highestState << 4]);
                }
            }
        }
    }
}
 
Example 5
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);
	}
}