diff options
| author | Draknyte1 <Draknyte1@hotmail.com> | 2016-11-06 19:32:27 +1000 |
|---|---|---|
| committer | Draknyte1 <Draknyte1@hotmail.com> | 2016-11-06 19:32:27 +1000 |
| commit | cbe0e497be8e466c380a5b4fa781b314ede9ada3 (patch) | |
| tree | b85848b432adf458e3abda466ee46d9dfc3e454b /src/Java/gtPlusPlus/core/util/player | |
| parent | c40416b036c0e89451e1558253ccf07bbee028d0 (diff) | |
| download | GT5-Unofficial-cbe0e497be8e466c380a5b4fa781b314ede9ada3.tar.gz GT5-Unofficial-cbe0e497be8e466c380a5b4fa781b314ede9ada3.tar.bz2 GT5-Unofficial-cbe0e497be8e466c380a5b4fa781b314ede9ada3.zip | |
Revert "$ Cleaned up the entire project."
This reverts commit 0669f5eb9d5029a8b94ec552171b0837605f7747.
# Conflicts:
# src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/GregtechMTE_NuclearReactor.java
# src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/GregtechMetaTileEntity_MassFabricator.java
Revert "% Cleaned up Imports."
This reverts commit 3654052fb63a571c5eaca7f20714b87c17f7e966.
Diffstat (limited to 'src/Java/gtPlusPlus/core/util/player')
| -rw-r--r-- | src/Java/gtPlusPlus/core/util/player/PlayerCache.java | 282 | ||||
| -rw-r--r-- | src/Java/gtPlusPlus/core/util/player/PlayerUtils.java | 179 | ||||
| -rw-r--r-- | src/Java/gtPlusPlus/core/util/player/UtilsMining.java | 204 |
3 files changed, 323 insertions, 342 deletions
diff --git a/src/Java/gtPlusPlus/core/util/player/PlayerCache.java b/src/Java/gtPlusPlus/core/util/player/PlayerCache.java index ea40993dae..095eb543db 100644 --- a/src/Java/gtPlusPlus/core/util/player/PlayerCache.java +++ b/src/Java/gtPlusPlus/core/util/player/PlayerCache.java @@ -1,11 +1,24 @@ package gtPlusPlus.core.util.player; -import java.io.*; -import java.util.*; -import java.util.Map.Entry; - import gtPlusPlus.core.lib.CORE; import gtPlusPlus.core.util.Utils; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.FileReader; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.OutputStream; +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Objects; +import java.util.Properties; +import java.util.UUID; + import net.minecraft.client.Minecraft; import net.minecraft.world.World; @@ -13,170 +26,165 @@ public class PlayerCache { private static final File cache = new File("PlayerCache.dat"); - public static void appendParamChanges(final String playerName, final String playerUUIDasString) { - final HashMap<String, UUID> playerInfo = new HashMap<String, UUID>(); - playerInfo.put(playerName, UUID.fromString(playerUUIDasString)); - - /* - * try { Utils.LOG_INFO("Attempting to load "+cache.getName()); - * properties.load(new FileInputStream(cache)); if (properties == null - * || properties.equals(null)){ Utils.LOG_INFO("Please wait."); } else { - * Utils.LOG_INFO("Loaded PlayerCache.dat"); - * properties.setProperty(playerName+"_", playerUUIDasString); - * FileOutputStream fr=new FileOutputStream(cache); properties.store(fr, - * "Player Cache."); fr.close(); } - * - * } - */ - - try { - final FileOutputStream fos = new FileOutputStream("PlayerCache.dat"); - final ObjectOutputStream oos = new ObjectOutputStream(fos); - oos.writeObject(playerInfo); - oos.close(); - fos.close(); - Utils.LOG_INFO("Serialized Player data saved in PlayerCache.dat"); - } - - catch (final IOException e) { - Utils.LOG_INFO("No PlayerCache file found, creating one."); - PlayerCache.createPropertiesFile(playerName, playerUUIDasString); - } - } - - public static void createPropertiesFile(final String playerName, final String playerUUIDasString) { - try { - final Properties props = new Properties(); - props.setProperty(playerName + " ", playerUUIDasString); - final OutputStream out = new FileOutputStream(PlayerCache.cache); - props.store(out, "Player Cache."); - Utils.LOG_INFO("PlayerCache.dat created for future use."); - } - catch (final Exception e) { - e.printStackTrace(); - } - } - public static final void initCache() { - if (CORE.PlayerCache == null || CORE.PlayerCache.equals(null)) { + if (CORE.PlayerCache == null || CORE.PlayerCache.equals(null)){ try { - if (PlayerCache.cache != null) { + if (cache != null){ CORE.PlayerCache = PlayerCache.readPropertiesFileAsMap(); - Utils.LOG_INFO("Loaded PlayerCache.dat"); + Utils.LOG_INFO("Loaded PlayerCache.dat"); } - } - catch (final Exception e) { + + } catch (Exception e) { Utils.LOG_INFO("Failed to initialise PlayerCache.dat"); PlayerCache.createPropertiesFile("PLAYER_", "DATA"); - // e.printStackTrace(); + //e.printStackTrace(); } } } - public static String lookupPlayerByUUID(final UUID UUID) { - + public static void createPropertiesFile(String playerName, String playerUUIDasString) { try { - final World worldw = Minecraft.getMinecraft().thePlayer.worldObj; - // if (!worldw.isRemote){ - - try { - Map<String, UUID> map = null; - try { - map = PlayerCache.readPropertiesFileAsMap(); - } - catch (final Exception e) { - Utils.LOG_INFO("With " + e.getCause() + " as cause, Caught Exception: " + e.toString()); - // e.printStackTrace(); - } - for (final Entry<String, UUID> entry : map.entrySet()) { - if (Objects.equals(UUID, entry.getValue())) { - return entry.getKey(); - } - } - return null; - } - catch (final NullPointerException e) { - Utils.LOG_INFO("With " + e.getCause() + " as cause, Caught Exception: " + e.toString()); - // e.printStackTrace(); - } - - // } - + Properties props = new Properties(); + props.setProperty(playerName+" ", playerUUIDasString); + OutputStream out = new FileOutputStream(cache); + props.store(out, "Player Cache."); + Utils.LOG_INFO("PlayerCache.dat created for future use."); } - catch (final Throwable r) { - Utils.LOG_INFO("With " + r.getCause() + " as cause, Caught Exception: " + r.toString()); + catch (Exception e ) { + e.printStackTrace(); } - return null; } - public static HashMap<String, UUID> readPropertiesFileAsMap() { - HashMap<String, UUID> map = null; - try { - final FileInputStream fis = new FileInputStream(PlayerCache.cache); - final ObjectInputStream ois = new ObjectInputStream(fis); - map = (HashMap<String, UUID>) ois.readObject(); - ois.close(); - fis.close(); - } - catch (final IOException ioe) { - ioe.printStackTrace(); - return null; - } - catch (final ClassNotFoundException c) { - Utils.LOG_INFO("Class not found"); - c.printStackTrace(); - return null; - } - Utils.LOG_WARNING("Deserialized PlayerCache.."); - return map; + public static void appendParamChanges(String playerName, String playerUUIDasString) { + HashMap<String, UUID> playerInfo = new HashMap<String, UUID>(); + playerInfo.put(playerName, UUID.fromString(playerUUIDasString)); + + /*try { + Utils.LOG_INFO("Attempting to load "+cache.getName()); + properties.load(new FileInputStream(cache)); + if (properties == null || properties.equals(null)){ + Utils.LOG_INFO("Please wait."); + } + else { + Utils.LOG_INFO("Loaded PlayerCache.dat"); + properties.setProperty(playerName+"_", playerUUIDasString); + FileOutputStream fr=new FileOutputStream(cache); + properties.store(fr, "Player Cache."); + fr.close(); + } + + } */ + + try + { + FileOutputStream fos = new FileOutputStream("PlayerCache.dat"); + ObjectOutputStream oos = new ObjectOutputStream(fos); + oos.writeObject(playerInfo); + oos.close(); + fos.close(); + Utils.LOG_INFO("Serialized Player data saved in PlayerCache.dat"); + } + + catch (IOException e) { + Utils.LOG_INFO("No PlayerCache file found, creating one."); + createPropertiesFile(playerName, playerUUIDasString); + } } /** - * Reads a "properties" file, and returns it as a Map (a collection of - * key/value pairs). - * - * Credit due to Alvin Alexander - - * http://alvinalexander.com/java/java-properties-file-map-example?nocache=1 - * #comment-8215 Changed slightly as the filename and delimiter are constant - * in my case. - * - * @param filename - * The properties filename to read. - * @param delimiter - * The string (or character) that separates the key from the - * value in the properties file. + * Reads a "properties" file, and returns it as a Map + * (a collection of key/value pairs). + * + * Credit due to Alvin Alexander - http://alvinalexander.com/java/java-properties-file-map-example?nocache=1#comment-8215 + * Changed slightly as the filename and delimiter are constant in my case. + * + * @param filename The properties filename to read. + * @param delimiter The string (or character) that separates the key + * from the value in the properties file. * @return The Map that contains the key/value pairs. * @throws Exception */ @Deprecated public static Map<String, String> readPropertiesFileAsMapOld() throws Exception { - final String delimiter = "="; - @SuppressWarnings({ - "rawtypes", "unchecked" - }) - final Map<String, String> map = new HashMap<String, String>(); - final BufferedReader reader = new BufferedReader(new FileReader(PlayerCache.cache)); + String delimiter = "="; + @SuppressWarnings({ "rawtypes", "unchecked" }) + Map<String, String> map = new HashMap<String, String>(); + BufferedReader reader = new BufferedReader(new FileReader(cache)); String line; - while ((line = reader.readLine()) != null) { - if (line.trim().length() == 0) { - continue; - } - if (line.charAt(0) == '#') { - continue; - } - // assumption here is that proper lines are like "String : <a - // href="http://xxx.yyy.zzz/foo/bar"" - // title="http://xxx.yyy.zzz/foo/bar"">http://xxx.yyy.zzz/foo/bar"</a>, + while ((line = reader.readLine()) != null) + { + if (line.trim().length()==0) continue; + if (line.charAt(0)=='#') continue; + // assumption here is that proper lines are like "String : <a href="http://xxx.yyy.zzz/foo/bar"" title="http://xxx.yyy.zzz/foo/bar"">http://xxx.yyy.zzz/foo/bar"</a>, // and the ":" is the delimiter - final int delimPosition = line.indexOf(delimiter); - final String key = line.substring(0, delimPosition - 1).trim(); - final String value = line.substring(delimPosition + 1).trim(); + int delimPosition = line.indexOf(delimiter); + String key = line.substring(0, delimPosition-1).trim(); + String value = line.substring(delimPosition+1).trim(); map.put(key, value); } reader.close(); CORE.PlayerCache = map; return map; } + + public static HashMap<String, UUID> readPropertiesFileAsMap() { + HashMap<String, UUID> map = null; + try + { + FileInputStream fis = new FileInputStream(cache); + ObjectInputStream ois = new ObjectInputStream(fis); + map = (HashMap<String, UUID>) ois.readObject(); + ois.close(); + fis.close(); + }catch(IOException ioe) + { + ioe.printStackTrace(); + return null; + }catch(ClassNotFoundException c) + { + Utils.LOG_INFO("Class not found"); + c.printStackTrace(); + return null; + } + Utils.LOG_WARNING("Deserialized PlayerCache.."); + return map; + } + + public static String lookupPlayerByUUID(UUID UUID){ + + try { + World worldw = Minecraft.getMinecraft().thePlayer.worldObj; + //if (!worldw.isRemote){ + + + try { + Map<String, UUID> map = null; + try { + map = readPropertiesFileAsMap(); + } catch (Exception e) { + Utils.LOG_INFO("With "+e.getCause()+" as cause, Caught Exception: "+e.toString()); + //e.printStackTrace(); + } + for (Entry<String, UUID> entry : map.entrySet()) { + if (Objects.equals(UUID, entry.getValue())) { + return entry.getKey(); + } + } + return null; + } catch (NullPointerException e) { + Utils.LOG_INFO("With "+e.getCause()+" as cause, Caught Exception: "+e.toString()); + //e.printStackTrace(); + } + + + //} + + + } catch (Throwable r){ + Utils.LOG_INFO("With "+r.getCause()+" as cause, Caught Exception: "+r.toString()); + } + return null; + } } diff --git a/src/Java/gtPlusPlus/core/util/player/PlayerUtils.java b/src/Java/gtPlusPlus/core/util/player/PlayerUtils.java index 7d6e2f42e7..e1d5a4b311 100644 --- a/src/Java/gtPlusPlus/core/util/player/PlayerUtils.java +++ b/src/Java/gtPlusPlus/core/util/player/PlayerUtils.java @@ -1,9 +1,10 @@ package gtPlusPlus.core.util.player; -import java.util.*; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.UUID; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.client.Minecraft; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; @@ -11,132 +12,118 @@ import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.server.MinecraftServer; import net.minecraft.world.World; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; public class PlayerUtils { - @SideOnly(Side.CLIENT) - public static Item getItemInPlayersHand() { - final Minecraft mc = Minecraft.getMinecraft(); - Item heldItem = null; - - try { - heldItem = mc.thePlayer.getHeldItem().getItem(); - } - catch (final NullPointerException e) { - return null; - } + public static void messagePlayer(EntityPlayer P, String S){ + gregtech.api.util.GT_Utility.sendChatToPlayer(P, S); + } - if (heldItem != null) { - return heldItem; + public static EntityPlayer getPlayer(String name){ + List<EntityPlayer> i = new ArrayList<EntityPlayer>(); + Iterator<EntityPlayer> crunchifyIterator = MinecraftServer.getServer().getConfigurationManager().playerEntityList.iterator(); + while (crunchifyIterator.hasNext()) { + i.add((crunchifyIterator.next())); + } + try{ + for (EntityPlayer temp : i) { + if (temp.getDisplayName().toLowerCase().equals(name.toLowerCase())){ + return temp; + } + } } - + catch(NullPointerException e){} return null; } - - @SideOnly(Side.CLIENT) - public static ItemStack getItemStackInPlayersHand() { - final Minecraft mc = Minecraft.getMinecraft(); - ItemStack heldItem = null; - try { - heldItem = mc.thePlayer.getHeldItem(); - } - catch (final NullPointerException e) { + + public static EntityPlayer getPlayerOnServerFromUUID(UUID parUUID){ + if (parUUID == null) + { return null; } - if (heldItem != null) { - return heldItem; + List<EntityPlayerMP> allPlayers = MinecraftServer.getServer().getConfigurationManager().playerEntityList; + for (EntityPlayerMP player : allPlayers) + { + if (player.getUniqueID().equals(parUUID)) + { + return player; + } } return null; } - @SideOnly(Side.SERVER) - public static ItemStack getItemStackInPlayersHand(final EntityPlayer player) { - ItemStack heldItem = null; - try { - heldItem = player.getHeldItem(); - } - catch (final NullPointerException e) { + //Not Clientside + public static EntityPlayer getPlayerInWorld(World world, String Name){ + List<EntityPlayer> i = world.playerEntities; + Minecraft mc = Minecraft.getMinecraft(); + try{ + for (EntityPlayer temp : i) { + if (temp.getDisplayName().toLowerCase().equals(Name.toLowerCase())){ + return temp; + } + } + } + catch(NullPointerException e){} return null; } - if (heldItem != null) { - return heldItem; + + public static boolean isPlayerOP(EntityPlayer player){ + if (player.canCommandSenderUseCommand(2, "")){ + return true; } - return null; + return false; } - // Not Clientside - public static ItemStack getItemStackInPlayersHand(final World world, final String Name) { - final EntityPlayer thePlayer = PlayerUtils.getPlayer(Name); + //Not Clientside + public static ItemStack getItemStackInPlayersHand(World world, String Name){ + EntityPlayer thePlayer = getPlayer(Name); ItemStack heldItem = null; - try { - heldItem = thePlayer.getHeldItem(); - } - catch (final NullPointerException e) { - return null; - } - if (heldItem != null) { + try{heldItem = thePlayer.getHeldItem(); + }catch(NullPointerException e){return null;} + if (heldItem != null){ return heldItem; } return null; } - public static EntityPlayer getPlayer(final String name) { - final List<EntityPlayer> i = new ArrayList<EntityPlayer>(); - final Iterator<EntityPlayer> crunchifyIterator = MinecraftServer.getServer() - .getConfigurationManager().playerEntityList.iterator(); - while (crunchifyIterator.hasNext()) { - i.add(crunchifyIterator.next()); - } - try { - for (final EntityPlayer temp : i) { - if (temp.getDisplayName().toLowerCase().equals(name.toLowerCase())) { - return temp; - } - } - } - catch (final NullPointerException e) { + @SideOnly(Side.CLIENT) + public static ItemStack getItemStackInPlayersHand(){ + Minecraft mc = Minecraft.getMinecraft(); + ItemStack heldItem = null; + try{heldItem = mc.thePlayer.getHeldItem(); + }catch(NullPointerException e){return null;} + if (heldItem != null){ + return heldItem; } return null; } - - // Not Clientside - public static EntityPlayer getPlayerInWorld(final World world, final String Name) { - final List<EntityPlayer> i = world.playerEntities; - final Minecraft mc = Minecraft.getMinecraft(); - try { - for (final EntityPlayer temp : i) { - if (temp.getDisplayName().toLowerCase().equals(Name.toLowerCase())) { - return temp; - } - } - } - catch (final NullPointerException e) { + + @SideOnly(Side.SERVER) + public static ItemStack getItemStackInPlayersHand(EntityPlayer player){ + ItemStack heldItem = null; + try{heldItem = player.getHeldItem(); + }catch(NullPointerException e){return null;} + if (heldItem != null){ + return heldItem; } return null; } - public static EntityPlayer getPlayerOnServerFromUUID(final UUID parUUID) { - if (parUUID == null) { - return null; - } - final List<EntityPlayerMP> allPlayers = MinecraftServer.getServer().getConfigurationManager().playerEntityList; - for (final EntityPlayerMP player : allPlayers) { - if (player.getUniqueID().equals(parUUID)) { - return player; - } + @SideOnly(Side.CLIENT) + 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 boolean isPlayerOP(final EntityPlayer player) { - if (player.canCommandSenderUseCommand(2, "")) { - return true; - } - return false; - } - - public static void messagePlayer(final EntityPlayer P, final String S) { - gregtech.api.util.GT_Utility.sendChatToPlayer(P, S); - } - } diff --git a/src/Java/gtPlusPlus/core/util/player/UtilsMining.java b/src/Java/gtPlusPlus/core/util/player/UtilsMining.java index e92a5ac41a..1b6b957b32 100644 --- a/src/Java/gtPlusPlus/core/util/player/UtilsMining.java +++ b/src/Java/gtPlusPlus/core/util/player/UtilsMining.java @@ -8,133 +8,139 @@ import net.minecraft.item.ItemStack; import net.minecraft.world.World; public class UtilsMining { + + private static boolean durabilityDamage = false; + private static ItemStack stack; - private static boolean durabilityDamage = false; - private static ItemStack stack; - - public static Boolean canPickaxeBlock(final Block currentBlock, final World currentWorld) { + public static Boolean canPickaxeBlock(Block currentBlock, World currentWorld){ String correctTool = ""; - if (!currentWorld.isRemote) { + if (!currentWorld.isRemote){ try { correctTool = currentBlock.getHarvestTool(0); - // Utils.LOG_WARNING(correctTool); - if (correctTool.equals("pickaxe")) { - return true; + //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 (final NullPointerException e) { - return false; - } + } catch (NullPointerException e){ + } - return false; } - public static void customMine(final World world, final String FACING, final EntityPlayer aPlayer) { + public static void customMine(World world, String FACING, EntityPlayer aPlayer){ float DURABILITY_LOSS = 0; - if (!world.isRemote) { + if (!world.isRemote){ int X = 0; int Y = 0; int Z = 0; - if (FACING.equals("below") || FACING.equals("above")) { + if (FACING.equals("below") || FACING.equals("above")){ - // Set Player Facing + //Set Player Facing X = (int) aPlayer.posX; - Utils.LOG_WARNING("Setting Variable X: " + X); - if (FACING.equals("above")) { + 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); - } + 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); + 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); - */ UtilsMining.removeBlockAndDropAsItem(world, X + i, Y + k, Z + j); + 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")) { + else if (FACING.equals("facingEast") || FACING.equals("facingWest")){ - // Set Player Facing + //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; - } + 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); - */ - UtilsMining.removeBlockAndDropAsItem(world, X + k, Y + i, Z + j); + 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")) { + else if (FACING.equals("facingNorth") || FACING.equals("facingSouth")){ - // Set Player Facing + //Set Player Facing X = (int) aPlayer.posX; Y = (int) aPlayer.posY; - - if (FACING.equals("facingNorth")) { - Z = (int) aPlayer.posZ + 1; - } + + if (FACING.equals("facingNorth")){ + Z = (int) aPlayer.posZ + 1;} else { - Z = (int) aPlayer.posZ - 1; - } - + 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); - */ - UtilsMining.removeBlockAndDropAsItem(world, X + j, Y + i, Z + k); + 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 (UtilsMining.durabilityDamage == true) { - Utils.LOG_WARNING("Total Loss: " + (int) DURABILITY_LOSS); - if (UtilsMining.stack.getItemDamage() < UtilsMining.stack.getMaxDamage() - DURABILITY_LOSS) { - UtilsMining.stack.damageItem((int) DURABILITY_LOSS, aPlayer); - } + //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(final Block block) { + + + public static boolean getBlockType(Block block){ final String LIQUID = "liquid"; final String BLOCK = "block"; final String ORE = "ore"; @@ -144,51 +150,31 @@ public class UtilsMining { try { blockClass = block.getClass().toString().toLowerCase(); Utils.LOG_WARNING(blockClass); - if (blockClass.toLowerCase().contains(LIQUID)) { - Utils.LOG_WARNING(block.toString() + " is a Liquid."); + 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."); + 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."); + 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."); + 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."); + Utils.LOG_WARNING(block.toString()+" is mystery."); return false; } } - catch (final NullPointerException e) { + catch(NullPointerException e){ return false; } } - - private static void removeBlockAndDropAsItem(final World world, final int X, final int Y, final int Z) { - try { - final Block block = world.getBlock(X, Y, Z); - if (UtilsMining.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 (final NullPointerException e) { - - } - } - + + } |
