Sponge icon indicating copy to clipboard operation
Sponge copied to clipboard

EventContextKeys.PLAYER_PLACE is always included in InteractBlockEvent event context

Open ImMorpheus opened this issue 4 years ago • 0 comments

I am currently running

  • SpongeForge version: https://github.com/SpongePowered/SpongeForge/commit/272574e5da45bcc0c19e97e71d7dd985d1e158e5
  • Plugins/Mods: None

Issue Description API:

/**
 * Used when a {@link Player} places a block.
 */
public static final EventContextKey<World> PLAYER_PLACE = createFor("PLAYER_PLACE");

EventContextKeys.PLAYER_PLACE is always added during PlaceBlockPacketState and UseItemPacketState thus making developers unable to know if InteractBlockEvent is going to place a block.

Code to reproduce:

@Listener
public void onBlockChange(InteractBlockEvent.Secondary.MainHand event) {
    System.err.println(event.getContext());
}

Right click on a block of grass with an empty hand:

Context[
"sponge:owner"=EntityPlayerMP['Player198'/259, l='New World', x=-55.12, y=70.00, z=327.58], 
"sponge:player_place"=WorldServer{Name=New World, DimensionId=0, DimensionType=minecraft:overworld}, 
"sponge:used_hand"=MAIN_HAND, 
"sponge:block_hit"=SpongeBlockSnapshot{worldUniqueId=87c8201f-3002-4719-8640-7b6c887ae909, position=(-55, 69, 328), blockState=minecraft:grass[snowy=false], extendedState=minecraft:grass[snowy=false]}, 
"sponge:notifier"=EntityPlayerMP['Player198'/259, l='New World', x=-55.12, y=70.00, z=327.58], 
"sponge:used_item"=SpongeItemStackSnapshot{itemType=minecraft:air, quantity=0}
]

Right click on a block of grass with a bone:

Context[
"sponge:owner"=EntityPlayerMP['Player198'/259, l='New World', x=-56.90, y=70.00, z=328.09], 
"sponge:player_place"=WorldServer{Name=New World, DimensionId=0, DimensionType=minecraft:overworld}, 
"sponge:used_hand"=MAIN_HAND, 
"sponge:block_hit"=SpongeBlockSnapshot{worldUniqueId=87c8201f-3002-4719-8640-7b6c887ae909, position=(-57, 69, 329), blockState=minecraft:grass[snowy=false], extendedState=minecraft:grass[snowy=false]}, 
"sponge:notifier"=EntityPlayerMP['Player198'/259, l='New World', x=-56.90, y=70.00, z=328.09], 
"sponge:used_item"=SpongeItemStackSnapshot{itemType=minecraft:bone, quantity=30}
]

Right click on a block of grass with a block of dirt (this is correct, it's going to place a block and should have EventContextKeys.PLAYER_PLACE:

Context[
"sponge:owner"=EntityPlayerMP['Player198'/259, l='New World', x=-57.94, y=70.00, z=330.59], 
"sponge:player_place"=WorldServer{Name=New World, DimensionId=0, DimensionType=minecraft:overworld}, 
"sponge:used_hand"=MAIN_HAND, 
"sponge:block_hit"=SpongeBlockSnapshot{worldUniqueId=87c8201f-3002-4719-8640-7b6c887ae909, position=(-59, 70, 331), blockState=minecraft:dirt[snowy=false,variant=dirt], extendedState=minecraft:dirt[snowy=false,variant=dirt]}, 
"sponge:notifier"=EntityPlayerMP['Player198'/259, l='New World', x=-57.94, y=70.00, z=330.59], 
"sponge:used_item"=SpongeItemStackSnapshot{itemType=minecraft:dirt, quantity=35}
]

ImMorpheus avatar Mar 18 '20 21:03 ImMorpheus