private void addBlockAtCoordAndAxis(Coord co, Axis axis, AlignedCoord alco, Coord nudgeCoord, BlockType btype) { Block neg_neighbor_block = this.m_chunk.blockAt(new ChunkIndex(co - nudgeCoord)); //x_one Block pos_neighbor_block = this.m_chunk.blockAt(new ChunkIndex(co + nudgeCoord)); int relevantComponent = Coord.SumOfComponents(co * nudgeCoord); int relevantUpperLimit = Coord.SumOfComponents(Chunk.DIMENSIONSINBLOCKS * nudgeCoord); Direction relevantPosDir = MeshBuilder.posDirectionForAxis(axis); FaceAggregator faXY = null; if (Block.BlockTypeIsATranslucentType(neg_neighbor_block.type) || Block.BlockTypeIsATranslucentType(pos_neighbor_block.type)) { faXY = faceAggregatorAt(co, relevantPosDir); // don't allocate if we won't have to... } //NEG NEIGHBOR if (!Block.BlockTypeIsATranslucentType(neg_neighbor_block.type)) // (neg_neighbor_block.type != BlockType.Air) { if (relevantComponent > 0) { // * neighbor not air, so there should be a face that is now hidden and that we should remove if (isFaceAggregatorAt(co - nudgeCoord, axis)) { FaceAggregator faXminusOne = faceAggregatorAt(co - nudgeCoord, relevantPosDir); // aggregatorArray[relevantComponent - 1]; faXminusOne.removePositiveSideFaceAtCoord(alco); // if faceSetCount now zero, remove faceAgg if (faXminusOne.faceSetCount == 0) { removeFaceAggregatorAt(co - nudgeCoord, axis); } else { // else get Face geom... faXminusOne.getFaceGeometry(relevantComponent - 1); } } } } else { // * neighbor is air, so we need to add a face at our coord faXY.addFaceAtCoordBlockType(new FaceInfo(co, Block.MAX_LIGHT_LEVEL, relevantPosDir + 1, btype, this.m_chunk.lightDataProvider)); faXY.getFaceGeometry(relevantComponent); } // POS NEIGHBOR // neighbor_block = this.m_chunk.blockAt(new ChunkIndex( co + nudgeCoord)); if (!Block.BlockTypeIsATranslucentType(pos_neighbor_block.type)) // (pos_neighbor_block.type != BlockType.Air) { if (relevantComponent < relevantUpperLimit - 1) { if (isFaceAggregatorAt(co + nudgeCoord, axis)) { // * neighbor not air, remove occluded face FaceAggregator faXplusone = faceAggregatorAt(co + nudgeCoord, relevantPosDir); // aggregatorArray[relevantComponent + 1]; faXplusone.removeNegativeSideFaceAtCoord(alco); //check if face agg now empty if (faXplusone.faceSetCount == 0) { removeFaceAggregatorAt(co + nudgeCoord, axis); } else { // else get Face geom... faXplusone.getFaceGeometry(relevantComponent + 1); } } } } else { // * neighbor is air, need to add a face at this coord faXY.addFaceAtCoordBlockType(new FaceInfo(co, Block.MAX_LIGHT_LEVEL, relevantPosDir, btype, this.m_chunk.lightDataProvider)); faXY.getFaceGeometry(relevantComponent); } }
private void removeBlockAtCoordAndAxis(Coord co, Axis axis, AlignedCoord alco, Coord nudgeCoord, BlockType btype) { Block test_b; test_b = this.m_chunk.blockAt(new ChunkIndex(co - nudgeCoord)); //x_one int relevantComponent = Coord.SumOfComponents(co * nudgeCoord); int relevantUpperLimit = Coord.SumOfComponents(Chunk.DIMENSIONSINBLOCKS * nudgeCoord); Direction relevantPosDir = MeshBuilder.posDirectionForAxis(axis); FaceAggregator faXY = null; if (isFaceAggregatorAt(co, axis)) { faXY = faceAggregatorAt(co, relevantPosDir); } // *Neg direction neighbor block wasn't air? // *we need to add a face on its pos side if (test_b.type != BlockType.Air) { if (relevantComponent > 0) { FaceAggregator faXminusOne = faceAggregatorAt(co - nudgeCoord, relevantPosDir); // aggregatorArray[relevantComponent - 1]; // TODO: make sure this func is really 'add face if not exists.' faXminusOne.addFaceAtCoordBlockType(new FaceInfo(co, Block.MAX_LIGHT_LEVEL, relevantPosDir, test_b.type, this.m_chunk.lightDataProvider)); faXminusOne.getFaceGeometry(relevantComponent - 1); // CONSIDER: TRY REMOVING A FACE AT THIS FACE AGG AS WELL. EVEN THOUGH THERE 'SHOULDN'T' BE ONE. // AND SIMILAR FOR ADDING BLOCKS } } else // it is air at x (or whichever co) - 1 { if (faXY != null) { // * neighbor is an air block, so there should be a face to remove at our block in this direction faXY.removeNegativeSideFaceAtCoord(alco); if (faXY.faceSetCount == 0) { removeFaceAggregatorAt(co, axis); } else { faXY.getFaceGeometry(relevantComponent); } } } // x plus one test_b = this.m_chunk.blockAt(new ChunkIndex(co + nudgeCoord)); if (test_b.type != BlockType.Air) { if (relevantComponent < relevantUpperLimit - 1) { FaceAggregator faXplusone = faceAggregatorAt(co + nudgeCoord, relevantPosDir); // aggregatorArray[relevantComponent + 1]; faXplusone.addFaceAtCoordBlockType(new FaceInfo(co, Block.MAX_LIGHT_LEVEL, relevantPosDir + 1, test_b.type, this.m_chunk.lightDataProvider)); faXplusone.getFaceGeometry(relevantComponent + 1); } } else { if (faXY != null) { // * neighbor was air, so there should be a face to remove faXY.removePositiveSideFaceAtCoord(alco); if (faXY.faceSetCount == 0) { removeFaceAggregatorAt(co, axis); } else { faXY.getFaceGeometry(relevantComponent); } faXY.getFaceGeometry(relevantComponent); } } }