Skip to content

Commit

Permalink
Code optimisation, removed WorldRenderer.java as it was useless. Fixe…
Browse files Browse the repository at this point in the history
…d PMR rendering out of chat hud.
  • Loading branch information
tanishisherewithhh committed Sep 5, 2024
1 parent 5c42f65 commit b38fb09
Show file tree
Hide file tree
Showing 15 changed files with 138 additions and 220 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ dependencies {


// Baritone API from meteor's fork
modCompileOnly "meteordevelopment:baritone:1.20.4-SNAPSHOT"
modCompileOnly "meteordevelopment:baritone:${project.baritone_version}"

// LuaJ library
modInclude("org.luaj:luaj-jse:3.0.1")
Expand Down
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ yarn_mappings=1.20.4+build.1
loader_version=0.15.0

# Mod Properties
mod_version = dev
maven_group = dev
archives_base_name = heliosclient
mod_version = dev
maven_group = dev
archives_base_name = heliosclient

# Dependencies
fabric_version=0.91.1+1.20.4
modmenu_version=9.0.0
baritone_version=v1.5.3
baritone_version=1.20.4-SNAPSHOT
2 changes: 1 addition & 1 deletion src/main/java/dev/heliosclient/HeliosClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public static boolean shouldUpdate() {

@SubscribeEvent
public void onDisconnect(DisconnectEvent client) {
HeliosClient.saveConfigHook();
HeliosClient.saveConfig();
}

@SubscribeEvent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

/**
* Using <a href="https://mojang-api-docs.gapple.pw/authentication/msa">Authentication Docs</a>
* Untested
*/
public class XboxLiveAuthenticator {
private static final String XBOX_LIVE_AUTH_URL = "https://user.auth.xboxlive.com/user/authenticate";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.session.Session;

import java.io.IOException;
import java.util.Optional;
import java.util.UUID;

Expand All @@ -24,7 +25,13 @@ public boolean login() {
UUID uuid = UUID.fromString(ProfileUtils.insertHyphensToUUID(uuidString));
String accessToken = this.sessionID.substring(this.sessionID.indexOf(":") + 1,this.sessionID.lastIndexOf(':'));

Session session = new Session("", uuid,accessToken, Optional.empty(),Optional.empty(), Session.AccountType.MOJANG);
Session session;
try {
session = new Session(ProfileUtils.getProfileName(uuidString), uuid,accessToken, Optional.empty(),Optional.empty(), Session.AccountType.MOJANG);
} catch (IOException e){
session = new Session("", uuid,accessToken, Optional.empty(),Optional.empty(), Session.AccountType.MOJANG);
e.printStackTrace();
}
((AccessorMinecraftClient) MinecraftClient.getInstance()).setSession(session);
}

Expand Down
4 changes: 3 additions & 1 deletion src/main/java/dev/heliosclient/mixin/MixinChatHud.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,15 @@ public abstract class MixinChatHud {
@Shadow
public abstract int getWidth();

@Shadow protected abstract boolean isChatFocused();

@Inject(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/hud/ChatHudLine$Visible;addedTime()I"))
public void getChatLineIndex(CallbackInfo ci, @Local(ordinal = 13) int chatLineIndex) {
this.chatLineIndex = chatLineIndex;
}
@Inject(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/hud/ChatHud;isChatHidden()Z",shift = At.Shift.AFTER))
public void onRender$GUICoolVisuals(DrawContext context, int currentTick, int mouseX, int mouseY,CallbackInfo ci) {
if(GUI.coolVisualsChatHud()){
if(this.isChatFocused() && GUI.coolVisualsChatHud()){
PolygonMeshPatternRenderer.INSTANCE.render(context.getMatrices(),mouseX,mouseY);
}
}
Expand Down
68 changes: 43 additions & 25 deletions src/main/java/dev/heliosclient/module/modules/world/AntiBot.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package dev.heliosclient.module.modules.world;

import dev.heliosclient.event.SubscribeEvent;
import dev.heliosclient.event.events.entity.EntityAddedEvent;
import dev.heliosclient.managers.ModuleManager;
import dev.heliosclient.module.Categories;
import dev.heliosclient.module.Module_;
import dev.heliosclient.module.settings.BooleanSetting;
import dev.heliosclient.module.settings.SettingGroup;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;

Expand All @@ -20,7 +23,6 @@ public class AntiBot extends Module_ {
.defaultValue(true)
.build()
);

BooleanSetting noIllegalName = sgGeneral.add(new BooleanSetting.Builder()
.name("No Illegal Name")
.description("Removes entities with illegal name")
Expand Down Expand Up @@ -63,23 +65,50 @@ public class AntiBot extends Module_ {
.defaultValue(false)
.build()
);
BooleanSetting removeFromWorld = sgGeneral.add(new BooleanSetting.Builder()
.name("Remove from world")
.description("Removes entities that match the above conditions from the world (WARNING: This will remove them from the world, so you want be able to see them or interact with them)")
.onSettingChange(this)
.defaultValue(false)
.build()
);

public AntiBot() {
super("Anti Bot","An Antibot module", Categories.WORLD);
super("Anti Bot","An AntiBot module", Categories.WORLD);
addSettingGroup(sgGeneral);
addQuickSettings(sgGeneral.getSettings());
}

public static AntiBot get(){
@SubscribeEvent
public void onEntityAdd(EntityAddedEvent event){
if(removeFromWorld.value || mc.world == null) return;

if(!(event.entity instanceof LivingEntity livingEntity))return;

if(isBot(livingEntity)){
mc.world.removeEntity(livingEntity.getId(), Entity.RemovalReason.DISCARDED);
}
}

public static AntiBot get() {
return ModuleManager.get(AntiBot.class);
}

public static boolean isBot(LivingEntity entity){
if(entity instanceof PlayerEntity player) {
if (!get().isActive()) {
return false;
}
if (!get().isActive()) {
return false;
}
if (get().noIllegalName.value && hasIllegalName(entity)) {
return true;
}
if (get().noFakeID.value && isFakeEntityId(entity)) {
return true;
}
if (get().noIllegalPitch.value && hasIllegalPitch(entity)) {
return true;
}

if(entity instanceof PlayerEntity player) {
if (get().illegalHealth.value && hasIllegalHealth(player)) {
return true;
}
Expand All @@ -88,22 +117,10 @@ public static boolean isBot(LivingEntity entity){
return true;
}

if (get().noIllegalName.value && isIllegalName(player)) {
return true;
}

if (get().noFakeID.value && isFakeEntityId(player)) {
return true;
}

if (get().noGamemode.value && hasNoGamemode(player)) {
return true;
}

if (get().noIllegalPitch.value && isIllegalPitch(player)) {
return true;
}

if (get().noNPC.value) {
return mc.getNetworkHandler().getPlayerListEntry(player.getUuid()) == null;
}
Expand All @@ -113,17 +130,18 @@ public static boolean isBot(LivingEntity entity){
}


private static boolean isIllegalName(PlayerEntity player) {
String name = player.getName().getString();
private static boolean hasIllegalName(LivingEntity entity) {
if(entity.getName() == null) return true;
String name = entity.getName().getString();
return name.length() < 3 || name.length() > 16 || !name.matches("^[a-zA-Z0-9_]+$");
}

private static boolean isIllegalPitch(PlayerEntity player) {
return player.getPitch(1.0F) > 90.0F;
private static boolean hasIllegalPitch(Entity entity) {
return entity.getPitch(1.0F) > 90.0F;
}

private static boolean isFakeEntityId(PlayerEntity player) {
double entityId = player.getId();
private static boolean isFakeEntityId(LivingEntity entity) {
double entityId = entity.getId();
return entityId < 1.0 || entityId >= 1E+9;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public void onTick(TickEvent.PLAYER event) {
if (flintAndSteelSlot != -1 && mc.player.getInventory().selectedSlot != flintAndSteelSlot) {
hasSwitched = InventoryUtils.swapToSlot(flintAndSteelSlot, swapBack.value);
} else if (flintAndSteelSlot == -1) {
ChatUtils.sendHeliosMsg(ColorUtils.darkRed +"Flint and Steel not found in hotbar, disabling...");
ChatUtils.sendHeliosMsg(ColorUtils.darkRed + "Flint and Steel not found in hotbar, disabling...");
toggle();
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ public class Painter extends Module_ {
.description("Locks canvas to the current set direction and position or unlocks the canvas to return to normal")
.build()
);

KeyBind lockCanvasKey = sgGeneral.add(new KeyBind.Builder()
.name("Lock Canvas Key")
.description("Keybind to lock canvas")
Expand Down Expand Up @@ -245,6 +244,7 @@ public class Painter extends Module_ {
.shouldRender(() -> !useBlockMapColor.value)
.build()
);

private int ticksPassed = 0;

public Painter() {
Expand Down Expand Up @@ -291,10 +291,10 @@ public Painter() {
@SubscribeEvent
public void keyPressedEvent(KeyPressedEvent e) {
if (e.getKey() == lockCanvasKey.value) {
if (!isLocked) {
lock();
} else {
if (isLocked) {
unlock();
} else {
lock();
}
}
}
Expand All @@ -307,16 +307,14 @@ public void onEnable() {
loadCanvas();
}



private void loadCanvas(){
if (structure.getOption() == Structure.Custom && painterFile == null) {
ChatUtils.sendHeliosMsg("Paint file has not been selected! Toggling off...");
toggle();
} else if(painterFile != null){
CANVAS_MAP = PainterFileParser.parseFile(painterFile);
}else {
} else if(painterFile == null){
CANVAS_MAP = PainterFileParser.parseString(((Structure)structure.getOption()).structureString);
}else {
CANVAS_MAP = PainterFileParser.parseFile(painterFile);
}
}

Expand All @@ -340,7 +338,7 @@ public void onTick(TickEvent.CLIENT event) {

//Experimental, if a block is supposed to be an air, but it is not, then try to break it
if ((block == Blocks.AIR || block == Blocks.CAVE_AIR) && !mc.world.isAir(pos) && BlockUtils.canBreak(pos, state)) {
int fastestTool = InventoryUtils.getFastestTool(state, true);
int fastestTool = InventoryUtils.getFastestTool(state, false);
//Slot may be -1
if (fastestTool != -1 || forceBreak.value) {
InventoryUtils.swapToSlot(fastestTool, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,25 +95,25 @@ public void renderCompact(DrawContext drawContext, int x, int y, int mouseX, int

String trimmedName = FontRenderers.Small_fxfontRenderer.trimToWidth(name,moduleWidth - 12);
FontRenderers.Small_fxfontRenderer.drawString(drawContext.getMatrices(), trimmedName, x + 2, y + 2, ColorManager.INSTANCE.defaultTextColor());
double diff = Math.min(moduleWidth - 10, Math.max(0, (mouseX - x)));
double diff = Math.min(moduleWidth - 4, Math.max(0, (mouseX - x)));

if (sliding) {
if (diff <= 0) {
value = min;
} else {
value = MathUtils.round(((diff / (moduleWidth - 10)) * (max - min) + min), roundingPlace);
value = MathUtils.round(((diff / (moduleWidth - 4)) * (max - min) + min), roundingPlace);
}
postSettingChange();
}
value = MathHelper.clamp(value, min, max);

//Draw the value beside the name
String valueString = "" + MathUtils.round(value, roundingPlace);
FontRenderers.Small_fxfontRenderer.drawString(drawContext.getMatrices(), valueString, (x + moduleWidth - 10) - FontRenderers.Small_fxfontRenderer.getStringWidth(valueString), y + 2, ColorManager.INSTANCE.defaultTextColor());
FontRenderers.Small_fxfontRenderer.drawString(drawContext.getMatrices(), valueString, (x + moduleWidth - 4) - FontRenderers.Small_fxfontRenderer.getStringWidth(valueString), y + 2, ColorManager.INSTANCE.defaultTextColor());

//Draw the slider itself and the background fill
Renderer2D.drawRoundedRectangle(drawContext.getMatrices().peek().getPositionMatrix(), x + 2, y + 16, moduleWidth - 8, 2, 1, 0xFFAAAAAA);
int scaledValue = (int) ((value - min) / (max - min) * (moduleWidth - 10)) + 2;
Renderer2D.drawRoundedRectangle(drawContext.getMatrices().peek().getPositionMatrix(), x + 2, y + 16, moduleWidth - 4, 2, 1, 0xFFAAAAAA);
int scaledValue = (int) ((value - min) / (max - min) * (moduleWidth - 4)) + 2;
Renderer2D.drawRoundedRectangle(drawContext.getMatrices().peek().getPositionMatrix(), x + 2, y + 16, scaledValue, 2, 1, 0xFF55FFFF);

//Slider Bar which moves and cartoony shadow
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,19 @@

import dev.heliosclient.HeliosClient;
import dev.heliosclient.managers.GradientManager;
import dev.heliosclient.module.settings.buttonsetting.Button;
import dev.heliosclient.module.settings.lists.ListSetting;
import dev.heliosclient.ui.clickgui.gui.tables.Table;
import dev.heliosclient.ui.clickgui.gui.tables.TableEntry;
import dev.heliosclient.ui.clickgui.settings.GradientSettingScreen;
import dev.heliosclient.util.fontutils.FontRenderers;
import dev.heliosclient.util.interfaces.ISettingChange;
import dev.heliosclient.util.render.Renderer2D;
import dev.heliosclient.util.render.Renderer3D;
import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.DrawContext;
;

import java.awt.*;
import java.util.*;
import java.util.List;
import java.util.*;
import java.util.function.BooleanSupplier;

public class GradientSetting extends ParentScreenSetting<GradientManager.Gradient> {
Expand Down Expand Up @@ -202,7 +200,7 @@ public void setValue(GradientManager.Gradient value) {
}

public static class GradientEntry implements TableEntry{
public double x,y,width = 50;
public double x,y,width = 62;
public final GradientManager.Gradient gradient;

public GradientEntry(GradientManager.Gradient gradient) {
Expand Down
Loading

0 comments on commit b38fb09

Please sign in to comment.