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