/** * Creates an instance with a random size. * * @param random the PRNG that will generate the size * @param location the location to generate in */ public GlowDungeon(Random random, Location location) { super(location, new Vector(9, HEIGHT, 9)); // inner dungeon shape is 5x5, 5x7 or 7x7 radiusX = random.nextInt(2) + MIN_RADIUS; radiusZ = random.nextInt(2) + MIN_RADIUS; sizeX = (radiusX << 1) + 1; sizeZ = (radiusZ << 1) + 1; loc = location; }
private int countAvailableBlocks(Vector from, Vector to, World world) { int n = 0; Vector target = to.subtract(from); int maxDistance = Math.max(Math.abs(target.getBlockY()), Math.max(Math.abs(target.getBlockX()), Math.abs(target.getBlockZ()))); float dx = (float) target.getX() / maxDistance; float dy = (float) target.getY() / maxDistance; float dz = (float) target.getZ() / maxDistance; for (int i = 0; i <= maxDistance; i++, n++) { target = from.clone() .add(new Vector((double) (0.5F + i * dx), 0.5F + i * dy, 0.5F + i * dz)); if (target.getBlockY() < 0 || target.getBlockY() > 255 || !overridables.contains(blockTypeAt( target.getBlockX(), target.getBlockY(), target.getBlockZ(), world))) { return n; } } return -1; }
protected Vector getVelocityFromMovement() { movement.setY(0); double mag = movement.getX() * movement.getX() + movement.getZ() * movement.getZ(); return new Vector(); movement.setX(movement.getX() / mag); movement.setZ(movement.getZ() / mag); Vector movement = this.movement.clone(); movement.multiply(mag); double yaw = Math.toRadians(location.getYaw()); double z = Math.sin(yaw); double x = Math.cos(yaw); movement.setX(movement.getZ() * x - movement.getX() * z); movement.setZ(movement.getX() * x + movement.getZ() * z); if (!isOnGround() || location.getBlock().isLiquid()) { movement.multiply(0.02); } else { this.slipMultiplier = ((GlowBlock) location.getBlock()).getMaterialValues() .getSlipperiness(); double slipperiness = slipMultiplier * 0.91; movement.multiply(0.1 * (0.1627714 / Math.pow(slipperiness, 3)));
/** * Creates a structure piece. * * @param random the PRNG that will choose the orientation * @param location the root location * @param size the size as a width-height-depth vector */ public GlowStructurePiece(Random random, Location location, Vector size) { orientation = getOrientationFromOrdinal(random.nextInt(4)); switch (orientation) { case EAST: case WEST: size = new Vector(size.getBlockZ(), size.getBlockY(), size.getBlockX()); break; default: break; } createNewBoundingBox(location, size); }
@Override public void decorate(World world, Random random, Chunk source) { if (random.nextInt(1000) == 0) { int x = (source.getX() << 4) + random.nextInt(16); int z = (source.getZ() << 4) + random.nextInt(16); int y = world.getHighestBlockYAt(x, z); GlowDesertWell well = new GlowDesertWell(new Location(world, x, y, z)); BlockStateDelegate delegate = new BlockStateDelegate(); if (well.generate(world, random, new StructureBoundingBox(new Vector(x - 15, 1, z - 15), new Vector(x + 15, 511, z + 15)), delegate)) { delegate.updateBlockStates(); } } } }
@Override public void populate(World world, Random random, Chunk source) { SimplexNoiseGenerator noise = new SimplexNoiseGenerator(world); double density = noise.noise(source.getX(), source.getZ()); if (density > 0.8) { // TODO later switch to this loop to have 8 attempts of dungeon placement per chunk, // once we get caves and ravines //for (int i = 0; i < 8; i++) { int x = (source.getX() << 4) + random.nextInt(16); int z = (source.getZ() << 4) + random.nextInt(16); int y = random.nextInt(256); GlowDungeon dungeon = new GlowDungeon(random, new Location(world, x, y, z)); BlockStateDelegate delegate = new BlockStateDelegate(); if (dungeon.generate(world, random, new StructureBoundingBox(new Vector(x - 15, 1, z - 15), new Vector(x + 15, 511, z + 15)), delegate)) { delegate.updateBlockStates(); } //} } } }
boundingBox.offset(new Vector(-radiusX, -1, -radiusZ)); for (int z = 0; z < sizeZ; z++) { for (int y = HEIGHT - 1; y >= 0; y--) { BlockState state = builder.getBlockState(new Vector(x, y, z)); if (y > 0 && x > 0 && z > 0 && x < sizeX - 1 && y < HEIGHT - 1 && z < sizeZ - 1) { builder.setBlock(new Vector(x, y, z), Material.AIR); } else if (!builder.getBlockState(new Vector(x, y - 1, z)).getType() .isSolid()) { builder.setBlock(new Vector(x, y, z), Material.AIR); } else if (state.getType().isSolid()) { builder.setBlockWithRandomMaterial(new Vector(x, y, z), random, stones); } else { builder.setBlock(new Vector(x, y, z), Material.COBBLESTONE); int x = random.nextInt((radiusX << 1) - 1) + 1; int z = random.nextInt((radiusZ << 1) - 1) + 1; if (builder.getBlockState(new Vector(x, 1, z)).getType() == Material.AIR) { BlockFace face = null; int solidBlocksCount = 0; if (builder.getBlockState(new Vector(x - 1, 1, z)).getType() == Material.COBBLESTONE) { solidBlocksCount++; face = BlockFace.EAST;
@Override public void decorate(World world, Random random, Chunk c) { if (random.nextInt(8) != 0) { return; final int startCx = random.nextInt(16); final int startCz = random.nextInt(16); final int startY = chunk.getHeight(startCx, startCz); final GlowBlock startBlock = chunk.getBlock(startCx, startY, startCz); int deltaX = NumberConversions.floor((double) length * Math.cos(Math.toRadians(yaw))); int deltaZ = NumberConversions.floor((double) length * Math.sin(Math.toRadians(yaw))); currentNode.add(new Vector(deltaX, deltaY, deltaZ)); nodes.add(new BlockVector(currentNode.getBlockX(), currentNode.getBlockY(), currentNode.getBlockZ())); .getBlockAt(node.getBlockX(), node.getBlockY(), node.getBlockZ()); caveAroundRay(block, random);
@Override public PowerResult<Double> hit(Player player, ItemStack stack, LivingEntity entity, double damage, EntityDamageByEntityEvent event) { if (!getItem().consumeDurability(stack, cost)) return PowerResult.cost(); if (rand.nextInt(chance) == 0) { Bukkit.getScheduler().runTask(RPGItems.plugin, () -> entity.setVelocity(player.getLocation().getDirection().setY(power))); } return PowerResult.ok(damage); }
/** * Gets a random vector with components having a random value between 0 * and 1. * * @return A random vector. */ public static Vector getRandom() { return new Vector(random.nextDouble(), random.nextDouble(), random.nextDouble()); }
if (f >= 0.0F) { for (int i = 0; i < nodeCount; i++) { double d1 = f * (random.nextFloat() + 0.328D); double d2 = random.nextFloat() * Math.PI * 2.0D; int x = (int) (d1 * Math.sin(d2) + blockX + 0.5D); int z = (int) (d1 * Math.cos(d2) + blockZ + 0.5D); if (countAvailableBlocks(new Vector(x, y, z), new Vector(x, y + maxLeafDistance, z), world) == -1) { int offX = blockX - x; int offZ = blockZ - z; int branchBaseY = Math.min(trunkTopY, (int) (y - distance)); if (countAvailableBlocks( new Vector(x, branchBaseY, z), new Vector(x, y, z), world) == -1) { leafNodes.add(new LeafNode(x, y, z, branchBaseY));
private void tickNpcs() { for (NPC npc : this.npcRegistry) { if (!npc.isSpawned() || !npc.hasTrait(ClickableTrait.class)) continue; Npc helperNpc = npc.getTrait(ClickableTrait.class).npc; // ensure npcs stay in the same position Location loc = npc.getEntity().getLocation(); if (loc.getBlockX() != helperNpc.getInitialSpawn().getBlockX() || loc.getBlockZ() != helperNpc.getInitialSpawn().getBlockZ()) { npc.teleport(helperNpc.getInitialSpawn().clone(), PlayerTeleportEvent.TeleportCause.PLUGIN); } // don't let players stand near npcs for (Entity entity : npc.getStoredLocation().getWorld().getNearbyEntities(npc.getStoredLocation(), 1.0, 1.0, 1.0)) { if (!(entity instanceof Player) || this.npcRegistry.isNPC(entity)) continue; final Player p = (Player) entity; if (p.getGameMode() == GameMode.CREATIVE || p.getGameMode() == GameMode.SPECTATOR) { continue; } if (npc.getEntity().getLocation().distance(p.getLocation()) < 3.5) { p.setVelocity(p.getLocation().getDirection().multiply(-0.5).setY(0.4)); } } } }
private void playOutExplosion(GlowPlayer player, Iterable<Block> blocks) { Collection<Record> records = new ArrayList<>(); for (Block block : blocks) { Location blockLocation = block.getLocation(); byte x = (byte) (blockLocation.getBlockX() - (int) this.location.getX()); byte y = (byte) (blockLocation.getBlockY() - (int) this.location.getY()); byte z = (byte) (blockLocation.getBlockZ() - (int) this.location.getZ()); records.add(new Record(x, y, z)); } Vector velocity = player.getVelocity(); ExplosionMessage message = new ExplosionMessage( (float) location.getX(), (float) location.getY(), (float) location.getZ(), power, (float) velocity.getX(), (float) velocity.getY(), (float) velocity.getZ(), records); player.getSession().send(message); }
/** * Fires a snowball from the NPC at a target. */ public void fireSnowball(Location target) { sentinel.swingWeapon(); sentinel.stats_snowballsThrown++; sentinel.faceLocation(target); Vector forward = getLivingEntity().getEyeLocation().getDirection(); Location spawnAt = getLivingEntity().getEyeLocation().clone().add(forward.clone().multiply(sentinel.firingMinimumRange())); Entity ent = spawnAt.getWorld().spawnEntity(spawnAt, EntityType.SNOWBALL); ((Projectile) ent).setShooter(getLivingEntity()); ent.setVelocity(sentinel.fixForAcc(target.clone().subtract(spawnAt).toVector().normalize().multiply(2.0))); // TODO: Fiddle with '2.0'. }
if (pendingBlock.getType().isSolid()) { Location pendingLocationX = location.clone().add(velocity.getX(), 0, 0); if (pendingLocationX.getBlock().getType().isSolid()) { velocity.setX(0); Location pendingLocationY = location.clone().add(0, velocity.getY(), 0); if (pendingLocationY.getBlock().getType().isSolid()) { velocity.setY(0); Location pendingLocationZ = location.clone().add(0, 0, velocity.getZ()); if (pendingLocationZ.getBlock().getType().isSolid()) { velocity.setZ(0); velocity.multiply(liquidDrag); velocity.setY(velocity.getY() + getGravityAccel().getY() / 4); } else if (location.getBlock().getType() == Material.LAVA) { velocity.multiply(liquidDrag - 0.3); velocity.setY(velocity.getY() + getGravityAccel().getY() / 4); } else { if (applyDragBeforeAccel) { velocity.setY(airDrag * velocity.getY() + getGravityAccel().getY()); } else { velocity.setY(airDrag * (velocity.getY() + getGravityAccel().getY())); velocity.setX(velocity.getX() * slipMultiplier); velocity.setY(0); velocity.setZ(velocity.getZ() * slipMultiplier); } else { velocity.setX(velocity.getX() * airDrag);
@Override public boolean onRightClick(ItemUseEvent e, Player p, ItemStack item) { if (SlimefunManager.isItemSimiliar(item, SlimefunItems.STAFF_WIND, true)) { if (p.getFoodLevel() >= 2) { if (p.getInventory().getItemInMainHand().getType() != Material.SHEARS && p.getGameMode() != GameMode.CREATIVE) { FoodLevelChangeEvent event = new FoodLevelChangeEvent(p, p.getFoodLevel() - 2); Bukkit.getPluginManager().callEvent(event); p.setFoodLevel(event.getFoodLevel()); } p.setVelocity(p.getEyeLocation().getDirection().multiply(4)); p.getWorld().playSound(p.getLocation(), Sound.ENTITY_TNT_PRIMED, 1, 1); p.getWorld().playEffect(p.getLocation(), Effect.SMOKE, 1); p.setFallDistance(0.0f); } else { Messages.local.sendTranslation(p, "messages.hungry", true); } return true; } else return false; } });
if (location.getWorld() != world) { throw new IllegalArgumentException( "Cannot setRawLocation to a different world (got " + location.getWorld() + ", expected " + world + ")"); Material type = location.getBlock().getType(); double detectOffsetY = 0; if (boundingBox != null) { detectOffsetY = boundingBox.getSize().getY(); Location detectLocation = location.clone().add(0, -detectOffsetY, 0); setOnGround(detectLocation.getBlock().getType().isSolid());