Skip to content
This repository was archived by the owner on May 19, 2025. It is now read-only.

Commit b1345b8

Browse files
committed
0.5.0
1 parent 12ffb9c commit b1345b8

File tree

8 files changed

+198
-115
lines changed

8 files changed

+198
-115
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@ My personal RusherHack tweaks plugin
77
- PauseOnUse (AutoWalk/ElytraFly/RotationLock) - Pause modules while using/eating
88
- NightVision (FullBright) - Client Side Effect
99
- Durability101 (Armor HUD) - Durability101 Mod
10-
- RepairPriority (AutoArmor) - Prioritize low durability armor with mending
10+
- RepairPriority (AutoArmor) - Prioritize low durability armor with mending
11+
- GoldenPriority (AutoArmor) - Prioritize one piece of golden armor for piglins
12+
- Priority Binds (AutoArmor) - Key binds for priority setting toggles

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ minecraft_version=1.20.4
77
parchment_version=2024.04.14
88

99
# Plugin Properties
10-
plugin_version=0.4.1
10+
plugin_version=0.5.0
1111
maven_group=com.shaybox.rusher
1212
archives_base_name=shays-rusher-plugin

src/main/java/com/shaybox/rusher/Main.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,25 @@ public class Main extends Plugin {
1111

1212
/* EventBus & Listeners */
1313
private final IEventBus eventBus = RusherHackAPI.getEventBus();
14+
private final EventListener armorPriority = new ArmorPriority();
1415
private final EventListener durability101 = new Durability101();
1516
private final EventListener nightVision = new NightVision();
1617
private final EventListener pauseOnUse = new PauseOnUse();
17-
private final EventListener repairPriority = new RepairPriority();
1818

1919
@Override
2020
public void onLoad() {
21+
eventBus.subscribe(armorPriority);
2122
eventBus.subscribe(durability101);
2223
eventBus.subscribe(nightVision);
2324
eventBus.subscribe(pauseOnUse);
24-
eventBus.subscribe(repairPriority);
2525
}
2626

2727
@Override
2828
public void onUnload() {
29+
eventBus.unsubscribe(armorPriority);
2930
eventBus.unsubscribe(durability101);
3031
eventBus.unsubscribe(nightVision);
3132
eventBus.unsubscribe(pauseOnUse);
32-
eventBus.unsubscribe(repairPriority);
3333
}
3434

3535
}
Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
package com.shaybox.rusher.tweaks;
2+
3+
import net.minecraft.client.Minecraft;
4+
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
5+
import net.minecraft.client.gui.screens.inventory.InventoryScreen;
6+
import net.minecraft.client.player.LocalPlayer;
7+
import net.minecraft.world.entity.EquipmentSlot;
8+
import net.minecraft.world.entity.player.Inventory;
9+
import net.minecraft.world.inventory.Slot;
10+
import net.minecraft.world.item.Equipable;
11+
import net.minecraft.world.item.Item;
12+
import net.minecraft.world.item.ItemStack;
13+
import net.minecraft.world.item.Items;
14+
import net.minecraft.world.item.enchantment.EnchantmentHelper;
15+
import net.minecraft.world.item.enchantment.Enchantments;
16+
import org.rusherhack.client.api.RusherHackAPI;
17+
import org.rusherhack.client.api.events.client.EventUpdate;
18+
import org.rusherhack.client.api.events.player.EventPlayerUpdate;
19+
import org.rusherhack.client.api.feature.module.IModule;
20+
import org.rusherhack.client.api.feature.module.ToggleableModule;
21+
import org.rusherhack.client.api.setting.BindSetting;
22+
import org.rusherhack.client.api.utils.InventoryUtils;
23+
import org.rusherhack.core.bind.key.IKey;
24+
import org.rusherhack.core.bind.key.NullKey;
25+
import org.rusherhack.core.event.listener.EventListener;
26+
import org.rusherhack.core.event.subscribe.Subscribe;
27+
import org.rusherhack.core.feature.IFeatureManager;
28+
import org.rusherhack.core.setting.BooleanSetting;
29+
30+
import java.util.Comparator;
31+
import java.util.List;
32+
import java.util.function.Consumer;
33+
import java.util.function.Supplier;
34+
35+
public class ArmorPriority implements EventListener {
36+
37+
/* Minecraft */
38+
private final Minecraft minecraft = Minecraft.getInstance();
39+
40+
/* RusherHackAPI Managers & Modules */
41+
private final IFeatureManager<IModule> moduleManager = RusherHackAPI.getModuleManager();
42+
private final ToggleableModule autoArmor = (ToggleableModule) moduleManager.getFeature("AutoArmor").orElseThrow();
43+
44+
/* AutoArmor Settings */
45+
private final BooleanSetting soft = (BooleanSetting) autoArmor.getSetting("Soft");
46+
private final BooleanSetting inventory = (BooleanSetting) autoArmor.getSetting("Inventory");
47+
private final BooleanSetting elytraPriority = (BooleanSetting) autoArmor.getSetting("ElytraPriority");
48+
private final BooleanSetting repairPriority = new BooleanSetting("RepairPriority", "Prioritize low durability armor with mending", false);
49+
private final BooleanSetting goldenPriority = new BooleanSetting("GoldenPriority", "Prioritize one piece of golden armor for piglins", false);
50+
private final BindSetting elytraPriorityBind = new BindSetting("Bind", NullKey.INSTANCE);
51+
private final BindSetting repairPriorityBind = new BindSetting("Bind", NullKey.INSTANCE);
52+
private final BindSetting goldenPriorityBind = new BindSetting("Bind", NullKey.INSTANCE);
53+
54+
/* Equipment Slots & Golden Armor Priority */
55+
private final EquipmentSlot[] equipmentSlots = {EquipmentSlot.HEAD, EquipmentSlot.CHEST, EquipmentSlot.LEGS, EquipmentSlot.FEET};
56+
private final List<Item> goldenArmorPriority = List.of(Items.GOLDEN_BOOTS, Items.GOLDEN_HELMET, Items.GOLDEN_LEGGINGS, Items.GOLDEN_CHESTPLATE);
57+
58+
/* Previous State */
59+
private boolean isPaused = false;
60+
private boolean isElytraDown = false;
61+
private boolean isRepairDown = false;
62+
private boolean isGoldenDown = false;
63+
private boolean lastSoft = this.soft.getValue();
64+
65+
/* Initialize */
66+
public ArmorPriority() {
67+
this.elytraPriority.addSubSettings(this.elytraPriorityBind);
68+
this.repairPriority.addSubSettings(this.repairPriorityBind);
69+
this.goldenPriority.addSubSettings(this.goldenPriorityBind);
70+
this.autoArmor.registerSettings(this.repairPriority, this.goldenPriority);
71+
}
72+
73+
@Override
74+
public boolean isListening() {
75+
IKey elytraBind = this.elytraPriorityBind.getValue();
76+
IKey repairBind = this.repairPriorityBind.getValue();
77+
IKey goldenBind = this.goldenPriorityBind.getValue();
78+
79+
return this.isPaused || this.autoArmor.isToggled() && (
80+
(this.repairPriority.getValue() || this.goldenPriority.getValue()) || (
81+
(this.isElytraDown || this.isRepairDown || this.isGoldenDown) || (
82+
(elytraBind.isKeyDown() || repairBind.isKeyDown() || goldenBind.isKeyDown())
83+
)
84+
)
85+
);
86+
}
87+
88+
@Subscribe
89+
@SuppressWarnings("unused")
90+
private void onUpdate(EventUpdate event) {
91+
if (minecraft.screen != null) return;
92+
93+
handleKey(this.elytraPriorityBind::getValue, this.isElytraDown, (value) -> this.isElytraDown = value, this.elytraPriority::getValue, this.elytraPriority::setValue);
94+
handleKey(this.repairPriorityBind::getValue, this.isRepairDown, (value) -> this.isRepairDown = value, this.repairPriority::getValue, this.repairPriority::setValue);
95+
handleKey(this.goldenPriorityBind::getValue, this.isGoldenDown, (value) -> this.isGoldenDown = value, this.goldenPriority::getValue, this.goldenPriority::setValue);
96+
}
97+
98+
private void handleKey(Supplier<IKey> key, boolean isDown, Consumer<Boolean> setIsDown, Supplier<Boolean> getPriority, Consumer<Boolean> setPriority) {
99+
if (key.get().isKeyDown()) {
100+
if (!isDown) {
101+
setIsDown.accept(true);
102+
setPriority.accept(!getPriority.get());
103+
}
104+
} else {
105+
setIsDown.accept(false);
106+
}
107+
}
108+
109+
@Subscribe
110+
@SuppressWarnings("unused")
111+
private void onPlayerUpdate(EventPlayerUpdate event) {
112+
LocalPlayer player = event.getPlayer();
113+
Inventory inventory = player.getInventory();
114+
115+
/* Prevent moving items in other containers */
116+
if (minecraft.screen instanceof InventoryScreen) if (!this.inventory.getValue()) return;
117+
else if (minecraft.screen instanceof AbstractContainerScreen) return;
118+
119+
/* There can only be one enabled at a time */
120+
boolean prioritizeRepair = this.repairPriority.getValue();
121+
boolean prioritizeGolden = this.goldenPriority.getValue();
122+
123+
if (prioritizeRepair || prioritizeGolden) {
124+
if (!isPaused) {
125+
isPaused = true;
126+
this.lastSoft = this.soft.getValue();
127+
}
128+
129+
this.soft.setValue(true);
130+
131+
if (prioritizeRepair) {
132+
this.goldenPriority.setValue(false);
133+
134+
for (EquipmentSlot equipmentSlot : equipmentSlots) {
135+
int armorSlotId = InventoryUtils.getInventorySlot(equipmentSlot);
136+
137+
player.inventoryMenu.slots.stream()
138+
.filter(slot -> slot.getItem().getItem() instanceof Equipable e && e.getEquipmentSlot() == equipmentSlot)
139+
.filter(slot -> EnchantmentHelper.getItemEnchantmentLevel(Enchantments.MENDING, slot.getItem()) > 0)
140+
.min(Comparator.comparingInt(slot -> slot.getItem().getDamageValue()))
141+
.ifPresent(slot -> {
142+
Slot armorSlot = player.inventoryMenu.getSlot(armorSlotId);
143+
ItemStack armorStack = armorSlot.getItem();
144+
ItemStack itemStack = slot.getItem();
145+
146+
int itemDamage = itemStack.getDamageValue();
147+
int armorDamage = armorStack.getDamageValue();
148+
if (itemDamage > armorDamage) swapSlotId(player, slot, armorSlotId);
149+
});
150+
}
151+
}
152+
153+
if (prioritizeGolden) {
154+
this.repairPriority.setValue(false);
155+
156+
for (Item goldArmor : this.goldenArmorPriority)
157+
player.inventoryMenu.slots.stream()
158+
.filter(slot -> slot.getItem().getItem() instanceof Equipable e && e == goldArmor)
159+
.filter(slot -> { /* Only one piece of gold armor */
160+
for (Item item : this.goldenArmorPriority)
161+
if (inventory.armor.stream().map(ItemStack::getItem).toList().contains(item))
162+
return false;
163+
164+
return true;
165+
}).findFirst().ifPresent(slot -> {
166+
Equipable equipable = (Equipable) slot.getItem().getItem();
167+
EquipmentSlot equipmentSlot = equipable.getEquipmentSlot();
168+
int armorSlotId = InventoryUtils.getInventorySlot(equipmentSlot);
169+
this.swapSlotId(player, slot, armorSlotId);
170+
});
171+
}
172+
} else if (isPaused) {
173+
isPaused = false;
174+
this.soft.setValue(this.lastSoft);
175+
}
176+
}
177+
178+
private void swapSlotId(LocalPlayer player, Slot slot, int armorSlotId) {
179+
InventoryUtils.clickSlot(slot.index, false);
180+
InventoryUtils.clickSlot(armorSlotId, false);
181+
InventoryUtils.clickSlot(slot.index, false);
182+
}
183+
184+
}

