Skip to content

Commit 09b021e

Browse files
Improvement for AutoSmelter (#6359)
- Add setting for fuel items amount and screen auto-close
1 parent d64d735 commit 09b021e

1 file changed

Lines changed: 48 additions & 1 deletion

File tree

  • src/main/java/meteordevelopment/meteorclient/systems/modules/world

src/main/java/meteordevelopment/meteorclient/systems/modules/world/AutoSmelter.java

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import meteordevelopment.meteorclient.mixininterface.IAbstractFurnaceMenu;
99
import meteordevelopment.meteorclient.settings.BoolSetting;
10+
import meteordevelopment.meteorclient.settings.IntSetting;
1011
import meteordevelopment.meteorclient.settings.ItemListSetting;
1112
import meteordevelopment.meteorclient.settings.Setting;
1213
import meteordevelopment.meteorclient.settings.SettingGroup;
@@ -15,6 +16,7 @@
1516
import meteordevelopment.meteorclient.utils.Utils;
1617
import meteordevelopment.meteorclient.utils.player.InvUtils;
1718
import net.minecraft.world.inventory.AbstractFurnaceMenu;
19+
import net.minecraft.world.inventory.ContainerInput;
1820
import net.minecraft.world.item.Item;
1921
import net.minecraft.world.item.ItemStack;
2022
import net.minecraft.world.item.Items;
@@ -34,6 +36,15 @@ public class AutoSmelter extends Module {
3436
.build()
3537
);
3638

39+
private final Setting<Integer> fuelItemsPerRefill = sgGeneral.add(new IntSetting.Builder()
40+
.name("fuel-items-per-refill")
41+
.description("How many fuel items to put into the furnace each time it refills")
42+
.defaultValue(64)
43+
.range(1, 64)
44+
.sliderRange(1, 16)
45+
.build()
46+
);
47+
3748
private final Setting<List<Item>> smeltableItems = sgGeneral.add(new ItemListSetting.Builder()
3849
.name("smeltable-items")
3950
.description("Items to smelt")
@@ -50,6 +61,12 @@ public class AutoSmelter extends Module {
5061
.build()
5162
);
5263

64+
private final Setting<Boolean> autoClose = sgGeneral.add(new BoolSetting.Builder()
65+
.name("auto-close")
66+
.defaultValue(false)
67+
.build()
68+
);
69+
5370
public AutoSmelter() {
5471
super(Categories.World, "auto-smelter", "Automatically smelts items from your inventory");
5572
}
@@ -76,6 +93,8 @@ public void tick(AbstractFurnaceMenu c) {
7693

7794
// Insert new items
7895
insertItems(c);
96+
97+
if (autoClose.get()) mc.setScreen(null);
7998
}
8099

81100
private void insertItems(AbstractFurnaceMenu c) {
@@ -100,7 +119,10 @@ private void insertItems(AbstractFurnaceMenu c) {
100119
return;
101120
}
102121

122+
if (slot == -1) return;
123+
103124
InvUtils.move().fromId(slot).toId(0);
125+
c.slots.getFirst().getItem().isEmpty();
104126
}
105127

106128
private void checkFuel(AbstractFurnaceMenu c) {
@@ -125,7 +147,32 @@ private void checkFuel(AbstractFurnaceMenu c) {
125147
return;
126148
}
127149

128-
InvUtils.move().fromId(slot).toId(1);
150+
if (slot == -1) return;
151+
152+
ItemStack sourceStack = c.slots.get(slot).getItem();
153+
int moveCount = Math.min(fuelItemsPerRefill.get(), Math.min(sourceStack.getCount(), c.slots.get(1).getMaxStackSize(sourceStack)));
154+
155+
if (moveCount <= 0) return;
156+
157+
moveFuelItems(c, slot, moveCount);
158+
}
159+
160+
private void moveFuelItems(AbstractFurnaceMenu c, int fromId, int amount) {
161+
if (amount <= 0 || mc.player == null || mc.gameMode == null) return;
162+
if (!mc.player.containerMenu.getCarried().isEmpty()) return;
163+
164+
mc.gameMode.handleContainerInput(c.containerId, fromId, 0, ContainerInput.PICKUP, mc.player);
165+
166+
for (int i = 0; i < amount; i++) {
167+
if (mc.player.containerMenu.getCarried().isEmpty()) break;
168+
mc.gameMode.handleContainerInput(c.containerId, 1, 1, ContainerInput.PICKUP, mc.player);
169+
}
170+
171+
if (!mc.player.containerMenu.getCarried().isEmpty()) {
172+
mc.gameMode.handleContainerInput(c.containerId, fromId, 0, ContainerInput.PICKUP, mc.player);
173+
}
174+
175+
c.slots.get(1).getItem().isEmpty();
129176
}
130177

131178
private void takeResults(AbstractFurnaceMenu c) {

0 commit comments

Comments
 (0)