From 4cdc6d13622807e1c0f9ea228334aa0ddfc12cb7 Mon Sep 17 00:00:00 2001 From: FoundationGames <43485105+FoundationGames@users.noreply.github.com> Date: Fri, 18 Aug 2023 15:37:36 -0700 Subject: [PATCH] Fix potential server crash while constructing biome item names --- gradle.properties | 2 +- .../blocks/entity/container/screen/DesalinatorScreen.java | 4 ++-- .../io/github/foundationgames/sandwichable/util/Util.java | 6 ++++-- src/main/resources/assets/sandwichable/lang/en_us.json | 4 ++-- src/main/resources/assets/sandwichable/lang/zh_cn.json | 4 ++-- 5 files changed, 11 insertions(+), 9 deletions(-) diff --git a/gradle.properties b/gradle.properties index e87aba1..711b2de 100644 --- a/gradle.properties +++ b/gradle.properties @@ -7,7 +7,7 @@ loader_version=0.14.2 #Fabric api fabric_version=0.84.0+1.20.1 -mod_version = 1.3.1+1.20.1 +mod_version = 1.3.1.a+1.20.1 maven_group = io.github.foundationgames archives_base_name = sandwichable diff --git a/src/main/java/io/github/foundationgames/sandwichable/blocks/entity/container/screen/DesalinatorScreen.java b/src/main/java/io/github/foundationgames/sandwichable/blocks/entity/container/screen/DesalinatorScreen.java index 0dfe104..39d6110 100644 --- a/src/main/java/io/github/foundationgames/sandwichable/blocks/entity/container/screen/DesalinatorScreen.java +++ b/src/main/java/io/github/foundationgames/sandwichable/blocks/entity/container/screen/DesalinatorScreen.java @@ -37,8 +37,8 @@ public void render(DrawContext context, int mouseX, int mouseY, float delta) { this.drawMouseoverTooltip(context, mouseX, mouseY); if(waterTankBox.isMouseOver(mouseX, mouseY)) { List tooltip = Lists.newArrayList( - Text.literal(((DesalinatorBlockEntity) this.handler.inventory).getWaterAmount() +" B "+ I18n.translate("desalinator.tooltip.filled")), - Text.literal(I18n.translate("desalinator.tooltip.maxCapacity")+" "+DesalinatorBlockEntity.maxFluidAmount +" B") + Text.translatable("desalinator.tooltip.bucketsFilled", ((DesalinatorBlockEntity) this.handler.inventory).getWaterAmount()), + Text.translatable("desalinator.tooltip.bucketsMaxCapacity", DesalinatorBlockEntity.maxFluidAmount) ); if(this.getScreenHandler().inventory instanceof DesalinatorBlockEntity) { if(((DesalinatorBlockEntity)this.handler.inventory).getWaterAmount() > 0) { diff --git a/src/main/java/io/github/foundationgames/sandwichable/util/Util.java b/src/main/java/io/github/foundationgames/sandwichable/util/Util.java index 68ceea9..8fe9345 100644 --- a/src/main/java/io/github/foundationgames/sandwichable/util/Util.java +++ b/src/main/java/io/github/foundationgames/sandwichable/util/Util.java @@ -23,6 +23,7 @@ import net.minecraft.text.Text; import net.minecraft.util.Formatting; import net.minecraft.util.Identifier; +import net.minecraft.util.Language; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.random.Random; import net.minecraft.village.TradeOffers; @@ -149,8 +150,9 @@ public static int getSaltyWaterColor() { public static String biomeName(Identifier id) { var key = id.toTranslationKey("biome"); - if (I18n.hasTranslation(key)) { - return I18n.translate(key); + var lang = Language.getInstance(); + if (lang != null && lang.hasTranslation(key)) { + return lang.get(key); } var path = id.getPath(); diff --git a/src/main/resources/assets/sandwichable/lang/en_us.json b/src/main/resources/assets/sandwichable/lang/en_us.json index e91c218..f126ef9 100644 --- a/src/main/resources/assets/sandwichable/lang/en_us.json +++ b/src/main/resources/assets/sandwichable/lang/en_us.json @@ -197,8 +197,8 @@ "kitchen_knife.tooltip.items_cut": "Cuts %s items", "kitchen_knife.tooltip.items_cut_singular": "Cuts %s item", - "desalinator.tooltip.filled": "Filled", - "desalinator.tooltip.maxCapacity": "Max Capacity:", + "desalinator.tooltip.bucketsFilled": "%s B Filled", + "desalinator.tooltip.bucketsMaxCapacity": "Max Capacity: %s B", "desalinator.tooltip.saline": "Salinity Level HIGH", "desalinator.tooltip.notSaline": "Salinity Level LOW", "desalinator.tooltip.moveToSaltyBiome": "Please move to a saltwater area or biome!", diff --git a/src/main/resources/assets/sandwichable/lang/zh_cn.json b/src/main/resources/assets/sandwichable/lang/zh_cn.json index 4a378e0..36b775d 100644 --- a/src/main/resources/assets/sandwichable/lang/zh_cn.json +++ b/src/main/resources/assets/sandwichable/lang/zh_cn.json @@ -139,8 +139,8 @@ "cheese_culture_bottle.tooltip.uses": "剩余:%d/10", - "desalinator.tooltip.filled": "已装满", - "desalinator.tooltip.maxCapacity": "最大容量:", + "desalinator.tooltip.bucketsFilled": "%s B 已装满", + "desalinator.tooltip.bucketsMaxCapacity": "最大容量:%s B", "desalinator.tooltip.saline": "盐分含量:高", "desalinator.tooltip.notSaline": "盐分含量:低", "desalinator.tooltip.moveToSaltyBiome": "请移至咸水区域/生物群系!",