Guest User

Untitled

a guest
Feb 2nd, 2018
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.81 KB | None | 0 0
  1. @EventTarget
  2. public void onUpdate(EventUpdate event) {
  3. mc.thePlayer.setSprinting(false);
  4. BlockPos pos = new BlockPos(mc.thePlayer).offsetDown();
  5. if(!material(pos).isReplaceable()) return;
  6. int slot = -1;
  7. for(int i = 0; i < 9; i++) {
  8. ItemStack item = mc.thePlayer.inventory.getStackInSlot(i);
  9. if(!empty(item) && item.getItem() instanceof ItemBlock) {
  10. slot = i;
  11. break;
  12. }
  13. }
  14. if(slot == -1)return;
  15. int oldSlot = mc.thePlayer.inventory.currentItem;
  16. mc.thePlayer.inventory.currentItem = slot;
  17. if(mc.gameSettings.keyBindJump.pressed) mc.thePlayer.jump();
  18. place(pos);
  19. mc.thePlayer.inventory.currentItem = oldSlot;
  20. }
  21. public void onEnable(EventUpdate event) {
  22. mc.thePlayer.setSprinting(false);
  23. }
  24. private IBlockState state(BlockPos pos) {
  25. return mc.theWorld.getBlockState(pos);
  26. }
  27. private Block block(BlockPos pos) {
  28. return state(pos).getBlock();
  29. }
  30. private Material material(BlockPos pos) {
  31. return block(pos).getMaterial();
  32. }
  33. private boolean empty(ItemStack item) {
  34. return item == null;
  35. }
  36. private boolean place(BlockPos pos) {
  37. Vec3 eye = new Vec3(mc.thePlayer.posX, mc.thePlayer.posY + mc.thePlayer.getEyeHeight(), mc.thePlayer.posZ);
  38. EnumFacing[] face;
  39. int j = (face = EnumFacing.values()).length;
  40. for(int i = 0; i < j; i++) {
  41. EnumFacing side = face[i];
  42. BlockPos bpos = pos.offset(side);
  43. EnumFacing otherSide = side.getOpposite();
  44. if(eye.squareDistanceTo(new Vec3(pos).addVector(0.5D, 0.5D, 0.5D)) < eye.squareDistanceTo(new Vec3(bpos).addVector(0.5D, 0.5D, 0.5D))) {
  45. if(block(bpos).canCollideCheck(state(bpos), false)) {
  46. Vec3 vec = new Vec3(bpos).addVector(0.5D, 0.5D, 0.5D).add(new Vec3(otherSide.getDirectionVec()).mutli(0.5D));
  47. if(eye.squareDistanceTo(vec) <= 18.0D) {
  48. lock(vec);
  49. mc.playerController.func_178890_a(mc.thePlayer, mc.theWorld, mc.thePlayer.getCurrentEquippedItem(), bpos, otherSide, vec);
  50. mc.thePlayer.swingItem();
  51. return true;
  52. }
  53. }
  54. }
  55. }
  56. return false;
  57. }
  58.  
  59. private void lock(Vec3 v) {
  60. double diffX = v.xCoord - mc.thePlayer.posX;
  61. double diffY = v.yCoord - mc.thePlayer.getEyeHeight();
  62. double diffZ = v.zCoord - mc.thePlayer.posZ;
  63.  
  64. double distance = MathHelper.sqrt_double(diffX * diffX + diffZ * diffZ);
  65.  
  66. float yaw = (float)Math.toDegrees(Math.atan2(diffZ, diffX)) - 90.0F;
  67. float pitch = (float)-Math.toDegrees(Math.atan2(diffY, distance));
  68.  
  69. mc.thePlayer.sendQueue.addToSendQueue(new C03PacketPlayer.C05PacketPlayerLook(mc.thePlayer.rotationYaw + MathHelper.wrapAngleTo180_float(yaw - mc.thePlayer.rotationYaw), mc.thePlayer.rotationPitch + MathHelper.wrapAngleTo180_float(pitch - mc.thePlayer.rotationPitch), mc.thePlayer.onGround));
  70. }
  71. public void onDisable(EventUpdate event) {
  72. mc.thePlayer.setSprinting(true);
  73. super.onDisable();
  74. }
  75.  
  76. }
Advertisement
Add Comment
Please, Sign In to add comment