diff --git a/MineTweaker3-API/src/main/java/minetweaker/MineTweakerImplementationAPI.java b/MineTweaker3-API/src/main/java/minetweaker/MineTweakerImplementationAPI.java index c86c6fc..8795688 100644 --- a/MineTweaker3-API/src/main/java/minetweaker/MineTweakerImplementationAPI.java +++ b/MineTweaker3-API/src/main/java/minetweaker/MineTweakerImplementationAPI.java @@ -40,568 +40,586 @@ import static minetweaker.MineTweakerAPI.server; /** * The implementation API is used by API implementations for internal * communication and initialization. - * + * * @author Stan Hebben */ public class MineTweakerImplementationAPI { - private static Set blockInfoPlayers = new HashSet(); - private static IEventHandle blockEventHandler = null; + private static Set blockInfoPlayers = new HashSet(); + private static IEventHandle blockEventHandler = null; - private static final Map minetweakerCommands; + private static final Map minetweakerCommands; - private static final Comparator ITEM_COMPARATOR = new ItemComparator(); - private static final Comparator LIQUID_COMPARATOR = new LiquidComparator(); - private static final Comparator BLOCK_COMPARATOR = new BlockComparator(); - private static final Comparator ENTITY_COMPARATOR = new EntityComparator(); + private static final Comparator ITEM_COMPARATOR = new ItemComparator(); + private static final Comparator LIQUID_COMPARATOR = new LiquidComparator(); + private static final Comparator BLOCK_COMPARATOR = new BlockComparator(); + private static final Comparator ENTITY_COMPARATOR = new EntityComparator(); - private static final ListenPlayerLoggedIn LISTEN_LOGIN = new ListenPlayerLoggedIn(); - private static final ListenPlayerLoggedOut LISTEN_LOGOUT = new ListenPlayerLoggedOut(); - private static final ListenBlockInfo LISTEN_BLOCK_INFO = new ListenBlockInfo(); - private static final EventList ONRELOAD = new EventList(); - private static final EventList ONPOSTRELOAD = new EventList(); + private static final ListenPlayerLoggedIn LISTEN_LOGIN = new ListenPlayerLoggedIn(); + private static final ListenPlayerLoggedOut LISTEN_LOGOUT = new ListenPlayerLoggedOut(); + private static final ListenBlockInfo LISTEN_BLOCK_INFO = new ListenBlockInfo(); + private static final EventList ONRELOAD = new EventList(); + private static final EventList ONPOSTRELOAD = new EventList(); - static { - minetweakerCommands = new HashMap(); + static { + minetweakerCommands = new HashMap(); - minetweakerCommands.put("reload", new MineTweakerCommand( - "reload", - new String[] { - "/minetweaker reload", - " Reloads all scripts" - }, new ICommandFunction() { - @Override - public void execute(String[] arguments, IPlayer player) { - reload(); - player.sendChat("Scripts reloaded"); - } - })); + minetweakerCommands.put("reload", new MineTweakerCommand( + "reload", + new String[]{ + "/minetweaker reload", + " Reloads all scripts" + }, new ICommandFunction() { + @Override + public void execute(String[] arguments, IPlayer player) { + reload(); + player.sendChat("Scripts reloaded"); + } + })); - minetweakerCommands.put("names", new MineTweakerCommand( - "names", - new String[] { - "/minetweaker names", - " Outputs a list of all item names in the game to the minetweaker log" - }, new ICommandFunction() { - @Override - public void execute(String[] arguments, IPlayer player) { - List items = MineTweakerAPI.game.getItems(); - Collections.sort(items, ITEM_COMPARATOR); - for (IItemDefinition item : items) { - String displayName; + minetweakerCommands.put("names", new MineTweakerCommand( + "names", + new String[]{ + "/minetweaker names", + " Outputs a list of all item names in the game to the minetweaker log" + }, new ICommandFunction() { + @Override + public void execute(String[] arguments, IPlayer player) { + List items = MineTweakerAPI.game.getItems(); + Collections.sort(items, ITEM_COMPARATOR); + for (IItemDefinition item : items) { + String displayName; - try { - displayName = ", " + item.makeStack(0).getDisplayName(); - } catch (Throwable ex) { - // some mods (such as buildcraft) may throw - // exceptions when calling - // getDisplayName on an item stack that doesn't - // contain valid NBT data - // also seems to cause errors in some other - // cases too - displayName = " -- Name could not be retrieved due to an error: " + ex; - } + try { + displayName = ", " + item.makeStack(0).getDisplayName(); + } catch (Throwable ex) { + // some mods (such as buildcraft) may throw + // exceptions when calling + // getDisplayName on an item stack that doesn't + // contain valid NBT data + // also seems to cause errors in some other + // cases too + displayName = " -- Name could not be retrieved due to an error: " + ex; + } - MineTweakerAPI.logCommand("<" + item.getId() + ">" + displayName); - } + MineTweakerAPI.logCommand("<" + item.getId() + ">" + displayName); + } - if (player != null) { - player.sendChat("List generated; see minetweaker.log in your minecraft dir"); - } - } - })); + if (player != null) { + player.sendChat("List generated; see minetweaker.log in your minecraft dir"); + } + } + })); - minetweakerCommands.put("liquids", new MineTweakerCommand( - "liquids", - new String[] { - "/minetweaker liquids", - " Outputs a list of all liquid names in the game to the minetweaker log" - }, new ICommandFunction() { - @Override - public void execute(String[] arguments, IPlayer player) { - List liquids = MineTweakerAPI.game.getLiquids(); - Collections.sort(liquids, LIQUID_COMPARATOR); + minetweakerCommands.put("liquids", new MineTweakerCommand( + "liquids", + new String[]{ + "/minetweaker liquids", + " Outputs a list of all liquid names in the game to the minetweaker log" + }, new ICommandFunction() { + @Override + public void execute(String[] arguments, IPlayer player) { + List liquids = MineTweakerAPI.game.getLiquids(); + Collections.sort(liquids, LIQUID_COMPARATOR); - MineTweakerAPI.logCommand("Liquids:"); - for (ILiquidDefinition liquid : liquids) { - MineTweakerAPI.logCommand(", " + liquid.getDisplayName()); - } + MineTweakerAPI.logCommand("Liquids:"); + for (ILiquidDefinition liquid : liquids) { + MineTweakerAPI.logCommand(", " + liquid.getDisplayName()); + } - if (player != null) { - player.sendChat("List generated; see minetweaker.log in your minecraft dir"); - } - } - })); + if (player != null) { + player.sendChat("List generated; see minetweaker.log in your minecraft dir"); + } + } + })); - minetweakerCommands.put("blocks", new MineTweakerCommand( - "blocks", - new String[] { - "/minetweaker blocks", - " Outputs a list of all blocks in the game to the minetweaker log" - }, new ICommandFunction() { - @Override - public void execute(String[] arguments, IPlayer player) { - List blocks = MineTweakerAPI.game.getBlocks(); - Collections.sort(blocks, BLOCK_COMPARATOR); + minetweakerCommands.put("blocks", new MineTweakerCommand( + "blocks", + new String[]{ + "/minetweaker blocks", + " Outputs a list of all blocks in the game to the minetweaker log" + }, new ICommandFunction() { + @Override + public void execute(String[] arguments, IPlayer player) { + List blocks = MineTweakerAPI.game.getBlocks(); + Collections.sort(blocks, BLOCK_COMPARATOR); - MineTweakerAPI.logCommand("Blocks:"); - for (IBlockDefinition block : blocks) { - MineTweakerAPI.logCommand(", " + block.getDisplayName()); - } + MineTweakerAPI.logCommand("Blocks:"); + for (IBlockDefinition block : blocks) { + MineTweakerAPI.logCommand(", " + block.getDisplayName()); + } - if (player != null) { - player.sendChat("List generated; see minetweaker.log in your minecraft dir"); - } - } - })); + if (player != null) { + player.sendChat("List generated; see minetweaker.log in your minecraft dir"); + } + } + })); - minetweakerCommands.put("entities", new MineTweakerCommand( - "entities", - new String[] { - "/minetweaker entities", - " Outputs a list of all entity definitions in the game to the minetweaker log" - }, new ICommandFunction() { - @Override - public void execute(String[] arguments, IPlayer player) { - List entities = MineTweakerAPI.game.getEntities(); - Collections.sort(entities, ENTITY_COMPARATOR); + minetweakerCommands.put("entities", new MineTweakerCommand( + "entities", + new String[]{ + "/minetweaker entities", + " Outputs a list of all entity definitions in the game to the minetweaker log" + }, new ICommandFunction() { + @Override + public void execute(String[] arguments, IPlayer player) { + List entities = MineTweakerAPI.game.getEntities(); + Collections.sort(entities, ENTITY_COMPARATOR); - MineTweakerAPI.logCommand("Entities:"); - for (IEntityDefinition entity : entities) { - MineTweakerAPI.logCommand(entity.getId() + " -- " + entity.getName()); - } + MineTweakerAPI.logCommand("Entities:"); + for (IEntityDefinition entity : entities) { + MineTweakerAPI.logCommand(entity.getId() + " -- " + entity.getName()); + } - if (player != null) { - player.sendChat("List generated; see minetweaker.log in your minecraft dir"); - } - } - })); + if (player != null) { + player.sendChat("List generated; see minetweaker.log in your minecraft dir"); + } + } + })); - minetweakerCommands.put("recipes", new MineTweakerCommand( - "recipes", - new String[] { - "/minetweaker recipes", - " Lists all crafting recipes in the game", - "/minetweaker recipes hand", - " Lists all crafting recipes for the item in your hand", - " Also copies the recipes to clipboard" - }, new ICommandFunction() { - @Override - public void execute(String[] arguments, IPlayer player) - { - if (arguments.length == 0) { - if (player != null) { - player.sendChat("Generating recipe list, this could take a while..."); - } + minetweakerCommands.put("recipes", new MineTweakerCommand( + "recipes", + new String[]{ + "/minetweaker recipes", + " Lists all crafting recipes in the game", + "/minetweaker recipes hand", + " Lists all crafting recipes for the item in your hand", + " Also copies the recipes to clipboard", + "/minetweaker recipes furnace", + " lists all furnace recipes in the game" + }, new ICommandFunction() { + @Override + public void execute(String[] arguments, IPlayer player) { + if (arguments.length == 0) { + if (player != null) { + player.sendChat("Generating recipe list, this could take a while..."); + } - MineTweakerAPI.logCommand("Recipes:"); - for (ICraftingRecipe recipe : MineTweakerAPI.recipes.getAll()) { - try { - MineTweakerAPI.logCommand(recipe.toCommandString()); - } catch (Throwable ex) { - // Some recipes can result in an NPE :-( - if (recipe instanceof ShapedRecipe) { - ShapedRecipe shaped = (ShapedRecipe) recipe; - IItemStack out = shaped.getOutput(); - MineTweakerAPI.logError("Could not dump recipe for " + out, ex); - } else if (recipe instanceof ShapelessRecipe) { - ShapelessRecipe shapeless = (ShapelessRecipe) recipe; - IItemStack out = shapeless.getOutput(); - MineTweakerAPI.logError("Could not dump recipe for " + out, ex); - } else { - MineTweakerAPI.logError("Could not dump recipe", ex); - } - } - } + MineTweakerAPI.logCommand("Recipes:"); + for (ICraftingRecipe recipe : MineTweakerAPI.recipes.getAll()) { + try { + MineTweakerAPI.logCommand(recipe.toCommandString()); + } catch (Throwable ex) { + // Some recipes can result in an NPE :-( + if (recipe instanceof ShapedRecipe) { + ShapedRecipe shaped = (ShapedRecipe) recipe; + IItemStack out = shaped.getOutput(); + MineTweakerAPI.logError("Could not dump recipe for " + out, ex); + } else if (recipe instanceof ShapelessRecipe) { + ShapelessRecipe shapeless = (ShapelessRecipe) recipe; + IItemStack out = shapeless.getOutput(); + MineTweakerAPI.logError("Could not dump recipe for " + out, ex); + } else { + MineTweakerAPI.logError("Could not dump recipe", ex); + } + } + } - if (player != null) { - player.sendChat("Recipe list generated; see minetweaker.log in your minecraft dir"); - } - } else if (arguments[0].equals("hand") && player != null) { - IItemStack item = player.getCurrentItem(); - if (item != null) { - List recipes = MineTweakerAPI.recipes.getRecipesFor(item.anyAmount()); - if (recipes.isEmpty()) { - player.sendChat("No crafting recipes found for that item"); - } else { - StringBuilder recipesString = new StringBuilder(); + if (player != null) { + player.sendChat("Recipe list generated; see minetweaker.log in your minecraft dir"); + } + } else if (arguments[0].equals("hand") && player != null) { + IItemStack item = player.getCurrentItem(); + if (item != null) { + List recipes = MineTweakerAPI.recipes.getRecipesFor(item.anyAmount()); + if (recipes.isEmpty()) { + player.sendChat("No crafting recipes found for that item"); + } else { + StringBuilder recipesString = new StringBuilder(); - for (ICraftingRecipe recipe : recipes) { - MineTweakerAPI.logCommand(recipe.toCommandString()); - player.sendChat(recipe.toCommandString()); - recipesString.append(recipe.toCommandString()).append("\n"); - } + for (ICraftingRecipe recipe : recipes) { + MineTweakerAPI.logCommand(recipe.toCommandString()); + player.sendChat(recipe.toCommandString()); + recipesString.append(recipe.toCommandString()).append("\n"); + } - copyToClipboard(recipesString.toString()); - } - } else { - player.sendChat("No item was found"); - } - } else { - if (player != null) { - player.sendChat("Invalid arguments for recipes command"); - } - } - } - })); + copyToClipboard(recipesString.toString()); + } + } else { + player.sendChat("No item was found"); + } + } else if (arguments[0].equals("furnace") && player != null) { + if (player != null) { + player.sendChat("Generating furnace list, this could take a while..."); + } - minetweakerCommands.put("inventory", new MineTweakerCommand( - "inventory", - new String[] { - "/minetweaker inventory", - " Lists all items in your inventory" - }, new ICommandFunction() { - @Override - public void execute(String[] arguments, IPlayer player) { - for (int i = 0; i < player.getInventorySize(); i++) { - IItemStack stack = player.getInventoryStack(i); - if (stack != null) { - player.sendChat(stack.toString()); - } - } - } - })); + MineTweakerAPI.logCommand("Furnace Recipes:"); + for (IFurnaceRecipe recipe : MineTweakerAPI.furnace.getAll()) { + try { + MineTweakerAPI.logCommand(recipe.toCommandString()); + } catch (Throwable ex) { + MineTweakerAPI.logError("Could not dump furnace recipe", ex); + } + } - minetweakerCommands.put("hand", new MineTweakerCommand( - "hand", - new String[] { - "/minetweaker hand", - " Outputs the name of the item in your hand", - " Also copies the name to clipboard and prints", - " oredict entries" - }, new ICommandFunction() { - @Override - public void execute(String[] arguments, IPlayer player) { - IItemStack hand = player.getCurrentItem(); - if (hand != null) { - String value = hand.toString(); - player.sendChat(value); - copyToClipboard(value); + if (player != null) { + player.sendChat("Furnace Recipe list generated; see minetweaker.log in your minecraft dir"); + } + } else { + if (player != null) { + player.sendChat("Invalid arguments for recipes command"); + } + } + } + })); - List entries = hand.getOres(); - for (IOreDictEntry entry : entries) { - player.sendChat("Is in "); - } - } - } - })); + minetweakerCommands.put("inventory", new MineTweakerCommand( + "inventory", + new String[]{ + "/minetweaker inventory", + " Lists all items in your inventory" + }, new ICommandFunction() { + @Override + public void execute(String[] arguments, IPlayer player) { + for (int i = 0; i < player.getInventorySize(); i++) { + IItemStack stack = player.getInventoryStack(i); + if (stack != null) { + player.sendChat(stack.toString()); + } + } + } + })); - minetweakerCommands.put("oredict", new MineTweakerCommand( - "oredict", - new String[] { - "/minetweaker oredict", - " Outputs all ore dictionary entries in the game to the minetweaker log", - "/minetweaker oredict ", - " Outputs all items in the given ore dictionary entry to the minetweaker log" - }, new ICommandFunction() { - @Override - public void execute(String[] arguments, IPlayer player) { - if (arguments.length > 0) { - String entryName = arguments[0]; - IOreDictEntry entry = MineTweakerAPI.oreDict.get(entryName); - if (entry.isEmpty()) { - player.sendChat("Entry doesn't exist"); - return; - } else { - MineTweakerAPI.logCommand("Ore entries for " + entryName + ":"); - for (IItemStack ore : entry.getItems()) { - MineTweakerAPI.logCommand(" " + ore); - } - } - } else { - for (IOreDictEntry entry : MineTweakerAPI.oreDict.getEntries()) { - if (!entry.isEmpty()) { - MineTweakerAPI.logCommand("Ore entries for :"); - for (IItemStack ore : entry.getItems()) { - MineTweakerAPI.logCommand(" " + ore); - } - } - } - } - player.sendChat("List generated; see minetweaker.log in your minecraft dir"); - } - })); + minetweakerCommands.put("hand", new MineTweakerCommand( + "hand", + new String[]{ + "/minetweaker hand", + " Outputs the name of the item in your hand", + " Also copies the name to clipboard and prints", + " oredict entries" + }, new ICommandFunction() { + @Override + public void execute(String[] arguments, IPlayer player) { + IItemStack hand = player.getCurrentItem(); + if (hand != null) { + String value = hand.toString(); + player.sendChat(value); + copyToClipboard(value); - minetweakerCommands.put("mods", new MineTweakerCommand( - "mods", - new String[] { - "/minetweaker mods", - " Outputs all active mod IDs and versions in the game" - }, new ICommandFunction() { - @Override - public void execute(String[] arguments, IPlayer player) { - MineTweakerAPI.logCommand("Mods list:"); - for (IMod mod : MineTweakerAPI.loadedMods) { - String message = mod.getId() + " - " + mod.getName() + " - " + mod.getVersion(); - player.sendChat(message); - MineTweakerAPI.logCommand("Mod: " + message); - } - } - })); + List entries = hand.getOres(); + for (IOreDictEntry entry : entries) { + player.sendChat("Is in "); + } + } + } + })); - minetweakerCommands.put("name", new MineTweakerCommand( - "name", - new String[] { - "/minetweaker name ", - " Outputs the name for the given item ID", - }, - new ICommandFunction() { - @Override - public void execute(String[] arguments, IPlayer player) { - if (arguments.length < 1) { - player.sendChat("missing id parameter"); - } else { - try { - int id = Integer.parseInt(arguments[0]); - IItemDefinition definition = platform.getItemDefinition(id); - if (definition == null) { - player.sendChat("no such item"); - } else { - StringBuilder description = new StringBuilder(); - description.append('<'); - description.append(definition.getId()); - description.append('>'); - player.sendChat(description.toString()); - } - } catch (NumberFormatException e) { - MineTweakerAPI.logCommand("ID must be an integer"); - } - } - } - })); + minetweakerCommands.put("oredict", new MineTweakerCommand( + "oredict", + new String[]{ + "/minetweaker oredict", + " Outputs all ore dictionary entries in the game to the minetweaker log", + "/minetweaker oredict ", + " Outputs all items in the given ore dictionary entry to the minetweaker log" + }, new ICommandFunction() { + @Override + public void execute(String[] arguments, IPlayer player) { + if (arguments.length > 0) { + String entryName = arguments[0]; + IOreDictEntry entry = MineTweakerAPI.oreDict.get(entryName); + if (entry.isEmpty()) { + player.sendChat("Entry doesn't exist"); + return; + } else { + MineTweakerAPI.logCommand("Ore entries for " + entryName + ":"); + for (IItemStack ore : entry.getItems()) { + MineTweakerAPI.logCommand(" " + ore); + } + } + } else { + for (IOreDictEntry entry : MineTweakerAPI.oreDict.getEntries()) { + if (!entry.isEmpty()) { + MineTweakerAPI.logCommand("Ore entries for :"); + for (IItemStack ore : entry.getItems()) { + MineTweakerAPI.logCommand(" " + ore); + } + } + } + } + player.sendChat("List generated; see minetweaker.log in your minecraft dir"); + } + })); - minetweakerCommands.put("seeds", new MineTweakerCommand( - "seeds", - new String[] { - "/minetweaker seeds", - " Prints all seeds registered", - " for tall grass" - }, new ICommandFunction() { - @Override - public void execute(String[] arguments, IPlayer player) { - MineTweakerAPI.logCommand("Seeds:"); - for (WeightedItemStack seed : MineTweakerAPI.vanilla.getSeeds().getSeeds()) { - String message = seed.getStack() + " - " + (int) seed.getChance(); - player.sendChat(message); - MineTweakerAPI.logCommand("Seed: " + message); - } - } - })); + minetweakerCommands.put("mods", new MineTweakerCommand( + "mods", + new String[]{ + "/minetweaker mods", + " Outputs all active mod IDs and versions in the game" + }, new ICommandFunction() { + @Override + public void execute(String[] arguments, IPlayer player) { + MineTweakerAPI.logCommand("Mods list:"); + for (IMod mod : MineTweakerAPI.loadedMods) { + String message = mod.getId() + " - " + mod.getName() + " - " + mod.getVersion(); + player.sendChat(message); + MineTweakerAPI.logCommand("Mod: " + message); + } + } + })); - minetweakerCommands.put("loot", new MineTweakerCommand( - "seeds", - new String[] { - "/minetweaker seeds", - " Prints all seeds registered", - " for tall grass" - }, new ICommandFunction() { - @Override - public void execute(String[] arguments, IPlayer player) { - if (arguments.length == 0) { - MineTweakerAPI.logCommand("Loot chest contents:"); - List types = MineTweakerAPI.vanilla.getLoot().getLootTypes(); - Collections.sort(types); - for (String lootType : types) { - MineTweakerAPI.logCommand("Loot type: " + lootType); + minetweakerCommands.put("name", new MineTweakerCommand( + "name", + new String[]{ + "/minetweaker name ", + " Outputs the name for the given item ID", + }, + new ICommandFunction() { + @Override + public void execute(String[] arguments, IPlayer player) { + if (arguments.length < 1) { + player.sendChat("missing id parameter"); + } else { + try { + int id = Integer.parseInt(arguments[0]); + IItemDefinition definition = platform.getItemDefinition(id); + if (definition == null) { + player.sendChat("no such item"); + } else { + StringBuilder description = new StringBuilder(); + description.append('<'); + description.append(definition.getId()); + description.append('>'); + player.sendChat(description.toString()); + } + } catch (NumberFormatException e) { + MineTweakerAPI.logCommand("ID must be an integer"); + } + } + } + })); - List entries = MineTweakerAPI.vanilla.getLoot().getLoot(lootType); - for (LootEntry entry : entries) { - MineTweakerAPI.logCommand(" " + entry.toString()); - } - } + minetweakerCommands.put("seeds", new MineTweakerCommand( + "seeds", + new String[]{ + "/minetweaker seeds", + " Prints all seeds registered", + " for tall grass" + }, new ICommandFunction() { + @Override + public void execute(String[] arguments, IPlayer player) { + MineTweakerAPI.logCommand("Seeds:"); + for (WeightedItemStack seed : MineTweakerAPI.vanilla.getSeeds().getSeeds()) { + String message = seed.getStack() + " - " + (int) seed.getChance(); + player.sendChat(message); + MineTweakerAPI.logCommand("Seed: " + message); + } + } + })); - player.sendChat("List generated; see minetweaker.log in your minecraft dir"); - } else { - MineTweakerAPI.logCommand("Loot for type: " + arguments[0]); + minetweakerCommands.put("loot", new MineTweakerCommand( + "seeds", + new String[]{ + "/minetweaker seeds", + " Prints all seeds registered", + " for tall grass" + }, new ICommandFunction() { + @Override + public void execute(String[] arguments, IPlayer player) { + if (arguments.length == 0) { + MineTweakerAPI.logCommand("Loot chest contents:"); + List types = MineTweakerAPI.vanilla.getLoot().getLootTypes(); + Collections.sort(types); + for (String lootType : types) { + MineTweakerAPI.logCommand("Loot type: " + lootType); - List entries = MineTweakerAPI.vanilla.getLoot().getLoot(arguments[0]); - for (LootEntry entry : entries) { - MineTweakerAPI.logCommand(" " + entry.toString()); - } + List entries = MineTweakerAPI.vanilla.getLoot().getLoot(lootType); + for (LootEntry entry : entries) { + MineTweakerAPI.logCommand(" " + entry.toString()); + } + } - player.sendChat("List generated; see minetweaker.log in your minecraft dir"); - } - } - })); + player.sendChat("List generated; see minetweaker.log in your minecraft dir"); + } else { + MineTweakerAPI.logCommand("Loot for type: " + arguments[0]); - minetweakerCommands.put("wiki", new MineTweakerCommand( - "wiki", - new String[] { - "/minetweaker wiki", - " Opens your browser with the wiki" - }, new ICommandFunction() { - @Override - public void execute(String[] arguments, IPlayer player) { - player.openBrowser("http://minetweaker3.powerofbytes.com/wiki/"); - } - })); + List entries = MineTweakerAPI.vanilla.getLoot().getLoot(arguments[0]); + for (LootEntry entry : entries) { + MineTweakerAPI.logCommand(" " + entry.toString()); + } - minetweakerCommands.put("bugs", new MineTweakerCommand( - "bugs", - new String[] { - "/minetweaker bugs", - " Opens your browser with the GitHub bug tracker" - }, new ICommandFunction() { - @Override - public void execute(String[] arguments, IPlayer player) { - player.openBrowser("https://github.com/stanhebben/MineTweaker3/issues"); - } - })); + player.sendChat("List generated; see minetweaker.log in your minecraft dir"); + } + } + })); - minetweakerCommands.put("forum", new MineTweakerCommand( - "forum", - new String[] { - "/minetweaker forum", - " Opens your browser with the forum" - }, new ICommandFunction() { - @Override - public void execute(String[] arguments, IPlayer player) { - player.openBrowser("http://minetweaker3.powerofbytes.com/forum"); - } - })); + minetweakerCommands.put("wiki", new MineTweakerCommand( + "wiki", + new String[]{ + "/minetweaker wiki", + " Opens your browser with the wiki" + }, new ICommandFunction() { + @Override + public void execute(String[] arguments, IPlayer player) { + player.openBrowser("http://minetweaker3.powerofbytes.com/wiki/"); + } + })); - minetweakerCommands.put("biomes", new MineTweakerCommand( - "biomes", - new String[] { - "/minetweaker biomes", - " Lists all the biomes in the game" - }, new ICommandFunction() { - @Override - public void execute(String[] arguments, IPlayer player) { - MineTweakerAPI.logCommand("Biomes:"); + minetweakerCommands.put("bugs", new MineTweakerCommand( + "bugs", + new String[]{ + "/minetweaker bugs", + " Opens your browser with the GitHub bug tracker" + }, new ICommandFunction() { + @Override + public void execute(String[] arguments, IPlayer player) { + player.openBrowser("https://github.com/stanhebben/MineTweaker3/issues"); + } + })); - for (IBiome biome : MineTweakerAPI.game.getBiomes()) { - MineTweakerAPI.logCommand(" " + biome.getName()); - } + minetweakerCommands.put("forum", new MineTweakerCommand( + "forum", + new String[]{ + "/minetweaker forum", + " Opens your browser with the forum" + }, new ICommandFunction() { + @Override + public void execute(String[] arguments, IPlayer player) { + player.openBrowser("http://minetweaker3.powerofbytes.com/forum"); + } + })); - player.sendChat("Biome list generated; see minetweaker.log in your minecraft dir"); - } - })); + minetweakerCommands.put("biomes", new MineTweakerCommand( + "biomes", + new String[]{ + "/minetweaker biomes", + " Lists all the biomes in the game" + }, new ICommandFunction() { + @Override + public void execute(String[] arguments, IPlayer player) { + MineTweakerAPI.logCommand("Biomes:"); - minetweakerCommands.put("blockinfo", new MineTweakerCommand( - "blockinfo", - new String[] { - "/minetweaker blockinfo", - " Activates or deactivates block reader. In block info mode,", - " right-click a block to see ID, meta and tile entity data" - }, new ICommandFunction() { - @Override - public void execute(String[] arguments, IPlayer player) { - if (blockInfoPlayers.isEmpty()) { - blockEventHandler = events.onPlayerInteract(LISTEN_BLOCK_INFO); - } + for (IBiome biome : MineTweakerAPI.game.getBiomes()) { + MineTweakerAPI.logCommand(" " + biome.getName()); + } - if (blockInfoPlayers.contains(player)) { - blockInfoPlayers.remove(player); - player.sendChat("Block info mode deactivated."); - } else { - blockInfoPlayers.add(player); - player.sendChat("Block info mode activated. Right-click a block to see its data."); - } + player.sendChat("Biome list generated; see minetweaker.log in your minecraft dir"); + } + })); - if (blockInfoPlayers.isEmpty()) { - blockEventHandler.close(); - } - } - })); - } + minetweakerCommands.put("blockinfo", new MineTweakerCommand( + "blockinfo", + new String[]{ + "/minetweaker blockinfo", + " Activates or deactivates block reader. In block info mode,", + " right-click a block to see ID, meta and tile entity data" + }, new ICommandFunction() { + @Override + public void execute(String[] arguments, IPlayer player) { + if (blockInfoPlayers.isEmpty()) { + blockEventHandler = events.onPlayerInteract(LISTEN_BLOCK_INFO); + } - /** - * Access point to the event handler implementation. - */ - public static final MTEventManager events = new MTEventManager(); + if (blockInfoPlayers.contains(player)) { + blockInfoPlayers.remove(player); + player.sendChat("Block info mode deactivated."); + } else { + blockInfoPlayers.add(player); + player.sendChat("Block info mode activated. Right-click a block to see its data."); + } - /** - * Access point to the internal logger instance. - */ - public static final MTLogger logger = new MTLogger(); + if (blockInfoPlayers.isEmpty()) { + blockEventHandler.close(); + } + } + })); + } - /** - * Access point to general platform functions. - */ - public static IPlatformFunctions platform = null; + /** + * Access point to the event handler implementation. + */ + public static final MTEventManager events = new MTEventManager(); - /** - * Initializes the MineTweaker API. - * - * @param oreDict ore dictionary interface - * @param recipes recipe manager interface - * @param furnace furnace manager interface - * @param game game interface - * @param mods mods interface - * @param formatter formatter interface - * @param vanilla vanilla interface - */ - public static void init( - IOreDict oreDict, - IRecipeManager recipes, - IFurnaceManager furnace, - IGame game, - ILoadedMods mods, - IFormatter formatter, - IVanilla vanilla) { - MineTweakerAPI.oreDict = oreDict; - MineTweakerAPI.recipes = recipes; - MineTweakerAPI.furnace = furnace; - MineTweakerAPI.game = game; - MineTweakerAPI.loadedMods = mods; - MineTweakerAPI.format = formatter; - MineTweakerAPI.vanilla = vanilla; - } + /** + * Access point to the internal logger instance. + */ + public static final MTLogger logger = new MTLogger(); - /** - * Register an event handler to be fired upon reload. - * - * @param handler - * @return - */ - public static IEventHandle onReloadEvent(IEventHandler handler) { - return ONRELOAD.add(handler); - } - - public static IEventHandle onPostReload(IEventHandler handler) { - return ONPOSTRELOAD.add(handler); - } + /** + * Access point to general platform functions. + */ + public static IPlatformFunctions platform = null; - /** - * Must be called upon server start. - * - * @param server server interface - */ - public static void onServerStart(IServer server) { - MineTweakerAPI.server = server; - reload(); - } + /** + * Initializes the MineTweaker API. + * + * @param oreDict ore dictionary interface + * @param recipes recipe manager interface + * @param furnace furnace manager interface + * @param game game interface + * @param mods mods interface + * @param formatter formatter interface + * @param vanilla vanilla interface + */ + public static void init( + IOreDict oreDict, + IRecipeManager recipes, + IFurnaceManager furnace, + IGame game, + ILoadedMods mods, + IFormatter formatter, + IVanilla vanilla) { + MineTweakerAPI.oreDict = oreDict; + MineTweakerAPI.recipes = recipes; + MineTweakerAPI.furnace = furnace; + MineTweakerAPI.game = game; + MineTweakerAPI.loadedMods = mods; + MineTweakerAPI.format = formatter; + MineTweakerAPI.vanilla = vanilla; + } - /** - * Must be called upon server stop. - */ - public static void onServerStop() { - MineTweakerAPI.server = null; - } + /** + * Register an event handler to be fired upon reload. + * + * @param handler + * @return + */ + public static IEventHandle onReloadEvent(IEventHandler handler) { + return ONRELOAD.add(handler); + } - /** - * Sets the script provider. - * - * @param provider script provider - */ - public static void setScriptProvider(IScriptProvider provider) { - MineTweakerAPI.tweaker.setScriptProvider(provider); - } + public static IEventHandle onPostReload(IEventHandler handler) { + return ONPOSTRELOAD.add(handler); + } - /** - * Called to reload scripts. Must be called after setting a new script - * provider in order to reload scripts. - */ - public static void reload() { - blockInfoPlayers.clear(); + /** + * Must be called upon server start. + * + * @param server server interface + */ + public static void onServerStart(IServer server) { + MineTweakerAPI.server = server; + reload(); + } - logger.clear(); - events.clear(); + /** + * Must be called upon server stop. + */ + public static void onServerStop() { + MineTweakerAPI.server = null; + } - if (MineTweakerAPI.server != null) { - events.onPlayerLoggedIn(LISTEN_LOGIN); - events.onPlayerLoggedOut(LISTEN_LOGOUT); - } + /** + * Sets the script provider. + * + * @param provider script provider + */ + public static void setScriptProvider(IScriptProvider provider) { + MineTweakerAPI.tweaker.setScriptProvider(provider); + } + + /** + * Called to reload scripts. Must be called after setting a new script + * provider in order to reload scripts. + */ + public static void reload() { + blockInfoPlayers.clear(); + + logger.clear(); + events.clear(); + + if (MineTweakerAPI.server != null) { + events.onPlayerLoggedIn(LISTEN_LOGIN); + events.onPlayerLoggedOut(LISTEN_LOGOUT); + } // // byte[] currentScript = MineTweakerAPI.tweaker.getScriptData(); // if (currentScript != null) { @@ -624,204 +642,204 @@ public class MineTweakerImplementationAPI { // System.out.println("First time loading a script, go ahead"); // } - MineTweakerAPI.tweaker.rollback(); + MineTweakerAPI.tweaker.rollback(); - if (MineTweakerAPI.server != null) { - server.addCommand("minetweaker", "", new String[] { "mt" }, new ICommandFunction() { - @Override - public void execute(String[] arguments, IPlayer player) { - if (arguments.length == 0) { - player.sendChat("Please provide a command. Use /mt help for more info."); - } else if (arguments[0].equals("help")) { - String[] keys = minetweakerCommands.keySet().toArray(new String[minetweakerCommands.size()]); - Arrays.sort(keys); - for (String key : keys) { - for (String helpMessage : minetweakerCommands.get(key).description) { - player.sendChat(helpMessage); - } - } - } else { - MineTweakerCommand command = minetweakerCommands.get(arguments[0]); - if (command == null) { - player.sendChat("No such minetweaker command available"); - } else { - command.function.execute(Arrays.copyOfRange(arguments, 1, arguments.length), player); - } - } - } - }, new ICommandValidator() { - @Override - public boolean canExecute(IPlayer player) { - return server.isOp(player); - } - }, null); - } + if (MineTweakerAPI.server != null) { + server.addCommand("minetweaker", "", new String[]{"mt"}, new ICommandFunction() { + @Override + public void execute(String[] arguments, IPlayer player) { + if (arguments.length == 0) { + player.sendChat("Please provide a command. Use /mt help for more info."); + } else if (arguments[0].equals("help")) { + String[] keys = minetweakerCommands.keySet().toArray(new String[minetweakerCommands.size()]); + Arrays.sort(keys); + for (String key : keys) { + for (String helpMessage : minetweakerCommands.get(key).description) { + player.sendChat(helpMessage); + } + } + } else { + MineTweakerCommand command = minetweakerCommands.get(arguments[0]); + if (command == null) { + player.sendChat("No such minetweaker command available"); + } else { + command.function.execute(Arrays.copyOfRange(arguments, 1, arguments.length), player); + } + } + } + }, new ICommandValidator() { + @Override + public boolean canExecute(IPlayer player) { + return server.isOp(player); + } + }, null); + } - ONRELOAD.publish(new ReloadEvent()); + ONRELOAD.publish(new ReloadEvent()); - MineTweakerAPI.tweaker.load(); + MineTweakerAPI.tweaker.load(); - if (MineTweakerAPI.server != null) { - platform.distributeScripts(MineTweakerAPI.tweaker.getScriptData()); - } - - ONPOSTRELOAD.publish(new ReloadEvent()); - } + if (MineTweakerAPI.server != null) { + platform.distributeScripts(MineTweakerAPI.tweaker.getScriptData()); + } - /** - * Adds a new minetweaker command. Can be called with /mt <command&;gt; - * <arguments>. - * - * @param name command name - * @param description description strings - * @param function command implementation - */ - public static void addMineTweakerCommand(String name, String[] description, ICommandFunction function) { - MineTweakerAPI.apply(new AddMineTweakerCommandAction(new MineTweakerCommand(name, description, function))); - } + ONPOSTRELOAD.publish(new ReloadEvent()); + } - // ############################## - // ### Private static methods ### - // ############################## + /** + * Adds a new minetweaker command. Can be called with /mt <command&;gt; + * <arguments>. + * + * @param name command name + * @param description description strings + * @param function command implementation + */ + public static void addMineTweakerCommand(String name, String[] description, ICommandFunction function) { + MineTweakerAPI.apply(new AddMineTweakerCommandAction(new MineTweakerCommand(name, description, function))); + } - private static void copyToClipboard(String value) { - StringSelection stringSelection = new StringSelection(value); - if(!(Toolkit.getDefaultToolkit() instanceof HeadlessToolkit)) { - Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); - clipboard.setContents(stringSelection, null); - } - } + // ############################## + // ### Private static methods ### + // ############################## - // ############################ - // ### Public inner classes ### - // ############################ + private static void copyToClipboard(String value) { + StringSelection stringSelection = new StringSelection(value); + if (!(Toolkit.getDefaultToolkit() instanceof HeadlessToolkit)) { + Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); + clipboard.setContents(stringSelection, null); + } + } - public static class ReloadEvent { + // ############################ + // ### Public inner classes ### + // ############################ - } + public static class ReloadEvent { - // ###################### - // ### Action classes ### - // ###################### + } - private static class AddMineTweakerCommandAction implements IUndoableAction { - private final MineTweakerCommand command; - private boolean added; + // ###################### + // ### Action classes ### + // ###################### - public AddMineTweakerCommandAction(MineTweakerCommand command) { - this.command = command; - } + private static class AddMineTweakerCommandAction implements IUndoableAction { + private final MineTweakerCommand command; + private boolean added; - @Override - public void apply() { - if (!minetweakerCommands.containsKey(command.name)) { - minetweakerCommands.put(command.name, command); - added = true; - } else { - added = false; - } - } + public AddMineTweakerCommandAction(MineTweakerCommand command) { + this.command = command; + } - @Override - public boolean canUndo() { - return true; - } + @Override + public void apply() { + if (!minetweakerCommands.containsKey(command.name)) { + minetweakerCommands.put(command.name, command); + added = true; + } else { + added = false; + } + } - @Override - public void undo() { - if (added) { - minetweakerCommands.remove(command.name); - } - } + @Override + public boolean canUndo() { + return true; + } - @Override - public String describe() { - return "Adding minetweaker command " + command.name; - } + @Override + public void undo() { + if (added) { + minetweakerCommands.remove(command.name); + } + } - @Override - public String describeUndo() { - return "Removing minetweaker command " + command.name; - } + @Override + public String describe() { + return "Adding minetweaker command " + command.name; + } - @Override - public Object getOverrideKey() { - return null; - } - } + @Override + public String describeUndo() { + return "Removing minetweaker command " + command.name; + } - // ############################# - // ### Private inner classes ### - // ############################# + @Override + public Object getOverrideKey() { + return null; + } + } - private static class MineTweakerCommand { - private final String name; - private final String[] description; - private final ICommandFunction function; + // ############################# + // ### Private inner classes ### + // ############################# - public MineTweakerCommand(String name, String[] description, ICommandFunction function) { - this.name = name; - this.description = description; - this.function = function; - } - } + private static class MineTweakerCommand { + private final String name; + private final String[] description; + private final ICommandFunction function; - private static class ItemComparator implements Comparator { - @Override - public int compare(IItemDefinition o1, IItemDefinition o2) { - return o1.getId().compareTo(o2.getId()); - } - } + public MineTweakerCommand(String name, String[] description, ICommandFunction function) { + this.name = name; + this.description = description; + this.function = function; + } + } - private static class LiquidComparator implements Comparator { - @Override - public int compare(ILiquidDefinition o1, ILiquidDefinition o2) { - return o1.getName().compareTo(o2.getName()); - } - } + private static class ItemComparator implements Comparator { + @Override + public int compare(IItemDefinition o1, IItemDefinition o2) { + return o1.getId().compareTo(o2.getId()); + } + } - private static class BlockComparator implements Comparator { - @Override - public int compare(IBlockDefinition o1, IBlockDefinition o2) { - return o1.getId().compareTo(o2.getId()); - } - } + private static class LiquidComparator implements Comparator { + @Override + public int compare(ILiquidDefinition o1, ILiquidDefinition o2) { + return o1.getName().compareTo(o2.getName()); + } + } - private static class EntityComparator implements Comparator { - @Override - public int compare(IEntityDefinition o1, IEntityDefinition o2) { - return o1.getId().compareTo(o2.getId()); - } - } + private static class BlockComparator implements Comparator { + @Override + public int compare(IBlockDefinition o1, IBlockDefinition o2) { + return o1.getId().compareTo(o2.getId()); + } + } - private static class ListenPlayerLoggedIn implements IEventHandler { - @Override - public void handle(PlayerLoggedInEvent event) { - if (MineTweakerAPI.server != null && MineTweakerAPI.server.isOp(event.getPlayer())) { - logger.addPlayer(event.getPlayer()); - } - } - } + private static class EntityComparator implements Comparator { + @Override + public int compare(IEntityDefinition o1, IEntityDefinition o2) { + return o1.getId().compareTo(o2.getId()); + } + } - private static class ListenPlayerLoggedOut implements IEventHandler { - @Override - public void handle(PlayerLoggedOutEvent event) { - logger.removePlayer(event.getPlayer()); - } - } + private static class ListenPlayerLoggedIn implements IEventHandler { + @Override + public void handle(PlayerLoggedInEvent event) { + if (MineTweakerAPI.server != null && MineTweakerAPI.server.isOp(event.getPlayer())) { + logger.addPlayer(event.getPlayer()); + } + } + } - private static class ListenBlockInfo implements IEventHandler { - @Override - public void handle(PlayerInteractEvent event) { - if (blockInfoPlayers.contains(event.getPlayer())) { - IBlock block = event.getBlock(); - event.getPlayer().sendChat("Block ID: " + block.getDefinition().getId()); - event.getPlayer().sendChat("Meta value: " + block.getMeta()); - IData data = block.getTileData(); - if (data != null) { - event.getPlayer().sendChat("Tile entity data: " + data.asString()); - } - } - } - } + private static class ListenPlayerLoggedOut implements IEventHandler { + @Override + public void handle(PlayerLoggedOutEvent event) { + logger.removePlayer(event.getPlayer()); + } + } + + private static class ListenBlockInfo implements IEventHandler { + @Override + public void handle(PlayerInteractEvent event) { + if (blockInfoPlayers.contains(event.getPlayer())) { + IBlock block = event.getBlock(); + event.getPlayer().sendChat("Block ID: " + block.getDefinition().getId()); + event.getPlayer().sendChat("Meta value: " + block.getMeta()); + IData data = block.getTileData(); + if (data != null) { + event.getPlayer().sendChat("Tile entity data: " + data.asString()); + } + } + } + } } diff --git a/MineTweaker3-API/src/main/java/minetweaker/api/recipes/FurnaceRecipe.java b/MineTweaker3-API/src/main/java/minetweaker/api/recipes/FurnaceRecipe.java new file mode 100644 index 0000000..51a3e56 --- /dev/null +++ b/MineTweaker3-API/src/main/java/minetweaker/api/recipes/FurnaceRecipe.java @@ -0,0 +1,24 @@ +package minetweaker.api.recipes; + +import minetweaker.api.item.IItemStack; + +/** + * Created by Jared on 4/18/2016. + */ +public class FurnaceRecipe implements IFurnaceRecipe { + private final IItemStack input; + private final IItemStack output; + private final float xp; + + public FurnaceRecipe(IItemStack input, IItemStack output, float xp) { + this.input = input; + this.output = output; + this.xp = xp; + } + + @Override + public String toCommandString() { + return String.format("furnace.addRecipe(%s, %s, %s", output, input, xp); + } + +} diff --git a/MineTweaker3-API/src/main/java/minetweaker/api/recipes/IFurnaceManager.java b/MineTweaker3-API/src/main/java/minetweaker/api/recipes/IFurnaceManager.java index d20b386..b55d425 100644 --- a/MineTweaker3-API/src/main/java/minetweaker/api/recipes/IFurnaceManager.java +++ b/MineTweaker3-API/src/main/java/minetweaker/api/recipes/IFurnaceManager.java @@ -10,8 +10,11 @@ import minetweaker.api.item.IIngredient; import minetweaker.api.item.IItemStack; import stanhebben.zenscript.annotations.Optional; import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenGetter; import stanhebben.zenscript.annotations.ZenMethod; +import java.util.List; + /** * * @author Stan @@ -29,4 +32,12 @@ public interface IFurnaceManager { @ZenMethod public int getFuel(IItemStack item); + + /** + * Returns all crafting recipes. + * + * @return all crafting recipes + */ + @ZenGetter("all") + public List getAll(); } diff --git a/MineTweaker3-API/src/main/java/minetweaker/api/recipes/IFurnaceRecipe.java b/MineTweaker3-API/src/main/java/minetweaker/api/recipes/IFurnaceRecipe.java new file mode 100644 index 0000000..8f9d814 --- /dev/null +++ b/MineTweaker3-API/src/main/java/minetweaker/api/recipes/IFurnaceRecipe.java @@ -0,0 +1,10 @@ +package minetweaker.api.recipes; + +/** + * Created by Jared on 4/18/2016. + */ +public interface IFurnaceRecipe { + + + public String toCommandString(); +} diff --git a/MineTweaker3-MC1710-Main/src/main/java/minetweaker/mc19/furnace/MCFurnaceManager.java b/MineTweaker3-MC1710-Main/src/main/java/minetweaker/mc19/furnace/MCFurnaceManager.java index f40bb7c..04be2c0 100644 --- a/MineTweaker3-MC1710-Main/src/main/java/minetweaker/mc19/furnace/MCFurnaceManager.java +++ b/MineTweaker3-MC1710-Main/src/main/java/minetweaker/mc19/furnace/MCFurnaceManager.java @@ -7,206 +7,219 @@ package minetweaker.mc19.furnace; import cpw.mods.fml.common.registry.GameRegistry; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; import minetweaker.IUndoableAction; import minetweaker.MineTweakerAPI; import minetweaker.api.item.IIngredient; import minetweaker.api.item.IItemStack; -import static minetweaker.api.minecraft.MineTweakerMC.getItemStack; -import static minetweaker.api.minecraft.MineTweakerMC.getItemStacks; +import minetweaker.api.recipes.FurnaceRecipe; import minetweaker.api.recipes.IFurnaceManager; +import minetweaker.api.recipes.IFurnaceRecipe; import minetweaker.mc19.item.MCItemStack; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.FurnaceRecipes; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import static minetweaker.api.minecraft.MineTweakerMC.getItemStack; +import static minetweaker.api.minecraft.MineTweakerMC.getItemStacks; + /** - * * @author Stan */ public class MCFurnaceManager implements IFurnaceManager { - public MCFurnaceManager() { + public MCFurnaceManager() { - } + } - @Override - public void remove(IIngredient output, IIngredient input) { - if (output == null) - throw new IllegalArgumentException("output cannot be null"); + @Override + public void remove(IIngredient output, IIngredient input) { + if (output == null) + throw new IllegalArgumentException("output cannot be null"); - Map smeltingList = FurnaceRecipes.smelting().getSmeltingList(); + Map smeltingList = FurnaceRecipes.smelting().getSmeltingList(); - List toRemove = new ArrayList(); - List toRemoveValues = new ArrayList(); - for (Map.Entry entry : smeltingList.entrySet()) { - if (output.matches(new MCItemStack(entry.getValue())) - && (input == null || input.matches(new MCItemStack(entry.getKey())))) { - toRemove.add(entry.getKey()); - toRemoveValues.add(entry.getValue()); - } - } + List toRemove = new ArrayList(); + List toRemoveValues = new ArrayList(); + for (Map.Entry entry : smeltingList.entrySet()) { + if (output.matches(new MCItemStack(entry.getValue())) + && (input == null || input.matches(new MCItemStack(entry.getKey())))) { + toRemove.add(entry.getKey()); + toRemoveValues.add(entry.getValue()); + } + } - if (toRemove.isEmpty()) { - MineTweakerAPI.logWarning("No furnace recipes for " + output.toString()); - } else { - MineTweakerAPI.apply(new RemoveAction(toRemove, toRemoveValues)); - } - } + if (toRemove.isEmpty()) { + MineTweakerAPI.logWarning("No furnace recipes for " + output.toString()); + } else { + MineTweakerAPI.apply(new RemoveAction(toRemove, toRemoveValues)); + } + } - @Override - public void addRecipe(IItemStack output, IIngredient input, double xp) { - List items = input.getItems(); - if (items == null) { - MineTweakerAPI.logError("Cannot turn " + input.toString() + " into a furnace recipe"); - } + @Override + public void addRecipe(IItemStack output, IIngredient input, double xp) { + List items = input.getItems(); + if (items == null) { + MineTweakerAPI.logError("Cannot turn " + input.toString() + " into a furnace recipe"); + } - ItemStack[] items2 = getItemStacks(items); - ItemStack output2 = getItemStack(output); - MineTweakerAPI.apply(new AddRecipeAction(input, items2, output2, xp)); - } + ItemStack[] items2 = getItemStacks(items); + ItemStack output2 = getItemStack(output); + MineTweakerAPI.apply(new AddRecipeAction(input, items2, output2, xp)); + } - @Override - public void setFuel(IIngredient item, int fuel) { - MineTweakerAPI.apply(new SetFuelAction(new SetFuelPattern(item, fuel))); - } + @Override + public void setFuel(IIngredient item, int fuel) { + MineTweakerAPI.apply(new SetFuelAction(new SetFuelPattern(item, fuel))); + } - @Override - public int getFuel(IItemStack item) { - return GameRegistry.getFuelValue(getItemStack(item)); - } + @Override + public int getFuel(IItemStack item) { + return GameRegistry.getFuelValue(getItemStack(item)); + } - // ###################### - // ### Action classes ### - // ###################### + @Override + public List getAll() { + List retList = new ArrayList(); + for (Map.Entry ent : (Set>) FurnaceRecipes.smelting().getSmeltingList().entrySet()) { + retList.add(new FurnaceRecipe(new MCItemStack(ent.getKey()), new MCItemStack(ent.getValue()), FurnaceRecipes.smelting().func_151398_b(ent.getValue()))); + } + return retList; + } - private static class RemoveAction implements IUndoableAction { - private final List items; - private final List values; + // ###################### + // ### Action classes ### + // ###################### - public RemoveAction(List items, List values) { - this.items = items; - this.values = values; - } + private static class RemoveAction implements IUndoableAction { + private final List items; + private final List values; - @Override - public void apply() { - for (ItemStack item : items) { - FurnaceRecipes.smelting().getSmeltingList().remove(item); - } - } + public RemoveAction(List items, List values) { + this.items = items; + this.values = values; + } - @Override - public boolean canUndo() { - return true; - } + @Override + public void apply() { + for (ItemStack item : items) { + FurnaceRecipes.smelting().getSmeltingList().remove(item); + } + } - @Override - public void undo() { - for (int i = 0; i < items.size(); i++) { - FurnaceRecipes.smelting().getSmeltingList().put(items.get(i), values.get(i)); - } - } + @Override + public boolean canUndo() { + return true; + } - @Override - public String describe() { - return "Removing " + items.size() + " furnace recipes"; - } + @Override + public void undo() { + for (int i = 0; i < items.size(); i++) { + FurnaceRecipes.smelting().getSmeltingList().put(items.get(i), values.get(i)); + } + } - @Override - public String describeUndo() { - return "Restoring " + items.size() + " furnace recipes"; - } + @Override + public String describe() { + return "Removing " + items.size() + " furnace recipes"; + } - @Override - public Object getOverrideKey() { - return null; - } - } + @Override + public String describeUndo() { + return "Restoring " + items.size() + " furnace recipes"; + } - private static class AddRecipeAction implements IUndoableAction { - private final IIngredient ingredient; - private final ItemStack[] input; - private final ItemStack output; - private final double xp; + @Override + public Object getOverrideKey() { + return null; + } + } - public AddRecipeAction(IIngredient ingredient, ItemStack[] input, ItemStack output, double xp) { - this.ingredient = ingredient; - this.input = input; - this.output = output; - this.xp = xp; - } + private static class AddRecipeAction implements IUndoableAction { + private final IIngredient ingredient; + private final ItemStack[] input; + private final ItemStack output; + private final double xp; - @Override - public void apply() { - for (ItemStack inputStack : input) { - FurnaceRecipes.smelting().func_151394_a(inputStack, output, (float) xp); - } - } + public AddRecipeAction(IIngredient ingredient, ItemStack[] input, ItemStack output, double xp) { + this.ingredient = ingredient; + this.input = input; + this.output = output; + this.xp = xp; + } - @Override - public boolean canUndo() { - return true; - } + @Override + public void apply() { + for (ItemStack inputStack : input) { + FurnaceRecipes.smelting().func_151394_a(inputStack, output, (float) xp); + } + } - @Override - public void undo() { - for (ItemStack inputStack : input) { - FurnaceRecipes.smelting().getSmeltingList().remove(inputStack); - } - } + @Override + public boolean canUndo() { + return true; + } - @Override - public String describe() { - return "Adding furnace recipe for " + ingredient; - } + @Override + public void undo() { + for (ItemStack inputStack : input) { + FurnaceRecipes.smelting().getSmeltingList().remove(inputStack); + } + } - @Override - public String describeUndo() { - return "Removing furnace recipe for " + ingredient; - } + @Override + public String describe() { + return "Adding furnace recipe for " + ingredient; + } - @Override - public Object getOverrideKey() { - return null; - } - } + @Override + public String describeUndo() { + return "Removing furnace recipe for " + ingredient; + } - private static class SetFuelAction implements IUndoableAction { - private final SetFuelPattern pattern; + @Override + public Object getOverrideKey() { + return null; + } + } - public SetFuelAction(SetFuelPattern pattern) { - this.pattern = pattern; - } + private static class SetFuelAction implements IUndoableAction { + private final SetFuelPattern pattern; - @Override - public void apply() { - FuelTweaker.INSTANCE.addFuelPattern(pattern); - } + public SetFuelAction(SetFuelPattern pattern) { + this.pattern = pattern; + } - @Override - public boolean canUndo() { - return true; - } + @Override + public void apply() { + FuelTweaker.INSTANCE.addFuelPattern(pattern); + } - @Override - public void undo() { - FuelTweaker.INSTANCE.removeFuelPattern(pattern); - } + @Override + public boolean canUndo() { + return true; + } - @Override - public String describe() { - return "Setting fuel for " + pattern.getPattern(); - } + @Override + public void undo() { + FuelTweaker.INSTANCE.removeFuelPattern(pattern); + } - @Override - public String describeUndo() { - return "Removing fuel for " + pattern.getPattern(); - } + @Override + public String describe() { + return "Setting fuel for " + pattern.getPattern(); + } - @Override - public Object getOverrideKey() { - return null; - } - } + @Override + public String describeUndo() { + return "Removing fuel for " + pattern.getPattern(); + } + + @Override + public Object getOverrideKey() { + return null; + } + } }