| 1 | package net.minecraft.item;
|
| 2 |
|
| 3 | import net.minecraft.block.Block;
|
| 4 | import net.minecraft.block.BlockDirt;
|
| 5 | import net.minecraft.block.material.Material;
|
| 6 | import net.minecraft.block.state.IBlockState;
|
| 7 | import net.minecraft.creativetab.CreativeTabs;
|
| 8 | import net.minecraft.entity.player.EntityPlayer;
|
| 9 | import net.minecraft.init.Blocks;
|
| 10 | import net.minecraft.util.BlockPos;
|
| 11 | import net.minecraft.util.EnumFacing;
|
| 12 | import net.minecraft.world.World;
|
| 13 |
|
| 14 | public class ItemHoe extends Item
|
| 15 | {
|
| 16 | protected Item.ToolMaterial theToolMaterial;
|
| 17 |
|
| 18 | public ItemHoe(Item.ToolMaterial material)
|
| 19 | {
|
| 20 | this.theToolMaterial = material;
|
| 21 | this.maxStackSize = 1;
|
| 22 | this.setMaxDamage(material.getMaxUses());
|
| 23 | this.setCreativeTab(CreativeTabs.tabTools);
|
| 24 | }
|
| 25 |
|
| 26 | @SuppressWarnings("incomplete-switch")
|
| 27 |
|
| 28 | /**
|
| 29 | * Called when a Block is right-clicked with this Item
|
| 30 | */
|
| 31 | public boolean onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ)
|
| 32 | {
|
| 33 | if (!playerIn.canPlayerEdit(pos.offset(side), side, stack))
|
| 34 | {
|
| 35 | return false;
|
| 36 | }
|
| 37 | else
|
| 38 | {
|
| 39 | IBlockState iblockstate = worldIn.getBlockState(pos);
|
| 40 | Block block = iblockstate.getBlock();
|
| 41 |
|
| 42 | if (side != EnumFacing.DOWN && worldIn.getBlockState(pos.up()).getBlock().getMaterial() == Material.air)
|
| 43 | {
|
| 44 | if (block == Blocks.grass)
|
| 45 | {
|
| 46 | return this.useHoe(stack, playerIn, worldIn, pos, Blocks.farmland.getDefaultState());
|
| 47 | }
|
| 48 |
|
| 49 | if (block == Blocks.dirt)
|
| 50 | {
|
| 51 | switch ((BlockDirt.DirtType)iblockstate.getValue(BlockDirt.VARIANT))
|
| 52 | {
|
| 53 | case DIRT:
|
| 54 | return this.useHoe(stack, playerIn, worldIn, pos, Blocks.farmland.getDefaultState());
|
| 55 |
|
| 56 | case COARSE_DIRT:
|
| 57 | return this.useHoe(stack, playerIn, worldIn, pos, Blocks.dirt.getDefaultState().withProperty(BlockDirt.VARIANT, BlockDirt.DirtType.DIRT));
|
| 58 | }
|
| 59 | }
|
| 60 | }
|
| 61 |
|
| 62 | return false;
|
| 63 | }
|
| 64 | }
|
| 65 |
|
| 66 | protected boolean useHoe(ItemStack stack, EntityPlayer player, World worldIn, BlockPos target, IBlockState newState)
|
| 67 | {
|
| 68 | worldIn.playSoundEffect((double)((float)target.getX() + 0.5F), (double)((float)target.getY() + 0.5F), (double)((float)target.getZ() + 0.5F), newState.getBlock().stepSound.getStepSound(), (newState.getBlock().stepSound.getVolume() + 1.0F) / 2.0F, newState.getBlock().stepSound.getFrequency() * 0.8F);
|
| 69 |
|
| 70 | if (worldIn.isRemote)
|
| 71 | {
|
| 72 | return true;
|
| 73 | }
|
| 74 | else
|
| 75 | {
|
| 76 | worldIn.setBlockState(target, newState);
|
| 77 | stack.damageItem(1, player);
|
| 78 | return true;
|
| 79 | }
|
| 80 | }
|
| 81 |
|
| 82 | /**
|
| 83 | * Returns True is the item is renderer in full 3D when hold.
|
| 84 | */
|
| 85 | public boolean isFull3D()
|
| 86 | {
|
| 87 | return true;
|
| 88 | }
|
| 89 |
|
| 90 | /**
|
| 91 | * Returns the name of the material this tool is made from as it is declared in EnumToolMaterial (meaning diamond
|
| 92 | * would return "EMERALD")
|
| 93 | */
|
| 94 | public String getMaterialName()
|
| 95 | {
|
| 96 | return this.theToolMaterial.toString();
|
| 97 | }
|
| 98 | }
|
| 99 |
|