From 2a4110e11910f8103d96c035d1ca3377a7151b44 Mon Sep 17 00:00:00 2001 From: ZhuRuoLing Date: Fri, 20 Dec 2024 16:25:39 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=97=A0=E6=9E=81=E6=BB=9A=E8=BD=AE?= =?UTF-8?q?=E6=91=A7=E6=AF=81=E9=93=81=E7=A0=A7=E9=94=A4=20=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E4=BE=A6=E6=B5=8B=E5=99=A8=E4=B8=8D=E8=83=BD=E8=B0=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../event/ClientBlockEventListener.java | 2 +- .../client/gui/screen/AnvilHammerScreen.java | 27 +++++++++++++++++++ .../anvilcraft/event/BlockEventListener.java | 2 +- 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/main/java/dev/dubhe/anvilcraft/client/event/ClientBlockEventListener.java b/src/main/java/dev/dubhe/anvilcraft/client/event/ClientBlockEventListener.java index c3dc315ed..90be171f3 100644 --- a/src/main/java/dev/dubhe/anvilcraft/client/event/ClientBlockEventListener.java +++ b/src/main/java/dev/dubhe/anvilcraft/client/event/ClientBlockEventListener.java @@ -38,7 +38,7 @@ public static void anvilHammerUse(@NotNull PlayerInteractEvent.RightClickBlock e if (AnvilHammerItem.ableToUseAnvilHammer(event.getLevel(), event.getPos(), event.getEntity())) { Block b = event.getLevel().getBlockState(event.getPos()).getBlock(); if ((b instanceof IHammerRemovable || b.defaultBlockState().is(ModBlockTags.HAMMER_REMOVABLE)) - && !(b instanceof IHammerChangeable) + && !(b instanceof IHammerChangeable || b.defaultBlockState().is(ModBlockTags.HAMMER_CHANGEABLE)) && !event.getEntity().isShiftKeyDown() ) { return; diff --git a/src/main/java/dev/dubhe/anvilcraft/client/gui/screen/AnvilHammerScreen.java b/src/main/java/dev/dubhe/anvilcraft/client/gui/screen/AnvilHammerScreen.java index e496ebfce..0e204c08a 100644 --- a/src/main/java/dev/dubhe/anvilcraft/client/gui/screen/AnvilHammerScreen.java +++ b/src/main/java/dev/dubhe/anvilcraft/client/gui/screen/AnvilHammerScreen.java @@ -155,6 +155,33 @@ protected void init() { ).mul(1, -1); } + @Override + public boolean mouseScrolled(double mouseX, double mouseY, double scrollX, double scrollY) { + System.out.println("scrollX = " + scrollX); + System.out.println("scrollY = " + scrollY); + int selectionIdx = possibleStates.indexOf(currentBlockState); + if (scrollY > 0) { + if (selectionIdx == possibleStates.size() - 1) { + selectionIdx = 0; + } else { + selectionIdx++; + } + } else if (scrollY < 0) { + if (selectionIdx == 0) { + selectionIdx = possibleStates.size() - 1; + } else { + selectionIdx--; + } + } + currentBlockState = possibleStates.get(selectionIdx); + targetAngle = items.stream() + .filter(it -> it.state == currentBlockState) + .findFirst() + .orElseThrow() + .angle; + return true; + } + @Override public boolean mouseDragged(double mouseX, double mouseY, int button, double dragX, double dragY) { if (closingAnimationStarted) return true; diff --git a/src/main/java/dev/dubhe/anvilcraft/event/BlockEventListener.java b/src/main/java/dev/dubhe/anvilcraft/event/BlockEventListener.java index c011f1420..e35826a5c 100644 --- a/src/main/java/dev/dubhe/anvilcraft/event/BlockEventListener.java +++ b/src/main/java/dev/dubhe/anvilcraft/event/BlockEventListener.java @@ -45,7 +45,7 @@ public static void anvilHammerUse(@NotNull PlayerInteractEvent.RightClickBlock e if (AnvilHammerItem.ableToUseAnvilHammer(event.getLevel(), event.getPos(), event.getEntity())) { Block b = event.getLevel().getBlockState(event.getPos()).getBlock(); if ((b instanceof IHammerRemovable || b.defaultBlockState().is(ModBlockTags.HAMMER_REMOVABLE)) - && !(b instanceof IHammerChangeable) + && !(b instanceof IHammerChangeable || b.defaultBlockState().is(ModBlockTags.HAMMER_CHANGEABLE)) && !event.getEntity().isShiftKeyDown() ) { return; From feb247a3aa394c612653d8a04460fcd4d2764908 Mon Sep 17 00:00:00 2001 From: ZhuRuoLing Date: Fri, 20 Dec 2024 16:26:42 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=88=A0println?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dubhe/anvilcraft/client/gui/screen/AnvilHammerScreen.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/dev/dubhe/anvilcraft/client/gui/screen/AnvilHammerScreen.java b/src/main/java/dev/dubhe/anvilcraft/client/gui/screen/AnvilHammerScreen.java index 0e204c08a..13ea116d1 100644 --- a/src/main/java/dev/dubhe/anvilcraft/client/gui/screen/AnvilHammerScreen.java +++ b/src/main/java/dev/dubhe/anvilcraft/client/gui/screen/AnvilHammerScreen.java @@ -157,8 +157,6 @@ protected void init() { @Override public boolean mouseScrolled(double mouseX, double mouseY, double scrollX, double scrollY) { - System.out.println("scrollX = " + scrollX); - System.out.println("scrollY = " + scrollY); int selectionIdx = possibleStates.indexOf(currentBlockState); if (scrollY > 0) { if (selectionIdx == possibleStates.size() - 1) {