Search in sources :

Example 1 with SPacketExplosion

use of net.minecraft.network.play.server.SPacketExplosion 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)

Example 2 with SPacketExplosion

use of net.minecraft.network.play.server.SPacketExplosion in project BuildCraft by BuildCraft.

the class BlockUtil method explodeBlock.

/**
 * Create an explosion which only affects a single block.
 */
public static void explodeBlock(World world, BlockPos pos) {
    if (FMLCommonHandler.instance().getEffectiveSide().isClient()) {
        return;
    }
    double x = pos.getX() + 0.5;
    double y = pos.getY() + 0.5;
    double z = pos.getZ() + 0.5;
    Explosion explosion = new Explosion(world, null, x, y, z, 3f, false, false);
    explosion.getAffectedBlockPositions().add(pos);
    explosion.doExplosionB(true);
    for (EntityPlayer player : world.playerEntities) {
        if (!(player instanceof EntityPlayerMP)) {
            continue;
        }
        if (player.getDistanceSq(pos) < 4096) {
            ((EntityPlayerMP) player).connection.sendPacket(new SPacketExplosion(x, y, z, 3f, explosion.getAffectedBlockPositions(), null));
        }
    }
}
Also used : Explosion(net.minecraft.world.Explosion) SPacketExplosion(net.minecraft.network.play.server.SPacketExplosion) SPacketExplosion(net.minecraft.network.play.server.SPacketExplosion) EntityPlayer(net.minecraft.entity.player.EntityPlayer) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP)

Example 3 with SPacketExplosion

use of net.minecraft.network.play.server.SPacketExplosion in project takumicraft by TNTModders.

the class TakumiUtils method takumiCreateExplosion.

public static void takumiCreateExplosion(World world, Entity entity, double x, double y, double z, float power, boolean fire, boolean destroy, double amp) {
    boolean flg = world instanceof WorldServer;
    TakumiExplosion explosion = new TakumiExplosion(world, entity, x, y, z, power, fire, destroy, amp);
    if (ForgeEventFactory.onExplosionStart(world, explosion)) {
        return;
    }
    explosion.doExplosionA();
    explosion.doExplosionB(!flg);
    if (flg) {
        if (!fire) {
            explosion.clearAffectedBlockPositions();
        }
        for (EntityPlayer entityplayer : world.playerEntities) {
            if (entityplayer.getDistanceSq(x, y, z) < 4096.0D) {
                ((EntityPlayerMP) entityplayer).connection.sendPacket(new SPacketExplosion(x, y, z, power, explosion.getAffectedBlockPositions(), explosion.getPlayerKnockbackMap().get(entityplayer)));
            }
        }
    }
}
Also used : TakumiExplosion(com.tntmodders.takumi.world.TakumiExplosion) SPacketExplosion(net.minecraft.network.play.server.SPacketExplosion) EntityPlayer(net.minecraft.entity.player.EntityPlayer) WorldServer(net.minecraft.world.WorldServer)

Example 4 with SPacketExplosion

use of net.minecraft.network.play.server.SPacketExplosion in project SpongeCommon by SpongePowered.

the class MixinWorldServer method triggerExplosion.

@Override
public void triggerExplosion(org.spongepowered.api.world.explosion.Explosion explosion) {
    checkNotNull(explosion, "explosion");
    Location<org.spongepowered.api.world.World> origin = explosion.getLocation();
    checkNotNull(origin, "location");
    final PhaseTracker phaseTracker = PhaseTracker.getInstance();
    try (final PhaseContext<?> phaseContext = PluginPhase.State.CUSTOM_EXPLOSION.createPhaseContext().explosion(explosion).buildAndSwitch()) {
        final Explosion mcExplosion;
        try {
            // Since we already have the API created implementation Explosion, let's use it.
            mcExplosion = (Explosion) explosion;
        } catch (Exception e) {
            new PrettyPrinter(60).add("Explosion not compatible with this implementation").centre().hr().add("An explosion that was expected to be used for this implementation does not").add("originate from this implementation.").add(e).trace();
            return;
        }
        final double x = mcExplosion.x;
        final double y = mcExplosion.y;
        final double z = mcExplosion.z;
        final boolean damagesTerrain = explosion.shouldBreakBlocks();
        final float strength = explosion.getRadius();
        // Set up the pre event
        final ExplosionEvent.Pre event = SpongeEventFactory.createExplosionEventPre(Sponge.getCauseStackManager().getCurrentCause(), explosion, this);
        if (SpongeImpl.postEvent(event)) {
            this.processingExplosion = false;
            return;
        }
        // Sponge End
        mcExplosion.doExplosionA();
        mcExplosion.doExplosionB(false);
        if (!damagesTerrain) {
            mcExplosion.clearAffectedBlockPositions();
        }
        for (EntityPlayer entityplayer : this.playerEntities) {
            if (entityplayer.getDistanceSq(x, y, z) < 4096.0D) {
                ((EntityPlayerMP) entityplayer).connection.sendPacket(new SPacketExplosion(x, y, z, strength, mcExplosion.getAffectedBlockPositions(), mcExplosion.getPlayerKnockbackMap().get(entityplayer)));
            }
        }
        // Sponge Start - end processing
        this.processingExplosion = false;
    }
// Sponge End
}
Also used : Explosion(net.minecraft.world.Explosion) SPacketExplosion(net.minecraft.network.play.server.SPacketExplosion) ExplosionEvent(org.spongepowered.api.event.world.ExplosionEvent) World(net.minecraft.world.World) ReportedException(net.minecraft.util.ReportedException) MinecraftException(net.minecraft.world.MinecraftException) IOException(java.io.IOException) PositionOutOfBoundsException(org.spongepowered.api.util.PositionOutOfBoundsException) PrettyPrinter(org.spongepowered.asm.util.PrettyPrinter) PhaseTracker(org.spongepowered.common.event.tracking.PhaseTracker) SPacketExplosion(net.minecraft.network.play.server.SPacketExplosion) EntityPlayer(net.minecraft.entity.player.EntityPlayer)

Aggregations

EntityPlayer (net.minecraft.entity.player.EntityPlayer)4 SPacketExplosion (net.minecraft.network.play.server.SPacketExplosion)4 Explosion (net.minecraft.world.Explosion)3 ExplosionEvent (org.spongepowered.api.event.world.ExplosionEvent)2 TakumiExplosion (com.tntmodders.takumi.world.TakumiExplosion)1 IOException (java.io.IOException)1 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)1 ReportedException (net.minecraft.util.ReportedException)1 MinecraftException (net.minecraft.world.MinecraftException)1 World (net.minecraft.world.World)1 WorldServer (net.minecraft.world.WorldServer)1 PositionOutOfBoundsException (org.spongepowered.api.util.PositionOutOfBoundsException)1 Overwrite (org.spongepowered.asm.mixin.Overwrite)1 PrettyPrinter (org.spongepowered.asm.util.PrettyPrinter)1 PhaseTracker (org.spongepowered.common.event.tracking.PhaseTracker)1 ExplosionContext (org.spongepowered.common.event.tracking.phase.general.ExplosionContext)1