Skip to content

Commit

Permalink
fix crash when removing spawn position
Browse files Browse the repository at this point in the history
  • Loading branch information
MelanX committed Apr 6, 2024
1 parent dd23bcf commit 963cdb6
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 12 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Expand Up @@ -19,7 +19,7 @@ dependencies {
annotationProcessor "org.moddingx:LibX:1.20.1-5.0.5"

implementation fg.deobf("org.moddingx:LibX:1.20.1-5.0.5")
implementation fg.deobf("de.melanx:SkyblockBuilder:1.20.1-5.0.5")
implementation fg.deobf("de.melanx:SkyblockBuilder:1.20.1-5.0.16")

runtimeOnly fg.deobf("mezz.jei:jei-1.20.1-forge:15.0.0.12")
}
Expand Up @@ -62,20 +62,15 @@ protected void init() {
Minecraft.getInstance().player.sendSystemMessage(ComponentBuilder.text("empty_templates").withStyle(ChatFormatting.BOLD, ChatFormatting.RED));
return;
}
String original = this.templates.get(this.currIndex);
String shortened = TextHelper.shorten(this.font, original, 110);
this.enableTooltip = !shortened.equals(original);
this.currTemplate = original;

String shortened = this.setCurrentTemplateAndGetShortenedName();
Button templateButton = Button.builder(Component.literal(shortened), button -> {
this.currIndex++;
if (this.currIndex >= this.templates.size()) {
this.currIndex = 0;
}

String orig = this.templates.get(this.currIndex);
String s = TextHelper.shorten(this.font, orig, 110);
this.enableTooltip = !s.equals(orig);
this.currTemplate = orig;
String s = this.setCurrentTemplateAndGetShortenedName();
button.setMessage(Component.literal(s));
})
.bounds(this.x(65), this.y(60), 122, 20)
Expand Down Expand Up @@ -103,6 +98,17 @@ protected void init() {
this.addRenderableWidget(Button.builder(ABORT, button -> this.onClose()).bounds(this.x(106), this.y(92), 60, 20).build());
}

private String setCurrentTemplateAndGetShortenedName() {
String orig = this.templates.get(this.currIndex);
String s = TextHelper.shorten(this.font, orig, 110);
//noinspection DataFlowIssue
String desc = TemplateLoader.getConfiguredTemplate(orig).getDescriptionComponent().getString();
this.enableTooltip = !s.equals(orig) || !desc.isBlank();
this.currTemplate = orig;

return s;
}

@Override
public void tick() {
this.name.tick();
Expand Down
Expand Up @@ -92,7 +92,7 @@ public void render_(@Nonnull GuiGraphics guiGraphics, int mouseX, int mouseY, fl

public void updateButtons() {
Set<UUID> selectedIds = this.getSelectedValues().stream().map(GameProfile::getId).collect(Collectors.toSet());
this.inviteButton.active = selectedIds.size() > 0;
this.inviteButton.active = !selectedIds.isEmpty();
this.selectAll.selected = this.allSelected();
this.selectedAmount = selectedIds.size();
}
Expand Down
Expand Up @@ -89,7 +89,7 @@ public void render_(@Nonnull GuiGraphics guiGraphics, int mouseX, int mouseY, fl

public void updateButtons() {
Set<UUID> selectedIds = this.getSelectedValues().stream().map(GameProfile::getId).collect(Collectors.toSet());
this.kickButton.active = selectedIds.size() > 0;
this.kickButton.active = !selectedIds.isEmpty();
this.selectAll.selected = this.allSelected();
this.selectedAmount = selectedIds.size();
}
Expand Down
Expand Up @@ -107,7 +107,7 @@ protected void init() {
this.removeButton = this.addRenderableWidget(Button.builder(REMOVE, button -> {
BlockPos removePos = this.getPos();
if (this.posValid && removePos != null) {
SkyGUIs.getNetwork().handleEditSpawns(EditSpawns.Type.REMOVE, removePos, null);
SkyGUIs.getNetwork().handleEditSpawns(EditSpawns.Type.REMOVE, removePos, Direction.UP);
//noinspection ConstantConditions
this.getLoadingCircle().setActive(true);
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/de/melanx/skyguis/network/EasyNetwork.java
Expand Up @@ -11,9 +11,11 @@
import org.moddingx.libx.mod.ModX;
import org.moddingx.libx.network.NetworkX;

import javax.annotation.ParametersAreNonnullByDefault;
import java.util.Set;
import java.util.UUID;

@ParametersAreNonnullByDefault
public class EasyNetwork extends NetworkX {

public EasyNetwork(ModX mod) {
Expand Down

0 comments on commit 963cdb6

Please sign in to comment.