Jump to content

[1.5.1][WIP] Automation mod - computers


Recommended Posts

Posted

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).

  • 2 weeks later...
Posted

I'm kind of interested in this for a certain project of mine. I propose Python for the programming language.

Reasoning: easy to learn, has a native Java implementation (Jython), great Java interoperability, lots of standard library features, it's not Lua.

Posted

I'm kind of interested in this for a certain project of mine. I propose Python for the programming language.

Reasoning: easy to learn, has a native Java implementation (Jython), great Java interoperability, lots of standard library features, it's not Lua.

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.

Posted

I don't think it's a good idea. A custom language is basically useless outside the mod, and the implementation is quite tricky to get right. Jython shouldn't have the freezing issue, as long as it has at least a thread of its own. ComputerCraft does everything on the main thread and uses Lua coroutines for scheduling, which is a massive hack. I was thinking of a transaction based design for world changes, with the main interpreter running on a different thread, and the game commiting transactions every redstone tick (because no world state can change faster).

Posted

I don't think it's a good idea. A custom language is basically useless outside the mod, and the implementation is quite tricky to get right. Jython shouldn't have the freezing issue, as long as it has at least a thread of its own. ComputerCraft does everything on the main thread and uses Lua coroutines for scheduling, which is a massive hack. I was thinking of a transaction based design for world changes, with the main interpreter running on a different thread, and the game commiting transactions every redstone tick (because no world state can change faster).

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.

Posted

Is your implementation ECMAScript compliant (assuming you turn off that check)? No? Then it's not JavaScript. I wanted to use something like this as an educational tool, and I don't think a subset of JavaScript is good for this use case. As for threading, Jython should be able to handle that with greenlets/coroutines, and if that doesn't cut it, there's always PyPy, which scales way better with implementation-native greenlets. Having it on a separate thread means that we don't have to care about scheduling it, but we can still have it run at lower priority. Synchronization needs testing, but I think a context switch every N ticks should be OK.

 

Edit: you also gave me another reason why an existing language should be easier to work with: tools. You'll want an editor with good syntax highlighting, and maybe even basic refactoring support, and that takes quite a lot of coding. For, say, Python or (compliant) JavaScript, there are lots of already existing open source tools and components that can be integrated into the game.

Posted

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.

Posted

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());
    }

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Im trying to build my mod using shade since i use the luaj library however i keep getting this error Reason: Task ':reobfJar' uses this output of task ':shadowJar' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed. So i try adding reobfJar.dependsOn shadowJar  Could not get unknown property 'reobfJar' for object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler. my gradle file plugins { id 'eclipse' id 'idea' id 'maven-publish' id 'net.minecraftforge.gradle' version '[6.0,6.2)' id 'com.github.johnrengelman.shadow' version '7.1.2' id 'org.spongepowered.mixin' version '0.7.+' } apply plugin: 'net.minecraftforge.gradle' apply plugin: 'org.spongepowered.mixin' apply plugin: 'com.github.johnrengelman.shadow' version = mod_version group = mod_group_id base { archivesName = mod_id } // Mojang ships Java 17 to end users in 1.18+, so your mod should target Java 17. java.toolchain.languageVersion = JavaLanguageVersion.of(17) //jarJar.enable() println "Java: ${System.getProperty 'java.version'}, JVM: ${System.getProperty 'java.vm.version'} (${System.getProperty 'java.vendor'}), Arch: ${System.getProperty 'os.arch'}" minecraft { mappings channel: mapping_channel, version: mapping_version copyIdeResources = true runs { configureEach { workingDirectory project.file('run') property 'forge.logging.markers', 'REGISTRIES' property 'forge.logging.console.level', 'debug' arg "-mixin.config=derp.mixin.json" mods { "${mod_id}" { source sourceSets.main } } } client { // Comma-separated list of namespaces to load gametests from. Empty = all namespaces. property 'forge.enabledGameTestNamespaces', mod_id } server { property 'forge.enabledGameTestNamespaces', mod_id args '--nogui' } gameTestServer { property 'forge.enabledGameTestNamespaces', mod_id } data { workingDirectory project.file('run-data') args '--mod', mod_id, '--all', '--output', file('src/generated/resources/'), '--existing', file('src/main/resources/') } } } sourceSets.main.resources { srcDir 'src/generated/resources' } repositories { flatDir { dirs './libs' } maven { url = "https://jitpack.io" } } configurations { shade implementation.extendsFrom shade } dependencies { minecraft "net.minecraftforge:forge:${minecraft_version}-${forge_version}" implementation 'org.luaj:luaj-jse-3.0.2' implementation fg.deobf("com.github.Virtuoel:Pehkui:${pehkui_version}") annotationProcessor 'org.spongepowered:mixin:0.8.5:processor' minecraftLibrary 'luaj:luaj-jse:3.0.2' shade 'luaj:luaj-jse:3.0.2' } // Example for how to get properties into the manifest for reading at runtime. tasks.named('jar', Jar).configure { manifest { attributes([ 'Specification-Title' : mod_id, 'Specification-Vendor' : mod_authors, 'Specification-Version' : '1', // We are version 1 of ourselves 'Implementation-Title' : project.name, 'Implementation-Version' : project.jar.archiveVersion, 'Implementation-Vendor' : mod_authors, 'Implementation-Timestamp': new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"), "TweakClass" : "org.spongepowered.asm.launch.MixinTweaker", "TweakOrder" : 0, "MixinConfigs" : "derp.mixin.json" ]) } rename 'mixin.refmap.json', 'derp.mixin-refmap.json' } shadowJar { archiveClassifier = '' configurations = [project.configurations.shade] finalizedBy 'reobfShadowJar' } assemble.dependsOn shadowJar reobf { re shadowJar {} } publishing { publications { mavenJava(MavenPublication) { artifact jar } } repositories { maven { url "file://${project.projectDir}/mcmodsrepo" } } }  
    • Todas as versões do Minecraft Forge são repentinamente tela preta, mesmo sem mods (tentei reinstalar o Minecraft original, Java, atualizar os drivers não funciona)
    • When i join minecraft all ok, when i join world all working fine, but when i open indentity menu, i get this The game crashed whilst unexpected error Error: java.lang.NullPointerException: Cannot invoke "top.ribs.scguns.common.Gun$Projectile.getDamage()" because "this.projectile" is null crash report here https://paste.ee/p/0vKaf
  • Topics

×
×
  • Create New...

Important Information

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