blob: 2e26594678d189e7018ca29c35245a5f1b64a7b5 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
package ftbsc.bscv.modules.self;
import java.util.List;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.IntegerArgumentType;
import ftbsc.bscv.ICommons;
import ftbsc.bscv.modules.Module;
import ftbsc.bscv.tools.Inventory;
import net.minecraft.block.BlockState;
import net.minecraft.command.CommandSource;
import net.minecraft.inventory.container.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraftforge.client.event.InputEvent;
import net.minecraftforge.common.ForgeConfigSpec;
import net.minecraftforge.eventbus.api.SubscribeEvent;
public class AutoTool extends Module implements ICommons {
public final ForgeConfigSpec.ConfigValue<Integer> limit;
public AutoTool(ForgeConfigSpec.Builder builder, CommandDispatcher<CommandSource> dispatcher) {
super("AutoTool", Group.SELF, builder, dispatcher);
this.limit = this.option(
"limit", "durability limit for tools, set to 0 to destroy them", 1,
IntegerArgumentType.integer(0), Integer.class,
builder, dispatcher
);
}
private boolean itemIsTooDamaged(ItemStack item) {
return this.limit.get() > 0
&& item.getMaxDamage() > 0
&& item.getMaxDamage() - item.getDamageValue() <= this.limit.get();
}
@SubscribeEvent
public void onClick(InputEvent.ClickInputEvent event) {
if (MC.player == null) return;
// TODO this is fired many times consecutively, can we filter out
// some without putting a dumb time cooldown?;
if (event.isAttack()) {
List<Slot> hotbar = Inventory.hotbar(MC.player);
int current_slot = MC.player.inventory.selected;
switch (MC.hitResult.getType()) {
case BLOCK:
BlockRayTraceResult result = (BlockRayTraceResult) MC.hitResult;
BlockState state = MC.level.getBlockState(result.getBlockPos());
float current_speed = 0.f;
for (int i = 0; i < Inventory.HOTBAR_SIZE; i++) {
ItemStack item = hotbar.get(i).getItem();
if (this.itemIsTooDamaged(item)) {
continue;
}
float speed = item.getDestroySpeed(state);
if (speed > current_speed) {
current_slot = i;
current_speed = speed;
}
}
MC.player.inventory.selected = current_slot;
break;
case ENTITY:
double current_damage = 0.f;
for (int i = 0; i < Inventory.HOTBAR_SIZE; i++) {
ItemStack item = hotbar.get(i).getItem();
if (this.itemIsTooDamaged(item)) {
continue;
}
double damage = Inventory.itemDamage(item);
if (damage > current_damage) {
current_slot = i;
current_damage = damage;
}
}
MC.player.inventory.selected = current_slot;
break;
case MISS:
break;
}
}
}
}
|