ff09th 9

NMS Plugin Mob All in Minecraft 26.2 ที่ change ai และ machanic ตัวมันเองหมดเลย

Kodari AI
KodariOct 21 at 9:02 pm 2
MobMindOverhaul
Transforms Minecraft NMS 26.2 by replacing default mob AI with advanced behavioral mechanics. Implements custom mob controllers that override vanilla pathfinding, combat tactics, and social interactions. Features dynamic difficulty scaling, pack coordination, territorial aggression, and environmental awareness systems. Includes configurable mob-specific traits, adaptive learning algorithms that modify behavior based on player actions, and performance-optimized tick management. Provides API for developers to register custom AI modules and behavior trees, enabling complete control over mob decision-making processes.

I’ll set a clear default for “Mob All”: all eligible mobs become faster, tougher, and hostile to nearby players; the exact NMS goal APIs will determine which mobs can support that behavior safely.

  • Create a Paperweight project targeting Paper 26.2.

  • On all current and newly loaded/spawned mobs, boost health/speed and add player-hunting AI; add melee only when the mob has an attack-damage attribute.

  • Keep stat boosts from stacking on reload and replace this plugin’s prior goals safely.

Created MobAll for Paper 26.2. It boosts mob movement speed by 1.35× and max health and available attack damage by 1.5×, then adds AI to target nearby visible players. Melee AI is added only to pathfinding mobs that have an attack-damage attribute; vanilla goals otherwise remain intact. Stat boosts won’t stack when the plugin reloads.

ff09th 9

ได้ใช้ NMS ไหมในการ inject ค่าและเปลี่ยนพวก AI ของ mob และเปลี่ยน Machanic ของตัวมัน

Kodari AI
KodariOct 21 at 9:06 pm 1

ใช่ครับ โค้ดนี้ใช้ NMS โดยตรง เพื่อแก้ค่าและ AI ของม็อบ:

  • เรียก CraftMob#getHandle() เพื่อเข้าถึง NMS mob

  • ปรับค่า base ของความเร็ว, พลังชีวิตสูงสุด และพลังโจมตี

  • เพิ่ม goal ให้ม็อบหาและไล่โจมตีผู้เล่น โดยใช้ targetSelector และ goalSelector

แต่ยัง ไม่ได้แทนที่ AI เดิมทั้งหมด — มันเพิ่ม goal ใหม่เข้าไปพร้อมคง goal วานิลลาไว้ และเพิ่ม melee ให้เฉพาะม็อบที่มีค่าโจมตีเท่านั้น ส่วนการตรวจม็อบตอนเกิด/โหลดชังก์และการจำว่าปรับค่าสเตตัสแล้ว ใช้ Bukkit/Paper API ครับ

ff09th 9

ลองเพิ่ม pattern ให้พวก mob หน่อยสิ ให้มันฉลาดขึ้นอะไรแบบนี้ มีสมองดี

Kodari AI
KodariOct 21 at 9:13 pm 1
  • เพิ่มแพตเทิร์นไล่ล่าและอ้อมโจมตีให้ม็อบระยะประชิด โดยยังใช้ระบบโจมตีเดิมของเกม

  • แยกม็อบที่ยิงระยะไกลออก ไม่ให้วิ่งเข้าไปตีประชิด และคง AI ยิงวานิลลาไว้

  • ส่วนเปลี่ยน GoalSelector/AI ต้องใช้ NMS เพราะ Bukkit API ไม่มี API สำหรับแก้ goal ภายในของม็อบโดยตรง; ตรวจ signature ที่ใช้กับ Paper 26.2 แล้ว

เพิ่มแพตเทิร์น AI ด้วย NMS ของ Paper 26.2 แล้วครับ:

  • ม็อบประชิดจะไล่ผู้เล่น และเมื่ออยู่ระยะกลางจะสุ่มเปลี่ยนมุมเข้าประชิดแบบอ้อมซ้าย/ขวา แทนการวิ่งตรงอย่างเดียว

  • ม็อบที่ใช้ RangedAttackMob จะไม่ถูกใส่ goal ตีประชิดทับ จึงคง AI ยิงระยะไกลของวานิลลาไว้

  • การปรับนี้ใช้ GoalSelector และ navigation ภายในของเซิร์ฟเวอร์ เพราะ Bukkit API ไม่มี API สำหรับแก้ goal AI ของม็อบโดยตรง

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
settings.gradle
Code
4 192
src/main/java/dev/kodari/moball/MobAllPlugin.java
package dev.kodari.moball;

import net.minecraft.world.entity.ai.attributes.AttributeInstance;
import net.minecraft.world.entity.ai.attributes.Attributes;
import net.minecraft.world.entity.ai.goal.GoalSelector;
import net.minecraft.world.entity.ai.goal.MeleeAttackGoal;
import net.minecraft.world.entity.ai.goal.target.NearestAttackableTargetGoal;
import net.minecraft.world.entity.PathfinderMob;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.monster.RangedAttackMob;
import net.minecraft.world.entity.player.Player;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.NamespacedKey;
import org.bukkit.World;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Mob;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.event.world.ChunkLoadEvent;
import org.bukkit.persistence.PersistentDataType;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.craftbukkit.entity.CraftMob;

import java.util.concurrent.ThreadLocalRandom;

public final class MobAllPlugin extends JavaPlugin implements Listener {
    private NamespacedKey tunedKey;

    @Override
    public void onEnable() {
        tunedKey = new NamespacedKey(this, "stats_tuned");
        getServer().getPluginManager().registerEvents(this, this);

        for (World world : Bukkit.getWorlds()) {
            for (Chunk chunk : world.getLoadedChunks()) {
                for (Entity entity : chunk.getEntities()) {
                    if (entity instanceof Mob mob) {
                        overhaul(mob);
                    }
                }
            }
        }
    }

    @EventHandler
    public void onCreatureSpawn(CreatureSpawnEvent event) {
        if (event.getEntity() instanceof Mob mob) {
            overhaul(mob);
        }
    }

    @EventHandler
    public void onChunkLoad(ChunkLoadEvent event) {
        for (Entity entity : event.getChunk().getEntities()) {
            if (entity instanceof Mob mob) {
                overhaul(mob);
            }
        }
    }

    private void overhaul(Mob bukkitMob) {
        if (!(bukkitMob instanceof CraftMob craftMob)) {
            return;
        }

        net.minecraft.world.entity.Mob mob = craftMob.getHandle();
        if (!bukkitMob.getPersistentDataContainer().has(tunedKey, PersistentDataType.BYTE)) {
            AttributeInstance movementSpeed = mob.getAttribute(Attributes.MOVEMENT_SPEED);
            if (movementSpeed != null) {
                movementSpeed.setBaseValue(movementSpeed.getBaseValue() * 1.35D);
            }

            AttributeInstance maxHealth = mob.getAttribute(Attributes.MAX_HEALTH);
            if (maxHealth != null) {
                maxHealth.setBaseValue(maxHealth.getBaseValue() * 1.5D);
                bukkitMob.setHealth(bukkitMob.getMaxHealth());
            }

            AttributeInstance attackDamage = mob.getAttribute(Attributes.ATTACK_DAMAGE);
            if (attackDamage != null) {
                attackDamage.setBaseValue(attackDamage.getBaseValue() * 1.5D);
            }

            bukkitMob.getPersistentDataContainer().set(tunedKey, PersistentDataType.BYTE, (byte) 1);
        }

        GoalSelector targetSelector = mob.targetSelector;
        targetSelector.removeAllGoals(goal -> goal.getClass().getName().equals(PlayerHuntGoal.class.getName()));
        targetSelector.addGoal(0, new PlayerHuntGoal(mob));

        if (mob instanceof PathfinderMob pathfinderMob) {
            GoalSelector goalSelector = pathfinderMob.getGoalSelector();
            goalSelector.removeAllGoals(goal -> goal instanceof SmartMeleeGoal);

            if (!(pathfinderMob instanceof RangedAttackMob)
                    && pathfinderMob.getAttribute(Attributes.ATTACK_DAMAGE) != null) {
                goalSelector.addGoal(0, new SmartMeleeGoal(pathfinderMob));
            }
        }
    }

    private static final class PlayerHuntGoal extends NearestAttackableTargetGoal<Player> {
        private PlayerHuntGoal(net.minecraft.world.entity.Mob mob) {
            super(mob, Player.class, true);
        }
    }

    private static final class SmartMeleeGoal extends MeleeAttackGoal {
        private final PathfinderMob mob;
        private int ticksUntilStrafe;

        private SmartMeleeGoal(PathfinderMob mob) {
            super(mob, 1.35D, true);
            this.mob = mob;
        }

        @Override
        public void tick() {
            super.tick();

            LivingEntity target = mob.getTarget();
            if (target == null) {
                return;
            }

            double distanceSqr = mob.distanceToSqr(target);
            if (distanceSqr < 9.0D || distanceSqr > 64.0D) {
                ticksUntilStrafe = 0;
                return;
            }

            if (ticksUntilStrafe > 0) {
                ticksUntilStrafe--;
                return;
            }

            double dx = mob.getX() - target.getX();
            double dz = mob.getZ() - target.getZ();
            double length = Math.sqrt(dx * dx + dz * dz);
            if (length < 0.001D) {
                return;
            }

            double direction = ThreadLocalRandom.current().nextBoolean() ? 1.0D : -1.0D;
            double offsetX = (dx / length * 0.5D - dz / length * 0.866D * direction) * 3.5D;
            double offsetZ = (dz / length * 0.5D + dx / length * 0.866D * direction) * 3.5D;
            mob.getNavigation().moveTo(
                    target.getX() + offsetX,
                    target.getY(),
                    target.getZ() + offsetZ,
                    1.1D
            );
            ticksUntilStrafe = ThreadLocalRandom.current().nextInt(14, 27);
        }
    }
}