Advertisement
Guest User

Untitled

a guest
Feb 19th, 2023
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.34 KB | None | 0 0
  1. public class TeleporterScreen extends AbstractContainerScreen<TeleporterMenu> {
  2.  
  3. public static final ResourceLocation TEXTURE = new ResourceLocation(Constants.MOD_ID, "textures/gui/teleporter_gui.png");
  4.  
  5. private final Player player;
  6. private float xMouse, yMouse;
  7. private int guiLeft, guiTop;
  8. private final int WIDTH = this.imageWidth;
  9. private final int HEIGHT = this.imageHeight;
  10.  
  11. //private EditBox box;
  12.  
  13. public TeleporterScreen(TeleporterMenu menu, Inventory inv, Component component) {
  14. super(menu, inv, component);
  15. this.player = inv.player;
  16. inventoryLabelY = -1000;
  17. guiLeft = (this.width - WIDTH) / 2;
  18. guiTop = (this.height - HEIGHT) / 2;
  19. }
  20.  
  21. public void savePos(int q) {
  22. ItemStack item = menu.getBlockEntity().getItemFromSlot(0);
  23. CompoundTag tag = item.getTag();
  24. if(tag != null && tag.contains("hasInfo")) {
  25. String name = (!item.hasCustomHoverName()) ? "" : TotisPlayerUtils.getItemDisplayName(item);
  26. ModMessages.sendToServer(new PacketSyncTeleporter2S(q,
  27. tag.getInt("x"),tag.getInt("y"),tag.getInt("z"),
  28. q, true, tag.getString(Constants.DIMENSION), name, menu.getBlockEntity().getBlockPos()));
  29. } else {
  30. player.sendMessage(new TextComponent("No crystal found!"), player.getUUID());
  31. }
  32. }
  33. public void saveSelected(int q) {
  34. menu.getBlockEntity().setSelectedWheelPart(q);
  35. }
  36. @Override
  37. public boolean mouseClicked(double mousex, double mousey, int button) {
  38. int cx = (this.width - WIDTH) / 2;
  39. int cy = (this.height - HEIGHT) / 2;
  40. int q = getSelected(mousex,mousey,cx,cy);
  41.  
  42. if(q != -1) {
  43. if(button == 0) { //left click
  44. savePos(q);
  45. player.playSound(SoundEvents.UI_BUTTON_CLICK, 1,1);
  46. } else if(button == 1) { //right click
  47. saveSelected(q);
  48. player.playSound(SoundEvents.UI_BUTTON_CLICK, 1,1);
  49. }
  50. }
  51. return super.mouseClicked(mousex, mousey, button);
  52. }
  53.  
  54. @Override
  55. protected void renderLabels(PoseStack stack, int mousex, int mousey) {
  56. super.renderLabels(stack, mousex, mousey);
  57. int cx = (this.width - WIDTH) / 2;
  58. int cy = (this.height - HEIGHT) / 2;
  59. int q = getSelected(mousex,mousey,cx,cy);
  60.  
  61. if(q != -1) {
  62. // IN EMPTY SPACE
  63. if(q == 0 || q == 1 ||q == 2 || q == 3 ||q == 4 || q == 5 ||q == 6 || q == 7) {
  64. if(q == 0 && menu.getBlockEntity().dest0exists) {
  65. renderTooltip(stack, List.of(new TextComponent(
  66. menu.getBlockEntity().dest0name +
  67. "\n" +
  68. ChatFormatting.BLUE + "Left click: " + ChatFormatting.RESET + "save crystal's pos in this space(consumes 1 crystal)" +
  69. "\n" +
  70. ChatFormatting.BLUE + "Right click: " + ChatFormatting.RESET + "select this destination to teleport")), Optional.empty(), mousex - cx, mousey - cy);
  71. }else if(q == 1 && menu.getBlockEntity().dest1exists) {
  72. renderTooltip(stack, List.of(new TextComponent(
  73. menu.getBlockEntity().dest1name +
  74. "\n" +
  75. ChatFormatting.BLUE + "Left click: " + ChatFormatting.RESET + "save crystal's pos in this space(consumes 1 crystal)" +
  76. "\n" +
  77. ChatFormatting.BLUE + "Right click: " + ChatFormatting.RESET + "select this destination to teleport")), Optional.empty(), mousex - cx, mousey - cy);
  78. }else if(q == 2 && menu.getBlockEntity().dest2exists) {
  79. renderTooltip(stack, List.of(new TextComponent(
  80. menu.getBlockEntity().dest2name +
  81. "\n" +
  82. ChatFormatting.BLUE + "Left click: " + ChatFormatting.RESET + "save crystal's pos in this space(consumes 1 crystal)" +
  83. "\n" +
  84. ChatFormatting.BLUE + "Right click: " + ChatFormatting.RESET + "select this destination to teleport")), Optional.empty(), mousex - cx, mousey - cy);
  85. }else if(q == 3 && menu.getBlockEntity().dest3exists) {
  86. renderTooltip(stack, List.of(new TextComponent(
  87. menu.getBlockEntity().dest3name +
  88. "\n" +
  89. ChatFormatting.BLUE + "Left click: " + ChatFormatting.RESET + "save crystal's pos in this space(consumes 1 crystal)" +
  90. "\n" +
  91. ChatFormatting.BLUE + "Right click: " + ChatFormatting.RESET + "select this destination to teleport")), Optional.empty(), mousex - cx, mousey - cy);
  92. }else if(q == 4 && menu.getBlockEntity().dest4exists) {
  93. renderTooltip(stack, List.of(new TextComponent(
  94. menu.getBlockEntity().dest4name +
  95. "\n" +
  96. ChatFormatting.BLUE + "Left click: " + ChatFormatting.RESET + "save crystal's pos in this space(consumes 1 crystal)" +
  97. "\n" +
  98. ChatFormatting.BLUE + "Right click: " + ChatFormatting.RESET + "select this destination to teleport")), Optional.empty(), mousex - cx, mousey - cy);
  99. }else if(q == 5 && menu.getBlockEntity().dest5exists) {
  100. renderTooltip(stack, List.of(new TextComponent(
  101. menu.getBlockEntity().dest5name +
  102. "\n" +
  103. ChatFormatting.BLUE + "Left click: " + ChatFormatting.RESET + "save crystal's pos in this space(consumes 1 crystal)" +
  104. "\n" +
  105. ChatFormatting.BLUE + "Right click: " + ChatFormatting.RESET + "select this destination to teleport")), Optional.empty(), mousex - cx, mousey - cy);
  106. }else if(q == 6 && menu.getBlockEntity().dest6exists) {
  107. renderTooltip(stack, List.of(new TextComponent(
  108. menu.getBlockEntity().dest6name +
  109. "\n" +
  110. ChatFormatting.BLUE + "Left click: " + ChatFormatting.RESET + "save crystal's pos in this space(consumes 1 crystal)" +
  111. "\n" +
  112. ChatFormatting.BLUE + "Right click: " + ChatFormatting.RESET + "select this destination to teleport")), Optional.empty(), mousex - cx, mousey - cy);
  113. }else if(q == 7 && menu.getBlockEntity().dest7exists) {
  114. renderTooltip(stack, List.of(new TextComponent(
  115. menu.getBlockEntity().dest7name +
  116. "\n" +
  117. ChatFormatting.BLUE + "Left click: " + ChatFormatting.RESET + "save crystal's pos in this space(consumes 1 crystal)" +
  118. "\n" +
  119. ChatFormatting.BLUE + "Right click: " + ChatFormatting.RESET + "select this destination to teleport")), Optional.empty(), mousex - cx, mousey - cy);
  120. } else {
  121. renderTooltip(stack, List.of(new TextComponent(
  122. ChatFormatting.BLUE + "Left click: " + ChatFormatting.RESET + "save crystal's pos in this space(consumes 1 crystal)" +
  123. "\n" +
  124. ChatFormatting.BLUE + "Right click: " + ChatFormatting.RESET + "select this destination to teleport")), Optional.empty(), mousex - cx, mousey - cy);
  125. }
  126. }
  127. }
  128. }
  129.  
  130. private int getSelected(double mouseX, double mouseY, int cx, int cy) {
  131. if(TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+89,cy+12, 20,9) ||
  132. TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+89,cy+6, 6,6) ||
  133. TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+95,cy+7, 4,5) ||
  134. TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+99,cy+8, 3,4) ||
  135. TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+109,cy+13, 2,7) ||
  136. TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+111,cy+15, 2,3) ||
  137. TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+91,cy+21, 18,1) ||
  138. TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+97,cy+22, 10,2) ||
  139. TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+101,cy+24, 4,2)) {
  140. return 0;
  141. } else if(TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+110,cy+34, 15,9) ||
  142. TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+109,cy+24, 11,10) ||
  143. TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+112,cy+21, 6,3) ||
  144. TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+120,cy+29, 3,5) ||
  145. TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+106,cy+27, 3,5) ||
  146. TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+120,cy+27, 2,2)) {
  147. return 1;
  148. } else if(TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+109,cy+49, 12,14) ||
  149. TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+110,cy+45, 15,4) ||
  150. TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+121,cy+49, 3,7) ||
  151. TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+110,cy+63, 10,2) ||
  152. TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+112,cy+65, 6,2) ||
  153. TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+114,cy+67, 3,2) ||
  154. TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+106,cy+56, 3,5) ||
  155. TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+107,cy+54, 2,2) ||
  156. TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+121,cy+56, 2,3)) {
  157. return 2;
  158. } else if(TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+89,cy+66, 20,10) ||
  159. TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+89,cy+76, 16,2) ||
  160. TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+89,cy+78, 11,2) ||
  161. TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+98,cy+63, 8,3) ||
  162. TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+93,cy+65, 5,1) ||
  163. TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+101,cy+61, 3,2) ||
  164. TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+109,cy+68, 2,6) ||
  165. TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+111,cy+70, 2,3)) {
  166. return 3;
  167. } else if(TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+67,cy+66, 20,10) ||
  168. TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+75,cy+76, 12,4) ||
  169. TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+64,cy+69, 3,5) ||
  170. TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+60,cy+73, 7,3) ||
  171. TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+70,cy+76, 5,2) ||
  172. TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+78,cy+80, 9,1) ||
  173. TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+77,cy+65, 5,1) ||
  174. TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+72,cy+61, 2,2)) {
  175. return 4;
  176. } else if(TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+51,cy+45, 14,10) ||
  177. TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+53,cy+55, 16,5) ||
  178. TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+55,cy+60, 12,4) ||
  179. TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+57,cy+64, 7,3) ||
  180. TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+59,cy+67, 3,2) ||
  181. TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+65,cy+51, 2,4) ||
  182. TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+67,cy+60, 2,2) ||
  183. TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+69,cy+57, 1,3)) {
  184. return 5;
  185. } else if(TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+51,cy+33, 14,10) ||
  186. TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+55,cy+24, 12,9) ||
  187. TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+57,cy+21, 7,3) ||
  188. TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+59,cy+18, 2,3) ||
  189. TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+53,cy+27, 2,6) ||
  190. TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+67,cy+26, 2,6) ||
  191. TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+69,cy+28, 2,2) ||
  192. TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+65,cy+33, 2,4) ||
  193. TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+50,cy+36, 1,7)) {
  194. return 6;
  195. } else if(TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+71,cy+9, 16,12) ||
  196. TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+67,cy+12, 18,10) ||
  197. TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+80,cy+6, 7,3) ||
  198. TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+70,cy+22, 6,3) ||
  199. TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+64,cy+14, 3,5) ||
  200. TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+62,cy+15, 2,2) ||
  201. TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+77,cy+7, 3,2) ||
  202. TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+72,cy+25, 2,2) ||
  203. TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+76,cy+22, 2,2)) {
  204. return 7;
  205. } else {
  206. return -1;
  207. }
  208. }
  209. @Override
  210. public void init() {
  211. super.init();
  212. this.minecraft.keyboardHandler.setSendRepeatsToGui(true);
  213. }
  214.  
  215. @Override
  216. protected void renderBg(PoseStack stack, float partialTick, int mouseX, int mouseY) {
  217. RenderSystem.setShader(GameRenderer::getPositionTexShader);
  218. RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
  219. RenderSystem.setShaderTexture(0, TEXTURE);
  220.  
  221. int x = (this.width - WIDTH) / 2;
  222. int y = (this.height - HEIGHT) / 2;
  223.  
  224. this.blit(stack, x, y, 0, 0, imageWidth + 26, imageHeight+20);
  225. }
  226.  
  227. @Override
  228. public void render(PoseStack pPoseStack, int mouseX, int mouseY, float delta) {
  229. renderBackground(pPoseStack);
  230. super.render(pPoseStack, mouseX, mouseY, delta);
  231. renderTooltip(pPoseStack, mouseX, mouseY);
  232. this.xMouse = (float)mouseX;
  233. this.yMouse = (float)mouseY;
  234. }
  235. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement