Пример #1
0
        public void RegenMesh(ItemStack workitemStack, byte[,,] voxels, bool[,,] recipeToOutlineVoxels)
        {
            workItemMeshRef?.Dispose();
            workItemMeshRef = null;
            this.ingot      = workitemStack;

            if (workitemStack == null)
            {
                return;
            }

            ObjectCacheUtil.Delete(api, "" + workitemStack.Attributes.GetInt("meshRefId"));
            workitemStack.Attributes.RemoveAttribute("meshRefId");

            if (recipeToOutlineVoxels != null)
            {
                RegenOutlineMesh(recipeToOutlineVoxels, voxels);
            }

            MeshData workItemMesh = ItemWorkItem.GenMesh(api, workitemStack, voxels, out texId);

            workItemMeshRef = api.Render.UploadMesh(workItemMesh);
        }
        void RegenMesh()
        {
            workItemMeshRef?.Dispose();
            workItemMeshRef = null;
            if (stack == null)
            {
                return;
            }

            Shape shape;

            tmpMetal = stack.Collectible.LastCodePart();
            MeshData mesh = null;

            string firstCodePart = stack.Collectible.FirstCodePart();

            if (firstCodePart == "metalplate")
            {
                tmpTextureSource = capi.Tesselator.GetTexSource(capi.World.GetBlock(new AssetLocation("platepile")));
                shape            = capi.Assets.TryGet("shapes/block/stone/forge/platepile.json").ToObject <Shape>();
                textureId        = tmpTextureSource[tmpMetal].atlasTextureId;
                capi.Tesselator.TesselateShape("block-fcr", shape, out mesh, this, null, 0, 0, 0, stack.StackSize);
            }
            else if (firstCodePart == "workitem")
            {
                MeshData workItemMesh = ItemWorkItem.GenMesh(capi, stack, ItemWorkItem.GetVoxels(stack), out textureId);
                workItemMesh.Scale(new Vec3f(0.5f, 0.5f, 0.5f), 0.75f, 0.75f, 0.75f);
                workItemMesh.Translate(0, -9f / 16f, 0);
                workItemMeshRef = capi.Render.UploadMesh(workItemMesh);
            }
            else if (firstCodePart == "ingot")
            {
                tmpTextureSource = capi.Tesselator.GetTexSource(capi.World.GetBlock(new AssetLocation("ingotpile")));
                shape            = capi.Assets.TryGet("shapes/block/stone/forge/ingotpile.json").ToObject <Shape>();
                textureId        = tmpTextureSource[tmpMetal].atlasTextureId;
                capi.Tesselator.TesselateShape("block-fcr", shape, out mesh, this, null, 0, 0, 0, stack.StackSize);
            }
            else if (stack.Collectible.Attributes?.IsTrue("forgable") == true)
            {
                if (stack.Class == EnumItemClass.Block)
                {
                    mesh      = capi.TesselatorManager.GetDefaultBlockMesh(stack.Block).Clone();
                    textureId = capi.BlockTextureAtlas.AtlasTextureIds[0];
                }
                else
                {
                    capi.Tesselator.TesselateItem(stack.Item, out mesh);
                    textureId = capi.ItemTextureAtlas.AtlasTextureIds[0];
                }

                ModelTransform tf = stack.Collectible.Attributes["inForgeTransform"].AsObject <ModelTransform>();
                if (tf != null)
                {
                    tf.EnsureDefaultValues();
                    mesh.ModelTransform(tf);
                }
            }

            if (mesh != null)
            {
                //mesh.Rgba2 = null;
                workItemMeshRef = capi.Render.UploadMesh(mesh);
            }
        }