| package mekanism.tools.item; |
| |
| import java.util.List; |
| |
| import mekanism.api.util.StackUtils; |
| import mekanism.common.item.ItemMekanism; |
| import mekanism.common.util.LangUtils; |
| import net.minecraft.block.Block; |
| import net.minecraft.block.BlockDirt; |
| import net.minecraft.block.state.IBlockState; |
| import net.minecraft.creativetab.CreativeTabs; |
| import net.minecraft.entity.EntityLivingBase; |
| import net.minecraft.entity.SharedMonsterAttributes; |
| import net.minecraft.entity.ai.attributes.AttributeModifier; |
| import net.minecraft.entity.player.EntityPlayer; |
| import net.minecraft.init.Blocks; |
| import net.minecraft.init.SoundEvents; |
| import net.minecraft.inventory.EntityEquipmentSlot; |
| import net.minecraft.item.ItemStack; |
| import net.minecraft.util.EnumActionResult; |
| import net.minecraft.util.EnumFacing; |
| import net.minecraft.util.EnumHand; |
| import net.minecraft.util.SoundCategory; |
| import net.minecraft.util.math.BlockPos; |
| import net.minecraft.world.World; |
| import net.minecraftforge.fml.relauncher.Side; |
| import net.minecraftforge.fml.relauncher.SideOnly; |
| |
| import com.google.common.collect.Multimap; |
| |
| public class ItemMekanismHoe extends ItemMekanism |
| { |
| protected ToolMaterial toolMaterial; |
| |
| private final float speed; |
| |
| public ItemMekanismHoe(ToolMaterial enumtoolmaterial) |
| { |
| super(); |
| toolMaterial = enumtoolmaterial; |
| maxStackSize = 1; |
| setMaxDamage(enumtoolmaterial.getMaxUses()); |
| setCreativeTab(CreativeTabs.TOOLS); |
| speed = enumtoolmaterial.getDamageVsEntity() + 1.0F; |
| } |
| |
| @Override |
| public boolean getIsRepairable(ItemStack stack1, ItemStack stack2) |
| { |
| return StackUtils.equalsWildcard(ItemMekanismTool.getRepairStack(toolMaterial), stack2) ? true : super.getIsRepairable(stack1, stack2); |
| } |
| |
| @Override |
| @SuppressWarnings("incomplete-switch") |
| public EnumActionResult onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) |
| { |
| if(!playerIn.canPlayerEdit(pos.offset(facing), facing, stack)) |
| { |
| return EnumActionResult.FAIL; |
| } |
| else { |
| int hook = net.minecraftforge.event.ForgeEventFactory.onHoeUse(stack, playerIn, worldIn, pos); |
| if(hook != 0) return hook > 0 ? EnumActionResult.SUCCESS : EnumActionResult.FAIL; |
| |
| IBlockState iblockstate = worldIn.getBlockState(pos); |
| Block block = iblockstate.getBlock(); |
| |
| if(facing != EnumFacing.DOWN && worldIn.isAirBlock(pos.up())) |
| { |
| if(block == Blocks.GRASS || block == Blocks.GRASS_PATH) |
| { |
| setBlock(stack, playerIn, worldIn, pos, Blocks.FARMLAND.getDefaultState()); |
| return EnumActionResult.SUCCESS; |
| } |
| |
| if(block == Blocks.DIRT) |
| { |
| switch((BlockDirt.DirtType)iblockstate.getValue(BlockDirt.VARIANT)) |
| { |
| case DIRT: |
| setBlock(stack, playerIn, worldIn, pos, Blocks.FARMLAND.getDefaultState()); |
| return EnumActionResult.SUCCESS; |
| case COARSE_DIRT: |
| setBlock(stack, playerIn, worldIn, pos, Blocks.DIRT.getDefaultState().withProperty(BlockDirt.VARIANT, BlockDirt.DirtType.DIRT)); |
| return EnumActionResult.SUCCESS; |
| } |
| } |
| } |
| |
| return EnumActionResult.PASS; |
| } |
| } |
| |
| protected void setBlock(ItemStack stack, EntityPlayer player, World worldIn, BlockPos pos, IBlockState state) |
| { |
| worldIn.playSound(player, pos, SoundEvents.ITEM_HOE_TILL, SoundCategory.BLOCKS, 1.0F, 1.0F); |
| |
| if(!worldIn.isRemote) |
| { |
| worldIn.setBlockState(pos, state, 11); |
| stack.damageItem(1, player); |
| } |
| } |
| |
| @Override |
| public Multimap<String, AttributeModifier> getAttributeModifiers(EntityEquipmentSlot equipmentSlot, ItemStack stack) |
| { |
| Multimap<String, AttributeModifier> multimap = super.getAttributeModifiers(equipmentSlot, stack); |
| |
| if(equipmentSlot == EntityEquipmentSlot.MAINHAND) |
| { |
| multimap.put(SharedMonsterAttributes.ATTACK_DAMAGE.getAttributeUnlocalizedName(), new AttributeModifier(ATTACK_DAMAGE_MODIFIER, "Weapon modifier", 0.0D, 0)); |
| multimap.put(SharedMonsterAttributes.ATTACK_SPEED.getAttributeUnlocalizedName(), new AttributeModifier(ATTACK_SPEED_MODIFIER, "Weapon modifier", (double)(this.speed - 4.0F), 0)); |
| } |
| |
| return multimap; |
| } |
| |
| @Override |
| public boolean hitEntity(ItemStack stack, EntityLivingBase target, EntityLivingBase attacker) |
| { |
| stack.damageItem(1, attacker); |
| |
| return true; |
| } |
| |
| @Override |
| public void addInformation(ItemStack itemstack, EntityPlayer entityplayer, List list, boolean flag) |
| { |
| list.add(LangUtils.localize("tooltip.hp") + ": " + (itemstack.getMaxDamage() - itemstack.getItemDamage())); |
| } |
| |
| @Override |
| @SideOnly(Side.CLIENT) |
| public boolean isFull3D() |
| { |
| return true; |
| } |
| } |