fix npc look for non-player entity types & make small npcs look at the player's head

This commit is contained in:
Pyrbu 2023-05-25 18:35:12 +01:00
parent 182fec9618
commit facc0eb1f7
3 changed files with 4 additions and 3 deletions

@ -142,7 +142,7 @@ public class ZNpcsPlus extends JavaPlugin {
shutdownTasks.add(adventure::close);
if (configManager.getConfig().autoSaveEnabled()) shutdownTasks.add(npcRegistry::save);
NpcApiProvider.register(this, new ZNPCsPlusApi(npcRegistry, typeRegistry, propertyRegistry));
NpcApiProvider.register(this, new ZNpcsPlusApi(npcRegistry, typeRegistry, propertyRegistry));
enabled = true;
log(ChatColor.WHITE + " * Loading complete! (" + (System.currentTimeMillis() - before) + "ms)");
log("");
@ -156,6 +156,7 @@ public class ZNpcsPlus extends JavaPlugin {
entry.setProcessed(true);
NpcImpl npc = entry.getNpc();
npc.getHologram().addLineComponent(Component.text("Hello, World!"));
npc.setProperty(propertyRegistry.getByName("look", Boolean.class), true);
i++;
}
}

@ -81,7 +81,7 @@ public class V1_8PacketFactory implements PacketFactory {
public void teleportEntity(Player player, PacketEntity entity) {
NpcLocation location = entity.getLocation();
sendPacket(player, new WrapperPlayServerEntityTeleport(entity.getEntityId(), npcLocationToVector(location), location.getYaw(), location.getPitch(), true));
if (entity.getType() == EntityTypes.PLAYER) sendPacket(player, new WrapperPlayServerEntityHeadLook(entity.getEntityId(), location.getYaw()));
sendPacket(player, new WrapperPlayServerEntityHeadLook(entity.getEntityId(), location.getYaw()));
}
@Override

@ -61,7 +61,7 @@ public class NpcProcessorTask extends BukkitRunnable {
}
// look property
if (closest != null && npc.getProperty(lookProperty) && lookPropertyDistSq >= closestDist) {
NpcLocation expected = npc.getLocation().lookingAt(closest.getLocation());
NpcLocation expected = npc.getLocation().lookingAt(closest.getLocation().add(0, -npc.getType().getHologramOffset(), 0));
if (!expected.equals(npc.getLocation())) npc.setLocation(expected);
}
}