David Barreto

un plugin para que las vacas vuele para la version 1.20

Kodari AI
KodariOct 13 at 6:48 pm 1
FlyingCows
FlyingCows is a Minecraft 1.20 plugin that makes cows fly. When a cow spawns, it gains the ability to levitate and move through the air. Players can toggle flying mode for all cows with a simple command. Cows will float upward, glide around the world, and descend slowly when landing. The plugin includes configurable flight speed, height limits, and particle effects to visualize the flying cows. It also prevents cows from taking fall damage while flying and allows them to navigate over obstacles. Perfect for adding a whimsical, chaotic element to any server.
  1. Crearé la configuración Gradle para Paper 1.20.

  2. Añadiré un plugin que permite montar vacas y hacerlas volar mirando en la dirección deseada; agacharse sirve para desmontar.

Creé VacasVoladoras para Paper 1.20: haz clic derecho en una vaca para montarla, mira hacia donde quieras volar y agáchate para desmontar.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
settings.gradle
Code
4 98
src/main/java/com/kodari/vacasvoladoras/VacasVoladorasPlugin.java
package com.kodari.vacasvoladoras;

import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import org.bukkit.entity.Cow;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDismountEvent;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.util.Vector;

public final class VacasVoladorasPlugin extends JavaPlugin implements Listener {
    private final Set<UUID> flyingCows = new HashSet<>();

    @Override
    public void onEnable() {
        getServer().getPluginManager().registerEvents(this, this);
        getServer().getScheduler().runTaskTimer(this, this::moveFlyingCows, 1L, 1L);
    }

    @EventHandler
    public void onCowInteract(PlayerInteractEntityEvent event) {
        if (!(event.getRightClicked() instanceof Cow cow)) {
            return;
        }

        Player player = event.getPlayer();
        if (!cow.getPassengers().isEmpty()) {
            return;
        }

        event.setCancelled(true);
        if (cow.addPassenger(player)) {
            flyingCows.add(cow.getUniqueId());
            player.sendMessage("&a¡Has montado una vaca voladora! Mira hacia donde quieres volar y agáchate para bajar.");
        }
    }

    @EventHandler
    public void onDismount(EntityDismountEvent event) {
        if (event.getDismounted() instanceof Cow cow
                && event.getEntity() instanceof Player
                && cow.getPassengers().size() <= 1) {
            flyingCows.remove(cow.getUniqueId());
        }
    }

    private void moveFlyingCows() {
        flyingCows.removeIf(uuid -> {
            Entity entity = getServer().getEntity(uuid);
            if (!(entity instanceof Cow cow) || !cow.isValid() || cow.getPassengers().isEmpty()) {
                return true;
            }

            if (!(cow.getPassengers().get(0) instanceof Player rider)) {
                return true;
            }

            Vector direction = rider.getLocation().getDirection().normalize();
            cow.setVelocity(direction.multiply(0.45));
            return false;
        });
    }
}