From fa4e80c0995f5b98855745cddc195872363ed916 Mon Sep 17 00:00:00 2001 From: BlayTheNinth <1933180+BlayTheNinth@users.noreply.github.com> Date: Wed, 27 Dec 2023 14:41:41 +0100 Subject: [PATCH] feat: Open waystone settings even if waystone blocks are shift-clicked with an item in hand --- .../waystones/client/WaystonesClient.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/shared/src/main/java/net/blay09/mods/waystones/client/WaystonesClient.java b/shared/src/main/java/net/blay09/mods/waystones/client/WaystonesClient.java index ab4cbd26..8a709358 100644 --- a/shared/src/main/java/net/blay09/mods/waystones/client/WaystonesClient.java +++ b/shared/src/main/java/net/blay09/mods/waystones/client/WaystonesClient.java @@ -1,11 +1,18 @@ package net.blay09.mods.waystones.client; +import net.blay09.mods.balm.api.Balm; import net.blay09.mods.balm.api.client.BalmClient; +import net.blay09.mods.balm.api.event.client.UseItemInputEvent; import net.blay09.mods.waystones.InternalClientMethodsImpl; import net.blay09.mods.waystones.api.client.WaystonesClientAPI; +import net.blay09.mods.waystones.block.entity.WaystoneBlockEntityBase; import net.blay09.mods.waystones.client.requirement.RequirementClientRegistry; import net.blay09.mods.waystones.compat.Compat; +import net.blay09.mods.waystones.network.message.RequestEditWaystoneMessage; import net.minecraft.client.ClientBrandRetriever; +import net.minecraft.client.Minecraft; +import net.minecraft.world.phys.BlockHitResult; +import net.minecraft.world.phys.HitResult; import java.util.Locale; @@ -22,5 +29,22 @@ public static void initialize() { InventoryButtonGuiHandler.initialize(); Compat.isVivecraftInstalled = ClientBrandRetriever.getClientModName().toLowerCase(Locale.ENGLISH).contains(Compat.VIVECRAFT); + + Balm.getEvents().onEvent(UseItemInputEvent.class, event -> { + final var mc = Minecraft.getInstance(); + if (mc.level == null || mc.player == null || mc.hitResult == null || mc.hitResult.getType() != HitResult.Type.BLOCK) { + return; + } + + if (mc.player.isShiftKeyDown()) { + final var blockHitResult = (BlockHitResult) mc.hitResult; + final var targetBlockEntity = mc.level.getBlockEntity(blockHitResult.getBlockPos()); + if (targetBlockEntity instanceof WaystoneBlockEntityBase waystoneBlockEntity) { + Balm.getNetworking().sendToServer(new RequestEditWaystoneMessage(waystoneBlockEntity.getBlockPos())); + mc.player.swing(event.getHand()); + event.setCanceled(true); + } + } + }); } }