juliarn / npc-lib

Asynchronous, high-performance Minecraft NPC library for 1.8-1.21 servers.
MIT License
296 stars 50 forks source link

Exmape to create NPCS #102

Closed DevSnx closed 1 day ago

DevSnx commented 1 year ago

Hey, you have any simple examples to create a NPC?

kingOf0 commented 1 year ago

An example how to create a npc & pool for bukkit can be found here: NPC Pool creation, NPC creation, NPC Event subscriptions.

And here is a kotlin scratch. Works with beta v3 on 1.19.3.

import com.github.juliarn.npclib.api.Npc
import com.github.juliarn.npclib.api.NpcActionController
import com.github.juliarn.npclib.api.profile.Profile
import com.github.juliarn.npclib.bukkit.BukkitPlatform
import com.github.juliarn.npclib.bukkit.BukkitWorldAccessor
import com.github.juliarn.npclib.bukkit.util.BukkitPlatformUtil
import org.bukkit.Bukkit
import org.bukkit.Location
import java.util.*

val npcPlatform = BukkitPlatform.bukkitNpcPlatformBuilder()
    .extension(PLUGIN_INSTANCE)
    .actionController { builder ->
        builder
            .flag(NpcActionController.SPAWN_DISTANCE, 60)
            .flag(NpcActionController.IMITATE_DISTANCE, 16)
            .flag(NpcActionController.TAB_REMOVAL_TICKS, 20)
    }
    .worldAccessor(BukkitWorldAccessor.nameBasedAccessor())
    .build()

val location = Location(Bukkit.getWorld("world"), 0.0, 0.0, 0.0)

val npc = npcPlatform.newNpcBuilder()
    .position(BukkitPlatformUtil.positionFromBukkitLegacy(location))
    .profile(Profile.resolved("name", UUID.fromString("uuid")))
    .flag(Npc.LOOK_AT_PLAYER, false)
    .flag(Npc.HIT_WHEN_PLAYER_HITS, false)
    .flag(Npc.SNEAK_WHEN_PLAYER_SNEAKS, false)
    .buildAndTrack()
derklaro commented 1 day ago

I just added documentation and a bunch of code examples into the readme, feel free to leave feedback if something is missing.