Extra Alchemy

Extra Alchemy

13M Downloads

The behavior of the Potion Ring does not follow its tooltip

lonefelidae16 opened this issue · 1 comments

commented

Describe the bug

As you know, we can change key bindings to different ones.

"item.extraalchemy.potion_ring.disabled": "Inactive. Shift-right click to enable",
"item.extraalchemy.potion_ring.enabled": "Active. Shift-right click to disable",

When I follow this tooltip to activate the Potion Ring with Shift + Right Click, it doesn’t. After examining the code, I was able to figure out why it doesn’t.

@Override
public TypedActionResult<ItemStack> use(World world, PlayerEntity user, Hand hand) {
ItemStack stack = user.getStackInHand(hand);
if (user.isSneaking()) {
toggleRingStack(stack);
return new TypedActionResult<ItemStack>(ActionResult.SUCCESS, stack);
}
return new TypedActionResult<ItemStack>(ActionResult.FAIL, stack);
}

That’s because my Shift key is assigned to Sprint and the Potion Ring checks for Sneaking at line 79.

To Reproduce

Steps to reproduce the behavior:

  1. Set the Sneak key from Shift to another on the key bind setting screen.
  2. Get the Potion Ring in the Hotbar.
  3. Shift + Right Click and it doesn’t activate.

Expected behavior

If it needs to sneak, I think the tooltip should to be changed to Right click while sneaking to enable/disable. If not, it would be more awesome if it could determine if the Shift key is really being pressed.

I tried to implement this, but I found that it requires interaction between server and client using the packet behavior.

  • Register a new receiver on the server side by executing ServerPlayNetworking#registerGlobalReceiver.
  • Register a new callback on the client side by executing Event#register in ClientTickEvents#END_CLIENT_TICK.
  • Send the packet to tell from the client side that the combination key is pressed or not using ClientPlayNetworking#send.
    The state can be detected by calling InputUtil#isKeyPressed.
  • When the packet is received on the server side, the state needs to be stored for each player.
  • Get the state in the use method.

It works for me, but the statements get more complex, so I think it’s just enough to determine if the player is sneaking or not. Maybe there is another way or useful library to do this, but I could not find it, perhaps my search skills are not good enough.

Environment (please complete the following information):

  • Mod Version: local build rev.7b31ca9b (1.9.2)
  • MC Version: 1.19.3
  • Fabric Version: 0.14.12
  • Fabric API version: 0.72.0
  • System: Ubuntu Linux 22.04 / Windows 11
  • Installation type: “Open to LAN” on Integrated Server via :runClient Gradle task / Dedicated Server via :runServer Gradle task
commented

Changing the tooltip will be more than enough, no need to implement all of that.
Thanks for the feedback