Advertisement
Rain_Effect

CustomGui Helper[1.12.2] v1.0

Jun 22nd, 2020
5,190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var Menus = [
  2.     { // ID: 0
  3.         Setting: {
  4.             Width: 250,
  5.             Height: 150,
  6.             Pause: false,
  7.             Texture: "minecraft:textures/gui/demo_background.png"
  8.         },
  9.         Childs: [
  10.             {
  11.                 Type: 0, // Label
  12.                 Text: "First menu",
  13.                 PosX: 105,
  14.                 PosY: 10,
  15.                 Width: 40,
  16.                 Height: 16,
  17.                 Color: 0xFF0000 // Optional param
  18.             },
  19.             {
  20.                 Type: 1, // Button & TexturedButton
  21.                 Text: "Teleport Spawn",
  22.                 PosX: 95,
  23.                 PosY: 130,
  24.                 Width: 60, // Optional param
  25.                 Height: 15, // Optional param
  26.                 func: function(e){
  27.                     e.player.setPos(e.player.spawnPoint.pos);
  28.                     e.player.closeGui();
  29.                 }
  30.             },
  31.             {
  32.                 Type: 1,
  33.                 Text: "",
  34.                 PosX: 5,
  35.                 PosY: 5,
  36.                 Width: 20,
  37.                 Height: 20,
  38.                 Texture: "minecraft:textures/gui/widgets.png",
  39.                 TextureX: 0,
  40.                 TextureY: 106,
  41.                 HoverText: ["Join \"CNPC scripting\"", "Learn More Script!", "Click to link"],
  42.                 func: function(e){
  43.                     e.player.message("\"CNPC scripting\" Discord: https://discord.gg/2jZm88M");
  44.                     e.player.closeGui();
  45.                 }
  46.             },
  47.             {
  48.                 Type: 2, // TexturedRect
  49.                 Texture: "minecraft:textures/painting/paintings_kristoffer_zetterstrand.png",
  50.                 PosX: 20,
  51.                 PosY: 30,
  52.                 Width: 64,
  53.                 Height: 48,
  54.                 TextureX: 192,
  55.                 TextureY: 112
  56.             }
  57.         ]
  58.     }
  59. ];
  60.  
  61. function interact(e){
  62.     if(e.type == 0 && e.player.mainhandItem.name == "minecraft:clock"){
  63.         showMenu(e, 0);
  64.     }
  65. }
  66.  
  67. function showMenu(e, id){
  68.     var Menu = Menus[0];
  69.     var UI = e.API.createCustomGui(id, Menu.Setting.Width, Menu.Setting.Height, Menu.Setting.Pause);
  70.     UI.setBackgroundTexture(Menu.Setting.Texture);
  71.     var Childs = Menu.Childs;
  72.     for(var i = 0; i < Childs.length; i++){
  73.         switch(Childs[i].Type){
  74.             case 0:
  75.                 var Child = UI.addLabel(i, Childs[i].Text, Childs[i].PosX, Childs[i].PosY, Childs[i].Width, Childs[i].Height, Childs[i].Color);
  76.                 break;
  77.             case 1:
  78.                 if(Childs[i].Texture){
  79.                     UI.addTexturedButton(i, Childs[i].Text, Childs[i].PosX, Childs[i].PosY, Childs[i].Width, Childs[i].Height, Childs[i].Texture, Childs[i].TextureX, Childs[i].TextureY)
  80.                 }else{
  81.                     var Child = UI.addButton(i, Childs[i].Text, Childs[i].PosX, Childs[i].PosY, Childs[i].Width, Childs[i].Height);
  82.                 }
  83.                 break;
  84.             case 2:
  85.                 var Child = UI.addTexturedRect(i, Childs[i].Texture, Childs[i].PosX, Childs[i].PosY, Childs[i].Width, Childs[i].Height, Childs[i].TextureX, Childs[i].TextureY);
  86.                 break;
  87.         }
  88.         if(Childs[i].HoverText) UI.getComponent(i).setHoverText(Childs[i].HoverText);
  89.     }
  90.    
  91.     e.player.showCustomGui(UI);
  92. }
  93.  
  94. function customGuiButton(e){
  95.     var Child = Menus[e.gui.ID].Childs[e.buttonId];
  96.     if(Child.func) Child.func(e);
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement