BiomesOPlenty/common/biomesoplenty/worldgen/WorldGenHive.java

137 lines
5.3 KiB
Java
Raw Normal View History

2013-10-27 18:21:13 +00:00
package biomesoplenty.worldgen;
import java.util.Random;
import net.minecraft.block.Block;
import net.minecraft.tileentity.TileEntityMobSpawner;
2013-10-27 18:21:13 +00:00
import net.minecraft.world.World;
import net.minecraft.world.gen.feature.WorldGenerator;
import biomesoplenty.api.Blocks;
2013-10-28 04:20:08 +00:00
import biomesoplenty.api.Fluids;
2013-10-28 01:32:18 +00:00
import biomesoplenty.entities.EntityWasp;
2013-10-27 18:21:13 +00:00
public class WorldGenHive extends WorldGenerator
{
@Override
2013-10-27 21:23:28 +00:00
public boolean generate(World world, Random rand, int x, int y, int z)
2013-10-27 18:21:13 +00:00
{
2013-10-27 21:23:28 +00:00
int baseWidth = 4 + rand.nextInt(2);
int baseHeight = 8 + rand.nextInt(2);
2013-10-27 18:21:13 +00:00
if (world.getBlockId(x, y + 3, z) != Block.netherrack.blockID || !world.isAirBlock(x, y + 2, z))
2013-10-27 20:47:23 +00:00
{
return false;
2013-10-27 20:47:23 +00:00
}
2013-10-27 18:21:13 +00:00
for (int cubeno = 0; cubeno < 3; cubeno++)
{
float chance = 0.0F;
switch (cubeno)
{
case 0:
2013-10-27 20:03:05 +00:00
chance = 0.25F;
2013-10-27 18:21:13 +00:00
break;
case 1:
chance = 1.0F;
break;
case 2:
chance = 0.5F;
2013-10-27 18:21:13 +00:00
break;
}
int honeychance = rand.nextInt(2);
2013-10-27 20:03:05 +00:00
//Top
2013-10-27 21:23:28 +00:00
generateHiveCubeSmall(world, x, y + cubeno, z, (baseHeight - 8) + (cubeno * 2), (baseWidth - 1) + cubeno, cubeno, chance);
2013-10-27 20:03:05 +00:00
//Middle
generateHiveCube(world, x, (y - 2) + cubeno, z, baseHeight + (cubeno * 2), baseWidth + cubeno, cubeno, chance, honeychance);
2013-10-27 20:03:05 +00:00
//Bottom
2013-10-27 21:23:28 +00:00
generateHiveCubeSmall(world, x, (y - (baseHeight + 4)) + cubeno, z, (baseHeight - 8) + (cubeno * 2), (baseWidth - 1) + cubeno, cubeno, chance);
2013-10-27 20:03:05 +00:00
//Bottom 2
2013-10-27 21:23:28 +00:00
generateHiveCubeSmall(world, x, (y - (baseHeight + 5)) + cubeno, z, (baseHeight - 7) + (cubeno * 2), (baseWidth - 2) + cubeno, cubeno, chance);
2013-10-27 20:03:05 +00:00
//Bottom 3
2013-10-27 21:23:28 +00:00
generateHiveCubeSmall(world, x, (y - (baseHeight + 7)) + cubeno, z, (baseHeight - 7) + (cubeno * 2), (baseWidth - 4) + cubeno, cubeno, chance);
2013-10-28 01:32:18 +00:00
2013-10-28 04:20:08 +00:00
spawnWasps(world, rand, x, y, z, 15);
2013-10-27 18:21:13 +00:00
}
return true;
}
public void generateHiveCube(World world, int origx, int origy, int origz, int height, int width, int cubeno, float chance, int honeychance)
2013-10-27 18:21:13 +00:00
{
for (int hLayer = 0; hLayer < height; hLayer++)
{
for (int i = -width; i < width; i++)
{
for (int j = -width; j < width; j++)
{
if ((hLayer == 0 || hLayer == (height - 1)) && (world.rand.nextFloat() <= chance)) world.setBlock(origx + i, origy - hLayer, origz + j, Blocks.hive.get().blockID);
else if ((i == -width || i == (width - 1) || j == -width || j == (width - 1)) && (world.rand.nextFloat() <= chance)) world.setBlock(origx + i, origy - hLayer, origz + j, Blocks.hive.get().blockID);
if (hLayer > (height / 2))
{
if (honeychance == 0)
{
if (cubeno < 2 && world.getBlockId(origx + i, origy - hLayer, origz + j) != Blocks.hive.get().blockID) world.setBlock(origx + i, origy - hLayer, origz + j, Fluids.honey.get().blockID);
}
else
{
if (cubeno < 2 && world.getBlockId(origx + i, origy - hLayer, origz + j) != Blocks.hive.get().blockID) world.setBlockToAir(origx + i, origy - hLayer, origz + j);
}
}
else
{
if (cubeno < 2 && world.getBlockId(origx + i, origy - hLayer, origz + j) != Blocks.hive.get().blockID) world.setBlockToAir(origx + i, origy - hLayer, origz + j);
}
2013-10-27 18:21:13 +00:00
}
}
}
}
2013-10-27 20:03:05 +00:00
public void generateHiveCubeSmall(World world, int origx, int origy, int origz, int height, int width, int cubeno, float chance)
{
for (int hLayer = 0; hLayer < height; hLayer++)
{
for (int i = -width; i < width; i++)
{
for (int j = -width; j < width; j++)
{
if ((hLayer == 0 || hLayer == (height - 1)) && (world.rand.nextFloat() <= chance)) world.setBlock(origx + i, origy - hLayer, origz + j, Blocks.hive.get().blockID);
else if ((i == -width || i == (width - 1) || j == -width || j == (width - 1)) && (world.rand.nextFloat() <= chance)) world.setBlock(origx + i, origy - hLayer, origz + j, Blocks.hive.get().blockID);
}
}
}
}
2013-10-28 01:32:18 +00:00
public void spawnWasps(World world, Random rand, int x, int y, int z, int amount)
2013-10-28 01:32:18 +00:00
{
for (int spawn = 0; spawn < amount; spawn++)
2013-10-28 01:32:18 +00:00
{
2013-10-29 19:31:35 +00:00
int spawnx = (x - 8) + rand.nextInt(16);
int spawny = (y + 2) - rand.nextInt(16);
int spawnz = (z - 8) + rand.nextInt(16);
2013-10-28 01:32:18 +00:00
2013-10-29 19:31:35 +00:00
if (world.getBlockId(spawnx, spawny, spawnz) == Blocks.hive.get().blockID)
2013-10-28 01:32:18 +00:00
{
2013-10-29 19:31:35 +00:00
world.setBlock(spawnx, spawny, spawnz, Block.mobSpawner.blockID);
TileEntityMobSpawner tileentitymobspawner = (TileEntityMobSpawner)world.getBlockTileEntity(spawnx, spawny, spawnz);
if (tileentitymobspawner != null)
{
tileentitymobspawner.getSpawnerLogic().setMobID("BiomesOPlenty.Wasp");
}
2013-10-28 01:32:18 +00:00
}
}
}
2013-10-27 18:21:13 +00:00
}