public override void OnHeldInteractStart(ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, bool firstEvent, ref EnumHandHandling handling) { if (blockSel != null) { var block = api.World.BlockAccessor.GetBlock(blockSel.Position); if (block.Attributes?.IsTrue("pieFormingSurface") == true) { if (slot.StackSize >= 2) { BlockPie blockform = api.World.GetBlock(new AssetLocation("pie-raw")) as BlockPie; blockform.TryPlacePie(byEntity, blockSel); } else { ICoreClientAPI capi = api as ICoreClientAPI; if (capi != null) { capi.TriggerIngameError(this, "notpieable", Lang.Get("Need at least 2 dough")); } } handling = EnumHandHandling.PreventDefault; return; } } base.OnHeldInteractStart(slot, byEntity, blockSel, entitySel, firstEvent, ref handling); }
public MeshData GetPieMesh(ItemStack pieStack, ModelTransform transform = null) { // Slot 0: Base dough // Slot 1: Filling // Slot 2: Crust dough nowTesselatingBlock = pieStack.Block as BlockPie; if (nowTesselatingBlock == null) { return(null); //This will occur if the pieStack changed to rot } contentStacks = nowTesselatingBlock.GetContents(capi.World, pieStack); int pieSize = pieStack.Attributes.GetInt("pieSize"); // At this spot we have to determine the textures for "dough" and "filling" // Texture determination rules: // 1. dough is simple: first itemstack must be dough, take from attributes // 2. pie allows 4 items as fillings, but with specific mixing rules // - berries/fruit can be mixed // - vegetables can be mixed // - meat can be mixed // no other mixing allowed // Thus we deduce: It's enough to test if // a) all 4 fillings are equal: Then use texture from inPieProperties from first one // b) Otherwise use hardcoded // for item.NutritionProps.FoodCategory == Vegetable => block/food/pie/fill-mixedvegetable.png // for item.NutritionProps.FoodCategory == Protein => block/food/pie/fill-mixedmeat.png // for item.NutritionProps.FoodCategory == Fruit => block/food/pie/fill-mixedfruit.png var stackprops = contentStacks.Select(stack => stack?.ItemAttributes?["inPieProperties"]?.AsObject <InPieProperties>(null, stack.Collectible.Code.Domain)).ToArray(); int bakeLevel = pieStack.Attributes.GetInt("bakeLevel", 0); if (stackprops.Length == 0) { return(null); } ItemStack cstack = contentStacks[1]; bool equal = true; for (int i = 2; equal && i < contentStacks.Length - 1; i++) { if (contentStacks[i] == null || cstack == null) { continue; } equal &= cstack.Equals(capi.World, contentStacks[i], GlobalConstants.IgnoredStackAttributes); cstack = contentStacks[i]; } if (ContentsRotten(contentStacks)) { crustTextureLoc = new AssetLocation("block/rot/rot"); fillingTextureLoc = new AssetLocation("block/rot/rot"); topCrustTextureLoc = new AssetLocation("block/rot/rot"); } else { if (stackprops[0] != null) { crustTextureLoc = stackprops[0].Texture.Clone(); crustTextureLoc.Path = crustTextureLoc.Path.Replace("{bakelevel}", "" + (bakeLevel + 1)); fillingTextureLoc = new AssetLocation("block/transparent"); } topCrustTextureLoc = new AssetLocation("block/transparent"); if (stackprops[5] != null) { topCrustTextureLoc = stackprops[5].Texture.Clone(); topCrustTextureLoc.Path = topCrustTextureLoc.Path.Replace("{bakelevel}", "" + (bakeLevel + 1)); } if (contentStacks[1] != null) { EnumFoodCategory fillingFoodCat = contentStacks[1].Collectible.NutritionProps?.FoodCategory ?? contentStacks[1].ItemAttributes?["nutritionPropsWhenInMeal"]?.AsObject <FoodNutritionProperties>()?.FoodCategory ?? EnumFoodCategory.Vegetable ; fillingTextureLoc = equal ? stackprops[1]?.Texture : pieMixedFillingTextures[(int)fillingFoodCat]; } } int fillLevel = (contentStacks[1] != null ? 1 : 0) + (contentStacks[2] != null ? 1 : 0) + (contentStacks[3] != null ? 1 : 0) + (contentStacks[4] != null ? 1 : 0); bool isComplete = fillLevel == 4; AssetLocation shapeloc = isComplete ? pieShapeBySize[pieSize - 1] : pieShapeLocByFillLevel[fillLevel]; shapeloc.WithPathAppendixOnce(".json").WithPathPrefixOnce("shapes/"); Shape shape = capi.Assets.TryGet(shapeloc).ToObject <Shape>(); MeshData mesh; int topCrustType = pieStack.Attributes.GetInt("topCrustType"); string[] topCrusts = new string[] { "origin/base/top crust full/*", "origin/base/top crust square/*", "origin/base/top crust diagonal/*" }; string[] selectiveElements = new string[] { "origin/base/crust regular/*", "origin/base/filling/*", "origin/base/base-quarter/*", "origin/base/fillingquarter/*", topCrusts[topCrustType] }; capi.Tesselator.TesselateShape("pie", shape, out mesh, this, null, 0, 0, 0, null, selectiveElements); if (transform != null) { mesh.ModelTransform(transform); } return(mesh); }