From 5af9d8491d5e17aad41050b2b1afcd3a0277163a Mon Sep 17 00:00:00 2001 From: WhichOnesPink Date: Tue, 3 Nov 2015 07:26:46 +0000 Subject: [PATCH] Fixed issue with scattered features generating everywhere. --- .../structure/MapGenScatteredFeatureRTG.java | 258 ++++++------------ 1 file changed, 84 insertions(+), 174 deletions(-) diff --git a/src/main/java/rtg/world/gen/structure/MapGenScatteredFeatureRTG.java b/src/main/java/rtg/world/gen/structure/MapGenScatteredFeatureRTG.java index 0f60511ef..2a8864629 100644 --- a/src/main/java/rtg/world/gen/structure/MapGenScatteredFeatureRTG.java +++ b/src/main/java/rtg/world/gen/structure/MapGenScatteredFeatureRTG.java @@ -1,23 +1,9 @@ package rtg.world.gen.structure; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Random; - -import org.apache.logging.log4j.Level; - -import rtg.config.rtg.ConfigRTG; - import com.google.common.collect.ImmutableList; import cpw.mods.fml.common.FMLLog; -import net.minecraft.entity.monster.EntityWitch; -import net.minecraft.util.MathHelper; import net.minecraft.world.World; import net.minecraft.world.biome.BiomeGenBase; import net.minecraft.world.gen.structure.ComponentScatteredFeaturePieces; @@ -27,106 +13,62 @@ import net.minecraftforge.common.BiomeDictionary; -public class MapGenScatteredFeatureRTG extends MapGenScatteredFeature -{ +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; +import java.util.Random; + +import org.apache.logging.log4j.Level; + +import rtg.config.rtg.ConfigRTG; +import rtg.util.Logger; + +/** + * Author: Choonster (https://github.com/Choonster) + * Source: https://github.com/Choonster/TestMod2/blob/1575b85ad8949381215f3aeb6ca76ea2368074de/src/main/java/com/choonster/testmod2/world/gen/structure/MapGenScatteredFeatureModBiomes.java + * + * Allows scattered features (jungle/desert temples, witch huts) to spawn in mod biomes equivalent to the vanilla biomes, + * i.e. any biome registered as JUNGLE, SANDY or SWAMP + * http://www.minecraftforum.net/forums/mapping-and-modding/minecraft-mods/modification-development/2471489-jungle-and-desert-temple-spawn-biome + */ +public class MapGenScatteredFeatureRTG extends MapGenScatteredFeature { public final List biomeTypes = ImmutableList.of(BiomeDictionary.Type.JUNGLE, BiomeDictionary.Type.SANDY, BiomeDictionary.Type.SWAMP); - - private static List biomelist = Arrays.asList(new BiomeGenBase[] {BiomeGenBase.desert, BiomeGenBase.desertHills, BiomeGenBase.jungle, - BiomeGenBase.jungleHills, BiomeGenBase.swampland}); - - /** contains possible spawns for scattered features */ - private List scatteredFeatureSpawnList; - - /** the maximum distance between scattered features */ - private int maxDistanceBetweenScatteredFeatures; - - /** the minimum distance between scattered features */ - private int minDistanceBetweenScatteredFeatures; - - private static final String __OBFID = "CL_00000471"; - - public MapGenScatteredFeatureRTG() - { - super(); - - int minDistanceScatteredFeatures = ConfigRTG.minDistanceScatteredFeatures; - int maxDistanceScatteredFeatures = ConfigRTG.maxDistanceScatteredFeatures; + + protected boolean canSpawnStructureAtCoords(int chunkX, int chunkZ) { - if (minDistanceScatteredFeatures > maxDistanceScatteredFeatures) { - minDistanceScatteredFeatures = 8; - maxDistanceScatteredFeatures = 32; - } + // These fields are private in the super class and always constant for non-flat worlds so inline them here + // Flat worlds don't fire InitMapGenEvent, so this class will never be used in a flat world - this.scatteredFeatureSpawnList = new ArrayList(); - this.minDistanceBetweenScatteredFeatures = minDistanceScatteredFeatures; - this.maxDistanceBetweenScatteredFeatures = maxDistanceScatteredFeatures; - this.scatteredFeatureSpawnList.add(new BiomeGenBase.SpawnListEntry(EntityWitch.class, 1, 1, 1)); - } - - public MapGenScatteredFeatureRTG(Map p_i2061_1_) - { - this(); - Iterator iterator = p_i2061_1_.entrySet().iterator(); + int minDistance = ConfigRTG.minDistanceScatteredFeatures; + int maxDistance = ConfigRTG.maxDistanceScatteredFeatures; - while (iterator.hasNext()) - { - Entry entry = (Entry) iterator.next(); - - if (((String) entry.getKey()).equals("distance")) - { - this.maxDistanceBetweenScatteredFeatures = - MathHelper.parseIntWithDefaultAndMax((String) entry.getValue(), this.maxDistanceBetweenScatteredFeatures, - this.minDistanceBetweenScatteredFeatures + 1); - } + if (minDistance > maxDistance) { + minDistance = 8; + maxDistance = 32; } - } - - @Override - public String func_143025_a() - { - return "Temple"; - } - - @Override - protected boolean canSpawnStructureAtCoords(int chunkX, int chunkZ) - { - int intX = chunkX; - int intZ = chunkZ; - if (chunkX < 0) - { - chunkX -= this.maxDistanceBetweenScatteredFeatures - 1; + final int minDistanceBetweenScatteredFeatures = minDistance; //Original value = 8 + final int maxDistanceBetweenScatteredFeatures = maxDistance; //Original value = 32 + + if (chunkX < 0) { + chunkX -= maxDistanceBetweenScatteredFeatures - 1; } - - if (chunkZ < 0) - { - chunkZ -= this.maxDistanceBetweenScatteredFeatures - 1; + + if (chunkZ < 0) { + chunkZ -= maxDistanceBetweenScatteredFeatures - 1; } - - int i1 = chunkX / this.maxDistanceBetweenScatteredFeatures; - int j1 = chunkZ / this.maxDistanceBetweenScatteredFeatures; + + int i1 = chunkX / maxDistanceBetweenScatteredFeatures; + int j1 = chunkZ / maxDistanceBetweenScatteredFeatures; Random random = this.worldObj.setRandomSeed(i1, j1, 14357617); - i1 *= this.maxDistanceBetweenScatteredFeatures; - j1 *= this.maxDistanceBetweenScatteredFeatures; - i1 += random.nextInt(this.maxDistanceBetweenScatteredFeatures - this.minDistanceBetweenScatteredFeatures); - j1 += random.nextInt(this.maxDistanceBetweenScatteredFeatures - this.minDistanceBetweenScatteredFeatures); - - if (intX == i1 && intZ == j1) - { - BiomeGenBase biomegenbase = this.worldObj.getWorldChunkManager().getBiomeGenAt(intX * 16 + 8, intZ * 16 + 8); - - Iterator iterator = biomelist.iterator(); - - while (iterator.hasNext()) - { - BiomeGenBase biomegenbase1 = (BiomeGenBase) iterator.next(); - - if (biomegenbase == biomegenbase1) - { - return true; - } - } - + i1 *= maxDistanceBetweenScatteredFeatures; + j1 *= maxDistanceBetweenScatteredFeatures; + i1 += random.nextInt(maxDistanceBetweenScatteredFeatures - minDistanceBetweenScatteredFeatures); + j1 += random.nextInt(maxDistanceBetweenScatteredFeatures - minDistanceBetweenScatteredFeatures); + + if (chunkX == i1 && chunkZ == j1) { + BiomeGenBase biomegenbase = this.worldObj.getWorldChunkManager().getBiomeGenAt(chunkX * 16 + 8, chunkZ * 16 + 8); + if (biomegenbase != null) { for (BiomeDictionary.Type type : biomeTypes) { if (BiomeDictionary.isBiomeOfType(biomegenbase, type)) { @@ -135,83 +77,51 @@ protected boolean canSpawnStructureAtCoords(int chunkX, int chunkZ) } } } - - return false; + + return super.canSpawnStructureAtCoords(chunkX, chunkZ); } - + @Override - protected StructureStart getStructureStart(int p_75049_1_, int p_75049_2_) - { - return new MapGenScatteredFeatureRTG.Start(this.worldObj, this.rand, p_75049_1_, p_75049_2_); + protected StructureStart getStructureStart(int chunkX, int chunkZ) { + return new Start(worldObj, rand, chunkX, chunkZ); } - - @Override - public boolean func_143030_a(int p_143030_1_, int p_143030_2_, int p_143030_3_) - { - StructureStart structurestart = this.func_143028_c(p_143030_1_, p_143030_2_, p_143030_3_); - - if (structurestart != null && structurestart instanceof MapGenScatteredFeatureRTG.Start - && !structurestart.getComponents().isEmpty()) - { - StructureComponent structurecomponent = (StructureComponent) structurestart.getComponents().getFirst(); - return structurecomponent instanceof ComponentScatteredFeaturePieces.SwampHut; - } - else - { - return false; + + public static class Start extends MapGenScatteredFeature.Start { + public Start() { } - } - - /** - * returns possible spawns for scattered features - */ - @Override - public List getScatteredFeatureSpawnList() - { - return this.scatteredFeatureSpawnList; - } - - public static class Start extends StructureStart - { - - private static final String __OBFID = "CL_00000472"; - - public Start() {} - - public Start(World p_i2060_1_, Random p_i2060_2_, int p_i2060_3_, int p_i2060_4_) - { - super(p_i2060_3_, p_i2060_4_); - BiomeGenBase biomegenbase = p_i2060_1_.getBiomeGenForCoords(p_i2060_3_ * 16 + 8, p_i2060_4_ * 16 + 8); + + public Start(World worldIn, Random random, int chunkX, int chunkZ) { - if (!BiomeDictionary.isBiomeOfType(biomegenbase, BiomeDictionary.Type.JUNGLE)) - { - if (BiomeDictionary.isBiomeOfType(biomegenbase, BiomeDictionary.Type.SWAMP)) - { - ComponentScatteredFeaturePieces.SwampHut swamphut = - new ComponentScatteredFeaturePieces.SwampHut(p_i2060_2_, p_i2060_3_ * 16, p_i2060_4_ * 16); - this.components.add(swamphut); - - FMLLog.log(Level.INFO, "Witch Hut generated at %d, %d", p_i2060_3_ * 16, p_i2060_4_ * 16); - } - else if (BiomeDictionary.isBiomeOfType(biomegenbase, BiomeDictionary.Type.SANDY)) - { - ComponentScatteredFeaturePieces.DesertPyramid desertpyramid = - new ComponentScatteredFeaturePieces.DesertPyramid(p_i2060_2_, p_i2060_3_ * 16, p_i2060_4_ * 16); - this.components.add(desertpyramid); - - FMLLog.log(Level.INFO, "Desert Temple generated at %d, %d", p_i2060_3_ * 16, p_i2060_4_ * 16); - } + super(worldIn, random, chunkX, chunkZ); + + LinkedList arrComponents = new LinkedList(); + + BiomeGenBase biomegenbase = worldIn.getBiomeGenForCoords(chunkX * 16 + 8, chunkZ * 16 + 8); + + if (BiomeDictionary.isBiomeOfType(biomegenbase, BiomeDictionary.Type.SANDY)) { + ComponentScatteredFeaturePieces.DesertPyramid desertpyramid = new ComponentScatteredFeaturePieces.DesertPyramid(random, chunkX * 16, chunkZ * 16); + arrComponents.add(desertpyramid); + } + + if (BiomeDictionary.isBiomeOfType(biomegenbase, BiomeDictionary.Type.JUNGLE)) { + ComponentScatteredFeaturePieces.JunglePyramid junglepyramid = new ComponentScatteredFeaturePieces.JunglePyramid(random, chunkX * 16, chunkZ * 16); + arrComponents.add(junglepyramid); + } + + if (BiomeDictionary.isBiomeOfType(biomegenbase, BiomeDictionary.Type.SWAMP)) { + ComponentScatteredFeaturePieces.SwampHut swamphut = new ComponentScatteredFeaturePieces.SwampHut(random, chunkX * 16, chunkZ * 16); + arrComponents.add(swamphut); } - else - { - ComponentScatteredFeaturePieces.JunglePyramid junglepyramid = - new ComponentScatteredFeaturePieces.JunglePyramid(p_i2060_2_, p_i2060_3_ * 16, p_i2060_4_ * 16); - this.components.add(junglepyramid); - - FMLLog.log(Level.INFO, "Jungle Temple generated at %d, %d", p_i2060_3_ * 16, p_i2060_4_ * 16); + + this.components.clear(); + + if (arrComponents.size() > 0) { + this.components.add(arrComponents.get(random.nextInt(arrComponents.size()))); } + FMLLog.log(Level.INFO, "Scattered feature candidate at %d, %d", chunkX * 16, chunkZ * 16); + this.updateBoundingBox(); } } -} +} \ No newline at end of file