Nukkit icon indicating copy to clipboard operation
Nukkit copied to clipboard

Implement client behaviour packs

Open DasEtwas opened this issue 2 years ago • 6 comments

Overview

  • This PR enables the downloading of behavior packs.
  • It adds a new directory client_behavior_packs in the data folder.
  • Resource Packs belong in resource_packs as before, and Behavior Packs belong in client_behavior_packs
  • The server now checks if a pack is of the right type for the folder it is in by checking metadata.json:modules[n].type
  • For setting the scripting flag in the resource data info packet, the server now reads the zip's entry list and sets this flag to true is a file ending with .js was found

Motivation

  • Client-side behavior packs for normal minecraft worlds can now be used
  • By enabling the use of client-side behavior packs, plugin developers can now enhance their plugins using ScriptCustomEventPacket etc. to trigger client-side JavaScript (on Win10, where scripts are supported).

Testing

This PR was tested to work in the following cases (meaning players could join and download and display the packs):

  • One resource pack loaded
  • One behavior pack loaded
  • One resource pack and behavior pack loaded (tested on android and win)

furthermore:

  • requiresScripts() was tested to work by placing a .js file in a behavior pack

Problems

  • The newly added errors don't seem to print correctly, they print the translation keys instead, at least in my build. Submodules were cloned.

New language keys

nukkit.resources.unsupported-module-type
nukkit.resources.invalid-type-resource
nukkit.resources.invalid-type-behavior
nukkit.resources.loaded-resource-pack
nukkit.resources.loaded-behavior-pack

Further ideas

It may make sense to check if a client supports scripting, and if not, set scripting to false in the resource info packet.

DasEtwas avatar Aug 04 '21 17:08 DasEtwas

Please excuse @belohnung 's commits, they don't seem to affect my diff.

DasEtwas avatar Aug 04 '21 17:08 DasEtwas

Do you have an example behavior pack this can be tested with? Also maybe it could be a good idea to bump the API version.

PetteriM1 avatar Aug 26 '21 15:08 PetteriM1

Not one to post here.

DasEtwas avatar Aug 28 '21 03:08 DasEtwas

Behaviour packs is applies by client? I can create behaviour pack with changed stack size of, e.x. golden apple and it can be work?

ghost avatar Apr 11 '22 05:04 ghost

Behaviour packs is applies by client? I can create behaviour pack with changed stack size of, e.x. golden apple and it can be work?

This only supports client features and doesn't affect server logic.

belohnung avatar Apr 14 '22 04:04 belohnung

Is this still maintained or going to be tested?

snaildos avatar Dec 21 '22 05:12 snaildos