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);
}
}
}
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);
}
}
}
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);
}
}
}
}
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);
}
}
}
}
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;
}
}
Aggregations