Search in sources :

Example 1 with SolidSideProperty

use of org.lanternpowered.server.block.property.SolidSideProperty in project LanternServer by LanternPowered.

the class HandlerPlayInPlayerAbilities method handle.

@Override
public void handle(NetworkContext context, MessagePlayInPlayerAbilities message) {
    final boolean flying = message.isFlying();
    final LanternPlayer player = context.getSession().getPlayer();
    if (!flying || player.get(Keys.CAN_FLY).orElse(false)) {
        player.offer(Keys.IS_FLYING, flying);
    } else {
        // TODO: Just set velocity once it's implemented
        if (player.get(LanternKeys.SUPER_STEVE).orElse(false)) {
            context.getSession().send(new MessagePlayOutEntityVelocity(player.getNetworkId(), 0, 1.0, 0));
            player.offer(LanternKeys.IS_ELYTRA_FLYING, true);
        } else if (player.get(LanternKeys.CAN_WALL_JUMP).orElse(false)) {
            final Location<World> location = player.getLocation();
            // Get the horizontal direction the player is looking
            final Direction direction = player.getHorizontalDirection(Direction.Division.CARDINAL);
            // Get the block location the player may step against
            final Location<World> location1 = location.add(direction.asOffset().mul(0.6, 0, 0.6));
            SolidSideProperty solidSideProperty = location1.getExtent().getProperty(location1.getBlockPosition(), direction.getOpposite(), SolidSideProperty.class).orElse(null);
            // noinspection ConstantConditions
            if (solidSideProperty != null && solidSideProperty.getValue()) {
                // Push the player a bit back in the other direction,
                // to give a more realistic feeling when pushing off
                // against a wall
                final Vector3d pushBack = direction.asBlockOffset().toDouble().mul(-0.1);
                // Push the player up
                context.getSession().send(new MessagePlayOutEntityVelocity(player.getNetworkId(), pushBack.getX(), 0.8, pushBack.getZ()));
            } else {
                // Now we try if the player can jump away from the wall
                // Get the block location the player may step against
                final Location<World> location2 = location.add(direction.asOffset().mul(-0.6, 0, -0.6));
                solidSideProperty = location2.getExtent().getProperty(location2.getBlockPosition(), direction, SolidSideProperty.class).orElse(null);
                // noinspection ConstantConditions
                if (solidSideProperty != null && solidSideProperty.getValue()) {
                    // Combine the vectors in the direction of the block face
                    // and the direction the player is looking
                    final Vector3d vector = direction.asBlockOffset().toDouble().mul(0.25).mul(1, 0, 1).add(0, 0.65, 0).add(player.getDirectionVector().mul(0.4, 0.25, 0.4));
                    // Push the player forward and up
                    context.getSession().send(new MessagePlayOutEntityVelocity(player.getNetworkId(), vector.getX(), vector.getY(), vector.getZ()));
                }
            }
        }
        player.triggerEvent(RefreshAbilitiesPlayerEvent.of());
    }
}
Also used : SolidSideProperty(org.lanternpowered.server.block.property.SolidSideProperty) Vector3d(com.flowpowered.math.vector.Vector3d) MessagePlayOutEntityVelocity(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutEntityVelocity) Direction(org.spongepowered.api.util.Direction) LanternPlayer(org.lanternpowered.server.entity.living.player.LanternPlayer) Location(org.spongepowered.api.world.Location)

Aggregations

Vector3d (com.flowpowered.math.vector.Vector3d)1 SolidSideProperty (org.lanternpowered.server.block.property.SolidSideProperty)1 LanternPlayer (org.lanternpowered.server.entity.living.player.LanternPlayer)1 MessagePlayOutEntityVelocity (org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutEntityVelocity)1 Direction (org.spongepowered.api.util.Direction)1 Location (org.spongepowered.api.world.Location)1