public bool OnTesselation(ITerrainMeshPool mesher, ITesselatorAPI tessThreadTesselator) { ICoreClientAPI capi = api as ICoreClientAPI; Matrixf mat = new Matrixf(); mat.RotateYDeg(block.Shape.rotateY); for (int i = 0; i < 8; i++) { if (inv[i].Empty) { continue; } ItemStack stack = inv[i].Itemstack; BlockCrock crockblock = stack.Collectible as BlockCrock; Vec3f rot = new Vec3f(0, block.Shape.rotateY, 0); MeshData mesh = BlockEntityCrock.GetMesh(tessThreadTesselator, api, crockblock, crockblock.GetContents(api.World, stack), crockblock.GetRecipeCode(api.World, stack), rot); float y = i >= 4 ? 10 / 16f : 2 / 16f; float x = (i % 2 == 0) ? 4 / 16f : 12 / 16f; float z = ((i % 4) >= 2) ? 10 / 16f : 4 / 16f; Vec4f offset = mat.TransformVector(new Vec4f(x - 0.5f, y, z - 0.5f, 0)); mesh.Translate(offset.XYZ); mesher.AddMeshData(mesh); } return(false); }
protected override MeshData genMesh(ItemStack stack, int index) { BlockCrock crockblock = stack.Collectible as BlockCrock; BlockMeal mealblock = stack.Collectible as BlockMeal; MeshData mesh; if (crockblock != null) { Vec3f rot = new Vec3f(0, block.Shape.rotateY, 0); mesh = BlockEntityCrock.GetMesh(capi.Tesselator, Api, crockblock, crockblock.GetContents(Api.World, stack), crockblock.GetRecipeCode(Api.World, stack), rot).Clone(); } else if (mealblock != null) { ICoreClientAPI capi = Api as ICoreClientAPI; MealMeshCache meshCache = capi.ModLoader.GetModSystem <MealMeshCache>(); mesh = meshCache.GenMealInContainerMesh(mealblock, mealblock.GetCookingRecipe(capi.World, stack), mealblock.GetNonEmptyContents(capi.World, stack)); } else { ICoreClientAPI capi = Api as ICoreClientAPI; if (stack.Class == EnumItemClass.Block) { mesh = capi.TesselatorManager.GetDefaultBlockMesh(stack.Block).Clone(); } else { nowTesselatingItem = stack.Item; nowTesselatingShape = capi.TesselatorManager.GetCachedShape(stack.Item.Shape.Base); capi.Tesselator.TesselateItem(stack.Item, out mesh, this); mesh.RenderPasses.Fill((short)EnumChunkRenderPass.BlendNoCull); } } if (stack.Collectible.Attributes?["onDisplayTransform"].Exists == true) { ModelTransform transform = stack.Collectible.Attributes?["onDisplayTransform"].AsObject <ModelTransform>(); transform.EnsureDefaultValues(); mesh.ModelTransform(transform); } if (stack.Class == EnumItemClass.Item && (stack.Item.Shape == null || stack.Item.Shape.VoxelizeTexture)) { mesh.Rotate(new Vec3f(0.5f, 0.5f, 0.5f), GameMath.PIHALF, 0, 0); mesh.Scale(new Vec3f(0.5f, 0.5f, 0.5f), 0.33f, 0.5f, 0.33f); mesh.Translate(0, -7.5f / 16f, 0f); } float x = ((index % 4) >= 2) ? 12 / 16f : 4 / 16f; float y = index >= 4 ? 10 / 16f : 2 / 16f; float z = (index % 2 == 0) ? 4 / 16f : 10 / 16f; Vec4f offset = mat.TransformVector(new Vec4f(x - 0.5f, y, z - 0.5f, 0)); mesh.Translate(offset.XYZ); return(mesh); }
public override void GetHeldItemInfo(ItemSlot inSlot, StringBuilder dsc, IWorldAccessor world, bool withDebugInfo) { float temp = GetTemperature(world, inSlot.Itemstack); if (temp > 20) { dsc.AppendLine(Lang.Get("Temperature: {0}°C", (int)temp)); } CookingRecipe recipe = GetCookingRecipe(world, inSlot.Itemstack); ItemStack[] stacks = GetNonEmptyContents(world, inSlot.Itemstack); ItemSlot slot = BlockCrock.GetDummySlotForFirstPerishableStack(world, stacks, null, inSlot.Inventory); slot.Itemstack?.Collectible.AppendPerishableInfoText(slot, dsc, world); float servings = GetQuantityServings(world, inSlot.Itemstack); if (recipe != null) { if (Math.Round(servings, 1) < 0.05) { dsc.AppendLine(Lang.Get("{1}% serving of {0}", recipe.GetOutputName(world, stacks).UcFirst(), Math.Round(servings * 100, 0))); } else { dsc.AppendLine(Lang.Get("{0} serving of {1}", Math.Round(servings, 1), recipe.GetOutputName(world, stacks).UcFirst())); } } else { if (inSlot.Itemstack.Attributes.HasAttribute("quantityServings")) { dsc.AppendLine(Lang.Get("{0} servings left", Math.Round(servings, 1))); } else if (displayContentsInfo) { dsc.AppendLine(Lang.Get("Contents:")); if (stacks != null && stacks.Length > 0) { dsc.AppendLine(stacks[0].StackSize + "x " + stacks[0].GetName()); } } } if (!MealMeshCache.ContentsRotten(stacks)) { string facts = GetContentNutritionFacts(world, inSlot, null, recipe == null); if (facts != null) { dsc.Append(facts); } } }
private MeshData getMesh(ITesselatorAPI tesselator) { BlockCrock block = Api.World.BlockAccessor.GetBlock(Pos) as BlockCrock; if (block == null) { return(null); } ItemStack[] stacks = inventory.Where(slot => !slot.Empty).Select(slot => slot.Itemstack).ToArray(); Vec3f rot = new Vec3f(0, block.Shape.rotateY, 0); return(GetMesh(tesselator, Api, block, stacks, RecipeCode, rot)); }
public static MeshData GetMesh(ITesselatorAPI tesselator, ICoreAPI api, BlockCrock block, ItemStack[] stacks, string recipeCode, Vec3f rot) { Dictionary <string, MeshData> meshes = ObjectCacheUtil.GetOrCreate(api, "blockCrockMeshes", () => new Dictionary <string, MeshData>()); MeshData mesh = null; AssetLocation labelLoc = block.LabelForContents(recipeCode, stacks); if (labelLoc == null) { return(null); } if (meshes.TryGetValue(labelLoc.ToShortString() + block.Shape.rotateY, out mesh)) { return(mesh); } return(meshes[labelLoc.ToString() + block.Shape.rotateY] = block.GenMesh(api as ICoreClientAPI, labelLoc, rot, tesselator)); }
public override void GetHeldItemInfo(ItemSlot inSlot, StringBuilder dsc, IWorldAccessor world, bool withDebugInfo) { //base.GetHeldItemInfo(inSlot, dsc, world, withDebugInfo); float temp = GetTemperature(world, inSlot.Itemstack); if (temp > 20) { dsc.AppendLine(Lang.Get("Temperature: {0}°C", (int)temp)); } CookingRecipe recipe = GetMealRecipe(world, inSlot.Itemstack); float servings = inSlot.Itemstack.Attributes.GetFloat("quantityServings"); ItemStack[] stacks = GetNonEmptyContents(world, inSlot.Itemstack); if (recipe != null) { if (servings == 1) { dsc.AppendLine(Lang.Get("{0} serving of {1}", Math.Round(servings, 1), recipe.GetOutputName(world, stacks))); } else { dsc.AppendLine(Lang.Get("{0} servings of {1}", Math.Round(servings, 1), recipe.GetOutputName(world, stacks))); } } BlockMeal mealblock = api.World.GetBlock(new AssetLocation("bowl-meal")) as BlockMeal; string nutriFacts = mealblock.GetContentNutritionFacts(api.World, inSlot, stacks, null); if (nutriFacts != null) { dsc.AppendLine(nutriFacts); } ItemSlot slot = BlockCrock.GetDummySlotForFirstPerishableStack(api.World, stacks, null, inSlot.Inventory); slot.Itemstack?.Collectible.AppendPerishableInfoText(slot, dsc, world); }
public override void Initialize(ICoreAPI api) { base.Initialize(api); this.ownBlock = Block as BlockCrock; }
public string CrockInfoCompact(ItemSlot inSlot) { BlockMeal mealblock = Api.World.GetBlock(new AssetLocation("bowl-meal")) as BlockMeal; BlockCrock crock = inSlot.Itemstack.Collectible as BlockCrock; IWorldAccessor world = Api.World; CookingRecipe recipe = crock.GetCookingRecipe(world, inSlot.Itemstack); ItemStack[] stacks = crock.GetNonEmptyContents(world, inSlot.Itemstack); if (stacks == null || stacks.Length == 0) { return(Lang.Get("Empty Crock") + "\n"); } StringBuilder dsc = new StringBuilder(); if (recipe != null) { double servings = inSlot.Itemstack.Attributes.GetDecimal("quantityServings"); if (recipe != null) { if (servings == 1) { dsc.Append(Lang.Get("{0}x {1}.", servings, recipe.GetOutputName(world, stacks))); } else { dsc.Append(Lang.Get("{0}x {1}.", servings, recipe.GetOutputName(world, stacks))); } } } else { int i = 0; foreach (var stack in stacks) { if (stack == null) { continue; } if (i++ > 0) { dsc.Append(", "); } dsc.Append(stack.StackSize + "x " + stack.GetName()); } dsc.Append("."); } DummyInventory dummyInv = new DummyInventory(Api); ItemSlot contentSlot = BlockCrock.GetDummySlotForFirstPerishableStack(Api.World, stacks, null, dummyInv); dummyInv.OnAcquireTransitionSpeed = (transType, stack, mul) => { return(mul * crock.GetContainingTransitionModifierContained(world, inSlot, transType) * inv.GetTransitionSpeedMul(transType, stack)); }; TransitionState[] transitionStates = contentSlot.Itemstack?.Collectible.UpdateAndGetTransitionStates(Api.World, contentSlot); bool addNewLine = true; if (transitionStates != null) { for (int i = 0; i < transitionStates.Length; i++) { TransitionState state = transitionStates[i]; TransitionableProperties prop = state.Props; float perishRate = contentSlot.Itemstack.Collectible.GetTransitionRateMul(world, contentSlot, prop.Type); if (perishRate <= 0) { continue; } addNewLine = false; float transitionLevel = state.TransitionLevel; float freshHoursLeft = state.FreshHoursLeft / perishRate; switch (prop.Type) { case EnumTransitionType.Perish: if (transitionLevel > 0) { dsc.AppendLine(" " + Lang.Get("{0}% spoiled", (int)Math.Round(transitionLevel * 100))); } else { double hoursPerday = Api.World.Calendar.HoursPerDay; if (freshHoursLeft / hoursPerday >= Api.World.Calendar.DaysPerYear) { dsc.AppendLine(" " + Lang.Get("Fresh for {0} years", Math.Round(freshHoursLeft / hoursPerday / Api.World.Calendar.DaysPerYear, 1))); } /*else if (freshHoursLeft / hoursPerday >= Api.World.Calendar.DaysPerMonth) - confusing. 12 days per months and stuff.. * { * dsc.AppendLine(Lang.Get("<font color=\"orange\">Perishable.</font> Fresh for {0} months", Math.Round(freshHoursLeft / hoursPerday / Api.World.Calendar.DaysPerMonth, 1))); * }*/ else if (freshHoursLeft > hoursPerday) { dsc.AppendLine(" " + Lang.Get("Fresh for {0} days", Math.Round(freshHoursLeft / hoursPerday, 1))); } else { dsc.AppendLine(" " + Lang.Get("Fresh for {0} hours", Math.Round(freshHoursLeft, 1))); } } break; } } } if (addNewLine) { dsc.AppendLine(""); } return(dsc.ToString()); }