use of org.bukkit.material.MaterialData in project Glowstone by GlowstoneMC.
the class BlockWater method updateBlock.
@Override
public void updateBlock(GlowBlock block) {
super.updateBlock(block);
if (block.getLightFromBlocks() <= 11 - block.getMaterialValues().getLightOpacity()) {
if (block.getRelative(BlockFace.UP).isEmpty() && hasNearSolidBlock(block) && GlowBiomeClimate.isCold(block)) {
GlowBlockState state = block.getState();
state.setType(Material.ICE);
state.setData(new MaterialData(Material.ICE));
BlockSpreadEvent spreadEvent = new BlockSpreadEvent(state.getBlock(), block, state);
EventFactory.callEvent(spreadEvent);
if (!spreadEvent.isCancelled()) {
state.update(true);
}
}
}
}
use of org.bukkit.material.MaterialData in project Glowstone by GlowstoneMC.
the class BlockTallGrass method grow.
@Override
public void grow(GlowPlayer player, GlowBlock block) {
MaterialData data = block.getState().getData();
if (data instanceof LongGrass) {
GrassSpecies species = ((LongGrass) data).getSpecies();
if (species == GrassSpecies.NORMAL || species == GrassSpecies.FERN_LIKE) {
GlowBlockState headBlockState = block.getRelative(BlockFace.UP).getState();
if (headBlockState.getType() == Material.AIR) {
DoublePlantSpecies doublePlantSpecies = species == GrassSpecies.FERN_LIKE ? DoublePlantSpecies.LARGE_FERN : DoublePlantSpecies.DOUBLE_TALLGRASS;
GlowBlockState blockState = block.getState();
blockState.setType(Material.DOUBLE_PLANT);
blockState.setData(new DoublePlant(doublePlantSpecies));
headBlockState.setType(Material.DOUBLE_PLANT);
headBlockState.setData(new DoublePlant(DoublePlantSpecies.PLANT_APEX));
BlockGrowEvent growEvent = new BlockGrowEvent(block, blockState);
EventFactory.callEvent(growEvent);
if (!growEvent.isCancelled()) {
blockState.update(true);
headBlockState.update(true);
}
}
}
} else {
warnMaterialData(LongGrass.class, data);
}
}
use of org.bukkit.material.MaterialData in project Glowstone by GlowstoneMC.
the class BlockSkull method afterPlace.
@Override
public void afterPlace(GlowPlayer player, GlowBlock block, ItemStack holding, GlowBlockState oldState) {
GlowSkull skull = (GlowSkull) block.getState();
skull.setSkullType(getType(holding.getDurability()));
if (skull.getSkullType() == SkullType.PLAYER) {
SkullMeta meta = (SkullMeta) holding.getItemMeta();
if (meta != null) {
skull.setOwner(meta.getOwner());
}
}
MaterialData data = skull.getData();
if (!(data instanceof Skull)) {
warnMaterialData(Skull.class, data);
return;
}
Skull skullData = (Skull) data;
if (canRotate(skullData)) {
// Can be rotated
skull.setRotation(player.getFacing().getOppositeFace());
}
skull.update();
// Wither
for (int i = 0; i < 3; i++) {
if (WITHER_PATTERN.matches(block.getLocation().clone(), true, i, 0)) {
block.getWorld().spawnEntity(block.getLocation().clone().subtract(0, 2, 0), EntityType.WITHER);
break;
}
}
}
use of org.bukkit.material.MaterialData in project Glowstone by GlowstoneMC.
the class MelonDecorator method populate.
@Override
public void populate(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.getSeaLevel() << 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.MELON_BLOCK);
state.setData(new MaterialData(Material.MELON_BLOCK));
state.update(true);
}
}
}
use of org.bukkit.material.MaterialData in project Glowstone by GlowstoneMC.
the class GroundGenerator method generateTerrainColumn.
public void generateTerrainColumn(ChunkData chunkData, World world, Random random, int x, int z, Biome biome, double surfaceNoise) {
int seaLevel = world.getSeaLevel();
MaterialData topMat = topMaterial;
MaterialData groundMat = groundMaterial;
int chunkX = x;
int chunkZ = z;
x &= 0xF;
z &= 0xF;
int surfaceHeight = Math.max((int) (surfaceNoise / 3.0D + 3.0D + random.nextDouble() * 0.25D), 1);
int deep = -1;
for (int y = 255; y >= 0; y--) {
if (y <= random.nextInt(5)) {
chunkData.setBlock(x, y, z, Material.BEDROCK);
} else {
Material mat = chunkData.getType(x, y, z);
if (mat == Material.AIR) {
deep = -1;
} else if (mat == Material.STONE) {
if (deep == -1) {
if (y >= seaLevel - 5 && y <= seaLevel) {
topMat = topMaterial;
groundMat = groundMaterial;
}
deep = surfaceHeight;
if (y >= seaLevel - 2) {
chunkData.setBlock(x, y, z, topMat);
} else if (y < seaLevel - 8 - surfaceHeight) {
topMat = AIR;
groundMat = STONE;
chunkData.setBlock(x, y, z, Material.GRAVEL);
} else {
chunkData.setBlock(x, y, z, groundMat);
}
} else if (deep > 0) {
deep--;
chunkData.setBlock(x, y, z, groundMat);
if (deep == 0 && groundMat.getItemType() == Material.SAND) {
deep = random.nextInt(4) + Math.max(0, y - seaLevel - 1);
groundMat = SANDSTONE;
}
}
} else if (mat == Material.STATIONARY_WATER && y == seaLevel - 2 && GlowBiomeClimate.isCold(biome, chunkX, y, chunkZ)) {
chunkData.setBlock(x, y, z, Material.ICE);
}
}
}
}
Aggregations