Exemplo n.º 1
0
        public override TemplateObject Handle(TagData data)
        {
            if (data.Remaining == 0)
            {
                return(this);
            }
            switch (data[0])
            {
            // TODO: Mode, etc.
            // <--[tag]
            // @Name RecipeTag.input
            // @Group General Information
            // @ReturnType ListTag
            // @Returns the result of this recipe.
            // @Example "blocks/grass|blocks/dirt" .result returns "blocks/dirt|".
            // -->
            case "input":
            {
                ListTag list = new ListTag();
                for (int i = 0; i < Internal.Input.Length; i++)
                {
                    list.ListEntries.Add(new ItemTag(Internal.Input[i]));
                }
                return(list.Handle(data.Shrink()));
            }

            default:
                return(new TextTag(ToString()).Handle(data));
            }
        }
Exemplo n.º 2
0
        public override TemplateObject Handle(TagData data)
        {
            if (data.Remaining == 0)
            {
                return(this);
            }
            switch (data[0])
            {
            // <--[tag]
            // @Name RecipeResultTag.recipe
            // @Group General Information
            // @ReturnType RecipeTag
            // @Returns the original recipe used to form this recipe result.
            // -->
            case "recipe":
                return(new RecipeTag(Internal.Recipe).Handle(data.Shrink()));

            // <--[tag]
            // @Name RecipeResultTag.used_input
            // @Group General Information
            // @ReturnType ListTag
            // @Returns the input items used by this recipe result.
            // @Example "1|blocks/grass|blocks/dirt" .result returns "blocks/grass|blocks/dirt|".
            // -->
            case "used_input":
            {
                ListTag list = new ListTag();
                for (int i = 0; i < Internal.UsedInput.Count; i++)
                {
                    list.ListEntries.Add(new ItemTag(Internal.UsedInput[i]));
                }
                return(list.Handle(data.Shrink()));
            }

            default:
                return(new TextTag(ToString()).Handle(data));
            }
        }
Exemplo n.º 3
0
        public override TemplateObject Handle(TagData data)
        {
            data.Shrink();
            if (data.Remaining == 0)
            {
                return(new TextTag(ToString()));
            }
            switch (data[0])
            {
            // <--[tagbase]
            // @Name ServerTag.online_players
            // @Group Entities
            // @ReturnType ListTag
            // @Returns a list of all online players.
            // @Example .online_players could return "Fortifier|mcmonkey".
            // -->
            case "online_players":
            {
                ListTag players = new ListTag();
                foreach (PlayerEntity p in TheServer.Players)
                {
                    players.ListEntries.Add(new PlayerTag(p));
                }
                return(players.Handle(data.Shrink()));
            }

            // <--[tagbase]
            // @Name ServerTag.loaded_worlds
            // @Group World
            // @ReturnType ListTag
            // @Returns a list of all loaded worlds.
            // @Example .loaded_worlds could return "default|bob".
            // -->
            case "loaded_worlds":
            {
                ListTag worlds = new ListTag();
                foreach (World w in TheServer.LoadedWorlds)
                {
                    worlds.ListEntries.Add(new WorldTag(w));
                }
                return(worlds.Handle(data.Shrink()));
            }

            // <--[tagbase]
            // @Name ServerTag.loaded_recipes
            // @Group Items
            // @ReturnType ListTag
            // @Returns a list of all loaded recipes.
            // -->
            case "loaded_recipes":
            {
                ListTag recipes = new ListTag();
                foreach (ItemRecipe r in TheServer.Recipes.Recipes)
                {
                    recipes.ListEntries.Add(new RecipeTag(r));
                }
                return(recipes.Handle(data.Shrink()));
            }

            // <--[tagbase]
            // @Name ServerTag.can_craft_from[<ListTag>]
            // @Group Items
            // @ReturnType ListTag
            // @Returns a list of all loaded recipes that can be crafted from the given input.
            // @Example .can_craft_from[blocks/grass_forest] could return "1&pipeblocks/grass_forest|".
            // -->
            case "can_craft_from":
            {
                // TODO: Handle errors neatly!
                List <ItemStack> items = new List <ItemStack>();
                ListTag          list  = ListTag.For(data.GetModifierObject(0));
                foreach (TemplateObject obj in list.ListEntries)
                {
                    items.Add(ItemTag.For(TheServer, obj).Internal);
                }
                ListTag recipes = new ListTag();
                foreach (RecipeResult r in TheServer.Recipes.CanCraftFrom(items.ToArray()))
                {
                    recipes.ListEntries.Add(new RecipeResultTag(r));
                }
                return(recipes.Handle(data.Shrink()));
            }

            // <--[tagbase]
            // @Name ServerTag.match_player[<TextTag>]
            // @Group Entities
            // @ReturnType PlayerTag
            // @Returns the player whose name best matches the input.
            // @Example .match_player[Fort] out of a group of "Fortifier", "Fort", and "Forty" would return "Fort".
            // @Example .match_player[monk] out of a group of "mcmonkey", "morph", and "Fort" would return "mcmonkey".
            // -->
            case "match_player":
            {
                string       pname  = data.GetModifier(0);
                PlayerEntity player = TheServer.GetPlayerFor(pname);
                if (player == null)
                {
                    data.Error("Invalid player '" + TagParser.Escape(pname) + "'!");
                    return(new NullTag());
                }
                return(new PlayerTag(player).Handle(data.Shrink()));
            }

            default:
                return(new TextTag(ToString()).Handle(data));
            }
        }
Exemplo n.º 4
0
 public override TemplateObject Handle(TagData data)
 {
     if (data.Remaining == 0)
     {
         return this;
     }
     switch (data[0])
     {
         // TODO: Mode, etc.
         // <--[tag]
         // @Name RecipeTag.input
         // @Group General Information
         // @ReturnType ListTag
         // @Returns the result of this recipe.
         // @Example "blocks/grass|blocks/dirt" .result returns "blocks/dirt|".
         // -->
         case "input":
             {
                 ListTag list = new ListTag();
                 for (int i = 0; i < Internal.Input.Length; i++)
                 {
                     list.ListEntries.Add(new ItemTag(Internal.Input[i]));
                 }
                 return list.Handle(data.Shrink());
             }
         default:
             return new TextTag(ToString()).Handle(data);
     }
 }
Exemplo n.º 5
0
 public override TemplateObject Handle(TagData data)
 {
     data.Shrink();
     if (data.Remaining == 0)
     {
         return new TextTag(ToString());
     }
     switch (data[0])
     {
         // <--[tagbase]
         // @Name ServerTag.online_players
         // @Group Entities
         // @ReturnType ListTag
         // @Returns a list of all online players.
         // @Example .online_players could return "Fortifier|mcmonkey".
         // -->
         case "online_players":
             {
                 ListTag players = new ListTag();
                 foreach (PlayerEntity p in TheServer.Players)
                 {
                     players.ListEntries.Add(new PlayerTag(p));
                 }
                 return players.Handle(data.Shrink());
             }
         // <--[tagbase]
         // @Name ServerTag.loaded_worlds
         // @Group World
         // @ReturnType ListTag
         // @Returns a list of all loaded worlds.
         // @Example .loaded_worlds could return "default|bob".
         // -->
         case "loaded_worlds":
             {
                 ListTag worlds = new ListTag();
                 foreach (World w in TheServer.LoadedWorlds)
                 {
                     worlds.ListEntries.Add(new WorldTag(w));
                 }
                 return worlds.Handle(data.Shrink());
             }
         // <--[tagbase]
         // @Name ServerTag.loaded_recipes
         // @Group Items
         // @ReturnType ListTag
         // @Returns a list of all loaded recipes.
         // -->
         case "loaded_recipes":
             {
                 ListTag recipes = new ListTag();
                 foreach (ItemRecipe r in TheServer.Recipes.Recipes)
                 {
                     recipes.ListEntries.Add(new RecipeTag(r));
                 }
                 return recipes.Handle(data.Shrink());
             }
         // <--[tagbase]
         // @Name ServerTag.can_craft_from[<ListTag>]
         // @Group Items
         // @ReturnType ListTag
         // @Returns a list of all loaded recipes that can be crafted from the given input.
         // @Example .can_craft_from[blocks/grass_forest] could return "1&pipeblocks/grass_forest|".
         // -->
         case "can_craft_from":
             {
                 // TODO: Handle errors neatly!
                 List<ItemStack> items = new List<ItemStack>();
                 ListTag list = ListTag.For(data.GetModifierObject(0));
                 foreach (TemplateObject obj in list.ListEntries)
                 {
                     items.Add(ItemTag.For(TheServer, obj).Internal);
                 }
                 ListTag recipes = new ListTag();
                 foreach (RecipeResult r in TheServer.Recipes.CanCraftFrom(items.ToArray()))
                 {
                     recipes.ListEntries.Add(new RecipeResultTag(r));
                 }
                 return recipes.Handle(data.Shrink());
             }
         // <--[tagbase]
         // @Name ServerTag.match_player[<TextTag>]
         // @Group Entities
         // @ReturnType PlayerTag
         // @Returns the player whose name best matches the input.
         // @Example .match_player[Fort] out of a group of "Fortifier", "Fort", and "Forty" would return "Fort".
         // @Example .match_player[monk] out of a group of "mcmonkey", "morph", and "Fort" would return "mcmonkey".
         // -->
         case "match_player":
             {
                 string pname = data.GetModifier(0);
                 PlayerEntity player = TheServer.GetPlayerFor(pname);
                 if (player == null)
                 {
                     data.Error("Invalid player '" + TagParser.Escape(pname) + "'!");
                     return new NullTag();
                 }
                 return new PlayerTag(player).Handle(data.Shrink());
             }
         default:
             return new TextTag(ToString()).Handle(data);
     }
 }
Exemplo n.º 6
0
 public override TemplateObject Handle(TagData data)
 {
     if (data.Remaining == 0)
     {
         return this;
     }
     switch (data[0])
     {
         // <--[tag]
         // @Name RecipeResultTag.recipe
         // @Group General Information
         // @ReturnType RecipeTag
         // @Returns the original recipe used to form this recipe result.
         // -->
         case "recipe":
             return new RecipeTag(Internal.Recipe).Handle(data.Shrink());
         // <--[tag]
         // @Name RecipeResultTag.used_input
         // @Group General Information
         // @ReturnType ListTag
         // @Returns the input items used by this recipe result.
         // @Example "1|blocks/grass|blocks/dirt" .result returns "blocks/grass|blocks/dirt|".
         // -->
         case "used_input":
             {
                 ListTag list = new ListTag();
                 for (int i = 0; i < Internal.UsedInput.Count; i++)
                 {
                     list.ListEntries.Add(new ItemTag(Internal.UsedInput[i]));
                 }
                 return list.Handle(data.Shrink());
             }
         default:
             return new TextTag(ToString()).Handle(data);
     }
 }