Changed cave world spawning a bit, made the world generate with cobble and glowstone in the walls

This commit is contained in:
Ellpeck 2016-05-17 22:26:26 +02:00
parent b5e8cf0345
commit 22b0a9a64e
5 changed files with 290 additions and 147 deletions

View file

@ -22,7 +22,7 @@ import de.ellpeck.actuallyadditions.mod.crafting.ItemCrafting;
import de.ellpeck.actuallyadditions.mod.entity.InitEntities; import de.ellpeck.actuallyadditions.mod.entity.InitEntities;
import de.ellpeck.actuallyadditions.mod.event.InitEvents; import de.ellpeck.actuallyadditions.mod.event.InitEvents;
import de.ellpeck.actuallyadditions.mod.fluids.InitFluids; import de.ellpeck.actuallyadditions.mod.fluids.InitFluids;
import de.ellpeck.actuallyadditions.mod.gen.CaveWorldType; import de.ellpeck.actuallyadditions.mod.gen.cave.CaveWorldType;
import de.ellpeck.actuallyadditions.mod.gen.InitVillager; import de.ellpeck.actuallyadditions.mod.gen.InitVillager;
import de.ellpeck.actuallyadditions.mod.gen.OreGen; import de.ellpeck.actuallyadditions.mod.gen.OreGen;
import de.ellpeck.actuallyadditions.mod.inventory.GuiHandler; import de.ellpeck.actuallyadditions.mod.inventory.GuiHandler;
@ -44,7 +44,6 @@ import de.ellpeck.actuallyadditions.mod.tile.TileEntityBase;
import de.ellpeck.actuallyadditions.mod.update.UpdateChecker; import de.ellpeck.actuallyadditions.mod.update.UpdateChecker;
import de.ellpeck.actuallyadditions.mod.util.FakePlayerUtil; import de.ellpeck.actuallyadditions.mod.util.FakePlayerUtil;
import de.ellpeck.actuallyadditions.mod.util.ModUtil; import de.ellpeck.actuallyadditions.mod.util.ModUtil;
import de.ellpeck.actuallyadditions.mod.util.Util;
import net.minecraftforge.fluids.FluidRegistry; import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler; import net.minecraftforge.fml.common.Mod.EventHandler;

View file

