Skip to content

Instantly share code, notes, and snippets.

@Commoble
Created December 13, 2020 18:40
Show Gist options
  • Save Commoble/1c52d985a714ea304c70a9885882f516 to your computer and use it in GitHub Desktop.
Save Commoble/1c52d985a714ea304c70a9885882f516 to your computer and use it in GitHub Desktop.
Minecraft Forge on-right-click-block logic flow
RIGHT CLICK BLOCK LOGIC FLOW -- SERVER THREAD (after interaction packet is received by server)
fire RightClickBlock event
if event is canceled, return the cancellation's action result type
if gametype is SPECTATOR, attempt to open the ContainerBlock container of the clicked block
return SUCCESS if block had a container, PASS otherwise
if event.getUseItem() is NOT DENIED, call ItemStack::onItemUseFirst (which usually delegates to Item::onItemUseFirst)
if the result of this is not PASS, return that result
if event.getUseBlock() is NOT DENIED and if sneaking isn't active or relevant for either of the player's held items
// sneaking isn't considered relevant if the item is air or returns true for IForgeItem::doesSneakBypassUse
// doesSneakBypassUse returns false for all vanilla items
run BlockState::onBlockActivated for the clicked block
if the result of this is SUCCESS or CONSUME, fire advancement trigger and return that result
if the input itemstack is empty or is on cooldown, return PASS
if event.getUseItem() is DENIED, return PASS
run ItemStack::onItemUse
if we are in creative mode, revert the itemstack's stack size afterward
if the result of onItemUse is SUCCESS or CONSUME, fire advancement trigger
return the result of onItemUse
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment