Exemplo n.º 1
0
        public void SetBlock(int x, int y, int z, Block block, bool isInRange = false)
        {
            if (!isInRange && !IsInRange(x, y, z))
            {
                chunk.SetBlock(x, chunkOffsetY + y, z, block);
            }
            else
            {
                Block b = GetRealBlock(x, y, z);
                BlockAttributeCalculator old           = BlockAttributeCalculatorFactory.GetCalculator(b.BlockType);
                BlockRenderType          oldRenderType = old.GetBlockRenderType(b.ExtendId);
                if (oldRenderType != BlockRenderType.None)
                {
                    visibleBlocks--;
                }

                if (oldRenderType == BlockRenderType.Part)
                {
                    specialBlocks--;
                }
                BlockAttributeCalculator cur           = BlockAttributeCalculatorFactory.GetCalculator(block.BlockType);
                BlockRenderType          curRenderType = cur.GetBlockRenderType(block.ExtendId);
                if (curRenderType != BlockRenderType.None)
                {
                    visibleBlocks++;
                }
                if (curRenderType == BlockRenderType.Part)
                {
                    specialBlocks++;
                }
                SetRealBlock(x, y, z, block);
                chunk.isUpdate = true;
            }
        }
Exemplo n.º 2
0
        private void CalculateRenderMesh(Chunk chunk, MeshData meshData, int x1, int y1, int z1, int x2, int y2, int z2,
                                         Block bA, Block bB, BlockAttributeCalculator aBAC, BlockAttributeCalculator bBAC, int direction, bool bBInRange)
        {
            BlockRenderType aBACRenderType = aBAC.GetBlockRenderType(bA.ExtendId);

            if (aBACRenderType == BlockRenderType.Part)
            {
                //渲染(特殊)物块
                aBAC.CalculateSpecialMesh(chunk, x1, y1, z1, meshData, bA, bB, bBAC, (Direction)direction);
            }

            BlockRenderType bBACRenderType = bBAC.GetBlockRenderType(bB.ExtendId);

            if (bBACRenderType == BlockRenderType.Part)
            {
                //不能因为x2,y2,z2有可能不在chunk中 而需要保证x2,y2,z2在chunk中)
//				Chunk tempChunk = chunk;
//				if(!bBInRange)
//				{
//					int x2WorldPos = chunk.worldPos.x + x2;
//					int y2WorldPos = chunk.worldPos.y + y2;
//					int z2WorldPos = chunk.worldPos.z + z2;
//					tempChunk = chunk.world.GetChunk(x2WorldPos,y2WorldPos,z2WorldPos);
//					x2 = x2WorldPos - tempChunk.worldPos.x;
//					y2 = y2WorldPos - tempChunk.worldPos.y;
//					z2 = z2WorldPos - tempChunk.worldPos.z;
//				}
                //渲染(特殊)物块(不能确定当前坐标会在chunk中)
                bBAC.CalculateSpecialMesh(chunk, x2, y2, z2, meshData, bB, bA, aBAC, (Direction)(-direction));
            }
        }
Exemplo n.º 3
0
 public virtual bool CanCalculateMesh(Block self, Block other, BlockAttributeCalculator otherCalculator, Direction direction)
 {
     if (GetBlockRenderType(self.ExtendId) == BlockRenderType.All &&
         otherCalculator.GetBlockRenderType(other.ExtendId) != BlockRenderType.All)
     {
         return(true);
     }
     return(false);
 }
Exemplo n.º 4
0
 public override void CalculateSpecialMesh(Chunk chunk, int x, int y, int z, MeshData meshData, Block self, Block other, BlockAttributeCalculator otherCalculator, Direction direction)
 {
     if (other.BlockType == BlockType.Air || (direction == Direction.up && other.BlockType != BlockType.FlowingWater && other.BlockType != BlockType.StillWater) ||
         otherCalculator.GetBlockRenderType(other.ExtendId) == MTB.BlockRenderType.Part && other.BlockType != BlockType.FlowingWater && other.BlockType != BlockType.StillWater)
     {
         meshData.useTransparentTexture = true;
         meshData.useDoubleFace         = true;
         CalculatorDirection(chunk, x, y, z, meshData, self.ExtendId, direction);
         meshData.useTransparentTexture = MeshData.DefaultUseTransparentTexture;
         meshData.useDoubleFace         = MeshData.DefaultUseDoubleFace;
     }
 }