diff --git a/README.md b/README.md index 4a7eb41..ed00658 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,7 @@ Download World Handler or build from source # Expansion # The World Handler GUI can also be expanded with custom tabs configured with json and javascript files or as a separate child mod in java. -A description on how to implement a custom json and javascript file can be found [here](https://github.com/Exopandora/WorldHandler/blob/master/README.md) and an example child mod can be found [here](https://github.com/Exopandora/WorldHandlerPlugin). +A description on how to implement a custom json and javascript file can be found [here](./doc/Usercontent.md) and an example child mod can be found [here](https://github.com/Exopandora/WorldHandlerPlugin). # FAQ # diff --git a/curseforge.html b/curseforge.html index 1140de0..b1c31e7 100644 --- a/curseforge.html +++ b/curseforge.html @@ -112,7 +112,7 @@

Expansion

The World Handler GUI can also be expanded with custom tabs configured with json and javascript files or as a separate child mod written in java. - A description on how to implement a custom json and javascript file can be found here and an example child mod can be found here. + A description on how to implement a custom json and javascript file can be found here and an example child mod can be found here.

FAQ

    diff --git a/doc/Usercontent.md b/doc/Usercontent.md index 5639cd3..5a33a7b 100644 --- a/doc/Usercontent.md +++ b/doc/Usercontent.md @@ -14,7 +14,7 @@ Example setup for a custom GUI with id `example`: `../.minecraft/config/worldhandler/usercontent/example/example.json` `../.minecraft/config/worldhandler/usercontent/example/example.js` -An example GUI can be found [here](../../run/config/worldhandler/usercontent/) +An example GUI can be found [here](../run/config/worldhandler/usercontent/) # Index # diff --git a/run/config/worldhandler/usercontent/example/example.js b/run/config/worldhandler/usercontent/example/example.js new file mode 100644 index 0000000..df37718 --- /dev/null +++ b/run/config/worldhandler/usercontent/example/example.js @@ -0,0 +1,36 @@ +var ActionHelper = Java.type('exopandora.worldhandler.helper.ActionHelper'); + +var visible = true; +var enabled = true; + +function toggleVisibility() { + visible = !visible; +} + +function toggleEnabled() { + enabled = !enabled; +} + +function isVisible() { + return visible; +} + +function isEnabled() { + return enabled; +} + +function selected(arg) { + api.addChatMessage(arg); +} + +function updateText(arg) { + api.setCommandArgument(0, 4, arg); +} + +function openContent(arg) { + ActionHelper.open(arg); +} + +function addChatMessage(arg) { + api.addChatMessage(arg); +} \ No newline at end of file diff --git a/run/config/worldhandler/usercontent/example/example.json b/run/config/worldhandler/usercontent/example/example.json new file mode 100644 index 0000000..4acca22 --- /dev/null +++ b/run/config/worldhandler/usercontent/example/example.json @@ -0,0 +1,351 @@ +{ + "model": { + "commands": [ + { + "name": "example", + "syntax": [ + { + "name": "list_button", + "type": "resource_location", + "required": true + }, + { + "name": "page_list", + "type": "resource_location", + "default": "minecraft:air", + "required": false + }, + { + "name": "slider", + "type": "int", + "default": 0, + "required": false + }, + { + "name": "player", + "type": "player", + "required": false + }, + { + "name": "textfield", + "type": "string", + "required": false + } + ], + "visible": { + "type": "bool", + "bool": true + } + }, + { + "name": "example2", + "syntax": [ + { + "name": "arg1", + "type": "float", + "default": 0, + "required": true + } + ], + "visible": { + "type": "bool", + "bool": true + } + }, + { + "name": "example3", + "syntax": [ + { + "name": "arg1", + "type": "int", + "default": "0", + "required": false + } + ], + "visible": { + "type": "bool", + "bool": false + } + } + ] + }, + "gui": { + "title": "Example Title", + "tab": { + "title": "Example", + "category": "main", + "category_index": 3, + "active_content": "example" + }, + "buttons": [ + { + "text": "Button", + "type": "button", + "dimensions": { + "x": 0, + "y": 0, + "width": 114, + "height": 20 + }, + "action": { + "type": "js", + "attributes": { + "function": "addChatMessage", + "value": "Example message" + } + }, + "attributes": { + "visible": { + "type": "bool", + "bool": true + }, + "enabled": { + "type": "bool", + "bool": true + } + } + }, + { + "text": "Textfield", + "type": "textfield", + "action": { + "type": "js", + "attributes": { + "function": "updateText" + } + }, + "dimensions": { + "x": 0, + "y": 48, + "width": 114, + "height": 20 + }, + "attributes": { + "visible": { + "type": "js", + "function": "isVisible" + }, + "enabled": { + "type": "js", + "function": "isEnabled" + }, + "id": "textfield_id" + } + }, + { + "type": "item_button", + "action": { + "type": "run", + "attributes": { + "value": "/give @p minecraft:diamond_sword 1" + } + }, + "dimensions": { + "x": 0, + "y": 24, + "width": 20, + "height": 20 + }, + "attributes": { + "item": "minecraft:diamond_sword" + } + }, + { + "type": "icon_button", + "action": { + "type": "open", + "attributes": { + "value": "main" + } + }, + "dimensions": { + "x": 24, + "y": 24, + "width": 20, + "height": 20 + }, + "attributes": { + "icon": "home" + } + }, + { + "text": "ActionHelper", + "type": "button", + "action": { + "type": "js", + "attributes": { + "function": "openContent", + "value": "settings" + } + }, + "dimensions": { + "x": 48, + "y": 24, + "width": 66, + "height": 20 + }, + "attributes": { + "tooltip": "Opens Settings" + } + }, + { + "type": "list_button", + "action": { + "type": "set", + "attributes": { + "command": 0, + "index": 0 + } + }, + "dimensions": { + "x": 118, + "y": 72, + "width": 114, + "height": 20 + }, + "attributes": { + "items": [ + { + "id": "minecraft:grass", + "translation": "block.minecraft.grass" + }, + { + "id": "minecraft:stone", + "translation": "block.minecraft.stone" + }, + { + "id": "minecraft:dirt", + "translation": "block.minecraft.dirt" + }, + { + "id": "minecraft:cobblestone", + "translation": "block.minecraft.cobblestone" + } + ] + } + }, + { + "text": "Slider", + "type": "slider", + "action": { + "type": "set", + "attributes": { + "command": 0, + "index": 2 + } + }, + "dimensions": { + "x": 0, + "y": 96, + "width": 114, + "height": 20 + }, + "attributes": { + "id": "slider_id", + "min": 0.0, + "max": 100.0, + "start": 10.0 + } + }, + { + "text": "Visible", + "type": "button", + "action": { + "type": "js", + "attributes": { + "function": "toggleVisibility" + } + }, + "dimensions": { + "x": 0, + "y": 72, + "width": 56, + "height": 20 + }, + "attributes": { + "tooltip": "Toggle Visibility State" + } + }, + { + "text": "Enabled", + "type": "button", + "action": { + "type": "js", + "attributes": { + "function": "toggleEnabled" + } + }, + "dimensions": { + "x": 58, + "y": 72, + "width": 56, + "height": 20 + }, + "attributes": { + "tooltip": "Toggle Enabled State" + } + }, + { + "text": "gui.worldhandler.generic.backToGame", + "type": "button", + "action": { + "type": "back_to_game" + }, + "dimensions": { + "x": 118, + "y": 96, + "width": 114, + "height": 20 + } + } + ], + "elements": [ + { + "type": "page_list", + "dimensions": { + "x": 118, + "y": 0, + "width": 114, + "height": 20 + }, + "action": { + "type": "set", + "attributes": { + "command": 0, + "index": 1 + } + }, + "attributes": { + "id": "page_list", + "length": 2, + "items": [ + { + "id": "minecraft:grass", + "translation": "block.minecraft.grass" + }, + { + "id": "minecraft:stone", + "translation": "block.minecraft.stone" + }, + { + "id": "minecraft:dirt", + "translation": "block.minecraft.dirt" + }, + { + "id": "minecraft:cobblestone", + "translation": "block.minecraft.cobblestone" + } + ] + } + } + ], + "texts": [ + { + "text": "Text", + "x": 0, + "y": -11, + "color": 2039583 + } + ] + } +} \ No newline at end of file