Hello,
I using the event “InteractEvent” and when the player interact with Primary button return the correct Location, but if the interact is with secondary return wrong locations, like numbers around 0 and 1:
Hello,
I using the event “InteractEvent” and when the player interact with Primary button return the correct Location, but if the interact is with secondary return wrong locations, like numbers around 0 and 1:
I think you post this to spongecommon the devs have a better chance of seeing and fixing it
Maybe its an offset on the block you clicked?
I tested clicking without itens in my hand on a grass block.
Post the code you are using to print it out.
Shure, here the code:
And in this line is the temporary fix. I check if the y <= 2 because wrong locaion only return numbers into 0 and 1, and if is wrong, get the player location.
Using Sponge API v. 4.0.3 (LATEST maven dependency)
*Only with Right click, Left click return correct location.
Interaction point is the location of the exact interaction…think of it as the exact point in space you did it at.
In your case, you would be much better off using InteractBlockEvent which has the block being interacted with and not worry about the exact interaction point.
I have the same result, i have tryed! The location is always wrong with right click.
The problem seems to be that sometimes the vector is relative to the block face, and other times is an absolute position in the world.
InteractBlockEvent.Secondary (right click) is relative to the block position
example: Optional[(0.1875, 1.0, 0.625)]
InteractBlockEvent.Primary (left click) is absolute.
example: Optional[(-230.15709182852765, 74.64246353206443, 291.0)]
InteractEntityEvent.Secondary is relative.
example: Optional[(-0.550000011920929, 1.2400784492492676, -0.08944406360387802)]
InteractEntityEvent.Primary does not provide a position, it’s always Optional.empty
I also noticed that InteractBlockEvent.Secondary is fired (in addition to InteractEntityEvent.Secondary) when right-clicking on an entity when holding an item in hand, but not when using an empty hotbar slot. In this case, it was always Optional[(0.0, 0.0, 0.0)] with a block position of (0, 0, 0)
In addition, when attempting to place a solid block beneath me (it wouldn’t place as I was in the way), I also observed an InteractBlockEvent.Secondary with interaction point Optional[(0.0, 0.0, 0.0)] and position=(0, 0, 0). This was instead of the expected event rather than an additional one.
This was all with SpongeForge in a development environment
In addition to what @simon816 said, I’m pretty sure @FabioZumbi12 you merely want the location of the block that was interacted.
See: https://jd.spongepowered.org/4.0.3/org/spongepowered/api/event/block/TargetBlockEvent.html which has BlockSnapshot which has the information you need
(InteractBlockEvent extends TargetBlockEvent iirc)