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