|
19 | 19 |
|
20 | 20 | package me.moros.bending.fabric.mixin;
|
21 | 21 |
|
22 |
| -import java.util.Collections; |
23 | 22 | import java.util.List;
|
24 | 23 |
|
| 24 | +import com.llamalad7.mixinextras.injector.WrapWithCondition; |
25 | 25 | import me.moros.bending.fabric.event.ServerItemEvents;
|
26 | 26 | import net.minecraft.core.BlockPos;
|
27 | 27 | import net.minecraft.server.level.ServerLevel;
|
28 | 28 | import net.minecraft.world.InteractionResult;
|
29 | 29 | import net.minecraft.world.item.ItemStack;
|
30 | 30 | import net.minecraft.world.level.Explosion;
|
31 | 31 | import net.minecraft.world.level.Level;
|
32 |
| -import net.minecraft.world.level.block.state.BlockState; |
33 |
| -import net.minecraft.world.level.storage.loot.LootParams; |
34 |
| -import net.minecraft.world.level.storage.loot.parameters.LootContextParams; |
35 |
| -import org.spongepowered.asm.mixin.Final; |
36 | 32 | import org.spongepowered.asm.mixin.Mixin;
|
37 |
| -import org.spongepowered.asm.mixin.Shadow; |
38 | 33 | import org.spongepowered.asm.mixin.injection.At;
|
39 |
| -import org.spongepowered.asm.mixin.injection.Redirect; |
40 | 34 |
|
41 | 35 | @Mixin(Explosion.class)
|
42 | 36 | public abstract class ExplosionMixin {
|
43 |
| - @Shadow |
44 |
| - @Final |
45 |
| - private Level level; |
46 |
| - |
47 |
| - @Redirect(method = "finalizeExplosion", at = @At(value = "INVOKE", |
48 |
| - target = "Lnet/minecraft/world/level/block/state/BlockState;getDrops(Lnet/minecraft/world/level/storage/loot/LootParams$Builder;)Ljava/util/List;") |
49 |
| - ) |
50 |
| - private List<ItemStack> bending$blockDrops(BlockState state, LootParams.Builder builder) { |
51 |
| - var stacks = state.getDrops(builder); |
52 |
| - var pos = BlockPos.containing(builder.getParameter(LootContextParams.ORIGIN)); |
53 |
| - var result = ServerItemEvents.BLOCK_DROP_LOOT.invoker().onDropLoot((ServerLevel) level, pos, stacks); |
54 |
| - if (result.getResult() != InteractionResult.FAIL) { |
55 |
| - return result.getObject(); |
56 |
| - } |
57 |
| - return Collections.emptyList(); |
| 37 | + @WrapWithCondition(method = "finalizeExplosion", at = @At(value = "INVOKE", |
| 38 | + target = "Lnet/minecraft/world/level/block/Block;popResource(Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/item/ItemStack;)V")) |
| 39 | + private boolean bending$blockDrops(Level level, BlockPos pos, ItemStack itemStack) { |
| 40 | + var result = ServerItemEvents.BLOCK_DROP_LOOT.invoker().onDropLoot((ServerLevel) level, pos, List.of(itemStack)); |
| 41 | + return result.getResult() != InteractionResult.FAIL; |
58 | 42 | }
|
59 | 43 | }
|
0 commit comments