Skip to content

Commit f99b4dc

Browse files
Merge pull request #2 from Clasictrashcode/dev
Version 0.0.3
2 parents a1e06bd + a48da7c commit f99b4dc

8 files changed

Lines changed: 487 additions & 7 deletions

File tree

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ org.gradle.jvmargs=-Xmx1G
55
minecraft_version=1.21.10
66
loader_version=0.18.4
77
# Mod Properties
8-
mod_version=0.0.2
8+
mod_version=0.0.3
99
maven_group=com.classictrashcode
1010
archives_base_name=suxaddons
1111
# Dependencies

src/main/java/com/classictrashcode/suxaddons/client/SuxaddonsClient.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,33 @@
22

33
import com.classictrashcode.suxaddons.client.commands.CommandManager;
44
import com.classictrashcode.suxaddons.client.config.ConfigManager;
5-
import com.classictrashcode.suxaddons.client.hunting.CinderBatTracker;
6-
import com.classictrashcode.suxaddons.client.hunting.CinderBatTrackerHud;
7-
import com.classictrashcode.suxaddons.client.hunting.HideonLeafTracker;
8-
import com.classictrashcode.suxaddons.client.hunting.HideonLeafTrackerHud;
5+
import com.classictrashcode.suxaddons.client.hunting.*;
96
import com.classictrashcode.suxaddons.client.macros.ChatMacros;
107
import com.classictrashcode.suxaddons.client.utils.BazzarTracker.BazzarTracker;
118
import com.classictrashcode.suxaddons.client.utils.ChatUtils;
9+
import com.classictrashcode.suxaddons.client.utils.UpdateChecker;
1210
import net.fabricmc.api.ClientModInitializer;
1311
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
12+
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents;
1413
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback;
1514

1615
public class SuxaddonsClient implements ClientModInitializer {
1716
public static final String MOD_ID = "suxaddons";
1817
@Override
1918
public void onInitializeClient() {
2019
ConfigManager.load();
20+
SoundManager.initialize();// Initialize sound manager for custom sounds\
2121
CommandManager.registerCommands();
2222
ClientTickEvents.END_CLIENT_TICK.register(client -> {
2323
ChatUtils.tick();
2424
HideonLeafTracker.tick();
2525
CinderBatTracker.tick();
2626
BazzarTracker.tick();
27+
AutoFusion.tick();
2728
ChatMacros.tick(client.getWindow().handle());
2829
});
2930
HudRenderCallback.EVENT.register(new HideonLeafTrackerHud());
3031
HudRenderCallback.EVENT.register(new CinderBatTrackerHud());
32+
ClientPlayConnectionEvents.JOIN.register((handler, sender, client) -> UpdateChecker.onJoin());
3133
}
3234
}

