use of net.glowstone.block.GlowBlockState in project Glowstone by GlowstoneMC.
the class BlockStem method grow.
@Override
public void grow(GlowPlayer player, GlowBlock block) {
GlowBlockState state = block.getState();
int cropState = block.getData() + random.nextInt(CropState.MEDIUM.ordinal()) + CropState.VERY_SMALL.ordinal();
if (cropState > CropState.RIPE.ordinal()) {
cropState = CropState.RIPE.ordinal();
}
state.setRawData((byte) cropState);
BlockGrowEvent growEvent = new BlockGrowEvent(block, state);
EventFactory.callEvent(growEvent);
if (!growEvent.isCancelled()) {
state.update(true);
}
}
use of net.glowstone.block.GlowBlockState in project Glowstone by GlowstoneMC.
the class BlockSugarCane method updateBlock.
@Override
public void updateBlock(GlowBlock block) {
if (!canPlaceAt(block, BlockFace.DOWN)) {
block.breakNaturally();
return;
}
GlowBlock blockAbove = block.getRelative(BlockFace.UP);
// check it's the highest block of cactus
if (blockAbove.isEmpty()) {
// check the current cane height
Block blockBelow = block.getRelative(BlockFace.DOWN);
int height = 1;
while (blockBelow.getType() == Material.SUGAR_CANE_BLOCK) {
height++;
blockBelow = blockBelow.getRelative(BlockFace.DOWN);
}
if (height < 3) {
GlowBlockState state = block.getState();
if (state.getRawData() < 15) {
// increase age
state.setRawData((byte) (state.getRawData() + 1));
state.update(true);
} else {
// grow the sugar cane on the above block
state.setRawData((byte) 0);
state.update(true);
state = blockAbove.getState();
state.setType(Material.SUGAR_CANE_BLOCK);
state.setRawData((byte) 0);
BlockGrowEvent growEvent = new BlockGrowEvent(blockAbove, state);
EventFactory.callEvent(growEvent);
if (!growEvent.isCancelled()) {
state.update(true);
}
updatePhysics(blockAbove);
}
}
}
}
use of net.glowstone.block.GlowBlockState 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);
if (attachedChests.isEmpty()) {
chest.setFacingDirection(normalFacing);
state.setData(chest);
return;
} else if (attachedChests.size() > 1) {
GlowServer.logger.warning("Chest placed near two other chests!");
return;
}
BlockFace otherPart = attachedChests.iterator().next();
GlowBlock otherPartBlock = chestBlock.getRelative(otherPart);
if (getAttachedChest(otherPartBlock) != null) {
GlowServer.logger.warning("Chest placed near already attached chest!");
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 net.glowstone.block.GlowBlockState in project Glowstone by GlowstoneMC.
the class BlockButton method blockInteract.
@Override
public boolean blockInteract(GlowPlayer player, GlowBlock block, BlockFace face, Vector clickedLoc) {
GlowBlockState state = block.getState();
MaterialData data = state.getData();
if (!(data instanceof Button)) {
warnMaterialData(Button.class, data);
return false;
}
Button button = (Button) data;
if (button.isPowered()) {
return true;
}
button.setPowered(true);
state.update();
extraUpdate(block);
// todo: switch to block scheduling system when one is available
new BukkitRunnable() {
@Override
public void run() {
button.setPowered(false);
state.update();
if (block.getType() == Material.WOOD_BUTTON || block.getType() == Material.STONE_BUTTON) {
extraUpdate(block);
block.getWorld().playSound(block.getLocation(), block.getType() == Material.WOOD_BUTTON ? Sound.BLOCK_WOOD_BUTTON_CLICK_OFF : Sound.BLOCK_STONE_BUTTON_CLICK_OFF, 0.3f, 0.5f);
}
}
}.runTaskLater(null, block.getType() == Material.STONE_BUTTON ? 20 : 30);
return true;
}
use of net.glowstone.block.GlowBlockState in project Glowstone by GlowstoneMC.
the class BlockCactus method updateBlock.
@Override
public void updateBlock(GlowBlock block) {
// TODO: Drop entity if the block has near blocks
GlowBlock blockAbove = block.getRelative(BlockFace.UP);
// check it's the highest block of cactus
if (blockAbove.isEmpty()) {
// check the current cactus height
Block blockBelow = block.getRelative(BlockFace.DOWN);
int height = 1;
while (blockBelow.getType() == Material.CACTUS) {
height++;
blockBelow = blockBelow.getRelative(BlockFace.DOWN);
}
if (height < 3) {
GlowBlockState state = block.getState();
if (state.getRawData() < 15) {
// increase age
state.setRawData((byte) (state.getRawData() + 1));
state.update(true);
} else {
// grow the cactus on the above block
state.setRawData((byte) 0);
state.update(true);
state = blockAbove.getState();
state.setType(Material.CACTUS);
state.setRawData((byte) 0);
BlockGrowEvent growEvent = new BlockGrowEvent(blockAbove, state);
EventFactory.callEvent(growEvent);
if (!growEvent.isCancelled()) {
state.update(true);
}
updatePhysics(blockAbove);
}
}
}
}
Aggregations