Skip to content

Commit

Permalink
Merge pull request #61 from AdyTech99/main
Browse files Browse the repository at this point in the history
Closes #26, #59, #60
  • Loading branch information
MichaelHillcox authored Jul 22, 2024
2 parents b96c8b8 + 3280833 commit f4caba4
Show file tree
Hide file tree
Showing 10 changed files with 166 additions and 36 deletions.
6 changes: 5 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,16 @@ archivesBaseName = project.archives_base_name
version = project.mod_version
group = project.maven_group

repositories {
maven { url "https://maven.terraformersmc.com/releases/"}
}

dependencies {
// To change the versions see the gradle.properties file
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"

modImplementation "com.terraformersmc:modmenu:${project.modmenu_version}"
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
}

Expand Down
3 changes: 2 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ org.gradle.parallel=true
minecraft_version=1.21
yarn_mappings=1.21+build.1
# Mod Properties
mod_version=21.0.1
mod_version=21.0.2
maven_group=pro.mikey.mods
archives_base_name=auto-clicker-fabric
# Dependencies
# currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api
loader_version=0.15.11
fabric_version=0.100.1+1.21
modmenu_version=11.0.0-beta.1
curseforge_id=445095
modrinth_id=r8axuw4u
4 changes: 2 additions & 2 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
# * functions;
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
# * compound commands having a testable exit status, especially «case»;
# * various built-in commands including «command», «set», and «ulimit».
# * compound command having a testable exit status, especially «case»;
# * various built-in command including «command», «set», and «ulimit».
#
# Important for patching:
#
Expand Down
48 changes: 37 additions & 11 deletions src/main/java/pro/mikey/autoclicker/AutoClicker.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package pro.mikey.autoclicker;

