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