当前位置: 首页>>代码示例>>Java>>正文


Java Vector.setX方法代码示例

本文整理汇总了Java中org.bukkit.util.Vector.setX方法的典型用法代码示例。如果您正苦于以下问题:Java Vector.setX方法的具体用法?Java Vector.setX怎么用?Java Vector.setX使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.bukkit.util.Vector的用法示例。


在下文中一共展示了Vector.setX方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onItemDamage

import org.bukkit.util.Vector; //导入方法依赖的package包/类
@EventHandler
public void onItemDamage(EntityDamageEvent event) {
    if (event.getEntityType() == EntityType.DROPPED_ITEM && (event.getCause() == DamageCause.LAVA || event.getCause() == DamageCause.FIRE_TICK || event.getCause() == DamageCause.FIRE)) {
        Vector v = Vector.getRandom().normalize();
        v = v.setX(v.getX() - 0.5f);
        v = v.setZ(v.getZ() - 0.5f);
        v = v.multiply(0.35);
        if (v.getX() > 0 && v.getX() < 0.10)
            v.setX(0.10);
        if (v.getZ() > 0 && v.getZ() < 0.10)
            v.setZ(0.10);
        if (v.getX() < 0 && v.getX() > -0.10)
            v.setX(-0.10);
        if (v.getZ() < 0 && v.getZ() > -0.10)
            v.setZ(-0.10);
        v.setY(0.3);
        event.getEntity().setVelocity(v);
        event.setCancelled(true);
        RScheduler.schedule(plugin, () -> {
            event.getEntity().setFireTicks(0);
        }, RTicks.seconds(1));
    }
    if (event.getEntityType() == EntityType.ARMOR_STAND && (event.getCause() == DamageCause.LAVA || event.getCause() == DamageCause.FIRE_TICK || event.getCause() == DamageCause.FIRE)) {
        event.setCancelled(true);
    }
}
 
开发者ID:edasaki,项目名称:ZentrelaRPG,代码行数:27,代码来源:EnvironmentManager.java

示例2: getVectorsNormal

import org.bukkit.util.Vector; //导入方法依赖的package包/类
private ArrayList<Vector> getVectorsNormal(LivingEntity e) {
    ArrayList<Vector> vectors = new ArrayList<Vector>();
    Vector v = e.getEyeLocation().getDirection().normalize();
    v.setY(0);
    vectors.add(v);
    double z = v.getZ();
    double x = v.getX();
    double radians = Math.atan(z / x);
    if (x < 0)
        radians += Math.PI;
    for (int k = 1; k < 4; k++) {
        Vector v2 = new Vector();
        v2.setY(v.getY());
        v2.setX(Math.cos(radians + k * Math.PI / 2));
        v2.setZ(Math.sin(radians + k * Math.PI / 2));
        vectors.add(v2.normalize());
    }
    return vectors;
}
 
开发者ID:edasaki,项目名称:ZentrelaRPG,代码行数:20,代码来源:SentinelBossGenerator.java

示例3: onRun

import org.bukkit.util.Vector; //导入方法依赖的package包/类
@Override
public void onRun() {
    Vector vector = new Vector();
    Location location = getLocation();
    location.add(0, -1, 0);
    for (int i = 0; i < particlesPerIteration; i++) {
        step++;

        float t = (MathUtils.PI / particles) * step;
        float r = MathUtils.sin(t) * size;
        float s = 2 * MathUtils.PI * t;

        vector.setX(xFactor * r * MathUtils.cos(s) + xOffset);
        vector.setZ(zFactor * r * MathUtils.sin(s) + zOffset);
        vector.setY(yFactor * size * MathUtils.cos(t) + yOffset);

        VectorUtils.rotateVector(vector, xRotation, yRotation, zRotation);

        display(particle, location.add(vector));
        location.subtract(vector);
    }
}
 
开发者ID:edasaki,项目名称:ZentrelaRPG,代码行数:23,代码来源:SwirlyEffect.java

示例4: boost

import org.bukkit.util.Vector; //导入方法依赖的package包/类
private boolean boost(Entity source, Entity receiver) {
    if (!(source instanceof Player) || !(receiver instanceof Player) || !isPlaying((Player) source) || !isPlaying((Player) receiver))
        return false;
    receiver.sendMessage(ChatColor.GREEN + "Whoosh!");
    Vector toSender = source.getVelocity().subtract(receiver.getVelocity());
    toSender.setY(0);
    double distance = toSender.length();
    if(distance > 0) {
        toSender.multiply(1D / distance);
    } else {
        float yaw = source.getLocation().getYaw();
        toSender.setX(-1 * Math.sin(toRad(yaw)));
        toSender.setZ(Math.cos(toRad(yaw)));
    }
    toSender.multiply(2.5D);
    toSender.setY(2);
    receiver.setVelocity(toSender);
    return true;
}
 
开发者ID:Kneesnap,项目名称:Kineticraft,代码行数:20,代码来源:Boost.java

示例5: getVectors

import org.bukkit.util.Vector; //导入方法依赖的package包/类
public ArrayList<Vector> getVectors(Entity e) {
    ArrayList<Vector> vectors = new ArrayList<Vector>();
    Vector v = e.getLocation().getDirection().normalize();
    v.setY(0);
    vectors.add(v);
    double z = v.getZ();
    double x = v.getX();
    double radians = Math.atan(z / x);
    if (x < 0)
        radians += Math.PI;
    for (int k = 1; k < 24; k++) {
        Vector v2 = new Vector();
        v2.setY(v.getY());
        v2.setX(Math.cos(radians + k * Math.PI / 12));
        v2.setZ(Math.sin(radians + k * Math.PI / 12));
        vectors.add(v2.normalize());
    }
    return vectors;
}
 
开发者ID:edasaki,项目名称:ZentrelaRPG,代码行数:20,代码来源:SlimeKingBurstSpell.java

示例6: pullEntityToLocation

import org.bukkit.util.Vector; //导入方法依赖的package包/类
public void pullEntityToLocation(Entity e, Location loc) {
    Location entityLoc = e.getLocation();
    entityLoc.setY(entityLoc.getY() + 0.5D);
    e.teleport(entityLoc);
    double g = -0.08D;
    if (loc.getWorld() != entityLoc.getWorld())
        return;
    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);
    e.setFallDistance(0f);
}
 
开发者ID:edasaki,项目名称:ZentrelaRPG,代码行数:20,代码来源:GrappleManager.java

示例7: onPlayerJump

import org.bukkit.util.Vector; //导入方法依赖的package包/类
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerJump(PlayerMoveEvent event) {
    Player player = event.getPlayer();

    if (!InventoryManager.playerIsLoaded(player)) {
        return;
    }

    Vector velocity = player.getVelocity();
    Modifier jumpModifier = ItemManager.getModifier(player, ItemStat.StatType.JUMP);

    if (jumpModifier.getBonus() == 0 && jumpModifier.getMultiplier() == 1) {
        return;
    }

    // === START: Magic constants ===
    if (velocity.getY() == 0.41999998688697815D) {
        double jump = (1.5 + Math.sqrt(jumpModifier.getBonus())) * jumpModifier.getMultiplier();
        Vector moveDirection = event.getTo().toVector().subtract(event.getFrom().toVector());
        velocity.setX(moveDirection.getX() * jump * player.getWalkSpeed());
        velocity.setY(velocity.getY() * jump / 1.5);
        velocity.setZ(moveDirection.getZ() * jump * player.getWalkSpeed());
        player.setVelocity(velocity);
    }
    // === END: Magic constants ===
}
 
开发者ID:EndlessCodeGroup,项目名称:RPGInventory,代码行数:27,代码来源:ItemListener.java

示例8: getVectors

import org.bukkit.util.Vector; //导入方法依赖的package包/类
public ArrayList<Vector> getVectors(Player p) {
    ArrayList<Vector> vectors = new ArrayList<Vector>();
    Vector v = p.getEyeLocation().getDirection().normalize();
    v.setY(0);
    vectors.add(v);
    double z = v.getZ();
    double x = v.getX();
    double radians = Math.atan(z / x);
    if (x < 0)
        radians += Math.PI;
    for (int k = 1; k < 24; k++) {
        Vector v2 = new Vector();
        v2.setY(v.getY());
        v2.setX(Math.cos(radians + k * Math.PI / 12));
        v2.setZ(Math.sin(radians + k * Math.PI / 12));
        vectors.add(v2.normalize());
    }
    return vectors;
}
 
开发者ID:edasaki,项目名称:ZentrelaRPG,代码行数:20,代码来源:HyperBody.java

示例9: repellExpOrb

import org.bukkit.util.Vector; //导入方法依赖的package包/类
final void repellExpOrb(final Player player, final ExperienceOrb orb) {
	final Location pLoc = player.getLocation();
	final Location oLoc = orb.getLocation();
	final Vector dir = oLoc.toVector().subtract(pLoc.toVector());
	final double dx = Math.abs(dir.getX());
	final double dz = Math.abs(dir.getZ());
	if ( (dx == 0.0) && (dz == 0.0)){
		// Special case probably never happens
		dir.setX(0.001);
	}
	if ((dx < 3.0) && (dz < 3.0)){
		final Vector nDir = dir.normalize();
		final Vector newV = nDir.clone().multiply(0.3);
		newV.setY(0);
		orb.setVelocity(newV);
		if ((dx < 1.0) && (dz < 1.0)){
			// maybe oLoc
			orb.teleport(oLoc.clone().add(nDir.multiply(1.0)), TeleportCause.PLUGIN);
		} 
		if ((dx < 0.5) && (dz < 0.5)){
			orb.remove();
		} 
	} 
}
 
开发者ID:smessie,项目名称:SkyWarsReloaded,代码行数:25,代码来源:SpectatorListener.java

示例10: onBlockBreak

import org.bukkit.util.Vector; //导入方法依赖的package包/类
@EventHandler(ignoreCancelled = false, priority = EventPriority.MONITOR)
public void onBlockBreak(BlockPlaceEvent event) {
    if (event.isCancelled()) {
        Player player = event.getPlayer();
        if (player.getGameMode() == GameMode.CREATIVE || player.getAllowFlight()) {
            return;
        }

        Block block = event.getBlockPlaced();
        if (block.getType().isSolid() && !(block.getState() instanceof Sign)) {
            int playerY = player.getLocation().getBlockY();
            int blockY = block.getLocation().getBlockY();
            if (playerY > blockY) {
                Vector vector = player.getVelocity();
                vector.setX(-0.1);
                vector.setZ(-0.1);
                player.setVelocity(vector.setY(vector.getY() - 0.41999998688697815D)); // Magic number acquired from EntityLiving#bj()
            }
        }
    }
}
 
开发者ID:funkemunky,项目名称:HCFCore,代码行数:22,代码来源:BlockJumpGlitchFixListener.java

示例11: FiniteBlockRegion

import org.bukkit.util.Vector; //导入方法依赖的package包/类
public FiniteBlockRegion(Collection<BlockVector> positions) {
    this.positions = BlockVectorSet.of(positions);

    // calculate AABB
    final Vector min = new Vector(Double.MAX_VALUE);
    final Vector max = new Vector(-Double.MAX_VALUE);

    for(BlockVector pos : this.positions) {
        min.setX(Math.min(min.getX(), pos.getBlockX()));
        min.setY(Math.min(min.getY(), pos.getBlockY()));
        min.setZ(Math.min(min.getZ(), pos.getBlockZ()));

        max.setX(Math.max(max.getX(), pos.getBlockX() + 1));
        max.setY(Math.max(max.getY(), pos.getBlockY() + 1));
        max.setZ(Math.max(max.getZ(), pos.getBlockZ() + 1));
    }

    this.bounds = Cuboid.between(min, max);
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:20,代码来源:FiniteBlockRegion.java

示例12: dropItem

import org.bukkit.util.Vector; //导入方法依赖的package包/类
public void dropItem( ItemStack itemStack ) {
    float yaw = location.getYaw(), pitch = location.getPitch();
    Vector vector = new Vector( -Math.cos( pitch ) * Math.sin( yaw ), 0D, Math.cos( pitch ) * Math.sin( yaw ) ).multiply( 3D );
    vector.setX( Math.min( 2, vector.getX() ) );
    vector.setZ( Math.min( 2, vector.getZ() ) );
    this.getWorld().spawnItem( new Location( getWorld(),location.getX() + vector.getX(), location.getY(), location.getZ() + vector.getZ() ), itemStack );
}
 
开发者ID:lukas81298,项目名称:FlexMC,代码行数:8,代码来源:FlexPlayer.java

示例13: rayIntersection

import org.bukkit.util.Vector; //导入方法依赖的package包/类
public WrappedDirection rayIntersection(Vector ray, Vector rayOrigin, Location pipeBlockLoc) {

		//optimization to decrease division operations
		Vector dirFrac = new Vector(1d / ray.getX(), 1d / ray.getY(), 1d / ray.getZ());

		double t1 = (minx + pipeBlockLoc.getX() - rayOrigin.getX()) * dirFrac.getX();
		double t2 = (maxx + pipeBlockLoc.getX() - rayOrigin.getX()) * dirFrac.getX();
		double t3 = (miny + pipeBlockLoc.getY() - rayOrigin.getY()) * dirFrac.getY();
		double t4 = (maxy + pipeBlockLoc.getY() - rayOrigin.getY()) * dirFrac.getY();
		double t5 = (minz + pipeBlockLoc.getZ() - rayOrigin.getZ()) * dirFrac.getZ();
		double t6 = (maxz + pipeBlockLoc.getZ() - rayOrigin.getZ()) * dirFrac.getZ();

		double tMin = Math.max(Math.max(Math.min(t1, t2), Math.min(t3, t4)), Math.min(t5, t6));
		double tMax = Math.min(Math.min(Math.max(t1, t2), Math.max(t3, t4)), Math.max(t5, t6));

		//AABB is behind player
		if (tMax < 0) {
			return null;
		}

		//don't intersect
		if (tMin > tMax) {
			return null;
		}

		Vector intersectionPoint = rayOrigin.clone().add(ray.clone().multiply(tMin));

		Vector aabbMiddle = getAABBMiddle(pipeBlockLoc);
		Vector faceMiddle = new Vector();

		for (WrappedDirection pd : WrappedDirection.values()) {
			faceMiddle.setX(aabbMiddle.getX() + pd.getX() * (maxx - minx) / 2d);
			faceMiddle.setY(aabbMiddle.getY() + pd.getY() * (maxy - miny) / 2d);
			faceMiddle.setZ(aabbMiddle.getZ() + pd.getZ() * (maxz - minz) / 2d);
			double v = 1d;
			if (pd.getX() != 0) {
				v = Math.abs(intersectionPoint.getX() - faceMiddle.getX());
			}
			if (pd.getY() != 0) {
				v = Math.abs(intersectionPoint.getY() - faceMiddle.getY());
			}
			if (pd.getZ() != 0) {
				v = Math.abs(intersectionPoint.getZ() - faceMiddle.getZ());
			}
			if (v <= 0.001d) {
				return pd;
			}
		}

		return null;
	}
 
开发者ID:RoboTricker,项目名称:Transport-Pipes,代码行数:52,代码来源:AxisAlignedBB.java

示例14: cast

import org.bukkit.util.Vector; //导入方法依赖的package包/类
@Override
public boolean cast(final Player p, final PlayerDataRPG pd, int level) {
    int damage = pd.getDamage(true);
    int amount = 0;
    damage *= functions[1].applyAsDouble(level) / 100.0;
    amount = (int) functions[0].applyAsDouble(level);
    Location loc = p.getLocation().add(0, p.getEyeHeight() * 0.8, 0);
    loc.add(p.getLocation().getDirection().normalize().multiply(0.4));
    for (int count = 0; count < amount; count++) {
        final Item item = p.getWorld().dropItem(loc, new ItemStack(Material.FIREWORK_CHARGE));
        item.setMetadata(RMetadata.META_NO_PICKUP, new FixedMetadataValue(Spell.plugin, 0));
        //            ItemManager.attachLabel(item, ChatColor.BOLD + "= " + p.getName() + "'s Mine =");
        Spell.plugin.getInstance(DropManager.class).attachLabel(item, ChatColor.DARK_GRAY.toString() + ChatColor.ITALIC + p.getName());
        Vector dir = Vector.getRandom();
        dir.setX(dir.getX() - 0.5f);
        dir.setZ(dir.getZ() - 0.5f);
        dir = dir.normalize().multiply(Math.random() * 0.5 + 0.2);
        item.setVelocity(dir);
        final int fDamage = damage;
        RScheduler.schedule(Spell.plugin, new Runnable() {
            int tick = 1;
            ArrayList<Entity> hit = new ArrayList<Entity>();

            public void run() {
                if (item == null || !item.isValid())
                    return;
                hit.addAll(Spell.damageNearby(fDamage, p, item.getLocation(), 2.0, hit));
                if (hit.size() > 0) {
                    Spell.damageNearby(fDamage, p, item.getLocation(), 3, hit);
                    DropManager.removeLabel(item);
                    item.remove();
                    RParticles.show(ParticleEffect.EXPLOSION_LARGE, item.getLocation(), 5);
                }
                if (tick == 20) {
                    RParticles.show(ParticleEffect.CLOUD, item.getLocation().add(0, 0.1, 0));
                    DropManager.removeLabel(item);
                    item.remove();
                }
                tick++;
                if (tick <= 20)
                    RScheduler.schedule(Spell.plugin, this, (int) (Math.random() * 7 + 6));
            }
        }, 5);
    }
    Spell.notify(p, "You scatter a field of explosive mines.");
    return true;
}
 
开发者ID:edasaki,项目名称:ZentrelaRPG,代码行数:48,代码来源:Minefield.java

示例15: onEntityDamageByEntity

import org.bukkit.util.Vector; //导入方法依赖的package包/类
@EventHandler(priority = EventPriority.HIGHEST)
	public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
		if (!(event.getEntity() instanceof Player) || !(event.getDamager() instanceof Player)) {
			return;
		}

		if (event.isCancelled()) {
			return;
		}

		Player damaged = (Player) event.getEntity();
		Player damager = (Player) event.getDamager();
		
		if (damaged.getNoDamageTicks() > damaged.getMaximumNoDamageTicks() / 2D) {
			return;
		}
		
		Vector knockback = damaged.getLocation().toVector().subtract(damager.getLocation().toVector()).normalize();
		double horMultiplier = 1.1;
		double verMultiplier = 1.04;
		double sprintMultiplier = damager.isSprinting() ? 0.81D : 0.5D;
		double kbMultiplier = damager.getItemInHand() == null ? 0 : damager.getItemInHand().getEnchantmentLevel(Enchantment.KNOCKBACK) * 0.2D;
		@SuppressWarnings("deprecation")
		double airMultiplier = damaged.isOnGround() ? 1 : 0.94;

		knockback.setX((knockback.getX() * sprintMultiplier + kbMultiplier) * horMultiplier);
		knockback.setY(0.35D * airMultiplier * verMultiplier);
		knockback.setZ((knockback.getZ() * sprintMultiplier + kbMultiplier) * horMultiplier);
		
		try {
			// Send the velocity packet immediately instead of using setVelocity, which fixes the 'relog bug'
			Object entityPlayer = damaged.getClass().getMethod("getHandle").invoke(damaged);
			Object playerConnection = fieldPlayerConnection.get(entityPlayer);
			Object packet = packetVelocity.newInstance(damaged.getEntityId(), knockback.getX(), knockback.getY(), knockback.getZ());
			sendPacket.invoke(playerConnection, packet);
		} catch (SecurityException | IllegalArgumentException | IllegalAccessException | InvocationTargetException | NoSuchMethodException | InstantiationException e) {
			e.printStackTrace();
		}
		//Bukkit.getScheduler().scheduleSyncDelayedTask(core, new Runnable() {
			//public void run() {
				//double horMultiplier = KnockbackPatch.getInstance().getHorMultiplier();
				//double verMultiplier = KnockbackPatch.getInstance().getVerMultiplier();
				//double sprintMultiplier = damager.isSprinting() ? 0.8D : 0.5D;
				//double kbMultiplier = damager.getItemInHand() == null ? 0 : damager.getItemInHand().getEnchantmentLevel(Enchantment.KNOCKBACK) * 0.2D;
				//@SuppressWarnings("deprecation")
				//double airMultiplier = damaged.isOnGround() ? 1 : 0.8;
//
				//nockback.setX((knockback.getX() * sprintMultiplier + kbMultiplier) * horMultiplier);
				//knockback.setY(0.35D * airMultiplier * verMultiplier);
				//knockback.setZ((knockback.getZ() * sprintMultiplier + kbMultiplier) * horMultiplier);
				//
				//try {
			     	// Send the velocity packet immediately instead of using setVelocity, which fixes the 'relog bug'
				//	Object entityPlayer = damaged.getClass().getMethod("getHandle").invoke(damaged);
				//	Object playerConnection = fieldPlayerConnection.get(entityPlayer);
				//	Object packet = packetVelocity.newInstance(damaged.getEntityId(), knockback.getX(), knockback.getY(), knockback.getZ());
				//	sendPacket.invoke(playerConnection, packet);
		//		} catch (SecurityException | IllegalArgumentException | IllegalAccessException | InvocationTargetException | NoSuchMethodException | InstantiationException e) {
	//				e.printStackTrace();
			//	}
			//}
		//}, 2L);
	}
 
开发者ID:funkemunky,项目名称:HCFCore,代码行数:64,代码来源:KnockBackListener.java


注:本文中的org.bukkit.util.Vector.setX方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。