001package net.minecraft.world.gen.structure;
002
003import java.util.List;
004import java.util.Random;
005import net.minecraft.block.Block;
006import net.minecraft.util.MathHelper;
007import net.minecraft.world.World;
008
009public class ComponentVillageField2 extends ComponentVillage
010{
011    private int averageGroundLevel = -1;
012
013    /** First crop type for this field. */
014    private int cropTypeA;
015
016    /** Second crop type for this field. */
017    private int cropTypeB;
018
019    public ComponentVillageField2(ComponentVillageStartPiece par1ComponentVillageStartPiece, int par2, Random par3Random, StructureBoundingBox par4StructureBoundingBox, int par5)
020    {
021        super(par1ComponentVillageStartPiece, par2);
022        this.coordBaseMode = par5;
023        this.boundingBox = par4StructureBoundingBox;
024        this.cropTypeA = this.pickRandomCrop(par3Random);
025        this.cropTypeB = this.pickRandomCrop(par3Random);
026    }
027
028    /**
029     * Returns a crop type to be planted on this field.
030     */
031    private int pickRandomCrop(Random par1Random)
032    {
033        switch (par1Random.nextInt(5))
034        {
035            case 0:
036                return Block.carrot.blockID;
037            case 1:
038                return Block.potato.blockID;
039            default:
040                return Block.crops.blockID;
041        }
042    }
043
044    public static ComponentVillageField2 func_74902_a(ComponentVillageStartPiece par0ComponentVillageStartPiece, List par1List, Random par2Random, int par3, int par4, int par5, int par6, int par7)
045    {
046        StructureBoundingBox structureboundingbox = StructureBoundingBox.getComponentToAddBoundingBox(par3, par4, par5, 0, 0, 0, 7, 4, 9, par6);
047        return canVillageGoDeeper(structureboundingbox) && StructureComponent.findIntersecting(par1List, structureboundingbox) == null ? new ComponentVillageField2(par0ComponentVillageStartPiece, par7, par2Random, structureboundingbox, par6) : null;
048    }
049
050    /**
051     * second Part of Structure generating, this for example places Spiderwebs, Mob Spawners, it closes Mineshafts at
052     * the end, it adds Fences...
053     */
054    public boolean addComponentParts(World par1World, Random par2Random, StructureBoundingBox par3StructureBoundingBox)
055    {
056        if (this.averageGroundLevel < 0)
057        {
058            this.averageGroundLevel = this.getAverageGroundLevel(par1World, par3StructureBoundingBox);
059
060            if (this.averageGroundLevel < 0)
061            {
062                return true;
063            }
064
065            this.boundingBox.offset(0, this.averageGroundLevel - this.boundingBox.maxY + 4 - 1, 0);
066        }
067
068        this.fillWithBlocks(par1World, par3StructureBoundingBox, 0, 1, 0, 6, 4, 8, 0, 0, false);
069        this.fillWithBlocks(par1World, par3StructureBoundingBox, 1, 0, 1, 2, 0, 7, Block.tilledField.blockID, Block.tilledField.blockID, false);
070        this.fillWithBlocks(par1World, par3StructureBoundingBox, 4, 0, 1, 5, 0, 7, Block.tilledField.blockID, Block.tilledField.blockID, false);
071        this.fillWithBlocks(par1World, par3StructureBoundingBox, 0, 0, 0, 0, 0, 8, Block.wood.blockID, Block.wood.blockID, false);
072        this.fillWithBlocks(par1World, par3StructureBoundingBox, 6, 0, 0, 6, 0, 8, Block.wood.blockID, Block.wood.blockID, false);
073        this.fillWithBlocks(par1World, par3StructureBoundingBox, 1, 0, 0, 5, 0, 0, Block.wood.blockID, Block.wood.blockID, false);
074        this.fillWithBlocks(par1World, par3StructureBoundingBox, 1, 0, 8, 5, 0, 8, Block.wood.blockID, Block.wood.blockID, false);
075        this.fillWithBlocks(par1World, par3StructureBoundingBox, 3, 0, 1, 3, 0, 7, Block.waterMoving.blockID, Block.waterMoving.blockID, false);
076        int i;
077
078        for (i = 1; i <= 7; ++i)
079        {
080            this.placeBlockAtCurrentPosition(par1World, this.cropTypeA, MathHelper.getRandomIntegerInRange(par2Random, 2, 7), 1, 1, i, par3StructureBoundingBox);
081            this.placeBlockAtCurrentPosition(par1World, this.cropTypeA, MathHelper.getRandomIntegerInRange(par2Random, 2, 7), 2, 1, i, par3StructureBoundingBox);
082            this.placeBlockAtCurrentPosition(par1World, this.cropTypeB, MathHelper.getRandomIntegerInRange(par2Random, 2, 7), 4, 1, i, par3StructureBoundingBox);
083            this.placeBlockAtCurrentPosition(par1World, this.cropTypeB, MathHelper.getRandomIntegerInRange(par2Random, 2, 7), 5, 1, i, par3StructureBoundingBox);
084        }
085
086        for (i = 0; i < 9; ++i)
087        {
088            for (int j = 0; j < 7; ++j)
089            {
090                this.clearCurrentPositionBlocksUpwards(par1World, j, 4, i, par3StructureBoundingBox);
091                this.fillCurrentPositionBlocksDownwards(par1World, Block.dirt.blockID, 0, j, -1, i, par3StructureBoundingBox);
092            }
093        }
094
095        return true;
096    }
097}