Skip to content

Commit

Permalink
Moved spikes to IWorldGenerator.
Browse files Browse the repository at this point in the history
  • Loading branch information
DisasterMoo committed Aug 30, 2019
1 parent 8b64930 commit 569fad7
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 36 deletions.
Expand Up @@ -140,7 +140,10 @@ public BlockRockVariant(Rock.Type type, Rock rock)
setHarvestLevel("shovel", 0);
break;
}
OreDictionaryHelper.registerRockType(this, type, rock);
if (type != Rock.Type.SPIKE) //since spikes don't generate ItemBlocks
{
OreDictionaryHelper.registerRockType(this, type, rock);
}
}

public BlockRockVariant getVariant(Rock.Type t)
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/net/dries007/tfc/world/classic/ChunkGenTFC.java
Expand Up @@ -90,6 +90,8 @@ public class ChunkGenTFC implements IChunkGenerator
private static final IWorldGenerator BERRY_BUSH_GEN = new WorldGenBerryBushes();
private static final IWorldGenerator FRUIT_TREE_GEN = new WorldGenFruitTrees();
private static final IWorldGenerator LOOSE_ROCKS_GEN = new WorldGenLooseRocks();
private static final IWorldGenerator STALACTITE_GEN = new WorldGenSpikes(true, 300);
private static final IWorldGenerator STALAGMITE_GEN = new WorldGenSpikes(false, 300);
private static final IWorldGenerator WATERFALL_GEN = new WorldGenFalls(FRESH_WATER, 50);
private static final IWorldGenerator LAVAFALL_GEN = new WorldGenFalls(Blocks.FLOWING_LAVA.getDefaultState(), 15); //Todo change this if TFC implements it's own lava. Using static lava here makes the falls static

Expand Down Expand Up @@ -297,6 +299,8 @@ public void populate(int chunkX, int chunkZ)
LOOSE_ROCKS_GEN.generate(rand, chunkX, chunkZ, world, this, world.getChunkProvider());
WATERFALL_GEN.generate(rand, chunkX, chunkZ, world, this, world.getChunkProvider());
LAVAFALL_GEN.generate(rand, chunkX, chunkZ, world, this, world.getChunkProvider());
STALACTITE_GEN.generate(rand, chunkX, chunkZ, world, this, world.getChunkProvider());
STALAGMITE_GEN.generate(rand, chunkX, chunkZ, world, this, world.getChunkProvider());

if (TerrainGen.populate(this, world, rand, chunkX, chunkZ, false, ANIMALS))
{
Expand Down
Expand Up @@ -17,9 +17,6 @@
import net.dries007.tfc.api.registries.TFCRegistries;
import net.dries007.tfc.api.types.Rock;
import net.dries007.tfc.objects.blocks.BlocksTFC;
import net.dries007.tfc.objects.blocks.stone.BlockRockRaw;
import net.dries007.tfc.objects.blocks.stone.BlockRockSpike;
import net.dries007.tfc.objects.blocks.stone.BlockRockVariant;
import net.dries007.tfc.world.classic.DataLayer;

import static net.dries007.tfc.world.classic.ChunkGenTFC.AIR;
Expand Down Expand Up @@ -228,42 +225,12 @@ protected void generateCaveNode(long seed, int chunkX, int chunkZ, ChunkPrimer p
{
primer.setBlockState(xCoord, y - 1, zCoord, grass);
}
//================ Cave Decoration ===============
//Stalactites & Stalagmites
//Check for previously placed spikes and remove them. (as sometimes a cave nodes can cross one another)
if (primer.getBlockState(xCoord, y + 1, zCoord).getBlock() instanceof BlockRockSpike)
{
primer.setBlockState(xCoord, y + 1, zCoord, AIR);
primer.setBlockState(xCoord, y + 2, zCoord, AIR);
}
if (primer.getBlockState(xCoord, y - 1, zCoord).getBlock() instanceof BlockRockSpike)
{
primer.setBlockState(xCoord, y - 1, zCoord, AIR);
primer.setBlockState(xCoord, y - 2, zCoord, AIR);
}
//Place the spikes
if (primer.getBlockState(xCoord, y + 1, zCoord) == AIR && primer.getBlockState(xCoord, y + 2, zCoord) == AIR)
{
if (primer.getBlockState(xCoord, y + 3, zCoord).getBlock() instanceof BlockRockRaw && rng.nextDouble() < 0.07D)
{
BlockRockRaw rockBlock = (BlockRockRaw) primer.getBlockState(xCoord, y + 3, zCoord).getBlock();
primer.setBlockState(xCoord, y + 2, zCoord, BlockRockVariant.get(rockBlock.getRock(), Rock.Type.SPIKE).getDefaultState().withProperty(BlockRockSpike.BASE, true).withProperty(BlockRockSpike.CEILING, true));
primer.setBlockState(xCoord, y + 1, zCoord, BlockRockVariant.get(rockBlock.getRock(), Rock.Type.SPIKE).getDefaultState().withProperty(BlockRockSpike.BASE, false).withProperty(BlockRockSpike.CEILING, true));
}
else if (primer.getBlockState(xCoord, y - 1, zCoord).getBlock() instanceof BlockRockRaw && rng.nextDouble() < 0.07D)
{
BlockRockRaw rockBlock = (BlockRockRaw) primer.getBlockState(xCoord, y - 1, zCoord).getBlock();
primer.setBlockState(xCoord, y, zCoord, BlockRockVariant.get(rockBlock.getRock(), Rock.Type.SPIKE).getDefaultState().withProperty(BlockRockSpike.BASE, true).withProperty(BlockRockSpike.CEILING, false));
primer.setBlockState(xCoord, y + 1, zCoord, BlockRockVariant.get(rockBlock.getRock(), Rock.Type.SPIKE).getDefaultState().withProperty(BlockRockSpike.BASE, false).withProperty(BlockRockSpike.CEILING, false));
}
}
}
}

}
}
if (onlyOne) break;
}
}
}
}
}
@@ -0,0 +1,71 @@
/*
* Work under Copyright. Licensed under the EUPL.
* See the project README.md and LICENSE.txt for more information.
*/

