Ejemplo n.º 1
0
        private MeshData getContentMesh(ItemStack contentStack, ref int index, ITesselatorAPI tesselator)
        {
            if (contentStack == null)
            {
                return(null);
            }

            if (contentStack.Collectible is IInFirepitMeshSupplier)
            {
                EnumFirepitModel model = EnumFirepitModel.Normal;
                MeshData         mesh  = (contentStack.Collectible as IInFirepitMeshSupplier).GetMeshWhenInFirepit(contentStack, api.World, pos, ref model);

                if (mesh != null)
                {
                    index += (int)model;
                    return(mesh);
                }
            }

            if (contentStack.Collectible is IInFirepitRendererSupplier)
            {
                EnumFirepitModel model = (contentStack.Collectible as IInFirepitRendererSupplier).GetDesiredFirepitModel(contentStack, this, contentStack == outputStack);
                index += (int)model;
                return(null);
            }

            InFirePitProps renderProps = GetRenderProps(contentStack);

            if (renderProps != null)
            {
                index += (int)renderProps.UseFirepitModel;

                if (contentStack.Class != EnumItemClass.Item)
                {
                    MeshData ingredientMesh;
                    tesselator.TesselateBlock(contentStack.Block, out ingredientMesh);

                    ingredientMesh.ModelTransform(renderProps.Transform);

                    // Lower by 1 voxel if extinct
                    if (!IsBurning && renderProps.UseFirepitModel != EnumFirepitModel.Cooking)
                    {
                        ingredientMesh.Translate(0, -1 / 16f, 0);
                    }

                    return(ingredientMesh);
                }

                return(null);
            }
            else
            {
                if (renderer.RequireSpit)
                {
                    index += 1;
                }
                return(null); // Mesh drawing is handled by the FirepitContentsRenderer
            }
        }
Ejemplo n.º 2
0
 InFirePitProps GetRenderProps(ItemStack contentStack)
 {
     if (contentStack?.ItemAttributes?.KeyExists("inFirePitProps") == true)
     {
         InFirePitProps props = contentStack.ItemAttributes["inFirePitProps"].AsObject <InFirePitProps>();
         props.Transform.EnsureDefaultValues();
         return(props);
     }
     return(null);
 }
Ejemplo n.º 3
0
        void UpdateRenderer()
        {
            if (renderer == null)
            {
                return;
            }

            ItemStack contentStack = inputStack == null ? outputStack : inputStack;
            ItemStack prevStack    = renderer.ContentStack;

            bool useOldRenderer =
                renderer.ContentStack != null &&
                renderer.contentStackRenderer != null &&
                contentStack?.Collectible is IInFirepitRendererSupplier &&
                renderer.ContentStack.Equals(api.World, contentStack, GlobalConstants.IgnoredStackAttributes)
            ;

            if (useOldRenderer)
            {
                return;                 // Otherwise the cooking sounds restarts all the time
            }
            renderer.contentStackRenderer?.Dispose();
            renderer.contentStackRenderer = null;

            if (contentStack?.Collectible is IInFirepitRendererSupplier)
            {
                IInFirepitRenderer childrenderer = (contentStack.Collectible as IInFirepitRendererSupplier).GetRendererWhenInFirepit(contentStack, this, contentStack == outputStack);
                if (childrenderer != null)
                {
                    renderer.SetChildRenderer(contentStack, childrenderer);
                    return;
                }
            }

            InFirePitProps props = GetRenderProps(contentStack);

            if (contentStack?.Collectible != null && !(contentStack?.Collectible is IInFirepitMeshSupplier) && props != null)
            {
                renderer.SetContents(contentStack, props.Transform);
            }
            else
            {
                renderer.SetContents(null, null);
            }
        }
Ejemplo n.º 4
0
        void UpdateRenderer()
        {
            if (renderer == null)
            {
                return;
            }

            ItemStack contentStack = inputStack == null ? outputStack : inputStack;
            ItemStack prevStack    = renderer.ContentStack;

            if (prevStack != null && prevStack.Equals(api.World, contentStack, GlobalConstants.IgnoredStackAttributes))
            {
                // But still update the stack for the temperature update
                renderer.ContentStack = contentStack;
                return;
            }

            renderer.contentStackRenderer?.Dispose();
            renderer.contentStackRenderer = null;

            if (contentStack?.Collectible is IInFirepitRendererSupplier)
            {
                IInFirepitRenderer childrenderer = (contentStack.Collectible as IInFirepitRendererSupplier).GetRendererWhenInFirepit(contentStack, this, contentStack == outputStack);
                if (childrenderer != null)
                {
                    renderer.SetChildRenderer(contentStack, childrenderer);
                    return;
                }
            }

            InFirePitProps props = GetRenderProps(contentStack);

            if (contentStack?.Collectible != null && !(contentStack?.Collectible is IInFirepitMeshSupplier) && (props == null || contentStack.Class == EnumItemClass.Item))
            {
                renderer.SetContents(contentStack, props?.Transform);
            }
            else
            {
                renderer.SetContents(null, null);
            }
        }