Created
July 21, 2012 11:25
-
-
Save md-5/3155559 to your computer and use it in GitHub Desktop.
A*
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import net.minecraft.client.Minecraft; | |
public class DiamondDig implements Runnable { | |
public static int oldPlayerX; | |
public static int oldPlayerY; | |
public static int oldPlayerZ; | |
public static int stuckCount = 0; | |
public boolean noY = false; | |
public boolean noZ = false; | |
public static boolean noX = false; | |
public boolean wasEast = false; | |
public boolean wasWest = false; | |
public boolean wasNorth = false; | |
public boolean wasSouth = false; | |
public boolean isNorth = false; | |
public boolean isSouth = false; | |
public boolean isEast = false; | |
public boolean isWest = false; | |
public static boolean isAbove = false; | |
public boolean isBelow = false; | |
public static boolean jiggle = false; | |
public static int PlayerX; | |
public static int PlayerY; | |
public static int PlayerZ; | |
public static boolean isDigging = false; | |
public int diamondX; | |
public int diamondY; | |
public int diamondZ; | |
public int oldInv = 0; | |
public static boolean jump; | |
public Minecraft mc = Minecraft.theMinecraft; | |
public PlayerControllerMP pc = new PlayerControllerMP(mc, mc.getSendQueue()); | |
public void run() { | |
jump = false; | |
resetVals(); | |
isDigging = true; | |
find(); | |
isDigging = false; | |
while (GuiIngame.diamonddig) { | |
try { | |
if (mc.thePlayer.handleLavaMovement()) { | |
mc.thePlayer.sendChatMessage("/home"); | |
GuiIngame.diamonddig = false; | |
} | |
if (ifStuck()) { | |
resetVals(); | |
} | |
oldPlayerX = PlayerX; | |
oldPlayerY = PlayerY; | |
oldPlayerZ = PlayerZ; | |
PlayerX = (int) mc.thePlayer.posX; | |
PlayerY = ((int) Math.rint(mc.thePlayer.posY)); | |
PlayerZ = (int) mc.thePlayer.posZ; | |
Thread.sleep(25); | |
updateVals(diamondX, diamondY, diamondZ); | |
Thread.sleep(25); | |
checkSurround(); | |
Thread.sleep(25); | |
if (mc.theWorld.getBlockId(diamondX, diamondY, diamondZ) != 56) { | |
isDigging = true; | |
resetVals(); | |
find(); | |
isDigging = false; | |
} | |
Thread.sleep(25); | |
} | |
catch (Exception e) { | |
} | |
} | |
} | |
public void find() { //Cuboids around the player looking for diamonds FINISHED | |
int posx = (int)mc.thePlayer.posX; | |
int posy = (int)mc.thePlayer.posY; | |
int posz = (int)mc.thePlayer.posZ; | |
for (int count = 0; count >= 0; count++) | |
{ | |
int item = 0; | |
try { item = 56; } | |
catch(Exception e) { mc.thePlayer.addChatMessage("Please enter a valid integer"); return; } | |
Block check; | |
try { check = Block.blocksList[item]; } | |
catch(Exception e) { mc.thePlayer.addChatMessage("Block id does not exist"); return; } | |
//code below borrowed from mcforge source for cuboids. I just modified it slightly | |
int x = posx + count; int y = posy + count; int z = posz + count; | |
int cposx = posx - count; int cposy = posy - count; int cposz = posz - count; | |
int xx = 0; int yy = 0; int zz = 0; | |
for (xx = Math.min(cposx, x); xx <= Math.max(cposx, x); ++xx) | |
for (yy = Math.min(cposy, y); yy <= Math.max(cposy, y); ++yy) | |
for (zz = Math.min(cposz, z); zz <= Math.max(cposz, z); ++zz) | |
{ | |
if (count <= 125) { | |
if (mc.theWorld.getBlockId(xx, yy, zz) == item) | |
{ | |
if (setDPos(xx, yy, zz)) | |
{ | |
mc.thePlayer.addChatMessage("\247bFound diamonds at X=" + xx + " Y=" + yy + " Z=" + zz); | |
updateVals(xx, yy, zz); | |
return; | |
} | |
} | |
} | |
else | |
{ | |
mc.thePlayer.addChatMessage("\247cNo Diamonds found :("); | |
GuiIngame.diamonddig = false; | |
return; | |
} | |
} | |
} | |
return; | |
} | |
public void point(double posX, int y, double d){ //Points to a set block FINISHED | |
double d2 = 0.0D; | |
double d5 = 0; | |
double d6 = 0; | |
double d7 = 0; | |
try { | |
d5 = (posX - mc.thePlayer.posX) + 0.5D; | |
d6 = (d - mc.thePlayer.posZ) + 0.5D; | |
d7 = (y - (mc.thePlayer.posY - 1.6D)) - 1.1D; | |
} | |
catch (Exception e) { } | |
if(d6 > 0.0D && d5 > 0.0D) | |
{ | |
d2 = Math.toDegrees(-Math.atan(d5 / d6)); | |
} else | |
if(d6 > 0.0D && d5 < 0.0D) | |
{ | |
d2 = Math.toDegrees(-Math.atan(d5 / d6)); | |
} else | |
if(d6 < 0.0D && d5 > 0.0D) | |
{ | |
d2 = -90D + Math.toDegrees(Math.atan(d6 / d5)); | |
} else | |
if(d6 < 0.0D && d5 < 0.0D) | |
{ | |
d2 = 90D + Math.toDegrees(Math.atan(d6 / d5)); | |
} | |
try { | |
mc.thePlayer.rotationYaw = (float)d2; | |
} | |
catch (Exception e) { } | |
double d8 = Math.sqrt(d6 * d6 + d5 * d5); | |
double d9 = -Math.toDegrees(Math.atan(d7 / d8)); | |
try { | |
mc.thePlayer.rotationPitch = (float)d9; | |
} | |
catch (Exception e) { | |
} | |
} | |
public void checkSurround() { | |
try { | |
PlayerX = (int) mc.thePlayer.posX; | |
PlayerY = ((int) Math.rint(mc.thePlayer.posY)); | |
PlayerZ = (int) mc.thePlayer.posZ; | |
int xx = PlayerX; | |
int yy = PlayerY - 1; | |
int zz = PlayerZ; | |
if (wasNorth && wasSouth) { | |
noZ = true; | |
} | |
if (wasEast && wasWest) { | |
noX = true; | |
} | |
if (isNorth && !noZ) { | |
wasNorth = true; | |
if (mc.thePlayer.posZ > 0) { | |
point(xx, yy, zz + 1); | |
dig(xx, yy, zz + 1); | |
dig(xx, yy - 1, zz + 1); | |
} | |
else { | |
point(xx - 1, yy, zz); | |
dig(xx - 1, yy, zz); | |
dig(xx - 1, yy - 1, zz); | |
} | |
return; | |
} | |
if (isSouth && !noZ) { | |
wasSouth = true; | |
if (mc.thePlayer.posZ > 0) { | |
point(xx, yy, zz - 1); | |
dig(xx, yy, zz - 1); | |
dig(xx, yy - 1, zz - 1); | |
} | |
else { | |
point(mc.thePlayer.posX - 0.5001D, yy, mc.thePlayer.posZ - 1); | |
dig((int)Math.round(mc.thePlayer.posX - 0.5001D), yy, (int)Math.round(mc.thePlayer.posZ - 1)); | |
dig((int)Math.round(mc.thePlayer.posX - 0.5001D), yy - 1, (int)Math.round(mc.thePlayer.posZ - 1)); | |
} | |
return; | |
} | |
if (isWest && !noX && wasNorth && wasSouth) { | |
wasWest = true; | |
if (mc.thePlayer.posX > 0) { | |
point(xx + 1, yy, zz); | |
dig(xx + 1, yy, zz); | |
dig(xx + 1, yy - 1, zz); | |
} | |
else { | |
point(xx, yy, zz - 1); | |
dig(xx, yy, zz - 1); | |
dig(xx, yy - 1, zz - 1); | |
} | |
return; | |
} | |
if (isEast && !noX && wasNorth && wasSouth) { | |
wasEast = true; | |
if (mc.thePlayer.posX > 0) { | |
point(xx - 1, yy, zz); | |
dig(xx - 1, yy, zz); | |
dig(xx - 1, yy - 1, zz); | |
} | |
else { | |
point(mc.thePlayer.posX - 1, yy, mc.thePlayer.posZ - 0.5001D); | |
dig((int)Math.round(mc.thePlayer.posX - 1), yy, (int)Math.round(mc.thePlayer.posZ - 0.5001D)); | |
dig((int)Math.round(mc.thePlayer.posX - 1), yy - 1, (int)Math.round(mc.thePlayer.posZ - 0.5001D)); | |
} | |
return; | |
} | |
isDigging = true; | |
if (isBelow && diamondY < yy) { | |
dig(xx, yy - 2, zz); | |
} | |
else { | |
if (!isAbove && diamondY == yy) { | |
resetVals(); | |
} | |
} | |
if (isAbove && diamondY > yy) { | |
if (!blockAir(xx, yy + 1, zz)) | |
{ | |
removeBlock(xx, yy + 1, zz); | |
} | |
else { | |
point(xx, yy - 2, zz); | |
jump = true; | |
Thread.sleep(100); | |
jump = false; | |
while (blockAir(xx, yy - 2, zz)) { | |
isDigging = true; | |
int inventoryNum = -1; | |
for (int i = 0; i < 9; i++ ) { | |
float resistance = 0.0f; | |
ItemStack itemstack = mc.thePlayer.inventory.getStackInSlot(i); //FIX ME | |
try { | |
Block block = Block.blocksList[itemstack.itemID]; | |
if (block.isCollidable()) { | |
resistance = block.blockResistance; | |
inventoryNum = i; | |
break; | |
} | |
} | |
catch (Exception e){ | |
} | |
} | |
if (inventoryNum == -1) { | |
GuiIngame.diamonddig = false; | |
mc.thePlayer.addChatMessage("No solid blocks found in your hotbar so diamond dig was turned off"); | |
return; | |
} | |
SyncItem(inventoryNum); | |
while (mc.theWorld.getBlockId(xx, yy - 2, zz) != 0) { | |
Thread.sleep(20); | |
} | |
int j = mc.objectMouseOver.blockX; | |
int k = mc.objectMouseOver.blockY; | |
int l = mc.objectMouseOver.blockZ; | |
int i1 = mc.objectMouseOver.sideHit; | |
ItemStack itemstack = mc.thePlayer.inventory.getCurrentItem(); | |
mc.playerController.onPlayerRightClick(mc.thePlayer, mc.theWorld, itemstack, j, k, l, i1); | |
mc.thePlayer.swingItem(); | |
isDigging = false; | |
} | |
} | |
} | |
else { | |
if (!isBelow && diamondY == yy) { | |
resetVals(); | |
} | |
} | |
} catch (Exception e) { mc.thePlayer.addChatMessage(e.toString()); } | |
} | |
public void dig(int x, int y, int z){ //Digs at a given block | |
try { | |
if (!EntityClientPlayerMP.instant) | |
{ | |
EntityClientPlayerMP.instant = true; | |
} | |
if (!blockAir(x, y, z)) | |
{ | |
removeBlock(x, y, z); | |
} | |
} | |
catch (Exception e) { | |
mc.thePlayer.addChatMessage(e.toString()); | |
} | |
} | |
public void removeBlock(int x, int y, int z) { | |
isDigging = true; | |
while (!blockAir(x, y, z) && GuiIngame.diamonddig && mc.thePlayer.getDistance(x, y, z) < 4.5) | |
{ | |
try { | |
point(x, y, z); | |
PlayerControllerMP pcm = new PlayerControllerMP(mc, mc.getSendQueue()); | |
int j = x; | |
int k = y; | |
int l = z; | |
int i1 = 2; | |
try { | |
i1 = mc.objectMouseOver.sideHit; | |
} | |
catch (Exception e) { } | |
pcm.AutoTool(j, k, l); | |
pcm.clickBlock(j, k, l, i1); | |
mc.thePlayer.swingItem(); | |
pcm.onPlayerDamageBlock(j, k, l, i1); | |
mc.thePlayer.swingItem(); | |
Thread.sleep(100); | |
} | |
catch (Exception e) { | |
mc.thePlayer.addChatMessage(e.toString()); | |
} | |
} | |
isDigging = false; | |
} | |
public boolean blockAir(int x, int y, int z){ //Checks if blocks is air FINISHED | |
try { | |
int l2 = mc.theWorld.getBlockId(x, y, z); | |
Block block = Block.blocksList[l2]; | |
if(block == null) | |
{ | |
return true; | |
} | |
else | |
{ | |
if (mc.theWorld.getBlockId(x, y, z) == 8) | |
{ | |
return true; | |
} | |
else if (mc.theWorld.getBlockId(x, y, z) == 9) | |
{ | |
return true; | |
} | |
else if (mc.theWorld.getBlockId(x, y, z) == 10) | |
{ | |
} | |
else if (mc.theWorld.getBlockId(x, y, z) == 11) | |
{ | |
return true; | |
} | |
else if (mc.theWorld.getBlockId(x, y, z) == 7) | |
{ | |
return true; | |
} | |
return false; | |
} | |
} | |
catch (Exception e) { return true; } | |
} | |
public boolean setDPos(int x, int y, int z) { //Checks if diamond position is suitable | |
if (y >= 7) { | |
for (int i = -1; i < 2; i++) { | |
if (mc.theWorld.getBlockId(x, y + i, z) == 11) { | |
return false; | |
} | |
if (mc.theWorld.getBlockId(x + 1, y + i, z) == 11) { | |
return false; | |
} | |
if (mc.theWorld.getBlockId(x + 1, y + i, z + 1) == 11) { | |
return false; | |
} | |
if (mc.theWorld.getBlockId(x - 1, y + i, z) == 11) { | |
return false; | |
} | |
if (mc.theWorld.getBlockId(x - 1, y + i, z - 1) == 11) { | |
return false; | |
} | |
if (mc.theWorld.getBlockId(x, y + i, z - 1) == 11) { | |
return false; | |
} | |
if (mc.theWorld.getBlockId(x, y + i, z + 1) == 11) { | |
return false; | |
} | |
if (mc.theWorld.getBlockId(x - 1, y + i, z + 1) == 11) { | |
return false; | |
} | |
if (mc.theWorld.getBlockId(x + 1, y + i, z - 1) == 11) { | |
return false; | |
} | |
} | |
diamondX = x; | |
diamondY = y; | |
diamondZ = z; | |
return true; | |
} | |
else { | |
return false; | |
} | |
} | |
public void SyncItem(int x) { | |
int i = x; | |
if(i != mc.thePlayer.inventory.currentItem) | |
{ | |
mc.thePlayer.inventory.currentItem = i; | |
mc.getSendQueue().addToSendQueue(new Packet16BlockItemSwitch(mc.thePlayer.inventory.currentItem)); | |
} | |
} | |
public void updateVals(int x, int y, int z) { | |
if (z > mc.thePlayer.posZ) { | |
isNorth = true; | |
} | |
else { | |
isNorth = false; | |
} | |
if (z < mc.thePlayer.posZ) { | |
isSouth = true; | |
} | |
else { | |
isSouth = false; | |
} | |
if (x > mc.thePlayer.posX) { | |
isWest = true; | |
} | |
else { | |
isWest = false; | |
} | |
if (x < mc.thePlayer.posX) { | |
isEast = true; | |
} | |
else { | |
isEast = false; | |
} | |
if (y > mc.thePlayer.posY) { | |
isAbove = true; | |
} | |
else { | |
isAbove = false; | |
} | |
if (y < mc.thePlayer.posY) { | |
isBelow = true; | |
} | |
else { | |
isBelow = false; | |
} | |
} | |
public void resetVals() { | |
stuckCount = 0; | |
isDigging = false; | |
noZ = false; | |
noX = false; | |
noY = false; | |
wasNorth = false; | |
wasSouth = false; | |
wasWest = false; | |
wasEast = false; | |
} | |
private float updateRotation(float f, float f1, float f2) | |
{ | |
float f3; | |
for (f3 = f1 - f; f3 < -180F; f3 += 360F) { } | |
for (; f3 >= 180F; f3 -= 360F) { } | |
if (f3 > f2) | |
{ | |
f3 = f2; | |
} | |
if (f3 < -f2) | |
{ | |
f3 = -f2; | |
} | |
return f + f3; | |
} | |
public boolean ifStuck(){ | |
if (oldPlayerZ == PlayerZ && oldPlayerX == PlayerX && oldPlayerY == PlayerY) { | |
stuckCount += 1; | |
} | |
else { | |
stuckCount = 0; | |
} | |
if (stuckCount >= 50) { | |
mc.thePlayer.addChatMessage("\247cYou got stuck. Trying to reset values"); | |
return true; | |
} | |
else { | |
return false; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment