Skip to content

Commit

Permalink
Loose sticks now generate based on tree density. Also tweaked loose r…
Browse files Browse the repository at this point in the history
…ock generation to be more consistent with other decorations.
  • Loading branch information
alcatrazEscapee committed Aug 14, 2018
1 parent 247ff48 commit dced342
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import java.util.Random; import java.util.Random;
import javax.annotation.Nullable; import javax.annotation.Nullable;


import net.minecraft.block.state.IBlockState;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraft.world.chunk.IChunkProvider; import net.minecraft.world.chunk.IChunkProvider;
Expand Down Expand Up @@ -58,7 +57,7 @@ public void generate(Random random, int chunkX, int chunkZ, World world, IChunkG
int xoff = chunkX * 16 + 8; int xoff = chunkX * 16 + 8;
int zoff = chunkZ * 16 + 8; int zoff = chunkZ * 16 + 8;


for (int i = 0; i < 8; i++) for (int i = 0; i < 12; i++)
{ {
BlockPos pos = new BlockPos( BlockPos pos = new BlockPos(
xoff + random.nextInt(16), xoff + random.nextInt(16),
Expand All @@ -73,8 +72,7 @@ public void generate(Random random, int chunkX, int chunkZ, World world, IChunkG
private void generateRock(World world, BlockPos pos, @Nullable VeinType vein, Rock rock) private void generateRock(World world, BlockPos pos, @Nullable VeinType vein, Rock rock)
{ {


IBlockState stateAt = world.getBlockState(pos.down()); if (world.getBlockState(pos).getMaterial().isReplaceable() && !world.getBlockState(pos).getMaterial().isLiquid() && world.getBlockState(pos.down()).isFullCube())
if (world.isAirBlock(pos) && stateAt.isFullCube())
{ {
//noinspection ConstantConditions //noinspection ConstantConditions
world.setBlockState(pos, BlocksTFC.WORLD_ITEM.getDefaultState(), 2); world.setBlockState(pos, BlocksTFC.WORLD_ITEM.getDefaultState(), 2);
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Blocks; import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraft.world.WorldServer; import net.minecraft.world.WorldServer;
Expand All @@ -25,7 +27,9 @@


import net.dries007.tfc.api.ITreeGenerator; import net.dries007.tfc.api.ITreeGenerator;
import net.dries007.tfc.api.types.Tree; import net.dries007.tfc.api.types.Tree;
import net.dries007.tfc.objects.blocks.BlocksTFC;
import net.dries007.tfc.objects.blocks.wood.BlockLeavesTFC; import net.dries007.tfc.objects.blocks.wood.BlockLeavesTFC;
import net.dries007.tfc.objects.te.TEWorldItem;
import net.dries007.tfc.world.classic.ChunkGenTFC; import net.dries007.tfc.world.classic.ChunkGenTFC;
import net.dries007.tfc.world.classic.biomes.BiomeTFC; import net.dries007.tfc.world.classic.biomes.BiomeTFC;
import net.dries007.tfc.world.classic.biomes.BiomesTFC; import net.dries007.tfc.world.classic.biomes.BiomesTFC;
Expand Down Expand Up @@ -113,6 +117,11 @@ public void generate(Random random, int chunkX, int chunkZ, World world, IChunkG
List<Tree> trees = chunkData.getValidTrees(); List<Tree> trees = chunkData.getValidTrees();
Collections.rotate(trees, -(int) (diversity * (trees.size() - 1f))); Collections.rotate(trees, -(int) (diversity * (trees.size() - 1f)));


int stickDensity = 3 + (int) (4f * density + 1.5f * trees.size());
if (trees.isEmpty())
stickDensity = 1 + (int) (1.5f * density);
generateLooseSticks(random, chunkX, chunkZ, world, stickDensity);

// This is to avoid giant regions of no trees whatsoever. // This is to avoid giant regions of no trees whatsoever.
// It will create sparse trees ( < 1 per chunk) by averaging the climate data to make it more temperate // It will create sparse trees ( < 1 per chunk) by averaging the climate data to make it more temperate
// The thought is in very harsh conditions, a few trees might survive outside their typical temperature zone // The thought is in very harsh conditions, a few trees might survive outside their typical temperature zone
Expand Down Expand Up @@ -163,4 +172,23 @@ public void generate(Random random, int chunkX, int chunkZ, World world, IChunkG
} }
} }


private void generateLooseSticks(Random rand, int chunkX, int chunkZ, World world, int amount)
{
for (int i = 0; i < amount; i++)
{
final int x = chunkX * 16 + rand.nextInt(16) + 8;
final int z = chunkZ * 16 + rand.nextInt(16) + 8;
final BlockPos pos = world.getTopSolidOrLiquidBlock(new BlockPos(x, 0, z));

if (world.getBlockState(pos).getMaterial().isReplaceable() && !world.getBlockState(pos).getMaterial().isLiquid() && world.getBlockState(pos.down()).isOpaqueCube())
{
//noinspection ConstantConditions
world.setBlockState(pos, BlocksTFC.WORLD_ITEM.getDefaultState());
TEWorldItem tile = (TEWorldItem) world.getTileEntity(pos);
if (tile != null)
tile.inventory.setStackInSlot(0, new ItemStack(Items.STICK));
}
}
}

} }

0 comments on commit dced342

Please sign in to comment.