How to make a higher speed minecart

Discussion in 'Spigot Plugin Help' started by LinXin, Aug 11, 2021.

  1. I tring to use .setMaxSpeed()
    However, I found that it still had a max speed around 30m/s whateve how large I setting.
    Here are my code

    @EventHandler
    public void ClickListener(EntityMountEvent e){
    if(e.getMount().getType().toString() == "MINECART" && e.getEntity().getWorld().getName().toString().equalsIgnoreCase("world") && e.getEntity().getType().toString().equalsIgnoreCase("PLAYER")){
    Player p = (Player) e.getEntity();
    Minecart c = (Minecart) e.getMount();
    c.setMaxSpeed(400);
    }
    }
     
  2. Try using instanceof in your code (Example: if(e.getEntity() instanceof Player)) instead of using a string, and when you query the name of the world, a string is already returned. So the toString() method is unnecessary.
    This might make the code work ;)
     
  3. So I mean it like this:

    Code (Java):
        @EventHandler
        public void onEntityMount(@NotNull EntityMountEvent event) {

            if(event.getMount() instanceof Minecart && Objects.requireNonNull(event.getEntity().getLocation().getWorld()).getName().equalsIgnoreCase("world")
                && event.getEntity() instanceof Player) {

                Minecart minecart = (Minecart) event.getMount();
                minecart.setMaxSpeed(400);
                //or
                //Sets the maximum speed for the Minecart
                minecart.setMaxSpeed(minecart.getMaxSpeed());
         
           
            }
        }
     
    #3 Steen0301, Aug 11, 2021
    Last edited: Aug 11, 2021
  4. e.getMount().getType().toString() == "MINECART"
    You are comparing these strings using == instead of #equals.
     
    • Like Like x 2
  5. Strahan

    Benefactor

    Christ I'm blind, lol, didn't even catch that.
     
  6. :D