Skip to content

Commit

Permalink
HUGE code revamp
Browse files Browse the repository at this point in the history
  • Loading branch information
Jelly298 committed Jul 13, 2022
1 parent a8545f7 commit adc4991
Show file tree
Hide file tree
Showing 37 changed files with 1,196 additions and 946 deletions.
14 changes: 8 additions & 6 deletions src/main/java/com/jelly/CaneBuilder/BuilderState.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,33 @@

import com.jelly.CaneBuilder.config.Config;
import com.jelly.CaneBuilder.structures.Coord;
import com.jelly.CaneBuilder.utils.Utils;
import com.jelly.CaneBuilder.utils.LogUtils;
import net.minecraft.client.Minecraft;
import net.minecraft.util.BlockPos;
import net.minecraft.util.EnumChatFormatting;

public class BuilderState {
private static final Minecraft mc = Minecraft.getMinecraft();

public static boolean enabled = false;
public static boolean paused = false;
public static Coord corner1 = null;
public static Coord corner2 = null;
public static int direction = -1;
public static int layer = 0;
public static boolean isSwitchingLayer = false;
public static boolean log = true;

public static void setCorner1(int x, int y, int z) {
corner1 = new Coord(x, y, z);
Utils.addCustomMessage("Set corner 1 to: " + corner1, EnumChatFormatting.GREEN);
LogUtils.addCustomMessage("Set corner 1 to: " + corner1, EnumChatFormatting.GREEN);
Config.writeConfig();
}

public static void setCorner2(int x, int y, int z) {
corner2 = new Coord(x, y, z);
Utils.addCustomMessage("Set corner 2 to: " + corner2, EnumChatFormatting.GREEN);
LogUtils.addCustomMessage("Set corner 2 to: " + corner2, EnumChatFormatting.GREEN);
Config.writeConfig();
}


public static int lookingAtParallel() {
if (direction == 0) {
return mc.objectMouseOver.getBlockPos().getZ();
Expand Down Expand Up @@ -64,4 +64,6 @@ public static int onPerpendicular() {
}
return -1;
}


}
371 changes: 28 additions & 343 deletions src/main/java/com/jelly/CaneBuilder/CaneBuilder.java

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions src/main/java/com/jelly/CaneBuilder/commands/Corner1.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.jelly.CaneBuilder.commands;

import com.jelly.CaneBuilder.BuilderState;
import com.jelly.CaneBuilder.utils.Utils;
import com.jelly.CaneBuilder.utils.LogUtils;
import net.minecraft.client.Minecraft;
import net.minecraft.command.CommandBase;
import net.minecraft.command.CommandException;
Expand Down Expand Up @@ -34,10 +34,10 @@ public void processCommand(ICommandSender sender, String[] args) throws CommandE
} else if (args.length == 3) {
BuilderState.setCorner1(Integer.parseInt(args[0]), Integer.parseInt(args[1]), Integer.parseInt(args[2]));
} else {
Utils.addCustomMessage("Error, Usage: /corner1 or /corner1 <x> <y> <z>", EnumChatFormatting.RED);
LogUtils.addCustomMessage("Error, Usage: /corner1 or /corner1 <x> <y> <z>", EnumChatFormatting.RED);
}
} catch (Exception e) {
Utils.addCustomMessage("Error, Usage: /corner1 or /corner1 <x> <y> <z>", EnumChatFormatting.RED);
LogUtils.addCustomMessage("Error, Usage: /corner1 or /corner1 <x> <y> <z>", EnumChatFormatting.RED);
}
}
}
6 changes: 3 additions & 3 deletions src/main/java/com/jelly/CaneBuilder/commands/Corner2.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.jelly.CaneBuilder.commands;

