diff --git a/build.gradle b/build.gradle index 0df0f2a..cb6e2d8 100644 --- a/build.gradle +++ b/build.gradle @@ -16,6 +16,10 @@ repositories { // See https://docs.gradle.org/current/userguide/declaring_repositories.html maven { url "https://maven.shedaniel.me/" } maven { url "https://maven.terraformersmc.com/releases/" } + maven { + name 'Xander Maven' + url 'https://maven.isxander.dev/releases' + } } allprojects { repositories { @@ -31,16 +35,13 @@ dependencies { minecraft "com.mojang:minecraft:${project.minecraft_version}" mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2" modImplementation "net.fabricmc:fabric-loader:${project.loader_version}" - modApi("me.shedaniel.cloth:cloth-config-fabric:11.0.99") { - exclude(group: "net.fabricmc.fabric-api") - } + modApi "me.shedaniel.cloth:cloth-config-fabric:13.0.121" //DynamicHUD - modImplementation 'com.github.V-Fast:DynamicHUD:1.2.0-1' - - + modImplementation "dev.isxander.yacl:yet-another-config-lib-fabric:3.3.2+1.20.4" + modApi 'com.github.V-Fast:DynamicHUD:2.0.0' // Mod Menu - modApi "com.terraformersmc:modmenu:7.0.1" + modApi "com.terraformersmc:modmenu:9.0.0" // Fabric API. This is technically optional, but you probably want it anyway. modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" diff --git a/gradle.properties b/gradle.properties index 75db00a..9e16b25 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,17 +1,17 @@ # Done to increase the memory available to gradle. -org.gradle.jvmargs=-Xmx1G +org.gradle.jvmargs=-Xmx3G org.gradle.parallel=true # Fabric Properties - # check these on https://fabricmc.net/develop -minecraft_version=1.20.1 -yarn_mappings=1.20.1+build.1 -loader_version=0.14.21 +# check these on https://fabricmc.net/develop +minecraft_version=1.20.4 +yarn_mappings=1.20.4+build.1 +loader_version=0.15.0 # Mod Properties - mod_version = 2.5.2 + mod_version = 2.6 maven_group = net.smphack archives_base_name = smp-hack # Dependencies -fabric_version=0.83.0+1.20.1 \ No newline at end of file +fabric_version=0.91.1+1.20.4 \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 37aef8d..fe4d52e 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip networkTimeout=10000 zipStoreBase=GRADLE_USER_HOME -zipStorePath=wrapper/dists +zipStorePath=wrapper/dists \ No newline at end of file diff --git a/src/main/java/net/fabricmc/smphack/HUDoverlay.java b/src/main/java/net/fabricmc/smphack/HUDoverlay.java index 01128fd..d88ac90 100644 --- a/src/main/java/net/fabricmc/smphack/HUDoverlay.java +++ b/src/main/java/net/fabricmc/smphack/HUDoverlay.java @@ -127,7 +127,7 @@ public void onHudRender(DrawContext drawContext, float tickDelta) { //To stop rendering if debug screen or F3 menu is enabled - if (mc.options.debugEnabled) {return;} + if (mc.getDebugHud().shouldShowDebugHud()) {return;} //To avoid null crashes if (Formatting.RED.getColorValue() == null || Formatting.BLUE.getColorValue() == null || Formatting.WHITE.getColorValue() == null || Formatting.GREEN.getColorValue() == null) { diff --git a/src/main/java/net/fabricmc/smphack/Hacks/Fakeplayer/FakePlayerEntity.java b/src/main/java/net/fabricmc/smphack/Hacks/Fakeplayer/FakePlayerEntity.java index 60d8a4b..63b8d9d 100644 --- a/src/main/java/net/fabricmc/smphack/Hacks/Fakeplayer/FakePlayerEntity.java +++ b/src/main/java/net/fabricmc/smphack/Hacks/Fakeplayer/FakePlayerEntity.java @@ -34,7 +34,7 @@ public void spawn(PlayerEntity player) { this.setPose(player.getPose()); this.getInventory().clone(player.getInventory()); assert mc.world != null; - mc.world.addEntity(getId(), this); + mc.world.addEntity(this); System.out.println("FakePlayer Spawned Instance: " + this); } public void clear() { diff --git a/src/main/java/net/fabricmc/smphack/MainGui.java b/src/main/java/net/fabricmc/smphack/MainGui.java index 8b51bad..1a6513b 100644 --- a/src/main/java/net/fabricmc/smphack/MainGui.java +++ b/src/main/java/net/fabricmc/smphack/MainGui.java @@ -2,7 +2,7 @@ public abstract class MainGui { - // i dont know why am i Using this. Yes i am bad at OOP + // i dont know why am i using this. Yes i am bad at OOP public boolean enabled=false; public void toggled(){ enabled=!enabled; diff --git a/src/main/java/net/fabricmc/smphack/RGBtext/CharacterMode.java b/src/main/java/net/fabricmc/smphack/RGBtext/CharacterMode.java index 4cd3fa3..83c2609 100644 --- a/src/main/java/net/fabricmc/smphack/RGBtext/CharacterMode.java +++ b/src/main/java/net/fabricmc/smphack/RGBtext/CharacterMode.java @@ -54,7 +54,7 @@ public static void init() { //font TextRenderer font = mc.textRenderer; if (font == null || mc.player == null) return; - if (mc.options.debugEnabled) return; + if (mc.getDebugHud().shouldShowDebugHud()) return; PlayerEntity player = MinecraftClient.getInstance().player; if (GeneralConfig.getConfig() == null) { return; @@ -64,13 +64,11 @@ public static void init() { //Start of variables TextShadow = GeneralConfig.getConfig().getTextshadow(); - String CoordSide = String.valueOf(config.Coordside); coordinates(player); displayposandcolour(font); int x_offset = 0; //End of initializing variables; - String text = "XYZ " + xp + " " + yp + " " + zp; - String LOGO = "SMP-Hack v2-5-0"; + String LOGO = "SMP-Hack v2-6"; int stringWidth = font.getWidth(LOGO); for (int i = 0; i < LOGO.length(); i++) { @@ -82,42 +80,7 @@ public static void init() { x_offset += charWidth; } - // Calculate text width and colors - int textWidth = font.getWidth(text); - Color[] colors = new Color[text.length()]; - for (int i = 0; i < text.length(); i++) { - float hueOffset = i / (float) text.length(); - colors[i] = Color.getHSBColor(hue + hueOffset, 1, 1); - } - - // Draw coordinate text - for (int i = 0; i < text.length(); i++) { - char c = text.charAt(i); - int width = font.getWidth(String.valueOf(c)); - switch (CoordSide) { - case "TopRight" -> { - tsw = screenWidth - textWidth - 20 + i * width; - y = 16; - } - case "BottomRight" -> { - tsw = screenWidth - textWidth - 20 + i * width; - y = windowHeight - font.fontHeight - 10; - } - case "BottomLeft" -> { - tsw = (tw + i * width); - y = windowHeight - font.fontHeight - 23; - } - case "Top" -> { - tsw = (((screenWidth - textWidth) / 2) + i * width) - 2; - y = 5; - } - - } - rendertext(drawContext, font, String.valueOf(c), tsw, y, colors[i].getRGB()); - } - } - }); } } diff --git a/src/main/java/net/fabricmc/smphack/hud/ArmorWidgetExtension.java b/src/main/java/net/fabricmc/smphack/hud/ArmorWidgetExtension.java deleted file mode 100644 index ecc1720..0000000 --- a/src/main/java/net/fabricmc/smphack/hud/ArmorWidgetExtension.java +++ /dev/null @@ -1,88 +0,0 @@ -package net.fabricmc.smphack.hud; - -import com.tanishisherewith.dynamichud.helpers.ColorHelper; -import com.tanishisherewith.dynamichud.helpers.TextureHelper; -import com.tanishisherewith.dynamichud.interfaces.TextGenerator; -import com.tanishisherewith.dynamichud.widget.armor.ArmorWidget; -import net.fabricmc.smphack.config.ConfigUtil; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.gui.DrawContext; -import net.minecraft.entity.EquipmentSlot; -import net.minecraft.item.ItemStack; - -import java.awt.*; -import java.util.Objects; -import java.util.function.Supplier; - -public class ArmorWidgetExtension extends ArmorWidget { - /** - * Constructs an ArmorWidget object. - * - * @param client The Minecraft client instance - * @param slot The equipment slot to display the armor item from - * @param xPercent The x position of the widget as a percentage of the screen width - * @param yPercent The y position of the widget as a percentage of the screen height - * @param enabled - * @param currentTextPosition - * @param textGenerator - * @param color - */ - public ArmorWidgetExtension(MinecraftClient client, EquipmentSlot slot, float xPercent, float yPercent, boolean enabled, TextureHelper.Position currentTextPosition, TextGenerator textGenerator, Supplier color, boolean TextBackground,String label) { - super(client, slot, xPercent, yPercent, enabled, currentTextPosition, textGenerator, color,TextBackground,label); - } - private static final int COLOR_GREEN = 0x00FF00; - private static final int COLOR_YELLOW = 0xFFFF00; - private static final int COLOR_RED = 0xFF0000; - - public static int getDurabilityColor(float durability) { - if (durability > 0.5) { - return interpolateColors(COLOR_YELLOW, COLOR_GREEN, (durability - 0.5f) * 2); - } else { - return interpolateColors(COLOR_RED, COLOR_YELLOW, durability * 2); - } - } - - private static int interpolateColors(int color1, int color2, float factor) { - int red = (int) (((color1 >> 16) & 0xFF) * (1 - factor) + ((color2 >> 16) & 0xFF) * factor); - int green = (int) (((color1 >> 8) & 0xFF) * (1 - factor) + ((color2 >> 8) & 0xFF) * factor); - int blue = (int) ((color1 & 0xFF) * (1 - factor) + (color2 & 0xFF) * factor); - return (red << 16) | (green << 8) | blue; - } - - - @Override - public void render(DrawContext drawContext) { - super.render(drawContext); - String ArmorDurabilityDisplay = String.valueOf(ConfigUtil.config.ArmorDurability); - int x=0; - int y=0; - if (Objects.equals(ArmorDurabilityDisplay, "Bar")) { - ItemStack stack = MinecraftClient.getInstance().player.getEquippedStack(slot); - if (!stack.isEmpty()) { - double durabilityPercentage = ((double) stack.getMaxDamage() - (double) stack.getDamage()) / (double) stack.getMaxDamage(); - int barWidth = Math.round((float)durabilityPercentage * 16); - Color color= ColorHelper.getColorFromInt(getDurabilityColor((float)durabilityPercentage)); - switch (currentTextPosition[0]) { - case ABOVE -> { - x = getX(); - y = getY(); - } - case BELOW -> { - x = getX(); - y = getY() + 16; - } - case LEFT -> { - x = getX() - 18; - y = getY() + 8; - } - case RIGHT -> { - x = getX() + 18; - y = getY() + 8; - } - } - drawContext.fill( x, y + 1, x + 16, y - 1, Color.BLACK.getRGB()); - drawContext.fill( x, y, x + barWidth, y - 1, color.getRGB()); - } - } - } -} diff --git a/src/main/java/net/fabricmc/smphack/hud/DynamicHUDIntegration.java b/src/main/java/net/fabricmc/smphack/hud/DynamicHUDIntegration.java new file mode 100644 index 0000000..d299d3b --- /dev/null +++ b/src/main/java/net/fabricmc/smphack/hud/DynamicHUDIntegration.java @@ -0,0 +1,170 @@ +package net.fabricmc.smphack.hud; + +import com.tanishisherewith.dynamichud.DynamicHudIntegration; +import com.tanishisherewith.dynamichud.screens.AbstractMoveableScreen; +import com.tanishisherewith.dynamichud.utils.DynamicValueRegistry; +import com.tanishisherewith.dynamichud.widget.Widget; +import com.tanishisherewith.dynamichud.widget.WidgetManager; +import com.tanishisherewith.dynamichud.widget.WidgetRenderer; +import com.tanishisherewith.dynamichud.widgets.TextWidget; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.gui.screen.TitleScreen; +import net.minecraft.client.network.ClientPlayerEntity; +import net.minecraft.client.network.PlayerListEntry; +import net.minecraft.registry.RegistryKey; +import net.minecraft.text.Text; + +import java.awt.*; +import java.text.DecimalFormat; +import java.util.List; +import java.util.Optional; + +import static net.fabricmc.loader.impl.util.StringUtil.capitalize; +import static net.fabricmc.smphack.Hacks.Fly.Modes.BoatFly.BoatFlyHack.player; + +public class DynamicHUDIntegration implements DynamicHudIntegration { + static MinecraftClient mc = MinecraftClient.getInstance(); + TextWidget coordsWidget, fpsWidget, biomeWidget,pingWidget,speedWidget; + MuppetWidget muppetWidget; + WidgetRenderer renderer; + + public static int getPing() { + assert mc.player != null; + PlayerListEntry entry = mc.player.networkHandler.getPlayerListEntry(mc.player.getUuid()); + if (entry != null) { + return entry.getLatency(); // This method updates slow + } + return 0; + } + + public static String getBiome() { + String biomes = ""; + if (mc.world != null) { + Optional> biome = mc.world.getBiome(player.getBlockPos()).getKey(); + + if (biome.isPresent()) { + String biomeName = Text.translatable("biome." + biome.get().getValue().getNamespace() + "." + biome.get().getValue().getPath()).getString(); + biomes = Text.translatable("text.biome", capitalize(biomeName)).getString(); + } + } + return biomes.trim(); + } + private static String getSpeed(){ + String bps = "0.0f"; + ClientPlayerEntity player = mc.player; + if(player != null) { + double deltaX, deltaY, deltaZ; + deltaX = player.getX() - player.prevX; + deltaY = player.getY() - player.prevY; + deltaZ = player.getZ() - player.prevZ; + float floatbps = (float) Math.abs(Math.sqrt(Math.pow(deltaX, 2) + Math.pow(deltaY, 2) + Math.pow(deltaZ, 2)) * 20); + DecimalFormat df = new DecimalFormat("#.#"); + bps = df.format(floatbps); + } + return bps; + } + + @Override + public void init() { + DynamicValueRegistry.registerGlobal("Coordinates", () -> { + int x = 0, y = 0, z = 0; + if (mc.player != null) { + x = (int) mc.player.getX(); + y = (int) mc.player.getY(); + z = (int) mc.player.getZ(); + } + return "XYZ: " + x + " " + y + " " + z; + }); + DynamicValueRegistry.registerGlobal("Biome", () ->"Biome: "+ getBiome()); + DynamicValueRegistry.registerGlobal("Ping", () ->"Ping: " + getPing()); + DynamicValueRegistry.registerGlobal("BPS", () -> "BPS: " + getSpeed()); + DynamicValueRegistry.registerGlobal("FPS", () -> "FPS: " + mc.getCurrentFps()); + + coordsWidget = new TextWidget.Builder() + .setX(10) + .setY(50) + .setDRKey("Coordinates") + .rainbow(true) + .shadow(false) + .setTextColor(Color.WHITE) + .setModID("smphack") + .shouldScale(true) + .build(); + fpsWidget = new TextWidget.Builder() + .setX(10) + .setY(55) + .setDRKey("FPS") + .rainbow(true) + .shadow(false) + .setTextColor(Color.WHITE) + .setModID("smphack") + .shouldScale(true) + .build(); + biomeWidget = new TextWidget.Builder() + .setX(10) + .setY(60) + .setDRKey("Biome") + .rainbow(true) + .shadow(false) + .setTextColor(Color.WHITE) + .setModID("smphack") + .shouldScale(true) + .build(); + speedWidget = new TextWidget.Builder() + .setX(10) + .setY(65) + .setDRKey("BPS") + .rainbow(true) + .shadow(false) + .setTextColor(Color.WHITE) + .setModID("smphack") + .shouldScale(true) + .build(); + pingWidget = new TextWidget.Builder() + .setX(10) + .setY(70) + .setDRKey("Ping") + .rainbow(true) + .shadow(false) + .setTextColor(Color.WHITE) + .setModID("smphack") + .shouldScale(true) + .build(); + + muppetWidget = new MuppetWidget("smphack"); + muppetWidget.shouldScale = true; + muppetWidget.setPosition(20,60); + } + @Override + public void addWidgets() { + WidgetManager.addWidgets( + coordsWidget, + muppetWidget); + } + + @Override + public void registerCustomWidgets() { + WidgetManager.registerCustomWidgets(MuppetWidget.DATA); + } + + @Override + public void initAfter() { + List widgets = WidgetManager.getWidgetsForMod("smphack"); + + renderer = new WidgetRenderer(widgets); + renderer.shouldRenderInGameHud(true); + renderer.addScreen(TitleScreen.class); + } + + @Override + public AbstractMoveableScreen getMovableScreen() { + return new AbstractMoveableScreen(Text.of("Editor Screen"),renderer) { + }; + } + + @Override + public WidgetRenderer getWidgetRenderer() { + return renderer; + } + +} diff --git a/src/main/java/net/fabricmc/smphack/hud/DynamicHudClient.java b/src/main/java/net/fabricmc/smphack/hud/DynamicHudClient.java deleted file mode 100644 index b31efcc..0000000 --- a/src/main/java/net/fabricmc/smphack/hud/DynamicHudClient.java +++ /dev/null @@ -1,220 +0,0 @@ -package net.fabricmc.smphack.hud; - -import com.tanishisherewith.dynamichud.DynamicHUD; -import com.tanishisherewith.dynamichud.helpers.ColorHelper; -import com.tanishisherewith.dynamichud.helpers.TextureHelper; -import com.tanishisherewith.dynamichud.interfaces.IWigdets; -import com.tanishisherewith.dynamichud.interfaces.WidgetLoading; -import com.tanishisherewith.dynamichud.util.DynamicUtil; -import com.tanishisherewith.dynamichud.widget.Widget; -import com.tanishisherewith.dynamichud.widget.item.ItemWidget; -import com.tanishisherewith.dynamichud.widget.text.TextWidget; -import net.fabricmc.api.ClientModInitializer; -import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents; -import net.fabricmc.smphack.GeneralConfig; -import net.fabricmc.smphack.config.ConfigUtil; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.network.ClientPlayerEntity; -import net.minecraft.client.network.PlayerListEntry; -import net.minecraft.entity.EquipmentSlot; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.ItemStack; -import net.minecraft.item.Items; -import net.minecraft.nbt.NbtCompound; -import net.minecraft.registry.RegistryKey; -import net.minecraft.text.Text; -import net.minecraft.world.biome.Biome; - -import java.awt.*; -import java.text.DecimalFormat; -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; -import java.util.Set; - -import static com.tanishisherewith.dynamichud.DynamicHUD.WIDGETS_FILE; -import static net.fabricmc.loader.impl.util.StringUtil.capitalize; - -public class DynamicHudClient implements ClientModInitializer, IWigdets, WidgetLoading { - private static final int COLOR_GREEN = 0x00FF00; - private static final int COLOR_YELLOW = 0xFFFF00; - private static final int COLOR_RED = 0xFF0000; - static MinecraftClient mc = MinecraftClient.getInstance(); - static int fps; - static int ping; - static String Biome; - static double deltaX, deltaY, deltaZ, floatbps; - static String bps; - protected List widgets = new ArrayList<>(); - private DynamicUtil dynamicutil; - private String ArmorDurabilityDisplay; - private Color color = Color.RED; - static ClientPlayerEntity player; - - - public static int getDurabilityColor(float durability) { - if (durability > 0.5) { - return interpolateColors(COLOR_YELLOW, COLOR_GREEN, (durability - 0.5f) * 2); - } else { - return interpolateColors(COLOR_RED, COLOR_YELLOW, durability * 2); - } - } - - private static int interpolateColors(int color1, int color2, float factor) { - int red = (int) (((color1 >> 16) & 0xFF) * (1 - factor) + ((color2 >> 16) & 0xFF) * factor); - int green = (int) (((color1 >> 8) & 0xFF) * (1 - factor) + ((color2 >> 8) & 0xFF) * factor); - int blue = (int) ((color1 & 0xFF) * (1 - factor) + (color2 & 0xFF) * factor); - return (red << 16) | (green << 8) | blue; - } - - private static void getVariableValues() { - deltaX = player.getX() - player.prevX; - deltaY = player.getY() - player.prevY; - deltaZ = player.getZ() - player.prevZ; - floatbps = (float) Math.abs(Math.sqrt(Math.pow(deltaX, 2) + Math.pow(deltaY, 2) + Math.pow(deltaZ, 2)) * 20); - DecimalFormat df = new DecimalFormat("#.#"); - bps = df.format(floatbps); - ping = getValue(); - fps = mc.getCurrentFps(); - Biome = getBiome(); - } - - public static int getValue() { - assert mc.player != null; - PlayerListEntry entry = mc.player.networkHandler.getPlayerListEntry(mc.player.getUuid()); - if (entry != null) { - return entry.getLatency(); // This method updates slow - } - return 0; - } - - public static String getBiome() { - String biomes = ""; - if (mc.world != null) { - Optional> biome = mc.world.getBiome(player.getBlockPos()).getKey(); - - if (biome.isPresent()) { - String biomeName = Text.translatable("biome." + biome.get().getValue().getNamespace() + "." + biome.get().getValue().getPath()).getString(); - biomes = Text.translatable("text.biome", capitalize(biomeName)).getString(); - } - } - return biomes.trim(); - } - - @Override - public void onInitializeClient() { - dynamicutil = (DynamicHUD.getDynamicUtil()==null)?new DynamicUtil(mc):DynamicHUD.getDynamicUtil(); - widgets.clear(); - - DynamicHUD.setAbstractScreen(new MoveableScreenExtension(Text.of("Editors Screen"), dynamicutil)); - DynamicHUD.setIWigdets(new DynamicHudClient()); - ClientTickEvents.START_WORLD_TICK.register(world -> { - if(mc.player!=null) { - player=mc.player; - getVariableValues(); - } - }); - } - - @Override - public void addWigdets(DynamicUtil dynamicUtil) { - if (mc.player!=null) { - boolean shadow = GeneralConfig.getConfig().getTextshadow(); - widgets.add(new ArmorWidgetExtension(mc, EquipmentSlot.HEAD, 0.1f, 0.9f, true, TextureHelper.Position.ABOVE, () -> getDurabilityForStack(mc.player.getEquippedStack(EquipmentSlot.HEAD)), () -> color, true, "HeadArmor")); - widgets.add(new ArmorWidgetExtension(mc, EquipmentSlot.CHEST, 0.15f, 0.9f, true, TextureHelper.Position.ABOVE, () -> getDurabilityForStack(mc.player.getEquippedStack(EquipmentSlot.CHEST)), () -> color, true, "ChestArmor")); - widgets.add(new ArmorWidgetExtension(mc, EquipmentSlot.LEGS, 0.2f, 0.9f, true, TextureHelper.Position.ABOVE, () -> getDurabilityForStack(mc.player.getEquippedStack(EquipmentSlot.LEGS)), () -> color, true, "LegArmor")); - widgets.add(new ArmorWidgetExtension(mc, EquipmentSlot.FEET, 0.25f, 0.9f, true, TextureHelper.Position.ABOVE, () -> getDurabilityForStack(mc.player.getEquippedStack(EquipmentSlot.FEET)), () -> color, true, "FootArmor")); - - widgets.add(new TextWidget(mc, "FPS: ", () -> String.valueOf(fps), 0.05f, 0.7f, shadow, true, Color.WHITE.getRGB(), Color.WHITE.getRGB(), true)); - widgets.add(new TextWidget(mc, "BPS: ", () -> String.valueOf(bps), 0.05f, 0.75f, shadow, true, Color.WHITE.getRGB(), Color.WHITE.getRGB(), true)); - widgets.add(new TextWidget(mc, "Ping: ", () -> String.valueOf(ping), 0.05f, 0.8f, shadow, true, Color.WHITE.getRGB(), Color.WHITE.getRGB(), true)); - widgets.add(new TextWidget(mc, "", () -> String.valueOf(Biome), 0.05f, 0.85f, shadow, true, Color.WHITE.getRGB(), Color.WHITE.getRGB(), true)); - - widgets.add(new ItemWidget(mc, Items.TOTEM_OF_UNDYING::getDefaultStack, 0.3f, 0.9f, true, TextureHelper.Position.ABOVE, () -> String.valueOf(mc.player.getInventory().count(Items.TOTEM_OF_UNDYING)), () -> Color.YELLOW, true, "Totem")); - - widgets.add(new MuppetWidget(mc, 0.9f, 0.8f, true, "InGameMuppet")); - - for (Widget wigdet : widgets) { - dynamicUtil.getWidgetManager().addWidget(wigdet); - } - dynamicUtil.WidgetAdded = true; - - } - } - - @Override - public void addMainMenuWigdets(DynamicUtil dynamicUtil) { - dynamicUtil.MainMenuWidgetAdded=true; - } - - public void setColor(Color color) { - this.color = color; - } - - private String getDurabilityForStack(ItemStack stack) { - String durabilityText = null; - PlayerEntity player = MinecraftClient.getInstance().player; - if (player != null) { - ArmorDurabilityDisplay = String.valueOf(ConfigUtil.config.ArmorDurability); - double durabilityPercentage = ((double) stack.getMaxDamage() - (double) stack.getDamage()) / (double) stack.getMaxDamage(); - durabilityText = (int) (durabilityPercentage * 100.0D) + "%"; - setColor(ColorHelper.getColorFromInt(getDurabilityColor((float) durabilityPercentage))); - switch (ArmorDurabilityDisplay) { - case "Percent" -> { - //Percent Display - return (stack.getDamage() > 0) ? durabilityText : null; - } - case "Bar" -> { - // Bar display - return null; - } - case "Number" -> { - //Number display - return (stack.getDamage() > 0) ? stack.getMaxDamage() - stack.getDamage() + "/" + stack.getMaxDamage() : null; - } - } - } - return durabilityText; - } - - @Override - public void loadWigdets(DynamicUtil dynamicUtil) { - dynamicUtil.getWidgetManager().setWidgetLoading(new DynamicHudClient()); - Set widgets = dynamicUtil.getWidgetManager().loadWigdets(WIDGETS_FILE); - assert mc.player != null; - - Widget.addTextGenerator("HeadArmor", () -> getDurabilityForStack(mc.player.getEquippedStack(EquipmentSlot.HEAD))); - Widget.addTextGenerator("ChestArmor", () -> getDurabilityForStack(mc.player.getEquippedStack(EquipmentSlot.CHEST))); - Widget.addTextGenerator("LegArmor", () -> getDurabilityForStack(mc.player.getEquippedStack(EquipmentSlot.LEGS))); - Widget.addTextGenerator("FootArmor", () -> getDurabilityForStack(mc.player.getEquippedStack(EquipmentSlot.FEET))); - Widget.addTextGenerator("Totem", () -> String.valueOf(mc.player.getInventory().count(Items.TOTEM_OF_UNDYING))); - - Widget.addTextGenerator("FPS: ",()-> String.valueOf(fps)); - Widget.addTextGenerator("BPS: ",()-> String.valueOf(bps)); - Widget.addTextGenerator("Ping: ",()-> String.valueOf(ping)); - Widget.addTextGenerator("",()-> String.valueOf(Biome)); - - - for (Widget widget : widgets) { - dynamicUtil.getWidgetManager().addWidget(widget); - } - dynamicUtil.WidgetLoaded=true; - } - - @Override - public Widget loadWidgetsFromTag(String className, NbtCompound widgetTag) { - System.out.println("Loading widgets from tag"); - if (className.equals(MuppetWidget.class.getName())) { - MuppetWidget widget = new MuppetWidget(MinecraftClient.getInstance(), 0, 0, true,""); - widget.readFromTag(widgetTag); - return widget; - } - if (className.equals(ArmorWidgetExtension.class.getName())) { - ArmorWidgetExtension widget = new ArmorWidgetExtension(mc, EquipmentSlot.FEET, 0, 0, true, TextureHelper.Position.ABOVE, () -> "", () -> color,true,""); - widget.readFromTag(widgetTag); - return widget; - } - return WidgetLoading.super.loadWidgetsFromTag(className, widgetTag); - } - -} diff --git a/src/main/java/net/fabricmc/smphack/hud/MoveableScreenExtension.java b/src/main/java/net/fabricmc/smphack/hud/MoveableScreenExtension.java deleted file mode 100644 index 96e19d9..0000000 --- a/src/main/java/net/fabricmc/smphack/hud/MoveableScreenExtension.java +++ /dev/null @@ -1,35 +0,0 @@ -package net.fabricmc.smphack.hud; - -import com.tanishisherewith.dynamichud.huds.MoveableScreen; -import com.tanishisherewith.dynamichud.util.DynamicUtil; -import com.tanishisherewith.dynamichud.widget.Widget; -import net.minecraft.client.gui.DrawContext; -import net.minecraft.text.Text; - -public class MoveableScreenExtension extends MoveableScreen { - /** - * Constructs a AbstractMoveableScreen object. - * - * @param title - * @param dynamicutil The DynamicUtil instance used by this screen - */ - public MoveableScreenExtension(Text title, DynamicUtil dynamicutil) { - super(title, dynamicutil); - } - - @Override - protected void menu(Widget widget, int x, int y) { - super.menu(widget, x, y); - if (widget instanceof MuppetWidget) - { - contextMenus.clear(); - Sliders.clear(); - colorPicker=null; - } - } - - @Override - public void render(DrawContext drawContext, int mouseX, int mouseY, float delta) { - super.render(drawContext, mouseX, mouseY, delta); - } -} diff --git a/src/main/java/net/fabricmc/smphack/hud/MuppetWidget.java b/src/main/java/net/fabricmc/smphack/hud/MuppetWidget.java index 8ad103d..d877c5f 100644 --- a/src/main/java/net/fabricmc/smphack/hud/MuppetWidget.java +++ b/src/main/java/net/fabricmc/smphack/hud/MuppetWidget.java @@ -1,75 +1,85 @@ package net.fabricmc.smphack.hud; +import com.mojang.blaze3d.systems.RenderSystem; import com.tanishisherewith.dynamichud.widget.Widget; import com.tanishisherewith.dynamichud.widget.WidgetBox; +import com.tanishisherewith.dynamichud.widget.WidgetData; import net.fabricmc.smphack.GeneralConfig; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.screen.ingame.InventoryScreen; import net.minecraft.client.network.ClientPlayerEntity; +import net.minecraft.client.render.DiffuseLighting; +import net.minecraft.client.render.entity.EntityRenderDispatcher; +import net.minecraft.entity.LivingEntity; import net.minecraft.nbt.NbtCompound; import net.minecraft.util.math.MathHelper; +import org.joml.Matrix4f; +import org.joml.Quaternionf; +import org.joml.Vector3f; public class MuppetWidget extends Widget { - MinecraftClient mc=MinecraftClient.getInstance(); - /** - * Constructs a Widget object. - * - * @param client The Minecraft client instance - */ - public MuppetWidget(MinecraftClient client,float xPercent, float yPercent,boolean enabled, String label) { - super(client, label); - this.xPercent=xPercent; - this.yPercent=yPercent; - this.enabled=enabled; - } - @Override - public void setTextGeneratorFromLabel() { + public static WidgetData DATA = new WidgetData<>("Muppet","Shows a muppet on screen",MuppetWidget::new); + public MuppetWidget(){ + this("Empty"); } - @Override - public WidgetBox getWidgetBox() { - int boxWidth = 30; // Set the desired width of the widget box - int boxHeight = 60; // Set the desired height of the widget box - int x1 = this.getX(); - int y1 = this.getY(); - int x2 = this.getX() + boxWidth; - int y2 = this.getY() + boxHeight; - return new WidgetBox(x1, y1, x2, y2,scale); + public MuppetWidget(String modID) { + super(DATA,modID); } - - @Override - public void render(DrawContext drawContext) { + public void renderWidget(DrawContext context, int mouseX, int mouseY) { boolean showMuppet= GeneralConfig.getConfig().getShowMuppet(); //SHOW MUPPET - if (showMuppet) { - ClientPlayerEntity player=MinecraftClient.getInstance().player; - assert player != null; + ClientPlayerEntity player=MinecraftClient.getInstance().player; + if (showMuppet && player != null && player.getWorld() != null) { float yaw = MathHelper.wrapDegrees(player.prevYaw + (player.getYaw() - player.prevYaw) * mc.getTickDelta()); float pitch = player.getPitch(); - int x = this.getX(); - int y = this.getY(); - InventoryScreen.drawEntity(drawContext,x + 15,y + 54, (int) (25*scale), -yaw, -pitch, player); + drawEntity(context,x + 25/2,y + 25/2, (int) (25*scale),-yaw, -pitch, player); + widgetBox.setSizeAndPosition(x,y,25*scale,30*scale); } } - @Override - public void writeToTag(NbtCompound tag) { - super.writeToTag(tag); - tag.putString("class", getClass().getName()); - tag.putFloat("xPercent", xPercent); - tag.putFloat("yPercent", yPercent); - tag.putBoolean("Enabled", this.enabled); - } + public static void drawEntity(DrawContext context, int x, int y, int size, float mouseX, float mouseY, LivingEntity entity) { + float f = (float) Math.atan(mouseX / 40.0F); + float g = (float) Math.atan(mouseY / 40.0F); + Quaternionf quaternionf = (new Quaternionf()).rotateZ(3.1415927F); + Quaternionf quaternionf2 = (new Quaternionf()).rotateX(g * 20.0F * 0.017453292F); + quaternionf.mul(quaternionf2); + float h = entity.bodyYaw; + float i = entity.getYaw(); + float j = entity.getPitch(); + float k = entity.prevHeadYaw; + float l = entity.headYaw; + entity.bodyYaw = 360.0F + f * 20.0F; + entity.setYaw(360.0F + f * 40.0F); + entity.headYaw = entity.getYaw(); + entity.prevHeadYaw = entity.getYaw(); + context.getMatrices().push(); + context.getMatrices().translate(x, y, 50.0); + context.getMatrices().multiplyPositionMatrix((new Matrix4f()).scaling((float) size, (float) size, (float) (-size))); + context.getMatrices().multiply(quaternionf); + DiffuseLighting.method_34742(); + EntityRenderDispatcher entityRenderDispatcher = MinecraftClient.getInstance().getEntityRenderDispatcher(); + if (quaternionf2 != null) { + quaternionf2.conjugate(); + entityRenderDispatcher.setRotation(quaternionf2); + } - @Override - public void readFromTag(NbtCompound tag) { - super.readFromTag(tag); - xPercent = tag.getFloat("xPercent"); - yPercent = tag.getFloat("yPercent"); - enabled = tag.getBoolean("Enabled"); + entityRenderDispatcher.setRenderShadows(false); + RenderSystem.runAsFancy(() -> { + entityRenderDispatcher.render(entity, 0.0, 0.0, 0.0, 0.0F, MinecraftClient.getInstance().getTickDelta(), context.getMatrices(), context.getVertexConsumers(), 15728880); + }); + context.draw(); + entityRenderDispatcher.setRenderShadows(true); + context.getMatrices().pop(); + DiffuseLighting.enableGuiDepthLighting(); + entity.bodyYaw = h; + entity.setYaw(i); + entity.setPitch(j); + entity.prevHeadYaw = k; + entity.headYaw = l; } } diff --git a/src/main/java/net/fabricmc/smphack/mixins/PlayerEntityRendererMixin.java b/src/main/java/net/fabricmc/smphack/mixins/PlayerEntityRendererMixin.java index 7370000..7987047 100644 --- a/src/main/java/net/fabricmc/smphack/mixins/PlayerEntityRendererMixin.java +++ b/src/main/java/net/fabricmc/smphack/mixins/PlayerEntityRendererMixin.java @@ -10,6 +10,7 @@ import net.minecraft.client.render.entity.PlayerEntityRenderer; import net.minecraft.client.render.entity.model.PlayerEntityModel; import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.scoreboard.ScoreboardDisplaySlot; import net.minecraft.util.Identifier; import net.minecraft.util.math.MathHelper; import org.joml.Matrix4f; @@ -35,7 +36,7 @@ public void renderHealth(AbstractClientPlayerEntity abstractClientPlayerEntity, matrixStack.translate(0, abstractClientPlayerEntity.getHeight() + 0.5f, 0); if (this.hasLabel(abstractClientPlayerEntity) && d <= 4096.0) { matrixStack.translate(0.0D, 9.0F * 1.15F * 0.025F, 0.0D); - if (d < 100.0 && abstractClientPlayerEntity.getScoreboard().getObjectiveForSlot(2) != null) { + if (d < 100.0 && abstractClientPlayerEntity.getScoreboard().getObjectiveForSlot(ScoreboardDisplaySlot.LIST) != null) { matrixStack.translate(0.0D, 9.0F * 1.15F * 0.025F, 0.0D); } } diff --git a/src/main/java/net/fabricmc/smphack/mixins/TitleScreenMixin.java b/src/main/java/net/fabricmc/smphack/mixins/TitleScreenMixin.java index 7a95d97..4048575 100644 --- a/src/main/java/net/fabricmc/smphack/mixins/TitleScreenMixin.java +++ b/src/main/java/net/fabricmc/smphack/mixins/TitleScreenMixin.java @@ -4,6 +4,7 @@ import com.terraformersmc.modmenu.gui.ModsScreen; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; +import net.fabricmc.loader.api.FabricLoader; import net.fabricmc.smphack.GeneralConfig; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.DrawContext; @@ -45,8 +46,7 @@ public class TitleScreenMixin extends Screen { protected TitleScreenMixin(Text title) { super(title); } - - @Inject(at = @At("RETURN"), method = "render") + @Inject(at = @At("TAIL"), method = "render") private void render(DrawContext drawContext, int mouseX, int mouseY, float delta, CallbackInfo ci) { CustomScreen = GeneralConfig.getConfig().isCustomBG(); if (CustomScreen) { @@ -54,10 +54,28 @@ private void render(DrawContext drawContext, int mouseX, int mouseY, float delta if (this.backgroundFadeStart == 0L) { this.backgroundFadeStart = Util.getMeasuringTimeMs(); } + + // Smoothing factor + float smoothFactor = 0.09f; + + // Calculate the texture shift based on the mouse position + float shiftX = (float) mouseX / this.width - 0.5f; + float shiftY = (float) mouseY / this.height - 0.5f; + + // Apply the smoothing factor + shiftX *= smoothFactor; + shiftY *= smoothFactor; + + // Enlarge the texture and apply the shift + int textureWidth = this.width * 2; + int textureHeight = this.height * 2; + int textureX = (int) (-textureWidth / 4 + shiftX * this.width / 2); + int textureY = (int) (-textureHeight / 4 + shiftY * this.height / 2); + mc.getTextureManager().bindTexture(SPACE_BACKGROUND); RenderSystem.setShaderTexture(0, SPACE_BACKGROUND); RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, (float) MathHelper.ceil(MathHelper.clamp((float) (Util.getMeasuringTimeMs() - this.backgroundFadeStart) / 1000.0F, 0.0F, 1.0F))); - drawContext.drawTexture(SPACE_BACKGROUND,0, 0, 0, 0, MinecraftClient.getInstance().getWindow().getScaledWidth(), MinecraftClient.getInstance().getWindow().getScaledHeight(), MinecraftClient.getInstance().getWindow().getScaledWidth(), MinecraftClient.getInstance().getWindow().getScaledHeight()); + drawContext.drawTexture(SPACE_BACKGROUND, textureX, textureY, 0, 0, textureWidth, textureHeight, textureWidth, textureHeight); this.logoDrawer.draw(drawContext, mc.getWindow().getScaledWidth(), 255); } } @@ -100,11 +118,13 @@ public void renderButtons(DrawContext drawContext, int mouseX, int mouseY, float y += buttonHeight + spacing; - this.addDrawableChild(new PressableTextWidget((this.width/2) - 20, y, buttonWidth, buttonHeight, Text.translatable("Mods"), (button) -> { - mc.setScreen(new ModsScreen(this)); - }, this.textRenderer)); + if(FabricLoader.getInstance().isModLoaded("modmenu")) { + this.addDrawableChild(new PressableTextWidget((this.width / 2) - 20, y, buttonWidth, buttonHeight, Text.translatable("Mods"), (button) -> { + mc.setScreen(new ModsScreen(this)); + }, this.textRenderer)); - y += buttonHeight + spacing; + y += buttonHeight + spacing; + } this.addDrawableChild(new PressableTextWidget((this.width / 2) - 29, y, buttonWidth, buttonHeight, Text.translatable("menu.quit"), (button) -> { mc.stop(); diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index dacc72b..87e5ab7 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -19,14 +19,14 @@ "environment": "client", "entrypoints": { - "client": [ - "net.fabricmc.smphack.hud.DynamicHudClient" - ], "main": [ "net.fabricmc.smphack.MainHack", "net.fabricmc.smphack.GeneralConfig", "net.fabricmc.smphack.HealthIndicatorsMod" ], + "dynamicHud": [ + "net.fabricmc.smphack.hud.DynamicHUDIntegration" + ], "modmenu": [ "net.fabricmc.smphack.config.ModMenuIntegration" ]