2013-10-27 18:21:13 +00:00
|
|
|
package biomesoplenty.worldgen;
|
|
|
|
|
|
|
|
import java.util.Random;
|
|
|
|
|
|
|
|
import net.minecraft.block.Block;
|
2013-10-28 08:30:51 +00:00
|
|
|
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-27 23:20:07 +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
|
|
|
{
|
2013-10-27 23:20:07 +00:00
|
|
|
return false;
|
2013-10-27 20:47:23 +00:00
|
|
|
}
|
|
|
|
|
2013-10-29 20:52:51 +00:00
|
|
|
for (int cubeno = 0; cubeno < 4; cubeno++)
|
2013-10-27 18:21:13 +00:00
|
|
|
{
|
|
|
|
float chance = 0.0F;
|
2013-10-29 20:52:51 +00:00
|
|
|
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;
|
2013-10-29 20:52:51 +00:00
|
|
|
meta = 0;
|
2013-10-27 18:21:13 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
chance = 1.0F;
|
2013-10-29 20:52:51 +00:00
|
|
|
meta = 0;
|
2013-10-27 18:21:13 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
2013-10-29 20:52:51 +00:00
|
|
|
chance = 1.0F;
|
|
|
|
meta = 2;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 3:
|
2013-10-27 23:20:07 +00:00
|
|
|
chance = 0.5F;
|
2013-10-29 20:52:51 +00:00
|
|
|
meta = 2;
|
2013-10-27 18:21:13 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-10-28 02:26:50 +00:00
|
|
|
int honeychance = rand.nextInt(2);
|
|
|
|
|
2013-10-27 20:03:05 +00:00
|
|
|
//Top
|
2013-10-29 20:52:51 +00:00
|
|
|
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
|
2013-10-29 20:52:51 +00:00
|
|
|
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
|
2013-10-29 20:52:51 +00:00
|
|
|
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
|
2013-10-29 20:52:51 +00:00
|
|
|
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
|
2013-10-29 20:52:51 +00:00
|
|
|
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-28 04:20:08 +00:00
|
|
|
spawnWasps(world, rand, x, y, z, 15);
|
2013-10-27 18:21:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-10-29 20:52:51 +00:00
|
|
|
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++)
|
|
|
|
{
|
2013-10-29 20:52:51 +00:00
|
|
|
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
|
|
|
|
2013-10-28 08:30:51 +00:00
|
|
|
if (hLayer > (height / 2))
|
2013-10-28 02:26:50 +00:00
|
|
|
{
|
2013-10-28 08:30:51 +00:00
|
|
|
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);
|
2013-10-29 20:52:51 +00:00
|
|
|
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);
|
2013-10-28 08:30:51 +00:00
|
|
|
}
|
|
|
|
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-29 20:52:51 +00:00
|
|
|
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-28 08:30:51 +00:00
|
|
|
}
|
2013-10-28 02:26:50 +00:00
|
|
|
}
|
|
|
|
else
|
2013-10-28 08:30:51 +00:00
|
|
|
{
|
|
|
|
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-29 20:52:51 +00:00
|
|
|
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-28 08:30:51 +00:00
|
|
|
}
|
2013-10-27 18:21:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-10-27 20:03:05 +00:00
|
|
|
|
2013-10-29 20:52:51 +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-29 20:52:51 +00:00
|
|
|
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 20:03:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-10-28 01:32:18 +00:00
|
|
|
|
2013-10-28 02:26:50 +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
|
|
|
{
|
2013-10-28 02:26:50 +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 20:52:51 +00:00
|
|
|
if (world.getBlockMetadata(spawnx, spawny, spawnz) == 0)
|
|
|
|
{
|
|
|
|
world.setBlock(spawnx, spawny, spawnz, Blocks.hive.get().blockID, 1, 0);
|
|
|
|
|
|
|
|
TileEntityMobSpawner tileentitymobspawner = (TileEntityMobSpawner)world.getBlockTileEntity(spawnx, spawny, spawnz);
|
|
|
|
|
|
|
|
if (tileentitymobspawner != null)
|
|
|
|
{
|
|
|
|
tileentitymobspawner.getSpawnerLogic().setMobID("BiomesOPlenty.Wasp");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (world.getBlockMetadata(spawnx, spawny, spawnz) == 2)
|
|
|
|
{
|
|
|
|
world.setBlock(spawnx, spawny, spawnz, Blocks.hive.get().blockID, 3, 0);
|
|
|
|
|
|
|
|
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
|
|
|
}
|