npc-lib icon indicating copy to clipboard operation
npc-lib copied to clipboard

Exmape to create NPCS

Open DevSnx opened this issue 2 years ago • 1 comments

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

DevSnx avatar Mar 07 '23 11:03 DevSnx

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()

kingOf0 avatar Mar 25 '23 01:03 kingOf0

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

derklaro avatar Aug 19 '24 16:08 derklaro