Java Code Examples for org.bukkit.util.Vector#setX()
The following examples show how to use
org.bukkit.util.Vector#setX() .
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: Scout.java From AnnihilationPro with MIT License | 6 votes |
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); }
Example 2
Source File: AnimatedBallEffect.java From EffectLib with MIT License | 6 votes |
@Override public void onRun() { Vector vector = new Vector(); Location location = getLocation(); 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); } }
Example 3
Source File: WrappedBlock8.java From Hawk with GNU General Public License v3.0 | 6 votes |
@Override public Vector getFlowDirection() { Vector vec = new Vector(); Vec3D nmsVec = new Vec3D(0, 0, 0); Entity dummy = null; if(!block.getMaterial().isLiquid()) return vec; BlockPosition bPos = new BlockPosition(obBlock.getX(), obBlock.getY(), obBlock.getZ()); //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; } } nmsVec = block.a(((CraftWorld) obBlock.getWorld()).getHandle(), bPos, dummy, nmsVec); vec.setX(nmsVec.a); vec.setY(nmsVec.b); vec.setZ(nmsVec.c); return vec; }
Example 4
Source File: MathPlus.java From Hawk with GNU General Public License v3.0 | 6 votes |
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)); } }
Example 5
Source File: GridEffect.java From EffectLib with MIT License | 6 votes |
@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); } } }
Example 6
Source File: FiniteBlockRegion.java From ProjectAres with GNU Affero General Public License v3.0 | 6 votes |
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); }
Example 7
Source File: CannonExplosionProjectile.java From civcraft with GNU General Public License v2.0 | 5 votes |
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; }
Example 8
Source File: LagCompensator.java From Hawk with GNU General Public License v3.0 | 5 votes |
@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)); } }
Example 9
Source File: MathPlus.java From Hawk with GNU General Public License v3.0 | 5 votes |
public static Vector getDirection(float yaw, float pitch) { Vector vector = new Vector(); float rotX = (float)Math.toRadians(yaw); float rotY = (float)Math.toRadians(pitch); vector.setY(-sin(rotY)); double xz = cos(rotY); vector.setX(-xz * sin(rotX)); vector.setZ(xz * cos(rotX)); return vector; }
Example 10
Source File: VectorMath.java From Skript with GNU General Public License v3.0 | 5 votes |
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; }
Example 11
Source File: VectorMath.java From Skript with GNU General Public License v3.0 | 5 votes |
public static Vector rotY(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, 0, sin); Vector vz = new Vector(-sin, 0, cos); Vector clone = vector.clone(); vector.setX(clone.dot(vx)); vector.setZ(clone.dot(vz)); return vector; }
Example 12
Source File: PortalTransform.java From ProjectAres with GNU Affero General Public License v3.0 | 4 votes |
private Vector mutate(Vector v) { v.setX(x.applyAsDouble(v.getX())); v.setY(y.applyAsDouble(v.getY())); v.setZ(z.applyAsDouble(v.getZ())); return v; }
Example 13
Source File: GrapplingHookListener.java From Slimefun4 with GNU General Public License v3.0 | 4 votes |
private void handleGrapplingHook(Arrow arrow) { if (arrow != null && arrow.isValid() && arrow.getShooter() instanceof Player) { Player p = (Player) arrow.getShooter(); GrapplingHookEntity hook = activeHooks.get(p.getUniqueId()); if (hook != null) { Location target = arrow.getLocation(); hook.drop(target); Vector velocity = new Vector(0.0, 0.2, 0.0); if (p.getLocation().distance(target) < 3.0) { if (target.getY() <= p.getLocation().getY()) { velocity = target.toVector().subtract(p.getLocation().toVector()); } } else { Location l = p.getLocation(); l.setY(l.getY() + 0.5); p.teleport(l); double g = -0.08; double d = target.distance(l); double t = d; double vX = (1.0 + 0.08 * t) * (target.getX() - l.getX()) / t; double vY = (1.0 + 0.04 * t) * (target.getY() - l.getY()) / t - 0.5D * g * t; double vZ = (1.0 + 0.08 * t) * (target.getZ() - l.getZ()) / t; velocity = p.getVelocity(); velocity.setX(vX); velocity.setY(vY); velocity.setZ(vZ); } p.setVelocity(velocity); hook.remove(); Slimefun.runSync(() -> activeHooks.remove(p.getUniqueId()), 20L); } } }
Example 14
Source File: AxisAlignedBB.java From Transport-Pipes with MIT License | 4 votes |
public TPDirection performRayIntersection(Vector ray, Vector rayOrigin, BlockLocation aabbBlockLoc) { //optimization to decrease division operations Vector dirFrac = new Vector(1d / ray.getX(), 1d / ray.getY(), 1d / ray.getZ()); double t1 = (min.getDoubleX() + aabbBlockLoc.getX() - rayOrigin.getX()) * dirFrac.getX(); double t2 = (max.getDoubleX() + aabbBlockLoc.getX() - rayOrigin.getX()) * dirFrac.getX(); double t3 = (min.getDoubleY() + aabbBlockLoc.getY() - rayOrigin.getY()) * dirFrac.getY(); double t4 = (max.getDoubleY() + aabbBlockLoc.getY() - rayOrigin.getY()) * dirFrac.getY(); double t5 = (min.getDoubleZ() + aabbBlockLoc.getZ() - rayOrigin.getZ()) * dirFrac.getZ(); double t6 = (max.getDoubleZ() + aabbBlockLoc.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(aabbBlockLoc); Vector faceMiddle = new Vector(); for (TPDirection tpDir : TPDirection.values()) { faceMiddle.setX(aabbMiddle.getX() + tpDir.getX() * (getWidth()) / 2d); faceMiddle.setY(aabbMiddle.getY() + tpDir.getY() * (getHeight()) / 2d); faceMiddle.setZ(aabbMiddle.getZ() + tpDir.getZ() * (getDepth()) / 2d); double v = 1d; if (tpDir.getX() != 0) { v = Math.abs(intersectionPoint.getX() - faceMiddle.getX()); } if (tpDir.getY() != 0) { v = Math.abs(intersectionPoint.getY() - faceMiddle.getY()); } if (tpDir.getZ() != 0) { v = Math.abs(intersectionPoint.getZ() - faceMiddle.getZ()); } if (v <= 0.001d) { return tpDir; } } return null; }
Example 15
Source File: BlockDropsMatchModule.java From ProjectAres with GNU Affero General Public License v3.0 | 4 votes |
/** * 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); boolean explosion = false; MatchPlayer player = ParticipantBlockTransformEvent.getParticipant(event); if(event.getCause() instanceof EntityExplodeEvent) { EntityExplodeEvent explodeEvent = (EntityExplodeEvent) event.getCause(); explosion = true; if(drops.fallChance != null && oldState.getType().isBlock() && oldState.getType() != Material.AIR && this.getMatch().getRandom().nextFloat() < drops.fallChance) { FallingBlock fallingBlock = event.getOldState().spawnFallingBlock(); fallingBlock.setDropItem(false); if(drops.landChance != null && this.getMatch().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 && Materials.isColliding(west.getType())) || v.getX() > 0 && east != null && Materials.isColliding(east.getType())) { v.setX(-v.getX()); } if((v.getY() < 0 && down != null && Materials.isColliding(down.getType())) || v.getY() > 0 && up != null && Materials.isColliding(up.getType())) { v.setY(-v.getY()); } if((v.getZ() < 0 && north != null && Materials.isColliding(north.getType())) || v.getZ() > 0 && south != null && Materials.isColliding(south.getType())) { v.setZ(-v.getZ()); } fallingBlock.setVelocity(v); } } dropObjects(drops, player, newState.getLocation(), 1d, explosion); } }
Example 16
Source File: ModifyBowProjectileMatchModule.java From PGM with GNU Affero General Public License v3.0 | 4 votes |
@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 += match.getRandom().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); } // If the projectile is not an arrow, play an impact sound. if (event.getEntity() instanceof Player && (projectile instanceof Projectile && !(projectile instanceof Arrow))) { Projectile customProjectile = (Projectile) projectile; if (customProjectile.getShooter() instanceof Player) { Player bukkitShooter = (Player) customProjectile.getShooter(); MatchPlayer shooter = match.getPlayer(bukkitShooter); if (shooter != null && event.getEntity() != null) { shooter.playSound(PROJECTILE_SOUND); } } } } // Apply any potion effects attached to the projectile if (event.getEntity() instanceof LivingEntity) { for (PotionEffect potionEffect : this.potionEffects) { ((LivingEntity) event.getEntity()).addPotionEffect(potionEffect); } } } }
Example 17
Source File: ModifyBowProjectileMatchModule.java From ProjectAres with GNU Affero General Public License v3.0 | 4 votes |
@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); } } } }
Example 18
Source File: Strafe.java From Hawk with GNU General Public License v3.0 | 4 votes |
@Override protected void check(MoveEvent e) { HawkPlayer pp = e.getHawkPlayer(); boolean bounced = bouncedSet.contains(pp.getUuid()); boolean collidingHorizontally = collidingHorizontally(e); Block footBlock = ServerUtils.getBlockAsync(pp.getPlayer().getLocation().clone().add(0, -0.1, 0)); if(footBlock == null) return; long ticksSinceIdle = pp.getCurrentTick() - lastIdleTick.getOrDefault(pp.getUuid(), pp.getCurrentTick()); double friction = e.getFriction(); //A really rough check to handle sneaking on edge of blocks. boolean sneakEdge = pp.isSneaking() && !WrappedBlock.getWrappedBlock(footBlock, pp.getClientVersion()).isSolid() && e.isOnGround(); Vector prevVelocity = pp.getVelocity().clone(); if(e.hasHitSlowdown()) { prevVelocity.multiply(0.6); } Set<Material> collidedMats = WrappedEntity.getWrappedEntity(e.getPlayer()).getCollisionBox(e.getFrom().toVector()).getMaterials(pp.getWorld()); if(collidedMats.contains(Material.SOUL_SAND)) { prevVelocity.multiply(0.4); } boolean nearLiquid = testLiquid(collidedMats); if(Math.abs(prevVelocity.getX() * friction) < 0.005) { prevVelocity.setX(0); } if(Math.abs(prevVelocity.getZ() * friction) < 0.005) { prevVelocity.setZ(0); } double dX = e.getTo().getX() - e.getFrom().getX(); double dZ = e.getTo().getZ() - e.getFrom().getZ(); dX /= friction; dZ /= friction; dX -= prevVelocity.getX(); dZ -= prevVelocity.getZ(); Vector accelDir = new Vector(dX, 0, dZ); Vector yaw = MathPlus.getDirection(e.getTo().getYaw(), 0); //Return if player hasn't sent at least 2 moves in a row. Let Speed handle any bypasses for this. if(e.hasTeleported() || e.hasAcceptedKnockback() || bounced || collidingHorizontally || !e.isUpdatePos() || sneakEdge || e.isJump() || ticksSinceIdle <= 2 || nearLiquid || //TODO get rid of e.isJump() from here and actually try to handle it pp.getCurrentTick() - pp.getLastVelocityAcceptTick() == 1 || collidedMats.contains(Material.LADDER) || collidedMats.contains(Material.VINE)) { prepareNextMove(e, pp, pp.getCurrentTick()); return; } //You aren't pressing a WASD key if(accelDir.lengthSquared() < 0.000001) { prepareNextMove(e, pp, pp.getCurrentTick()); return; } boolean vectorDir = accelDir.clone().crossProduct(yaw).dot(new Vector(0, 1, 0)) >= 0; double angle = (vectorDir ? 1 : -1) * MathPlus.angle(accelDir, yaw); if(!isValidStrafe(angle)) { Debug.broadcastMessage(pp.isSneaking()); punishAndTryRubberband(pp, e); } else reward(pp); prepareNextMove(e, pp, pp.getCurrentTick()); }
Example 19
Source File: Location.java From Kettle with GNU General Public License v3.0 | 4 votes |
/** * Gets a unit-vector pointing in the direction that this Location is * facing. * * @return a vector pointing the direction of this location's {@link * #getPitch() pitch} and {@link #getYaw() yaw} */ public Vector getDirection() { Vector vector = new Vector(); double rotX = this.getYaw(); double rotY = this.getPitch(); vector.setY(-Math.sin(Math.toRadians(rotY))); double xz = Math.cos(Math.toRadians(rotY)); vector.setX(-xz * Math.sin(Math.toRadians(rotX))); vector.setZ(xz * Math.cos(Math.toRadians(rotX))); return vector; }
Example 20
Source File: BlockDropsMatchModule.java From PGM with GNU Affero General Public License v3.0 | 4 votes |
/** * 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()); } } } }