package net.dries007.tfc.world.classic.worldgen;

import java.util.Random;

import net.minecraft.block.state.IBlockState;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.chunk.IChunkProvider;
import net.minecraft.world.gen.IChunkGenerator;
import net.minecraftforge.fml.common.IWorldGenerator;

import net.dries007.tfc.api.types.Rock;
import net.dries007.tfc.objects.blocks.BlocksTFC;
import net.dries007.tfc.objects.blocks.stone.BlockRockRaw;
import net.dries007.tfc.objects.blocks.stone.BlockRockSpike;
import net.dries007.tfc.objects.blocks.stone.BlockRockVariant;
import net.dries007.tfc.world.classic.WorldTypeTFC;

public class WorldGenSpikes implements IWorldGenerator
{
private final boolean ceiling; //Is this a stalactite generator?
private final int rarity;

public WorldGenSpikes(boolean ceiling, int rarity)
{
this.ceiling = ceiling;
this.rarity = rarity;
}

@Override
public void generate(Random random, int chunkX, int chunkZ, World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider)
{
for (int k5 = 0; k5 < rarity; ++k5)
{
int x = random.nextInt(16) + 8;
int z = random.nextInt(16) + 8;
int y = random.nextInt(WorldTypeTFC.SEALEVEL - 50) + 30;
BlockPos basePos = new BlockPos(chunkX << 4, y, chunkZ << 4).add(x, 0, z);
BlockPos topPos = ceiling ? basePos.down() : basePos.up();
BlockPos stoneAttach = ceiling ? basePos.up() : basePos.down();
BlockPos freeSpace = ceiling ? topPos.down() : topPos.up();
if (!BlocksTFC.isRawStone(world.getBlockState(stoneAttach)) || !world.isAirBlock(basePos) || !world.isAirBlock(topPos) || !world.isAirBlock(freeSpace))
{
continue;
}
boolean canPlace = true;
for (EnumFacing facing : EnumFacing.HORIZONTALS)
{
if (!world.isAirBlock(basePos.offset(facing)) || !world.isAirBlock(topPos.offset(facing)))
{
canPlace = false;
break;
}
}
if (canPlace)
{
BlockRockRaw rockBlock = (BlockRockRaw) world.getBlockState(stoneAttach).getBlock();
IBlockState baseState = BlockRockVariant.get(rockBlock.getRock(), Rock.Type.SPIKE).getDefaultState().withProperty(BlockRockSpike.BASE, true).withProperty(BlockRockSpike.CEILING, ceiling);
IBlockState topState = BlockRockVariant.get(rockBlock.getRock(), Rock.Type.SPIKE).getDefaultState().withProperty(BlockRockSpike.BASE, false).withProperty(BlockRockSpike.CEILING, ceiling);
world.setBlockState(basePos, baseState, 2);
world.setBlockState(topPos, topState, 2);
}
}
}
}

0 comments on commit 569fad7

Please sign in to comment.