Skip to content

Instantly share code, notes, and snippets.

@alcatrazEscapee
Created December 29, 2020 16:27
Show Gist options
  • Save alcatrazEscapee/f7b388527e8597cb3ff22918b9208568 to your computer and use it in GitHub Desktop.
Save alcatrazEscapee/f7b388527e8597cb3ff22918b9208568 to your computer and use it in GitHub Desktop.
@Override
public void apply(Random random, IChunk chunkIn, Biome biomeIn, int x, int z, int startHeight, double surfaceNoise, BlockState defaultBlock, BlockState defaultFluid, int seaLevel, long seed, SurfaceBuilderConfig config)
{
double squareIcebergValue = 0.0D;
double underwaterIcebergValue = 0.0D;
BlockPos.Mutable mutablePos = new BlockPos.Mutable();
float seaLevelTemperature = biomeIn.getTemperature(mutablePos.set(x, 63, z));
double icebergValue = Math.min(Math.abs(surfaceNoise), icebergNoise.getValue(x * 0.1D, z * 0.1D, false) * 15.0D);
if (icebergValue > 1.8D)
{
double icebergRoofValue = Math.abs(icebergRoofNoise.getValue(x * 0.09765625D, z * 0.09765625D, false));
squareIcebergValue = icebergValue * icebergValue * 1.2D;
double maximumIcebergRoofValue = Math.ceil(icebergRoofValue * 40.0D) + 14.0D;
if (squareIcebergValue > maximumIcebergRoofValue)
{
squareIcebergValue = maximumIcebergRoofValue;
}
if (seaLevelTemperature > 0.1F)
{
squareIcebergValue -= 2.0D;
}
if (squareIcebergValue > 2.0D)
{
underwaterIcebergValue = (double) seaLevel - squareIcebergValue - 7.0D;
squareIcebergValue = squareIcebergValue + (double) seaLevel;
}
else
{
squareIcebergValue = 0.0D;
}
}
int localX = x & 15;
int localZ = z & 15;
ISurfaceBuilderConfig surfaceBuilderConfig = biomeIn.getGenerationSettings().getSurfaceBuilderConfig();
BlockState defaultUnderState = surfaceBuilderConfig.getUnderMaterial();
BlockState defaultTopState = surfaceBuilderConfig.getTopMaterial();
BlockState underState = defaultUnderState;
BlockState topState = defaultTopState;
int normalSurfaceDepth = (int) (surfaceNoise / 3.0D + 3.0D + random.nextDouble() * 0.25D);
int surfaceFlag = -1;
int currentSnowLayers = 0;
int maximumSnowLayers = 2 + random.nextInt(4);
int minimumSnowY = seaLevel + 18 + random.nextInt(10);
for (int y = Math.max(startHeight, (int) squareIcebergValue + 1); y >= 0; --y)
{
mutablePos.set(localX, y, localZ);
if (chunkIn.getBlockState(mutablePos).isAir() && y < (int) squareIcebergValue && random.nextDouble() > 0.01D)
{
chunkIn.setBlockState(mutablePos, PACKED_ICE, false);
}
else if (chunkIn.getBlockState(mutablePos).getMaterial() == Material.WATER && y > (int) underwaterIcebergValue && y < seaLevel && underwaterIcebergValue != 0.0D && random.nextDouble() > 0.15D)
{
chunkIn.setBlockState(mutablePos, PACKED_ICE, false);
}
BlockState stateAt = chunkIn.getBlockState(mutablePos);
if (stateAt.isAir())
{
surfaceFlag = -1;
}
else if (!stateAt.is(defaultBlock.getBlock()))
{
if (stateAt.is(Blocks.PACKED_ICE) && currentSnowLayers <= maximumSnowLayers && y > minimumSnowY)
{
chunkIn.setBlockState(mutablePos, SNOW_BLOCK, false);
++currentSnowLayers;
}
}
else if (surfaceFlag == -1)
{
if (normalSurfaceDepth <= 0)
{
topState = AIR;
underState = defaultBlock;
}
else if (y >= seaLevel - 4 && y <= seaLevel + 1)
{
topState = defaultTopState;
underState = defaultUnderState;
}
if (y < seaLevel && (topState == null || topState.isAir()))
{
if (biomeIn.getTemperature(mutablePos.set(x, y, z)) < 0.15F)
{
topState = ICE;
}
else
{
topState = defaultFluid;
}
}
surfaceFlag = normalSurfaceDepth;
if (y >= seaLevel - 1)
{
chunkIn.setBlockState(mutablePos, topState, false);
}
else if (y < seaLevel - 7 - normalSurfaceDepth)
{
topState = AIR;
underState = defaultBlock;
chunkIn.setBlockState(mutablePos, GRAVEL, false);
}
else
{
chunkIn.setBlockState(mutablePos, underState, false);
}
}
else if (surfaceFlag > 0)
{
--surfaceFlag;
chunkIn.setBlockState(mutablePos, underState, false);
if (surfaceFlag == 0 && underState.is(Blocks.SAND) && normalSurfaceDepth > 1)
{
surfaceFlag = random.nextInt(4) + Math.max(0, y - 63);
underState = underState.is(Blocks.RED_SAND) ? Blocks.RED_SANDSTONE.defaultBlockState() : Blocks.SANDSTONE.defaultBlockState();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment