org.bukkit.util.Vector Java Examples
The following examples show how to use
org.bukkit.util.Vector.
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: MoveEvent.java From Hawk with GNU General Public License v3.0 | 6 votes |
private float computeFriction() { float friction = 0.91F; //patch some inconsistencies boolean teleportBug = pp.getCurrentTick() == pp.getLastTeleportAcceptTick(); boolean onGround = teleportBug ? pp.isOnGroundReally() : pp.isOnGround(); if (onGround) { Vector pos = pp.getPosition(); Block b = ServerUtils.getBlockAsync(new Location(pp.getWorld(), pos.getX(), pos.getY() - 1, pos.getZ())); if(b != null) { friction *= WrappedBlock.getWrappedBlock(b, pp.getClientVersion()).getSlipperiness(); } } return friction; }
Example #2
Source File: BigBangEffect.java From EffectLib with MIT License | 6 votes |
@Override public void onRun() { if (firework == null) { Builder b = FireworkEffect.builder().with(fireworkType); b.withColor(color).withColor(color2).withColor(color3); b.withFade(fadeColor); b.trail(true); firework = b.build(); } Location location = getLocation(); for (int i = 0; i < explosions; i++) { Vector v = RandomUtils.getRandomVector().multiply(radius); detonate(location, v); if (soundInterval != 0 && step % soundInterval == 0) { location.getWorld().playSound(location, sound, soundVolume, soundPitch); } } step++; }
Example #3
Source File: CoreMatchModule.java From PGM with GNU Affero General Public License v3.0 | 6 votes |
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void leakCheck(final BlockTransformEvent event) { if (event.getWorld() != this.match.getWorld()) return; if (event.getNewState().getType() == Material.STATIONARY_LAVA) { Vector blockVector = BlockVectors.center(event.getNewState()).toVector(); for (Core core : this.cores) { if (!core.hasLeaked() && core.getLeakRegion().contains(blockVector)) { // core has leaked core.markLeaked(); this.match.callEvent(new CoreLeakEvent(this.match, core, event.getNewState())); this.match.callEvent( new GoalCompleteEvent( this.match, core, core.getOwner(), false, core.getContributions())); } } } }
Example #4
Source File: Vectors.java From TabooLib with MIT License | 6 votes |
public static Item itemDrop(Player player, ItemStack itemStack, double bulletSpread, double radius) { Location location = player.getLocation().add(0.0D, 1.5D, 0.0D); Item item = player.getWorld().dropItem(location, itemStack); double yaw = Math.toRadians((double)(-player.getLocation().getYaw() - 90.0F)); double pitch = Math.toRadians((double)(-player.getLocation().getPitch())); double x; double y; double z; if (bulletSpread > 0.0D) { double[] spread = new double[]{1.0D, 1.0D, 1.0D}; IntStream.range(0, 3).forEach((t) -> { spread[t] = (Numbers.getRandom().nextDouble() - Numbers.getRandom().nextDouble()) * bulletSpread * 0.1D; }); x = Math.cos(pitch) * Math.cos(yaw) + spread[0]; y = Math.sin(pitch) + spread[1]; z = -Math.sin(yaw) * Math.cos(pitch) + spread[2]; } else { x = Math.cos(pitch) * Math.cos(yaw); y = Math.sin(pitch); z = -Math.sin(yaw) * Math.cos(pitch); } Vector dirVel = new Vector(x, y, z); item.setVelocity(dirVel.normalize().multiply(radius)); return item; }
Example #5
Source File: ControlPointBlockDisplay.java From ProjectAres with GNU Affero General Public License v3.0 | 6 votes |
protected void setProgress(Competitor controllingTeam, Competitor capturingTeam, double capturingProgress) { if(this.progressDisplayRegion != null) { Vector center = this.progressDisplayRegion.getBounds().center(); // capturingProgress can be zero, but it can never be one, so invert it to avoid // a zero-area SectorRegion that can cause glitchy rendering SectorRegion sectorRegion = new SectorRegion(center.getX(), center.getZ(), 0, (1 - capturingProgress) * 2 * Math.PI); for(BlockVector pos : this.progressDisplayRegion.getBlockVectors()) { if(sectorRegion.contains(pos)) { this.setBlock(pos, controllingTeam); } else { this.setBlock(pos, capturingTeam); } } } }
Example #6
Source File: GeneralizingListener.java From PGM with GNU Affero General Public License v3.0 | 6 votes |
/** * Modify the to location of the given event to prevent the movement and move the player so they * are standing on the center of the block at the from location. */ private static void resetPosition(final PlayerMoveEvent event) { Location newLoc; double yValue = event.getFrom().getY(); if (yValue <= 0 || event instanceof PlayerTeleportEvent) { newLoc = event.getFrom(); } else { newLoc = BlockVectors.center(event.getFrom()).subtract(new Vector(0, 0.5, 0)); if (newLoc.getBlock() != null) { switch (newLoc.getBlock().getType()) { case STEP: case WOOD_STEP: newLoc.add(new Vector(0, 0.5, 0)); break; default: break; } } } newLoc.setPitch(event.getTo().getPitch()); newLoc.setYaw(event.getTo().getYaw()); event.setCancelled(false); event.setTo(newLoc); }
Example #7
Source File: ParticleUtils.java From NovaGuilds with GNU General Public License v3.0 | 6 votes |
/** * Gets circle vectors * * @param radius radius of a circle * @param precision precision (amount of vectors) * @return list of vectors */ public static List<Vector> getCircleVectors(int radius, int precision) { final List<Vector> list = new ArrayList<>(); for(int i = 0; i < precision; i++) { double p1 = (i * Math.PI) / (precision / 2); double p2 = (((i == 0) ? precision : i - 1) * Math.PI) / (precision / 2); double x1 = Math.cos(p1) * radius; double x2 = Math.cos(p2) * radius; double z1 = Math.sin(p1) * radius; double z2 = Math.sin(p2) * radius; Vector vec = new Vector(x2 - x1, 0, z2 - z1); list.add(vec); } return list; }
Example #8
Source File: ConeEffect.java From EffectLib with MIT License | 6 votes |
@Override public void onRun() { Location location = getLocation(); for (int x = 0; x < particles; x++) { if (step > particlesCone) { step = 0; } if (randomize && step == 0) { rotation = RandomUtils.getRandomAngle(); } double angle = step * angularVelocity + rotation; float radius = step * radiusGrow; float length = step * lengthGrow; Vector v = new Vector(Math.cos(angle) * radius, length, Math.sin(angle) * radius); VectorUtils.rotateAroundAxisX(v, (location.getPitch() + 90) * MathUtils.degreesToRadians); VectorUtils.rotateAroundAxisY(v, -location.getYaw() * MathUtils.degreesToRadians); location.add(v); display(particle, location); location.subtract(v); step++; } }
Example #9
Source File: CoreMatchModule.java From ProjectAres with GNU Affero General Public License v3.0 | 6 votes |
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void leakCheck(final BlockTransformEvent event) { if(event.getWorld() != this.match.getWorld()) return; if(event.getNewState().getType() == Material.STATIONARY_LAVA) { Vector blockVector = BlockUtils.center(event.getNewState()).toVector(); for(Core core : this.cores) { if(!core.hasLeaked() && core.getLeakRegion().contains(blockVector)) { // core has leaked core.markLeaked(); this.match.getPluginManager().callEvent(new CoreLeakEvent(this.match, core, event.getNewState())); this.match.getPluginManager().callEvent(new GoalCompleteEvent(core, true, c -> false, c -> !c.equals(core.getOwner()), core.getContributions())); } } } }
Example #10
Source File: DoubleJumpKit.java From CardinalPGM with MIT License | 6 votes |
@EventHandler public void onPlayerToggleFly(PlayerToggleFlightEvent event) { if (!enabled) return; Player player = event.getPlayer(); if (!players.contains(player.getUniqueId()) || player.getExp() > 1.0f || !event.isFlying()) return; player.setAllowFlight(false); player.setExp(0.0f); event.setCancelled(true); Vector normal = player.getEyeLocation().getDirection(); normal.setY(0.75 + Math.max(normal.getY() * 0.5, 0)); normal.multiply(power / 2); event.getPlayer().setVelocity(normal); player.getWorld().playSound(player.getLocation(), Sound.ENTITY_ZOMBIE_INFECT, 0.5f, 1.8f); update(); }
Example #11
Source File: Rocket.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
public Vector getCenter() { int num = this.fireworks.size(); double totalX = 0; double totalY = 0; double totalZ = 0; for(Firework firework : this.fireworks) { totalX += firework.getLocation().getX(); totalY += firework.getLocation().getY(); totalZ += firework.getLocation().getZ(); } return new Vector(totalX / num, totalY / num, totalZ / num); }
Example #12
Source File: VanillaPipeModelEW.java From Transport-Pipes with MIT License | 5 votes |
private List<ArmorStandData> createSimplePipeASD(ItemStack block) { List<ArmorStandData> asd = new ArrayList<>(); asd.add(new ArmorStandData(new RelativeLocation(0.05f, -0.35f, 0.5f - 0.44f), false, new Vector(1, 0, 0), new Vector(0f, 0f, 0f), new Vector(-10f, 0f, 45f), null, ITEM_BLAZE_ROD)); asd.add(new ArmorStandData(new RelativeLocation(0.05f, -1.0307f, 0.5f - 0.86f), false, new Vector(1, 0, 0), new Vector(0f, 0f, 0f), new Vector(-10f, 0f, 135f), null, ITEM_BLAZE_ROD)); asd.add(new ArmorStandData(new RelativeLocation(0.05f, -1.0307f - 0.45f, 0.5f - 0.37f), false, new Vector(1, 0, 0), new Vector(0f, 0f, 0f), new Vector(-10f, 0f, 135f), null, ITEM_BLAZE_ROD)); asd.add(new ArmorStandData(new RelativeLocation(0.05f, -0.35f - 0.45f, 0.5f - 0.93f), false, new Vector(1, 0, 0), new Vector(0f, 0f, 0f), new Vector(-10f, 0f, 45f), null, ITEM_BLAZE_ROD)); asd.add(new ArmorStandData(new RelativeLocation(0.55f - 0.3f, -0.43f, 0.5f), true, new Vector(1, 0, 0), new Vector(0f, 0f, 0f), new Vector(0f, 0f, 0f), block, null)); asd.add(new ArmorStandData(new RelativeLocation(0.55f + 0.2f, -0.43f, 0.5f), true, new Vector(1, 0, 0), new Vector(0f, 0f, 0f), new Vector(0f, 0f, 0f), block, null)); return asd; }
Example #13
Source File: Vectors.java From Chimera with MIT License | 5 votes |
public static Vector rotateAroundYAxis(Vector vector, double angle) { double cos = cos(angle); double sin = sin(angle); double x = vector.getX() * cos + vector.getZ() * sin; double z = vector.getX() * -sin + vector.getZ() * cos; return vector.setX(x).setZ(z); }
Example #14
Source File: InteractWorldEvent.java From Hawk with GNU General Public License v3.0 | 5 votes |
public InteractWorldEvent(Player p, HawkPlayer pp, Location location, Material material, BlockFace blockFace, Vector cursorPosition, InteractionType interactionType, WrappedPacket packet) { super(p, pp, packet); this.location = location; this.material = material; this.blockFace = blockFace; this.interactionType = interactionType; this.cursorPosition = cursorPosition; }
Example #15
Source File: MoveEvent.java From Hawk with GNU General Public License v3.0 | 5 votes |
private boolean testStep() { Vector extraVelocity = pp.getVelocity().clone(); if(pp.isOnGroundReally()) extraVelocity.setY(-0.0784); else extraVelocity.setY((extraVelocity.getY() - 0.08) * 0.98); Location extraPos = pp.getPosition().toLocation(pp.getWorld()); extraPos.add(extraVelocity); float deltaY = (float) (getTo().getY() - getFrom().getY()); return AdjacentBlocks.onGroundReally(extraPos, extraVelocity.getY(), false, 0.001, pp) && onGroundReally && deltaY > 0.002F && deltaY <= 0.6F; }
Example #16
Source File: ControllableChickenEntity.java From EntityAPI with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void g(double x, double y, double z) { if (this.controllableEntity != null) { Vector velocity = this.controllableEntity.getMind().getAttribute(PushAttribute.class).call(this.controllableEntity, new Vector(x, y, z)).getPushVelocity(); x = velocity.getX(); y = velocity.getY(); z = velocity.getZ(); } super.g(x, y, z); }
Example #17
Source File: SphereEffect.java From EffectLib with MIT License | 5 votes |
@Override public void onRun() { if (radiusIncrease != 0) { radius += radiusIncrease; } Location location = getLocation(); location.add(0, yOffset, 0); for (int i = 0; i < particles; i++) { Vector vector = RandomUtils.getRandomVector().multiply(radius); location.add(vector); display(particle, location); location.subtract(vector); } }
Example #18
Source File: RegionDefinitionParser.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
@MethodParser public MirroredRegion mirror(Element el) throws InvalidXMLException { Vector normal = XMLUtils.parseVector(XMLUtils.getRequiredAttribute(el, "normal")); if(normal.lengthSquared() == 0) { throw new InvalidXMLException("normal must have a non-zero length", el); } Vector origin = XMLUtils.parseVector(el.getAttribute("origin"), new Vector()); return new MirroredRegion(regionParser.parseReferenceAndChildUnion(el), origin, normal); }
Example #19
Source File: ControllableSnowmanEntity.java From EntityAPI with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void g(double x, double y, double z) { if (this.controllableEntity != null) { Vector velocity = this.controllableEntity.getMind().getAttribute(PushAttribute.class).call(this.controllableEntity, new Vector(x, y, z)).getPushVelocity(); x = velocity.getX(); y = velocity.getY(); z = velocity.getZ(); } super.g(x, y, z); }
Example #20
Source File: EffVectorRotateAroundAnother.java From Skript with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings("null") @Override protected void execute(Event e) { Vector v2 = second.getSingle(e); Number d = degree.getSingle(e); if (v2 == null || d == null) return; for (Vector v1 : first.getArray(e)) VectorMath.rot(v1, v2, d.doubleValue()); }
Example #21
Source File: ControllableGhastEntity.java From EntityAPI with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void g(double x, double y, double z) { if (this.controllableEntity != null) { Vector velocity = this.controllableEntity.getMind().getAttribute(PushAttribute.class).call(this.controllableEntity, new Vector(x, y, z)).getPushVelocity(); x = velocity.getX(); y = velocity.getY(); z = velocity.getZ(); } super.g(x, y, z); }
Example #22
Source File: ControllableWitchEntity.java From EntityAPI with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void g(double x, double y, double z) { if (this.controllableEntity != null) { Vector velocity = this.controllableEntity.getMind().getAttribute(PushAttribute.class).call(this.controllableEntity, new Vector(x, y, z)).getPushVelocity(); x = velocity.getX(); y = velocity.getY(); z = velocity.getZ(); } super.g(x, y, z); }
Example #23
Source File: TransformedRegion.java From PGM with GNU Affero General Public License v3.0 | 5 votes |
/** * Generic bounding box transform - transform all 8 vertices and find the minimum bounding box * containing them. */ protected Bounds getTransformedBounds() { Vector[] oldVertices = this.region.getBounds().getVertices(); Vector[] newVertices = new Vector[8]; for (int i = 0; i < oldVertices.length; i++) { newVertices[i] = this.transform(oldVertices[i]); } return new Bounds(newVertices); }
Example #24
Source File: IntersectRegion.java From CardinalPGM with MIT License | 5 votes |
@Override public boolean contains(Vector vector) { for (int i = 0; i < regions.size(); i++) { for (int k = 0; k < regions.size(); k++) { if (i != k) { if (regions.get(i).contains(vector) && regions.get(k).contains(vector)) return true; } } } return false; }
Example #25
Source File: EventRuleContext.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
public EventRule getNearest(Vector pos) { EventRule nearest = null; double distance = Double.POSITIVE_INFINITY; for(EventRule rule : byPriority) { double d = pos.distanceSquared(rule.region().getBounds().center()); if(d < distance) { nearest = rule; distance = d; } } return nearest; }
Example #26
Source File: Net.java From PGM with GNU Affero General Public License v3.0 | 5 votes |
public Net( @Nullable String id, Region region, Filter captureFilter, Filter respawnFilter, @Nullable FeatureReference<TeamFactory> owner, double pointsPerCapture, boolean sticky, @Nullable Component denyMessage, @Nullable Component respawnMessage, @Nullable Post returnPost, ImmutableSet<FlagDefinition> capturableFlags, ImmutableSet<FlagDefinition> recoverableFlags, boolean respawnTogether, @Nullable Vector proximityLocation) { super(id); this.region = region; this.captureFilter = captureFilter; this.respawnFilter = respawnFilter; this.owner = owner; this.pointsPerCapture = pointsPerCapture; this.sticky = sticky; this.denyMessage = denyMessage; this.respawnMessage = respawnMessage; this.returnPost = returnPost; this.capturableFlags = capturableFlags; this.recoverableFlags = recoverableFlags; this.respawnTogether = respawnTogether; this.proximityLocation = proximityLocation; }
Example #27
Source File: ControllableHorseEntity.java From EntityAPI with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void g(double x, double y, double z) { if (this.controllableEntity != null) { Vector velocity = this.controllableEntity.getMind().getAttribute(PushAttribute.class).call(this.controllableEntity, new Vector(x, y, z)).getPushVelocity(); x = velocity.getX(); y = velocity.getY(); z = velocity.getZ(); } super.g(x, y, z); }
Example #28
Source File: SeismicAxe.java From Slimefun4 with GNU General Public License v3.0 | 5 votes |
private void pushEntity(Player p, Entity entity) { Vector vector = entity.getLocation().toVector().subtract(p.getLocation().toVector()).normalize(); vector.multiply(STRENGTH); vector.setY(0.9); entity.setVelocity(vector); if (entity.getType() != EntityType.PLAYER || p.getWorld().getPVP()) { EntityDamageByEntityEvent event = new EntityDamageByEntityEvent(p, entity, DamageCause.ENTITY_ATTACK, 6D); Bukkit.getPluginManager().callEvent(event); if (!event.isCancelled()) { ((LivingEntity) entity).damage(DAMAGE); } } }
Example #29
Source File: EntityInteractDirectionB.java From Hawk with GNU General Public License v3.0 | 5 votes |
private void processMove(MoveEvent e) { Player p = e.getPlayer(); UUID uuid = p.getUniqueId(); if(lastHitVecMap.containsKey(uuid)) { Vector headPos = e.getHawkPlayer().getHeadPosition(); Vector dirA = MathPlus.getDirection(e.getFrom().getYaw(), e.getTo().getPitch()); Vector dirB = lastHitVecMap.get(uuid).subtract(headPos).normalize(); //dirA.dot(dirB) should be close to 1.0 } lastHitVecMap.remove(uuid); }
Example #30
Source File: RegionParser.java From PGM with GNU Affero General Public License v3.0 | 5 votes |
@MethodParser("mirror") public MirroredRegion parseMirror(Element el) throws InvalidXMLException { Vector normal = XMLUtils.parseVector(XMLUtils.getRequiredAttribute(el, "normal")); if (normal.lengthSquared() == 0) { throw new InvalidXMLException("normal must have a non-zero length", el); } Vector origin = XMLUtils.parseVector(el.getAttribute("origin"), new Vector()); return new MirroredRegion(this.parseChildren(el), origin, normal); }