TheBrokenRail
b6614da325
All checks were successful
SlightlyVanilla/pipeline/head This commit looks good
40 lines
1.9 KiB
Java
40 lines
1.9 KiB
Java
package com.thebrokenrail.slightlyvanilla.mixin;
|
|
|
|
import com.thebrokenrail.slightlyvanilla.SlightlyVanilla;
|
|
import com.thebrokenrail.slightlyvanilla.client.screen.NoteBlockScreen;
|
|
import net.fabricmc.api.EnvType;
|
|
import net.fabricmc.api.Environment;
|
|
import net.minecraft.block.Blocks;
|
|
import net.minecraft.client.MinecraftClient;
|
|
import net.minecraft.client.network.ClientPlayerEntity;
|
|
import net.minecraft.client.network.ClientPlayerInteractionManager;
|
|
import net.minecraft.client.world.ClientWorld;
|
|
import net.minecraft.screen.ScreenHandlerContext;
|
|
import net.minecraft.util.ActionResult;
|
|
import net.minecraft.util.Hand;
|
|
import net.minecraft.util.hit.BlockHitResult;
|
|
import org.spongepowered.asm.mixin.Final;
|
|
import org.spongepowered.asm.mixin.Mixin;
|
|
import org.spongepowered.asm.mixin.Shadow;
|
|
import org.spongepowered.asm.mixin.injection.At;
|
|
import org.spongepowered.asm.mixin.injection.Inject;
|
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
|
|
|
@Environment(EnvType.CLIENT)
|
|
@Mixin(ClientPlayerInteractionManager.class)
|
|
public class MixinClientPlayerInteractionManager {
|
|
@Shadow
|
|
@Final
|
|
private MinecraftClient client;
|
|
|
|
@Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;getStackInHand(Lnet/minecraft/util/Hand;)Lnet/minecraft/item/ItemStack;", ordinal = 0), method = "interactBlock", cancellable = true)
|
|
public void interactBlock(ClientPlayerEntity player, ClientWorld world, Hand hand, BlockHitResult hitResult, CallbackInfoReturnable<ActionResult> info) {
|
|
if (!player.isSpectator() && SlightlyVanilla.getConfig().noteBlockScreen && world.getBlockState(hitResult.getBlockPos()).getBlock() == Blocks.NOTE_BLOCK) {
|
|
NoteBlockScreen screen = new NoteBlockScreen(ScreenHandlerContext.create(world, hitResult.getBlockPos()));
|
|
client.openScreen(screen);
|
|
|
|
info.setReturnValue(ActionResult.SUCCESS);
|
|
}
|
|
}
|
|
}
|