customstuff4 icon indicating copy to clipboard operation
customstuff4 copied to clipboard

Experimental scripting feature

Open Frontrider opened this issue 6 years ago • 3 comments

The first version of a scripting option is ready, it currently can only handle a few events, and is uncomfortable to use.

What's ready:

  • scripts can be reloaded at runtime (/cs4reload)
  • scripts can log to console
  • include method will run the desired script, in the same context, whatever that script did will be available after the call.
  • ~~require method will get the "export" variable of a desired script.The script is evaluated in a clean context, than the function will return the variable named "export". There should be a better way to do this, but couldn't find one.~~
  • config option, to turn scripting on and off (it's off by default) -scripts sandboxed, they can not interact with the "outside" world (aka: call java, make java classes, create files, that sort of stuff), only via designated methods.

Events (they exist, so you can hook into something):

  • EntityItemPickupEvent
  • PlayerInteractEvent.RightClickBlock
  • PlayerInteractEvent.RightClickItem
  • PlayerInteractEvent.RightClickEmpty
  • LivingEntityUseItemEvent

Usage will change, currently you get the event object from Java/forge.(should definitely not be a a real thing)

Also, a library needs to be shadowed, but I'm not sure how those things work.

Crashing can be guaranteed, still refactoring stuff, but the functionality works.

Now I only need feedback.

Frontrider avatar Apr 04 '18 07:04 Frontrider