Skip to content

Commit

Permalink
hopefully fix #1120
Browse files Browse the repository at this point in the history
  • Loading branch information
TropheusJ committed Feb 14, 2024
1 parent b3dd5c2 commit fb322c8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
1 change: 1 addition & 0 deletions FABRIC_CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ Change logging starts below:
- fix schematic-printing deployers consuming double the resources they should (#1273)
- fix invalid auto-shapeless recipes from appearing in EMI (#1148)
- potential fix for a rare belt-related crash (#941)
- potential fix for errors/crashes due to a missing locale (#1120)
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
package com.simibubi.create.foundation;

import java.util.Collection;
import java.util.Set;

import com.simibubi.create.Create;
import com.simibubi.create.CreateClient;
import com.simibubi.create.content.kinetics.belt.BeltHelper;
import com.simibubi.create.foundation.sound.SoundScapes;
import com.simibubi.create.foundation.utility.LangNumberFormat;

import net.fabricmc.fabric.api.resource.IdentifiableResourceReloadListener;
import net.fabricmc.fabric.api.resource.ResourceReloadListenerKeys;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.packs.resources.ResourceManager;
import net.minecraft.server.packs.resources.ResourceManagerReloadListener;

public class ClientResourceReloadListener implements ResourceManagerReloadListener, IdentifiableResourceReloadListener {
public static final ResourceLocation ID = Create.asResource("client_reload_listener");
// fabric: make sure number format is updated after languages load
public static final Set<ResourceLocation> DEPENDENCIES = Set.of(ResourceReloadListenerKeys.LANGUAGES);

@Override
public void onResourceManagerReload(ResourceManager resourceManager) {
Expand All @@ -26,4 +32,9 @@ public void onResourceManagerReload(ResourceManager resourceManager) {
public ResourceLocation getFabricId() {
return ID;
}

@Override
public Collection<ResourceLocation> getFabricDependencies() {
return DEPENDENCIES;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.Locale;

import net.minecraft.client.Minecraft;
import net.minecraft.client.resources.language.LanguageInfo;
import net.minecraft.util.Mth;

public class LangNumberFormat {
Expand All @@ -16,10 +17,17 @@ public NumberFormat get() {
}

public void update() {
format = NumberFormat.getInstance(Minecraft.getInstance()
.getLanguageManager()
.getSelected()
.getJavaLocale());
LanguageInfo lang = Minecraft.getInstance()
.getLanguageManager()
.getSelected();
Locale locale = lang.getJavaLocale();

// fabric: clear error if this is somehow null.
if (locale == null) {
throw new IllegalStateException("LanguageInfo's javaLocale is null! info: " + lang);
}

format = NumberFormat.getInstance(locale);
format.setMaximumFractionDigits(2);
format.setMinimumFractionDigits(0);
format.setGroupingUsed(true);
Expand All @@ -33,4 +41,4 @@ public static String format(double d) {
.replace("\u00A0", " ");
}

}
}

0 comments on commit fb322c8

Please sign in to comment.