More out of MineCart's!

Discussion in 'Archived: Plugin Requests' started by Marius A. Winsjansen, Jul 30, 2011.

  1. Offline

    Tster

    Hmm, I have some nifty functions

    Can you send me the folder(zipped), I'm going to add an extra class or two to it,
    :D

    Whos god isn't him?

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

    bergerkiller

    If you can make it into something even more epic, go ahead. :p
    Note: I'll add the get/setForwardForce functions in the Resources section. Could be useful to calculate the speed an entity is moving.
     
  3. Offline

    Tster

    Yeh, I just need to check out how youve classed it up and from there I can go, can you send me project folder?
     
  4. Offline

    bergerkiller

    <Edit by Moderator: Redacted mediafire url>
    <Edit by Moderator: Redacted mediafire url>
    Uploaded it. Also contains the exported jar file if someone wishes to try it out for themselves.
     
    Last edited by a moderator: Nov 13, 2016
  5. If will try it RIGHT away ;D
     
  6. Offline

    bergerkiller

    Note: it is all pretty simple, I made it in less than 3 hours whatya expect. ;)
    All that this does is generate groups of minecarts and ensures that every member minecart of this group uses the average forwarding force of all their other members.

    EDIT

    Reason why the class is called "MinecartPair":
    I assumed it was possible to have multiple linked pairs that push eachother around. This somewhat worked, but caused some mild disturbance. (not all carts have the same velocity)
     
  7. This works great, no bug so far, i LOVE it!! !:D
     
  8. Offline

    bergerkiller

    Now the tough part: ordering the carts. At this point I have NO idea what the first cart is, the second, etc. It is just a random mess. Time to find some way to order them based on Location, which will be pretty tough. I got weeks time, so I don't mind. :)

    Might "try" to order them in the collision detection scheduler.
     
  9. Yeah that would be awsome whit the collision detection scheduler! I already enjoy the version you postet, and i look forward to see more!

    Thanks for taking my idea to work!:)
     
  10. Offline

    bergerkiller

    Good news: I ordered the carts! It was simpler than I thought: all I had to do is get if the "collided" cart was the first or last cart of a group. Based on that the new cart is pushed in front or in the back of the stack. (I now use an ArrayList instead of a HashSet). I added a message with the cart that was closest to me, and it nicely gave me 0-1-2-3-4-5 when passing by. Now adding a distance check between carts. :)

    First things first: get the "front" of the train. This is either the first or the last cart. I have to obtain this cart based on the direction it is heading, this can be hard. I'll use cart [0] for now.

    EDIT

    Distance is now kept, one downside: when a group hits a cart it stops abruptly. Will have to fix that.

    Ok I fixed pretty much everything, with one simple thing: lining the carts. When one cart has the same z or x location of another cart, the yaw is taken over. This ensures that a positive force means the same for all carts in the group, and prevents a lot of bugs.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 18, 2016
  11. This sound so awsome! I cant w8 to test it out! Let me know when its ready for finely downloading:)
     
  12. Offline

    matthayez011

    now this plugin, is wow, you are amazing!
     
  13. Yeah, i am so happy that some1 took my idea and made it :D
     
  14. Offline

    matthayez011

    now we just need boats to be linkable
    and then it would be just amazing
     
  15. that would ba hard, since the boats in this game sux! they get destroyd whit one touch of annything else! and the massiv boat "train" will probly just destroy everything!:/
     
  16. Offline

    ohtwo

    If this could be used in conjunction with Minecart Mania, that would be great!
     
  17. It will, that was what i asked him to do!:)
     
  18. Offline

    ohtwo

    Haha I'm excited then. I always thought it wasn't possible since I thought every Minecart plugin maker would have thought of this. But since my first day of playing Minecraft, I wanted linkable mine carts.
     
  19. Yeah, this is SO awsome! I have an test version running on my server as we speak, and it works great:)

    You can stack the furnuce and the chest to!

    Your Welcome to join my server and see, it works great:

    46.253.203.229:25865
     
  20. Offline

    bergerkiller

    Still having a hard time getting a fixed distance to work. The uploaded version remains the distance, but any interference will cause permanent distance change. Now got it till the state I can tell when the first cart and when the last cart goes by me and managed to get an array with the first element being the "engine" (first minecart).

    It's hard to prevent the minecarts from "sucking into eachother" or "blowing apart from eachother". But I'll get there. :)

    And yep, thanks Marius. Without your impulse I wouldn't have a project right now...hehe :)
     
  21. No problame, its me that should thank YOU that made this possible! ITs SO awsome :D
    Dont feel like rushing, use your time:)
     
  22. Offline

    bergerkiller

    Well my time investment have paid off. :)
    EVERYTHING is working. Only thing currently bugging me: cart order. If for some reason cart #1 is not the actual cart #1 (cart went through other cart?) there is no way to restore it, since it can't go through the cart in front of him. The collision update prevents that. So now working on a "smart" method that checks if this is happening, and if it is, swap the two bugging carts. Also, groups and members are now successfully cleaned up automatically. You'll see a "member removed" and "group removed" message when this is the case. I will also clean up carts drifting off too far from their max allowed distance.
     
  23. This is just to awsome!

    When i had the idea of this mod, it wasnt even close to what you have done! ITs so awsome, and i really love this!!

    If you have time, go to your "wall" on your profile, i have posted something for you there!:)
     
  24. Offline

    Jaker232

    Rats, he beated me to it.
     
  25. hehe, he was fast and worked hard to day! So hard to beat actualy!:p
     
  26. Offline

    bergerkiller

    End of the day. Result: a few things I have to take care of tomorrow.
    The real problem still is: having the same FORWARD for all minecarts at all times. Currently it sometimes happens that the first cart is swapped with the last cart, causing unwanted behaviours.

    (This because of the fun fact that you can place a cart on a track in two ways, their yaw differ 180 degrees)
    When on straight tracks (x = 0 or z = 0) I will try to calculate the assumed yaw based on the velocity, and if this differs, I will teleport the cart to have the correct yaw. As soon this is working, this section will finally do it's job:
    Code:
                //LAST CART MAX SPEED - CARTS IN FRONT DECREASED/INCREASED SPEED BASED ON DISTANCE DIFF
                double totaldistance = 0;
                for (int i = mf.length - 2;i >= 0;i--) {
                    double distance = mf[i].distance(mf[i + 1]);
                    totaldistance += distance;
                    double perfectdistance = (mf.length - i - 1) * cartDistance;
                    //COMPARE PERFECT vs CURRENT and DECREASE if needed
                }
     
  27. Yeah, i was thinking that, that would be a problame! :/
    I hope you can make it work :D

    I just wonder, is it possible for those who downloade the mod to adjust the speed, the distance for the cart and stuff like that?
    I now this may make the plugin laggy and stuff if it is beeing changed to much, but would be awsome to adjust some speed and so on for testing!
     
  28. Offline

    bergerkiller

    It is already possible to change the distance between carts, it's at 1.2 atm. Not sure about speed, since a max speed setting needs changing then. It could also cause odd behaviours when on laggy servers, where chunks are not (yet) loaded underneath you.
     
  29. Nice, the distance part is awsome!

    The speed limit is it already an plugin for if i am not wrong so thats not anny problame:)
    When do you think you will have the finely version done?:)
     
  30. Offline

    bergerkiller

    Will take a bit longer I'm afraid. I still need to find out a way to "line" the carts. A "forward" force does not mean the same to all carts, and that's a problem. I made a "flip" function to turn carts 180 degrees, but I am having a hard time checking if the cart needs to be flipped. (Should only have to happen once)
    Code:
                for (Minecart m : mc) {
                    Vector vel = m.getVelocity();
                    Location loc = m.getLocation();
                    boolean flip = false;
                    if (vel.getX() < 0.0001 && vel.getX() > 0.0001) {
                        if (force > 0) {
                            if (loc.getYaw() == 180) flip = true;
                        } else if (vel.getZ() < 0.0001) {
                            if (loc.getYaw() == 0) flip = true;
                        }
                    }
    
                    if (flip) {
                        flipCart(m);
                        broadcast("FLIPPED");
                    }
                }
    Ugh unbelievable, obviously I take this entire problem completely wrong. :oops:
    I thought that the YAW was a problem, well that was already solved. I had to order the carts from head at 0 to tail at last. Obviously you can't know this through velocity, since all carts have the same. Same for yaw. Yet still I was trying to do this through this...ugh sometimes. :rolleyes:

    Simplest solution ever: I made a function for it:
    Code:
        public static boolean isHeadingTo(Entity heading, Entity to) {
            Location dest = heading.getLocation();
            Vector head = heading.getVelocity();
            dest = dest.add(head.getX(), head.getY(), head.getZ());
            return dest.distance(to.getLocation()) < heading.getLocation().distance(to.getLocation());
        }
    Passed the first and the last minecart to this function and it finally gave me the "head" of the train.
    Code:
                Minecart m1 = mc.get(0);
                Minecart m2 = mc.get(mc.size() - 1);
                if (isHeadingTo(m1, m2)) {
                    broadcast("M2 is the head");
                } else {
                    broadcast("M1 is the head");
                }
                if (getNearPlayer(m1.getLocation()) != null) {
                    broadcast("M1 is the near");
                } else if (getNearPlayer(m2.getLocation()) != null) {
                    broadcast("M2 is the near");
                } else {
                    broadcast("Nothing is the near");
                }
    Now time to finally work on keeping distance...

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

Share This Page