Search in sources :

Example 1 with EntityHuman

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

the class MixinEntityTrackerEntry method onSendMetadata.

@Inject(method = "sendMetadata", at = @At("HEAD"))
public void onSendMetadata(CallbackInfo ci) {
    if (!(this.trackedEntity instanceof EntityHuman)) {
        return;
    }
    EntityHuman human = (EntityHuman) this.trackedEntity;
    Packet<?>[] packets = human.popQueuedPackets(null);
    for (EntityPlayerMP player : this.trackingPlayers) {
        if (packets != null) {
            for (Packet<?> packet : packets) {
                player.connection.sendPacket(packet);
            }
        }
        Packet<?>[] playerPackets = human.popQueuedPackets(player);
        if (playerPackets != null) {
            for (Packet<?> packet : playerPackets) {
                player.connection.sendPacket(packet);
            }
        }
    }
}
Also used : EntityHuman(org.spongepowered.common.entity.living.human.EntityHuman) Packet(net.minecraft.network.Packet) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) IMixinEntityPlayerMP(org.spongepowered.common.interfaces.entity.player.IMixinEntityPlayerMP) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 2 with EntityHuman

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

the class MixinCommandScoreboard method onGetEntityNameLeaveSecond.

@Redirect(method = "leaveTeam", at = @At(value = "INVOKE", target = GET_ENTITY_NAME, ordinal = 1))
public String onGetEntityNameLeaveSecond(MinecraftServer server, ICommandSender sender, String string) throws CommandException {
    String entityName = CommandBase.getEntityName(server, sender, string);
    if (this.isExpandedSelector()) {
        try {
            UUID uuid = UUID.fromString(entityName);
            Entity entity = sender.getServer().getEntityFromUuid(uuid);
            if (entity != null && entity instanceof EntityHuman) {
                return entity.getCustomNameTag();
            }
        } catch (IllegalArgumentException e) {
        // Fall through to normal return
        }
    }
    return entityName;
}
Also used : Entity(net.minecraft.entity.Entity) EntityHuman(org.spongepowered.common.entity.living.human.EntityHuman) UUID(java.util.UUID) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Example 3 with EntityHuman

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

the class MixinEntityLivingBase method onDeath.

/**
 * @author blood - May 12th, 2016
 * @author gabizou - June 4th, 2016 - Update for 1.9.4 and Cause Tracker changes
 *
 * @reason SpongeForge requires an overwrite so we do it here instead. This handles all living entity death events
 * (except players). Note should be taken that normally, there are lists for drops captured, however, the drops
 * are retroactively captured by the PhaseTracker and associated through the different phases, depending on
 * how they are handled, so no lists and flags on the entities themselves are needed as they are tracked through
 * the {@link PhaseContext} of the current {@link IPhaseState} at which this method is called. The compatibility
 * for Forge's events to throw are handled specially in SpongeForge.
 */
@Overwrite
public void onDeath(DamageSource cause) {
    // Sponge Start - Call our event, and forge's event
    // This will transitively call the forge event
    SpongeCommonEventFactory.callDestructEntityEventDeath((EntityLivingBase) (Object) this, cause);
    // Double check that the PhaseTracker is already capturing the Death phase
    final PhaseTracker phaseTracker = PhaseTracker.getInstance();
    final boolean isMainThread = !this.world.isRemote || Sponge.isServerAvailable() && Sponge.getServer().isMainThread();
    try (final StackFrame frame = isMainThread ? Sponge.getCauseStackManager().pushCauseFrame() : null) {
        if (!this.world.isRemote) {
            final PhaseData peek = phaseTracker.getCurrentPhaseData();
            final IPhaseState state = peek.state;
            this.tracksEntityDeaths = !phaseTracker.getCurrentState().tracksEntityDeaths() && state != EntityPhase.State.DEATH;
            if (this.tracksEntityDeaths) {
                Sponge.getCauseStackManager().pushCause(this);
                final PhaseContext<?> context = EntityPhase.State.DEATH.createPhaseContext().setDamageSource((org.spongepowered.api.event.cause.entity.damage.source.DamageSource) cause).source(this);
                this.getNotifierUser().ifPresent(context::notifier);
                this.getCreatorUser().ifPresent(context::owner);
                context.buildAndSwitch();
            }
        } else {
            this.tracksEntityDeaths = false;
        }
        // Sponge End
        if (this.dead) {
            // Sponge Start - ensure that we finish the tracker if necessary
            if (this.tracksEntityDeaths && !properlyOverridesOnDeathForCauseTrackerCompletion()) {
                phaseTracker.completePhase(EntityPhase.State.DEATH);
            }
            // Sponge End
            return;
        }
        Entity entity = cause.getTrueSource();
        EntityLivingBase entitylivingbase = this.getAttackingEntity();
        if (this.scoreValue >= 0 && entitylivingbase != null) {
            entitylivingbase.awardKillScore((EntityLivingBase) (Object) this, this.scoreValue, cause);
        }
        if (entity != null) {
            entity.onKillEntity((EntityLivingBase) (Object) this);
        }
        this.dead = true;
        this.getCombatTracker().reset();
        if (!this.world.isRemote) {
            int i = 0;
            if (entity instanceof EntityPlayer) {
                i = EnchantmentHelper.getLootingModifier((EntityLivingBase) entity);
            }
            if (this.canDropLoot() && this.world.getGameRules().getBoolean("doMobLoot")) {
                boolean flag = this.recentlyHit > 0;
                this.dropLoot(flag, i, cause);
            }
        }
        // Sponge Start - Don't send the state if this is a human. Fixes ghost items on client.
        if (!((EntityLivingBase) (Object) this instanceof EntityHuman)) {
            this.world.setEntityState((EntityLivingBase) (Object) this, (byte) 3);
        }
        if (phaseTracker != null && this.tracksEntityDeaths && !properlyOverridesOnDeathForCauseTrackerCompletion()) {
            this.tracksEntityDeaths = false;
            phaseTracker.completePhase(EntityPhase.State.DEATH);
        }
    }
// Sponge End
}
Also used : Entity(net.minecraft.entity.Entity) EntityHuman(org.spongepowered.common.entity.living.human.EntityHuman) PhaseData(org.spongepowered.common.event.tracking.PhaseData) FallingBlockDamageSource(org.spongepowered.api.event.cause.entity.damage.source.FallingBlockDamageSource) DamageSource(net.minecraft.util.DamageSource) IPhaseState(org.spongepowered.common.event.tracking.IPhaseState) PhaseTracker(org.spongepowered.common.event.tracking.PhaseTracker) StackFrame(org.spongepowered.api.event.CauseStackManager.StackFrame) IMixinEntityLivingBase(org.spongepowered.common.interfaces.entity.IMixinEntityLivingBase) EntityLivingBase(net.minecraft.entity.EntityLivingBase) EntityPlayer(net.minecraft.entity.player.EntityPlayer) DamageObject(org.spongepowered.common.event.damage.DamageObject) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 4 with EntityHuman

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

the class MixinEntityTrackerEntry method onSendSpawnPacket.

@Redirect(method = "updatePlayerEntity", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/NetHandlerPlayServer;sendPacket(Lnet/minecraft/network/Packet;)V", ordinal = 0))
public void onSendSpawnPacket(final NetHandlerPlayServer thisCtx, final Packet<?> spawnPacket, final EntityPlayerMP playerIn) {
    if (!(this.trackedEntity instanceof EntityHuman)) {
        // This is the method call that was @Redirected
        thisCtx.sendPacket(spawnPacket);
        return;
    }
    final EntityHuman human = (EntityHuman) this.trackedEntity;
    // Adds the GameProfile to the client
    thisCtx.sendPacket(human.createPlayerListPacket(SPacketPlayerListItem.Action.ADD_PLAYER));
    // Actually spawn the human (a player)
    thisCtx.sendPacket(spawnPacket);
    // Remove from tab list
    final SPacketPlayerListItem removePacket = human.createPlayerListPacket(SPacketPlayerListItem.Action.REMOVE_PLAYER);
    if (human.canRemoveFromListImmediately()) {
        thisCtx.sendPacket(removePacket);
    } else {
        human.removeFromTabListDelayed(playerIn, removePacket);
    }
}
Also used : EntityHuman(org.spongepowered.common.entity.living.human.EntityHuman) SPacketPlayerListItem(net.minecraft.network.play.server.SPacketPlayerListItem) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Aggregations

EntityHuman (org.spongepowered.common.entity.living.human.EntityHuman)4 Entity (net.minecraft.entity.Entity)2 Redirect (org.spongepowered.asm.mixin.injection.Redirect)2 UUID (java.util.UUID)1 EntityLivingBase (net.minecraft.entity.EntityLivingBase)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)1 Packet (net.minecraft.network.Packet)1 SPacketPlayerListItem (net.minecraft.network.play.server.SPacketPlayerListItem)1 DamageSource (net.minecraft.util.DamageSource)1 StackFrame (org.spongepowered.api.event.CauseStackManager.StackFrame)1 FallingBlockDamageSource (org.spongepowered.api.event.cause.entity.damage.source.FallingBlockDamageSource)1 Overwrite (org.spongepowered.asm.mixin.Overwrite)1 Inject (org.spongepowered.asm.mixin.injection.Inject)1 DamageObject (org.spongepowered.common.event.damage.DamageObject)1 IPhaseState (org.spongepowered.common.event.tracking.IPhaseState)1 PhaseData (org.spongepowered.common.event.tracking.PhaseData)1 PhaseTracker (org.spongepowered.common.event.tracking.PhaseTracker)1 IMixinEntityLivingBase (org.spongepowered.common.interfaces.entity.IMixinEntityLivingBase)1 IMixinEntityPlayerMP (org.spongepowered.common.interfaces.entity.player.IMixinEntityPlayerMP)1