Skip to content

Commit

Permalink
added projectile warner
Browse files Browse the repository at this point in the history
  • Loading branch information
SymoHTL committed Apr 21, 2024
1 parent 257eef4 commit d6b6c2b
Show file tree
Hide file tree
Showing 11 changed files with 251 additions and 32 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ yarn_mappings=1.20.4+build.3
loader_version=0.15.9

# Mod Properties
mod_version=1.1.2
mod_version=1.1.6

maven_group=dev.symo.finz
archives_base_name=finz
Expand Down
1 change: 0 additions & 1 deletion src/client/java/dev/symo/finz/config/KeyBind.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,4 @@ public boolean equals(Object o) {
else if (!(o instanceof KeyBind keyBind)) return false;
else return this.keyName.equalsIgnoreCase(keyBind.keyName) && this.module.equals(keyBind.module);
}

}
7 changes: 6 additions & 1 deletion src/client/java/dev/symo/finz/config/KeyBindSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,12 @@ public void save() {
}

public void add(KeyBind keyBind) {
for (KeyBind bind : keyBinds) if (bind.equals(keyBind)) return;
for (KeyBind bind : keyBinds){
if(bind.getModule().equals(keyBind.getModule())){
keyBinds.remove(bind);
break;
}
}
keyBinds.add(keyBind);
}

Expand Down
2 changes: 1 addition & 1 deletion src/client/java/dev/symo/finz/modules/AModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void addSetting(ModuleSetting setting) {
}

public void registerKeyBind(String keyName){
FinZClient.keyBindSettings.addAndSave(new KeyBind(keyName, this));
FinZClient.keyBindSettings.add(new KeyBind(keyName, this));
}

