Merge pull request #1845 from mariusdkm/master

Fixing crash after clicking into the air using the #click command
This commit is contained in:
Leijurv 2020-10-14 10:59:34 -07:00 committed by GitHub
commit 5eeb33a6f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 20 additions and 19 deletions

View File

@ -20,7 +20,6 @@ package baritone.utils;
import baritone.Baritone; import baritone.Baritone;
import baritone.api.BaritoneAPI; import baritone.api.BaritoneAPI;
import baritone.api.pathing.goals.GoalBlock; import baritone.api.pathing.goals.GoalBlock;
import baritone.api.pathing.goals.GoalTwoBlocks;
import baritone.api.utils.BetterBlockPos; import baritone.api.utils.BetterBlockPos;
import baritone.api.utils.Helper; import baritone.api.utils.Helper;
import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.GuiScreen;
@ -43,8 +42,8 @@ import java.nio.FloatBuffer;
import java.nio.IntBuffer; import java.nio.IntBuffer;
import java.util.Collections; import java.util.Collections;
import static org.lwjgl.opengl.GL11.*;
import static baritone.api.command.IBaritoneChatControl.FORCE_COMMAND_PREFIX; import static baritone.api.command.IBaritoneChatControl.FORCE_COMMAND_PREFIX;
import static org.lwjgl.opengl.GL11.*;
public class GuiClick extends GuiScreen { public class GuiClick extends GuiScreen {
@ -79,24 +78,26 @@ public class GuiClick extends GuiScreen {
@Override @Override
protected void mouseReleased(int mouseX, int mouseY, int mouseButton) { protected void mouseReleased(int mouseX, int mouseY, int mouseButton) {
if (mouseButton == 0) { if (currentMouseOver != null) { //Catch this, or else a click into void will result in a crash
if (clickStart != null && !clickStart.equals(currentMouseOver)) { if (mouseButton == 0) {
BaritoneAPI.getProvider().getPrimaryBaritone().getSelectionManager().removeAllSelections(); if (clickStart != null && !clickStart.equals(currentMouseOver)) {
BaritoneAPI.getProvider().getPrimaryBaritone().getSelectionManager().addSelection(BetterBlockPos.from(clickStart), BetterBlockPos.from(currentMouseOver)); BaritoneAPI.getProvider().getPrimaryBaritone().getSelectionManager().removeAllSelections();
ITextComponent component = new TextComponentString("Selection made! For usage: " + Baritone.settings().prefix.value + "help sel"); BaritoneAPI.getProvider().getPrimaryBaritone().getSelectionManager().addSelection(BetterBlockPos.from(clickStart), BetterBlockPos.from(currentMouseOver));
component.getStyle() ITextComponent component = new TextComponentString("Selection made! For usage: " + Baritone.settings().prefix.value + "help sel");
.setColor(TextFormatting.WHITE) component.getStyle()
.setClickEvent(new ClickEvent( .setColor(TextFormatting.WHITE)
ClickEvent.Action.RUN_COMMAND, .setClickEvent(new ClickEvent(
FORCE_COMMAND_PREFIX + "help sel" ClickEvent.Action.RUN_COMMAND,
)); FORCE_COMMAND_PREFIX + "help sel"
Helper.HELPER.logDirect(component); ));
clickStart = null; Helper.HELPER.logDirect(component);
} else { clickStart = null;
BaritoneAPI.getProvider().getPrimaryBaritone().getCustomGoalProcess().setGoalAndPath(new GoalTwoBlocks(currentMouseOver)); } else {
BaritoneAPI.getProvider().getPrimaryBaritone().getCustomGoalProcess().setGoalAndPath(new GoalBlock(currentMouseOver));
}
} else if (mouseButton == 1) {
BaritoneAPI.getProvider().getPrimaryBaritone().getCustomGoalProcess().setGoalAndPath(new GoalBlock(currentMouseOver.up()));
} }
} else if (mouseButton == 1) {
BaritoneAPI.getProvider().getPrimaryBaritone().getCustomGoalProcess().setGoalAndPath(new GoalBlock(currentMouseOver.up()));
} }
clickStart = null; clickStart = null;
} }