@Override public BlockType getBlockType() { return this.blockState.getBlockType(); }
/** * The type of the Fuzzy BlockState * * @param state The state * @return The builder, for chaining */ public Builder type(BlockState state) { checkNotNull(state); this.type = state.getBlockType(); return this; }
@Override public boolean test(BlockVector3 vector) { return blocks.contains(getExtent().getBlock(vector).getBlockType()); }
@Override public boolean apply(BlockVector3 position) throws WorldEditException { BlockState blk = extent.getBlock(position); if (!separateStates) { blk = blk.getBlockType().getDefaultState(); } if (map.containsKey(blk)) { map.get(blk).increment(); } else { Countable<BlockState> c = new Countable<>(blk, 1); map.put(blk, c); distribution.add(c); } return true; }
/** * Stores a block as if it was mined. * * @param blockState the block state * @throws BlockBagException on error */ public void storeDroppedBlock(BlockState blockState) throws BlockBagException { BlockState dropped = blockState; // TODO BlockType.getBlockBagItem(id, data); if (dropped == null) return; if (dropped.getBlockType().getMaterial().isAir()) return; storeBlock(dropped); }
@Override public int getBlockType(double x, double y, double z) { return editSession.getBlock(toWorld(x, y, z)).getBlockType().getLegacyId(); }
@Override public int getBlockTypeAbs(double x, double y, double z) { return editSession.getBlock(toWorld(x, y, z)).getBlockType().getLegacyId(); }
@Override public int getBlockTypeRel(double x, double y, double z) { return editSession.getBlock(toWorld(x, y, z)).getBlockType().getLegacyId(); }
@Override public boolean apply(BlockVector3 position) throws WorldEditException { BlockState block = editSession.getBlock(position); if (block.getBlockType() == BlockTypes.GRASS_BLOCK) { editSession.setBlock(position.add(0, 1, 0), temperatePattern.apply(position)); return true; } else if (block.getBlockType() == BlockTypes.SAND) { editSession.setBlock(position.add(0, 1, 0), desertPattern.apply(position)); return true; } return false; }
/** * Set a block only if there's no block already there. * * @param position the position * @param block the block to set * @return if block was changed * @throws MaxChangedBlocksException thrown if too many blocks are changed */ private static <B extends BlockStateHolder<B>> boolean setBlockIfAir(EditSession session, BlockVector3 position, B block) throws MaxChangedBlocksException { return session.getBlock(position).getBlockType().getMaterial().isAir() && session.setBlock(position, block); }
@Override public boolean test(BlockVector3 vector) { Extent extent = getExtent(); BlockState block = extent.getBlock(vector); return block.getBlockType().getMaterial().isMovementBlocker(); }
/** * Set a block only if there's no block already there. * * @param position the position * @param block the block to set * @return if block was changed * @throws MaxChangedBlocksException thrown if too many blocks are changed */ private static <B extends BlockStateHolder<B>> boolean setBlockIfAir(EditSession session, BlockVector3 position, B block) throws MaxChangedBlocksException { return session.getBlock(position).getBlockType().getMaterial().isAir() && session.setBlock(position, block); } }
@Override public boolean test(BlockVector3 vector) { return !getExtent().getBlock(vector).getBlockType().getMaterial().isAir(); }
@Override public boolean isEmpty(int x, int y, int z) { return editSession.getBlock(BlockVector3.at(x, y, z)).getBlockType().getMaterial().isAir(); }
/** * Returns the block at the sight. Returns null if out of range or if no * viable target was found * * @return Block */ public Location getSolidTargetBlock() { while (getNextBlock() != null && !world.getBlock(targetPos).getBlockType().getMaterial().isMovementBlocker()) ; return getCurrentBlock(); }
/** * Returns the block at the sight. Returns null if out of range or if no * viable target was found * * @return Block */ public Location getTargetBlock() { while (getNextBlock() != null && world.getBlock(targetPos).getBlockType().getMaterial().isAir()) ; return getCurrentBlock(); }
@Override public boolean actSecondary(Platform server, LocalConfiguration config, Player player, LocalSession session, com.sk89q.worldedit.util.Location clicked) { BlockState targetBlock = player.getWorld().getBlock(clicked.toVector().toBlockPoint()); if (targetBlock != null) { pattern = new BlockPattern(targetBlock); player.print("Replacer tool switched to: " + targetBlock.getBlockType().getName()); } return true; }
@Override public void setOnGround(Location searchPos) { Extent world = searchPos.getExtent(); int x = searchPos.getBlockX(); int y = Math.max(0, searchPos.getBlockY()); int z = searchPos.getBlockZ(); while (y >= 0) { final BlockVector3 pos = BlockVector3.at(x, y, z); final BlockState id = world.getBlock(pos); if (id.getBlockType().getMaterial().isMovementBlocker()) { setPosition(Vector3.at(x + 0.5, y + 1, z + 0.5)); return; } --y; } }
@Override public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 position, B block) throws WorldEditException { BlockType existing = getExtent().getBlock(position).getBlockType(); if (existing.getMaterial().hasContainer()) { world.clearContainerBlockContents(position); // Clear the container block so that it doesn't drop items } else if (existing == BlockTypes.ICE) { world.setBlock(position, BlockTypes.AIR.getDefaultState()); // Ice turns until water so this has to be done first } return super.setBlock(position, block); }
@Override public void floatAt(int x, int y, int z, boolean alwaysGlass) { try { BlockVector3 spot = BlockVector3.at(x, y - 1, z); if (!getLocation().getExtent().getBlock(spot).getBlockType().getMaterial().isMovementBlocker()) { getLocation().getExtent().setBlock(spot, BlockTypes.GLASS.getDefaultState()); } } catch (WorldEditException e) { e.printStackTrace(); } setPosition(Vector3.at(x + 0.5, y, z + 0.5)); }