Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
SymoHTL committed Apr 16, 2024
1 parent 55d6aeb commit 4cbb404
Show file tree
Hide file tree
Showing 12 changed files with 130 additions and 102 deletions.
105 changes: 55 additions & 50 deletions src/client/java/dev/symo/finz/FinZClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,55 +19,60 @@

public class FinZClient implements ClientModInitializer {

public static final String MOD_ID = "finz";
public static final String CONFIG_VERSION = "1";

public static EventManager eventManager = new EventManager();
public static List<ModContainer> MODS = new ArrayList<>();

public static boolean isConfigOpen = false;
private static ConfigScreen configScreen;

public static final MinecraftClient mc = MinecraftClient.getInstance();

public static Path FinZPath = FabricLoader.getInstance().getConfigDir().resolve("finz");

public static final FriendList friendList = new FriendList(FinZPath.resolve("friends.json").toString());

public static final FinZSettings settings = new FinZSettings(FinZPath.resolve("config.json").toString());

@Override
public void onInitializeClient() {
createFinZFolder();

ModuleManager.init();

settings.load();
friendList.load();
FinZClient.MODS = ImmutableList.copyOf(FabricLoader.getInstance().getAllMods());
}

private void createFinZFolder(){
var cfgDir = FabricLoader.getInstance().getConfigDir();
var finzDir = cfgDir.resolve("finz");
if (!finzDir.toFile().exists()) {
try {
Files.createDirectories(finzDir);
} catch (IOException e) {
e.printStackTrace();
}
}
}

public static void showConfigScreen() {
if (isConfigOpen) {
configScreen.close();
return;
}
mc.setScreen(configScreen = new ConfigScreen());
//ConfigManager.build();
//Screen screen = ConfigManager.configBuilder.build();
//mc.setScreen(screen);
}
public static final String MOD_ID = "finz";
public static final String CONFIG_VERSION = "1";

public static EventManager eventManager = new EventManager();
public static List<ModContainer> MODS = new ArrayList<>();

public static boolean isConfigOpen = false;
private static ConfigScreen configScreen;

public static final MinecraftClient mc = MinecraftClient.getInstance();

public static Path FinZPath = FabricLoader.getInstance().getConfigDir().resolve("finz");

public static final FriendList friendList = new FriendList(FinZPath.resolve("friends.json").toString());

public static final FinZSettings settings = new FinZSettings(FinZPath.resolve("config.json").toString());

@Override
public void onInitializeClient() {
createFinZFolder();

ModuleManager.init();

settings.load();
friendList.load();
FinZClient.MODS = ImmutableList.copyOf(FabricLoader.getInstance().getAllMods());
}

private void createFinZFolder() {
var cfgDir = FabricLoader.getInstance().getConfigDir();
var finzDir = cfgDir.resolve("finz");
if (!finzDir.toFile().exists()) {
try {
Files.createDirectories(finzDir);
} catch (IOException e) {
e.printStackTrace();
}
}
}

public static void showConfigScreen() {
System.out.println("showConfigScreen");
if (isConfigOpen) {
configScreen.close();
configScreen = null;
isConfigOpen = false;
return;
}
configScreen = new ConfigScreen();
mc.setScreen(configScreen);
isConfigOpen = true;
//ConfigManager.build();
//Screen screen = ConfigManager.configBuilder.build();
//mc.setScreen(screen);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,32 @@

import dev.symo.finz.events.impl.Event;
import dev.symo.finz.events.impl.Listener;
import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext;
import net.minecraft.client.util.math.MatrixStack;
import org.lwjgl.opengl.GL11;

import java.util.ArrayList;

public interface WorldRenderListener extends Listener {
void onWorldRender(MatrixStack matrixStack, float partialTicks);
void onWorldRender(MatrixStack matrixStack, float partialTicks, WorldRenderContext context);

public static class RenderEvent extends Event<WorldRenderListener> {
private final MatrixStack matrixStack;
private final float partialTicks;
private final WorldRenderContext context;

public RenderEvent(MatrixStack matrixStack, float partialTicks) {
public RenderEvent(MatrixStack matrixStack, float partialTicks, WorldRenderContext context) {
this.matrixStack = matrixStack;
this.partialTicks = partialTicks;
this.context = context;
}

@Override
public void fire(ArrayList<WorldRenderListener> listeners) {
GL11.glEnable(GL11.GL_LINE_SMOOTH);

for (WorldRenderListener listener : listeners)
listener.onWorldRender(matrixStack, partialTicks);
listener.onWorldRender(matrixStack, partialTicks, context);

GL11.glDisable(GL11.GL_LINE_SMOOTH);
}
Expand Down
12 changes: 4 additions & 8 deletions src/client/java/dev/symo/finz/modules/ModuleManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,19 @@ public static void init() {

// register events
KeyEvent.KEY_EVENT.register(() -> {
HandleKeyEvent();
if (_openGuiKey.wasPressed()) {
FinZClient.showConfigScreen();
}
return ActionResult.PASS;
});
ClientTickEvents.END_CLIENT_TICK.register(mc ->
EventManager.fire(TickListener.UpdateEvent.INSTANCE));
WorldRenderEvents.END.register(context ->
EventManager.fire(new WorldRenderListener.RenderEvent(context.matrixStack(), context.tickDelta())));
EventManager.fire(new WorldRenderListener.RenderEvent(context.matrixStack(), context.tickDelta(), context)));
HudRenderCallback.EVENT.register((c, t) ->
EventManager.fire(new HudRenderListener.HudRenderEvent(c, t)));
}

private static void HandleKeyEvent() {
if (_openGuiKey.wasPressed()) {
FinZClient.showConfigScreen();
}
}

public static AModule getModule(String name) {
return _modules.stream().filter(module -> module._name.equalsIgnoreCase(name))
.findFirst().orElse(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@
import dev.symo.finz.events.listeners.KnockbackListener;
import dev.symo.finz.modules.AModule;
import dev.symo.finz.modules.settings.DoubleSetting;
import dev.symo.finz.modules.settings.IntSetting;
import dev.symo.finz.util.Category;
import dev.symo.finz.util.InputType;

public class AntiKnockback extends AModule implements KnockbackListener {

private final DoubleSetting _horizontal = new DoubleSetting("Horizontal", "100% = no knockback -- >100% = reverse knockback", 0.2, 0.0, 1.0, InputType.PERCENT_SLIDER);
private final DoubleSetting _vertical = new DoubleSetting("Vertical", "100% = no knockback -- >100% = reverse knockback",0.2, 0.0, 1.0, InputType.PERCENT_SLIDER);
private final DoubleSetting _vertical = new DoubleSetting("Vertical", "100% = no knockback -- >100% = reverse knockback", 0.2, 0.0, 1.0, InputType.PERCENT_SLIDER);
private final IntSetting _everyNth = new IntSetting("Every Nth", "Only apply anti-knockback every Nth hit/velocity change, 1 -> every hit, 2 -> every 2nd hit, etc.", 1, 1, 100);

private int _hitCount = 0;

public AntiKnockback() {
super("AntiKnockback", Category.MOVEMENT);
Expand All @@ -19,6 +23,8 @@ public AntiKnockback() {

@Override
public void onKnockback(KnockbackEvent event) {
if (++_hitCount % _everyNth.getValue() != 0) return;

double verticalMultiplier = 1 - _vertical.getValue();
double horizontalMultiplier = 1 - _horizontal.getValue();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import dev.symo.finz.modules.settings.StringSetting;
import dev.symo.finz.util.Category;
import dev.symo.finz.util.WorldSpaceRenderer;
import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.registry.Registries;
import net.minecraft.util.math.BlockPos;
Expand Down Expand Up @@ -85,7 +86,7 @@ public void onTick() {
blocks.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) {
public void onWorldRender(MatrixStack matrixStack, float partialTicks, WorldRenderContext context) {
if (mc.player == null) return;
if (mc.world == null) return;

Expand Down
3 changes: 2 additions & 1 deletion src/client/java/dev/symo/finz/modules/impl/PathTracer.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import dev.symo.finz.util.PlayerUtil;
import dev.symo.finz.util.RegionPos;
import dev.symo.finz.util.WorldSpaceRenderer;
import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext;
import net.minecraft.block.BlockState;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.util.math.BlockPos;
Expand Down Expand Up @@ -65,7 +66,7 @@ public void onTick() {

}

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

Expand Down
23 changes: 20 additions & 3 deletions src/client/java/dev/symo/finz/modules/impl/esp/ItemESP.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import dev.symo.finz.util.Category;
import dev.symo.finz.util.UiRenderer;
import dev.symo.finz.util.WorldSpaceRenderer;
import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.Entity;
Expand All @@ -18,7 +19,7 @@
import java.util.ArrayList;
import java.util.Objects;

public class ItemESP extends AModule implements TickListener, WorldRenderListener {
public class ItemESP extends AModule implements TickListener, WorldRenderListener, HudRenderListener {
private final ArrayList<Entity> items = new ArrayList<>();

private final BoolSetting renderItemSprite = new BoolSetting("Render Sprite", "Render the item sprite",
Expand All @@ -31,18 +32,20 @@ public class ItemESP extends AModule implements TickListener, WorldRenderListene
public ItemESP() {
super("ItemESP", Category.RENDER);
addSetting(itemEspRange);
//addSetting(renderItemSprite);
addSetting(renderItemSprite);
}

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

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

Expand All @@ -56,9 +59,23 @@ public void onTick() {
}

@Override
public void onWorldRender(MatrixStack matrices, float partialTicks) {
public void onWorldRender(MatrixStack matrices, float partialTicks, WorldRenderContext c) {
if (renderItemSprite.getValue()) return;

WorldSpaceRenderer.renderEntitiesEsp(matrices, partialTicks, items);
}

@Override
public void onHudRender(DrawContext drawContext, float tickDelta) {
if (!renderItemSprite.getValue()) return;

for (Entity item : items) {
Vec3d screenPos = UiRenderer.worldSpaceToScreenSpace(item.getPos());
if (!UiRenderer.screenSpaceCoordinateIsVisible(screenPos)) continue;

var itemStack = ((ItemEntity) item).getStack();

UiRenderer.drawItem(drawContext, itemStack, (int) screenPos.x, (int) screenPos.z, 32);
}
}
}
3 changes: 2 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 @@ -7,6 +7,7 @@
import dev.symo.finz.modules.settings.IntSetting;
import dev.symo.finz.util.Category;
import dev.symo.finz.util.WorldSpaceRenderer;
import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
Expand Down Expand Up @@ -69,7 +70,7 @@ public void onTick() {
}

@Override
public void onWorldRender(MatrixStack matrices, float partialTicks) {
public void onWorldRender(MatrixStack matrices, float partialTicks, WorldRenderContext context) {
WorldSpaceRenderer.renderEntitiesEsp(matrices, partialTicks, mobs);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import dev.symo.finz.util.Category;
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.util.math.MatrixStack;
import net.minecraft.entity.Entity;
Expand All @@ -19,6 +20,7 @@
import java.util.stream.Stream;

public class PlayerESP extends AModule implements TickListener, WorldRenderListener {

private final ArrayList<Entity> players = new ArrayList<>();

public PlayerESP() {
Expand Down Expand Up @@ -66,7 +68,7 @@ public void onTick() {
}

@Override
public void onWorldRender(MatrixStack matrices, float partialTicks) {
public void onWorldRender(MatrixStack matrices, float partialTicks, WorldRenderContext context) {
WorldSpaceRenderer.renderEntitiesEsp(matrices, partialTicks, players);
}
}
10 changes: 3 additions & 7 deletions src/client/java/dev/symo/finz/ui/ConfigScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,6 @@ public final class ConfigScreen extends Screen {

public ConfigScreen() {
super(Text.literal("FinZ Config"));
FinZClient.isConfigOpen = true;
}

@Override
public void close() {
FinZClient.isConfigOpen = false;
super.close();
}

@Override
Expand Down Expand Up @@ -91,4 +84,7 @@ public boolean mouseClicked(double mouseX, double mouseY, int button) {

return false;
}

public void savePositions() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class ModuleRenderer implements Drawable, Element, Selectable, ParentElem
private final int parentHeight = FinZClient.mc.getWindow().getHeight();

private final TextRenderer textRenderer = FinZClient.mc.textRenderer;
private final ConfigScreen scr;

@Nullable
private Element focused;
Expand All @@ -47,6 +48,7 @@ public class ModuleRenderer implements Drawable, Element, Selectable, ParentElem

public ModuleRenderer(Text text, int x, int y, Collection<ModuleSetting> settings, ConfigScreen screen) {
this.text = text;
this.scr = screen;
headerHeight = (int) (textRenderer.fontHeight * 1.5 + 4);
var settingWidth = settings.stream()
.mapToInt(setting -> textRenderer.getWidth(setting.getName())).max().orElse(0) + 5;
Expand Down Expand Up @@ -134,6 +136,11 @@ public boolean isDragging() {
@Override
public void setDragging(boolean dragging) {
this.dragging = dragging;
if (!dragging) {
dragOffsetX = 0;
dragOffsetY = 0;
scr.savePositions();
}
}

@Nullable
Expand Down
Loading

0 comments on commit 4cbb404

Please sign in to comment.