Interaction (v1.0.0)#

A small library that serves to enable easier usage of interaction entities.

Usage entails putting data on the interaction entity. Specifically, giving the interaction the smithed.interaction tag and then adding custom data in the entity's data field.

Usually, this is done by summoning the interaction with the relevant data like below:

summon minecraft:interaction ~ ~ ~ {
  Tags: ["smithed.interaction"],
  data: {
    smithed_interaction: {
      on_right_click: {
        command: "say hello world"
      }
    }
  }
}

However, you can also use /tag and /data to add the tag and data respectively if you wish.

Basics#

All actions are run as and at the interaction. You can re-target the player who interacted either by using execute on target ... for right click, or execute on attacker ... for left click. The player is also tagged with smithed.interaction.player if you'd prefer to use a target selector.

This library supports both right and left click interactions, with the data fields inside data.smithed_interaction being named on_right_click and on_left_click respectively.

Both of these support the following fields

  • command : String representing a valid command.

  • function : String representing a valid function resource location or # prefixed function tag resource location.

  • custom : A custom string representing a custom interaction type. This will run a function tag using the interaction type (right or left click) and this custom string.

Additionally, it is supported behaviour to utilize any combination of actions at the same time. They will run in the order Custom, Function, Command.

Custom Interactions#

Custom interactions exist as a shortcut for custom functionality without having to list out a full command or function location when summoning the interaction.

Built into this library is the sit custom interaction type, which will have the player sit "on" the interaction. (More information on this below)

Custom interaction types are tied to the interaction type (right or left click). For instance, the sit custom interaction is only supported for on_right_click.

These custom types will run a function tag using the interaction type and the custom string. For example, custom: "sit" runs the function tag #smithed.interaction:on_right_click/sit, located at data/smithed.interaction/tags/function/on_right_click/sit.json.

Read up on function tags on the Minecraft Wiki, if you're new to using them in this way.

custom: sit#

Example usage:

summon minecraft:interaction ~ ~ ~ {
  Tags: ["smithed.interaction"],
  data: {
    smithed_interaction: {
      on_right_click: {
        custom: "sit",
        height: 0.5
      }
    }
  }
}

With this custom type there is an optional height field like above. This represents the height above the origin of the interaction that the player will sit. When this field is not present, it will default to half of the interactions hit box height.

Technically, this is acheived by summoning an empty item display for the player to sit on. This is done due to players taking their vehicles with them when they log out and we dont want players to take the interaction itself with them.

A consequence of the player riding a detached item display is that moving the interaction does not move the player sitting on it. For this use-case, you can set this custom height field to "follow", which will have the player sit exactly at the interactions origin, but have the item display follow the interaction.