for (int cz = 0; cz < 16; ++cz) {
int z = cz + cp.z*16 - origin.z;
for (int cx = 0; cx < 16; ++cx) {
int x = cx + cp.x*16 - origin.x;
int type = octree.get(x, cy, z);
Block block = Block.get(type);
// set non-visible blocks to be stone, in order to merge large patches
if ((cx == 0 || cx == 15 || cz == 0 || cz == 15) &&
cy > -origin.y && cy < Chunk.Y_MAX-origin.y-1 &&
block != Block.STONE && block.isOpaque) {
if (Block.get(octree.get(x-1, cy, z)).isOpaque &&
Block.get(octree.get(x+1, cy, z)).isOpaque &&
Block.get(octree.get(x, cy-1, z)).isOpaque &&
Block.get(octree.get(x, cy+1, z)).isOpaque &&
Block.get(octree.get(x, cy, z-1)).isOpaque &&
Block.get(octree.get(x, cy, z+1)).isOpaque) {
octree.set(Block.STONE.id, x, cy, z);
continue;
}
}
int fullBlock;
int data;
int level0;
int level;
int corner0;
int corner1;
int corner2;
int corner3;
int connections;
int dir;
int bd;
int bd_alt;
int tex;
Block other;
Block other_alt;
Block above;
Block west;
Block east;
Block north;
Block south;
switch (block.id) {
case Block.LARGE_FLOWER_ID:
data = type >> BlockData.OFFSET;
if ((data&8) != 0) {
// get flower kind from block beneath
int kind = (octree.get(x, cy-1, z) >> BlockData.OFFSET)&7;
type = (type & ~(15<<BlockData.OFFSET)) | ( (8|kind) << BlockData.OFFSET);
octree.set(type, x, cy, z);
}
break;
case Block.WATER_ID:
fullBlock = (type >> WaterModel.FULL_BLOCK) & 1;
if (fullBlock != 0) break;
level0 = 8 - (0xF & (type >> 8));
corner0 = level0;
corner1 = level0;
corner2 = level0;
corner3 = level0;
data = octree.get(x-1, cy, z);
level = level0;
if (Block.get(data) == Block.WATER) {
fullBlock = (data >> WaterModel.FULL_BLOCK) & 1;
level = 8 - (1-fullBlock) * (7 & (data >> 8));
} else if (!Block.get(data).isSolid) {
level = 0;
}
corner3 += level;
corner0 += level;
data = octree.get(x-1, cy, z+1);
level = level0;
if (Block.get(data) == Block.WATER) {
fullBlock = (data >> WaterModel.FULL_BLOCK) & 1;
level = 8 - (1-fullBlock) * (7 & (data >> 8));
} else if (!Block.get(data).isSolid) {
level = 0;
}
corner0 += level;
data = octree.get(x, cy, z+1);
level = level0;
if (Block.get(data) == Block.WATER) {
fullBlock = (data >> WaterModel.FULL_BLOCK) & 1;
level = 8 - (1-fullBlock) * (7 & (data >> 8));
} else if (!Block.get(data).isSolid) {
level = 0;
}
corner0 += level;
corner1 += level;
data = octree.get(x+1, cy, z+1);
level = level0;
if (Block.get(data) == Block.WATER) {
fullBlock = (data >> WaterModel.FULL_BLOCK) & 1;
level = 8 - (1-fullBlock) * (7 & (data >> 8));
} else if (!Block.get(data).isSolid) {
level = 0;
}
corner1 += level;
data = octree.get(x+1, cy, z);
level = level0;
if (Block.get(data) == Block.WATER) {
fullBlock = (data >> WaterModel.FULL_BLOCK) & 1;
level = 8 - (1-fullBlock) * (7 & (data >> 8));
} else if (!Block.get(data).isSolid) {
level = 0;
}
corner1 += level;
corner2 += level;
data = octree.get(x+1, cy, z-1);
level = level0;
if (Block.get(data) == Block.WATER) {
fullBlock = (data >> WaterModel.FULL_BLOCK) & 1;
level = 8 - (1-fullBlock) * (7 & (data >> 8));
} else if (!Block.get(data).isSolid) {
level = 0;
}
corner2 += level;
data = octree.get(x, cy, z-1);
level = level0;
if (Block.get(data) == Block.WATER) {
fullBlock = (data >> WaterModel.FULL_BLOCK) & 1;
level = 8 - (1-fullBlock) * (7 & (data >> 8));
} else if (!Block.get(data).isSolid) {
level = 0;
}
corner2 += level;
corner3 += level;
data = octree.get(x-1, cy, z-1);
level = level0;
if (Block.get(data) == Block.WATER) {
fullBlock = (data >> WaterModel.FULL_BLOCK) & 1;
level = 8 - (1-fullBlock) * (7 & (data >> 8));
} else if (!Block.get(data).isSolid) {
level = 0;
}
corner3 += level;
corner0 = Math.min(7, 8 - (corner0 / 4));
corner1 = Math.min(7, 8 - (corner1 / 4));
corner2 = Math.min(7, 8 - (corner2 / 4));
corner3 = Math.min(7, 8 - (corner3 / 4));
type |= (corner0 << 16);
type |= (corner1 << 20);
type |= (corner2 << 24);
type |= (corner3 << 28);
octree.set(type, x, cy, z);
break;
case Block.LAVA_ID:
fullBlock = (type >> WaterModel.FULL_BLOCK) & 1;
if (fullBlock != 0) break;
level0 = 8 - (0xF & (type >> 8));
corner0 = level0;
corner1 = level0;
corner2 = level0;
corner3 = level0;
data = octree.get(x-1, cy, z);
level = level0;
if (Block.get(data) == Block.LAVA) {
fullBlock = (data >> WaterModel.FULL_BLOCK) & 1;
level = 8 - (1-fullBlock) * (7 & (data >> 8));
} else if (!Block.get(data).isSolid) {
level = 0;
}
corner3 += level;
corner0 += level;
data = octree.get(x-1, cy, z+1);
level = level0;
if (Block.get(data) == Block.LAVA) {
fullBlock = (data >> WaterModel.FULL_BLOCK) & 1;
level = 8 - (1-fullBlock) * (7 & (data >> 8));
} else if (!Block.get(data).isSolid) {
level = 0;
}
corner0 += level;
data = octree.get(x, cy, z+1);
level = level0;
if (Block.get(data) == Block.LAVA) {
fullBlock = (data >> WaterModel.FULL_BLOCK) & 1;
level = 8 - (1-fullBlock) * (7 & (data >> 8));
} else if (!Block.get(data).isSolid) {
level = 0;
}
corner0 += level;
corner1 += level;
data = octree.get(x+1, cy, z+1);
level = level0;
if (Block.get(data) == Block.LAVA) {
fullBlock = (data >> WaterModel.FULL_BLOCK) & 1;
level = 8 - (1-fullBlock) * (7 & (data >> 8));
} else if (!Block.get(data).isSolid) {
level = 0;
}
corner1 += level;
data = octree.get(x+1, cy, z);
level = level0;
if (Block.get(data) == Block.LAVA) {
fullBlock = (data >> WaterModel.FULL_BLOCK) & 1;
level = 8 - (1-fullBlock) * (7 & (data >> 8));
} else if (!Block.get(data).isSolid) {
level = 0;
}
corner1 += level;
corner2 += level;
data = octree.get(x+1, cy, z-1);
level = level0;
if (Block.get(data) == Block.LAVA) {
fullBlock = (data >> WaterModel.FULL_BLOCK) & 1;
level = 8 - (1-fullBlock) * (7 & (data >> 8));
} else if (!Block.get(data).isSolid) {
level = 0;
}
corner2 += level;
data = octree.get(x, cy, z-1);
level = level0;
if (Block.get(data) == Block.LAVA) {
fullBlock = (data >> WaterModel.FULL_BLOCK) & 1;
level = 8 - (1-fullBlock) * (7 & (data >> 8));
} else if (!Block.get(data).isSolid) {
level = 0;
}
corner2 += level;
corner3 += level;
data = octree.get(x-1, cy, z-1);
level = level0;
if (Block.get(data) == Block.LAVA) {
fullBlock = (data >> WaterModel.FULL_BLOCK) & 1;
level = 8 - (1-fullBlock) * (7 & (data >> 8));
} else if (!Block.get(data).isSolid) {
level = 0;
}
corner3 += level;
corner0 = Math.min(7, 8 - (corner0 / 4));
corner1 = Math.min(7, 8 - (corner1 / 4));
corner2 = Math.min(7, 8 - (corner2 / 4));
corner3 = Math.min(7, 8 - (corner3 / 4));
type |= (corner0 << 16);
type |= (corner1 << 20);
type |= (corner2 << 24);
type |= (corner3 << 28);
octree.set(type, x, cy, z);
break;
case Block.TRIPWIRE_ID:
other = Block.get(octree.get(x - 1, cy, z));
if (other == Block.TRIPWIRE || other == Block.TRIPWIREHOOK) {
type |= 1 << 12;
} else {
other = Block.get(octree.get(x + 1, cy, z));
if (other == Block.TRIPWIRE || other == Block.TRIPWIREHOOK) {
type |= 1 << 12;
}
}
octree.set(type, x, cy, z);
break;
case Block.REDSTONEWIRE_ID:
above = Block.get(octree.get(x, cy + 1, z));
west = Block.get(octree.get(x - 1, cy, z));
east = Block.get(octree.get(x + 1, cy, z));
north = Block.get(octree.get(x, cy, z - 1));
south = Block.get(octree.get(x, cy, z + 1));
if (above == Block.AIR) {
Block westAbove = Block.get(octree.get(x - 1, cy + 1, z));
if (west.isSolid && westAbove == Block.REDSTONEWIRE) {
// wire on west block side
type |= 1 << BlockData.RSW_WEST_CONNECTION;
type |= 1 << BlockData.RSW_WEST_SIDE;
}
Block eastAbove = Block.get(octree.get(x + 1, cy + 1, z));
if (east.isSolid && eastAbove == Block.REDSTONEWIRE) {
// wire on east block side
type |= 1 << BlockData.RSW_EAST_CONNECTION;
type |= 1 << BlockData.RSW_EAST_SIDE;
}
Block northAbove = Block.get(octree.get(x, cy + 1, z - 1));
if (north.isSolid && northAbove == Block.REDSTONEWIRE) {
// wire on north block side
type |= 1 << BlockData.RSW_NORTH_CONNECTION;
type |= 1 << BlockData.RSW_NORTH_SIDE;
}
Block southAbove = Block.get(octree.get(x, cy + 1, z + 1));
if (south.isSolid && southAbove == Block.REDSTONEWIRE) {
// wire on south block side
type |= 1 << BlockData.RSW_SOUTH_CONNECTION;
type |= 1 << BlockData.RSW_SOUTH_SIDE;
}
}
if (west.isRedstoneWireConnector()) {
type |= 1 << BlockData.RSW_WEST_CONNECTION;
} else if (west == Block.AIR) {
Block westBelow = Block.get(octree.get(x - 1, cy - 1, z));
if (westBelow == Block.REDSTONEWIRE) {
type |= 1 << BlockData.RSW_WEST_CONNECTION;
}
}
if (east.isRedstoneWireConnector()) {
type |= 1 << BlockData.RSW_EAST_CONNECTION;
} else if (east == Block.AIR) {
Block eastBelow = Block.get(octree.get(x + 1, cy - 1, z));
if (eastBelow == Block.REDSTONEWIRE) {
type |= 1 << BlockData.RSW_EAST_CONNECTION;
}
}
if (north.isRedstoneWireConnector() || south.isRedstoneWireConnector()) {
type |= 1 << BlockData.RSW_NORTH_CONNECTION;
} else if (north == Block.AIR) {
Block northBelow = Block.get(octree.get(x, cy - 1, z - 1));
if (northBelow == Block.REDSTONEWIRE) {
type |= 1 << BlockData.RSW_NORTH_CONNECTION;
}
}
if (south.isRedstoneWireConnector()) {
type |= 1 << BlockData.RSW_SOUTH_CONNECTION;
} else if (south == Block.AIR) {
Block southBelow = Block.get(octree.get(x, cy - 1, z + 1));
if (southBelow == Block.REDSTONEWIRE) {
type |= 1 << BlockData.RSW_SOUTH_CONNECTION;
}
}