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 newType the new block type
* @param oldData the old data
* @param newData the new data
*/
public void applyPhysics(Material oldType, Material newType, byte oldData, byte newData) {
if (!world.isInitialized()) {
// World is still loading.
return;
}
// notify the surrounding blocks that this block has changed
ItemTable itemTable = ItemTable.instance();
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.getType());
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 BlockBed method afterPlace.
@Override
public void afterPlace(GlowPlayer player, GlowBlock block, ItemStack holding, GlowBlockState oldState) {
Material type = block.getType();
if (!MaterialTags.BEDS.isTagged(type)) {
return;
}
GlowBed bed = (GlowBed) block.getState();
bed.setColor(DyeColor.getByWoolData(holding.getData().getData()));
bed.update(true);
BlockFace direction = ((Bed) bed.getData()).getFacing();
GlowBlock headBlock = block.getRelative(direction);
headBlock.setType(type);
GlowBed headBlockState = (GlowBed) headBlock.getState();
headBlockState.setColor(DyeColor.getByWoolData(holding.getData().getData()));
MaterialData data = headBlockState.getData();
((Bed) data).setHeadOfBed(true);
((Bed) data).setFacingDirection(direction);
headBlockState.setData(data);
headBlockState.update(true);
}
use of org.bukkit.block.BlockFace in project Glowstone by GlowstoneMC.
the class BlockBed method canPlaceAt.
@Override
public boolean canPlaceAt(GlowPlayer player, GlowBlock block, BlockFace against) {
if (player != null) {
BlockFace direction = getOppositeBlockFace(player.getLocation(), false).getOppositeFace();
final GlowBlock otherEnd = block.getRelative(direction);
return otherEnd.getType() == Material.AIR && otherEnd.getRelative(BlockFace.DOWN).getType().isSolid();
} else {
return false;
}
}
use of org.bukkit.block.BlockFace in project Glowstone by GlowstoneMC.
the class BlockChest 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 Chest) {
Chest chest = (Chest) data;
GlowBlock chestBlock = state.getBlock();
BlockFace normalFacing = getOppositeBlockFace(player.getLocation(), false);
Collection<BlockFace> attachedChests = searchChests(chestBlock);
switch(attachedChests.size()) {
case 0:
chest.setFacingDirection(normalFacing);
state.setData(chest);
return;
case 1:
break;
default:
ConsoleMessages.Warn.Block.Chest.TRIPLE_MIDDLE.log();
return;
}
BlockFace otherPart = attachedChests.iterator().next();
GlowBlock otherPartBlock = chestBlock.getRelative(otherPart);
if (getAttachedChest(otherPartBlock) != null) {
ConsoleMessages.Warn.Block.Chest.TRIPLE_END.log();
return;
}
BlockState otherPartState = otherPartBlock.getState();
MaterialData otherPartData = otherPartState.getData();
if (otherPartData instanceof Chest) {
Chest otherChest = (Chest) otherPartData;
BlockFace facing = getFacingDirection(normalFacing, otherChest.getFacing(), otherPart, player);
chest.setFacingDirection(facing);
state.setData(chest);
otherChest.setFacingDirection(facing);
otherPartState.setData(otherChest);
otherPartState.update();
} else {
warnMaterialData(Chest.class, otherPartData);
}
} else {
warnMaterialData(Chest.class, data);
}
}
use of org.bukkit.block.BlockFace in project Glowstone by GlowstoneMC.
the class BlockDoor method placeBlock.
@Override
public void placeBlock(GlowPlayer player, GlowBlockState state, BlockFace face, ItemStack holding, Vector clickedLoc) {
// place the door and calculate the facing
super.placeBlock(player, state, face, holding, clickedLoc);
MaterialData data = state.getData();
if (!(data instanceof Door)) {
warnMaterialData(Door.class, data);
return;
}
BlockFace facing = player.getCardinalFacing();
((Door) data).setFacingDirection(facing.getOppositeFace());
// modify facing for double-doors
GlowBlock leftBlock = null;
byte newDirectionData = 0;
switch(facing) {
case NORTH:
leftBlock = state.getBlock().getRelative(BlockFace.WEST);
newDirectionData = 6;
break;
case WEST:
leftBlock = state.getBlock().getRelative(BlockFace.SOUTH);
newDirectionData = 5;
break;
case SOUTH:
leftBlock = state.getBlock().getRelative(BlockFace.EAST);
newDirectionData = 4;
break;
case EAST:
leftBlock = state.getBlock().getRelative(BlockFace.NORTH);
newDirectionData = 7;
break;
default:
}
if (leftBlock != null && leftBlock.getState().getData() instanceof Door) {
data.setData(newDirectionData);
}
// place top half of door
GlowBlockState topState = state.getBlock().getRelative(BlockFace.UP).getState();
topState.setType(state.getType());
MaterialData topData = topState.getData();
if (!(topData instanceof Door)) {
warnMaterialData(Door.class, data);
} else {
((Door) topData).setTopHalf(true);
topState.update(true);
}
}
Aggregations