use of org.bukkit.block.BlockFace in project Glowstone by GlowstoneMC.
the class GlowChest method getInventory.
@Override
public Inventory getInventory() {
GlowBlock me = getBlock();
BlockChest blockChest = (BlockChest) ItemTable.instance().getBlock(me.getType());
BlockFace attachedChest = blockChest.getAttachedChest(me);
if (attachedChest != null) {
Block nearbyBlock = me.getRelative(attachedChest);
GlowChest nearbyChest = (GlowChest) nearbyBlock.getState();
switch(attachedChest) {
case SOUTH:
case EAST:
return new GlowDoubleChestInventory(this, nearbyChest);
case WEST:
case NORTH:
return new GlowDoubleChestInventory(nearbyChest, this);
default:
GlowServer.logger.warning("GlowChest#getInventory() can only handle N/O/S/W BlockFaces, got " + attachedChest);
return getBlockInventory();
}
}
return getBlockInventory();
}
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 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()));
}
}
}
}
}
use of org.bukkit.block.BlockFace in project Glowstone by GlowstoneMC.
the class ItemItemFrame method rightClickBlock.
@Override
public void rightClickBlock(GlowPlayer player, GlowBlock target, BlockFace face, ItemStack holding, Vector clickedLoc) {
GlowItemFrame entity = new GlowItemFrame(player, target.getLocation().getBlock().getRelative(face).getLocation(), face);
List<Message> spawnMessage = entity.createSpawnMessage();
entity.getWorld().getRawPlayers().stream().filter(p -> p.canSeeEntity(entity)).forEach(p -> p.getSession().sendAll(spawnMessage.toArray(new Message[spawnMessage.size()])));
}
use of org.bukkit.block.BlockFace in project Essentials by drtshock.
the class EssentialsSign method checkIfBlockBreaksSigns.
protected static boolean checkIfBlockBreaksSigns(final Block block) {
final Block sign = block.getRelative(BlockFace.UP);
if (sign.getType() == Material.SIGN_POST && isValidSign(new BlockSign(sign))) {
return true;
}
final BlockFace[] directions = new BlockFace[] { BlockFace.NORTH, BlockFace.EAST, BlockFace.SOUTH, BlockFace.WEST };
for (BlockFace blockFace : directions) {
final Block signblock = block.getRelative(blockFace);
if (signblock.getType() == Material.WALL_SIGN) {
try {
final org.bukkit.material.Sign signMat = (org.bukkit.material.Sign) signblock.getState().getData();
if (signMat != null && signMat.getFacing() == blockFace && isValidSign(new BlockSign(signblock))) {
return true;
}
} catch (NullPointerException ex) {
// Sometimes signs enter a state of being semi broken, having no text or state data, usually while burning.
}
}
}
return false;
}
Aggregations