Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class TeleporterScreen extends AbstractContainerScreen<TeleporterMenu> {
- public static final ResourceLocation TEXTURE = new ResourceLocation(Constants.MOD_ID, "textures/gui/teleporter_gui.png");
- private final Player player;
- private float xMouse, yMouse;
- private int guiLeft, guiTop;
- private final int WIDTH = this.imageWidth;
- private final int HEIGHT = this.imageHeight;
- //private EditBox box;
- public TeleporterScreen(TeleporterMenu menu, Inventory inv, Component component) {
- super(menu, inv, component);
- this.player = inv.player;
- inventoryLabelY = -1000;
- guiLeft = (this.width - WIDTH) / 2;
- guiTop = (this.height - HEIGHT) / 2;
- }
- public void savePos(int q) {
- ItemStack item = menu.getBlockEntity().getItemFromSlot(0);
- CompoundTag tag = item.getTag();
- if(tag != null && tag.contains("hasInfo")) {
- String name = (!item.hasCustomHoverName()) ? "" : TotisPlayerUtils.getItemDisplayName(item);
- ModMessages.sendToServer(new PacketSyncTeleporter2S(q,
- tag.getInt("x"),tag.getInt("y"),tag.getInt("z"),
- q, true, tag.getString(Constants.DIMENSION), name, menu.getBlockEntity().getBlockPos()));
- } else {
- player.sendMessage(new TextComponent("No crystal found!"), player.getUUID());
- }
- }
- public void saveSelected(int q) {
- menu.getBlockEntity().setSelectedWheelPart(q);
- }
- @Override
- public boolean mouseClicked(double mousex, double mousey, int button) {
- int cx = (this.width - WIDTH) / 2;
- int cy = (this.height - HEIGHT) / 2;
- int q = getSelected(mousex,mousey,cx,cy);
- if(q != -1) {
- if(button == 0) { //left click
- savePos(q);
- player.playSound(SoundEvents.UI_BUTTON_CLICK, 1,1);
- } else if(button == 1) { //right click
- saveSelected(q);
- player.playSound(SoundEvents.UI_BUTTON_CLICK, 1,1);
- }
- }
- return super.mouseClicked(mousex, mousey, button);
- }
- @Override
- protected void renderLabels(PoseStack stack, int mousex, int mousey) {
- super.renderLabels(stack, mousex, mousey);
- int cx = (this.width - WIDTH) / 2;
- int cy = (this.height - HEIGHT) / 2;
- int q = getSelected(mousex,mousey,cx,cy);
- if(q != -1) {
- // IN EMPTY SPACE
- if(q == 0 || q == 1 ||q == 2 || q == 3 ||q == 4 || q == 5 ||q == 6 || q == 7) {
- if(q == 0 && menu.getBlockEntity().dest0exists) {
- renderTooltip(stack, List.of(new TextComponent(
- menu.getBlockEntity().dest0name +
- "\n" +
- ChatFormatting.BLUE + "Left click: " + ChatFormatting.RESET + "save crystal's pos in this space(consumes 1 crystal)" +
- "\n" +
- ChatFormatting.BLUE + "Right click: " + ChatFormatting.RESET + "select this destination to teleport")), Optional.empty(), mousex - cx, mousey - cy);
- }else if(q == 1 && menu.getBlockEntity().dest1exists) {
- renderTooltip(stack, List.of(new TextComponent(
- menu.getBlockEntity().dest1name +
- "\n" +
- ChatFormatting.BLUE + "Left click: " + ChatFormatting.RESET + "save crystal's pos in this space(consumes 1 crystal)" +
- "\n" +
- ChatFormatting.BLUE + "Right click: " + ChatFormatting.RESET + "select this destination to teleport")), Optional.empty(), mousex - cx, mousey - cy);
- }else if(q == 2 && menu.getBlockEntity().dest2exists) {
- renderTooltip(stack, List.of(new TextComponent(
- menu.getBlockEntity().dest2name +
- "\n" +
- ChatFormatting.BLUE + "Left click: " + ChatFormatting.RESET + "save crystal's pos in this space(consumes 1 crystal)" +
- "\n" +
- ChatFormatting.BLUE + "Right click: " + ChatFormatting.RESET + "select this destination to teleport")), Optional.empty(), mousex - cx, mousey - cy);
- }else if(q == 3 && menu.getBlockEntity().dest3exists) {
- renderTooltip(stack, List.of(new TextComponent(
- menu.getBlockEntity().dest3name +
- "\n" +
- ChatFormatting.BLUE + "Left click: " + ChatFormatting.RESET + "save crystal's pos in this space(consumes 1 crystal)" +
- "\n" +
- ChatFormatting.BLUE + "Right click: " + ChatFormatting.RESET + "select this destination to teleport")), Optional.empty(), mousex - cx, mousey - cy);
- }else if(q == 4 && menu.getBlockEntity().dest4exists) {
- renderTooltip(stack, List.of(new TextComponent(
- menu.getBlockEntity().dest4name +
- "\n" +
- ChatFormatting.BLUE + "Left click: " + ChatFormatting.RESET + "save crystal's pos in this space(consumes 1 crystal)" +
- "\n" +
- ChatFormatting.BLUE + "Right click: " + ChatFormatting.RESET + "select this destination to teleport")), Optional.empty(), mousex - cx, mousey - cy);
- }else if(q == 5 && menu.getBlockEntity().dest5exists) {
- renderTooltip(stack, List.of(new TextComponent(
- menu.getBlockEntity().dest5name +
- "\n" +
- ChatFormatting.BLUE + "Left click: " + ChatFormatting.RESET + "save crystal's pos in this space(consumes 1 crystal)" +
- "\n" +
- ChatFormatting.BLUE + "Right click: " + ChatFormatting.RESET + "select this destination to teleport")), Optional.empty(), mousex - cx, mousey - cy);
- }else if(q == 6 && menu.getBlockEntity().dest6exists) {
- renderTooltip(stack, List.of(new TextComponent(
- menu.getBlockEntity().dest6name +
- "\n" +
- ChatFormatting.BLUE + "Left click: " + ChatFormatting.RESET + "save crystal's pos in this space(consumes 1 crystal)" +
- "\n" +
- ChatFormatting.BLUE + "Right click: " + ChatFormatting.RESET + "select this destination to teleport")), Optional.empty(), mousex - cx, mousey - cy);
- }else if(q == 7 && menu.getBlockEntity().dest7exists) {
- renderTooltip(stack, List.of(new TextComponent(
- menu.getBlockEntity().dest7name +
- "\n" +
- ChatFormatting.BLUE + "Left click: " + ChatFormatting.RESET + "save crystal's pos in this space(consumes 1 crystal)" +
- "\n" +
- ChatFormatting.BLUE + "Right click: " + ChatFormatting.RESET + "select this destination to teleport")), Optional.empty(), mousex - cx, mousey - cy);
- } else {
- renderTooltip(stack, List.of(new TextComponent(
- ChatFormatting.BLUE + "Left click: " + ChatFormatting.RESET + "save crystal's pos in this space(consumes 1 crystal)" +
- "\n" +
- ChatFormatting.BLUE + "Right click: " + ChatFormatting.RESET + "select this destination to teleport")), Optional.empty(), mousex - cx, mousey - cy);
- }
- }
- }
- }
- private int getSelected(double mouseX, double mouseY, int cx, int cy) {
- if(TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+89,cy+12, 20,9) ||
- TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+89,cy+6, 6,6) ||
- TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+95,cy+7, 4,5) ||
- TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+99,cy+8, 3,4) ||
- TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+109,cy+13, 2,7) ||
- TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+111,cy+15, 2,3) ||
- TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+91,cy+21, 18,1) ||
- TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+97,cy+22, 10,2) ||
- TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+101,cy+24, 4,2)) {
- return 0;
- } else if(TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+110,cy+34, 15,9) ||
- TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+109,cy+24, 11,10) ||
- TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+112,cy+21, 6,3) ||
- TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+120,cy+29, 3,5) ||
- TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+106,cy+27, 3,5) ||
- TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+120,cy+27, 2,2)) {
- return 1;
- } else if(TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+109,cy+49, 12,14) ||
- TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+110,cy+45, 15,4) ||
- TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+121,cy+49, 3,7) ||
- TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+110,cy+63, 10,2) ||
- TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+112,cy+65, 6,2) ||
- TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+114,cy+67, 3,2) ||
- TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+106,cy+56, 3,5) ||
- TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+107,cy+54, 2,2) ||
- TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+121,cy+56, 2,3)) {
- return 2;
- } else if(TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+89,cy+66, 20,10) ||
- TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+89,cy+76, 16,2) ||
- TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+89,cy+78, 11,2) ||
- TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+98,cy+63, 8,3) ||
- TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+93,cy+65, 5,1) ||
- TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+101,cy+61, 3,2) ||
- TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+109,cy+68, 2,6) ||
- TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+111,cy+70, 2,3)) {
- return 3;
- } else if(TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+67,cy+66, 20,10) ||
- TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+75,cy+76, 12,4) ||
- TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+64,cy+69, 3,5) ||
- TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+60,cy+73, 7,3) ||
- TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+70,cy+76, 5,2) ||
- TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+78,cy+80, 9,1) ||
- TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+77,cy+65, 5,1) ||
- TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+72,cy+61, 2,2)) {
- return 4;
- } else if(TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+51,cy+45, 14,10) ||
- TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+53,cy+55, 16,5) ||
- TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+55,cy+60, 12,4) ||
- TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+57,cy+64, 7,3) ||
- TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+59,cy+67, 3,2) ||
- TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+65,cy+51, 2,4) ||
- TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+67,cy+60, 2,2) ||
- TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+69,cy+57, 1,3)) {
- return 5;
- } else if(TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+51,cy+33, 14,10) ||
- TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+55,cy+24, 12,9) ||
- TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+57,cy+21, 7,3) ||
- TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+59,cy+18, 2,3) ||
- TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+53,cy+27, 2,6) ||
- TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+67,cy+26, 2,6) ||
- TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+69,cy+28, 2,2) ||
- TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+65,cy+33, 2,4) ||
- TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+50,cy+36, 1,7)) {
- return 6;
- } else if(TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+71,cy+9, 16,12) ||
- TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+67,cy+12, 18,10) ||
- TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+80,cy+6, 7,3) ||
- TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+70,cy+22, 6,3) ||
- TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+64,cy+14, 3,5) ||
- TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+62,cy+15, 2,2) ||
- TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+77,cy+7, 3,2) ||
- TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+72,cy+25, 2,2) ||
- TotisScreenUtils.isMouseAboveArea(mouseX,mouseY, cx+76,cy+22, 2,2)) {
- return 7;
- } else {
- return -1;
- }
- }
- @Override
- public void init() {
- super.init();
- this.minecraft.keyboardHandler.setSendRepeatsToGui(true);
- }
- @Override
- protected void renderBg(PoseStack stack, float partialTick, int mouseX, int mouseY) {
- RenderSystem.setShader(GameRenderer::getPositionTexShader);
- RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
- RenderSystem.setShaderTexture(0, TEXTURE);
- int x = (this.width - WIDTH) / 2;
- int y = (this.height - HEIGHT) / 2;
- this.blit(stack, x, y, 0, 0, imageWidth + 26, imageHeight+20);
- }
- @Override
- public void render(PoseStack pPoseStack, int mouseX, int mouseY, float delta) {
- renderBackground(pPoseStack);
- super.render(pPoseStack, mouseX, mouseY, delta);
- renderTooltip(pPoseStack, mouseX, mouseY);
- this.xMouse = (float)mouseX;
- this.yMouse = (float)mouseY;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement