Jump to content

MarcinS

Members
  • Posts

    17
  • Joined

  • Last visited

Converted

  • Gender
    Undisclosed
  • Personal Text
    I am new!

MarcinS's Achievements

Tree Puncher

Tree Puncher (2/8)

1

Reputation

  1. As for conformance with ECMAScript, I've run the examples for Wikipedia page, and they get the results that are required for it. I do not intend to have full ECMAScript conformance, as I see little to no value in doing that. As an example, why have more than one way of defining an object? Anyway, here are the tests I've written that give the expected results: @Test public void recursiveFunctionCall() throws IllegalSyntaxException, IOException, ExecutionException { final Variable variable = executeScript("function factorial(n) { if (n == 0) { return 1; } return n * factorial(n - 1); } return factorial(3);"); assertEquals(6, ((Number) variable.getValue()).intValue()); } @Test public void recursiveFunctionCall2() throws IllegalSyntaxException, IOException, ExecutionException { final Variable variable = executeScript("var factorial = function(n) { if (n == 0) { return 1; } return n * factorial(n - 1); }; return factorial(3);"); assertEquals(6, ((Number) variable.getValue()).intValue()); } @Test public void testClosure() throws IllegalSyntaxException, IOException, ExecutionException { final Variable variable = executeScript("var displayClosure = function() { var count = 0; return function () { return ++count; }; };" +" var inc = displayClosure(); return \"\"+inc()+\" \"+inc()+\" \"+inc();"); assertEquals("1.0 2.0 3.0", variable.getValue()); } @Test public void anonymousFunction() throws IllegalSyntaxException, IOException, ExecutionException { final Variable variable = executeScript("var v; v = 1; var getValue = (function(v) { return function() {return v;}; }(v)); v = 2; return getValue();"); assertEquals(1, ((Number) variable.getValue()).intValue()); }
  2. Running a "busy waiting" thread (in case of badly written program) on a lower-priority does not prevent thread starvation (on main Minecraft thread), therefore I think it's a mistake to run a program on a separate thread. It only introduces complexity and potential for thread-safety issues when done wrong. If an implementation does not offer me complete control over scheduling it's a "no go" for me. Thank you for your comments, but for the time being I will stick with what I have.
  3. It's not really a custom language, as it's basically a JavaScript, by "stricter version" I mean - I enforce definition of variables (with "var") before the variable can be accessed, which allows me to detect any problems during parsing - editing the program and quickly highlight the problem. If need be, I can turn off that check. Having one thread per each running program is also a scaling issue (ignore this comment if you mean having one thread for all the programs). With potentially hundreds of computers running programs in game, this poses a threat of exhausting Java resources by the mere volume of threads. However, I do not understand your approach. What gain would that be, having interpreter on a separate thread, if it always has to run in sync with world ticks. Please keep in mind, that AFAIK Minecraft is not thread-safe and utilizes single-thread model when operating on World, therefore you shouldn't access, both read and/or write, it's data from any other thread than the main thread itself.
  4. Actually I already implemented JavaScript syntax (a bit stricter version of it). Also, I'm not sure if I would be able to use any existing language implementations, as these probably do not offer too much of a control over how many operations are executed in one go, and if a "busy wait" was done in a program, might introduce the same problem ComputerCraft has with world freezing. I should have an alpha version in about 2 weeks, just need to figure out, what kind of options I want to give for the Redstone module, write and test it.
  5. I have started and am at a quite advanced state of working on an "Automation" mod. This mod introduces computers and programming to your world of Minecraft. Mod is currently in pre-alpha stage and soon I will add an alpha download to allow testing. Why did I start working on this mod? Being computer programmer myself, I was very excited when I saw Guude use ComputerCraft in his series. I've decided to start using turtles, when playing on my old laptop (single-player mode), but after starting just one turtle with "excavate", the frame rate dropped to 1-2, so I had to quickly abandon this idea. I've decided to help fix the problems ComputerCraft has. Unfortunately, due to the fact that it is not open-source, I was unable to provide input to it. Also, I'm afraid that a lot of issues it has, are a result of some architectural choices made early during the project, and cannot be fixed without major changes. Therefore, I've decided to write my own mod. Goals for this mod: - be open-source - I can't understand non-commercial software being any other way, - badly written programs should not cause a deadly lag (everything stops for couple of seconds) of the server/world, - mod should work comfortably on servers with many users (i.e. public), and should not be just limited to private/white-listed servers, - mod should not allow for dead-locks or server crashes (quite obvious), - running computer programs should not start and run in new threads, as this consumes a lot of server resources and does not scale well above hundred computers running programs on a server, - writing/editing a program should be user friendly and not impacted by client-server communication speed, - syntax checking and error finding during program editing is a must, to avoid spending hours trying to find a typo in code after trying to run the program, - if possible, mod should use a popular widely-known computer language, - built-in objects should be extendable to allow adding new functions in new versions, - mod should gracefully handle multiple players using the same computer at the same time, - provide easy to use configuration and monitoring tools for server owners, to allow throttling of computer speed for players running many computers and other throttling and configuration options, - provide an easy to use public API for adding new computer modules (see below). Mod description: Mod introduces several levels of computers, starting with a simple computer with limited capabilities, going up to "super-computer" class. The more advanced the computer is, the faster it runs, can house more modules, allows for larger program memory usage, etc. Each computer has 1-5 (not finalized yet) slots for modules. Modules (items) are added to a computer via inventory interface of the computer. These add capabilities to the computer, as a computer without modules cannot really interact with the world. There will be several modules released with the core Automation mod (list not yet finalized): - Location - module that allows the program to query the computer's location and which side it faces, - Storage - module that allows to store items in the computer, as well as interacting with adjacent inventories, - Mobility - module that allows the computer to change its location and facing (move in the world), - Harvest - module that allows to harvest blocks in the vicinity of the computer, - Redstone - module that allows to measure received and emit redstone signal. In addition to modules, one extra item will be added to the game - Terminal. This item allows to connect to the computer, by right-clicking on it while holding Terminal in hand, to start a new computer session. What's left to do: - textures and icons, - Mobility module testing, - Harvest and Redstone modules - code and testing, - configuration and monitoring tools to allow throttling; throttling part is actually very easy to do as mod was designed with this in mind, - loads of testing by others. Future plans: 1. Requirement for computers to consume energy (duh!). I would like to make the mod compatible with both Buildcraft and IC2 energy, and which one will be used, will be based on mod configuration and the other mod (BC, IC2) presence. 2. Computer user access, inter-computer communication security - this opens a nice field for extra-layer of game-play, where players can attempt to hack each other systems, if they manage to find a security whole in someone's program. 3. Peripherals and connecting/communicating with them using a cable, or if possible - using existing networks (for example glass-fibre cable from IC2).
  6. Can you give me an URL, where I can find some kind of Bugzilla for FML? I already was given the GitHub address for Forge, so I'm sorted on that front. Thank you in advance!
  7. Can you give me an URL, where I can find some kind of Bugzilla for FML? I already was given the GitHub address for Forge, so I'm sorted on that front. Thank you in advance!
  8. In the following method in GameRegistry class, in the second attempt at getting a constructor with signature of (int, Block), due to the imports in this class, the Block refers to cpw.mods.fml.common.Mod.Block annotation (class) rather than the intended net.minecraft.block.Block. To remedy the problem, a fully qualified class (with package) should be used in the code, the same it is used in signature of the method itself for first parameter. public static void registerBlock(net.minecraft.block.Block block, Class<? extends ItemBlock> itemclass, String name, String modId) { if (Loader.instance().isInState(LoaderState.CONSTRUCTING)) { FMLLog.warning("The mod %s is attempting to register a block whilst it it being constructed. This is bad modding practice - please use a proper mod lifecycle event.", Loader.instance().activeModContainer()); } try { assert block != null : "registerBlock: block cannot be null"; assert itemclass != null : "registerBlock: itemclass cannot be null"; int blockItemId = block.field_71990_ca - 256; Constructor<? extends ItemBlock> itemCtor; Item i; try { itemCtor = itemclass.getConstructor(int.class); i = itemCtor.newInstance(blockItemId); } catch (NoSuchMethodException e) { itemCtor = itemclass.getConstructor(int.class, Block.class); i = itemCtor.newInstance(blockItemId, block); } GameRegistry.registerItem(i,name, modId); } catch (Exception e) { FMLLog.log(Level.SEVERE, e, "Caught an exception during block registration"); throw new LoaderException(e); } blockRegistry.put(Loader.instance().activeModContainer(), (BlockProxy) block); }
  9. In the following method in GameRegistry class, in the second attempt at getting a constructor with signature of (int, Block), due to the imports in this class, the Block refers to cpw.mods.fml.common.Mod.Block annotation (class) rather than the intended net.minecraft.block.Block. To remedy the problem, a fully qualified class (with package) should be used in the code, the same it is used in signature of the method itself for first parameter. public static void registerBlock(net.minecraft.block.Block block, Class<? extends ItemBlock> itemclass, String name, String modId) { if (Loader.instance().isInState(LoaderState.CONSTRUCTING)) { FMLLog.warning("The mod %s is attempting to register a block whilst it it being constructed. This is bad modding practice - please use a proper mod lifecycle event.", Loader.instance().activeModContainer()); } try { assert block != null : "registerBlock: block cannot be null"; assert itemclass != null : "registerBlock: itemclass cannot be null"; int blockItemId = block.field_71990_ca - 256; Constructor<? extends ItemBlock> itemCtor; Item i; try { itemCtor = itemclass.getConstructor(int.class); i = itemCtor.newInstance(blockItemId); } catch (NoSuchMethodException e) { itemCtor = itemclass.getConstructor(int.class, Block.class); i = itemCtor.newInstance(blockItemId, block); } GameRegistry.registerItem(i,name, modId); } catch (Exception e) { FMLLog.log(Level.SEVERE, e, "Caught an exception during block registration"); throw new LoaderException(e); } blockRegistry.put(Loader.instance().activeModContainer(), (BlockProxy) block); }
  10. @SideOnly(CLIENT) public static boolean isGUIOpen(Class<? extends GuiScreen> gui) { return FMLClientHandler.instance().getClient().currentScreen != null && FMLClientHandler.instance().getClient().currentScreen.equals(gui); } This code copmpares an instance of class GuiScreen to class extending GuiScreen, which will always be false. Here is how the code should be: @SideOnly(CLIENT) public static boolean isGUIOpen(Class<? extends GuiScreen> gui) { return FMLClientHandler.instance().getClient().currentScreen != null && FMLClientHandler.instance().getClient().currentScreen.getClass().equals(gui); }
  11. @SideOnly(CLIENT) public static boolean isGUIOpen(Class<? extends GuiScreen> gui) { return FMLClientHandler.instance().getClient().currentScreen != null && FMLClientHandler.instance().getClient().currentScreen.equals(gui); } This code copmpares an instance of class GuiScreen to class extending GuiScreen, which will always be false. Here is how the code should be: @SideOnly(CLIENT) public static boolean isGUIOpen(Class<? extends GuiScreen> gui) { return FMLClientHandler.instance().getClient().currentScreen != null && FMLClientHandler.instance().getClient().currentScreen.getClass().equals(gui); }
  12. Just a quick question: How to access an open gui on client, from a context of packet handler? What I try to achieve: Server sends a custom packet to client to update the gui screen with some data. On client I receive this packet and want to do, whatever server has asked to do. What I tried already: I've been looking at the existing sources, however the built-in packet handlers have access to Minecraft instance, while this instance is not passed in any way to the packet handler instantiated by Forge. The EntityPlayerSP class has Minecraft instance, however it's protected and not exposed by any methods of the class. Is there any way I can access the Minecraft instance from packet handler context?
  13. Just a quick question: How to access an open gui on client, from a context of packet handler? What I try to achieve: Server sends a custom packet to client to update the gui screen with some data. On client I receive this packet and want to do, whatever server has asked to do. What I tried already: I've been looking at the existing sources, however the built-in packet handlers have access to Minecraft instance, while this instance is not passed in any way to the packet handler instantiated by Forge. The EntityPlayerSP class has Minecraft instance, however it's protected and not exposed by any methods of the class. Is there any way I can access the Minecraft instance from packet handler context?
  14. I had similar issue in the past, and it was caused by one of the mods misbehaving. You have two choices: - figure out which mod is misbehaving and just remove it, - make a thread dump from Java (if you know how) and see where is it getting stuck. To figure out, which mod is misbehaving, remove half of the mods, try creating a world, if it works, the misbehaving one is in the removed ones, if it doesn't, it's in the ones still in, keep halving the number of mods added/removed to pinpoint the mod that doesn't work.
  15. I guess in the server PacketHandler I'll make a call to a static method in my main Mod class getServerProxy() which will check if the static proxy injected by Forge is instanceof the Server Proxy I want to use, and if not, just create and store an instance of it. That way, on the real server, it will be injected by the Forge, on the single-player mode "server" it will be lazily created by this method, and all the calls that are done specifically on the server side, will use that method to get the proxy they require. Thanks!
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.