Skip to content

NPC

Module for creating multi-platform NPC entities.

Features

  • Multiline names
  • Skins
  • Head following player

Visuals API

The NPC interface extends LocatableVisual, so you can use its methods to customize the NPC further.

Usage

Supported platforms are the same as the packets module, because this module doesn't have any platform specific code.

Maven

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<repositories>
    <repository>
        <id>screamingrepo</id>
        <url>https://repo.screamingsandals.org/repository/maven-public</url>
    </repository>
    <repository>
        <id>papermc</id>
        <url>https://papermc.io/repo/repository/maven-public</url>
    </repository>
</repositories>

<dependencies>
    <dependency>
        <groupId>org.screamingsandals.lib</groupId>
        <artifactId>npc-YOUR_PLATFORM</artifactId>
        <version>2.0.1-SNAPSHOT</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.screamingsandals.lib</groupId>
        <artifactId>annotation</artifactId>
        <version>2.0.1-SNAPSHOT</version>
        <scope>provided</scope>
    </dependency>
</dependencies>

<!-- Shade plugin configuration and relocation package org.screamingsandals.lib to your own package -->

Gradle

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
repositories {
    maven { 
        url 'https://repo.screamingsandals.org/repository/maven-public'
    }
    maven {
        url 'https://papermc.io/repo/repository/maven-public'
    }
}

dependencies {
    implementation 'org.screamingsandals.lib:npc-YOUR_PLATFORM:2.0.1-SNAPSHOT'
    annotationProcessor 'org.screamingsandals.lib:annotation:2.0.1-SNAPSHOT'
}

Examples

Creating your first NPC

Start by spawning the NPC on a specified location, like this:

1
final NPC npc = NPC.of(yourLocation);
Now let's set a nice skin for the NPC. I'll use Misat's skin in this example.
1
2
3
4
5
6
7
8
final PlayerWrapper misat = PlayerMapper.getPlayer("Misat11").orElseThrow(() -> new RuntimeException("No misat here lol"));
final NPC npc = NPC.of(yourLocation);
NPCSkin.retrieveSkin(misat.getUuid()).thenAccept(skin -> {
    // null if an error occurred, like no internet connection
    if (skin != null) {
        npc.setSkin(skin);
    }
});
I think that NPC's looking into your soul are not creepy at all, so let's make the NPC look at players and let's give it a name.
1
2
3
4
final NPC npc = ...;
npc.setShouldLookAtPlayer(true)
    // requires a List<Component> to allow for multiline names
    .setDisplayName(List.of(Component.text("Misat11")));
And you've made yourself a fresh new NPC!

Destroying a NPC

If you want to destroy a NPC, you can call the LocatableVisual#destroy() method.

1
2
final NPC npc = NPC.of(yourLocation);
npc.destroy();


Last update: 2022-01-18
Back to top