private static List<Vec3d> derivative(List<Vec3d> controlPoints) { if (controlPoints.isEmpty()) { throw new IllegalArgumentException("controlPoints must not be empty"); } int size = controlPoints.size() - 1; List<Vec3d> derivative = new ArrayList<>(size); Vec3d prev = controlPoints.get(0); for (Vec3d vec : Iterables.skip(controlPoints, 1)) { derivative.add(prev.subtract(vec).scale(size)); prev = vec; } return derivative; } }
protected final void moveLongDistance(double x, double y, double z) { Vec3d vec = new Vec3d(x - npc.posX, y - npc.posY, z - npc.posZ); //normalize vector to a -1 <-> 1 value range double w = Math.sqrt(vec.x * vec.x + vec.y * vec.y + vec.z * vec.z); if (w != 0) { vec = vec.scale(1d / w); } //then mult by PF distance to find the proper vector for our PF length vec = vec.scale(maxPFDist); //finally re-offset by npc position to get an actual target position vec = vec.addVector(npc.posX, npc.posY, npc.posZ); //move npc towards the calculated partial target setPath(vec.x, vec.y, vec.z); }
private void moveTowardsTarget() { rotationYaw = (float) Math.toRadians(UtilEntity.yawDegreesBetweenPoints(posX, posY, posZ, targetEntity.posX, targetEntity.posY, targetEntity.posZ)); rotationPitch = (float) Math.toRadians(UtilEntity.pitchDegreesBetweenPoints(posX, posY, posZ, targetEntity.posX, targetEntity.posY, targetEntity.posZ)); Vec3d moveVec = UtilEntity.lookVector(this.rotationYaw, this.rotationPitch).scale(SPEED); this.motionX = 0.5f * motionX + 0.5f * moveVec.x; this.motionY = 0.5f * motionY + 0.5f * moveVec.y; this.motionZ = 0.5f * motionZ + 0.5f * moveVec.z; } }
private void moveTowardsTarget() { rotationYaw = (float) Math.toRadians(UtilEntity.yawDegreesBetweenPoints(posX, posY, posZ, targetEntity.posX, targetEntity.posY, targetEntity.posZ)); rotationPitch = (float) Math.toRadians(UtilEntity.pitchDegreesBetweenPoints(posX, posY, posZ, targetEntity.posX, targetEntity.posY, targetEntity.posZ)); Vec3d moveVec = UtilEntity.lookVector(this.rotationYaw, this.rotationPitch).scale(SPEED); this.motionX = 0.5f * motionX + 0.5f * moveVec.x; this.motionY = 0.5f * motionY + 0.503f * moveVec.y; this.motionZ = 0.5f * motionZ + 0.5f * moveVec.z; } }
public @Nonnull List<RaytraceResult> doRayTraceAll(@Nonnull World world, @Nonnull BlockPos pos, @Nonnull EntityPlayer entityPlayer) { double reachDistance = EnderIO.proxy.getReachDistanceForPlayer(entityPlayer); Vec3d origin = Util.getEyePosition(entityPlayer); Vec3d look = entityPlayer.getLook(EnderIOConduits.proxy.getPartialTicks()); Vec3d direction = origin.add(look.scale(reachDistance)); return doRayTraceAll(world.getBlockState(pos), world, pos, origin, direction, entityPlayer); }
@Override public Vec3d get(float v) { double x = new CubicBezier(0.22f, 0.86f, 0.3f, 0.96f).eval(v); return start.subtract(finish).scale(x); }
public static RayTraceResult getPlayerTarget(EntityPlayer player, float range, float border) { HashSet<Entity> excluded = new HashSet<>(); excluded.add(player); if (player.getRidingEntity() != null) { excluded.add(player.getRidingEntity()); } float yOffset = player.getEyeHeight(); Vec3d look = player.getLookVec(); look = look.scale(range); look = look.addVector(player.posX, player.posY + yOffset, player.posZ); return tracePath(player.world, player.posX, player.posY + yOffset, player.posZ, look.x, look.y, look.z, border, excluded); }
public void createObstructionsInAir() { if (currentInversion > 1000) { Vec3d vec = new Vec3d(getWorld().rand.nextDouble() * 2 - 1, getWorld().rand.nextDouble() * 2 - 1, getWorld().rand.nextDouble() * 2 - 1).normalize().scale(2 * currentInfectionRadius); BlockPos centralPos = pos.add(vec.x, vec.y, vec.z); getWorld().setBlockState(centralPos, RegistrarBloodMagicBlocks.DEMON_EXTRAS.getStateFromMeta(0)); currentInversion -= 1000; } }
public static void boom(World world, Vec3d pos, @Nullable Entity excluded, double scale, boolean reverseDirection) { List<Entity> entityList = world.getEntitiesWithinAABBExcludingEntity(excluded, new AxisAlignedBB(new BlockPos(pos)).grow(32, 32, 32)); for (Entity entity1 : entityList) { double x = entity1.getDistance(pos.x, pos.y, pos.z) / 32.0; double magY; if (reverseDirection) magY = x; else magY = -x + 1; Vec3d dir = entity1.getPositionVector().subtract(pos).normalize().scale(reverseDirection ? -1 : 1).scale(magY).scale(scale); entity1.motionX += (dir.x); entity1.motionY += (dir.y); entity1.motionZ += (dir.z); entity1.fallDistance = 0; entity1.velocityChanged = true; if (entity1 instanceof EntityPlayerMP) ((EntityPlayerMP) entity1).connection.sendPacket(new SPacketEntityVelocity(entity1)); } } }
@NotNull @Override public SpellData renderVisualization(ModuleInstanceShape instance, @Nonnull SpellData data, @Nonnull SpellRing ring, @Nonnull SpellData previousData) { World world = data.world; Vec3d look = data.getData(LOOK); Vec3d position = data.getOrigin(); Entity caster = data.getCaster(); if (look == null || position == null || caster == null) return previousData; double range = ring.getAttributeValue(AttributeRegistry.RANGE, data); RayTraceResult trace = new RayTrace(world, look, position, range) .setEntityFilter(input -> input != caster) .setReturnLastUncollidableBlock(true) .setIgnoreBlocksWithoutBoundingBoxes(true) .trace(); data.processTrace(trace, look.scale(range)); return previousData; }
@Override @SideOnly(Side.CLIENT) public void renderSpell(ModuleInstanceEffect instance, @Nonnull SpellData spell, @Nonnull SpellRing spellRing) { Vec3d position = spell.getTarget(); Entity entityHit = spell.getVictim(); if (position == null) return; if (entityHit == null) return; if (!entityHit.hasNoGravity()) { Vec3d normal = new Vec3d(entityHit.motionX, entityHit.motionY, entityHit.motionZ).normalize().scale(1 / 2.0); LibParticles.AIR_THROTTLE(spell.world, position, normal, instance.getPrimaryColor(), instance.getSecondaryColor(), 0.5); } }
private static double getLineDistance( final Vec3d v, final Vec3d w, final EntityPlayer player, final float partialTicks ) { final Vec3d p = player.getPositionEyes( partialTicks ); final double segmentLength = v.squareDistanceTo( w ); if ( segmentLength == 0.0 ) { return p.distanceTo( v ); } final double t = Math.max( 0, Math.min( 1, p.subtract( v ).dotProduct( w.subtract( v ) ) / segmentLength ) ); final Vec3d projection = v.add( w.subtract( v ).scale( t ) ); return p.distanceTo( projection ); }
@Override public void startExecuting() { EntityLivingBase target = this.attacker.getAttackTarget(); @SuppressWarnings("unused") Vec3d shieldPos = attacker.getPositionVector().add(target.getPositionVector().subtract(attacker.getPositionVector()).scale(DIST_MULT)); attacker.shieldCooldown = 0; }
@Override public boolean attackEntityAsMob(Entity entityIn) { boolean did = super.attackEntityAsMob(entityIn); if(did) { if(entityIn instanceof EntityLivingBase) ((EntityLivingBase) entityIn).addPotionEffect(new PotionEffect(MobEffects.SLOWNESS, 60, 1)); double dx = posX - entityIn.posX; double dz = posZ - entityIn.posZ; Vec3d vec = new Vec3d(dx, 0, dz).normalize().addVector(0, 0.5, 0).normalize().scale(0.85); motionX = vec.x; motionY = vec.y; motionZ = vec.z; } return did; }
/** * Returns an approximate absolute (world) position of the held item. * This assumes a ModelBiped like model and a normal item. * * @param entity Assumes a ModelBiped like creature * @param mainHand If main hand position * @return Absolute position in the world */ public static @Nonnull Vec3d getItemPosition(EntityLivingBase entity, boolean mainHand) { boolean left = (mainHand ? entity.getPrimaryHand() : entity.getPrimaryHand().opposite()) == EnumHandSide.LEFT; boolean firstPerson = entity instanceof EntityPlayer && ((EntityPlayer) entity).isUser() && Minecraft.getMinecraft().gameSettings.thirdPersonView == 0; Vec3d dir = firstPerson ? entity.getForward() : Vec3d.fromPitchYawVector(new Vec2f(entity.rotationPitch, entity.renderYawOffset)); dir = dir.rotateYaw((float) (Math.PI / 5f) * (left ? 1f : -1f)).scale(0.75f); return dir.addVector(entity.posX, entity.posY + entity.getEyeHeight(), entity.posZ); }
@Override public void broken() { if (stacks == null) return; Vec3d offsetPos = new Vec3d(pos).add(new Vec3d(getFacing().getOpposite().getDirectionVec()).scale(OFFSET)); for (ItemStack stack : stacks) { if (stack != null) { Helpers.spawnItemStack(getWorld(), offsetPos.x, offsetPos.y, offsetPos.z, stack); } } stacks.clear(); stackHash = 0; }
private static int dropItem(IWorldLocation location, @Nonnull ItemStack stack, EnumFacing direction) { if (stack.isEmpty()) return 0; World world = location.getWorld(); Vec3d pos = location.getLoc(); if (direction != null) { pos = pos.add(new Vec3d(direction.getDirectionVec()).scale(0.75)); } EntityItem entity = new EntityItem(world, pos.x, pos.y, pos.z, stack.copy()); entity.motionX = 0; entity.motionY = 0; entity.motionZ = 0; entity.setDefaultPickupDelay(); world.spawnEntity(entity); return stack.getCount(); }
protected boolean renderRaycastedBeam(Vec3d position, Vec3d direction, Vec3d offset, T caster) { double maxDistance = getBeamMaxDistance(caster); RayTraceResult hit = MOPhysicsHelper.rayTrace(position, caster.world, maxDistance, 0, new Vec3d(0, 0, 0), false, true, direction, caster); if (hit != null && hit.typeOfHit != RayTraceResult.Type.MISS) { renderBeam(position.add(direction.scale(0.2)), hit.hitVec, offset, getBeamColor(caster), getBeamTexture(caster), getBeamThickness(caster), caster); onBeamRender(caster); onBeamRaycastHit(hit, caster); return true; } else { renderBeam(position.add(direction.scale(0.2)), position.addVector(direction.x * maxDistance, direction.y * maxDistance, direction.z * maxDistance), offset, getBeamColor(caster), getBeamTexture(caster), getBeamThickness(caster), caster); onBeamRender(caster); } return false; }
@Override public boolean forceShot() { Vec3d direction = MathUtil.getVectorFromYawPitch(this.yaw, this.pitch).scale(5D); Vec3d baseVector = new Vec3d(this.getPos().getX() + 0.5D, this.getPos().getY() + 0.6D, this.getPos().getZ() + 0.5D); Vec3d result = baseVector.add(direction); shootRay(result.x, result.y, result.z, this.getActualTurretAccuracy()); return true; }
private boolean runAway() { if (!useRunAwayTactic.get()) { return false; } runAwayTimer = 40; Vec3d targetDir = new Vec3d(attackTarget.posX, attackTarget.getEntityBoundingBox().minY, attackTarget.posZ); Vec3d entityPos = EntityUtil.getEntityPosition(entityHost); targetDir = entityPos.subtract(targetDir).normalize().scale(attackRange.get() * 0.9).add(entityPos); BlockPos probePoint = new BlockPos((int) Math.round(targetDir.x), (int) Math.round(entityHost.posY), (int) Math.round(targetDir.z)); World world = entityHost.getEntityWorld(); BlockPos clearGround = SpawnUtil.findClearGround(world, probePoint); if (clearGround == null) { return false; } boolean res = getNavigator().tryMoveToXYZ(clearGround.getX() + .5, clearGround.getY(), clearGround.getZ() + .5, mountedEntityMoveSpeed.get()); if (getNavigator().noPath()) { runningAwayTo = null; } else { final Path path = getNavigator().getPath(); runningAwayTo = path != null ? path.getFinalPathPoint() : null; } return res; }