2013-05-29 17:49:54 -07:00
|
|
|
package magicbees.world.feature;
|
|
|
|
|
|
|
|
|
|
import net.minecraft.block.Block;
|
|
|
|
|
import net.minecraft.world.World;
|
2014-04-08 12:39:01 -07:00
|
|
|
|
|
|
|
|
import java.util.Random;
|
2013-05-29 17:49:54 -07:00
|
|
|
|
|
|
|
|
public class FeatureOreVein
|
|
|
|
|
{
|
2014-01-18 12:44:14 -08:00
|
|
|
private Block veinBlock;
|
2013-05-29 17:49:54 -07:00
|
|
|
private int veinBlockMeta;
|
2014-01-18 12:44:14 -08:00
|
|
|
private Block replacesBlock;
|
2013-05-29 17:49:54 -07:00
|
|
|
|
2014-01-18 12:44:14 -08:00
|
|
|
public FeatureOreVein(Block block, Block replacesBlock)
|
2013-05-29 17:49:54 -07:00
|
|
|
{
|
2014-01-18 12:44:14 -08:00
|
|
|
this(block, 0, replacesBlock);
|
2013-05-29 17:49:54 -07:00
|
|
|
}
|
|
|
|
|
|
2014-01-18 12:44:14 -08:00
|
|
|
public FeatureOreVein(Block block, int meta, Block replacesBlock)
|
2013-05-29 17:49:54 -07:00
|
|
|
{
|
2014-01-18 12:44:14 -08:00
|
|
|
this.veinBlock = block;
|
2013-05-29 17:49:54 -07:00
|
|
|
this.veinBlockMeta = meta;
|
2014-01-18 12:44:14 -08:00
|
|
|
this.replacesBlock = replacesBlock;
|
2013-05-29 17:49:54 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void generateVein(World world, Random random, int startX, int startY, int startZ, int maxSpawnCount)
|
|
|
|
|
{
|
|
|
|
|
int currentX = startX;
|
|
|
|
|
int currentY = startY;
|
|
|
|
|
int currentZ = startZ;
|
|
|
|
|
int spawnAttempts = 0;
|
|
|
|
|
int spawnCount = 0;
|
|
|
|
|
|
|
|
|
|
while (spawnCount < maxSpawnCount && spawnAttempts < maxSpawnCount * 2)
|
|
|
|
|
{
|
|
|
|
|
++spawnAttempts;
|
|
|
|
|
|
2014-01-18 12:44:14 -08:00
|
|
|
if (!world.isAirBlock(currentX, currentY, currentZ) && canBlockReplaceAt(world, currentX, currentY, currentZ, replacesBlock))
|
2013-05-29 17:49:54 -07:00
|
|
|
{
|
2014-04-08 12:39:01 -07:00
|
|
|
world.setBlock(currentX, currentY, currentZ, this.veinBlock, this.veinBlockMeta, 2);
|
2013-05-29 17:49:54 -07:00
|
|
|
++spawnCount;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (random.nextInt(6))
|
|
|
|
|
{
|
|
|
|
|
case 0:
|
|
|
|
|
++currentY;
|
|
|
|
|
break;
|
|
|
|
|
case 1:
|
|
|
|
|
--currentY;
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
++currentZ;
|
|
|
|
|
break;
|
|
|
|
|
case 3:
|
|
|
|
|
--currentZ;
|
|
|
|
|
break;
|
|
|
|
|
case 4:
|
|
|
|
|
++currentX;
|
|
|
|
|
break;
|
|
|
|
|
case 5:
|
|
|
|
|
--currentX;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-01-18 12:44:14 -08:00
|
|
|
|
|
|
|
|
private static boolean canBlockReplaceAt(World world, int x, int y, int z, Block block)
|
|
|
|
|
{
|
2014-04-08 12:39:01 -07:00
|
|
|
return world.getBlock(x, y, z) != null &&
|
|
|
|
|
world.getBlock(x, y, z).isReplaceableOreGen(world, x, y, z, block);
|
2014-01-18 12:44:14 -08:00
|
|
|
}
|
2013-05-29 17:49:54 -07:00
|
|
|
}
|