Sponge: InteractItemEvent and InteractBlockEvent behave incorrectly

I am currently running

  • SpongeVanilla version: spongevanilla-1.12.2-7.1.0-BETA-93
  • Java version: OpenJDK Version “1.8.0_171”
  • Operating System: Linux Mint 18.3 Sylvia (Kernel: x86_64 Linux 4.13.0-45-generic)
  • Plugins/Mods: Empty (Only one my experimental plugin)

Issue Description

At the last build for version 1.12.2, the following bugs are observed: 1. InteractBlockEvent is not called when the right mouse button is clicked (this is a SECONDARY event for both hands). 2. InteractBlockEvent for the left hand (PRIMARY event) does not contain data about the used item when the player clicked into the air. EventContext is empty.

My experiment conditions:

  • Main hand: Stick
  • Off hand: Empty

Listener code:

@Listener
public final void onInteractBlock(InteractBlockEvent event) {
	Objects.requireNonNull(event, "event");
	
	System.out.println(event.getClass().getName());
	System.out.println(event);
}

Console output:

Left button to air

org.spongepowered.api.event.InteractBlockEvent$Primary$MainHand$Impl
MainHand{cancelled=false, cause=Cause[Context=Context[], Stack={EntityPlayerMP['Lignium'/0, l='world', x=-0,53, y=64,00, z=1,22]}], context=Context[], handType=MAIN_HAND, interactionPoint=Optional.empty, source=EntityPlayerMP['Lignium'/0, l='world', x=-0,53, y=64,00, z=1,22], targetBlock=SpongeBlockSnapshot{worldUniqueId=00000000-0000-0000-0000-000000000000, position=(0, 0, 0), blockState=minecraft:air, extendedState=minecraft:air}, targetSide=NONE}

Right button to air

<empty>

Left Button to block

org.spongepowered.api.event.InteractBlockEvent$Primary$MainHand$Impl
MainHand{cancelled=false, cause=Cause[Context=Context["sponge:owner"=EntityPlayerMP['Lignium'/0, l='world', x=-0,53, y=64,00, z=1,65], "sponge:notifier"=EntityPlayerMP['Lignium'/0, l='world', x=-0,53, y=64,00, z=1,65]], Stack={EntityPlayerMP['Lignium'/0, l='world', x=-0,53, y=64,00, z=1,65], com.google.common.util.concurrent.ListenableFutureTask@6c85ea3e}], context=Context["sponge:owner"=EntityPlayerMP['Lignium'/0, l='world', x=-0,53, y=64,00, z=1,65], "sponge:notifier"=EntityPlayerMP['Lignium'/0, l='world', x=-0,53, y=64,00, z=1,65]], handType=MAIN_HAND, interactionPoint=Optional[(-2.370593761577998, 64.0, 1.7115556037860598)], source=EntityPlayerMP['Lignium'/0, l='world', x=-0,53, y=64,00, z=1,65], targetBlock=SpongeBlockSnapshot{worldUniqueId=8a2303f1-f006-4e0d-a866-8ffddde81fd6, position=(-3, 63, 1), blockState=minecraft:stone[variant=stone], extendedState=minecraft:stone[variant=stone]}, targetSide=UP}

Right button to block

org.spongepowered.api.event.InteractBlockEvent$Secondary$MainHand$Impl
MainHand{cancelled=false, cause=Cause[Context=Context["sponge:owner"=EntityPlayerMP['Lignium'/0, l='world', x=-0,54, y=64,00, z=0,58], "sponge:notifier"=EntityPlayerMP['Lignium'/0, l='world', x=-0,54, y=64,00, z=0,58], "sponge:used_item"=SpongeItemStackSnapshot{itemType=minecraft:stick, quantity=1}], Stack={EntityPlayerMP['Lignium'/0, l='world', x=-0,54, y=64,00, z=0,58], com.google.common.util.concurrent.ListenableFutureTask@e404e4c}], context=Context["sponge:owner"=EntityPlayerMP['Lignium'/0, l='world', x=-0,54, y=64,00, z=0,58], "sponge:notifier"=EntityPlayerMP['Lignium'/0, l='world', x=-0,54, y=64,00, z=0,58], "sponge:used_item"=SpongeItemStackSnapshot{itemType=minecraft:stick, quantity=1}], handType=MAIN_HAND, interactionPoint=Optional[(-2.336925506591797, 64.0, 0.6462124586105347)], originalUseBlockResult=UNDEFINED, originalUseItemResult=UNDEFINED, source=EntityPlayerMP['Lignium'/0, l='world', x=-0,54, y=64,00, z=0,58], targetBlock=SpongeBlockSnapshot{worldUniqueId=8a2303f1-f006-4e0d-a866-8ffddde81fd6, position=(-3, 63, 0), blockState=minecraft:stone[variant=stone], extendedState=minecraft:stone[variant=stone]}, targetSide=UP, useBlockResult=UNDEFINED, useItemResult=UNDEFINED}

