NPC Library which is 99% based on packets to spawn in custom player looking npcs.
The library is based on paper and should break on other non paper server distributions.
Add my nexus as a repository
<repositories>
<repository>
<id>crystall.dev</id>
<url>https://nexus.crystall.dev</url>
</repository>
</repositories>Add PlayerNPCLib as a dependency
<dependencies>
<dependency>
<groupId>dev.crystall</groupId>
<artifactId>playernpclib-api</artifactId>
<version>1.3.1-SNAPSHOT</version>
</dependency>
</dependencies>Note: As of version 1.3.1, NMS modules have been consolidated into the API module. You only need the playernpclib-api dependency - it works for all supported Minecraft versions (1.16.3-1.21.7) automatically.
Add my nexus as a repository
repositories {
maven { url 'https://nexus.crystall.dev' }
}Add PlayerNPCLib as a dependency
dependencies {
implementation 'dev.crystall:PlayerNPCLib:1.0-SNAPSHOT'
}Set up the library. This should be called on startup
playerNPCLib = newPlayerNPCLib(this);To manage a npc, you should always use the entityManager.
PlayerNPCLib.getEntityManager().spawnEntity(characterSelectionNPC, true);PlayerNPCLib.getEntityManager().removeEntity(characterSelectionNPC, true);To Create your own entity, you simply have to extend the BasePlayerNPC class. A good example is the already existing MovablePlayerNPC which uses packets to display a moving PlayerNPC.
publicclassMovablePlayerNPCextendsBasePlayerNPC {
protectedCreaturebukkitLivingEntity;
privatefinalEntityTypeentityType;
privatebooleanisAggressive = false;
publicMovablePlayerNPC(Stringname, Locationlocation, EntityTypeentityType) {
super(name, location);
this.entityType = entityType;
}
publicvoidspawn() {
this.bukkitLivingEntity = (Creature)this.getLocation().getWorld().spawnEntity(this.getLocation(), this.entityType);
if (this.bukkitLivingEntityinstanceofAgeable) {
((Ageable)this.bukkitLivingEntity).setAdult();
}
if (this.bukkitLivingEntityinstanceofZombie) {
((Zombie)this.bukkitLivingEntity).setShouldBurnInDay(false);
}
this.bukkitLivingEntity.setSilent(true);
this.bukkitLivingEntity.setCanPickupItems(false);
super.spawn();
}
}The visibility of an entity is handled its settings. If an entity is visible by default, each nearby player receives on certain conditions the packets to display the entity.
If an entity is not visible by default, each nearby player receives on certain conditions the packets to hide the entity.
A npc can be shown to a player by adding it to the visibleTo list of the npc.