Allow oregen in non-vanilla dimensions. Closes #1571

This commit is contained in:
drcrazy 2018-08-08 17:00:02 +03:00
parent 1cd5e06757
commit fb957e9dac
2 changed files with 39 additions and 36 deletions

View file

@ -114,8 +114,8 @@ public class TechRebornWorldGen implements IWorldGenerator {
for (OreConfig ore : config) { for (OreConfig ore : config) {
if (ore.blockName.equals(defaultOre.blockName) && ore.meta == defaultOre.meta) { if (ore.blockName.equals(defaultOre.blockName) && ore.meta == defaultOre.meta) {
hasFoundOre = true; hasFoundOre = true;
ore.state = defaultOre.state; // Should allow for states to // Should allow for states to be saved/loaded
// be saved/loaded ore.state = defaultOre.state;
} }
} }
if (!hasFoundOre) { if (!hasFoundOre) {
@ -194,52 +194,53 @@ public class TechRebornWorldGen implements IWorldGenerator {
boolean genTree = false; boolean genTree = false;
List<OreConfig> list = new ArrayList<>(); List<OreConfig> list = new ArrayList<>();
Predicate<IBlockState> predicate = BlockMatcher.forBlock(Blocks.STONE); Predicate<IBlockState> predicate = BlockMatcher.forBlock(Blocks.STONE);
if (world.provider.isSurfaceWorld()) { if (world.provider.getDimension() == -1) {
list.addAll(getAllGenOresFromList(config.overworldOres));
genTree = true;
} else if (world.provider.getDimension() == -1) {
list.addAll(getAllGenOresFromList(config.neatherOres)); list.addAll(getAllGenOresFromList(config.neatherOres));
predicate = BlockMatcher.forBlock(Blocks.NETHERRACK); predicate = BlockMatcher.forBlock(Blocks.NETHERRACK);
} else if (world.provider.getDimension() == 1) { } else if (world.provider.getDimension() == 1) {
list.addAll(getAllGenOresFromList(config.endOres)); list.addAll(getAllGenOresFromList(config.endOres));
predicate = BlockMatcher.forBlock(Blocks.END_STONE); predicate = BlockMatcher.forBlock(Blocks.END_STONE);
} }
else if (config.overworldOresInModdedDims || world.provider.getDimension() == 0) {
list.addAll(getAllGenOresFromList(config.overworldOres));
genTree = true;
}
if (!list.isEmpty() && config.generateOres) { if (!list.isEmpty() && config.generateOres) {
int xPos, yPos, zPos; int xPos, yPos, zPos;
for (OreConfig ore : list) { for (OreConfig ore : list) {
WorldGenMinable worldGenMinable = new WorldGenMinable(ore.state, ore.veinSize, predicate); WorldGenMinable worldGenMinable = new WorldGenMinable(ore.state, ore.veinSize, predicate);
if (ore.state != null) { if (ore.state == null) {
for (int i = 0; i < ore.veinsPerChunk; i++) { continue;
xPos = chunkX * 16 + random.nextInt(16); }
if (ore.maxYHeight == -1 || ore.minYHeight == -1) { for (int i = 0; i < ore.veinsPerChunk; i++) {
continue; xPos = chunkX * 16 + random.nextInt(16);
} if (ore.maxYHeight == -1 || ore.minYHeight == -1) {
yPos = ore.minYHeight + random.nextInt(ore.maxYHeight - ore.minYHeight); continue;
zPos = chunkZ * 16 + random.nextInt(16); }
BlockPos pos = new BlockPos(xPos, yPos, zPos); yPos = ore.minYHeight + random.nextInt(ore.maxYHeight - ore.minYHeight);
zPos = chunkZ * 16 + random.nextInt(16);
if (ore.veinSize < 4){ BlockPos pos = new BlockPos(xPos, yPos, zPos);
// Workaround for small veins
for (int j = 1; j < ore.veinSize; j++) { if (ore.veinSize < 4) {
// standard worldgen offset is added here like in WorldGenMinable#generate // Workaround for small veins
BlockPos smallVeinPos = pos.add(8, 0, 8); for (int j = 1; j < ore.veinSize; j++) {
smallVeinPos.add(random.nextInt(2), random.nextInt(2), random.nextInt(2)); // standard worldgen offset is added here like in WorldGenMinable#generate
IBlockState blockState = world.getBlockState(smallVeinPos); BlockPos smallVeinPos = pos.add(8, 0, 8);
if (blockState.getBlock().isReplaceableOreGen(blockState, world, smallVeinPos, predicate)) { smallVeinPos.add(random.nextInt(2), random.nextInt(2), random.nextInt(2));
world.setBlockState(smallVeinPos, ore.state, 2); IBlockState blockState = world.getBlockState(smallVeinPos);
} if (blockState.getBlock().isReplaceableOreGen(blockState, world, smallVeinPos, predicate)) {
} world.setBlockState(smallVeinPos, ore.state, 2);
} else {
try {
worldGenMinable.generate(world, random, pos);
} catch (ArrayIndexOutOfBoundsException e) {
Core.logHelper.error("Something bad is happening during world gen the ore "
+ ore.blockNiceName
+ " caused a crash when generating. Report this to the TechReborn devs with a log");
} }
} }
} else {
try {
worldGenMinable.generate(world, random, pos);
} catch (ArrayIndexOutOfBoundsException e) {
Core.logHelper.error("Something bad is happening during world gen the ore "
+ ore.blockNiceName
+ " caused a crash when generating. Report this to the TechReborn devs with a log");
}
} }
} }
} }

View file

@ -36,6 +36,8 @@ public class WorldGenConfig {
public boolean generateOres = true; public boolean generateOres = true;
public boolean retroGenOres = false; public boolean retroGenOres = false;
public boolean overworldOresInModdedDims = true;
public List<OreConfig> overworldOres; public List<OreConfig> overworldOres;