Merge branch 'ConfImprovements' into HEAD
Conflicts: src/main/java/cr0s/warpdrive/WarpDrive.java src/main/java/cr0s/warpdrive/conf/WarpDriveConfig.java
This commit is contained in:
commit
673752b26c
13 changed files with 540 additions and 89 deletions
|
@ -17,4 +17,4 @@ See mcmod.info for credits
|
|||
Installation
|
||||
============
|
||||
1. Download WarpDrive.jar from Downloads and put it in your mods folder
|
||||
3. You need to have CoFHCore and IC2 installed to run. You also need either ComputerCraft or OpenComputers
|
||||
3. You need to have either CoFHCore or IC2 installed to run. You also need either ComputerCraft or OpenComputers
|
||||
|
|
|
@ -2,8 +2,6 @@ package cr0s.warpdrive;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
@ -30,8 +28,10 @@ import net.minecraftforge.common.config.Configuration;
|
|||
import net.minecraftforge.common.util.EnumHelper;
|
||||
import net.minecraftforge.oredict.ShapedOreRecipe;
|
||||
import net.minecraftforge.oredict.ShapelessOreRecipe;
|
||||
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.Loader;
|
||||
import cpw.mods.fml.common.Mod;
|
||||
import cpw.mods.fml.common.Mod.EventHandler;
|
||||
import cpw.mods.fml.common.Mod.Instance;
|
||||
|
@ -101,10 +101,10 @@ import cr0s.warpdrive.data.CamerasRegistry;
|
|||
import cr0s.warpdrive.data.CloakManager;
|
||||
import cr0s.warpdrive.data.JumpgatesRegistry;
|
||||
import cr0s.warpdrive.data.ShipCoresRegistry;
|
||||
import cr0s.warpdrive.item.ItemIC2reactorLaserFocus;
|
||||
import cr0s.warpdrive.item.ItemAirCanisterFull;
|
||||
import cr0s.warpdrive.item.ItemHelmet;
|
||||
import cr0s.warpdrive.item.ItemComponent;
|
||||
import cr0s.warpdrive.item.ItemHelmet;
|
||||
import cr0s.warpdrive.item.ItemIC2reactorLaserFocus;
|
||||
import cr0s.warpdrive.item.ItemUpgrade;
|
||||
import cr0s.warpdrive.network.PacketHandler;
|
||||
import cr0s.warpdrive.render.CameraOverlay;
|
||||
|
@ -351,7 +351,6 @@ public class WarpDrive implements LoadingCallback {
|
|||
GameRegistry.registerBlock(blockIC2reactorLaserMonitor, "blockIC2reactorLaserMonitor");
|
||||
GameRegistry.registerTileEntity(TileEntityIC2reactorLaserMonitor.class, MODID + ":blockIC2reactorLaserMonitor");
|
||||
}
|
||||
|
||||
// TRANSPORT BEACON
|
||||
blockTransportBeacon = new BlockTransportBeacon();
|
||||
|
||||
|
@ -384,7 +383,6 @@ public class WarpDrive implements LoadingCallback {
|
|||
itemIC2reactorLaserFocus = new ItemIC2reactorLaserFocus();
|
||||
GameRegistry.registerItem(itemIC2reactorLaserFocus, "itemIC2reactorLaserFocus");
|
||||
}
|
||||
|
||||
// COMPONENT ITEMS
|
||||
itemComponent = new ItemComponent();
|
||||
GameRegistry.registerItem(itemComponent, "itemComponent");
|
||||
|
@ -416,7 +414,6 @@ public class WarpDrive implements LoadingCallback {
|
|||
creativeTabWarpDrive.setBackgroundImageName("items.png");
|
||||
MinecraftForge.EVENT_BUS.register(new CameraOverlay(Minecraft.getMinecraft()));
|
||||
}
|
||||
|
||||
if (WarpDriveConfig.isComputerCraftLoaded) {
|
||||
peripheralHandler = new WarpDrivePeripheralHandler();
|
||||
peripheralHandler.register();
|
||||
|
@ -429,6 +426,7 @@ public class WarpDrive implements LoadingCallback {
|
|||
hyperSpace = DimensionManager.getWorld(WarpDriveConfig.G_HYPERSPACE_DIMENSION_ID);
|
||||
|
||||
WarpDriveConfig.postInit();
|
||||
WarpDriveConfig.loadWorldGen();
|
||||
|
||||
if (WarpDriveConfig.isIndustrialCraft2loaded && WarpDriveConfig.G_ENABLE_IC2_RECIPES) {
|
||||
initIC2Recipes();
|
||||
|
@ -456,13 +454,13 @@ public class WarpDrive implements LoadingCallback {
|
|||
'p', itemComponent.getItemStack(6),
|
||||
'c', itemComponent.getItemStack(2),
|
||||
'd', Items.diamond));
|
||||
|
||||
|
||||
// Controller
|
||||
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(blockShipController), false, "ici", "idi", "iii",
|
||||
'i', Items.iron_ingot,
|
||||
'c', itemComponent.getItemStack(5),
|
||||
'd', Items.diamond));
|
||||
|
||||
|
||||
// Radar
|
||||
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(blockRadar), false, "ggg", "pdc", "iii",
|
||||
'i', Items.iron_ingot,
|
||||
|
@ -470,13 +468,13 @@ public class WarpDrive implements LoadingCallback {
|
|||
'p', itemComponent.getItemStack(6),
|
||||
'g', Blocks.glass,
|
||||
'd', Items.diamond));
|
||||
|
||||
|
||||
// Isolation Block
|
||||
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(blockWarpIsolation), false, "igi", "geg", "igi",
|
||||
'i', Items.iron_ingot,
|
||||
'g', Blocks.glass,
|
||||
'e', Items.ender_pearl));
|
||||
|
||||
|
||||
// Air generator
|
||||
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(blockAirGenerator), false, "ibi", "i i", "ipi",
|
||||
'i', Items.iron_ingot,
|
||||
|
@ -506,7 +504,7 @@ public class WarpDrive implements LoadingCallback {
|
|||
't', itemComponent.getItemStack(1),
|
||||
'c', itemComponent.getItemStack(5),
|
||||
'l', itemComponent.getItemStack(3)));
|
||||
|
||||
|
||||
// Laser Lift
|
||||
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(blockLift), false, "ipi", "rtr", "ili",
|
||||
'i', Items.iron_ingot,
|
||||
|
@ -560,7 +558,7 @@ public class WarpDrive implements LoadingCallback {
|
|||
'd', Items.diamond,
|
||||
'r', Items.redstone,
|
||||
'n', Items.gold_nugget));
|
||||
|
||||
|
||||
// Power Laser
|
||||
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(blockEnanReactorLaser), false, "iii", "ilg", "ici",
|
||||
'i', Items.iron_ingot,
|
||||
|
@ -589,7 +587,7 @@ public class WarpDrive implements LoadingCallback {
|
|||
'l', "dyeBlue",
|
||||
'd', Items.diamond,
|
||||
's', Items.stick));
|
||||
|
||||
|
||||
// Chunk Loader
|
||||
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(blockChunkLoader), false, "ipi", "ici", "ifi",
|
||||
'i', Items.iron_ingot,
|
||||
|
@ -963,7 +961,7 @@ public class WarpDrive implements LoadingCallback {
|
|||
ForgeChunkManager.releaseTicket(ticket);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void addChatMessage(final EntityPlayer player, final String message) {
|
||||
String[] lines = message.split("\n");
|
||||
for (String line : lines) {
|
||||
|
|
29
src/main/java/cr0s/warpdrive/conf/InvalidXmlException.java
Normal file
29
src/main/java/cr0s/warpdrive/conf/InvalidXmlException.java
Normal file
|
@ -0,0 +1,29 @@
|
|||
package cr0s.warpdrive.conf;
|
||||
|
||||
public class InvalidXmlException extends Exception {
|
||||
|
||||
public InvalidXmlException() {
|
||||
super("An unknown xml error occured");
|
||||
}
|
||||
|
||||
public InvalidXmlException(String arg0) {
|
||||
super(arg0);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public InvalidXmlException(Throwable arg0) {
|
||||
super(arg0);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public InvalidXmlException(String arg0, Throwable arg1) {
|
||||
super(arg0, arg1);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public InvalidXmlException(String arg0, Throwable arg1, boolean arg2, boolean arg3) {
|
||||
super(arg0, arg1, arg2, arg3);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
}
|
75
src/main/java/cr0s/warpdrive/conf/OreManager.java
Normal file
75
src/main/java/cr0s/warpdrive/conf/OreManager.java
Normal file
|
@ -0,0 +1,75 @@
|
|||
package cr0s.warpdrive.conf;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
import cr0s.warpdrive.WarpDrive;
|
||||
|
||||
public class OreManager {
|
||||
|
||||
|
||||
public enum OreSpawnValue {
|
||||
RARE, COMMON;
|
||||
|
||||
|
||||
private TreeMap<Block, Double> ores;
|
||||
public int totWeight;
|
||||
|
||||
private OreSpawnValue() {
|
||||
ores = new TreeMap<Block, Double>(new BlockComparator());
|
||||
}
|
||||
|
||||
public void addOre(Block b, double prob) {
|
||||
|
||||
if (b == null || prob > 1 || prob <= 0)
|
||||
throw new IllegalArgumentException();
|
||||
|
||||
ores.put(b, prob);
|
||||
totWeight += prob;
|
||||
}
|
||||
|
||||
public Set<Entry<Block, Double>> getOres() {
|
||||
return ores.entrySet();
|
||||
}
|
||||
|
||||
public Double getOreWeight(Block b) {
|
||||
return ores.get(b);
|
||||
}
|
||||
|
||||
public int getTotalWeight() {
|
||||
return totWeight;
|
||||
}
|
||||
|
||||
public static OreSpawnValue getOreSpawnValue(String s) {
|
||||
return OreSpawnValue.valueOf(s.trim().toUpperCase());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void loadOres() {
|
||||
|
||||
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);
|
||||
|
||||
//TODO:
|
||||
}
|
||||
|
||||
public static class BlockComparator implements Comparator<Block> {
|
||||
|
||||
@Override
|
||||
public int compare(Block arg0, Block arg1) {
|
||||
return arg0.getUnlocalizedName().compareTo(arg1.getUnlocalizedName());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -44,7 +44,7 @@ public class WarpDriveConfig {
|
|||
public static Method forgeMultipart_helper_createTileFromNBT = null;
|
||||
public static Method forgeMultipart_helper_sendDescPacket = null;
|
||||
public static Method forgeMultipart_tileMultipart_onChunkLoad = null;
|
||||
|
||||
|
||||
public static ItemStack IC2_air;
|
||||
public static ItemStack IC2_empty;
|
||||
public static ItemStack IC2_rubberWood;
|
||||
|
@ -502,37 +502,32 @@ public class WarpDriveConfig {
|
|||
if (isForgeMultipartLoaded) {
|
||||
loadForgeMultipart();
|
||||
}
|
||||
|
||||
|
||||
isIndustrialCraft2loaded = Loader.isModLoaded("IC2");
|
||||
if (isIndustrialCraft2loaded) {
|
||||
loadIC2();
|
||||
}
|
||||
|
||||
|
||||
isComputerCraftLoaded = Loader.isModLoaded("ComputerCraft");
|
||||
if (isComputerCraftLoaded) {
|
||||
loadCC();
|
||||
}
|
||||
|
||||
|
||||
isAdvancedSolarPanelLoaded = Loader.isModLoaded("AdvancedSolarPanel");
|
||||
if (isAdvancedSolarPanelLoaded) {
|
||||
loadASP();
|
||||
}
|
||||
|
||||
|
||||
isAtomicScienceLoaded = Loader.isModLoaded("ResonantInduction|Atomic");
|
||||
if (isAtomicScienceLoaded) {
|
||||
loadAtomicScience();
|
||||
}
|
||||
|
||||
isICBMLoaded = Loader.isModLoaded("ICBM|Explosion");
|
||||
if (isICBMLoaded) {
|
||||
loadICBM();
|
||||
}
|
||||
|
||||
isMFFSLoaded = Loader.isModLoaded("MFFS");
|
||||
if (isMFFSLoaded) {
|
||||
loadMFFS();
|
||||
}
|
||||
|
||||
|
||||
isGraviSuiteLoaded = Loader.isModLoaded("GraviSuite");
|
||||
if (isGraviSuiteLoaded) {
|
||||
loadGraviSuite();
|
||||
|
@ -573,7 +568,7 @@ public class WarpDriveConfig {
|
|||
if (isIndustrialCraft2loaded) {
|
||||
// Metadata: 0 Batbox, 1 MFE, 2 MFSU, 3 LV transformer, 4 MV transformer, 5 HV transformer, 6 EV transformer, 7 CESU
|
||||
scannerIgnoreBlocks.add(Block.getBlockFromName("IC2:blockElectric"));
|
||||
|
||||
|
||||
// Metadata: 0 Batbox, 1 CESU, 2 MFE, 3 MFSU
|
||||
scannerIgnoreBlocks.add(Block.getBlockFromName("IC2:blockChargepad"));
|
||||
}
|
||||
|
@ -645,19 +640,19 @@ public class WarpDriveConfig {
|
|||
try {
|
||||
IC2_solarPanel = getIC2Item("blockGenerator");
|
||||
IC2_solarPanel.setItemDamage(3);
|
||||
|
||||
|
||||
spaceHelmets.add(getIC2Item("itemArmorHazmatHelmet").getItem());
|
||||
spaceHelmets.add(getIC2Item("itemSolarHelmet").getItem());
|
||||
spaceHelmets.add(getIC2Item("itemArmorNanoHelmet").getItem());
|
||||
spaceHelmets.add(getIC2Item("itemArmorQuantumHelmet").getItem());
|
||||
|
||||
|
||||
jetpacks.add(getIC2Item("itemArmorJetpack").getItem());
|
||||
jetpacks.add(getIC2Item("itemArmorJetpackElectric").getItem());
|
||||
|
||||
|
||||
IC2_empty = getIC2Item("itemCellEmpty");
|
||||
IC2_air = getIC2Item("itemCellEmpty");
|
||||
IC2_air.setItemDamage(5);
|
||||
|
||||
|
||||
ItemStack rubberWood = getIC2Item("blockRubWood");
|
||||
IC2_Resin = getIC2Item("itemHarz");
|
||||
if (rubberWood != null) {
|
||||
|
@ -676,7 +671,7 @@ public class WarpDriveConfig {
|
|||
ore = getIC2Item("blockOreLead");
|
||||
if (ore != null)
|
||||
commonWorldGenOres.add(Block.getBlockFromItem(ore.getItem()));
|
||||
|
||||
|
||||
IC2_fluidCell = getIC2Item("itemFluidCell").getItem();
|
||||
} catch (Exception exception) {
|
||||
WarpDrive.logger.error("WarpDriveConfig Error loading IndustrialCraft2 classes");
|
||||
|
@ -686,7 +681,7 @@ public class WarpDriveConfig {
|
|||
|
||||
private static void loadCC() {
|
||||
try {
|
||||
/*
|
||||
/*
|
||||
CC_Computer = ComputerCraft.Blocks.computer;
|
||||
CC_peripheral = ComputerCraft.Blocks.peripheral;
|
||||
CC_Floppy = ComputerCraft.Items.disk;
|
||||
|
@ -861,4 +856,8 @@ public class WarpDriveConfig {
|
|||
}
|
||||
return def;
|
||||
}
|
||||
|
||||
public static void loadWorldGen() {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
12
src/main/java/cr0s/warpdrive/conf/XmlRepresentable.java
Normal file
12
src/main/java/cr0s/warpdrive/conf/XmlRepresentable.java
Normal file
|
@ -0,0 +1,12 @@
|
|||
package cr0s.warpdrive.conf;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
public interface XmlRepresentable {
|
||||
|
||||
public void loadFromXmlElement(Element e) throws InvalidXmlException;
|
||||
|
||||
public void saveToXmlElement(Element e, Document d) throws InvalidXmlException;
|
||||
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package cr0s.warpdrive.conf.structures;
|
||||
|
||||
import net.minecraft.world.gen.feature.WorldGenerator;
|
||||
|
||||
/**
|
||||
* @author Francesco
|
||||
*
|
||||
*/
|
||||
public abstract class DeployableStructure extends WorldGenerator {
|
||||
|
||||
private int height;
|
||||
private int width;
|
||||
private int length;
|
||||
|
||||
public DeployableStructure(int height, int width, int length) {
|
||||
this.height = height;
|
||||
this.width = width;
|
||||
this.length = length;
|
||||
}
|
||||
|
||||
public int getHeight() {
|
||||
return height;
|
||||
}
|
||||
|
||||
public int getWidth() {
|
||||
return width;
|
||||
}
|
||||
|
||||
public int getLength() {
|
||||
return length;
|
||||
}
|
||||
|
||||
}
|
249
src/main/java/cr0s/warpdrive/conf/structures/Orb.java
Normal file
249
src/main/java/cr0s/warpdrive/conf/structures/Orb.java
Normal file
|
@ -0,0 +1,249 @@
|
|||
package cr0s.warpdrive.conf.structures;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
import cr0s.warpdrive.WarpDrive;
|
||||
import cr0s.warpdrive.conf.InvalidXmlException;
|
||||
import cr0s.warpdrive.conf.OreManager.OreSpawnValue;
|
||||
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) 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) {
|
||||
for (OrbShell shell : shells) {
|
||||
Element tmp = d.createElement("shell");
|
||||
shell.saveToXmlElement(tmp, d);
|
||||
e.appendChild(tmp);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean generate(World p_76484_1_, Random p_76484_2_, int p_76484_3_, int p_76484_4_, int p_76484_5_) {
|
||||
// TODO Auto-generated method stub
|
||||
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;
|
||||
|
||||
private HashMap<String, Integer> compositionBlocks;
|
||||
|
||||
private Block[] blockWeights;
|
||||
|
||||
private String name;
|
||||
|
||||
private int totalWeight;
|
||||
|
||||
private double genericOreChance;
|
||||
|
||||
public OrbShell() {
|
||||
compositionBlocks = new HashMap<String, Integer>();
|
||||
totalWeight = 1;
|
||||
blockWeights = new Block[0];
|
||||
oreSpawnValue = null;
|
||||
genericOreChance = 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)];
|
||||
}
|
||||
|
||||
public int getRadiusInner() {
|
||||
return radiusInner;
|
||||
}
|
||||
|
||||
public void setRadiusInner(int radiusInner) {
|
||||
|
||||
this.radiusInner = radiusInner;
|
||||
}
|
||||
|
||||
public int getRadiusOuter() {
|
||||
return radiusOuter;
|
||||
}
|
||||
|
||||
public void setRadiusOuter(int radiusOuter) {
|
||||
this.radiusOuter = radiusOuter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadFromXmlElement(Element e) throws InvalidXmlException {
|
||||
|
||||
WarpDrive.logger.info("Loading shell " + e.getAttribute("name"));
|
||||
name = e.getAttribute("name");
|
||||
|
||||
totalWeight = 0;
|
||||
|
||||
try {
|
||||
radiusInner = Integer.parseInt(e.getAttribute("radiusInner"));
|
||||
radiusOuter = Integer.parseInt(e.getAttribute("radiusOuter"));
|
||||
|
||||
if (radiusInner < 1 || radiusInner > radiusOuter)
|
||||
throw new InvalidXmlException("Orb creation arguments are incorrect!");
|
||||
|
||||
NodeList compBlocks = e.getElementsByTagName("CompositionBlock");
|
||||
for (int i = 0; i < compBlocks.getLength(); i++) {
|
||||
Element tmp = (Element) compBlocks.item(i);
|
||||
|
||||
if (!tmp.hasAttribute("weight"))
|
||||
throw new InvalidXmlException("Shell is missing weight at place " + i + "!");
|
||||
|
||||
if (!tmp.hasAttribute("block"))
|
||||
throw new InvalidXmlException("Shell is missing block at place " + i + "!");
|
||||
|
||||
int tmpWeight = Integer.parseInt(tmp.getAttribute("weight"));
|
||||
|
||||
if (tmpWeight < 1)
|
||||
throw new InvalidXmlException("Weight is less than 1 at place " + i + "!");
|
||||
|
||||
String tmpBlock = tmp.getAttribute("block");
|
||||
|
||||
if (Block.getBlockFromName(tmpBlock) == null)
|
||||
throw new InvalidXmlException("Shell has unknown block at place " + i + "!");
|
||||
|
||||
totalWeight += tmpWeight;
|
||||
|
||||
compositionBlocks.put(tmpBlock, tmpWeight);
|
||||
}
|
||||
|
||||
HashMap<String, Integer> categoryTemp = new HashMap<String, Integer>();
|
||||
|
||||
NodeList oreCategories = e.getElementsByTagName("OreCategory");
|
||||
for (int i = 0; i < oreCategories.getLength(); i++) {
|
||||
Element cat = (Element) oreCategories.item(i);
|
||||
|
||||
if (!cat.hasAttribute("weight"))
|
||||
throw new InvalidXmlException("OreCategory " + i + " must have a weight");
|
||||
|
||||
if (!cat.hasAttribute("category"))
|
||||
throw new InvalidXmlException("OreCategory " + i + " must have a category");
|
||||
|
||||
int weight = Integer.parseInt(cat.getAttribute("weight"));
|
||||
String oreSpawnCategory = cat.getAttribute("category");
|
||||
|
||||
if (OreSpawnValue.getOreSpawnValue(oreSpawnCategory) == null)
|
||||
throw new InvalidXmlException("Shell has an invalid ores category!");
|
||||
|
||||
if (weight < 1)
|
||||
throw new InvalidXmlException("Shell has an invalid ores probability!");
|
||||
|
||||
totalWeight += weight;
|
||||
|
||||
if(categoryTemp.containsKey(oreSpawnCategory))
|
||||
throw new InvalidXmlException("OreCategory used twice in same shell!");
|
||||
|
||||
categoryTemp.put(oreSpawnCategory, weight);
|
||||
|
||||
}
|
||||
|
||||
int index = 0;
|
||||
blockWeights = new Block[totalWeight];
|
||||
|
||||
for (Entry<String, Integer> compBlock : compositionBlocks.entrySet()) {
|
||||
|
||||
Block bl = Block.getBlockFromName(compBlock.getKey());
|
||||
|
||||
for (int i = 0; i < compBlock.getValue(); i++) {
|
||||
blockWeights[index++] = bl;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
for(Entry<String, Integer> category : categoryTemp.entrySet()) {
|
||||
OreSpawnValue value = OreSpawnValue.getOreSpawnValue(category.getKey());
|
||||
for (Entry<Block, Double> compBlock : value.getOres()) {
|
||||
|
||||
for (int i = 0; i < compBlock.getValue(); i++) {
|
||||
blockWeights[index++] = bl;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} catch (NumberFormatException ex) {
|
||||
throw new InvalidXmlException("Invalid integer in shell " + name + "!");
|
||||
}
|
||||
|
||||
if (totalWeight < 1)
|
||||
throw new InvalidXmlException("At least one kind of block must be defined!");
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveToXmlElement(Element e, Document d) {
|
||||
WarpDrive.logger.info("Saving shell " + e.getAttribute("name"));
|
||||
|
||||
e.setAttribute("name", name);
|
||||
e.setAttribute("radiusInner", "" + radiusInner);
|
||||
e.setAttribute("radiusOuter", "" + radiusOuter);
|
||||
|
||||
for (Entry<String, Integer> compBlock : compositionBlocks.entrySet()) {
|
||||
Element child = d.createElement("CompositionBlock");
|
||||
child.setAttribute("weight", compBlock.getValue() + "");
|
||||
child.setAttribute("block", compBlock.getKey());
|
||||
e.appendChild(child);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
10
src/main/java/cr0s/warpdrive/conf/structures/Planetoid.java
Normal file
10
src/main/java/cr0s/warpdrive/conf/structures/Planetoid.java
Normal file
|
@ -0,0 +1,10 @@
|
|||
package cr0s.warpdrive.conf.structures;
|
||||
|
||||
public class Planetoid extends Orb {
|
||||
|
||||
public Planetoid(int diameter) {
|
||||
super(diameter);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
}
|
24
src/main/java/cr0s/warpdrive/conf/structures/Star.java
Normal file
24
src/main/java/cr0s/warpdrive/conf/structures/Star.java
Normal file
|
@ -0,0 +1,24 @@
|
|||
package cr0s.warpdrive.conf.structures;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.world.World;
|
||||
import cr0s.warpdrive.world.EntityStarCore;
|
||||
|
||||
public class Star extends Orb {
|
||||
|
||||
public Star(int diameter) {
|
||||
super(diameter);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean generate(World p_76484_1_, Random p_76484_2_, int p_76484_3_, int p_76484_4_, int p_76484_5_) {
|
||||
boolean success = super.generate(p_76484_1_, p_76484_2_, p_76484_3_, p_76484_4_, p_76484_5_);
|
||||
|
||||
if (success)
|
||||
p_76484_1_.spawnEntityInWorld(new EntityStarCore(p_76484_1_, p_76484_3_, p_76484_4_, p_76484_5_, super.getHeight() / 2));
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package cr0s.warpdrive.conf.structures;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class StructureManager {
|
||||
|
||||
public StructureManager() {
|
||||
|
||||
}
|
||||
|
||||
public void loadStructures(File f) {
|
||||
//TODO:
|
||||
}
|
||||
|
||||
}
|
|
@ -2,14 +2,13 @@ package cr0s.warpdrive.world;
|
|||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cr0s.warpdrive.WarpDrive;
|
||||
import cr0s.warpdrive.conf.WarpDriveConfig;
|
||||
import cr0s.warpdrive.conf.structures.Orb;
|
||||
import cr0s.warpdrive.data.JumpBlock;
|
||||
|
||||
/*
|
||||
|
@ -47,12 +46,6 @@ public final class EntitySphereGen extends Entity {
|
|||
public int zCoord;
|
||||
|
||||
private int radius;
|
||||
private Block defaultBlock;
|
||||
private boolean hollow;
|
||||
private boolean fillingSphere; // new sphere blocks does not replace
|
||||
// existing blocks (for gases & moons)
|
||||
private boolean generateOres; // generate random surface blocks (ores) or
|
||||
// fixed blockID
|
||||
private int gasColor;
|
||||
|
||||
private final int BLOCKS_PER_TICK = 5000;
|
||||
|
@ -69,12 +62,14 @@ public final class EntitySphereGen extends Entity {
|
|||
|
||||
private ArrayList<JumpBlock> blocks;
|
||||
private int defaultMeta;
|
||||
private Orb orb;
|
||||
private boolean replace;
|
||||
|
||||
public EntitySphereGen(World world) {
|
||||
super(world);
|
||||
}
|
||||
|
||||
public EntitySphereGen(World world, int x, int y, int z, int radius, Block block, int blockMeta, boolean hollow, boolean fillingSphere, boolean generateOres) {
|
||||
public EntitySphereGen(World world, int x, int y, int z, int radius, Orb orb, boolean replace) {
|
||||
super(world);
|
||||
this.xCoord = x;
|
||||
this.posX = x;
|
||||
|
@ -82,17 +77,14 @@ public final class EntitySphereGen extends Entity {
|
|||
this.posY = y;
|
||||
this.zCoord = z;
|
||||
this.posZ = z;
|
||||
this.radius = radius;
|
||||
this.hollow = hollow;
|
||||
this.fillingSphere = fillingSphere;
|
||||
this.generateOres = generateOres;
|
||||
this.gasColor = worldObj.rand.nextInt(12);
|
||||
this.radius = radius;
|
||||
this.state = STATE_SAVING;
|
||||
this.pregenSize = (int) Math.ceil(Math.PI * 4.0F / 3.0F * Math.pow(radius + 1, 3));
|
||||
blocks = new ArrayList<JumpBlock>(this.pregenSize);
|
||||
this.defaultBlock = block;
|
||||
this.defaultMeta = blockMeta;
|
||||
this.ticksDelay = world.rand.nextInt(60);
|
||||
this.orb = orb;
|
||||
this.replace = replace;
|
||||
}
|
||||
|
||||
public void killEntity() {
|
||||
|
@ -150,57 +142,43 @@ public final class EntitySphereGen extends Entity {
|
|||
private void tickScheduleBlocks() {
|
||||
// LocalProfiler.start("EntitySphereGen.tickScheduleBlocks");
|
||||
radius += 0.5D; // Radius from center of block
|
||||
double radiusSq = radius * radius; // Optimization to avoid square roots
|
||||
double radius1Sq = (radius - 1.0D) * (radius - 1.0D); // for hollow
|
||||
// sphere
|
||||
int ceilRadius = (int) Math.ceil(radius);
|
||||
|
||||
// Pass the cube and check points for sphere equation x^2 + y^2 + z^2 =
|
||||
// r^2
|
||||
Block block = defaultBlock;
|
||||
for (int x = 0; x <= ceilRadius; x++) {
|
||||
double x2 = (x + 0.5D) * (x + 0.5D);
|
||||
for (int y = 0; y <= ceilRadius; y++) {
|
||||
double y2 = (y + 0.5D) * (y + 0.5D);
|
||||
for (int z = 0; z <= ceilRadius; z++) {
|
||||
double z2 = (z + 0.5D) * (z + 0.5D);
|
||||
double dSq = x2 + y2 + z2; // Distance from current position
|
||||
double dSq = Math.sqrt(x2 + y2 + z2); // Distance from current position
|
||||
// to center
|
||||
|
||||
// Skip too far blocks
|
||||
if (dSq > radiusSq)
|
||||
continue;
|
||||
// Hollow sphere condition
|
||||
if ((hollow)
|
||||
&& ((dSq < radius1Sq) || ((lengthSq(x + 1.5D, y + 0.5D, z + 0.5D) <= radiusSq)
|
||||
&& (lengthSq(x + 0.5D, y + 1.5D, z + 0.5D) <= radiusSq) && (lengthSq(x + 0.5D, y + 0.5D, z + 1.5D) <= radiusSq))))
|
||||
if (dSq > radius)
|
||||
continue;
|
||||
|
||||
if (generateOres)
|
||||
block = WarpDriveConfig.getRandomSurfaceBlock(worldObj.rand, defaultBlock, true);
|
||||
int rad = (int) Math.ceil(dSq);
|
||||
|
||||
// Add blocks to memory
|
||||
addBlock(new JumpBlock(block, defaultMeta, xCoord + x, yCoord + y, zCoord + z));
|
||||
if (generateOres)
|
||||
block = WarpDriveConfig.getRandomSurfaceBlock(worldObj.rand, defaultBlock, true);
|
||||
addBlock(new JumpBlock(block, defaultMeta, xCoord - x, yCoord + y, zCoord + z));
|
||||
if (generateOres)
|
||||
block = WarpDriveConfig.getRandomSurfaceBlock(worldObj.rand, defaultBlock, true);
|
||||
addBlock(new JumpBlock(block, defaultMeta, xCoord + x, yCoord - y, zCoord + z));
|
||||
if (generateOres)
|
||||
block = WarpDriveConfig.getRandomSurfaceBlock(worldObj.rand, defaultBlock, true);
|
||||
addBlock(new JumpBlock(block, defaultMeta, xCoord + x, yCoord + y, zCoord - z));
|
||||
if (generateOres)
|
||||
block = WarpDriveConfig.getRandomSurfaceBlock(worldObj.rand, defaultBlock, true);
|
||||
addBlock(new JumpBlock(block, defaultMeta, xCoord - x, yCoord - y, zCoord + z));
|
||||
if (generateOres)
|
||||
block = WarpDriveConfig.getRandomSurfaceBlock(worldObj.rand, defaultBlock, true);
|
||||
addBlock(new JumpBlock(block, defaultMeta, xCoord + x, yCoord - y, zCoord - z));
|
||||
if (generateOres)
|
||||
block = WarpDriveConfig.getRandomSurfaceBlock(worldObj.rand, defaultBlock, true);
|
||||
addBlock(new JumpBlock(block, defaultMeta, xCoord - x, yCoord + y, zCoord - z));
|
||||
if (generateOres)
|
||||
block = WarpDriveConfig.getRandomSurfaceBlock(worldObj.rand, defaultBlock, true);
|
||||
addBlock(new JumpBlock(block, defaultMeta, xCoord - x, yCoord - y, zCoord - z));
|
||||
addBlock(new JumpBlock(orb.getBlockForRadius(rand, rad), defaultMeta, xCoord + x, yCoord + y, zCoord + z));
|
||||
|
||||
addBlock(new JumpBlock(orb.getBlockForRadius(rand, rad), defaultMeta, xCoord - x, yCoord + y, zCoord + z));
|
||||
|
||||
addBlock(new JumpBlock(orb.getBlockForRadius(rand, rad), defaultMeta, xCoord + x, yCoord - y, zCoord + z));
|
||||
|
||||
addBlock(new JumpBlock(orb.getBlockForRadius(rand, rad), defaultMeta, xCoord + x, yCoord + y, zCoord - z));
|
||||
|
||||
addBlock(new JumpBlock(orb.getBlockForRadius(rand, rad), defaultMeta, xCoord - x, yCoord - y, zCoord + z));
|
||||
|
||||
addBlock(new JumpBlock(orb.getBlockForRadius(rand, rad), defaultMeta, xCoord + x, yCoord - y, zCoord - z));
|
||||
|
||||
addBlock(new JumpBlock(orb.getBlockForRadius(rand, rad), defaultMeta, xCoord - x, yCoord + y, zCoord - z));
|
||||
|
||||
addBlock(new JumpBlock(orb.getBlockForRadius(rand, rad), defaultMeta, xCoord - x, yCoord - y, zCoord - z));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -214,7 +192,7 @@ public final class EntitySphereGen extends Entity {
|
|||
if (blocks == null)
|
||||
return;
|
||||
// Replace water with random gas (ship in moon)
|
||||
if (worldObj.getBlock(jb.x, jb.y, jb.z).isAssociatedBlock(Blocks.leaves)) {
|
||||
if (worldObj.getBlock(jb.x, jb.y, jb.z).isAssociatedBlock(Blocks.water)) {
|
||||
if (worldObj.rand.nextInt(50) != 1) {
|
||||
jb.block = WarpDrive.blockGas;
|
||||
jb.blockMeta = gasColor;
|
||||
|
@ -223,15 +201,11 @@ public final class EntitySphereGen extends Entity {
|
|||
return;
|
||||
}
|
||||
// Do not replace existing blocks if fillingSphere is true
|
||||
if (fillingSphere && !worldObj.isAirBlock(jb.x, jb.y, jb.z))
|
||||
if (!replace && !worldObj.isAirBlock(jb.x, jb.y, jb.z))
|
||||
return;
|
||||
blocks.add(jb);
|
||||
}
|
||||
|
||||
private static double lengthSq(double x, double y, double z) {
|
||||
return (x * x) + (y * y) + (z * z);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void readEntityFromNBT(NBTTagCompound tag) {
|
||||
}
|
||||
|
|
30
src/main/resources/structures/default.xml
Normal file
30
src/main/resources/structures/default.xml
Normal file
|
@ -0,0 +1,30 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<structure type="star" name="red_giant" radius="40" maxScaling="3.0">
|
||||
<shell name="core" radiusInner="1" radiusOuter="10" >
|
||||
<CompositionBlock weight="1" block="net.minecraft.blocks.iron_block" />
|
||||
</shell>
|
||||
|
||||
<shell name="mantle" radiusInner="11" radiusOuter="30" >
|
||||
<CompositionBlock weight="10" block="net.minecraft.blocks.sand" />
|
||||
<CompositionBlock weight="1" block="net.minecraft.blocks.iron_block" />
|
||||
</shell>
|
||||
|
||||
<shell name="surface" radiusInner="31" radiusOuter="40" >
|
||||
<CompositionBlock weight="5" block="net.minecraft.blocks.glowstone" />
|
||||
<CompositionBlock weight="10" block="net.minecraft.blocks.lava" />
|
||||
</shell>
|
||||
|
||||
</structure>
|
||||
|
||||
<structure type="planetoid" name="theMoon" radius="20" maxScaling="2.0">
|
||||
<shell name="core" radiusInner="1" radiusOuter="5" ores="rare">
|
||||
<CompositionBlock weight="1" block="net.minecraft.blocks.iron_block" />
|
||||
</shell>
|
||||
|
||||
<shell name="mantle" radiusInner="6" radiusOuter="20" ores="common">
|
||||
<CompositionBlock weight="10" block="net.minecraft.blocks.stone" />
|
||||
<CompositionBlock weight="3" block="net.minecraft.blocks.clay" />
|
||||
</shell>
|
||||
|
||||
</structure>
|
Loading…
Add table
Reference in a new issue