Search in sources :

Example 1 with TaxicabBlockIterator

use of net.glowstone.util.TaxicabBlockIterator in project Glowstone by GlowstoneMC.

the class BlockSponge method placeBlock.

@Override
public void placeBlock(GlowPlayer player, GlowBlockState state, BlockFace face, ItemStack holding, Vector clickedLoc) {
    // TODO: Move this to a new method when physics works and run this on neighbour change too.
    MaterialData data = holding.getData();
    if (!(data instanceof Sponge)) {
        warnMaterialData(Sponge.class, data);
        return;
    }
    Sponge sponge = (Sponge) data;
    if (sponge.getType() == SpongeType.NORMAL) {
        GlowBlock block = state.getBlock();
        TaxicabBlockIterator iterator = new TaxicabBlockIterator(block);
        iterator.setMaxDistance(7);
        iterator.setMaxBlocks(66);
        iterator.setValidator(new BlockMaterialValidator(WATER_MATERIALS));
        if (iterator.hasNext()) {
            sponge = sponge.clone();
            sponge.setType(SpongeType.WET);
            do {
                iterator.next().setType(Material.AIR);
            } while (iterator.hasNext());
        }
    }
    state.setType(Material.SPONGE);
    state.setData(sponge);
}
Also used : TaxicabBlockIterator(net.glowstone.util.TaxicabBlockIterator) GlowBlock(net.glowstone.block.GlowBlock) BlockMaterialValidator(net.glowstone.util.BlockMaterialValidator) Sponge(org.bukkit.material.Sponge) MaterialData(org.bukkit.material.MaterialData)

Aggregations

GlowBlock (net.glowstone.block.GlowBlock)1 BlockMaterialValidator (net.glowstone.util.BlockMaterialValidator)1 TaxicabBlockIterator (net.glowstone.util.TaxicabBlockIterator)1 MaterialData (org.bukkit.material.MaterialData)1 Sponge (org.bukkit.material.Sponge)1