From 54ec75fd3d618f01e52fb6cb6416cecbb53c5011 Mon Sep 17 00:00:00 2001 From: jaredlll08 Date: Mon, 31 Aug 2015 19:08:46 +0200 Subject: [PATCH] close #74 close #133 --- .../MineTweakerImplementationAPI.java | 790 +++++++++--------- .../java/minetweaker/api/item/IItemStack.java | 64 +- MineTweaker3-MC1710-Main/formatter.xml | 295 +++++++ .../minetweaker/mc1710/MineTweakerMod.java | 3 + .../minetweaker/mc1710/item/MCItemStack.java | 7 +- .../mc1710/recipes/MCRecipeManager.java | 91 +- .../java/stanhebben/zenscript/ZenModule.java | 113 +-- .../zenscript/compiler/TypeRegistry.java | 22 +- .../statements/StatementExpression.java | 8 +- .../zenscript/type/natives/IJavaMethod.java | 16 +- .../type/natives/ZenNativeMember.java | 34 +- 11 files changed, 872 insertions(+), 571 deletions(-) create mode 100644 MineTweaker3-MC1710-Main/formatter.xml diff --git a/MineTweaker3-API/src/main/java/minetweaker/MineTweakerImplementationAPI.java b/MineTweaker3-API/src/main/java/minetweaker/MineTweakerImplementationAPI.java index 22a6b06..fa81611 100644 --- a/MineTweaker3-API/src/main/java/minetweaker/MineTweakerImplementationAPI.java +++ b/MineTweaker3-API/src/main/java/minetweaker/MineTweakerImplementationAPI.java @@ -47,466 +47,469 @@ import minetweaker.util.EventList; import minetweaker.util.IEventHandler; /** - * The implementation API is used by API implementations for internal communication - * and initialization. + * 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 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 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(); - + static { minetweakerCommands = new HashMap(); - + minetweakerCommands.put("reload", new MineTweakerCommand( "reload", new String[] { - "/minetweaker reload", - " Reloads all scripts" + "/minetweaker reload", + " Reloads all scripts" }, new ICommandFunction() { - @Override - public void execute(String[] arguments, IPlayer player) { - reload(); - player.sendChat("Scripts reloaded"); - } - })); - + @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" + "/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; + @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); + } + + if (player != null) { + player.sendChat("List generated; see minetweaker.log in your minecraft dir"); + } } - - MineTweakerAPI.logCommand("<" + item.getId() + ">" + displayName); - } - - 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" + "/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()); - } - - if (player != null) { - player.sendChat("List generated; see minetweaker.log in your minecraft dir"); - } - } - })); - + @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()); + } + + 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" + "/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()); - } - - if (player != null) { - player.sendChat("List generated; see minetweaker.log in your minecraft dir"); - } - } - })); - + @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()); + } + + 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" + "/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()); - } - - if (player != null) { - player.sendChat("List generated; see minetweaker.log in your minecraft dir"); - } - } - })); - + @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()); + } + + 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" + "/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..."); - } - - MineTweakerAPI.logCommand("Recipes:"); - for (ICraftingRecipe recipe : MineTweakerAPI.recipes.getAll()) { - MineTweakerAPI.logCommand(recipe.toCommandString()); - } + @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..."); + } - 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(); - - 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"); - } - - copyToClipboard(recipesString.toString()); - } - } else { - if (player != null) { - player.sendChat("Invalid arguments for recipes command"); - } - } - } - })); - - 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("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); - - List entries = hand.getOres(); - for (IOreDictEntry entry : entries) { - player.sendChat("Is in "); - } - } - } - })); - - 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); + MineTweakerAPI.logCommand("Recipes:"); + for (ICraftingRecipe recipe : MineTweakerAPI.recipes.getAll()) { + MineTweakerAPI.logCommand(recipe.toCommandString()); + } + + 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(); + + 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"); + } + + copyToClipboard(recipesString.toString()); + } + } else { + if (player != null) { + player.sendChat("Invalid arguments for recipes command"); } } } - } - player.sendChat("List generated; see minetweaker.log in your minecraft dir"); - } - })); - + })); + + 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("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); + + List entries = hand.getOres(); + for (IOreDictEntry entry : entries) { + player.sendChat("Is in "); + } + } + } + })); + + 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("mods", new MineTweakerCommand( "mods", new String[] { - "/minetweaker mods", - " Outputs all active mod IDs and versions in the game" + "/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); - } - } - })); - + @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("name", new MineTweakerCommand( "name", new String[] { - "/minetweaker name ", - " Outputs the name for the given item ID", + "/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"); + @Override + public void execute(String[] arguments, IPlayer player) { + if (arguments.length < 1) { + player.sendChat("missing id parameter"); } else { - StringBuilder description = new StringBuilder(); - description.append('<'); - description.append(definition.getId()); - description.append('>'); - player.sendChat(description.toString()); + 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"); + } } - } catch (NumberFormatException e) { - MineTweakerAPI.logCommand("ID must be an integer"); } - } - } - })); - + })); + minetweakerCommands.put("seeds", new MineTweakerCommand( "seeds", new String[] { - "/minetweaker seeds", - " Prints all seeds registered", - " for tall grass" + "/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); - } - } + @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("loot", new MineTweakerCommand( "seeds", new String[] { - "/minetweaker seeds", - " Prints all seeds registered", - " for tall grass" + "/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(lootType); - for (LootEntry entry : entries) { - MineTweakerAPI.logCommand(" " + entry.toString()); + @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(lootType); + for (LootEntry entry : entries) { + MineTweakerAPI.logCommand(" " + entry.toString()); + } + } + + player.sendChat("List generated; see minetweaker.log in your minecraft dir"); + } else { + MineTweakerAPI.logCommand("Loot for type: " + arguments[0]); + + List entries = MineTweakerAPI.vanilla.getLoot().getLoot(arguments[0]); + 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]); - - List entries = MineTweakerAPI.vanilla.getLoot().getLoot(arguments[0]); - for (LootEntry entry : entries) { - MineTweakerAPI.logCommand(" " + entry.toString()); - } - - player.sendChat("List generated; see minetweaker.log in your minecraft dir"); - } - } })); - + minetweakerCommands.put("wiki", new MineTweakerCommand( "wiki", new String[] { - "/minetweaker wiki", - " Opens your browser with the wiki" + "/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/"); - } - })); - + @Override + public void execute(String[] arguments, IPlayer player) { + player.openBrowser("http://minetweaker3.powerofbytes.com/wiki/"); + } + })); + minetweakerCommands.put("bugs", new MineTweakerCommand( "bugs", new String[] { - "/minetweaker bugs", - " Opens your browser with the GitHub bug tracker" + "/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"); - } - })); - + @Override + public void execute(String[] arguments, IPlayer player) { + player.openBrowser("https://github.com/stanhebben/MineTweaker3/issues"); + } + })); + minetweakerCommands.put("forum", new MineTweakerCommand( "forum", new String[] { - "/minetweaker forum", - " Opens your browser with the forum" + "/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"); - } - })); - + @Override + public void execute(String[] arguments, IPlayer player) { + player.openBrowser("http://minetweaker3.powerofbytes.com/forum"); + } + })); + minetweakerCommands.put("biomes", new MineTweakerCommand( "biomes", new String[] { - "/minetweaker biomes", - " Lists all the biomes in the game" + "/minetweaker biomes", + " Lists all the biomes in the game" }, new ICommandFunction() { - @Override - public void execute(String[] arguments, IPlayer player) { - MineTweakerAPI.logCommand("Biomes:"); - - for (IBiome biome : MineTweakerAPI.game.getBiomes()) { - MineTweakerAPI.logCommand(" " + biome.getName()); - } - - player.sendChat("Biome list generated; see minetweaker.log in your minecraft dir"); - } - })); - + @Override + public void execute(String[] arguments, IPlayer player) { + MineTweakerAPI.logCommand("Biomes:"); + + for (IBiome biome : MineTweakerAPI.game.getBiomes()) { + MineTweakerAPI.logCommand(" " + biome.getName()); + } + + player.sendChat("Biome list generated; see minetweaker.log in your minecraft dir"); + } + })); + 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" + "/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); - } - - 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."); - } - - if (blockInfoPlayers.isEmpty()) { - blockEventHandler.close(); - } - } + @Override + public void execute(String[] arguments, IPlayer player) { + if (blockInfoPlayers.isEmpty()) { + blockEventHandler = events.onPlayerInteract(LISTEN_BLOCK_INFO); + } + + 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."); + } + + if (blockInfoPlayers.isEmpty()) { + blockEventHandler.close(); + } + } })); } - + /** * Access point to the event handler implementation. */ public static final MTEventManager events = new MTEventManager(); - + /** * Access point to the internal logger instance. */ public static final MTLogger logger = new MTLogger(); - + /** * Access point to general platform functions. */ public static IPlatformFunctions platform = null; - + /** * Initializes the MineTweaker API. * @@ -534,17 +537,17 @@ public class MineTweakerImplementationAPI { MineTweakerAPI.format = formatter; MineTweakerAPI.vanilla = vanilla; } - + /** * Register an event handler to be fired upon reload. * * @param handler - * @return + * @return */ public static IEventHandle onReloadEvent(IEventHandler handler) { return ONRELOAD.add(handler); } - + /** * Must be called upon server start. * @@ -554,14 +557,14 @@ public class MineTweakerImplementationAPI { MineTweakerAPI.server = server; reload(); } - + /** * Must be called upon server stop. */ public static void onServerStop() { MineTweakerAPI.server = null; } - + /** * Sets the script provider. * @@ -570,35 +573,34 @@ public class MineTweakerImplementationAPI { 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) { System.out.println("Already loaded a script before"); - + // alread loaded a script byte[] stagedScript = MineTweakerAPI.tweaker.getStagedScriptData(); - + if (Arrays.equals(currentScript, stagedScript)) { System.out.println("No reload needed"); return; // no reload necessary } - + if (MineTweakerAPI.game.isLocked()) { System.out.println("Reload blocked"); MineTweakerAPI.game.signalLockError(); @@ -607,10 +609,9 @@ public class MineTweakerImplementationAPI { } else { System.out.println("First time loading a script, go ahead"); } - - + MineTweakerAPI.tweaker.rollback(); - + if (MineTweakerAPI.server != null) { server.addCommand("minetweaker", "", new String[] { "mt" }, new ICommandFunction() { @Override @@ -641,18 +642,19 @@ public class MineTweakerImplementationAPI { } }, null); } - + ONRELOAD.publish(new ReloadEvent()); - + MineTweakerAPI.tweaker.load(); - + if (MineTweakerAPI.server != null) { platform.distributeScripts(MineTweakerAPI.tweaker.getScriptData()); } } - + /** - * Adds a new minetweaker command. Can be called with /mt <command&;gt; <arguments>. + * Adds a new minetweaker command. Can be called with /mt <command&;gt; + * <arguments>. * * @param name command name * @param description description strings @@ -661,33 +663,33 @@ public class MineTweakerImplementationAPI { public static void addMineTweakerCommand(String name, String[] description, ICommandFunction function) { MineTweakerAPI.apply(new AddMineTweakerCommandAction(new MineTweakerCommand(name, description, function))); } - + // ############################## // ### Private static methods ### // ############################## - + private static void copyToClipboard(String value) { StringSelection stringSelection = new StringSelection(value); Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); clipboard.setContents(stringSelection, null); } - + // ############################ // ### Public inner classes ### // ############################ - + public static class ReloadEvent { - + } - + // ###################### // ### Action classes ### // ###################### - + private static class AddMineTweakerCommandAction implements IUndoableAction { private final MineTweakerCommand command; private boolean added; - + public AddMineTweakerCommandAction(MineTweakerCommand command) { this.command = command; } @@ -729,51 +731,51 @@ public class MineTweakerImplementationAPI { return null; } } - + // ############################# // ### Private inner classes ### // ############################# - + private static class MineTweakerCommand { private final String name; private final String[] description; private final ICommandFunction function; - + public MineTweakerCommand(String name, String[] description, ICommandFunction function) { this.name = name; this.description = description; this.function = function; } } - + private static class ItemComparator implements Comparator { @Override public int compare(IItemDefinition o1, IItemDefinition 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 BlockComparator implements Comparator { @Override public int compare(IBlockDefinition o1, IBlockDefinition o2) { return o1.getId().compareTo(o2.getId()); } } - + private static class EntityComparator implements Comparator { @Override public int compare(IEntityDefinition o1, IEntityDefinition o2) { return o1.getId().compareTo(o2.getId()); } } - + private static class ListenPlayerLoggedIn implements IEventHandler { @Override public void handle(PlayerLoggedInEvent event) { @@ -782,14 +784,14 @@ public class MineTweakerImplementationAPI { } } } - + 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) { diff --git a/MineTweaker3-API/src/main/java/minetweaker/api/item/IItemStack.java b/MineTweaker3-API/src/main/java/minetweaker/api/item/IItemStack.java index 2419e0b..dd8440c 100644 --- a/MineTweaker3-API/src/main/java/minetweaker/api/item/IItemStack.java +++ b/MineTweaker3-API/src/main/java/minetweaker/api/item/IItemStack.java @@ -14,17 +14,17 @@ import stanhebben.zenscript.annotations.ZenOperator; import stanhebben.zenscript.annotations.ZenSetter; /** - * Contains an item stack. An item stack consists of an item definition, - * a meta or damage value and NBT data. + * Contains an item stack. An item stack consists of an item definition, a meta + * or damage value and NBT data. * - * Item stacks can be retrieved using its name (or ID, in 1.6.4) with the bracket - * syntax. When using the bracket syntax, by default, the item stack will match - * any size when used as ingredient. Item stacks can be multiplied with an integer - * to create a stack of different size. + * Item stacks can be retrieved using its name (or ID, in 1.6.4) with the + * bracket syntax. When using the bracket syntax, by default, the item stack + * will match any size when used as ingredient. Item stacks can be multiplied + * with an integer to create a stack of different size. * - * Item stacks are immutable. You can, however, easily create modified stacks using - * the helper methods. Adding conditions and transformations will turn the item - * stack into an ingredients. + * Item stacks are immutable. You can, however, easily create modified stacks + * using the helper methods. Adding conditions and transformations will turn the + * item stack into an ingredients. * * @author Stan Hebben */ @@ -37,7 +37,7 @@ public interface IItemStack extends IIngredient { */ @ZenGetter("definition") public IItemDefinition getDefinition(); - + /** * Gets the unlocalized item name. * @@ -45,7 +45,7 @@ public interface IItemStack extends IIngredient { */ @ZenGetter("name") public String getName(); - + /** * Gets the display name. By default, it is the localized item name, but * could also be the display name from NBT data, or another item-specific @@ -55,7 +55,7 @@ public interface IItemStack extends IIngredient { */ @ZenGetter("displayName") public String getDisplayName(); - + /** * Sets the display name. Only works if the name is translatable. Does not * override names set by NBT data or using item-specific logic. @@ -64,15 +64,15 @@ public interface IItemStack extends IIngredient { */ @ZenSetter("displayName") public void setDisplayName(String name); - - + /** * Gets the max stack size for an item * * @return int max stack size */ - @ZenGetter + @ZenGetter("maxStackSize") public int getMaxStackSize(); + /** * Sets the ItemStack max stack size. * @@ -80,7 +80,7 @@ public interface IItemStack extends IIngredient { */ @ZenSetter("maxStackSize") public void setMaxStackSize(int size); - + /** * Gets the item damage. Returns 0 if the item cannot be damaged. * @@ -88,7 +88,7 @@ public interface IItemStack extends IIngredient { */ @ZenGetter("damage") public int getDamage(); - + /** * Gets the maximum item damage. Returns 0 if the item cannot be damaged. * @@ -96,7 +96,7 @@ public interface IItemStack extends IIngredient { */ @ZenGetter("maxDamage") public int getMaxDamage(); - + /** * Gets the item tag. (NBT data) The resulting data is immutable and can * only be changed with updateTag. Returns empty data if there is no data. @@ -106,17 +106,17 @@ public interface IItemStack extends IIngredient { */ @ZenGetter("tag") public IData getTag(); - + /** * Gets the liquid contained in this item, if any. If this item stack is not - * an item container, it returns null. Only returns the amount of liquid - * in a single item and doesn't into account stack size. + * an item container, it returns null. Only returns the amount of liquid in + * a single item and doesn't into account stack size. * * @return liquid data */ @ZenGetter("liquid") public ILiquidStack getLiquid(); - + /** * Creates a new item stack with a different stack size. * @@ -126,7 +126,7 @@ public interface IItemStack extends IIngredient { @ZenOperator(OperatorType.MUL) @ZenMethod public IItemStack amount(int amount); - + /** * Creates a weighted item stack with the given percentage chance. Does the * same as item.weight(p * 0.01). @@ -136,7 +136,7 @@ public interface IItemStack extends IIngredient { */ @ZenOperator(OperatorType.MOD) public WeightedItemStack percent(float p); - + /** * Creates a weighted item stack with the given weight. * @@ -145,7 +145,7 @@ public interface IItemStack extends IIngredient { */ @ZenMethod public WeightedItemStack weight(float p); - + /** * Creates an item stack with the same item and stack size, but accepting * any damage value. Only useful for items used as ingredients. @@ -154,7 +154,7 @@ public interface IItemStack extends IIngredient { */ @ZenMethod public IIngredient anyDamage(); - + /** * Creates an item stack with the specified damage. * @@ -163,7 +163,7 @@ public interface IItemStack extends IIngredient { */ @ZenMethod public IItemStack withDamage(int damage); - + /** * Creates an item stack with the specified stack size. * @@ -172,7 +172,7 @@ public interface IItemStack extends IIngredient { */ @ZenMethod public IItemStack withAmount(int amount); - + /** * Creates an item stack with wildcard stack size. * @@ -180,7 +180,7 @@ public interface IItemStack extends IIngredient { */ @ZenMethod public IItemStack anyAmount(); - + /** * Creates an item stack with the given nbt tag. Ignores existing tags. * @@ -189,7 +189,7 @@ public interface IItemStack extends IIngredient { */ @ZenMethod public IItemStack withTag(IData tag); - + /** * Creates an item stack with updated nbt tag. Updates existing tags. * @@ -198,7 +198,7 @@ public interface IItemStack extends IIngredient { */ @ZenMethod public IItemStack updateTag(IData tagUpdate); - + /** * Converts this item stack into a block. * @@ -206,7 +206,7 @@ public interface IItemStack extends IIngredient { */ @ZenCaster public IBlock asBlock(); - + /** * Retrieves all the ores referring to this item. Includes wildcard ore * entries. diff --git a/MineTweaker3-MC1710-Main/formatter.xml b/MineTweaker3-MC1710-Main/formatter.xml new file mode 100644 index 0000000..ae0d68d --- /dev/null +++ b/MineTweaker3-MC1710-Main/formatter.xml @@ -0,0 +1,295 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/MineTweaker3-MC1710-Main/src/main/java/minetweaker/mc1710/MineTweakerMod.java b/MineTweaker3-MC1710-Main/src/main/java/minetweaker/mc1710/MineTweakerMod.java index 71280cf..b4b0072 100644 --- a/MineTweaker3-MC1710-Main/src/main/java/minetweaker/mc1710/MineTweakerMod.java +++ b/MineTweaker3-MC1710-Main/src/main/java/minetweaker/mc1710/MineTweakerMod.java @@ -17,8 +17,11 @@ import cpw.mods.fml.common.event.FMLServerStartingEvent; import cpw.mods.fml.common.event.FMLServerStoppedEvent; import cpw.mods.fml.common.network.NetworkRegistry; import cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper; +import cpw.mods.fml.common.registry.VillagerRegistry; import cpw.mods.fml.relauncher.Side; + import java.io.File; + import minetweaker.MineTweakerAPI; import minetweaker.MineTweakerImplementationAPI; import minetweaker.api.logger.FileLogger; diff --git a/MineTweaker3-MC1710-Main/src/main/java/minetweaker/mc1710/item/MCItemStack.java b/MineTweaker3-MC1710-Main/src/main/java/minetweaker/mc1710/item/MCItemStack.java index ffdf6a5..995f093 100644 --- a/MineTweaker3-MC1710-Main/src/main/java/minetweaker/mc1710/item/MCItemStack.java +++ b/MineTweaker3-MC1710-Main/src/main/java/minetweaker/mc1710/item/MCItemStack.java @@ -56,7 +56,7 @@ public class MCItemStack implements IItemStack { throw new IllegalArgumentException("stack cannot be null"); stack = itemStack.copy(); - items = Collections. singletonList(this); + items = Collections.singletonList(this); } public MCItemStack(ItemStack itemStack, boolean wildcardSize) { @@ -70,13 +70,13 @@ public class MCItemStack implements IItemStack { throw new IllegalArgumentException("stack cannot be null"); stack = itemStack; - items = Collections. singletonList(this); + items = Collections.singletonList(this); this.tag = tag; } private MCItemStack(ItemStack itemStack, IData tag, boolean wildcardSize) { stack = itemStack; - items = Collections. singletonList(this); + items = Collections.singletonList(this); this.tag = tag; this.wildcardSize = wildcardSize; } @@ -108,7 +108,6 @@ public class MCItemStack implements IItemStack { @Override public void setMaxStackSize(int size) { - System.out.println("changing stack size"); MineTweakerAPI.apply(new SetStackSizeAction((ItemStack) getInternal(), size)); } diff --git a/MineTweaker3-MC1710-Main/src/main/java/minetweaker/mc1710/recipes/MCRecipeManager.java b/MineTweaker3-MC1710-Main/src/main/java/minetweaker/mc1710/recipes/MCRecipeManager.java index 597bc9e..ed148a8 100644 --- a/MineTweaker3-MC1710-Main/src/main/java/minetweaker/mc1710/recipes/MCRecipeManager.java +++ b/MineTweaker3-MC1710-Main/src/main/java/minetweaker/mc1710/recipes/MCRecipeManager.java @@ -36,16 +36,16 @@ import net.minecraftforge.oredict.ShapelessOreRecipe; public class MCRecipeManager implements IRecipeManager { private final List recipes; private final List transformerRecipes; - + public MCRecipeManager() { recipes = (List) CraftingManager.getInstance().getRecipeList(); transformerRecipes = new ArrayList(); } - + public boolean hasTransformerRecipes() { return transformerRecipes.size() > 0; } - + public void applyTransformations(ICraftingInventory inventory, IPlayer byPlayer) { for (ICraftingRecipe recipe : transformerRecipes) { if (recipe.matches(inventory)) { @@ -54,40 +54,40 @@ public class MCRecipeManager implements IRecipeManager { } } } - + @Override public List getRecipesFor(IIngredient ingredient) { List results = new ArrayList(); - + for (IRecipe recipe : recipes) { if (ingredient.matches(MineTweakerMC.getIItemStack(recipe.getRecipeOutput()))) { ICraftingRecipe converted = RecipeConverter.toCraftingRecipe(recipe); results.add(converted); } } - + return results; } - + @Override public List getAll() { List results = new ArrayList(); - + for (IRecipe recipe : recipes) { ICraftingRecipe converted = RecipeConverter.toCraftingRecipe(recipe); results.add(converted); } - + return results; } - + @Override public int remove(IIngredient output) { List toRemove = new ArrayList(); List removeIndex = new ArrayList(); for (int i = 0; i < recipes.size(); i++) { IRecipe recipe = recipes.get(i); - + // certain special recipes have no predefined output. ignore those // since these cannot be removed with MineTweaker scripts if (recipe.getRecipeOutput() != null) { @@ -97,11 +97,11 @@ public class MCRecipeManager implements IRecipeManager { } } } - + MineTweakerAPI.apply(new ActionRemoveRecipes(toRemove, removeIndex)); return toRemove.size(); } - + @Override public void addShaped(IItemStack output, IIngredient[][] ingredients, IRecipeFunction function) { addShaped(output, ingredients, function, false); @@ -123,24 +123,24 @@ public class MCRecipeManager implements IRecipeManager { public int removeShaped(IIngredient output, IIngredient[][] ingredients) { int ingredientsWidth = 0; int ingredientsHeight = 0; - + if (ingredients != null) { ingredientsHeight = ingredients.length; - + for (int i = 0; i < ingredients.length; i++) { ingredientsWidth = Math.max(ingredientsWidth, ingredients[i].length); } } - + List toRemove = new ArrayList(); List removeIndex = new ArrayList(); outer: for (int i = 0; i < recipes.size(); i++) { IRecipe recipe = recipes.get(i); - + if (recipe.getRecipeOutput() == null || !output.matches(getIItemStack(recipe.getRecipeOutput()))) { continue; } - + if (ingredients != null) { if (recipe instanceof ShapedRecipes) { ShapedRecipes srecipe = (ShapedRecipes) recipe; @@ -153,7 +153,7 @@ public class MCRecipeManager implements IRecipeManager { for (int k = 0; k < ingredientsWidth; k++) { IIngredient ingredient = k > row.length ? null : row[k]; ItemStack recipeIngredient = srecipe.recipeItems[j * srecipe.recipeWidth + k]; - + if (!matches(recipeIngredient, ingredient)) { continue outer; } @@ -166,7 +166,7 @@ public class MCRecipeManager implements IRecipeManager { if (ingredientsWidth != recipeWidth || ingredientsHeight != recipeHeight) { continue; } - + for (int j = 0; j < ingredientsHeight; j++) { IIngredient[] row = ingredients[j]; for (int k = 0; k < ingredientsWidth; k++) { @@ -180,14 +180,14 @@ public class MCRecipeManager implements IRecipeManager { } } else { if (recipe instanceof ShapedRecipes) { - + } else if (recipe instanceof ShapedOreRecipe) { - + } else { continue; } } - + toRemove.add(recipe); removeIndex.add(i); } @@ -202,60 +202,61 @@ public class MCRecipeManager implements IRecipeManager { List removeIndex = new ArrayList(); outer: for (int i = 0; i < recipes.size(); i++) { IRecipe recipe = recipes.get(i); - + if (recipe.getRecipeOutput() == null || !output.matches(getIItemStack(recipe.getRecipeOutput()))) { continue; } - + if (ingredients != null) { if (recipe instanceof ShapelessRecipes) { ShapelessRecipes srecipe = (ShapelessRecipes) recipe; - + if (ingredients.length > srecipe.getRecipeSize()) { continue; } else if (!wildcard && ingredients.length < srecipe.getRecipeSize()) { continue; } - + checkIngredient: for (int j = 0; j < ingredients.length; j++) { for (int k = 0; k < srecipe.getRecipeSize(); k++) { if (matches(srecipe.recipeItems.get(k), ingredients[j])) { continue checkIngredient; } } - + continue outer; } } else if (recipe instanceof ShapelessOreRecipe) { ShapelessOreRecipe srecipe = (ShapelessOreRecipe) recipe; ArrayList inputs = srecipe.getInput(); - + if (inputs.size() < ingredients.length) { continue; - } if (!wildcard && inputs.size() > ingredients.length) { + } + if (!wildcard && inputs.size() > ingredients.length) { continue; } - + checkIngredient: for (int j = 0; j < ingredients.length; j++) { for (int k = 0; k < srecipe.getRecipeSize(); k++) { if (matches(inputs.get(k), ingredients[j])) { continue checkIngredient; } } - + continue outer; } } } else { if (recipe instanceof ShapelessRecipes) { - + } else if (recipe instanceof ShapelessOreRecipe) { - + } else { continue; } } - + toRemove.add(recipe); removeIndex.add(i); } @@ -267,13 +268,13 @@ public class MCRecipeManager implements IRecipeManager { @Override public IItemStack craft(IItemStack[][] contents) { Container container = new ContainerVirtual(); - + int width = 0; int height = contents.length; for (IItemStack[] row : contents) { width = Math.max(width, row.length); } - + ItemStack[] iContents = new ItemStack[width * height]; for (int i = 0; i < height; i++) { for (int j = 0; j < contents[i].length; j++) { @@ -282,7 +283,7 @@ public class MCRecipeManager implements IRecipeManager { } } } - + InventoryCrafting inventory = new InventoryCrafting(container, width, height); for (int i = 0; i < iContents.length; i++) { inventory.setInventorySlotContents(i, iContents[i]); @@ -294,18 +295,18 @@ public class MCRecipeManager implements IRecipeManager { return getIItemStack(result); } } - + private class ContainerVirtual extends Container { @Override public boolean canInteractWith(EntityPlayer var1) { return false; } } - + private class ActionRemoveRecipes implements IUndoableAction { private final List removingIndices; private final List removingRecipes; - + public ActionRemoveRecipes(List recipes, List indices) { this.removingIndices = indices; this.removingRecipes = recipes; @@ -346,11 +347,11 @@ public class MCRecipeManager implements IRecipeManager { return null; } } - + private class ActionAddRecipe implements IUndoableAction { private final IRecipe recipe; private final ICraftingRecipe craftingRecipe; - + public ActionAddRecipe(IRecipe recipe, ICraftingRecipe craftingRecipe) { this.recipe = recipe; this.craftingRecipe = craftingRecipe; @@ -398,7 +399,7 @@ public class MCRecipeManager implements IRecipeManager { IRecipe irecipe = RecipeConverter.convert(recipe); MineTweakerAPI.apply(new ActionAddRecipe(irecipe, recipe)); } - + private static boolean matches(Object input, IIngredient ingredient) { if ((input == null) != (ingredient == null)) { return false; @@ -413,7 +414,7 @@ public class MCRecipeManager implements IRecipeManager { } } } - + return true; } } diff --git a/ZenScript/src/main/java/stanhebben/zenscript/ZenModule.java b/ZenScript/src/main/java/stanhebben/zenscript/ZenModule.java index dfe148c..b2b25c7 100644 --- a/ZenScript/src/main/java/stanhebben/zenscript/ZenModule.java +++ b/ZenScript/src/main/java/stanhebben/zenscript/ZenModule.java @@ -37,9 +37,9 @@ import static stanhebben.zenscript.util.ZenTypeUtil.internal; * Main module class. Contains a compiled module. The static methods of this * class can be used to compile a specific file or files. * - * Modules may contain statements in their source, or define functions. Functions - * in different scripts within the same module are accessible to each other, but - * not to other modules. + * Modules may contain statements in their source, or define functions. + * Functions in different scripts within the same module are accessible to each + * other, but not to other modules. * * @author Stan Hebben */ @@ -55,11 +55,11 @@ public class ZenModule { public static void compileScripts(String mainFileName, List scripts, IEnvironmentGlobal environmentGlobal, boolean debug) { ClassWriter clsMain = new ClassWriter(ClassWriter.COMPUTE_FRAMES); clsMain.visitSource(mainFileName, null); - - clsMain.visit(Opcodes.V1_6, Opcodes.ACC_PUBLIC, "__ZenMain__", null, internal(Object.class), new String[] {internal(Runnable.class)}); + + clsMain.visit(Opcodes.V1_6, Opcodes.ACC_PUBLIC, "__ZenMain__", null, internal(Object.class), new String[] { internal(Runnable.class) }); MethodOutput mainRun = new MethodOutput(clsMain, Opcodes.ACC_PUBLIC, "run", "()V", null, null); mainRun.start(); - + for (ZenParsedFile script : scripts) { for (Map.Entry function : script.getFunctions().entrySet()) { ParsedFunction fn = function.getValue(); @@ -71,17 +71,17 @@ public class ZenModule { fn.getReturnType()), fn.getPosition()); } } - + for (ZenParsedFile script : scripts) { ClassWriter clsScript = new ClassWriter(ClassWriter.COMPUTE_FRAMES); clsScript.visitSource(script.getFileName(), null); EnvironmentClass environmentScript = new EnvironmentClass(clsScript, script.getEnvironment()); - - clsScript.visit(Opcodes.V1_6, Opcodes.ACC_PUBLIC, script.getClassName().replace('.', '/'), null, internal(Object.class), new String[] {internal(Runnable.class)}); - + + clsScript.visit(Opcodes.V1_6, Opcodes.ACC_PUBLIC, script.getClassName().replace('.', '/'), null, internal(Object.class), new String[] { internal(Runnable.class) }); + for (Map.Entry function : script.getFunctions().entrySet()) { ParsedFunction fn = function.getValue(); - + String signature = fn.getSignature(); MethodOutput methodOutput = new MethodOutput(clsScript, Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, function.getKey(), signature, null, null); EnvironmentMethod methodEnvironment = new EnvironmentMethod(methodOutput, environmentScript); @@ -101,14 +101,14 @@ public class ZenModule { if (statements[statements.length - 1] instanceof StatementReturn) { if (((StatementReturn) statements[statements.length - 1]).getExpression() != null) { fn.getReturnType() - .defaultValue(fn.getPosition()) - .compile(true, methodEnvironment); + .defaultValue(fn.getPosition()) + .compile(true, methodEnvironment); methodOutput.returnType(fn.getReturnType().toASMType()); } } else { fn.getReturnType() - .defaultValue(fn.getPosition()) - .compile(true, methodEnvironment); + .defaultValue(fn.getPosition()) + .compile(true, methodEnvironment); methodOutput.returnType(fn.getReturnType().toASMType()); } } @@ -118,25 +118,25 @@ public class ZenModule { if (script.getStatements().size() > 0) { MethodOutput scriptOutput = new MethodOutput(clsScript, Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, "__script__", "()V", null, null); IEnvironmentMethod functionMethod = new EnvironmentMethod(scriptOutput, environmentScript); - //scriptOutput.enableDebug(); + // scriptOutput.enableDebug(); scriptOutput.start(); for (Statement statement : script.getStatements()) { statement.compile(functionMethod); } scriptOutput.ret(); scriptOutput.end(); - + mainRun.invokeStatic(script.getClassName().replace('.', '/'), "__script__", "()V"); } - + clsScript.visitEnd(); environmentGlobal.putClass(script.getClassName(), clsScript.toByteArray()); } - + mainRun.ret(); mainRun.end(); clsMain.visitEnd(); - + MethodVisitor constructor = clsMain.visitMethod(Opcodes.ACC_PUBLIC, "", "()V", null, null); constructor.visitCode(); constructor.visitVarInsn(Opcodes.ALOAD, 0); @@ -144,7 +144,7 @@ public class ZenModule { constructor.visitInsn(Opcodes.RETURN); constructor.visitMaxs(0, 0); constructor.visitEnd(); - + // debug: output classes if (debug) { try { @@ -153,11 +153,11 @@ public class ZenModule { for (String className : environmentGlobal.getClassNames()) { File outputFile = new File(outputDir, className.replace('.', '/') + ".class"); - + if (!outputFile.getParentFile().exists()) { outputFile.getParentFile().mkdirs(); } - + FileOutputStream output = new FileOutputStream(outputFile); output.write(environmentGlobal.getClass(className)); output.close(); @@ -166,10 +166,10 @@ public class ZenModule { ex.printStackTrace(); } } - + environmentGlobal.putClass("__ZenMain__", clsMain.toByteArray()); } - + /** * Compiles a single script file. * @@ -186,26 +186,26 @@ public class ZenModule { environment, classes, nameGen - ); - + ); + String filename = single.getName(); String className = extractClassName(filename); - + FileInputStream input = new FileInputStream(single); Reader reader = new InputStreamReader(new BufferedInputStream(input)); ZenTokener parser = new ZenTokener(reader, environment); ZenParsedFile file = new ZenParsedFile(filename, className, parser, environmentGlobal); reader.close(); - + List files = new ArrayList(); files.add(file); - + compileScripts(filename, files, environmentGlobal, false); - + // debug: output classes File outputDir = new File("generated"); outputDir.mkdir(); - + for (Map.Entry entry : classes.entrySet()) { File outputFile = new File(outputDir, entry.getKey().replace('.', '/') + ".class"); if (!outputFile.getParentFile().exists()) { @@ -215,10 +215,10 @@ public class ZenModule { output.write(entry.getValue()); output.close(); } - + return new ZenModule(classes, baseClassLoader); } - + /** * Compiles a zip file as module. All containing files (inside the given * subdirectory) will be compiled. @@ -240,19 +240,19 @@ public class ZenModule { environment, classes, nameGen - ); - + ); + List files = new ArrayList(); - + ZipFile zipFile = new ZipFile(file); Enumeration entries = zipFile.entries(); while (entries.hasMoreElements()) { ZipEntry entry = entries.nextElement(); - + if (entry.getName().startsWith(subdir) && !entry.getName().equals(subdir)) { String filename = entry.getName().substring(subdir.length()); String className = extractClassName(filename); - + Reader reader = new InputStreamReader(new BufferedInputStream(zipFile.getInputStream(entry))); ZenTokener parser = new ZenTokener(reader, environment); ZenParsedFile pfile = new ZenParsedFile(filename, className, parser, environmentGlobal); @@ -260,30 +260,30 @@ public class ZenModule { reader.close(); } } - + String filename = file.getName(); compileScripts(filename, files, environmentGlobal, true); - + return new ZenModule(classes, baseClassLoader); } - + private final Map classes; private final MyClassLoader classLoader; - + /** * Constructs a module for the given set of classes. Mostly intended for * internal use. * - * @param classes + * @param classes */ public ZenModule(Map classes, ClassLoader baseClassLoader) { this.classes = classes; classLoader = new MyClassLoader(baseClassLoader); } - + /** - * Retrieves the main runnable. Running this runnable will execute the content - * of the given module. + * Retrieves the main runnable. Running this runnable will execute the + * content of the given module. * * @return main runnable */ @@ -298,11 +298,11 @@ public class ZenModule { return null; } } - + // ###################### // ### Static methods ### // ###################### - + /** * Converts a filename into a class name. * @@ -311,11 +311,12 @@ public class ZenModule { */ public static String extractClassName(String filename) { filename = filename.replace('\\', '/'); - if (filename.startsWith("/")) filename = filename.substring(1); - + if (filename.startsWith("/")) + filename = filename.substring(1); + int lastSlash = filename.lastIndexOf('/'); int lastDot = filename.lastIndexOf('.'); - + if (lastDot > lastSlash) { filename = filename.substring(0, lastDot); } @@ -327,11 +328,11 @@ public class ZenModule { return filename.substring(0, 1).toUpperCase() + filename.substring(1); } } - + // ############################# // ### Private inner classes ### // ############################# - + /** * Custom class loader. Loads classes from this module. */ @@ -339,13 +340,13 @@ public class ZenModule { private MyClassLoader(ClassLoader baseClassLoader) { super(baseClassLoader); } - + @Override public Class findClass(String name) throws ClassNotFoundException { if (classes.containsKey(name)) { return defineClass(name, classes.get(name), 0, classes.get(name).length); } - + return super.findClass(name); } } diff --git a/ZenScript/src/main/java/stanhebben/zenscript/compiler/TypeRegistry.java b/ZenScript/src/main/java/stanhebben/zenscript/compiler/TypeRegistry.java index 5cc60cd..02a7c8e 100644 --- a/ZenScript/src/main/java/stanhebben/zenscript/compiler/TypeRegistry.java +++ b/ZenScript/src/main/java/stanhebben/zenscript/compiler/TypeRegistry.java @@ -41,10 +41,10 @@ import stanhebben.zenscript.value.IAny; */ public class TypeRegistry implements ITypeRegistry { private final Map types; - + public TypeRegistry() { types = new HashMap(); - + types.put(boolean.class, ZenType.BOOL); types.put(byte.class, ZenTypeByte.INSTANCE); types.put(short.class, ZenTypeShort.INSTANCE); @@ -53,7 +53,7 @@ public class TypeRegistry implements ITypeRegistry { types.put(float.class, ZenTypeFloat.INSTANCE); types.put(double.class, ZenTypeDouble.INSTANCE); types.put(void.class, ZenTypeVoid.INSTANCE); - + types.put(Boolean.class, ZenTypeBoolObject.INSTANCE); types.put(Byte.class, ZenTypeByteObject.INSTANCE); types.put(Short.class, ZenTypeShortObject.INSTANCE); @@ -61,13 +61,13 @@ public class TypeRegistry implements ITypeRegistry { types.put(Long.class, ZenTypeLongObject.INSTANCE); types.put(Float.class, ZenTypeFloatObject.INSTANCE); types.put(Double.class, ZenTypeDoubleObject.INSTANCE); - + types.put(IAny.class, ZenTypeAny.INSTANCE); - + types.put(String.class, ZenTypeString.INSTANCE); types.put(List.class, new ZenTypeArrayBasic(ZenTypeAny.INSTANCE)); } - + public ZenType getClassType(Class cls) { if (types.containsKey(cls)) { return types.get(cls); @@ -82,7 +82,7 @@ public class TypeRegistry implements ITypeRegistry { return result; } } - + @Override public ZenType getType(Type type) { if (type instanceof ParameterizedType) { @@ -107,22 +107,22 @@ public class TypeRegistry implements ITypeRegistry { return null; } } - + private ZenType getListType(ParameterizedType type) { if (type.getRawType() == List.class) { return new ZenTypeArrayList(getType(type.getActualTypeArguments()[0])); } - + return null; } - + private ZenType getMapType(ParameterizedType type) { if (type.getRawType() == Map.class) { return new ZenTypeAssociative( getType(type.getActualTypeArguments()[1]), getType(type.getActualTypeArguments()[0])); } - + return null; } } diff --git a/ZenScript/src/main/java/stanhebben/zenscript/statements/StatementExpression.java b/ZenScript/src/main/java/stanhebben/zenscript/statements/StatementExpression.java index 4ab8bee..7fd445a 100644 --- a/ZenScript/src/main/java/stanhebben/zenscript/statements/StatementExpression.java +++ b/ZenScript/src/main/java/stanhebben/zenscript/statements/StatementExpression.java @@ -6,10 +6,10 @@ import stanhebben.zenscript.util.ZenPosition; public class StatementExpression extends Statement { private final ParsedExpression expression; - + public StatementExpression(ZenPosition position, ParsedExpression expression) { super(position); - + this.expression = expression; } @@ -17,7 +17,7 @@ public class StatementExpression extends Statement { public void compile(IEnvironmentMethod environment) { environment.getOutput().position(getPosition()); expression.compile(environment, null) - .eval(environment) - .compile(false, environment); + .eval(environment) + .compile(false, environment); } } diff --git a/ZenScript/src/main/java/stanhebben/zenscript/type/natives/IJavaMethod.java b/ZenScript/src/main/java/stanhebben/zenscript/type/natives/IJavaMethod.java index 5fe0fff..a7a3dfb 100644 --- a/ZenScript/src/main/java/stanhebben/zenscript/type/natives/IJavaMethod.java +++ b/ZenScript/src/main/java/stanhebben/zenscript/type/natives/IJavaMethod.java @@ -17,20 +17,20 @@ import stanhebben.zenscript.util.MethodOutput; */ public interface IJavaMethod { public boolean isStatic(); - + public boolean accepts(int numArguments); - + public boolean accepts(IEnvironmentGlobal environment, Expression... arguments); - + public int getPriority(IEnvironmentGlobal environment, Expression... arguments); - + public void invokeVirtual(MethodOutput output); - + public void invokeStatic(MethodOutput output); - + public ZenType[] getParameterTypes(); - + public ZenType getReturnType(); - + public boolean isVarargs(); } diff --git a/ZenScript/src/main/java/stanhebben/zenscript/type/natives/ZenNativeMember.java b/ZenScript/src/main/java/stanhebben/zenscript/type/natives/ZenNativeMember.java index fcc7b56..baab678 100644 --- a/ZenScript/src/main/java/stanhebben/zenscript/type/natives/ZenNativeMember.java +++ b/ZenScript/src/main/java/stanhebben/zenscript/type/natives/ZenNativeMember.java @@ -28,15 +28,15 @@ public class ZenNativeMember { private IJavaMethod getter; private IJavaMethod setter; private final List methods = new ArrayList(); - + public IJavaMethod getGetter() { return getter; } - + public IJavaMethod getSetter() { return setter; } - + public void setGetter(IJavaMethod getter) { if (this.getter == null) { this.getter = getter; @@ -44,7 +44,7 @@ public class ZenNativeMember { throw new RuntimeException("already has a getter"); } } - + public void setSetter(IJavaMethod setter) { if (this.setter == null) { this.setter = setter; @@ -60,20 +60,20 @@ public class ZenNativeMember { public IPartialExpression instance(ZenPosition position, IEnvironmentGlobal environment) { return new StaticGetValue(position); } - + public void addMethod(JavaMethod method) { methods.add(method); } - + private class InstanceGetValue implements IPartialExpression { private final ZenPosition position; private final IPartialExpression value; - + public InstanceGetValue(ZenPosition position, IPartialExpression value) { this.position = position; this.value = value; } - + @Override public Expression eval(IEnvironmentGlobal environment) { return new ExpressionCallVirtual(position, environment, getter, value.eval(environment)); @@ -99,17 +99,17 @@ public class ZenNativeMember { return new ExpressionCallVirtual(position, environment, method, value.eval(environment), values); } } - + @Override public ZenType[] predictCallTypes(int numArguments) { return JavaMethod.predict(methods, numArguments); } - + @Override public IZenSymbol toSymbol() { return null; } - + @Override public ZenType getType() { return getter.getReturnType(); @@ -121,14 +121,14 @@ public class ZenNativeMember { return ZenType.ANY; } } - + private class StaticGetValue implements IPartialExpression { private final ZenPosition position; - + public StaticGetValue(ZenPosition position) { this.position = position; } - + @Override public Expression eval(IEnvironmentGlobal environment) { return new ExpressionCallStatic(position, environment, setter); @@ -154,7 +154,7 @@ public class ZenNativeMember { return new ExpressionCallStatic(position, environment, method, values); } } - + @Override public ZenType[] predictCallTypes(int numArguments) { return JavaMethod.predict(methods, numArguments); @@ -164,7 +164,7 @@ public class ZenNativeMember { public IZenSymbol toSymbol() { return new StaticSymbol(); } - + @Override public ZenType getType() { return getter.getReturnType(); @@ -176,7 +176,7 @@ public class ZenNativeMember { return ZenType.ANY; } } - + private class StaticSymbol implements IZenSymbol { @Override public IPartialExpression instance(ZenPosition position) {