Skip to content

Surround improvements #5459

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import meteordevelopment.meteorclient.utils.render.color.Color;
import meteordevelopment.meteorclient.utils.render.color.SettingColor;
import meteordevelopment.meteorclient.utils.world.BlockUtils;
import meteordevelopment.meteorclient.utils.world.CardinalDirection;
import meteordevelopment.meteorclient.utils.world.Dir;
import meteordevelopment.orbit.EventHandler;
import net.minecraft.block.Block;
Expand All @@ -34,6 +33,7 @@
import net.minecraft.network.packet.c2s.play.PlayerInteractEntityC2SPacket;
import net.minecraft.network.packet.s2c.play.DeathMessageS2CPacket;
import net.minecraft.util.Hand;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Box;

Expand Down Expand Up @@ -64,6 +64,14 @@ public class Surround extends Module {
.build()
);

private final Setting<Integer> blocksPerTick = sgGeneral.add(new IntSetting.Builder()
.name("blocks-per-tick")
.description("How many blocks to place in one tick.")
.defaultValue(1)
.min(1)
.build()
);

private final Setting<Center> center = sgGeneral.add(new EnumSetting.Builder<Center>()
.name("center")
.description("Teleports you to the center of the block.")
Expand All @@ -85,6 +93,13 @@ public class Surround extends Module {
.build()
);

private final Setting<Boolean> airPlace = sgGeneral.add(new BoolSetting.Builder()
.name("air-place")
.description("Allows Surround to place blocks in the air.")
.defaultValue(true)
.build()
);

private final Setting<Boolean> toggleModules = sgGeneral.add(new BoolSetting.Builder()
.name("toggle-modules")
.description("Turn off other modules when surround is activated.")
Expand Down Expand Up @@ -222,11 +237,8 @@ public class Surround extends Module {
.build()
);

private final BlockPos.Mutable placePos = new BlockPos.Mutable();
private final BlockPos.Mutable renderPos = new BlockPos.Mutable();
private final BlockPos.Mutable testPos = new BlockPos.Mutable();
public ArrayList<Module> toActivate = new ArrayList<>();
private int ticks;
private int timer;

public Surround() {
super(Categories.Combat, "surround", "Surrounds you in blocks to prevent massive crystal damage.");
Expand All @@ -238,24 +250,23 @@ public Surround() {
private void onRender3D(Render3DEvent event) {
if (!render.get()) return;

BlockPos playerPos = mc.player.getBlockPos();

// Below
if (renderBelow.get()) draw(event, null, -1, 0);
if (renderBelow.get()) draw(playerPos.down(), event, 0);

// Regular surround positions
for (CardinalDirection direction : CardinalDirection.values()) {
draw(event, direction, 0, doubleHeight.get() ? Dir.UP : 0);
}
for (Direction direction : Direction.HORIZONTAL) {
BlockPos renderPos = playerPos.offset(direction);

// Double height
if (doubleHeight.get()) {
for (CardinalDirection direction : CardinalDirection.values()) {
draw(event, direction, 1, Dir.DOWN);
}
// Regular surround positions
draw(renderPos, event, doubleHeight.get() ? Dir.UP : 0);

// Double height
if (doubleHeight.get()) draw(renderPos.up(), event, Dir.DOWN);
}
}

private void draw(Render3DEvent event, CardinalDirection direction, int y, int exclude) {
renderPos.set(offsetPosFromPlayer(direction, y));
private void draw(BlockPos renderPos, Render3DEvent event, int exclude) {
Color sideColor = getSideColor(renderPos);
Color lineColor = getLineColor(renderPos);
event.renderer.box(renderPos, sideColor, lineColor, shapeMode.get(), exclude);
Expand All @@ -269,7 +280,7 @@ public void onActivate() {
if (center.get() == Center.OnActivate) PlayerUtils.centerPlayer();

// Reset delay
ticks = 0;
timer = delay.get();

if (toggleModules.get() && !modules.get().isEmpty() && mc.world != null && mc.player != null) {
for (Module module : modules.get()) {
Expand All @@ -294,14 +305,8 @@ public void onDeactivate() {

@EventHandler
private void onTick(TickEvent.Pre event) {
// Tick the placement timer, should always happen
if (ticks > 0) {
ticks--;
return;
}
else {
ticks = delay.get();
}
// Delay
if (timer++ < delay.get()) return;

// Toggle if Y level changed
if (toggleOnYChange.get() && mc.player.lastY != mc.player.getY()) {
Expand All @@ -313,28 +318,42 @@ private void onTick(TickEvent.Pre event) {
if (onlyOnGround.get() && !mc.player.isOnGround()) return;

// Wait until the player has a block available to place
if (!getInvBlock().found()) return;
FindItemResult block = InvUtils.findInHotbar(itemStack -> blocks.get().contains(Block.getBlockFromItem(itemStack.getItem())));
if (!block.found()) return;

// Centering player
if (center.get() == Center.Always) PlayerUtils.centerPlayer();

// Check surround blocks in order and place the first missing one if present
int safe = 0;
int placedCount = 0;

BlockPos playerPos = mc.player.getBlockPos();

// Looping through feet blocks
for (CardinalDirection direction : CardinalDirection.values()) {
if (place(direction, 0)) break;
for (Direction direction : Direction.HORIZONTAL) {
BlockPos placePos = playerPos.offset(direction);

// Place support blocks if air place is disabled
if (!airPlace.get() && isAirPlace(placePos) && mc.world.getBlockState(placePos).isReplaceable()){
if (place(placePos.down(), block) && ++placedCount >= blocksPerTick.get()) break;
}

if (place(placePos, block) && ++placedCount >= blocksPerTick.get()) break;
safe++;
}

// Looping through head blocks
if (doubleHeight.get() && safe == 4) {
for (CardinalDirection direction : CardinalDirection.values()) {
if (place(direction, 1)) break;
for (Direction direction : Direction.HORIZONTAL) {
BlockPos placePos = playerPos.offset(direction).up();
if (place(placePos, block) && ++placedCount >= blocksPerTick.get()) break;
safe++;
}
}

timer = 0;

boolean complete = safe == (doubleHeight.get() ? 8 : 4);

// Disable if all the surround blocks are placed
Expand All @@ -347,18 +366,9 @@ private void onTick(TickEvent.Pre event) {
if (!complete && center.get() == Center.Incomplete) PlayerUtils.centerPlayer();
}

private boolean place(CardinalDirection direction, int y) {
placePos.set(offsetPosFromPlayer(direction, y));

private boolean place(BlockPos placePos, FindItemResult block) {
// Attempt to place
boolean placed = BlockUtils.place(
placePos,
getInvBlock(),
rotate.get(),
100,
swing.get(),
true
);
boolean placed = BlockUtils.place(placePos, block, rotate.get(), 100, swing.get(), true);

// Check if the block is being mined
boolean beingMined = false;
Expand Down Expand Up @@ -408,26 +418,6 @@ private void onPacketReceive(PacketEvent.Receive event) {
}
}

private BlockPos.Mutable offsetPosFromPlayer(CardinalDirection direction, int y) {
return offsetPos(mc.player.getBlockPos(), direction, y);
}

private BlockPos.Mutable offsetPos(BlockPos origin, CardinalDirection direction, int y) {
if (direction == null) {
return testPos.set(
origin.getX(),
origin.getY() + y,
origin.getZ()
);
}

return testPos.set(
origin.getX() + direction.toDirection().getOffsetX(),
origin.getY() + y,
origin.getZ() + direction.toDirection().getOffsetZ()
);
}

private BlockType getBlockType(BlockPos pos) {
BlockState blockState = mc.world.getBlockState(pos);

Expand Down Expand Up @@ -455,16 +445,15 @@ private Color getLineColor(BlockPos pos) {
};
}

private FindItemResult getInvBlock() {
return InvUtils.findInHotbar(itemStack -> blocks.get().contains(Block.getBlockFromItem(itemStack.getItem())));
private boolean isAirPlace(BlockPos blockPos) {
for (Direction direction : Direction.values()) {
if (!mc.world.getBlockState(blockPos.offset(direction)).isReplaceable()) return false;
}
return true;
}

private boolean blockFilter(Block block) {
return block == Blocks.OBSIDIAN ||
block == Blocks.CRYING_OBSIDIAN ||
block == Blocks.NETHERITE_BLOCK ||
block == Blocks.ENDER_CHEST ||
block == Blocks.RESPAWN_ANCHOR;
return block.getBlastResistance() >= 600 && block.getHardness() >= 0 && block != Blocks.REINFORCED_DEEPSLATE;
}

public enum Center {
Expand Down