Files
PrimalSorcery/build/tmp/recompileMc/sources/net/minecraft/item/ItemHoe.java
Mohammad-Ali Minaie b86dedad2f base mod created
2018-10-08 09:07:47 -04:00

139 lines
5.1 KiB
Java

package net.minecraft.item;
import com.google.common.collect.Multimap;
import net.minecraft.block.Block;
import net.minecraft.block.BlockDirt;
import net.minecraft.block.material.Material;
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.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;
public class ItemHoe extends Item
{
private final float speed;
protected Item.ToolMaterial toolMaterial;
public ItemHoe(Item.ToolMaterial material)
{
this.toolMaterial = material;
this.maxStackSize = 1;
this.setMaxDamage(material.getMaxUses());
this.setCreativeTab(CreativeTabs.TOOLS);
this.speed = material.getAttackDamage() + 1.0F;
}
/**
* Called when a Block is right-clicked with this Item
*/
@SuppressWarnings("incomplete-switch")
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
{
ItemStack itemstack = player.getHeldItem(hand);
if (!player.canPlayerEdit(pos.offset(facing), facing, itemstack))
{
return EnumActionResult.FAIL;
}
else
{
int hook = net.minecraftforge.event.ForgeEventFactory.onHoeUse(itemstack, player, 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)
{
this.setBlock(itemstack, player, worldIn, pos, Blocks.FARMLAND.getDefaultState());
return EnumActionResult.SUCCESS;
}
if (block == Blocks.DIRT)
{
switch ((BlockDirt.DirtType)iblockstate.getValue(BlockDirt.VARIANT))
{
case DIRT:
this.setBlock(itemstack, player, worldIn, pos, Blocks.FARMLAND.getDefaultState());
return EnumActionResult.SUCCESS;
case COARSE_DIRT:
this.setBlock(itemstack, player, worldIn, pos, Blocks.DIRT.getDefaultState().withProperty(BlockDirt.VARIANT, BlockDirt.DirtType.DIRT));
return EnumActionResult.SUCCESS;
}
}
}
return EnumActionResult.PASS;
}
}
/**
* Current implementations of this method in child classes do not use the entry argument beside ev. They just raise
* the damage on the stack.
*/
public boolean hitEntity(ItemStack stack, EntityLivingBase target, EntityLivingBase attacker)
{
stack.damageItem(1, attacker);
return true;
}
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);
}
}
/**
* Returns True is the item is renderer in full 3D when hold.
*/
@SideOnly(Side.CLIENT)
public boolean isFull3D()
{
return true;
}
/**
* Returns the name of the material this tool is made from as it is declared in EnumToolMaterial (meaning diamond
* would return "EMERALD")
*/
public String getMaterialName()
{
return this.toolMaterial.toString();
}
/**
* Gets a map of item attribute modifiers, used by ItemSword to increase hit damage.
*/
public Multimap<String, AttributeModifier> getItemAttributeModifiers(EntityEquipmentSlot equipmentSlot)
{
Multimap<String, AttributeModifier> multimap = super.getItemAttributeModifiers(equipmentSlot);
if (equipmentSlot == EntityEquipmentSlot.MAINHAND)
{
multimap.put(SharedMonsterAttributes.ATTACK_DAMAGE.getName(), new AttributeModifier(ATTACK_DAMAGE_MODIFIER, "Weapon modifier", 0.0D, 0));
multimap.put(SharedMonsterAttributes.ATTACK_SPEED.getName(), new AttributeModifier(ATTACK_SPEED_MODIFIER, "Weapon modifier", (double)(this.speed - 4.0F), 0));
}
return multimap;
}
}