HudComponent: Now has value saving, Entire project optimize import & code reformat

This commit is contained in:
noil 2020-12-24 14:47:30 -05:00
parent aabb8161d6
commit dc80e6fc3f
14 changed files with 148 additions and 68 deletions

View File

@ -1,5 +1,10 @@
package me.rigamortis.seppuku.api.gui.hud.component;
import me.rigamortis.seppuku.api.value.Value;
import java.util.ArrayList;
import java.util.List;
/**
* Author Seth
* 7/25/2019 @ 4:14 AM.
@ -18,6 +23,8 @@ public class HudComponent {
private boolean visible;
private List<Value> valueList = new ArrayList<Value>();
public HudComponent() {
}
@ -91,6 +98,21 @@ public class HudComponent {
return collisionX && collisionY;
}
public Value findValue(String alias) {
for (Value v : this.getValueList()) {
for (String s : v.getAlias()) {
if (alias.equalsIgnoreCase(s)) {
return v;
}
}
if (v.getName().equalsIgnoreCase(alias)) {
return v;
}
}
return null;
}
public float getX() {
return x;
}
@ -154,4 +176,12 @@ public class HudComponent {
public void setVisible(boolean visible) {
this.visible = visible;
}
public List<Value> getValueList() {
return valueList;
}
public void setValueList(List<Value> valueList) {
this.valueList = valueList;
}
}

View File

@ -116,7 +116,7 @@ public class Module {
return msg;
}
public Value find(String alias) {
public Value findValue(String alias) {
for (Value v : this.getValueList()) {
for (String s : v.getAlias()) {
if (alias.equalsIgnoreCase(s)) {

View File

@ -1,14 +1,17 @@
package me.rigamortis.seppuku.impl.config;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import me.rigamortis.seppuku.Seppuku;
import me.rigamortis.seppuku.api.config.Configurable;
import me.rigamortis.seppuku.api.gui.hud.component.DraggableHudComponent;
import me.rigamortis.seppuku.api.gui.hud.component.HudComponent;
import me.rigamortis.seppuku.api.util.FileUtil;
import me.rigamortis.seppuku.api.value.Value;
import me.rigamortis.seppuku.impl.gui.hud.anchor.AnchorPoint;
import java.io.File;
import java.util.Map;
/**
* @author noil
@ -69,6 +72,8 @@ public final class HudConfig extends Configurable {
break;
}
this.loadValues(entry);
});
} else {
this.getJsonObject().entrySet().forEach(entry -> {
@ -89,6 +94,8 @@ public final class HudConfig extends Configurable {
hudComponent.setVisible(entry.getValue().getAsBoolean());
break;
}
this.loadValues(entry);
});
}
}
@ -111,6 +118,44 @@ public final class HudConfig extends Configurable {
componentsListJsonObject.addProperty("GlueSide", draggableHudComponent.getGlued() == null ? "NONE" : ((DraggableHudComponent) hudComponent).getGlueSide().name());
}
if (hudComponent.getValueList().size() != 0) {
hudComponent.getValueList().forEach(value -> {
if (value.getValue() instanceof Boolean)
componentsListJsonObject.addProperty(value.getName(), (Boolean) value.getValue());
else if (value.getValue() instanceof Number && !(value.getValue() instanceof Enum)) {
if (value.getValue().getClass() == Float.class) {
componentsListJsonObject.addProperty(value.getName(), (Float) value.getValue());
} else if (value.getValue().getClass() == Double.class) {
componentsListJsonObject.addProperty(value.getName(), (Double) value.getValue());
} else if (value.getValue().getClass() == Integer.class) {
componentsListJsonObject.addProperty(value.getName(), (Integer) value.getValue());
}
} else if (value.getValue() instanceof Enum) {
componentsListJsonObject.addProperty(value.getName(), ((Enum) value.getValue()).name());
}
});
}
this.saveJsonObjectToFile(componentsListJsonObject);
}
private void loadValues(Map.Entry<String, JsonElement> entry) {
for (Value val : hudComponent.getValueList()) {
if (val.getName().equalsIgnoreCase(entry.getKey())) {
if (val.getValue() instanceof Boolean) {
val.setValue(entry.getValue().getAsBoolean());
} else if (val.getValue() instanceof Number && !(val.getValue() instanceof Enum)) {
if (val.getValue().getClass() == Float.class) {
val.setValue(entry.getValue().getAsFloat());
} else if (val.getValue().getClass() == Double.class) {
val.setValue(entry.getValue().getAsDouble());
} else if (val.getValue().getClass() == Integer.class) {
val.setValue(entry.getValue().getAsInt());
}
} else if (val.getValue() instanceof Enum) {
val.setEnumValue(entry.getValue().getAsString());
}
}
}
}
}

View File

@ -20,7 +20,6 @@ import net.minecraft.entity.item.EntityEnderPearl;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntityThrowable;
import net.minecraft.item.ItemShulkerBox;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagCompound;

View File

@ -1,15 +1,12 @@
package me.rigamortis.seppuku.impl.gui.hud.component;
import com.mojang.realmsclient.gui.ChatFormatting;
import me.rigamortis.seppuku.Seppuku;
import me.rigamortis.seppuku.api.gui.hud.component.DraggableHudComponent;
import me.rigamortis.seppuku.api.gui.hud.component.ResizableHudComponent;
import me.rigamortis.seppuku.api.util.ColorUtil;
import me.rigamortis.seppuku.api.util.MathUtil;
import me.rigamortis.seppuku.api.util.RenderUtil;
import me.rigamortis.seppuku.api.util.Timer;
import me.rigamortis.seppuku.api.value.Value;
import me.rigamortis.seppuku.impl.gui.hud.GuiHudEditor;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.util.math.Vec2f;
import org.lwjgl.input.Keyboard;
@ -23,11 +20,11 @@ import java.util.concurrent.CopyOnWriteArrayList;
*/
public final class TpsGraphComponent extends ResizableHudComponent {
public final Value<Float> delay = new Value<Float>("Delay", new String[]{"Del"}, "The amount of delay in milliseconds.", 500.0f, 0.0f, 2500.0f, 100.0f);
private final List<TpsNode> tpsNodes = new CopyOnWriteArrayList<TpsNode>();
private final Timer timer = new Timer();
private float timerDelay = 500.0f;
public TpsGraphComponent() {
super("TpsGraph", 60, 27);
this.setW(60);
@ -43,7 +40,7 @@ public final class TpsGraphComponent extends ResizableHudComponent {
this.tpsNodes.clear();
}
if (this.timer.passed(this.timerDelay)) {
if (this.timer.passed(this.delay.getValue())) {
if (this.tpsNodes.size() > (this.getW() / 2 - 1)) {
this.tpsNodes.remove(0); // remove oldest
}
@ -87,7 +84,7 @@ public final class TpsGraphComponent extends ResizableHudComponent {
if (this.isMouseInside(mouseX, mouseY)) {
// draw delay
mc.fontRenderer.drawStringWithShadow(this.timerDelay + "ms", this.getX() + 2, this.getY() + this.getH() - mc.fontRenderer.FONT_HEIGHT - 2, 0xFFAAAAAA);
mc.fontRenderer.drawStringWithShadow(this.delay.getValue() + "ms", this.getX() + 2, this.getY() + this.getH() - mc.fontRenderer.FONT_HEIGHT - 2, 0xFFAAAAAA);
}
// hovered data
@ -116,15 +113,15 @@ public final class TpsGraphComponent extends ResizableHudComponent {
super.mouseRelease(mouseX, mouseY, button);
if (this.isMouseInside(mouseX, mouseY) && button == 1/* right click */) {
if (Keyboard.isKeyDown(Keyboard.KEY_LCONTROL)) {
this.timerDelay += 100.0f;
this.delay.setValue(this.delay.getValue() + this.delay.getInc());
} else if (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) {
this.timerDelay -= 10.0f;
this.delay.setValue(this.delay.getValue() - 10.0f);
} else {
this.timerDelay -= 100.0f;
this.delay.setValue(this.delay.getValue() - this.delay.getInc());
}
if (this.timerDelay <= 0.0f || this.timerDelay > 2500.0f)
this.timerDelay = 1000.0f;
if (this.delay.getValue() <= this.delay.getMin() || this.delay.getValue() > this.delay.getMax())
this.delay.setValue(1000.0f);
}
}

View File

@ -135,7 +135,7 @@ public final class CommandManager {
final String[] split = input.split(" ");
final Value v = module.find(split[1]);
final Value v = module.findValue(split[1]);
if (v != null) {
if (v.getValue() instanceof Boolean) {

View File

@ -5,6 +5,7 @@ import me.rigamortis.seppuku.api.event.render.EventRender2D;
import me.rigamortis.seppuku.api.gui.hud.component.HudComponent;
import me.rigamortis.seppuku.api.module.Module;
import me.rigamortis.seppuku.api.util.ReflectionUtil;
import me.rigamortis.seppuku.api.value.Value;
import me.rigamortis.seppuku.impl.gui.hud.GuiHudEditor;
import me.rigamortis.seppuku.impl.gui.hud.anchor.AnchorPoint;
import me.rigamortis.seppuku.impl.gui.hud.component.*;
@ -15,6 +16,7 @@ import net.minecraft.client.gui.ScaledResolution;
import team.stiff.pomelo.impl.annotated.handler.annotation.Listener;
import java.io.File;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
@ -68,46 +70,46 @@ public final class HudManager {
moduleList.setY(moduleList.getY() + moduleListYOffset);
}
this.componentList.add(moduleList);
add(moduleList);
moduleListXOffset += moduleList.getW() + 4 /* gap between each list */;
}
this.componentList.add(new WatermarkComponent());
this.componentList.add(new EnabledModsComponent(TOP_RIGHT)); // creates the enabled mods component & by default anchors in the top right (to aid new users)
this.componentList.add(new TpsComponent());
this.componentList.add(new PotionEffectsComponent());
this.componentList.add(new FpsComponent());
this.componentList.add(new CoordsComponent());
this.componentList.add(new NetherCoordsComponent());
this.componentList.add(new SpeedComponent());
this.componentList.add(new ArmorComponent());
this.componentList.add(new PingComponent());
this.componentList.add(new ServerBrandComponent());
this.componentList.add(new BiomeComponent());
this.componentList.add(new DirectionComponent());
this.componentList.add(new PacketTimeComponent());
this.componentList.add(new TimeComponent());
this.componentList.add(new EnemyPotionsComponent());
this.componentList.add(new CompassComponent());
this.componentList.add(new HubComponent());
this.componentList.add(new InventoryComponent());
this.componentList.add(new TotemCountComponent());
this.componentList.add(new TutorialComponent());
this.componentList.add(new HoleOverlayComponent());
this.componentList.add(new PlayerCountComponent());
this.componentList.add(new OverViewComponent());
this.componentList.add(new RearViewComponent());
this.componentList.add(new EntityListComponent());
this.componentList.add(new TpsGraphComponent());
add(new WatermarkComponent());
add(new EnabledModsComponent(TOP_RIGHT)); // creates the enabled mods component & by default anchors in the top right (to aid new users)
add(new TpsComponent());
add(new PotionEffectsComponent());
add(new FpsComponent());
add(new CoordsComponent());
add(new NetherCoordsComponent());
add(new SpeedComponent());
add(new ArmorComponent());
add(new PingComponent());
add(new ServerBrandComponent());
add(new BiomeComponent());
add(new DirectionComponent());
add(new PacketTimeComponent());
add(new TimeComponent());
add(new EnemyPotionsComponent());
add(new CompassComponent());
add(new HubComponent());
add(new InventoryComponent());
add(new TotemCountComponent());
add(new TutorialComponent());
add(new HoleOverlayComponent());
add(new PlayerCountComponent());
add(new OverViewComponent());
add(new RearViewComponent());
add(new EntityListComponent());
add(new TpsGraphComponent());
TrayComponent trayComponent = new TrayComponent();
trayComponent.setAnchorPoint(BOTTOM_CENTER);
this.componentList.add(trayComponent);
add(trayComponent);
NotificationsComponent notificationsComponent = new NotificationsComponent();
notificationsComponent.setAnchorPoint(TOP_CENTER);
this.componentList.add(notificationsComponent);
add(notificationsComponent);
this.loadExternalHudComponents();
@ -120,6 +122,29 @@ public final class HudManager {
Seppuku.INSTANCE.getEventManager().addEventListener(this);
}
/**
* Find all fields within the hud component that are values
* and add them to the list of values inside of the hud component
*
* @param component the HudComponent to add
*/
public void add(HudComponent component) {
try {
for (Field field : component.getClass().getDeclaredFields()) {
if (Value.class.isAssignableFrom(field.getType())) {
if (!field.isAccessible()) {
field.setAccessible(true);
}
final Value val = (Value) field.get(component);
component.getValueList().add(val);
}
}
this.componentList.add(component);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Update our anchor point positions when we render
*

View File

@ -7,7 +7,6 @@ import me.rigamortis.seppuku.api.util.Timer;
import me.rigamortis.seppuku.api.value.Value;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.renderer.InventoryEffectRenderer;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.init.Enchantments;
import net.minecraft.init.Items;

View File

@ -10,7 +10,6 @@ import me.rigamortis.seppuku.api.value.Value;
import net.minecraft.client.Minecraft;
import net.minecraft.network.play.server.SPacketChat;
import net.minecraft.util.StringUtils;
import net.minecraft.util.math.Vec2f;
import team.stiff.pomelo.impl.annotated.handler.annotation.Listener;
import java.io.File;
@ -19,7 +18,6 @@ import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

View File

@ -1,9 +1,6 @@
package me.rigamortis.seppuku.impl.module.misc;
import com.google.common.collect.Maps;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject;
import com.mojang.realmsclient.gui.ChatFormatting;
import me.rigamortis.seppuku.Seppuku;
import me.rigamortis.seppuku.api.event.EventStageable;
@ -12,7 +9,6 @@ import me.rigamortis.seppuku.api.module.Module;
import me.rigamortis.seppuku.api.util.FileUtil;
import me.rigamortis.seppuku.api.value.Value;
import me.rigamortis.seppuku.impl.module.hidden.CommandsModule;
import me.rigamortis.seppuku.impl.module.render.LogoutSpotsModule;
import net.minecraft.client.Minecraft;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.play.server.SPacketChunkData;
@ -24,9 +20,7 @@ import net.minecraft.util.text.event.HoverEvent;
import team.stiff.pomelo.impl.annotated.handler.annotation.Listener;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

View File

@ -1,18 +1,15 @@
package me.rigamortis.seppuku.impl.module.render;
import me.rigamortis.seppuku.api.event.client.EventSaveConfig;
import me.rigamortis.seppuku.api.event.player.EventPlayerDamageBlock;
import me.rigamortis.seppuku.api.event.render.EventRender3D;
import me.rigamortis.seppuku.api.module.Module;
import me.rigamortis.seppuku.api.util.ColorUtil;
import me.rigamortis.seppuku.api.util.MathUtil;
import me.rigamortis.seppuku.api.util.RenderUtil;
import me.rigamortis.seppuku.api.value.Value;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.init.Blocks;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;

View File

@ -1,14 +1,12 @@
package me.rigamortis.seppuku.impl.module.render;
import me.rigamortis.seppuku.Seppuku;
import me.rigamortis.seppuku.api.event.client.EventSaveConfig;
import me.rigamortis.seppuku.api.event.player.EventDestroyBlock;
import me.rigamortis.seppuku.api.event.render.EventRender3D;
import me.rigamortis.seppuku.api.event.render.EventRenderBlockModel;
import me.rigamortis.seppuku.api.event.world.EventLoadWorld;
import me.rigamortis.seppuku.api.module.Module;
import me.rigamortis.seppuku.api.util.ColorUtil;
import me.rigamortis.seppuku.api.util.MathUtil;
import me.rigamortis.seppuku.api.util.RenderUtil;
import me.rigamortis.seppuku.api.value.Value;
import net.minecraft.block.Block;
@ -22,7 +20,6 @@ import net.minecraft.init.Blocks;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.math.Vec3i;
import team.stiff.pomelo.impl.annotated.handler.annotation.Listener;
import java.util.ArrayList;

View File

@ -1,14 +1,12 @@
package me.rigamortis.seppuku.impl.module.render;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.mojang.realmsclient.gui.ChatFormatting;
import me.rigamortis.seppuku.Seppuku;
import me.rigamortis.seppuku.api.event.EventStageable;
import me.rigamortis.seppuku.api.event.network.EventReceivePacket;
import me.rigamortis.seppuku.api.event.render.EventRender2D;
import me.rigamortis.seppuku.api.event.render.EventRenderName;
import me.rigamortis.seppuku.api.event.world.EventAddEntity;
import me.rigamortis.seppuku.api.friend.Friend;
import me.rigamortis.seppuku.api.module.Module;
import me.rigamortis.seppuku.api.util.*;
@ -24,12 +22,10 @@ import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.*;
import net.minecraft.entity.monster.IMob;
import net.minecraft.entity.passive.AbstractHorse;
import net.minecraft.entity.passive.EntityHorse;
import net.minecraft.entity.passive.EntityTameable;
import net.minecraft.entity.passive.IAnimals;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.init.MobEffects;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
@ -45,7 +41,10 @@ import net.minecraft.util.math.Vec3d;
import team.stiff.pomelo.impl.annotated.handler.annotation.Listener;
import java.text.DecimalFormat;
import java.util.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
/**