use of org.spongepowered.common.event.tracking.IPhaseState in project SpongeCommon by SpongePowered.
the class MixinWorldServer method onFireBlockEvent.
// special handling for Pistons since they use their own event system
@Redirect(method = "sendQueuedBlockEvents", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/WorldServer;fireBlockEvent(Lnet/minecraft/block/BlockEventData;)Z"))
private boolean onFireBlockEvent(net.minecraft.world.WorldServer worldIn, BlockEventData event) {
final PhaseTracker phaseTracker = PhaseTracker.getInstance();
final IPhaseState phaseState = phaseTracker.getCurrentState();
if (phaseState.ignoresBlockEvent()) {
return fireBlockEvent(event);
}
return TrackingUtil.fireMinecraftBlockEvent(worldIn, event);
}
use of org.spongepowered.common.event.tracking.IPhaseState in project SpongeCommon by SpongePowered.
the class MixinWorldServer method onCallEntityUpdate.
@Override
public void onCallEntityUpdate(net.minecraft.entity.Entity entity) {
final PhaseTracker phaseTracker = PhaseTracker.getInstance();
final IPhaseState state = phaseTracker.getCurrentState();
if (state.alreadyCapturingEntityTicks()) {
entity.onUpdate();
return;
}
TrackingUtil.tickEntity(entity);
updateRotation(entity);
}
use of org.spongepowered.common.event.tracking.IPhaseState in project SpongeCommon by SpongePowered.
the class MixinEntityPlayerMP method onDeath.
/**
* @author blood - May 12th, 2016
* @author gabizou - June 3rd, 2016
*
* @reason SpongeForge requires an overwrite so we do it here instead. This handles player death events.
*/
@Override
@Overwrite
public void onDeath(DamageSource cause) {
// Sponge start
DestructEntityEvent.Death event = SpongeCommonEventFactory.callDestructEntityEventDeath((EntityPlayerMP) (Object) this, cause);
// Double check that the PhaseTracker is already capturing the Death phase
final PhaseTracker phaseTracker;
final boolean tracksEntityDeaths;
if (!this.world.isRemote) {
phaseTracker = PhaseTracker.getInstance();
final PhaseData peek = phaseTracker.getCurrentPhaseData();
final IPhaseState state = peek.state;
tracksEntityDeaths = state.tracksEntityDeaths();
} else {
phaseTracker = null;
tracksEntityDeaths = false;
}
try (PhaseContext<?> context = !tracksEntityDeaths ? EntityPhase.State.DEATH.createPhaseContext().source(this).setDamageSource((org.spongepowered.api.event.cause.entity.damage.source.DamageSource) cause).buildAndSwitch() : null) {
// Sponge end
boolean flag = this.world.getGameRules().getBoolean("showDeathMessages");
this.connection.sendPacket(new SPacketCombatEvent(this.getCombatTracker(), SPacketCombatEvent.Event.ENTITY_DIED, flag));
if (flag) {
Team team = this.getTeam();
if (team != null && team.getDeathMessageVisibility() != Team.EnumVisible.ALWAYS) {
if (team.getDeathMessageVisibility() == Team.EnumVisible.HIDE_FOR_OTHER_TEAMS) {
this.mcServer.getPlayerList().sendMessageToAllTeamMembers((EntityPlayerMP) (Object) this, this.getCombatTracker().getDeathMessage());
} else if (team.getDeathMessageVisibility() == Team.EnumVisible.HIDE_FOR_OWN_TEAM) {
this.mcServer.getPlayerList().sendMessageToTeamOrAllPlayers((EntityPlayerMP) (Object) this, this.getCombatTracker().getDeathMessage());
}
} else {
this.mcServer.getPlayerList().sendMessage(this.getCombatTracker().getDeathMessage());
}
}
this.spawnShoulderEntities();
// Ignore keepInventory GameRule instead use keepInventory from Event
if (!event.getKeepInventory() && !this.isSpectator()) {
this.destroyVanishingCursedItems();
this.inventory.dropAllItems();
}
for (ScoreObjective scoreobjective : this.getWorldScoreboard().getObjectivesFromCriteria(IScoreCriteria.DEATH_COUNT)) {
Score score = this.getWorldScoreboard().getOrCreateScore(this.getName(), scoreobjective);
score.incrementScore();
}
EntityLivingBase entitylivingbase = this.getAttackingEntity();
if (entitylivingbase != null) {
EntityList.EntityEggInfo entitylist$entityegginfo = EntityList.ENTITY_EGGS.get(EntityList.getKey(entitylivingbase));
if (entitylist$entityegginfo != null) {
this.addStat(entitylist$entityegginfo.entityKilledByStat);
}
entitylivingbase.awardKillScore((EntityPlayerMP) (Object) this, this.scoreValue, cause);
}
this.addStat(StatList.DEATHS);
this.takeStat(StatList.TIME_SINCE_DEATH);
this.extinguish();
this.setFlag(0, false);
this.getCombatTracker().reset();
this.keepInventory = event.getKeepInventory();
}
// Sponge - brackets
}
use of org.spongepowered.common.event.tracking.IPhaseState in project SpongeCommon by SpongePowered.
the class MixinItemStack method capturePlayerOnBlockDestroyed.
@SuppressWarnings("unchecked")
@Inject(method = "onBlockDestroyed", at = @At("HEAD"))
private void capturePlayerOnBlockDestroyed(World worldIn, IBlockState blockIn, BlockPos pos, EntityPlayer playerIn, CallbackInfo ci) {
if (!worldIn.isRemote) {
final PhaseTracker phaseTracker = PhaseTracker.getInstance();
final PhaseData peek = phaseTracker.getCurrentPhaseData();
final IPhaseState state = peek.state;
state.capturePlayerUsingStackToBreakBlock((ItemStack) this, (EntityPlayerMP) playerIn, peek.context);
}
}
use of org.spongepowered.common.event.tracking.IPhaseState in project SpongeCommon by SpongePowered.
the class ExplosionContext method populateFromCurrentState.
@SuppressWarnings("unchecked")
public ExplosionContext populateFromCurrentState() {
final PhaseData currentPhaseData = PhaseTracker.getInstance().getCurrentPhaseData();
((IPhaseState) currentPhaseData.state).appendContextPreExplosion(this, currentPhaseData.context);
return this;
}
Aggregations