Skip to content

Commit

Permalink
Further Allay syncing
Browse files Browse the repository at this point in the history
  • Loading branch information
fullwall committed Feb 16, 2023
1 parent 27991c9 commit 5bc6b07
Showing 1 changed file with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public AllayNPC(EntityAllayNPC entity) {

public static class EntityAllayNPC extends Allay implements NPCHolder {
private final CitizensNPC npc;
private int taskId = -1;

public EntityAllayNPC(EntityType<? extends Allay> types, Level level) {
this(types, level, null);
Expand Down Expand Up @@ -161,12 +162,19 @@ protected AABB makeBoundingBox() {
protected InteractionResult mobInteract(Player var0, InteractionHand var1) {
if (npc != null && npc.isProtected()) {
// prevent clientside prediction
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), () -> {
NMSImpl.sendPacketNearby(null, getBukkitEntity().getLocation(),
new ClientboundSetEquipmentPacket(getId(), Lists.newArrayList(
Pair.of(EquipmentSlot.OFFHAND, this.getItemInHand(InteractionHand.OFF_HAND)),
Pair.of(EquipmentSlot.MAINHAND, this.getItemInHand(InteractionHand.MAIN_HAND)))));
});
if (taskId != -1) {
taskId = Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), () -> {
NMSImpl.sendPacket((org.bukkit.entity.Player) var0.getBukkitEntity(),
new ClientboundSetEquipmentPacket(getId(),
Lists.newArrayList(
Pair.of(EquipmentSlot.OFFHAND,
this.getItemInHand(InteractionHand.OFF_HAND)),
Pair.of(EquipmentSlot.MAINHAND,
this.getItemInHand(InteractionHand.MAIN_HAND)))));
((org.bukkit.entity.Player) var0.getBukkitEntity()).updateInventory();
taskId = -1;
});
}
return InteractionResult.FAIL;
}
return super.mobInteract(var0, var1);
Expand Down

0 comments on commit 5bc6b07

Please sign in to comment.