Search in sources :

Example 26 with BlockState

use of org.bukkit.block.BlockState in project Glowstone by GlowstoneMC.

the class MushroomDecorator method decorate.

@Override
public void decorate(World world, Random random, Chunk source) {
    int sourceX = (source.getX() << 4) + random.nextInt(16);
    int sourceZ = (source.getZ() << 4) + random.nextInt(16);
    int sourceY = random.nextInt(128);
    for (int i = 0; i < 64; i++) {
        int x = sourceX + random.nextInt(8) - random.nextInt(8);
        int z = sourceZ + random.nextInt(8) - random.nextInt(8);
        int y = sourceY + random.nextInt(4) - random.nextInt(4);
        Block block = world.getBlockAt(x, y, z);
        Block blockBelow = world.getBlockAt(x, y - 1, z);
        if (y < 128 && block.getType() == Material.AIR && Arrays.asList(MATERIALS).contains(blockBelow.getType())) {
            BlockState state = block.getState();
            state.setType(type);
            state.setData(new MaterialData(type));
            state.update(true);
        }
    }
}
Also used : BlockState(org.bukkit.block.BlockState) Block(org.bukkit.block.Block) MaterialData(org.bukkit.material.MaterialData)

Example 27 with BlockState

use of org.bukkit.block.BlockState in project Glowstone by GlowstoneMC.

the class WaterLilyDecorator method decorate.

@Override
public void decorate(World world, Random random, Chunk source) {
    int sourceX = (source.getX() << 4) + random.nextInt(16);
    int sourceZ = (source.getZ() << 4) + random.nextInt(16);
    int sourceY = random.nextInt(world.getHighestBlockYAt(sourceX, sourceZ) << 1);
    while (world.getBlockAt(sourceX, sourceY - 1, sourceZ).getType() == Material.AIR && sourceY > 0) {
        sourceY--;
    }
    for (int j = 0; j < 10; j++) {
        int x = sourceX + random.nextInt(8) - random.nextInt(8);
        int z = sourceZ + random.nextInt(8) - random.nextInt(8);
        int y = sourceY + random.nextInt(4) - random.nextInt(4);
        if (y >= 0 && y <= 255 && world.getBlockAt(x, y, z).getType() == Material.AIR && world.getBlockAt(x, y - 1, z).getType() == Material.STATIONARY_WATER) {
            BlockState state = world.getBlockAt(x, y, z).getState();
            state.setType(Material.WATER_LILY);
            state.setData(new MaterialData(Material.WATER_LILY));
            state.update(true);
        }
    }
}
Also used : BlockState(org.bukkit.block.BlockState) MaterialData(org.bukkit.material.MaterialData)

Example 28 with BlockState

use of org.bukkit.block.BlockState in project Glowstone by GlowstoneMC.

the class PumpkinDecorator method populate.

@Override
public void populate(World world, Random random, Chunk source) {
    if (random.nextInt(32) == 0) {
        int sourceX = (source.getX() << 4) + random.nextInt(16);
        int sourceZ = (source.getZ() << 4) + random.nextInt(16);
        int sourceY = random.nextInt(world.getHighestBlockYAt(sourceX, sourceZ) << 1);
        for (int i = 0; i < 64; i++) {
            int x = sourceX + random.nextInt(8) - random.nextInt(8);
            int z = sourceZ + random.nextInt(8) - random.nextInt(8);
            int y = sourceY + random.nextInt(4) - random.nextInt(4);
            if (world.getBlockAt(x, y, z).getType() == Material.AIR && world.getBlockAt(x, y - 1, z).getType() == Material.GRASS) {
                BlockState state = world.getBlockAt(x, y, z).getState();
                state.setType(Material.PUMPKIN);
                // random facing
                state.setData(new Pumpkin(FACES[random.nextInt(FACES.length)]));
                state.update(true);
            }
        }
    }
}
Also used : BlockState(org.bukkit.block.BlockState) Pumpkin(org.bukkit.material.Pumpkin)

Example 29 with BlockState

use of org.bukkit.block.BlockState in project Glowstone by GlowstoneMC.

the class MushroomDecorator method decorate.

@Override
public void decorate(World world, Random random, Chunk source) {
    if (random.nextFloat() < density) {
        int sourceX = (source.getX() << 4) + random.nextInt(16);
        int sourceZ = (source.getZ() << 4) + random.nextInt(16);
        int sourceY = world.getHighestBlockYAt(sourceX, sourceZ);
        sourceY = fixedHeightRange ? sourceY : random.nextInt(sourceY << 1);
        for (int i = 0; i < 64; i++) {
            int x = sourceX + random.nextInt(8) - random.nextInt(8);
            int z = sourceZ + random.nextInt(8) - random.nextInt(8);
            int y = sourceY + random.nextInt(4) - random.nextInt(4);
            Block block = world.getBlockAt(x, y, z);
            Block blockBelow = world.getBlockAt(x, y - 1, z);
            if (y < 255 && block.getType() == Material.AIR && ((blockBelow.getType() == Material.GRASS || blockBelow.getState().getData() instanceof Dirt && ((Dirt) blockBelow.getState().getData()).getType() != DirtType.PODZOL) && block.getLightLevel() < 13 || blockBelow.getType() == Material.MYCEL || blockBelow.getState().getData() instanceof Dirt && ((Dirt) blockBelow.getState().getData()).getType() == DirtType.PODZOL)) {
                BlockState state = block.getState();
                state.setType(type);
                state.setData(new MaterialData(type));
                state.update(true);
            }
        }
    }
}
Also used : BlockState(org.bukkit.block.BlockState) Dirt(org.bukkit.material.Dirt) Block(org.bukkit.block.Block) MaterialData(org.bukkit.material.MaterialData)

Example 30 with BlockState

use of org.bukkit.block.BlockState in project BKCommonLib by bergerhealer.

the class BlockStateConversion method tileEntityToBlockState.

public static BlockState tileEntityToBlockState(Block block, Object nmsTileEntity) {
    // Store and restore old state in case of recursive calls to this function
    // This could happen if inside BlockState construction a chunk is loaded anyway
    // Would be bad, but its best to assume the worst
    TileState old_state = input_state;
    try {
        input_state = new TileState(block, nmsTileEntity);
        BlockState result = proxy_block.getState();
        // Internal BlockState needs to have all proxy field instances replaced with what it should be
        BlockStateCache cache = BlockStateCache.get(result.getClass());
        for (SafeField<World> worldField : cache.worldFields) {
            worldField.set(result, input_state.block.getWorld());
        }
        for (SafeField<Chunk> chunkField : cache.chunkFields) {
            chunkField.set(result, input_state.block.getChunk());
        }
        // All done!
        return result;
    } catch (Throwable t) {
        Logging.LOGGER_CONVERSION.once(Level.SEVERE, "Failed to convert " + nmsTileEntity.getClass().getName() + " to CraftBlockState", t);
        return CraftBlockStateHandle.createNew(input_state.block);
    } finally {
        input_state = old_state;
    }
}
Also used : BlockState(org.bukkit.block.BlockState) World(org.bukkit.World) Chunk(org.bukkit.Chunk)

Aggregations

BlockState (org.bukkit.block.BlockState)59 Block (org.bukkit.block.Block)26 EventHandler (org.bukkit.event.EventHandler)15 MaterialData (org.bukkit.material.MaterialData)12 Location (org.bukkit.Location)11 BlockFace (org.bukkit.block.BlockFace)8 Material (org.bukkit.Material)6 Player (org.bukkit.entity.Player)6 ArrayList (java.util.ArrayList)5 BlockStateChange (me.botsko.prism.events.BlockStateChange)5 World (org.bukkit.World)5 GlowBlockState (net.glowstone.block.GlowBlockState)4 CreatureSpawner (org.bukkit.block.CreatureSpawner)4 ItemStack (org.bukkit.inventory.ItemStack)4 GlowBlock (net.glowstone.block.GlowBlock)3 HashMap (java.util.HashMap)2 Handler (me.botsko.prism.actions.Handler)2 ChangeResult (me.botsko.prism.appliers.ChangeResult)2 net.aufdemrand.denizen.objects.dLocation (net.aufdemrand.denizen.objects.dLocation)2 Element (net.aufdemrand.denizencore.objects.Element)2