Files
MagicBees/src/main/java/magicbees/world/feature/FeatureOreVein.java
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

77 lines
2.4 KiB
Java
Raw Normal View History

2013-05-29 17:49:54 -07:00
package magicbees.world.feature;
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;
import net.minecraft.init.Blocks;
2013-05-29 17:49:54 -07:00
import net.minecraft.world.World;
2022-10-12 21:09:45 +02:00
public class FeatureOreVein {
2022-10-12 21:09:45 +02:00
public static final FeatureOreVein redstoneGen;
public static final FeatureOreVein netherQuartzGen;
public static final FeatureOreVein glowstoneGen;
public static final FeatureOreVein endStoneGen;
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);
}
2022-10-12 21:09:45 +02:00
private final Block veinBlock;
private final int veinBlockMeta;
private final Block replacesBlock;
2022-10-12 21:09:45 +02:00
public FeatureOreVein(Block block, Block replacesBlock) {
this(block, 0, replacesBlock);
}
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;
}
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;
2022-10-12 21:09:45 +02:00
while (spawnCount < maxSpawnCount && spawnAttempts < maxSpawnCount * 2) {
++spawnAttempts;
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
}