From 2bba86190c94278ed7e7531beb2a4d3f84ffdf4b Mon Sep 17 00:00:00 2001 From: LemADEC Date: Sun, 31 Jan 2016 22:54:48 +0100 Subject: [PATCH] Reimplemented safe corridor in space dimension (y> 200) Added smaller bottom safe corridor (y < 5) --- .../warpdrive/config/WarpDriveConfig.java | 9 +++++ .../config/structures/MetaOrbInstance.java | 8 +++-- .../config/structures/OrbInstance.java | 9 +++-- .../config/structures/StructureReference.java | 33 +++++++++++++++++++ .../warpdrive/world/SpaceWorldGenerator.java | 20 ++--------- 5 files changed, 56 insertions(+), 23 deletions(-) create mode 100644 src/main/java/cr0s/warpdrive/config/structures/StructureReference.java diff --git a/src/main/java/cr0s/warpdrive/config/WarpDriveConfig.java b/src/main/java/cr0s/warpdrive/config/WarpDriveConfig.java index a0773831..a0b2e6ea 100644 --- a/src/main/java/cr0s/warpdrive/config/WarpDriveConfig.java +++ b/src/main/java/cr0s/warpdrive/config/WarpDriveConfig.java @@ -11,6 +11,7 @@ import java.util.Arrays; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; + import org.xml.sax.ErrorHandler; import org.xml.sax.SAXException; import org.xml.sax.SAXParseException; @@ -21,6 +22,7 @@ import cpw.mods.fml.common.registry.GameRegistry; import cr0s.warpdrive.WarpDrive; import cr0s.warpdrive.config.filler.FillerManager; import cr0s.warpdrive.config.structures.StructureManager; +import cr0s.warpdrive.config.structures.StructureReference; import cr0s.warpdrive.data.Planet; import net.minecraft.block.Block; import net.minecraft.item.Item; @@ -121,6 +123,13 @@ public class WarpDriveConfig { // Planets public static Planet[] PLANETS = null; + // Space generator + public static int SPACE_GENERATOR_Y_MIN_CENTER = 55; + public static int SPACE_GENERATOR_Y_MAX_CENTER = 128; + public static int SPACE_GENERATOR_Y_MIN_BORDER = 5; + public static int SPACE_GENERATOR_Y_MAX_BORDER = 200; + public static RandomCollection SPACE_GENERATOR_STRUCTURES_CHANCES = null; + // Ship public static int SHIP_MAX_ENERGY_STORED = 100000000; public static int SHIP_NORMALJUMP_ENERGY_PER_BLOCK = 10; diff --git a/src/main/java/cr0s/warpdrive/config/structures/MetaOrbInstance.java b/src/main/java/cr0s/warpdrive/config/structures/MetaOrbInstance.java index b82076ea..89fb0e43 100644 --- a/src/main/java/cr0s/warpdrive/config/structures/MetaOrbInstance.java +++ b/src/main/java/cr0s/warpdrive/config/structures/MetaOrbInstance.java @@ -30,15 +30,17 @@ public class MetaOrbInstance extends OrbInstance { } LocalProfiler.start("[AsteroidInstance] Generating MetaOrb " + structure.name + " of " + metashell.count + " cores with radius of " + totalThickness); + int y2 = Math.min(WarpDriveConfig.SPACE_GENERATOR_Y_MAX_BORDER - totalThickness - (int)metashell.radius, + Math.max(y, WarpDriveConfig.SPACE_GENERATOR_Y_MIN_BORDER + totalThickness + (int)metashell.radius)); if (((MetaOrb)structure).metashell == null) { - return super.generate(world, random, x, y, z); + return super.generate(world, random, x, y2, z); } // generate an abstract form for the core for (VectorI location: metashell.locations) { // place core block if (metashell.block != null) { - world.setBlock(x + location.x, y + location.y, z + location.z, metashell.block, metashell.metadata, 2); + world.setBlock(x + location.x, y2 + location.y, z + location.z, metashell.block, metashell.metadata, 2); } // calculate distance to borders of generation area @@ -52,7 +54,7 @@ public class MetaOrbInstance extends OrbInstance { maxLocalRadius = Math.max(minThickness, maxLocalRadius); // Generate shell - addShell(world, new VectorI(x, y, z).add(location), maxLocalRadius); + addShell(world, new VectorI(x, y2, z).add(location), maxLocalRadius); } LocalProfiler.stop(); diff --git a/src/main/java/cr0s/warpdrive/config/structures/OrbInstance.java b/src/main/java/cr0s/warpdrive/config/structures/OrbInstance.java index dd5d3daf..21dd7efa 100644 --- a/src/main/java/cr0s/warpdrive/config/structures/OrbInstance.java +++ b/src/main/java/cr0s/warpdrive/config/structures/OrbInstance.java @@ -4,6 +4,7 @@ import java.util.Random; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.World; +import cr0s.warpdrive.config.WarpDriveConfig; import cr0s.warpdrive.config.structures.Orb.OrbShell; import cr0s.warpdrive.world.EntitySphereGen; import cr0s.warpdrive.world.EntityStarCore; @@ -71,13 +72,15 @@ public class OrbInstance extends AbstractInstance { @Override public boolean generate(World world, Random random, int x, int y, int z) { boolean hasShip = schematicName != null && !schematicName.isEmpty(); + int y2 = Math.min(WarpDriveConfig.SPACE_GENERATOR_Y_MAX_BORDER - totalThickness, + Math.max(y, WarpDriveConfig.SPACE_GENERATOR_Y_MIN_BORDER + totalThickness)); if (hasShip) { - new WorldGenSmallShip(false).generate(world, random, x, y, z); + new WorldGenSmallShip(false).generate(world, random, x, y2, z); } - EntitySphereGen entitySphereGen = new EntitySphereGen(world, x, y, z, this, !hasShip); + EntitySphereGen entitySphereGen = new EntitySphereGen(world, x, y2, z, this, !hasShip); world.spawnEntityInWorld(entitySphereGen); if (((Orb)structure).hasStarCore) { - return world.spawnEntityInWorld(new EntityStarCore(world, x, y, z, totalThickness)); + return world.spawnEntityInWorld(new EntityStarCore(world, x, y2, z, totalThickness)); } return true; } diff --git a/src/main/java/cr0s/warpdrive/config/structures/StructureReference.java b/src/main/java/cr0s/warpdrive/config/structures/StructureReference.java new file mode 100644 index 00000000..8c754d8f --- /dev/null +++ b/src/main/java/cr0s/warpdrive/config/structures/StructureReference.java @@ -0,0 +1,33 @@ +package cr0s.warpdrive.config.structures; + +import java.util.Random; + +import net.minecraft.world.World; + +import org.w3c.dom.Element; + +import cr0s.warpdrive.config.InvalidXmlException; + +public class StructureReference extends AbstractStructure { + + public StructureReference(final String group, final String name) { + super(group, name); + } + + @Override + public boolean loadFromXmlElement(Element element) throws InvalidXmlException { + super.loadFromXmlElement(element); + + return true; + } + + @Override + public boolean generate(World world, Random random, int x, int y, int z) { + return instantiate(random).generate(world, random, x, y, z); + } + + @Override + public AbstractInstance instantiate(Random random) { + return StructureManager.getStructure(random, group, name).instantiate(random); + } +} diff --git a/src/main/java/cr0s/warpdrive/world/SpaceWorldGenerator.java b/src/main/java/cr0s/warpdrive/world/SpaceWorldGenerator.java index a52c1cb2..c96fc48f 100644 --- a/src/main/java/cr0s/warpdrive/world/SpaceWorldGenerator.java +++ b/src/main/java/cr0s/warpdrive/world/SpaceWorldGenerator.java @@ -18,21 +18,6 @@ import cr0s.warpdrive.config.structures.StructureManager; * @author Cr0s */ public class SpaceWorldGenerator implements IWorldGenerator { - // Radius of simple moon - public final int MOON_RADIUS = 32; - public final int MOON_CORE_RADIUS = 10; - - // Star radius - public final int RED_DWARF_RADIUS = 42; - public final int YELLOW_GIANT_RADIUS = 64; - public final int YELLOW_SUPERGIANT_RADIUS = 80; - - // Upper than 200 nothing should generate naturally (safe place) - public static int Y_LIMIT_HARD_MAX = 200; - // Upper than 128 almost nothing will be generated - public static int Y_LIMIT_SOFT_MAX = 128; - // Lower limit - public static int Y_LIMIT_SOFT_MIN = 55; /** * Generator for chunk @@ -55,7 +40,7 @@ public class SpaceWorldGenerator implements IWorldGenerator { if (WarpDriveConfig.G_SPACE_WORLDBORDER_BLOCKS > 0 && (Math.abs(x) > WarpDriveConfig.G_SPACE_WORLDBORDER_BLOCKS || Math.abs(z) > WarpDriveConfig.G_SPACE_WORLDBORDER_BLOCKS)) { return; } - int y = Y_LIMIT_SOFT_MIN + random.nextInt(Y_LIMIT_SOFT_MAX - Y_LIMIT_SOFT_MIN); + int y = WarpDriveConfig.SPACE_GENERATOR_Y_MIN_CENTER + random.nextInt(WarpDriveConfig.SPACE_GENERATOR_Y_MAX_CENTER - WarpDriveConfig.SPACE_GENERATOR_Y_MIN_CENTER); // Moon setup if (random.nextInt(700) == 1) { AbstractStructure moon = StructureManager.getStructure(world.rand, StructureManager.GROUP_MOONS, null); @@ -145,7 +130,8 @@ public class SpaceWorldGenerator implements IWorldGenerator { int numOfSmallAsteroids = Math.round((1.0F - bigRatio) * surfaceSmall / surfacePerAsteroid); int numOfClouds = Math.round(numOfBigAsteroids * 1.0F / (10.0F + world.rand.nextInt(10))); int maxHeight = 70 + world.rand.nextInt(50); - int y2 = Math.min(Y_LIMIT_HARD_MAX - maxHeight, Math.max(y1, maxHeight)); + int y2 = Math.min(WarpDriveConfig.SPACE_GENERATOR_Y_MAX_BORDER - maxHeight, + Math.max(y1, WarpDriveConfig.SPACE_GENERATOR_Y_MIN_BORDER + maxHeight)); WarpDrive.logger.info("Generating asteroid field at " + x + "," + y2 + "," + z + " qty " + numOfBigAsteroids + ", " + numOfSmallAsteroids + ", " + numOfClouds + " over " + maxDistance + ", " + maxHeight + " surfacePerAsteroid " + String.format("%.1f", surfacePerAsteroid));