blob: 2788d7bb20e5a30e9903dec3a6fe5204489d0578 [file] [log] [blame] [raw]
package net.glowstone.generator.objects;
import java.util.Random;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
public class OreVein {
final Material type;
final int data;
final int amount;
public OreVein(OreType oreType) {
type = oreType.getType();
data = oreType.getData();
amount = oreType.getAmount();
}
public void generate(World world, Random random, int sourceX, int sourceY, int sourceZ) {
float angle = random.nextFloat() * (float) Math.PI;
double dx1 = sourceX + Math.sin(angle) * (float) (amount / 8.0F);
double dx2 = sourceX - Math.sin(angle) * (float) (amount / 8.0F);
double dz1 = sourceZ + Math.cos(angle) * (float) (amount / 8.0F);
double dz2 = sourceZ - Math.cos(angle) * (float) (amount / 8.0F);
double dy1 = sourceY + random.nextInt(3) - 2;
double dy2 = sourceY + random.nextInt(3) - 2;
for (int i = 0; i < amount; i++) {
double originX = dx1 + (dx2 - dx1) * i / amount;
double originY = dy1 + (dy2 - dy1) * i / amount;
double originZ = dz1 + (dz2 - dz1) * i / amount;
double q = random.nextDouble() * amount / 16.0D;
double hRadius = (Math.sin(i * (float) Math.PI / amount) + 1 * q + 1) / 2.0D;
double vRadius = (Math.sin(i * (float) Math.PI / amount) + 1 * q + 1) / 2.0D;
for (int x = (int) (originX - hRadius); x <= (int) (originX - hRadius); x++) {
double pX = (x + 0.5D - originX) / hRadius;
pX *= pX;
if (pX < 1) {
for (int y = (int) (originY - vRadius); y <= (int) (originY + vRadius); y++) {
double pY = (y + 0.5D - originY) / vRadius;
pY *= pY;
if (pX + pY < 1) {
for (int z = (int) (originZ - hRadius); z <= (int) (originZ + hRadius); z++) {
double pZ = (z + 0.5D - originZ) / hRadius;
pZ *= pZ;
if (pX + pY + pZ < 1 && world.getBlockAt(x, y, z).getType() == Material.STONE) {
final Block block = world.getBlockAt(x, y, z);
block.setType(type);
block.setData((byte) data);
}
}
}
}
}
}
}
}
}