MinecraftTransportSimulator icon indicating copy to clipboard operation
MinecraftTransportSimulator copied to clipboard

Added Custom Interaction Handlers to Interactable Parts

Open TechTastic opened this issue 2 months ago • 0 comments

So, as part of my addon, Computerized Vehicles, I wanted to add an onboard computer via an interactable part. Unfortunately, despite much trial and error, I did not succeed. So, I have made yet another PR to expand what IV/MTS can do for mod integration!

To do this in a way where it did not apply to just computer mods, I added the new InteractableComponentType.CUSTOM enum value and a new customInteractionHandler field that is only required when the interaction type is set to custom.

Within PartInteractable, I proceeded to add the new static CUSTOM_INTRACTION_HANDLERS field which is a Map<String, CustomInteractionHandler>. CustomInteractionHandler being a new nested interface with functions to be called. Inside the constructor, I expanded the switch statement to include the custom type and to call the CustomInteractionHandler specified by the JSON. Likewise, I did the same for interact. and finally, within remove, update, and save, I also implemented the necessary calls for CustomInteraction Handler.

So, for example, lets say Computerized Vehicles setup an CustomInteractionHandler like so:

PartInteractable.registerCustomInteractionHandler("computerized_vehicles:onboard_computer", new PartInteractable.CustomInteractionHandler {...})

To utilize this new handler, the interactable JSON section would contain this:

"interactable": {
    "interactionType": "custom",
    "customInteractionHandler": "computerized_vehicles:onboard_computer"
}

With this, not only can I add onboard CC: Tweaked computers to vehicles, but anyone wanting to add new interactables with custom behavior can as well!

TechTastic avatar Oct 17 '25 14:10 TechTastic