Java Code Examples for net.minecraft.util.math.Vec3d#add()
The following examples show how to use
net.minecraft.util.math.Vec3d#add() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Freecam.java From bleachhack-1.14 with GNU General Public License v3.0 | 6 votes |
@Subscribe public void onMovement(EventMovementTick event) { mc.player.setVelocity(0, 0, 0); camera.setVelocity(0, 0, 0); mc.player.setPos(playerPos[0], playerPos[1], playerPos[2]); camera.yaw = mc.player.yaw; camera.headYaw = mc.player.headYaw; camera.pitch = mc.player.pitch; double speed = getSettings().get(0).toSlider().getValue(); Vec3d forward = new Vec3d(0, 0, speed * 2.5).rotateY(-(float) Math.toRadians(camera.headYaw)); Vec3d strafe = forward.rotateY((float) Math.toRadians(90)); Vec3d motion = camera.getVelocity(); if (mc.options.keyJump.isPressed()) motion = motion.add(0, speed * 1.5, 0); if (mc.options.keySneak.isPressed()) motion = motion.add(0, -speed * 1.5, 0); if (mc.options.keyForward.isPressed()) motion = motion.add(forward.x, 0, forward.z); if (mc.options.keyBack.isPressed()) motion = motion.add(-forward.x, 0, -forward.z); if (mc.options.keyLeft.isPressed()) motion = motion.add(strafe.x, 0, strafe.z); if (mc.options.keyRight.isPressed()) motion = motion.add(-strafe.x, 0, -strafe.z); mc.player.networkHandler.sendPacket(new ClientCommandC2SPacket(mc.player, ClientCommandC2SPacket.Mode.RELEASE_SHIFT_KEY)); camera.setPos(camera.getX() + motion.x, camera.getY() + motion.y, camera.getZ() + motion.z); event.setCancelled(true); }
Example 2
Source File: Freecam.java From bleachhack-1.14 with GNU General Public License v3.0 | 6 votes |
public void onUpdate() { if (this.isToggled()) { mc.player.setMotion(0, 0, 0); mc.player.setPosition(playerPos[0], playerPos[1], playerPos[2]); dummy.rotationYaw = camera.rotationYaw = mc.player.rotationYaw; dummy.rotationPitch = camera.rotationPitch = mc.player.rotationPitch; double speed = getSettings().get(0).toSlider().getValue(); Vec3d forward = new Vec3d(0, 0, speed * 2.5).rotateYaw(-(float) Math.toRadians(camera.rotationYaw)); Vec3d strafe = forward.rotateYaw((float) Math.toRadians(90)); Vec3d motion = Vec3d.ZERO; if (mc.gameSettings.keyBindJump.isKeyDown()) motion = motion.add(0, speed, 0); if (mc.gameSettings.keyBindSneak.isKeyDown()) motion = motion.add(0, -speed, 0); if (mc.gameSettings.keyBindForward.isKeyDown()) motion = motion.add(forward.x, 0, forward.z); if (mc.gameSettings.keyBindBack.isKeyDown()) motion = motion.add(-forward.x, 0, -forward.z); if (mc.gameSettings.keyBindLeft.isKeyDown()) motion = motion.add(strafe.x, 0, strafe.z); if (mc.gameSettings.keyBindRight.isKeyDown()) motion = motion.add(-strafe.x, 0, -strafe.z); camera.setPosition(camera.posX + motion.x, camera.posY + motion.y, camera.posZ + motion.z); } }
Example 3
Source File: RayTraceUtils.java From litematica with GNU Lesser General Public License v3.0 | 6 votes |
@Nullable public static RayTraceResult traceToSchematicWorld(Entity entity, double range, boolean respectRenderRange) { World world = SchematicWorldHandler.getSchematicWorld(); boolean invert = Hotkeys.INVERT_GHOST_BLOCK_RENDER_STATE.getKeybind().isKeybindHeld(); if (world == null || (respectRenderRange && (Configs.Visuals.ENABLE_RENDERING.getBooleanValue() == false || Configs.Visuals.ENABLE_SCHEMATIC_RENDERING.getBooleanValue() == invert))) { return null; } Vec3d start = entity.getPositionEyes(1f); Vec3d look = entity.getLook(1f).scale(range); Vec3d end = start.add(look); LayerRange layerRange = respectRenderRange ? DataManager.getRenderLayerRange() : null; return fi.dy.masa.malilib.util.RayTraceUtils.rayTraceBlocks(world, start, end, fi.dy.masa.malilib.util.RayTraceUtils::checkRayCollision, fi.dy.masa.malilib.util.RayTraceUtils.RayTraceFluidHandling.SOURCE_ONLY, fi.dy.masa.malilib.util.RayTraceUtils.BLOCK_FILTER_NON_AIR, false, true, layerRange, 200); }
Example 4
Source File: Freecam.java From bleachhack-1.14 with GNU General Public License v3.0 | 6 votes |
@Subscribe public void onMovement(EventMovementTick event) { mc.player.setVelocity(0, 0, 0); camera.setVelocity(0, 0, 0); mc.player.setPos(playerPos[0], playerPos[1], playerPos[2]); camera.yaw = mc.player.yaw; camera.headYaw = mc.player.headYaw; camera.pitch = mc.player.pitch; double speed = getSettings().get(0).toSlider().getValue(); Vec3d forward = new Vec3d(0, 0, speed * 2.5).rotateY(-(float) Math.toRadians(camera.headYaw)); Vec3d strafe = forward.rotateY((float) Math.toRadians(90)); Vec3d motion = camera.getVelocity(); if (mc.options.keyJump.isPressed()) motion = motion.add(0, speed * 1.5, 0); if (mc.options.keySneak.isPressed()) motion = motion.add(0, -speed * 1.5, 0); if (mc.options.keyForward.isPressed()) motion = motion.add(forward.x, 0, forward.z); if (mc.options.keyBack.isPressed()) motion = motion.add(-forward.x, 0, -forward.z); if (mc.options.keyLeft.isPressed()) motion = motion.add(strafe.x, 0, strafe.z); if (mc.options.keyRight.isPressed()) motion = motion.add(-strafe.x, 0, -strafe.z); mc.player.networkHandler.sendPacket(new ClientCommandC2SPacket(mc.player, ClientCommandC2SPacket.Mode.RELEASE_SHIFT_KEY)); camera.setPos(camera.getX() + motion.x, camera.getY() + motion.y, camera.getZ() + motion.z); event.setCancelled(true); }
Example 5
Source File: Freecam.java From bleachhack-1.14 with GNU General Public License v3.0 | 6 votes |
@Subscribe public void onMovement(EventMovementTick event) { mc.player.setVelocity(0, 0, 0); camera.setVelocity(0, 0, 0); mc.player.setPosition(playerPos[0], playerPos[1], playerPos[2]); camera.yaw = mc.player.yaw; camera.headYaw = mc.player.headYaw; camera.pitch = mc.player.pitch; double speed = getSettings().get(0).toSlider().getValue(); Vec3d forward = new Vec3d(0, 0, speed * 2.5).rotateY(-(float) Math.toRadians(camera.headYaw)); Vec3d strafe = forward.rotateY((float) Math.toRadians(90)); Vec3d motion = camera.getVelocity(); if (mc.options.keyJump.isPressed()) motion = motion.add(0, speed * 1.5, 0); if (mc.options.keySneak.isPressed()) motion = motion.add(0, -speed * 1.5, 0); if (mc.options.keyForward.isPressed()) motion = motion.add(forward.x, 0, forward.z); if (mc.options.keyBack.isPressed()) motion = motion.add(-forward.x, 0, -forward.z); if (mc.options.keyLeft.isPressed()) motion = motion.add(strafe.x, 0, strafe.z); if (mc.options.keyRight.isPressed()) motion = motion.add(-strafe.x, 0, -strafe.z); mc.player.networkHandler.sendPacket(new ClientCommandC2SPacket(mc.player, ClientCommandC2SPacket.Mode.STOP_SNEAKING)); camera.setPosition(camera.x + motion.x, camera.y + motion.y, camera.z + motion.z); event.setCancelled(true); }
Example 6
Source File: AntiAfkMod.java From ForgeHax with MIT License | 5 votes |
@Override public void onStart() { ForgeHaxHooks.isSafeWalkActivated = true; Bindings.forward.bind(); Vec3d eye = EntityUtils.getEyePos(getLocalPlayer()); List<Double> yaws = Lists.newArrayList(); for (int i = 0; i < (360 / DEGREES); ++i) { yaws.add((i * DEGREES) - 180.D); } Collections.shuffle(yaws); double lastDistance = -1.D; for (double y : yaws) { double[] cc = Angle.degrees(0.f, (float) y).getForwardVector(); Vec3d target = eye.add(new Vec3d(cc[0], cc[1], cc[2]).normalize().scale(64)); RayTraceResult result = getWorld().rayTraceBlocks(eye, target, false, true, false); double distance = result == null ? 64.D : eye.distanceTo(result.hitVec); if ((distance >= 1.D || lastDistance == -1.D) && (distance > lastDistance || Math.random() < 0.20D)) { angle = y; lastDistance = distance; } } }
Example 7
Source File: BlockBBarrel.java From BetterChests with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void onBlockClicked(World world, BlockPos pos, EntityPlayer player) { if (world.isRemote) { return; } TileEntity te = world.getTileEntity(pos); if (te instanceof TileEntityBBarrel) { TileEntityBBarrel chest = (TileEntityBBarrel)te; InventoryPartBarrel part = chest.getChestPart(); ItemStack stack = part.getDummy(); int targetAmount = !player.isSneaking() ? 1 : stack.getMaxStackSize(); int gottenAmount = 0; for (int i = 0; i < part.getSizeInventory() && !part.isEmpty(); i++) { if (ItemUtil.areItemsSameMatchingIdDamageNbt(stack, part.getStackInSlot(i))) { gottenAmount += part.decrStackSize(i, targetAmount - gottenAmount).getCount(); if (gottenAmount >= targetAmount) { break; } } } if (gottenAmount > 0) { Vec3d vec = new Vec3d(pos).addVector(.5, .5, .5); vec = vec.add(player.getPositionVector().subtract(vec).normalize()); ItemStack drop = stack.copy(); drop.setCount(gottenAmount); WorldUtil.dropItems(world, drop, vec.x, vec.y, vec.z); chest.getChestPart().markDirty(); } } }
Example 8
Source File: BlockUtils.java From ForgeWurst with GNU General Public License v3.0 | 5 votes |
public static void breakBlocksPacketSpam(Iterable<BlockPos> blocks) { Vec3d eyesPos = RotationUtils.getEyesPos(); NetHandlerPlayClient connection = WMinecraft.getPlayer().connection; for(BlockPos pos : blocks) { Vec3d posVec = new Vec3d(pos).addVector(0.5, 0.5, 0.5); double distanceSqPosVec = eyesPos.squareDistanceTo(posVec); for(EnumFacing side : EnumFacing.values()) { Vec3d hitVec = posVec.add(new Vec3d(side.getDirectionVec()).scale(0.5)); // check if side is facing towards player if(eyesPos.squareDistanceTo(hitVec) >= distanceSqPosVec) continue; // break block connection.sendPacket(new CPacketPlayerDigging( Action.START_DESTROY_BLOCK, pos, side)); connection.sendPacket(new CPacketPlayerDigging( Action.STOP_DESTROY_BLOCK, pos, side)); break; } } }
Example 9
Source File: ShapeDispatcher.java From fabric-carpet with MIT License | 5 votes |
public Vec3d toAbsolute(Entity e, Vec3d vec, float partialTick) { return vec.add( snapX?MathHelper.lerp(partialTick, e.prevX, e.getX()):0.0, snapY?MathHelper.lerp(partialTick, e.prevY, e.getY()):0.0, snapZ?MathHelper.lerp(partialTick, e.prevZ, e.getZ()):0.0 ); }
Example 10
Source File: BonemealAuraHack.java From Wurst7 with GNU General Public License v3.0 | 5 votes |
private boolean rightClickBlockSimple(BlockPos pos) { Vec3d eyesPos = RotationUtils.getEyesPos(); Vec3d posVec = Vec3d.ofCenter(pos); double distanceSqPosVec = eyesPos.squaredDistanceTo(posVec); for(Direction side : Direction.values()) { Vec3d hitVec = posVec.add(Vec3d.of(side.getVector()).multiply(0.5)); double distanceSqHitVec = eyesPos.squaredDistanceTo(hitVec); // check if hitVec is within range (6 blocks) if(distanceSqHitVec > 36) continue; // check if side is facing towards player if(distanceSqHitVec >= distanceSqPosVec) continue; // place block IMC.getInteractionManager().rightClickBlock(pos, side, hitVec); return true; } return false; }
Example 11
Source File: TemplateEnderUtilities.java From enderutilities with GNU Lesser General Public License v3.0 | 4 votes |
public void addEntitiesToWorld(World world, BlockPos posStart) { if (this.placement.getIgnoreEntities()) { return; } Mirror mirror = this.placement.getMirror(); Rotation rotation = this.placement.getRotation(); BlockPos posEnd = posStart.add(PositionUtils.getRelativeEndPositionFromAreaSize(this.size)); BlockPos pos1 = PositionUtils.getMinCorner(posStart, posEnd); BlockPos pos2 = PositionUtils.getMaxCorner(posStart, posEnd).add(1, 1, 1); List<Entity> existingEntities = world.getEntitiesWithinAABBExcludingEntity(null, new AxisAlignedBB(pos1, pos2)); for (TemplateEnderUtilities.TemplateEntityInfo entityInfo : this.entities) { BlockPos pos = transformedBlockPos(this.placement, entityInfo.blockPos).add(posStart); NBTTagCompound nbt = entityInfo.entityData; UUID uuidOriginal = nbt.getUniqueId("UUID"); Vec3d vec3d = PositionUtils.transformedVec3d(entityInfo.pos, mirror, rotation); Vec3d vec3d1 = vec3d.add((double)posStart.getX(), (double)posStart.getY(), (double)posStart.getZ()); NBTTagList tagList = new NBTTagList(); tagList.appendTag(new NBTTagDouble(vec3d1.x)); tagList.appendTag(new NBTTagDouble(vec3d1.y)); tagList.appendTag(new NBTTagDouble(vec3d1.z)); nbt.setTag("Pos", tagList); nbt.setUniqueId("UUID", UUID.randomUUID()); Entity entity; try { entity = EntityList.createEntityFromNBT(nbt, world); } catch (Exception e) { entity = null; } if (entity != null) { if (entity instanceof EntityPainting) { entity.getMirroredYaw(mirror); entity.getRotatedYaw(rotation); entity.setPosition(pos.getX(), pos.getY(), pos.getZ()); entity.setLocationAndAngles(vec3d1.x, vec3d1.y, vec3d1.z, entity.rotationYaw, entity.rotationPitch); } else { float f = entity.getMirroredYaw(mirror); f = f + (entity.rotationYaw - entity.getRotatedYaw(rotation)); entity.setLocationAndAngles(vec3d1.x, vec3d1.y, vec3d1.z, f, entity.rotationPitch); // FIXME should call updateFacingWithBoundingBox(EnumFacing) for EntityHanging, otherwise a world reload is needed // for ItemFrames for example to visually update to the correct facing } // Use the original UUID if possible. If there is an entity with the same UUID within the pasted area, // then the old one will be killed. Otherwise if there is no entity currently in the world with // the same UUID, then the original UUID will be used. Entity existing = EntityUtils.findEntityByUUID(existingEntities, uuidOriginal); if (existing != null) { world.removeEntityDangerously(existing); entity.setUniqueId(uuidOriginal); } else if (world instanceof WorldServer && ((WorldServer) world).getEntityFromUuid(uuidOriginal) == null) { entity.setUniqueId(uuidOriginal); } world.spawnEntity(entity); } } }
Example 12
Source File: Scaffold.java From bleachhack-1.14 with GNU General Public License v3.0 | 4 votes |
@Subscribe public void onTick(EventTick event) { for (Entry<BlockPos, Integer> e: new HashMap<>(lastPlaced).entrySet()) { if (e.getValue() > 0) lastPlaced.replace(e.getKey(), e.getValue() - 1); else lastPlaced.remove(e.getKey()); } int slot = -1; int prevSlot = mc.player.inventory.selectedSlot; if (mc.player.inventory.getMainHandStack().getItem() instanceof BlockItem) { slot = mc.player.inventory.selectedSlot; } else for (int i = 0; i < 9; i++) { if (mc.player.inventory.getStack(i).getItem() instanceof BlockItem) { slot = i; break; } } if (slot == -1) return; mc.player.inventory.selectedSlot = slot; double range = getSettings().get(0).toSlider().getValue(); int mode = getSettings().get(1).toMode().mode; if (mode == 0) { for (int r = 0; r < 5; r++) { Vec3d r1 = new Vec3d(0,-0.85,0); if (r == 1) r1 = r1.add(range, 0, 0); if (r == 2) r1 = r1.add(-range, 0, 0); if (r == 3) r1 = r1.add(0, 0, range); if (r == 4) r1 = r1.add(0, 0, -range); if (placeBlockAuto(new BlockPos(mc.player.getPos().add(r1)))) { return; } } } else { int cap = 0; for (int x = (mode == 1 ? -1 : -2); x <= (mode == 1 ? 1 : 2); x++) { for (int z = (mode == 1 ? -1 : -2); z <= (mode == 1 ? 1 : 2); z++) { if (placeBlockAuto(new BlockPos(mc.player.getPos().add(x, -0.85, z)))) cap++; if (cap > 3) return; } } } mc.player.inventory.selectedSlot = prevSlot; }
Example 13
Source File: RenderUtils.java From Wizardry with GNU Lesser General Public License v3.0 | 4 votes |
public static void drawFaceOutline(@Nonnull BlockPos pos, @Nonnull EnumFacing facing, Color color) { GlStateManager.pushMatrix(); GlStateManager.disableDepth(); GlStateManager.disableLighting(); GlStateManager.disableCull(); GlStateManager.enableAlpha(); GlStateManager.enableBlend(); GlStateManager.shadeModel(GL11.GL_SMOOTH); GlStateManager.blendFunc(GL_SRC_ALPHA, GL_ONE); GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO); GlStateManager.color(1, 1, 1, 1); GlStateManager.disableTexture2D(); GlStateManager.enableColorMaterial(); Tessellator tessellator = Tessellator.getInstance(); tessellator.getBuffer().begin(GL11.GL_LINES, DefaultVertexFormats.POSITION_COLOR); Vec3d directionOffsetVec = new Vec3d(facing.getDirectionVec()).scale(0.5); Vec3d adjPos = new Vec3d(pos).add(0.5, 0.5, 0.5).add(directionOffsetVec); GlStateManager.glLineWidth(0.5f); for (EnumFacing facing1 : getPerpendicularFacings(facing)) { for (EnumFacing facing2 : getPerpendicularFacings(facing)) { if (facing1 == facing2 || facing1.getOpposite() == facing2 || facing2.getOpposite() == facing1) continue; Vec3d p1 = new Vec3d(facing1.getDirectionVec()).scale(0.5); Vec3d p2 = new Vec3d(facing2.getDirectionVec()).scale(0.5); Vec3d edge = adjPos.add(p1.add(p2)); tessellator.getBuffer().pos(edge.x, edge.y, edge.z).color(color.getRed(), color.getGreen(), color.getBlue(), 255).endVertex(); } } tessellator.draw(); GlStateManager.disableBlend(); GlStateManager.enableDepth(); GlStateManager.enableAlpha(); GlStateManager.enableTexture2D(); GlStateManager.disableColorMaterial(); GlStateManager.enableDepth(); GlStateManager.popMatrix(); }
Example 14
Source File: TunnellerHack.java From Wurst7 with GNU General Public License v3.0 | 4 votes |
private boolean breakBlockSimple(BlockPos pos) { Direction side = null; Direction[] sides = Direction.values(); Vec3d eyesPos = RotationUtils.getEyesPos(); Vec3d relCenter = BlockUtils.getBoundingBox(pos) .offset(-pos.getX(), -pos.getY(), -pos.getZ()).getCenter(); Vec3d center = Vec3d.of(pos).add(relCenter); Vec3d[] hitVecs = new Vec3d[sides.length]; for(int i = 0; i < sides.length; i++) { Vec3i dirVec = sides[i].getVector(); Vec3d relHitVec = new Vec3d(relCenter.x * dirVec.getX(), relCenter.y * dirVec.getY(), relCenter.z * dirVec.getZ()); hitVecs[i] = center.add(relHitVec); } for(int i = 0; i < sides.length; i++) { // check line of sight if(MC.world .rayTrace(new RayTraceContext(eyesPos, hitVecs[i], RayTraceContext.ShapeType.COLLIDER, RayTraceContext.FluidHandling.NONE, MC.player)) .getType() != HitResult.Type.MISS) continue; side = sides[i]; break; } if(side == null) { double distanceSqToCenter = eyesPos.squaredDistanceTo(center); for(int i = 0; i < sides.length; i++) { // check if side is facing towards player if(eyesPos.squaredDistanceTo(hitVecs[i]) >= distanceSqToCenter) continue; side = sides[i]; break; } } if(side == null) throw new RuntimeException( "How could none of the sides be facing towards the player?!"); // face block WURST.getRotationFaker().faceVectorPacket(hitVecs[side.ordinal()]); // damage block if(!MC.interactionManager.updateBlockBreakingProgress(pos, side)) return false; // swing arm MC.player.networkHandler .sendPacket(new HandSwingC2SPacket(Hand.MAIN_HAND)); return true; }
Example 15
Source File: InstantBunkerHack.java From Wurst7 with GNU General Public License v3.0 | 4 votes |
private void placeBlockSimple(BlockPos pos) { Direction side = null; Direction[] sides = Direction.values(); Vec3d eyesPos = RotationUtils.getEyesPos(); Vec3d posVec = Vec3d.ofCenter(pos); double distanceSqPosVec = eyesPos.squaredDistanceTo(posVec); Vec3d[] hitVecs = new Vec3d[sides.length]; for(int i = 0; i < sides.length; i++) hitVecs[i] = posVec.add(Vec3d.of(sides[i].getVector()).multiply(0.5)); for(int i = 0; i < sides.length; i++) { // check if neighbor can be right clicked BlockPos neighbor = pos.offset(sides[i]); if(!BlockUtils.canBeClicked(neighbor)) continue; // check line of sight BlockState neighborState = BlockUtils.getState(neighbor); VoxelShape neighborShape = neighborState.getOutlineShape(MC.world, neighbor); if(MC.world.rayTraceBlock(eyesPos, hitVecs[i], neighbor, neighborShape, neighborState) != null) continue; side = sides[i]; break; } if(side == null) for(int i = 0; i < sides.length; i++) { // check if neighbor can be right clicked if(!BlockUtils.canBeClicked(pos.offset(sides[i]))) continue; // check if side is facing away from player if(distanceSqPosVec > eyesPos.squaredDistanceTo(hitVecs[i])) continue; side = sides[i]; break; } if(side == null) return; Vec3d hitVec = hitVecs[side.ordinal()]; // face block // WURST.getRotationFaker().faceVectorPacket(hitVec); // if(RotationUtils.getAngleToLastReportedLookVec(hitVec) > 1) // return; // check timer // if(IMC.getItemUseCooldown() > 0) // return; // place block IMC.getInteractionManager().rightClickBlock(pos.offset(side), side.getOpposite(), hitVec); // swing arm MC.player.networkHandler .sendPacket(new HandSwingC2SPacket(Hand.MAIN_HAND)); // reset timer IMC.setItemUseCooldown(4); }
Example 16
Source File: RayTraceUtils.java From litematica with GNU Lesser General Public License v3.0 | 4 votes |
@Nonnull public static RayTraceWrapper getWrappedRayTraceFromEntity(World world, Entity entity, double range) { Vec3d eyesPos = entity.getPositionEyes(1f); Vec3d rangedLookRot = entity.getLook(1f).scale(range); Vec3d lookEndPos = eyesPos.add(rangedLookRot); RayTraceResult result = fi.dy.masa.malilib.util.RayTraceUtils .getRayTraceFromEntity(world, entity, RayTraceFluidHandling.NONE, false, range); double closestVanilla = result.typeOfHit != RayTraceResult.Type.MISS ? result.hitVec.distanceTo(eyesPos) : -1D; AreaSelection area = DataManager.getSelectionManager().getCurrentSelection(); RayTraceWrapper wrapper = null; clearTraceVars(); if (DataManager.getToolMode().getUsesSchematic() == false && area != null) { for (SelectionBox box : area.getAllSubRegionBoxes()) { boolean hitCorner = false; hitCorner |= traceToSelectionBoxCorner(box, Corner.CORNER_1, eyesPos, lookEndPos); hitCorner |= traceToSelectionBoxCorner(box, Corner.CORNER_2, eyesPos, lookEndPos); if (hitCorner == false) { traceToSelectionBoxBody(box, eyesPos, lookEndPos); } } BlockPos origin = area.getExplicitOrigin(); if (origin != null) { traceToOrigin(origin, eyesPos, lookEndPos, HitType.SELECTION_ORIGIN, null); } } if (DataManager.getToolMode().getUsesSchematic()) { for (SchematicPlacement placement : DataManager.getSchematicPlacementManager().getVisibleSchematicPlacements()) { if (placement.isEnabled()) { traceToPlacementBox(placement, eyesPos, lookEndPos); traceToOrigin(placement.getOrigin(), eyesPos, lookEndPos, HitType.PLACEMENT_ORIGIN, placement); } } } double closestDistance = closestVanilla; if (closestBoxDistance >= 0 && (closestVanilla < 0 || closestBoxDistance <= closestVanilla)) { closestDistance = closestBoxDistance; wrapper = closestBox; } // Corners are preferred over box body hits, thus this being after the box check if (closestCornerDistance >= 0 && (closestVanilla < 0 || closestCornerDistance <= closestVanilla)) { closestDistance = closestCornerDistance; wrapper = closestCorner; } // Origins are preferred over everything else if (closestOriginDistance >= 0 && (closestVanilla < 0 || closestOriginDistance <= closestVanilla)) { closestDistance = closestOriginDistance; if (originType == HitType.PLACEMENT_ORIGIN) { wrapper = closestOrigin; } else { wrapper = new RayTraceWrapper(RayTraceWrapper.HitType.SELECTION_ORIGIN); } } clearTraceVars(); if (wrapper == null || closestDistance < 0) { wrapper = new RayTraceWrapper(); } return wrapper; }
Example 17
Source File: PlayerUtils.java From GriefPrevention with MIT License | 4 votes |
public static RayTraceResult rayTracePlayerEyes(EntityPlayerMP player) { double distance = SpongeImplHooks.getBlockReachDistance(player) + 1; Vec3d startPos = new Vec3d(player.posX, player.posY + player.getEyeHeight(), player.posZ); Vec3d endPos = startPos.add(new Vec3d(player.getLookVec().x * distance, player.getLookVec().y * distance, player.getLookVec().z * distance)); return player.world.rayTraceBlocks(startPos, endPos); }
Example 18
Source File: BonemealAuraHack.java From Wurst7 with GNU General Public License v3.0 | 4 votes |
private boolean rightClickBlockLegit(BlockPos pos) { Vec3d eyesPos = RotationUtils.getEyesPos(); Vec3d posVec = Vec3d.ofCenter(pos); double distanceSqPosVec = eyesPos.squaredDistanceTo(posVec); for(Direction side : Direction.values()) { Vec3d hitVec = posVec.add(Vec3d.of(side.getVector()).multiply(0.5)); double distanceSqHitVec = eyesPos.squaredDistanceTo(hitVec); // check if hitVec is within range (4.25 blocks) if(distanceSqHitVec > 18.0625) continue; // check if side is facing towards player if(distanceSqHitVec >= distanceSqPosVec) continue; // check line of sight if(MC.world .rayTrace(new RayTraceContext(eyesPos, hitVec, RayTraceContext.ShapeType.COLLIDER, RayTraceContext.FluidHandling.NONE, MC.player)) .getType() != HitResult.Type.MISS) continue; // face block WURST.getRotationFaker().faceVectorPacket(hitVec); // place block IMC.getInteractionManager().rightClickBlock(pos, side, hitVec); MC.player.swingHand(Hand.MAIN_HAND); IMC.setItemUseCooldown(4); return true; } return false; }
Example 19
Source File: AutoFarmHack.java From Wurst7 with GNU General Public License v3.0 | 4 votes |
private void placeBlockSimple(BlockPos pos) { Direction side = null; Direction[] sides = Direction.values(); Vec3d eyesPos = RotationUtils.getEyesPos(); Vec3d posVec = Vec3d.ofCenter(pos); double distanceSqPosVec = eyesPos.squaredDistanceTo(posVec); Vec3d[] hitVecs = new Vec3d[sides.length]; for(int i = 0; i < sides.length; i++) hitVecs[i] = posVec.add(Vec3d.of(sides[i].getVector()).multiply(0.5)); for(int i = 0; i < sides.length; i++) { // check if neighbor can be right clicked BlockPos neighbor = pos.offset(sides[i]); if(!BlockUtils.canBeClicked(neighbor)) continue; // check line of sight BlockState neighborState = BlockUtils.getState(neighbor); VoxelShape neighborShape = neighborState.getOutlineShape(MC.world, neighbor); if(MC.world.rayTraceBlock(eyesPos, hitVecs[i], neighbor, neighborShape, neighborState) != null) continue; side = sides[i]; break; } if(side == null) for(int i = 0; i < sides.length; i++) { // check if neighbor can be right clicked if(!BlockUtils.canBeClicked(pos.offset(sides[i]))) continue; // check if side is facing away from player if(distanceSqPosVec > eyesPos.squaredDistanceTo(hitVecs[i])) continue; side = sides[i]; break; } if(side == null) return; Vec3d hitVec = hitVecs[side.ordinal()]; // face block WURST.getRotationFaker().faceVectorPacket(hitVec); if(RotationUtils.getAngleToLastReportedLookVec(hitVec) > 1) return; // check timer if(IMC.getItemUseCooldown() > 0) return; // place block IMC.getInteractionManager().rightClickBlock(pos.offset(side), side.getOpposite(), hitVec); // swing arm MC.player.networkHandler .sendPacket(new HandSwingC2SPacket(Hand.MAIN_HAND)); // reset timer IMC.setItemUseCooldown(4); }
Example 20
Source File: Scaffold.java From bleachhack-1.14 with GNU General Public License v3.0 | 4 votes |
@Subscribe public void onTick(EventTick event) { for (Entry<BlockPos, Integer> e: new HashMap<>(lastPlaced).entrySet()) { if (e.getValue() > 0) lastPlaced.replace(e.getKey(), e.getValue() - 1); else lastPlaced.remove(e.getKey()); } int slot = -1; int prevSlot = mc.player.inventory.selectedSlot; if (mc.player.inventory.getMainHandStack().getItem() instanceof BlockItem) { slot = mc.player.inventory.selectedSlot; } else for (int i = 0; i < 9; i++) { if (mc.player.inventory.getInvStack(i).getItem() instanceof BlockItem) { slot = i; break; } } if (slot == -1) return; mc.player.inventory.selectedSlot = slot; double range = getSettings().get(0).toSlider().getValue(); int mode = getSettings().get(1).toMode().mode; if (mode == 0) { for (int r = 0; r < 5; r++) { Vec3d r1 = new Vec3d(0,-0.85,0); if (r == 1) r1 = r1.add(range, 0, 0); if (r == 2) r1 = r1.add(-range, 0, 0); if (r == 3) r1 = r1.add(0, 0, range); if (r == 4) r1 = r1.add(0, 0, -range); if (placeBlockAuto(new BlockPos(mc.player.getPos().add(r1)))) { return; } } } else { int cap = 0; for (int x = (mode == 1 ? -1 : -2); x <= (mode == 1 ? 1 : 2); x++) { for (int z = (mode == 1 ? -1 : -2); z <= (mode == 1 ? 1 : 2); z++) { if (placeBlockAuto(new BlockPos(mc.player.getPos().add(x, -0.85, z)))) cap++; if (cap > 3) return; } } } mc.player.inventory.selectedSlot = prevSlot; }