    001    package net.minecraft.src;
    002
    003    public class ItemDoor extends Item
    004    {
    005        private Material doorMaterial;
    006
    007        public ItemDoor(int par1, Material par2Material)
    008        {
    009            super(par1);
    010            this.doorMaterial = par2Material;
    011            this.maxStackSize = 1;
    012            this.setCreativeTab(CreativeTabs.tabRedstone);
    013        }
    014
    015        /**
    016         * Callback for item usage. If the item does something special on right clicking, he will have one of those. Return
    017         * True if something happen and false if it don't. This is for ITEMS, not BLOCKS
    018         */
    019        public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10)
    020        {
    021            if (par7 != 1)
    022            {
    023                return false;
    024            }
    025            else
    026            {
    027                ++par5;
    028                Block var11;
    029
    030                if (this.doorMaterial == Material.wood)
    031                {
    032                    var11 = Block.doorWood;
    033                }
    034                else
    035                {
    036                    var11 = Block.doorSteel;
    037                }
    038
    039                if (par2EntityPlayer.func_82247_a(par4, par5, par6, par7, par1ItemStack) && par2EntityPlayer.func_82247_a(par4, par5 + 1, par6, par7, par1ItemStack))
    040                {
    041                    if (!var11.canPlaceBlockAt(par3World, par4, par5, par6))
    042                    {
    043                        return false;
    044                    }
    045                    else
    046                    {
    047                        int var12 = MathHelper.floor_double((double)((par2EntityPlayer.rotationYaw + 180.0F) * 4.0F / 360.0F) - 0.5D) & 3;
    048                        placeDoorBlock(par3World, par4, par5, par6, var12, var11);
    049                        --par1ItemStack.stackSize;
    050                        return true;
    051                    }
    052                }
    053                else
    054                {
    055                    return false;
    056                }
    057            }
    058        }
    059
    060        public static void placeDoorBlock(World par0World, int par1, int par2, int par3, int par4, Block par5Block)
    061        {
    062            byte var6 = 0;
    063            byte var7 = 0;
    064
    065            if (par4 == 0)
    066            {
    067                var7 = 1;
    068            }
    069
    070            if (par4 == 1)
    071            {
    072                var6 = -1;
    073            }
    074
    075            if (par4 == 2)
    076            {
    077                var7 = -1;
    078            }
    079
    080            if (par4 == 3)
    081            {
    082                var6 = 1;
    083            }
    084
    085            int var8 = (par0World.isBlockNormalCube(par1 - var6, par2, par3 - var7) ? 1 : 0) + (par0World.isBlockNormalCube(par1 - var6, par2 + 1, par3 - var7) ? 1 : 0);
    086            int var9 = (par0World.isBlockNormalCube(par1 + var6, par2, par3 + var7) ? 1 : 0) + (par0World.isBlockNormalCube(par1 + var6, par2 + 1, par3 + var7) ? 1 : 0);
    087            boolean var10 = par0World.getBlockId(par1 - var6, par2, par3 - var7) == par5Block.blockID || par0World.getBlockId(par1 - var6, par2 + 1, par3 - var7) == par5Block.blockID;
    088            boolean var11 = par0World.getBlockId(par1 + var6, par2, par3 + var7) == par5Block.blockID || par0World.getBlockId(par1 + var6, par2 + 1, par3 + var7) == par5Block.blockID;
    089            boolean var12 = false;
    090
    091            if (var10 && !var11)
    092            {
    093                var12 = true;
    094            }
    095            else if (var9 > var8)
    096            {
    097                var12 = true;
    098            }
    099
    100            par0World.editingBlocks = true;
    101            par0World.setBlockAndMetadataWithNotify(par1, par2, par3, par5Block.blockID, par4);
    102            par0World.setBlockAndMetadataWithNotify(par1, par2 + 1, par3, par5Block.blockID, 8 | (var12 ? 1 : 0));
    103            par0World.editingBlocks = false;
    104            par0World.notifyBlocksOfNeighborChange(par1, par2, par3, par5Block.blockID);
    105            par0World.notifyBlocksOfNeighborChange(par1, par2 + 1, par3, par5Block.blockID);
    106        }
    107    }