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
}
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();
}
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();
}
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);
}
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));
}
Aggregations