88import meteordevelopment .meteorclient .events .packets .PacketEvent ;
99import meteordevelopment .meteorclient .events .render .Render3DEvent ;
1010import meteordevelopment .meteorclient .events .world .TickEvent ;
11+ import meteordevelopment .meteorclient .mixin .DirectionAccessor ;
1112import meteordevelopment .meteorclient .mixin .WorldRendererAccessor ;
1213import meteordevelopment .meteorclient .renderer .ShapeMode ;
1314import meteordevelopment .meteorclient .settings .*;
2122import meteordevelopment .meteorclient .utils .render .color .Color ;
2223import meteordevelopment .meteorclient .utils .render .color .SettingColor ;
2324import meteordevelopment .meteorclient .utils .world .BlockUtils ;
24- import meteordevelopment .meteorclient .utils .world .CardinalDirection ;
2525import meteordevelopment .meteorclient .utils .world .Dir ;
2626import meteordevelopment .orbit .EventHandler ;
2727import net .minecraft .block .Block ;
3434import net .minecraft .network .packet .c2s .play .PlayerInteractEntityC2SPacket ;
3535import net .minecraft .network .packet .s2c .play .DeathMessageS2CPacket ;
3636import net .minecraft .util .Hand ;
37+ import net .minecraft .util .math .Direction ;
3738import net .minecraft .util .math .BlockPos ;
3839import net .minecraft .util .math .Box ;
3940
@@ -64,6 +65,14 @@ public class Surround extends Module {
6465 .build ()
6566 );
6667
68+ private final Setting <Integer > blocksPerTick = sgGeneral .add (new IntSetting .Builder ()
69+ .name ("blocks-per-tick" )
70+ .description ("How many blocks to place in one tick." )
71+ .defaultValue (1 )
72+ .min (1 )
73+ .build ()
74+ );
75+
6776 private final Setting <Center > center = sgGeneral .add (new EnumSetting .Builder <Center >()
6877 .name ("center" )
6978 .description ("Teleports you to the center of the block." )
@@ -85,6 +94,13 @@ public class Surround extends Module {
8594 .build ()
8695 );
8796
97+ private final Setting <Boolean > airPlace = sgGeneral .add (new BoolSetting .Builder ()
98+ .name ("air-place" )
99+ .description ("Allows Surround to place blocks in the air." )
100+ .defaultValue (true )
101+ .build ()
102+ );
103+
88104 private final Setting <Boolean > toggleModules = sgGeneral .add (new BoolSetting .Builder ()
89105 .name ("toggle-modules" )
90106 .description ("Turn off other modules when surround is activated." )
@@ -222,11 +238,8 @@ public class Surround extends Module {
222238 .build ()
223239 );
224240
225- private final BlockPos .Mutable placePos = new BlockPos .Mutable ();
226- private final BlockPos .Mutable renderPos = new BlockPos .Mutable ();
227- private final BlockPos .Mutable testPos = new BlockPos .Mutable ();
228241 public ArrayList <Module > toActivate = new ArrayList <>();
229- private int ticks ;
242+ private int timer ;
230243
231244 public Surround () {
232245 super (Categories .Combat , "surround" , "Surrounds you in blocks to prevent massive crystal damage." );
@@ -238,24 +251,23 @@ public Surround() {
238251 private void onRender3D (Render3DEvent event ) {
239252 if (!render .get ()) return ;
240253
254+ BlockPos playerPos = mc .player .getBlockPos ();
255+
241256 // Below
242- if (renderBelow .get ()) draw (event , null , - 1 , 0 );
257+ if (renderBelow .get ()) draw (playerPos . down (), event , 0 );
243258
244- // Regular surround positions
245- for (CardinalDirection direction : CardinalDirection .values ()) {
246- draw (event , direction , 0 , doubleHeight .get () ? Dir .UP : 0 );
247- }
259+ for (Direction direction : DirectionAccessor .meteor$getHorizontal ()) {
260+ BlockPos renderPos = playerPos .offset (direction );
248261
249- // Double height
250- if ( doubleHeight .get ()) {
251- for ( CardinalDirection direction : CardinalDirection . values ()) {
252- draw ( event , direction , 1 , Dir . DOWN );
253- }
262+ // Regular surround positions
263+ draw ( renderPos , event , doubleHeight .get () ? Dir . UP : 0 );
264+
265+ // Double height
266+ if ( doubleHeight . get ()) draw ( renderPos . up (), event , Dir . DOWN );
254267 }
255268 }
256269
257- private void draw (Render3DEvent event , CardinalDirection direction , int y , int exclude ) {
258- renderPos .set (offsetPosFromPlayer (direction , y ));
270+ private void draw (BlockPos renderPos , Render3DEvent event , int exclude ) {
259271 Color sideColor = getSideColor (renderPos );
260272 Color lineColor = getLineColor (renderPos );
261273 event .renderer .box (renderPos , sideColor , lineColor , shapeMode .get (), exclude );
@@ -269,7 +281,7 @@ public void onActivate() {
269281 if (center .get () == Center .OnActivate ) PlayerUtils .centerPlayer ();
270282
271283 // Reset delay
272- ticks = 0 ;
284+ timer = delay . get () ;
273285
274286 if (toggleModules .get () && !modules .get ().isEmpty () && mc .world != null && mc .player != null ) {
275287 for (Module module : modules .get ()) {
@@ -294,14 +306,8 @@ public void onDeactivate() {
294306
295307 @ EventHandler
296308 private void onTick (TickEvent .Pre event ) {
297- // Tick the placement timer, should always happen
298- if (ticks > 0 ) {
299- ticks --;
300- return ;
301- }
302- else {
303- ticks = delay .get ();
304- }
309+ // Delay
310+ if (timer ++ < delay .get ()) return ;
305311
306312 // Toggle if Y level changed
307313 if (toggleOnYChange .get () && mc .player .lastY != mc .player .getY ()) {
@@ -313,29 +319,44 @@ private void onTick(TickEvent.Pre event) {
313319 if (onlyOnGround .get () && !mc .player .isOnGround ()) return ;
314320
315321 // Wait until the player has a block available to place
316- if (!getInvBlock ().found ()) return ;
322+ FindItemResult block = InvUtils .findInHotbar (itemStack -> blocks .get ().contains (Block .getBlockFromItem (itemStack .getItem ())));
323+ if (!block .found ()) return ;
317324
318325 // Centering player
319326 if (center .get () == Center .Always ) PlayerUtils .centerPlayer ();
320327
321- // Check surround blocks in order and place the first missing one if present
322- int safe = 0 ;
328+ int placedCount = 0 ;
329+ boolean complete = true ;
330+
331+ BlockPos playerPos = mc .player .getBlockPos ();
323332
324- // Looping through feet blocks
325- for (CardinalDirection direction : CardinalDirection .values ()) {
326- if (place (direction , 0 )) break ;
327- safe ++;
333+ // Placing feet blocks
334+ for (Direction direction : DirectionAccessor .meteor$getHorizontal ()) {
335+ BlockPos placePos = playerPos .offset (direction );
336+
337+ // Place support blocks if air place is disabled
338+ if (!airPlace .get () && isAirPlace (placePos ) && mc .world .getBlockState (placePos ).isReplaceable ()){
339+ if (place (placePos .down (), block ) && ++placedCount >= blocksPerTick .get ()) break ;
340+
341+ if (mc .world .getBlockState (placePos .down ()).isReplaceable ()) complete = false ;
342+ }
343+
344+ if (place (placePos , block ) && ++placedCount >= blocksPerTick .get ()) break ;
345+
346+ if (mc .world .getBlockState (placePos ).isReplaceable ()) complete = false ;
328347 }
329348
330- // Looping through head blocks
331- if (doubleHeight .get () && safe == 4 ) {
332- for (CardinalDirection direction : CardinalDirection .values ()) {
333- if (place (direction , 1 )) break ;
334- safe ++;
349+ // Placing head blocks
350+ if (doubleHeight .get () && complete ) {
351+ for (Direction direction : DirectionAccessor .meteor$getHorizontal ()) {
352+ BlockPos placePos = playerPos .offset (direction ).up ();
353+ if (place (placePos , block ) && ++placedCount >= blocksPerTick .get ()) break ;
354+
355+ if (mc .world .getBlockState (placePos ).isReplaceable ()) complete = false ;
335356 }
336357 }
337358
338- boolean complete = safe == ( doubleHeight . get () ? 8 : 4 ) ;
359+ timer = 0 ;
339360
340361 // Disable if all the surround blocks are placed
341362 if (complete && toggleOnComplete .get ()) {
@@ -347,18 +368,9 @@ private void onTick(TickEvent.Pre event) {
347368 if (!complete && center .get () == Center .Incomplete ) PlayerUtils .centerPlayer ();
348369 }
349370
350- private boolean place (CardinalDirection direction , int y ) {
351- placePos .set (offsetPosFromPlayer (direction , y ));
352-
371+ private boolean place (BlockPos placePos , FindItemResult block ) {
353372 // Attempt to place
354- boolean placed = BlockUtils .place (
355- placePos ,
356- getInvBlock (),
357- rotate .get (),
358- 100 ,
359- swing .get (),
360- true
361- );
373+ boolean placed = BlockUtils .place (placePos , block , rotate .get (), 100 , swing .get (), true );
362374
363375 // Check if the block is being mined
364376 boolean beingMined = false ;
@@ -408,26 +420,6 @@ private void onPacketReceive(PacketEvent.Receive event) {
408420 }
409421 }
410422
411- private BlockPos .Mutable offsetPosFromPlayer (CardinalDirection direction , int y ) {
412- return offsetPos (mc .player .getBlockPos (), direction , y );
413- }
414-
415- private BlockPos .Mutable offsetPos (BlockPos origin , CardinalDirection direction , int y ) {
416- if (direction == null ) {
417- return testPos .set (
418- origin .getX (),
419- origin .getY () + y ,
420- origin .getZ ()
421- );
422- }
423-
424- return testPos .set (
425- origin .getX () + direction .toDirection ().getOffsetX (),
426- origin .getY () + y ,
427- origin .getZ () + direction .toDirection ().getOffsetZ ()
428- );
429- }
430-
431423 private BlockType getBlockType (BlockPos pos ) {
432424 BlockState blockState = mc .world .getBlockState (pos );
433425
@@ -455,16 +447,15 @@ private Color getLineColor(BlockPos pos) {
455447 };
456448 }
457449
458- private FindItemResult getInvBlock () {
459- return InvUtils .findInHotbar (itemStack -> blocks .get ().contains (Block .getBlockFromItem (itemStack .getItem ())));
450+ private boolean isAirPlace (BlockPos blockPos ) {
451+ for (Direction direction : Direction .values ()) {
452+ if (!mc .world .getBlockState (blockPos .offset (direction )).isReplaceable ()) return false ;
453+ }
454+ return true ;
460455 }
461456
462457 private boolean blockFilter (Block block ) {
463- return block == Blocks .OBSIDIAN ||
464- block == Blocks .CRYING_OBSIDIAN ||
465- block == Blocks .NETHERITE_BLOCK ||
466- block == Blocks .ENDER_CHEST ||
467- block == Blocks .RESPAWN_ANCHOR ;
458+ return block .getBlastResistance () >= 600 && block .getHardness () >= 0 && block != Blocks .REINFORCED_DEEPSLATE ;
468459 }
469460
470461 public enum Center {
0 commit comments