Advertisement
Guest User

Untitled

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