aboutsummaryrefslogtreecommitdiff
path: root/src/Java/miscutil/core/util
diff options
context:
space:
mode:
authorDraknyte1 <Draknyte1@hotmail.com>2016-03-25 01:47:09 +1000
committerDraknyte1 <Draknyte1@hotmail.com>2016-03-25 01:47:09 +1000
commit6e2d7b787d2338fd6e35532f91e6ff6a48eed682 (patch)
tree664c2caeb0a6b9fcc18bfd53a9d7a4afd7bee74b /src/Java/miscutil/core/util
parent46590e0c7b1f874c368f9ac335b4333222723c1e (diff)
downloadGT5-Unofficial-6e2d7b787d2338fd6e35532f91e6ff6a48eed682.tar.gz
GT5-Unofficial-6e2d7b787d2338fd6e35532f91e6ff6a48eed682.tar.bz2
GT5-Unofficial-6e2d7b787d2338fd6e35532f91e6ff6a48eed682.zip
Pickaxe should be rather 100% now.
Final commit before new builds.
Diffstat (limited to 'src/Java/miscutil/core/util')
-rw-r--r--src/Java/miscutil/core/util/MiningMethods.java179
-rw-r--r--src/Java/miscutil/core/util/Utils.java196
2 files changed, 300 insertions, 75 deletions
diff --git a/src/Java/miscutil/core/util/MiningMethods.java b/src/Java/miscutil/core/util/MiningMethods.java
new file mode 100644
index 0000000000..6f8042f800
--- /dev/null
+++ b/src/Java/miscutil/core/util/MiningMethods.java
@@ -0,0 +1,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 MiningMethods {
+
+ 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;
+ }
+ }
+
+
+}
diff --git a/src/Java/miscutil/core/util/Utils.java b/src/Java/miscutil/core/util/Utils.java
index ab60de8557..10375f3f8e 100644
--- a/src/Java/miscutil/core/util/Utils.java
+++ b/src/Java/miscutil/core/util/Utils.java
@@ -6,9 +6,12 @@ import java.awt.Graphics;
import java.util.Random;
import miscutil.core.lib.CORE;
+import net.minecraft.block.Block;
+import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
+import net.minecraft.world.World;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
import cpw.mods.fml.common.FMLLog;
@@ -17,7 +20,7 @@ import cpw.mods.fml.common.registry.GameRegistry;
public class Utils {
public static final int WILDCARD_VALUE = Short.MAX_VALUE;
-
+
/**
* Returns a psuedo-random number between min and max, inclusive.
* The difference between min and max can be at most
@@ -30,90 +33,90 @@ public class Utils {
*/
public static int randInt(int min, int max) {
- // Usually this can be a field rather than a method variable
- Random rand = new Random();
+ // Usually this can be a field rather than a method variable
+ Random rand = new Random();
- // nextInt is normally exclusive of the top value,
- // so add 1 to make it inclusive
- int randomNum = rand.nextInt((max - min) + 1) + min;
+ // nextInt is normally exclusive of the top value,
+ // so add 1 to make it inclusive
+ int randomNum = rand.nextInt((max - min) + 1) + min;
- return randomNum;
+ return randomNum;
}
-
+
public static long randLong(long min, long max) {
- // Usually this can be a field rather than a method variable
- Random rand = new Random();
+ // Usually this can be a field rather than a method variable
+ Random rand = new Random();
- // nextInt is normally exclusive of the top value,
- // so add 1 to make it inclusive
- long randomNum = nextLong(rand,(max - min) + 1) + min;
+ // nextInt is normally exclusive of the top value,
+ // so add 1 to make it inclusive
+ long randomNum = nextLong(rand,(max - min) + 1) + min;
- return randomNum;
+ return randomNum;
}
-
+
private static long nextLong(Random rng, long n) {
- // error checking and 2^x checking removed for simplicity.
- long bits, val;
- do {
- bits = (rng.nextLong() << 1) >>> 1;
- val = bits % n;
- } while (bits-val+(n-1) < 0L);
- return val;
+ // error checking and 2^x checking removed for simplicity.
+ long bits, val;
+ do {
+ bits = (rng.nextLong() << 1) >>> 1;
+ val = bits % n;
+ } while (bits-val+(n-1) < 0L);
+ return val;
+ }
+
+ public static boolean containsMatch(boolean strict, ItemStack[] inputs, ItemStack... targets)
+ {
+ for (ItemStack input : inputs)
+ {
+ for (ItemStack target : targets)
+ {
+ if (itemMatches(target, input, strict))
+ {
+ return true;
+ }
+ }
}
-
- public static boolean containsMatch(boolean strict, ItemStack[] inputs, ItemStack... targets)
- {
- for (ItemStack input : inputs)
- {
- for (ItemStack target : targets)
- {
- if (itemMatches(target, input, strict))
- {
- return true;
- }
- }
- }
- return false;
- }
-
- public static boolean itemMatches(ItemStack target, ItemStack input, boolean strict)
- {
- if (input == null && target != null || input != null && target == null)
- {
- return false;
- }
- return (target.getItem() == input.getItem() && ((target.getItemDamage() == WILDCARD_VALUE && !strict) || target.getItemDamage() == input.getItemDamage()));
- }
-
- //Non-Dev Comments
- public static void LOG_INFO(String s){
- //if (CORE.DEBUG){
- FMLLog.info("MiscUtils: "+s);
+ return false;
+ }
+
+ public static boolean itemMatches(ItemStack target, ItemStack input, boolean strict)
+ {
+ if (input == null && target != null || input != null && target == null)
+ {
+ return false;
+ }
+ return (target.getItem() == input.getItem() && ((target.getItemDamage() == WILDCARD_VALUE && !strict) || target.getItemDamage() == input.getItemDamage()));
+ }
+
+ //Non-Dev Comments
+ public static void LOG_INFO(String s){
+ //if (CORE.DEBUG){
+ FMLLog.info("MiscUtils: "+s);
//}
- }
-
- //Developer Comments
- public static void LOG_WARNING(String s){
- if (CORE.DEBUG){
+ }
+
+ //Developer Comments
+ public static void LOG_WARNING(String s){
+ if (CORE.DEBUG){
FMLLog.warning("MiscUtils: "+s);
}
- }
-
- //Errors
- public static void LOG_ERROR(String s){
- if (CORE.DEBUG){
+ }
+
+ //Errors
+ public static void LOG_ERROR(String s){
+ if (CORE.DEBUG){
FMLLog.severe("MiscUtils: "+s);
}
- }
-
- public static void paintBox(Graphics g, int MinA, int MinB, int MaxA, int MaxB){
- g.drawRect (MinA, MinB, MaxA, MaxB);
- }
-
- public static void messagePlayer(EntityPlayer P, String S){
- gregtech.api.util.GT_Utility.sendChatToPlayer(P, S);
- }
-
+ }
+
+ public static void paintBox(Graphics g, int MinA, int MinB, int MaxA, int MaxB){
+ g.drawRect (MinA, MinB, MaxA, MaxB);
+ }
+
+ public static void messagePlayer(EntityPlayer P, String S){
+ gregtech.api.util.GT_Utility.sendChatToPlayer(P, S);
+ }
+
/**
* Returns if that Liquid is IC2Steam.
*/
@@ -121,7 +124,7 @@ public class Utils {
if (aFluid == null) return F;
return aFluid.isFluidEqual(getIC2Steam(1));
}
-
+
/**
* Returns a Liquid Stack with given amount of IC2Steam.
*/
@@ -131,9 +134,52 @@ public class Utils {
public static Item getItem(String fqrn) // fqrn = fully qualified resource name
{
- String[] fqrnSplit = fqrn.split(":");
- return GameRegistry.findItem(fqrnSplit[0], fqrnSplit[1]);
+ String[] fqrnSplit = fqrn.split(":");
+ return GameRegistry.findItem(fqrnSplit[0], fqrnSplit[1]);
+ }
+
+ public static Item getItemInPlayersHand(){
+ Minecraft mc = Minecraft.getMinecraft();
+ Item heldItem = null;
+
+ try{heldItem = mc.thePlayer.getHeldItem().getItem();
+ }catch(NullPointerException e){return null;}
+
+ if (heldItem != null){
+ return heldItem;
+ }
+
+ return null;
+ }
+
+ public static void recipeBuilderBlock(ItemStack slot_1, ItemStack slot_2, ItemStack slot_3, ItemStack slot_4, ItemStack slot_5, ItemStack slot_6, ItemStack slot_7, ItemStack slot_8, ItemStack slot_9, Block resultBlock){
+ GameRegistry.addRecipe(
+ new ItemStack(resultBlock),
+ slot_1, slot_2, slot_3,
+ slot_4, slot_5, slot_6,
+ slot_7, slot_8, slot_9);
+ }
+
+ public static void recipeBuilderItem(ItemStack slot_1, ItemStack slot_2, ItemStack slot_3, ItemStack slot_4, ItemStack slot_5, ItemStack slot_6, ItemStack slot_7, ItemStack slot_8, ItemStack slot_9, Item resultItem){
+ GameRegistry.addRecipe(
+ new ItemStack(resultItem),
+ slot_1, slot_2, slot_3,
+ slot_4, slot_5, slot_6,
+ slot_7, slot_8, slot_9);
}
-
+ public static String checkCorrectMiningToolForBlock(Block currentBlock, World currentWorld){
+ String correctTool = "";
+ if (!currentWorld.isRemote){
+ try {
+ correctTool = currentBlock.getHarvestTool(0);
+ Utils.LOG_WARNING(correctTool);
+
+ } catch (NullPointerException e){
+
+ }
+ }
+
+ return correctTool;
+ }
}