Using the Wand, Scripter or Cloner on an NPC no longer runs its interact through an offhand click

This commit is contained in:
KAMKEEL committed 2026-10-06 01:51:13 -04:00
1 parent 2c29f11550
commit 8f4fcae735
2 files changed
+16

No files matched your search

@@ -104,6 +104,7 @@ public class ServerEventsHandler {
return;
}
event.setCanceled(true);
((EntityNPCInterface) event.target).markToolUse(event.entityPlayer);
NoppesUtilServer.sendOpenGui(event.entityPlayer, EnumGuiType.MainMenuDisplay, (EntityNPCInterface) event.target);
if (ConfigDebug.PlayerLogging && FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER) {
LogWriter.script(String.format("[%s] (Player) %s OPEN NPC %s (%s, %s, %s) [%s]", "WAND", event.entityPlayer.getCommandSenderName(), ((EntityNPCInterface) (event.target)).display.getName(), (int) (event.target).posX, (int) (event.target).posY, (int) (event.target).posZ, (event.target).worldObj.getWorldInfo().getWorldName()));
@@ -119,6 +120,7 @@ public class ServerEventsHandler {
PacketHandler.Instance.sendToPlayer(new ClonerPacket(compound), (EntityPlayerMP) event.entityPlayer);
data.cloned = compound;
if (event.target instanceof EntityNPCInterface) {
((EntityNPCInterface) event.target).markToolUse(event.entityPlayer);
NoppesUtilServer.setEditingNpc(event.entityPlayer, (EntityNPCInterface) event.target);
}
event.setCanceled(true);
@@ -126,6 +128,7 @@ public class ServerEventsHandler {
if (!CustomNpcsPermissions.hasPermission(event.entityPlayer, CustomNpcsPermissions.TOOL_SCRIPTER))
return;
NoppesUtilServer.setEditingNpc(event.entityPlayer, (EntityNPCInterface) event.target);
((EntityNPCInterface) event.target).markToolUse(event.entityPlayer);
event.setCanceled(true);
GuiOpenPacket.openGUI((EntityPlayerMP) event.entityPlayer, EnumGuiType.Script, 0, 0, 0);
if (ConfigDebug.PlayerLogging && FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER) {
@@ -539,10 +539,23 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti
updateClient = false;
}
/** Who last used a tool on this NPC and when, so an offhand click right after it does not run the interact. */
private String toolUser;
private long toolUsedAt;
/** Marks that this player just used the Wand, Scripter or Cloner on this NPC. */
public void markToolUse(EntityPlayer player) {
toolUser = player.getCommandSenderName();
toolUsedAt = worldObj.getTotalWorldTime();
}
@Override
public boolean interact(EntityPlayer player) {
if (worldObj.isRemote)
return false;
// An offhand mod like Backhand clicks again with the other hand after a tool click is cancelled
if (player.getCommandSenderName().equals(toolUser) && worldObj.getTotalWorldTime() - toolUsedAt <= 2)
return true;
ItemStack currentItem = player.inventory.getCurrentItem();
if (currentItem != null) {
Item item = currentItem.getItem();