use of org.bukkit.material.MaterialData in project Glowstone by GlowstoneMC.
the class BlockPumpkinBase method placeBlock.
@Override
public void placeBlock(GlowPlayer player, GlowBlockState state, BlockFace face, ItemStack holding, Vector clickedLoc) {
super.placeBlock(player, state, face, holding, clickedLoc);
MaterialData data = state.getData();
if (data instanceof Pumpkin) {
((Pumpkin) data).setFacingDirection(player.getDirection());
state.setData(data);
} else {
warnMaterialData(Pumpkin.class, data);
}
}
use of org.bukkit.material.MaterialData in project Glowstone by GlowstoneMC.
the class ChunkManager method generateChunk.
/**
* Initialize a single chunk from the chunk generator.
*/
private void generateChunk(GlowChunk chunk, int x, int z) {
Random random = new Random(x * 341873128712L + z * 132897987541L);
BiomeGrid biomes = new BiomeGrid();
int[] biomeValues = biomeGrid[0].generateValues(x * GlowChunk.WIDTH, z * GlowChunk.HEIGHT, GlowChunk.WIDTH, GlowChunk.HEIGHT);
for (int i = 0; i < biomeValues.length; i++) {
biomes.biomes[i] = (byte) biomeValues[i];
}
// extended sections with data
GlowChunkData glowChunkData = null;
if (generator instanceof GlowChunkGenerator) {
glowChunkData = (GlowChunkData) generator.generateChunkData(world, random, x, z, biomes);
} else {
ChunkGenerator.ChunkData chunkData = generator.generateChunkData(world, random, x, z, biomes);
if (chunkData != null) {
glowChunkData = new GlowChunkData(world);
for (int i = 0; i < 16; ++i) {
for (int j = 0; j < 16; ++j) {
int maxHeight = chunkData.getMaxHeight();
for (int k = 0; k < maxHeight; ++k) {
MaterialData materialData = chunkData.getTypeAndData(i, k, j);
if (materialData != null) {
glowChunkData.setBlock(i, k, j, materialData);
} else {
glowChunkData.setBlock(i, k, j, new MaterialData(Material.AIR));
}
}
}
}
}
}
if (glowChunkData != null) {
short[][] extSections = glowChunkData.getSections();
if (extSections != null) {
ChunkSection[] sections = new ChunkSection[extSections.length];
for (int i = 0; i < extSections.length; ++i) {
if (extSections[i] != null) {
sections[i] = ChunkSection.fromStateArray(extSections[i]);
}
}
chunk.initializeSections(sections);
chunk.setBiomes(biomes.biomes);
chunk.automaticHeightMap();
return;
}
}
// extended sections
short[][] extSections = generator.generateExtBlockSections(world, random, x, z, biomes);
if (extSections != null) {
ChunkSection[] sections = new ChunkSection[extSections.length];
for (int i = 0; i < extSections.length; ++i) {
if (extSections[i] != null) {
sections[i] = ChunkSection.fromIdArray(extSections[i]);
}
}
chunk.initializeSections(sections);
chunk.setBiomes(biomes.biomes);
chunk.automaticHeightMap();
return;
}
// normal sections
byte[][] blockSections = generator.generateBlockSections(world, random, x, z, biomes);
if (blockSections != null) {
ChunkSection[] sections = new ChunkSection[blockSections.length];
for (int i = 0; i < blockSections.length; ++i) {
if (blockSections[i] != null) {
sections[i] = ChunkSection.fromIdArray(blockSections[i]);
}
}
chunk.initializeSections(sections);
chunk.setBiomes(biomes.biomes);
chunk.automaticHeightMap();
return;
}
// deprecated flat generation
byte[] types = generator.generate(world, random, x, z);
ChunkSection[] sections = new ChunkSection[8];
for (int sy = 0; sy < sections.length; ++sy) {
// We can't use a normal constructor here due to the "interesting"
// choices used for this deprecated API (blocks are in vertical columns)
ChunkSection sec = new ChunkSection();
int by = 16 * sy;
for (int cx = 0; cx < 16; ++cx) {
for (int cz = 0; cz < 16; ++cz) {
for (int cy = by; cy < by + 16; ++cy) {
char type = (char) types[(((cx << 4) + cz) << 7) + cy];
sec.setType(cx, cy, cz, (char) (type << 4));
}
}
}
sections[sy] = sec;
}
chunk.initializeSections(sections);
chunk.setBiomes(biomes.biomes);
chunk.automaticHeightMap();
}
use of org.bukkit.material.MaterialData in project Glowstone by GlowstoneMC.
the class StoneBoulder method generate.
public void generate(World world, Random random, int sourceX, int sourceY, int sourceZ) {
boolean groundReached = false;
while (!groundReached && sourceY > 3) {
Block block = world.getBlockAt(sourceX, sourceY - 1, sourceZ);
if (!block.isEmpty()) {
for (Material mat : GROUND_TYPES) {
if (mat == block.getType()) {
groundReached = true;
sourceY++;
break;
}
}
}
sourceY--;
}
if (groundReached && world.getBlockAt(sourceX, sourceY, sourceZ).isEmpty()) {
for (int i = 0; i < 3; i++) {
int radiusX = random.nextInt(2);
int radiusZ = random.nextInt(2);
int radiusY = random.nextInt(2);
float f = (radiusX + radiusZ + radiusY) * 0.333F + 0.5F;
for (int x = -radiusX; x <= radiusX; x++) {
for (int z = -radiusZ; z <= radiusZ; z++) {
for (int y = -radiusY; y <= radiusY; y++) {
if (x * x + z * z + y * y <= f * f) {
BlockState state = world.getBlockAt(sourceX + x, sourceY + y, sourceZ + z).getState();
Block blockAbove = state.getBlock().getRelative(BlockFace.UP);
for (Material mat : PLANT_TYPES) {
if (blockAbove.getType() == mat) {
if (mat == Material.DOUBLE_PLANT && blockAbove.getState().getData() instanceof DoublePlant && ((DoublePlant) blockAbove.getState().getData()).getSpecies() == DoublePlantSpecies.PLANT_APEX) {
blockAbove.getRelative(BlockFace.UP).setType(Material.AIR);
}
blockAbove.setType(Material.AIR);
break;
}
}
state.setType(Material.MOSSY_COBBLESTONE);
state.setData(new MaterialData(Material.MOSSY_COBBLESTONE));
state.update(true);
}
}
}
}
sourceX += random.nextInt(4) - 1;
sourceZ += random.nextInt(4) - 1;
sourceY -= random.nextInt(2);
}
}
}
use of org.bukkit.material.MaterialData in project Glowstone by GlowstoneMC.
the class SugarCane method generate.
public void generate(World world, Random random, int x, int y, int z) {
if (world.getBlockAt(x, y, z).isEmpty()) {
Block block = world.getBlockAt(x, y, z).getRelative(BlockFace.DOWN);
boolean adjacentWater = false;
for (BlockFace face : FACES) {
// needs a directly adjacent water block
if (block.getRelative(face).getType() == Material.STATIONARY_WATER || block.getRelative(face).getType() == Material.WATER) {
adjacentWater = true;
break;
}
}
if (adjacentWater) {
for (int n = 0; n <= random.nextInt(random.nextInt(3) + 1) + 1; n++) {
block = world.getBlockAt(x, y + n, z).getRelative(BlockFace.DOWN);
if (block.getType() == Material.SUGAR_CANE_BLOCK || block.getType() == Material.GRASS || block.getType() == Material.DIRT && block.getState().getData() instanceof Dirt && ((Dirt) block.getState().getData()).getType() == DirtType.NORMAL || block.getType() == Material.SAND) {
Block caneBlock = block.getRelative(BlockFace.UP);
if (!caneBlock.isEmpty() && !caneBlock.getRelative(BlockFace.UP).isEmpty()) {
return;
}
BlockState state = caneBlock.getState();
state.setType(Material.SUGAR_CANE_BLOCK);
state.setData(new MaterialData(Material.SUGAR_CANE_BLOCK));
state.update(true);
}
}
}
}
}
use of org.bukkit.material.MaterialData in project Essentials by drtshock.
the class YamlStorageWriter method writeMaterialData.
private void writeMaterialData(final Object data) {
final MaterialData matData = (MaterialData) data;
writeMaterial(matData.getItemType());
if (matData.getData() > 0) {
writer.print(':');
writer.print(matData.getData());
}
}
Aggregations