another extension for the mixin

This commit is contained in:
Jörg Henke 2020-07-28 08:41:48 +02:00
parent 18d4032f6c
commit abcf173057
3 changed files with 9 additions and 5 deletions

View File

@ -3,6 +3,7 @@ package de.jottyfan.minecraft.quickiefabric.event;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
@ -20,9 +21,9 @@ import net.minecraft.world.World;
*/
@Mixin(Block.class)
public class BlockBreakMixin {
@Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/block/Block;onBreak(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;Lnet/minecraft/entity/player/PlayerEntity;)V"), method = "interactOnBreak", cancellable = true)
private void interactOnBreak(final World world, final BlockPos blockPos, final BlockState blockState, final PlayerEntity player, final CallbackInfoReturnable<Boolean> info) {
ActionResult result = BreakBlockCallback.EVENT.invoker().interact(world, blockPos, blockState, player);
@Inject(method = "injectBlockBreakCallback", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/Block;onBreak(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;Lnet/minecraft/entity/player/PlayerEntity;)V"), cancellable = true)
private void interactOnBreak(final World world, final BlockPos blockPos, final BlockState blockState, final PlayerEntity player, final CallbackInfo info) {
ActionResult result = BreakBlockCallback.EVENT.invoker().injectBlockBreakCallback(world, blockPos, blockState, player);
if (result == ActionResult.FAIL) {
info.cancel();
}

View File

@ -17,7 +17,7 @@ public interface BreakBlockCallback {
Event<BreakBlockCallback> EVENT = EventFactory.createArrayBacked(BreakBlockCallback.class,
(listeners) -> (world, blockPos, blockState, player) -> {
for (BreakBlockCallback listener : listeners) {
ActionResult result = listener.interact(world, blockPos, blockState, player);
ActionResult result = listener.injectBlockBreakCallback(world, blockPos, blockState, player);
if (result != ActionResult.PASS) {
return result;
}
@ -25,5 +25,5 @@ public interface BreakBlockCallback {
return ActionResult.PASS;
});
ActionResult interact(World world, BlockPos blockPos, BlockState blockState, PlayerEntity player);
ActionResult injectBlockBreakCallback(World world, BlockPos blockPos, BlockState blockState, PlayerEntity player);
}

View File

@ -22,6 +22,9 @@
"de.jottyfan.minecraft.quickiefabric.QuickieFabric"
]
},
"mixins": [
"quickiefabric.mixins.json"
],
"depends": {
"fabricloader": ">=0.7.4",
"fabric": "*",