Grabbing schedule back doesn't take it away from entity
BlastBolt5 opened this issue ยท 3 comments
Describe the Bug
When testing a train that picks up and deposits water I tried to grab the schedule from the parrot and it gave me one but didn't take it away from the parrot. Upon further testing this glitch happens only with the first free hotbar slot but if you have 2 open it the second one will correctly take away the schedule
Reproduction Steps
- make train
- give entity schedule
- try to take schedule back with first open hotbar slot
- do the same but with the second open slot
Expected Result
get schedule back no matter the slot
Screenshots and Videos
2022-07-11.21-10-40.mp4
Crash Report or Log
No response
Operating System
Windows 11
Mod Version
0.5.0
Minecraft Version
1.18.2
Other Mods
fabric-api-0.57.0+1.18.2
Additional Context
No response
I've been interested in learning some minecraft mod dev, so I looked into this bug a bit. Here's what I've found:
This bug appears to be a race condition caused by the UseEntityCallback
being called before the Item.interactLivingEntity
is called on the item in the player's main hand. If the removeScheduleFromConductor
method places the schedule in the player's main hand, the server will subsequently call the interactLivingEntity
method on the newly created ScheduleItem
, which just reapplies the schedule that was just removed.
Because of this, the bug doesn't only happen with the first hotbar slot. You can reproduce the bug by trying to remove the schedule from an entity while your main hand is hovering the slot that the schedule is supposed to be placed in. For example, if the first hotbar slot is full, trying to remove a schedule while your main hand is on the second hotbar slot will result in the same bug.
I'm a bit of a minecraft modding noob, but I see three ways to fix this:
- Make sure when a schedule is removed, it never ends up in the main hand
- Move the apply schedule logic out of
ScheduleItem
and into anotherUseEntityCallback
, making sure callbacks happen in the correct order - Drop the schedule item on the ground when it is removed
@TropheusJ, if you don't mind, I can make a PR for this?