import com.jelly.CaneBuilder.BuilderState;
import com.jelly.CaneBuilder.utils.Utils;
import com.jelly.CaneBuilder.utils.LogUtils;
import net.minecraft.client.Minecraft;
import net.minecraft.command.CommandBase;
import net.minecraft.command.CommandException;
Expand Down Expand Up @@ -34,10 +34,10 @@ public void processCommand(ICommandSender sender, String[] args) throws CommandE
} else if (args.length == 3) {
BuilderState.setCorner2(Integer.parseInt(args[0]), Integer.parseInt(args[1]), Integer.parseInt(args[2]));
} else {
Utils.addCustomMessage("Error, Usage: /corner2 or /corner2 <x> <y> <z>", EnumChatFormatting.RED);
LogUtils.addCustomMessage("Error, Usage: /corner2 or /corner2 <x> <y> <z>", EnumChatFormatting.RED);
}
} catch (Exception e) {
Utils.addCustomMessage("Error, Usage: /corner2 or /corner2 <x> <y> <z>", EnumChatFormatting.RED);
LogUtils.addCustomMessage("Error, Usage: /corner2 or /corner2 <x> <y> <z>", EnumChatFormatting.RED);
}
}
}
11 changes: 5 additions & 6 deletions src/main/java/com/jelly/CaneBuilder/commands/SetDirection.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

import com.jelly.CaneBuilder.BuilderState;
import com.jelly.CaneBuilder.config.Config;
import com.jelly.CaneBuilder.utils.Utils;
import com.jelly.CaneBuilder.utils.LogUtils;
import net.minecraft.command.CommandBase;
import net.minecraft.command.CommandException;
import net.minecraft.command.ICommandSender;
import net.minecraft.util.EnumChatFormatting;

Expand All @@ -28,18 +27,18 @@ public int getRequiredPermissionLevel() {
public void processCommand(ICommandSender sender, String[] args) {
try {
if (Integer.parseInt(args[0]) == 0) {
Utils.addCustomMessage("Set direction to N/S", EnumChatFormatting.GREEN);
LogUtils.addCustomMessage("Set direction to N/S", EnumChatFormatting.GREEN);
BuilderState.direction = 0;
Config.writeConfig();
} else if (Integer.parseInt(args[0]) == 1) {
Utils.addCustomMessage("Set direction to E/W", EnumChatFormatting.GREEN);
LogUtils.addCustomMessage("Set direction to E/W", EnumChatFormatting.GREEN);
BuilderState.direction = 1;
Config.writeConfig();
} else {
Utils.addCustomMessage("Error, Usage: /direction [0/1]", EnumChatFormatting.RED);
LogUtils.addCustomMessage("Error, Usage: /direction [0/1]", EnumChatFormatting.RED);
}
} catch (Exception e) {
Utils.addCustomMessage("Error, Usage: /direction [0/1]", EnumChatFormatting.RED);
LogUtils.addCustomMessage("Error, Usage: /direction [0/1]", EnumChatFormatting.RED);
}
}
}
10 changes: 4 additions & 6 deletions src/main/java/com/jelly/CaneBuilder/commands/SetLayer.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package com.jelly.CaneBuilder.commands;

import com.jelly.CaneBuilder.BuilderState;
import com.jelly.CaneBuilder.utils.Utils;
import net.minecraft.client.Minecraft;
import com.jelly.CaneBuilder.utils.LogUtils;
import net.minecraft.command.CommandBase;
import net.minecraft.command.CommandException;
import net.minecraft.command.ICommandSender;
import net.minecraft.util.EnumChatFormatting;

public class SetLayer extends CommandBase {
Minecraft mc = Minecraft.getMinecraft();

@Override
public String getCommandName() {
Expand All @@ -31,12 +29,12 @@ public void processCommand(ICommandSender sender, String[] args) throws CommandE
try {
if (args.length == 1){
BuilderState.layer = Integer.parseInt(args[0]);
Utils.addCustomMessage("Set layer count to : " + args[0]);
LogUtils.addCustomMessage("Set layer count to : " + args[0]);
} else {
Utils.addCustomMessage("Error, Usage: /layer <n>", EnumChatFormatting.RED);
LogUtils.addCustomMessage("Error, Usage: /layer <n>", EnumChatFormatting.RED);
}
} catch (Exception e) {
Utils.addCustomMessage("Error, Usage: /layer <n>", EnumChatFormatting.RED);
LogUtils.addCustomMessage("Error, Usage: /layer <n>", EnumChatFormatting.RED);
}
}
}
44 changes: 44 additions & 0 deletions src/main/java/com/jelly/CaneBuilder/commands/ToggleLog.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.jelly.CaneBuilder.commands;

