org.bukkit.util.Vector#setY ( )源码实例Demo

下面列出了org.bukkit.util.Vector#setY ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: EffectLib   文件: StarEffect.java
@Override
public void onRun() {
    Location location = getLocation();
    float radius = 3 * innerRadius / MathUtils.SQRT_3;
    for (int i = 0; i < spikesHalf * 2; i++) {
        double xRotation = i * Math.PI / spikesHalf;
        for (int x = 0; x < particles; x++) {
            double angle = 2 * Math.PI * x / particles;
            float height = RandomUtils.random.nextFloat() * spikeHeight;
            Vector v = new Vector(Math.cos(angle), 0, Math.sin(angle));
            v.multiply((spikeHeight - height) * radius / spikeHeight);
            v.setY(innerRadius + height);
            VectorUtils.rotateAroundAxisX(v, xRotation);
            location.add(v);
            display(particle, location);
            location.subtract(v);
            VectorUtils.rotateAroundAxisX(v, Math.PI);
            VectorUtils.rotateAroundAxisY(v, Math.PI / 2);
            location.add(v);
            display(particle, location);
            location.subtract(v);
        }
    }
}
 
源代码2 项目: QualityArmory   文件: GunUtil.java
private static void addRecoilWithTeleport(Player player, Gun g, boolean useHighRecoil) {
	Location tempCur = (QAMain.recoilHelperMovedLocation.get(player.getUniqueId()));
	final Location current;
	if (tempCur == null) {
		current = player.getLocation();
	} else {
		current = tempCur;
	}
	Vector movementOffset = player.getVelocity().multiply(0.2);
	if (movementOffset.getY() > -0.1 && movementOffset.getY() < 0)
		movementOffset.setY(0);
	current.add(movementOffset);
	current.setPitch((float) (current.getPitch()
			- (useHighRecoil ? highRecoilCounter.get(player.getUniqueId()) : g.getRecoil())));
	if (useHighRecoil)
		highRecoilCounter.remove(player.getUniqueId());
	Vector temp = player.getVelocity();
	// player.getLocation().setDirection(vector);
	player.teleport(current);
	player.setVelocity(temp);
}
 
源代码3 项目: EffectLib   文件: GridEffect.java
@Override
public void onRun() {
    Location location = getLocation();
    // Draw rows
    Vector v = new Vector();
    for (int i = 0; i <= (rows + 1); i++) {
        for (int j = 0; j < particlesWidth * (columns + 1); j++) {
            v.setY(i * heightCell);
            v.setX(j * widthCell / particlesWidth);
            addParticle(location, v);
        }
    }
    // Draw columns
    for (int i = 0; i <= (columns + 1); i++) {
        for (int j = 0; j < particlesHeight * (rows + 1); j++) {
            v.setX(i * widthCell);
            v.setY(j * heightCell / particlesHeight);
            addParticle(location, v);
        }
    }
}
 
源代码4 项目: AnnihilationPro   文件: Scout.java
private void pullEntityToLocation(Entity e, Location loc)
{
	Location entityLoc = e.getLocation();

	entityLoc.setY(entityLoc.getY() + 0.5D);
	e.teleport(entityLoc);

	double g = -0.08D;
	double d = loc.distance(entityLoc);
	double t = d;
	double v_x = (1.0D + 0.07000000000000001D * t)
			* (loc.getX() - entityLoc.getX()) / t;
	double v_y = (1.0D + 0.03D * t) * (loc.getY() - entityLoc.getY()) / t
			- 0.5D * g * t;
	double v_z = (1.0D + 0.07000000000000001D * t)
			* (loc.getZ() - entityLoc.getZ()) / t;

	Vector v = e.getVelocity();
	v.setX(v_x);
	v.setY(v_y);
	v.setZ(v_z);
	e.setVelocity(v);

	//addNoFall(e, 100);
}
 
源代码5 项目: Hawk   文件: WrappedBlock7.java
@Override
public Vector getFlowDirection() {
    Vector vec = new Vector();
    Vec3D nmsVec = Vec3D.a(0, 0, 0);
    Entity dummy = null;
    if(!block.getMaterial().isLiquid())
        return vec;

    //this should prevent async threads from calling NMS code that actually loads chunks
    if(!Bukkit.isPrimaryThread()) {
        if(!obBlock.getWorld().isChunkLoaded(obBlock.getX() >> 4, obBlock.getZ() >> 4) ||
                !obBlock.getWorld().isChunkLoaded(obBlock.getX() + 1 >> 4, obBlock.getZ() >> 4) ||
                !obBlock.getWorld().isChunkLoaded(obBlock.getX() - 1 >> 4, obBlock.getZ() >> 4) ||
                !obBlock.getWorld().isChunkLoaded(obBlock.getX() >> 4, obBlock.getZ() + 1 >> 4) ||
                !obBlock.getWorld().isChunkLoaded(obBlock.getX() >> 4, obBlock.getZ() - 1 >> 4)) {
            return vec;
        }
    }

    block.a(((CraftWorld) obBlock.getWorld()).getHandle(), obBlock.getX(), obBlock.getY(), obBlock.getZ(), dummy, nmsVec);
    vec.setX(nmsVec.a);
    vec.setY(nmsVec.b);
    vec.setZ(nmsVec.c);
    return vec;
}
 
源代码6 项目: Hawk   文件: MathPlus.java
public static void rotateVectorsEulerXYZ(Vector[] vertices, float radX, float radY, float radZ) {
    for(Vector vertex : vertices) {
        double x, y, z;

        //rotate around X axis (pitch)
        z = vertex.getZ();
        y = vertex.getY();
        vertex.setZ(z * cos(radX) - y * sin(radX));
        vertex.setY(z * sin(radX) + y * cos(radX));

        //rotate around Y axis (yaw)
        x = vertex.getX();
        z = vertex.getZ();
        vertex.setX(x * cos(radY) - z * sin(radY));
        vertex.setZ(x * sin(radY) + z * cos(radY));

        //rotate around Z axis (roll)
        x = vertex.getX();
        y = vertex.getY();
        vertex.setX(x * cos(radZ) - y * sin(radZ));
        vertex.setY(x * sin(radZ) + y * cos(radZ));
    }
}
 
源代码7 项目: CardinalPGM   文件: ProximityInfo.java
public ProximityInfo(Vector location, boolean horizontal, boolean needsTouch, GameObjectiveProximityHandler.ProximityMetric metric) {
    this.horizontal = horizontal;
    this.needsTouch = needsTouch;
    this.metric = metric;
    this.locations = new HashSet<>();
    if (location != null) locations.add(location);
    if (horizontal) {
        for (Vector vec : this.locations) {
            vec.setY(0);
        }
    }
}
 
源代码8 项目: ProjectAres   文件: KnockbackSettings.java
public Vector pitchedNormal(Vector delta) {
    delta = delta.clone();
    delta.setY(0);
    if(delta.isZero()) return Vectors.ZERO;
    delta.normalize();
    final double theta = Math.toRadians(pitch);
    final double cos = Math.cos(theta);
    delta.set(cos * delta.getX(),
               Math.sin(theta),
               cos * delta.getZ());
    return delta;
}
 
源代码9 项目: Hawk   文件: EntityInteractReach.java
@Override
protected void check(InteractEntityEvent e) {
    Entity victimEntity = e.getEntity();
    if (!(victimEntity instanceof Player) && !CHECK_OTHER_ENTITIES)
        return;
    int ping = ServerUtils.getPing(e.getPlayer());
    if (PING_LIMIT > -1 && ping > PING_LIMIT)
        return;
    Player p = e.getPlayer();
    HawkPlayer att = e.getHawkPlayer();

    Location victimLocation;
    if (LAG_COMPENSATION)
        victimLocation = hawk.getLagCompensator().getHistoryLocation(ping, victimEntity);
    else
        victimLocation = victimEntity.getLocation();

    AABB victimAABB = WrappedEntity.getWrappedEntity(victimEntity).getHitbox(victimLocation.toVector());

    Vector attackerPos;
    if(att.isInVehicle()) {
        attackerPos = hawk.getLagCompensator().getHistoryLocation(ServerUtils.getPing(p), p).toVector();
        attackerPos.setY(attackerPos.getY() + p.getEyeHeight());
    }
    else {
        attackerPos = att.getHeadPosition();
    }

    double maxReach = att.getPlayer().getGameMode() == GameMode.CREATIVE ? MAX_REACH_CREATIVE : MAX_REACH;
    double dist = victimAABB.distanceToPosition(attackerPos);

    if (dist > maxReach) {
        punish(att, 1, true, e, new Placeholder("distance", MathPlus.round(dist, 2)));
    } else {
        reward(att);
    }
}
 
源代码10 项目: Sentinel   文件: SentinelUtilities.java
/**
 * Gets a 'launch detail' (starting location with direction vector set to correct firing direction, and a vector holding the exact launch vector, scaled to the correct speed).
 */
public static HashMap.SimpleEntry<Location, Vector> getLaunchDetail(Location start, Location target, Vector lead) {
    double speeda;
    double angt = Double.POSITIVE_INFINITY;
    double sbase = SentinelPlugin.instance.minShootSpeed;
    for (speeda = sbase; speeda <= sbase + 15; speeda += 5) {
        // TODO: Mathematically calculate a valid starting speed, to avoid pointlessly looping on a math utility.
        angt = SentinelUtilities.getArrowAngle(start, target, speeda, 20);
        if (!Double.isInfinite(angt)) {
            break;
        }
    }
    if (Double.isInfinite(angt)) {
        return null;
    }
    double hangT = SentinelUtilities.hangtime(angt, speeda, target.getY() - start.getY(), 20);
    Location to = target.clone().add(lead.clone().multiply(hangT));
    Vector relative = to.clone().subtract(start.toVector()).toVector();
    double deltaXZ = Math.sqrt(relative.getX() * relative.getX() + relative.getZ() * relative.getZ());
    if (deltaXZ == 0) {
        deltaXZ = 0.1;
    }
    for (speeda = sbase; speeda <= sbase + 15; speeda += 5) {
        angt = SentinelUtilities.getArrowAngle(start, to, speeda, 20);
        if (!Double.isInfinite(angt)) {
            break;
        }
    }
    if (Double.isInfinite(angt)) {
        return null;
    }
    relative.setY(Math.tan(angt) * deltaXZ);
    relative = relative.normalize();
    Vector normrel = relative.clone();
    speeda = speeda + (1.188 * hangT * hangT);
    relative = relative.multiply(speeda / 20.0);
    start.setDirection(normrel);
    return new HashMap.SimpleEntry<>(start, relative);
}
 
源代码11 项目: ProjectAres   文件: Core.java
public Core(CoreFactory definition, Match match) {
    super(definition, match);

    this.material = definition.getMaterial();

    Region region = definition.getRegion();

    final FiniteBlockRegion.Factory regionFactory = new FiniteBlockRegion.Factory(match.getMapInfo().proto);

    this.casingRegion = regionFactory.fromWorld(region, match.getWorld(), new MaterialPattern(this.material));
    if(this.casingRegion.blockVolume() == 0) {
        match.getServer().getLogger().warning("No casing material (" + this.material + ") found in core " + this.getName());
    }

    this.lavaRegion = regionFactory.fromWorld(region,
                                              match.getWorld(),
                                              new MaterialPattern(Material.LAVA, (byte) 0),
                                              new MaterialPattern(Material.STATIONARY_LAVA, (byte) 0));
    if(this.lavaRegion.blockVolume() == 0) {
        match.getServer().getLogger().warning("No lava found in core " + this.getName());
    }

    Vector min = new Vector(region.getBounds().minimum()).subtract(new Vector(15, 0, 15));
    min.setY(0);
    Vector max = new Vector(region.getBounds().maximum()).add(new Vector(15, 0, 15));
    max.setY(region.getBounds().minimum().getY() - definition.getLeakLevel());
    this.leakRegion = new CuboidRegion(min, max);
    this.breakers = new HashMap<>();
}
 
源代码12 项目: HoloAPI   文件: HologramImpl.java
@Override
public void move(Player observer, Vector to) {
    checkNotNull(observer, "The Player object in HologramImpl#move(Player, Vector) is null");
    checkNotNull(to, "The Vector object in HologramImpl#move(Player, Vector) is null");
    Vector loc = to.clone();
    for (int index = 0; index < this.getTagCount(); index++) {
        this.moveTag(observer, index, loc);
        loc.setY(loc.getY() - Settings.VERTICAL_LINE_SPACING.getValue());
    }
    this.playerToLocationMap.put(IdentUtil.getIdentificationForAsString(observer), to);
}
 
源代码13 项目: civcraft   文件: CannonExplosionProjectile.java
public Vector getVectorBetween(Location to, Location from) {
	Vector dir = new Vector();
	
	dir.setX(to.getX() - from.getX());
	dir.setY(to.getY() - from.getY());
	dir.setZ(to.getZ() - from.getZ());

	return dir;
}
 
源代码14 项目: Hawk   文件: LagCompensator.java
@EventHandler
public void pistonExtend(BlockPistonExtendEvent e) {
    World world = e.getBlock().getWorld();
    BlockFace bf = e.getDirection();
    Vector offset = new Vector(0, 0, 0);
    switch (bf) {
        case UP:
            offset.setY(1);
            break;
        case DOWN:
            offset.setY(-1);
            break;
        case EAST:
            offset.setX(1);
            break;
        case WEST:
            offset.setX(-1);
            break;
        case NORTH:
            offset.setZ(-1);
            break;
        case SOUTH:
            offset.setZ(1);
    }

    long currTime = System.currentTimeMillis();

    pistonPushes.add(new PistonPush(world, e.getBlock().getLocation().toVector().add(offset), bf, currTime));

    for(Block b : e.getBlocks()) {
        pistonPushes.add(new PistonPush(world, b.getLocation().toVector().add(offset), bf, currTime));
    }
}
 
源代码15 项目: CardinalPGM   文件: ProximityInfo.java
public void setLocations(Set<Vector> locations) {
    this.locations = locations;
    if (horizontal) {
        for (Vector vec : this.locations) {
            vec.setY(0);
        }
    }
}
 
源代码16 项目: Skript   文件: VectorMath.java
public static Vector rotZ(Vector vector, double angle) {
	double sin = Math.sin(angle * DEG_TO_RAD);
	double cos = Math.cos(angle * DEG_TO_RAD);
	Vector vx = new Vector(cos, -sin, 0);
	Vector vy = new Vector(sin, cos, 0);
	Vector clone = vector.clone();
	vector.setX(clone.dot(vx));
	vector.setY(clone.dot(vy));
	return vector;
}
 
源代码17 项目: Sentinel   文件: SentinelWeaponHelper.java
/**
 * Knocks a target back from damage received (for hacked-in damage applications when required by config).
 */
public void knockback(LivingEntity entity) {
    Vector relative = entity.getLocation().toVector().subtract(getLivingEntity().getLocation().toVector());
    if (relative.lengthSquared() > 0) {
        relative = relative.normalize();
    }
    relative.setY(0.75);
    relative.multiply(0.5 / Math.max(1.0, entity.getVelocity().length()));
    entity.setVelocity(entity.getVelocity().multiply(0.25).add(relative));
    if (SentinelPlugin.debugMe) {
        debug("applied knockback velocity adder of " + relative);
    }
}
 
源代码18 项目: PGM   文件: BlockDropsMatchModule.java
/**
 * This is not an event handler. It is called explicitly by BlockTransformListener after all event
 * handlers have been called.
 */
@SuppressWarnings("deprecation")
public void doBlockDrops(final BlockTransformEvent event) {
  if (!causesDrops(event.getCause())) {
    return;
  }

  final BlockDrops drops = event.getDrops();
  if (drops != null) {
    event.setCancelled(true);
    final BlockState oldState = event.getOldState();
    final BlockState newState = event.getNewState();
    final Block block = event.getOldState().getBlock();
    final int newTypeId = newState.getTypeId();
    final byte newData = newState.getRawData();

    block.setTypeIdAndData(newTypeId, newData, true);

    if (event.getCause() instanceof EntityExplodeEvent) {
      EntityExplodeEvent explodeEvent = (EntityExplodeEvent) event.getCause();
      final float yield = explodeEvent.getYield();

      if (drops.fallChance != null
          && oldState.getType().isBlock()
          && oldState.getType() != Material.AIR
          && match.getRandom().nextFloat() < drops.fallChance) {

        FallingBlock fallingBlock =
            match
                .getWorld()
                .spawnFallingBlock(
                    block.getLocation(),
                    event.getOldState().getType(),
                    event.getOldState().getRawData());
        fallingBlock.setDropItem(false);

        if (drops.landChance != null && match.getRandom().nextFloat() >= drops.landChance) {
          this.fallingBlocksThatWillNotLand.add(fallingBlock);
        }

        Vector v = fallingBlock.getLocation().subtract(explodeEvent.getLocation()).toVector();
        double distance = v.length();
        v.normalize().multiply(BASE_FALL_SPEED * drops.fallSpeed / Math.max(1d, distance));

        // A very simple deflection model. Check for a solid
        // neighbor block and "bounce" the velocity off of it.
        Block west = block.getRelative(BlockFace.WEST);
        Block east = block.getRelative(BlockFace.EAST);
        Block down = block.getRelative(BlockFace.DOWN);
        Block up = block.getRelative(BlockFace.UP);
        Block north = block.getRelative(BlockFace.NORTH);
        Block south = block.getRelative(BlockFace.SOUTH);

        if ((v.getX() < 0 && west != null && west.getType().isSolid())
            || v.getX() > 0 && east != null && east.getType().isSolid()) {
          v.setX(-v.getX());
        }

        if ((v.getY() < 0 && down != null && down.getType().isSolid())
            || v.getY() > 0 && up != null && up.getType().isSolid()) {
          v.setY(-v.getY());
        }

        if ((v.getZ() < 0 && north != null && north.getType().isSolid())
            || v.getZ() > 0 && south != null && south.getType().isSolid()) {
          v.setZ(-v.getZ());
        }

        fallingBlock.setVelocity(v);
      }

      // Defer item drops so the explosion doesn't destroy them
      match
          .getExecutor(MatchScope.RUNNING)
          .execute(() -> dropItems(drops, newState.getLocation(), yield));
    } else {
      MatchPlayer player = ParticipantBlockTransformEvent.getParticipant(event);
      if (player == null
          || player.getBukkit().getGameMode()
              != GameMode.CREATIVE) { // Don't drop items in creative mode
        dropItems(drops, newState.getLocation(), 1d);
        dropExperience(drops, newState.getLocation());
      }
    }
  }
}
 
源代码19 项目: civcraft   文件: PlayerListener.java
private void setModifiedMovementSpeed(Player player) {
	/* Change move speed based on armor. */
	double speed = CivSettings.normal_speed;
	
	/* Set speed from armor. */
	if (Unit.isWearingFullComposite(player)) {
		speed *= CivSettings.T4_leather_speed;
	}
	
	if (Unit.isWearingFullHardened(player)) {
		speed *= CivSettings.T3_leather_speed;
	}
	
	if (Unit.isWearingFullRefined(player)) {
		speed *= CivSettings.T2_leather_speed;
	}
	
	if (Unit.isWearingFullBasicLeather(player)) {
		speed *= CivSettings.T1_leather_speed;
	}
	
	if (Unit.isWearingAnyIron(player)) {
		speed *= CivSettings.T1_metal_speed;
	}
	
	if (Unit.isWearingAnyChain(player)) {
		speed *= CivSettings.T2_metal_speed;
	}
	
	if (Unit.isWearingAnyGold(player)) {
		speed *= CivSettings.T3_metal_speed;
	}
	
	if (Unit.isWearingAnyDiamond(player)) {
		speed *= CivSettings.T4_metal_speed;
	}
	
	Resident resident = CivGlobal.getResident(player);
	if (resident != null && resident.isOnRoad()) {	
		if (player.getVehicle() != null && player.getVehicle().getType().equals(EntityType.HORSE)) {
			Vector vec = player.getVehicle().getVelocity();
			double yComp = vec.getY();
			
			vec.multiply(Road.ROAD_HORSE_SPEED);
			vec.setY(yComp); /* Do not multiply y velocity. */
			
			player.getVehicle().setVelocity(vec);
		} else {
			speed *= Road.ROAD_PLAYER_SPEED;
		}
	}
	
	player.setWalkSpeed((float) Math.min(1.0f, speed));
}
 
@EventHandler(ignoreCancelled = true)
public void fixEntityDamage(EntityDamageByEntityEvent event) {
    Entity projectile = event.getDamager();
    if(projectile.hasMetadata("customProjectile")) {

        // If the custom projectile replaced an arrow, recreate some effects specific to arrows
        if(projectile.hasMetadata("damage")) {
            boolean critical = projectile.getMetadata("critical").get(0).asBoolean();
            int knockback = projectile.getMetadata("knockback").get(0).asInt();
            double damage = projectile.getMetadata("damage").get(0).asDouble();
            double speed = projectile.getVelocity().length();

            // Reproduce the damage calculation from nms.EntityArrow with the addition of our modifier
            int finalDamage = (int) Math.ceil(speed * damage * this.velocityMod);
            if(critical) {
                finalDamage += random.nextInt(finalDamage / 2 + 2);
            }
            event.setDamage(finalDamage);

            // Flame arrows - target burns for 5 seconds always
            if(projectile.getFireTicks() > 0) {
                event.getEntity().setFireTicks(100);
            }

            // Reproduce the knockback calculation for punch bows
            if(knockback > 0) {
                Vector projectileVelocity = projectile.getVelocity();
                double horizontalSpeed = Math.sqrt(projectileVelocity.getX() * projectileVelocity.getX() +
                                                   projectileVelocity.getZ() * projectileVelocity.getZ());
                Vector velocity = event.getEntity().getVelocity();
                velocity.setX(velocity.getX() + projectileVelocity.getX() * knockback * 0.6 / horizontalSpeed);
                velocity.setY(velocity.getY() + 0.1);
                velocity.setZ(velocity.getZ() + projectileVelocity.getZ() * knockback * 0.6 / horizontalSpeed);
                event.getEntity().setVelocity(velocity);
            }
        }

        // Apply any potion effects attached to the projectile
        if(event.getEntity() instanceof LivingEntity) {
            for(PotionEffect potionEffect : this.potionEffects) {
                ((LivingEntity) event.getEntity()).addPotionEffect(potionEffect);
            }
        }
    }
}