Search in sources :

Example 1 with ExplosionContext

use of org.spongepowered.common.event.tracking.phase.general.ExplosionContext in project SpongeCommon by SpongePowered.

the class MixinWorldServer method newExplosion.

/**
 * @author gabizou - September 10th, 2016
 * @author gabizou - September 21st, 2017 - Update for PhaseContext refactor.
 * @reason Due to the amount of changes, and to ensure that Forge's events are being properly
 * thrown, we must overwrite to have our hooks in place where we need them to be and when.
 * Likewise, since the event context is very ambiguously created, we may have an entity
 * coming in, or no entity, the explosion must always have a "source" in some context.
 *
 * @param entityIn The entity that caused the explosion
 * @param x The x position
 * @param y The y position
 * @param z The z position
 * @param strength The strength of the explosion, determines what blocks can be destroyed
 * @param isFlaming Whether fire will be caused from the explosion
 * @param isSmoking Whether blocks will break
 * @return The explosion
 */
@Overwrite
@Override
public Explosion newExplosion(@Nullable net.minecraft.entity.Entity entityIn, double x, double y, double z, float strength, boolean isFlaming, boolean isSmoking) {
    Explosion explosion = new Explosion((WorldServer) (Object) this, entityIn, x, y, z, strength, isFlaming, isSmoking);
    // Sponge Start - Cause tracking
    try (final ExplosionContext context = GeneralPhase.State.EXPLOSION.createPhaseContext().potentialExplosionSource((WorldServer) (Object) this, entityIn).explosion(explosion).buildAndSwitch()) {
        this.processingExplosion = true;
        // Sponge End
        // Sponge Start - More cause tracking
        // Set up the pre event
        final ExplosionEvent.Pre event = SpongeEventFactory.createExplosionEventPre(Sponge.getCauseStackManager().getCurrentCause(), (org.spongepowered.api.world.explosion.Explosion) explosion, this);
        if (SpongeImpl.postEvent(event)) {
            this.processingExplosion = false;
            return explosion;
        }
        // Sponge End
        explosion.doExplosionA();
        explosion.doExplosionB(false);
        if (!isSmoking) {
            explosion.clearAffectedBlockPositions();
        }
        for (EntityPlayer entityplayer : this.playerEntities) {
            if (entityplayer.getDistanceSq(x, y, z) < 4096.0D) {
                ((EntityPlayerMP) entityplayer).connection.sendPacket(new SPacketExplosion(x, y, z, strength, explosion.getAffectedBlockPositions(), explosion.getPlayerKnockbackMap().get(entityplayer)));
            }
        }
        // Sponge Start - end processing
        this.processingExplosion = false;
        // Sponge End
        return explosion;
    }
// Sponge - brackets
}
Also used : Explosion(net.minecraft.world.Explosion) SPacketExplosion(net.minecraft.network.play.server.SPacketExplosion) ExplosionContext(org.spongepowered.common.event.tracking.phase.general.ExplosionContext) SPacketExplosion(net.minecraft.network.play.server.SPacketExplosion) ExplosionEvent(org.spongepowered.api.event.world.ExplosionEvent) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Aggregations

EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 SPacketExplosion (net.minecraft.network.play.server.SPacketExplosion)1 Explosion (net.minecraft.world.Explosion)1 ExplosionEvent (org.spongepowered.api.event.world.ExplosionEvent)1 Overwrite (org.spongepowered.asm.mixin.Overwrite)1 ExplosionContext (org.spongepowered.common.event.tracking.phase.general.ExplosionContext)1