예제 #1
0
        protected Shape addGearToShape(ItemSlot slot, Shape entityShape, string shapePathForLogging)
        {
            if (slot.Empty)
            {
                return(entityShape);
            }
            ItemStack  stack   = slot.Itemstack;
            JsonObject attrObj = stack.Collectible.Attributes;


            string[] disableElements = attrObj?["disableElements"]?.AsArray <string>(null);
            if (disableElements != null)
            {
                foreach (var val in disableElements)
                {
                    entityShape.RemoveElementByName(val);
                }
            }

            if (attrObj?["wearableAttachment"].Exists != true)
            {
                return(entityShape);
            }

            CompositeShape compArmorShape = !attrObj["attachShape"].Exists ? (stack.Class == EnumItemClass.Item ? stack.Item.Shape : stack.Block.Shape) : attrObj["attachShape"].AsObject <CompositeShape>(null, stack.Collectible.Code.Domain);

            AssetLocation shapePath = shapePath = compArmorShape.Base.CopyWithPath("shapes/" + compArmorShape.Base.Path + ".json");



            IAsset asset = Api.Assets.TryGet(shapePath);

            if (asset == null)
            {
                Api.World.Logger.Warning("Entity armor shape {0} defined in {1} {2} not found, was supposed to be at {3}. Armor piece will be invisible.", compArmorShape.Base, stack.Class, stack.Collectible.Code, shapePath);
                return(null);
            }

            Shape armorShape;

            try
            {
                armorShape = asset.ToObject <Shape>();
            }
            catch (Exception e)
            {
                Api.World.Logger.Warning("Exception thrown when trying to load entity armor shape {0} defined in {1} {2}. Armor piece will be invisible. Exception: {3}", compArmorShape.Base, slot.Itemstack.Class, slot.Itemstack.Collectible.Code, e);
                return(null);
            }

            bool added = false;

            foreach (var val in armorShape.Elements)
            {
                ShapeElement elem;

                if (val.StepParentName != null)
                {
                    elem = entityShape.GetElementByName(val.StepParentName, StringComparison.InvariantCultureIgnoreCase);
                    if (elem == null)
                    {
                        Api.World.Logger.Warning("Entity armor shape {0} defined in {1} {2} requires step parent element with name {3}, but no such element was found in shape {4}. Will not be visible.", compArmorShape.Base, slot.Itemstack.Class, slot.Itemstack.Collectible.Code, val.StepParentName, shapePathForLogging);
                        continue;
                    }
                }
                else
                {
                    Api.World.Logger.Warning("Entity armor shape element {0} in shape {1} defined in {2} {3} did not define a step parent element. Will not be visible.", val.Name, compArmorShape.Base, slot.Itemstack.Class, slot.Itemstack.Collectible.Code);
                    continue;
                }

                if (elem.Children == null)
                {
                    elem.Children = new ShapeElement[] { val };
                }
                else
                {
                    elem.Children = elem.Children.Append(val);
                }

                val.SetJointIdRecursive(elem.JointId);
                val.WalkRecursive((el) =>
                {
                    foreach (var face in el.Faces)
                    {
                        face.Value.Texture = "#" + stack.Collectible.Code + "-" + face.Value.Texture.TrimStart('#');
                    }
                });

                added = true;
            }

            if (added && armorShape.Textures != null)
            {
                Dictionary <string, AssetLocation> newdict = new Dictionary <string, AssetLocation>();
                foreach (var val in armorShape.Textures)
                {
                    newdict[stack.Collectible.Code + "-" + val.Key] = val.Value;
                }

                // Item overrides
                var collDict = stack.Class == EnumItemClass.Block ? stack.Block.Textures : stack.Item.Textures;
                foreach (var val in collDict)
                {
                    newdict[stack.Collectible.Code + "-" + val.Key] = val.Value.Base;
                }

                armorShape.Textures = newdict;

                foreach (var val in armorShape.Textures)
                {
                    CompositeTexture ctex = new CompositeTexture()
                    {
                        Base = val.Value
                    };

                    entityShape.TextureSizes[val.Key] = new int[] { armorShape.TextureWidth, armorShape.TextureHeight };

                    AssetLocation armorTexLoc = val.Value;

                    // Weird backreference to the shaperenderer. Should be refactored.
                    var texturesByLoc  = extraTextureByLocation;
                    var texturesByName = extraTexturesByTextureName;

                    BakedCompositeTexture bakedCtex;

                    ICoreClientAPI capi = Api as ICoreClientAPI;

                    if (!texturesByLoc.TryGetValue(armorTexLoc, out bakedCtex))
                    {
                        int textureSubId = 0;
                        TextureAtlasPosition texpos;

                        IAsset texAsset = Api.Assets.TryGet(val.Value.Clone().WithPathPrefixOnce("textures/").WithPathAppendixOnce(".png"));
                        if (texAsset != null)
                        {
                            BitmapRef bmp = texAsset.ToBitmap(capi);
                            capi.EntityTextureAtlas.InsertTexture(bmp, out textureSubId, out texpos);
                        }
                        else
                        {
                            capi.World.Logger.Warning("Entity armor shape {0} defined texture {1}, no such texture found.", shapePath, val.Value);
                        }

                        ctex.Baked = new BakedCompositeTexture()
                        {
                            BakedName = val.Value, TextureSubId = textureSubId
                        };

                        texturesByName[val.Key]    = ctex;
                        texturesByLoc[armorTexLoc] = ctex.Baked;
                    }
                    else
                    {
                        ctex.Baked = bakedCtex;
                        texturesByName[val.Key] = ctex;
                    }
                }

                foreach (var val in armorShape.TextureSizes)
                {
                    entityShape.TextureSizes[val.Key] = val.Value;
                }
            }

            return(entityShape);
        }
