Changed OreManager to FillerManager
Also added new categories to match
This commit is contained in:
parent
bb921c6907
commit
834f4f8b95
3 changed files with 83 additions and 87 deletions
|
@ -16,168 +16,165 @@ import org.w3c.dom.Element;
|
|||
import org.w3c.dom.NodeList;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import cpw.mods.fml.common.Loader;
|
||||
import cr0s.warpdrive.WarpDrive;
|
||||
|
||||
public class OreManager {
|
||||
|
||||
|
||||
public enum OreSpawnCategory {
|
||||
RARE, COMMON;
|
||||
|
||||
public class FillerManager {
|
||||
|
||||
|
||||
public enum FillerCategory {
|
||||
RARE_ORES("rareOres"), COMMON_ORES("commonOres"), UNCOMMON_ORES("uncommonOres"), OVERWORLD("overworld"), NETHER("nether"), END("end");
|
||||
|
||||
private TreeMap<Block, Integer> ores;
|
||||
|
||||
private TreeMap<Block, Integer> fillerBlocks;
|
||||
public int totWeight;
|
||||
|
||||
private OreSpawnCategory() {
|
||||
ores = new TreeMap<Block, Integer>(new BlockComparator());
|
||||
private String name;
|
||||
|
||||
private FillerCategory(String name) {
|
||||
this.name = name;
|
||||
fillerBlocks = new TreeMap<Block, Integer>(new BlockComparator());
|
||||
}
|
||||
|
||||
public void addFillerBlock(Block b, int weight) {
|
||||
|
||||
public void addOre(Block b, int weight) {
|
||||
|
||||
if (b == null || weight < 1)
|
||||
throw new IllegalArgumentException();
|
||||
|
||||
ores.put(b, weight);
|
||||
|
||||
fillerBlocks.put(b, weight);
|
||||
totWeight += weight;
|
||||
}
|
||||
|
||||
public Set<Entry<Block, Integer>> getOres() {
|
||||
return ores.entrySet();
|
||||
}
|
||||
|
||||
public Integer getOreWeight(Block b) {
|
||||
return ores.get(b);
|
||||
|
||||
public Set<Entry<Block, Integer>> getBlocks() {
|
||||
return fillerBlocks.entrySet();
|
||||
}
|
||||
|
||||
public Integer getBlockWeight(Block b) {
|
||||
return fillerBlocks.get(b);
|
||||
}
|
||||
|
||||
public int getTotalWeight() {
|
||||
return totWeight;
|
||||
}
|
||||
|
||||
public static OreSpawnCategory getOreSpawnValue(String s) {
|
||||
return OreSpawnCategory.valueOf(s.trim().toUpperCase());
|
||||
|
||||
public static FillerCategory getOreSpawnValue(String s) {
|
||||
for (FillerCategory cat : FillerCategory.values())
|
||||
if (cat.name.equals(s))
|
||||
return cat;
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void loadOres(String oreConfDirectory) {
|
||||
|
||||
loadOres(new File(oreConfDirectory));
|
||||
|
||||
}
|
||||
|
||||
public static void loadOres(String oreConfDirectory) {
|
||||
|
||||
loadOres(new File(oreConfDirectory));
|
||||
|
||||
}
|
||||
|
||||
public static void loadOres(File dir) {
|
||||
|
||||
|
||||
String s = "These are the ores names that have been registered, and so may be used to create structures: ";
|
||||
|
||||
|
||||
for (String ore : OreDictionary.getOreNames()) {
|
||||
s = s + "\n" + ore;
|
||||
}
|
||||
|
||||
|
||||
WarpDrive.logger.info(s);
|
||||
|
||||
|
||||
dir.mkdir();
|
||||
|
||||
|
||||
if (!dir.isDirectory())
|
||||
throw new IllegalArgumentException("File path " + dir.getPath() + " must be a drectory!");
|
||||
|
||||
File[] files = dir.listFiles(new FilenameFilter() {
|
||||
|
||||
File[] files = dir.listFiles(new FilenameFilter() {
|
||||
|
||||
@Override
|
||||
public boolean accept(File dir, String name) {
|
||||
return name.startsWith("ores") && name.endsWith(".xml");
|
||||
return name.startsWith("filler") && name.endsWith(".xml");
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
||||
for(File f : files) {
|
||||
|
||||
|
||||
try {
|
||||
|
||||
WarpDrive.logger.info("Loading ore data file " + f.getPath());
|
||||
|
||||
|
||||
WarpDrive.logger.info("Loading filler data file " + f.getPath());
|
||||
|
||||
loadXmlOreFile(f);
|
||||
|
||||
WarpDrive.logger.info("Finished loading ore data file " + f.getPath());
|
||||
|
||||
|
||||
WarpDrive.logger.info("Finished loading filler data file " + f.getPath());
|
||||
|
||||
} catch (Exception e) {
|
||||
WarpDrive.logger.error("Error loading file " + f.getPath() + ": " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
private static void loadXmlOreFile(File f) throws InvalidXmlException, SAXException, IOException {
|
||||
|
||||
|
||||
Document base = WarpDriveConfig.getXmlDocumentBuilder().parse(f);
|
||||
|
||||
|
||||
NodeList modReqList = base.getElementsByTagName("ModRequirements");
|
||||
for (int i = 0; i < modReqList.getLength(); i++) {
|
||||
NodeList mods = ((Element) modReqList.item(i)).getElementsByTagName("mod");
|
||||
for (int j = 0; j < mods.getLength(); j++) {
|
||||
Element mod = (Element) mods.item(j);
|
||||
String res = ModRequirementChecker.getMissingMods((Element) modReqList.item(i));
|
||||
|
||||
if (!res.isEmpty()) {
|
||||
|
||||
String name = mod.getTextContent();
|
||||
if (name.isEmpty())
|
||||
throw new InvalidXmlException("A mod requirement at " + i + ":" + j + " is empty!");
|
||||
|
||||
if (!Loader.isModLoaded(name)) {
|
||||
WarpDrive.logger.info("Skippping ore data file " + f.getPath() + " because the mod " + name + " is not loaded");
|
||||
}
|
||||
|
||||
WarpDrive.logger.info("Skippping filler data file " + f.getPath() + " because the mods " + res + " are not loaded");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
NodeList ores = base.getElementsByTagName("ore");
|
||||
for (int i = 0; i < ores.getLength(); i++) {
|
||||
|
||||
|
||||
Element ore = (Element) ores.item(i);
|
||||
|
||||
|
||||
String oreName = ore.getAttribute("name");
|
||||
if (oreName.isEmpty())
|
||||
throw new InvalidXmlException("Ore " + i + "does not contain a name!");
|
||||
|
||||
|
||||
String oreWeight = ore.getAttribute("weight");
|
||||
if (oreWeight.isEmpty())
|
||||
throw new InvalidXmlException("Ore " + i + " does not contain a weight!");
|
||||
|
||||
|
||||
String category = ore.getAttribute("category");
|
||||
if (category.isEmpty())
|
||||
throw new InvalidXmlException("Ore " + i + " does not contain a category!");
|
||||
|
||||
|
||||
int weight;
|
||||
try {
|
||||
weight = Integer.parseInt(oreWeight);
|
||||
} catch (NumberFormatException e) {
|
||||
throw new InvalidXmlException("Ore weight at " + i + " is invalid!");
|
||||
}
|
||||
|
||||
|
||||
if(weight < 1)
|
||||
throw new InvalidXmlException("Ore weight at " + i + " is too low!");
|
||||
|
||||
OreSpawnCategory cat = OreSpawnCategory.getOreSpawnValue(category);
|
||||
|
||||
FillerCategory cat = FillerCategory.getOreSpawnValue(category);
|
||||
if(cat == null)
|
||||
throw new InvalidXmlException();
|
||||
|
||||
|
||||
Block b = Block.getBlockFromName(oreName);
|
||||
if(b == null)
|
||||
throw new InvalidXmlException("Ore name at " + i + " is not a valid block!");
|
||||
|
||||
|
||||
//Everything is fine
|
||||
cat.addOre(b, weight);
|
||||
cat.addFillerBlock(b, weight);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class BlockComparator implements Comparator<Block> {
|
||||
|
||||
|
||||
@Override
|
||||
public int compare(Block arg0, Block arg1) {
|
||||
return arg0.getUnlocalizedName().compareTo(arg1.getUnlocalizedName());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -891,7 +891,7 @@ public class WarpDriveConfig {
|
|||
|
||||
|
||||
|
||||
OreManager.loadOres(baseConfFolder);
|
||||
FillerManager.loadOres(baseConfFolder);
|
||||
StructureManager.loadStructures(baseConfFolder);
|
||||
}
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ import org.w3c.dom.NodeList;
|
|||
|
||||
import cr0s.warpdrive.WarpDrive;
|
||||
import cr0s.warpdrive.conf.InvalidXmlException;
|
||||
import cr0s.warpdrive.conf.OreManager.OreSpawnCategory;
|
||||
import cr0s.warpdrive.conf.FillerManager.FillerCategory;
|
||||
import cr0s.warpdrive.conf.XmlRepresentable;
|
||||
import cr0s.warpdrive.world.EntitySphereGen;
|
||||
|
||||
|
@ -195,7 +195,7 @@ public abstract class Orb extends DeployableStructure implements XmlRepresentabl
|
|||
int weight = Integer.parseInt(cat.getAttribute("weight"));
|
||||
String oreSpawnCategory = cat.getAttribute("category");
|
||||
|
||||
if (OreSpawnCategory.getOreSpawnValue(oreSpawnCategory) == null)
|
||||
if (FillerCategory.getOreSpawnValue(oreSpawnCategory) == null)
|
||||
throw new InvalidXmlException("Shell has an invalid ores category!");
|
||||
|
||||
if (weight < 1)
|
||||
|
@ -217,15 +217,14 @@ public abstract class Orb extends DeployableStructure implements XmlRepresentabl
|
|||
|
||||
Block bl = Block.getBlockFromName(compBlock.getKey());
|
||||
|
||||
for (int i = 0; i < compBlock.getValue(); i++) {
|
||||
for (int i = 0; i < compBlock.getValue(); i++)
|
||||
blockWeights[index++] = bl;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
for(Entry<String, Integer> category : categoryTemp.entrySet()) {
|
||||
OreSpawnCategory value = OreSpawnCategory.getOreSpawnValue(category.getKey());
|
||||
for (Entry<Block, Integer> compBlock : value.getOres()) {
|
||||
FillerCategory value = FillerCategory.getOreSpawnValue(category.getKey());
|
||||
for (Entry<Block, Integer> compBlock : value.getBlocks()) {
|
||||
|
||||
int reduced = category.getValue() * compBlock.getValue() / value.getTotalWeight();
|
||||
for (int i = 0; i < reduced; i++) {
|
||||
|
|
Loading…
Reference in a new issue