    001package net.minecraft.world.gen.feature;
    002
    003import java.util.Random;
    004import net.minecraft.block.Block;
    005import net.minecraft.util.MathHelper;
    006import net.minecraft.world.World;
    007
    008public class WorldGenMinable extends WorldGenerator
    009{
    010    /** The block ID of the ore to be placed using this generator. */
    011    private int minableBlockId;
    012    private int minableBlockMeta = 0;
    013
    014    /** The number of blocks to generate. */
    015    private int numberOfBlocks;
    016    private int field_94523_c;
    017
    018    public WorldGenMinable(int par1, int par2)
    019    {
    020        this(par1, par2, Block.stone.blockID);
    021    }
    022
    023    public WorldGenMinable(int par1, int par2, int par3)
    024    {
    025        this.minableBlockId = par1;
    026        this.numberOfBlocks = par2;
    027        this.field_94523_c = par3;
    028    }
    029
    030    public WorldGenMinable(int id, int meta, int number, int target)
    031    {
    032        this(id, number, target);
    033        minableBlockMeta = meta;
    034    }
    035
    036    public boolean generate(World par1World, Random par2Random, int par3, int par4, int par5)
    037    {
    038        float f = par2Random.nextFloat() * (float)Math.PI;
    039        double d0 = (double)((float)(par3 + 8) + MathHelper.sin(f) * (float)this.numberOfBlocks / 8.0F);
    040        double d1 = (double)((float)(par3 + 8) - MathHelper.sin(f) * (float)this.numberOfBlocks / 8.0F);
    041        double d2 = (double)((float)(par5 + 8) + MathHelper.cos(f) * (float)this.numberOfBlocks / 8.0F);
    042        double d3 = (double)((float)(par5 + 8) - MathHelper.cos(f) * (float)this.numberOfBlocks / 8.0F);
    043        double d4 = (double)(par4 + par2Random.nextInt(3) - 2);
    044        double d5 = (double)(par4 + par2Random.nextInt(3) - 2);
    045
    046        for (int l = 0; l <= this.numberOfBlocks; ++l)
    047        {
    048            double d6 = d0 + (d1 - d0) * (double)l / (double)this.numberOfBlocks;
    049            double d7 = d4 + (d5 - d4) * (double)l / (double)this.numberOfBlocks;
    050            double d8 = d2 + (d3 - d2) * (double)l / (double)this.numberOfBlocks;
    051            double d9 = par2Random.nextDouble() * (double)this.numberOfBlocks / 16.0D;
    052            double d10 = (double)(MathHelper.sin((float)l * (float)Math.PI / (float)this.numberOfBlocks) + 1.0F) * d9 + 1.0D;
    053            double d11 = (double)(MathHelper.sin((float)l * (float)Math.PI / (float)this.numberOfBlocks) + 1.0F) * d9 + 1.0D;
    054            int i1 = MathHelper.floor_double(d6 - d10 / 2.0D);
    055            int j1 = MathHelper.floor_double(d7 - d11 / 2.0D);
    056            int k1 = MathHelper.floor_double(d8 - d10 / 2.0D);
    057            int l1 = MathHelper.floor_double(d6 + d10 / 2.0D);
    058            int i2 = MathHelper.floor_double(d7 + d11 / 2.0D);
    059            int j2 = MathHelper.floor_double(d8 + d10 / 2.0D);
    060
    061            for (int k2 = i1; k2 <= l1; ++k2)
    062            {
    063                double d12 = ((double)k2 + 0.5D - d6) / (d10 / 2.0D);
    064
    065                if (d12 * d12 < 1.0D)
    066                {
    067                    for (int l2 = j1; l2 <= i2; ++l2)
    068                    {
    069                        double d13 = ((double)l2 + 0.5D - d7) / (d11 / 2.0D);
    070
    071                        if (d12 * d12 + d13 * d13 < 1.0D)
    072                        {
    073                            for (int i3 = k1; i3 <= j2; ++i3)
    074                            {
    075                                double d14 = ((double)i3 + 0.5D - d8) / (d10 / 2.0D);
    076
    077                                Block block = Block.blocksList[par1World.getBlockId(k2, l2, i3)];
    078                                if (d12 * d12 + d13 * d13 + d14 * d14 < 1.0D && (block != null && block.isGenMineableReplaceable(par1World, k2, l2, i3, field_94523_c)))
    079                                {
    080                                    par1World.setBlock(k2, l2, i3, this.minableBlockId, minableBlockMeta, 2);
    081                                }
    082                            }
    083                        }
    084                    }
    085                }
    086            }
    087        }
    088
    089        return true;
    090    }
    091}