org.spongepowered.api.event.InteractBlockEvent$Secondary$OffHand$Impl
OffHand{cancelled=false, cause=Cause[Context=Context["sponge:owner"=EntityPlayerMP['Lignium'/0, l='world', x=-0,54, y=64,00, z=0,58], "sponge:notifier"=EntityPlayerMP['Lignium'/0, l='world', x=-0,54, y=64,00, z=0,58], "sponge:used_item"=SpongeItemStackSnapshot{itemType=minecraft:air, quantity=0}], Stack={EntityPlayerMP['Lignium'/0, l='world', x=-0,54, y=64,00, z=0,58], com.google.common.util.concurrent.ListenableFutureTask@2978b321}], context=Context["sponge:owner"=EntityPlayerMP['Lignium'/0, l='world', x=-0,54, y=64,00, z=0,58], "sponge:notifier"=EntityPlayerMP['Lignium'/0, l='world', x=-0,54, y=64,00, z=0,58], "sponge:used_item"=SpongeItemStackSnapshot{itemType=minecraft:air, quantity=0}], handType=OFF_HAND, interactionPoint=Optional[(-2.336925506591797, 64.0, 0.6462124586105347)], originalUseBlockResult=UNDEFINED, originalUseItemResult=UNDEFINED, source=EntityPlayerMP['Lignium'/0, l='world', x=-0,54, y=64,00, z=0,58], targetBlock=SpongeBlockSnapshot{worldUniqueId=8a2303f1-f006-4e0d-a866-8ffddde81fd6, position=(-3, 63, 0), blockState=minecraft:stone[variant=stone], extendedState=minecraft:stone[variant=stone]}, targetSide=UP, useBlockResult=UNDEFINED, useItemResult=UNDEFINED}

My conclusion:

Left button to air: Missing context. Right button to air: Does not fired. Perhaps also there is no context. Left button to block: Missing data about used item. Right button to block: Fired SECONDARY event with full data. However, also fired SECONDARY event of the off hand.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 1
  • Comments: 31 (27 by maintainers)

Commits related to this issue

Most upvoted comments

Only now I noticed that InteractBlockEvent.Primary.MainHand has block_hit context that is not equal to BlockSnapshot.NONE when a player left clicks to air.

Already 8 months have passed, but bugs with these two events are still not fixed. I can’t make a properly working wand to highlight regions (similar to WorldEdit), but with 2 additional functions when air clicks. I am already losing hope that this issue will ever be closed.

@GreWeMa Open an issue with the steps to reproduce your issue. (minimal code snippet + instructions).

@Lignium Keeping in mind that orange is working as intended, ListenableFutureTask can be ignored, is there anything else which is not working ?

@ImMorpheus, thanks for the work and time spent but unfortunately there are still shortcomings…

The conditions of the experiment are the same. In the main hand a stick.

  • Red - Missing the data.
  • Orange - An event wasn’t fired. (I understand that this has already been discussed)
  • Violet - Missing the data. I think InteractBlockEvent must containing block hit in the context.
  • Green - Instead of the intersection point with a block - the coordinates of this block.
  • Blue - Invalid the data. InteractItemEvent always contained none and empty for block hit and interaction point data respectively.

What about the “orange” problem? Will it ever be fixed in the future or will it remain as a feature?

interaction

Yes, the right click on block is not a bug and is working as intended.