Example #1
0
        public void OpenDialog(IClientWorldAccessor world, BlockPos pos, ItemStack ingredient)
        {
            if (ingredient.Collectible is ItemWorkItem)
            {
                ingredient = new ItemStack(world.GetItem(new AssetLocation("clay-" + ingredient.Collectible.LastCodePart())));
            }

            List <ItemStack> stacks = world.ClayFormingRecipes
                                      .Where(r => r.Ingredient.SatisfiesAsIngredient(ingredient))
                                      .OrderBy(r => r.Output.ResolvedItemstack.GetName())
                                      .Select(r => r.Output.ResolvedItemstack)
                                      .ToList()
            ;

            GuiDialog dlg = new GuiDialogBlockEntityRecipeSelector("Select recipe", stacks.ToArray(), pos, api as ICoreClientAPI);

            dlg.TryOpen();
        }
Example #2
0
        public void OpenDialog(IClientWorldAccessor world, BlockPos pos, ItemStack ingredient)
        {
            if (ingredient.Collectible is ItemWorkItem)
            {
                ingredient = new ItemStack(world.GetItem(new AssetLocation("clay-" + ingredient.Collectible.LastCodePart())));
            }

            List <ClayFormingRecipe> recipes = world.ClayFormingRecipes
                                               .Where(r => r.Ingredient.SatisfiesAsIngredient(ingredient))
                                               .OrderBy(r => r.Output.ResolvedItemstack.Collectible.Code) // Cannot sort by name, thats language dependent!
                                               .ToList();

            ;


            List <ItemStack> stacks = recipes
                                      .Select(r => r.Output.ResolvedItemstack)
                                      .ToList()
            ;

            ICoreClientAPI capi = Api as ICoreClientAPI;

            dlg = new GuiDialogBlockEntityRecipeSelector(
                Lang.Get("Select recipe"),
                stacks.ToArray(),
                (selectedIndex) => {
                capi.Logger.VerboseDebug("Select clay from recipe {0}, have {1} recipes.", selectedIndex, recipes.Count);

                selectedRecipeId = recipes[selectedIndex].RecipeId;
                capi.Network.SendBlockEntityPacket(pos.X, pos.Y, pos.Z, (int)EnumClayFormingPacket.SelectRecipe, SerializerUtil.Serialize(recipes[selectedIndex].RecipeId));
            },
                () => {
                capi.Network.SendBlockEntityPacket(pos.X, pos.Y, pos.Z, (int)EnumClayFormingPacket.CancelSelect);
            },
                pos,
                Api as ICoreClientAPI
                );

            dlg.OnClosed += dlg.Dispose;
            dlg.TryOpen();
        }