@Override protected void pulsePhysics() { // drag application movement.multiply(airDrag); // convert movement x/z to a velocity Vector velMovement = getVelocityFromMovement(); velocity.add(velMovement); super.pulsePhysics(); }
@Override public void setDirection(Vector vector) { setVelocity(vector.normalize().multiply(velocity.length())); }
@Override public Arrow spawnArrow(Location location, Vector velocity, float speed, float spread) { // Transformative magic Vector randVec = new Vector(ThreadLocalRandom.current().nextGaussian(), ThreadLocalRandom .current().nextGaussian(), ThreadLocalRandom.current().nextGaussian()); randVec.multiply(0.0075 * spread); velocity.normalize(); velocity.add(randVec); velocity.multiply(speed); // yaw = Math.atan2(x, z) * 180.0D / 3.1415927410125732D; // pitch = Math.atan2(y, Math.sqrt(x * x + z * z)) * 180.0D / 3.1415927410125732D Arrow arrow = spawn(location, Arrow.class); arrow.setVelocity(velocity); return arrow; }
/** * Creates a thrown egg with default speed. * * @param location the position and facing of the thrower */ public GlowEgg(Location location) { super(location); setAirDrag(0.99); setGravityAccel(new Vector(0, VERTICAL_GRAVITY_ACCEL, 0)); setApplyDragBeforeAccel(true); setVelocity(location.getDirection().multiply(3)); setBoundingBox(0.25, 0.25); }
/** * Creates a thrown snowball with default speed. * * @param location the position and facing of the thrower */ public GlowSnowball(Location location) { super(location); setAirDrag(0.99); setGravityAccel(new Vector(0, VERTICAL_GRAVITY_ACCEL, 0)); setApplyDragBeforeAccel(true); setVelocity(location.getDirection().multiply(3)); setBoundingBox(0.25, 0.25); }
/** * Creates a thrown ender pearl. * * @param location the position and facing of the thrower * @param speed the initial speed */ public GlowEnderPearl(Location location, float speed) { super(location); setAirDrag(0.99); setGravityAccel(new Vector(0, VERTICAL_GRAVITY_ACCEL, 0)); setApplyDragBeforeAccel(true); setVelocity(location.getDirection().multiply(speed)); setBoundingBox(0.25, 0.25); }
/** * Creates a fishing bob. * * @param location the location * @param itemStack the fishing rod (used to handle enchantments) or null (equivalent to * @param angler the player who is casting this fish hook (must be set at spawn time) */ public GlowFishingHook(Location location, ItemStack itemStack, Player angler) { super(location); setSize(0.25f, 0.25f); lifeTime = calculateLifeTime(); this.itemStack = InventoryUtil.itemOrEmpty(itemStack).clone(); // TODO: velocity does not match vanilla Vector direction = location.getDirection(); setVelocity(direction.multiply(1.5)); super.setShooter(angler); }
/** * Spawns a new {@link GlowItem} in the world, as if this HumanEntity had dropped it. * * <p>Note that this does NOT remove the item from the inventory. * * @param stack The item to drop * @return the GlowItem that was generated, or null if the spawning was cancelled * @throws IllegalArgumentException if the stack is empty */ public GlowItem drop(ItemStack stack) { checkArgument(!InventoryUtil.isEmpty(stack), "stack must not be empty"); Location dropLocation = location.clone().add(0, getEyeHeight(true) - 0.3, 0); GlowItem dropItem = world.dropItem(dropLocation, stack); /* These calculations are strictly based off of trial-and-error to find the closest similar behavior to the official server. May be changed in the future. */ Vector vel = location.getDirection().multiply(0.3); ThreadLocalRandom tlr = ThreadLocalRandom.current(); double randOffset = 0.02; vel.add(new Vector( tlr.nextDouble(randOffset) - randOffset / 2, tlr.nextDouble(0.12), tlr.nextDouble(randOffset) - randOffset / 2)); dropItem.setVelocity(vel); return dropItem; }
@Override protected ItemStack dispenseStack(GlowBlock block, ItemStack stack) { GlowWorld world = block.getWorld(); Vector position = BlockDispenser.getDispensePosition(block); BlockFace face = BlockDispenser.getFacing(block); Projectile entity = projectileCreator.apply( new Location(world, position.getX(), position.getY(), position.getZ()), stack); entity.setShooter(new GlowDispenser(block)); entity.setVelocity( new Vector(face.getModX(), face.getModY() + 0.1f, face.getModZ()).multiply(6)); stack.setAmount(stack.getAmount() - 1); if (stack.getAmount() < 1) { return null; } return stack; }
direction.normalize(); direction.multiply(speed); this.setVelocity(direction);
launchedProjectile.setVelocity(player.getEyeLocation().getDirection().multiply( Math.max(5, chargeFraction * MAX_SPEED)));
LivingEntity livingEntity = (LivingEntity) entity; Vector rayLength = RayUtil.getVelocityRay(distanceToHead(livingEntity)); rayLength.multiply(exposure);
currentVelocity.add(rayLength.multiply(((amount + 1) / 2d))); setVelocity(currentVelocity);
velocity.add(getGravityAccel()); location.add(getVelocity()); velocity.multiply(airDrag); } else { if (supportingBlock(location.getBlock().getType())) {
@Override public boolean entityInteract(GlowPlayer player, InteractEntityMessage message) { super.entityInteract(player, message); if (message.getAction() == InteractEntityMessage.Action.INTERACT.ordinal()) { if (player.getGameMode().equals(GameMode.CREATIVE) || player.getGameMode() .equals(GameMode.SPECTATOR)) { return false; } if (!isAdult()) { return false; } ItemStack hand = InventoryUtil .itemOrEmpty(player.getInventory().getItem(message.getHandSlot())); if (!hand.getType().equals(Material.BUCKET)) { return false; } player.getInventory().consumeItemInHand(message.getHandSlot()); if (player.getInventory().firstEmpty() == -1) { GlowItem item = player.getWorld() .dropItem(player.getLocation().clone().add(0, 1, 0), new ItemStack(Material.MILK_BUCKET, 1)); item.setVelocity(getLocation().add(0, -1, 0).clone().toVector() .subtract(player.getLocation().clone().add(0, 1, 0).toVector()).multiply(0.3)); } else { player.getInventory().addItem(new ItemStack(Material.MILK_BUCKET, 1)); } } return true; }
@Override public void onRun() { Location location = getLocation(); for (int i = 0; i < 20; i++) { location.add(RandomUtils.getRandomCircleVector().multiply(RandomUtils.random.nextDouble() * 0.6d)); location.add(0, RandomUtils.random.nextFloat() * 2, 0); display(particle, location); } }
@Override public void onRun() { Location location = getLocation(); for (int i = 0; i < 10; i++) { Vector v = RandomUtils.getRandomCircleVector().multiply(RandomUtils.random.nextDouble() * 0.6d); v.setY(RandomUtils.random.nextFloat() * 1.8); location.add(v); display(particle, location); location.subtract(v); } }
public void dropItem(Location dropLocation, ItemStack itemStack) { Item item = this.game.getRegion().getWorld().dropItemNaturally(dropLocation, itemStack); item.setPickupDelay(0); if (this.spread != 1.0) { item.setVelocity(item.getVelocity().multiply(this.spread)); } }