Minecart Engine

Discussion in 'Plugin Development' started by ClaudeSpeedIII, Sep 13, 2012.

Thread Status:
Not open for further replies.
  1. Offline



    Hi guys, my name is Pedro Lucas, as i said in my profile, my english is not very good, so i ask to the grammar nazis take it easy

    As you know, in vanilla minecraft the minecart with furnace is buggy, and you can't couple minecarts, with traincarts is little better but the minecart-with-furnace can only push the train...

    Anyway, i like roleplay, so a few months ago with my poor java knowedge (it is my first project i had used OO), i worked in this plugin, during 1 month extacly, then the entusiasm has gone (my first big OO project, it simply does not have documentation, javadoc, comments, the variables do not have default, i hate this code, i will start a new one (or refactor the existing))

    Anyway, below i will talk about the plugin, what it does and etc.

    It is a complementary plugin to bergerkiller's traincarts, called Minecart Engine, in this thread i pretend to talk about this plugin and ask for help relative to this (and i will, in the future, this post is for a introduction)

    In the state it reached to work, you create a locomotive coupling various minecarts

    example: [normal] + [ furnace ] + [ chest ] + [ furnace ] + [normal]


    you enter in one of the heads of the locomotive (the [normal]) and run the command "/loco create diesel" (the alias for diesel is lava and coal, cause is the fuel inserted in the chest, diesel is for the user see the relationship with the real life) and the locomotive is created, it will print in the console the number of slots for fuel of the created loco, and the power (in HP) of same, where each furnace-minecart has 500hp of power.

    In the final version you will couple this locomotive with the stuff you want to pull (chest minecarts and minecarts), and will have a command to uncouple, but in this version it is not coded (yet)

    Optionaly, you can use electric locomotive, you don't need the chest cause the energy will come from the catenary/overhead line

    The command is "/loco create electric [voltage]"
    The part of the overhead lines and the voltage stuff is not working (yet too), but the idea is that the higher the voltage, the greater can be the distance between a substation and other...

    Ah, i had started to code the substations too: "/substation create [name] [voltage] [power capacity (in hp)]"


    To create a substation you will need: torch, lever and a iron block, run the command, place a torch to create the transformer, place the iron block anywhere (the substation don't have any relationship with the overhead lines... yet) and place a lever in a wall, you will see a nether-fence transformer, a lever with a wool to indicate the state and a useless iron block.

    The useful part is not coded yet but the fun part this:
    Start the transformer pushing the lever (the wool will be green), then try to destroy the transformer... MUAHMUAHMUAHMAUH...

    Try to destroy only the lever too, with it turned on (obviously).

    In the future i will codify to when the substation is overloaded it will tiles around (overheat), later will simply explode, or something like this.

    Other thing: the electric locomotive have a efficiency algorithm , if you have two [engines], 1000hp will be the power in the axle, 500 in each minecart. BUT the consumption (what it will get from the substation) will be a bit more then it (i dont remember how the algorithm works but i know it has)


    And i almost forgot: the panel, the last thing i had codified before i stop to work in this code.


    I used the map api of bukkit to draw a panel to the locomotive, it show the formation in a "LCD display" and the speed in a led display.

    Anyway, here a short tutorial:

    Create a train with max of 5 minecarts, and min of 3, the heads must be normal minecarts, if is a electric train, the chest minecart is not needed, if not, you will need a chest minecart, whatever type be the train, you must place a furnace minecart.

    If you don't understand, use this formation:
    [normal] + [ furnace ] + [ chest ] + [normal]

    enter in the head of the locomotive, run
    /loco create <type> [voltage]

    when type can be diesel or electric, and voltage is only needed if electric

    in the formation i had passed above, use /loco create diesel

    now get a map, get off the train and enter again, you will see the panel... turned off

    to turn on, run:
    /control start

    it will turn on the low voltage system, which include the panel

    now you see the panel with the led showing you incredible velocity of 0 something per hour (if you is not in a slope) and a LCD display showing the pressure of the air in the tank (you need this to stop)


    Time to start the high voltage systems, in a diesel train, run:
    /control engine

    in a electric train, run:
    /control panto


    If you already played before BVE, Microsoft Train Simulator or other of these boring games, you must know that you have two levers at least, one for the direction: the commands are:

    /df - direction forward
    /dn - direction neutral
    /db - direction backward

    So, first you set the first lever to go forward: run /df

    Then, you have the velocity and brake lever:
    /p4 - Full power
    /p3 - Almost full power
    /p2 - A bit more fast then a turtle
    /p1 - A turtle
    /neutral - Don't use it, is buggy, will stop the train very fast
    /b1 - A bit of brake
    /b2 - A bit more of brake
    /b3 - Almost full brake
    /b4 - Full brake


    Wow, and see the compressor running to charge the air tank: alternate beetwen /b4 and /neutral (you will hear a lava sound, pretend it is the air escaping), when the panel displays 30 PSI, the compressor will start, enjoy it

    That's all, folks

    I tested it today in this release of craftbukkit:

    With this release of Traincarts:

    And obvsiously, with Minecraft 1.2.5

    Here my plugin (.jar):
    <Edit by Moderator: Redacted mediafire url>

    Here the source of my plugin (You will not understand, variables/classes in portuguese and etc):
    <Edit by Moderator: Redacted mediafire url>
    Last edited by a moderator: Nov 9, 2016
    Timr, Icyene, devilquak and 1 other person like this.
  2. Offline


    Wow, that is impressive. You should put it on BukkitDev.
    kroltan, devilquak and hawkfalcon like this.
  3. Offline


    If you don't like the code, why don't you just re-write it? Now that you have all the knowledge, and you know exactly what to do, you can write code that does the same thing in 1/1000 of the time!
  4. Offline


    This looks amazing, man, great job. Even if you think it's coded badly, it doesn't matter at all unless (it impacts performance, but still, whatever) since no one looks at the code when they're actually playing the game. I agree with Icyene, do the world a favor and upload it to BukkitDev.
  5. Offline


    Ok, i will put it into the BukkitDev (i am creating the account now)

    But the code have some problems, and is not cause it is ugly, with bad variable names and etc: it i fix with the "rename" of eclipse ;)

    And the comments, I can add now, if I want (not now, i have work tomorow, but... some day)

    The problem is logical: performance related, here come a example in pseudo-code:

    when you put /b4 the train will slow down until stops, bergerkiller wrote a method called "setVelocity(double)" or something like that, the problem is: the train will have the velocity setted to the value passed, then the natural forces of minecraft world will back to actuate in the train.

    My solution?

    To slow down

    while(speed > 0) {
      speed = factor % of speed;
    It run in a separated thread

    When speed is close to 0, it will "push the park brake"

    Brake extends Thread {
        boolean runBrake = true;
        Location positionToStop = null;
        Brake(positionToStop) {
            this.positionToStop = positionToStop;
        public static releaseBrake() {
            this.runBrake = false;
        run() { //You know? The run of the Thread class
            for(int i = 0; i &lt;= train_composition.length; i++) {
                this.sleep(100); //I always put the thread to sleep by a while to my plugin don't eat all the CPU
    I look to this and think it is irational, imagine that my car needs resources to stay in his place, to stay stoped? Is ridiculous...

    MUST BE other way of lock the minecarts, it is one of my doubts, the principal, maybe

    Hey folks, i am snooping in the BukkitDev and i see various plugins of light, with a date of release very recent, then appeared to doubt: now is possible to control the light in the client side on the server side? (again :cool: )

    In the code i had make, i had thought "wow, i am sure that have a way of making light via bukkit", so i left ready some variables in the class Locomotiva (locomotive), something like "boolean farol" (headlight) and etc.

    The original idea is to have headlights in two levels (like in the car, i don't know how it calls in english culture, in brazil we call "Farol alto" and "farol baixo", what in a literal translations will be: "high headlight" and "low headlight") in the locomotive and travel lights in the passenger cars. Then have one command to turn on and off the HEP (Head End Power, the energy line generated or transformed in the locomotive, avaiable to the rest of the train use), and a passenger car with the HEP avaiable can turn on and off the light or use in board entertainment systems or whatever.

    Until i discover that the developers of minecraft had moved the light processing per complete to the client-side...

    This weekend i hope to play with this code. Starting by let it work with the trunk

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: May 28, 2016
  6. Offline


    This is amazing. I love the idea. Even if the code is bad. If you want you can write it again. I always find it easer to write it again. And it takes little time.
  7. Offline


    I think i will refactor the code, since the logic are ready (and i think, in the best way) in the most parts of the plugin. anyway, today i have snooped in the code for try making it work in the current release (1.3.2), and.... IS WORKING :cool:

    Months been passed, is hard to understand at first seem, but after some time, you see the logic without needing comments or javadoc...

    If you want to test my pre alpha plugin, you only will need
    this version of CraftBukkit: CB 1.3.2-R0.1
    and this version of TrainCarts: V1.71.5

    and obviously, the "MinecartEngine"

    if you want to try to understand my code, here the source

    Attached Files:

  8. Offline


    Hey folks, check out my BukkitDev page: http://dev.bukkit.org/server-mods/minecart-engine/

    I think I will rewrite the entire code, and at the same time I will codify the headlight of the train on the atual code based on the code of ChessCraft, i need to learn how to use the EnumSkyBlock to set a light level.
    desht likes this.
  9. Offline


    Good luck - love the plugin idea! One thing to bear in mind is that ChessCraft lights static boards, which will be a little easier than applying a lighted area around a moving train - continually relighting the ground around the vehicle could prove heavy on CPU. But you never know, it could turn out to be workable :)
  10. Offline


    Good point, but still that the CPU use turn it impraticable, i will have at least learned how to set light level in a region :D

    I already understand the use of the b method (good name for a method #NOT) to set the light level, but it really SET the light level.

    When the train is passing it is what I want, but when the train has already passed, I need to make the client and server calculate the light how it makes naturally

    Maybe in the "World" class that I had passed above, have a method that makes it, but it seems to be get from one of this reverse enginering software, don't have documentation, comments or at minimum a decent variable/method name.

    Anyone here know how to do it?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: May 28, 2016
  11. Offline


    ClaudeSpeedIII what you'll probably need to do is save the previous lighting level for each block and then restore it when the train's passed - which is why I suggested that it could get CPU-heavy :) Block lighting manipulation is not well-documented or easy to manage, especially on the server side...
  12. Offline


    i get error :((( "An internal error occurred while attempting to perform this command"
Thread Status:
Not open for further replies.

Share This Page