Skip to content

Commit

Permalink
STOP_USE_ITEM not supported
Browse files Browse the repository at this point in the history
  • Loading branch information
fullwall committed Oct 4, 2022
1 parent 838aa30 commit d11fd91
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
10 changes: 9 additions & 1 deletion main/src/main/java/net/citizensnpcs/EventListen.java
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,13 @@ public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
event.setCancelled(true);
return;
}
PlayerAnimation.STOP_USE_ITEM.play(player);
if (SUPPORT_STOP_USE_ITEM) {
try {
PlayerAnimation.STOP_USE_ITEM.play(player);
} catch (UnsupportedOperationException e) {
SUPPORT_STOP_USE_ITEM = false;
}
}
if (npc.hasTrait(CommandTrait.class)) {
npc.getTraitNullable(CommandTrait.class).dispatch(player, CommandTrait.Hand.RIGHT);
}
Expand Down Expand Up @@ -764,4 +770,6 @@ private boolean spawn(NPC npc) {
}
return npc.spawn(spawn, SpawnReason.CHUNK_LOAD);
}

private static boolean SUPPORT_STOP_USE_ITEM = true;
}
10 changes: 10 additions & 0 deletions main/src/main/java/net/citizensnpcs/trait/ArmorStandTrait.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,16 @@ public void run() {
entity.setMarker(marker);
}

public void setAsHelperEntity(NPC parent) {
npc.addTrait(new ClickRedirectTrait(npc));
setAsPointEntity();
}

public void setAsHelperEntityWithName(NPC parent) {
npc.addTrait(new ClickRedirectTrait(npc));
setAsPointEntityWithName();
}

/**
* Configures the entity as an invisible point entity, e.g. for mounting NPCs on top, nameplates, etc.
*/
Expand Down
3 changes: 1 addition & 2 deletions main/src/main/java/net/citizensnpcs/trait/HologramTrait.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ public void clear() {

private NPC createHologram(String line, double heightOffset) {
NPC hologramNPC = registry.createNPC(EntityType.ARMOR_STAND, line);
hologramNPC.addTrait(new ClickRedirectTrait(npc));
hologramNPC.getOrAddTrait(ArmorStandTrait.class).setAsPointEntityWithName();
hologramNPC.getOrAddTrait(ArmorStandTrait.class).setAsHelperEntityWithName(npc);
hologramNPC.spawn(currentLoc.clone().add(0,
getEntityHeight()
+ (direction == HologramDirection.BOTTOM_UP ? heightOffset : getMaxHeight() - heightOffset),
Expand Down
4 changes: 3 additions & 1 deletion main/src/main/java/net/citizensnpcs/trait/SitTrait.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,17 @@ public void run() {
if (!npc.isSpawned() || !sitting) {
return;
}

if (holder == null) {
NPCRegistry registry = CitizensAPI.getNamedNPCRegistry("PlayerAnimationImpl");
if (registry == null) {
registry = CitizensAPI.createNamedNPCRegistry("PlayerAnimationImpl", new MemoryNPCDataStore());
}
holder = registry.createNPC(EntityType.ARMOR_STAND, "");
holder.getOrAddTrait(ArmorStandTrait.class).setAsPointEntity();
holder.getOrAddTrait(ArmorStandTrait.class).setAsHelperEntity(npc);
holder.spawn(npc.getStoredLocation());
}

if (holder.getEntity() != null && !NMS.getPassengers(holder.getEntity()).contains(npc.getEntity())) {
NMS.mount(holder.getEntity(), npc.getEntity());
}
Expand Down

0 comments on commit d11fd91

Please sign in to comment.