forked from DFOnline/CodeClient
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScanPlot.java
More file actions
182 lines (166 loc) · 6.83 KB
/
Copy pathScanPlot.java
File metadata and controls
182 lines (166 loc) · 6.83 KB
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
package dev.dfonline.codeclient.action.impl;
import dev.dfonline.codeclient.Callback;
import dev.dfonline.codeclient.CodeClient;
import dev.dfonline.codeclient.Utility;
import dev.dfonline.codeclient.action.Action;
import dev.dfonline.codeclient.hypercube.template.Template;
import dev.dfonline.codeclient.location.Dev;
import net.minecraft.item.ItemStack;
import net.minecraft.network.packet.Packet;
import net.minecraft.network.packet.c2s.play.ClientCommandC2SPacket;
import net.minecraft.network.packet.c2s.play.CreativeInventoryActionC2SPacket;
import net.minecraft.network.packet.s2c.play.ScreenHandlerSlotUpdateS2CPacket;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.Vec3d;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.regex.Pattern;
public class ScanPlot extends Action {
private static final Vec3d goToOffset = new Vec3d(0, 1.5, 0);
private final ArrayList<ItemStack> returnList;
private List<BlockPos> blocks = null;
private HashMap<BlockPos, ItemStack> scanned = null;
private Action step = null;
public ScanPlot(Callback callback, ArrayList<ItemStack> scanList) {
super(callback);
this.returnList = scanList;
if (!(CodeClient.location instanceof Dev)) {
throw new IllegalStateException("Player must be in dev mode.");
}
}
@Override
public void init() {
if (CodeClient.location instanceof Dev plot) {
blocks = plot.scanForSigns(Pattern.compile("(PLAYER|ENTITY) EVENT|FUNCTION|PROCESS"), Pattern.compile(".*")).keySet().stream().toList();
scanned = new HashMap<>(blocks.size());
}
}
@Override
public boolean onReceivePacket(Packet<?> packet) {
if (step != null) return step.onReceivePacket(packet);
return false;
// var net = CodeClient.MC.getNetworkHandler();
// if(waitForResponse && net != null && packet instanceof ScreenHandlerSlotUpdateS2CPacket slot) {
// var data = Utility.templateDataItem(slot.getStack());
// var template = Template.parse64(data);
// if(template == null) return false;
// scanList.add(Template.parse64(data));
// waitForResponse = false;
// progress += 1;
// net.sendPacket(new CreativeInventoryActionC2SPacket(slot.getSlot(), ItemStack.EMPTY));
// return true;
// }
}
@Nullable
private BlockPos findNextBlock() {
var player = CodeClient.MC.player.getPos();
BlockPos nearest = null;
for (BlockPos pos : blocks) {
if (nearest == null || pos.isWithinDistance(player, nearest.toCenterPos().distanceTo(player))) {
if (scanned.containsKey(pos) && scanned.get(pos) != null) {
continue;
}
nearest = pos;
}
}
return nearest;
}
private void next() {
var block = findNextBlock();
if (block == null) {
returnList.clear();
returnList.addAll(scanned.values());
callback();
return;
}
step = new GoTo(block.toCenterPos().add(goToOffset), () -> {
this.step = new PickUpBlock(block, () -> {
this.step = null;
// next(progress + 1);
});
this.step.init();
});
step.init();
}
@Override
public void tick() {
if (blocks == null) return;
if (step != null) step.tick();
else {
next();
}
}
private class PickUpBlock extends Action {
private final BlockPos pos;
private Integer ticks = 0;
public PickUpBlock(BlockPos pos, Callback callback) {
super(callback);
this.pos = pos;
}
@Override
public void init() {
var net = CodeClient.MC.getNetworkHandler();
Utility.makeHolding(ItemStack.EMPTY);
var player = CodeClient.MC.player;
var inter = CodeClient.MC.interactionManager;
boolean sneaky = !player.isSneaking();
if (sneaky) net.sendPacket(new ClientCommandC2SPacket(player, ClientCommandC2SPacket.Mode.PRESS_SHIFT_KEY));
inter.interactBlock(player, Hand.MAIN_HAND, new BlockHitResult(this.pos.toCenterPos(), Direction.UP, this.pos, false));
if (sneaky)
net.sendPacket(new ClientCommandC2SPacket(player, ClientCommandC2SPacket.Mode.RELEASE_SHIFT_KEY));
}
@Override
public boolean onReceivePacket(Packet<?> packet) {
var net = CodeClient.MC.getNetworkHandler();
if (net != null && packet instanceof ScreenHandlerSlotUpdateS2CPacket slot) {
var data = Utility.templateDataItem(slot.getStack());
var template = Template.parse64(data);
if (template == null) return false;
scanned.put(pos, slot.getStack());
net.sendPacket(new CreativeInventoryActionC2SPacket(slot.getSlot(), ItemStack.EMPTY));
this.callback();
return true;
}
return super.onReceivePacket(packet);
}
@Override
public void tick() {
ticks += 1;
if (ticks == 10) {
ticks = 0;
init();
}
}
// if(progress == blocks.size()) {
// if(!waitForResponse) {
// callback();
// }
// return;
// }
// var net = CodeClient.MC.getNetworkHandler();
// var player = CodeClient.MC.player;
// var inter = CodeClient.MC.interactionManager;
// if(CodeClient.location instanceof Dev && this.blocks != null && net != null && player != null && inter != null) {
// if(goTo == null || goTo.complete) {
// if(goTo != null && !waitForResponse) {
// var current = blocks.get(progress);
// boolean sneaky = !player.isSneaking();
// if(sneaky) net.sendPacket(new ClientCommandC2SPacket(player, ClientCommandC2SPacket.Mode.PRESS_SHIFT_KEY));
// inter.interactBlock(player, Hand.MAIN_HAND, new BlockHitResult(current.toCenterPos(), Direction.UP, current,false));
// if(sneaky) net.sendPacket(new ClientCommandC2SPacket(player, ClientCommandC2SPacket.Mode.RELEASE_SHIFT_KEY));
// waitForResponse = true;
// goTo = null;
// }
// goTo = new GoTo(blocks.get(progress).toCenterPos().add(goToOffset), () -> {});
// goTo.init();
// }
// goTo.tick();
// }
// }
}
}