resent-1.8/src/main/java/dev/resent/module/base/Mod.java

111 lines
2.7 KiB
Java
Raw Normal View History

2023-01-12 14:10:43 -08:00
package dev.resent.module.base;
2023-01-31 20:40:17 -08:00
import dev.resent.annotation.Module;
2023-02-24 09:16:21 -08:00
import dev.resent.module.base.setting.Setting;
2023-01-19 11:36:49 -08:00
import dev.resent.util.render.RenderUtils;
2023-02-24 09:16:21 -08:00
import dev.resent.visual.ui.Theme;
2023-02-19 09:39:01 -08:00
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
2023-01-12 14:10:43 -08:00
import net.minecraft.client.Minecraft;
2023-02-02 08:07:00 -08:00
public abstract class Mod {
2023-01-12 14:10:43 -08:00
2023-02-11 12:06:38 -08:00
protected Minecraft mc = Minecraft.getMinecraft();
private String name;
private Category category;
private boolean enabled = false;
private boolean hasSetting;
2023-02-24 21:11:49 -08:00
public boolean expanded;
public int index;
2023-01-14 07:56:36 -08:00
public List<Setting> settings = new ArrayList<>();
2023-02-19 09:39:01 -08:00
public Mod() {
2023-01-31 20:40:17 -08:00
Module modInfo;
2023-02-19 09:39:01 -08:00
if (getClass().isAnnotationPresent(Module.class)) {
2023-01-31 20:40:17 -08:00
modInfo = getClass().getAnnotation(Module.class);
2023-02-11 12:06:38 -08:00
this.setName(modInfo.name());
this.setCategory(modInfo.category());
this.setHasSetting(modInfo.hasSetting());
2023-02-02 08:05:40 -08:00
}
2023-01-31 20:40:17 -08:00
}
2023-02-19 09:39:01 -08:00
public void addSetting(final Setting... settings) {
this.settings.addAll(Arrays.asList(settings));
}
2023-01-14 07:56:36 -08:00
public void onEnable() {}
2023-02-19 09:39:01 -08:00
2023-01-14 07:56:36 -08:00
public void onDisable() {}
public void toggle() {
this.enabled = !this.enabled;
2023-02-11 12:06:38 -08:00
onChange();
}
2023-02-19 09:39:01 -08:00
private void onChange() {
if (enabled) onEnable(); else onDisable();
2023-02-11 12:06:38 -08:00
}
2023-02-19 09:39:01 -08:00
2023-02-11 12:06:38 -08:00
public void setEnabled(final boolean enabled) {
this.enabled = enabled;
onChange();
2023-01-14 07:56:36 -08:00
}
2023-02-19 09:39:01 -08:00
protected void drawRect(final int left, final int top, final int right, final int bottom, final int color) {
2023-02-02 08:05:40 -08:00
RenderUtils.drawRoundedRect(left, top, right, bottom, 4, color, Theme.getRounded());
2023-01-19 11:36:49 -08:00
}
2023-02-19 09:39:01 -08:00
protected int drawString(final String text, final int x, final int y, final int color, final boolean idk) {
if (color == 6942069) {
2023-01-30 16:41:01 -08:00
RenderUtils.drawChromaString(text, x, y, idk);
2023-02-19 09:39:01 -08:00
} else {
2023-01-30 16:41:01 -08:00
Minecraft.getMinecraft().fontRendererObj.drawString(text, x, y, color, idk);
}
2023-02-19 09:39:01 -08:00
2023-01-30 16:41:01 -08:00
return x;
}
2023-02-02 19:18:34 -08:00
public enum Category {
HUD("Hud"),
MISC("Misc");
2023-02-19 09:39:01 -08:00
2023-02-02 19:18:34 -08:00
public final String name;
2023-02-04 15:51:17 -08:00
public int i;
2023-02-19 09:39:01 -08:00
2023-02-04 14:59:09 -08:00
Category(final String name) {
2023-02-02 19:18:34 -08:00
this.name = name;
}
}
2023-01-23 14:45:04 -08:00
2023-02-19 09:39:01 -08:00
public boolean isEnabled() {
return enabled;
}
public boolean isHasSetting() {
return hasSetting;
}
2023-01-14 07:56:36 -08:00
2023-02-19 09:39:01 -08:00
public String getName() {
return name;
}
public Category getCategory() {
return category;
}
public void setName(String name) {
this.name = name;
}
public void setCategory(Category category) {
this.category = category;
}
public void setHasSetting(boolean hasSetting) {
this.hasSetting = hasSetting;
}
2023-01-12 14:10:43 -08:00
}