aboutsummaryrefslogtreecommitdiff
path: root/src/Java/miscutil/core/util/UtilsMining.java
blob: 4c6ef7cda9768f5d875fca0072239ea9bdd53a34 (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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
package miscutil.core.util;

import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;

public class UtilsMining {
	
	private static boolean durabilityDamage = false;
	private static ItemStack stack;

	public static Boolean canPickaxeBlock(Block currentBlock, World currentWorld){
		String correctTool = "";
		if (!currentWorld.isRemote){			
			try {
				correctTool = currentBlock.getHarvestTool(0);
				//Utils.LOG_WARNING(correctTool);
				if (correctTool.equals("pickaxe")){
					return true;}
			} catch (NullPointerException e){
				return false;}
		}
		return false;
	}
	
	private static void removeBlockAndDropAsItem(World world, int X, int Y, int Z){
		try {
			Block block = world.getBlock(X, Y, Z);		
				if (canPickaxeBlock(block, world)){
					if((block != Blocks.bedrock) && (block.getBlockHardness(world, X, Y, Z) != -1) && (block.getBlockHardness(world, X, Y, Z) <= 100) && (block != Blocks.water) && (block != Blocks.lava)){
						block.dropBlockAsItem(world, X, Y, Z, world.getBlockMetadata(X, Y, Z), 0);
						world.setBlockToAir(X, Y, Z);

				}
				else {
					Utils.LOG_WARNING("Incorrect Tool for mining this block.");
				}
			}
		} catch (NullPointerException e){

		}
	}

	public static void customMine(World world, String FACING, EntityPlayer aPlayer){

		float DURABILITY_LOSS = 0;
		if (!world.isRemote){
			int X = 0;
			int Y = 0;
			int Z = 0;

			if (FACING.equals("below") || FACING.equals("above")){

				//Set Player Facing
				X = (int) aPlayer.posX;
				Utils.LOG_WARNING("Setting Variable X: "+X);
				if (FACING.equals("above")){
					Z = (int) aPlayer.posY + 1;
					Utils.LOG_WARNING("Setting Variable Y: "+Y);
					}
					else {
						Z = (int) aPlayer.posY - 1;
						Utils.LOG_WARNING("Setting Variable Y: "+Y);}
				Z = (int) aPlayer.posZ;
				Utils.LOG_WARNING("Setting Variable Z: "+Z);

				DURABILITY_LOSS = 0;
				for(int i = -2; i < 3; i++) {
					for(int j = -2; j < 3; j++) {
						for(int k = -2; k < 3; k++) {
/*//							float dur = calculateDurabilityLoss(world, X + i, Y + k, Z + j);
//							DURABILITY_LOSS = (DURABILITY_LOSS + dur);	
//							Utils.LOG_WARNING("Added Loss: "+dur);
*/							removeBlockAndDropAsItem(world, X + i, Y + k, Z + j);
						}
					}
				}
			}

			else if (FACING.equals("facingEast") || FACING.equals("facingWest")){

				//Set Player Facing
				Z = (int) aPlayer.posZ;
				Y = (int) aPlayer.posY;
				if (FACING.equals("facingEast")){
					X = (int) aPlayer.posX + 1;}
					else {
						X = (int) aPlayer.posX - 1;}
					

				DURABILITY_LOSS = 0;
				for(int i = -1; i < 2; i++) {
					for(int j = -1; j < 2; j++) {
						for(int k = -1; k < 2; k++) {
							/*float dur = calculateDurabilityLoss(world, X+k, Y + i, Z + j);
							DURABILITY_LOSS = (DURABILITY_LOSS + dur);
							Utils.LOG_WARNING("Added Loss: "+dur);*/
							removeBlockAndDropAsItem(world, X+k, Y + i, Z + j);
						}
					}
				}
			}

			else if (FACING.equals("facingNorth") || FACING.equals("facingSouth")){

				//Set Player Facing
				X = (int) aPlayer.posX;
				Y = (int) aPlayer.posY;
				
				if (FACING.equals("facingNorth")){
				Z = (int) aPlayer.posZ + 1;}
				else {
					Z = (int) aPlayer.posZ - 1;}
				
				DURABILITY_LOSS = 0;
				for(int i = -1; i < 2; i++) {
					for(int j = -1; j < 2; j++) {
						for(int k = -1; k < 2; k++) {
							/*float dur = calculateDurabilityLoss(world, X + j, Y + i, Z+k);
							DURABILITY_LOSS = (DURABILITY_LOSS + dur);
							Utils.LOG_WARNING("Added Loss: "+dur);*/
							removeBlockAndDropAsItem(world, X + j, Y + i, Z+k);
						}
					}
				}
			}

			//Set Durability damage to the item
			if (durabilityDamage == true){
			Utils.LOG_WARNING("Total Loss: "+(int)DURABILITY_LOSS);
			if (stack.getItemDamage() < (stack.getMaxDamage()-DURABILITY_LOSS)){
				stack.damageItem((int) DURABILITY_LOSS, aPlayer);
			}
			}
			DURABILITY_LOSS = 0;
		}
	}
	
	
	public static boolean getBlockType(Block block){
		final String LIQUID = "liquid";
		final String BLOCK = "block";
		final String ORE = "ore";
		final String AIR = "air";
		String blockClass = "";

		try {
			blockClass = block.getClass().toString().toLowerCase();
			Utils.LOG_WARNING(blockClass);
			if (blockClass.toLowerCase().contains(LIQUID)){
				Utils.LOG_WARNING(block.toString()+" is a Liquid.");
				return false;
			}
			else if (blockClass.toLowerCase().contains(ORE)){
				Utils.LOG_WARNING(block.toString()+" is an Ore.");
				return true;
			}
			else if (blockClass.toLowerCase().contains(AIR)){
				Utils.LOG_WARNING(block.toString()+" is Air.");
				return false;
			}
			else if (blockClass.toLowerCase().contains(BLOCK)){
				Utils.LOG_WARNING(block.toString()+" is a block of some kind.");
				return false;
			}
			else {
				Utils.LOG_WARNING(block.toString()+" is mystery.");
				return false;
			}
		}
		catch(NullPointerException e){
			return false;
		}
	}
	
	
}