Overclicked

- Fixed Schematic and Quill selection registering mouse clicks twice
This commit is contained in:
simibubi 2022-09-28 23:43:09 +02:00
parent 97906cb4cc
commit 4985a521a4
3 changed files with 20 additions and 17 deletions

View file

@ -98,40 +98,41 @@ public class SchematicAndQuillHandler {
return true; return true;
} }
public void onMouseInput(int button, boolean pressed) { public boolean onMouseInput(int button, boolean pressed) {
if (!pressed || button != 1) if (!pressed || button != 1)
return; return false;
if (!isActive()) if (!isActive())
return; return false;
LocalPlayer player = Minecraft.getInstance().player; LocalPlayer player = Minecraft.getInstance().player;
if (player.isShiftKeyDown()) { if (player.isShiftKeyDown()) {
discard(); discard();
return; return true;
} }
if (secondPos != null) { if (secondPos != null) {
ScreenOpener.open(new SchematicPromptScreen()); ScreenOpener.open(new SchematicPromptScreen());
return; return true;
} }
if (selectedPos == null) { if (selectedPos == null) {
Lang.translate("schematicAndQuill.noTarget") Lang.translate("schematicAndQuill.noTarget")
.sendStatus(player); .sendStatus(player);
return; return true;
} }
if (firstPos != null) { if (firstPos != null) {
secondPos = selectedPos; secondPos = selectedPos;
Lang.translate("schematicAndQuill.secondPos") Lang.translate("schematicAndQuill.secondPos")
.sendStatus(player); .sendStatus(player);
return; return true;
} }
firstPos = selectedPos; firstPos = selectedPos;
Lang.translate("schematicAndQuill.firstPos") Lang.translate("schematicAndQuill.firstPos")
.sendStatus(player); .sendStatus(player);
return true;
} }
public void discard() { public void discard() {

View file

@ -243,23 +243,23 @@ public class SchematicHandler {
selectionScreen.renderPassive(poseStack, partialTicks); selectionScreen.renderPassive(poseStack, partialTicks);
} }
public void onMouseInput(int button, boolean pressed) { public boolean onMouseInput(int button, boolean pressed) {
if (!active) if (!active)
return; return false;
if (!pressed || button != 1) if (!pressed || button != 1)
return; return false;
Minecraft mc = Minecraft.getInstance(); Minecraft mc = Minecraft.getInstance();
if (mc.player.isShiftKeyDown()) if (mc.player.isShiftKeyDown())
return; return false;
if (mc.hitResult instanceof BlockHitResult) { if (mc.hitResult instanceof BlockHitResult) {
BlockHitResult blockRayTraceResult = (BlockHitResult) mc.hitResult; BlockHitResult blockRayTraceResult = (BlockHitResult) mc.hitResult;
BlockState clickedBlock = mc.level.getBlockState(blockRayTraceResult.getBlockPos()); BlockState clickedBlock = mc.level.getBlockState(blockRayTraceResult.getBlockPos());
if (AllBlocks.SCHEMATICANNON.has(clickedBlock)) if (AllBlocks.SCHEMATICANNON.has(clickedBlock))
return; return false;
if (AllBlocks.DEPLOYER.has(clickedBlock)) if (AllBlocks.DEPLOYER.has(clickedBlock))
return; return false;
} }
currentTool.getTool() return currentTool.getTool()
.handleRightClick(); .handleRightClick();
} }

View file

@ -45,15 +45,17 @@ public class InputEvents {
} }
@SubscribeEvent @SubscribeEvent
public static void onMouseInput(InputEvent.MouseButton event) { public static void onMouseInput(InputEvent.MouseButton.Pre event) {
if (Minecraft.getInstance().screen != null) if (Minecraft.getInstance().screen != null)
return; return;
int button = event.getButton(); int button = event.getButton();
boolean pressed = !(event.getAction() == 0); boolean pressed = !(event.getAction() == 0);
CreateClient.SCHEMATIC_HANDLER.onMouseInput(button, pressed); if (CreateClient.SCHEMATIC_HANDLER.onMouseInput(button, pressed))
CreateClient.SCHEMATIC_AND_QUILL_HANDLER.onMouseInput(button, pressed); event.setCanceled(true);
else if (CreateClient.SCHEMATIC_AND_QUILL_HANDLER.onMouseInput(button, pressed))
event.setCanceled(true);
} }
@SubscribeEvent @SubscribeEvent