Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package xyz.bhopped.trend.utilities.minecraft;
- import net.minecraft.client.*;
- import net.minecraft.world.*;
- import java.math.*;
- import net.minecraft.network.play.client.*;
- import net.minecraft.network.*;
- import net.minecraft.block.*;
- import net.minecraft.util.*;
- public class MovementUtils
- {
- public Minecraft mc;
- public MovementUtils() {
- this.mc = Minecraft.getMinecraft();
- }
- public void teleport(final double x, final double y, final double z) {
- double playerX = Minecraft.thePlayer.posX;
- double playerY = Minecraft.thePlayer.posY;
- double playerZ = Minecraft.thePlayer.posZ;
- double xDistance = x - playerX;
- double yDistance = y - playerY;
- double zDistance = z - playerZ;
- double distance = Math.sqrt(xDistance * xDistance + yDistance * yDistance + zDistance * zDistance);
- if (distance < 5.0) {
- this.setPosition(x, y, z);
- return;
- }
- distance /= 8.0;
- xDistance /= distance;
- yDistance /= distance;
- zDistance /= distance;
- for (int i = 0; i < distance; ++i) {
- playerX += xDistance;
- playerY += yDistance;
- playerZ += zDistance;
- this.setPosition(playerX, playerY, playerZ);
- try {
- Thread.sleep(10L);
- }
- catch (Exception ex) {}
- }
- this.setPosition(x, y, z);
- }
- public boolean isInsideBlock() {
- for (int x = MathHelper.floor_double(Minecraft.thePlayer.getEntityBoundingBox().minX); x < MathHelper.floor_double(Minecraft.thePlayer.getEntityBoundingBox().maxX) + 1; ++x) {
- for (int y = MathHelper.floor_double(Minecraft.thePlayer.getEntityBoundingBox().minY); y < MathHelper.floor_double(Minecraft.thePlayer.getEntityBoundingBox().maxY) + 1; ++y) {
- for (int z = MathHelper.floor_double(Minecraft.thePlayer.getEntityBoundingBox().minZ); z < MathHelper.floor_double(Minecraft.thePlayer.getEntityBoundingBox().maxZ) + 1; ++z) {
- final Block block = Minecraft.theWorld.getBlockState(new BlockPos(x, y, z)).getBlock();
- if (block != null && !(block instanceof BlockAir)) {
- AxisAlignedBB boundingBox = block.getCollisionBoundingBox(Minecraft.theWorld, new BlockPos(x, y, z), Minecraft.theWorld.getBlockState(new BlockPos(x, y, z)));
- if (block instanceof BlockHopper) {
- boundingBox = new AxisAlignedBB(x, y, z, x + 1, y + 1, z + 1);
- }
- if (boundingBox != null && Minecraft.thePlayer.getEntityBoundingBox().intersectsWith(boundingBox)) {
- return true;
- }
- }
- }
- }
- }
- return false;
- }
- public void blinkToPos(final double[] startPos, final BlockPos endPos, final double slack) {
- double curX = startPos[0];
- double curY = startPos[1];
- double curZ = startPos[2];
- final double endX = endPos.getX() + 0.5;
- final double endY = endPos.getY() + 1.0;
- final double endZ = endPos.getZ() + 0.5;
- double distance = Math.abs(curX - endX) + Math.abs(curY - endY) + Math.abs(curZ - endZ);
- int count = 0;
- while (distance > slack) {
- distance = Math.abs(curX - endX) + Math.abs(curY - endY) + Math.abs(curZ - endZ);
- if (count > 120) {
- break;
- }
- final boolean next = false;
- final double diffX = curX - endX;
- final double diffY = curY - endY;
- final double diffZ = curZ - endZ;
- final double offset = ((count & 0x1) == 0x0) ? 0.4 : 0.1;
- if (diffX < 0.0) {
- if (Math.abs(diffX) > offset) {
- curX += offset;
- }
- else {
- curX += Math.abs(diffX);
- }
- }
- if (diffX > 0.0) {
- if (Math.abs(diffX) > offset) {
- curX -= offset;
- }
- else {
- curX -= Math.abs(diffX);
- }
- }
- if (diffY < 0.0) {
- if (Math.abs(diffY) > 0.25) {
- curY += 0.25;
- }
- else {
- curY += Math.abs(diffY);
- }
- }
- if (diffY > 0.0) {
- if (Math.abs(diffY) > 0.25) {
- curY -= 0.25;
- }
- else {
- curY -= Math.abs(diffY);
- }
- }
- if (diffZ < 0.0) {
- if (Math.abs(diffZ) > offset) {
- curZ += offset;
- }
- else {
- curZ += Math.abs(diffZ);
- }
- }
- if (diffZ > 0.0) {
- if (Math.abs(diffZ) > offset) {
- curZ -= offset;
- }
- else {
- curZ -= Math.abs(diffZ);
- }
- }
- Minecraft.thePlayer.setPosition(curX, curY, curZ);
- ++count;
- }
- }
- public static double round(final double value, final int places) {
- if (places < 0) {
- throw new IllegalArgumentException();
- }
- BigDecimal bd = new BigDecimal(value);
- bd = bd.setScale(places, RoundingMode.HALF_UP);
- return bd.doubleValue();
- }
- private void setPosition(final double x, final double y, final double z) {
- Minecraft.thePlayer.setPosition(x, y, z);
- this.mc.getNetHandler().addToSendQueue(new C03PacketPlayer.C04PacketPlayerPosition(x, y, z, true));
- }
- public boolean shouldSprint() {
- final boolean hasFood = Minecraft.thePlayer.getFoodStats().getFoodLevel() > 6;
- final boolean isNotCollided = !Minecraft.thePlayer.isCollidedHorizontally;
- final boolean isMoving = Minecraft.thePlayer.motionX != 0.0 || Minecraft.thePlayer.motionZ != 0.0;
- final boolean isSneaking = !Minecraft.thePlayer.isSneaking();
- return hasFood && isSneaking && isNotCollided && isMoving;
- }
- public boolean shouldStep() {
- final boolean isCollided = Minecraft.thePlayer.isCollidedHorizontally;
- final boolean onGround = Minecraft.thePlayer.onGround;
- final boolean onLadder = !Minecraft.thePlayer.isOnLadder();
- final boolean isInWater = !Minecraft.thePlayer.isInWater();
- return isCollided && onLadder && isInWater && onGround;
- }
- public boolean isInLiquid() {
- Minecraft.getMinecraft();
- int x = MathHelper.floor_double(Minecraft.thePlayer.boundingBox.minX);
- Label_0129: {
- break Label_0129;
- int i;
- do {
- Minecraft.getMinecraft();
- int z = MathHelper.floor_double(Minecraft.thePlayer.boundingBox.minZ);
- Label_0104: {
- break Label_0104;
- int j;
- do {
- final int x2 = x;
- Minecraft.getMinecraft();
- final BlockPos pos = new BlockPos(x2, (int)Minecraft.thePlayer.boundingBox.minY, z);
- Minecraft.getMinecraft();
- final Block block = Minecraft.theWorld.getBlockState(pos).getBlock();
- if (block != null && !(block instanceof BlockAir)) {
- return block instanceof BlockLiquid;
- }
- ++z;
- j = z;
- Minecraft.getMinecraft();
- } while (j < MathHelper.floor_double(Minecraft.thePlayer.boundingBox.maxZ) + 1);
- }
- ++x;
- i = x;
- Minecraft.getMinecraft();
- } while (i < MathHelper.floor_double(Minecraft.thePlayer.boundingBox.maxX) + 1);
- }
- return false;
- }
- public boolean isOnAir() {
- Minecraft.getMinecraft();
- int x = MathHelper.floor_double(Minecraft.thePlayer.boundingBox.minX);
- Label_0109: {
- break Label_0109;
- int i;
- do {
- Minecraft.getMinecraft();
- final int floor_double;
- final int z = floor_double = MathHelper.floor_double(Minecraft.thePlayer.boundingBox.minZ);
- Minecraft.getMinecraft();
- if (floor_double < MathHelper.floor_double(Minecraft.thePlayer.boundingBox.maxZ) + 1) {
- final int x2 = x;
- Minecraft.getMinecraft();
- final BlockPos pos = new BlockPos(x2, (int)Minecraft.thePlayer.posY - 1, z);
- Minecraft.getMinecraft();
- final Block block = Minecraft.theWorld.getBlockState(pos).getBlock();
- return block instanceof BlockAir;
- }
- ++x;
- i = x;
- Minecraft.getMinecraft();
- } while (i < MathHelper.floor_double(Minecraft.thePlayer.boundingBox.maxX) + 1);
- }
- return false;
- }
- public int blocksUnderPlayer(final double posX, final double posY, final double posZ) {
- int height = 0;
- Minecraft.getMinecraft();
- int x = MathHelper.floor_double(Minecraft.thePlayer.boundingBox.minX);
- Label_0131: {
- break Label_0131;
- int i;
- do {
- Minecraft.getMinecraft();
- int z = MathHelper.floor_double(Minecraft.thePlayer.boundingBox.minZ);
- Label_0105: {
- break Label_0105;
- int j;
- do {
- final int x2 = x;
- Minecraft.getMinecraft();
- final BlockPos pos = new BlockPos(x2, (int)Minecraft.thePlayer.posY - height, z);
- Minecraft.getMinecraft();
- final Block block = Minecraft.theWorld.getBlockState(pos).getBlock();
- if (block instanceof BlockAir) {
- ++height;
- }
- ++z;
- j = z;
- Minecraft.getMinecraft();
- } while (j < MathHelper.floor_double(Minecraft.thePlayer.boundingBox.maxZ) + 1);
- }
- ++x;
- i = x;
- Minecraft.getMinecraft();
- } while (i < MathHelper.floor_double(Minecraft.thePlayer.boundingBox.maxX) + 1);
- }
- return height;
- }
- public boolean isOnLiquidOld() {
- Minecraft.getMinecraft();
- int x = MathHelper.floor_double(Minecraft.thePlayer.boundingBox.minX);
- Label_0109: {
- break Label_0109;
- int i;
- do {
- Minecraft.getMinecraft();
- final int floor_double;
- final int z = floor_double = MathHelper.floor_double(Minecraft.thePlayer.boundingBox.minZ);
- Minecraft.getMinecraft();
- if (floor_double < MathHelper.floor_double(Minecraft.thePlayer.boundingBox.maxZ) + 1) {
- final int x2 = x;
- Minecraft.getMinecraft();
- final BlockPos pos = new BlockPos(x2, (int)Minecraft.thePlayer.posY - 1, z);
- Minecraft.getMinecraft();
- final Block block = Minecraft.theWorld.getBlockState(pos).getBlock();
- return block instanceof BlockLiquid;
- }
- ++x;
- i = x;
- Minecraft.getMinecraft();
- } while (i < MathHelper.floor_double(Minecraft.thePlayer.boundingBox.maxX) + 1);
- }
- return false;
- }
- public boolean isOnLiquid() {
- Minecraft.getMinecraft();
- final AxisAlignedBB par1AxisAlignedBB = Minecraft.thePlayer.boundingBox.offset(0.0, -0.01, 0.0).contract(0.001, 0.001, 0.001);
- int var4 = MathHelper.floor_double(par1AxisAlignedBB.minX);
- final int var5 = MathHelper.floor_double(par1AxisAlignedBB.maxX + 1.0);
- final int var6 = MathHelper.floor_double(par1AxisAlignedBB.minY);
- var4 = MathHelper.floor_double(par1AxisAlignedBB.maxY + 1.0);
- final int var7 = MathHelper.floor_double(par1AxisAlignedBB.minZ);
- final int var8 = MathHelper.floor_double(par1AxisAlignedBB.maxZ + 1.0);
- final Vec3 var9 = new Vec3(0.0, 0.0, 0.0);
- for (int var10 = var4; var10 < var5; ++var10) {
- for (int var11 = var6; var11 < var4; ++var11) {
- for (int var12 = var7; var12 < var8; ++var12) {
- Minecraft.getMinecraft();
- final Block var13 = (Block)Minecraft.theWorld.getBlockState(new BlockPos(var10, var11, var12));
- if (!(var13 instanceof BlockAir) && !(var13 instanceof BlockLiquid)) {
- return false;
- }
- }
- }
- }
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement