use of net.glowstone.GlowWorld 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.GlowWorld in project Glowstone by GlowstoneMC.
the class BlockLeaves method updateBlock.
@Override
public void updateBlock(GlowBlock block) {
GlowBlockState state = block.getState();
if ((state.getRawData() & 0x08) != 0 && (state.getRawData() & 0x04) == 0) {
// check decay is on and decay is on
GlowWorld world = block.getWorld();
// build a 9x9x9 box to map neighboring blocks
for (int x = 0; x < 9; x++) {
for (int z = 0; z < 9; z++) {
for (int y = 0; y < 9; y++) {
GlowBlock b = world.getBlockAt(block.getLocation().add(x - 4, y - 4, z - 4));
byte val = 127;
if (b.getType() == Material.LOG || b.getType() == Material.LOG_2) {
val = 0;
} else if (b.getType() == Material.LEAVES || b.getType() == Material.LEAVES_2) {
val = -1;
}
setBlockInMap(val, x, y, z);
}
}
}
// to another connected leaves block will decay
for (int i = 0; i < 4; i++) {
for (int x = 0; x < 9; x++) {
for (int z = 0; z < 9; z++) {
for (int y = 0; y < 9; y++) {
if (getBlockInMap(x, y, z) == i) {
if (getBlockInMap(x - 1, y, z) == -1) {
setBlockInMap((byte) (i + 1), x - 1, y, z);
}
if (getBlockInMap(x, y - 1, z) == -1) {
setBlockInMap((byte) (i + 1), x, y - 1, z);
}
if (getBlockInMap(x, y, z - 1) == -1) {
setBlockInMap((byte) (i + 1), x, y, z - 1);
}
if (getBlockInMap(x + 1, y, z) == -1) {
setBlockInMap((byte) (i + 1), x + 1, y, z);
}
if (getBlockInMap(x, y + 1, z) == -1) {
setBlockInMap((byte) (i + 1), x, y + 1, z);
}
if (getBlockInMap(x, y, z + 1) == -1) {
setBlockInMap((byte) (i + 1), x, y, z + 1);
}
}
}
}
}
}
if (getBlockInMap(4, 4, 4) < 0) {
// leaf decay
LeavesDecayEvent decayEvent = new LeavesDecayEvent(block);
EventFactory.callEvent(decayEvent);
if (!decayEvent.isCancelled()) {
block.breakNaturally();
}
} else {
// cancel decay check on this leaves block
state.setRawData((byte) (state.getRawData() & -0x09));
state.update(true);
}
}
}
use of net.glowstone.GlowWorld in project Glowstone by GlowstoneMC.
the class BlockLeaves method blockDestroy.
@Override
public void blockDestroy(GlowPlayer player, GlowBlock block, BlockFace face) {
// vanilla set decay check in a 3x3x3 neighboring when a leaves block is removed
GlowWorld world = block.getWorld();
for (int x = 0; x < 3; x++) {
for (int z = 0; z < 3; z++) {
for (int y = 0; y < 3; y++) {
GlowBlock b = world.getBlockAt(block.getLocation().add(x - 1, y - 1, z - 1));
if (b.getType() == Material.LEAVES || b.getType() == Material.LEAVES_2) {
GlowBlockState state = b.getState();
if ((state.getRawData() & 0x08) == 0 && (state.getRawData() & 0x04) == 0) {
// check decay is off and decay is on
// set decay check on for this leaves block
state.setRawData((byte) (state.getRawData() | 0x08));
state.update(true);
}
}
}
}
}
}
Aggregations