add Replenish module

Ported from Sydney-Legacy ReplenishModule:
- Switch modes Pickup (3-click), Swap and Quick (quick-move)
- Threshold / MinimumCount settings scaled by stack max size
- skipped while inventory, creative, container or shulker screens are open
- refill paced by ServerManager.getPingDelay()
This commit is contained in:
froslanz
2026-10-30 15:38:37 -04:00
parent 0a8957b477
commit b9a80b6347
2 changed files with 76 additions and 0 deletions
@@ -0,0 +1,74 @@
package cc.fros.features.modules.player;
import cc.fros.Fros;
import cc.fros.features.modules.Module;
import cc.fros.features.settings.Setting;
import cc.fros.util.inventory.InventoryUtil;
import cc.fros.util.inventory.Result;
import cc.fros.util.inventory.ResultType;
import net.minecraft.client.gui.screens.inventory.CreativeModeInventoryScreen;
import net.minecraft.client.gui.screens.inventory.InventoryScreen;
import net.minecraft.client.gui.screens.inventory.ContainerScreen;
import net.minecraft.client.gui.screens.inventory.ShulkerBoxScreen;
import net.minecraft.world.inventory.ClickType;
import net.minecraft.world.item.ItemStack;
import java.util.EnumSet;
/**
* Replenish — refills hotbar stacks from storage once they drop to (or below) a threshold.
* Ported from Sydney's {@code ReplenishModule}.
*/
public class ReplenishModule extends Module {
private final Setting<Switch> switchMode = mode("Switch", Switch.Swap);
private final Setting<Integer> threshold = num("Threshold", 12, 1, 64);
private final Setting<Integer> minimumCount = num("MinimumCount", 48, 1, 64);
private int ticks;
public ReplenishModule() {
super("Replenish", "Automatically replenishes stacks in your hotbar with new ones when they meet a specified threshold.", Category.PLAYER);
}
@Override
public void onTick() {
if (nullCheck()) return;
if (mc.screen instanceof InventoryScreen || mc.screen instanceof CreativeModeInventoryScreen
|| mc.screen instanceof ContainerScreen || mc.screen instanceof ShulkerBoxScreen) return;
if (ticks <= 0) {
for (int i = 0; i <= 8; i++) {
ItemStack stack = mc.player.getInventory().getItem(i);
if (!stack.isStackable() || stack.isEmpty()) continue;
if (stack.getCount() > (int) ((threshold.getValue() / 64.0f) * stack.getMaxStackSize())) continue;
int min = (int) ((minimumCount.getValue() / 64.0f) * stack.getMaxStackSize());
Result refill = InventoryUtil.find(s -> s.is(stack.getItem()) && s.getCount() >= min,
EnumSet.of(ResultType.INVENTORY));
if (!refill.found()) continue;
// storage indices 9-35 double as their container-menu slot ids
switch (switchMode.getValue()) {
case Quick -> InventoryUtil.click(refill.slot(), 0, ClickType.QUICK_MOVE);
case Pickup -> {
InventoryUtil.click(refill.slot(), 0, ClickType.PICKUP);
InventoryUtil.click(36 + i, 0, ClickType.PICKUP);
InventoryUtil.click(refill.slot(), 0, ClickType.PICKUP);
}
case Swap -> InventoryUtil.click(refill.slot(), i, ClickType.SWAP);
}
ticks = 2 + Fros.serverManager.getPingDelay();
}
}
ticks--;
}
@Override
public String getDisplayInfo() {
return String.valueOf(threshold.getValue());
}
private enum Switch {
Pickup, Swap, Quick
}
}
@@ -46,6 +46,7 @@ import cc.fros.features.modules.movement.FastAccelModule;
import cc.fros.features.modules.movement.ReverseStepModule;
import cc.fros.features.modules.movement.StepModule;
import cc.fros.features.modules.player.ExpThrowerModule;
import cc.fros.features.modules.player.ReplenishModule;
import cc.fros.features.modules.player.FastPlaceModule;
import cc.fros.features.modules.player.NoFallModule;
import cc.fros.features.modules.player.VelocityModule;
@@ -111,6 +112,7 @@ public class ModuleManager implements Jsonable, Util {
register(new SurroundModule());
register(new AutoTotemModule());
register(new ExpThrowerModule());
register(new ReplenishModule());
register(new FastAccelModule());
LOGGER.info("Registered {} modules", modules.size());