Search in sources :

Example 26 with Living

use of org.spongepowered.api.entity.living.Living in project LanternServer by LanternPowered.

the class EntityProtocol method update.

@Override
protected void update(EntityProtocolUpdateContext context) {
    final Vector3d rot = this.entity.getRotation();
    final Vector3d headRot = this.entity instanceof Living ? ((Living) this.entity).getHeadRotation() : null;
    final Vector3d pos = this.entity.getPosition();
    final double x = pos.getX();
    final double y = pos.getY();
    final double z = pos.getZ();
    final long xu = (long) (x * 4096);
    final long yu = (long) (y * 4096);
    final long zu = (long) (z * 4096);
    final byte yaw = wrapAngle(rot.getY());
    // All living entities have a head rotation and changing the pitch
    // would only affect the head pitch.
    final byte pitch = wrapAngle((headRot != null ? headRot : rot).getX());
    boolean dirtyPos = xu != this.lastX || yu != this.lastY || zu != this.lastZ;
    boolean dirtyRot = yaw != this.lastYaw || pitch != this.lastPitch;
    // TODO: On ground state
    final int entityId = getRootEntityId();
    final boolean passenger = this.entity.getVehicle().isPresent();
    if (dirtyRot) {
        this.lastYaw = yaw;
        this.lastPitch = pitch;
    }
    if (dirtyPos) {
        final long dxu = xu - this.lastX;
        final long dyu = yu - this.lastY;
        final long dzu = zu - this.lastZ;
        this.lastX = xu;
        this.lastY = yu;
        this.lastZ = zu;
        // rule the world.
        if (!passenger) {
            if (Math.abs(dxu) <= Short.MAX_VALUE && Math.abs(dyu) <= Short.MAX_VALUE && Math.abs(dzu) <= Short.MAX_VALUE) {
                if (dirtyRot) {
                    context.sendToAllExceptSelf(new MessagePlayOutEntityLookAndRelativeMove(entityId, (int) dxu, (int) dyu, (int) dzu, yaw, pitch, this.entity.isOnGround()));
                    // The rotation is already send
                    dirtyRot = false;
                } else {
                    context.sendToAllExceptSelf(new MessagePlayOutEntityRelativeMove(entityId, (int) dxu, (int) dyu, (int) dzu, this.entity.isOnGround()));
                }
            } else {
                context.sendToAllExceptSelf(new MessagePlayOutEntityTeleport(entityId, x, y, z, yaw, pitch, this.entity.isOnGround()));
                // The rotation is already send
                dirtyRot = false;
            }
        }
    }
    if (dirtyRot) {
        context.sendToAllExceptSelf(() -> new MessagePlayOutEntityLook(entityId, yaw, pitch, this.entity.isOnGround()));
    } else if (!passenger) {
        if (headRot != null) {
            final byte headYaw = wrapAngle(headRot.getY());
            if (headYaw != this.lastHeadYaw) {
                context.sendToAllExceptSelf(() -> new MessagePlayOutEntityHeadLook(entityId, headYaw));
                this.lastHeadYaw = headYaw;
            }
        }
    }
    final Vector3d velocity = this.entity.getVelocity();
    final double vx = velocity.getX();
    final double vy = velocity.getY();
    final double vz = velocity.getZ();
    if (vx != this.lastVelX || vy != this.lastVelY || vz != this.lastVelZ) {
        context.sendToAll(() -> new MessagePlayOutEntityVelocity(entityId, vx, vy, vz));
        this.lastVelX = vx;
        this.lastVelY = vy;
        this.lastVelZ = vz;
    }
    final ParameterList parameterList = context == EntityProtocolUpdateContext.empty() ? fillParameters(false, EmptyParameterList.INSTANCE) : fillParameters(false);
    // There were parameters applied
    if (!parameterList.isEmpty()) {
        context.sendToAll(() -> new MessagePlayOutEntityMetadata(entityId, parameterList));
    }
    if (hasEquipment() && this.entity instanceof Carrier) {
        final Inventory inventory = ((Carrier) this.entity).getInventory();
        for (int i = 0; i < Holder.EQUIPMENT_TYPES.length; i++) {
            final ItemStack itemStack = inventory.query(Holder.EQUIPMENT_QUERIES[i]).first().peek().orElse(null);
            final ItemStack oldItemStack = this.lastEquipment.get(i);
            if (!LanternItemStack.areSimilar(itemStack, oldItemStack)) {
                this.lastEquipment.put(i, itemStack);
                final int slotIndex = i;
                context.sendToAllExceptSelf(() -> new MessagePlayOutEntityEquipment(getRootEntityId(), slotIndex, itemStack));
            }
        }
    }
// TODO: Update attributes
}
Also used : MessagePlayOutEntityLookAndRelativeMove(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutEntityLookAndRelativeMove) Living(org.spongepowered.api.entity.living.Living) LanternLiving(org.lanternpowered.server.entity.LanternLiving) MessagePlayOutEntityEquipment(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutEntityEquipment) MessagePlayOutEntityRelativeMove(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutEntityRelativeMove) Vector3d(com.flowpowered.math.vector.Vector3d) MessagePlayOutEntityLook(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutEntityLook) MessagePlayOutEntityVelocity(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutEntityVelocity) ParameterList(org.lanternpowered.server.network.entity.parameter.ParameterList) EmptyParameterList(org.lanternpowered.server.network.entity.parameter.EmptyParameterList) ByteBufParameterList(org.lanternpowered.server.network.entity.parameter.ByteBufParameterList) MessagePlayOutEntityMetadata(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutEntityMetadata) MessagePlayOutEntityTeleport(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutEntityTeleport) Carrier(org.spongepowered.api.item.inventory.Carrier) MessagePlayOutEntityHeadLook(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutEntityHeadLook) ItemStack(org.spongepowered.api.item.inventory.ItemStack) LanternItemStack(org.lanternpowered.server.inventory.LanternItemStack) Inventory(org.spongepowered.api.item.inventory.Inventory)

