aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gregtech/common/tools/GT_Tool_BranchCutter.java
blob: a1e29211533a8624329a54aa5b34692750dbf2d5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package gregtech.common.tools;

import gregtech.api.enums.Materials;
import gregtech.api.enums.Textures;
import gregtech.api.enums.Textures.ItemIcons;
import gregtech.api.interfaces.IIconContainer;
import gregtech.api.items.GT_MetaGenerated_Tool;
import gregtech.api.util.GT_ModHandler;
import gregtech.api.util.GT_Utility;

import java.util.List;
import java.util.Random;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.IChatComponent;
import net.minecraft.world.World;
import net.minecraftforge.event.world.BlockEvent;
import net.minecraftforge.event.world.BlockEvent.HarvestDropsEvent;

public class GT_Tool_BranchCutter
  extends GT_Tool
{
  public float getBaseDamage()
  {
    return 2.5F;
  }
  
  public float getSpeedMultiplier()
  {
    return 0.25F;
  }
  
  public float getMaxDurabilityMultiplier()
  {
    return 0.25F;
  }
  
  public boolean isGrafter()
  {
    return true;
  }
  
  public int convertBlockDrops(List<ItemStack> aDrops, ItemStack aStack, EntityPlayer aPlayer, Block aBlock, int aX, int aY, int aZ, byte aMetaData, int aFortune, boolean aSilkTouch, BlockEvent.HarvestDropsEvent aEvent)
  {
    if (aBlock.getMaterial() == Material.leaves)
    {
      aEvent.dropChance = Math.min(1.0F, Math.max(aEvent.dropChance, (aStack.getItem().getHarvestLevel(aStack, "") + 1) * 0.2F));
      if (aBlock == Blocks.leaves)
      {
        aDrops.clear();
        if (((aMetaData & 0x3) == 0) && (aPlayer.worldObj.rand.nextInt(9) <= aFortune * 2)) {
          aDrops.add(new ItemStack(Items.apple, 1, 0));
        } else {
          aDrops.add(new ItemStack(Blocks.sapling, 1, aMetaData & 0x3));
        }
      }
      else if (aBlock == Blocks.leaves2)
      {
        aDrops.clear();
        aDrops.add(new ItemStack(Blocks.sapling, 1, (aMetaData & 0x3) + 4));
      }
      else if (aBlock == GT_Utility.getBlockFromStack(GT_ModHandler.getIC2Item("rubberLeaves", 1L)))
      {
        aDrops.clear();
        aDrops.add(GT_ModHandler.getIC2Item("rubberSapling", 1L));
      }
    }
    return 0;
  }
  
  public boolean isMinableBlock(Block aBlock, byte aMetaData)
  {
    String tTool = aBlock.getHarvestTool(aMetaData);
    return ((tTool != null) && (tTool.equals("grafter"))) || (aBlock.getMaterial() == Material.leaves);
  }
  
  public IIconContainer getIcon(boolean aIsToolHead, ItemStack aStack)
  {
    return aIsToolHead ? Textures.ItemIcons.GRAFTER : null;
  }
  
  public short[] getRGBa(boolean aIsToolHead, ItemStack aStack)
  {
    return aIsToolHead ? GT_MetaGenerated_Tool.getPrimaryMaterial(aStack).mRGBa : GT_MetaGenerated_Tool.getSecondaryMaterial(aStack).mRGBa;
  }
  
  public IChatComponent getDeathMessage(EntityLivingBase aPlayer, EntityLivingBase aEntity)
  {
    return new ChatComponentText(EnumChatFormatting.RED + aEntity.getCommandSenderName() + EnumChatFormatting.WHITE + " has been trimmed by " + EnumChatFormatting.GREEN + aPlayer.getCommandSenderName() + EnumChatFormatting.WHITE);
  }
}