Improved world generation configuration logs

Fixed block names in default structure
This commit is contained in:
LemADEC 2016-01-15 12:01:25 +01:00
parent 31bec889a8
commit 803e0e19d5
6 changed files with 72 additions and 94 deletions

View file

@ -19,16 +19,16 @@ public class XmlPreprocessor {
/**
* Will check the given element for a mod attribute and return a string of all the ones that are not loaded, separated by commas
*
* @param e
* @param element
* Element to check
* @return A string, which is empty if all the mods are loaded.
* @throws InvalidXmlException
*/
public static ModCheckResults checkModRequirements(Element e) {
public static ModCheckResults checkModRequirements(Element element) {
ModCheckResults modErrors = new ModCheckResults();
for (String mod : e.getAttribute("mods").split(",")) {
for (String mod : element.getAttribute("mods").split(",")) {
//TODO: add version check
@ -63,29 +63,25 @@ public class XmlPreprocessor {
Node child = children.item(i);
if (child instanceof Element) {
ModCheckResults res = checkModRequirements((Element) child);
Element elementChild = (Element) child;
ModCheckResults res = checkModRequirements(elementChild);
if (!res.isEmpty()) {
WarpDrive.logger.info("Skipping " + base.getNodeName() + "/" + elementChild.getNodeName()
+ " " + elementChild.getAttribute("group") + elementChild.getAttribute("name") + elementChild.getAttribute("block")
+ " due to " + res);
base.removeChild(child);
WarpDrive.logger.info("Removed child element " + child.getBaseURI() + " of element " + base.getBaseURI() + ", results: " + res);
} else {
doModReqSanitation(child);
}
}
}
}
public static void doLogicPreprocessing(Node root) throws InvalidXmlException {
NodeList children = root.getChildNodes();
for (int i = 0; i < children.getLength(); i++)
for (int i = 0; i < children.getLength(); i++) {
doLogicPreprocessing(children.item(i));
}
if (root.getNodeType() == Node.ELEMENT_NODE && ((Element) root).getTagName().equalsIgnoreCase("for")) {
@ -235,15 +231,18 @@ public class XmlPreprocessor {
@Override
public String toString() {
String s = "{";
for (Entry<String, String> e : mods.entrySet())
s = s + e.getKey() + ": " + e.getValue() + ", ";
return s + "}";
String string = (mods.size() > 1 ? "{" : "");
boolean isFirst = true;
for (Entry<String, String> entry : mods.entrySet()) {
if (isFirst) {
isFirst = false;
} else {
string += ", ";
}
string += entry.getKey() + ": " + entry.getValue();
}
return string + (mods.size() > 1 ? "}" : "");
}
}
}

View file

@ -36,10 +36,6 @@ public class FillerManager {
public static final String END = "end";
/**/
public static void loadOres(String oreConfDirectory) {
loadOres(new File(oreConfDirectory));
}
public static void loadOres(File dir) {
// directory is created by caller, so it can copy default files if any
@ -58,12 +54,12 @@ public class FillerManager {
try {
WarpDrive.logger.info("Loading filler data file " + file.getName() + "...");
loadXmlFillerFile(file);
WarpDrive.logger.info("Loading filler data file " + file.getName() + " done");
} catch (Exception exception) {
WarpDrive.logger.error("Error loading file " + file.getName() + ": " + exception.getMessage());
WarpDrive.logger.error("Error loading filler data file " + file.getName() + ": " + exception.getMessage());
exception.printStackTrace();
}
}
WarpDrive.logger.info("Loading filler data files done");
}
private static void loadXmlFillerFile(File file) throws InvalidXmlException, SAXException, IOException {
@ -73,7 +69,7 @@ public class FillerManager {
ModCheckResults res = XmlPreprocessor.checkModRequirements(base.getDocumentElement());
if (!res.isEmpty()) {
WarpDrive.logger.info("Skippping filler data file " + file.getName() + " because of: " + res);
WarpDrive.logger.info("Skippping filler data file " + file.getName() + " due to " + res);
return;
}
@ -133,7 +129,7 @@ public class FillerManager {
if (!fillerSets.containsKey(dep)) {
WarpDrive.logger.error("A fillerSet " + entry.getKey() + " has a dependency that doesnt exist!");
WarpDrive.logger.error("Skipping FillerSet " + entry.getKey() + " due to missing dependency " + dep);
fillerSets.remove(entry.getKey().getName());
toRemove.add(entry.getKey());
@ -155,14 +151,4 @@ public class FillerManager {
public static FillerSet getFillerSet(String name) {
return fillerSets.get(name);
}
/* TODO dead code?
public static class BlockComparator implements Comparator<Block> {
@Override
public int compare(Block arg0, Block arg1) {
return arg0.getUnlocalizedName().compareTo(arg1.getUnlocalizedName());
}
}
/**/
}

View file

@ -18,18 +18,13 @@ import net.minecraft.init.Blocks;
*
* If FillerSet(blocks[]) is called, that is not necessary.
*
*
*/
public class FillerSet implements XmlRepresentable, Comparable {
private MetaBlock[] weightedFillerBlocks;
private FillerFactory factory;
private String name;
protected String name;
/**
* @return the name
*/
public String getName() {
return name;
}
@ -60,24 +55,24 @@ public class FillerSet implements XmlRepresentable, Comparable {
// Check there is a block name
if (!filler.hasAttribute("block")) {
throw new InvalidXmlException("Filler " + filler.getBaseURI() + " is missing a block tag!");
throw new InvalidXmlException("Filler " + filler + " is missing a block tag!");
}
String blockName = filler.getAttribute("block");
Block block = Block.getBlockFromName(blockName);
if (block == null) {
WarpDrive.logger.warn("Filler " + filler.getBaseURI() + " refers to missing block " + blockName + ": ignoring that entry...");
WarpDrive.logger.warn("Skipping missing block " + blockName);
continue;
}
// Get metadata attribute, defaults to 0
int metadata = 0;
String metaString = filler.getAttribute("metadata");
if (!metaString.isEmpty()) {
int intMetadata = 0;
String stringMetadata = filler.getAttribute("metadata");
if (!stringMetadata.isEmpty()) {
try {
metadata = Integer.parseInt(metaString);
intMetadata = Integer.parseInt(stringMetadata);
} catch (NumberFormatException exception) {
throw new InvalidXmlException("Filler " + filler.getBaseURI() + " metadata attribute is NaN!");
throw new InvalidXmlException("Invalid metadata for block " + blockName);
}
}
@ -95,10 +90,10 @@ public class FillerSet implements XmlRepresentable, Comparable {
try {
weight = Integer.parseInt(stringWeight);
factory.addWeightedBlock(block, metadata, weight);
factory.addWeightedBlock(block, intMetadata, weight);
} catch (NumberFormatException exception) {
throw new InvalidXmlException("Filler " + filler.getBaseURI() + " weight is NaN!");
throw new InvalidXmlException("Invalid weight for block " + blockName);
} catch (IllegalArgumentException exception) {
throw new InvalidXmlException(exception.getMessage());
}
@ -110,21 +105,21 @@ public class FillerSet implements XmlRepresentable, Comparable {
hasWeightOrRatio = true;
try {
factory.addRatioBlock(block, metadata, stringRatio);
factory.addRatioBlock(block, intMetadata, stringRatio);
} catch (IllegalArgumentException ex) {
throw new InvalidXmlException(ex.getMessage());
} catch (IllegalArgumentException exception) {
throw new InvalidXmlException(exception.getMessage());
}
}
if (!hasWeightOrRatio) {
throw new InvalidXmlException("Filler " + filler.getBaseURI() + " is missing a weight or a ratio!");
throw new InvalidXmlException("No ratio nor weight defined for block " + blockName + " " + stringMetadata);
}
}
}
@Override
public void saveToXmlElement(Element e, Document d) throws InvalidXmlException {
public void saveToXmlElement(Element element, Document document) throws InvalidXmlException {
throw new InvalidXmlException("Not supported");
}
@ -134,7 +129,7 @@ public class FillerSet implements XmlRepresentable, Comparable {
* Clears the memory used for construction
*/
public void finishContruction() {
WarpDrive.logger.info("Finishing construction of FillerSet " + name);
WarpDrive.logger.info("Finishing construction of " + name);
weightedFillerBlocks = factory.constructWeightedMetaBlockList();
//For some reason some entries are null, so replace them with air
@ -148,8 +143,8 @@ public class FillerSet implements XmlRepresentable, Comparable {
}
@Override
public int compareTo(Object obj) {
return name.compareTo(((FillerSet) obj).name);
public int compareTo(Object object) {
return name.compareTo(((FillerSet) object).name);
}
@Override

View file

@ -19,7 +19,7 @@ import cr0s.warpdrive.world.EntitySphereGen;
public abstract class Orb extends DeployableStructure implements XmlRepresentable {
private OrbShell[] shellRelative;
private ArrayList<OrbShell> shells;
// private ArrayList<OrbShell> shells;
private String name;
/**
@ -55,23 +55,22 @@ public abstract class Orb extends DeployableStructure implements XmlRepresentabl
}
@Override
public void loadFromXmlElement(Element e) throws InvalidXmlException {
public void loadFromXmlElement(Element element) throws InvalidXmlException {
this.name = e.getAttribute("name");
name = element.getAttribute("name");
ArrayList<OrbShell> newShells = new ArrayList<OrbShell>();
int totalThickness = 0;
NodeList shells = e.getElementsByTagName("shell");
NodeList shells = element.getElementsByTagName("shell");
for (int i = 0; i < shells.getLength(); i++) {
Element tmp = (Element) shells.item(i);
Element elementShell = (Element) shells.item(i);
OrbShell shell = new OrbShell();
shell.loadFromXmlElement(tmp);
shell.loadFromXmlElement(elementShell);
shell.finishContruction();
totalThickness += shell.thickness;
newShells.add(shell);
}
int index = 0;
@ -84,28 +83,27 @@ public abstract class Orb extends DeployableStructure implements XmlRepresentabl
}
setRadius(totalThickness - 1);
}
@Override
public void saveToXmlElement(Element e, Document d) {
public void saveToXmlElement(Element element, Document document) {
/* TODO: dead code?
for (OrbShell shell : shells) {
Element tmp = d.createElement("shell");
shell.saveToXmlElement(tmp, d);
e.appendChild(tmp);
Element tmp = document.createElement("shell");
shell.saveToXmlElement(tmp, document);
element.appendChild(tmp);
}
/**/
}
@Override
public boolean generate(World world, Random p_76484_2_, int x, int y, int z) {
public boolean generate(World world, Random random, int x, int y, int z) {
EntitySphereGen entitySphereGen = new EntitySphereGen(world, x, y, z, getRadius(), this, true);
world.spawnEntityInWorld(entitySphereGen);
return false;
}
public boolean generate(World world, Random p_76484_2_, int x, int y, int z, final int radius) {
public boolean generate(World world, Random random, int x, int y, int z, final int radius) {
EntitySphereGen entitySphereGen = new EntitySphereGen(world, x, y, z, radius, this, true);
world.spawnEntityInWorld(entitySphereGen);
return false;
@ -140,15 +138,15 @@ public abstract class Orb extends DeployableStructure implements XmlRepresentabl
}
@Override
public void loadFromXmlElement(Element e) throws InvalidXmlException {
public void loadFromXmlElement(Element element) throws InvalidXmlException {
WarpDrive.logger.info("Loading shell " + e.getAttribute("name"));
name = e.getAttribute("name");
WarpDrive.logger.info("Loading shell " + element.getAttribute("name"));
name = element.getAttribute("name");
super.loadFromXmlElement(e);
super.loadFromXmlElement(element);
if (e.hasAttribute("fillerSets")) {
String[] imports = e.getAttribute("fillerSets").split(",");
if (element.hasAttribute("fillerSets")) {
String[] imports = element.getAttribute("fillerSets").split(",");
for (String imp : imports) {
FillerSet fillSet = FillerManager.getFillerSet(imp);
@ -161,7 +159,7 @@ public abstract class Orb extends DeployableStructure implements XmlRepresentabl
}
try {
thickness = Integer.parseInt(e.getAttribute("maxThickness"));
thickness = Integer.parseInt(element.getAttribute("maxThickness"));
} catch (NumberFormatException ex) {
throw new InvalidXmlException("MaxThickness is not valid!");
}

View file

@ -56,20 +56,20 @@ public class StructureManager {
WarpDrive.logger.info("Finished loading structure data file " + file.getName());
} catch (Exception e) {
WarpDrive.logger.error("Error loading file " + file.getName() + ": " + e.getMessage());
e.printStackTrace();
} catch (Exception exception) {
WarpDrive.logger.error("Error loading file " + file.getName() + ": " + exception.getMessage());
exception.printStackTrace();
}
}
}
private static void loadXmlStructureFile(File f) throws SAXException, IOException, InvalidXmlException {
Document base = WarpDriveConfig.getXmlDocumentBuilder().parse(f);
private static void loadXmlStructureFile(File file) throws SAXException, IOException, InvalidXmlException {
Document base = WarpDriveConfig.getXmlDocumentBuilder().parse(file);
ModCheckResults res = XmlPreprocessor.checkModRequirements(base.getDocumentElement());
if (!res.isEmpty()) {
WarpDrive.logger.info("Skippping structure data file " + f.getName() + " because of: " + res);
WarpDrive.logger.info("Skippping structure " + file.getName() + " due to " + res);
return;
}

View file

@ -48,7 +48,7 @@
<shell name="surface" minThickness="10" maxThickness="20" fillerSets="overworld,commonOres">
<filler weight="3" block="minecraft:clay" />
<filler ratio=".05" block="minecraft:brick" />
<filler ratio=".05" block="minecraft:brick_block" />
<filler ratio=".5" block="minecraft:air" />
</shell>
</structure>
@ -63,7 +63,7 @@
<structure name="end_moon" group="moon" >
<shell name="substance" minThickness="10" maxThickness="30">
<filler block="minecraft:whiteStone" weight="1"/>
<filler block="minecraft:end_stone" weight="1"/>
<filler block="minecraft:bedrock" ratio=".001" />
</shell>
</structure>