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

91 lines
2.6 KiB
Java
Raw Normal View History

2023-01-12 14:10:43 -08:00
package dev.resent.module.base;
2023-02-27 06:31:35 -08:00
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
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-28 18:57:47 -08:00
import dev.resent.visual.ui.Theme;
2023-02-26 11:01:36 -08:00
import dev.resent.visual.ui.animation.SimpleAnimation;
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;
2023-02-27 06:31:35 -08:00
private boolean enabled;
2023-02-11 12:06:38 -08:00
private boolean hasSetting;
2023-02-27 06:31:35 -08:00
public SimpleAnimation toggleAnimation = new SimpleAnimation(0);
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() {}
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-27 06:31:35 -08:00
RenderUtils.drawRoundedRect(left, top, right, bottom, 4, color);
2023-01-19 11:36:49 -08:00
}
2023-03-11 18:42:52 -08:00
protected int drawString(final String text, final int x, final int y) {
if (Theme.getFontColor() == 6942069) {
RenderUtils.drawChromaString(text, x, y, Theme.getTextShadow());
2023-02-19 09:39:01 -08:00
} else {
2023-03-26 07:02:54 -07:00
Minecraft.getMinecraft().fontRendererObj.drawString(text, x, y, Theme.getFontColor(), Theme.getTextShadow());
2023-01-30 16:41:01 -08:00
}
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-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-03-11 18:42:52 -08:00
public boolean isEnabled() { return enabled; }
2023-03-12 08:41:57 -07:00
public boolean doesHaveSetting() { return hasSetting; }
public String getName() { return name; }
2023-03-11 18:42:52 -08:00
public Category getCategory() { return category; }
2023-02-19 09:39:01 -08:00
2023-03-11 18:42:52 -08:00
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-02-19 09:39:01 -08:00
2023-01-12 14:10:43 -08:00
}