More out of MineCart's!

Discussion in 'Plugin Requests' started by Marius A. Winsjansen, Jul 31, 2011.

  1. Offline

    Marius A. Winsjansen

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Hello,

    I wonder if its possible to make mod that make's it possible to "stack" minecarts in a row, like a train, so different players can ride togheter in 1 "train"?

    Would be awsome, all tho its probly not that usful tho!
  2. Offline

    rapidfireshot

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    I REALLY want this. Minecarts suck currently. Storage minecarts can't move without powered pushing them, but the collisions are awful and they bounce off each other or get stuck inside each other. Make it to where if a minecart links to a minecart if it collides with it. Hell, if people don't want it to do this on collision, make a "linkable" variable, and people can set certain minecarts to be linkable.

    Marius, this is EXTREMELY useful.

    This post has been edited 1 time. It was last edited by rapidfireshot Jul 31, 2011.
  3. Offline

    Marius A. Winsjansen

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Its brilliant to see others that are interested in this like me!

    Yeah, i like what you say and i aggree! It should be more focus on the MineCarts in the game! On the most of the servers out there, peoples nerly use them.. why? its not good, ass you said!

    Its only 2-3 mods out there for the Carts, and they really do nothing much!

    It would be awsome to add some more function to some carts, (like the normal one) so they can go by them self! So, if a normal one is first in line, it drags the others!

    And i love your idea btw, when a cart hits another, it links! would be SO greate!

    All develobers out there, go to work!:)
  4. Offline

    Marius A. Winsjansen

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    It would also be awsome to have a possibility to push a button and then get a minecart!
    Lets say, i am on a rollorcoaster, and i am at the start, and whant a minecart at the start instead of taking out of a chest and MOSTLY instead of making a HUGE redstone creation to get a auto minecarft give type off thingi!

    I actualy dont have anny idea on how to get that to work, but maby by having a chest under a rail and pressing a button and a minecart goes out of the chest and to the rail! Something like that, i dont know!
    I am just saying my ideas out loud:)
  5. Offline

    Master24

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
  6. Offline

    bergerkiller

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    I'm extremely bored and this seems a nice plug-in indeed. I'll see if I can "bind" two minecarts together.
    (handling velocity updates combined with obvious force distribution among the carts)

    EDIT

    Well this is the first time I end up using no events at all. An "EntityCollideWithEntityEvent" is missing, so I end up looping through all entities in a repeating task.

    EDIT2

    HAHAA!!
    I did it! I managed to make two minecarts move over a track completely connected :D

    EDIT3
    Corners work too? Didn't expect it to be this easy :O

    This post has been edited 3 times. It was last edited by bergerkiller Jul 31, 2011.
  7. Offline

    Marius A. Winsjansen

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Lovly, nice too see you liked my idea and worked on it!! :D

    Can you make more carts toghere, and different types also?

    Let me know when you are finnish whit a test version :D
  8. Offline

    Jaker232

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    I'm already designing a similar plugin called CartModifier, I'll see if I can get the trains feature.

    EDIT: Didn't notice bergerkiller was already working on it. Shit. ;(

    This post has been edited 1 time. It was last edited by Jaker232 Jul 31, 2011.
  9. Offline

    Marius A. Winsjansen

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Yeah, it would be awsome!

    Also, if it can be used togheter whit the MineCart Mania, it would be create! Since that plugin got almoast everything exept the possibility to ride toghetere!!!:)
  10. Offline

    bergerkiller

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Works. 100%. Works !!!!

    I just made 20 carts bound together in a single train, no commands, no events, all in a runned task!
    Only thing to fix: 180-turned carts move the opposite way..lol

    EDIT

    Hills work too. Only thing now is 180 degrees

    This post has been edited 1 time. It was last edited by bergerkiller Jul 31, 2011.
  11. Offline

    Marius A. Winsjansen

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    damn, i am so excited to see this! :D i CANT w8 :D:D

    do you think it takes much more time? :D

    it would be SO awsome if you logged on to my server and showed me and we could test it out and talk more there when you have a test ready for instaling :D
  12. Offline

    bergerkiller

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Lemme make a video for ya :D
  13. Offline

    Marius A. Winsjansen

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Awsome! :D

    I am updating the web browser on and on and on to see when your done :D
  14. Offline

    Tster

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Berge can I collab on you with this one, I can make an epic video :p
  15. Offline

    Marius A. Winsjansen

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    If you are going to make the video on a SMP server PLZZZ let me join :D
  16. Offline

    Tster

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    How do you not make a video of a Bukkit plugin on a serveR?
  17. Offline

    Marius A. Winsjansen

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    What do you mean?
    He is going to make a video on how to use it!
  18. Offline

    Marius A. Winsjansen

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    oh, i read wrong! and i write wrong on the last comment, i meant if he is going to do it on a offical and open server for, not dedicated!:) sorry!
  19. Offline

    Tster

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Yes, and he is making the plugin with bukkit, so he is using an online server, can you join, maybe, depending on whether he can be bothered to port forward
  20. Offline

    bergerkiller

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    yup I am.

    Note: it's a bit laggy/buggy since Im hosting a server, running the game, running Fraps and eclipse all at the same time on a dual core 2.0 ghz cpu. But it will demonstrate that what is currently achieved. Ignore weird cart teleportations, doesn't happen w/o recording.

    And running on a local server, so no port forwarding sorry. :)

    I'll give some idea of how this works, since it's pretty easy.
    What happens:
    Code:
    Every 0.5 seconds it is checked if two carts are close enough to form a pair or join a group.
    Every tick it is for every group calculated what the forward speed is. The average.
    Every cart is then pushed with the same force.
    What I haven't added yet is "keeping distance a certain value". I will add that later on.

    This post has been edited 2 times. It was last edited by bergerkiller Jul 31, 2011.
  21. Offline

    Tster

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    (full stop)
  22. Offline

    Tster

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    So, you wana collaborate?
  23. Offline

    Marius A. Winsjansen

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    yeah, i know!

    i typed wrong, and as i said, i meant if he had a server that peopls could join, or if i only had a dedicated server that only he had permission to play on! Like it seems he have!
  24. Offline

    bergerkiller

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    @Tster Sure, if you can make a nice video of it go ahead. But let me fix a few minor bugs first. At the moment the velocity of every cart is equal. I have to add a variation to it to remain the same distance between carts.

    This post has been edited 3 times. It was last edited by bergerkiller Jul 31, 2011.
  25. Offline

    Tster

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Ok, atm I will develop, and when we are further through the promo vid can be a train station(I whip ass with redstone)
  26. Offline

    bergerkiller

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
  27. Offline

    Tster

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Oh my god, legend
  28. Offline

    Tster

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    How does it store the minecarts linked, a hashmap?
  29. Offline

    Marius A. Winsjansen

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    SO awsome! can you add other carts to the train to? That would be so awsome!
  30. Offline

    bergerkiller

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    xD Thanks.

    Time for some source I guess. It is pretty basic. See this class I made:
    Code:
        public static double getForwardForce(Entity e) {
            Vector v = e.getVelocity();
            Vector rval = new Vector();
            // Convert rotation to radians
            double ryaw = -e.getLocation().getYaw() / 180f * Math.PI;
            //double rpitch = e.getLocation().getPitch() / 180f * Math.PI;
            double force = Math.sin(ryaw) * v.getZ() - Math.cos(ryaw) * v.getX();
               return force;
        }
        public static void setForwardForce(Entity e, double force) {
            double ryaw = -e.getLocation().getYaw() / 180f * Math.PI;
            Vector f = new Vector(0, e.getVelocity().getY(), 0);
    
            f.setX(-Math.cos(ryaw) * force);
            f.setZ(Math.sin(ryaw) * force);
            e.setVelocity(f);
        }
    
        public class MinecartPair {
            public HashSet<Minecart> mc = new HashSet<Minecart>();
            public void eventForce() {
                double force = 0;
                for (Minecart m : mc) {
                    if (m.)
                    force += getForwardForce(m);
                }
                force /= mc.size();
                for (Minecart m : mc) {
                    setForwardForce(m, force);
                }
            }
        }
    getForwardForce/setForwardForce took me a while to make. They are the key behind everything atm. This is how all carts are stored:
    Code:
        public static ArrayList<MinecartPair> pairs = new ArrayList<MinecartPair>();
        public static HashMap<Minecart, MinecartPair> addedPairs = new HashMap<Minecart, MinecartPair>();
    No events are used. Everything is done is two scheduled tasks. One calls for every pair eventForce, the other makes pairs:
    Code:
                        ArrayList<Minecart> mc = minecarts(w);
                        for (Minecart m1 : mc) {
                            for (Minecart m2 : mc) {
                                if (m1 != m2) {
                                    if (m1.getLocation().distance(m2.getLocation()) < 2) {
                                        //validate pair not added yet
                                        MinecartPair p1 = addedPairs.get(m1);
                                        MinecartPair p2 = addedPairs.get(m2);
                                        if (p1 == null && p2 == null) {
                                            MinecartPair p = new MinecartPair();
                                            p.mc.add(m1);
                                            p.mc.add(m2);
                                            pairs.add(p);
                                            addedPairs.put(m1, p);
                                            addedPairs.put(m2, p);
                                            getServer().broadcastMessage("PAIR ADDED");
                                        } else if (p1 == null && p2 != null) {
                                            addedPairs.put(m1, p2);
                                            p2.mc.add(m1);
                                            getServer().broadcastMessage("MEMBER ADDED");
                                        } else if (p2 == null && p1 != null) {
                                            addedPairs.put(m2, p1);
                                            p1.mc.add(m2);
                                            getServer().broadcastMessage("MEMBER ADDED");
                                        } else if (p1 != null && p2 != null && p1 != p2) {
                                            p1.mc.addAll(p2.mc);
                                            pairs.remove(p2);
                                            for (Minecart m : p1.mc) {
                                                addedPairs.put(m, p1);
                                            }
                                            getServer().broadcastMessage("GROUPS COMBINED");
                                        }
                                    }
                                }
                            }
                        }

    This post has been edited 1 time. It was last edited by bergerkiller Jul 31, 2011.

Share This Page