public Collection<ModuleSetting> getSettings() {
Expand Down
11 changes: 9 additions & 2 deletions src/client/java/dev/symo/finz/modules/Modules.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ public class Modules {

public static final ArrayList<AModule> all = new ArrayList<>();

// misc
// combat
public static ProjectileWarner projectileWarner = new ProjectileWarner();
public static AntiKnockback knockback = new AntiKnockback();

// misc

public static Zoom zoom = new Zoom();

// movement
Expand All @@ -38,8 +41,12 @@ public class Modules {
public static SettingsModule settings = new SettingsModule();

static {
// misc

// combat
all.add(projectileWarner);
all.add(knockback);

// misc
all.add(zoom);

// movement
Expand Down
90 changes: 90 additions & 0 deletions src/client/java/dev/symo/finz/modules/impl/ProjectileWarner.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package dev.symo.finz.modules.impl;

import dev.symo.finz.events.listeners.HudRenderListener;
import dev.symo.finz.events.listeners.TickListener;
import dev.symo.finz.modules.AModule;
import dev.symo.finz.modules.settings.IntSetting;
import dev.symo.finz.util.Category;
import dev.symo.finz.util.EntityUtil;
import dev.symo.finz.util.UiRenderer;
import me.x150.renderer.util.RendererUtils;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.entity.projectile.*;
import net.minecraft.entity.projectile.thrown.EggEntity;
import net.minecraft.entity.projectile.thrown.EnderPearlEntity;
import net.minecraft.entity.projectile.thrown.SnowballEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;

import java.util.ArrayList;

public class ProjectileWarner extends AModule implements TickListener, HudRenderListener {

private final IntSetting scale = new IntSetting("Scale", "Scale of the item sprite",
36, 1, 100);

private final ArrayList<ProjectileEntity> projectiles = new ArrayList<>();

public ProjectileWarner() {
super("Projectile Warner", Category.COMBAT);
addSetting(scale);
}

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

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

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

projectiles.clear();
var stream = mc.world.getEntitiesByClass(ProjectileEntity.class, mc.player.getBoundingBox().expand(50.0, 20.0, 50.0), entity -> true)
.parallelStream()
.filter(entity -> entity.getOwner() != mc.player)
.filter(entity -> entity.getVelocity().length() > 0.1)
.filter(entity -> entity.getVelocity().dotProduct(mc.player.getPos().subtract(entity.getPos())) > 0);

projectiles.addAll(stream.toList());


}

@Override
public void onHudRender(DrawContext drawContext, float tickDelta) {

var scale = this.scale.getValue();
// draw a waring icon on the screen where the projectile is coming from
for (ProjectileEntity projectile : projectiles) {
var pos = EntityUtil.getLerpedPos(projectile, tickDelta);
var screenPos = RendererUtils.worldSpaceToScreenSpace(pos);
// if it is not visible snap it to the edge of the screen
screenPos = UiRenderer.sanitizeScreenPos(screenPos, scale);
var item = projectileToItem(projectile);

UiRenderer.drawItem(drawContext, item, (int) screenPos.x, (int) screenPos.y, scale);
}
}

private ItemStack projectileToItem(ProjectileEntity projectile) {
if (projectile instanceof FireballEntity) return new ItemStack(net.minecraft.item.Items.FIRE_CHARGE);
if (projectile instanceof ArrowEntity) return new ItemStack(net.minecraft.item.Items.ARROW);
if (projectile instanceof SnowballEntity) return new ItemStack(net.minecraft.item.Items.SNOWBALL);
if (projectile instanceof EnderPearlEntity) return new ItemStack(net.minecraft.item.Items.ENDER_PEARL);
if (projectile instanceof EggEntity) return new ItemStack(net.minecraft.item.Items.EGG);
if (projectile instanceof TridentEntity) return new ItemStack(net.minecraft.item.Items.TRIDENT);
if (projectile instanceof FireworkRocketEntity) return new ItemStack(net.minecraft.item.Items.FIREWORK_ROCKET);
if (projectile instanceof SmallFireballEntity) return new ItemStack(net.minecraft.item.Items.FIRE_CHARGE);
if (projectile instanceof WitherSkullEntity) return new ItemStack(net.minecraft.item.Items.WITHER_SKELETON_SKULL);
if (projectile instanceof DragonFireballEntity) return new ItemStack(net.minecraft.item.Items.DRAGON_BREATH);
return new ItemStack(Items.BARRIER);
}
}
6 changes: 4 additions & 2 deletions src/client/java/dev/symo/finz/modules/impl/esp/ItemESP.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import dev.symo.finz.modules.settings.BoolSetting;
import dev.symo.finz.modules.settings.IntSetting;
import dev.symo.finz.util.Category;
import dev.symo.finz.util.EntityUtil;
import dev.symo.finz.util.UiRenderer;
import dev.symo.finz.util.WorldSpaceRenderer;
import me.x150.renderer.util.RendererUtils;
Expand All @@ -17,6 +18,7 @@
import net.minecraft.entity.ItemEntity;
import net.minecraft.util.math.Vec3d;

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

Expand Down Expand Up @@ -72,7 +74,7 @@ public void onTick() {
public void onWorldRender(MatrixStack matrices, float partialTicks, WorldRenderContext c) {
if (renderItemSprite.getValue()) return;

WorldSpaceRenderer.renderEntitiesEsp(matrices, partialTicks, items);
WorldSpaceRenderer.renderEntitiesEsp(matrices, partialTicks, items, entity -> Color.WHITE, entity -> null, false);
}

@Override
Expand All @@ -81,7 +83,7 @@ public void onHudRender(DrawContext drawContext, float tickDelta) {
if (!renderItemSprite.getValue()) return;

for (Entity item : items) {
var itemPos = item.getPos();
var itemPos = EntityUtil.getLerpedPos(item, tickDelta);
itemPos = itemPos.add(0, item.getHeight() / 2, 0);
Vec3d screenPos = RendererUtils.worldSpaceToScreenSpace(itemPos);
if (!RendererUtils.screenSpaceCoordinateIsVisible(screenPos)) continue;
Expand Down
11 changes: 10 additions & 1 deletion src/client/java/dev/symo/finz/modules/impl/esp/MobEsp.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import dev.symo.finz.modules.ModuleManager;
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.client.util.math.MatrixStack;
Expand All @@ -15,6 +16,7 @@
import net.minecraft.util.hit.EntityHitResult;
import net.minecraft.util.hit.HitResult;

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

Expand Down Expand Up @@ -76,6 +78,13 @@ public void onTick() {

@Override
public void onWorldRender(MatrixStack matrices, float partialTicks, WorldRenderContext context) {
WorldSpaceRenderer.renderEntitiesEsp(matrices, partialTicks, mobs);
WorldSpaceRenderer.renderEntitiesEsp(matrices, partialTicks, mobs, entity -> Color.RED, entity -> {
if (entity instanceof LivingEntity livingEntity) {
var hpPercent = livingEntity.getHealth() / livingEntity.getMaxHealth();
return ColorUtil.percentageToColor(hpPercent * 100);
}

return Color.WHITE;
}, true);
}
}
48 changes: 40 additions & 8 deletions src/client/java/dev/symo/finz/modules/impl/esp/PlayerESP.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,30 @@
import dev.symo.finz.events.listeners.WorldRenderListener;
import dev.symo.finz.modules.AModule;
import dev.symo.finz.modules.ModuleManager;
import dev.symo.finz.modules.settings.BoolSetting;
import dev.symo.finz.util.Category;
import dev.symo.finz.util.ColorUtil;
import dev.symo.finz.util.FakePlayerEntity;
import dev.symo.finz.util.WorldSpaceRenderer;
import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext;
import net.minecraft.client.network.AbstractClientPlayerEntity;
import net.minecraft.client.network.PlayerListEntry;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.scoreboard.Team;
import net.minecraft.util.Nullables;
import net.minecraft.util.hit.EntityHitResult;
import net.minecraft.util.hit.HitResult;
import net.minecraft.world.GameMode;
import org.apache.logging.log4j.Level;

import java.awt.*;
import java.util.*;
import java.util.List;
import java.util.stream.Stream;

public class PlayerESP extends AModule implements TickListener, WorldRenderListener {

private final BoolSetting filterNps = new BoolSetting("Filter Npcs", "If enabled, only \"real\" players will be shown", true);

private final Set<Entity> players = new HashSet<>();

private List<PlayerListEntry> playerListEntries;
Expand All @@ -34,6 +37,7 @@ public class PlayerESP extends AModule implements TickListener, WorldRenderListe

public PlayerESP() {
super("PlayerESP", Category.RENDER);
addSetting(filterNps);
}


Expand All @@ -55,25 +59,32 @@ protected void onSettingsChanged() {
}



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

if (_tickDelay == 10)
if ((_tickDelay == 10 || playerListEntries == null) && filterNps.getValue())
playerListEntries = mc.player.networkHandler.getListedPlayerListEntries().stream().limit(80L).toList();
_tickDelay = (_tickDelay + 1) % 20;

players.clear();
var sb = mc.world.getScoreboard();
var clientTeam = sb.getScoreHolderTeam(mc.player.getName().getString());
Stream<AbstractClientPlayerEntity> stream = mc.world.getPlayers()
.parallelStream()
.filter(e -> e != mc.player)
.filter(e -> !e.isRemoved() && e.getHealth() > 0)
.filter(e -> !(e instanceof FakePlayerEntity))
.filter(e -> Math.abs(e.getY() - mc.player.getY()) <= 1e6)
.filter(e -> !FinZClient.friendList.contains(e.getName().getString()))
.filter(e -> playerListEntries.stream().anyMatch(p -> p.getProfile().getId().equals(e.getUuid())));
.filter(e -> {
var team = sb.getScoreHolderTeam(e.getName().getString());
if (team == null ||clientTeam == null) return true;
return !clientTeam.getName().equals(team.getName());
});
if (filterNps.getValue())
stream = stream.filter(e -> playerListEntries.stream().anyMatch(p -> p.getProfile().getId().equals(e.getUuid())));

players.addAll(stream.toList());

Expand All @@ -91,6 +102,27 @@ public void onTick() {

@Override
public void onWorldRender(MatrixStack matrices, float partialTicks, WorldRenderContext context) {
WorldSpaceRenderer.renderEntitiesEsp(matrices, partialTicks, players);
assert mc.world != null;
var sb = mc.world.getScoreboard();
WorldSpaceRenderer.renderEntitiesEsp(matrices, partialTicks, players, entity -> {
var color = Color.BLACK;
if (FinZClient.friendList.contains(entity.getName().getString())) color = Color.GREEN;
else if (entity instanceof PlayerEntity pe) {
var team = sb.getScoreHolderTeam(pe.getName().getString());
if (team != null) {
var teamColor = team.getColor().getColorValue();
if (teamColor != null) color = new Color(teamColor);
}
}

return color;
}, entity -> {
if (entity instanceof LivingEntity livingEntity) {
var hpPercent = livingEntity.getHealth() / livingEntity.getMaxHealth();
return ColorUtil.percentageToColor(hpPercent * 100);
}

return Color.WHITE;
}, true);
}
}
24 changes: 21 additions & 3 deletions src/client/java/dev/symo/finz/util/UiRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,32 @@
import net.minecraft.client.render.model.json.ModelTransformationMode;
import net.minecraft.entity.LivingEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.Vec3d;
import org.jetbrains.annotations.Nullable;
import org.joml.Matrix4f;
import org.joml.Quaternionf;
import org.joml.Vector3f;

public class UiRenderer {

public static Vec3d sanitizeScreenPos(Vec3d vec, int padding){
if (vec.z > -1 && vec.z < 1) return vec;
// now it isnt visible so we snap the x and y to the screen edge
// to make it looklike it is coming from behind for the palyer
return snapToScreenEdge(vec, padding);
}

public static Vec3d snapToScreenEdge(Vec3d vec, int padding) {
var screen = FinZClient.mc.getWindow();
double x = vec.x;
double y = vec.y;
double z = vec.z;
var halfWidth = screen.getScaledWidth() / 2;
if (x > halfWidth) x = padding;
else x = screen.getScaledWidth() - padding;
return new Vec3d(x, y, z);
}


public static void drawRectDouble(DrawContext drawContext, double left, double top, double right, double bottom, int color) {
if (left < right) {
Expand Down Expand Up @@ -58,8 +77,7 @@ public static void drawItem(DrawContext context, ItemStack stack, int x, int y,
matrices.pop();
}

public static void drawEntity(DrawContext context, int x, int y, int size, float mouseX, float mouseY, LivingEntity entity) {
float i = (float) Math.atan((x - mouseX) / 40.0F);
public static void drawEntity(DrawContext context, int x, int y, int size, float mouseY, LivingEntity entity) {
float j = (float) Math.atan((y - mouseY) / 40.0F);
Quaternionf quaternionf = (new Quaternionf()).rotateZ(3.1415927F);
Quaternionf quaternionf2 = (new Quaternionf()).rotateX(j * 20.0F * 0.017453292F);
Expand All @@ -82,7 +100,7 @@ private static void drawEntity(DrawContext context, float x, float y, int size,
}

entityRenderDispatcher.setRenderShadows(false);
RenderSystem.runAsFancy(() -> entityRenderDispatcher.render(entity, 0.0D, 0.0D, 0.0D, 0.0F, 1.0F, context.getMatrices(), context.getVertexConsumers(), 15728880));
entityRenderDispatcher.render(entity, 0.0D, 0.0D, 0.0D, 0.0F, 1.0F, context.getMatrices(), context.getVertexConsumers(), 15728880);
context.draw();
entityRenderDispatcher.setRenderShadows(true);
context.getMatrices().pop();
Expand Down
Loading

0 comments on commit d6b6c2b

Please sign in to comment.