STOP_USE_ITEM not supported

This commit is contained in:
fullwall 2022-10-04 22:18:05 +08:00
parent 838aa3019b
commit d11fd91d4a
4 changed files with 23 additions and 4 deletions

View File

@ -526,7 +526,13 @@ public class EventListen implements Listener {
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
if (SUPPORT_STOP_USE_ITEM) {
try {
PlayerAnimation.STOP_USE_ITEM.play(player); PlayerAnimation.STOP_USE_ITEM.play(player);
} catch (UnsupportedOperationException e) {
SUPPORT_STOP_USE_ITEM = false;
}
}
if (npc.hasTrait(CommandTrait.class)) { if (npc.hasTrait(CommandTrait.class)) {
npc.getTraitNullable(CommandTrait.class).dispatch(player, CommandTrait.Hand.RIGHT); npc.getTraitNullable(CommandTrait.class).dispatch(player, CommandTrait.Hand.RIGHT);
} }
@ -764,4 +770,6 @@ public class EventListen implements Listener {
} }
return npc.spawn(spawn, SpawnReason.CHUNK_LOAD); return npc.spawn(spawn, SpawnReason.CHUNK_LOAD);
} }
private static boolean SUPPORT_STOP_USE_ITEM = true;
} }

View File

@ -121,6 +121,16 @@ public class ArmorStandTrait extends Trait {
entity.setMarker(marker); 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. * Configures the entity as an invisible point entity, e.g. for mounting NPCs on top, nameplates, etc.
*/ */

View File

@ -86,8 +86,7 @@ public class HologramTrait extends Trait {
private NPC createHologram(String line, double heightOffset) { private NPC createHologram(String line, double heightOffset) {
NPC hologramNPC = registry.createNPC(EntityType.ARMOR_STAND, line); NPC hologramNPC = registry.createNPC(EntityType.ARMOR_STAND, line);
hologramNPC.addTrait(new ClickRedirectTrait(npc)); hologramNPC.getOrAddTrait(ArmorStandTrait.class).setAsHelperEntityWithName(npc);
hologramNPC.getOrAddTrait(ArmorStandTrait.class).setAsPointEntityWithName();
hologramNPC.spawn(currentLoc.clone().add(0, hologramNPC.spawn(currentLoc.clone().add(0,
getEntityHeight() getEntityHeight()
+ (direction == HologramDirection.BOTTOM_UP ? heightOffset : getMaxHeight() - heightOffset), + (direction == HologramDirection.BOTTOM_UP ? heightOffset : getMaxHeight() - heightOffset),

View File

@ -38,15 +38,17 @@ public class SitTrait extends Trait {
if (!npc.isSpawned() || !sitting) { if (!npc.isSpawned() || !sitting) {
return; return;
} }
if (holder == null) { if (holder == null) {
NPCRegistry registry = CitizensAPI.getNamedNPCRegistry("PlayerAnimationImpl"); NPCRegistry registry = CitizensAPI.getNamedNPCRegistry("PlayerAnimationImpl");
if (registry == null) { if (registry == null) {
registry = CitizensAPI.createNamedNPCRegistry("PlayerAnimationImpl", new MemoryNPCDataStore()); registry = CitizensAPI.createNamedNPCRegistry("PlayerAnimationImpl", new MemoryNPCDataStore());
} }
holder = registry.createNPC(EntityType.ARMOR_STAND, ""); holder = registry.createNPC(EntityType.ARMOR_STAND, "");
holder.getOrAddTrait(ArmorStandTrait.class).setAsPointEntity(); holder.getOrAddTrait(ArmorStandTrait.class).setAsHelperEntity(npc);
holder.spawn(npc.getStoredLocation()); holder.spawn(npc.getStoredLocation());
} }
if (holder.getEntity() != null && !NMS.getPassengers(holder.getEntity()).contains(npc.getEntity())) { if (holder.getEntity() != null && !NMS.getPassengers(holder.getEntity()).contains(npc.getEntity())) {
NMS.mount(holder.getEntity(), npc.getEntity()); NMS.mount(holder.getEntity(), npc.getEntity());
} }