src/main/java/com/classictrashcode/suxaddons/client/commands/CommandManager.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ public class CommandManager {
1010
public static void registerCommands(){
1111
System.out.printf("[%s] Registering Commands%n", SuxaddonsClient.MOD_ID);
1212
ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> {
13-
1413
LiteralArgumentBuilder<FabricClientCommandSource> base =
1514
ClientCommandManager.literal(SuxaddonsClient.MOD_ID);
1615
base = ConfigScreenCommand.register(base);

src/main/java/com/classictrashcode/suxaddons/client/config/Config.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,8 @@ public static class hunting {
233233
public HideonLeafTracker hideonLeafTracker = new HideonLeafTracker();
234234
@ConfigSubSettings(name = "Cinderbat Tracker",description = "Cinderbat Tracker Settings",order = 2)
235235
public CinderBatTracker cinderBatTracker = new CinderBatTracker();
236+
@ConfigSubSettings(name = "AutoFusion",description = "Automatically refuse the shards untill they run out or you press stop",order = 99)
237+
public AutoFusion autoFusion = new AutoFusion();
236238
}
237239
public static class AutoFusion {
238240
@ConfigOption(name = "Enabled")
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
package com.classictrashcode.suxaddons.client.hunting;
2+
3+
4+
import com.classictrashcode.suxaddons.client.Logger;
5+
import com.classictrashcode.suxaddons.client.SoundAlert;
6+
import com.classictrashcode.suxaddons.client.SoundManager;
7+
import com.classictrashcode.suxaddons.client.config.ConfigManager;
8+
import com.classictrashcode.suxaddons.client.utils.InventoryUtils;
9+
import net.minecraft.client.Minecraft;
10+
import net.minecraft.world.inventory.AbstractContainerMenu;
11+
12+
public class AutoFusion {
13+
public static boolean running = false;
14+
static int actionStep = 0; // Package-private for AutoFusionOverlay
15+
private static int stepTimer = 0;
16+
static int completedCycles = 0; // Package-private for AutoFusionOverlay
17+
public static boolean isFusionMenu = false;
18+
public static String currentInventoryTitle;
19+
private static int nullScreenTicks = 0;
20+
21+
22+
public static void tick(){
23+
if (Minecraft.getInstance().screen == null) {
24+
isFusionMenu = false;
25+
currentInventoryTitle = "";
26+
nullScreenTicks++;
27+
// Only reset after 10 consecutive ticks of null screen (grace period for lag)
28+
if (nullScreenTicks >= 10) {
29+
reset();
30+
}
31+
return;
32+
}
33+
// Screen is not null, reset the grace period counter
34+
nullScreenTicks = 0;
35+
if (Minecraft.getInstance().screen.getTitle().getString().contains("Fusion")) {
36+
isFusionMenu = true;
37+
currentInventoryTitle = Minecraft.getInstance().screen.getTitle().getString();
38+
} else {
39+
isFusionMenu = false;
40+
currentInventoryTitle = "";
41+
}
42+
if (!ConfigManager.getConfig().hunting.autoFusion.enabled || !isFusionMenu) {
43+
reset();
44+
return;
45+
}
46+
if (!running) return;
47+
processActionSequence();
48+
}
49+
public static void processActionSequence() {
50+
AbstractContainerMenu screenHandler = Minecraft.getInstance().player.containerMenu;
51+
stepTimer++;
52+
int actionDelayTicks = ConfigManager.getConfig().hunting.autoFusion.actionDelayTicks;
53+
int LongDelayTicks = ConfigManager.getConfig().hunting.autoFusion.longDelayTicks;
54+
switch (actionStep) {
55+
case 0:
56+
if (currentInventoryTitle.contains("Box") && stepTimer >= actionDelayTicks) {
57+
if (!screenHandler.getSlot(47).getItem().getDisplayName().getString().contains("Repeat Previous Fusion")) {
58+
reset();
59+
break;
60+
}
61+
InventoryUtils.clickSlot(47);
62+
stepTimer = 0;
63+
actionStep++;
64+
}
65+
break;
66+
case 1:
67+
if (currentInventoryTitle.contains("Confirm") && stepTimer >= actionDelayTicks) {
68+
if (!screenHandler.getSlot(33).getItem().getDisplayName().getString().contains("Fusion")) break;
69+
InventoryUtils.clickSlot(33);
70+
stepTimer = 0;
71+
actionStep++;
72+
}
73+
break;
74+
case 2:
75+
if(stepTimer >= LongDelayTicks){
76+
stepTimer = 0;
77+
completedCycles++;
78+
actionStep = 0;
79+
}
80+
break;
81+
}
82+
}
83+
public static void reset() {
84+
if (running){
85+
Logger.inGameLog("AutoFusion","Finished Fusion with "+completedCycles+" Completed!");
86+
87+
// Play sound alert if enabled
88+
if (ConfigManager.getConfig().hunting.autoFusion.soundAlertEnabled) {
89+
String soundTypeName = ConfigManager.getConfig().hunting.autoFusion.soundType;
90+
float volume = (float) ConfigManager.getConfig().hunting.autoFusion.soundVolume;
91+
float pitch = (float) ConfigManager.getConfig().hunting.autoFusion.soundPitch;
92+
93+
// Check if it's a custom sound or built-in
94+
if (SoundAlert.isCustomSound(soundTypeName)) {
95+
// Play custom sound by name
96+
SoundManager.playCustomSound(soundTypeName, volume, pitch);
97+
} else {
98+
// Play built-in sound
99+
SoundAlert soundAlert = SoundAlert.fromDisplayName(soundTypeName);
100+
SoundManager.playSound(soundAlert, volume, pitch);
101+
}
102+
}
103+
}
104+
running = false;
105+
actionStep = 0;
106+
stepTimer = 0;
107+
completedCycles = 0;
108+
nullScreenTicks = 0;
109+
}
110+
}
Lines changed: 218 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,218 @@
1+
package com.classictrashcode.suxaddons.client.hunting;
2+
3+
4+
import com.classictrashcode.suxaddons.client.config.Config;
5+
import com.classictrashcode.suxaddons.client.config.ConfigManager;
6+
import net.minecraft.client.Minecraft;
7+
import net.minecraft.client.gui.GuiGraphics;
8+
import net.minecraft.network.chat.Component;
9+
10+
public class AutoFusionOverlay {
11+
private static final int OVERLAY_WIDTH = 200;
12+
private static final int OVERLAY_HEIGHT = 140;
13+
private static final int PADDING = 10;
14+
private static final int LINE_HEIGHT = 12;
15+
16+
// Button dimensions
17+
private static final int BUTTON_WIDTH = 80;
18+
private static final int BUTTON_HEIGHT = 24;
19+
20+
// State for button hover detection
21+
private static int buttonX;
22+
private static int buttonY;
23+
24+
public static void renderOverlay(GuiGraphics context, int screenWidth, int screenHeight, int mouseX, int mouseY) {
25+
if (!AutoFusion.isFusionMenu || !ConfigManager.getConfig().hunting.autoFusion.enabled) {
26+
return;
27+
}
28+
29+
// Get theme colors from config
30+
var theme = ConfigManager.getConfig().guiTheme;
31+
int backgroundColor = theme.parseColor(theme.surfaceColor);
32+
int borderColor = theme.parseColor(theme.dividerColor);
33+
int textColor = theme.parseColor(theme.textPrimaryColor);
34+
int textSecondaryColor = theme.parseColor(theme.textSecondaryColor);
35+
36+
int overlayX = PADDING;
37+
int overlayY = PADDING + 20; // Add extra padding from top
38+
39+
// Draw background with slight transparency
40+
int bgColorWithAlpha = (backgroundColor & 0x00FFFFFF) | 0xE6000000; // 90% opacity
41+
context.fill(overlayX, overlayY, overlayX + OVERLAY_WIDTH, overlayY + OVERLAY_HEIGHT, bgColorWithAlpha);
42+
43+
// Draw colored title bar
44+
int titleBarHeight = 22;
45+
int titleBarColor = theme.parseColor(theme.primaryColor);
46+
context.fill(overlayX, overlayY, overlayX + OVERLAY_WIDTH, overlayY + titleBarHeight, titleBarColor);
47+
48+
// Draw border
49+
drawBorder(context, overlayX, overlayY, OVERLAY_WIDTH, OVERLAY_HEIGHT, borderColor);
50+
51+
// Draw title in white on colored bar
52+
context.drawString(
53+
Minecraft.getInstance().font,
54+
Component.literal("Auto Fusion"),
55+
overlayX + PADDING,
56+
overlayY + (titleBarHeight - 8) / 2, // Center vertically in title bar
57+
0xFFFFFFFF, // White text
58+
false
59+
);
60+
61+
// Content starts below title bar
62+
int currentY = overlayY + titleBarHeight + 8;
63+
64+
// Draw status
65+
int statusColor = AutoFusion.running ? theme.parseColor(theme.successColor) : textSecondaryColor;
66+
context.drawString(
67+
Minecraft.getInstance().font,
68+
Component.literal("Status: "),
69+
overlayX + PADDING,
70+
currentY,
71+
textColor,
72+
false
73+
);
74+
context.drawString(
75+
Minecraft.getInstance().font,
76+
Component.literal(AutoFusion.running ? "Running" : "Stopped"),
77+
overlayX + PADDING + Minecraft.getInstance().font.width("Status: "),
78+
currentY,
79+
statusColor,
80+
false
81+
);
82+
83+
// Draw completed cycles
84+
currentY += LINE_HEIGHT + 2;
85+
context.drawString(
86+
Minecraft.getInstance().font,
87+
Component.literal("Cycles: " + AutoFusion.completedCycles),
88+
overlayX + PADDING,
89+
currentY,
90+
textColor,
91+
false
92+
);
93+
94+
// Draw current step
95+
currentY += LINE_HEIGHT + 2;
96+
int actionStep = AutoFusion.actionStep;
97+
context.drawString(
98+
Minecraft.getInstance().font,
99+
Component.literal("Step: " + actionStep + "/2"),
100+
overlayX + PADDING,
101+
currentY,
102+
textColor,
103+
false
104+
);
105+
106+
// Draw delay settings
107+
currentY += LINE_HEIGHT + 4;
108+
int actionDelay = ConfigManager.getConfig().hunting.autoFusion.actionDelayTicks;
109+
int longDelay = ConfigManager.getConfig().hunting.autoFusion.longDelayTicks;
110+
context.drawString(
111+
Minecraft.getInstance().font,
112+
Component.literal("Action Delay: " + actionDelay + "t"),
113+
overlayX + PADDING,
114+
currentY,
115+
textSecondaryColor,
116+
false
117+
);
118+
currentY += LINE_HEIGHT;
119+
context.drawString(
120+
Minecraft.getInstance().font,
121+
Component.literal("Long Delay: " + longDelay + "t"),
122+
overlayX + PADDING,
123+
currentY,
124+
textSecondaryColor,
125+
false
126+
);
127+
128+
// Draw toggle button
129+
currentY += LINE_HEIGHT + 6;
130+
buttonX = overlayX + (OVERLAY_WIDTH - BUTTON_WIDTH) / 2;
131+
buttonY = currentY;
132+
133+
boolean hovered = isMouseOver(mouseX, mouseY, buttonX, buttonY, BUTTON_WIDTH, BUTTON_HEIGHT);
134+
drawToggleButton(context, buttonX, buttonY, hovered);
135+
}
136+
137+
private static void drawBorder(GuiGraphics context, int x, int y, int width, int height, int color) {
138+
// Top
139+
context.fill(x, y, x + width, y + 1, color);
140+
// Bottom
141+
context.fill(x, y + height - 1, x + width, y + height, color);
142+
// Left
143+
context.fill(x, y, x + 1, y + height, color);
144+
// Right
145+
context.fill(x + width - 1, y, x + width, y + height, color);
146+
}
147+
private static void drawToggleButton(GuiGraphics context, int x, int y, boolean hovered) {
148+
var theme = ConfigManager.getConfig().guiTheme;
149+
150+
int buttonColor;
151+
if (AutoFusion.running) {
152+
// Stop button - use error color
153+
buttonColor = hovered ?
154+
theme.parseColor(theme.errorColor) :
155+
darken(theme.parseColor(theme.errorColor), 0.8f);
156+
} else {
157+
// Start button - use success color
158+
buttonColor = hovered ?
159+
theme.parseColor(theme.buttonHoverColor) :
160+
theme.parseColor(theme.buttonNormalColor);
161+
}
162+
163+
// Draw button background
164+
context.fill(x, y, x + BUTTON_WIDTH, y + BUTTON_HEIGHT, buttonColor);
165+
166+
// Draw button border
167+
int borderColor = theme.parseColor(theme.dividerColor);
168+
drawBorder(context, x, y, BUTTON_WIDTH, BUTTON_HEIGHT, borderColor);
169+
170+
// Draw button text
171+
String buttonText = AutoFusion.running ? "Stop" : "Start";
172+
int textWidth = Minecraft.getInstance().font.width(buttonText);
173+
int textX = x + (BUTTON_WIDTH - textWidth) / 2;
174+
int textY = y + (BUTTON_HEIGHT - 8) / 2;
175+
176+
context.drawString(
177+
Minecraft.getInstance().font,
178+
Component.literal(buttonText),
179+
textX,
180+
textY,
181+
0xFFFFFFFF,
182+
false
183+
);
184+
}
185+
186+
private static boolean isMouseOver(int mouseX, int mouseY, int x, int y, int width, int height) {
187+
return mouseX >= x && mouseX <= x + width && mouseY >= y && mouseY <= y + height;
188+
}
189+
190+
public static boolean handleClick(int mouseX, int mouseY) {
191+
if (!AutoFusion.isFusionMenu) {
192+
return false;
193+
}
194+
195+
if (isMouseOver(mouseX, mouseY, buttonX, buttonY, BUTTON_WIDTH, BUTTON_HEIGHT)) {
196+
if (!ConfigManager.getConfig().hunting.autoFusion.enabled) {
197+
return true; // Consume click but don't toggle
198+
}
199+
200+
AutoFusion.running = !AutoFusion.running;
201+
if (!AutoFusion.running){
202+
AutoFusion.reset();
203+
}
204+
return true;
205+
}
206+
207+
return false;
208+
}
209+
210+
private static int darken(int color, float factor) {
211+
int alpha = (color >> 24) & 0xFF;
212+
int red = (int) (((color >> 16) & 0xFF) * factor);
213+
int green = (int) (((color >> 8) & 0xFF) * factor);
214+
int blue = (int) ((color & 0xFF) * factor);
215+
216+
return (alpha << 24) | (red << 16) | (green << 8) | blue;
217+
}
218+
}

0 commit comments

Comments
 (0)