mirror of
https://github.com/HbmMods/Hbm-s-Nuclear-Tech-GIT.git
synced 2026-01-25 10:32:49 +00:00
Merge pull request #2371 from FOlkvangrField/Multilingual-Function-Repair
Fixed the multilingual feature failure error of the "QMAW" system
This commit is contained in:
commit
96793ec599
@ -1,9 +1,8 @@
|
||||
package com.hbm.config;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.*;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
@ -148,7 +147,7 @@ public class CustomMachineConfigJSON {
|
||||
public static void readConfig(File config) {
|
||||
|
||||
try {
|
||||
JsonObject json = gson.fromJson(new FileReader(config), JsonObject.class);
|
||||
JsonObject json = gson.fromJson(new InputStreamReader(Files.newInputStream(config.toPath()), StandardCharsets.UTF_8), JsonObject.class);
|
||||
JsonArray machines = json.get("machines").getAsJsonArray();
|
||||
|
||||
for(int i = 0; i < machines.size(); i++) {
|
||||
@ -182,32 +181,32 @@ public class CustomMachineConfigJSON {
|
||||
try {
|
||||
JsonArray recipeShape = machineObject.get("recipeShape").getAsJsonArray();
|
||||
JsonArray recipeParts = machineObject.get("recipeParts").getAsJsonArray();
|
||||
|
||||
|
||||
Object[] parts = new Object[recipeShape.size() + recipeParts.size()];
|
||||
|
||||
|
||||
for(int j = 0; j < recipeShape.size(); j++) {
|
||||
parts[j] = recipeShape.get(j).getAsString();
|
||||
}
|
||||
|
||||
|
||||
for(int j = 0; j < recipeParts.size(); j++) {
|
||||
Object o = null;
|
||||
|
||||
|
||||
if(j % 2 == 0) {
|
||||
o = recipeParts.get(j).getAsString().charAt(0); //god is dead and we killed him
|
||||
} else {
|
||||
AStack a = SerializableRecipe.readAStack(recipeParts.get(j).getAsJsonArray());
|
||||
|
||||
|
||||
if(a instanceof ComparableStack) o = ((ComparableStack) a).toStack();
|
||||
if(a instanceof OreDictStack) o = ((OreDictStack) a).name;
|
||||
}
|
||||
|
||||
|
||||
parts[j + recipeShape.size()] = o;
|
||||
}
|
||||
|
||||
|
||||
ItemStack stack = new ItemStack(ModBlocks.custom_machine, 1, i + 100);
|
||||
stack.stackTagCompound = new NBTTagCompound();
|
||||
stack.stackTagCompound.setString("machineType", configuration.unlocalizedName);
|
||||
|
||||
|
||||
CraftingManager.addRecipeAuto(stack, parts);
|
||||
} catch(Exception ex) {
|
||||
MainRegistry.logger.error("Caught exception trying to parse core recipe for custom machine " + configuration.unlocalizedName);
|
||||
|
||||
@ -1,9 +1,8 @@
|
||||
package com.hbm.inventory.fluid;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.*;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@ -35,7 +34,7 @@ import net.minecraft.potion.PotionEffect;
|
||||
public class Fluids {
|
||||
|
||||
public static final Gson gson = new Gson();
|
||||
|
||||
|
||||
public static List<IFluidRegisterListener> additionalListeners = new ArrayList();
|
||||
|
||||
public static FluidType NONE;
|
||||
@ -797,7 +796,7 @@ public class Fluids {
|
||||
private static void readCustomFluids(File file) {
|
||||
|
||||
try {
|
||||
JsonObject json = gson.fromJson(new FileReader(file), JsonObject.class);
|
||||
JsonObject json = gson.fromJson(new InputStreamReader(Files.newInputStream(file.toPath()), StandardCharsets.UTF_8), JsonObject.class);
|
||||
|
||||
for(Entry<String, JsonElement> entry : json.entrySet()) {
|
||||
|
||||
@ -879,12 +878,12 @@ public class Fluids {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void reloadFluids(){
|
||||
File folder = MainRegistry.configHbmDir;
|
||||
File customTypes = new File(folder.getAbsolutePath() + File.separatorChar + "hbmFluidTypes.json");
|
||||
if(!customTypes.exists()) initDefaultFluids(customTypes);
|
||||
|
||||
|
||||
for(FluidType type : customFluids){
|
||||
idMapping.remove(type.getID());
|
||||
registerOrder.remove(type);
|
||||
@ -892,7 +891,7 @@ public class Fluids {
|
||||
metaOrder.remove(type);
|
||||
}
|
||||
customFluids.clear();
|
||||
|
||||
|
||||
for(FluidType type : foreignFluids){
|
||||
idMapping.remove(type.getID());
|
||||
registerOrder.remove(type);
|
||||
@ -900,7 +899,7 @@ public class Fluids {
|
||||
metaOrder.remove(type);
|
||||
}
|
||||
foreignFluids.clear();
|
||||
|
||||
|
||||
readCustomFluids(customTypes);
|
||||
for(FluidType custom : customFluids) metaOrder.add(custom);
|
||||
File config = new File(MainRegistry.configHbmDir.getAbsolutePath() + File.separatorChar + "hbmFluidTraits.json");
|
||||
@ -911,7 +910,7 @@ public class Fluids {
|
||||
} else {
|
||||
readTraits(config);
|
||||
}
|
||||
|
||||
|
||||
for(IFluidRegisterListener listener : additionalListeners) listener.onFluidsLoad();
|
||||
}
|
||||
private static void registerCalculatedFuel(FluidType type, double base, double combustMult, FuelGrade grade) {
|
||||
|
||||
@ -23,7 +23,7 @@ import net.minecraft.util.ResourceLocation;
|
||||
public class GuiQMAW extends GuiScreen {
|
||||
|
||||
protected static final ResourceLocation texture = new ResourceLocation(RefStrings.MODID + ":textures/gui/gui_wiki.png");
|
||||
|
||||
|
||||
public String title;
|
||||
public String qmawID;
|
||||
public ItemStack icon;
|
||||
@ -31,51 +31,51 @@ public class GuiQMAW extends GuiScreen {
|
||||
/** History for returning via button */
|
||||
public List<String> back = new ArrayList();
|
||||
public List<String> forward = new ArrayList();
|
||||
|
||||
|
||||
protected int xSize = 340;
|
||||
protected int ySize = 224;
|
||||
protected int guiLeft;
|
||||
protected int guiTop;
|
||||
|
||||
|
||||
protected boolean isDragging = false;
|
||||
protected int scrollProgress = 0;
|
||||
protected int lastClickX = 0;
|
||||
protected int lastClickY = 0;
|
||||
|
||||
|
||||
public static final String EN_US = "en_US";
|
||||
|
||||
|
||||
public GuiQMAW(QuickManualAndWiki qmaw) {
|
||||
qmawID = qmaw.name;
|
||||
parseQMAW(qmaw);
|
||||
}
|
||||
|
||||
|
||||
protected void parseQMAW(QuickManualAndWiki qmaw) {
|
||||
LanguageManager lang = Minecraft.getMinecraft().getLanguageManager();
|
||||
|
||||
this.title = qmaw.title.get(lang.getCurrentLanguage());
|
||||
|
||||
this.title = qmaw.title.get(lang.getCurrentLanguage().getLanguageCode());
|
||||
if(title == null) this.title = qmaw.title.get(EN_US);
|
||||
if(title == null) this.title = "Missing Localization!";
|
||||
|
||||
|
||||
this.icon = qmaw.icon;
|
||||
|
||||
String toParse = qmaw.contents.get(lang.getCurrentLanguage());
|
||||
|
||||
String toParse = qmaw.contents.get(lang.getCurrentLanguage().getLanguageCode());
|
||||
if(toParse == null) toParse = qmaw.contents.get(EN_US);
|
||||
if(toParse == null) toParse = "Missing Localization!";
|
||||
toParse = "" + toParse; // strings are reference types, no?
|
||||
|
||||
|
||||
int maxLineLength = xSize - 29;
|
||||
String prevToParse = "" + toParse;
|
||||
int maxIterations = 1000;
|
||||
int currentLineWidth = 0;
|
||||
|
||||
|
||||
while(!toParse.isEmpty() && maxIterations > 0) {
|
||||
if(this.lines.isEmpty()) this.lines.add(new ArrayList());
|
||||
List<ManualElement> currentLine = this.lines.get(this.lines.size() - 1);
|
||||
|
||||
|
||||
toParse = toParse.trim();
|
||||
|
||||
|
||||
maxIterations--;
|
||||
|
||||
|
||||
if(toParse.startsWith("<br>")) {
|
||||
toParse = toParse.substring(4);
|
||||
currentLine = new ArrayList();
|
||||
@ -83,25 +83,25 @@ public class GuiQMAW extends GuiScreen {
|
||||
currentLineWidth = 0;
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
// handle links
|
||||
if(toParse.startsWith("[[")) {
|
||||
int end = toParse.indexOf("]]");
|
||||
if(end != -1) {
|
||||
String link = toParse.substring(2, end);
|
||||
toParse = toParse.substring(end + 2);
|
||||
|
||||
|
||||
int pipe = link.indexOf("|");
|
||||
QComponentLink linkComponent;
|
||||
|
||||
|
||||
String suffix = toParse.startsWith(" ") ? " " : "";
|
||||
|
||||
|
||||
if(pipe == -1) {
|
||||
linkComponent = new QComponentLink(link, link + suffix);
|
||||
} else {
|
||||
linkComponent = new QComponentLink(link.substring(pipe + 1, link.length()), link.substring(0, pipe) + suffix);
|
||||
}
|
||||
|
||||
|
||||
// append to current line
|
||||
int width = linkComponent.getWidth();
|
||||
if(width + currentLineWidth <= maxLineLength) {
|
||||
@ -119,21 +119,21 @@ public class GuiQMAW extends GuiScreen {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// handle standard text
|
||||
int delimit = toParse.length();
|
||||
|
||||
|
||||
int spaceIndex = toParse.indexOf(" ");
|
||||
if(spaceIndex != -1) delimit = Math.min(delimit, spaceIndex);
|
||||
int linkIndex = toParse.indexOf("[[");
|
||||
if(linkIndex != -1) delimit = Math.min(delimit, linkIndex);
|
||||
int brIndex = toParse.indexOf("<br>");
|
||||
if(brIndex != -1) delimit = Math.min(delimit, brIndex);
|
||||
|
||||
|
||||
if(delimit > 0) {
|
||||
QComponentText textComponent = new QComponentText(toParse.substring(0, delimit) + (spaceIndex == delimit ? " " : ""));
|
||||
toParse = toParse.substring(delimit);
|
||||
|
||||
|
||||
// append to current line
|
||||
int width = textComponent.getWidth();
|
||||
if(width + currentLineWidth <= maxLineLength) {
|
||||
@ -150,7 +150,7 @@ public class GuiQMAW extends GuiScreen {
|
||||
prevToParse = "" + toParse;
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if(toParse.equals(prevToParse)) break;
|
||||
prevToParse = "" + toParse;
|
||||
}
|
||||
@ -166,7 +166,7 @@ public class GuiQMAW extends GuiScreen {
|
||||
@Override
|
||||
protected void mouseClicked(int x, int y, int key) {
|
||||
super.mouseClicked(x, y, key);
|
||||
|
||||
|
||||
if(key == 0) {
|
||||
this.lastClickX = x;
|
||||
this.lastClickY = y;
|
||||
@ -175,10 +175,10 @@ public class GuiQMAW extends GuiScreen {
|
||||
if(guiLeft + 3 <= x && guiLeft + 3 + 18 > x && guiTop + 3 < y && guiTop + 3 + 18 >= y) back();
|
||||
if(guiLeft + 21 <= x && guiLeft + 21 + 18 > x && guiTop + 3 < y && guiTop + 3 + 18 >= y) forward();
|
||||
}
|
||||
|
||||
|
||||
public void back() {
|
||||
if(this.back.isEmpty()) return;
|
||||
|
||||
|
||||
String prev = back.get(back.size() - 1);
|
||||
|
||||
QuickManualAndWiki qmaw = QMAWLoader.qmaw.get(prev);
|
||||
@ -192,10 +192,10 @@ public class GuiQMAW extends GuiScreen {
|
||||
FMLCommonHandler.instance().showGuiScreen(screen);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void forward() {
|
||||
if(this.forward.isEmpty()) return;
|
||||
|
||||
|
||||
String next = forward.get(forward.size() - 1);
|
||||
|
||||
QuickManualAndWiki qmaw = QMAWLoader.qmaw.get(next);
|
||||
@ -209,7 +209,7 @@ public class GuiQMAW extends GuiScreen {
|
||||
FMLCommonHandler.instance().showGuiScreen(screen);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public int getSliderPosition() {
|
||||
double progress = (double) scrollProgress / (double) (lines.size() - 1);
|
||||
return 25 + (int) (progress * 180);
|
||||
@ -217,38 +217,38 @@ public class GuiQMAW extends GuiScreen {
|
||||
|
||||
@Override
|
||||
public void drawScreen(int mouseX, int mouseY, float f) {
|
||||
|
||||
|
||||
if(Mouse.isButtonDown(0) && guiLeft + xSize - 15 <= mouseX && guiLeft + xSize - 15 + 12 > mouseX && guiTop + 25 < mouseY && guiTop + 25 + 191 >= mouseY) {
|
||||
isDragging = true;
|
||||
}
|
||||
|
||||
|
||||
if(!Mouse.isButtonDown(0)) isDragging = false;
|
||||
|
||||
|
||||
if(isDragging) {
|
||||
int min = guiTop + 25 + 8;
|
||||
int max = guiTop + 25 + 191 - 8;
|
||||
int span = max - min;
|
||||
|
||||
|
||||
double progress = MathHelper.clamp_double((double) (mouseY - min) / span, 0D, 1D);
|
||||
this.scrollProgress = MathHelper.clamp_int((int) Math.round((lines.size() - 1) * progress), 0, lines.size() - 1);
|
||||
}
|
||||
|
||||
|
||||
handleScroll();
|
||||
|
||||
//this.drawRect(0, 0, this.width, this.height, 0x80919191);
|
||||
this.drawRect(0, 0, this.width, this.height, 0xe0000000);
|
||||
|
||||
|
||||
this.drawGuiContainerBackgroundLayer(f, mouseX, mouseY);
|
||||
GL11.glDisable(GL11.GL_LIGHTING);
|
||||
this.drawGuiContainerForegroundLayer(mouseX, mouseY);
|
||||
GL11.glEnable(GL11.GL_LIGHTING);
|
||||
|
||||
|
||||
this.lastClickX = 0;
|
||||
this.lastClickY = 0;
|
||||
}
|
||||
|
||||
|
||||
protected void handleScroll() {
|
||||
|
||||
|
||||
if(!Mouse.isButtonDown(0) && !Mouse.isButtonDown(1) && Mouse.next()) {
|
||||
int scroll = Mouse.getEventDWheel();
|
||||
if(scroll > 0 && this.scrollProgress > 0) this.scrollProgress--;
|
||||
@ -257,10 +257,10 @@ public class GuiQMAW extends GuiScreen {
|
||||
}
|
||||
|
||||
private void drawGuiContainerForegroundLayer(int mouseX, int mouseY) {
|
||||
|
||||
|
||||
int x = 43;
|
||||
int y = 4;
|
||||
|
||||
|
||||
if(this.icon != null) {
|
||||
GL11.glPushMatrix();
|
||||
GL11.glEnable(GL11.GL_DEPTH_TEST);
|
||||
@ -273,13 +273,13 @@ public class GuiQMAW extends GuiScreen {
|
||||
RenderHelper.disableStandardItemLighting();
|
||||
GL11.glDisable(GL11.GL_DEPTH_TEST);
|
||||
GL11.glPopMatrix();
|
||||
|
||||
|
||||
x += 18;
|
||||
y += (16 - this.fontRendererObj.FONT_HEIGHT) / 2;
|
||||
}
|
||||
|
||||
|
||||
y += 1;
|
||||
|
||||
|
||||
this.fontRendererObj.drawString(title, guiLeft + x, guiTop + y, 0xFFFFFF);
|
||||
}
|
||||
|
||||
@ -292,30 +292,30 @@ public class GuiQMAW extends GuiScreen {
|
||||
|
||||
if(!back.isEmpty()) drawTexturedModalRect(guiLeft + 3, guiTop + 3, 204, 0, 18, 18);
|
||||
if(!forward.isEmpty()) drawTexturedModalRect(guiLeft + 21, guiTop + 3, 222, 0, 18, 18);
|
||||
|
||||
|
||||
// scroll bar
|
||||
drawTexturedModalRect(guiLeft + xSize - 15, guiTop + getSliderPosition(), 192, 0, 12, 16);
|
||||
|
||||
|
||||
int x = guiLeft + 7;
|
||||
int y = guiTop + 30;
|
||||
int lineNum = 0;
|
||||
|
||||
|
||||
for(List<ManualElement> line : lines) {
|
||||
lineNum++;
|
||||
|
||||
|
||||
if(lineNum <= this.scrollProgress) continue;
|
||||
|
||||
|
||||
int maxHeight = 0;
|
||||
int inset = 0;
|
||||
|
||||
|
||||
for(ManualElement element : line) {
|
||||
maxHeight = Math.max(maxHeight, element.getHeight());
|
||||
}
|
||||
|
||||
|
||||
if(y + maxHeight > guiTop + 219) break;
|
||||
|
||||
|
||||
if(line.isEmpty()) y += this.fontRendererObj.FONT_HEIGHT;
|
||||
|
||||
|
||||
for(ManualElement element : line) {
|
||||
int elementX = x + inset;
|
||||
int elementY = y + (maxHeight - element.getHeight()) / 2;
|
||||
@ -325,7 +325,7 @@ public class GuiQMAW extends GuiScreen {
|
||||
element.onClick(this);
|
||||
inset += element.getWidth();
|
||||
}
|
||||
|
||||
|
||||
y += maxHeight + 2;
|
||||
}
|
||||
}
|
||||
@ -335,7 +335,7 @@ public class GuiQMAW extends GuiScreen {
|
||||
|
||||
if(keyCode == Keyboard.KEY_LEFT) back();
|
||||
if(keyCode == Keyboard.KEY_RIGHT) forward();
|
||||
|
||||
|
||||
if(keyCode == 1 || keyCode == this.mc.gameSettings.keyBindInventory.getKeyCode()) {
|
||||
this.mc.displayGuiScreen((GuiScreen) null);
|
||||
this.mc.setIngameFocus();
|
||||
|
||||
@ -1,9 +1,8 @@
|
||||
package com.hbm.qmaw;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.*;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
@ -47,7 +46,7 @@ public class QMAWLoader implements IResourceManagerReloadListener {
|
||||
init();
|
||||
MainRegistry.logger.info("[QMAW] Loaded " + qmaw.size() + " manual entries! (" + (System.currentTimeMillis() - timestamp) + "ms)");
|
||||
}
|
||||
|
||||
|
||||
/** For the like 2 people who might consider making an NTM addon and want to include manual pages. Requires the mod's actual JAR file as the parameter. */
|
||||
public static void registerModFileURL(File file) {
|
||||
registeredModFiles.add(file);
|
||||
@ -62,14 +61,14 @@ public class QMAWLoader implements IResourceManagerReloadListener {
|
||||
// exclude .class in the case of a dev env
|
||||
MainRegistry.logger.info("[QMAW] Current running file: " + path);
|
||||
if(!path.endsWith(".class")) registerModFileURL(new File(path)); // i am going to shit myself*/ // deactivated because it likely doesn't even fucking work
|
||||
|
||||
|
||||
// registering of the mod file now happens in the MainRegistry during preinit
|
||||
|
||||
|
||||
qmaw.clear();
|
||||
triggers.clear();
|
||||
agonyEngine();
|
||||
}
|
||||
|
||||
|
||||
/** "digital equivalent to holywater" yielded few results on google, if only i had the answer i would drown this entire class in it <br><br>
|
||||
* This affront to god can load QMAW definition files from four different sources:<br>
|
||||
* * Any mod's jar that has registered itself to include QMAW files<br>
|
||||
@ -78,12 +77,12 @@ public class QMAWLoader implements IResourceManagerReloadListener {
|
||||
* * Folder-based resource packs
|
||||
* */
|
||||
public static void agonyEngine() {
|
||||
|
||||
|
||||
for(File modFile : registeredModFiles) {
|
||||
logJarAttempt(modFile.getName());
|
||||
dissectZip(modFile);
|
||||
}
|
||||
|
||||
|
||||
File devEnvManualFolder = new File(Minecraft.getMinecraft().mcDataDir.getAbsolutePath().replace("/eclipse/.".replace('/', File.separatorChar), "") + "/src/main/resources/assets/hbm/manual".replace('/', File.separatorChar));
|
||||
if(devEnvManualFolder.exists() && devEnvManualFolder.isDirectory()) {
|
||||
MainRegistry.logger.info("[QMAW] Exploring " + devEnvManualFolder.getAbsolutePath());
|
||||
@ -91,17 +90,17 @@ public class QMAWLoader implements IResourceManagerReloadListener {
|
||||
}
|
||||
|
||||
ResourcePackRepository repo = Minecraft.getMinecraft().getResourcePackRepository();
|
||||
|
||||
|
||||
for(Object o : repo.getRepositoryEntries()) {
|
||||
ResourcePackRepository.Entry entry = (ResourcePackRepository.Entry) o;
|
||||
IResourcePack pack = entry.getResourcePack();
|
||||
|
||||
logPackAttempt(pack.getPackName());
|
||||
|
||||
|
||||
if(pack instanceof FileResourcePack) {
|
||||
dissectZip(((FileResourcePack) pack).resourcePackFile);
|
||||
}
|
||||
|
||||
|
||||
if(pack instanceof FolderResourcePack) {
|
||||
dissectFolder(((FolderResourcePack) pack).resourcePackFile);
|
||||
}
|
||||
@ -111,27 +110,27 @@ public class QMAWLoader implements IResourceManagerReloadListener {
|
||||
public static void logJarAttempt(String name) { MainRegistry.logger.info("[QMAW] Dissecting jar " + name); }
|
||||
public static void logPackAttempt(String name) { MainRegistry.logger.info("[QMAW] Dissecting resource " + name); }
|
||||
public static void logFoundManual(String name) { MainRegistry.logger.info("[QMAW] Found manual " + name); }
|
||||
|
||||
|
||||
/** You put your white gloves on, you get your hand in there, and then you iterate OVER THE ENTIRE FUCKING ZIP until we find things we deem usable */
|
||||
public static void dissectZip(File zipFile) {
|
||||
|
||||
|
||||
if(zipFile == null) {
|
||||
MainRegistry.logger.info("[QMAW] Pack file does not exist!");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
ZipFile zip = null;
|
||||
|
||||
|
||||
try {
|
||||
zip = new ZipFile(zipFile);
|
||||
Enumeration<? extends ZipEntry> enumerator = zip.entries();
|
||||
|
||||
|
||||
while(enumerator.hasMoreElements()) {
|
||||
ZipEntry entry = enumerator.nextElement();
|
||||
String name = entry.getName();
|
||||
if(name.startsWith("assets/hbm/manual/") && name.endsWith(".json")) {
|
||||
InputStream fileStream = zip.getInputStream(entry);
|
||||
InputStreamReader reader = new InputStreamReader(fileStream);
|
||||
InputStreamReader reader = new InputStreamReader(fileStream, StandardCharsets.UTF_8);
|
||||
try {
|
||||
JsonObject obj = (JsonObject) parser.parse(reader);
|
||||
String manName = name.replace("assets/hbm/manual/", "");
|
||||
@ -143,7 +142,7 @@ public class QMAWLoader implements IResourceManagerReloadListener {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} catch(Exception ex) {
|
||||
MainRegistry.logger.info("[QMAW] Error dissecting zip " + zipFile.getName() + ": " + ex);
|
||||
} finally {
|
||||
@ -152,13 +151,13 @@ public class QMAWLoader implements IResourceManagerReloadListener {
|
||||
} catch(Exception ex) { }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** Opens a resource pack folder, skips to the manual folder, then tries to dissect that */
|
||||
public static void dissectFolder(File folder) {
|
||||
File manualFolder = new File(folder, "/assets/hbm/manual");
|
||||
if(manualFolder.exists() && manualFolder.isDirectory()) dissectManualFolder(manualFolder);
|
||||
}
|
||||
|
||||
|
||||
/** Anal bleeding */
|
||||
public static void dissectManualFolder(File folder) {
|
||||
|
||||
@ -167,7 +166,8 @@ public class QMAWLoader implements IResourceManagerReloadListener {
|
||||
String name = file.getName();
|
||||
if(file.isFile() && name.endsWith(".json")) {
|
||||
try {
|
||||
FileReader reader = new FileReader(file);
|
||||
//FileReader reader = new FileReader(file);
|
||||
InputStreamReader reader = new InputStreamReader(Files.newInputStream(file.toPath()), StandardCharsets.UTF_8);
|
||||
JsonObject obj = (JsonObject) parser.parse(reader);
|
||||
registerJson(name, obj);
|
||||
logFoundManual(name);
|
||||
@ -179,35 +179,35 @@ public class QMAWLoader implements IResourceManagerReloadListener {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** Extracts all the info from a json file's main object to add a QMAW to the system. Very barebones, only handles name, icon and the localized text. */
|
||||
public static void registerJson(String file, JsonObject json) {
|
||||
|
||||
|
||||
String name = json.get("name").getAsString();
|
||||
|
||||
|
||||
if(QMAWLoader.qmaw.containsKey(name)) {
|
||||
MainRegistry.logger.info("[QMAW] Skipping existing entry " + file);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
QuickManualAndWiki qmaw = new QuickManualAndWiki(name);
|
||||
|
||||
|
||||
if(json.has("icon")) {
|
||||
qmaw.setIcon(SerializableRecipe.readItemStack(json.get("icon").getAsJsonArray()));
|
||||
}
|
||||
|
||||
|
||||
JsonObject title = json.get("title").getAsJsonObject();
|
||||
for(Entry<String, JsonElement> part : title.entrySet()) {
|
||||
qmaw.addTitle(part.getKey(), part.getValue().getAsString());
|
||||
}
|
||||
|
||||
|
||||
JsonObject content = json.get("content").getAsJsonObject();
|
||||
for(Entry<String, JsonElement> part : content.entrySet()) {
|
||||
qmaw.addLang(part.getKey(), part.getValue().getAsString());
|
||||
}
|
||||
|
||||
|
||||
JsonArray triggers = json.get("trigger").getAsJsonArray();
|
||||
|
||||
|
||||
for(JsonElement element : triggers) {
|
||||
ItemStack trigger = SerializableRecipe.readItemStack(element.getAsJsonArray());
|
||||
// items get renamed and removed all the time, so we add some more debug goodness for those cases
|
||||
@ -217,7 +217,7 @@ public class QMAWLoader implements IResourceManagerReloadListener {
|
||||
QMAWLoader.triggers.put(new ComparableStack(trigger).makeSingular(), qmaw);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(!qmaw.contents.isEmpty()) {
|
||||
QMAWLoader.qmaw.put(name, qmaw);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user