import com.google.gson.Gson;
import com.google.gson.JsonIOException;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientLifecycleEvents;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
Expand Down Expand Up @@ -43,12 +42,14 @@ public class AutoClicker implements ModInitializer {
public static Holding.AttackHolding leftHolding;
public static Holding rightHolding;
public static Holding jumpHolding;
public static Config.HudConfig hudConfig;
private static AutoClicker INSTANCE;
private boolean isActive = false;
private Config config = new Config(
new Config.LeftMouseConfig(false, false, 0, false, false, false),
new Config.RightMouseConfig(false, false, 0),
new Config.JumpConfig(false, false, 0)
new Config.JumpConfig(false, false, 0),
new Config.HudConfig(true, "top-left")
);

public AutoClicker() {
Expand Down Expand Up @@ -87,17 +88,19 @@ private void clientReady(MinecraftClient client) {
FileReader json = new FileReader(CONFIG_FILE.toFile());
Config config = new Gson().fromJson(json, Config.class);
json.close();
if (config != null && config.getJump() != null) {
if (config != null && config.getHudConfig() != null) {
this.config = config;
}
} catch (JsonIOException | IOException e) {
} catch (Exception e){
e.printStackTrace();
this.saveConfig();
}
}

leftHolding = new Holding.AttackHolding(client.options.attackKey, this.config.getLeftClick());
rightHolding = new Holding(client.options.useKey, this.config.getRightClick());
jumpHolding = new Holding(client.options.jumpKey, this.config.getJump());
hudConfig = this.config.getHudConfig();
}

public void saveConfig() {
Expand All @@ -113,31 +116,54 @@ public void saveConfig() {
}

private void RenderGameOverlayEvent(DrawContext context, RenderTickCounter delta) {
if ((!leftHolding.isActive() && !rightHolding.isActive() && !jumpHolding.isActive()) || !this.isActive) {

if ((!leftHolding.isActive() && !rightHolding.isActive() && !jumpHolding.isActive()) || !this.isActive || !config.getHudConfig().isEnabled()) {
return;
}

MinecraftClient client = MinecraftClient.getInstance();

int y = 10;
if (leftHolding.isActive()) {
Text text = Language.HUD_HOLDING.getText(I18n.translate(leftHolding.getKey().getTranslationKey()));
context.drawTextWithShadow(client.textRenderer, text.asOrderedText(), 10, y, 0xffffff);
y += 15;
int y = getHudY() + (15 * 0);
int x = getHudX(text);
context.drawTextWithShadow(client.textRenderer, text.asOrderedText(), x, y, 0xffffff);
}

if (rightHolding.isActive()) {
Text text = Language.HUD_HOLDING.getText(I18n.translate(rightHolding.getKey().getTranslationKey()));
context.drawTextWithShadow(client.textRenderer, text.asOrderedText(), 10, y, 0xffffff);
y += 15;
int y = getHudY() + (15 * 1);
int x = getHudX(text);
context.drawTextWithShadow(client.textRenderer, text.asOrderedText(), x, y, 0xffffff);
}

if (jumpHolding.isActive()) {
Text text = Language.HUD_HOLDING.getText(I18n.translate(jumpHolding.getKey().getTranslationKey()));
context.drawTextWithShadow(client.textRenderer, text.asOrderedText(), 10, y, 0xffffff);
int y = getHudY() + (15 * 2);
int x = getHudX(text);
context.drawTextWithShadow(client.textRenderer, text.asOrderedText(), x, y, 0xffffff);
}
}

public int getHudX(Text text){
MinecraftClient client = MinecraftClient.getInstance();

String location = this.config.getHudConfig().getLocation();
return switch (location) {
case "top-left", "bottom-left" -> 10;
case "top-right", "bottom-right" -> (MinecraftClient.getInstance().getWindow().getScaledWidth()) - 10 - client.textRenderer.getWidth(text);
default -> 10;
};
}
public int getHudY(){
String location = this.config.getHudConfig().getLocation();
return switch (location) {
case "top-left", "top-right" -> 10;
case "bottom-left", "bottom-right" -> (MinecraftClient.getInstance().getWindow().getScaledHeight()) - 50;
default -> 10;
};
}

private void clientTickEvent(MinecraftClient mc) {
if (mc.player == null || mc.world == null) {
return;
Expand Down
39 changes: 38 additions & 1 deletion src/main/java/pro/mikey/autoclicker/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ public class Config {
private final LeftMouseConfig leftClick;
private final RightMouseConfig rightClick;
private final JumpConfig jump;
private final HudConfig hudConfig;

public Config(LeftMouseConfig leftClick, RightMouseConfig rightClick, JumpConfig jump) {
public Config(LeftMouseConfig leftClick, RightMouseConfig rightClick, JumpConfig jump, HudConfig hudConfig) {
this.leftClick = leftClick;
this.rightClick = rightClick;
this.jump = jump;
this.hudConfig = hudConfig;
}

public LeftMouseConfig getLeftClick() {
Expand All @@ -24,6 +26,8 @@ public JumpConfig getJump() {
return this.jump;
}

public HudConfig getHudConfig(){return this.hudConfig;}

@Override
public String toString() {
return "Config{" +
Expand All @@ -33,6 +37,39 @@ public String toString() {
'}';
}

public static class HudConfig {
private boolean enabled;
private String location;

public HudConfig(Boolean enabled, String location){
this.enabled = enabled;
this.location = location;
}

public boolean isEnabled() {
return this.enabled;
}

public void setEnabled(boolean enabled) {
this.enabled = enabled;
}

public String getLocation(){
return this.location;
}

public void setLocation(String location) {
this.location = location;
}

public String toString(){
return "Config{" +
"hudEnabled=" + this.enabled +
", hudLocation=" + this.location +
'}';
}
}

public static class LeftMouseConfig extends SharedConfig {
private boolean respectCooldown;
private boolean respectShield;
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/pro/mikey/autoclicker/Language.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ public enum Language {
GUI_JUMP("autoclicker-fabric.gui.jump"),
GUI_RESPECT_COOLDOWN("autoclicker-fabric.gui.respect"),
GUI_RESPECT_SHIELD("autoclicker-fabric.gui.shield"),
GUI_MOB_MODE("autoclicker-fabric.gui.mob-mode");
GUI_MOB_MODE("autoclicker-fabric.gui.mob-mode"),
GUI_HUD_ENABLED("autoclicker-fabric.gui.hud-enabled"),
GUI_HUD_LOCATION("autoclicker-fabric.gui.hud-location");

private final String key;
MutableText text;
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/pro/mikey/autoclicker/ModMenuAPIImpl.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package pro.mikey.autoclicker;

import com.terraformersmc.modmenu.api.ConfigScreenFactory;
import com.terraformersmc.modmenu.api.ModMenuApi;
import net.minecraft.client.gui.screen.Screen;


public class ModMenuAPIImpl implements ModMenuApi {
@Override
public ConfigScreenFactory<?> getModConfigScreenFactory() {
return OptionsScreen::createScreen;
}
}
Loading

0 comments on commit f4caba4

Please sign in to comment.