From 19083f4a010a9523f172cb2e2e1de7ab8dc4b407 Mon Sep 17 00:00:00 2001 From: SammySemicolon Date: Sun, 24 Nov 2024 21:18:41 +0100 Subject: [PATCH] Fix explosion mixin --- .../sammy/malum/mixin/BlockBehaviorMixin.java | 37 +++++++++++++++++++ .../com/sammy/malum/mixin/ExplosionMixin.java | 5 --- src/main/resources/malum.mixins.json | 1 + .../META-INF/neoforge.mods.toml | 0 4 files changed, 38 insertions(+), 5 deletions(-) create mode 100644 src/main/java/com/sammy/malum/mixin/BlockBehaviorMixin.java rename src/main/{resources => templates}/META-INF/neoforge.mods.toml (100%) diff --git a/src/main/java/com/sammy/malum/mixin/BlockBehaviorMixin.java b/src/main/java/com/sammy/malum/mixin/BlockBehaviorMixin.java new file mode 100644 index 000000000..3970b0d8e --- /dev/null +++ b/src/main/java/com/sammy/malum/mixin/BlockBehaviorMixin.java @@ -0,0 +1,37 @@ +package com.sammy.malum.mixin; + +import com.sammy.malum.common.item.curiosities.curios.sets.prospector.CurioProspectorBelt; +import net.minecraft.core.BlockPos; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.Explosion; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.state.BlockBehaviour; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.storage.loot.LootParams; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Unique; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.ModifyArg; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import java.util.function.BiConsumer; + +@Mixin(BlockBehaviour.class) +public class BlockBehaviorMixin { + + @Unique + Explosion malum$explosion; + + @Inject(method = "onExplosionHit", at = @At(value = "HEAD")) + private void malum$getBlockDrops$cacheExplosion(BlockState state, Level level, BlockPos pos, Explosion explosion, BiConsumer dropConsumer, CallbackInfo ci) { + malum$explosion = explosion; + } + @ModifyArg(method = "onExplosionHit", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/block/state/BlockState;getDrops(Lnet/minecraft/world/level/storage/loot/LootParams$Builder;)Ljava/util/List;")) + private LootParams.Builder malum$getBlockDrops(LootParams.Builder builder) { + if (malum$explosion == null) { + return builder; + } + return CurioProspectorBelt.applyFortune(malum$explosion.getIndirectSourceEntity(), builder); + } +} diff --git a/src/main/java/com/sammy/malum/mixin/ExplosionMixin.java b/src/main/java/com/sammy/malum/mixin/ExplosionMixin.java index c9389d348..8b83eb427 100644 --- a/src/main/java/com/sammy/malum/mixin/ExplosionMixin.java +++ b/src/main/java/com/sammy/malum/mixin/ExplosionMixin.java @@ -40,11 +40,6 @@ public abstract class ExplosionMixin { @Nullable public abstract LivingEntity getIndirectSourceEntity(); - @ModifyArg(method = "finalizeExplosion", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/block/state/BlockState;getDrops(Lnet/minecraft/world/level/storage/loot/LootParams$Builder;)Ljava/util/List;")) - private LootParams.Builder malum$getBlockDrops(LootParams.Builder builder) { - return CurioProspectorBelt.applyFortune(getIndirectSourceEntity(), builder); - } - @Inject(method = "(Lnet/minecraft/world/level/Level;Lnet/minecraft/world/entity/Entity;Lnet/minecraft/world/damagesource/DamageSource;Lnet/minecraft/world/level/ExplosionDamageCalculator;DDDFZLnet/minecraft/world/level/Explosion$BlockInteraction;Lnet/minecraft/core/particles/ParticleOptions;Lnet/minecraft/core/particles/ParticleOptions;Lnet/minecraft/core/Holder;)V", at = @At(value = "RETURN")) private void malum$modifyExplosionStats(Level level, Entity source, DamageSource damageSource, ExplosionDamageCalculator damageCalculator, double x, double y, double z, float radius, boolean fire, Explosion.BlockInteraction blockInteraction, ParticleOptions smallExplosionParticles, ParticleOptions largeExplosionParticles, Holder explosionSound, CallbackInfo ci) { this.radius = CurioDemolitionistRing.increaseExplosionRadius(getIndirectSourceEntity(), radius); diff --git a/src/main/resources/malum.mixins.json b/src/main/resources/malum.mixins.json index eb79451aa..5407677de 100644 --- a/src/main/resources/malum.mixins.json +++ b/src/main/resources/malum.mixins.json @@ -7,6 +7,7 @@ "AccessorEvent", "AccessorEvent$PostDamage", "AccessorFeatureFlagSet", + "BlockBehaviorMixin", "ExplosionMixin", "FeatureFlagSetMixin", "FishingHookEntityMixin", diff --git a/src/main/resources/META-INF/neoforge.mods.toml b/src/main/templates/META-INF/neoforge.mods.toml similarity index 100% rename from src/main/resources/META-INF/neoforge.mods.toml rename to src/main/templates/META-INF/neoforge.mods.toml