Помогите Как задать прямой вектор фейерверку

  • Автор темы Автор темы JW1408
  • Дата начала Дата начала

JW1408

Новичок
Пользователь
Баллы
6
Имя в Minecraft
JW
Всем привет, подскажите пожалуйста, как задать фейерверку прямой вектор ,а то если брать player.getEyeLocation().getDirection(); то он улетает вверх по-тихоньку
 
Тебе обязательно использовать фейерверк? Думаю там в NMS прописано чтобы он каждый тик получал ускорение вверх.
В теории, можно каждый тик через BukkitRunnable ему ставить ускорение на нужное, но получим небольшой костыль.
 
Тебе обязательно использовать фейерверк? Думаю там в NMS прописано чтобы он каждый тик получал ускорение вверх.
В теории, можно каждый тик через BukkitRunnable ему ставить ускорение на нужное, но получим небольшой костыль.
В QuakeCraft он прямо летит, хочу сделать типа как рейлган квейка
 
Ответ со SpigotMC

xADudex сказал(а):
Guess something like this could work, you could optimize it a bit if you wanted to but guess you won't need it.
Код:
   @EventHandler
    public void onInteract(PlayerInteractEvent event){
        if(event.getItem() == null || event.getItem().getType() != Material.STICK
                || !event.getItem().getItemMeta().hasDisplayName() || !event.getItem().getItemMeta().getDisplayName().equals("Firework Gun")){
            return; // The player is not holding our gun
        }
        if(event.getAction() != Action.RIGHT_CLICK_AIR && event.getAction() != Action.RIGHT_CLICK_BLOCK){
            //If you want it only to fire when you right click
            return;
        }
     
        final Location loc = event.getPlayer().getEyeLocation();
        final Vector v = loc.getDirection();
        v.setY(0); // if you want it to go horizontally, if you want it to go the direction the player is looking then remove this line
        double speed = 0.5;
        v.normalize().multiply(speed); // The speed is how fast it should move, 1 = one block per tick, values over 1 might cause the firework to go through 1 thick block walls
        final Firework f = loc.getWorld().spawn(loc, Firework.class);
     
        /*
         * Do all your firework effect stuff here (e.g. if it should be a star, colors etc)
         */
     
        final boolean ent = true; // Also check if we hit entities
     
        new BukkitRunnable(){
            public void run(){
                f.setTicksLived(0); // To prevent it from detonating before we want it to
                loc.add(v);
                f.teleport(loc);
                if(f.isOnGround()){ // We have hit a solid block, but are now inside that block
                    f.teleport(loc.subtract(v)); // Go back one step to get outside the block
                    f.detonate();
                    this.cancel(); // Stops the task as we are now done
                }
             
                if(ent){ // Check if we have hit entities
                    Vec3D v3 = new Vec3D(loc.getX(), loc.getY(), loc.getZ()); // Create a nms vector representing the firework's location
                    for(Entity e : f.getNearbyEntities(2, 2, 2)){ // Scan nearby entities
                        if(((CraftEntity)e).getHandle().getBoundingBox().a(v3)){ // Check if the firework is inside the entity's hitbox/bounding box
                            // We have hit an entity, detonate and exit (return prevents the for loop form continuing as we are now done
                            f.detonate();
                            this.cancel();
                            return;
                        }
                    }
                 
                }
             
            }
        }.runTaskTimer(plugin, 0, 1); // Create a task to run every tick (plugin = your plugin instance)
    }
 
Вобщем то не обязательно копипастить с той темы, что уже кидали выше, еще и не проверяя, работает ли код
В той теме был нормальный, рабочий ответ. Ты говоришь, что всё перерыл, хотя тебе скинули ссылку на решение твоей проблемы.
 
Назад
Верх