Skip to content
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

Bed esp #3

Merged
merged 3 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ loader_version=0.15.9

# Mod Properties
mod_version=1.1.0

maven_group=dev.symo.finz
archives_base_name=finz

Expand Down
3 changes: 3 additions & 0 deletions src/client/java/dev/symo/finz/modules/Modules.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dev.symo.finz.modules;

import dev.symo.finz.modules.impl.*;
import dev.symo.finz.modules.impl.esp.BedESP;
import dev.symo.finz.modules.impl.esp.ItemESP;
import dev.symo.finz.modules.impl.esp.MobEsp;
import dev.symo.finz.modules.impl.esp.PlayerESP;
Expand Down Expand Up @@ -31,6 +32,7 @@ public class Modules {
public static PlayerESP playerESP = new PlayerESP();
public static MobEsp mobEsp = new MobEsp();
public static ItemESP itemESP = new ItemESP();
public static BedESP bedESP = new BedESP();

// settings
public static SettingsModule settings = new SettingsModule();
Expand All @@ -55,6 +57,7 @@ public class Modules {
all.add(playerESP);
all.add(mobEsp);
all.add(itemESP);
all.add(bedESP);

// settings
all.add(settings);
Expand Down
93 changes: 93 additions & 0 deletions src/client/java/dev/symo/finz/modules/impl/esp/BedESP.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package dev.symo.finz.modules.impl.esp;

import dev.symo.finz.events.listeners.ConfigChangeListener;
import dev.symo.finz.events.listeners.TickListener;
import dev.symo.finz.events.listeners.WorldRenderListener;
import dev.symo.finz.modules.AModule;
import dev.symo.finz.modules.settings.IntSetting;
import dev.symo.finz.util.Category;
import dev.symo.finz.util.ColorUtil;
import dev.symo.finz.util.WorldSpaceRenderer;
import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext;
import net.minecraft.block.BedBlock;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.util.math.BlockPos;

import java.awt.*;
import java.util.ArrayList;

public class BedESP extends AModule implements ConfigChangeListener, TickListener, WorldRenderListener {
private final IntSetting _range = new IntSetting("Range", "Range to scan for blocks",
50, 1, 100);

private final ArrayList<BlockPos> beds = new ArrayList<>();

private int _tickDelay = 0;

public BedESP() {
super("Bed ESP", Category.RENDER);
addSetting(_range);
}

public void onConfigChange() {
beds.clear();
}

@Override
public void onEnable() {
EVENTS.add(TickListener.class, this);
EVENTS.add(WorldRenderListener.class, this);
}

@Override
public void onDisable() {
EVENTS.remove(TickListener.class, this);
EVENTS.remove(WorldRenderListener.class, this);
beds.clear();
}

public void onTick() {
if (mc.player == null) return;
if (mc.world == null) return;

if (_tickDelay > 0) {
_tickDelay--;
return;
}
_tickDelay = 40;

// look for beds in range around player

var playerPos = mc.player.getBlockPos();
var playerX = playerPos.getX();
var playerY = playerPos.getY();
var playerZ = playerPos.getZ();

var range = _range.getValue();

for (int x = playerX - range; x < playerX + range; x++) {
for (int y = playerY - range; y < playerY + range; y++) {
for (int z = playerZ - range; z < playerZ + range; z++) {
var pos = new BlockPos(x, y, z);
var state = mc.world.getBlockState(pos);
var block = state.getBlock();
if (block instanceof BedBlock && !beds.contains(pos))
beds.add(pos);
}
}
}

beds.removeIf(pos -> !(mc.world.getBlockState(pos).getBlock() instanceof BedBlock));

beds.removeIf(pos -> Math.abs(pos.getX() - playerX) > range + range / 2 || Math.abs(pos.getY() - playerY) > range + range / 2 || Math.abs(pos.getZ() - playerZ) > range + range / 2);
}

public void onWorldRender(MatrixStack matrixStack, float partialTicks, WorldRenderContext context) {
if (mc.player == null) return;
if (mc.world == null) return;

var color = ColorUtil.getRainbowColor();

WorldSpaceRenderer.renderBlocks(matrixStack, new Color(color), beds.stream());
}
}
Loading