예제 #2
0
 /// <summary>
 /// Checks to see whether or not the itemstack matches the ingredient.
 /// </summary>
 /// <param name="inputStack"></param>
 /// <returns></returns>
 public bool Matches(ItemStack inputStack)
 {
     return(GetMatchingStack(inputStack) != null);
 }
예제 #3
0
        private void HandleHandAnimations()
        {
            ItemStack rightstack = RightHandItemSlot?.Itemstack;

            EnumHandInteract interact = servercontrols.HandUse;

            bool nowUseStack = (interact == EnumHandInteract.BlockInteract || interact == EnumHandInteract.HeldItemInteract) || (servercontrols.RightMouseDown && !servercontrols.LeftMouseDown);
            bool wasUseStack = lastRunningHeldUseAnimation != null && AnimManager.ActiveAnimationsByAnimCode.ContainsKey(lastRunningHeldUseAnimation);

            bool nowHitStack = interact == EnumHandInteract.HeldItemAttack || (servercontrols.LeftMouseDown);
            bool wasHitStack = lastRunningHeldHitAnimation != null && AnimManager.ActiveAnimationsByAnimCode.ContainsKey(lastRunningHeldHitAnimation);



            string nowHeldRightUseAnim  = rightstack?.Collectible.GetHeldTpUseAnimation(RightHandItemSlot, this);
            string nowHeldRightHitAnim  = rightstack?.Collectible.GetHeldTpHitAnimation(RightHandItemSlot, this);
            string nowHeldRightIdleAnim = rightstack?.Collectible.GetHeldTpIdleAnimation(RightHandItemSlot, this, EnumHand.Right);
            string nowHeldLeftIdleAnim  = LeftHandItemSlot?.Itemstack?.Collectible.GetHeldTpIdleAnimation(LeftHandItemSlot, this, EnumHand.Left);

            bool nowRightIdleStack = nowHeldRightIdleAnim != null && !nowUseStack && !nowHitStack;
            bool wasRightIdleStack = lastRunningRightHeldIdleAnimation != null && AnimManager.ActiveAnimationsByAnimCode.ContainsKey(lastRunningRightHeldIdleAnimation);

            bool nowLeftIdleStack = nowHeldLeftIdleAnim != null;
            bool wasLeftIdleStack = lastRunningLeftHeldIdleAnimation != null && AnimManager.ActiveAnimationsByAnimCode.ContainsKey(lastRunningLeftHeldIdleAnimation);

            if (rightstack == null)
            {
                nowHeldRightHitAnim = "breakhand";
            }

            if (nowUseStack != wasUseStack || (lastRunningHeldUseAnimation != null && nowHeldRightUseAnim != lastRunningHeldUseAnimation))
            {
                AnimManager.StopAnimation(lastRunningHeldUseAnimation);
                lastRunningHeldUseAnimation = null;

                if (nowUseStack)
                {
                    AnimManager.StopAnimation(lastRunningRightHeldIdleAnimation);
                    AnimManager.StartAnimation(lastRunningHeldUseAnimation = nowHeldRightUseAnim);
                }
            }

            if (nowHitStack != wasHitStack || (lastRunningHeldHitAnimation != null && nowHeldRightHitAnim != lastRunningHeldHitAnimation))
            {
                AnimManager.StopAnimation(lastRunningHeldHitAnimation);
                lastRunningHeldHitAnimation = null;


                if (nowHitStack)
                {
                    AnimManager.StopAnimation(lastRunningLeftHeldIdleAnimation);
                    AnimManager.StopAnimation(lastRunningRightHeldIdleAnimation);
                    AnimManager.StartAnimation(lastRunningHeldHitAnimation = nowHeldRightHitAnim);
                }
            }

            if (nowRightIdleStack != wasRightIdleStack || (lastRunningRightHeldIdleAnimation != null && nowHeldRightIdleAnim != lastRunningRightHeldIdleAnimation))
            {
                AnimManager.StopAnimation(lastRunningRightHeldIdleAnimation);
                lastRunningRightHeldIdleAnimation = null;

                if (nowRightIdleStack)
                {
                    AnimManager.StartAnimation(lastRunningRightHeldIdleAnimation = nowHeldRightIdleAnim);
                }
            }

            if (nowLeftIdleStack != wasLeftIdleStack || (lastRunningLeftHeldIdleAnimation != null && nowHeldLeftIdleAnim != lastRunningLeftHeldIdleAnimation))
            {
                AnimManager.StopAnimation(lastRunningLeftHeldIdleAnimation);

                lastRunningLeftHeldIdleAnimation = null;

                if (nowLeftIdleStack)
                {
                    AnimManager.StartAnimation(lastRunningLeftHeldIdleAnimation = nowHeldLeftIdleAnim);
                }
            }
        }