@ -1,145 +0,0 @@
/*
* This file ("CaveWorldType.java") is part of the Actually Additions mod for Minecraft.
* It is created and owned by Ellpeck and distributed
* under the Actually Additions License to be found at
* http://ellpeck.de/actaddlicense
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
*
* © 2015-2016 Ellpeck
*/
package de.ellpeck.actuallyadditions.mod.gen;
import de.ellpeck.actuallyadditions.mod.config.ConfigValues;
import de.ellpeck.actuallyadditions.mod.items.InitItems;
import de.ellpeck.actuallyadditions.mod.misc.WorldData;
import de.ellpeck.actuallyadditions.mod.util.ModUtil;
import de.ellpeck.actuallyadditions.mod.util.Util;
import de.ellpeck.actuallyadditions.mod.util.playerdata.PersistentServerData;
import net.minecraft.block.BlockPlanks;
import net.minecraft.block.BlockSlab;
import net.minecraft.block.BlockWoodSlab;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import net.minecraft.world.WorldType;
import net.minecraft.world.chunk.IChunkGenerator;
import net.minecraft.world.gen.ChunkProviderFlat;
import net.minecraft.world.gen.feature.WorldGenTrees;
import net.minecraftforge.event.entity.living.LivingEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
public class CaveWorldType extends WorldType{
public CaveWorldType(){
//Name can't be longer than 16 :'(
super("actaddcaveworld");
Util.registerEvent(this);
}
public static boolean isCave(World world){
return ConfigValues.caveWorld && world.getWorldType() instanceof CaveWorldType;
}
@Override
public IChunkGenerator getChunkGenerator(World world, String generatorOptions){
return new ChunkProviderFlat(world, world.getSeed(), false, "3;minecraft:bedrock,254*minecraft:stone,minecraft:bedrock;2;");
}
@Override
public int getSpawnFuzz(WorldServer world, MinecraftServer server){
return 1;
}
private void generateCave(World world, BlockPos center){
this.makeSphere(world, center, 8);
this.makeSphere(world, center.add(-3, 4, 3), 4);
this.makeSphere(world, center.add(4, 6, 1), 4);
this.makeSphere(world, center.add(3, 4, -3), 6);
this.makeSphere(world, center.add(4, -2, -3), 2);
this.makeSphere(world, center.add(5, 0, -3), 4);
this.makeSphere(world, center.add(1, 4, 3), 6);
this.makeSphere(world, center.add(-5, 1, 1), 4);
this.makeSphere(world, center.add(-1, 1, -7), 6);
this.makeSphere(world, center.add(-2, -1, 8), 3);
world.setBlockState(center.add(-1, -5, -8), Blocks.DIRT.getStateFromMeta(1));
WorldGenTrees trees = new WorldGenTrees(true);
trees.generate(world, Util.RANDOM, center.add(-1, -4, -8));
for(int z = 0; z <= 24; z++){
for(int x = 0; x < 5; x++){
for(int y = 0; y < 4; y++){
BlockPos pos = center.add(x-3, y-4, 11+z);
if(z%4 == 0 && (x == 0 || x == 4)){
world.setBlockState(pos, Blocks.LOG2.getStateFromMeta(1));
}
else if((z%4 == 0 || x == 0 || x == 4) && y == 3){
world.setBlockState(pos, Blocks.PLANKS.getStateFromMeta(1));
}
else if(!((y == 0 || y == 3) && Util.RANDOM.nextInt(5) <= 0)){
world.setBlockToAir(pos);
}
}
}
}
world.setBlockState(center.down(1), Blocks.GLOWSTONE.getDefaultState());
}
private void makeSphere(World world, BlockPos center, int radius){
for(double x = -radius; x < radius; x++){
for(double y = -radius; y < radius; y++){
for(double z = -radius; z < radius; z++){
if(Math.sqrt((x*x)+(y*y)+(z*z)) < radius){
world.setBlockToAir(center.add(x, y, z));
}
}
}
}
}
@SubscribeEvent
public void onUpdate(LivingEvent.LivingUpdateEvent event){
if(event.getEntity() != null){
World world = event.getEntity().getEntityWorld();
if(world != null && isCave(world) && !world.isRemote){
BlockPos spawn = world.getSpawnPoint();
BlockPos center = new BlockPos(spawn.getX(), 100, spawn.getZ());
NBTTagCompound data = WorldData.additionalData;
if(!data.getBoolean("GeneratedCave")){
ModUtil.LOGGER.info("Starting to generate cave world...");
this.generateCave(world, center);
ModUtil.LOGGER.info("Generating cave world completed!");
data.setBoolean("GeneratedCave", true);
WorldData.makeDirty();
}
if(event.getEntity() instanceof EntityPlayerMP){
EntityPlayerMP player = (EntityPlayerMP)event.getEntity();
if(player.posY >= world.getHeight()){
player.playerNetServerHandler.setPlayerLocation(center.getX()+0.5, center.getY()+1, center.getZ()+0.5, player.rotationYaw, player.rotationPitch);
}
NBTTagCompound playerData = PersistentServerData.getDataFromPlayer(player);
if(!playerData.getBoolean("SpawnedFirst")){
player.inventory.addItemStackToInventory(new ItemStack(InitItems.itemBooklet));
playerData.setBoolean("SpawnedFirst", true);
WorldData.makeDirty();
}
}
}
}
}
}

View file

@ -0,0 +1,73 @@
/*
* This file ("CaveWorldType.java") is part of the Actually Additions mod for Minecraft.
* It is created and owned by Ellpeck and distributed
* under the Actually Additions License to be found at
* http://ellpeck.de/actaddlicense
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
*
* © 2015-2016 Ellpeck
*/
package de.ellpeck.actuallyadditions.mod.gen.cave;
import de.ellpeck.actuallyadditions.mod.config.ConfigValues;
import de.ellpeck.actuallyadditions.mod.items.InitItems;
import de.ellpeck.actuallyadditions.mod.misc.WorldData;
import de.ellpeck.actuallyadditions.mod.util.Util;
import de.ellpeck.actuallyadditions.mod.util.playerdata.PersistentServerData;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import net.minecraft.world.WorldType;
import net.minecraft.world.chunk.IChunkGenerator;
import net.minecraftforge.event.entity.living.LivingEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
public class CaveWorldType extends WorldType{
public CaveWorldType(){
//Name can't be longer than 16 :'(
super("actaddcaveworld");
Util.registerEvent(this);
}
public static boolean isCave(World world){
return ConfigValues.caveWorld && world.getWorldType() instanceof CaveWorldType;
}
@Override
public IChunkGenerator getChunkGenerator(World world, String generatorOptions){
return new ChunkProviderCave(world);
}
@Override
public int getSpawnFuzz(WorldServer world, MinecraftServer server){
return 1;
}
@SubscribeEvent
public void onSpawn(LivingEvent.LivingUpdateEvent event){
if(event.getEntity() instanceof EntityPlayerMP){
EntityPlayerMP player = (EntityPlayerMP)event.getEntity();
if(isCave(player.worldObj) && !player.worldObj.isRemote){
if(player.posY >= player.worldObj.getHeight() && !player.isSpectator()){
BlockPos spawn = player.worldObj.getSpawnPoint();
player.playerNetServerHandler.setPlayerLocation(spawn.getX()+0.5, spawn.getY()+1, spawn.getZ()+0.5, player.rotationYaw, player.rotationPitch);
}
NBTTagCompound playerData = PersistentServerData.getDataFromPlayer(player);
if(!playerData.getBoolean("SpawnedFirst")){
player.inventory.addItemStackToInventory(new ItemStack(InitItems.itemBooklet));
playerData.setBoolean("SpawnedFirst", true);
WorldData.makeDirty();
}
}
}
}
}

