Search in sources :

Example 1 with HumanEntity

use of org.spongepowered.common.entity.living.human.HumanEntity in project SpongeCommon by SpongePowered.

the class ServerEntityMixin method impl$sendHumanMetadata.

@Inject(method = "sendDirtyEntityData", at = @At("HEAD"))
public void impl$sendHumanMetadata(final CallbackInfo ci) {
    if (!(this.entity instanceof HumanEntity)) {
        return;
    }
    final HumanEntity human = (HumanEntity) this.entity;
    Stream<Packet<?>> packets = human.popQueuedPackets(null);
    packets.forEach(this.broadcast);
// Note that this will further call in ChunkManager_EntityTrackerMixin
// for any player specific packets to send.
}
Also used : ClientboundPlayerInfoPacket(net.minecraft.network.protocol.game.ClientboundPlayerInfoPacket) ClientboundSetEntityDataPacket(net.minecraft.network.protocol.game.ClientboundSetEntityDataPacket) Packet(net.minecraft.network.protocol.Packet) HumanEntity(org.spongepowered.common.entity.living.human.HumanEntity) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 2 with HumanEntity

use of org.spongepowered.common.entity.living.human.HumanEntity in project SpongeCommon by SpongePowered.

the class ServerEntityMixin method impl$sendHumanSpawnPacket.

/**
 * @author gabizou
 * @reason Because the entity spawn packet is just a lone packet, we have to actually
 * do some hackery to create the player list packet first, then the spawn packet,
 * then perform the remove packet.
 */
@Redirect(method = "sendPairingData", at = @At(value = "INVOKE", remap = false, target = "Ljava/util/function/Consumer;accept(Ljava/lang/Object;)V", ordinal = 0))
public void impl$sendHumanSpawnPacket(final Consumer<Packet<?>> consumer, final Object spawnPacket) {
    if (!(this.entity instanceof HumanEntity)) {
        consumer.accept((Packet<?>) spawnPacket);
        return;
    }
    final HumanEntity human = (HumanEntity) this.entity;
    // Adds the GameProfile to the client
    consumer.accept(human.createPlayerListPacket(ClientboundPlayerInfoPacket.Action.ADD_PLAYER));
    // Actually spawn the human (a player)
    consumer.accept((Packet<?>) spawnPacket);
    // Remove from tab list
    final ClientboundPlayerInfoPacket removePacket = human.createPlayerListPacket(ClientboundPlayerInfoPacket.Action.REMOVE_PLAYER);
    if (human.canRemoveFromListImmediately()) {
        consumer.accept(removePacket);
    } else {
        // TODO - find out if this is still needed.
        human.removeFromTabListDelayed(null, removePacket);
    }
}
Also used : HumanEntity(org.spongepowered.common.entity.living.human.HumanEntity) ClientboundPlayerInfoPacket(net.minecraft.network.protocol.game.ClientboundPlayerInfoPacket) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Aggregations

ClientboundPlayerInfoPacket (net.minecraft.network.protocol.game.ClientboundPlayerInfoPacket)2 HumanEntity (org.spongepowered.common.entity.living.human.HumanEntity)2 Packet (net.minecraft.network.protocol.Packet)1 ClientboundSetEntityDataPacket (net.minecraft.network.protocol.game.ClientboundSetEntityDataPacket)1 Inject (org.spongepowered.asm.mixin.injection.Inject)1 Redirect (org.spongepowered.asm.mixin.injection.Redirect)1