src/main/java/com/shaybox/rusher/tweaks/Durability101.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public boolean isListening() {
6565

6666
@SuppressWarnings("unused")
6767
@Subscribe(priority = -10000, stage = Stage.ALL)
68-
private void onUpdate(EventRender2D event) {
68+
private void onRender2D(EventRender2D event) {
6969
Stage stage = event.getStage();
7070
if (this.minecraft.screen == this.hudEditorScreen) {
7171
if (stage != Stage.POST) return;
@@ -122,7 +122,7 @@ private void onUpdate(EventRender2D event) {
122122
x += (slot * 38) + textOffset + 16;
123123
y += 18;
124124

125-
boolean isStable203 = this.watermark.getText().startsWith("rusherhack v2.0.3");
125+
boolean isStable203 = this.watermark.getText().endsWith("v2.0.3");
126126
if (isStable203 && this.hotbarLock.getValue() && this.autoAdjust.getValue()) {
127127
if (player.showVehicleHealth() && player.getVehicle() instanceof LivingEntity living) {
128128
if (living.getMaxHealth() > 20) y -= 20;

src/main/java/com/shaybox/rusher/tweaks/NightVision.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import org.rusherhack.core.feature.IFeatureManager;
1313
import org.rusherhack.core.setting.BooleanSetting;
1414

15-
@SuppressWarnings("unused")
1615
public class NightVision implements EventListener {
1716

1817
/* RusherHackAPI Managers & Modules */
@@ -39,7 +38,8 @@ public boolean isListening() {
3938
}
4039

4140
@Subscribe
42-
private void onUpdate(EventPlayerUpdate event) {
41+
@SuppressWarnings("unused")
42+
private void onPlayerUpdate(EventPlayerUpdate event) {
4343
LocalPlayer player = event.getPlayer();
4444
boolean hasNightVision = player.hasEffect(MobEffects.NIGHT_VISION);
4545
boolean isFullBright = this.fullBright.isToggled();

src/main/java/com/shaybox/rusher/tweaks/PauseOnUse.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,11 @@
1010
import org.rusherhack.core.feature.IFeatureManager;
1111
import org.rusherhack.core.setting.BooleanSetting;
1212

13-
@SuppressWarnings("unused")
1413
public class PauseOnUse implements EventListener {
1514

1615
/* RusherHackAPI & Modules */
1716
private final IFeatureManager<IModule> moduleManager = RusherHackAPI.getModuleManager();
18-
private final ToggleableModule autoEat = (ToggleableModule) moduleManager.getFeature("AutoEat").orElseThrow();
17+
// private final ToggleableModule autoEat = (ToggleableModule) moduleManager.getFeature("AutoEat").orElseThrow();
1918
private final ToggleableModule autoWalk = (ToggleableModule) moduleManager.getFeature("AutoWalk").orElseThrow();
2019
private final ToggleableModule elytraFly = (ToggleableModule) moduleManager.getFeature("ElytraFly").orElseThrow();
2120
private final ToggleableModule rotationLock = (ToggleableModule) moduleManager.getFeature("RotationLock").orElseThrow();
@@ -48,7 +47,8 @@ public boolean isListening() {
4847
}
4948

5049
@Subscribe
51-
private void onUpdate(EventPlayerUpdate event) {
50+
@SuppressWarnings("unused")
51+
private void onPlayerUpdate(EventPlayerUpdate event) {
5252
LocalPlayer player = event.getPlayer();
5353

5454
if (player.isUsingItem()) {

src/main/java/com/shaybox/rusher/tweaks/RepairPriority.java

Lines changed: 0 additions & 103 deletions
This file was deleted.

0 commit comments

Comments
 (0)