View file

@ -0,0 +1,101 @@
/*
* This file ("ChunkProviderCave.java") is part of the Actually Additions mod for Minecraft.
* It is created and owned by Ellpeck and distributed
* under the Actually Additions License to be found at
* http://ellpeck.de/actaddlicense
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
*
* © 2015-2016 Ellpeck
*/
package de.ellpeck.actuallyadditions.mod.gen.cave;
import de.ellpeck.actuallyadditions.mod.util.Util;
import net.minecraft.entity.EnumCreatureType;
import net.minecraft.init.Blocks;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.biome.BiomeGenBase;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.chunk.ChunkPrimer;
import net.minecraft.world.chunk.IChunkGenerator;
import net.minecraft.world.gen.MapGenBase;
import net.minecraft.world.gen.MapGenCaves;
import net.minecraft.world.gen.feature.WorldGenerator;
import java.util.List;
public class ChunkProviderCave implements IChunkGenerator{
private boolean generatedSpawn;
private World world;
private WorldGenerator spawnGenerator = new WorldGenCaveSpawn();
public ChunkProviderCave(World world){
this.world = world;
}
@Override
public Chunk provideChunk(int chunkX, int chunkZ){
ChunkPrimer primer = new ChunkPrimer();
for(int x = 0; x < 16; x++){
for(int z = 0; z < 16; z++){
for(int y = 0; y < this.world.getHeight(); y++){
if(y == this.world.getHeight()-1 || y == 0){
primer.setBlockState(x, y, z, Blocks.BEDROCK.getDefaultState());
}
else{
if(Util.RANDOM.nextInt(5) <= 0){
if(Util.RANDOM.nextFloat() <= 0.95F){
primer.setBlockState(x, y, z, (Util.RANDOM.nextFloat() >= 0.85F ? Blocks.MOSSY_COBBLESTONE : Blocks.COBBLESTONE).getDefaultState());
}
else{
primer.setBlockState(x, y, z, Blocks.GLOWSTONE.getDefaultState());
}
}
else{
primer.setBlockState(x, y, z, Blocks.STONE.getDefaultState());
}
}
}
}
}
Chunk chunk = new Chunk(this.world, primer, chunkX, chunkZ);
chunk.generateSkylightMap();
return chunk;
}
@Override
public void populate(int x, int z){
if(!this.generatedSpawn){
BlockPos spawn = this.world.getSpawnPoint();
Chunk chunk = this.world.getChunkFromBlockCoords(spawn);
if(chunk.xPosition == x && chunk.zPosition == z){
this.generatedSpawn = this.spawnGenerator.generate(this.world, this.world.rand, spawn);
}
}
}
@Override
public boolean generateStructures(Chunk chunkIn, int x, int z){
return false;
}
@Override
public List<BiomeGenBase.SpawnListEntry> getPossibleCreatures(EnumCreatureType creatureType, BlockPos pos){
return null;
}
@Override
public BlockPos getStrongholdGen(World worldIn, String structureName, BlockPos position){
return null;
}
@Override
public void recreateStructures(Chunk chunkIn, int x, int z){
}
}

View file

