aboutsummaryrefslogtreecommitdiff
path: root/main/java/gregtech/common/items/behaviors/Behaviour_Prospecting.java
blob: c90c5bf42f0db8e34f27b0e5573abfc575da2624 (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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
package gregtech.common.items.behaviors;

import gregtech.api.GregTech_API;
import gregtech.api.enums.Materials;
import gregtech.api.enums.OrePrefixes;
import gregtech.api.items.GT_MetaBase_Item;
import gregtech.api.items.GT_MetaGenerated_Tool;
import gregtech.api.objects.ItemData;
import gregtech.api.objects.MaterialStack;
import gregtech.api.util.GT_LanguageManager;
import gregtech.api.util.GT_ModHandler;
import gregtech.api.util.GT_OreDictUnificator;
import gregtech.api.util.GT_Utility;
import gregtech.common.blocks.GT_Block_Ores;
import gregtech.common.blocks.GT_TileEntity_Ores;
import java.util.List;
import java.util.Map;
import java.util.Random;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.IFluidBlock;

public class Behaviour_Prospecting
  extends Behaviour_None
{
  private final int mVanillaCosts;
  private final int mEUCosts;
  
  public Behaviour_Prospecting(int aVanillaCosts, int aEUCosts)
  {
    this.mVanillaCosts = aVanillaCosts;
    this.mEUCosts = aEUCosts;
  }
  
  public boolean onItemUseFirst(GT_MetaBase_Item aItem, ItemStack aStack, EntityPlayer aPlayer, World aWorld, int aX, int aY, int aZ, int aSide, float hitX, float hitY, float hitZ)
  {
    if (aWorld.isRemote) {
      return false;
    }
    Block aBlock = aWorld.getBlock(aX, aY, aZ);
    if (aBlock == null) {
      return false;
    }
    byte aMeta = (byte)aWorld.getBlockMetadata(aX, aY, aZ);
    

    ItemData tAssotiation = GT_OreDictUnificator.getAssociation(new ItemStack(aBlock, 1, aMeta));
    if ((tAssotiation != null) && (tAssotiation.mPrefix.toString().startsWith("ore")))
    {
      GT_Utility.sendChatToPlayer(aPlayer, "This is " + tAssotiation.mMaterial.mMaterial.mDefaultLocalName + " Ore.");
      GT_Utility.sendSoundToPlayers(aWorld, (String)GregTech_API.sSoundList.get(Integer.valueOf(1)), 1.0F, -1.0F, aX, aY, aZ);
      return true;
    }
    if ((aBlock.isReplaceableOreGen(aWorld, aX, aY, aZ, Blocks.stone)) || (aBlock.isReplaceableOreGen(aWorld, aX, aY, aZ, GregTech_API.sBlockGranites)) || (aBlock.isReplaceableOreGen(aWorld, aX, aY, aZ, Blocks.netherrack)) || (aBlock.isReplaceableOreGen(aWorld, aX, aY, aZ, Blocks.end_stone)))
    {
      if (GT_ModHandler.damageOrDechargeItem(aStack, this.mVanillaCosts, this.mEUCosts, aPlayer))
      {
        GT_Utility.sendSoundToPlayers(aWorld, (String)GregTech_API.sSoundList.get(Integer.valueOf(1)), 1.0F, -1.0F, aX, aY, aZ);
        int tX = aX;int tY = aY;int tZ = aZ;int tMetaID = 0;int tQuality = (aItem instanceof GT_MetaGenerated_Tool) ? ((GT_MetaGenerated_Tool)aItem).getHarvestLevel(aStack, "") : 0;
        
        int i = 0;
        for (int j = 6 + tQuality; i < j; i++)
        {
          tX -= ForgeDirection.getOrientation(aSide).offsetX;
          tY -= ForgeDirection.getOrientation(aSide).offsetY;
          tZ -= ForgeDirection.getOrientation(aSide).offsetZ;
          
          Block tBlock = aWorld.getBlock(tX, tY, tZ);
          if ((tBlock == Blocks.lava) || (tBlock == Blocks.flowing_lava))
          {
            GT_Utility.sendChatToPlayer(aPlayer, "There is Lava behind this Rock.");
            break;
          }
          if ((tBlock == Blocks.water) || (tBlock == Blocks.flowing_water) || ((tBlock instanceof IFluidBlock)))
          {
            GT_Utility.sendChatToPlayer(aPlayer, "There is a Liquid behind this Rock.");
            break;
          }
          if ((tBlock == Blocks.monster_egg) || (!GT_Utility.hasBlockHitBox(aWorld, tX, tY, tZ)))
          {
            GT_Utility.sendChatToPlayer(aPlayer, "There is an Air Pocket behind this Rock.");
            break;
          }
          if (tBlock != aBlock)
          {
            if (i >= 4) {
              break;
            }
            GT_Utility.sendChatToPlayer(aPlayer, "Material is changing behind this Rock."); break;
          }
        }
        Random tRandom = new Random(aX ^ aY ^ aZ ^ aSide);
        i = 0;
        for (int j = 9 + 2 * tQuality; i < j; i++)
        {
          tX = aX - 4 - tQuality + tRandom.nextInt(j);
          tY = aY - 4 - tQuality + tRandom.nextInt(j);
          tZ = aZ - 4 - tQuality + tRandom.nextInt(j);
          Block tBlock = aWorld.getBlock(tX, tY, tZ);
          if ((tBlock instanceof GT_Block_Ores))
          {
            TileEntity tTileEntity = aWorld.getTileEntity(tX, tY, tZ);
            if ((tTileEntity instanceof GT_TileEntity_Ores))
            {
              Materials tMaterial = GregTech_API.sGeneratedMaterials[(((GT_TileEntity_Ores)tTileEntity).mMetaData % 1000)];
              if ((tMaterial != null) && (tMaterial != Materials._NULL))
              {
                GT_Utility.sendChatToPlayer(aPlayer, "Found traces of " + tMaterial.mDefaultLocalName + " Ore.");
                return true;
              }
            }
          }
          else
          {
            tMetaID = aWorld.getBlockMetadata(tX, tY, tZ);
            tAssotiation = GT_OreDictUnificator.getAssociation(new ItemStack(tBlock, 1, tMetaID));
            if ((tAssotiation != null) && (tAssotiation.mPrefix.toString().startsWith("ore")))
            {
              GT_Utility.sendChatToPlayer(aPlayer, "Found traces of " + tAssotiation.mMaterial.mMaterial.mDefaultLocalName + " Ore.");
              return true;
            }
          }
        }
        GT_Utility.sendChatToPlayer(aPlayer, "No Ores found.");
      }
      return true;
    }
    return false;
  }
  
  private final String mTooltip = GT_LanguageManager.addStringLocalization("gt.behaviour.prospecting", "Usable for Prospecting");
  
  public List<String> getAdditionalToolTips(GT_MetaBase_Item aItem, List<String> aList, ItemStack aStack)
  {
    aList.add(this.mTooltip);
    return aList;
  }
}



/* Location:           F:\Torrent\minecraft\jd-gui-0.3.6.windows\gregtech_1.7.10-5.07.07-dev.jar

 * Qualified Name:     gregtech.common.items.behaviors.Behaviour_Prospecting

 * JD-Core Version:    0.7.0.1

 */