diff options
author | vicisacat <victor.branchu@gmail.com> | 2024-01-13 23:52:21 +0100 |
---|---|---|
committer | vicisacat <victor.branchu@gmail.com> | 2024-01-13 23:52:21 +0100 |
commit | d14554132ae518594f29ec7ba73bb4f46263e86e (patch) | |
tree | cb1f39a6921005219db97ee582de6db2d451ed85 /src/main/java/de/hysky/skyblocker/skyblock/dungeon/partyfinder | |
parent | b428d81a5ab0d6f858945eca236bbf562ae06593 (diff) | |
download | Skyblocker-d14554132ae518594f29ec7ba73bb4f46263e86e.tar.gz Skyblocker-d14554132ae518594f29ec7ba73bb4f46263e86e.tar.bz2 Skyblocker-d14554132ae518594f29ec7ba73bb4f46263e86e.zip |
Fixes and show Your Party at the top
- Lazy fix for if there is no party host
- Moved setting slot parse to the bottom row for loop
Diffstat (limited to 'src/main/java/de/hysky/skyblocker/skyblock/dungeon/partyfinder')
3 files changed, 83 insertions, 24 deletions
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/partyfinder/PartyEntry.java b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/partyfinder/PartyEntry.java index 84f450cc..d96922c8 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/partyfinder/PartyEntry.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/partyfinder/PartyEntry.java @@ -36,8 +36,8 @@ public class PartyEntry extends ElementListWidget.Entry<PartyEntry> { private static final Identifier PARTY_CARD_TEXTURE = new Identifier(SkyblockerMod.NAMESPACE, "textures/gui/party_card.png"); private static final Identifier PARTY_CARD_TEXTURE_HOVER = new Identifier(SkyblockerMod.NAMESPACE, "textures/gui/party_card_hover.png"); - private final PartyFinderScreen screen; - private final int slotID; + protected final PartyFinderScreen screen; + protected final int slotID; Player partyLeader; String floor = "???"; String dungeon = "???"; @@ -72,7 +72,8 @@ public class PartyEntry extends ElementListWidget.Entry<PartyEntry> { int membersIndex = -1; for (int i = 1; i < tooltips.size(); i++) { Text text = tooltips.get(i); - String tooltipText = text.getString(); + String tooltipText = Formatting.strip(text.getString()); + assert tooltipText != null; String lowerCase = tooltipText.toLowerCase(); //System.out.println("TOOLTIP"+i); //System.out.println(text.getSiblings()); @@ -143,11 +144,26 @@ public class PartyEntry extends ElementListWidget.Entry<PartyEntry> { if (playerNameTrim.equals(partyHost)) { partyLeader = player; j--; + } else if (j > 3) { + partyLeader = player; } else partyMembers[j] = player; } } - SkullBlockEntityAccessor.invokeFetchProfile(partyHost).thenAccept( + if (partyLeader == null) { + for (int i = partyMembers.length - 1; i >= 0; i--) { + if (partyMembers[i] != null) { + partyLeader = partyMembers[i]; + partyMembers[i] = null; + break; + } + } + } + if (partyLeader == null) { + partyLeader = new Player(Text.literal("Error"), "Error", -1); + } + + SkullBlockEntityAccessor.invokeFetchProfile(partyLeader.name.getString()).thenAccept( gameProfile -> gameProfile.ifPresent(profile -> partyLeaderSkin = client.getSkinProvider().getSkinTextures(profile).texture())); } @@ -167,13 +183,14 @@ public class PartyEntry extends ElementListWidget.Entry<PartyEntry> { matrices.push(); matrices.translate(x, y, 0); - if (hovered && !isLocked) context.drawTexture(PARTY_CARD_TEXTURE_HOVER, 0, 0, 0, 0, 336, 64, 336, 64); - else context.drawTexture(PARTY_CARD_TEXTURE, 0, 0, 0, 0, 336, 64, 336, 64); - + TextRenderer textRenderer = MinecraftClient.getInstance().textRenderer; + if (hovered && !isLocked) { + context.drawTexture(PARTY_CARD_TEXTURE_HOVER, 0, 0, 0, 0, 336, 64, 336, 64); + if (!(this instanceof YourParty)) context.drawText(textRenderer, Text.translatable("skyblocker.partyFinder.join"), 148, 6, 0xFFFFFFFF, false); + } else context.drawTexture(PARTY_CARD_TEXTURE, 0, 0, 0, 0, 336, 64, 336, 64); int mouseXLocal = mouseX - x; int mouseYLocal = mouseY - y; - TextRenderer textRenderer = MinecraftClient.getInstance().textRenderer; context.drawText(textRenderer, this.partyLeader.toText(), 18, 6, 0xFFFFFFFF, true); if (PartyFinderScreen.DEBUG) { @@ -229,9 +246,11 @@ public class PartyEntry extends ElementListWidget.Entry<PartyEntry> { @Override public boolean mouseClicked(double mouseX, double mouseY, int button) { - System.out.println("To be clicked" + slotID); - - if (button == 0 && !screen.isWaitingForServer()) { + //System.out.println("To be clicked" + slotID); + if (slotID == -1) { + PartyFinderScreen.LOGGER.error("[Skyblocker] Slot ID is null for " + partyLeader.name.getString() + "'s party"); + } + if (button == 0 && !screen.isWaitingForServer() && slotID != -1) { screen.clickAndWaitForServer(slotID); return true; } @@ -273,4 +292,30 @@ public class PartyEntry extends ElementListWidget.Entry<PartyEntry> { context.drawCenteredTextWithShadow(textRenderer, Text.translatable("skyblocker.partyFinder.noParties"), x+entryWidth/2, y+entryHeight/2-textRenderer.fontHeight/2, 0xFFFFFFFF); } } + + public static class YourParty extends PartyEntry { + + public YourParty(List<Text> tooltips, PartyFinderScreen screen, int deListSlotId) { + super(tooltips, screen, deListSlotId); + } + + @Override + public void render(DrawContext context, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta) { + MatrixStack matrices = context.getMatrices(); + matrices.push(); + matrices.translate(x, y, 0); + + hovered = hovered && slotID != -1; + + TextRenderer textRenderer = MinecraftClient.getInstance().textRenderer; + Text text; + if (hovered) { + text = Text.translatable("skyblocker.partyFinder.deList"); + } else text = Text.translatable("skyblocker.partyFinder.yourParty"); + context.drawText(textRenderer, text, 48, 6, 0x70000000, false); + + matrices.pop(); + super.render(context, index, y, x, entryWidth, entryHeight, mouseX, mouseY, hovered, tickDelta); + } + } } diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/partyfinder/PartyEntryListWidget.java b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/partyfinder/PartyEntryListWidget.java index de430ae5..0147f5da 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/partyfinder/PartyEntryListWidget.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/partyfinder/PartyEntryListWidget.java @@ -53,8 +53,9 @@ public class PartyEntryListWidget extends ElementListWidget<PartyEntry> { public void updateDisplay() { List<PartyEntry> entries = new ArrayList<>(partyEntries); - entries.removeIf(partyEntry -> !partyEntry.note.contains(search)); + entries.removeIf(partyEntry -> !partyEntry.note.contains(search) && !(partyEntry instanceof PartyEntry.YourParty)); entries.sort(Comparator.comparing(PartyEntry::isLocked)); + entries.sort(Comparator.comparing(partyEntry -> !(partyEntry instanceof PartyEntry.YourParty))); if (entries.isEmpty() && !partyEntries.isEmpty()) { entries.add(new PartyEntry.NoParties()); } diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/partyfinder/PartyFinderScreen.java b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/partyfinder/PartyFinderScreen.java index e7311073..3f4d2531 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/partyfinder/PartyFinderScreen.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/partyfinder/PartyFinderScreen.java @@ -343,30 +343,43 @@ public class PartyFinderScreen extends Screen { parties.add(new PartyEntry.NoParties()); }else { for (Slot slot : handler.slots) { - if (slot.id > handler.getRows() * 9 - 1 || !slot.hasStack()) continue; + if (slot.id > (handler.getRows()-1) * 9 - 1 || !slot.hasStack()) continue; if (slot.getStack().isOf(Items.PLAYER_HEAD)) { assert this.client != null; parties.add(new PartyEntry(slot.getStack().getTooltip(this.client.player, TooltipContext.BASIC), this, slot.id)); - } else if (slot.getStack().isOf(Items.NETHER_STAR)) { - settingsButtonSlotId = slot.id; - if (DEBUG) - settingsButton.setMessage(settingsButton.getMessage().copy().append(Text.of(" " + settingsButtonSlotId))); } } } - for (int i = (handler.getRows()-1) * 9; i < handler.getRows() * 9 - 1; i++) { + int deListSlotId = -1; + List<Text> tooltips = null; + for (int i = (handler.getRows()-1) * 9; i < handler.getRows() * 9; i++) { Slot slot = handler.slots.get(i); - int done = 0; - if (slot.hasStack() && slot.getStack().isOf(Items.EMERALD_BLOCK)) { + if (!slot.hasStack()) continue; + if (slot.getStack().isOf(Items.EMERALD_BLOCK)) { refreshSlotId = slot.id; refreshButton.active = true; - done += 1; - } else if (slot.hasStack() && slot.getStack().isOf(Items.REDSTONE_BLOCK)) { + } else if (slot.getStack().isOf(Items.REDSTONE_BLOCK)) { createPartyButtonSlotId = slot.id; createPartyButton.active = true; - done += 1; + } else if (slot.getStack().isOf(Items.NETHER_STAR)) { + settingsButtonSlotId = slot.id; + if (DEBUG) + settingsButton.setMessage(settingsButton.getMessage().copy().append(Text.of(" " + settingsButtonSlotId))); + } else if (slot.getStack().isOf(Items.BOOKSHELF)) { + deListSlotId = slot.id; + } else if (slot.getStack().isOf(Items.PLAYER_HEAD)) { + assert this.client != null; + tooltips = slot.getStack().getTooltip(this.client.player, TooltipContext.BASIC); } - if (done == 2) break; + } + if (tooltips != null) { + LOGGER.info("Your Party tooltips"); + tooltips.forEach(text -> LOGGER.info(text.toString())); + if (deListSlotId != -1) { + // Such a wacky thing lol + tooltips.set(0, Text.literal(MinecraftClient.getInstance().getSession().getUsername() + "'s party")); + } + parties.add(new PartyEntry.YourParty(tooltips, this, deListSlotId)); } this.partyEntryListWidget.setEntries(parties); List<ItemStack> temp = handler.slots.stream().map(Slot::getStack).toList(); |