예제 #4
0
 public override float GetTransitionSpeedMul(EnumTransitionType transType, ItemStack stack)
 {
     return(0);
 }
예제 #5
0
        public bool Matches(ItemStack[] inputStacks, ref int quantityServings)
        {
            List <ItemStack> inputStacksList = new List <ItemStack>(inputStacks);
            List <CookingRecipeIngredient> ingredientList = new List <CookingRecipeIngredient>(Ingredients);

            int totalOutputQuantity = 99999;

            int[] curQuantities = new int[ingredientList.Count];
            for (int i = 0; i < curQuantities.Length; i++)
            {
                curQuantities[i] = 0;
            }

            while (inputStacksList.Count > 0)
            {
                ItemStack inputStack = inputStacksList[0];
                inputStacksList.RemoveAt(0);
                if (inputStack == null)
                {
                    continue;
                }

                bool found = false;
                for (int i = 0; i < ingredientList.Count; i++)
                {
                    CookingRecipeIngredient ingred = ingredientList[i];

                    if (ingred.Matches(inputStack))
                    {
                        if (curQuantities[i] >= ingred.MaxQuantity)
                        {
                            continue;
                        }

                        totalOutputQuantity = Math.Min(totalOutputQuantity, inputStack.StackSize);
                        curQuantities[i]++;
                        found = true;
                        break;
                    }
                }

                // This input stack does not fit in this cooking recipe
                if (!found)
                {
                    return(false);
                }
            }

            // Any required ingredients left?
            for (int i = 0; i < ingredientList.Count; i++)
            {
                if (curQuantities[i] < ingredientList[i].MinQuantity)
                {
                    return(false);
                }
            }

            quantityServings = totalOutputQuantity;

            // Too many ingredients?
            for (int i = 0; i < inputStacks.Length; i++)
            {
                if (inputStacks[i] == null)
                {
                    continue;
                }
                if (inputStacks[i].StackSize > quantityServings)
                {
                    return(false);
                }
            }

            return(true);
        }
예제 #6
0
 private string getInternalName(ItemStack itemstack)
 {
     return(itemstack.Collectible.Code.Path);
 }
예제 #7
0
        /// <summary>
        /// Gets the name for ingredients in regards to food.
        /// </summary>
        /// <param name="worldForResolve">The world to resolve in.</param>
        /// <param name="recipeCode">The recipe code.</param>
        /// <param name="stacks">The stacks of items to add.</param>
        /// <returns>The name of the food type.</returns>
        public string GetNameForIngredients(IWorldAccessor worldForResolve, string recipeCode, ItemStack[] stacks)
        {
            OrderedDictionary <ItemStack, int> quantitiesByStack = new OrderedDictionary <ItemStack, int>();

            quantitiesByStack = mergeStacks(worldForResolve, stacks);

            CookingRecipe recipe = worldForResolve.CookingRecipes.FirstOrDefault(rec => rec.Code == recipeCode);

            if (recipeCode == null || recipe == null)
            {
                return("unknown");
            }

            int           max                 = 1;
            string        MealFormat          = "meal";
            string        topping             = string.Empty;
            ItemStack     PrimaryIngredient   = null;
            ItemStack     SecondaryIngredient = null;
            List <string> OtherIngredients    = new List <string>();
            List <string> MashedNames         = new List <string>();
            List <string> GarnishedNames      = new List <string>();
            List <string> grainNames          = new List <string>();
            string        mainIngredients;
            string        everythingelse = "";


            switch (recipeCode)
            {
            case "soup":
            {
                max = 0;
                foreach (var val in quantitiesByStack)
                {
                    CookingRecipeIngredient ingred = recipe.GetIngrendientFor(val.Key);
                    if (val.Key.Collectible.Code.Path.Contains("waterportion"))
                    {
                        continue;
                    }
                    if (ingred?.Code == "topping")
                    {
                        topping = "honeyportion";
                        continue;
                    }


                    if (max < val.Value)
                    {
                        max = val.Value;
                        if (PrimaryIngredient != null)
                        {
                            SecondaryIngredient = PrimaryIngredient;
                        }
                        PrimaryIngredient = val.Key;
                    }
                    else
                    {
                        OtherIngredients.Add(ingredientName(val.Key, true));
                    }
                }

                if (max == 2)
                {
                    max = 3;
                }
                else if (max == 3)
                {
                    max = 4;
                }
                else
                {
                    max = 2;
                }

                break;
            }

            case "porridge":
            {
                max = 0;
                foreach (var val in quantitiesByStack)
                {
                    CookingRecipeIngredient ingred = recipe.GetIngrendientFor(val.Key);
                    if (getFoodCat(val.Key) == EnumFoodCategory.Grain)
                    {
                        max++;
                        if (PrimaryIngredient == null)
                        {
                            PrimaryIngredient = val.Key;
                        }
                        else if (SecondaryIngredient == null && val.Key != PrimaryIngredient)
                        {
                            SecondaryIngredient = val.Key;
                        }

                        continue;
                    }

                    if (ingred?.Code == "topping")
                    {
                        topping = "honeyportion";
                        continue;
                    }

                    MashedNames.Add(ingredientName(val.Key, true));
                }
                break;
            }

            case "meatystew":
            {
                max = 0;
                foreach (var val in quantitiesByStack)
                {
                    CookingRecipeIngredient ingred = recipe.GetIngrendientFor(val.Key);

                    EnumFoodCategory foodCat = getFoodCat(val.Key);

                    if (foodCat == EnumFoodCategory.Protein)
                    {
                        if (PrimaryIngredient == val.Key || SecondaryIngredient == val.Key)
                        {
                            continue;
                        }

                        if (PrimaryIngredient == null)
                        {
                            PrimaryIngredient = val.Key;
                        }
                        else if (SecondaryIngredient == null)
                        {
                            SecondaryIngredient = val.Key;
                        }
                        else
                        {
                            OtherIngredients.Add(ingredientName(val.Key, true));
                        }

                        max += val.Value;

                        continue;
                    }


                    if (ingred?.Code == "topping")
                    {
                        topping = "honeyportion";
                        continue;
                    }

                    OtherIngredients.Add(ingredientName(val.Key, true));
                }

                recipeCode = "stew";
                break;
            }

            case "vegetablestew":
            {
                max = 0;

                foreach (var val in quantitiesByStack)
                {
                    if (getFoodCat(val.Key) == EnumFoodCategory.Vegetable)
                    {
                        if (PrimaryIngredient == val.Key || SecondaryIngredient == val.Key)
                        {
                            continue;
                        }

                        if (PrimaryIngredient == null)
                        {
                            PrimaryIngredient = val.Key;
                        }
                        else if (SecondaryIngredient == null)
                        {
                            SecondaryIngredient = val.Key;
                        }
                        else
                        {
                            GarnishedNames.Add(ingredientName(val.Key, true));
                        }

                        max += val.Value;

                        continue;
                    }
                    GarnishedNames.Add(ingredientName(val.Key, true));
                }

                // Slightly ugly hack for soybean stew
                if (PrimaryIngredient == null)
                {
                    foreach (var val in quantitiesByStack)
                    {
                        //CookingRecipeIngredient ingred = recipe.GetIngrendientFor(val.Key); - whats this for?
                        PrimaryIngredient = val.Key;
                        max += val.Value;
                    }
                }

                recipeCode = "stew";
                break;
            }


            case "jam":
            {
                foreach (var val in quantitiesByStack)
                {
                    if (val.Key.Collectible.NutritionProps?.FoodCategory == EnumFoodCategory.Fruit)
                    {
                        return(Lang.Get("{0} jam", val.Key.GetName()));
                    }
                }

                break;
            }
            }



            switch (max)
            {
            case 3:
                MealFormat += "-hearty-" + recipeCode;
                break;

            case 4:
                MealFormat += "-hefty-" + recipeCode;
                break;

            default:
                MealFormat += "-normal-" + recipeCode;
                break;
            }

            if (topping == "honeyportion")
            {
                MealFormat += "-honey";
            }
            //mealformat is done.  Time to do the main inredients.



            if (SecondaryIngredient != null)
            {
                mainIngredients = Lang.Get("multi-main-ingredients-format", getMainIngredientName(PrimaryIngredient, recipeCode), getMainIngredientName(SecondaryIngredient, recipeCode, true));
            }
            else
            {
                mainIngredients = PrimaryIngredient == null ? "" : getMainIngredientName(PrimaryIngredient, recipeCode);
            }
            // Main ingredients are done.

            switch (recipeCode)
            {
            case "porridge":
                if (MashedNames.Count > 0)
                {
                    everythingelse = getMealAddsString("meal-adds-porridge-mashed", MashedNames);
                }
                else
                {
                    everythingelse = "";
                }
                break;

            case "stew":
                if (OtherIngredients.Count > 0)
                {
                    everythingelse = getMealAddsString("meal-adds-meatystew-boiled", OtherIngredients);
                }
                else if (GarnishedNames.Count > 0)
                {
                    everythingelse = getMealAddsString("meal-adds-vegetablestew-garnish", GarnishedNames);
                }
                else
                {
                    everythingelse = "";
                }
                break;

            case "soup":
                if (OtherIngredients.Count > 0)
                {
                    everythingelse = getMealAddsString("meal-adds-generic", OtherIngredients);
                }
                break;
            }
            //everything else is done.

            return(Lang.Get(MealFormat, mainIngredients, everythingelse).Trim().UcFirst());
        }