Example 27 with Living

use of org.spongepowered.api.entity.living.Living in project Nucleus by NucleusPowered.

the class LightningCommand method executeCommand.

@Override
public CommandResult executeCommand(final CommandSource src, CommandContext args) throws Exception {
    Collection<Living> playerCollection = args.getAll(player);
    // No argument, let's not smite the subject.
    if (playerCollection.isEmpty()) {
        if (!(src instanceof Player)) {
            src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.playeronly"));
            return CommandResult.empty();
        }
        Player pl = (Player) src;
        // 100 is a good limit here.
        BlockRay<World> playerBlockRay = BlockRay.from(pl).distanceLimit(100).stopFilter(BlockRay.continueAfterFilter(BlockRay.onlyAirFilter(), 1)).build();
        Optional<BlockRayHit<World>> obh = playerBlockRay.end();
        Location<World> lightningLocation;
        // Smite above, but not on.
        lightningLocation = obh.map(BlockRayHit::getLocation).orElseGet(() -> pl.getLocation().add(0, 3, 0));
        return this.spawnLightning(lightningLocation, src, null);
    }
    int successCount = 0;
    for (Living pl : playerCollection) {
        CommandResult cr = this.spawnLightning(pl.getLocation(), src, pl instanceof Player ? (Player) pl : null);
        successCount += cr.getSuccessCount().orElse(0);
    }
    return CommandResult.builder().successCount(successCount).build();
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) Living(org.spongepowered.api.entity.living.Living) World(org.spongepowered.api.world.World) BlockRayHit(org.spongepowered.api.util.blockray.BlockRayHit) CommandResult(org.spongepowered.api.command.CommandResult)

Example 28 with Living

use of org.spongepowered.api.entity.living.Living in project Skree by Skelril.

the class SoulReaper method apply.

