Skip to content

Commit

Permalink
fix: remove calls to loadLanguage
Browse files Browse the repository at this point in the history
  • Loading branch information
ROMVoid95 committed Sep 18, 2023
1 parent 8155f9d commit ff4ebbe
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 140 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -562,16 +562,6 @@ public void postInit(FMLPostInitializationEvent event)
GalacticraftCore.logger.error("Error initialising JPEG compressor - this is likely caused by OpenJDK - see https://wiki.micdoodle8.com/wiki/Compatibility#For_clients_running_OpenJDK");
e.printStackTrace();
}

if (event.getSide() == Side.SERVER)
{
this.loadLanguageCore("en_US");
}
}

public void loadLanguageCore(String lang)
{
GCCoreUtil.loadLanguage(lang, Constants.ASSET_PREFIX, this.GCCoreSource);
}

@EventHandler
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,17 +318,7 @@ public void postInit(FMLPostInitializationEvent event)
@Override
public void onResourceManagerReload(IResourceManager resourceManager, Predicate<IResourceType> resourcePredicate)
{
String lang = net.minecraft.client.Minecraft.getMinecraft().gameSettings.language;
GalacticraftCore.logger.debug("Reloading entity names for language " + lang);
if (lang == null)
{
lang = "en_us";
}
GalacticraftCore.instance.loadLanguageCore(lang);
if (!GCCoreUtil.langDisable)
{
GalacticraftPlanets.instance.loadLanguagePlanets(lang);
}
//NOOP
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,10 @@

package micdoodle8.mods.galacticraft.core.util;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.Random;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

import javax.annotation.Nullable;

import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
Expand All @@ -48,7 +31,6 @@
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.text.translation.I18n;
import net.minecraft.util.text.translation.LanguageMap;
import net.minecraft.world.World;
import net.minecraft.world.WorldProvider;
import net.minecraft.world.WorldServer;
Expand All @@ -66,8 +48,6 @@
import micdoodle8.mods.galacticraft.core.network.PacketSimple;
import micdoodle8.mods.galacticraft.core.network.PacketSimple.EnumSimplePacket;

import org.apache.commons.io.IOUtils;

/**
* Starting with Release 4.1.0 this class will be removed and all methods moved
* to a dedicated utility class. At this time all planned utility classes will
Expand Down Expand Up @@ -241,83 +221,6 @@ public static String lowerCaseNoun(String string)
return GCCoreUtil.translate(string).toLowerCase();
}

@Nullable
public static InputStream supplementEntityKeys(InputStream inputstream, String assetprefix) throws IOException
{
ArrayList<String> langLines = new ArrayList<>();
BufferedReader br = new BufferedReader(new InputStreamReader(inputstream, StandardCharsets.UTF_8));
String line;
String supplemented = "entity." + assetprefix.toLowerCase() + ".";

// TODO: We could also load en_US here and have any language keys not in
// the other lang set to the en_US value

while ((line = br.readLine()) != null)
{
line = line.trim();
if (!line.isEmpty())
{
langLines.add(line);
if (line.substring(0, 7).equals("entity."))
{
langLines.add(supplemented + line.substring(7));
}
}
}

ByteArrayOutputStream outputstream = new ByteArrayOutputStream();
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(outputstream, StandardCharsets.UTF_8.newEncoder()));
for (String outLine : langLines)
writer.write(outLine + "\n");
writer.close();

return new ByteArrayInputStream(outputstream.toByteArray());
}

public static void loadLanguage(String langIdentifier, String assetPrefix, File source)
{
if (!lastLang.equals(langIdentifier))
{
langDisable = false;
}
if (langDisable)
return;
String langFile = "assets/" + assetPrefix + "/lang/" + langIdentifier + ".lang";
InputStream stream = null;
ZipFile zip = null;
try
{
if (source.isDirectory() && (Boolean) Launch.blackboard.get("fml.deobfuscatedEnvironment"))
{
stream = new FileInputStream(new File(source.toURI().resolve(langFile).getPath()));
} else
{
zip = new ZipFile(source);
ZipEntry entry = zip.getEntry(langFile);
if (entry == null)
throw new FileNotFoundException();
stream = zip.getInputStream(entry);
}
LanguageMap.inject(GCCoreUtil.supplementEntityKeys(stream, assetPrefix));
} catch (FileNotFoundException fnf)
{
langDisable = true;
} catch (Exception ignore)
{
} finally
{
if (stream != null)
IOUtils.closeQuietly(stream);
try
{
if (zip != null)
zip.close();
} catch (IOException ignore)
{
}
}
}

public static int getDimensionID(World world)
{
return world.provider.getDimension();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,7 @@
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import micdoodle8.mods.galacticraft.api.vector.Vector3;
import micdoodle8.mods.galacticraft.core.Constants;
import micdoodle8.mods.galacticraft.core.tile.TileEntityDeconstructor;
import micdoodle8.mods.galacticraft.core.util.ConfigManagerCore;
import micdoodle8.mods.galacticraft.core.util.GCCoreUtil;
import micdoodle8.mods.galacticraft.core.util.GalacticLog;
import micdoodle8.mods.galacticraft.planets.asteroids.AsteroidsModule;
import micdoodle8.mods.galacticraft.planets.asteroids.ConfigManagerAsteroids;
import micdoodle8.mods.galacticraft.planets.datafix.GCPlanetsDataFixers;
import micdoodle8.mods.galacticraft.planets.mars.ConfigManagerMars;
import micdoodle8.mods.galacticraft.planets.mars.MarsModule;
import micdoodle8.mods.galacticraft.planets.venus.ConfigManagerVenus;
import micdoodle8.mods.galacticraft.planets.venus.VenusModule;

import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.config.ConfigElement;
import net.minecraftforge.common.config.Property;
Expand All @@ -43,7 +31,19 @@
import net.minecraftforge.fml.common.event.FMLServerStartingEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.network.NetworkRegistry;
import net.minecraftforge.fml.relauncher.Side;

import micdoodle8.mods.galacticraft.api.vector.Vector3;
import micdoodle8.mods.galacticraft.core.Constants;
import micdoodle8.mods.galacticraft.core.tile.TileEntityDeconstructor;
import micdoodle8.mods.galacticraft.core.util.ConfigManagerCore;
import micdoodle8.mods.galacticraft.core.util.GalacticLog;
import micdoodle8.mods.galacticraft.planets.asteroids.AsteroidsModule;
import micdoodle8.mods.galacticraft.planets.asteroids.ConfigManagerAsteroids;
import micdoodle8.mods.galacticraft.planets.datafix.GCPlanetsDataFixers;
import micdoodle8.mods.galacticraft.planets.mars.ConfigManagerMars;
import micdoodle8.mods.galacticraft.planets.mars.MarsModule;
import micdoodle8.mods.galacticraft.planets.venus.ConfigManagerVenus;
import micdoodle8.mods.galacticraft.planets.venus.VenusModule;

@Mod(modid = Constants.MOD_ID_PLANETS,
name = GalacticraftPlanets.NAME,
Expand Down Expand Up @@ -130,13 +130,6 @@ public void postInit(FMLPostInitializationEvent event)
{
GalacticraftPlanets.proxy.postInit(event);
TileEntityDeconstructor.initialiseRecipeListPlanets();
if (event.getSide() == Side.SERVER)
this.loadLanguagePlanets("en_US");
}

public void loadLanguagePlanets(String lang)
{
GCCoreUtil.loadLanguage(lang, GalacticraftPlanets.ASSET_PREFIX, GCPlanetsSource);
}

@EventHandler
Expand Down Expand Up @@ -212,7 +205,7 @@ public static void finishProp(Property prop, String currentCat)
{
if (propOrder.get(currentCat) == null)
{
propOrder.put(currentCat, new ArrayList<String>());
propOrder.put(currentCat, new ArrayList<>());
}
propOrder.get(currentCat).add(prop.getName());
}
Expand Down

0 comments on commit ff4ebbe

Please sign in to comment.