Skip to content

Commit be6f2f6

Browse files
committed
fix: all spacing removed in tooltips
* fix broken translation in the config screen on 1.21-1.21.8
1 parent 71013a8 commit be6f2f6

4 files changed

Lines changed: 28 additions & 14 deletions

File tree

src/main/java/dev/ultimatchamp/enhancedtooltips/EnhancedTooltips.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424

2525
public class EnhancedTooltips {
2626
public static final String MOD_ID = "enhancedtooltips";
27-
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);
27+
public static final String MOD_NAME = "EnhancedTooltips";
28+
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_NAME);
2829

2930
public static void init() {
3031
EnhancedTooltipsConfig.load();

src/main/java/dev/ultimatchamp/enhancedtooltips/config/EnhancedTooltipsConfig.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -328,14 +328,14 @@ public static EnhancedTooltipsConfig load() {
328328

329329
try {
330330
if (!Files.exists(CONFIG_PATH)) {
331-
EnhancedTooltips.LOGGER.info("[EnhancedTooltips] Config file not found. Creating a new one...");
331+
EnhancedTooltips.LOGGER.info("[{}] Config file not found. Creating a new one...", EnhancedTooltips.MOD_NAME);
332332
config = new EnhancedTooltipsConfig();
333333
save(config);
334334
} else {
335335
var configContent = Files.readString(CONFIG_PATH).trim();
336336

337337
if (!configContent.startsWith("{") || !configContent.endsWith("}")) {
338-
EnhancedTooltips.LOGGER.error("[EnhancedTooltips] Config file is empty or invalid. Creating a new one...");
338+
EnhancedTooltips.LOGGER.error("[{}] Config file is empty or invalid. Creating a new one...", EnhancedTooltips.MOD_NAME);
339339
config = new EnhancedTooltipsConfig();
340340
save(config);
341341
} else {
@@ -344,7 +344,7 @@ public static EnhancedTooltipsConfig load() {
344344
}
345345
}
346346
} catch (IOException | SyntaxError e) {
347-
EnhancedTooltips.LOGGER.error("[EnhancedTooltips]", e);
347+
EnhancedTooltips.LOGGER.error("[{}]", EnhancedTooltips.MOD_NAME, e);
348348
config = new EnhancedTooltipsConfig();
349349
save(config);
350350
}
@@ -360,7 +360,7 @@ public static void save(EnhancedTooltipsConfig config) {
360360
Files.writeString(CONFIG_PATH, jsonString);
361361
cachedConfig = config;
362362
} catch (IOException e) {
363-
EnhancedTooltips.LOGGER.error("[EnhancedTooltips]", e);
363+
EnhancedTooltips.LOGGER.error("[{}]", EnhancedTooltips.MOD_NAME, e);
364364
}
365365
}
366366

@@ -376,12 +376,12 @@ private static JsonObject ensureDefaults(JsonObject configJson) {
376376
var defaultValue = field.get(defaultConfig);
377377

378378
if (!configJson.containsKey(fieldName)) {
379-
EnhancedTooltips.LOGGER.info("[EnhancedTooltips] Missing config field '{}'. Re-saving as default.", fieldName);
379+
EnhancedTooltips.LOGGER.info("[{}] Missing config field '{}'. Re-saving as default.", EnhancedTooltips.MOD_NAME, fieldName);
380380
configJson.put(fieldName, JANKSON.toJson(defaultValue));
381381
modified = true;
382382
}
383383
} catch (IllegalAccessException e) {
384-
EnhancedTooltips.LOGGER.error("[EnhancedTooltips] Failed to access field '{}'", field.getName(), e);
384+
EnhancedTooltips.LOGGER.error("[{}] Failed to access field '{}'", EnhancedTooltips.MOD_NAME, field.getName(), e);
385385
}
386386
}
387387

src/main/java/dev/ultimatchamp/enhancedtooltips/config/EnhancedTooltipsGui.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,13 @@ public static Screen createConfigScreen(Screen parent) {
6565
.group(OptionGroup.createBuilder()
6666
.name(Text.translatable("enhancedtooltips.config.popUpAnimation"))
6767
.option(Option.<Boolean>createBuilder()
68-
.name(Text.translatable("manageServer.resourcePack.enabled"))
68+
.name(Text.translatable(
69+
//? if >1.21.8 {
70+
"manageServer.resourcePack.enabled"
71+
//?} else {
72+
/*"addServer.resourcePack.enabled"
73+
*///?}
74+
))
6975
.description(OptionDescription.createBuilder()
7076
.text(Text.translatable("enhancedtooltips.config.popUpAnimation.desc"))
7177
.build())
@@ -104,7 +110,13 @@ public static Screen createConfigScreen(Screen parent) {
104110
.group(OptionGroup.createBuilder()
105111
.name(Text.translatable("enhancedtooltips.config.itemPreviewAnimation"))
106112
.option(Option.<Boolean>createBuilder()
107-
.name(Text.translatable("manageServer.resourcePack.enabled"))
113+
.name(Text.translatable(
114+
//? if >1.21.8 {
115+
"manageServer.resourcePack.enabled"
116+
//?} else {
117+
/*"addServer.resourcePack.enabled"
118+
*///?}
119+
))
108120
.description(OptionDescription.createBuilder()
109121
.text(Text.translatable("enhancedtooltips.config.itemPreviewAnimation.desc"))
110122
.build())

src/main/java/dev/ultimatchamp/enhancedtooltips/tooltip/EnhancedTooltipsDrawer.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ private static int getMaxWidth() {
3838
}
3939

4040
public static void drawTooltip(DrawContext context, TextRenderer textRenderer, List<TooltipComponent> components, int x, int y, TooltipPositioner positioner, ItemStack currentStack) {
41-
if (components.isEmpty() || currentStack.isEmpty()) {
41+
if (components == null || components.isEmpty() || currentStack.isEmpty()) {
4242
startTime = -1;
4343
lastStack = ItemStack.EMPTY;
4444
}
4545

46-
if (components.isEmpty()) return;
46+
if (components == null || components.isEmpty()) return;
4747

4848
if (!currentStack.isEmpty()) {
4949
if (lastStack.isEmpty() || !ItemStack.areEqual(lastStack, currentStack)) {
@@ -56,7 +56,8 @@ public static void drawTooltip(DrawContext context, TextRenderer textRenderer, L
5656

5757
TooltipBackgroundComponent backgroundComponent = getBackgroundComponent(components);
5858

59-
components.removeIf(component -> component.getHeight(/*? if >1.21.1 {*/textRenderer/*?}*/) == 0 || component.getWidth(textRenderer) == 0);
59+
if (components.size() > 1 && components.get(1).getWidth(textRenderer) == 0)
60+
components.remove(1);
6061

6162
MatricesUtil matrices = new MatricesUtil(context.getMatrices());
6263
List<TooltipPage> pageList = new ArrayList<>();
@@ -161,7 +162,7 @@ public static void drawTooltip(DrawContext context, TextRenderer textRenderer, L
161162
try {
162163
backgroundComponent.render(context, p.x, p.y, p.width, p.height, 400, pageList.indexOf(p));
163164
} catch (Exception e) {
164-
EnhancedTooltips.LOGGER.error("[EnhancedTooltips]", e);
165+
EnhancedTooltips.LOGGER.error("[{}]", EnhancedTooltips.MOD_NAME, e);
165166
}
166167
}
167168
}
@@ -186,7 +187,7 @@ public static void drawTooltip(DrawContext context, TextRenderer textRenderer, L
186187
cy += spacing;
187188
}
188189
} catch (Exception e) {
189-
EnhancedTooltips.LOGGER.error("[EnhancedTooltips]", e);
190+
EnhancedTooltips.LOGGER.error("[{}]", EnhancedTooltips.MOD_NAME, e);
190191
}
191192
}
192193
}

0 commit comments

Comments
 (0)