Skip to content

Commit d1fda1e

Browse files
fix: #294
1 parent fc69da7 commit d1fda1e

File tree

8 files changed

+32
-13
lines changed

8 files changed

+32
-13
lines changed

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
runs-on: ubuntu-latest
1111
steps:
1212
- uses: actions/checkout@v2
13-
- name: Set up JDK 17
13+
- name: Set up JDK
1414
uses: actions/setup-java@v2
1515
with:
1616
java-version: '21'

CHANGELOG.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
## [86.0.0]
1+
## [21.0.1]
22

3-
### Changed
3+
### Fixed
44

5-
- Updated to 1.20.6 for NeoForge
5+
- Crashing when certain mods cause block names to comeback as null

build.gradle

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,3 @@ sourceSets.each {
133133
it.output.resourcesDir = dir
134134
it.java.destinationDirectory = dir
135135
}
136-
137-
tasks.register("idePostSync") {
138-
139-
}

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ neogradle.subsystems.parchment.mappingsVersion=2024.06.02
88

99

1010
mod_id=xray
11-
mod_version=21.0.0
11+
mod_version=21.0.1
1212
minecraft_version=1.21
1313
minecraft_version_range=[%base],1.21.1
1414

src/main/java/pro/mikey/xray/Utils.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package pro.mikey.xray;
22

3+
import net.minecraft.network.chat.Component;
34
import net.minecraft.resources.ResourceLocation;
5+
import net.minecraft.world.item.ItemStack;
6+
import org.jetbrains.annotations.Nullable;
47

58
public class Utils {
69
public static ResourceLocation rl(String path) {
@@ -10,4 +13,22 @@ public static ResourceLocation rl(String path) {
1013
public static ResourceLocation rlFull(String namespaceAndPath) {
1114
return ResourceLocation.tryParse(namespaceAndPath);
1215
}
16+
17+
public static Component safeItemStackName(ItemStack stack) {
18+
try {
19+
@Nullable var hoverName = stack.getHoverName();
20+
if (hoverName != null) {
21+
return hoverName;
22+
}
23+
24+
var displayName = stack.getDisplayName();
25+
if (displayName != null) {
26+
return displayName;
27+
}
28+
29+
return Component.translatable(stack.getDescriptionId());
30+
} catch (Exception e) {
31+
return Component.literal("Unknown...");
32+
}
33+
}
1334
}

src/main/java/pro/mikey/xray/gui/GuiSelectionScreen.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public void init() {
9797

9898
// Check if the hand item is a block or not
9999
if (!(handItem.getItem() instanceof BlockItem)) {
100-
getMinecraft().player.displayClientMessage(Component.literal("[XRay] " + I18n.get("xray.message.invalid_hand", handItem.getHoverName().getString())), false);
100+
getMinecraft().player.displayClientMessage(Component.literal("[XRay] " + I18n.get("xray.message.invalid_hand", Utils.safeItemStackName(handItem).getString())), false);
101101
return;
102102
}
103103

src/main/java/pro/mikey/xray/gui/manage/BlockListScreen.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import net.minecraft.network.chat.Component;
1111
import net.minecraft.resources.ResourceLocation;
1212
import pro.mikey.xray.ClientController;
13+
import pro.mikey.xray.Utils;
1314
import pro.mikey.xray.gui.GuiSelectionScreen;
1415
import pro.mikey.xray.gui.utils.GuiBase;
1516
import pro.mikey.xray.store.GameBlockStore;
@@ -62,10 +63,10 @@ private void reloadBlocks() {
6263
return;
6364

6465
this.blockList.updateEntries(
65-
search.getValue().length() == 0
66+
search.getValue().isEmpty()
6667
? this.blocks
6768
: this.blocks.stream()
68-
.filter(e -> e.getItemStack().getHoverName().getString().toLowerCase().contains(search.getValue().toLowerCase()))
69+
.filter(e -> Utils.safeItemStackName(e.getItemStack()).getString().toLowerCase().contains(search.getValue().toLowerCase()))
6970
.collect(Collectors.toList())
7071
);
7172

src/main/java/pro/mikey/xray/gui/manage/GuiEdit.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import net.neoforged.neoforge.client.gui.widget.ExtendedSlider;
99
import org.apache.commons.lang3.tuple.Pair;
1010
import pro.mikey.xray.ClientController;
11+
import pro.mikey.xray.Utils;
1112
import pro.mikey.xray.gui.GuiSelectionScreen;
1213
import pro.mikey.xray.gui.utils.GuiBase;
1314
import pro.mikey.xray.utils.BlockData;
@@ -89,7 +90,7 @@ public void tick() {
8990

9091
@Override
9192
public void renderExtra(GuiGraphics graphics, int x, int y, float partialTicks) {
92-
graphics.drawString(font, this.block.getItemStack().getHoverName().getString(), getWidth() / 2 - 138, getHeight() / 2 - 90, 0xffffff);
93+
graphics.drawString(font, Utils.safeItemStackName(this.block.getItemStack()).getString(), getWidth() / 2 - 138, getHeight() / 2 - 90, 0xffffff);
9394

9495
oreName.render(graphics, x, y, partialTicks);
9596

0 commit comments

Comments
 (0)