Skip to content

Instantly share code, notes, and snippets.

Created May 12, 2017 17:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/3f6a74b51be39301711c3b22c321564a to your computer and use it in GitHub Desktop.
Save anonymous/3f6a74b51be39301711c3b22c321564a to your computer and use it in GitHub Desktop.
package com.chocolatemod.worldgen;
import net.minecraft.crash.CrashReport;
import net.minecraft.crash.CrashReportCategory;
import net.minecraft.util.BlockPos;
import net.minecraft.util.ReportedException;
import net.minecraft.world.World;
import net.minecraft.world.WorldType;
import net.minecraft.world.biome.BiomeCache;
import net.minecraft.world.biome.BiomeGenBase;
import net.minecraft.world.biome.WorldChunkManager;
import net.minecraft.world.gen.layer.GenLayer;
import net.minecraft.world.gen.layer.IntCache;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.terraingen.WorldTypeEvent;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import com.google.common.collect.Lists;
public class WorldChunkManagerChocolate extends WorldChunkManager {
private GenLayer myGenBiomes;
private GenLayer myBiomeIndexLayer;
private BiomeCache myBiomeCache;
private List myBiomesToSpawnIn;
protected WorldChunkManagerChocolate() {
this.myBiomeCache = new BiomeCache(this);
this.myBiomesToSpawnIn = Lists.newArrayList();
this.myBiomesToSpawnIn.add(BiomeGenChocolateBase.chocolatePlains);
this.myBiomesToSpawnIn.add(BiomeGenChocolateBase.chocolateForest);
this.myBiomesToSpawnIn.add(BiomeGenChocolateBase.chocolateMountians);
this.myBiomesToSpawnIn.add(BiomeGenChocolateBase.chocolateMushroom);
this.myBiomesToSpawnIn.add(BiomeGenChocolateBase.chocolateJungle);
// this.myBiomesToSpawnIn.add(BiomeGenChocolateBase.chocolateSwamp);
this.myBiomesToSpawnIn.add(BiomeGenChocolateBase.chocolateRiver);
this.myBiomesToSpawnIn.add(BiomeGenChocolateBase.chocolateOcean);
this.myBiomesToSpawnIn.add(BiomeGenChocolateBase.chocolateDesert);
}
public WorldChunkManagerChocolate(long seed, WorldType p_i45744_3_, String p_i45744_4_)
{
this();
GenLayer[] agenlayer = GenLayerChocolate.makeTheWorld(seed);
agenlayer = getModdedBiomeGenerators(p_i45744_3_, seed, agenlayer);
this.myGenBiomes = agenlayer[0];
this.myBiomeIndexLayer = agenlayer[1];
}
public WorldChunkManagerChocolate(World worldIn)
{
this(worldIn.getSeed(), worldIn.getWorldInfo().getTerrainType(), worldIn.getWorldInfo().getGeneratorOptions());
}
/**
* Gets the list of valid biomes for the player to spawn in.
*/
public List getBiomesToSpawnIn()
{
return this.myBiomesToSpawnIn;
}
/**
* Returns the biome generator
*/
public BiomeGenBase getBiomeGenerator(BlockPos p_180631_1_)
{
return this.func_180300_a(p_180631_1_, (BiomeGenBase)null);
}
public BiomeGenBase func_180300_a(BlockPos p_180300_1_, BiomeGenBase p_180300_2_)
{
return this.myBiomeCache.func_180284_a(p_180300_1_.getX(), p_180300_1_.getZ(), p_180300_2_);
}
/**
* Returns a list of rainfall values for the specified blocks. Args: listToReuse, x, z, width, length.
*/
public float[] getRainfall(float[] listToReuse, int x, int z, int width, int length)
{
IntCache.resetIntCache();
if (listToReuse == null || listToReuse.length < width * length)
{
listToReuse = new float[width * length];
}
int[] aint = this.myBiomeIndexLayer.getInts(x, z, width, length);
for (int i1 = 0; i1 < width * length; ++i1)
{
try
{
float f = (float)BiomeGenBase.getBiomeFromBiomeList(aint[i1], BiomeGenBase.field_180279_ad).getIntRainfall() / 65536.0F;
if (f > 1.0F)
{
f = 1.0F;
}
listToReuse[i1] = f;
}
catch (Throwable throwable)
{
CrashReport crashreport = CrashReport.makeCrashReport(throwable, "Invalid Biome id");
CrashReportCategory crashreportcategory = crashreport.makeCategory("DownfallBlock");
crashreportcategory.addCrashSection("biome id", Integer.valueOf(i1));
crashreportcategory.addCrashSection("downfalls[] size", Integer.valueOf(listToReuse.length));
crashreportcategory.addCrashSection("x", Integer.valueOf(x));
crashreportcategory.addCrashSection("z", Integer.valueOf(z));
crashreportcategory.addCrashSection("w", Integer.valueOf(width));
crashreportcategory.addCrashSection("h", Integer.valueOf(length));
throw new ReportedException(crashreport);
}
}
return listToReuse;
}
/**
* Return an adjusted version of a given temperature based on the y height
*/
@SideOnly(Side.CLIENT)
public float getTemperatureAtHeight(float p_76939_1_, int p_76939_2_)
{
return p_76939_1_;
}
/**
* Returns an array of biomes for the location input.
*/
public BiomeGenBase[] getBiomesForGeneration(BiomeGenBase[] p_76937_1_, int p_76937_2_, int p_76937_3_, int p_76937_4_, int p_76937_5_)
{
IntCache.resetIntCache();
if (p_76937_1_ == null || p_76937_1_.length < p_76937_4_ * p_76937_5_)
{
p_76937_1_ = new BiomeGenBase[p_76937_4_ * p_76937_5_];
}
int[] aint = this.myGenBiomes.getInts(p_76937_2_, p_76937_3_, p_76937_4_, p_76937_5_); //This line errors
try
{
for (int i1 = 0; i1 < p_76937_4_ * p_76937_5_; ++i1)
{
p_76937_1_[i1] = BiomeGenBase.getBiomeFromBiomeList(aint[i1], BiomeGenBase.field_180279_ad);
}
return p_76937_1_;
}
catch (Throwable throwable)
{
CrashReport crashreport = CrashReport.makeCrashReport(throwable, "Invalid Biome id");
CrashReportCategory crashreportcategory = crashreport.makeCategory("RawBiomeBlock");
crashreportcategory.addCrashSection("biomes[] size", Integer.valueOf(p_76937_1_.length));
crashreportcategory.addCrashSection("x", Integer.valueOf(p_76937_2_));
crashreportcategory.addCrashSection("z", Integer.valueOf(p_76937_3_));
crashreportcategory.addCrashSection("w", Integer.valueOf(p_76937_4_));
crashreportcategory.addCrashSection("h", Integer.valueOf(p_76937_5_));
throw new ReportedException(crashreport);
}
}
/**
* Returns biomes to use for the blocks and loads the other data like temperature and humidity onto the
* WorldChunkManager Args: oldBiomeList, x, z, width, depth
*/
public BiomeGenBase[] loadBlockGeneratorData(BiomeGenBase[] oldBiomeList, int x, int z, int width, int depth)
{
return this.getBiomeGenAt(oldBiomeList, x, z, width, depth, true);
}
/**
* Return a list of biomes for the specified blocks. Args: listToReuse, x, y, width, length, cacheFlag (if false,
* don't check biomeCache to avoid infinite loop in BiomeCacheBlock)
*
* @param cacheFlag If false, don't check biomeCache to avoid infinite loop in BiomeCacheBlock
*/
public BiomeGenBase[] getBiomeGenAt(BiomeGenBase[] listToReuse, int x, int z, int width, int length, boolean cacheFlag)
{
IntCache.resetIntCache();
if (listToReuse == null || listToReuse.length < width * length)
{
listToReuse = new BiomeGenBase[width * length];
}
if (cacheFlag && width == 16 && length == 16 && (x & 15) == 0 && (z & 15) == 0)
{
BiomeGenBase[] abiomegenbase1 = this.myBiomeCache.getCachedBiomes(x, z);
System.arraycopy(abiomegenbase1, 0, listToReuse, 0, width * length);
return listToReuse;
}
else
{
int[] aint = this.myBiomeIndexLayer.getInts(x, z, width, length);
for (int i1 = 0; i1 < width * length; ++i1)
{
listToReuse[i1] = BiomeGenBase.getBiomeFromBiomeList(aint[i1], BiomeGenBase.field_180279_ad);
}
return listToReuse;
}
}
/**
* checks given Chunk's Biomes against List of allowed ones
*/
public boolean areBiomesViable(int p_76940_1_, int p_76940_2_, int p_76940_3_, List p_76940_4_)
{
IntCache.resetIntCache();
int l = p_76940_1_ - p_76940_3_ >> 2;
int i1 = p_76940_2_ - p_76940_3_ >> 2;
int j1 = p_76940_1_ + p_76940_3_ >> 2;
int k1 = p_76940_2_ + p_76940_3_ >> 2;
int l1 = j1 - l + 1;
int i2 = k1 - i1 + 1;
int[] aint = this.myGenBiomes.getInts(l, i1, l1, i2);
try
{
for (int j2 = 0; j2 < l1 * i2; ++j2)
{
BiomeGenBase biomegenbase = BiomeGenBase.getBiome(aint[j2]);
if (!p_76940_4_.contains(biomegenbase))
{
return false;
}
}
return true;
}
catch (Throwable throwable)
{
CrashReport crashreport = CrashReport.makeCrashReport(throwable, "Invalid Biome id");
CrashReportCategory crashreportcategory = crashreport.makeCategory("Layer");
crashreportcategory.addCrashSection("Layer", this.myGenBiomes.toString());
crashreportcategory.addCrashSection("x", Integer.valueOf(p_76940_1_));
crashreportcategory.addCrashSection("z", Integer.valueOf(p_76940_2_));
crashreportcategory.addCrashSection("radius", Integer.valueOf(p_76940_3_));
crashreportcategory.addCrashSection("allowed", p_76940_4_);
throw new ReportedException(crashreport);
}
}
public BlockPos findBiomePosition(int x, int z, int range, List biomes, Random random)
{
IntCache.resetIntCache();
int l = x - range >> 2;
int i1 = z - range >> 2;
int j1 = x + range >> 2;
int k1 = z + range >> 2;
int l1 = j1 - l + 1;
int i2 = k1 - i1 + 1;
int[] aint = this.myGenBiomes.getInts(l, i1, l1, i2);
BlockPos blockpos = null;
int j2 = 0;
for (int k2 = 0; k2 < l1 * i2; ++k2)
{
int l2 = l + k2 % l1 << 2;
int i3 = i1 + k2 / l1 << 2;
BiomeGenBase biomegenbase = BiomeGenBase.getBiome(aint[k2]);
if (biomes.contains(biomegenbase) && (blockpos == null || random.nextInt(j2 + 1) == 0))
{
blockpos = new BlockPos(l2, 0, i3);
++j2;
}
}
return blockpos;
}
/**
* Calls the WorldChunkManager's biomeCache.cleanupCache()
*/
public void cleanupCache()
{
this.myBiomeCache.cleanupCache();
}
public GenLayer[] getModdedBiomeGenerators(WorldType worldType, long seed, GenLayer[] original)
{
WorldTypeEvent.InitBiomeGens event = new WorldTypeEvent.InitBiomeGens(worldType, seed, original);
MinecraftForge.TERRAIN_GEN_BUS.post(event);
return event.newBiomeGens;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment