2013-05-29 17:49:54 -07:00
|
|
|
package magicbees.world.feature;
|
|
|
|
|
|
2015-01-08 21:48:13 -08:00
|
|
|
import java.util.Random;
|
2022-10-12 21:09:45 +02:00
|
|
|
import magicbees.main.utils.BlockUtil;
|
2013-05-29 17:49:54 -07:00
|
|
|
import net.minecraft.block.Block;
|
2015-01-13 23:54:32 -08:00
|
|
|
import net.minecraft.init.Blocks;
|
2013-05-29 17:49:54 -07:00
|
|
|
import net.minecraft.world.World;
|
2014-04-08 12:39:01 -07:00
|
|
|
|
2022-10-12 21:09:45 +02:00
|
|
|
public class FeatureOreVein {
|
|
|
|
|
public static final FeatureOreVein redstoneGen;
|
|
|
|
|
public static final FeatureOreVein netherQuartzGen;
|
|
|
|
|
public static final FeatureOreVein glowstoneGen;
|
|
|
|
|
public static final FeatureOreVein endStoneGen;
|
2015-01-13 23:54:32 -08:00
|
|
|
|
2022-10-12 21:09:45 +02:00
|
|
|
static {
|
|
|
|
|
redstoneGen = new FeatureOreVein(Blocks.redstone_ore, Blocks.stone);
|
|
|
|
|
netherQuartzGen = new FeatureOreVein(Blocks.quartz_ore, Blocks.netherrack);
|
|
|
|
|
glowstoneGen = new FeatureOreVein(Blocks.glowstone, Blocks.stone);
|
|
|
|
|
endStoneGen = new FeatureOreVein(Blocks.end_stone, Blocks.stone);
|
|
|
|
|
}
|
2015-01-13 23:54:32 -08:00
|
|
|
|
2022-10-12 21:09:45 +02:00
|
|
|
private final Block veinBlock;
|
|
|
|
|
private final int veinBlockMeta;
|
|
|
|
|
private final Block replacesBlock;
|
2015-01-08 21:48:13 -08:00
|
|
|
|
2022-10-12 21:09:45 +02:00
|
|
|
public FeatureOreVein(Block block, Block replacesBlock) {
|
|
|
|
|
this(block, 0, replacesBlock);
|
|
|
|
|
}
|
2015-01-08 21:48:13 -08:00
|
|
|
|
2022-10-12 21:09:45 +02:00
|
|
|
public FeatureOreVein(Block block, int meta, Block replacesBlock) {
|
|
|
|
|
this.veinBlock = block;
|
|
|
|
|
this.veinBlockMeta = meta;
|
|
|
|
|
this.replacesBlock = replacesBlock;
|
|
|
|
|
}
|
2015-01-08 21:48:13 -08:00
|
|
|
|
2022-10-12 21:09:45 +02: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;
|
2015-01-08 21:48:13 -08:00
|
|
|
|
2022-10-12 21:09:45 +02:00
|
|
|
while (spawnCount < maxSpawnCount && spawnAttempts < maxSpawnCount * 2) {
|
|
|
|
|
++spawnAttempts;
|
2015-01-08 21:48:13 -08:00
|
|
|
|
2022-10-12 21:09:45 +02:00
|
|
|
if (!world.isAirBlock(currentX, currentY, currentZ)
|
|
|
|
|
&& BlockUtil.canBlockReplaceAt(world, currentX, currentY, currentZ, replacesBlock)) {
|
|
|
|
|
world.setBlock(currentX, currentY, currentZ, this.veinBlock, this.veinBlockMeta, 2);
|
|
|
|
|
++spawnCount;
|
|
|
|
|
}
|
2013-05-29 17:49:54 -07:00
|
|
|
|
2022-10-12 21:09:45 +02:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-05-29 17:49:54 -07:00
|
|
|
}
|