BiomesOPlenty/common/biomesoplenty/worldgen/WorldGenHive.java

216 lines
9.7 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
2013-10-30 04:21:12 +00:00
for (int air = 0; air < 26; air++)
{
if (world.getBlockId(x, y + 3, z) != Block.netherrack.blockID || !world.isAirBlock(x, (y + 2) - air, z))
2013-10-27 20:47:23 +00:00
{
2013-10-30 04:21:12 +00:00
return false;
2013-10-27 20:47:23 +00:00
}
2013-10-30 04:21:12 +00:00
}
2013-10-27 20:47:23 +00:00
for (int cubeno = 0; cubeno < 4; cubeno++)
2013-10-27 18:21:13 +00:00
{
float chance = 0.0F;
int meta = 0;
2013-10-27 18:21:13 +00:00
switch (cubeno)
{
case 0:
2013-10-27 20:03:05 +00:00
chance = 0.25F;
meta = 0;
2013-10-27 18:21:13 +00:00
break;
case 1:
chance = 1.0F;
meta = 0;
2013-10-27 18:21:13 +00:00
break;
case 2:
chance = 1.0F;
2013-10-30 04:21:12 +00:00
meta = 1;
break;
case 3:
chance = 0.5F;
2013-10-30 04:21:12 +00:00
meta = 1;
2013-10-27 18:21:13 +00:00
break;
}
int honeychance = rand.nextInt(2);
2013-10-27 20:03:05 +00:00
//Top
generateHiveCubeSmall(world, x, y + cubeno, z, (baseHeight - 11) + (cubeno * 2), (baseWidth - 1) + cubeno, cubeno, chance, meta);
2013-10-27 20:03:05 +00:00
//Middle
generateHiveCube(world, x, (y - 2) + cubeno, z, baseHeight + (cubeno * 2), baseWidth + cubeno, cubeno, chance, honeychance, meta);
2013-10-27 20:03:05 +00:00
//Bottom
generateHiveCubeSmall(world, x, (y - (baseHeight + 6)) + cubeno, z, (baseHeight - 10) + (cubeno * 2), (baseWidth - 1) + cubeno, cubeno, chance, meta);
2013-10-27 20:03:05 +00:00
//Bottom 2
generateHiveCubeSmall(world, x, (y - (baseHeight + 7)) + cubeno, z, (baseHeight - 9) + (cubeno * 2), (baseWidth - 2) + cubeno, cubeno, chance, meta);
2013-10-27 20:03:05 +00:00
//Bottom 3
generateHiveCubeSmall(world, x, (y - (baseHeight + 9)) + cubeno, z, (baseHeight - 9) + (cubeno * 2), (baseWidth - 4) + cubeno, cubeno, chance, meta);
2013-10-28 01:32:18 +00:00
2013-10-29 23:17:37 +00:00
spawnWasps(world, rand, x, y, z);
spawnEmptyHoneycombs(world, rand, x, y, z);
2013-10-30 20:24:48 +00:00
spawnFilledHoneycombs(world, rand, x, y, z);
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, int meta)
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, meta, 2);
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, meta, 2);
2013-10-27 18:21:13 +00:00
if (hLayer > (height / 2))
{
if (honeychance == 0)
{
2013-10-30 19:57:42 +00:00
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, 7, 2);
if (cubeno < 2 && world.getBlockId(origx + i, origy - hLayer, origz + j) == Blocks.hive.get().blockID && world.getBlockMetadata(origx + i, origy - hLayer, origz + j) != 0) world.setBlock(origx + i, origy - hLayer, origz + j, Fluids.honey.get().blockID, 7, 2);
}
else
{
if (cubeno < 2 && world.getBlockId(origx + i, origy - hLayer, origz + j) != Blocks.hive.get().blockID) world.setBlockToAir(origx + i, origy - hLayer, origz + j);
if (cubeno < 2 && world.getBlockId(origx + i, origy - hLayer, origz + j) == Blocks.hive.get().blockID && world.getBlockMetadata(origx + i, origy - hLayer, origz + j) != 0) world.setBlockToAir(origx + i, origy - hLayer, origz + j);
}
}
else
{
2013-10-30 19:57:42 +00:00
if (honeychance == 0)
{
if (hLayer == (height / 2))
{
if (cubeno < 2 && world.getBlockId(origx + i, origy - hLayer, origz + j) != Blocks.hive.get().blockID) world.setBlock(origx + i, origy - hLayer, origz + j, Blocks.honeyBlock.get().blockID, 0, 2);
if (cubeno < 2 && world.getBlockId(origx + i, origy - hLayer, origz + j) == Blocks.hive.get().blockID && world.getBlockMetadata(origx + i, origy - hLayer, origz + j) != 0) world.setBlock(origx + i, origy - hLayer, origz + j, Blocks.honeyBlock.get().blockID, 0, 2);
}
else
{
if (cubeno < 2 && world.getBlockId(origx + i, origy - hLayer, origz + j) != Blocks.hive.get().blockID) world.setBlockToAir(origx + i, origy - hLayer, origz + j);
if (cubeno < 2 && world.getBlockId(origx + i, origy - hLayer, origz + j) == Blocks.hive.get().blockID && world.getBlockMetadata(origx + i, origy - hLayer, origz + j) != 0) 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);
if (cubeno < 2 && world.getBlockId(origx + i, origy - hLayer, origz + j) == Blocks.hive.get().blockID && world.getBlockMetadata(origx + i, origy - hLayer, origz + j) != 0) 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, int meta)
2013-10-27 20:03:05 +00:00
{
for (int hLayer = 0; hLayer < height; hLayer++)
{
for (int i = -width; i < width; i++)
{
for (int j = -width; j < width; j++)
{
2013-10-30 04:21:12 +00:00
if ((hLayer == 0 || hLayer == (height - 1)) && (world.rand.nextFloat() <= chance)) world.setBlock(origx + i, origy - hLayer, origz + j, Blocks.hive.get().blockID, 1, 2);
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, 1, 2);
2013-10-27 20:03:05 +00:00
}
}
}
}
2013-10-28 01:32:18 +00:00
2013-10-29 23:17:37 +00:00
public void spawnWasps(World world, Random rand, int x, int y, int z)
2013-10-28 01:32:18 +00:00
{
2013-10-30 04:21:12 +00:00
for (int spawn = 0; spawn < 50; spawn++)
2013-10-28 01:32:18 +00:00
{
2013-10-29 23:17:37 +00:00
int spawnx = (x - 12) + rand.nextInt(24);
int spawny = y - rand.nextInt(24);
int spawnz = (z - 12) + rand.nextInt(24);
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-30 04:21:12 +00:00
if (world.getBlockMetadata(spawnx, spawny, spawnz) == 1)
{
2013-10-30 04:21:12 +00:00
if (world.getBlockId(spawnx - 1, spawny, spawnz) == Blocks.hive.get().blockID && world.getBlockId(spawnx + 1, spawny, spawnz) == Blocks.hive.get().blockID && world.getBlockId(spawnx, spawny, spawnz - 1) == Blocks.hive.get().blockID && world.getBlockId(spawnx, spawny, spawnz + 1) == Blocks.hive.get().blockID && world.getBlockId(spawnx, spawny - 1, spawnz) == Blocks.hive.get().blockID && world.getBlockId(spawnx, spawny + 1, spawnz) == Blocks.hive.get().blockID)
{
if (world.getBlockMetadata(spawnx - 1, spawny, spawnz) == 1 && world.getBlockMetadata(spawnx + 1, spawny, spawnz) == 1 && world.getBlockMetadata(spawnx, spawny, spawnz - 1) == 1 && world.getBlockMetadata(spawnx, spawny, spawnz + 1) == 1 && world.getBlockMetadata(spawnx, spawny - 1, spawnz) == 1 && world.getBlockMetadata(spawnx, spawny + 1, spawnz) == 1)
{
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-29 23:17:37 +00:00
}
}
}
}
2013-10-29 23:17:37 +00:00
public void spawnEmptyHoneycombs(World world, Random rand, int x, int y, int z)
{
for (int spawn = 0; spawn < 50; spawn++)
{
int spawnx = (x - 8) + rand.nextInt(16);
int spawny = y - rand.nextInt(12);
int spawnz = (z - 8) + rand.nextInt(16);
if (world.getBlockId(spawnx, spawny, spawnz) == Blocks.hive.get().blockID)
{
if (world.getBlockMetadata(spawnx, spawny, spawnz) == 0)
{
2013-10-30 20:24:48 +00:00
world.setBlock(spawnx, spawny, spawnz, Blocks.hive.get().blockID, 2, 2);
}
}
}
}
public void spawnFilledHoneycombs(World world, Random rand, int x, int y, int z)
{
for (int spawn = 0; spawn < 20; spawn++)
{
int spawnx = (x - 8) + rand.nextInt(16);
int spawny = y - rand.nextInt(12);
int spawnz = (z - 8) + rand.nextInt(16);
if (world.getBlockId(spawnx, spawny, spawnz) == Blocks.hive.get().blockID)
{
if (world.getBlockMetadata(spawnx, spawny, spawnz) == 0)
{
world.setBlock(spawnx, spawny, spawnz, Blocks.hive.get().blockID, 3, 2);
}
2013-10-28 01:32:18 +00:00
}
}
}
2013-10-27 18:21:13 +00:00
}