InCampFireProps GetRenderProps(ItemStack contentStack) { if (contentStack?.ItemAttributes?.KeyExists("inCampFireProps") == true) { InCampFireProps props = contentStack.ItemAttributes["inCampFireProps"].AsObject <InCampFireProps>(); props.Transform.EnsureDefaultValues(); return(props); } return(null); }
void UpdateRenderer() { if (renderer == null) { return; } ItemStack contentStack = inputStack == null ? outputStack : inputStack; 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 IInCampFireRendererSupplier) { IInCampFireRenderer childrenderer = (contentStack?.Collectible as IInCampFireRendererSupplier).GetRendererWhenInCampfire(contentStack, this, contentStack == outputStack); if (childrenderer != null) { renderer.SetChildRenderer(contentStack, childrenderer); return; } } InCampFireProps props = GetRenderProps(contentStack); if (contentStack?.Collectible != null && !(contentStack?.Collectible is IInCampFireMeshSupplier) && props != null) { renderer.SetContents(contentStack, props.Transform); } else { renderer.SetContents(null, null); } }
private MeshData getContentMesh(ItemStack contentStack, ITesselatorAPI tesselator) { CurrentModel = EnumCampFireModel.Normal; if (contentStack == null) { return(null); } if (contentStack.Collectible is IInCampFireMeshSupplier) { EnumCampFireModel model = EnumCampFireModel.Normal; MeshData mesh = (contentStack.Collectible as IInCampFireMeshSupplier).GetMeshWhenInCampfire(contentStack, Api.World, Pos, ref model); this.CurrentModel = model; if (mesh != null) { return(mesh); } } if (contentStack.Collectible is IInCampFireRendererSupplier) { EnumCampFireModel model = (contentStack.Collectible as IInCampFireRendererSupplier).GetDesiredCampfireModel(contentStack, this, contentStack == outputStack); this.CurrentModel = model; return(null); } InCampFireProps renderProps = GetRenderProps(contentStack); if (renderProps != null) { this.CurrentModel = renderProps.UseCampfireModel; 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.UseCampfireModel != EnumCampFireModel.Spit) { ingredientMesh.Translate(0, -1 / 16f, 0); } if (!IsBurning && renderProps.UseCampfireModel != EnumCampFireModel.Over) { ingredientMesh.Translate(0, -1 / 16f, 0); } return(ingredientMesh); } return(null); } else { if (renderer.RequireSpit) { this.CurrentModel = EnumCampFireModel.Spit; } if (renderer.RequireOver) { this.CurrentModel = EnumCampFireModel.Over; } return(null); // Mesh drawing is handled by the FirepitContentsRenderer } }