    001package net.minecraft.world.gen.structure;
    002
    003import java.util.List;
    004import java.util.Random;
    005import net.minecraft.block.Block;
    006import net.minecraft.item.Item;
    007import net.minecraft.util.WeightedRandomChestContent;
    008import net.minecraft.world.World;
    009
    010import net.minecraftforge.common.ChestGenHooks;
    011import static net.minecraftforge.common.ChestGenHooks.*;
    012
    013public class ComponentStrongholdLibrary extends ComponentStronghold
    014{
    015    /** List of items that Stronghold Library chests can contain. */
    016    public static final WeightedRandomChestContent[] strongholdLibraryChestContents = new WeightedRandomChestContent[] {new WeightedRandomChestContent(Item.book.itemID, 0, 1, 3, 20), new WeightedRandomChestContent(Item.paper.itemID, 0, 2, 7, 20), new WeightedRandomChestContent(Item.emptyMap.itemID, 0, 1, 1, 1), new WeightedRandomChestContent(Item.compass.itemID, 0, 1, 1, 1)};
    017    protected final EnumDoor doorType;
    018    private final boolean isLargeRoom;
    019
    020    public ComponentStrongholdLibrary(int par1, Random par2Random, StructureBoundingBox par3StructureBoundingBox, int par4)
    021    {
    022        super(par1);
    023        this.coordBaseMode = par4;
    024        this.doorType = this.getRandomDoor(par2Random);
    025        this.boundingBox = par3StructureBoundingBox;
    026        this.isLargeRoom = par3StructureBoundingBox.getYSize() > 6;
    027    }
    028
    029    public static ComponentStrongholdLibrary findValidPlacement(List par0List, Random par1Random, int par2, int par3, int par4, int par5, int par6)
    030    {
    031        StructureBoundingBox structureboundingbox = StructureBoundingBox.getComponentToAddBoundingBox(par2, par3, par4, -4, -1, 0, 14, 11, 15, par5);
    032
    033        if (!canStrongholdGoDeeper(structureboundingbox) || StructureComponent.findIntersecting(par0List, structureboundingbox) != null)
    034        {
    035            structureboundingbox = StructureBoundingBox.getComponentToAddBoundingBox(par2, par3, par4, -4, -1, 0, 14, 6, 15, par5);
    036
    037            if (!canStrongholdGoDeeper(structureboundingbox) || StructureComponent.findIntersecting(par0List, structureboundingbox) != null)
    038            {
    039                return null;
    040            }
    041        }
    042
    043        return new ComponentStrongholdLibrary(par6, par1Random, structureboundingbox, par5);
    044    }
    045
    046    /**
    047     * second Part of Structure generating, this for example places Spiderwebs, Mob Spawners, it closes Mineshafts at
    048     * the end, it adds Fences...
    049     */
    050    public boolean addComponentParts(World par1World, Random par2Random, StructureBoundingBox par3StructureBoundingBox)
    051    {
    052        if (this.isLiquidInStructureBoundingBox(par1World, par3StructureBoundingBox))
    053        {
    054            return false;
    055        }
    056        else
    057        {
    058            byte b0 = 11;
    059
    060            if (!this.isLargeRoom)
    061            {
    062                b0 = 6;
    063            }
    064
    065            this.fillWithRandomizedBlocks(par1World, par3StructureBoundingBox, 0, 0, 0, 13, b0 - 1, 14, true, par2Random, StructureStrongholdPieces.getStrongholdStones());
    066            this.placeDoor(par1World, par2Random, par3StructureBoundingBox, this.doorType, 4, 1, 0);
    067            this.randomlyFillWithBlocks(par1World, par3StructureBoundingBox, par2Random, 0.07F, 2, 1, 1, 11, 4, 13, Block.web.blockID, Block.web.blockID, false);
    068            int i;
    069
    070            for (i = 1; i <= 13; ++i)
    071            {
    072                if ((i - 1) % 4 == 0)
    073                {
    074                    this.fillWithBlocks(par1World, par3StructureBoundingBox, 1, 1, i, 1, 4, i, Block.planks.blockID, Block.planks.blockID, false);
    075                    this.fillWithBlocks(par1World, par3StructureBoundingBox, 12, 1, i, 12, 4, i, Block.planks.blockID, Block.planks.blockID, false);
    076                    this.placeBlockAtCurrentPosition(par1World, Block.torchWood.blockID, 0, 2, 3, i, par3StructureBoundingBox);
    077                    this.placeBlockAtCurrentPosition(par1World, Block.torchWood.blockID, 0, 11, 3, i, par3StructureBoundingBox);
    078
    079                    if (this.isLargeRoom)
    080                    {
    081                        this.fillWithBlocks(par1World, par3StructureBoundingBox, 1, 6, i, 1, 9, i, Block.planks.blockID, Block.planks.blockID, false);
    082                        this.fillWithBlocks(par1World, par3StructureBoundingBox, 12, 6, i, 12, 9, i, Block.planks.blockID, Block.planks.blockID, false);
    083                    }
    084                }
    085                else
    086                {
    087                    this.fillWithBlocks(par1World, par3StructureBoundingBox, 1, 1, i, 1, 4, i, Block.bookShelf.blockID, Block.bookShelf.blockID, false);
    088                    this.fillWithBlocks(par1World, par3StructureBoundingBox, 12, 1, i, 12, 4, i, Block.bookShelf.blockID, Block.bookShelf.blockID, false);
    089
    090                    if (this.isLargeRoom)
    091                    {
    092                        this.fillWithBlocks(par1World, par3StructureBoundingBox, 1, 6, i, 1, 9, i, Block.bookShelf.blockID, Block.bookShelf.blockID, false);
    093                        this.fillWithBlocks(par1World, par3StructureBoundingBox, 12, 6, i, 12, 9, i, Block.bookShelf.blockID, Block.bookShelf.blockID, false);
    094                    }
    095                }
    096            }
    097
    098            for (i = 3; i < 12; i += 2)
    099            {
    100                this.fillWithBlocks(par1World, par3StructureBoundingBox, 3, 1, i, 4, 3, i, Block.bookShelf.blockID, Block.bookShelf.blockID, false);
    101                this.fillWithBlocks(par1World, par3StructureBoundingBox, 6, 1, i, 7, 3, i, Block.bookShelf.blockID, Block.bookShelf.blockID, false);
    102                this.fillWithBlocks(par1World, par3StructureBoundingBox, 9, 1, i, 10, 3, i, Block.bookShelf.blockID, Block.bookShelf.blockID, false);
    103            }
    104
    105            if (this.isLargeRoom)
    106            {
    107                this.fillWithBlocks(par1World, par3StructureBoundingBox, 1, 5, 1, 3, 5, 13, Block.planks.blockID, Block.planks.blockID, false);
    108                this.fillWithBlocks(par1World, par3StructureBoundingBox, 10, 5, 1, 12, 5, 13, Block.planks.blockID, Block.planks.blockID, false);
    109                this.fillWithBlocks(par1World, par3StructureBoundingBox, 4, 5, 1, 9, 5, 2, Block.planks.blockID, Block.planks.blockID, false);
    110                this.fillWithBlocks(par1World, par3StructureBoundingBox, 4, 5, 12, 9, 5, 13, Block.planks.blockID, Block.planks.blockID, false);
    111                this.placeBlockAtCurrentPosition(par1World, Block.planks.blockID, 0, 9, 5, 11, par3StructureBoundingBox);
    112                this.placeBlockAtCurrentPosition(par1World, Block.planks.blockID, 0, 8, 5, 11, par3StructureBoundingBox);
    113                this.placeBlockAtCurrentPosition(par1World, Block.planks.blockID, 0, 9, 5, 10, par3StructureBoundingBox);
    114                this.fillWithBlocks(par1World, par3StructureBoundingBox, 3, 6, 2, 3, 6, 12, Block.fence.blockID, Block.fence.blockID, false);
    115                this.fillWithBlocks(par1World, par3StructureBoundingBox, 10, 6, 2, 10, 6, 10, Block.fence.blockID, Block.fence.blockID, false);
    116                this.fillWithBlocks(par1World, par3StructureBoundingBox, 4, 6, 2, 9, 6, 2, Block.fence.blockID, Block.fence.blockID, false);
    117                this.fillWithBlocks(par1World, par3StructureBoundingBox, 4, 6, 12, 8, 6, 12, Block.fence.blockID, Block.fence.blockID, false);
    118                this.placeBlockAtCurrentPosition(par1World, Block.fence.blockID, 0, 9, 6, 11, par3StructureBoundingBox);
    119                this.placeBlockAtCurrentPosition(par1World, Block.fence.blockID, 0, 8, 6, 11, par3StructureBoundingBox);
    120                this.placeBlockAtCurrentPosition(par1World, Block.fence.blockID, 0, 9, 6, 10, par3StructureBoundingBox);
    121                i = this.getMetadataWithOffset(Block.ladder.blockID, 3);
    122                this.placeBlockAtCurrentPosition(par1World, Block.ladder.blockID, i, 10, 1, 13, par3StructureBoundingBox);
    123                this.placeBlockAtCurrentPosition(par1World, Block.ladder.blockID, i, 10, 2, 13, par3StructureBoundingBox);
    124                this.placeBlockAtCurrentPosition(par1World, Block.ladder.blockID, i, 10, 3, 13, par3StructureBoundingBox);
    125                this.placeBlockAtCurrentPosition(par1World, Block.ladder.blockID, i, 10, 4, 13, par3StructureBoundingBox);
    126                this.placeBlockAtCurrentPosition(par1World, Block.ladder.blockID, i, 10, 5, 13, par3StructureBoundingBox);
    127                this.placeBlockAtCurrentPosition(par1World, Block.ladder.blockID, i, 10, 6, 13, par3StructureBoundingBox);
    128                this.placeBlockAtCurrentPosition(par1World, Block.ladder.blockID, i, 10, 7, 13, par3StructureBoundingBox);
    129                byte b1 = 7;
    130                byte b2 = 7;
    131                this.placeBlockAtCurrentPosition(par1World, Block.fence.blockID, 0, b1 - 1, 9, b2, par3StructureBoundingBox);
    132                this.placeBlockAtCurrentPosition(par1World, Block.fence.blockID, 0, b1, 9, b2, par3StructureBoundingBox);
    133                this.placeBlockAtCurrentPosition(par1World, Block.fence.blockID, 0, b1 - 1, 8, b2, par3StructureBoundingBox);
    134                this.placeBlockAtCurrentPosition(par1World, Block.fence.blockID, 0, b1, 8, b2, par3StructureBoundingBox);
    135                this.placeBlockAtCurrentPosition(par1World, Block.fence.blockID, 0, b1 - 1, 7, b2, par3StructureBoundingBox);
    136                this.placeBlockAtCurrentPosition(par1World, Block.fence.blockID, 0, b1, 7, b2, par3StructureBoundingBox);
    137                this.placeBlockAtCurrentPosition(par1World, Block.fence.blockID, 0, b1 - 2, 7, b2, par3StructureBoundingBox);
    138                this.placeBlockAtCurrentPosition(par1World, Block.fence.blockID, 0, b1 + 1, 7, b2, par3StructureBoundingBox);
    139                this.placeBlockAtCurrentPosition(par1World, Block.fence.blockID, 0, b1 - 1, 7, b2 - 1, par3StructureBoundingBox);
    140                this.placeBlockAtCurrentPosition(par1World, Block.fence.blockID, 0, b1 - 1, 7, b2 + 1, par3StructureBoundingBox);
    141                this.placeBlockAtCurrentPosition(par1World, Block.fence.blockID, 0, b1, 7, b2 - 1, par3StructureBoundingBox);
    142                this.placeBlockAtCurrentPosition(par1World, Block.fence.blockID, 0, b1, 7, b2 + 1, par3StructureBoundingBox);
    143                this.placeBlockAtCurrentPosition(par1World, Block.torchWood.blockID, 0, b1 - 2, 8, b2, par3StructureBoundingBox);
    144                this.placeBlockAtCurrentPosition(par1World, Block.torchWood.blockID, 0, b1 + 1, 8, b2, par3StructureBoundingBox);
    145                this.placeBlockAtCurrentPosition(par1World, Block.torchWood.blockID, 0, b1 - 1, 8, b2 - 1, par3StructureBoundingBox);
    146                this.placeBlockAtCurrentPosition(par1World, Block.torchWood.blockID, 0, b1 - 1, 8, b2 + 1, par3StructureBoundingBox);
    147                this.placeBlockAtCurrentPosition(par1World, Block.torchWood.blockID, 0, b1, 8, b2 - 1, par3StructureBoundingBox);
    148                this.placeBlockAtCurrentPosition(par1World, Block.torchWood.blockID, 0, b1, 8, b2 + 1, par3StructureBoundingBox);
    149            }
    150
    151            ChestGenHooks info = ChestGenHooks.getInfo(STRONGHOLD_LIBRARY);
    152
    153            this.generateStructureChestContents(par1World, par3StructureBoundingBox, par2Random, 3, 3, 5, info.getItems(par2Random), info.getCount(par2Random));
    154
    155            if (this.isLargeRoom)
    156            {
    157                this.placeBlockAtCurrentPosition(par1World, 0, 0, 12, 9, 1, par3StructureBoundingBox);
    158                this.generateStructureChestContents(par1World, par3StructureBoundingBox, par2Random, 12, 8, 1, info.getItems(par2Random), info.getCount(par2Random));
    159            }
    160
    161            return true;
    162        }
    163    }
    164}