use of org.bukkit.Material in project Glowstone by GlowstoneMC.
the class GenericTree method generate.
public boolean generate() {
if (!canHeightFit() || !canPlaceOn() || !canPlace()) {
return false;
}
// generate the leaves
for (int y = loc.getBlockY() + height - 3; y <= loc.getBlockY() + height; y++) {
int n = y - (loc.getBlockY() + height);
int radius = 1 - n / 2;
for (int x = loc.getBlockX() - radius; x <= loc.getBlockX() + radius; x++) {
for (int z = loc.getBlockZ() - radius; z <= loc.getBlockZ() + radius; z++) {
if (Math.abs(x - loc.getBlockX()) != radius || Math.abs(z - loc.getBlockZ()) != radius || random.nextBoolean() && n != 0) {
Material material = delegate.getBlockState(loc.getWorld(), x, y, z).getType();
if (material == Material.AIR || material == Material.LEAVES) {
delegate.setTypeAndRawData(loc.getWorld(), x, y, z, Material.LEAVES, leavesType);
}
}
}
}
}
// generate the trunk
for (int y = 0; y < height; y++) {
Material material = delegate.getBlockState(loc.getWorld(), loc.getBlockX(), loc.getBlockY() + y, loc.getBlockZ()).getType();
if (material == Material.AIR || material == Material.LEAVES) {
delegate.setTypeAndRawData(loc.getWorld(), loc.getBlockX(), loc.getBlockY() + y, loc.getBlockZ(), Material.LOG, logType);
}
}
// block below trunk is always dirt
Dirt dirt = new Dirt(DirtType.NORMAL);
delegate.setTypeAndData(loc.getWorld(), loc.getBlockX(), loc.getBlockY() - 1, loc.getBlockZ(), Material.DIRT, dirt);
return true;
}
use of org.bukkit.Material in project Glowstone by GlowstoneMC.
the class RedwoodTree method generate.
@Override
public boolean generate() {
if (!canHeightFit() || !canPlaceOn() || !canPlace()) {
return false;
}
// generate the leaves
int radius = random.nextInt(2);
int peakRadius = 1;
int minRadius = 0;
for (int y = loc.getBlockY() + height; y >= loc.getBlockY() + leavesHeight; y--) {
// leaves are built from top to bottom
for (int x = loc.getBlockX() - radius; x <= loc.getBlockX() + radius; x++) {
for (int z = loc.getBlockZ() - radius; z <= loc.getBlockZ() + radius; z++) {
if ((Math.abs(x - loc.getBlockX()) != radius || Math.abs(z - loc.getBlockZ()) != radius || radius <= 0) && delegate.getBlockState(loc.getWorld(), x, y, z).getType() == Material.AIR) {
delegate.setTypeAndRawData(loc.getWorld(), x, y, z, Material.LEAVES, leavesType);
}
}
}
if (radius >= peakRadius) {
radius = minRadius;
// after the peak radius is reached once, the min radius increases
minRadius = 1;
// the peak radius increases each time it's reached
peakRadius++;
if (peakRadius > maxRadius) {
peakRadius = maxRadius;
}
} else {
radius++;
}
}
// generate the trunk
for (int y = 0; y < height - random.nextInt(3); y++) {
Material type = delegate.getBlockState(loc.getWorld(), loc.getBlockX(), loc.getBlockY() + y, loc.getBlockZ()).getType();
if (overridables.contains(type)) {
delegate.setTypeAndRawData(loc.getWorld(), loc.getBlockX(), loc.getBlockY() + y, loc.getBlockZ(), Material.LOG, logType);
}
}
// block below trunk is always dirt
Dirt dirt = new Dirt(DirtType.NORMAL);
delegate.setTypeAndData(loc.getWorld(), loc.getBlockX(), loc.getBlockY() - 1, loc.getBlockZ(), Material.DIRT, dirt);
return true;
}
use of org.bukkit.Material in project Glowstone by GlowstoneMC.
the class SwampTree method generate.
@Override
public boolean generate() {
while (loc.getBlock().getRelative(BlockFace.DOWN).getType() == Material.WATER || loc.getBlock().getRelative(BlockFace.DOWN).getType() == Material.STATIONARY_WATER) {
loc.subtract(0, 1, 0);
}
if (!canHeightFit() || !canPlaceOn() || !canPlace()) {
return false;
}
// generate the leaves
for (int y = loc.getBlockY() + height - 3; y <= loc.getBlockY() + height; y++) {
int n = y - (loc.getBlockY() + height);
int radius = 2 - n / 2;
for (int x = loc.getBlockX() - radius; x <= loc.getBlockX() + radius; x++) {
for (int z = loc.getBlockZ() - radius; z <= loc.getBlockZ() + radius; z++) {
if (Math.abs(x - loc.getBlockX()) != radius || Math.abs(z - loc.getBlockZ()) != radius || random.nextBoolean() && n != 0) {
Material material = delegate.getBlockState(loc.getWorld(), x, y, z).getType();
if (material == Material.AIR || material == Material.LEAVES) {
delegate.setTypeAndRawData(loc.getWorld(), x, y, z, Material.LEAVES, leavesType);
}
}
}
}
}
// generate the trunk
for (int y = 0; y < height; y++) {
Material material = delegate.getBlockState(loc.getWorld(), loc.getBlockX(), loc.getBlockY() + y, loc.getBlockZ()).getType();
if (material == Material.AIR || material == Material.LEAVES || material == Material.WATER || material == Material.STATIONARY_WATER) {
delegate.setTypeAndRawData(loc.getWorld(), loc.getBlockX(), loc.getBlockY() + y, loc.getBlockZ(), Material.LOG, logType);
}
}
// add some vines on the leaves
addVinesOnLeaves();
// block below trunk is always dirt
Dirt dirt = new Dirt(DirtType.NORMAL);
delegate.setTypeAndData(loc.getWorld(), loc.getBlockX(), loc.getBlockY() - 1, loc.getBlockZ(), Material.DIRT, dirt);
return true;
}
use of org.bukkit.Material in project Glowstone by GlowstoneMC.
the class ItemIdsTest method mappingExists.
@Test
public void mappingExists() {
String nameid = ItemIds.getName(material);
assertThat("Identifier missing for " + material, nameid, notNullValue());
if (!nameid.startsWith("minecraft:")) {
fail("Identifier '" + nameid + "' does not start with 'minecraft:'");
}
Material item = ItemIds.getItem(nameid);
Material block = ItemIds.getBlock(nameid);
String base = "Material " + material + "\t-> \"" + nameid + "\"\t-> ";
if (material.isBlock()) {
assertThat(base + "block, has no block entry", block, notNullValue());
assertThat("wrong block material", block, is(material));
if (item != material) {
System.out.println(base + "item: " + item);
}
} else {
assertThat(base + "item, has no item entry", item, notNullValue());
assertThat("wrong item material", item, is(material));
if (block == material) {
fail(base + "not block, but maps to block: " + block);
}
}
}
use of org.bukkit.Material in project Glowstone by GlowstoneMC.
the class BlockTallGrass method canPlaceAt.
@Override
public boolean canPlaceAt(GlowBlock block, BlockFace against) {
int typeIdBelow = block.getWorld().getBlockTypeIdAt(block.getX(), block.getY() - 1, block.getZ());
Material typeBelow = Material.getMaterial(typeIdBelow);
return typeBelow == Material.GRASS || typeBelow == Material.DIRT || typeBelow == Material.SOIL;
}
Aggregations