Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exmape to create NPCS #102

Closed
DevSnx opened this issue Mar 7, 2023 · 2 comments
Closed

Exmape to create NPCS #102

DevSnx opened this issue Mar 7, 2023 · 2 comments

Comments

@DevSnx
Copy link

DevSnx commented Mar 7, 2023

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

@kingOf0
Copy link

kingOf0 commented Mar 25, 2023

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
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants