use of net.glowstone.block.GlowBlockState in project Glowstone by GlowstoneMC.
the class BlockMycel method updateBlock.
@Override
public void updateBlock(GlowBlock block) {
GlowBlock blockAbove = block.getRelative(BlockFace.UP);
if (blockAbove.getLightLevel() < 4 && blockAbove.getMaterialValues().getLightOpacity() > 2) {
// mycel block turns into dirt block
GlowBlockState state = block.getState();
state.setType(Material.DIRT);
BlockFadeEvent fadeEvent = new BlockFadeEvent(block, state);
EventFactory.callEvent(fadeEvent);
if (!fadeEvent.isCancelled()) {
state.update(true);
}
} else if (blockAbove.getLightLevel() >= 9) {
GlowWorld world = block.getWorld();
int sourceX = block.getX();
int sourceY = block.getY();
int sourceZ = block.getZ();
// mycel spread randomly around
for (int i = 0; i < 4; i++) {
int x = sourceX + random.nextInt(3) - 1;
int z = sourceZ + random.nextInt(3) - 1;
int y = sourceY + random.nextInt(5) - 3;
GlowBlock targetBlock = world.getBlockAt(x, y, z);
GlowBlock targetAbove = targetBlock.getRelative(BlockFace.UP);
if (targetBlock.getType() == Material.DIRT && // only spread on normal dirt
targetBlock.getData() == 0 && targetAbove.getMaterialValues().getLightOpacity() <= 2 && targetAbove.getLightLevel() >= 4) {
GlowBlockState state = targetBlock.getState();
state.setType(Material.MYCEL);
state.setRawData((byte) 0);
BlockSpreadEvent spreadEvent = new BlockSpreadEvent(targetBlock, block, state);
EventFactory.callEvent(spreadEvent);
if (!spreadEvent.isCancelled()) {
state.update(true);
}
}
}
}
}
use of net.glowstone.block.GlowBlockState in project Glowstone by GlowstoneMC.
the class BlockNetherWart method updateBlock.
@Override
public void updateBlock(GlowBlock block) {
int cropState = block.getData();
if (cropState < NetherWartsState.RIPE.ordinal() && random.nextInt(10) == 0) {
cropState++;
GlowBlockState state = block.getState();
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 BlockFenceGate method onRedstoneUpdate.
@Override
public void onRedstoneUpdate(GlowBlock block) {
GlowBlockState state = block.getState();
Gate gate = (Gate) state.getData();
boolean powered = block.isBlockIndirectlyPowered();
if (powered != gate.isOpen()) {
gate.setOpen(powered);
state.update();
}
}
use of net.glowstone.block.GlowBlockState 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.getDirection();
((Door) data).setFacingDirection(facing.getOppositeFace());
// modify facing for double-doors
GlowBlock leftBlock = null;
switch(facing) {
case NORTH:
leftBlock = state.getBlock().getRelative(BlockFace.WEST);
break;
case WEST:
leftBlock = state.getBlock().getRelative(BlockFace.SOUTH);
break;
case SOUTH:
leftBlock = state.getBlock().getRelative(BlockFace.EAST);
break;
case EAST:
leftBlock = state.getBlock().getRelative(BlockFace.NORTH);
break;
}
if (leftBlock != null && leftBlock.getState().getData() instanceof Door) {
switch(facing) {
case NORTH:
data.setData((byte) 6);
break;
case WEST:
data.setData((byte) 5);
break;
case SOUTH:
data.setData((byte) 4);
break;
case EAST:
data.setData((byte) 7);
break;
}
}
// 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);
}
}
use of net.glowstone.block.GlowBlockState in project Glowstone by GlowstoneMC.
the class BlockDoor method onRedstoneUpdate.
@Override
public void onRedstoneUpdate(GlowBlock block) {
GlowBlockState state = block.getState();
Door door = (Door) state.getData();
if (!door.isTopHalf()) {
boolean powered = block.isBlockIndirectlyPowered();
if (powered != door.isOpen()) {
door.setOpen(powered);
state.update();
}
}
}
Aggregations