@Override
public Optional<Instruction<DamageCondition, Boss<Zombie, CatacombsBossDetail>>> apply(DamageCondition damageCondition, Boss<Zombie, CatacombsBossDetail> zombieCatacombsBossDetailBoss) {
    CatacombsBossDetail detail = zombieCatacombsBossDetailBoss.getDetail();
    Entity attacked = damageCondition.getAttacked();
    if (attacked instanceof Player && activate(detail)) {
        Task.builder().execute(() -> {
            Optional<Zombie> optZombie = zombieCatacombsBossDetailBoss.getTargetEntity();
            if (optZombie.isPresent()) {
                Zombie boss = optZombie.get();
                double stolen = EntityHealthUtil.getHealth((Living) attacked) - 1;
                attacked.offer(Keys.HEALTH, 1D);
                EntityHealthUtil.heal(boss, stolen);
                ((Player) attacked).sendMessage(Text.of(TextColors.RED, "The necromancer reaps your soul."));
            }
        }).delayTicks(1).submit(SkreePlugin.inst());
    }
    return Optional.empty();
}
Also used : CatacombsBossDetail(com.skelril.skree.content.zone.group.catacombs.CatacombsBossDetail) Entity(org.spongepowered.api.entity.Entity) Player(org.spongepowered.api.entity.living.player.Player) Zombie(org.spongepowered.api.entity.living.monster.Zombie) Living(org.spongepowered.api.entity.living.Living)

Example 29 with Living

use of org.spongepowered.api.entity.living.Living in project Skree by Skelril.

the class TheForgeListener method onPlayerCombat.

@Listener
public void onPlayerCombat(CollideEntityEvent.Impact event, @First Projectile projectile) {
    Optional<TheForgeInstance> optInst = manager.getApplicableZone(projectile);
    if (!optInst.isPresent()) {
        return;
    }
    new PlayerCombatParser() {

        @Override
        public void processMonsterAttack(Living attacker, Player defender) {
            if (!(event instanceof DamageEntityEvent)) {
                return;
            }
            DamageEntityEvent dEvent = (DamageEntityEvent) event;
            if (isFlying(defender)) {
                dEvent.setBaseDamage(dEvent.getBaseDamage() * 3);
            }
        }
    }.parse(event);
}
Also used : DamageEntityEvent(org.spongepowered.api.event.entity.DamageEntityEvent) Player(org.spongepowered.api.entity.living.player.Player) Living(org.spongepowered.api.entity.living.Living) PlayerCombatParser(com.skelril.nitro.combat.PlayerCombatParser) Listener(org.spongepowered.api.event.Listener)

Example 30 with Living

use of org.spongepowered.api.entity.living.Living in project Skree by Skelril.

the class CoinToss method processAttackOnPlayer.

public void processAttackOnPlayer(Living attacker, Player defender, DamageEntityEvent event) {
    event.setBaseDamage(0);
    Living target = defender;
    if (Probability.getChance(2)) {
        target = attacker;
    }
    double targetHealth = getHealth(target);
    target.offer(Keys.HEALTH, Math.max(0, targetHealth - 16));
}
Also used : Living(org.spongepowered.api.entity.living.Living)

Aggregations

Living (org.spongepowered.api.entity.living.Living)63 Entity (org.spongepowered.api.entity.Entity)34 Player (org.spongepowered.api.entity.living.player.Player)16 Instruction (com.skelril.openboss.Instruction)15 ZoneBossDetail (com.skelril.skree.content.zone.ZoneBossDetail)13 Listener (org.spongepowered.api.event.Listener)13 World (org.spongepowered.api.world.World)12 NamedBindInstruction (com.skelril.skree.content.zone.group.catacombs.instruction.bossmove.NamedBindInstruction)10 HealthBindInstruction (com.skelril.skree.content.zone.group.freakyfour.boss.bossmove.HealthBindInstruction)10 DamageEntityEvent (org.spongepowered.api.event.entity.DamageEntityEvent)8 EntityDamageSource (org.spongepowered.api.event.cause.entity.damage.source.EntityDamageSource)7 Vector3d (com.flowpowered.math.vector.Vector3d)6 PlayerCombatParser (com.skelril.nitro.combat.PlayerCombatParser)6 CuboidContainmentPredicate (com.skelril.nitro.position.CuboidContainmentPredicate)6 BackTeleportInstruction (com.skelril.skree.content.zone.group.freakyfour.boss.bossmove.BackTeleportInstruction)6 HealableInstruction (com.skelril.skree.content.zone.group.freakyfour.boss.bossmove.HealableInstruction)6 IndirectEntityDamageSource (org.spongepowered.api.event.cause.entity.damage.source.IndirectEntityDamageSource)6 Vector3i (com.flowpowered.math.vector.Vector3i)5 IntegratedRunnable (com.skelril.nitro.time.IntegratedRunnable)5 TimedRunnable (com.skelril.nitro.time.TimedRunnable)5