Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @EventTarget
- public void onUpdate(EventUpdate event) {
- mc.thePlayer.setSprinting(false);
- BlockPos pos = new BlockPos(mc.thePlayer).offsetDown();
- if(!material(pos).isReplaceable()) return;
- int slot = -1;
- for(int i = 0; i < 9; i++) {
- ItemStack item = mc.thePlayer.inventory.getStackInSlot(i);
- if(!empty(item) && item.getItem() instanceof ItemBlock) {
- slot = i;
- break;
- }
- }
- if(slot == -1)return;
- int oldSlot = mc.thePlayer.inventory.currentItem;
- mc.thePlayer.inventory.currentItem = slot;
- if(mc.gameSettings.keyBindJump.pressed) mc.thePlayer.jump();
- place(pos);
- mc.thePlayer.inventory.currentItem = oldSlot;
- }
- public void onEnable(EventUpdate event) {
- mc.thePlayer.setSprinting(false);
- }
- private IBlockState state(BlockPos pos) {
- return mc.theWorld.getBlockState(pos);
- }
- private Block block(BlockPos pos) {
- return state(pos).getBlock();
- }
- private Material material(BlockPos pos) {
- return block(pos).getMaterial();
- }
- private boolean empty(ItemStack item) {
- return item == null;
- }
- private boolean place(BlockPos pos) {
- Vec3 eye = new Vec3(mc.thePlayer.posX, mc.thePlayer.posY + mc.thePlayer.getEyeHeight(), mc.thePlayer.posZ);
- EnumFacing[] face;
- int j = (face = EnumFacing.values()).length;
- for(int i = 0; i < j; i++) {
- EnumFacing side = face[i];
- BlockPos bpos = pos.offset(side);
- EnumFacing otherSide = side.getOpposite();
- 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))) {
- if(block(bpos).canCollideCheck(state(bpos), false)) {
- Vec3 vec = new Vec3(bpos).addVector(0.5D, 0.5D, 0.5D).add(new Vec3(otherSide.getDirectionVec()).mutli(0.5D));
- if(eye.squareDistanceTo(vec) <= 18.0D) {
- lock(vec);
- mc.playerController.func_178890_a(mc.thePlayer, mc.theWorld, mc.thePlayer.getCurrentEquippedItem(), bpos, otherSide, vec);
- mc.thePlayer.swingItem();
- return true;
- }
- }
- }
- }
- return false;
- }
- private void lock(Vec3 v) {
- double diffX = v.xCoord - mc.thePlayer.posX;
- double diffY = v.yCoord - mc.thePlayer.getEyeHeight();
- double diffZ = v.zCoord - mc.thePlayer.posZ;
- double distance = MathHelper.sqrt_double(diffX * diffX + diffZ * diffZ);
- float yaw = (float)Math.toDegrees(Math.atan2(diffZ, diffX)) - 90.0F;
- float pitch = (float)-Math.toDegrees(Math.atan2(diffY, distance));
- 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));
- }
- public void onDisable(EventUpdate event) {
- mc.thePlayer.setSprinting(true);
- super.onDisable();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment