use of org.bukkit.block.BlockFace in project Glowstone by GlowstoneMC.
the class BlockBed method placeBlock.
@Override
public void placeBlock(GlowPlayer player, GlowBlockState state, BlockFace face, ItemStack holding, Vector clickedLoc) {
BlockFace direction = getOppositeBlockFace(player.getLocation(), false).getOppositeFace();
if (state.getBlock().getRelative(direction).getType() == Material.AIR && state.getBlock().getRelative(direction).getRelative(BlockFace.DOWN).getType().isSolid()) {
super.placeBlock(player, state, face, holding, clickedLoc);
MaterialData data = state.getData();
if (data instanceof Bed) {
((Bed) data).setFacingDirection(direction);
state.setData(data);
} else {
warnMaterialData(Bed.class, data);
}
}
}
use of org.bukkit.block.BlockFace in project Glowstone by GlowstoneMC.
the class GlowBlock method applyPhysics.
/////////////////////////////////////////////////////////////////////////////
// Physics
/**
* Notify this block and its surrounding blocks that this block has changed
* type and data.
*
* @param oldType the old block type
* @param newTypeId the new block type
* @param oldData the old data
* @param newData the new data
*/
public void applyPhysics(Material oldType, int newTypeId, byte oldData, byte newData) {
// notify the surrounding blocks that this block has changed
ItemTable itemTable = ItemTable.instance();
Material newType = Material.getMaterial(newTypeId);
for (int y = -1; y <= 1; y++) {
for (BlockFace face : LAYER) {
if (y == 0 && face == BlockFace.SELF) {
continue;
}
GlowBlock notify = getRelative(face.getModX(), face.getModY() + y, face.getModZ());
BlockFace blockFace;
if (y == 0) {
blockFace = face.getOppositeFace();
} else if (y == -1 && face == BlockFace.SELF) {
blockFace = BlockFace.UP;
} else if (y == 1 && face == BlockFace.SELF) {
blockFace = BlockFace.DOWN;
} else {
blockFace = null;
}
BlockType notifyType = itemTable.getBlock(notify.getTypeId());
if (notifyType != null) {
notifyType.onNearBlockChanged(notify, blockFace, this, oldType, oldData, newType, newData);
}
}
}
BlockType type = itemTable.getBlock(oldType);
if (type != null) {
type.onBlockChanged(this, oldType, oldData, newType, newData);
}
}
use of org.bukkit.block.BlockFace in project Glowstone by GlowstoneMC.
the class GlowDungeon method generate.
@Override
public boolean generate(World world, Random random, StructureBoundingBox genBoundingBox, BlockStateDelegate delegate) {
if (!super.generate(world, random, boundingBox, delegate)) {
return false;
}
boundingBox.offset(new Vector(-radiusX, -1, -radiusZ));
StructureBuilder builder = new StructureBuilder(world, this, genBoundingBox, delegate);
if (!canPlace(builder)) {
return false;
}
Map<StructureMaterial, Integer> stones = new HashMap<>();
builder.addRandomMaterial(stones, 1, Material.COBBLESTONE, 0);
builder.addRandomMaterial(stones, 3, Material.MOSSY_COBBLESTONE, 0);
for (int x = 0; x < sizeX; x++) {
for (int z = 0; z < sizeZ; z++) {
for (int y = HEIGHT - 1; y >= 0; y--) {
BlockState state = builder.getBlockState(new Vector(x, y, z));
if (y > 0 && x > 0 && z > 0 && x < sizeX - 1 && y < HEIGHT - 1 && z < sizeZ - 1) {
// empty space inside
builder.setBlock(new Vector(x, y, z), Material.AIR);
} else if (!builder.getBlockState(new Vector(x, y - 1, z)).getType().isSolid()) {
// cleaning walls from non solid materials (because of air gaps below)
builder.setBlock(new Vector(x, y, z), Material.AIR);
} else if (state.getType().isSolid()) {
// preserve the air gaps
if (y == 0) {
builder.setBlockWithRandomMaterial(new Vector(x, y, z), random, stones);
} else {
builder.setBlock(new Vector(x, y, z), Material.COBBLESTONE);
}
}
}
}
}
RandomItemsContent chestContent = new RandomItemsContent();
chestContent.addItem(new RandomAmountItem(Material.SADDLE, 1, 1), 10);
chestContent.addItem(new RandomAmountItem(Material.IRON_INGOT, 1, 4), 10);
chestContent.addItem(new RandomAmountItem(Material.BREAD, 1, 1), 10);
chestContent.addItem(new RandomAmountItem(Material.WHEAT, 1, 4), 10);
chestContent.addItem(new RandomAmountItem(Material.SULPHUR, 1, 4), 10);
chestContent.addItem(new RandomAmountItem(Material.STRING, 1, 4), 10);
chestContent.addItem(new RandomAmountItem(Material.BUCKET, 1, 1), 10);
chestContent.addItem(new RandomAmountItem(Material.GOLDEN_APPLE, 1, 1), 1);
chestContent.addItem(new RandomAmountItem(Material.REDSTONE, 1, 4), 10);
chestContent.addItem(new RandomAmountItem(Material.GOLD_RECORD, 1, 1), 4);
chestContent.addItem(new RandomAmountItem(Material.GREEN_RECORD, 1, 1), 4);
chestContent.addItem(new RandomAmountItem(Material.NAME_TAG, 1, 1), 10);
chestContent.addItem(new RandomAmountItem(Material.GOLD_BARDING, 1, 1), 2);
chestContent.addItem(new RandomAmountItem(Material.IRON_BARDING, 1, 1), 5);
chestContent.addItem(new RandomAmountItem(Material.DIAMOND_BARDING, 1, 1), 1);
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 3; j++) {
int x = random.nextInt((radiusX << 1) - 1) + 1;
int z = random.nextInt((radiusZ << 1) - 1) + 1;
if (builder.getBlockState(new Vector(x, 1, z)).getType() == Material.AIR) {
BlockFace face = null;
int solidBlocksCount = 0;
if (builder.getBlockState(new Vector(x - 1, 1, z)).getType() == Material.COBBLESTONE) {
solidBlocksCount++;
face = BlockFace.EAST;
}
if (builder.getBlockState(new Vector(x + 1, 1, z)).getType() == Material.COBBLESTONE) {
solidBlocksCount++;
face = BlockFace.WEST;
}
if (builder.getBlockState(new Vector(x, 1, z - 1)).getType() == Material.COBBLESTONE) {
solidBlocksCount++;
face = BlockFace.SOUTH;
}
if (builder.getBlockState(new Vector(x, 1, z + 1)).getType() == Material.COBBLESTONE) {
solidBlocksCount++;
face = BlockFace.NORTH;
}
if (solidBlocksCount == 1) {
builder.createRandomItemsContainer(new Vector(x, 1, z), random, chestContent, new Chest(face), 8);
break;
}
}
}
}
builder.createMobSpawner(new Vector(radiusX, 1, radiusZ), mobTypes[random.nextInt(mobTypes.length)]);
GlowServer.logger.finer("dungeon generated: " + loc.getBlockX() + "," + loc.getBlockY() + "," + loc.getBlockZ());
return true;
}
use of org.bukkit.block.BlockFace in project Glowstone by GlowstoneMC.
the class Cactus method generate.
public void generate(World world, Random random, int x, int y, int z) {
if (world.getBlockAt(x, y, z).isEmpty()) {
int height = random.nextInt(random.nextInt(3) + 1) + 1;
for (int n = y; n < y + height; n++) {
Block block = world.getBlockAt(x, n, z);
if ((block.getRelative(BlockFace.DOWN).getType() == Material.SAND || block.getRelative(BlockFace.DOWN).getType() == Material.CACTUS) && block.getRelative(BlockFace.UP).isEmpty()) {
for (BlockFace face : FACES) {
if (block.getRelative(face).getType().isSolid()) {
return;
}
}
BlockState state = block.getState();
state.setType(Material.CACTUS);
state.setData(new MaterialData(Material.CACTUS));
state.update(true);
}
}
}
}
use of org.bukkit.block.BlockFace in project Glowstone by GlowstoneMC.
the class CocoaTree method addCocoa.
private void addCocoa(int sourceX, int sourceY, int sourceZ) {
if (height > 5 && random.nextInt(5) == 0) {
for (int y = 0; y < 2; y++) {
for (BlockFace cocoaFace : COCOA_FACES) {
// rotate the 4 trunk faces
if (random.nextInt(COCOA_FACES.length - y) == 0) {
// higher it is, more chances there is
CocoaPlantSize size = COCOA_SIZE[random.nextInt(COCOA_SIZE.length)];
Block block = delegate.getBlockState(loc.getWorld(), sourceX, sourceY + height - 5 + y, sourceZ).getBlock().getRelative(cocoaFace);
delegate.setTypeAndData(loc.getWorld(), block.getX(), block.getY(), block.getZ(), Material.COCOA, new CocoaPlant(size, cocoaFace.getOppositeFace()));
}
}
}
}
}
Aggregations