mirror of
https://github.com/GTNewHorizons/Mantle.git
synced 2026-11-24 05:44:46 +00:00
add rest of book code, dump biome ID's when config option is enabled
This commit is contained in:
1 parent
8c6a5a8791
commit
c21c497106
3 files changed
+103
-31
No files matched your search
+27
-2
@@ -4,10 +4,12 @@ import static mantle.lib.CoreRepo.logger;
|
||||
import static mantle.lib.CoreRepo.modId;
|
||||
import static mantle.lib.CoreRepo.modName;
|
||||
import static mantle.lib.CoreRepo.modVersion;
|
||||
import net.minecraft.world.biome.BiomeGenBase;
|
||||
import mantle.books.BookData;
|
||||
import mantle.books.BookDataStore;
|
||||
import mantle.common.MProxyCommon;
|
||||
import mantle.items.Manual;
|
||||
import mantle.lib.CoreConfig;
|
||||
import mantle.lib.CoreRepo;
|
||||
import mantle.lib.environment.EnvironmentChecks;
|
||||
import cpw.mods.fml.common.Mod;
|
||||
@@ -39,6 +41,18 @@ public class Mantle
|
||||
public static MProxyCommon proxy;
|
||||
public static Manual mantleBook;
|
||||
|
||||
/**
|
||||
* Method Loaded once FML loads mod containers
|
||||
* Environment loaded here to check for other
|
||||
*/
|
||||
|
||||
public Mantle()
|
||||
{
|
||||
|
||||
EnvironmentChecks.verifyEnvironmentSanity();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* FML preinitialisation handler
|
||||
*
|
||||
@@ -51,8 +65,7 @@ public class Mantle
|
||||
{
|
||||
logger.info("Mantle (" + modVersion + ") -- Preparing for launch.");
|
||||
logger.info("Entering preinitialization phase.");
|
||||
|
||||
EnvironmentChecks.verifyEnvironmentSanity();
|
||||
CoreConfig.loadConfiguration(evt.getModConfigurationDirectory());
|
||||
NetworkRegistry.INSTANCE.registerGuiHandler(instance, proxy);
|
||||
|
||||
mantleBook = (Manual) new Manual().setUnlocalizedName("mantle.manual");
|
||||
@@ -93,6 +106,18 @@ public class Mantle
|
||||
data.modID = CoreRepo.modId;
|
||||
BookDataStore.addBook(data);
|
||||
mantleBook.updateManual();
|
||||
CoreConfig.loadBookLocations();
|
||||
|
||||
for (BiomeGenBase b : BiomeGenBase.getBiomeGenArray())
|
||||
{
|
||||
if (CoreConfig.dumpBiomeIDs)
|
||||
{
|
||||
if (b != null && b.biomeName != null)
|
||||
{
|
||||
logger.info(b.biomeID + " " + b.biomeName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+42
-27
@@ -3,6 +3,7 @@ package mantle.books.external;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Map;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipFile;
|
||||
|
||||
@@ -26,12 +27,16 @@ import org.apache.commons.io.FilenameUtils;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
|
||||
public class ZipLoader
|
||||
{
|
||||
public BookData loadZip (File f)
|
||||
public static Map<String, ItemStack> loadedIS = Maps.newHashMap();
|
||||
|
||||
public static BookData loadZip (File f)
|
||||
{
|
||||
String flName = new String();
|
||||
String flExt = new String();
|
||||
@@ -49,6 +54,7 @@ public class ZipLoader
|
||||
{
|
||||
try
|
||||
{
|
||||
logger.info("Loading book zip " + f.getName());
|
||||
ZipFile zipfile = new ZipFile(f);
|
||||
Enumeration e = zipfile.entries();
|
||||
while (e.hasMoreElements())
|
||||
@@ -71,6 +77,10 @@ public class ZipLoader
|
||||
{
|
||||
b.doc = ManualReader.readManual(zipfile.getInputStream(entry), flName);
|
||||
}
|
||||
if (flExt.equalsIgnoreCase("lang"))
|
||||
{
|
||||
//TODO 1.7 put this data into the vanilla lang stuffs
|
||||
}
|
||||
if (flExt.equalsIgnoreCase("bookconfig"))
|
||||
{
|
||||
Document config = ManualReader.readManual(zipfile.getInputStream(entry), flName);
|
||||
@@ -126,13 +136,14 @@ public class ZipLoader
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logger.info(" Error Loading book zip " + f.getName());
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.error("Attempted to load non-zip file for mantle book. File will be skipped");
|
||||
logger.error("Attempted to load non-zip file for mantle book. File " + f.getName() + " will be skipped");
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -143,7 +154,7 @@ public class ZipLoader
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isImage (String ext)
|
||||
public static boolean isImage (String ext)
|
||||
{
|
||||
if (ext.equalsIgnoreCase("png"))
|
||||
return true;
|
||||
@@ -151,14 +162,12 @@ public class ZipLoader
|
||||
}
|
||||
|
||||
// public static void registerManualSmallRecipe (String name, ItemStack output, ItemStack... stacks)
|
||||
public void registerSmallRecipes (NodeList node)
|
||||
public static void registerSmallRecipes (NodeList node)
|
||||
{
|
||||
String item[];
|
||||
String name = new String();
|
||||
ItemStack isOut;
|
||||
ItemStack[] isIn = new ItemStack[4];
|
||||
int meta = 0;
|
||||
int num = 0;
|
||||
for (int i = 0; i < node.getLength(); i++)
|
||||
{
|
||||
item = node.item(i).getTextContent().split("|");
|
||||
@@ -173,14 +182,12 @@ public class ZipLoader
|
||||
}
|
||||
|
||||
// public static void registerManualLargeRecipe (String name, ItemStack output, ItemStack... stacks)
|
||||
public void registerLargeRecipes (NodeList node)
|
||||
public static void registerLargeRecipes (NodeList node)
|
||||
{
|
||||
String item[];
|
||||
String name = new String();
|
||||
ItemStack isOut;
|
||||
ItemStack[] isIn = new ItemStack[9];
|
||||
int meta = 0;
|
||||
int num = 0;
|
||||
for (int i = 0; i < node.getLength(); i++)
|
||||
{
|
||||
item = node.item(i).getTextContent().split("|");
|
||||
@@ -195,14 +202,12 @@ public class ZipLoader
|
||||
}
|
||||
|
||||
//name, Out, in,
|
||||
public void registerFurnaceRecipes (NodeList node)
|
||||
public static void registerFurnaceRecipes (NodeList node)
|
||||
{
|
||||
String item[];
|
||||
String name = new String();
|
||||
ItemStack isOut;
|
||||
ItemStack isIn;
|
||||
int meta = 0;
|
||||
int num = 0;
|
||||
for (int i = 0; i < node.getLength(); i++)
|
||||
{
|
||||
item = node.item(i).getTextContent().split("|");
|
||||
@@ -214,13 +219,11 @@ public class ZipLoader
|
||||
}
|
||||
|
||||
//name, out
|
||||
public void registerIcons (NodeList node)
|
||||
public static void registerIcons (NodeList node)
|
||||
{
|
||||
String item[];
|
||||
String name = new String();
|
||||
ItemStack is;
|
||||
int meta = 0;
|
||||
int num = 0;
|
||||
for (int i = 0; i < node.getLength(); i++)
|
||||
{
|
||||
item = node.item(i).getTextContent().split("|");
|
||||
@@ -230,28 +233,40 @@ public class ZipLoader
|
||||
}
|
||||
}
|
||||
|
||||
//TODO null protect this!!!
|
||||
public ItemStack getISFromString (String s)
|
||||
public static ItemStack getISFromString (String s)
|
||||
{
|
||||
try
|
||||
{
|
||||
String name = s.substring(0, s.indexOf("@") - 1);
|
||||
int meta = Integer.parseInt(s.substring(s.indexOf("@") + 1, s.contains("#") ? s.indexOf("#") - 1 : s.length() - 1));
|
||||
int stacksize = s.contains("#") ? Integer.parseInt(s.substring(s.indexOf("#") + 1)) : 1;
|
||||
String key = name + ":" + meta;
|
||||
Item i = (Item) Item.itemRegistry.getObject(key);
|
||||
Block b = (Block) Block.blockRegistry.getObject(key);
|
||||
if (i != null)
|
||||
ItemStack is = loadedIS.get(s);
|
||||
if (is == null)
|
||||
{
|
||||
return new ItemStack(i, stacksize, meta);
|
||||
String name = s.substring(0, s.indexOf("@") - 1);
|
||||
int meta = Integer.parseInt(s.substring(s.indexOf("@") + 1, s.contains("#") ? s.indexOf("#") - 1 : s.length() - 1));
|
||||
int stacksize = s.contains("#") ? Integer.parseInt(s.substring(s.indexOf("#") + 1)) : 1;
|
||||
String key = name + ":" + meta;
|
||||
Item i = (Item) Item.itemRegistry.getObject(key);
|
||||
Block b = (Block) Block.blockRegistry.getObject(key);
|
||||
if (i != null)
|
||||
{
|
||||
is = new ItemStack(i, stacksize, meta);
|
||||
return is;
|
||||
}
|
||||
if (b != null)
|
||||
{
|
||||
is = new ItemStack(b, stacksize, meta);
|
||||
loadedIS.put(s, is);
|
||||
return is;
|
||||
}
|
||||
}
|
||||
if (b != null)
|
||||
else
|
||||
{
|
||||
return new ItemStack(b, stacksize, meta);
|
||||
return is;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logger.error("Error creating ItemStack");
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,14 @@
|
||||
package mantle.lib;
|
||||
|
||||
import static mantle.lib.CoreRepo.logger;
|
||||
import static mantle.lib.CoreRepo.modId;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
|
||||
import mantle.books.external.ZipLoader;
|
||||
import net.minecraftforge.common.config.Configuration;
|
||||
|
||||
/**
|
||||
@@ -12,15 +20,29 @@ import net.minecraftforge.common.config.Configuration;
|
||||
*/
|
||||
public class CoreConfig
|
||||
{
|
||||
static Configuration config;
|
||||
public static File configFolder;
|
||||
|
||||
/**
|
||||
* Loads state from a Forge configuration object, or saves a new file if it doesn't already exist.
|
||||
*
|
||||
* @param config Configuration object (usually from a location given by FML in preinit)
|
||||
*/
|
||||
public static void loadConfiguration (Configuration config)
|
||||
public static void loadConfiguration (File mainConfigFolder)
|
||||
{
|
||||
logger.info("Loading configuration from disk.");
|
||||
try
|
||||
{
|
||||
configFolder = new File(mainConfigFolder.getCanonicalPath(), "SlimeKnights");
|
||||
if (!configFolder.exists())
|
||||
configFolder.mkdirs();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
logger.error("Error creating Mantle's Config File: " + e.getMessage());
|
||||
}
|
||||
|
||||
config = new Configuration(new File(configFolder, (modId + ".cfg")));
|
||||
config.load();
|
||||
|
||||
silenceEnvChecks = config.get("Environment", "unsupportedLogging", silenceEnvChecks).getBoolean(silenceEnvChecks);
|
||||
@@ -28,10 +50,10 @@ public class CoreConfig
|
||||
debug_enableConsole = config.get("DebugHelpers", "enableConsole", debug_enableConsole).getBoolean(debug_enableConsole);
|
||||
debug_enableChat = config.get("DebugHelpers", "enableChat", debug_enableChat).getBoolean(debug_enableChat);
|
||||
//check for debugging overrides in system environment
|
||||
dumpBiomeIDs = config.get("DebugHelpers", "Dump BIOME ID's in log", dumpBiomeIDs).getBoolean(dumpBiomeIDs);
|
||||
checkSysOverrides();
|
||||
config.save();
|
||||
logger.info("Configuration load completed.");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -51,6 +73,15 @@ public class CoreConfig
|
||||
}
|
||||
}
|
||||
|
||||
public static void loadBookLocations ()
|
||||
{
|
||||
for (File f : configFolder.listFiles())
|
||||
{
|
||||
if(f.isFile() && FilenameUtils.getExtension(f.getAbsolutePath()).equalsIgnoreCase("zip"))
|
||||
ZipLoader.loadZip(f);
|
||||
}
|
||||
}
|
||||
|
||||
// BEGIN CONFIG VARS
|
||||
// Env Checks
|
||||
public static boolean silenceEnvChecks = false;
|
||||
@@ -58,5 +89,6 @@ public class CoreConfig
|
||||
// Debug Helpers
|
||||
public static boolean debug_enableConsole = false;
|
||||
public static boolean debug_enableChat = false;
|
||||
public static boolean dumpBiomeIDs = false;
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user