@ -0,0 +1,115 @@
/*
* This file ("WorldGeneratorCaveSpawn.java") is part of the Actually Additions mod for Minecraft.
* It is created and owned by Ellpeck and distributed
* under the Actually Additions License to be found at
* http://ellpeck.de/actaddlicense
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
*
* © 2015-2016 Ellpeck
*/
package de.ellpeck.actuallyadditions.mod.gen.cave;
import de.ellpeck.actuallyadditions.mod.items.InitItems;
import de.ellpeck.actuallyadditions.mod.items.metalists.TheFoods;
import de.ellpeck.actuallyadditions.mod.util.Util;
import net.minecraft.block.BlockLadder;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityChest;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.World;
import net.minecraft.world.gen.feature.WorldGenTrees;
import net.minecraft.world.gen.feature.WorldGenerator;
import java.util.Random;
public class WorldGenCaveSpawn extends WorldGenerator{
@Override
public boolean generate(World world, Random rand, BlockPos position){
this.generateCave(world, position);
return true;
}
private void generateCave(World world, BlockPos center){
this.makeSphere(world, center, 8);
this.makeSphere(world, center.add(-3, 4, 3), 4);
this.makeSphere(world, center.add(4, 6, 1), 4);
this.makeSphere(world, center.add(3, 4, -3), 6);
this.makeSphere(world, center.add(4, -2, -3), 2);
this.makeSphere(world, center.add(5, 0, -3), 4);
this.makeSphere(world, center.add(1, 4, 3), 6);
this.makeSphere(world, center.add(-5, 1, 1), 4);
this.makeSphere(world, center.add(-1, 1, -7), 6);
this.makeSphere(world, center.add(-2, -1, 8), 3);
world.setBlockState(center.add(-1, -5, -8), Blocks.DIRT.getStateFromMeta(1));
WorldGenTrees trees = new WorldGenTrees(true);
trees.generate(world, Util.RANDOM, center.add(-1, -4, -8));
int length = Util.RANDOM.nextInt(20)+20;
for(int z = 0; z <= length; z++){
for(int x = 0; x < 5; x++){
for(int y = 0; y < 4; y++){
BlockPos pos = center.add(x-3, y-4, 11+z);
if(z%4 == 0 && (x == 0 || x == 4)){
world.setBlockState(pos, Blocks.LOG2.getStateFromMeta(1));
}
else if((z%4 == 0 || x == 0 || x == 4) && y == 3){
world.setBlockState(pos, Blocks.PLANKS.getStateFromMeta(1));
}
else if(!((y == 0 || y == 3) && Util.RANDOM.nextInt(5) <= 0)){
world.setBlockToAir(pos);
}
}
}
}
BlockPos chestPos = center.add(-1, -4, 11+length);
world.setBlockState(chestPos, Blocks.CHEST.getDefaultState());
TileEntity tile = world.getTileEntity(chestPos);
if(tile instanceof TileEntityChest){
TileEntityChest chest = (TileEntityChest)tile;
chest.setInventorySlotContents(12, new ItemStack(InitItems.itemFoods, MathHelper.getRandomIntegerInRange(Util.RANDOM, 5, 15), Util.RANDOM.nextInt(TheFoods.values().length)));
chest.setInventorySlotContents(14, new ItemStack(InitItems.itemAxeCrystalBlack));
}
for(int x = -2; x <= 2; x++){
for(int z = -2; z <= 2; z++){
for(int y = -7; y <= 0; y++){
if(x%2 == 0 && z%2 == 0 && x != 0 && z != 0){
world.setBlockState(center.add(x, y, z), Blocks.LOG.getDefaultState());
}
else if(y == 0 && (x == -2 || x == 2 || z == -2 || z == 2)){
world.setBlockState(center.add(x, y, z), Blocks.OAK_FENCE.getDefaultState());
}
else if(y == -1){
world.setBlockState(center.add(x, y, z), Blocks.PLANKS.getStateFromMeta(1));
}
}
}
}
for(int y = 3; y <= 12; y++){
world.setBlockState(center.add(0, y, 0), Blocks.LADDER.getDefaultState().withProperty(BlockLadder.FACING, EnumFacing.WEST));
world.setBlockState(center.add(1, y, 0), Blocks.PLANKS.getDefaultState());
}
world.setBlockState(center.add(0, 13, 0), Blocks.COBBLESTONE.getDefaultState());
}
private void makeSphere(World world, BlockPos center, int radius){
for(double x = -radius; x < radius; x++){
for(double y = -radius; y < radius; y++){
for(double z = -radius; z < radius; z++){
if(Math.sqrt((x*x)+(y*y)+(z*z)) < radius){
world.setBlockToAir(center.add(x, y, z));
}
}
}
}
}
}