import com.jelly.CaneBuilder.BuilderState;
import com.jelly.CaneBuilder.config.Config;
import com.jelly.CaneBuilder.utils.LogUtils;
import net.minecraft.command.CommandBase;
import net.minecraft.command.ICommandSender;
import net.minecraft.util.EnumChatFormatting;

public class ToggleLog extends CommandBase {
@Override
public String getCommandName() {
return "log";
}

@Override
public String getCommandUsage(ICommandSender sender) {
return "Toggles on/off debug logs";
}

@Override
public int getRequiredPermissionLevel() {
return 0;
}

@Override
public void processCommand(ICommandSender sender, String[] args) {
try {
if (args[0].equals("on")) {
BuilderState.log = true;
LogUtils.addCustomMessage("Set debug log to on", EnumChatFormatting.RED);
Config.writeConfig();
} else if (args[0].equals("off")){
BuilderState.log = false;
LogUtils.addCustomMessage("Set debug log to off", EnumChatFormatting.RED);
Config.writeConfig();
} else {
LogUtils.addCustomMessage("Error, Usage: /log [on/off]", EnumChatFormatting.RED);
}
} catch (Exception e) {
LogUtils.addCustomMessage("Error, Usage: /log [on/off]", EnumChatFormatting.RED);
}
}
}
11 changes: 8 additions & 3 deletions src/main/java/com/jelly/CaneBuilder/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
import java.io.FileWriter;

