private MeshData GenMesh(ITesselatorAPI tesselator)
        {
            BlockGenericTypedContainer block = ownBlock as BlockGenericTypedContainer;

            if (ownBlock == null)
            {
                block    = api.World.BlockAccessor.GetBlock(pos) as BlockGenericTypedContainer;
                ownBlock = block;
            }
            if (block == null)
            {
                return(null);
            }

            string key = "typedContainerMeshes" + ownBlock.FirstCodePart() + block.Subtype;

            Dictionary <string, MeshData> meshes = ObjectCacheUtil.GetOrCreate(api, key, () =>
            {
                return(new Dictionary <string, MeshData>());
            });

            MeshData mesh;

            if (meshes.TryGetValue(type + block.Subtype, out mesh))
            {
                return(mesh);
            }

            string shapename = ownBlock.Attributes?["shape"][type].AsString();

            if (shapename == null)
            {
                return(null);
            }

            return(meshes[type + block.Subtype] = block.GenMesh(api as ICoreClientAPI, type, shapename, tesselator));
        }
Beispiel #2
0
        private MeshData GenMesh(ITesselatorAPI tesselator)
        {
            BlockGenericTypedContainer block = Block as BlockGenericTypedContainer;

            if (Block == null)
            {
                block = Api.World.BlockAccessor.GetBlock(Pos) as BlockGenericTypedContainer;
                Block = block;
            }
            if (block == null)
            {
                return(null);
            }
            int rndTexNum = Block.Attributes?["rndTexNum"][type]?.AsInt(0) ?? 0;

            string key = "typedContainerMeshes" + Block.Code.ToShortString();
            Dictionary <string, MeshData> meshes = ObjectCacheUtil.GetOrCreate(Api, key, () =>
            {
                return(new Dictionary <string, MeshData>());
            });
            MeshData mesh;

            string shapename = Block.Attributes?["shape"][type].AsString();

            if (shapename == null)
            {
                return(null);
            }

            Shape shape = null;

            if (animUtil != null)
            {
                string skeydict = "typedContainerShapes";
                Dictionary <string, Shape> shapes = ObjectCacheUtil.GetOrCreate(Api, skeydict, () =>
                {
                    return(new Dictionary <string, Shape>());
                });
                string skey = Block.FirstCodePart() + block.Subtype + "-" + "-" + shapename + "-" + rndTexNum;
                if (!shapes.TryGetValue(skey, out shape))
                {
                    shapes[skey] = shape = block.GetShape(Api as ICoreClientAPI, type, shapename, tesselator, rndTexNum);
                }
            }

            string meshKey = type + block.Subtype + "-" + rndTexNum;

            if (meshes.TryGetValue(meshKey, out mesh))
            {
                if (animUtil != null && animUtil.renderer == null)
                {
                    animUtil.InitializeAnimator(type + "-" + key, mesh, shape, rendererRot);
                }

                return(mesh);
            }


            if (rndTexNum > 0)
            {
                rndTexNum = GameMath.MurmurHash3Mod(Pos.X, Pos.Y, Pos.Z, rndTexNum);
            }

            if (animUtil != null)
            {
                if (animUtil.renderer == null)
                {
                    mesh = animUtil.InitializeAnimator(type + "-" + key, shape, block, rendererRot);
                }

                return(meshes[meshKey] = mesh);
            }
            else
            {
                mesh = block.GenMesh(Api as ICoreClientAPI, type, shapename, tesselator, new Vec3f(), rndTexNum);

                return(meshes[meshKey] = mesh);
            }
        }