55import dev .dfonline .codeclient .Utility ;
66import dev .dfonline .codeclient .action .Action ;
77import dev .dfonline .codeclient .hypercube .template .Template ;
8- import dev .dfonline .codeclient .hypercube .template .TemplateBlock ;
98import dev .dfonline .codeclient .location .Dev ;
109import net .minecraft .item .ItemStack ;
1110import net .minecraft .network .packet .Packet ;
1211import net .minecraft .network .packet .c2s .play .ClientCommandC2SPacket ;
1312import net .minecraft .network .packet .c2s .play .CreativeInventoryActionC2SPacket ;
14- import net .minecraft .network .packet .c2s .play .PlayerActionC2SPacket ;
15- import net .minecraft .network .packet .c2s .play .PlayerInteractBlockC2SPacket ;
16- import net .minecraft .network .packet .s2c .play .InventoryS2CPacket ;
1713import net .minecraft .network .packet .s2c .play .ScreenHandlerSlotUpdateS2CPacket ;
1814import net .minecraft .util .Hand ;
1915import net .minecraft .util .hit .BlockHitResult ;
2319
2420import java .util .ArrayList ;
2521import java .util .List ;
22+ import java .util .concurrent .atomic .AtomicInteger ;
2623import java .util .regex .Pattern ;
2724
2825public class ScanPlot extends Action {
2926 private List <BlockPos > blocks = null ;
30- private GoTo goTo = null ;
31- private int progress = 0 ;
32- private static final Vec3d goToOffset = new Vec3d (0 ,1.5 ,0 );
33- private boolean waitForResponse = false ;
27+ private Action step = null ;
28+ private static final Vec3d goToOffset = new Vec3d (0 , 1.5 , 0 );
29+ private Integer progress = 0 ;
3430 private final ArrayList <Template > scanList ;
3531
3632 public ScanPlot (Callback callback , ArrayList <Template > scanList ) {
@@ -43,53 +39,108 @@ public ScanPlot(Callback callback, ArrayList<Template> scanList) {
4339
4440 @ Override
4541 public void init () {
46- if (CodeClient .location instanceof Dev plot ) {
47- blocks = plot .scanForSigns (Pattern .compile ("(PLAYER|ENTITY) EVENT|FUNCTION|PROCESS" ),Pattern .compile (".*" )).keySet ().stream ().toList ();
42+ if (CodeClient .location instanceof Dev plot ) {
43+ blocks = plot .scanForSigns (Pattern .compile ("(PLAYER|ENTITY) EVENT|FUNCTION|PROCESS" ), Pattern .compile (".*" )).keySet ().stream ().toList ();
4844 }
4945 }
5046
5147 @ Override
5248 public boolean onReceivePacket (Packet <?> packet ) {
53- var net = CodeClient .MC .getNetworkHandler ();
54- if (waitForResponse && net != null && packet instanceof ScreenHandlerSlotUpdateS2CPacket slot ) {
55- var data = Utility .templateDataItem (slot .getStack ());
56- var template = Template .parse64 (data );
57- if (template == null ) return false ;
58- scanList .add (Template .parse64 (data ));
59- waitForResponse = false ;
60- progress += 1 ;
61- net .sendPacket (new CreativeInventoryActionC2SPacket (slot .getSlot (), ItemStack .EMPTY ));
62- return true ;
63- }
49+ if (step != null ) return step .onReceivePacket (packet );
6450 return false ;
51+ // var net = CodeClient.MC.getNetworkHandler();
52+ // if(waitForResponse && net != null && packet instanceof ScreenHandlerSlotUpdateS2CPacket slot) {
53+ // var data = Utility.templateDataItem(slot.getStack());
54+ // var template = Template.parse64(data);
55+ // if(template == null) return false;
56+ // scanList.add(Template.parse64(data));
57+ // waitForResponse = false;
58+ // progress += 1;
59+ // net.sendPacket(new CreativeInventoryActionC2SPacket(slot.getSlot(), ItemStack.EMPTY));
60+ // return true;
61+ // }
6562 }
6663
6764 @ Override
6865 public void onTick () {
69- if (progress == blocks .size ()) {
70- if (!waitForResponse ) {
66+ if (step != null ) step .onTick ();
67+ else {
68+ if (progress >= blocks .size ()) {
7169 callback ();
70+ return ;
7271 }
73- return ;
72+ step = new GoTo (blocks .get (progress ).toCenterPos ().add (goToOffset ), () -> {
73+ this .step = new pickUpBlock (blocks .get (progress ),() -> {
74+ CodeClient .LOGGER .info ("picked up block" );
75+ step = null ;
76+ progress +=1 ;
77+ });
78+ this .step .init ();
79+ });
80+ step .init ();
7481 }
75- var net = CodeClient .MC .getNetworkHandler ();
76- var player = CodeClient .MC .player ;
77- var inter = CodeClient .MC .interactionManager ;
78- if (CodeClient .location instanceof Dev && this .blocks != null && net != null && player != null && inter != null ) {
79- if (goTo == null || goTo .complete ) {
80- if (goTo != null && !waitForResponse ) {
81- var current = blocks .get (progress );
82- boolean sneaky = !player .isSneaking ();
83- if (sneaky ) net .sendPacket (new ClientCommandC2SPacket (player , ClientCommandC2SPacket .Mode .PRESS_SHIFT_KEY ));
84- inter .interactBlock (player , Hand .MAIN_HAND , new BlockHitResult (current .toCenterPos (), Direction .UP , current ,false ));
85- if (sneaky ) net .sendPacket (new ClientCommandC2SPacket (player , ClientCommandC2SPacket .Mode .RELEASE_SHIFT_KEY ));
86- waitForResponse = true ;
87- goTo = null ;
88- }
89- goTo = new GoTo (blocks .get (progress ).toCenterPos ().add (goToOffset ), () -> {});
90- goTo .init ();
82+ }
83+
84+
85+ private class pickUpBlock extends Action {
86+ private BlockPos pos ;
87+
88+ public pickUpBlock (BlockPos pos , Callback callback ) {
89+ super (callback );
90+ this .pos = pos ;
91+ }
92+
93+ @ Override
94+ public void init () {
95+ var net = CodeClient .MC .getNetworkHandler ();
96+ var player = CodeClient .MC .player ;
97+ var inter = CodeClient .MC .interactionManager ;
98+ boolean sneaky = !player .isSneaking ();
99+ if (sneaky ) net .sendPacket (new ClientCommandC2SPacket (player , ClientCommandC2SPacket .Mode .PRESS_SHIFT_KEY ));
100+ inter .interactBlock (player , Hand .MAIN_HAND , new BlockHitResult (this .pos .toCenterPos (), Direction .UP , this .pos , false ));
101+ if (sneaky )
102+ net .sendPacket (new ClientCommandC2SPacket (player , ClientCommandC2SPacket .Mode .RELEASE_SHIFT_KEY ));
103+ }
104+
105+ @ Override
106+ public boolean onReceivePacket (Packet <?> packet ) {
107+ var net = CodeClient .MC .getNetworkHandler ();
108+ if (net != null && packet instanceof ScreenHandlerSlotUpdateS2CPacket slot ) {
109+ var data = Utility .templateDataItem (slot .getStack ());
110+ var template = Template .parse64 (data );
111+ if (template == null ) return false ;
112+ scanList .add (Template .parse64 (data ));
113+ net .sendPacket (new CreativeInventoryActionC2SPacket (slot .getSlot (), ItemStack .EMPTY ));
114+ this .callback ();
115+ return true ;
91116 }
92- goTo . onTick ( );
117+ return super . onReceivePacket ( packet );
93118 }
119+ // if(progress == blocks.size()) {
120+ // if(!waitForResponse) {
121+ // callback();
122+ // }
123+ // return;
124+ // }
125+ // var net = CodeClient.MC.getNetworkHandler();
126+ // var player = CodeClient.MC.player;
127+ // var inter = CodeClient.MC.interactionManager;
128+ // if(CodeClient.location instanceof Dev && this.blocks != null && net != null && player != null && inter != null) {
129+ // if(goTo == null || goTo.complete) {
130+ // if(goTo != null && !waitForResponse) {
131+ // var current = blocks.get(progress);
132+ // boolean sneaky = !player.isSneaking();
133+ // if(sneaky) net.sendPacket(new ClientCommandC2SPacket(player, ClientCommandC2SPacket.Mode.PRESS_SHIFT_KEY));
134+ // inter.interactBlock(player, Hand.MAIN_HAND, new BlockHitResult(current.toCenterPos(), Direction.UP, current,false));
135+ // if(sneaky) net.sendPacket(new ClientCommandC2SPacket(player, ClientCommandC2SPacket.Mode.RELEASE_SHIFT_KEY));
136+ // waitForResponse = true;
137+ // goTo = null;
138+ // }
139+ // goTo = new GoTo(blocks.get(progress).toCenterPos().add(goToOffset), () -> {});
140+ // goTo.init();
141+ // }
142+ // goTo.onTick();
143+ // }
144+ // }
94145 }
95146}
0 commit comments