Search in sources :

Example 1 with ExplosionAccessor

use of org.spongepowered.common.accessor.world.level.ExplosionAccessor in project SpongeCommon by SpongePowered.

the class DamageSourceMixin method onSetExplosionSource.

@Inject(method = "explosion(Lnet/minecraft/world/level/Explosion;)Lnet/minecraft/world/damagesource/DamageSource;", at = @At("HEAD"), cancellable = true)
private static void onSetExplosionSource(@Nullable final Explosion explosion, final CallbackInfoReturnable<net.minecraft.world.damagesource.DamageSource> cir) {
    if (explosion != null) {
        final Entity entity = ((ExplosionAccessor) explosion).accessor$source();
        if (entity != null && !((LevelBridge) ((ExplosionAccessor) explosion).accessor$level()).bridge$isFake()) {
            if (explosion.getSourceMob() == null && entity instanceof CreatorTrackedBridge) {
                // check creator
                final CreatorTrackedBridge creatorBridge = (CreatorTrackedBridge) entity;
                creatorBridge.tracker$getCreatorUUID().flatMap(x -> Sponge.server().player(x)).ifPresent(player -> {
                    final IndirectEntityDamageSource damageSource = new IndirectEntityDamageSource("explosion.player", entity, (Entity) player);
                    damageSource.setScalesWithDifficulty().setExplosion();
                    cir.setReturnValue(damageSource);
                });
            }
        }
    }
}
Also used : ExplosionAccessor(org.spongepowered.common.accessor.world.level.ExplosionAccessor) LivingEntity(net.minecraft.world.entity.LivingEntity) Inject(org.spongepowered.asm.mixin.injection.Inject) Supplier(java.util.function.Supplier) CallbackInfoReturnable(org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable) CallbackInfo(org.spongepowered.asm.mixin.injection.callback.CallbackInfo) CreatorTrackedBridge(org.spongepowered.common.bridge.CreatorTrackedBridge) DamageSourceBridge(org.spongepowered.common.bridge.world.damagesource.DamageSourceBridge) Mixin(org.spongepowered.asm.mixin.Mixin) DamageSource(net.minecraft.world.damagesource.DamageSource) ResourceKey(org.spongepowered.api.ResourceKey) IndirectEntityDamageSource(net.minecraft.world.damagesource.IndirectEntityDamageSource) Nullable(javax.annotation.Nullable) TranslatableComponent(net.minecraft.network.chat.TranslatableComponent) At(org.spongepowered.asm.mixin.injection.At) DamageSourceToTypeProvider(org.spongepowered.common.registry.provider.DamageSourceToTypeProvider) Mutable(org.spongepowered.asm.mixin.Mutable) LevelBridge(org.spongepowered.common.bridge.world.level.LevelBridge) Component(net.minecraft.network.chat.Component) DamageType(org.spongepowered.api.event.cause.entity.damage.DamageType) MoreObjects(com.google.common.base.MoreObjects) Sponge(org.spongepowered.api.Sponge) DamageTypes(org.spongepowered.api.event.cause.entity.damage.DamageTypes) ExplosionAccessor(org.spongepowered.common.accessor.world.level.ExplosionAccessor) Final(org.spongepowered.asm.mixin.Final) RegistryTypes(org.spongepowered.api.registry.RegistryTypes) Explosion(net.minecraft.world.level.Explosion) Entity(net.minecraft.world.entity.Entity) MemoizedSupplier(org.spongepowered.common.util.MemoizedSupplier) Shadow(org.spongepowered.asm.mixin.Shadow) LivingEntity(net.minecraft.world.entity.LivingEntity) Entity(net.minecraft.world.entity.Entity) CreatorTrackedBridge(org.spongepowered.common.bridge.CreatorTrackedBridge) LevelBridge(org.spongepowered.common.bridge.world.level.LevelBridge) IndirectEntityDamageSource(net.minecraft.world.damagesource.IndirectEntityDamageSource) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 2 with ExplosionAccessor

use of org.spongepowered.common.accessor.world.level.ExplosionAccessor in project SpongeCommon by SpongePowered.

the class ExplosionContext method isRunaway.

@Override
protected boolean isRunaway(final PhaseContext<?> phaseContext) {
    if (phaseContext.getClass() != ExplosionContext.class) {
        return false;
    }
    final ExplosionAccessor otherExplosion = (ExplosionAccessor) ((ExplosionContext) phaseContext).explosion;
    final ExplosionAccessor thisExplosion = (ExplosionAccessor) this.explosion;
    return otherExplosion.accessor$level() == thisExplosion.accessor$level() && otherExplosion.accessor$x() == thisExplosion.accessor$x() && otherExplosion.accessor$y() == thisExplosion.accessor$y() && otherExplosion.accessor$z() == thisExplosion.accessor$z();
}
Also used : ExplosionAccessor(org.spongepowered.common.accessor.world.level.ExplosionAccessor)

Aggregations

ExplosionAccessor (org.spongepowered.common.accessor.world.level.ExplosionAccessor)2 MoreObjects (com.google.common.base.MoreObjects)1 Supplier (java.util.function.Supplier)1 Nullable (javax.annotation.Nullable)1 Component (net.minecraft.network.chat.Component)1 TranslatableComponent (net.minecraft.network.chat.TranslatableComponent)1 DamageSource (net.minecraft.world.damagesource.DamageSource)1 IndirectEntityDamageSource (net.minecraft.world.damagesource.IndirectEntityDamageSource)1 Entity (net.minecraft.world.entity.Entity)1 LivingEntity (net.minecraft.world.entity.LivingEntity)1 Explosion (net.minecraft.world.level.Explosion)1 ResourceKey (org.spongepowered.api.ResourceKey)1 Sponge (org.spongepowered.api.Sponge)1 DamageType (org.spongepowered.api.event.cause.entity.damage.DamageType)1 DamageTypes (org.spongepowered.api.event.cause.entity.damage.DamageTypes)1 RegistryTypes (org.spongepowered.api.registry.RegistryTypes)1 Final (org.spongepowered.asm.mixin.Final)1 Mixin (org.spongepowered.asm.mixin.Mixin)1 Mutable (org.spongepowered.asm.mixin.Mutable)1 Shadow (org.spongepowered.asm.mixin.Shadow)1