some code improvements ig

This commit is contained in:
ThisIsALegitUsername 2023-02-19 20:29:19 +00:00
parent 361db9057e
commit c048193d8e
14 changed files with 28292 additions and 28523 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@ -1,23 +1,12 @@
package dev.resent;
package dev.resent.client;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.UnsupportedAudioFileException;
import dev.resent.module.base.ModManager;
import dev.resent.module.base.RenderMod;
import dev.resent.module.setting.BooleanSetting;
import dev.resent.module.setting.ModeSetting;
import net.minecraft.client.Minecraft;
import net.minecraft.client.audio.PositionedSoundRecord;
import net.minecraft.util.ResourceLocation;
import dev.resent.sound.SoundManager;
public class Resent {
static {
@ -26,10 +15,12 @@ public class Resent {
public static final String NAME = "Resent", VERSION = "3.5";
public static final Resent INSTANCE;
public SoundManager soundManager;
public ModManager modManager;
public void init() {
Resent.INSTANCE.modManager = new ModManager();
Resent.INSTANCE.soundManager = new SoundManager();
}
public void save(PrintWriter printwriter) {
@ -96,50 +87,4 @@ public class Resent {
});
}
//Legacy code below.
FileOutputStream fos = null;
File temp;
public void playSoundFromByteArray(byte[] bArray) {
try {
temp = new File("C:/test").getAbsoluteFile();
if (!temp.exists()) {
temp.createNewFile();
}
fos = new FileOutputStream(temp);
fos.write(bArray);
fos.flush();
AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(temp);
Clip clip = AudioSystem.getClip();
clip.open(audioInputStream);
clip.start();
} catch (IOException ioe) {
ioe.printStackTrace();
} catch (UnsupportedAudioFileException e) {
e.printStackTrace();
} catch (LineUnavailableException e) {
e.printStackTrace();
} finally {
try {
if (fos != null) {
fos.close();
}
} catch (IOException ioe) {
System.out.println("Error in closing the Stream");
}
}
}
public void test(){
Minecraft.getMinecraft().getSoundHandler().stopSounds();
Minecraft.getMinecraft().getSoundHandler().playSound(PositionedSoundRecord.create(new ResourceLocation("minecraft:music.res"), 1));
}
public void stopMusic() {
Minecraft.getMinecraft().getSoundHandler().stopSounds();
}
}

View File

@ -1,7 +1,7 @@
package dev.resent.module.impl.misc;
import dev.resent.Resent;
import dev.resent.annotation.Module;
import dev.resent.client.Resent;
import dev.resent.module.base.Mod;
import dev.resent.module.base.Mod.Category;
@ -11,7 +11,7 @@ public class Fullbright extends Mod {
@Override
public void onEnable() {
if (mc.thePlayer != null && mc.theWorld != null && mc.gameSettings != null) {
Resent.INSTANCE.test();
Resent.INSTANCE.soundManager.playAvasDedication();
mc.gameSettings.gammaSetting = 100;
}
}
@ -19,7 +19,7 @@ public class Fullbright extends Mod {
@Override
public void onDisable() {
if (mc.thePlayer != null && mc.theWorld != null && mc.gameSettings != null) {
Resent.INSTANCE.stopMusic();
Resent.INSTANCE.soundManager.stopMusic();
mc.gameSettings.gammaSetting = 1;
}
}

View File

@ -1,7 +1,7 @@
package dev.resent.module.impl.misc;
import dev.resent.Resent;
import dev.resent.annotation.RenderModule;
import dev.resent.client.Resent;
import dev.resent.module.base.Mod;
import dev.resent.module.base.Mod.Category;
import dev.resent.module.base.RenderMod;

View File

@ -0,0 +1,72 @@
package dev.resent.sound;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.Base64;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.UnsupportedAudioFileException;
import net.minecraft.client.Minecraft;
import net.minecraft.client.audio.PositionedSoundRecord;
import net.minecraft.util.ResourceLocation;
public class SoundManager {
FileOutputStream fos = null;
File temp;
public void playSound(String base64) throws UnsupportedEncodingException{
byte[] byteArray = Base64.getDecoder().decode(new String(base64).getBytes("UTF-8"));
this.playSound(byteArray);
}
public void playSound(byte[] bArray) {
try {
temp = new File("C:/test").getAbsoluteFile();
if (!temp.exists()) {
temp.createNewFile();
}
fos = new FileOutputStream(temp);
fos.write(bArray);
fos.flush();
AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(temp);
Clip clip = AudioSystem.getClip();
clip.open(audioInputStream);
clip.start();
} catch (IOException ioe) {
ioe.printStackTrace();
} catch (UnsupportedAudioFileException e) {
e.printStackTrace();
} catch (LineUnavailableException e) {
e.printStackTrace();
} finally {
try {
if (fos != null) {
fos.close();
}
} catch (IOException ioe) {
System.out.println("Error in closing the Stream");
}
}
}
// <3
public void playAvasDedication(){
Minecraft.getMinecraft().getSoundHandler().stopSounds();
Minecraft.getMinecraft().getSoundHandler().playSound(PositionedSoundRecord.create(new ResourceLocation("minecraft:music.res"), 1));
}
public void stopMusic() {
Minecraft.getMinecraft().getSoundHandler().stopSounds();
}
}

View File

@ -1,6 +1,6 @@
package dev.resent.ui;
import dev.resent.Resent;
import dev.resent.client.Resent;
import dev.resent.module.base.Mod;
import dev.resent.module.setting.BooleanSetting;
import dev.resent.module.setting.ModeSetting;

View File

@ -1,5 +1,6 @@
package dev.resent.ui;
import dev.resent.util.render.Color;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.Gui;
@ -17,6 +18,6 @@ public class ClientButton extends GuiButton {
this.hovered = (mouseX >= this.xPosition && mouseY >= this.yPosition && mouseX < this.xPosition + this.width && mouseY < this.yPosition + this.height);
Gui.drawRect(this.xPosition, this.yPosition, this.xPosition + this.width, this.yPosition + this.height, hovered ? 0x30ffffff : 0x20ffffff);
drawCenteredString(fr, this.displayString, this.xPosition + this.width / 2, this.yPosition + (this.height - 8) / 2, -1, false);
drawCenteredString(fr, this.displayString, this.xPosition + this.width / 2, this.yPosition + (this.height - 8) / 2, Color.RED.getRGB(), false);
}
}

View File

@ -1,253 +0,0 @@
package dev.resent.ui;
/*package dev.resent.ui.mods;
import java.util.ArrayList;
import dev.resent.Resent;
import dev.resent.module.base.Mod;
import dev.resent.setting.BooleanSetting;
import dev.resent.setting.Setting;
import dev.resent.util.misc.Keyboard;
GlStateManager.popMatrix();
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
import net.minecraft.src.GuiButton;
import net.minecraft.src.GuiScreen;
import net.minecraft.src.GuiTextField;
import net.minecraft.src.MathHelper;
@SuppressWarnings("all")
public class GuiScreenModule extends GuiScreen {
protected String screenTitle = "Resent";
public int mcount = 0;
public ArrayList<Mod> modules = new ArrayList<>();
public boolean watchingMod = false;
public Mod modWatching = null;
public String searchString = "";
public GuiTextField search;
public int offset = 0;
@Override
protected void mouseClicked(int mouseX, int mouseY, int par3) {
if (watchingMod == false && modWatching == null) {
this.search.mouseClicked(mouseX, mouseY, par3);
int i = 0;
for (int z = 0; z < Resent.INSTANCE.modManager.modules.size(); z++) {
Mod m = Resent.INSTANCE.modManager.modules.get(z);
if (m.name.toLowerCase().contains(this.searchString.toLowerCase())) {
int x = 10;
int y = (10 + fontRenderer.FONT_HEIGHT * 2 + 15 + 10 + 10) + 60 * i + 10 - offset;
int width = MathHelper.clamp_int(this.width / 4, 200, this.width / 4) - 10 - x;
int height = (10 + fontRenderer.FONT_HEIGHT * 2 + 15 + 10 + 10) + 60 * i + 60 - offset - y;
if ((mouseX >= x && mouseX <= x + width && mouseY >= y && mouseY <= y + height && par3 == 0)
&& !(mouseX >= x + 5 && mouseX <= x + width - 5 && mouseY >= y + height - 5 - 15
&& mouseY <= y + height - 5))
m.toggle();
if (par3 == 0 && mouseX >= x + 5 && mouseX <= x + width - 5 && mouseY >= y + height - 5 - 15
&& mouseY <= y + height - 5) {
this.modWatching = m;
this.watchingMod = true;
}
i++;
}
}
} else {
Mod m1 = this.modWatching;
if (par3 == 0 && mouseX >= (10 + fontRenderer.FONT_HEIGHT + 6) / 2 / 2
&& mouseX <= (10 + fontRenderer.FONT_HEIGHT + 6) / 2 / 2 + (10 + fontRenderer.FONT_HEIGHT + 6) / 2
&& mouseY >= (10 + fontRenderer.FONT_HEIGHT + 6) / 2 / 2
&& mouseY <= (10 + fontRenderer.FONT_HEIGHT + 6) / 2 / 2
+ (10 + fontRenderer.FONT_HEIGHT + 6) / 2) {
watchingMod = false;
modWatching = null;
}else {
int i = 0;
Mod m = this.modWatching;
for (int amongus = 0; amongus < m.settings.size(); amongus++) {
Setting s = m.settings.get(amongus);
BooleanSetting bS = null;
if (s instanceof BooleanSetting) {
bS = (BooleanSetting) s;
}
int x = 10;
int y = (fontRenderer.FONT_HEIGHT * 2 + 45) + 60 * i + 10 - offset;
int width = MathHelper.clamp_int(this.width / 4, 200, this.width / 4) - 10 - x;
int height = (fontRenderer.FONT_HEIGHT * 2 + 45) + 60 * i + 60 - offset - y;
if (isMouseInside(mouseX, mouseY, 10, (fontRenderer.FONT_HEIGHT*2+45)+60*i+10-offset,
MathHelper.clamp_int(this.width / 4, 200, this.width / 4) - 10,
(10 + fontRenderer.FONT_HEIGHT * 2 + 15 + 10 + 10) + 60 * i + 60 - offset) && par3 == 0) {
if (bS != null) {
bS.setValue(!bS.getValue());
}
}
i++;
}
}
}
super.mouseClicked(mouseX, mouseY, par3);
}
public void drawScreen(int mx, int my, float par3) {
offset = MathHelper.clamp_int(MathHelper.clamp_int(offset, 0, getListMaxScroll()), 0, getListMaxScroll());
Gui.drawRect(0, 0, MathHelper.clamp_int(this.width / 4, 200, this.width / 4), this.height, 0xFF090909);
if (!this.watchingMod && this.modWatching == null) {
int i = 0;
for (int z = 0; z < Resent.INSTANCE.modManager.modules.size(); z++) {
Mod m = Resent.INSTANCE.modManager.modules.get(z);
if (m.name.toLowerCase().contains(this.searchString.toLowerCase())) {
int frho = (10 + fontRenderer.FONT_HEIGHT * 2 + 15 + 10 + 10 + 60 * i + 60 - offset);
int x = 10;
int y = (fontRenderer.FONT_HEIGHT*2+45) + 60 * i + 10 - offset;
int width = MathHelper.clamp_int(this.width / 4, 200, this.width / 4) - 10 - x;
int height = frho - y;
Gui.drawRect(10, (10 + fontRenderer.FONT_HEIGHT * 2 + 15 + 10 + 10) + 60 * i + 10 - offset,
MathHelper.clamp_int(this.width / 4, 200, this.width / 4) - 10,
frho, 0xff1c1c1c);
fontRenderer.drawString(m.name, 20,
(10 + fontRenderer.FONT_HEIGHT * 2 + 15 + 10 + 10) + 60 * i + 10 - offset + 10, -1);
Gui.drawRect(x, y, x + width, y + 1, m.isEnabled() ? 0xff009e00 : 0xff9e0000);
Gui.drawRect(x, y, x + 1, y + height, m.isEnabled() ? 0xff009e00 : 0xff9e0000);
Gui.drawRect(x + width - 1, y, x + width, y + height, m.isEnabled() ? 0xff009e00 : 0xff9e0000);
Gui.drawRect(x, y + height - 1, x + width, y + height, m.isEnabled() ? 0xff009e00 : 0xff9e0000);
Gui.drawRect(x + 5, y + height - 5 - 15, x + width - 5, y + height - 5, 0xff333333);
fontRenderer.drawString("Settings",
(x + width / 2) - fontRenderer.getStringWidth("Settings") / 2,
y + height - 5 - 15 + fontRenderer.FONT_HEIGHT / 2, -1);
i++;
}
}
Gui.drawRect(0, 0, MathHelper.clamp_int(this.width / 4, 200, this.width / 4),
10 + fontRenderer.FONT_HEIGHT * 2 + 15 + 10, 0xFF090909);
this.search.drawTextBox();
fontRenderer.drawString(screenTitle + " - ClickGui", this.width / 4 / 2 - fontRenderer.getStringWidth(screenTitle + "") / 2,
10,
-1);
} else {
int frho3 = (10+fontRenderer.FONT_HEIGHT+6)/2/2;
Gui.drawRect(frho3, frho3, frho3+(10+fontRenderer.FONT_HEIGHT+6)/2, frho3+(10+fontRenderer.FONT_HEIGHT+6)/2,0xff1c1c1c);
fontRenderer.drawString("<", frho3+frho3-fontRenderer.getStringWidth("<")/2, frho3+frho3-fontRenderer.FONT_HEIGHT/2, -1);
fontRenderer.drawString(screenTitle + " - "+modWatching.name, MathHelper.clamp_int(this.width/4, 200, this.width/4)/2-fontRenderer.getStringWidth(screenTitle + " - "+modWatching.name)/2, 10, -1);
Gui.drawRect(0, 10+fontRenderer.FONT_HEIGHT+6, MathHelper.clamp_int(this.width/4, 200, this.width/4), 10+fontRenderer.FONT_HEIGHT+7, -1);
int i = 0;
Mod m = this.modWatching;
for (int amongus = 0; amongus < m.settings.size(); amongus++) {
Setting s = m.settings.get(amongus);
BooleanSetting bS = null;
if (s instanceof BooleanSetting) {
bS = (BooleanSetting)s;
}
int x = 10;
int y = (fontRenderer.FONT_HEIGHT*2+45)+60*i+10-offset;
int frho1 = (10 + fontRenderer.FONT_HEIGHT * 2 + 15 + 10 + 10);
int width = MathHelper.clamp_int(this.width / 4, 200, this.width / 4) - 10 - x;
int height = (fontRenderer.FONT_HEIGHT*2+45)+60*i+60-offset-y;
Gui.drawRect(10, y,
MathHelper.clamp_int(this.width / 4, 200, this.width / 4) - 10,
frho1 + 60 * i + 60 - offset, 0xff1c1c1c);
fontRenderer.drawString(s.name, 20,frho1 + 60 * i + 10 - offset + 10, -1);
if (bS != null) {
Gui.drawRect(x, y, x + width, y + 1, bS.getValue() ? 0xff009e00 : 0xff9e0000);
Gui.drawRect(x, y, x + 1, y + height, bS.getValue() ? 0xff009e00 : 0xff9e0000);
Gui.drawRect(x + width - 1, y, x + width, y + height, bS.getValue() ? 0xff009e00 : 0xff9e0000);
Gui.drawRect(x, y + height - 1, x + width, y + height, bS.getValue() ? 0xff009e00 : 0xff9e0000);
}
i++;
}
}
super.drawScreen(mx, my, par3);
}
@Override
protected void actionPerformed(GuiButton par1GuiButton) {
if (par1GuiButton.id == 200) {
this.mc.displayGuiScreen(null);
}else if (par1GuiButton.id == 5) {
mc.displayGuiScreen(new HUDConfigScreen());
}else if (par1GuiButton.id == 2) {
mc.displayGuiScreen(new ClickGUI());
}
if (par1GuiButton.id != 200 && par1GuiButton.id != 5 && par1GuiButton.id != 2) {
this.mc.displayGuiScreen(new GuiScreenModule());
}
super.actionPerformed(par1GuiButton);
}
public boolean doesGuiPauseGame() {
return false;
}
@Override
public void updateScreen() {
this.search.updateCursorCounter();
super.updateScreen();
}
@Override
protected void keyTyped(char par1, int par2) {
this.search.textboxKeyTyped(par1, par2);
searchString = this.search.getText();
if (par2 == Keyboard.KEY_ESCAPE || par2 == Minecraft.getMinecraft().gameSettings.keyBindClickGui.keyCode)
mc.displayGuiScreen(null);
super.keyTyped(par1, par2);
}
@Override
public void handleMouseInput() {
if (getListMaxScroll() + this.height >= this.height) {
int wheel = EaglerAdapter.mouseGetEventDWheel();
if (wheel < 0) {
for (int i = 0; i < 20; i++) {
offset = MathHelper.clamp_int(offset + 1, 0, getListMaxScroll());
}
} else if (wheel > 0) {
for (int i = 0; i < 20; i++) {
offset = MathHelper.clamp_int(offset - 1, 0, getListMaxScroll());
}
}
super.handleMouseInput();
}
offset = MathHelper.clamp_int(MathHelper.clamp_int(offset, 0, getListMaxScroll()), 0, getListMaxScroll());
}
private int getListMaxScroll() {
int mods = 0;
int i = 0;
for (int z = 0; z < Resent.INSTANCE.modManager.modules.size(); z++) {
Mod m = Resent.INSTANCE.modManager.modules.get(z);
if (m.name.toLowerCase().contains(this.searchString.toLowerCase())) {
mods++;
i++;
}
}
return 60 * mods + 70 - this.height;
}
public void initGui() {
this.buttonList.add(new GuiButton(200, this.width - 200, this.height - 20, 100, 20, "Back"));
this.buttonList.add(new GuiButton(5, this.width - 100, this.height - 20, 100, 20, "Modify HUD"));
this.buttonList.add(new GuiButton(2, this.width - 300, this.height - 20, 100, 20, "Test"));
search = new GuiTextField(fontRenderer, 10, 10 + fontRenderer.FONT_HEIGHT * 2,
MathHelper.clamp_int(this.width / 4, 200, this.width / 4) - 20, 15);
this.search.custom = true;
this.search.setText(searchString);
}
public void onGuiClosed() {
EaglerAdapter.enableRepeatEvents(false);
mc.gameSettings.saveOptions();
}
public boolean isMouseInside(int mouseX, int mouseY, int x, int y, int width, int height) {
return (mouseX >= x && mouseX <= width) && (mouseY >= y && mouseY <= height);
}
}*/

View File

@ -1,16 +1,15 @@
package dev.resent.ui;
import dev.resent.Resent;
import dev.resent.client.Resent;
import dev.resent.module.base.RenderMod;
import net.lax1dude.eaglercraft.v1_8.Keyboard;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
@SuppressWarnings("all")
public class HUDConfigScreen extends GuiScreen {
public void initGui() {
this.buttonList.add(new GuiButton(200, this.width / 2 - 100, this.height / 6 + 148, "Back"));
this.buttonList.add(new GuiButton(200, this.width / 2 - 100, this.height / 6 + 148, 50, 11, "Back"));
}
public void onGuiClosed() {
@ -20,11 +19,7 @@ public class HUDConfigScreen extends GuiScreen {
public void drawScreen(int mx, int my, float par3) {
this.drawDefaultBackground();
for (int i = 0; i < Resent.INSTANCE.modManager.modules.size(); i++) {
if (Resent.INSTANCE.modManager.modules.get(i).isEnabled() && (Resent.INSTANCE.modManager.modules.get(i) instanceof RenderMod)) {
((RenderMod) Resent.INSTANCE.modManager.modules.get(i)).renderLayout(mx, my);
}
}
Resent.INSTANCE.modManager.modules.stream().filter(m -> m.isEnabled() && m instanceof RenderMod).forEach(rm -> ((RenderMod)rm).renderLayout(mx, my));
super.drawScreen(mx, my, par3);
}
@ -33,8 +28,4 @@ public class HUDConfigScreen extends GuiScreen {
this.mc.displayGuiScreen(new ClickGUI());
}
}
public boolean doesGuiPauseGame() {
return false;
}
}

View File

@ -11,7 +11,8 @@ import static net.lax1dude.eaglercraft.v1_8.opengl.RealOpenGLEnums.GL_PROJECTION
import static net.lax1dude.eaglercraft.v1_8.opengl.RealOpenGLEnums.GL_SMOOTH;
import com.google.common.collect.Lists;
import dev.resent.Resent;
import dev.resent.client.Resent;
import dev.resent.module.base.ModManager;
import dev.resent.ui.PreGUI;
import dev.resent.util.misc.W;

View File

@ -8,7 +8,8 @@ import static net.lax1dude.eaglercraft.v1_8.opengl.RealOpenGLEnums.GL_SRC_ALPHA;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import dev.resent.Resent;
import dev.resent.client.Resent;
import dev.resent.module.base.RenderMod;
import dev.resent.ui.animation.SimpleAnimation;
import dev.resent.util.misc.W;

View File

@ -4,7 +4,8 @@ import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import dev.resent.Resent;
import dev.resent.client.Resent;
import dev.resent.module.base.ModManager;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;

View File

@ -2,7 +2,8 @@ package net.minecraft.entity.player;
import com.google.common.base.Charsets;
import com.google.common.collect.Lists;
import dev.resent.Resent;
import dev.resent.client.Resent;
import dev.resent.module.base.ModManager;
import java.util.Collection;
import java.util.List;