Skip to content

Commit

Permalink
Fix explosion mixin
Browse files Browse the repository at this point in the history
  • Loading branch information
SammySemicolon committed Nov 24, 2024
1 parent 2d5882a commit 19083f4
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 5 deletions.
37 changes: 37 additions & 0 deletions src/main/java/com/sammy/malum/mixin/BlockBehaviorMixin.java
Original file line number Diff line number Diff line change
@@ -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<ItemStack, BlockPos> 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);
}
}
5 changes: 0 additions & 5 deletions src/main/java/com/sammy/malum/mixin/ExplosionMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "<init>(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);
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/malum.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"AccessorEvent",
"AccessorEvent$PostDamage",
"AccessorFeatureFlagSet",
"BlockBehaviorMixin",
"ExplosionMixin",
"FeatureFlagSetMixin",
"FishingHookEntityMixin",
Expand Down

0 comments on commit 19083f4

Please sign in to comment.