public class Config {
public static void setConfig(Coord c1, Coord c2, int direction) {
public static void setConfig(Coord c1, Coord c2, int direction, boolean log) {
BuilderState.corner1 = c1;
BuilderState.corner2 = c2;
BuilderState.direction = direction;
BuilderState.log = log;

}

public static void writeConfig() {
Expand All @@ -27,6 +29,8 @@ public static void writeConfig() {
bufferedWriter.write("\n" + BuilderState.corner2.getZ());

bufferedWriter.write("\n" + BuilderState.direction);

bufferedWriter.write("\n" + BuilderState.log);
bufferedWriter.close();
} catch (Exception e) {
e.printStackTrace();
Expand All @@ -37,11 +41,12 @@ public static void readConfig() throws Exception {
try {
BufferedReader bufferedReader = new BufferedReader(new FileReader("config/canebuilder.txt"));
bufferedReader.readLine();
String url;
setConfig(
new Coord(Integer.parseInt(bufferedReader.readLine()), Integer.parseInt(bufferedReader.readLine()), Integer.parseInt(bufferedReader.readLine())),
new Coord(Integer.parseInt(bufferedReader.readLine()), Integer.parseInt(bufferedReader.readLine()), Integer.parseInt(bufferedReader.readLine())),
Integer.parseInt(bufferedReader.readLine())
Integer.parseInt(bufferedReader.readLine()),
Boolean.parseBoolean(bufferedReader.readLine())

);
bufferedReader.close();
} catch (Exception e) {
Expand Down
72 changes: 50 additions & 22 deletions src/main/java/com/jelly/CaneBuilder/features/Failsafe.java
Original file line number Diff line number Diff line change
@@ -1,63 +1,91 @@
package com.jelly.CaneBuilder.features;

import com.jelly.CaneBuilder.BuilderState;
import com.jelly.CaneBuilder.utils.BlockUtils;
import com.jelly.CaneBuilder.handlers.KeyBindHandler;
import com.jelly.CaneBuilder.handlers.MacroHandler;
import com.jelly.CaneBuilder.utils.Clock;
import com.jelly.CaneBuilder.utils.LogUtils;
import com.jelly.CaneBuilder.utils.ScoreboardUtils;
import com.jelly.CaneBuilder.utils.Utils;
import net.minecraft.client.Minecraft;
import net.minecraftforge.client.event.ClientChatReceivedEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent;

public class Failsafe {

private static final Minecraft mc = Minecraft.getMinecraft();
private static final Clock cooldown = new Clock();
private static boolean teleporting;
private static final Clock tpCooldown = new Clock();


public static boolean restarting = false;
public static boolean pauseOnLeave = true;



@SubscribeEvent
public void onMessageReceived(ClientChatReceivedEvent event) {
String message = net.minecraft.util.StringUtils.stripControlCodes(event.message.getUnformattedText());
if (BuilderState.enabled) {
if (message.contains("DYNAMIC") || message.contains("Something went wrong trying to send ") || message.contains("don't spam") || message.contains("A disconnect occurred ") || message.contains("An exception occurred ") || message.contains("Couldn't warp ") || message.contains("You are sending commands ") || message.contains("Cannot join ") || message.contains("There was a problem ") || message.contains("You cannot join ") || message.contains("You were kicked while ") || message.contains("You are already playing") || message.contains("You cannot join SkyBlock from here!")) {
Utils.addCustomLog("Failed teleport - waiting");
teleporting = false;
cooldown.schedule(10000);
tpCooldown.schedule(10000);
}
}
}


@SubscribeEvent
public final void tick(TickEvent.ClientTickEvent event) {
if (event.phase == TickEvent.Phase.END || mc.thePlayer == null || mc.theWorld == null) return;
if(!(BuilderState.enabled || BuilderState.isSwitchingLayer)) return;
if (!BuilderState.enabled || event.phase == TickEvent.Phase.END || mc.thePlayer == null || mc.theWorld == null) return;

if(ScoreboardUtils.getLocation() != ScoreboardUtils.location.ISLAND && !BuilderState.paused && pauseOnLeave){
MacroHandler.pauseScript();
KeyBindHandler.resetKeybindState();
}

switch (Utils.getLocation()) {
switch (ScoreboardUtils.getLocation()) {
case TELEPORTING:
teleporting = false;
if (tpCooldown.passed()) {
mc.thePlayer.sendChatMessage("/lobby");
tpCooldown.schedule(15000);
LogUtils.addCustomLog("teleporting");
}
return;
case LIMBO:
if (cooldown.passed()) {
if (tpCooldown.passed()) {
mc.thePlayer.sendChatMessage("/lobby");
cooldown.schedule(5000);
teleporting = true;
tpCooldown.schedule(5000);
LogUtils.addCustomLog("limbo");
}
return;
case LOBBY:
if (cooldown.passed()) {
if (tpCooldown.passed()) {
mc.thePlayer.sendChatMessage("/skyblock");
cooldown.schedule(5000);
teleporting = true;
tpCooldown.schedule(5000);
LogUtils.addCustomLog("lobby");
}
return;
case HUB:
Utils.addCustomMessage("Detected Hub");
if (cooldown.passed()) {
if (tpCooldown.passed()) {
mc.thePlayer.sendChatMessage("/is");
cooldown.schedule(5000);
teleporting = true;
tpCooldown.schedule(5000);
LogUtils.addCustomLog("hub");
}
return;
case ISLAND:
if (BuilderState.paused && pauseOnLeave && !restarting) {
restarting = true;
new Thread(() -> {
try {
mc.inGameHasFocus = true;
mc.mouseHelper.grabMouseCursor();
mc.displayGuiScreen(null);
KeyBindHandler.setKeyBindState(KeyBindHandler.keyBindShift, true);
Thread.sleep(1000);
KeyBindHandler.setKeyBindState(KeyBindHandler.keyBindShift, false);
MacroHandler.continueMacro();
restarting = false;

}catch (Exception e){e.printStackTrace();}
}).start();
}
}
}
Expand Down
Loading

0 comments on commit adc4991

Please sign in to comment.