Skip to content

Commit

Permalink
Copy-paste properties/settings of HudElements now!
Browse files Browse the repository at this point in the history
  • Loading branch information
tanishisherewithhh committed Jul 10, 2024
1 parent 805125b commit e04bcf6
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 21 deletions.
15 changes: 9 additions & 6 deletions src/main/java/dev/heliosclient/HeliosClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,28 +58,31 @@ public class HeliosClient implements ModInitializer, Listener {

public static void loadConfig() {
load(config -> {
CONFIG.loadEverything();
config.loadEverything();
LOGGER.info("Loading Config complete in: {}s", configTimer.getElapsedTime());

String configSelectedbefore = (String) CONFIG.otherConfigManager.getCurrentConfig().getReadData().get(CLICKGUI.switchConfigs.getSaveName());
if (configSelectedbefore != null) {
CONFIG.getModuleConfigManager().switchConfig(configSelectedbefore, false);
String configSelectedAsSaved = (String) config.otherConfigManager.getCurrentConfig().getReadData().get(CLICKGUI.switchConfigs.getSaveName());
if (configSelectedAsSaved != null) {
//We are loading at the earliest before the user can make changes so no need to save.
config.getModuleConfigManager().switchConfig(configSelectedAsSaved, false);
loadModulesOnly();
}
});
}

private static void load(Consumer<Config> consumer) {
//Record time it took

configTimer.startTimer();

consumer.accept(CONFIG);

configTimer.resetTimer();

if (shouldSendNotification() && ModuleManager.get(NotificationModule.class).clientNotification.value) {
NotificationManager.addNotification(new InfoNotification("Loading Done", "in: " + configTimer.getElapsedTime() + "s", 1000, SoundUtils.TING_SOUNDEVENT));
}

configTimer.resetTimer();

// Font event is posted to allow the GUI to reset its calculation for the new font by the config.
if (fonts != null)
EventManager.postEvent(new FontChangeEvent(fonts));
Expand Down
10 changes: 7 additions & 3 deletions src/main/java/dev/heliosclient/hud/HudElement.java
Original file line number Diff line number Diff line change
Expand Up @@ -465,15 +465,19 @@ public Object saveToFile(List<Object> objects) {

map.put("dimensions", objects);

saveSettingsToMap(map);

return map;
}

public void saveSettingsToMap(Map<String, Object> MAP){
for (SettingGroup settingGroup : settingGroups) {
for (Setting<?> setting : settingGroup.getSettings()) {
if (setting.name != null) {
map.put(setting.getSaveName(), setting.saveToFile(new ArrayList<>()));
MAP.put(setting.getSaveName(), setting.saveToFile(new ArrayList<>()));
}
}
}

return map;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ public ClientTag() {
this.height = Math.round(Renderer2D.getStringHeight());
this.draggable = false;
this.renderOutLineBox = false;
} public static HudElementData<ClientTag> DATA = new HudElementData<>("Client Tag", "Shows client watermark", ClientTag::new);
}

public static HudElementData<ClientTag> DATA = new HudElementData<>("Client Tag", "Shows client watermark", ClientTag::new);

@Override
public void renderElement(DrawContext drawContext, TextRenderer textRenderer) {
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/dev/heliosclient/managers/CapeManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ public class CapeManager {
//Where we store and get our capes.
private static final File CAPE_DIRECTORY = new File(HeliosClient.MC.runDirectory, "heliosclient/capes");
private static final String DEFAULT_CAPE = "helioscape.png";
//The default CURRENT_PLAYER_CAPE texture of heliosclient.
//The default cape texture of heliosclient.
public static final Identifier DEFAULT_CAPE_TEXTURE = new Identifier("heliosclient", "capes/" + DEFAULT_CAPE);
//All the capes which are registered in the dynamic texture manager
private static final Set<String> registeredTextures = new HashSet<>();
//A map of all CURRENT_PLAYER_CAPE textures keyed with the UUID
//A map of all cape textures keyed with the UUID
private static final Map<UUID, Identifier> CAPES = new HashMap<>();

//These maps are supposed to be used when we need to check for heliosclient users to apply capes to them
Expand All @@ -52,10 +52,10 @@ public class CapeManager {
//A string of the names of the CURRENT_PLAYER_CAPE. Used in CapeModule
public static String[] CAPE_NAMES = new String[]{};

//Current CURRENT_PLAYER_CAPE texture we are applying to the player
//Current cape texture we are applying to the player
public static Identifier CURRENT_PLAYER_CAPE;

//List of all CURRENT_PLAYER_CAPE and elytra textures.
//List of all capes and elytra textures.
public static List<Identifier> capeIdentifiers = new ArrayList<>();
public static List<Identifier> elytraIdentifiers = new ArrayList<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ public abstract class AbstractClientPlayerEntityMixin {
if (elytraTexture == null) {
elytraTexture = SKIN;
}

//Modify the skin texture
return new SkinTextures(original.texture(), original.textureUrl(), CapeManager.CURRENT_PLAYER_CAPE, elytraTexture, original.model(), original.secure());
return new SkinTextures(original.texture(), original.textureUrl(), CapeManager.CURRENT_PLAYER_CAPE == null? original.capeTexture() : CapeManager.CURRENT_PLAYER_CAPE, elytraTexture, original.model(), original.secure());
}

@Inject(method = "getSkinTextures", at = @At("RETURN"), cancellable = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,13 @@ public void onDisable() {
@SubscribeEvent
public void onTicks(TickEvent.PLAYER event) {
TargetUtils.getInstance().setRange(range.value);
LivingEntity entity = (LivingEntity) TargetUtils.getInstance().getNewTargetIfNull(true);
LivingEntity entity = (LivingEntity) TargetUtils.getInstance().getNewTargetIfNull(e-> !isBlackListed(e),true);

if (ignoreTeammate.value && ModuleManager.get(Teams.class).isInMyTeam(entity)) {
return;
}

if (entity != null) {
if (entity != null && entity.distanceTo(mc.player) <= range.value) {
if (mc.player == null || !entity.isAlive()) return;

Vec3d targetPos = entity.getPos();
Expand Down Expand Up @@ -204,7 +204,7 @@ public void onTicks(TickEvent.PLAYER event) {
}

} else {
doStrafe(playerPos, entity, targetPos);
doMotionStrafe(playerPos, entity, targetPos);
}
// jump while strafing
if (jump.value && mc.player.isOnGround()) {
Expand Down Expand Up @@ -235,7 +235,7 @@ public void onSettingChange(Setting<?> setting) {
}
}

public void doStrafe(Vec3d playerPos, Entity entity, Vec3d targetPos) {
public void doMotionStrafe(Vec3d playerPos, Entity entity, Vec3d targetPos) {
double dx = targetPos.x - playerPos.x;
double dz = targetPos.z - playerPos.z;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import dev.heliosclient.hud.HudElement;
import dev.heliosclient.managers.EventManager;
import dev.heliosclient.managers.HudManager;
import dev.heliosclient.module.settings.Setting;
import dev.heliosclient.module.settings.SettingGroup;
import dev.heliosclient.module.sysmodules.ClickGUI;
import dev.heliosclient.ui.clickgui.gui.HudBox;
import dev.heliosclient.ui.clickgui.navbar.NavBar;
Expand All @@ -19,7 +21,9 @@

import java.awt.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class HudEditorScreen extends Screen implements Listener {
public static HudEditorScreen INSTANCE = new HudEditorScreen();
Expand All @@ -29,6 +33,7 @@ public class HudEditorScreen extends Screen implements Listener {
// Variables to track the drag state and initial position
private boolean isDragging = false;
private HudBox dragBox = null;
private final Map<String, Object> copiedSettings = new HashMap<>();


private HudEditorScreen() {
Expand Down Expand Up @@ -221,14 +226,33 @@ public void keyPressed(KeyPressedEvent keyPressedEvent) {

@Override
public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
if (keyCode == GLFW.GLFW_KEY_LEFT_SHIFT) {
for (HudElement element : HudManager.INSTANCE.hudElements) {
boolean copied = false;
for (HudElement element : HudManager.INSTANCE.hudElements) {
if (keyCode == GLFW.GLFW_KEY_LEFT_SHIFT) {
element.shiftDown = true;
}

if (element.selected && isCopy(keyCode) && !copied) {
element.saveSettingsToMap(copiedSettings);
copied = true;
continue;
}

if (element.selected && isPaste(keyCode) && copiedSettings != null && !copiedSettings.isEmpty()) {
for (SettingGroup settingGroup : element.settingGroups) {
for (Setting<?> setting : settingGroup.getSettings()) {
if (!setting.shouldSaveAndLoad()) continue;

setting.loadFromFile(copiedSettings);
}
}
}
}

return super.keyPressed(keyCode, scanCode, modifiers);
}


@Override
public boolean keyReleased(int keyCode, int scanCode, int modifiers) {
if (keyCode == GLFW.GLFW_KEY_LEFT_SHIFT) {
Expand Down

0 comments on commit e04bcf6

Please sign in to comment.