Skip to content
Advertisement

How to change speed of Entities?

How can I change the speed of entities in Minecraft using plugins? I just recently started making plugins for Minecraft, so I will be very grateful if you can help me (I use spigot)

Advertisement

Answer

This forum post may solve your problem. A dude asked the same question as you and gave some code snippets to help.

private static final UUID movementSpeedUID = UUID.fromString("206a89dc-ae78-4c4d-b42c-3b31db3f5a7c");
   
    @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
    public void onEntityDamage(EntityDamageByEntityEvent event) {
        LivingEntity entity = (LivingEntity) event.getEntity();
       
        if (!(event.getDamager() instanceof Arrow)) return;
        Arrow arrow = (Arrow) event.getDamager();
        if (arrow.getShooter() instanceof Player) {
            EntityInsentient nmsEntity = (EntityInsentient) ((CraftLivingEntity) entity).getHandle();
            AttributeInstance attributes = nmsEntity.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED);
           
            AttributeModifier modifier = new AttributeModifier(movementSpeedUID, "movement speed multiplier", 1.0d, 1);
           
            attributes.b(modifier);
        }
    }

I wish I could help more, but I still haven’t learned Java. I hope to, soon. I literally have a book on my bookshelf teaching Java, but I just haven’t had the time.

Advertisement