Added new package and finished Orb implementation
Will still eventually need generate implementation, but not soon
This commit is contained in:
parent
372a98d620
commit
65aebd3b58
2 changed files with 92 additions and 47 deletions
|
@ -1,7 +1,7 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package cr0s.warpdrive.conf;
|
||||
package cr0s.warpdrive.conf.structures;
|
||||
|
||||
import net.minecraft.world.gen.feature.WorldGenerator;
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
package cr0s.warpdrive.conf;
|
||||
package cr0s.warpdrive.conf.structures;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Random;
|
||||
|
@ -12,22 +13,42 @@ import org.w3c.dom.Element;
|
|||
import org.w3c.dom.NodeList;
|
||||
|
||||
import cr0s.warpdrive.WarpDrive;
|
||||
import cr0s.warpdrive.conf.InvalidXmlException;
|
||||
import cr0s.warpdrive.conf.XmlRepresentable;
|
||||
|
||||
public abstract class Orb extends DeployableStructure implements XmlRepresentable {
|
||||
|
||||
private OrbShell[] shellRelative;
|
||||
private ArrayList<OrbShell> shells;
|
||||
|
||||
public Orb(int diameter) {
|
||||
super(diameter, diameter, diameter);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadFromXmlElement(Element e) {
|
||||
// TODO Auto-generated method stub
|
||||
public void loadFromXmlElement(Element e) throws InvalidXmlException {
|
||||
|
||||
NodeList shells = e.getElementsByTagName("shell");
|
||||
for (int i = 0; i < shells.getLength(); i++) {
|
||||
Element tmp = (Element) shells.item(i);
|
||||
|
||||
OrbShell shell = new OrbShell();
|
||||
shell.loadFromXmlElement(tmp);
|
||||
|
||||
setShell(shell.getRadiusInner(), shell.getRadiusOuter(), shell);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveToXmlElement(Element e, Document d) {
|
||||
// TODO Auto-generated method stub
|
||||
for (OrbShell shell : shells) {
|
||||
Element tmp = d.createElement("shell");
|
||||
shell.saveToXmlElement(tmp, d);
|
||||
e.appendChild(tmp);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -37,6 +58,20 @@ public abstract class Orb extends DeployableStructure implements XmlRepresentabl
|
|||
return false;
|
||||
}
|
||||
|
||||
public void setShell(int inner, int outer, OrbShell shell) {
|
||||
for (; inner <= outer; inner++)
|
||||
shellRelative[inner] = shell;
|
||||
}
|
||||
|
||||
public OrbShell getShellForRadius(int r) {
|
||||
return shellRelative[r];
|
||||
}
|
||||
|
||||
public Block getBlockForRadius(Random rand, int r) {
|
||||
return shellRelative[r].getNextBlock(rand);
|
||||
|
||||
}
|
||||
|
||||
public class OrbShell implements XmlRepresentable {
|
||||
|
||||
private int radiusInner, radiusOuter;
|
||||
|
@ -55,6 +90,13 @@ public abstract class Orb extends DeployableStructure implements XmlRepresentabl
|
|||
blockWeights = new Block[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a block randomly chosen according to the setup of this OrbShell
|
||||
*
|
||||
* @param r
|
||||
* The Random to use
|
||||
* @return A Non-null block instance
|
||||
*/
|
||||
public Block getNextBlock(Random r) {
|
||||
return blockWeights[r.nextInt(totalWeight)];
|
||||
}
|
||||
|
@ -133,6 +175,9 @@ public abstract class Orb extends DeployableStructure implements XmlRepresentabl
|
|||
throw new InvalidXmlException("Invalid integer in shell " + name + "!");
|
||||
}
|
||||
|
||||
if (totalWeight < 1)
|
||||
throw new InvalidXmlException("At least one kind of block must be defined!");
|
||||
|
||||
}
|
||||
|
||||
@Override
|
Loading…
Reference in a new issue