Ejemplo n.º 1
0
        /// <inheritdoc />
        public override void BlockUpdate(World world, Vector3i position, uint data, BlockSide side)
        {
            uint newData = data;

            if (side.IsLateral())
            {
                newData = CheckNeighbor(side.Offset(position), side.Opposite(), side.ToOrientation().ToFlag(), newData);
            }

            if (newData != data)
            {
                world.SetBlock(this.AsInstance(newData), position);
            }

            uint CheckNeighbor(Vector3i neighborPosition, BlockSide neighborSide, uint mask, uint oldData)
            {
                if (world.GetBlock(neighborPosition)?.Block is TConnectable neighbor &&
                    neighbor.IsConnectable(world, neighborSide, neighborPosition))
                {
                    oldData |= mask;
                }
Ejemplo n.º 2
0
                            void MeshSimpleSide(BlockSide side)
                            {
                                ClientSection?neighbor = neighbors[(int)side];
                                Block?        blockToCheck;

                                Vector3i checkPos = side.Offset(pos);

                                if (IsPositionOutOfSection(checkPos))
                                {
                                    checkPos = checkPos.Mod(SectionSize);

                                    bool atVerticalEnd = side is BlockSide.Top or BlockSide.Bottom;

                                    blockToCheck = neighbor?.GetBlock(checkPos) ??
                                                   (atVerticalEnd ? Block.Air : null);
                                }
                                else
                                {
                                    blockToCheck = GetBlock(checkPos);
                                }

                                if (blockToCheck == null)
                                {
                                    return;
                                }

                                if (!blockToCheck.IsFull ||
                                    !blockToCheck.IsOpaque && (currentBlock.IsOpaque ||
                                                               currentBlock.RenderFaceAtNonOpaques ||
                                                               blockToCheck.RenderFaceAtNonOpaques))
                                {
                                    BlockMeshData mesh = currentBlock.GetMesh(
                                        BlockMeshInfo.Simple(side, data, currentLiquid));

                                    side.Corners(out int[] a, out int[] b, out int[] c, out int[] d);
                                    int[][] uvs = BlockModels.GetBlockUVs(mesh.IsTextureRotated);

                                    // int: uv-- ---- ---- -xxx xxyy yyyz zzzz (uv: texture coords; xyz: position)
                                    int upperDataA = (uvs[0][0] << 31) | (uvs[0][1] << 30) | ((a[0] + x) << 10) |
                                                     ((a[1] + y) << 5) | (a[2] + z);

                                    int upperDataB = (uvs[1][0] << 31) | (uvs[1][1] << 30) | ((b[0] + x) << 10) |
                                                     ((b[1] + y) << 5) | (b[2] + z);

                                    int upperDataC = (uvs[2][0] << 31) | (uvs[2][1] << 30) | ((c[0] + x) << 10) |
                                                     ((c[1] + y) << 5) | (c[2] + z);

                                    int upperDataD = (uvs[3][0] << 31) | (uvs[3][1] << 30) | ((d[0] + x) << 10) |
                                                     ((d[1] + y) << 5) | (d[2] + z);

                                    // int: tttt tttt t--n nn-a ---i iiii iiii iiii (t: tint; n: normal; a: animated; i: texture index)
                                    int lowerData = (mesh.Tint.GetBits(blockTint) << 23) | ((int)side << 18) |
                                                    mesh.GetAnimationBit(shift: 16) | mesh.TextureIndex;

                                    blockMeshFaceHolders[(int)side].AddFace(
                                        pos,
                                        lowerData,
                                        (upperDataA, upperDataB, upperDataC, upperDataD),
                                        mesh.IsTextureRotated);
                                }
                            }