customstuff4 icon indicating copy to clipboard operation
customstuff4 copied to clipboard

Experimental scripting feature

Open Frontrider opened this issue 7 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

Can you remove everything from the pull request that isn't related to the scripting feature? You can do another pull request for the updated tests if you want. And definitely remove that code coverage report. It makes it harder to look at what actually changed and it's unnecessary to have that sort of thing in the repo.

You can find information on how to shade libraries here.

cubex2 avatar Apr 04 '18 12:04 cubex2

These are literally my first pull requests, and I'm still a bit "clunky" with this kind of stuff.

Thanks for the help.

Frontrider avatar Apr 04 '18 13:04 Frontrider

Found some issues with the behavior of the library (what I will not under any circumstance try to hack my way around), working on a proper fix.

Frontrider avatar Apr 07 '18 10:04 Frontrider