mirror of
https://github.com/Thorfusion/Mekanism-Community-Edition.git
synced 2026-11-22 04:52:25 +00:00
144 lines
5.0 KiB
Java
144 lines
5.0 KiB
Java
package mekanism.tools.item;
|
|
|
|
import java.util.List;
|
|
|
|
import mekanism.common.item.ItemMekanism;
|
|
import mekanism.common.util.LangUtils;
|
|
import mekanism.common.util.StackUtils;
|
|
import net.minecraft.block.Block;
|
|
import net.minecraft.block.BlockDirt;
|
|
import net.minecraft.block.state.IBlockState;
|
|
import net.minecraft.client.util.ITooltipFlag;
|
|
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;
|
|
setMaxStackSize(1);
|
|
setMaxDamage(enumtoolmaterial.getMaxUses());
|
|
setCreativeTab(CreativeTabs.TOOLS);
|
|
speed = enumtoolmaterial.getAttackDamage() + 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(EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
|
|
{
|
|
ItemStack stack = playerIn.getHeldItem(hand);
|
|
|
|
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.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;
|
|
}
|
|
|
|
@Override
|
|
public boolean hitEntity(ItemStack stack, EntityLivingBase target, EntityLivingBase attacker)
|
|
{
|
|
stack.damageItem(1, attacker);
|
|
|
|
return true;
|
|
}
|
|
|
|
@Override
|
|
@SideOnly(Side.CLIENT)
|
|
public void addInformation(ItemStack itemstack, World world, List<String> list, ITooltipFlag flag)
|
|
{
|
|
list.add(LangUtils.localize("tooltip.hp") + ": " + (itemstack.getMaxDamage() - itemstack.getItemDamage()));
|
|
}
|
|
|
|
@Override
|
|
@SideOnly(Side.CLIENT)
|
|
public boolean isFull3D()
|
|
{
|
|
return true;
|
|
}
|
|
}
|