Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit 02e6f52
Author: RickyTheRacc <[email protected]>
Date:   Thu Aug 8 13:24:42 2024 -0500

    Rewrite Hotbar Manager (#28)

    * Rewriter

    * Remove Unused Utils

    * Add Reset Button

commit bee6d78
Author: RedCarlos <[email protected]>
Date:   Wed Jul 24 00:24:21 2024 -0400

    Update README.md

commit 8f511ad
Author: RedCarlos <[email protected]>
Date:   Wed Jul 24 00:23:59 2024 -0400

    Update README.md

commit 6f1cd1c
Author: RedCarlos26 <[email protected]>
Date:   Wed Jul 24 00:07:12 2024 -0400

    Temporary stuff

commit e484837
Author: RedCarlos26 <[email protected]>
Date:   Mon Jul 22 20:44:23 2024 -0400

    Added HUD text presets

commit 9f3efaa
Author: RedCarlos26 <[email protected]>
Date:   Mon Jul 22 20:34:01 2024 -0400

    Small things

commit 80f6b81
Author: RickyTheRacc <[email protected]>
Date:   Fri Jul 19 23:10:57 2024 -0500

    Merge pull request #27 from RickyTheRacc/code-cleanup

    * Remove Enums Class

    * Change Javadocs to Comments

    * Remove General Comments

    * Move Variables

    * Use PlayerUtils in Center Command

    * Use .noSlider()

    * Optimize ToggleCommandMixin

    * Organize AxisViewer

    * Cleanup HIGUtils

    * Separate Modules into Categories

    * Make AFKLogout Settings Clearer

    * Standardize Event Function Names

commit 9cd7f47
Author: RedCarlos26 <[email protected]>
Date:   Thu Jul 18 14:17:52 2024 -0400

    Update README.md

commit 97299a6
Author: RedCarlos26 <[email protected]>
Date:   Thu Jul 18 13:12:33 2024 -0400

    Render place even if there is an entity

commit bdc33ec
Author: RedCarlos26 <[email protected]>
Date:   Thu Jul 18 13:10:21 2024 -0400

    Update gradle.properties

commit e4036b2
Author: RedCarlos26 <[email protected]>
Date:   Sat Jul 13 21:44:06 2024 -0400

    Added toggle for statistics

commit 07ad243
Author: RedCarlos26 <[email protected]>
Date:   Sat Jul 13 21:43:53 2024 -0400

    Formatting
  • Loading branch information
RedCarlos26 committed Aug 8, 2024
1 parent 54d2011 commit d9923b8
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 228 deletions.
202 changes: 66 additions & 136 deletions src/main/java/me/redcarlos/higtools/modules/main/HotbarManager.java
Original file line number Diff line number Diff line change
@@ -1,174 +1,104 @@
package me.redcarlos.higtools.modules.main;

import me.redcarlos.higtools.HIGTools;
import meteordevelopment.meteorclient.events.render.Render3DEvent;
import meteordevelopment.meteorclient.events.world.TickEvent;
import meteordevelopment.meteorclient.gui.GuiTheme;
import meteordevelopment.meteorclient.gui.widgets.WWidget;
import meteordevelopment.meteorclient.gui.widgets.containers.WTable;
import meteordevelopment.meteorclient.gui.widgets.pressable.WButton;
import meteordevelopment.meteorclient.settings.IntSetting;
import meteordevelopment.meteorclient.settings.Setting;
import meteordevelopment.meteorclient.settings.SettingGroup;
import meteordevelopment.meteorclient.settings.StringSetting;
import meteordevelopment.meteorclient.settings.*;
import meteordevelopment.meteorclient.systems.modules.Module;
import meteordevelopment.meteorclient.utils.render.MeteorToast;
import meteordevelopment.meteorclient.utils.player.FindItemResult;
import meteordevelopment.meteorclient.utils.player.InvUtils;
import meteordevelopment.meteorclient.utils.world.TickRate;
import meteordevelopment.orbit.EventHandler;
import net.minecraft.item.Item;
import net.minecraft.item.Items;
import net.minecraft.registry.Registries;
import net.minecraft.screen.slot.SlotActionType;
import net.minecraft.util.Identifier;
import net.minecraft.util.Util;

import java.util.stream.IntStream;

import static me.redcarlos.higtools.utils.HIGUtils.csToPs;
import java.util.ArrayList;
import java.util.List;

public class HotbarManager extends Module {
private final SettingGroup sgGeneral = settings.getDefaultGroup();
private final SettingGroup slotsGroup = settings.createGroup("Slots", false);

private final Identifier[] itemIds = IntStream.range(0, 9).mapToObj(i -> new Identifier("")).toArray(Identifier[]::new);

private final Setting<String> slot0 = slotsGroup.add(new StringSetting.Builder()
.name("slot0")
.defaultValue("")
.visible(() -> false)
.onChanged(cur -> itemIds[0] = new Identifier(cur))
.build()
);
private final Setting<String> slot1 = slotsGroup.add(new StringSetting.Builder()
.name("slot1")
.defaultValue("")
.visible(() -> false)
.onChanged(cur -> itemIds[1] = new Identifier(cur))
.build()
);
private final Setting<String> slot2 = slotsGroup.add(new StringSetting.Builder()
.name("slot2")
.defaultValue("")
.visible(() -> false)
.onChanged(cur -> itemIds[2] = new Identifier(cur))
.build()
);
private final Setting<String> slot3 = slotsGroup.add(new StringSetting.Builder()
.name("slot3")
.defaultValue("")
.visible(() -> false)
.onChanged(cur -> itemIds[3] = new Identifier(cur))
.build()
);
private final Setting<String> slot4 = slotsGroup.add(new StringSetting.Builder()
.name("slot4")
.defaultValue("")
.visible(() -> false)
.onChanged(cur -> itemIds[4] = new Identifier(cur))
.build()
);
private final Setting<String> slot5 = slotsGroup.add(new StringSetting.Builder()
.name("slot5")
.defaultValue("")
.visible(() -> false)
.onChanged(cur -> itemIds[5] = new Identifier(cur))
.build()
);
private final Setting<String> slot6 = slotsGroup.add(new StringSetting.Builder()
.name("slot6")
.defaultValue("")
.visible(() -> false)
.onChanged(cur -> itemIds[6] = new Identifier(cur))
.build()
);
private final Setting<String> slot7 = slotsGroup.add(new StringSetting.Builder()
.name("slot7")
.defaultValue("")
.visible(() -> false)
.onChanged(cur -> itemIds[7] = new Identifier(cur))
private final Setting<Integer> delay = sgGeneral.add(new IntSetting.Builder()
.name("move-delay")
.description("Delay in ticks between moving items.")
.defaultValue(1)
.range(1, 20)
.sliderRange(1, 20)
.build()
);
private final Setting<String> slot8 = slotsGroup.add(new StringSetting.Builder()
.name("slot8")
.defaultValue("")
.visible(() -> false)
.onChanged(cur -> itemIds[8] = new Identifier(cur))

private final Setting<Boolean> replace = sgGeneral.add(new BoolSetting.Builder()
.name("replace")
.description("Replace items already in your hotbar.")
.defaultValue(true)
.build()
);

private final Setting<Integer> delay = sgGeneral.add(new IntSetting.Builder()
.name("delay")
.description("Delay between moving actions.")
.defaultValue(1)
.range(1, 35)
.sliderRange(1, 35)
private final Setting<Boolean> toggle = sgGeneral.add(new BoolSetting.Builder()
.name("toggle")
.description("Toggle off automatically after one pass through the hotbar.")
.defaultValue(true)
.build()
);

public HotbarManager() {
super(HIGTools.MAIN, "hotbar-manager", "Automatically sort and replenish your hotbar.");
}

@Override
public WWidget getWidget(GuiTheme theme) {
WTable table = theme.table();
fillTable(theme, table);
WButton reset = theme.button("Reset");
reset.action = () -> itemSettings.forEach(Setting::reset);

return table;
return reset;
}

private void fillTable(GuiTheme theme, WTable table) {
WButton save = table.add(theme.button("Save")).expandCellX().right().widget();
save.action = this::save;
private final List<Setting<Item>> itemSettings = new ArrayList<>();
private double ticksLeft;

WButton reset = table.add(theme.button("Reset")).right().widget();
reset.action = this::reset;
}
public HotbarManager() {
super(HIGTools.MAIN, "hotbar-manager", "Automatically move items to your hotbar.");

@EventHandler
public void onRender3D(Render3DEvent event) {
if (mc.player == null || mc.world == null || mc.interactionManager == null) return;
if (mc.player.age % delay.get() != 0) return;

for (int i = 0; i <= 8; i++) {
if (itemIds[i].toString().replace("minecraft:", "").isEmpty()) continue;
if (!Registries.ITEM.getId(mc.player.getInventory().getStack(i).getItem()).equals(itemIds[i])) {
for (int j = 35; j >= 9; j--) {
if (Registries.ITEM.getId(mc.player.getInventory().getStack(j).getItem()).equals(itemIds[i])) {
mc.interactionManager.clickSlot(mc.player.currentScreenHandler.syncId, csToPs(j), 0, SlotActionType.PICKUP, mc.player);
mc.interactionManager.clickSlot(mc.player.currentScreenHandler.syncId, csToPs(i), 0, SlotActionType.PICKUP, mc.player);
mc.interactionManager.clickSlot(mc.player.currentScreenHandler.syncId, csToPs(j), 0, SlotActionType.PICKUP, mc.player);
mc.interactionManager.tick();
break;
}
}
}
final SettingGroup sgHotbar = settings.createGroup("Hotbar");

for (int i = 0; i < 9; i++) {
ItemSetting setting = new ItemSetting.Builder()
.name("slot-" + (i + 1))
.description("The item to store in slot " + (i + 1) + ".")
.defaultValue(Items.AIR)
.build();

itemSettings.add(sgHotbar.add(setting));
}
}

private void reset() {
slot0.set("");
slot1.set("");
slot2.set("");
slot3.set("");
slot4.set("");
slot5.set("");
slot6.set("");
slot7.set("");
slot8.set("");

mc.getToastManager().add(new MeteorToast(Items.ENDER_CHEST, "Hotbar Manager", "Cleared Saved Hotbar", 3000));
@Override
public void onActivate() {
ticksLeft = 0.0;
}

private void save() {
if (mc.player == null) return;
@EventHandler
private void onTick(TickEvent.Post event) {
if ((ticksLeft -= TickRate.INSTANCE.getTickRate() / 20.0) > 0.0) return;
int highestSlot = -1;

for (int i = 0; i < 9; i++) {
if (ticksLeft > 0.0) return;
highestSlot = Math.max(highestSlot, i);

slot0.set(Registries.ITEM.getId(mc.player.getInventory().getStack(0).getItem()).toString());
slot1.set(Registries.ITEM.getId(mc.player.getInventory().getStack(1).getItem()).toString());
slot2.set(Registries.ITEM.getId(mc.player.getInventory().getStack(2).getItem()).toString());
slot3.set(Registries.ITEM.getId(mc.player.getInventory().getStack(3).getItem()).toString());
slot4.set(Registries.ITEM.getId(mc.player.getInventory().getStack(4).getItem()).toString());
slot5.set(Registries.ITEM.getId(mc.player.getInventory().getStack(5).getItem()).toString());
slot6.set(Registries.ITEM.getId(mc.player.getInventory().getStack(6).getItem()).toString());
slot7.set(Registries.ITEM.getId(mc.player.getInventory().getStack(7).getItem()).toString());
slot8.set(Registries.ITEM.getId(mc.player.getInventory().getStack(8).getItem()).toString());
ItemSetting setting = (ItemSetting) itemSettings.get(i);
if (setting.get() == Items.AIR) continue;

Item slotItem = mc.player.getInventory().getStack(i).getItem();
if (slotItem != Items.AIR && !replace.get()) continue;
if (mc.player.getInventory().getStack(i).getItem() == setting.get()) continue;

FindItemResult result = InvUtils.find(stack -> stack.getItem() == setting.get(), i, 35);
if (!result.found()) continue;

InvUtils.move().from(result.slot()).to(i);
ticksLeft = delay.get();
}

mc.getToastManager().add(new MeteorToast(Items.ENDER_CHEST, "Hotbar Manager", "Saved Hotbar", 3000));
if (highestSlot == 8 && toggle.get()) toggle();
}
}
96 changes: 4 additions & 92 deletions src/main/java/me/redcarlos/higtools/utils/HIGUtils.java
Original file line number Diff line number Diff line change
@@ -1,51 +1,15 @@
package me.redcarlos.higtools.utils;

import it.unimi.dsi.fastutil.ints.Int2IntMap;
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
import net.minecraft.util.math.BlockPos;

import java.util.stream.IntStream;

import static meteordevelopment.meteorclient.MeteorClient.mc;
import static meteordevelopment.meteorclient.utils.world.BlockUtils.canPlace;

public class HIGUtils {
private HIGUtils() {}

/**
* Packets
*/
private static final Int2IntMap packetToClient = new Int2IntOpenHashMap();
private static final Int2IntMap clientToPacket = new Int2IntOpenHashMap();

static {
packetToClient.put(5, 39);
clientToPacket.put(39, 5);
packetToClient.put(6, 38);
clientToPacket.put(38, 6);
packetToClient.put(7, 37);
clientToPacket.put(37, 7);
packetToClient.put(8, 36);
clientToPacket.put(36, 8);
packetToClient.put(45, 40);
clientToPacket.put(40, 45);
IntStream.rangeClosed(9, 35).forEach(i -> {
packetToClient.put(i, i);
clientToPacket.put(i, i);
});
IntStream.rangeClosed(0, 8).forEach(i -> {
packetToClient.put(i + 36, i);
clientToPacket.put(i, i + 36);
});
}

public static int csToPs(int clientSlot) {
return clientToPacket.getOrDefault(clientSlot, -1);
}
// Block Pos

/**
* Block pos
*/
public static boolean canPlaceHIG(BlockPos blockPos) {
return canPlace(blockPos, false);
}
Expand Down Expand Up @@ -86,9 +50,8 @@ public static BlockPos right(BlockPos pos, int distance) {
};
}

/**
* Highway Axis
*/
// Highway Axes

public static int getHighway() {
double playerZ = mc.player.getZ();
double playerX = mc.player.getX();
Expand All @@ -109,56 +72,5 @@ public static int getHighway() {
return -1;
}

/**
* Desktop notifications (soon:tm:)
*/

/*
* This section of the file is part of Baritone
* Thanks to the Baritone team for the source code.
* Download Baritone here : https://github.com/cabaletta/baritonefile
*/


/**
* Send a message as a desktop notification
* @param message The message to display in the notification
*
private void logNotification(String message) {
logNotification(message, false);
}
*/
/**
* Send a message as a desktop notification
* @param message The message to display in the notification
* @param error Whether to log as an error
*/
/*
private void logNotification(String message, boolean error) {
if (-1) {
logNotificationDirect(message, error);
}
}
/**
* Send a message as a desktop notification regardless of desktopNotifications
* (should only be used for critically important messages)
* @param message The message to display in the notification
*/
/*
private void logNotificationDirect(String message) {
logNotificationDirect(message, false);
}
/**
* Send a message as a desktop notification regardless of desktopNotifications
* (should only be used for critically important messages)
* @param message The message to display in the notification
* @param error Whether to log as an error
*/
/*
private void logNotificationDirect(String message, boolean error) {
MinecraftClient.getInstance().execute(() -> BaritoneAPI.getSettings().notifier.value.accept(message, error));
}
*/
// TODO: Add toast notifications system (reference Baritone?)
}

0 comments on commit d9923b8

Please sign in to comment.