diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 96e3ff215f..469a275350 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -14,21 +14,22 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - uses: actions/setup-java@v3 + - uses: actions/checkout@v4 + - uses: actions/setup-java@v4 with: distribution: 'temurin' - java-version: '17' - - name: Run Gradle - uses: gradle/gradle-build-action@v2 + java-version: '21' + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v3 with: gradle-version: current - arguments: build -Pcommit=${{ github.sha }} + - name: Build with Gradle + run: gradle build -Pcommit=${{ github.sha }} - uses: "marvinpinto/action-automatic-releases@latest" with: repo_token: "${{ secrets.GITHUB_TOKEN }}" - automatic_release_tag: "latest-1.20.4" + automatic_release_tag: "latest-1.20.6" prerelease: false - title: "1.20.4 Build" + title: "1.20.6 Build" files: | ./build/libs/*.jar diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index de5037e85d..7c20343b0c 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -11,7 +11,7 @@ jobs: - uses: actions/setup-java@v3 with: distribution: 'temurin' - java-version: '17' + java-version: '21' - name: Run Gradle uses: gradle/gradle-build-action@v2 diff --git a/build.gradle b/build.gradle index 7de8b05aac..d949b97c1c 100644 --- a/build.gradle +++ b/build.gradle @@ -1,12 +1,14 @@ plugins { - id "fabric-loom" version "1.5-SNAPSHOT" + id "fabric-loom" version "1.6-SNAPSHOT" id "maven-publish" id "com.github.johnrengelman.shadow" version "8.1.1" } -archivesBaseName = project.archives_base_name -version = project.mod_version -group = project.maven_group +base { + archivesBaseName = project.archives_base_name + version = project.mod_version + group = project.maven_group +} repositories { maven { @@ -87,61 +89,63 @@ afterEvaluate { } } -shadowJar { - configurations = [project.configurations.shadow] - - dependencies { - exclude { - it.moduleGroup == "org.slf4j" +tasks { + processResources { + def propertyMap = [ + "version" : project.version, + "minecraft_version": project.minecraft_version, + "loader_version" : project.loader_version + ] + + inputs.properties(propertyMap) + filesMatching("fabric.mod.json") { + expand(propertyMap) } } - destinationDirectory.set(new File(project.buildDir, "devlibs")) + jar { + from("LICENSE") { + rename { "${it}_${project.base.archivesBaseName}" } + } } -processResources { - def propertyMap = [ - "version" : project.version, - "minecraft_version": project.minecraft_version, - "loader_version" : project.loader_version - ] + java { + sourceCompatibility = JavaVersion.VERSION_21 + targetCompatibility = JavaVersion.VERSION_21 - inputs.properties(propertyMap) - filesMatching("fabric.mod.json") { - expand(propertyMap) + withSourcesJar() + withJavadocJar() } -} -jar { - from("LICENSE") { - rename { "${it}_${archivesBaseName}" } - } -} + shadowJar { + configurations = [project.configurations.shadow] -java { - sourceCompatibility = JavaVersion.VERSION_17 - targetCompatibility = JavaVersion.VERSION_17 + from("LICENSE") { + rename { "${it}_${project.base.archivesBaseName}" } + } - withSourcesJar() -} + destinationDirectory.set(new File(project.buildDir, "devlibs")) -remapJar { - dependsOn shadowJar - inputFile.set(shadowJar.archiveFile) -} + dependencies { + exclude { + it.moduleGroup == "org.slf4j" + } + } + } -javadoc { - options.addStringOption("Xdoclint:none", "-quiet") - options.encoding = "UTF-8" -} + remapJar { + dependsOn shadowJar + inputFile.set(shadowJar.archiveFile) + } -tasks.register("javadocJar", Jar) { - from javadoc - archiveClassifier.set("javadoc") -} + javadoc { + options.addStringOption("Xdoclint:none", "-quiet") + options.encoding = "UTF-8" + } -build { - dependsOn javadocJar + build { + dependsOn javadocJar + } } publishing { diff --git a/gradle.properties b/gradle.properties index cc103dc9f3..32068df7e0 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,13 +1,13 @@ org.gradle.jvmargs=-Xmx2G # Fabric (https://fabricmc.net/develop) -minecraft_version=1.20.4 -yarn_mappings=1.20.4+build.3 -loader_version=0.15.2 -fapi_version=0.95.3+1.20.4 +minecraft_version=1.20.6 +yarn_mappings=1.20.6+build.1 +loader_version=0.15.10 +fapi_version=0.97.8+1.20.6 # Mod Properties -mod_version=0.5.6 +mod_version=0.5.7 maven_group=meteordevelopment archives_base_name=meteor-client @@ -17,16 +17,16 @@ archives_base_name=meteor-client baritone_version=1.20.4 # Sodium (https://github.com/CaffeineMC/sodium-fabric) -sodium_version=mc1.20.3-0.5.7 +sodium_version=mc1.20.6-0.5.8 # Lithium (https://github.com/CaffeineMC/lithium-fabric) -lithium_version=mc1.20.4-0.12.1 +lithium_version=mc1.20.6-0.12.3 # Iris (https://github.com/IrisShaders/Iris) -iris_version=1.6.14+1.20.4 +iris_version=1.7.0+1.20.6 # Indium (https://github.com/comp500/Indium) -indium_version=1.0.28+mc1.20.4 +indium_version=1.0.30+mc1.20.4 # Orbit (https://github.com/MeteorDevelopment/orbit) orbit_version=0.2.4 @@ -35,7 +35,7 @@ orbit_version=0.2.4 starscript_version=0.2.2 # LibJF (https://gitlab.com/jfmods/libjf) -libjf_version=3.14.1 +libjf_version=3.15.6 # Reflections (https://github.com/ronmamo/reflections) reflections_version=0.10.2 diff --git a/src/main/java/meteordevelopment/meteorclient/MeteorClient.java b/src/main/java/meteordevelopment/meteorclient/MeteorClient.java index 31b5f07ff3..2ad7170894 100644 --- a/src/main/java/meteordevelopment/meteorclient/MeteorClient.java +++ b/src/main/java/meteordevelopment/meteorclient/MeteorClient.java @@ -153,7 +153,7 @@ private void onMouseButton(MouseButtonEvent event) { private void toggleGui() { if (Utils.canCloseGui()) mc.currentScreen.close(); - else if (Utils.canOpenGui()) Tabs.get().get(0).openScreen(GuiThemes.get()); + else if (Utils.canOpenGui()) Tabs.get().getFirst().openScreen(GuiThemes.get()); } // Hide HUD diff --git a/src/main/java/meteordevelopment/meteorclient/addons/GithubRepo.java b/src/main/java/meteordevelopment/meteorclient/addons/GithubRepo.java index cce14d539b..0ee4158f9f 100644 --- a/src/main/java/meteordevelopment/meteorclient/addons/GithubRepo.java +++ b/src/main/java/meteordevelopment/meteorclient/addons/GithubRepo.java @@ -5,12 +5,31 @@ package meteordevelopment.meteorclient.addons; -public record GithubRepo(String owner, String name, String branch) { +import meteordevelopment.meteorclient.utils.network.Http; + +import javax.annotation.Nullable; + +public record GithubRepo(String owner, String name, String branch, @Nullable String accessToken) { + public GithubRepo(String owner, String name, @Nullable String accessToken) { + this(owner, name, "master", accessToken); + } + public GithubRepo(String owner, String name) { - this(owner, name, "master"); + this(owner, name, "master", null); } public String getOwnerName() { return owner + "/" + name; } + + public void authenticate(Http.Request request) { + if (this.accessToken != null && !this.accessToken.isBlank()) { + request.bearer(this.accessToken); + } else { + String personalAuthToken = System.getenv("meteor.github.authorization"); + if (personalAuthToken != null && !personalAuthToken.isBlank()) { + request.bearer(personalAuthToken); + } + } + } } diff --git a/src/main/java/meteordevelopment/meteorclient/commands/arguments/CompoundNbtTagArgumentType.java b/src/main/java/meteordevelopment/meteorclient/commands/arguments/CompoundNbtTagArgumentType.java index 4a36a93677..23d761922d 100644 --- a/src/main/java/meteordevelopment/meteorclient/commands/arguments/CompoundNbtTagArgumentType.java +++ b/src/main/java/meteordevelopment/meteorclient/commands/arguments/CompoundNbtTagArgumentType.java @@ -12,14 +12,14 @@ import net.minecraft.nbt.NbtCompound; import net.minecraft.nbt.StringNbtReader; -import java.util.Arrays; import java.util.Collection; +import java.util.List; import static net.minecraft.nbt.StringNbtReader.EXPECTED_VALUE; public class CompoundNbtTagArgumentType implements ArgumentType { private static final CompoundNbtTagArgumentType INSTANCE = new CompoundNbtTagArgumentType(); - private static final Collection EXAMPLES = Arrays.asList("{foo:bar}", "{foo:[aa, bb],bar:15}"); + private static final Collection EXAMPLES = List.of("{foo:bar}", "{foo:[aa, bb],bar:15}"); public static CompoundNbtTagArgumentType create() { return INSTANCE; @@ -53,8 +53,8 @@ else if (reader.peek() == '}') { reader.expect('}'); b.append('}'); return StringNbtReader.parse(b.toString() - .replace("$", "\u00a7") - .replace("\u00a7\u00a7", "$") + .replace("$", "§") + .replace("§§", "$") ); } diff --git a/src/main/java/meteordevelopment/meteorclient/commands/commands/CommandsCommand.java b/src/main/java/meteordevelopment/meteorclient/commands/commands/CommandsCommand.java index 18c1d79b4a..af7ad5a62d 100644 --- a/src/main/java/meteordevelopment/meteorclient/commands/commands/CommandsCommand.java +++ b/src/main/java/meteordevelopment/meteorclient/commands/commands/CommandsCommand.java @@ -45,12 +45,12 @@ private MutableText getCommandText(Command command) { tooltip.append(Text.literal(Utils.nameToTitle(command.getName())).formatted(Formatting.BLUE, Formatting.BOLD)).append("\n"); MutableText aliases = Text.literal(command.getName()); - if (command.getAliases().size() > 0) { + if (!command.getAliases().isEmpty()) { aliases.append(", "); for (String alias : command.getAliases()) { if (alias.isEmpty()) continue; aliases.append(alias); - if (!alias.equals(command.getAliases().get(command.getAliases().size() - 1))) aliases.append(", "); + if (!alias.equals(command.getAliases().getLast())) aliases.append(", "); } } tooltip.append(aliases.formatted(Formatting.GRAY)).append("\n\n"); @@ -59,7 +59,7 @@ private MutableText getCommandText(Command command) { // Text MutableText text = Text.literal(Utils.nameToTitle(command.getName())); - if (command != Commands.COMMANDS.get(Commands.COMMANDS.size() - 1)) + if (command != Commands.COMMANDS.getLast()) text.append(Text.literal(", ").formatted(Formatting.GRAY)); text.setStyle(text .getStyle() diff --git a/src/main/java/meteordevelopment/meteorclient/commands/commands/DisconnectCommand.java b/src/main/java/meteordevelopment/meteorclient/commands/commands/DisconnectCommand.java index 227ac3ae77..f87c0ff178 100644 --- a/src/main/java/meteordevelopment/meteorclient/commands/commands/DisconnectCommand.java +++ b/src/main/java/meteordevelopment/meteorclient/commands/commands/DisconnectCommand.java @@ -5,12 +5,9 @@ package meteordevelopment.meteorclient.commands.commands; -import com.mojang.blaze3d.systems.RenderSystem; -import com.mojang.brigadier.arguments.ArgumentType; import com.mojang.brigadier.arguments.StringArgumentType; import com.mojang.brigadier.builder.LiteralArgumentBuilder; import meteordevelopment.meteorclient.commands.Command; -import net.minecraft.client.gui.screen.DisconnectedScreen; import net.minecraft.command.CommandSource; import net.minecraft.network.packet.s2c.common.DisconnectS2CPacket; import net.minecraft.text.Text; diff --git a/src/main/java/meteordevelopment/meteorclient/commands/commands/EnchantCommand.java b/src/main/java/meteordevelopment/meteorclient/commands/commands/EnchantCommand.java index c667d4c398..f8b981b22a 100644 --- a/src/main/java/meteordevelopment/meteorclient/commands/commands/EnchantCommand.java +++ b/src/main/java/meteordevelopment/meteorclient/commands/commands/EnchantCommand.java @@ -14,7 +14,7 @@ import meteordevelopment.meteorclient.utils.Utils; import net.minecraft.client.gui.screen.ingame.InventoryScreen; import net.minecraft.command.CommandSource; -import net.minecraft.command.argument.RegistryEntryArgumentType; +import net.minecraft.command.argument.RegistryEntryReferenceArgumentType; import net.minecraft.enchantment.Enchantment; import net.minecraft.item.ItemStack; import net.minecraft.registry.Registries; @@ -22,14 +22,14 @@ import net.minecraft.registry.entry.RegistryEntry; import net.minecraft.text.Text; -import java.util.function.Function; +import java.util.function.ToIntFunction; import static com.mojang.brigadier.Command.SINGLE_SUCCESS; import static meteordevelopment.meteorclient.MeteorClient.mc; public class EnchantCommand extends Command { - private final static SimpleCommandExceptionType NOT_IN_CREATIVE = new SimpleCommandExceptionType(Text.literal("You must be in creative mode to use this.")); - private final static SimpleCommandExceptionType NOT_HOLDING_ITEM = new SimpleCommandExceptionType(Text.literal("You need to hold some item to enchant.")); + private static final SimpleCommandExceptionType NOT_IN_CREATIVE = new SimpleCommandExceptionType(Text.literal("You must be in creative mode to use this.")); + private static final SimpleCommandExceptionType NOT_HOLDING_ITEM = new SimpleCommandExceptionType(Text.literal("You need to hold some item to enchant.")); public EnchantCommand() { super("enchant", "Enchants the item in your hand. REQUIRES Creative mode."); @@ -37,7 +37,7 @@ public EnchantCommand() { @Override public void build(LiteralArgumentBuilder builder) { - builder.then(literal("one").then(argument("enchantment", RegistryEntryArgumentType.registryEntry(REGISTRY_ACCESS, RegistryKeys.ENCHANTMENT)) + builder.then(literal("one").then(argument("enchantment", RegistryEntryReferenceArgumentType.registryEntry(REGISTRY_ACCESS, RegistryKeys.ENCHANTMENT)) .then(literal("level").then(argument("level", IntegerArgumentType.integer()).executes(context -> { one(context, enchantment -> context.getArgument("level", Integer.class)); return SINGLE_SUCCESS; @@ -78,7 +78,7 @@ public void build(LiteralArgumentBuilder builder) { return SINGLE_SUCCESS; })); - builder.then(literal("remove").then(argument("enchantment", RegistryEntryArgumentType.registryEntry(REGISTRY_ACCESS, RegistryKeys.ENCHANTMENT)).executes(context -> { + builder.then(literal("remove").then(argument("enchantment", RegistryEntryReferenceArgumentType.registryEntry(REGISTRY_ACCESS, RegistryKeys.ENCHANTMENT)).executes(context -> { ItemStack itemStack = tryGetItemStack(); RegistryEntry.Reference enchantment = context.getArgument("enchantment", RegistryEntry.Reference.class); Utils.removeEnchantment(itemStack, enchantment.value()); @@ -88,21 +88,21 @@ public void build(LiteralArgumentBuilder builder) { }))); } - private void one(CommandContext context, Function level) throws CommandSyntaxException { + private void one(CommandContext context, ToIntFunction level) throws CommandSyntaxException { ItemStack itemStack = tryGetItemStack(); RegistryEntry.Reference enchantment = context.getArgument("enchantment", RegistryEntry.Reference.class); - Utils.addEnchantment(itemStack, enchantment.value(), level.apply(enchantment.value())); + Utils.addEnchantment(itemStack, enchantment.value(), level.applyAsInt(enchantment.value())); syncItem(); } - private void all(boolean onlyPossible, Function level) throws CommandSyntaxException { + private void all(boolean onlyPossible, ToIntFunction level) throws CommandSyntaxException { ItemStack itemStack = tryGetItemStack(); for (Enchantment enchantment : Registries.ENCHANTMENT) { if (!onlyPossible || enchantment.isAcceptableItem(itemStack)) { - Utils.addEnchantment(itemStack, enchantment, level.apply(enchantment)); + Utils.addEnchantment(itemStack, enchantment, level.applyAsInt(enchantment)); } } diff --git a/src/main/java/meteordevelopment/meteorclient/commands/commands/LocateCommand.java b/src/main/java/meteordevelopment/meteorclient/commands/commands/LocateCommand.java index fbddc68791..82892f461f 100644 --- a/src/main/java/meteordevelopment/meteorclient/commands/commands/LocateCommand.java +++ b/src/main/java/meteordevelopment/meteorclient/commands/commands/LocateCommand.java @@ -18,12 +18,14 @@ import net.minecraft.block.Block; import net.minecraft.block.Blocks; import net.minecraft.command.CommandSource; +import net.minecraft.component.ComponentMap; +import net.minecraft.component.DataComponentTypes; +import net.minecraft.component.type.LodestoneTrackerComponent; +import net.minecraft.component.type.MapDecorationsComponent; import net.minecraft.entity.EntityType; import net.minecraft.entity.EyeOfEnderEntity; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; -import net.minecraft.nbt.NbtCompound; -import net.minecraft.nbt.NbtList; import net.minecraft.network.packet.s2c.play.EntitySpawnS2CPacket; import net.minecraft.network.packet.s2c.play.PlaySoundS2CPacket; import net.minecraft.sound.SoundEvents; @@ -31,8 +33,9 @@ import net.minecraft.text.Text; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; +import net.minecraft.world.World; +import org.jetbrains.annotations.Nullable; -import java.util.Arrays; import java.util.List; import static com.mojang.brigadier.Command.SINGLE_SUCCESS; @@ -44,104 +47,141 @@ public class LocateCommand extends Command { private Vec3d secondStart; private Vec3d secondEnd; - private final List netherFortressBlocks = Arrays.asList( + private final List netherFortressBlocks = List.of( Blocks.NETHER_BRICKS, Blocks.NETHER_BRICK_FENCE, Blocks.NETHER_WART ); - private final List monumentBlocks = Arrays.asList( + private final List monumentBlocks = List.of( Blocks.PRISMARINE_BRICKS, Blocks.SEA_LANTERN, Blocks.DARK_PRISMARINE ); - private final List strongholdBlocks = Arrays.asList( + private final List strongholdBlocks = List.of( Blocks.END_PORTAL_FRAME ); + private final List endCityBlocks = List.of( + Blocks.PURPUR_BLOCK, + Blocks.PURPUR_PILLAR, + Blocks.PURPUR_SLAB, + Blocks.PURPUR_STAIRS, + Blocks.END_STONE_BRICKS, + Blocks.END_ROD + ); + public LocateCommand() { super("locate", "Locates structures", "loc"); } @Override public void build(LiteralArgumentBuilder builder) { + // Overworld structures + builder.then(literal("buried_treasure").executes(s -> { ItemStack stack = mc.player.getInventory().getMainHandStack(); - if (stack.getItem() != Items.FILLED_MAP) { - error("You need to hold a treasure map first"); + if (stack.getItem() != Items.FILLED_MAP + || stack.get(DataComponentTypes.ITEM_NAME) == null + || !stack.get(DataComponentTypes.ITEM_NAME).getString().equals(Text.translatable("filled_map.buried_treasure").getString())) { + error("You need to hold a (highlight)buried treasure map(default)!"); return SINGLE_SUCCESS; } - NbtCompound tag = stack.getNbt(); - NbtList nbt1 = (NbtList) tag.get("Decorations"); - if (nbt1 == null) { - error("Couldn't locate the cross. Are you holding a (highlight)treasure map(default)?"); + + MapDecorationsComponent mapDecorationsComponent = stack.get(DataComponentTypes.MAP_DECORATIONS); + if (mapDecorationsComponent == null) { + error("Couldn't locate the map icons!"); return SINGLE_SUCCESS; } - NbtCompound iconNBT = nbt1.getCompound(0); - if (iconNBT == null) { - error("Couldn't locate the cross. Are you holding a (highlight)treasure map(default)?"); - return SINGLE_SUCCESS; + for (MapDecorationsComponent.Decoration decoration : mapDecorationsComponent.decorations().values()) { + if (decoration.type().value().assetId().toString().equals("minecraft:red_x")) { + Vec3d coords = new Vec3d(decoration.x(), 62, decoration.z()); + MutableText text = Text.literal("Buried Treasure located at "); + text.append(ChatUtils.formatCoords(coords)); + text.append("."); + info(text); + return SINGLE_SUCCESS; + } } - Vec3d coords = new Vec3d(iconNBT.getDouble("x"), iconNBT.getDouble("y"), iconNBT.getDouble("z")); - MutableText text = Text.literal("Buried Treasure located at "); - text.append(ChatUtils.formatCoords(coords)); - text.append("."); - info(text); + error("Couldn't locate the buried treasure!"); return SINGLE_SUCCESS; })); - builder.then(literal("lodestone").executes(s -> { + builder.then(literal("mansion").executes(s -> { ItemStack stack = mc.player.getInventory().getMainHandStack(); - if (stack.getItem() != Items.COMPASS) { - error("You need to hold a lodestone compass"); + if (stack.getItem() != Items.FILLED_MAP + || stack.get(DataComponentTypes.ITEM_NAME) == null + || !stack.get(DataComponentTypes.ITEM_NAME).getString().equals(Text.translatable("filled_map.mansion").getString())) { + error("You need to hold a (highlight)woodland explorer map(default)!"); return SINGLE_SUCCESS; } - NbtCompound tag = stack.getNbt(); - if (tag == null) { - error("Couldn't get the NBT data. Are you holding a (highlight)lodestone(default) compass?"); + + MapDecorationsComponent mapDecorationsComponent = stack.get(DataComponentTypes.MAP_DECORATIONS); + if (mapDecorationsComponent == null) { + error("Couldn't locate the map icons!"); return SINGLE_SUCCESS; } - NbtCompound nbt1 = tag.getCompound("LodestonePos"); - if (nbt1 == null) { - error("Couldn't get the NBT data. Are you holding a (highlight)lodestone(default) compass?"); - return SINGLE_SUCCESS; + + for (MapDecorationsComponent.Decoration decoration : mapDecorationsComponent.decorations().values()) { + if (decoration.type().value().assetId().toString().equals("minecraft:woodland_mansion")) { + Vec3d coords = new Vec3d(decoration.x(), 62, decoration.z()); + MutableText text = Text.literal("Mansion located at "); + text.append(ChatUtils.formatCoords(coords)); + text.append("."); + info(text); + return SINGLE_SUCCESS; + } } - Vec3d coords = new Vec3d(nbt1.getDouble("X"), nbt1.getDouble("Y"), nbt1.getDouble("Z")); - MutableText text = Text.literal("Lodestone located at "); - text.append(ChatUtils.formatCoords(coords)); - text.append("."); - info(text); + error("Couldn't locate the mansion!"); return SINGLE_SUCCESS; })); - builder.then(literal("mansion").executes(s -> { + builder.then(literal("monument").executes(s -> { ItemStack stack = mc.player.getInventory().getMainHandStack(); - if (stack.getItem() != Items.FILLED_MAP) { - error("You need to hold a woodland explorer map first"); - return SINGLE_SUCCESS; - } - NbtCompound tag = stack.getNbt(); - NbtList nbt1 = (NbtList) tag.get("Decorations"); - if (nbt1 == null) { - error("Couldn't locate the mansion. Are you holding a (highlight)woodland explorer map(default)?"); + if (stack.getItem() == Items.FILLED_MAP + && stack.get(DataComponentTypes.ITEM_NAME) != null + && stack.get(DataComponentTypes.ITEM_NAME).getString().equals(Text.translatable("filled_map.monument").getString())) { + + MapDecorationsComponent mapDecorationsComponent = stack.get(DataComponentTypes.MAP_DECORATIONS); + if (mapDecorationsComponent == null) { + error("Couldn't locate the map icons!"); + return SINGLE_SUCCESS; + } + + for (MapDecorationsComponent.Decoration decoration : mapDecorationsComponent.decorations().values()) { + if (decoration.type().value().assetId().toString().equals("minecraft:ocean_monument")) { + Vec3d coords = new Vec3d(decoration.x(), 62, decoration.z()); + MutableText text = Text.literal("Monument located at "); + text.append(ChatUtils.formatCoords(coords)); + text.append("."); + info(text); + return SINGLE_SUCCESS; + } + } + + error("Couldn't locate the monument!"); return SINGLE_SUCCESS; } - NbtCompound iconNBT = nbt1.getCompound(0); - if (iconNBT == null) { - error("Couldn't locate the mansion. Are you holding a (highlight)woodland explorer map(default)?"); + // If the player is not holding a valid map, try to locate the monument using Baritone + if (BaritoneUtils.IS_AVAILABLE) { + Vec3d coords = findByBlockList(monumentBlocks); + if (coords == null) { + error("No monument found. Try using an (highlight)ocean explorer map(default) for more success."); + return SINGLE_SUCCESS; + } + MutableText text = Text.literal("Monument located at "); + text.append(ChatUtils.formatCoords(coords)); + text.append("."); + info(text); return SINGLE_SUCCESS; } - Vec3d coords = new Vec3d(iconNBT.getDouble("x"), iconNBT.getDouble("y"), iconNBT.getDouble("z")); - MutableText text = Text.literal("Mansion located at "); - text.append(ChatUtils.formatCoords(coords)); - text.append("."); - info(text); + error("Locating this structure without an (highlight)ocean explorer map(default) requires Baritone."); return SINGLE_SUCCESS; })); @@ -154,7 +194,7 @@ public void build(LiteralArgumentBuilder builder) { boolean foundEye = InvUtils.testInHotbar(Items.ENDER_EYE); if (foundEye) { - PathManagers.get().follow(entity -> entity instanceof EyeOfEnderEntity); + PathManagers.get().follow(EyeOfEnderEntity.class::isInstance); firstStart = null; firstEnd = null; secondStart = null; @@ -175,7 +215,14 @@ public void build(LiteralArgumentBuilder builder) { return SINGLE_SUCCESS; })); + // Nether structures + builder.then(literal("nether_fortress").executes(s -> { + if (mc.world.getRegistryKey() != World.NETHER) { + error("You need to be in the nether to locate a nether fortress."); + return SINGLE_SUCCESS; + } + if (!BaritoneUtils.IS_AVAILABLE) { error("Locating this structure requires Baritone."); return SINGLE_SUCCESS; @@ -193,36 +240,57 @@ public void build(LiteralArgumentBuilder builder) { return SINGLE_SUCCESS; })); - builder.then(literal("monument").executes(s -> { + // End structures + + builder.then(literal("end_city").executes(s -> { + if (mc.world.getRegistryKey() != World.END) { + error("You need to be in the end to locate an end city."); + return SINGLE_SUCCESS; + } + if (!BaritoneUtils.IS_AVAILABLE) { error("Locating this structure requires Baritone."); return SINGLE_SUCCESS; } + Vec3d coords = findByBlockList(endCityBlocks); + if (coords == null) { + error("No end city found."); + return SINGLE_SUCCESS; + } + MutableText text = Text.literal("End city located at "); + text.append(ChatUtils.formatCoords(coords)); + text.append("."); + info(text); + return SINGLE_SUCCESS; + })); + + // Misc structures + + builder.then(literal("lodestone").executes(s -> { ItemStack stack = mc.player.getInventory().getMainHandStack(); - if (stack.getItem() == Items.FILLED_MAP) { - NbtCompound tag = stack.getNbt(); - if (tag != null) { - NbtList nbt1 = (NbtList) tag.get("Decorations"); - if (nbt1 != null) { - NbtCompound iconNBT = nbt1.getCompound(0); - if (iconNBT != null) { - Vec3d coords = new Vec3d(iconNBT.getDouble("x"), iconNBT.getDouble("y"), iconNBT.getDouble("z")); - MutableText text = Text.literal("Monument located at "); - text.append(ChatUtils.formatCoords(coords)); - text.append("."); - info(text); - return SINGLE_SUCCESS; - } - } - } + if (stack.getItem() != Items.COMPASS) { + error("You need to hold a (highlight)lodestone(default) compass!"); + return SINGLE_SUCCESS; } - Vec3d coords = findByBlockList(monumentBlocks); - if (coords == null) { - error("No monument found. You can try using a (highlight)Ocean explorer map(default) for more success."); + ComponentMap components = stack.getComponents(); + if (components == null) { + error("Couldn't get the components data. Are you holding a (highlight)lodestone(default) compass?"); return SINGLE_SUCCESS; } - MutableText text = Text.literal("Monument located at "); + LodestoneTrackerComponent lodestoneTrackerComponent = components.get(DataComponentTypes.LODESTONE_TRACKER); + if (lodestoneTrackerComponent == null) { + error("Couldn't get the components data. Are you holding a (highlight)lodestone(default) compass?"); + return SINGLE_SUCCESS; + } + + if (lodestoneTrackerComponent.target().isEmpty()) { + error("Couldn't get the lodestone's target!"); + return SINGLE_SUCCESS; + } + + Vec3d coords = Vec3d.of(lodestoneTrackerComponent.target().get().pos()); + MutableText text = Text.literal("Lodestone located at "); text.append(ChatUtils.formatCoords(coords)); text.append("."); info(text); @@ -240,7 +308,7 @@ private void cancel() { MeteorClient.EVENT_BUS.unsubscribe(this); } - private Vec3d findByBlockList(List blockList) { + private @Nullable Vec3d findByBlockList(List blockList) { List posList = BaritoneAPI.getProvider().getWorldScanner().scanChunkRadius(BaritoneAPI.getProvider().getPrimaryBaritone().getPlayerContext(), blockList, 64, 10, 32); if (posList.isEmpty()) { return null; @@ -248,20 +316,17 @@ private Vec3d findByBlockList(List blockList) { if (posList.size() < 3) { warning("Only %d block(s) found. This search might be a false positive.", posList.size()); } - return new Vec3d(posList.get(0).getX(), posList.get(0).getY(), posList.get(0).getZ()); + return new Vec3d(posList.getFirst().getX(), posList.getFirst().getY(), posList.getFirst().getZ()); } @EventHandler private void onReadPacket(PacketEvent.Receive event) { - if (event.packet instanceof EntitySpawnS2CPacket packet) { - if (packet.getEntityType() == EntityType.EYE_OF_ENDER) { - firstPosition(packet.getX(), packet.getY(), packet.getZ()); - } + if (event.packet instanceof EntitySpawnS2CPacket packet && packet.getEntityType() == EntityType.EYE_OF_ENDER) { + firstPosition(packet.getX(), packet.getY(), packet.getZ()); } - if (event.packet instanceof PlaySoundS2CPacket packet) { - if (packet.getSound().value() == SoundEvents.ENTITY_ENDER_EYE_DEATH) { - lastPosition(packet.getX(), packet.getY(), packet.getZ()); - } + + if (event.packet instanceof PlaySoundS2CPacket packet && packet.getSound().value() == SoundEvents.ENTITY_ENDER_EYE_DEATH) { + lastPosition(packet.getX(), packet.getY(), packet.getZ()); } } @@ -269,8 +334,7 @@ private void firstPosition(double x, double y, double z) { Vec3d pos = new Vec3d(x, y, z); if (this.firstStart == null) { this.firstStart = pos; - } - else { + } else { this.secondStart = pos; } } @@ -281,8 +345,7 @@ private void lastPosition(double x, double y, double z) { if (this.firstEnd == null) { this.firstEnd = pos; info("Please throw the second Eye Of Ender from a different location."); - } - else { + } else { this.secondEnd = pos; findStronghold(); } diff --git a/src/main/java/meteordevelopment/meteorclient/commands/commands/ModulesCommand.java b/src/main/java/meteordevelopment/meteorclient/commands/commands/ModulesCommand.java index a343199ebb..da7b3ad220 100644 --- a/src/main/java/meteordevelopment/meteorclient/commands/commands/ModulesCommand.java +++ b/src/main/java/meteordevelopment/meteorclient/commands/commands/ModulesCommand.java @@ -48,7 +48,7 @@ private MutableText getModuleText(Module module) { MutableText finalModule = Text.literal(module.title); if (!module.isActive()) finalModule.formatted(Formatting.GRAY); - if (!module.equals(Modules.get().getGroup(module.category).get(Modules.get().getGroup(module.category).size() - 1))) finalModule.append(Text.literal(", ").formatted(Formatting.GRAY)); + if (!module.equals(Modules.get().getGroup(module.category).getLast())) finalModule.append(Text.literal(", ").formatted(Formatting.GRAY)); finalModule.setStyle(finalModule.getStyle().withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, tooltip))); return finalModule; diff --git a/src/main/java/meteordevelopment/meteorclient/commands/commands/NbtCommand.java b/src/main/java/meteordevelopment/meteorclient/commands/commands/NbtCommand.java index a3ecfb3ba0..a8f9e0f8ef 100644 --- a/src/main/java/meteordevelopment/meteorclient/commands/commands/NbtCommand.java +++ b/src/main/java/meteordevelopment/meteorclient/commands/commands/NbtCommand.java @@ -14,9 +14,9 @@ import meteordevelopment.meteorclient.utils.misc.text.MeteorClickEvent; import net.minecraft.command.CommandSource; import net.minecraft.command.argument.NbtPathArgumentType; +import net.minecraft.component.ComponentMap; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NbtCompound; -import net.minecraft.nbt.NbtHelper; import net.minecraft.network.packet.c2s.play.CreativeInventoryActionC2SPacket; import net.minecraft.text.ClickEvent; import net.minecraft.text.HoverEvent; @@ -34,16 +34,23 @@ public NbtCommand() { @Override public void build(LiteralArgumentBuilder builder) { - builder.then(literal("add").then(argument("nbt", CompoundNbtTagArgumentType.create()).executes(s -> { + builder.executes(context -> { + error("This command is not yet updated for 1.20.5 and above!"); + return SINGLE_SUCCESS; + }); + + // TODO: Update using Components over NBT + /*builder.then(literal("add").then(argument("nbt", CompoundNbtTagArgumentType.create()).executes(s -> { ItemStack stack = mc.player.getInventory().getMainHandStack(); if (validBasic(stack)) { NbtCompound tag = CompoundNbtTagArgumentType.get(s); - NbtCompound source = stack.getOrCreateNbt(); if (tag != null) { - source.copyFrom(tag); - setStack(stack); + ItemStack newStack = ItemStack.fromNbtOrEmpty(mc.world.getRegistryManager(), tag); + newStack.applyComponentsFrom(stack.getComponents()); + + setStack(newStack); } else { error("Some of the NBT data could not be found, try using: /m nbt set {nbt}"); } @@ -56,7 +63,7 @@ public void build(LiteralArgumentBuilder builder) { ItemStack stack = mc.player.getInventory().getMainHandStack(); if (validBasic(stack)) { - stack.setNbt(CompoundNbtTagArgumentType.get(context)); + stack = ItemStack.fromNbtOrEmpty(mc.world.getRegistryManager(), CompoundNbtTagArgumentType.get(context)); setStack(stack); } @@ -68,7 +75,7 @@ public void build(LiteralArgumentBuilder builder) { if (validBasic(stack)) { NbtPathArgumentType.NbtPath path = context.getArgument("nbt_path", NbtPathArgumentType.NbtPath.class); - path.remove(stack.getNbt()); + path.remove(stack.encode(mc.world.getRegistryManager())); } return SINGLE_SUCCESS; @@ -80,25 +87,25 @@ public void build(LiteralArgumentBuilder builder) { if (stack == null) { error("You must hold an item in your main hand."); } else { - NbtCompound tag = stack.getNbt(); + ComponentMap components = stack.getComponents(); MutableText copyButton = Text.literal("NBT"); copyButton.setStyle(copyButton.getStyle() - .withFormatting(Formatting.UNDERLINE) - .withClickEvent(new MeteorClickEvent( - ClickEvent.Action.RUN_COMMAND, - this.toString("copy") - )) - .withHoverEvent(new HoverEvent( - HoverEvent.Action.SHOW_TEXT, - Text.literal("Copy the NBT data to your clipboard.") - ))); + .withFormatting(Formatting.UNDERLINE) + .withClickEvent(new MeteorClickEvent( + ClickEvent.Action.RUN_COMMAND, + this.toString("copy") + )) + .withHoverEvent(new HoverEvent( + HoverEvent.Action.SHOW_TEXT, + Text.literal("Copy the NBT data to your clipboard.") + ))); MutableText text = Text.literal(""); text.append(copyButton); - if (tag == null) text.append("{}"); - else text.append(" ").append(NbtHelper.toPrettyPrintedText(tag)); + if (components == null) text.append("{}"); + else text.append(" ").append(Text.of(components.toString())); info(text); } @@ -112,15 +119,15 @@ public void build(LiteralArgumentBuilder builder) { if (stack == null) { error("You must hold an item in your main hand."); } else { - NbtCompound tag = stack.getOrCreateNbt(); - mc.keyboard.setClipboard(tag.toString()); + ComponentMap components = stack.getComponents(); + mc.keyboard.setClipboard(components.toString()); MutableText nbt = Text.literal("NBT"); nbt.setStyle(nbt.getStyle() - .withFormatting(Formatting.UNDERLINE) - .withHoverEvent(new HoverEvent( - HoverEvent.Action.SHOW_TEXT, - NbtHelper.toPrettyPrintedText(tag) - ))); + .withFormatting(Formatting.UNDERLINE) + .withHoverEvent(new HoverEvent( + HoverEvent.Action.SHOW_TEXT, + Text.of(components.toString()) + ))); MutableText text = Text.literal(""); text.append(nbt); @@ -136,7 +143,10 @@ public void build(LiteralArgumentBuilder builder) { ItemStack stack = mc.player.getInventory().getMainHandStack(); if (validBasic(stack)) { - stack.setNbt(CompoundNbtTagArgumentType.create().parse(new StringReader(mc.keyboard.getClipboard()))); + NbtCompound nbt = CompoundNbtTagArgumentType.create().parse(new StringReader(mc.keyboard.getClipboard())); + + stack = ItemStack.fromNbtOrEmpty(mc.world.getRegistryManager(), nbt); + setStack(stack); } @@ -150,11 +160,11 @@ public void build(LiteralArgumentBuilder builder) { int count = IntegerArgumentType.getInteger(context, "count"); stack.setCount(count); setStack(stack); - info("Set mainhand stack count to %s.",count); + info("Set mainhand stack count to %s.", count); } return SINGLE_SUCCESS; - }))); + })));*/ } private void setStack(ItemStack stack) { diff --git a/src/main/java/meteordevelopment/meteorclient/commands/commands/NotebotCommand.java b/src/main/java/meteordevelopment/meteorclient/commands/commands/NotebotCommand.java index 3f226bb9ec..f506ec017b 100644 --- a/src/main/java/meteordevelopment/meteorclient/commands/commands/NotebotCommand.java +++ b/src/main/java/meteordevelopment/meteorclient/commands/commands/NotebotCommand.java @@ -157,7 +157,7 @@ private void onReadPacket(PacketEvent.Receive event) { } private void saveRecording(Path path) { - if (song.size() < 1) { + if (song.isEmpty()) { MeteorClient.EVENT_BUS.unsubscribe(this); return; } diff --git a/src/main/java/meteordevelopment/meteorclient/commands/commands/ResetCommand.java b/src/main/java/meteordevelopment/meteorclient/commands/commands/ResetCommand.java index 21d1f1b6d3..4b080c4c2e 100644 --- a/src/main/java/meteordevelopment/meteorclient/commands/commands/ResetCommand.java +++ b/src/main/java/meteordevelopment/meteorclient/commands/commands/ResetCommand.java @@ -47,13 +47,13 @@ public void build(LiteralArgumentBuilder builder) { .then(argument("module", ModuleArgumentType.create()).executes(context -> { Module module = context.getArgument("module", Module.class); - module.keybind.set(true, -1); + module.keybind.reset(); module.info("Reset bind."); return SINGLE_SUCCESS; })) .then(literal("all").executes(context -> { - Modules.get().getAll().forEach(module -> module.keybind.set(true, -1)); + Modules.get().getAll().forEach(module -> module.keybind.reset()); ChatUtils.infoPrefix("Modules", "Reset all binds."); return SINGLE_SUCCESS; })) diff --git a/src/main/java/meteordevelopment/meteorclient/commands/commands/SaveMapCommand.java b/src/main/java/meteordevelopment/meteorclient/commands/commands/SaveMapCommand.java index e1dfdc29ab..75d71a301c 100644 --- a/src/main/java/meteordevelopment/meteorclient/commands/commands/SaveMapCommand.java +++ b/src/main/java/meteordevelopment/meteorclient/commands/commands/SaveMapCommand.java @@ -12,11 +12,14 @@ import meteordevelopment.meteorclient.mixin.MapRendererAccessor; import net.minecraft.client.render.MapRenderer; import net.minecraft.command.CommandSource; +import net.minecraft.component.DataComponentTypes; import net.minecraft.item.FilledMapItem; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; import net.minecraft.item.map.MapState; import net.minecraft.text.Text; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import org.lwjgl.BufferUtils; import org.lwjgl.PointerBuffer; import org.lwjgl.system.MemoryUtil; @@ -79,11 +82,11 @@ public void build(LiteralArgumentBuilder builder) { })); } - private void saveMap(ItemStack map, MapState state, String path, int scale) { + private void saveMap(@NotNull ItemStack map, MapState state, String path, int scale) { //this is horrible code but it somehow works MapRenderer mapRenderer = mc.gameRenderer.getMapRenderer(); - MapRenderer.MapTexture texture = ((MapRendererAccessor) mapRenderer).invokeGetMapTexture(FilledMapItem.getMapId(map), state); + MapRenderer.MapTexture texture = ((MapRendererAccessor) mapRenderer).invokeGetMapTexture(map.get(DataComponentTypes.MAP_ID), state); int[] data = texture.texture.getImage().makePixelArray(); BufferedImage image = new BufferedImage(128, 128, 2); @@ -104,17 +107,14 @@ private void saveMap(ItemStack map, MapState state, String path, int scale) { } } - private MapState getMapState() { + private @Nullable MapState getMapState() { ItemStack map = getMap(); if (map == null) return null; - MapState state = FilledMapItem.getMapState(FilledMapItem.getMapId(map), mc.world); - if (state == null) return null; - - return state; + return FilledMapItem.getMapState(map.get(DataComponentTypes.MAP_ID), mc.world); } - private String getPath() { + private @Nullable String getPath() { String path = TinyFileDialogs.tinyfd_saveFileDialog("Save image", null, filters, null); if (path == null) return null; if (!path.endsWith(".png")) path += ".png"; @@ -122,7 +122,7 @@ private String getPath() { return path; } - private ItemStack getMap() { + private @Nullable ItemStack getMap() { ItemStack itemStack = mc.player.getMainHandStack(); if (itemStack.getItem() == Items.FILLED_MAP) return itemStack; diff --git a/src/main/java/meteordevelopment/meteorclient/commands/commands/ServerCommand.java b/src/main/java/meteordevelopment/meteorclient/commands/commands/ServerCommand.java index a43077b949..0bb768307f 100644 --- a/src/main/java/meteordevelopment/meteorclient/commands/commands/ServerCommand.java +++ b/src/main/java/meteordevelopment/meteorclient/commands/commands/ServerCommand.java @@ -23,7 +23,6 @@ import net.minecraft.network.packet.c2s.play.RequestCommandCompletionsC2SPacket; import net.minecraft.network.packet.s2c.play.CommandSuggestionsS2CPacket; import net.minecraft.network.packet.s2c.play.CommandTreeS2CPacket; -import net.minecraft.registry.RegistryWrapper; import net.minecraft.server.integrated.IntegratedServer; import net.minecraft.text.ClickEvent; import net.minecraft.text.HoverEvent; @@ -35,16 +34,16 @@ import java.net.InetAddress; import java.net.UnknownHostException; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import java.util.Random; +import java.util.Set; import static com.mojang.brigadier.Command.SINGLE_SUCCESS; import static meteordevelopment.meteorclient.MeteorClient.mc; public class ServerCommand extends Command { - private static final List ANTICHEAT_LIST = Arrays.asList("nocheatplus", "negativity", "warden", "horizon", "illegalstack", "coreprotect", "exploitsx", "vulcan", "abc", "spartan", "kauri", "anticheatreloaded", "witherac", "godseye", "matrix", "wraith", "antixrayheuristics", "grimac"); - private static final String[] VERSION_ALIASES = {"version", "ver", "about", "bukkit:version", "bukkit:ver", "bukkit:about"}; // aliases for bukkit:version + private static final Set ANTICHEAT_LIST = Set.of("nocheatplus", "negativity", "warden", "horizon", "illegalstack", "coreprotect", "exploitsx", "vulcan", "abc", "spartan", "kauri", "anticheatreloaded", "witherac", "godseye", "matrix", "wraith", "antixrayheuristics", "grimac"); + private static final Set VERSION_ALIASES = Set.of("version", "ver", "about", "bukkit:version", "bukkit:ver", "bukkit:about"); // aliases for bukkit:version private String alias; private int ticks = 0; private boolean tick = false; @@ -228,23 +227,21 @@ private void onReadPacket(PacketEvent.Receive event) { // the rationale is that since we should get this packet whenever we log into the server, we can capture it // straight away and not need to send a command completion packet for essentially the same results if (event.packet instanceof CommandTreeS2CPacket packet) { - ClientPlayNetworkHandlerAccessor handler = (ClientPlayNetworkHandlerAccessor) event.packetListener; + ClientPlayNetworkHandlerAccessor handler = (ClientPlayNetworkHandlerAccessor) event.connection.getPacketListener(); commandTreePlugins.clear(); alias = null; // This gets the root node of the command tree. From there, all of its children have to be of type // LiteralCommandNode, so we don't need to worry about checking or casting and can just grab the name - packet.getCommandTree(CommandRegistryAccess.of((RegistryWrapper.WrapperLookup) handler.getCombinedDynamicRegistries(), handler.getEnabledFeatures())).getChildren().forEach(node -> { + packet.getCommandTree(CommandRegistryAccess.of(handler.getCombinedDynamicRegistries(), handler.getEnabledFeatures())).getChildren().forEach(node -> { String[] split = node.getName().split(":"); if (split.length > 1) { if (!commandTreePlugins.contains(split[0])) commandTreePlugins.add(split[0]); } // checking if any of the bukkit:version commands are available, which we can also grab plugins from - if (alias == null) { - for (String a : VERSION_ALIASES) { - if (node.getName().equals(a)) alias = a; - } + if (alias == null && VERSION_ALIASES.contains(node.getName())) { + alias = node.getName(); } }); @@ -256,7 +253,7 @@ private void onReadPacket(PacketEvent.Receive event) { if (event.packet instanceof CommandSuggestionsS2CPacket packet) { Suggestions matches = packet.getSuggestions(); - if (matches == null) { + if (matches.isEmpty()) { error("An error occurred while trying to find plugins."); return; } diff --git a/src/main/java/meteordevelopment/meteorclient/events/entity/player/PlaceBlockEvent.java b/src/main/java/meteordevelopment/meteorclient/events/entity/player/PlaceBlockEvent.java index b8e26d32f8..f38a18a802 100644 --- a/src/main/java/meteordevelopment/meteorclient/events/entity/player/PlaceBlockEvent.java +++ b/src/main/java/meteordevelopment/meteorclient/events/entity/player/PlaceBlockEvent.java @@ -5,16 +5,18 @@ package meteordevelopment.meteorclient.events.entity.player; +import meteordevelopment.meteorclient.events.Cancellable; import net.minecraft.block.Block; import net.minecraft.util.math.BlockPos; -public class PlaceBlockEvent { +public class PlaceBlockEvent extends Cancellable { private static final PlaceBlockEvent INSTANCE = new PlaceBlockEvent(); public BlockPos blockPos; public Block block; public static PlaceBlockEvent get(BlockPos blockPos, Block block) { + INSTANCE.setCancelled(false); INSTANCE.blockPos = blockPos; INSTANCE.block = block; return INSTANCE; diff --git a/src/main/java/meteordevelopment/meteorclient/events/game/SectionVisibleEvent.java b/src/main/java/meteordevelopment/meteorclient/events/game/SectionVisibleEvent.java index c92f9fc55c..726faf7966 100644 --- a/src/main/java/meteordevelopment/meteorclient/events/game/SectionVisibleEvent.java +++ b/src/main/java/meteordevelopment/meteorclient/events/game/SectionVisibleEvent.java @@ -5,15 +5,16 @@ package meteordevelopment.meteorclient.events.game; -import net.minecraft.item.ItemStack; +import net.minecraft.component.DataComponentType; + public class SectionVisibleEvent { private static final SectionVisibleEvent INSTANCE = new SectionVisibleEvent(); - public ItemStack.TooltipSection section; + public DataComponentType section; public boolean visible; - public static SectionVisibleEvent get(ItemStack.TooltipSection section, boolean visible) { + public static SectionVisibleEvent get(DataComponentType section, boolean visible) { INSTANCE.section = section; INSTANCE.visible = visible; return INSTANCE; diff --git a/src/main/java/meteordevelopment/meteorclient/events/packets/PacketEvent.java b/src/main/java/meteordevelopment/meteorclient/events/packets/PacketEvent.java index dfc2bb93eb..d525056c51 100644 --- a/src/main/java/meteordevelopment/meteorclient/events/packets/PacketEvent.java +++ b/src/main/java/meteordevelopment/meteorclient/events/packets/PacketEvent.java @@ -6,7 +6,7 @@ package meteordevelopment.meteorclient.events.packets; import meteordevelopment.meteorclient.events.Cancellable; -import net.minecraft.network.listener.PacketListener; +import net.minecraft.network.ClientConnection; import net.minecraft.network.packet.Packet; public class PacketEvent { @@ -14,12 +14,12 @@ public static class Receive extends Cancellable { private static final Receive INSTANCE = new Receive(); public Packet packet; - public PacketListener packetListener; + public ClientConnection connection; - public static Receive get(Packet packet, PacketListener listener) { + public static Receive get(Packet packet, ClientConnection connection) { INSTANCE.setCancelled(false); INSTANCE.packet = packet; - INSTANCE.packetListener = listener; + INSTANCE.connection = connection; return INSTANCE; } } @@ -27,6 +27,7 @@ public static Receive get(Packet packet, PacketListener listener) { public static class Send extends Cancellable { private static final Send INSTANCE = new Send(); + // overwriting this will overwrite the packet being sent public Packet packet; public static Send get(Packet packet) { diff --git a/src/main/java/meteordevelopment/meteorclient/gui/GuiKeyEvents.java b/src/main/java/meteordevelopment/meteorclient/gui/GuiKeyEvents.java index 2579002c99..bc89a81dfd 100644 --- a/src/main/java/meteordevelopment/meteorclient/gui/GuiKeyEvents.java +++ b/src/main/java/meteordevelopment/meteorclient/gui/GuiKeyEvents.java @@ -7,4 +7,7 @@ public class GuiKeyEvents { public static boolean canUseKeys = true; + + private GuiKeyEvents() { + } } diff --git a/src/main/java/meteordevelopment/meteorclient/gui/GuiTheme.java b/src/main/java/meteordevelopment/meteorclient/gui/GuiTheme.java index c9a317b529..16df9edb3f 100644 --- a/src/main/java/meteordevelopment/meteorclient/gui/GuiTheme.java +++ b/src/main/java/meteordevelopment/meteorclient/gui/GuiTheme.java @@ -33,7 +33,6 @@ import net.minecraft.nbt.NbtCompound; import net.minecraft.util.math.BlockPos; -import java.lang.reflect.InvocationTargetException; import java.util.HashMap; import java.util.Map; diff --git a/src/main/java/meteordevelopment/meteorclient/gui/GuiThemes.java b/src/main/java/meteordevelopment/meteorclient/gui/GuiThemes.java index 2b528f16c7..3cfa2f8d46 100644 --- a/src/main/java/meteordevelopment/meteorclient/gui/GuiThemes.java +++ b/src/main/java/meteordevelopment/meteorclient/gui/GuiThemes.java @@ -26,6 +26,9 @@ public class GuiThemes { private static final List themes = new ArrayList<>(); private static GuiTheme theme; + private GuiThemes() { + } + @PreInit public static void init() { add(new MeteorGuiTheme()); diff --git a/src/main/java/meteordevelopment/meteorclient/gui/screens/CommitsScreen.java b/src/main/java/meteordevelopment/meteorclient/gui/screens/CommitsScreen.java index f12c7b2ad7..69b980c827 100644 --- a/src/main/java/meteordevelopment/meteorclient/gui/screens/CommitsScreen.java +++ b/src/main/java/meteordevelopment/meteorclient/gui/screens/CommitsScreen.java @@ -15,12 +15,14 @@ import meteordevelopment.meteorclient.utils.network.MeteorExecutor; import net.minecraft.util.Util; +import java.net.http.HttpResponse; import java.time.format.DateTimeFormatter; import java.time.format.FormatStyle; public class CommitsScreen extends WindowScreen { private final MeteorAddon addon; private Commit[] commits; + private int statusCode; public CommitsScreen(GuiTheme theme, MeteorAddon addon) { super(theme, "Commits for " + addon.name); @@ -32,13 +34,17 @@ public CommitsScreen(GuiTheme theme, MeteorAddon addon) { MeteorExecutor.execute(() -> { GithubRepo repo = addon.getRepo(); - Response res = Http.get(String.format("https://api.github.com/repos/%s/compare/%s...%s", repo.getOwnerName(), addon.getCommit(), repo.branch())).sendJson(Response.class); - - if (res != null) { - commits = res.commits; - taskAfterRender = this::populateWidgets; + Http.Request request = Http.get(String.format("https://api.github.com/repos/%s/compare/%s...%s", repo.getOwnerName(), addon.getCommit(), repo.branch())); + repo.authenticate(request); + HttpResponse res = request.sendJsonResponse(Response.class); + + if (res.statusCode() == Http.SUCCESS) { + commits = res.body().commits; + taskAfterRender = this::populateCommits; + } else { + statusCode = res.statusCode(); + taskAfterRender = this::populateError; } - else locked = false; }); } @@ -47,13 +53,10 @@ public void initWidgets() { // Only initialize widgets after data arrives } - private void populateWidgets() { - // Top + private void populateHeader(String headerMessage) { WHorizontalList l = add(theme.horizontalList()).expandX().widget(); - String text = "There are %d new commits"; - if (commits.length == 1) text = "There is %d new commit"; - l.add(theme.label(String.format(text, commits.length))).expandX(); + l.add(theme.label(headerMessage)).expandX(); String website = addon.getWebsite(); if (website != null) l.add(theme.button("Website")).widget().action = () -> Util.getOperatingSystem().open(website); @@ -62,6 +65,37 @@ private void populateWidgets() { GithubRepo repo = addon.getRepo(); Util.getOperatingSystem().open(String.format("https://github.com/%s/tree/%s", repo.getOwnerName(), repo.branch())); }; + } + + private void populateError() { + String errorMessage = switch (statusCode) { + case Http.BAD_REQUEST -> "Connection dropped"; + case Http.UNAUTHORIZED -> "Unauthorized"; + case Http.FORBIDDEN -> "Rate-limited"; + case Http.NOT_FOUND -> "Invalid commit hash"; + default -> "Error Code: " + statusCode; + }; + + populateHeader("There was an error fetching commits: " + errorMessage); + + if (statusCode == Http.UNAUTHORIZED) { + add(theme.horizontalSeparator()).padVertical(theme.scale(8)).expandX(); + WHorizontalList l = add(theme.horizontalList()).expandX().widget(); + + l.add(theme.label("Consider using an authentication token: ")).expandX(); + l.add(theme.button("Authorization Guide")).widget().action = () -> { + Util.getOperatingSystem().open("https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens"); + }; + } + + locked = false; + } + + private void populateCommits() { + // Top + String text = "There are %d new commits"; + if (commits.length == 1) text = "There is %d new commit"; + populateHeader(String.format(text, commits.length)); // Commits if (commits.length > 0) { diff --git a/src/main/java/meteordevelopment/meteorclient/gui/screens/EditBookTitleAndAuthorScreen.java b/src/main/java/meteordevelopment/meteorclient/gui/screens/EditBookTitleAndAuthorScreen.java index 092d90a480..062729d00b 100644 --- a/src/main/java/meteordevelopment/meteorclient/gui/screens/EditBookTitleAndAuthorScreen.java +++ b/src/main/java/meteordevelopment/meteorclient/gui/screens/EditBookTitleAndAuthorScreen.java @@ -10,8 +10,11 @@ import meteordevelopment.meteorclient.gui.widgets.containers.WTable; import meteordevelopment.meteorclient.gui.widgets.input.WTextBox; import net.minecraft.client.gui.screen.ingame.BookScreen; +import net.minecraft.component.DataComponentTypes; +import net.minecraft.component.type.WrittenBookContentComponent; import net.minecraft.item.ItemStack; import net.minecraft.network.packet.c2s.play.BookUpdateC2SPacket; +import net.minecraft.text.RawFilteredPair; import net.minecraft.util.Hand; import java.util.ArrayList; @@ -35,18 +38,19 @@ public void initWidgets() { WTable t = add(theme.table()).expandX().widget(); t.add(theme.label("Title")); - WTextBox title = t.add(theme.textBox(itemStack.getOrCreateNbt().getString("title"))).minWidth(220).expandX().widget(); + WTextBox title = t.add(theme.textBox(itemStack.get(DataComponentTypes.WRITTEN_BOOK_CONTENT).title().get(mc.shouldFilterText()))).minWidth(220).expandX().widget(); t.row(); t.add(theme.label("Author")); - WTextBox author = t.add(theme.textBox(itemStack.getNbt().getString("author"))).minWidth(220).expandX().widget(); + WTextBox author = t.add(theme.textBox(itemStack.get(DataComponentTypes.WRITTEN_BOOK_CONTENT).author())).minWidth(220).expandX().widget(); t.row(); t.add(theme.button("Done")).expandX().widget().action = () -> { - itemStack.getNbt().putString("author", author.get()); - itemStack.getNbt().putString("title", title.get()); + WrittenBookContentComponent component = itemStack.get(DataComponentTypes.WRITTEN_BOOK_CONTENT); + WrittenBookContentComponent newComponent = new WrittenBookContentComponent(RawFilteredPair.of(title.get()), author.get(), component.generation(), component.pages(), component.resolved()); + itemStack.set(DataComponentTypes.WRITTEN_BOOK_CONTENT, newComponent); - BookScreen.Contents contents = new BookScreen.WrittenBookContents(itemStack); + BookScreen.Contents contents = new BookScreen.Contents(itemStack.get(DataComponentTypes.WRITTEN_BOOK_CONTENT).getPages(mc.shouldFilterText())); List pages = new ArrayList<>(contents.getPageCount()); for (int i = 0; i < contents.getPageCount(); i++) pages.add(contents.getPage(i).getString()); diff --git a/src/main/java/meteordevelopment/meteorclient/gui/screens/MarkerScreen.java b/src/main/java/meteordevelopment/meteorclient/gui/screens/MarkerScreen.java index ee26217760..809b919f7e 100644 --- a/src/main/java/meteordevelopment/meteorclient/gui/screens/MarkerScreen.java +++ b/src/main/java/meteordevelopment/meteorclient/gui/screens/MarkerScreen.java @@ -25,7 +25,7 @@ public MarkerScreen(GuiTheme theme, BaseMarker marker) { @Override public void initWidgets() { // Settings - if (marker.settings.groups.size() > 0) { + if (!marker.settings.groups.isEmpty()) { settingsContainer = add(theme.verticalList()).expandX().widget(); settingsContainer.add(theme.settings(marker.settings)).expandX(); } diff --git a/src/main/java/meteordevelopment/meteorclient/gui/screens/ModuleScreen.java b/src/main/java/meteordevelopment/meteorclient/gui/screens/ModuleScreen.java index 22e14a8596..d106a5604d 100644 --- a/src/main/java/meteordevelopment/meteorclient/gui/screens/ModuleScreen.java +++ b/src/main/java/meteordevelopment/meteorclient/gui/screens/ModuleScreen.java @@ -47,7 +47,7 @@ public void initWidgets() { add(theme.label(module.description, getWindowWidth() / 2.0)); // Settings - if (module.settings.groups.size() > 0) { + if (!module.settings.groups.isEmpty()) { settingsContainer = add(theme.verticalList()).expandX().widget(); settingsContainer.add(theme.settings(module.settings)).expandX(); } diff --git a/src/main/java/meteordevelopment/meteorclient/gui/screens/ModulesScreen.java b/src/main/java/meteordevelopment/meteorclient/gui/screens/ModulesScreen.java index 908e9f34b5..ce6c19a803 100644 --- a/src/main/java/meteordevelopment/meteorclient/gui/screens/ModulesScreen.java +++ b/src/main/java/meteordevelopment/meteorclient/gui/screens/ModulesScreen.java @@ -32,7 +32,7 @@ public class ModulesScreen extends TabScreen { private WCategoryController controller; public ModulesScreen(GuiTheme theme) { - super(theme, Tabs.get().get(0)); + super(theme, Tabs.get().getFirst()); } @Override @@ -82,7 +82,7 @@ protected void createSearchW(WContainer w, String text) { // Titles Set modules = Modules.get().searchTitles(text); - if (modules.size() > 0) { + if (!modules.isEmpty()) { WSection section = w.add(theme.section("Modules")).expandX().widget(); section.spacing = 0; @@ -97,7 +97,7 @@ protected void createSearchW(WContainer w, String text) { // Settings modules = Modules.get().searchSettingTitles(text); - if (modules.size() > 0) { + if (!modules.isEmpty()) { WSection section = w.add(theme.section("Settings")).expandX().widget(); section.spacing = 0; diff --git a/src/main/java/meteordevelopment/meteorclient/gui/screens/accounts/AccountInfoScreen.java b/src/main/java/meteordevelopment/meteorclient/gui/screens/accounts/AccountInfoScreen.java new file mode 100644 index 0000000000..e81bb64dc1 --- /dev/null +++ b/src/main/java/meteordevelopment/meteorclient/gui/screens/accounts/AccountInfoScreen.java @@ -0,0 +1,39 @@ +/* + * This file is part of the Meteor Client distribution (https://github.com/MeteorDevelopment/meteor-client). + * Copyright (c) Meteor Development. + */ + +package meteordevelopment.meteorclient.gui.screens.accounts; + +import meteordevelopment.meteorclient.gui.GuiTheme; +import meteordevelopment.meteorclient.gui.WindowScreen; +import meteordevelopment.meteorclient.gui.widgets.containers.WHorizontalList; +import meteordevelopment.meteorclient.gui.widgets.pressable.WButton; +import meteordevelopment.meteorclient.systems.accounts.Account; +import meteordevelopment.meteorclient.systems.accounts.AccountType; +import meteordevelopment.meteorclient.systems.accounts.TokenAccount; +import meteordevelopment.meteorclient.utils.render.color.Color; + +import static meteordevelopment.meteorclient.MeteorClient.mc; + +public class AccountInfoScreen extends WindowScreen { + private Account account; + + public AccountInfoScreen(GuiTheme theme, Account account) { + super(theme, account.getUsername() + " details"); + this.account = account; + } + + @Override + public void initWidgets() { + TokenAccount e = (TokenAccount) account; + WHorizontalList l = add(theme.horizontalList()).expandX().widget(); + + WButton copy = theme.button("Copy"); + copy.action = () -> mc.keyboard.setClipboard(e.getToken()); + + l.add(theme.label((account.getType() == AccountType.EasyMC ? "EasyMC" : "TheAltening") + " token")); + l.add(theme.label(e.getToken()).color(Color.GRAY)).pad(5); + l.add(copy); + } +} diff --git a/src/main/java/meteordevelopment/meteorclient/gui/screens/settings/BlockDataSettingScreen.java b/src/main/java/meteordevelopment/meteorclient/gui/screens/settings/BlockDataSettingScreen.java index ccf9df4017..8da1bc054e 100644 --- a/src/main/java/meteordevelopment/meteorclient/gui/screens/settings/BlockDataSettingScreen.java +++ b/src/main/java/meteordevelopment/meteorclient/gui/screens/settings/BlockDataSettingScreen.java @@ -60,7 +60,7 @@ public & ISerializable & IChangeable & IBlockData> for (Block block : Registries.BLOCK) { T blockData = (T) setting.get().get(block); - if (blockData != null && blockData.isChanged()) BLOCKS.add(0, block); + if (blockData != null && blockData.isChanged()) BLOCKS.addFirst(block); else BLOCKS.add(block); } diff --git a/src/main/java/meteordevelopment/meteorclient/gui/screens/settings/EntityTypeListSettingScreen.java b/src/main/java/meteordevelopment/meteorclient/gui/screens/settings/EntityTypeListSettingScreen.java index 1caf20e89a..c6399c7975 100644 --- a/src/main/java/meteordevelopment/meteorclient/gui/screens/settings/EntityTypeListSettingScreen.java +++ b/src/main/java/meteordevelopment/meteorclient/gui/screens/settings/EntityTypeListSettingScreen.java @@ -171,28 +171,28 @@ public void initWidgets() { for (Pair, Integer> pair : entities) entityTypeForEach.accept(pair.getLeft()); } - if (animalsT.cells.size() == 0) list.cells.remove(animalsCell); - if (waterAnimalsT.cells.size() == 0) list.cells.remove(waterAnimalsCell); - if (monstersT.cells.size() == 0) list.cells.remove(monstersCell); - if (ambientT.cells.size() == 0) list.cells.remove(ambientCell); - if (miscT.cells.size() == 0) list.cells.remove(miscCell); + if (animalsT.cells.isEmpty()) list.cells.remove(animalsCell); + if (waterAnimalsT.cells.isEmpty()) list.cells.remove(waterAnimalsCell); + if (monstersT.cells.isEmpty()) list.cells.remove(monstersCell); + if (ambientT.cells.isEmpty()) list.cells.remove(ambientCell); + if (miscT.cells.isEmpty()) list.cells.remove(miscCell); if (first) { int totalCount = (hasWaterAnimal + waterAnimals.cells.size() + monsters.cells.size() + ambient.cells.size() + misc.cells.size()) / 2; if (totalCount <= 20) { - if (animalsT.cells.size() > 0) animals.setExpanded(true); - if (waterAnimalsT.cells.size() > 0) waterAnimals.setExpanded(true); - if (monstersT.cells.size() > 0) monsters.setExpanded(true); - if (ambientT.cells.size() > 0) ambient.setExpanded(true); - if (miscT.cells.size() > 0) misc.setExpanded(true); + if (!animalsT.cells.isEmpty()) animals.setExpanded(true); + if (!waterAnimalsT.cells.isEmpty()) waterAnimals.setExpanded(true); + if (!monstersT.cells.isEmpty()) monsters.setExpanded(true); + if (!ambientT.cells.isEmpty()) ambient.setExpanded(true); + if (!miscT.cells.isEmpty()) misc.setExpanded(true); } else { - if (animalsT.cells.size() > 0) animals.setExpanded(false); - if (waterAnimalsT.cells.size() > 0) waterAnimals.setExpanded(false); - if (monstersT.cells.size() > 0) monsters.setExpanded(false); - if (ambientT.cells.size() > 0) ambient.setExpanded(false); - if (miscT.cells.size() > 0) misc.setExpanded(false); + if (!animalsT.cells.isEmpty()) animals.setExpanded(false); + if (!waterAnimalsT.cells.isEmpty()) waterAnimals.setExpanded(false); + if (!monstersT.cells.isEmpty()) monsters.setExpanded(false); + if (!ambientT.cells.isEmpty()) ambient.setExpanded(false); + if (!miscT.cells.isEmpty()) misc.setExpanded(false); } } } diff --git a/src/main/java/meteordevelopment/meteorclient/gui/screens/settings/LeftRightListSettingScreen.java b/src/main/java/meteordevelopment/meteorclient/gui/screens/settings/LeftRightListSettingScreen.java index ad90f9270f..407bb72a74 100644 --- a/src/main/java/meteordevelopment/meteorclient/gui/screens/settings/LeftRightListSettingScreen.java +++ b/src/main/java/meteordevelopment/meteorclient/gui/screens/settings/LeftRightListSettingScreen.java @@ -73,7 +73,7 @@ private void initWidgets(Registry registry) { if (v != null) addValue(registry, v); }); - if (left.cells.size() > 0) table.add(theme.verticalSeparator()).expandWidgetY(); + if (!left.cells.isEmpty()) table.add(theme.verticalSeparator()).expandWidgetY(); // Right (selected) abc(pairs -> { @@ -132,7 +132,7 @@ private WTable abc(Consumer>> addValues, boolean isLeft, C if (!filterText.isEmpty()) values.sort(Comparator.comparingInt(value -> -value.getRight())); for (Pair pair : values) forEach.accept(pair.getLeft()); - if (table.cells.size() > 0) cell.expandX(); + if (!table.cells.isEmpty()) cell.expandX(); return table; } diff --git a/src/main/java/meteordevelopment/meteorclient/gui/screens/settings/StatusEffectAmplifierMapSettingScreen.java b/src/main/java/meteordevelopment/meteorclient/gui/screens/settings/StatusEffectAmplifierMapSettingScreen.java index f4b4c073c8..6914e30680 100644 --- a/src/main/java/meteordevelopment/meteorclient/gui/screens/settings/StatusEffectAmplifierMapSettingScreen.java +++ b/src/main/java/meteordevelopment/meteorclient/gui/screens/settings/StatusEffectAmplifierMapSettingScreen.java @@ -5,7 +5,7 @@ package meteordevelopment.meteorclient.gui.screens.settings; -import it.unimi.dsi.fastutil.objects.Object2IntMap; +import it.unimi.dsi.fastutil.objects.Reference2IntMap; import meteordevelopment.meteorclient.gui.GuiTheme; import meteordevelopment.meteorclient.gui.WindowScreen; import meteordevelopment.meteorclient.gui.widgets.containers.WTable; @@ -13,6 +13,8 @@ import meteordevelopment.meteorclient.gui.widgets.input.WTextBox; import meteordevelopment.meteorclient.settings.Setting; import meteordevelopment.meteorclient.utils.misc.Names; +import net.minecraft.component.DataComponentTypes; +import net.minecraft.component.type.PotionContentsComponent; import net.minecraft.entity.effect.StatusEffect; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; @@ -21,15 +23,16 @@ import java.util.ArrayList; import java.util.Comparator; import java.util.List; +import java.util.Optional; public class StatusEffectAmplifierMapSettingScreen extends WindowScreen { - private final Setting> setting; + private final Setting> setting; private WTable table; private String filterText = ""; - public StatusEffectAmplifierMapSettingScreen(GuiTheme theme, Setting> setting) { + public StatusEffectAmplifierMapSettingScreen(GuiTheme theme, Setting> setting) { super(theme, "Modify Amplifiers"); this.setting = setting; @@ -74,7 +77,13 @@ private void initTable() { private ItemStack getPotionStack(StatusEffect effect) { ItemStack potion = Items.POTION.getDefaultStack(); - potion.getOrCreateNbt().putInt("CustomPotionColor", effect.getColor()); + + potion.set(DataComponentTypes.POTION_CONTENTS, new PotionContentsComponent( + potion.get(DataComponentTypes.POTION_CONTENTS).potion(), + Optional.of(effect.getColor()), + potion.get(DataComponentTypes.POTION_CONTENTS).customEffects()) + ); + return potion; } } diff --git a/src/main/java/meteordevelopment/meteorclient/gui/screens/settings/StatusEffectListSettingScreen.java b/src/main/java/meteordevelopment/meteorclient/gui/screens/settings/StatusEffectListSettingScreen.java index 39ba69ed93..b2172ed11c 100644 --- a/src/main/java/meteordevelopment/meteorclient/gui/screens/settings/StatusEffectListSettingScreen.java +++ b/src/main/java/meteordevelopment/meteorclient/gui/screens/settings/StatusEffectListSettingScreen.java @@ -9,12 +9,15 @@ import meteordevelopment.meteorclient.gui.widgets.WWidget; import meteordevelopment.meteorclient.settings.Setting; import meteordevelopment.meteorclient.utils.misc.Names; +import net.minecraft.component.DataComponentTypes; +import net.minecraft.component.type.PotionContentsComponent; import net.minecraft.entity.effect.StatusEffect; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; import net.minecraft.registry.Registries; import java.util.List; +import java.util.Optional; public class StatusEffectListSettingScreen extends LeftRightListSettingScreen { public StatusEffectListSettingScreen(GuiTheme theme, Setting> setting) { @@ -33,7 +36,13 @@ protected String getValueName(StatusEffect value) { private ItemStack getPotionStack(StatusEffect effect) { ItemStack potion = Items.POTION.getDefaultStack(); - potion.getOrCreateNbt().putInt("CustomPotionColor", effect.getColor()); + + potion.set(DataComponentTypes.POTION_CONTENTS, new PotionContentsComponent( + potion.get(DataComponentTypes.POTION_CONTENTS).potion(), + Optional.of(effect.getColor()), + potion.get(DataComponentTypes.POTION_CONTENTS).customEffects()) + ); + return potion; } } diff --git a/src/main/java/meteordevelopment/meteorclient/gui/tabs/Tabs.java b/src/main/java/meteordevelopment/meteorclient/gui/tabs/Tabs.java index 704eb5989e..d98cbd382d 100644 --- a/src/main/java/meteordevelopment/meteorclient/gui/tabs/Tabs.java +++ b/src/main/java/meteordevelopment/meteorclient/gui/tabs/Tabs.java @@ -6,7 +6,6 @@ package meteordevelopment.meteorclient.gui.tabs; import meteordevelopment.meteorclient.gui.tabs.builtin.*; -import meteordevelopment.meteorclient.pathing.BaritoneUtils; import meteordevelopment.meteorclient.pathing.PathManagers; import meteordevelopment.meteorclient.utils.PreInit; @@ -16,6 +15,9 @@ public class Tabs { private static final List tabs = new ArrayList<>(); + private Tabs() { + } + @PreInit(dependencies = PathManagers.class) public static void init() { add(new ModulesTab()); diff --git a/src/main/java/meteordevelopment/meteorclient/gui/utils/StarscriptTextBoxRenderer.java b/src/main/java/meteordevelopment/meteorclient/gui/utils/StarscriptTextBoxRenderer.java index 130ef022aa..a5831f7390 100644 --- a/src/main/java/meteordevelopment/meteorclient/gui/utils/StarscriptTextBoxRenderer.java +++ b/src/main/java/meteordevelopment/meteorclient/gui/utils/StarscriptTextBoxRenderer.java @@ -62,11 +62,11 @@ private void generate(GuiTheme theme, String text, Color defaultColor) { int charDepth = depth; if (result.hasErrors()) { - if (i == result.errors.get(0).character) { + if (i == result.errors.getFirst().character) { sections.add(new Section(sb.toString(), charDepth > 0 ? theme.starscriptTextColor() : defaultColor)); sb.setLength(0); } - else if (i > result.errors.get(0).character) { + else if (i > result.errors.getFirst().character) { sb.append(c); continue; } diff --git a/src/main/java/meteordevelopment/meteorclient/gui/widgets/WAccount.java b/src/main/java/meteordevelopment/meteorclient/gui/widgets/WAccount.java index 8262cc1c4e..1c4d3ef640 100644 --- a/src/main/java/meteordevelopment/meteorclient/gui/widgets/WAccount.java +++ b/src/main/java/meteordevelopment/meteorclient/gui/widgets/WAccount.java @@ -6,11 +6,13 @@ package meteordevelopment.meteorclient.gui.widgets; import meteordevelopment.meteorclient.gui.WidgetScreen; +import meteordevelopment.meteorclient.gui.screens.accounts.AccountInfoScreen; import meteordevelopment.meteorclient.gui.widgets.containers.WHorizontalList; import meteordevelopment.meteorclient.gui.widgets.pressable.WButton; import meteordevelopment.meteorclient.gui.widgets.pressable.WMinus; import meteordevelopment.meteorclient.systems.accounts.Account; import meteordevelopment.meteorclient.systems.accounts.Accounts; +import meteordevelopment.meteorclient.systems.accounts.TokenAccount; import meteordevelopment.meteorclient.utils.network.MeteorExecutor; import meteordevelopment.meteorclient.utils.render.color.Color; @@ -18,7 +20,6 @@ public abstract class WAccount extends WHorizontalList { public Runnable refreshScreenAction; - private final WidgetScreen screen; private final Account account; @@ -43,6 +44,12 @@ public void init() { WLabel label = add(theme.label("(" + account.getType() + ")")).expandCellX().right().widget(); label.color = accountTypeColor(); + // Info + if (account instanceof TokenAccount) { + WButton info = add(theme.button("Info")).widget(); + info.action = () -> mc.setScreen(new AccountInfoScreen(theme, account)); + } + // Login WButton login = add(theme.button("Login")).widget(); login.action = () -> { diff --git a/src/main/java/meteordevelopment/meteorclient/gui/widgets/WItemWithLabel.java b/src/main/java/meteordevelopment/meteorclient/gui/widgets/WItemWithLabel.java index 017ae3ffca..cd7b4decfc 100644 --- a/src/main/java/meteordevelopment/meteorclient/gui/widgets/WItemWithLabel.java +++ b/src/main/java/meteordevelopment/meteorclient/gui/widgets/WItemWithLabel.java @@ -7,13 +7,13 @@ import meteordevelopment.meteorclient.gui.widgets.containers.WHorizontalList; import meteordevelopment.meteorclient.utils.misc.Names; +import net.minecraft.component.DataComponentTypes; import net.minecraft.entity.effect.StatusEffectInstance; import net.minecraft.entity.effect.StatusEffectUtil; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; -import net.minecraft.potion.PotionUtil; -import java.util.List; +import java.util.Iterator; import static meteordevelopment.meteorclient.MeteorClient.mc; @@ -39,16 +39,15 @@ private String getStringToAppend() { String str = ""; if (itemStack.getItem() == Items.POTION) { - List effects = PotionUtil.getPotion(itemStack).getEffects(); + Iterator effects = itemStack.getItem().getComponents().get(DataComponentTypes.POTION_CONTENTS).getEffects().iterator(); + if (!effects.hasNext()) return str; - if (!effects.isEmpty()) { - str += " "; + str += " "; - StatusEffectInstance effect = effects.get(0); - if (effect.getAmplifier() > 0) str += "%d ".formatted(effect.getAmplifier() + 1); + StatusEffectInstance effect = effects.next(); + if (effect.getAmplifier() > 0) str += "%d ".formatted(effect.getAmplifier() + 1); - str += "(%s)".formatted(StatusEffectUtil.getDurationText(effect, 1, mc.world != null ? mc.world.getTickManager().getTickRate() : 20.0F).getString()); - } + str += "(%s)".formatted(StatusEffectUtil.getDurationText(effect, 1, mc.world != null ? mc.world.getTickManager().getTickRate() : 20.0F).getString()); } return str; diff --git a/src/main/java/meteordevelopment/meteorclient/gui/widgets/WKeybind.java b/src/main/java/meteordevelopment/meteorclient/gui/widgets/WKeybind.java index 6115d26865..16174de395 100644 --- a/src/main/java/meteordevelopment/meteorclient/gui/widgets/WKeybind.java +++ b/src/main/java/meteordevelopment/meteorclient/gui/widgets/WKeybind.java @@ -14,7 +14,7 @@ public class WKeybind extends WHorizontalList { public Runnable action; public Runnable actionOnSet; - private WLabel label; + private WButton button; private final Keybind keybind; private final Keybind defaultValue; @@ -27,12 +27,10 @@ public WKeybind(Keybind keybind, Keybind defaultValue) { @Override public void init() { - label = add(theme.label("")).widget(); - - WButton set = add(theme.button("Set")).widget(); - set.action = () -> { + button = add(theme.button("")).widget(); + button.action = () -> { listening = true; - label.set("..."); + button.set("..."); if (actionOnSet != null) actionOnSet.run(); }; @@ -40,9 +38,20 @@ public void init() { refreshLabel(); } - public boolean onAction(boolean isKey, int value) { - if (listening && keybind.canBindTo(isKey, value)) { - keybind.set(isKey, value); + public boolean onClear() { + if (listening) { + keybind.reset(); + reset(); + + return true; + } + + return false; + } + + public boolean onAction(boolean isKey, int value, int modifiers) { + if (listening && keybind.canBindTo(isKey, value, modifiers)) { + keybind.set(isKey, value, modifiers); reset(); return true; @@ -65,6 +74,6 @@ public void reset() { } private void refreshLabel() { - label.set(keybind.toString()); + button.set(keybind.toString()); } } diff --git a/src/main/java/meteordevelopment/meteorclient/gui/widgets/WMultiLabel.java b/src/main/java/meteordevelopment/meteorclient/gui/widgets/WMultiLabel.java index 9e986a3ee9..0f2d54b86d 100644 --- a/src/main/java/meteordevelopment/meteorclient/gui/widgets/WMultiLabel.java +++ b/src/main/java/meteordevelopment/meteorclient/gui/widgets/WMultiLabel.java @@ -63,7 +63,7 @@ protected void onCalculateSize() { } } - if (sb.length() > 0) lines.add(sb.toString()); + if (!sb.isEmpty()) lines.add(sb.toString()); width = maxLineWidth; height = theme.textHeight(title) * lines.size(); diff --git a/src/main/java/meteordevelopment/meteorclient/gui/widgets/containers/WContainer.java b/src/main/java/meteordevelopment/meteorclient/gui/widgets/containers/WContainer.java index 59764e78bb..4ae00b5ffe 100644 --- a/src/main/java/meteordevelopment/meteorclient/gui/widgets/containers/WContainer.java +++ b/src/main/java/meteordevelopment/meteorclient/gui/widgets/containers/WContainer.java @@ -34,7 +34,7 @@ public Cell add(T widget) { } public void clear() { - if (cells.size() > 0) { + if (!cells.isEmpty()) { cells.clear(); invalidate(); } diff --git a/src/main/java/meteordevelopment/meteorclient/gui/widgets/input/WBlockPosEdit.java b/src/main/java/meteordevelopment/meteorclient/gui/widgets/input/WBlockPosEdit.java index 08538d5723..cca613b5fb 100644 --- a/src/main/java/meteordevelopment/meteorclient/gui/widgets/input/WBlockPosEdit.java +++ b/src/main/java/meteordevelopment/meteorclient/gui/widgets/input/WBlockPosEdit.java @@ -44,8 +44,7 @@ public void init() { if (canUpdate()) { WButton click = add(theme.button("Click")).expandX().widget(); click.action = () -> { - String sb = "Click!\n" + "Right click to pick a new position.\n" + - "Left click to cancel."; + String sb = "Click!\nRight click to pick a new position.\nLeft click to cancel."; Modules.get().get(Marker.class).info(sb); clicking = true; diff --git a/src/main/java/meteordevelopment/meteorclient/gui/widgets/input/WTextBox.java b/src/main/java/meteordevelopment/meteorclient/gui/widgets/input/WTextBox.java index 61846c92cb..b2e1c9efd1 100644 --- a/src/main/java/meteordevelopment/meteorclient/gui/widgets/input/WTextBox.java +++ b/src/main/java/meteordevelopment/meteorclient/gui/widgets/input/WTextBox.java @@ -613,7 +613,7 @@ private void cursorChanged() { completions = renderer.getCompletions(text, this.cursor); completionsStart = 0; completionsW = null; - if (completions != null && completions.size() > 0) createCompletions(0); + if (completions != null && !completions.isEmpty()) createCompletions(0); } protected void onCursorChanged() {} diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/AbstractBlockMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/AbstractBlockMixin.java index 45fed77b49..9fcfb85976 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/AbstractBlockMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/AbstractBlockMixin.java @@ -14,6 +14,7 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.world.BlockView; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @@ -21,7 +22,8 @@ import java.util.Random; @Mixin(AbstractBlock.class) -public class AbstractBlockMixin { +public abstract class AbstractBlockMixin { + @Unique private static final Random RANDOM = new Random(); @Inject(method = "getAmbientOcclusionLightLevel", at = @At("HEAD"), cancellable = true) diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/AbstractBlockStateMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/AbstractBlockStateMixin.java index ff19c95594..c48dc7272d 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/AbstractBlockStateMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/AbstractBlockStateMixin.java @@ -10,13 +10,15 @@ import net.minecraft.block.AbstractBlock; import net.minecraft.util.math.BlockPos; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.ModifyVariable; import java.util.Random; @Mixin(AbstractBlock.AbstractBlockState.class) -public class AbstractBlockStateMixin { +public abstract class AbstractBlockStateMixin { + @Unique private static final Random RANDOM = new Random(); @ModifyVariable(method = "getModelOffset", at = @At("HEAD"), argsOnly = true) diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/AbstractClientPlayerEntityMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/AbstractClientPlayerEntityMixin.java index 9f0d700cb3..b43b644e8d 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/AbstractClientPlayerEntityMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/AbstractClientPlayerEntityMixin.java @@ -16,7 +16,7 @@ import static meteordevelopment.meteorclient.MeteorClient.mc; @Mixin(AbstractClientPlayerEntity.class) -public class AbstractClientPlayerEntityMixin { +public abstract class AbstractClientPlayerEntityMixin { // Player model rendering in main menu @Inject(method = "getPlayerListEntry", at = @At("HEAD"), cancellable = true) diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/AbstractSignEditScreenMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/AbstractSignEditScreenMixin.java index 1c4fbbed07..68cb072b41 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/AbstractSignEditScreenMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/AbstractSignEditScreenMixin.java @@ -15,7 +15,7 @@ import java.util.stream.Stream; @Mixin(AbstractSignEditScreen.class) -public class AbstractSignEditScreenMixin { +public abstract class AbstractSignEditScreenMixin { @ModifyExpressionValue(method = "(Lnet/minecraft/block/entity/SignBlockEntity;ZZLnet/minecraft/text/Text;)V", at = @At(value = "INVOKE", target = "Ljava/util/stream/IntStream;mapToObj(Ljava/util/function/IntFunction;)Ljava/util/stream/Stream;")) private Stream modifyTranslatableText(Stream original) { return original.map(this::modifyText); diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/ArmorFeatureRendererMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/ArmorFeatureRendererMixin.java index d493a00087..e4ce233fd4 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/ArmorFeatureRendererMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/ArmorFeatureRendererMixin.java @@ -20,7 +20,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(ArmorFeatureRenderer.class) -public class ArmorFeatureRendererMixin, A extends BipedEntityModel> { +public abstract class ArmorFeatureRendererMixin, A extends BipedEntityModel> { @Inject(method = "renderArmor", at = @At("HEAD"), cancellable = true) private void onRenderArmor(MatrixStack matrices, VertexConsumerProvider vertexConsumers, T livingEntity, EquipmentSlot equipmentSlot, int i, A bipedEntityModel, CallbackInfo info) { if (livingEntity instanceof PlayerEntity && Modules.get().get(NoRender.class).noArmor()) info.cancel(); diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/AttributeContainerMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/AttributeContainerMixin.java deleted file mode 100644 index cad576fb1e..0000000000 --- a/src/main/java/meteordevelopment/meteorclient/mixin/AttributeContainerMixin.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * This file is part of the Meteor Client distribution (https://github.com/MeteorDevelopment/meteor-client). - * Copyright (c) Meteor Development. - */ - -package meteordevelopment.meteorclient.mixin; - -import meteordevelopment.meteorclient.mixininterface.IAttributeContainer; -import meteordevelopment.meteorclient.mixininterface.IEntityAttributeInstance; -import net.minecraft.entity.attribute.AttributeContainer; -import net.minecraft.entity.attribute.EntityAttribute; -import net.minecraft.entity.attribute.EntityAttributeInstance; -import org.jetbrains.annotations.Nullable; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; - -import java.util.Map; -import java.util.Set; - -@Mixin(AttributeContainer.class) -public abstract class AttributeContainerMixin implements IAttributeContainer { - @Shadow @Final private Map custom; - @Shadow @Final private Set tracked; - - @Override - public void meteor$copyFrom(AttributeContainer other) { - for (var otherInstance : ((AttributeContainerMixin) (Object) other).custom.values()) { - @Nullable EntityAttributeInstance instance = custom.get(otherInstance.getAttribute()); - if (instance != null) { - ((IEntityAttributeInstance) instance).meteor$copyFrom(otherInstance); - } else { - custom.put(otherInstance.getAttribute(), otherInstance); - if (otherInstance.getAttribute().isTracked()) tracked.add(otherInstance); - } - } - } -} diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/BackgroundRendererMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/BackgroundRendererMixin.java index aca68480c3..514d2a369a 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/BackgroundRendererMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/BackgroundRendererMixin.java @@ -19,7 +19,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @Mixin(BackgroundRenderer.class) -public class BackgroundRendererMixin { +public abstract class BackgroundRendererMixin { @Inject(method = "applyFog", at = @At("TAIL")) private static void onApplyFog(Camera camera, BackgroundRenderer.FogType fogType, float viewDistance, boolean thickFog, float tickDelta, CallbackInfo info) { if (Modules.get().get(NoRender.class).noFog() || Modules.get().isActive(Xray.class)) { diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/BakedQuadMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/BakedQuadMixin.java index b474caf293..98847500f8 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/BakedQuadMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/BakedQuadMixin.java @@ -12,7 +12,7 @@ import org.spongepowered.asm.mixin.Shadow; @Mixin(BakedQuad.class) -public class BakedQuadMixin implements IBakedQuad { +public abstract class BakedQuadMixin implements IBakedQuad { @Shadow @Final protected int[] vertexData; @Override diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/BannerBlockEntityRendererMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/BannerBlockEntityRendererMixin.java index c91b941616..313160110d 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/BannerBlockEntityRendererMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/BannerBlockEntityRendererMixin.java @@ -22,12 +22,13 @@ import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(BannerBlockEntityRenderer.class) -public class BannerBlockEntityRendererMixin { +public abstract class BannerBlockEntityRendererMixin { @Final @Shadow private ModelPart pillar; @@ -56,11 +57,12 @@ else if (renderMode == NoRender.BannerRenderMode.Pillar) { } } + @Unique private void renderPillar(BannerBlockEntity bannerBlockEntity, MatrixStack matrixStack, VertexConsumerProvider vertexConsumerProvider, int i, int j) { matrixStack.push(); BlockState blockState = bannerBlockEntity.getCachedState(); matrixStack.translate(0.5D, 0.5D, 0.5D); - float h = (float)(-(Integer)blockState.get(BannerBlock.ROTATION) * 360) / 16.0F; + float h = (-(Integer)blockState.get(BannerBlock.ROTATION) * 360) / 16.0F; matrixStack.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(h)); matrixStack.push(); matrixStack.scale(0.6666667F, -0.6666667F, -0.6666667F); @@ -70,6 +72,7 @@ private void renderPillar(BannerBlockEntity bannerBlockEntity, MatrixStack matri matrixStack.pop(); } + @Unique private void renderCrossbar(BannerBlockEntity bannerBlockEntity, MatrixStack matrixStack, VertexConsumerProvider vertexConsumerProvider, int i, int j) { matrixStack.push(); BlockState blockState = bannerBlockEntity.getCachedState(); diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/BeaconBlockEntityRendererMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/BeaconBlockEntityRendererMixin.java index 7d2dc86390..7145c8d5d1 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/BeaconBlockEntityRendererMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/BeaconBlockEntityRendererMixin.java @@ -17,7 +17,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(BeaconBlockEntityRenderer.class) -public class BeaconBlockEntityRendererMixin { +public abstract class BeaconBlockEntityRendererMixin { @Inject(method = "render(Lnet/minecraft/block/entity/BeaconBlockEntity;FLnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;II)V", at = @At("HEAD"), cancellable = true) private void onRender(BeaconBlockEntity beaconBlockEntity, float f, MatrixStack matrixStack, VertexConsumerProvider vertexConsumerProvider, int i, int j, CallbackInfo info) { if (Modules.get().get(NoRender.class).noBeaconBeams()) info.cancel(); diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/BeaconScreenMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/BeaconScreenMixin.java index 0051b9ded8..eb9f7250d5 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/BeaconScreenMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/BeaconScreenMixin.java @@ -15,6 +15,7 @@ import net.minecraft.client.gui.widget.ClickableWidget; import net.minecraft.entity.effect.StatusEffect; import net.minecraft.entity.player.PlayerInventory; +import net.minecraft.registry.entry.RegistryEntry; import net.minecraft.screen.BeaconScreenHandler; import net.minecraft.text.Text; import org.spongepowered.asm.mixin.Mixin; @@ -23,7 +24,7 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import java.util.Arrays; +import java.util.Collection; import java.util.List; @Mixin(BeaconScreen.class) @@ -38,12 +39,11 @@ public BeaconScreenMixin(BeaconScreenHandler handler, PlayerInventory inventory, @Inject(method = "init", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/ingame/BeaconScreen;addButton(Lnet/minecraft/client/gui/widget/ClickableWidget;)V", ordinal = 1, shift = At.Shift.AFTER), cancellable = true) private void changeButtons(CallbackInfo ci) { if (!Modules.get().get(BetterBeacons.class).isActive()) return; - List effects = Arrays.stream(BeaconBlockEntity.EFFECTS_BY_LEVEL).flatMap(Arrays::stream).toList(); - + List> effects = BeaconBlockEntity.EFFECTS_BY_LEVEL.stream().flatMap(Collection::stream).toList(); if (MinecraftClient.getInstance().currentScreen instanceof BeaconScreen beaconScreen) { for (int x = 0; x < 3; x++) { for (int y = 0; y < 2; y++) { - StatusEffect effect = effects.get(x * 2 + y); + RegistryEntry effect = effects.get(x * 2 + y); int xMin = this.x + x * 25; int yMin = this.y + y * 25; addButton(beaconScreen.new EffectButtonWidget(xMin + 27, yMin + 32, effect, true, -1)); diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/BiomeColorsMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/BiomeColorsMixin.java index b14093abab..2166d8690c 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/BiomeColorsMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/BiomeColorsMixin.java @@ -16,7 +16,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @Mixin(BiomeColors.class) -public class BiomeColorsMixin { +public abstract class BiomeColorsMixin { /** * @author Walaryne */ diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/BlockCollisionSpliteratorMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/BlockCollisionSpliteratorMixin.java index f51dc897b0..e40b859046 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/BlockCollisionSpliteratorMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/BlockCollisionSpliteratorMixin.java @@ -20,7 +20,7 @@ import org.spongepowered.asm.mixin.injection.Redirect; @Mixin(BlockCollisionSpliterator.class) -public class BlockCollisionSpliteratorMixin { +public abstract class BlockCollisionSpliteratorMixin { @Redirect(method = "computeNext", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/BlockState;getCollisionShape(Lnet/minecraft/world/BlockView;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/ShapeContext;)Lnet/minecraft/util/shape/VoxelShape;")) private VoxelShape onComputeNextCollisionBox(BlockState state, BlockView world, BlockPos pos, ShapeContext context) { VoxelShape shape = state.getCollisionShape(world, pos, context); diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/BlockEntityRenderDispatcherMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/BlockEntityRenderDispatcherMixin.java index 958eb5b8dc..5774208d4b 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/BlockEntityRenderDispatcherMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/BlockEntityRenderDispatcherMixin.java @@ -17,7 +17,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(BlockEntityRenderDispatcher.class) -public class BlockEntityRenderDispatcherMixin { +public abstract class BlockEntityRenderDispatcherMixin { @Inject(method = "render(Lnet/minecraft/block/entity/BlockEntity;FLnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;)V", at = @At("HEAD"), cancellable = true) private void onRenderEntity(E blockEntity, float tickDelta, MatrixStack matrix, VertexConsumerProvider vertexConsumerProvider, CallbackInfo info) { RenderBlockEntityEvent event = MeteorClient.EVENT_BUS.post(RenderBlockEntityEvent.get(blockEntity)); diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/BlockItemMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/BlockItemMixin.java index d8c48698a5..6386182ebf 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/BlockItemMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/BlockItemMixin.java @@ -7,18 +7,47 @@ import meteordevelopment.meteorclient.MeteorClient; import meteordevelopment.meteorclient.events.entity.player.PlaceBlockEvent; +import meteordevelopment.meteorclient.systems.modules.Modules; +import meteordevelopment.meteorclient.systems.modules.world.NoGhostBlocks; import net.minecraft.block.BlockState; import net.minecraft.item.BlockItem; import net.minecraft.item.ItemPlacementContext; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.ModifyVariable; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @Mixin(BlockItem.class) -public class BlockItemMixin { - @Inject(method = "place(Lnet/minecraft/item/ItemPlacementContext;Lnet/minecraft/block/BlockState;)Z", at = @At("HEAD")) +public abstract class BlockItemMixin { + @Shadow + protected abstract BlockState getPlacementState(ItemPlacementContext context); + + @Inject(method = "place(Lnet/minecraft/item/ItemPlacementContext;Lnet/minecraft/block/BlockState;)Z", at = @At("HEAD"), cancellable = true) private void onPlace(ItemPlacementContext context, BlockState state, CallbackInfoReturnable info) { - if (context.getWorld().isClient) MeteorClient.EVENT_BUS.post(PlaceBlockEvent.get(context.getBlockPos(), state.getBlock())); + if (!context.getWorld().isClient) return; + + if (MeteorClient.EVENT_BUS.post(PlaceBlockEvent.get(context.getBlockPos(), state.getBlock())).isCancelled()) { + info.setReturnValue(true); + } + } + + @ModifyVariable( + method = "place(Lnet/minecraft/item/ItemPlacementContext;)Lnet/minecraft/util/ActionResult;", + ordinal = 1, + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/block/BlockState;isOf(Lnet/minecraft/block/Block;)Z" + ) + ) + private BlockState modifyState(BlockState state, ItemPlacementContext context) { + var noGhostBlocks = Modules.get().get(NoGhostBlocks.class); + + if (noGhostBlocks.isActive() && noGhostBlocks.placing.get()) { + return getPlacementState(context); + } + + return state; } } diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/BlockModelRendererMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/BlockModelRendererMixin.java index ec49bc8e38..cb90791d7d 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/BlockModelRendererMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/BlockModelRendererMixin.java @@ -23,7 +23,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(BlockModelRenderer.class) -public class BlockModelRendererMixin { +public abstract class BlockModelRendererMixin { @Unique private final ThreadLocal alphas = new ThreadLocal<>(); @Inject(method = "render(Lnet/minecraft/world/BlockRenderView;Lnet/minecraft/client/render/model/BakedModel;Lnet/minecraft/block/BlockState;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumer;ZLnet/minecraft/util/math/random/Random;JI)V", at = @At("HEAD"), cancellable = true) diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/BlockRenderManagerMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/BlockRenderManagerMixin.java index 05ae764d48..7e7fc2892a 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/BlockRenderManagerMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/BlockRenderManagerMixin.java @@ -20,7 +20,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(BlockRenderManager.class) -public class BlockRenderManagerMixin { +public abstract class BlockRenderManagerMixin { @Inject(method = "renderDamage", at = @At("HEAD"), cancellable = true) private void renderDamage(BlockState state, BlockPos pos, BlockRenderView world, MatrixStack matrix, VertexConsumer vertexConsumer, CallbackInfo info) { if (Modules.get().isActive(BreakIndicators.class) || Modules.get().get(NoRender.class).noBlockBreakOverlay()) info.cancel(); diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/BlockStateMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/BlockStateMixin.java index af438f17cb..353f279c9c 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/BlockStateMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/BlockStateMixin.java @@ -5,8 +5,8 @@ package meteordevelopment.meteorclient.mixin; -import com.google.common.collect.ImmutableMap; import com.mojang.serialization.MapCodec; +import it.unimi.dsi.fastutil.objects.Reference2ObjectArrayMap; import meteordevelopment.meteorclient.MeteorClient; import meteordevelopment.meteorclient.events.world.BlockActivateEvent; import net.minecraft.block.AbstractBlock; @@ -15,20 +15,19 @@ import net.minecraft.entity.player.PlayerEntity; import net.minecraft.state.property.Property; import net.minecraft.util.ActionResult; -import net.minecraft.util.Hand; import net.minecraft.util.hit.BlockHitResult; import net.minecraft.world.World; import org.spongepowered.asm.mixin.Mixin; @Mixin(BlockState.class) public abstract class BlockStateMixin extends AbstractBlock.AbstractBlockState { - public BlockStateMixin(Block block, ImmutableMap, Comparable> propertyMap, MapCodec mapCodec) { + public BlockStateMixin(Block block, Reference2ObjectArrayMap, Comparable> propertyMap, MapCodec mapCodec) { super(block, propertyMap, mapCodec); } @Override - public ActionResult onUse(World world, PlayerEntity player, Hand hand, BlockHitResult hit) { + public ActionResult onUse(World world, PlayerEntity player, BlockHitResult hit) { MeteorClient.EVENT_BUS.post(BlockActivateEvent.get((BlockState) (Object) this)); - return super.onUse(world, player, hand, hit); + return super.onUse(world, player, hit); } } diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/BoatEntityMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/BoatEntityMixin.java index c24b8974f8..cda37c9e0c 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/BoatEntityMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/BoatEntityMixin.java @@ -18,7 +18,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(BoatEntity.class) -public class BoatEntityMixin { +public abstract class BoatEntityMixin { @Shadow private boolean pressingLeft; @Shadow private boolean pressingRight; diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/BookScreenMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/BookScreenMixin.java index b66e8e7575..4da1997a8a 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/BookScreenMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/BookScreenMixin.java @@ -36,7 +36,7 @@ import static meteordevelopment.meteorclient.MeteorClient.mc; @Mixin(BookScreen.class) -public class BookScreenMixin extends Screen { +public abstract class BookScreenMixin extends Screen { @Shadow private BookScreen.Contents contents; @@ -67,7 +67,7 @@ private void onInit(CallbackInfo info) { } String encoded = Base64.getEncoder().encodeToString(bytes.array); - + @SuppressWarnings("resource") long available = MemoryStack.stackGet().getPointer(); long size = MemoryUtil.memLengthUTF8(encoded, true); diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/BossBarHudMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/BossBarHudMixin.java index da61a33382..0b6d51bac4 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/BossBarHudMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/BossBarHudMixin.java @@ -20,7 +20,7 @@ import java.util.Iterator; @Mixin(BossBarHud.class) -public class BossBarHudMixin { +public abstract class BossBarHudMixin { @Inject(method = "render", at = @At("HEAD"), cancellable = true) private void onRender(CallbackInfo info) { if (Modules.get().get(NoRender.class).noBossBar()) info.cancel(); diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/BoxMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/BoxMixin.java index b964e24f26..b4983c84c2 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/BoxMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/BoxMixin.java @@ -13,7 +13,7 @@ import org.spongepowered.asm.mixin.Shadow; @Mixin(Box.class) -public class BoxMixin implements IBox { +public abstract class BoxMixin implements IBox { @Shadow @Final @Mutable public double minX; @Shadow @Final @Mutable public double minY; @Shadow @Final @Mutable public double minZ; diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/ChatHudLineMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/ChatHudLineMixin.java index 77a94679a0..60b9b5fff6 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/ChatHudLineMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/ChatHudLineMixin.java @@ -15,7 +15,7 @@ import org.spongepowered.asm.mixin.Unique; @Mixin(value = ChatHudLine.class) -public class ChatHudLineMixin implements IChatHudLine { +public abstract class ChatHudLineMixin implements IChatHudLine { @Shadow @Final private Text content; @Unique private int id; @Unique private GameProfile sender; diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/ChatHudLineVisibleMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/ChatHudLineVisibleMixin.java index f797b6401b..c616b282ec 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/ChatHudLineVisibleMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/ChatHudLineVisibleMixin.java @@ -15,7 +15,7 @@ import org.spongepowered.asm.mixin.Unique; @Mixin(ChatHudLine.Visible.class) -public class ChatHudLineVisibleMixin implements IChatHudLineVisible { +public abstract class ChatHudLineVisibleMixin implements IChatHudLineVisible { @Shadow @Final private OrderedText content; @Unique private int id; @Unique private GameProfile sender; diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/ChatHudMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/ChatHudMixin.java index ac7b0b1bb7..c0093d7974 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/ChatHudMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/ChatHudMixin.java @@ -31,7 +31,8 @@ import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Unique; -import org.spongepowered.asm.mixin.injection.*; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.LocalCapture; @@ -39,16 +40,25 @@ @Mixin(ChatHud.class) public abstract class ChatHudMixin implements IChatHud { - @Shadow @Final private MinecraftClient client; - @Shadow @Final private List visibleMessages; - @Shadow @Final private List messages; + @Shadow + @Final + private MinecraftClient client; + @Shadow + @Final + private List visibleMessages; + @Shadow + @Final + private List messages; - @Unique private BetterChat betterChat; - @Unique private int nextId; - @Unique private boolean skipOnAddMessage; + @Unique + private BetterChat betterChat; + @Unique + private int nextId; + @Unique + private boolean skipOnAddMessage; @Shadow - protected abstract void addMessage(Text message, @Nullable MessageSignatureData signature, int ticks, @Nullable MessageIndicator indicator, boolean refresh); + public abstract void addMessage(Text message, @Nullable MessageSignatureData signatureData, @Nullable MessageIndicator indicator); @Shadow public abstract void addMessage(Text message); @@ -60,19 +70,19 @@ public abstract class ChatHudMixin implements IChatHud { nextId = 0; } - @Inject(method = "addMessage(Lnet/minecraft/text/Text;Lnet/minecraft/network/message/MessageSignatureData;ILnet/minecraft/client/gui/hud/MessageIndicator;Z)V", at = @At(value = "INVOKE", target = "Ljava/util/List;add(ILjava/lang/Object;)V", ordinal = 0, shift = At.Shift.AFTER)) - private void onAddMessageAfterNewChatHudLineVisible(Text message, MessageSignatureData signature, int ticks, MessageIndicator indicator, boolean refresh, CallbackInfo info) { - ((IChatHudLine) (Object) visibleMessages.get(0)).meteor$setId(nextId); + @Inject(method = "addVisibleMessage", at = @At(value = "INVOKE", target = "Ljava/util/List;add(ILjava/lang/Object;)V", shift = At.Shift.AFTER)) + private void onAddMessageAfterNewChatHudLineVisible(ChatHudLine message, CallbackInfo ci) { + ((IChatHudLine) (Object) visibleMessages.getFirst()).meteor$setId(nextId); } - @Inject(method = "addMessage(Lnet/minecraft/text/Text;Lnet/minecraft/network/message/MessageSignatureData;ILnet/minecraft/client/gui/hud/MessageIndicator;Z)V", at = @At(value = "INVOKE", target = "Ljava/util/List;add(ILjava/lang/Object;)V", ordinal = 1, shift = At.Shift.AFTER)) - private void onAddMessageAfterNewChatHudLine(Text message, MessageSignatureData signature, int ticks, MessageIndicator indicator, boolean refresh, CallbackInfo info) { - ((IChatHudLine) (Object) messages.get(0)).meteor$setId(nextId); + @Inject(method = "addMessage(Lnet/minecraft/client/gui/hud/ChatHudLine;)V", at = @At(value = "INVOKE", target = "Ljava/util/List;add(ILjava/lang/Object;)V", shift = At.Shift.AFTER)) + private void onAddMessageAfterNewChatHudLine(ChatHudLine message, CallbackInfo ci) { + ((IChatHudLine) (Object) messages.getFirst()).meteor$setId(nextId); } @SuppressWarnings("DataFlowIssue") - @ModifyExpressionValue(method = "addMessage(Lnet/minecraft/text/Text;Lnet/minecraft/network/message/MessageSignatureData;ILnet/minecraft/client/gui/hud/MessageIndicator;Z)V", at = @At(value = "NEW", target = "(ILnet/minecraft/text/OrderedText;Lnet/minecraft/client/gui/hud/MessageIndicator;Z)Lnet/minecraft/client/gui/hud/ChatHudLine$Visible;")) - private ChatHudLine.Visible onAddMessage_modifyChatHudLineVisible(ChatHudLine.Visible line, @Local(ordinal = 2) int j) { + @ModifyExpressionValue(method = "addVisibleMessage", at = @At(value = "NEW", target = "(ILnet/minecraft/text/OrderedText;Lnet/minecraft/client/gui/hud/MessageIndicator;Z)Lnet/minecraft/client/gui/hud/ChatHudLine$Visible;")) + private ChatHudLine.Visible onAddMessage_modifyChatHudLineVisible(ChatHudLine.Visible line, @Local(ordinal = 1) int j) { IMessageHandler handler = (IMessageHandler) client.getMessageHandler(); if (handler == null) return line; @@ -84,7 +94,7 @@ private ChatHudLine.Visible onAddMessage_modifyChatHudLineVisible(ChatHudLine.Vi return line; } - @ModifyExpressionValue(method = "addMessage(Lnet/minecraft/text/Text;Lnet/minecraft/network/message/MessageSignatureData;ILnet/minecraft/client/gui/hud/MessageIndicator;Z)V", at = @At(value = "NEW", target = "(ILnet/minecraft/text/Text;Lnet/minecraft/network/message/MessageSignatureData;Lnet/minecraft/client/gui/hud/MessageIndicator;)Lnet/minecraft/client/gui/hud/ChatHudLine;")) + @ModifyExpressionValue(method = "addMessage(Lnet/minecraft/text/Text;Lnet/minecraft/network/message/MessageSignatureData;Lnet/minecraft/client/gui/hud/MessageIndicator;)V", at = @At(value = "NEW", target = "(ILnet/minecraft/text/Text;Lnet/minecraft/network/message/MessageSignatureData;Lnet/minecraft/client/gui/hud/MessageIndicator;)Lnet/minecraft/client/gui/hud/ChatHudLine;")) private ChatHudLine onAddMessage_modifyChatHudLine(ChatHudLine line) { IMessageHandler handler = (IMessageHandler) client.getMessageHandler(); if (handler == null) return line; @@ -93,17 +103,17 @@ private ChatHudLine onAddMessage_modifyChatHudLine(ChatHudLine line) { return line; } - @Inject(at = @At("HEAD"), method = "addMessage(Lnet/minecraft/text/Text;Lnet/minecraft/network/message/MessageSignatureData;ILnet/minecraft/client/gui/hud/MessageIndicator;Z)V", cancellable = true) - private void onAddMessage(Text message, @Nullable MessageSignatureData signature, int ticks, @Nullable MessageIndicator indicator, boolean refresh, CallbackInfo info) { + @Inject(at = @At("HEAD"), method = "addMessage(Lnet/minecraft/text/Text;Lnet/minecraft/network/message/MessageSignatureData;Lnet/minecraft/client/gui/hud/MessageIndicator;)V", cancellable = true) + private void onAddMessage(Text message, MessageSignatureData signatureData, MessageIndicator indicator, CallbackInfo ci) { if (skipOnAddMessage) return; ReceiveMessageEvent event = MeteorClient.EVENT_BUS.post(ReceiveMessageEvent.get(message, indicator, nextId)); - if (event.isCancelled()) info.cancel(); + if (event.isCancelled()) ci.cancel(); else { visibleMessages.removeIf(msg -> ((IChatHudLine) (Object) msg).meteor$getId() == nextId && nextId != 0); - for (int i = messages.size() - 1; i > -1 ; i--) { + for (int i = messages.size() - 1; i > -1; i--) { if (((IChatHudLine) (Object) messages.get(i)).meteor$getId() == nextId && nextId != 0) { messages.remove(i); Modules.get().get(BetterChat.class).lines.removeInt(i); @@ -111,23 +121,30 @@ private void onAddMessage(Text message, @Nullable MessageSignatureData signature } if (event.isModified()) { - info.cancel(); + ci.cancel(); skipOnAddMessage = true; - addMessage(event.getMessage(), signature, ticks, event.getIndicator(), refresh); + addMessage(event.getMessage(), signatureData, event.getIndicator()); skipOnAddMessage = false; } } } //modify max lengths for messages and visible messages - @ModifyConstant(method = "addMessage(Lnet/minecraft/text/Text;Lnet/minecraft/network/message/MessageSignatureData;ILnet/minecraft/client/gui/hud/MessageIndicator;Z)V", constant = @Constant(intValue = 100)) + @ModifyExpressionValue(method = "addMessage(Lnet/minecraft/client/gui/hud/ChatHudLine;)V", at = @At(value = "CONSTANT", args = "intValue=100")) private int maxLength(int size) { if (Modules.get() == null || !getBetterChat().isLongerChat()) return size; return size + betterChat.getExtraChatLines(); } + @ModifyExpressionValue(method = "addVisibleMessage", at = @At(value = "CONSTANT", args = "intValue=100")) + private int maxLengthVisible(int size) { + if (Modules.get() == null || !getBetterChat().isLongerChat()) return size; + + return size + betterChat.getExtraChatLines(); + } + // Player Heads @ModifyExpressionValue(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/MathHelper;ceil(F)I")) @@ -150,24 +167,22 @@ private MessageIndicator onRender_modifyIndicator(MessageIndicator indicator) { // Anti spam - @Inject(method = "addMessage(Lnet/minecraft/text/Text;Lnet/minecraft/network/message/MessageSignatureData;ILnet/minecraft/client/gui/hud/MessageIndicator;Z)V", - at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/hud/ChatHud;isChatFocused()Z"), locals = LocalCapture.CAPTURE_FAILSOFT) - private void onBreakChatMessageLines(Text message, MessageSignatureData signature, int ticks, MessageIndicator indicator, boolean refresh, CallbackInfo ci, int i, List list) { + @Inject(method = "addVisibleMessage", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/hud/ChatHud;isChatFocused()Z"), locals = LocalCapture.CAPTURE_FAILSOFT) + private void onBreakChatMessageLines(ChatHudLine message, CallbackInfo ci, int i, MessageIndicator.Icon icon, List list) { if (Modules.get() == null) return; // baritone calls addMessage before we initialise - getBetterChat().lines.add(0, list.size()); + getBetterChat().lines.addFirst(list.size()); } - @Inject(method = "addMessage(Lnet/minecraft/text/Text;Lnet/minecraft/network/message/MessageSignatureData;ILnet/minecraft/client/gui/hud/MessageIndicator;Z)V", - slice = @Slice(from = @At(value = "FIELD", target = "Lnet/minecraft/client/gui/hud/ChatHud;messages:Ljava/util/List;")), at = @At(value = "INVOKE", target = "Ljava/util/List;remove(I)Ljava/lang/Object;")) - private void onRemoveMessage(Text message, MessageSignatureData signature, int ticks, MessageIndicator indicator, boolean refresh, CallbackInfo ci) { + @Inject(method = "addMessage(Lnet/minecraft/client/gui/hud/ChatHudLine;)V", at = @At(value = "INVOKE", target = "Ljava/util/List;remove(I)Ljava/lang/Object;")) + private void onRemoveMessage(ChatHudLine message, CallbackInfo ci) { if (Modules.get() == null) return; int extra = getBetterChat().isLongerChat() ? getBetterChat().getExtraChatLines() : 0; int size = betterChat.lines.size(); while (size > 100 + extra) { - betterChat.lines.removeInt(size - 1); + betterChat.lines.removeLast(); size--; } } diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/ChunkBorderDebugRendererMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/ChunkBorderDebugRendererMixin.java index fa0bb28354..3481e15180 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/ChunkBorderDebugRendererMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/ChunkBorderDebugRendererMixin.java @@ -19,7 +19,7 @@ import org.spongepowered.asm.mixin.injection.At; @Mixin(ChunkBorderDebugRenderer.class) -public class ChunkBorderDebugRendererMixin { +public abstract class ChunkBorderDebugRendererMixin { @Shadow @Final private MinecraftClient client; diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/ChunkOcclusionDataBuilderMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/ChunkOcclusionDataBuilderMixin.java index 478e346bd4..6d53a458a9 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/ChunkOcclusionDataBuilderMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/ChunkOcclusionDataBuilderMixin.java @@ -15,7 +15,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(ChunkOcclusionDataBuilder.class) -public class ChunkOcclusionDataBuilderMixin { +public abstract class ChunkOcclusionDataBuilderMixin { @Inject(method = "markClosed", at = @At("HEAD"), cancellable = true) private void onMarkClosed(BlockPos pos, CallbackInfo info) { ChunkOcclusionEvent event = MeteorClient.EVENT_BUS.post(ChunkOcclusionEvent.get()); diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/ChunkSkyLightProviderMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/ChunkSkyLightProviderMixin.java index fe22f39148..e05e1e90f4 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/ChunkSkyLightProviderMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/ChunkSkyLightProviderMixin.java @@ -14,7 +14,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(ChunkSkyLightProvider.class) -public class ChunkSkyLightProviderMixin { +public abstract class ChunkSkyLightProviderMixin { @Inject(at = @At("HEAD"), method = "method_51531", cancellable = true) private void recalculateLevel(long blockPos, long l, int lightLevel, CallbackInfo ci) { if (Modules.get().get(NoRender.class).noSkylightUpdates()) ci.cancel(); diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/ClientConnectionMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/ClientConnectionMixin.java index 95fb825805..b959abbe97 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/ClientConnectionMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/ClientConnectionMixin.java @@ -5,6 +5,8 @@ package meteordevelopment.meteorclient.mixin; +import com.llamalad7.mixinextras.sugar.Local; +import com.llamalad7.mixinextras.sugar.ref.LocalRef; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelPipeline; import io.netty.handler.proxy.Socks4ProxyHandler; @@ -23,7 +25,6 @@ import net.minecraft.network.handler.PacketEncoderException; import net.minecraft.network.handler.PacketSizeLogger; import net.minecraft.network.listener.ClientPlayPacketListener; -import net.minecraft.network.listener.PacketListener; import net.minecraft.network.packet.Packet; import net.minecraft.network.packet.s2c.play.BundleS2CPacket; import net.minecraft.text.MutableText; @@ -39,20 +40,21 @@ import java.util.Iterator; @Mixin(ClientConnection.class) -public class ClientConnectionMixin { - @Inject(method = "handlePacket", at = @At("HEAD"), cancellable = true) - private static void onHandlePacket(Packet packet, PacketListener listener, CallbackInfo info) { +public abstract class ClientConnectionMixin { + @Inject(method = "channelRead0(Lio/netty/channel/ChannelHandlerContext;Lnet/minecraft/network/packet/Packet;)V", + at = @At(value = "INVOKE", target = "Lnet/minecraft/network/ClientConnection;handlePacket(Lnet/minecraft/network/packet/Packet;Lnet/minecraft/network/listener/PacketListener;)V", shift = At.Shift.BEFORE), cancellable = true) + private void onHandlePacket(ChannelHandlerContext channelHandlerContext, Packet packet, CallbackInfo ci) { if (packet instanceof BundleS2CPacket bundle) { - for (Iterator> it = bundle.getPackets().iterator(); it.hasNext(); ) { - if (MeteorClient.EVENT_BUS.post(PacketEvent.Receive.get(it.next(), listener)).isCancelled()) it.remove(); + for (Iterator> it = bundle.getPackets().iterator(); it.hasNext(); ) { + if (MeteorClient.EVENT_BUS.post(PacketEvent.Receive.get(it.next(), (ClientConnection) (Object) this)).isCancelled()) it.remove(); } - } else if (MeteorClient.EVENT_BUS.post(PacketEvent.Receive.get(packet, listener)).isCancelled()) info.cancel(); + } else if (MeteorClient.EVENT_BUS.post(PacketEvent.Receive.get(packet, (ClientConnection) (Object) this)).isCancelled()) ci.cancel(); } @Inject(method = "disconnect", at = @At("HEAD")) private void disconnect(Text disconnectReason, CallbackInfo ci) { if (Modules.get().get(HighwayBuilder.class).isActive()) { - MutableText text = Text.literal(String.format("\n\n%s[%sHighway Builder%s] Statistics:", Formatting.GRAY, Formatting.BLUE, Formatting.GRAY)).append("\n"); + MutableText text = Text.literal("%n%n%s[%sHighway Builder%s] Statistics:%n".formatted(Formatting.GRAY, Formatting.BLUE, Formatting.GRAY)); text.append(Modules.get().get(HighwayBuilder.class).getStatsText()); ((MutableText) disconnectReason).append(text); @@ -65,8 +67,13 @@ private static void onConnect(InetSocketAddress address, boolean useEpoll, Clien } @Inject(at = @At("HEAD"), method = "send(Lnet/minecraft/network/packet/Packet;)V", cancellable = true) - private void onSendPacketHead(Packet packet, CallbackInfo info) { - if (MeteorClient.EVENT_BUS.post(PacketEvent.Send.get(packet)).isCancelled()) info.cancel(); + private void onSendPacketHead(CallbackInfo info, @Local LocalRef> packet) { + PacketEvent.Send processedPacket = MeteorClient.EVENT_BUS.post(PacketEvent.Send.get(packet.get())); + if (processedPacket.isCancelled()) { + info.cancel(); + } else { + packet.set(processedPacket.packet); + } } @Inject(method = "send(Lnet/minecraft/network/packet/Packet;)V", at = @At("TAIL")) @@ -84,7 +91,7 @@ private void exceptionCaught(ChannelHandlerContext context, Throwable throwable, } @Inject(method = "addHandlers", at = @At("RETURN")) - private static void onAddHandlers(ChannelPipeline pipeline, NetworkSide side, PacketSizeLogger packetSizeLogger, CallbackInfo ci) { + private static void onAddHandlers(ChannelPipeline pipeline, NetworkSide side, boolean local, PacketSizeLogger packetSizeLogger, CallbackInfo ci) { if (side != NetworkSide.CLIENTBOUND) return; Proxy proxy = Proxies.get().getEnabled(); diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/ClientPlayerEntityMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/ClientPlayerEntityMixin.java index c971bd64c4..cedf6b361c 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/ClientPlayerEntityMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/ClientPlayerEntityMixin.java @@ -12,10 +12,7 @@ import meteordevelopment.meteorclient.events.entity.DropItemsEvent; import meteordevelopment.meteorclient.events.entity.player.SendMovementPacketsEvent; import meteordevelopment.meteorclient.systems.modules.Modules; -import meteordevelopment.meteorclient.systems.modules.movement.NoSlow; -import meteordevelopment.meteorclient.systems.modules.movement.Scaffold; -import meteordevelopment.meteorclient.systems.modules.movement.Sneak; -import meteordevelopment.meteorclient.systems.modules.movement.Velocity; +import meteordevelopment.meteorclient.systems.modules.movement.*; import meteordevelopment.meteorclient.systems.modules.player.Portals; import meteordevelopment.meteorclient.utils.Utils; import net.minecraft.client.MinecraftClient; @@ -55,6 +52,7 @@ private boolean redirectUsingItem(boolean isUsingItem) { @Inject(method = "isSneaking", at = @At("HEAD"), cancellable = true) private void onIsSneaking(CallbackInfoReturnable info) { if (Modules.get().get(Scaffold.class).scaffolding()) info.setReturnValue(false); + if (Modules.get().get(Flight.class).noSneak()) info.setReturnValue(false); } @Inject(method = "shouldSlowDown", at = @At("HEAD"), cancellable = true) diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/ClientPlayerInteractionManagerMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/ClientPlayerInteractionManagerMixin.java index 7bbdcb9886..feb31e918e 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/ClientPlayerInteractionManagerMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/ClientPlayerInteractionManagerMixin.java @@ -12,7 +12,6 @@ import meteordevelopment.meteorclient.systems.modules.Modules; import meteordevelopment.meteorclient.systems.modules.misc.InventoryTweaks; import meteordevelopment.meteorclient.systems.modules.player.BreakDelay; -import meteordevelopment.meteorclient.systems.modules.player.Reach; import meteordevelopment.meteorclient.systems.modules.player.SpeedMine; import meteordevelopment.meteorclient.utils.player.Rotations; import meteordevelopment.meteorclient.utils.world.BlockUtils; @@ -60,6 +59,9 @@ public abstract class ClientPlayerInteractionManagerMixin implements IClientPlay @Final private ClientPlayNetworkHandler networkHandler; + @Shadow + public abstract boolean breakBlock(BlockPos pos); + @Inject(method = "clickSlot", at = @At("HEAD"), cancellable = true) private void onClickSlot(int syncId, int slotId, int button, SlotActionType actionType, PlayerEntity player, CallbackInfo info) { if (actionType == SlotActionType.THROW && slotId >= 0 && slotId < player.currentScreenHandler.slots.size()) { @@ -108,7 +110,7 @@ private void onAttackBlock(BlockPos blockPos, Direction direction, CallbackInfoR if (!sm.instamine() || !sm.filter(state.getBlock())) return; if (state.calcBlockBreakingDelta(mc.player, mc.world, blockPos) > 0.5f) { - mc.world.breakBlock(blockPos, true, mc.player); + breakBlock(blockPos); networkHandler.sendPacket(new PlayerActionC2SPacket(PlayerActionC2SPacket.Action.START_DESTROY_BLOCK, blockPos, direction)); networkHandler.sendPacket(new PlayerActionC2SPacket(PlayerActionC2SPacket.Action.STOP_DESTROY_BLOCK, blockPos, direction)); info.setReturnValue(true); @@ -136,16 +138,6 @@ private void onDropCreativeStack(ItemStack stack, CallbackInfo info) { if (MeteorClient.EVENT_BUS.post(DropItemsEvent.get(stack)).isCancelled()) info.cancel(); } - @Inject(method = "getReachDistance", at = @At("HEAD"), cancellable = true) - private void onGetReachDistance(CallbackInfoReturnable info) { - info.setReturnValue(Modules.get().get(Reach.class).blockReach()); - } - - @Inject(method = "hasExtendedReach", at = @At("HEAD"), cancellable = true) - private void onHasExtendedReach(CallbackInfoReturnable info) { - if (Modules.get().isActive(Reach.class)) info.setReturnValue(false); - } - @Redirect(method = "updateBlockBreakingProgress", at = @At(value = "FIELD", target = "Lnet/minecraft/client/network/ClientPlayerInteractionManager;blockBreakingCooldown:I", opcode = Opcodes.PUTFIELD, ordinal = 1)) private void creativeBreakDelayChange(ClientPlayerInteractionManager interactionManager, int value) { BlockBreakingCooldownEvent event = MeteorClient.EVENT_BUS.post(BlockBreakingCooldownEvent.get(value)); @@ -177,13 +169,7 @@ private float deltaChange(BlockState blockState, PlayerEntity player, BlockView @Inject(method = "breakBlock", at = @At("HEAD"), cancellable = true) private void onBreakBlock(BlockPos blockPos, CallbackInfoReturnable info) { - final BreakBlockEvent event = BreakBlockEvent.get(blockPos); - MeteorClient.EVENT_BUS.post(event); - - if (event.isCancelled()) { - info.setReturnValue(false); - info.cancel(); - } + if (MeteorClient.EVENT_BUS.post(BreakBlockEvent.get(blockPos)).isCancelled()) info.setReturnValue(false); } @Inject(method = "interactItem", at = @At("HEAD"), cancellable = true) @@ -206,7 +192,7 @@ private void onInteractItem(Args args) { } @Override - public void syncSelected() { + public void meteor$syncSelected() { syncSelectedSlot(); } } diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/CobwebBlockMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/CobwebBlockMixin.java index 59c0655bf6..ec594fb381 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/CobwebBlockMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/CobwebBlockMixin.java @@ -20,7 +20,7 @@ import static meteordevelopment.meteorclient.MeteorClient.mc; @Mixin(CobwebBlock.class) -public class CobwebBlockMixin { +public abstract class CobwebBlockMixin { @Inject(method = "onEntityCollision", at = @At("HEAD"), cancellable = true) private void onEntityCollision(BlockState state, World world, BlockPos pos, Entity entity, CallbackInfo info) { if (entity == mc.player && Modules.get().get(NoSlow.class).cobweb()) info.cancel(); diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/CompassAnglePredicateProviderMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/CompassAnglePredicateProviderMixin.java index feb2bc261a..a08ed2263d 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/CompassAnglePredicateProviderMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/CompassAnglePredicateProviderMixin.java @@ -5,23 +5,36 @@ package meteordevelopment.meteorclient.mixin; +import com.llamalad7.mixinextras.injector.ModifyExpressionValue; +import com.llamalad7.mixinextras.injector.ModifyReturnValue; +import meteordevelopment.meteorclient.systems.modules.Modules; +import meteordevelopment.meteorclient.systems.modules.render.Freecam; import net.minecraft.client.item.CompassAnglePredicateProvider; +import net.minecraft.client.render.Camera; +import net.minecraft.entity.Entity; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Vec3d; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; + +import static meteordevelopment.meteorclient.MeteorClient.mc; @Mixin(CompassAnglePredicateProvider.class) -public class CompassAnglePredicateProviderMixin { - // TODO: I don't fucking know, someone fix this - /*@Redirect(method = "method_43213", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;getBodyYaw()F")) - private float callLivingEntityGetYaw(Entity entity) { +public abstract class CompassAnglePredicateProviderMixin { + @ModifyExpressionValue(method = "getBodyYaw", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;getBodyYaw()F")) + private float callLivingEntityGetYaw(float original) { if (Modules.get().isActive(Freecam.class)) return mc.gameRenderer.getCamera().getYaw(); - return entity.getYaw(); - }*/ + return original; + } - /*@Inject(method = "getAngleTo", at = @At("HEAD"), cancellable = true) - private void onGetAngleToPos(Entity entity, long time, BlockPos pos, CallbackInfoReturnable info) { + @ModifyReturnValue(method = "getAngleTo(Lnet/minecraft/entity/Entity;Lnet/minecraft/util/math/BlockPos;)D", at = @At("RETURN")) + private double modifyGetAngleTo(double original, Entity entity, BlockPos pos) { if (Modules.get().isActive(Freecam.class)) { + Vec3d vec3d = Vec3d.ofCenter(pos); Camera camera = mc.gameRenderer.getCamera(); - info.setReturnValue((float) Math.atan2(pos.getZ() - camera.getPos().z, pos.getX() - camera.getPos().x)); + return Math.atan2(vec3d.getZ() - camera.getPos().z, vec3d.getX() - camera.getPos().x) / (float) (Math.PI * 2); } - }*/ + + return original; + } } diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/ConnectScreenMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/ConnectScreenMixin.java index fac824368d..6d2e056e5d 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/ConnectScreenMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/ConnectScreenMixin.java @@ -9,6 +9,7 @@ import meteordevelopment.meteorclient.events.world.ServerConnectBeginEvent; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.screen.multiplayer.ConnectScreen; +import net.minecraft.client.network.CookieStorage; import net.minecraft.client.network.ServerAddress; import net.minecraft.client.network.ServerInfo; import org.spongepowered.asm.mixin.Mixin; @@ -17,9 +18,9 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(ConnectScreen.class) -public class ConnectScreenMixin { - @Inject(method = "connect(Lnet/minecraft/client/MinecraftClient;Lnet/minecraft/client/network/ServerAddress;Lnet/minecraft/client/network/ServerInfo;)V", at = @At("HEAD")) - private void tryConnectEvent(MinecraftClient client, ServerAddress address, ServerInfo info, CallbackInfo ci) { +public abstract class ConnectScreenMixin { + @Inject(method = "connect(Lnet/minecraft/client/MinecraftClient;Lnet/minecraft/client/network/ServerAddress;Lnet/minecraft/client/network/ServerInfo;Lnet/minecraft/client/network/CookieStorage;)V", at = @At("HEAD")) + private void tryConnectEvent(MinecraftClient client, ServerAddress address, ServerInfo info, CookieStorage cookieStorage, CallbackInfo ci) { MeteorClient.EVENT_BUS.post(ServerConnectBeginEvent.get(address, info)); } } diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/CrashReportMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/CrashReportMixin.java index c9cf89c743..6f50dc96d2 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/CrashReportMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/CrashReportMixin.java @@ -21,7 +21,7 @@ import java.util.List; @Mixin(CrashReport.class) -public class CrashReportMixin { +public abstract class CrashReportMixin { @Inject(method = "addStackTrace", at = @At("TAIL")) private void onAddStackTrace(StringBuilder sb, CallbackInfo info) { sb.append("\n\n-- Meteor Client --\n\n"); diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/CreativeSlotMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/CreativeSlotMixin.java index d78cf6050e..80b24bc223 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/CreativeSlotMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/CreativeSlotMixin.java @@ -12,7 +12,7 @@ import org.spongepowered.asm.mixin.Shadow; @Mixin(targets = "net.minecraft.client.gui.screen.ingame.CreativeInventoryScreen$CreativeSlot") -public class CreativeSlotMixin implements ISlot { +public abstract class CreativeSlotMixin implements ISlot { @Shadow @Final Slot slot; @Override diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/CrossbowItemAccessor.java b/src/main/java/meteordevelopment/meteorclient/mixin/CrossbowItemAccessor.java index 1691cff90f..5ce1875a9d 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/CrossbowItemAccessor.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/CrossbowItemAccessor.java @@ -5,13 +5,13 @@ package meteordevelopment.meteorclient.mixin; +import net.minecraft.component.type.ChargedProjectilesComponent; import net.minecraft.item.CrossbowItem; -import net.minecraft.item.ItemStack; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.gen.Invoker; @Mixin(CrossbowItem.class) public interface CrossbowItemAccessor { @Invoker("getSpeed") - static float getSpeed(ItemStack itemStack) { return 0; } + static float getSpeed(ChargedProjectilesComponent itemStack) { return 0; } } diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/CustomPayloadS2CPacketMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/CustomPayloadS2CPacketMixin.java deleted file mode 100644 index 01a3ff3fef..0000000000 --- a/src/main/java/meteordevelopment/meteorclient/mixin/CustomPayloadS2CPacketMixin.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * This file is part of the Meteor Client distribution (https://github.com/MeteorDevelopment/meteor-client). - * Copyright (c) Meteor Development. - */ - -package meteordevelopment.meteorclient.mixin; - -import meteordevelopment.meteorclient.systems.modules.Modules; -import meteordevelopment.meteorclient.systems.modules.misc.AntiPacketKick; -import net.minecraft.network.packet.s2c.common.CustomPayloadS2CPacket; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.Constant; -import org.spongepowered.asm.mixin.injection.ModifyConstant; - -@Mixin(CustomPayloadS2CPacket.class) -public class CustomPayloadS2CPacketMixin { - @ModifyConstant(method = "readUnknownPayload", constant = @Constant(intValue = 1048576)) - private static int maxValue(int value) { - return Modules.get().isActive(AntiPacketKick.class) ? Integer.MAX_VALUE : value; - } -} diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/DefaultSkinHelperMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/DefaultSkinHelperMixin.java index a710fc3c87..22c5e91ef2 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/DefaultSkinHelperMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/DefaultSkinHelperMixin.java @@ -14,7 +14,7 @@ import java.util.UUID; @Mixin(DefaultSkinHelper.class) -public class DefaultSkinHelperMixin { +public abstract class DefaultSkinHelperMixin { // Player model rendering in main menu @Inject(method = "getSkinTextures(Ljava/util/UUID;)Lnet/minecraft/client/util/SkinTextures;", at = @At("HEAD"), cancellable = true) private static void onShouldUseSlimModel(UUID uuid, CallbackInfoReturnable info) { diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/DisconnectedScreenMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/DisconnectedScreenMixin.java index 44d87fbacc..f96e6c603c 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/DisconnectedScreenMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/DisconnectedScreenMixin.java @@ -78,6 +78,6 @@ private String getText() { @Unique private void tryConnecting() { var lastServer = Modules.get().get(AutoReconnect.class).lastServerConnection; - ConnectScreen.connect(new TitleScreen(), mc, lastServer.left(), lastServer.right(), false); + ConnectScreen.connect(new TitleScreen(), mc, lastServer.left(), lastServer.right(), false, null); } } diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/DrawContextMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/DrawContextMixin.java index 52d2aa8e69..904d377e5c 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/DrawContextMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/DrawContextMixin.java @@ -23,7 +23,7 @@ import java.util.function.Consumer; @Mixin(value = DrawContext.class) -public class DrawContextMixin { +public abstract class DrawContextMixin { @Inject(method = "drawTooltip(Lnet/minecraft/client/font/TextRenderer;Ljava/util/List;Ljava/util/Optional;II)V", at = @At(value = "INVOKE", target = "Ljava/util/Optional;ifPresent(Ljava/util/function/Consumer;)V", shift = At.Shift.BEFORE), locals = LocalCapture.CAPTURE_FAILHARD) private void onDrawTooltip(TextRenderer textRenderer, List text, Optional data, int x, int y, CallbackInfo ci, List list) { if (data.isPresent() && data.get() instanceof MeteorTooltipData meteorTooltipData) diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/EnchantingTableBlockEntityRendererMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/EnchantingTableBlockEntityRendererMixin.java index f429468f36..d17f55bb69 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/EnchantingTableBlockEntityRendererMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/EnchantingTableBlockEntityRendererMixin.java @@ -5,7 +5,7 @@ package meteordevelopment.meteorclient.mixin; -import com.llamalad7.mixinextras.injector.WrapWithCondition; +import com.llamalad7.mixinextras.injector.v2.WrapWithCondition; import meteordevelopment.meteorclient.systems.modules.Modules; import meteordevelopment.meteorclient.systems.modules.render.NoRender; import net.minecraft.client.render.VertexConsumer; @@ -16,7 +16,7 @@ import org.spongepowered.asm.mixin.injection.At; @Mixin(EnchantingTableBlockEntityRenderer.class) -public class EnchantingTableBlockEntityRendererMixin { +public abstract class EnchantingTableBlockEntityRendererMixin { @WrapWithCondition(method = "render(Lnet/minecraft/block/entity/EnchantingTableBlockEntity;FLnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;II)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/entity/model/BookModel;renderBook(Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumer;IIFFFF)V")) private boolean onRenderBookModelRenderProxy(BookModel model, MatrixStack matrixStack, VertexConsumer vertexConsumer, int i, int j, float f, float g, float h, float k) { return !Modules.get().get(NoRender.class).noEnchTableBook(); diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/EntityAttributeInstanceMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/EntityAttributeInstanceMixin.java deleted file mode 100644 index 58cf2eb80c..0000000000 --- a/src/main/java/meteordevelopment/meteorclient/mixin/EntityAttributeInstanceMixin.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * This file is part of the Meteor Client distribution (https://github.com/MeteorDevelopment/meteor-client). - * Copyright (c) Meteor Development. - */ - -package meteordevelopment.meteorclient.mixin; - -import meteordevelopment.meteorclient.mixininterface.IEntityAttributeInstance; -import net.minecraft.entity.attribute.EntityAttributeInstance; -import net.minecraft.entity.attribute.EntityAttributeModifier; -import org.jetbrains.annotations.Nullable; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; - -import java.util.Map; -import java.util.Set; -import java.util.UUID; - -@Mixin(EntityAttributeInstance.class) -public abstract class EntityAttributeInstanceMixin implements IEntityAttributeInstance { - @Shadow @Final private Map idToModifiers; - @Shadow @Final private Set persistentModifiers; - @Shadow public abstract Set getModifiers(EntityAttributeModifier.Operation operation); - @Shadow protected abstract void onUpdate(); - - @Override - public void meteor$copyFrom(EntityAttributeInstance other) { - for (var modifier : other.getModifiers()) { - @Nullable EntityAttributeModifier old = idToModifiers.put(modifier.getId(), modifier); - if (old != null) { - getModifiers(old.getOperation()).remove(old); - persistentModifiers.remove(old); - } - getModifiers(modifier.getOperation()).add(modifier); - } - onUpdate(); - } -} diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/EntityEffectParticleEffectAccessor.java b/src/main/java/meteordevelopment/meteorclient/mixin/EntityEffectParticleEffectAccessor.java new file mode 100644 index 0000000000..e071573e53 --- /dev/null +++ b/src/main/java/meteordevelopment/meteorclient/mixin/EntityEffectParticleEffectAccessor.java @@ -0,0 +1,16 @@ +/* + * This file is part of the Meteor Client distribution (https://github.com/MeteorDevelopment/meteor-client). + * Copyright (c) Meteor Development. + */ + +package meteordevelopment.meteorclient.mixin; + +import net.minecraft.particle.EntityEffectParticleEffect; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; + +@Mixin(EntityEffectParticleEffect.class) +public interface EntityEffectParticleEffectAccessor { + @Accessor + int getColor(); +} diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/EntityMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/EntityMixin.java index 74e4af8f4f..e62c6f6395 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/EntityMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/EntityMixin.java @@ -13,10 +13,7 @@ import meteordevelopment.meteorclient.events.entity.player.PlayerMoveEvent; import meteordevelopment.meteorclient.systems.modules.Modules; import meteordevelopment.meteorclient.systems.modules.combat.Hitboxes; -import meteordevelopment.meteorclient.systems.modules.movement.Flight; -import meteordevelopment.meteorclient.systems.modules.movement.NoFall; -import meteordevelopment.meteorclient.systems.modules.movement.NoSlow; -import meteordevelopment.meteorclient.systems.modules.movement.Velocity; +import meteordevelopment.meteorclient.systems.modules.movement.*; import meteordevelopment.meteorclient.systems.modules.movement.elytrafly.ElytraFly; import meteordevelopment.meteorclient.systems.modules.render.ESP; import meteordevelopment.meteorclient.systems.modules.render.NoRender; @@ -69,6 +66,22 @@ private void isInLava(CallbackInfoReturnable info) { if ((Object) this == mc.player && Modules.get().get(NoSlow.class).fluidDrag()) info.setReturnValue(false); } + @Inject(method = "onBubbleColumnSurfaceCollision", at = @At("HEAD")) + private void onBubbleColumnSurfaceCollision(CallbackInfo info) { + Jesus jesus = Modules.get().get(Jesus.class); + if ((Object) this == mc.player && jesus.isActive()) { + jesus.isInBubbleColumn = true; + } + } + + @Inject(method = "onBubbleColumnCollision", at = @At("HEAD")) + private void onBubbleColumnCollision(CallbackInfo info) { + Jesus jesus = Modules.get().get(Jesus.class); + if ((Object) this == mc.player && jesus.isActive()) { + jesus.isInBubbleColumn = true; + } + } + @ModifyExpressionValue(method = "updateSwimming", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;isSubmergedInWater()Z")) private boolean isSubmergedInWater(boolean submerged) { if ((Object) this == mc.player && Modules.get().get(NoSlow.class).fluidDrag()) return false; diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/EntityRendererMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/EntityRendererMixin.java index d7d227aedc..4409222e3d 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/EntityRendererMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/EntityRendererMixin.java @@ -36,12 +36,12 @@ public abstract class EntityRendererMixin implements IEntityRe public abstract Identifier getTexture(Entity entity); @Inject(method = "renderLabelIfPresent", at = @At("HEAD"), cancellable = true) - private void onRenderLabel(T entity, Text text, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, CallbackInfo info) { - if (PostProcessShaders.rendering) info.cancel(); - if (Modules.get().get(NoRender.class).noNametags()) info.cancel(); + private void onRenderLabel(T entity, Text text, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, float tickDelta, CallbackInfo ci) { + if (PostProcessShaders.rendering) ci.cancel(); + if (Modules.get().get(NoRender.class).noNametags()) ci.cancel(); if (!(entity instanceof PlayerEntity)) return; if (Modules.get().get(Nametags.class).playerNametags() && !(EntityUtils.getGameMode((PlayerEntity) entity) == null && Modules.get().get(Nametags.class).excludeBots())) - info.cancel(); + ci.cancel(); } @Inject(method = "shouldRender", at = @At("HEAD"), cancellable = true) diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/ExplosionMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/ExplosionMixin.java index 7e8a98d5a7..249df8bc33 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/ExplosionMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/ExplosionMixin.java @@ -19,7 +19,7 @@ import static meteordevelopment.meteorclient.MeteorClient.mc; @Mixin(Explosion.class) -public class ExplosionMixin implements IExplosion { +public abstract class ExplosionMixin implements IExplosion { @Shadow @Final @Mutable private World world; @Shadow @Final @Mutable @Nullable private Entity entity; diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/ExplosionS2CPacketMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/ExplosionS2CPacketMixin.java index 1a36efd412..e837f1aaaa 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/ExplosionS2CPacketMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/ExplosionS2CPacketMixin.java @@ -13,7 +13,7 @@ import org.spongepowered.asm.mixin.Shadow; @Mixin(ExplosionS2CPacket.class) -public class ExplosionS2CPacketMixin implements IExplosionS2CPacket { +public abstract class ExplosionS2CPacketMixin implements IExplosionS2CPacket { @Shadow @Final @Mutable private float playerVelocityX; @Shadow @Final @Mutable private float playerVelocityY; diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/FireworksSparkParticleMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/FireworksSparkParticleMixin.java index d486d8e346..a87d415071 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/FireworksSparkParticleMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/FireworksSparkParticleMixin.java @@ -5,6 +5,7 @@ package meteordevelopment.meteorclient.mixin; +import it.unimi.dsi.fastutil.ints.IntList; import net.minecraft.client.particle.FireworksSparkParticle; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -13,9 +14,9 @@ import org.spongepowered.asm.mixin.injection.callback.LocalCapture; @Mixin(FireworksSparkParticle.FireworkParticle.class) -public class FireworksSparkParticleMixin { +public abstract class FireworksSparkParticleMixin { @Inject(method = "addExplosionParticle", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/particle/FireworksSparkParticle$Explosion;setTrail(Z)V"), cancellable = true, locals = LocalCapture.CAPTURE_FAILSOFT) - private void onAddExplosion(double x, double y, double z, double velocityX, double velocityY, double velocityZ, int[] colors, int[] fadeColors, boolean trail, boolean flicker, CallbackInfo info, FireworksSparkParticle.Explosion explosion) { + private void onAddExplosion(double x, double y, double z, double velocityX, double velocityY, double velocityZ, IntList colors, IntList targetColors, boolean trail, boolean flicker, CallbackInfo info, FireworksSparkParticle.Explosion explosion) { if (explosion == null) info.cancel(); } } diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/FireworksSparkParticleSubMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/FireworksSparkParticleSubMixin.java index 0a6cc1e2e6..4f99f06fc0 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/FireworksSparkParticleSubMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/FireworksSparkParticleSubMixin.java @@ -16,7 +16,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(value = {FireworksSparkParticle.Explosion.class, FireworksSparkParticle.Flash.class}) -public class FireworksSparkParticleSubMixin { +public abstract class FireworksSparkParticleSubMixin { @Inject(method = "buildGeometry", at = @At("HEAD"), cancellable = true) private void buildExplosionGeometry(VertexConsumer vertexConsumer, Camera camera, float tickDelta, CallbackInfo info) { if (Modules.get().get(NoRender.class).noFireworkExplosions()) info.cancel(); diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/FishingBobberEntityMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/FishingBobberEntityMixin.java index 01cc2d60e3..5aa409b185 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/FishingBobberEntityMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/FishingBobberEntityMixin.java @@ -17,7 +17,7 @@ import static meteordevelopment.meteorclient.MeteorClient.mc; @Mixin(FishingBobberEntity.class) -public class FishingBobberEntityMixin { +public abstract class FishingBobberEntityMixin { @WrapOperation(method = "handleStatus", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/projectile/FishingBobberEntity;pullHookedEntity(Lnet/minecraft/entity/Entity;)V")) private void preventFishingRodPull(FishingBobberEntity instance, Entity entity, Operation original) { if (!instance.getWorld().isClient || entity != mc.player) original.call(instance, entity); diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/FluidRendererMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/FluidRendererMixin.java index e54bc17f84..53dab9cadd 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/FluidRendererMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/FluidRendererMixin.java @@ -23,7 +23,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(FluidRenderer.class) -public class FluidRendererMixin { +public abstract class FluidRendererMixin { @Unique private final ThreadLocal alphas = new ThreadLocal<>(); @Inject(method = "render", at = @At("HEAD"), cancellable = true) diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/FoliageColorsMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/FoliageColorsMixin.java index f27714a9a6..bc1e7e2282 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/FoliageColorsMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/FoliageColorsMixin.java @@ -13,7 +13,7 @@ import org.spongepowered.asm.mixin.injection.At; @Mixin(FoliageColors.class) -public class FoliageColorsMixin { +public abstract class FoliageColorsMixin { @ModifyReturnValue(method = "getBirchColor", at = @At("RETURN")) private static int onGetBirchColor(int original) { diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/GameOptionsMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/GameOptionsMixin.java index eeeda87148..cfbc41745d 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/GameOptionsMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/GameOptionsMixin.java @@ -26,7 +26,7 @@ import java.io.File; @Mixin(GameOptions.class) -public class GameOptionsMixin { +public abstract class GameOptionsMixin { @Inject(method = "setPerspective", at = @At("HEAD"), cancellable = true) private void setPerspective(Perspective perspective, CallbackInfo info) { if (Modules.get() == null) return; // nothing is loaded yet, shouldersurfing compat diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/GameRendererMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/GameRendererMixin.java index 04464a4c6a..728840038e 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/GameRendererMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/GameRendererMixin.java @@ -15,7 +15,6 @@ import meteordevelopment.meteorclient.systems.modules.Modules; import meteordevelopment.meteorclient.systems.modules.player.LiquidInteract; import meteordevelopment.meteorclient.systems.modules.player.NoMiningTrace; -import meteordevelopment.meteorclient.systems.modules.player.Reach; import meteordevelopment.meteorclient.systems.modules.render.Freecam; import meteordevelopment.meteorclient.systems.modules.render.HideRenderModules; import meteordevelopment.meteorclient.systems.modules.render.NoRender; @@ -32,45 +31,88 @@ import net.minecraft.item.ItemStack; import net.minecraft.item.Items; import net.minecraft.util.hit.HitResult; -import org.joml.Matrix3f; import org.joml.Matrix4f; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Unique; -import org.spongepowered.asm.mixin.injection.*; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.LocalCapture; @Mixin(GameRenderer.class) public abstract class GameRendererMixin { - @Shadow @Final MinecraftClient client; + @Shadow + @Final + MinecraftClient client; - @Shadow public abstract void updateTargetedEntity(float tickDelta); + @Shadow + public abstract void updateCrosshairTarget(float tickDelta); - @Shadow public abstract void reset(); + @Shadow + public abstract void reset(); - @Shadow @Final private Camera camera; - @Unique private Renderer3D renderer; + @Shadow + @Final + private Camera camera; - @Inject(method = "renderWorld", at = @At(value = "INVOKE_STRING", target = "Lnet/minecraft/util/profiler/Profiler;swap(Ljava/lang/String;)V", args = { "ldc=hand" }), locals = LocalCapture.CAPTURE_FAILEXCEPTION) - private void onRenderWorld(float tickDelta, long limitTime, MatrixStack matrices, CallbackInfo ci, boolean bl, Camera camera, Entity entity, MatrixStack matrixStack, double d, float f, float g, Matrix4f matrix4f, Matrix3f matrix3f) { + @Shadow + protected abstract void bobView(MatrixStack matrices, float tickDelta); + + @Shadow + protected abstract void tiltViewWhenHurt(MatrixStack matrices, float tickDelta); + + @Unique + private Renderer3D renderer; + + @Unique + private final MatrixStack matrices = new MatrixStack(); + + // FIXME: unsure + @Inject(method = "renderWorld", at = @At(value = "INVOKE_STRING", target = "Lnet/minecraft/util/profiler/Profiler;swap(Ljava/lang/String;)V", args = {"ldc=hand"}), locals = LocalCapture.CAPTURE_FAILEXCEPTION) + private void onRenderWorld(float tickDelta, long limitTime, CallbackInfo ci, boolean bl, Camera camera, Entity entity, double d, Matrix4f matrix4f, MatrixStack matrixStack, float f, float g, Matrix4f matrix4f2) { if (!Utils.canUpdate()) return; if (Modules.get().isActive(HideRenderModules.class)) return; client.getProfiler().push(MeteorClient.MOD_ID + "_render"); + // Create renderer and event + if (renderer == null) renderer = new Renderer3D(); - Render3DEvent event = Render3DEvent.get(matrices, renderer, tickDelta, camera.getPos().x, camera.getPos().y, camera.getPos().z); + Render3DEvent event = Render3DEvent.get(matrixStack, renderer, tickDelta, camera.getPos().x, camera.getPos().y, camera.getPos().z); + + // Call utility classes RenderUtils.updateScreenCenter(); - NametagUtils.onRender(matrices, matrix4f); + NametagUtils.onRender(matrix4f2); + + // Update model view matrix + + RenderSystem.getModelViewStack().pushMatrix().mul(matrix4f2); + + matrices.push(); + + tiltViewWhenHurt(matrices, camera.getLastTickDelta()); + if (client.options.getBobView().getValue()) bobView(matrices, camera.getLastTickDelta()); + + RenderSystem.getModelViewStack().mul(matrices.peek().getPositionMatrix().invert()); + matrices.pop(); + + RenderSystem.applyModelViewMatrix(); + + // Render renderer.begin(); MeteorClient.EVENT_BUS.post(event); - renderer.render(matrices); + renderer.render(matrixStack); + // Revert model view matrix + + RenderSystem.getModelViewStack().popMatrix(); RenderSystem.applyModelViewMatrix(); + client.getProfiler().pop(); } @@ -79,7 +121,7 @@ private void onRenderWorldTail(CallbackInfo info) { MeteorClient.EVENT_BUS.post(RenderAfterWorldEvent.get()); } - @Inject(method = "updateTargetedEntity", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/projectile/ProjectileUtil;raycast(Lnet/minecraft/entity/Entity;Lnet/minecraft/util/math/Vec3d;Lnet/minecraft/util/math/Vec3d;Lnet/minecraft/util/math/Box;Ljava/util/function/Predicate;D)Lnet/minecraft/util/hit/EntityHitResult;"), cancellable = true) + @Inject(method = "updateCrosshairTarget", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/GameRenderer;findCrosshairTarget(Lnet/minecraft/entity/Entity;DDF)Lnet/minecraft/util/hit/HitResult;"), cancellable = true) private void onUpdateTargetedEntity(float tickDelta, CallbackInfo info) { if (Modules.get().get(NoMiningTrace.class).canWork() && client.crosshairTarget.getType() == HitResult.Type.BLOCK) { client.getProfiler().pop(); @@ -87,7 +129,7 @@ private void onUpdateTargetedEntity(float tickDelta, CallbackInfo info) { } } - @Redirect(method = "updateTargetedEntity", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;raycast(DFZ)Lnet/minecraft/util/hit/HitResult;")) + @Redirect(method = "findCrosshairTarget", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;raycast(DFZ)Lnet/minecraft/util/hit/HitResult;")) private HitResult updateTargetedEntityEntityRayTraceProxy(Entity entity, double maxDistance, float tickDelta, boolean includeFluids) { if (Modules.get().isActive(LiquidInteract.class)) { HitResult result = entity.raycast(maxDistance, tickDelta, includeFluids); @@ -112,9 +154,10 @@ private float applyCameraTransformationsMathHelperLerpProxy(float original) { // Freecam + @Unique private boolean freecamSet = false; - @Inject(method = "updateTargetedEntity", at = @At("HEAD"), cancellable = true) + @Inject(method = "updateCrosshairTarget", at = @At("HEAD"), cancellable = true) private void updateTargetedEntityInvoke(float tickDelta, CallbackInfo info) { Freecam freecam = Modules.get().get(Freecam.class); boolean highwayBuilder = Modules.get().isActive(HighwayBuilder.class); @@ -137,8 +180,7 @@ private void updateTargetedEntityInvoke(float tickDelta, CallbackInfo info) { if (highwayBuilder) { cameraE.setYaw(camera.getYaw()); cameraE.setPitch(camera.getPitch()); - } - else { + } else { ((IVec3d) cameraE.getPos()).set(freecam.pos.x, freecam.pos.y - cameraE.getEyeHeight(cameraE.getPose()), freecam.pos.z); cameraE.prevX = freecam.prevPos.x; cameraE.prevY = freecam.prevPos.y - cameraE.getEyeHeight(cameraE.getPose()); @@ -150,7 +192,7 @@ private void updateTargetedEntityInvoke(float tickDelta, CallbackInfo info) { } freecamSet = true; - updateTargetedEntity(tickDelta); + updateCrosshairTarget(tickDelta); freecamSet = false; ((IVec3d) cameraE.getPos()).set(x, y, z); @@ -165,20 +207,9 @@ private void updateTargetedEntityInvoke(float tickDelta, CallbackInfo info) { } @Inject(method = "renderHand", at = @At("HEAD"), cancellable = true) - private void renderHand(MatrixStack matrices, Camera camera, float tickDelta, CallbackInfo info) { + private void renderHand(Camera camera, float tickDelta, Matrix4f matrix4f, CallbackInfo ci) { if (!Modules.get().get(Freecam.class).renderHands() || !Modules.get().get(Zoom.class).renderHands()) - info.cancel(); - } - - @ModifyConstant(method = "updateTargetedEntity", constant = @Constant(doubleValue = 6), require = 0) - private double updateTargetedEntityModifySurvivalReach(double d) { - return Modules.get().get(Reach.class).entityReach(); - } - - @ModifyConstant(method = "updateTargetedEntity", constant = @Constant(doubleValue = 9), require = 0) - private double updateTargetedEntityModifySquaredMaxReach(double d) { - Reach reach = Modules.get().get(Reach.class); - return reach.entityReach() * reach.entityReach(); + ci.cancel(); } } diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/HandledScreenMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/HandledScreenMixin.java index 18a7658299..66072bc939 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/HandledScreenMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/HandledScreenMixin.java @@ -21,9 +21,11 @@ import net.minecraft.screen.slot.Slot; import net.minecraft.screen.slot.SlotActionType; import net.minecraft.text.Text; +import org.jetbrains.annotations.Nullable; import org.lwjgl.glfw.GLFW; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @@ -34,19 +36,28 @@ @Mixin(HandledScreen.class) public abstract class HandledScreenMixin extends Screen implements ScreenHandlerProvider { - @Shadow protected Slot focusedSlot; + @Shadow + protected Slot focusedSlot; - @Shadow protected int x; - @Shadow protected int y; + @Shadow + protected int x; + @Shadow + protected int y; - @Shadow @org.jetbrains.annotations.Nullable protected abstract Slot getSlotAt(double xPosition, double yPosition); + @Shadow + @Nullable + protected abstract Slot getSlotAt(double xPosition, double yPosition); - @Shadow public abstract T getScreenHandler(); + @Shadow + public abstract T getScreenHandler(); - @Shadow private boolean doubleClicking; + @Shadow + private boolean doubleClicking; - @Shadow protected abstract void onMouseClick(Slot slot, int invSlot, int clickData, SlotActionType actionType); + @Shadow + protected abstract void onMouseClick(Slot slot, int invSlot, int clickData, SlotActionType actionType); + @Unique private static final ItemStack[] ITEMS = new ItemStack[27]; public HandledScreenMixin(Text title) { @@ -60,14 +71,14 @@ private void onInit(CallbackInfo info) { if (invTweaks.isActive() && invTweaks.showButtons() && invTweaks.canSteal(getScreenHandler())) { addDrawableChild( new ButtonWidget.Builder(Text.literal("Steal"), button -> invTweaks.steal(getScreenHandler())) - .position(width / 2 - 41, 3) + .position(x, y - 22) .size(40, 20) .build() ); addDrawableChild( new ButtonWidget.Builder(Text.literal("Dump"), button -> invTweaks.dump(getScreenHandler())) - .position(width / 2 + 2, 3) + .position(x + 42, y - 22) .size(40, 20) .build() ); diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/InGameHudMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/InGameHudMixin.java index 24288deca6..8796e51175 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/InGameHudMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/InGameHudMixin.java @@ -18,8 +18,6 @@ import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.hud.InGameHud; -import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.client.option.Perspective; import net.minecraft.entity.Entity; import net.minecraft.scoreboard.ScoreboardObjective; import org.spongepowered.asm.mixin.Final; @@ -33,10 +31,6 @@ @Mixin(InGameHud.class) public abstract class InGameHudMixin { - @Shadow private int scaledWidth; - - @Shadow private int scaledHeight; - @Shadow @Final private MinecraftClient client; @Shadow public abstract void clear(); @@ -48,7 +42,7 @@ private void onRender(DrawContext context, float tickDelta, CallbackInfo ci) { Utils.unscaledProjection(); - MeteorClient.EVENT_BUS.post(Render2DEvent.get(context, scaledWidth, scaledHeight, tickDelta)); + MeteorClient.EVENT_BUS.post(Render2DEvent.get(context, context.getScaledWindowWidth(), context.getScaledWindowWidth(), tickDelta)); Utils.scaledProjection(); RenderSystem.applyModelViewMatrix(); @@ -66,12 +60,12 @@ private void onRenderPortalOverlay(DrawContext context, float nauseaStrength, Ca if (Modules.get().get(NoRender.class).noPortalOverlay()) ci.cancel(); } - @ModifyArgs(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/hud/InGameHud;renderOverlay(Lnet/minecraft/client/gui/DrawContext;Lnet/minecraft/util/Identifier;F)V", ordinal = 0)) + @ModifyArgs(method = "renderMiscOverlays", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/hud/InGameHud;renderOverlay(Lnet/minecraft/client/gui/DrawContext;Lnet/minecraft/util/Identifier;F)V", ordinal = 0)) private void onRenderPumpkinOverlay(Args args) { if (Modules.get().get(NoRender.class).noPumpkinOverlay()) args.set(2, 0f); } - @ModifyArgs(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/hud/InGameHud;renderOverlay(Lnet/minecraft/client/gui/DrawContext;Lnet/minecraft/util/Identifier;F)V", ordinal = 1)) + @ModifyArgs(method = "renderMiscOverlays", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/hud/InGameHud;renderOverlay(Lnet/minecraft/client/gui/DrawContext;Lnet/minecraft/util/Identifier;F)V", ordinal = 1)) private void onRenderPowderedSnowOverlay(Args args) { if (Modules.get().get(NoRender.class).noPowderedSnowOverlay()) args.set(2, 0f); } @@ -81,11 +75,16 @@ private void onRenderVignetteOverlay(DrawContext context, Entity entity, Callbac if (Modules.get().get(NoRender.class).noVignette()) ci.cancel(); } - @Inject(method = "renderScoreboardSidebar", at = @At("HEAD"), cancellable = true) + @Inject(method = "renderScoreboardSidebar(Lnet/minecraft/client/gui/DrawContext;Lnet/minecraft/scoreboard/ScoreboardObjective;)V", at = @At("HEAD"), cancellable = true) private void onRenderScoreboardSidebar(DrawContext context, ScoreboardObjective objective, CallbackInfo ci) { if (Modules.get().get(NoRender.class).noScoreboard()) ci.cancel(); } + @Inject(method = "renderScoreboardSidebar(Lnet/minecraft/client/gui/DrawContext;F)V", at = @At("HEAD"), cancellable = true) + private void onRenderScoreboardSidebar(DrawContext context, float tickDelta, CallbackInfo ci) { + if (Modules.get().get(NoRender.class).noScoreboard()) ci.cancel(); + } + @Inject(method = "renderSpyglassOverlay", at = @At("HEAD"), cancellable = true) private void onRenderSpyglassOverlay(DrawContext context, float scale, CallbackInfo ci) { if (Modules.get().get(NoRender.class).noSpyglassOverlay()) ci.cancel(); @@ -97,7 +96,7 @@ private boolean alwaysRenderCrosshairInFreecam(boolean firstPerson) { } @Inject(method = "renderCrosshair", at = @At("HEAD"), cancellable = true) - private void onRenderCrosshair(DrawContext context, CallbackInfo ci) { + private void onRenderCrosshair(DrawContext context, float tickDelta, CallbackInfo ci) { if (Modules.get().get(NoRender.class).noCrosshair()) ci.cancel(); } diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/InGameOverlayRendererMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/InGameOverlayRendererMixin.java index 7a0dbdfa0c..402975e34d 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/InGameOverlayRendererMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/InGameOverlayRendererMixin.java @@ -17,7 +17,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(InGameOverlayRenderer.class) -public class InGameOverlayRendererMixin { +public abstract class InGameOverlayRendererMixin { @Inject(method = "renderFireOverlay", at = @At("HEAD"), cancellable = true) private static void onRenderFireOverlay(MinecraftClient minecraftClient, MatrixStack matrixStack, CallbackInfo info) { if (Modules.get().get(NoRender.class).noFireOverlay()) info.cancel(); diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/ItemEntityMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/ItemEntityMixin.java index 0819c38866..c24f735bed 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/ItemEntityMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/ItemEntityMixin.java @@ -9,9 +9,11 @@ import net.minecraft.entity.ItemEntity; import net.minecraft.util.math.Vec3d; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Unique; @Mixin(ItemEntity.class) -public class ItemEntityMixin implements IItemEntity { +public abstract class ItemEntityMixin implements IItemEntity { + @Unique private Vec3d rotation = new Vec3d(0, 0, 0); @Override diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/ItemMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/ItemMixin.java index c608ec1586..9a0971069a 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/ItemMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/ItemMixin.java @@ -18,7 +18,7 @@ import java.util.Optional; @Mixin(Item.class) -public class ItemMixin { +public abstract class ItemMixin { @Inject(method = "getTooltipData", at=@At("HEAD"), cancellable = true) private void onTooltipData(ItemStack stack, CallbackInfoReturnable> cir) { TooltipDataEvent event = MeteorClient.EVENT_BUS.post(TooltipDataEvent.get(stack)); diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/ItemRendererMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/ItemRendererMixin.java index fca37ed5ad..039cc037ee 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/ItemRendererMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/ItemRendererMixin.java @@ -23,7 +23,7 @@ import org.spongepowered.asm.mixin.injection.invoke.arg.Args; @Mixin(ItemRenderer.class) -public class ItemRendererMixin { +public abstract class ItemRendererMixin { @ModifyArgs( method = "renderItem(Lnet/minecraft/item/ItemStack;Lnet/minecraft/client/render/model/json/ModelTransformationMode;ZLnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;IILnet/minecraft/client/render/model/BakedModel;)V", at = @At( diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/ItemStackMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/ItemStackMixin.java index f48799196e..370aca9ebf 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/ItemStackMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/ItemStackMixin.java @@ -10,11 +10,8 @@ import meteordevelopment.meteorclient.events.entity.player.FinishUsingItemEvent; import meteordevelopment.meteorclient.events.entity.player.StoppedUsingItemEvent; import meteordevelopment.meteorclient.events.game.ItemStackTooltipEvent; -import meteordevelopment.meteorclient.events.game.SectionVisibleEvent; import meteordevelopment.meteorclient.utils.Utils; -import net.minecraft.client.item.TooltipContext; import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; import net.minecraft.text.Text; import net.minecraft.world.World; @@ -31,7 +28,7 @@ @Mixin(ItemStack.class) public abstract class ItemStackMixin { @ModifyReturnValue(method = "getTooltip", at = @At("RETURN")) - private List onGetTooltip(List original, PlayerEntity player, TooltipContext context) { + private List onGetTooltip(List original) { if (Utils.canUpdate()) { ItemStackTooltipEvent event = MeteorClient.EVENT_BUS.post(ItemStackTooltipEvent.get((ItemStack) (Object) this, original)); return event.list; @@ -53,10 +50,4 @@ private void onStoppedUsing(World world, LivingEntity user, int remainingUseTick MeteorClient.EVENT_BUS.post(StoppedUsingItemEvent.get((ItemStack) (Object) this)); } } - - @ModifyReturnValue(method = "isSectionVisible", at = @At("RETURN")) - private static boolean onSectionVisible(boolean original, int flags, ItemStack.TooltipSection tooltipSection) { - SectionVisibleEvent event = MeteorClient.EVENT_BUS.post(SectionVisibleEvent.get(tooltipSection, original)); - return event.visible; - } } diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/KeyboardInputMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/KeyboardInputMixin.java index e6acfcbfef..83c38782e3 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/KeyboardInputMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/KeyboardInputMixin.java @@ -15,7 +15,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(KeyboardInput.class) -public class KeyboardInputMixin extends Input { +public abstract class KeyboardInputMixin extends Input { @Inject(method = "tick", at = @At("TAIL")) private void isPressed(boolean slowDown, float f, CallbackInfo ci) { if (Modules.get().get(Sneak.class).doVanilla()) sneaking = true; diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/LightmapTextureManagerMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/LightmapTextureManagerMixin.java index 2872b3d765..a55a800623 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/LightmapTextureManagerMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/LightmapTextureManagerMixin.java @@ -18,7 +18,7 @@ import org.spongepowered.asm.mixin.injection.invoke.arg.Args; @Mixin(LightmapTextureManager.class) -public class LightmapTextureManagerMixin { +public abstract class LightmapTextureManagerMixin { @ModifyArgs(method = "update", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/texture/NativeImage;setColor(III)V")) private void update(Args args) { if (Modules.get().get(Fullbright.class).getGamma() || Modules.get().isActive(Xray.class)) { diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/LightningEntityRendererMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/LightningEntityRendererMixin.java index fd7e1e2f8e..a8bbb09df0 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/LightningEntityRendererMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/LightningEntityRendererMixin.java @@ -17,7 +17,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(LightningEntityRenderer.class) -public class LightningEntityRendererMixin { +public abstract class LightningEntityRendererMixin { /** * @author Walaryne */ diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/LivingEntityAccessor.java b/src/main/java/meteordevelopment/meteorclient/mixin/LivingEntityAccessor.java index 63d613eeec..2b8e2046d6 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/LivingEntityAccessor.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/LivingEntityAccessor.java @@ -8,11 +8,14 @@ import net.minecraft.entity.LivingEntity; import net.minecraft.entity.data.TrackedData; import net.minecraft.fluid.Fluid; +import net.minecraft.particle.ParticleEffect; import net.minecraft.registry.tag.TagKey; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.gen.Accessor; import org.spongepowered.asm.mixin.gen.Invoker; +import java.util.List; + @Mixin(LivingEntity.class) public interface LivingEntityAccessor { @Invoker("swimUpward") @@ -26,14 +29,4 @@ public interface LivingEntityAccessor { @Accessor("jumpingCooldown") void setJumpCooldown(int cooldown); - - @Accessor("POTION_SWIRLS_COLOR") - static TrackedData meteor$getPotionSwirlsColor() { - throw new AssertionError(); - } - - @Accessor("POTION_SWIRLS_AMBIENT") - static TrackedData meteor$getPotionSwirlsAmbient() { - throw new AssertionError(); - } } diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/LivingEntityMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/LivingEntityMixin.java index 5b5f763453..e11f9e9b0c 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/LivingEntityMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/LivingEntityMixin.java @@ -18,6 +18,7 @@ import meteordevelopment.meteorclient.systems.modules.render.HandView; import meteordevelopment.meteorclient.systems.modules.render.NoRender; import meteordevelopment.meteorclient.utils.Utils; +import net.minecraft.component.DataComponentTypes; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityType; import net.minecraft.entity.EquipmentSlot; @@ -25,14 +26,15 @@ import net.minecraft.entity.damage.DamageSource; import net.minecraft.entity.effect.StatusEffect; import net.minecraft.entity.effect.StatusEffectInstance; -import net.minecraft.entity.effect.StatusEffects; import net.minecraft.fluid.FluidState; import net.minecraft.item.ItemStack; +import net.minecraft.registry.entry.RegistryEntry; import net.minecraft.util.Hand; import net.minecraft.world.World; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.*; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @@ -65,18 +67,10 @@ private boolean onCanWalkOnFluid(boolean original, FluidState fluidState) { return event.walkOnFluid; } - @Redirect(method = "travel", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;hasNoGravity()Z")) - private boolean travelHasNoGravityProxy(LivingEntity self) { - if (activeStatusEffects.containsKey(StatusEffects.LEVITATION) && Modules.get().get(PotionSpoof.class).shouldBlock(StatusEffects.LEVITATION)) { - return !Modules.get().get(PotionSpoof.class).applyGravity.get(); - } - return self.hasNoGravity(); - } - @Inject(method = "spawnItemParticles", at = @At("HEAD"), cancellable = true) private void spawnItemParticles(ItemStack stack, int count, CallbackInfo info) { NoRender noRender = Modules.get().get(NoRender.class); - if (noRender.noEatParticles() && stack.isFood()) info.cancel(); + if (noRender.noEatParticles() && stack.getComponents().contains(DataComponentTypes.FOOD)) info.cancel(); } @Inject(method = "onEquipStack", at = @At("HEAD"), cancellable = true) @@ -111,6 +105,7 @@ private boolean isFallFlyingHook(boolean original) { return original; } + @Unique private boolean previousElytra = false; @Inject(method = "isFallFlying", at = @At("TAIL"), cancellable = true) @@ -124,8 +119,8 @@ public void recastOnLand(CallbackInfoReturnable cir) { } @ModifyReturnValue(method = "hasStatusEffect", at = @At("RETURN")) - private boolean hasStatusEffect(boolean original, StatusEffect effect) { - if (Modules.get().get(PotionSpoof.class).shouldBlock(effect)) return false; + private boolean hasStatusEffect(boolean original, RegistryEntry effect) { + if (Modules.get().get(PotionSpoof.class).shouldBlock(effect.value())) return false; return original; } diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/LivingEntityRendererMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/LivingEntityRendererMixin.java index a69f012d37..8d86e3a5cf 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/LivingEntityRendererMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/LivingEntityRendererMixin.java @@ -21,7 +21,6 @@ import net.minecraft.entity.Entity; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.scoreboard.AbstractTeam; import net.minecraft.scoreboard.Team; import org.jetbrains.annotations.Nullable; import org.spongepowered.asm.mixin.Mixin; diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/MapRendererAccessor.java b/src/main/java/meteordevelopment/meteorclient/mixin/MapRendererAccessor.java index 33d3461119..d2565ef54d 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/MapRendererAccessor.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/MapRendererAccessor.java @@ -6,6 +6,7 @@ package meteordevelopment.meteorclient.mixin; import net.minecraft.client.render.MapRenderer; +import net.minecraft.component.type.MapIdComponent; import net.minecraft.item.map.MapState; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.gen.Invoker; @@ -13,5 +14,5 @@ @Mixin(MapRenderer.class) public interface MapRendererAccessor { @Invoker("getMapTexture") - MapRenderer.MapTexture invokeGetMapTexture(int id, MapState state); + MapRenderer.MapTexture invokeGetMapTexture(MapIdComponent id, MapState state); } diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/MapRendererMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/MapRendererMixin.java index c123142c41..0394134d7e 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/MapRendererMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/MapRendererMixin.java @@ -10,14 +10,14 @@ import meteordevelopment.meteorclient.systems.modules.render.NoRender; import meteordevelopment.meteorclient.utils.misc.EmptyIterator; import net.minecraft.client.render.MapRenderer; -import net.minecraft.item.map.MapIcon; +import net.minecraft.item.map.MapDecoration; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @Mixin(MapRenderer.MapTexture.class) -public class MapRendererMixin { - @ModifyExpressionValue(method = "draw(Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;ZI)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/map/MapState;getIcons()Ljava/lang/Iterable;")) - private Iterable getIconsProxy(Iterable original) { +public abstract class MapRendererMixin { + @ModifyExpressionValue(method = "draw(Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;ZI)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/map/MapState;getDecorations()Ljava/lang/Iterable;")) + private Iterable getIconsProxy(Iterable original) { return (Modules.get().get(NoRender.class).noMapMarkers()) ? EmptyIterator::new : original; } } diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/MessageHandlerMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/MessageHandlerMixin.java index ef2ef3f283..6643158efc 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/MessageHandlerMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/MessageHandlerMixin.java @@ -20,7 +20,7 @@ import java.time.Instant; @Mixin(MessageHandler.class) -public class MessageHandlerMixin implements IMessageHandler { +public abstract class MessageHandlerMixin implements IMessageHandler { @Unique private GameProfile sender; diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/MinecraftClientMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/MinecraftClientMixin.java index c164481946..6dd2772022 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/MinecraftClientMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/MinecraftClientMixin.java @@ -107,8 +107,8 @@ private void onDoItemUse(CallbackInfo info) { doItemUseCalled = true; } - @Inject(method = "disconnect(Lnet/minecraft/client/gui/screen/Screen;)V", at = @At("HEAD")) - private void onDisconnect(Screen screen, CallbackInfo info) { + @Inject(method = "disconnect(Lnet/minecraft/client/gui/screen/Screen;Z)V", at = @At("HEAD")) + private void onDisconnect(Screen screen, boolean transferring, CallbackInfo info) { if (world != null) { MeteorClient.EVENT_BUS.post(GameLeftEvent.get()); } diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/MobSpawnerBlockEntityRendererMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/MobSpawnerBlockEntityRendererMixin.java index 6f6313d1b9..7cce6558a6 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/MobSpawnerBlockEntityRendererMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/MobSpawnerBlockEntityRendererMixin.java @@ -14,7 +14,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(MobSpawnerBlockEntityRenderer.class) -public class MobSpawnerBlockEntityRendererMixin { +public abstract class MobSpawnerBlockEntityRendererMixin { @Inject(method = "render(Lnet/minecraft/block/entity/MobSpawnerBlockEntity;FLnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;II)V", at = @At("HEAD"), cancellable = true) private void onRender(CallbackInfo ci) { if (Modules.get().get(NoRender.class).noMobInSpawner()) ci.cancel(); diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/MouseMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/MouseMixin.java index 9feb07814a..d9b5fcf5de 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/MouseMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/MouseMixin.java @@ -30,7 +30,7 @@ import static org.lwjgl.glfw.GLFW.GLFW_RELEASE; @Mixin(Mouse.class) -public class MouseMixin { +public abstract class MouseMixin { @Shadow @Final private MinecraftClient client; @Inject(method = "onMouseButton", at = @At("HEAD"), cancellable = true) diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/MultiplayerScreenMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/MultiplayerScreenMixin.java index 33de30691b..d206b5fd8c 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/MultiplayerScreenMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/MultiplayerScreenMixin.java @@ -11,15 +11,13 @@ import meteordevelopment.meteorclient.systems.proxies.Proxies; import meteordevelopment.meteorclient.systems.proxies.Proxy; import meteordevelopment.meteorclient.utils.render.color.Color; -import net.minecraft.client.font.TextRenderer; import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.screen.multiplayer.MultiplayerScreen; import net.minecraft.client.gui.widget.ButtonWidget; -import net.minecraft.client.render.BufferBuilder; -import net.minecraft.client.render.VertexConsumerProvider; import net.minecraft.text.Text; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @@ -27,11 +25,15 @@ import static meteordevelopment.meteorclient.MeteorClient.mc; @Mixin(MultiplayerScreen.class) -public class MultiplayerScreenMixin extends Screen { +public abstract class MultiplayerScreenMixin extends Screen { + @Unique private int textColor1; + @Unique private int textColor2; + @Unique private String loggedInAs; + @Unique private int loggedInAsLength; public MultiplayerScreenMixin(Text title) { diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/MutableTextMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/MutableTextMixin.java new file mode 100644 index 0000000000..e5a84e3e70 --- /dev/null +++ b/src/main/java/meteordevelopment/meteorclient/mixin/MutableTextMixin.java @@ -0,0 +1,24 @@ +/* + * This file is part of the Meteor Client distribution (https://github.com/MeteorDevelopment/meteor-client). + * Copyright (c) Meteor Development. + */ + +package meteordevelopment.meteorclient.mixin; + +import meteordevelopment.meteorclient.mixininterface.IText; +import net.minecraft.text.MutableText; +import net.minecraft.util.Language; +import org.jetbrains.annotations.Nullable; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; + +@Mixin(MutableText.class) +public abstract class MutableTextMixin implements IText { + @Shadow + private @Nullable Language language; + + @Override + public void meteor$invalidateCache() { + this.language = null; + } +} diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/PacketByteBufMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/PacketByteBufMixin.java index 2a6083c6bf..b0007ab418 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/PacketByteBufMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/PacketByteBufMixin.java @@ -15,8 +15,8 @@ @Mixin(PacketByteBuf.class) public abstract class PacketByteBufMixin { - @ModifyArg(method = "readNbt()Lnet/minecraft/nbt/NbtCompound;", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/PacketByteBuf;readNbt(Lnet/minecraft/nbt/NbtSizeTracker;)Lnet/minecraft/nbt/NbtElement;")) - private NbtSizeTracker xlPackets(NbtSizeTracker sizeTracker) { + @ModifyArg(method = "readNbt(Lio/netty/buffer/ByteBuf;)Lnet/minecraft/nbt/NbtCompound;", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/PacketByteBuf;readNbt(Lio/netty/buffer/ByteBuf;Lnet/minecraft/nbt/NbtSizeTracker;)Lnet/minecraft/nbt/NbtElement;")) + private static NbtSizeTracker xlPackets(NbtSizeTracker sizeTracker) { return Modules.get().isActive(AntiPacketKick.class) ? NbtSizeTracker.ofUnlimitedBytes() : sizeTracker; } } diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/PlayerArmorSlotMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/PlayerArmorSlotMixin.java index b6233dbbe9..d4f3bac608 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/PlayerArmorSlotMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/PlayerArmorSlotMixin.java @@ -14,7 +14,7 @@ import org.spongepowered.asm.mixin.injection.At; @Mixin(targets = "net/minecraft/screen/PlayerScreenHandler$1") -public class PlayerArmorSlotMixin { +public abstract class PlayerArmorSlotMixin { @ModifyReturnValue(method = "getMaxItemCount", at = @At("RETURN")) private int onGetMaxItemCount(int original) { if (Modules.get().get(InventoryTweaks.class).armorStorage()) return 64; diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/PlayerEntityMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/PlayerEntityMixin.java index 66916b2273..a135ee99e0 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/PlayerEntityMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/PlayerEntityMixin.java @@ -14,6 +14,7 @@ import meteordevelopment.meteorclient.systems.modules.movement.Flight; import meteordevelopment.meteorclient.systems.modules.movement.NoSlow; import meteordevelopment.meteorclient.systems.modules.movement.Scaffold; +import meteordevelopment.meteorclient.systems.modules.player.Reach; import meteordevelopment.meteorclient.systems.modules.player.SpeedMine; import meteordevelopment.meteorclient.utils.world.BlockUtils; import net.minecraft.block.BlockState; @@ -111,4 +112,15 @@ private void onGetOffGroundSpeed(CallbackInfoReturnable info) { float speed = Modules.get().get(Flight.class).getOffGroundSpeed(); if (speed != -1) info.setReturnValue(speed); } + + + @ModifyReturnValue(method = "getBlockInteractionRange", at = @At("RETURN")) + private double modifyBlockInteractionRange(double original) { + return Modules.get().get(Reach.class).blockReach(); + } + + @ModifyReturnValue(method = "getEntityInteractionRange", at = @At("RETURN")) + private double modifyEntityInteractionRange(double original) { + return Modules.get().get(Reach.class).entityReach(); + } } diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/PlayerEntityRendererMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/PlayerEntityRendererMixin.java index 434a79f3d7..44e999799c 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/PlayerEntityRendererMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/PlayerEntityRendererMixin.java @@ -24,7 +24,7 @@ import org.spongepowered.asm.mixin.injection.invoke.arg.Args; @Mixin(PlayerEntityRenderer.class) -public class PlayerEntityRendererMixin { +public abstract class PlayerEntityRendererMixin { @ModifyArgs(method = "renderArm", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/model/ModelPart;render(Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumer;II)V", ordinal = 0)) private void modifyRenderLayer(Args args, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, AbstractClientPlayerEntity player, ModelPart arm, ModelPart sleeve) { Chams chams = Modules.get().get(Chams.class); diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/PlayerInteractEntityC2SPacketMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/PlayerInteractEntityC2SPacketMixin.java index 54cd77cbd9..4e919c46fe 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/PlayerInteractEntityC2SPacketMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/PlayerInteractEntityC2SPacketMixin.java @@ -20,7 +20,7 @@ import static meteordevelopment.meteorclient.MeteorClient.mc; @Mixin(PlayerInteractEntityC2SPacket.class) -public class PlayerInteractEntityC2SPacketMixin implements IPlayerInteractEntityC2SPacket { +public abstract class PlayerInteractEntityC2SPacketMixin implements IPlayerInteractEntityC2SPacket { @Shadow @Final private PlayerInteractEntityC2SPacket.InteractTypeHandler type; @Shadow @Final private int entityId; diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/PlayerListHudMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/PlayerListHudMixin.java index ecb00bd57d..affa543550 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/PlayerListHudMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/PlayerListHudMixin.java @@ -5,8 +5,10 @@ package meteordevelopment.meteorclient.mixin; +import com.llamalad7.mixinextras.sugar.Local; +import com.llamalad7.mixinextras.sugar.ref.LocalIntRef; import meteordevelopment.meteorclient.systems.modules.Modules; -import meteordevelopment.meteorclient.systems.modules.misc.BetterTab; +import meteordevelopment.meteorclient.systems.modules.render.BetterTab; import net.minecraft.client.MinecraftClient; import net.minecraft.client.font.TextRenderer; import net.minecraft.client.gui.DrawContext; @@ -15,12 +17,18 @@ import net.minecraft.text.Text; import net.minecraft.util.math.MathHelper; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.*; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import java.util.List; + @Mixin(PlayerListHud.class) -public class PlayerListHudMixin { +public abstract class PlayerListHudMixin { + @Shadow + protected abstract List collectPlayerEntries(); + @ModifyConstant(constant = @Constant(longValue = 80L), method = "collectPlayerEntries") private long modifyCount(long count) { BetterTab module = Modules.get().get(BetterTab.class); @@ -42,10 +50,20 @@ private int modifyWidth(int width) { return module.isActive() && module.accurateLatency.get() ? width + 30 : width; } - @ModifyConstant(constant = @Constant(intValue = 20), method = "render") - private int modifyHeight(int height) { + @Inject(method = "render", at = @At(value = "INVOKE", target = "Ljava/lang/Math;min(II)I", shift = At.Shift.BEFORE)) + private void modifyHeight(CallbackInfo ci, @Local(ordinal = 5)LocalIntRef o, @Local(ordinal = 6)LocalIntRef p) { BetterTab module = Modules.get().get(BetterTab.class); - return module.isActive() ? module.tabHeight.get() : height; + if (!module.isActive()) return; + + int newO; + int newP = 1; + int totalPlayers = newO = this.collectPlayerEntries().size(); + while (newO > module.tabHeight.get()) { + newO = (totalPlayers + ++newP - 1) / newP; + } + + o.set(newO); + p.set(newP); } @Inject(method = "renderLatencyIcon", at = @At("HEAD"), cancellable = true) diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/PlayerMoveC2SPacketMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/PlayerMoveC2SPacketMixin.java index fdec8b5d5d..c7cf3a4e91 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/PlayerMoveC2SPacketMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/PlayerMoveC2SPacketMixin.java @@ -11,7 +11,7 @@ import org.spongepowered.asm.mixin.Unique; @Mixin(PlayerMoveC2SPacket.class) -public class PlayerMoveC2SPacketMixin implements IPlayerMoveC2SPacket { +public abstract class PlayerMoveC2SPacketMixin implements IPlayerMoveC2SPacket { @Unique private int tag; @Override diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/PowderSnowBlockMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/PowderSnowBlockMixin.java index 62161b7a3b..4b879762f5 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/PowderSnowBlockMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/PowderSnowBlockMixin.java @@ -16,7 +16,7 @@ import static meteordevelopment.meteorclient.MeteorClient.mc; @Mixin(PowderSnowBlock.class) -public class PowderSnowBlockMixin { +public abstract class PowderSnowBlockMixin { @ModifyReturnValue(method = "canWalkOnPowderSnow", at = @At("RETURN")) private static boolean onCanWalkOnPowderSnow(boolean original, Entity entity) { if (entity == mc.player && Modules.get().get(Jesus.class).canWalkOnPowderSnow()) return true; diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/RaycastContextMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/RaycastContextMixin.java index 659dc3160d..cb25de2505 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/RaycastContextMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/RaycastContextMixin.java @@ -16,7 +16,7 @@ import org.spongepowered.asm.mixin.Shadow; @Mixin(RaycastContext.class) -public class RaycastContextMixin implements IRaycastContext { +public abstract class RaycastContextMixin implements IRaycastContext { @Shadow @Final @Mutable private Vec3d start; @Shadow @Final @Mutable private Vec3d end; @Shadow @Final @Mutable private RaycastContext.ShapeType shapeType; diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/RegistriesMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/RegistriesMixin.java index 625ec10ba5..090c49ad6c 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/RegistriesMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/RegistriesMixin.java @@ -14,7 +14,7 @@ @Mixin(Registries.class) public abstract class RegistriesMixin { - @Redirect(method = "create(Lnet/minecraft/registry/RegistryKey;Lnet/minecraft/registry/MutableRegistry;Lnet/minecraft/registry/Registries$Initializer;Lcom/mojang/serialization/Lifecycle;)Lnet/minecraft/registry/MutableRegistry;", at = @At(value = "INVOKE", target = "Lnet/minecraft/Bootstrap;ensureBootstrapped(Ljava/util/function/Supplier;)V")) + @Redirect(method = "create(Lnet/minecraft/registry/RegistryKey;Lnet/minecraft/registry/MutableRegistry;Lnet/minecraft/registry/Registries$Initializer;)Lnet/minecraft/registry/MutableRegistry;", at = @At(value = "INVOKE", target = "Lnet/minecraft/Bootstrap;ensureBootstrapped(Ljava/util/function/Supplier;)V")) private static void ignoreBootstrap(Supplier callerGetter) { // nothing } diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/RenderLayersMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/RenderLayersMixin.java index 0a8c4646cd..1e4441421e 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/RenderLayersMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/RenderLayersMixin.java @@ -16,7 +16,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @Mixin(RenderLayers.class) -public class RenderLayersMixin { +public abstract class RenderLayersMixin { @Inject(method = "getBlockLayer", at = @At("HEAD"), cancellable = true) private static void onGetBlockLayer(BlockState state, CallbackInfoReturnable info) { if (Modules.get() == null) return; diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/RenderTickCounterMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/RenderTickCounterMixin.java index 32c40cba93..97bd3f4dde 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/RenderTickCounterMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/RenderTickCounterMixin.java @@ -16,7 +16,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @Mixin(RenderTickCounter.class) -public class RenderTickCounterMixin { +public abstract class RenderTickCounterMixin { @Shadow public float lastFrameDuration; @Inject(method = "beginRenderTick", at = @At(value = "FIELD", target = "Lnet/minecraft/client/render/RenderTickCounter;prevTimeMillis:J", opcode = Opcodes.PUTFIELD)) diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/ScreenMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/ScreenMixin.java index 5be6a2c661..053a43dde6 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/ScreenMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/ScreenMixin.java @@ -12,6 +12,8 @@ import meteordevelopment.meteorclient.systems.modules.movement.GUIMove; import meteordevelopment.meteorclient.systems.modules.render.NoRender; import meteordevelopment.meteorclient.utils.Utils; +import meteordevelopment.meteorclient.utils.misc.text.MeteorClickEvent; +import meteordevelopment.meteorclient.utils.misc.text.RunnableClickEvent; import net.minecraft.client.gui.screen.ChatScreen; import net.minecraft.client.gui.screen.Screen; import net.minecraft.text.Style; @@ -33,6 +35,26 @@ private void onRenderBackground(CallbackInfo info) { info.cancel(); } + @Inject(method = "handleTextClick", at = @At(value = "HEAD"), cancellable = true) + private void onInvalidClickEvent(Style style, CallbackInfoReturnable cir) { + if (!(style.getClickEvent() instanceof RunnableClickEvent runnableClickEvent)) return; + + runnableClickEvent.runnable.run(); + cir.setReturnValue(true); + } + + @Inject(method = "handleTextClick", at = @At(value = "INVOKE", target = "Lorg/slf4j/Logger;error(Ljava/lang/String;Ljava/lang/Object;)V", ordinal = 1, remap = false), cancellable = true) + private void onRunCommand(Style style, CallbackInfoReturnable cir) { + if (style.getClickEvent() instanceof MeteorClickEvent clickEvent && clickEvent.getValue().startsWith(Config.get().prefix.get())) { + try { + Commands.dispatch(style.getClickEvent().getValue().substring(Config.get().prefix.get().length())); + cir.setReturnValue(true); + } catch (CommandSyntaxException e) { + e.printStackTrace(); + } + } + } + @Inject(method = "keyPressed", at = @At("HEAD"), cancellable = true) private void onKeyPressed(int keyCode, int scanCode, int modifiers, CallbackInfoReturnable info) { if ((Object) (this) instanceof ChatScreen) return; diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/ShulkerBoxBlockMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/ShulkerBoxBlockMixin.java index 4dd696c2b8..0d5c17c436 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/ShulkerBoxBlockMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/ShulkerBoxBlockMixin.java @@ -8,10 +8,10 @@ import meteordevelopment.meteorclient.systems.modules.Modules; import meteordevelopment.meteorclient.systems.modules.render.BetterTooltips; import net.minecraft.block.ShulkerBoxBlock; -import net.minecraft.client.item.TooltipContext; +import net.minecraft.client.item.TooltipType; +import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.text.Text; -import net.minecraft.world.BlockView; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -20,16 +20,16 @@ import java.util.List; @Mixin(ShulkerBoxBlock.class) -public class ShulkerBoxBlockMixin { +public abstract class ShulkerBoxBlockMixin { @Inject(method = "appendTooltip", at = @At("HEAD"), cancellable = true) - private void onAppendTooltip(ItemStack stack, BlockView view, List tooltip, TooltipContext options, CallbackInfo info) { + private void onAppendTooltip(ItemStack stack, Item.TooltipContext context, List tooltip, TooltipType options, CallbackInfo ci) { if (Modules.get() == null) return; BetterTooltips tooltips = Modules.get().get(BetterTooltips.class); if (tooltips.isActive()) { - if (tooltips.previewShulkers()) info.cancel(); + if (tooltips.previewShulkers()) ci.cancel(); else if (tooltips.shulkerCompactTooltip()) { - info.cancel(); + ci.cancel(); tooltips.applyCompactShulkerTooltip(stack, tooltip); } } diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/ShulkerEntityAccessor.java b/src/main/java/meteordevelopment/meteorclient/mixin/ShulkerEntityAccessor.java deleted file mode 100644 index 715dfab8b5..0000000000 --- a/src/main/java/meteordevelopment/meteorclient/mixin/ShulkerEntityAccessor.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * This file is part of the Meteor Client distribution (https://github.com/MeteorDevelopment/meteor-client). - * Copyright (c) Meteor Development. - */ - -package meteordevelopment.meteorclient.mixin; - -import net.minecraft.entity.attribute.EntityAttributeModifier; -import net.minecraft.entity.data.TrackedData; -import net.minecraft.entity.mob.ShulkerEntity; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.gen.Accessor; - -@Mixin(ShulkerEntity.class) -public interface ShulkerEntityAccessor { - @Accessor("PEEK_AMOUNT") - static TrackedData meteor$getPeekAmount() { - throw new AssertionError(); - } - - @Accessor("COVERED_ARMOR_BONUS") - static EntityAttributeModifier meteor$getCoveredArmorBonus() { - throw new AssertionError(); - } -} diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/SignBlockEntityRendererMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/SignBlockEntityRendererMixin.java index dbc96a9a22..cad1b62f5e 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/SignBlockEntityRendererMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/SignBlockEntityRendererMixin.java @@ -13,7 +13,7 @@ import org.spongepowered.asm.mixin.injection.At; @Mixin(SignBlockEntityRenderer.class) -public class SignBlockEntityRendererMixin { +public abstract class SignBlockEntityRendererMixin { @ModifyExpressionValue(method = "renderText", at = @At(value = "CONSTANT", args = {"intValue=4", "ordinal=1"})) private int loopTextLengthProxy(int i) { if (Modules.get().get(NoRender.class).noSignText()) return 0; diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/SimpleOptionMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/SimpleOptionMixin.java index ee22308152..b0b0f109ce 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/SimpleOptionMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/SimpleOptionMixin.java @@ -16,7 +16,7 @@ import java.util.function.Consumer; @Mixin(SimpleOption.class) -public class SimpleOptionMixin implements ISimpleOption { +public abstract class SimpleOptionMixin implements ISimpleOption { @Shadow Object value; @Shadow @Final private Consumer changeCallback; diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/SlimeBlockMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/SlimeBlockMixin.java index 27a0d7455e..6bbadb9476 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/SlimeBlockMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/SlimeBlockMixin.java @@ -20,7 +20,7 @@ import static meteordevelopment.meteorclient.MeteorClient.mc; @Mixin(SlimeBlock.class) -public class SlimeBlockMixin { +public abstract class SlimeBlockMixin { @Inject(method = "onSteppedOn", at = @At("HEAD"), cancellable = true) private void onSteppedOn(World world, BlockPos pos, BlockState state, Entity entity, CallbackInfo info) { if (Modules.get().get(NoSlow.class).slimeBlock() && entity == mc.player) info.cancel(); diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/SlotMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/SlotMixin.java index 27ceaa570a..ff09a3dbf6 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/SlotMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/SlotMixin.java @@ -12,7 +12,7 @@ import org.spongepowered.asm.mixin.Shadow; @Mixin(Slot.class) -public class SlotMixin implements ISlot { +public abstract class SlotMixin implements ISlot { @Shadow public int id; @Shadow @Final private int index; diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/SoundSystemMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/SoundSystemMixin.java index dbf1fca2dd..4ae0e2081f 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/SoundSystemMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/SoundSystemMixin.java @@ -15,7 +15,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(SoundSystem.class) -public class SoundSystemMixin { +public abstract class SoundSystemMixin { @Inject(method = "play(Lnet/minecraft/client/sound/SoundInstance;)V", at = @At("HEAD"), cancellable = true) private void onPlay(SoundInstance soundInstance, CallbackInfo info) { PlaySoundEvent event = MeteorClient.EVENT_BUS.post(PlaySoundEvent.get(soundInstance)); diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/StatusEffectAccessor.java b/src/main/java/meteordevelopment/meteorclient/mixin/StatusEffectAccessor.java new file mode 100644 index 0000000000..1359060789 --- /dev/null +++ b/src/main/java/meteordevelopment/meteorclient/mixin/StatusEffectAccessor.java @@ -0,0 +1,20 @@ +/* + * This file is part of the Meteor Client distribution (https://github.com/MeteorDevelopment/meteor-client). + * Copyright (c) Meteor Development. + */ + +package meteordevelopment.meteorclient.mixin; + +import net.minecraft.entity.attribute.EntityAttribute; +import net.minecraft.entity.effect.StatusEffect; +import net.minecraft.registry.entry.RegistryEntry; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; + +import java.util.Map; + +@Mixin(StatusEffect.class) +public interface StatusEffectAccessor { + @Accessor + Map, StatusEffect.EffectAttributeModifierCreator> getAttributeModifiers(); +} diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/StatusEffectInstanceMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/StatusEffectInstanceMixin.java index 0b737cd1b3..b82ec5f656 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/StatusEffectInstanceMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/StatusEffectInstanceMixin.java @@ -16,14 +16,14 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @Mixin(StatusEffectInstance.class) -public class StatusEffectInstanceMixin { +public abstract class StatusEffectInstanceMixin { @Shadow private int duration; @Inject(method = "updateDuration", at = @At("HEAD"), cancellable = true) private void tick(CallbackInfoReturnable info) { if (!Utils.canUpdate()) return; - if (Modules.get().get(PotionSaver.class).shouldFreeze(((StatusEffectInstance) (Object) this).getEffectType())) { + if (Modules.get().get(PotionSaver.class).shouldFreeze(((StatusEffectInstance) (Object) this).getEffectType().value())) { info.setReturnValue(duration); } } diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/StringHelperMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/StringHelperMixin.java index 1375bbb0b8..4d525d5c0c 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/StringHelperMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/StringHelperMixin.java @@ -13,7 +13,7 @@ import org.spongepowered.asm.mixin.injection.ModifyArg; @Mixin(StringHelper.class) -public class StringHelperMixin { +public abstract class StringHelperMixin { @ModifyArg(method = "truncateChat", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/StringHelper;truncate(Ljava/lang/String;IZ)Ljava/lang/String;"), index = 1) private static int injected(int maxLength) { // this method is only used in one place, to truncate chat messages, so it's fine to do this return (Modules.get().get(BetterChat.class).isInfiniteChatBox() ? Integer.MAX_VALUE : maxLength); diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/SweetBerryBushBlockMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/SweetBerryBushBlockMixin.java index 342e5f9cd8..7d42da76af 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/SweetBerryBushBlockMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/SweetBerryBushBlockMixin.java @@ -20,7 +20,7 @@ import static meteordevelopment.meteorclient.MeteorClient.mc; @Mixin(SweetBerryBushBlock.class) -public class SweetBerryBushBlockMixin { +public abstract class SweetBerryBushBlockMixin { @Inject(method = "onEntityCollision", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;slowMovement(Lnet/minecraft/block/BlockState;Lnet/minecraft/util/math/Vec3d;)V"), cancellable = true) private void onEntityCollision(BlockState state, World world, BlockPos pos, Entity entity, CallbackInfo info) { if (entity == mc.player && Modules.get().get(NoSlow.class).berryBush()) info.cancel(); diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/TextMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/TextMixin.java new file mode 100644 index 0000000000..26403c1ecb --- /dev/null +++ b/src/main/java/meteordevelopment/meteorclient/mixin/TextMixin.java @@ -0,0 +1,16 @@ +/* + * This file is part of the Meteor Client distribution (https://github.com/MeteorDevelopment/meteor-client). + * Copyright (c) Meteor Development. + */ + +package meteordevelopment.meteorclient.mixin; + +import meteordevelopment.meteorclient.mixininterface.IText; +import net.minecraft.text.Text; +import org.spongepowered.asm.mixin.Mixin; + +@Mixin(Text.class) +public interface TextMixin extends IText { + @Override + default void meteor$invalidateCache() {} +} diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/TextRendererMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/TextRendererMixin.java index a35c7be184..9fdfc235a0 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/TextRendererMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/TextRendererMixin.java @@ -12,9 +12,12 @@ import org.spongepowered.asm.mixin.injection.At; @Mixin(targets = "net.minecraft.client.font.TextRenderer$Drawer") -public class TextRendererMixin { +public abstract class TextRendererMixin { @ModifyExpressionValue(method = "accept", at = @At(value = "INVOKE", target = "Lnet/minecraft/text/Style;isObfuscated()Z")) private boolean onRenderObfuscatedStyle(boolean original) { + if (Modules.get() == null || Modules.get().get(NoRender.class) == null) { + return original; + } return !Modules.get().get(NoRender.class).noObfuscation() && original; } } diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/TransformationMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/TransformationMixin.java index a11a4982f6..145052e07c 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/TransformationMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/TransformationMixin.java @@ -15,7 +15,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(Transformation.class) -public class TransformationMixin { +public abstract class TransformationMixin { @Inject(method = "apply", at = @At("HEAD"), cancellable = true) private void onApply(boolean leftHanded, MatrixStack matrices, CallbackInfo info) { ApplyTransformationEvent event = MeteorClient.EVENT_BUS.post(ApplyTransformationEvent.get((Transformation) (Object) this, leftHanded, matrices)); diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/TridentItemMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/TridentItemMixin.java index 2af0193ece..4bbdf059c0 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/TridentItemMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/TridentItemMixin.java @@ -23,7 +23,7 @@ import static meteordevelopment.meteorclient.MeteorClient.mc; @Mixin(TridentItem.class) -public class TridentItemMixin { +public abstract class TridentItemMixin { @Inject(method = "onStoppedUsing", at = @At("HEAD")) private void onStoppedUsingHead(ItemStack stack, World world, LivingEntity user, int remainingUseTicks, CallbackInfo info) { if (user == mc.player) Utils.isReleasingTrident = true; diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/Vec3dMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/Vec3dMixin.java index a418404943..ac71e313f9 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/Vec3dMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/Vec3dMixin.java @@ -13,7 +13,7 @@ import org.spongepowered.asm.mixin.Shadow; @Mixin(Vec3d.class) -public class Vec3dMixin implements IVec3d { +public abstract class Vec3dMixin implements IVec3d { @Shadow @Final @Mutable public double x; @Shadow @Final @Mutable public double y; @Shadow @Final @Mutable public double z; diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/VertexBufferMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/VertexBufferMixin.java index 167fe1bbb5..c0f052beaa 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/VertexBufferMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/VertexBufferMixin.java @@ -18,7 +18,7 @@ import java.nio.ByteBuffer; @Mixin(VertexBuffer.class) -public class VertexBufferMixin { +public abstract class VertexBufferMixin { @Shadow private int indexBufferId; @Inject(method = "uploadIndexBuffer", at = @At("RETURN")) diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/WorldChunkMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/WorldChunkMixin.java index 3bad44baf5..ce6435aaca 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/WorldChunkMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/WorldChunkMixin.java @@ -19,7 +19,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @Mixin(WorldChunk.class) -public class WorldChunkMixin { +public abstract class WorldChunkMixin { @Shadow @Final World world; @Inject(method = "setBlockState", at = @At("TAIL")) diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/WorldRendererMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/WorldRendererMixin.java index 5baabf8289..bba18185e9 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/WorldRendererMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/WorldRendererMixin.java @@ -29,11 +29,19 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import com.llamalad7.mixinextras.injector.ModifyExpressionValue; +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; +import com.llamalad7.mixinextras.sugar.Local; +import com.llamalad7.mixinextras.sugar.ref.LocalRef; + @Mixin(WorldRenderer.class) public abstract class WorldRendererMixin { @Shadow private Framebuffer entityOutlinesFramebuffer; + @Unique private ESP esp; + @Shadow protected abstract void renderEntity(Entity entity, double cameraX, double cameraY, double cameraZ, float tickDelta, MatrixStack matrices, VertexConsumerProvider vertexConsumers); @@ -67,7 +75,7 @@ private void hasBlindnessOrDarkness(Camera camera, CallbackInfoReturnable original, @Local LocalRef entity) { + if (!getESP().isGlow() || getESP().shouldSkip(entity.get())) original.call(instance, red, green, blue, alpha); + else { + Color color = getESP().getColor(entity.get()); + + if (color == null) original.call(instance, red, green, blue, alpha); + else instance.setColor(color.r, color.g, color.b, color.a); + } + } + @Inject(method = "onResized", at = @At("HEAD")) private void onResized(int width, int height, CallbackInfo info) { PostProcessShaders.onResized(width, height); @@ -135,4 +161,13 @@ private static int getLightmapCoordinatesModifySkyLight(int sky) { private static int getLightmapCoordinatesModifyBlockLight(int sky) { return Math.max(Modules.get().get(Fullbright.class).getLuminance(LightType.BLOCK), sky); } + + @Unique + private ESP getESP() { + if (esp == null) { + esp = Modules.get().get(ESP.class); + } + + return esp; + } } diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/baritone/ComeCommandMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/baritone/ComeCommandMixin.java index 6b68c0d15f..6a9ff88795 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/baritone/ComeCommandMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/baritone/ComeCommandMixin.java @@ -17,7 +17,7 @@ import static meteordevelopment.meteorclient.MeteorClient.mc; @Mixin(ComeCommand.class) -public class ComeCommandMixin { +public abstract class ComeCommandMixin { @ModifyArgs(method = "execute", at = @At(value = "INVOKE", target = "Lbaritone/api/process/ICustomGoalProcess;setGoalAndPath(Lbaritone/api/pathing/goals/Goal;)V"), remap = false) private void getComeCommandTarget(Args args) { Freecam freecam = Modules.get().get(Freecam.class); diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/canvas/CanvasWorldRendererMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/canvas/CanvasWorldRendererMixin.java index 3f209399ea..fa4fdb3266 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/canvas/CanvasWorldRendererMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/canvas/CanvasWorldRendererMixin.java @@ -21,7 +21,7 @@ // TODO: 1.19.3 //@Mixin(value = CanvasWorldRenderer.class, remap = false) -public class CanvasWorldRendererMixin { +public abstract class CanvasWorldRendererMixin { /*@ModifyVariable(method = "renderWorld", at = @At("LOAD"), name = "blockOutlines") private boolean renderWorld_blockOutlines(boolean blockOutlines) { if (Modules.get().isActive(BlockSelection.class)) return false; diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/indigo/AbstractBlockRenderContextMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/indigo/AbstractBlockRenderContextMixin.java index 12c97c52bd..5f047ab745 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/indigo/AbstractBlockRenderContextMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/indigo/AbstractBlockRenderContextMixin.java @@ -18,7 +18,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(AbstractBlockRenderContext.class) -public class AbstractBlockRenderContextMixin { +public abstract class AbstractBlockRenderContextMixin { @Final @Shadow(remap = false) protected BlockRenderInfo blockInfo; @Inject(method = "renderQuad", at = @At(value = "INVOKE", target = "Lnet/fabricmc/fabric/impl/client/indigo/renderer/render/AbstractBlockRenderContext;bufferQuad(Lnet/fabricmc/fabric/impl/client/indigo/renderer/mesh/MutableQuadViewImpl;Lnet/minecraft/client/render/VertexConsumer;)V"), cancellable = true) diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/indigo/AoCalculatorMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/indigo/AoCalculatorMixin.java index 2d74602f34..da22eba5f9 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/indigo/AoCalculatorMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/indigo/AoCalculatorMixin.java @@ -14,7 +14,7 @@ import org.spongepowered.asm.mixin.injection.ModifyVariable; @Mixin(AoCalculator.class) -public class AoCalculatorMixin { +public abstract class AoCalculatorMixin { @ModifyVariable(method = "getLightmapCoordinates(Lnet/minecraft/world/BlockRenderView;Lnet/minecraft/block/BlockState;Lnet/minecraft/util/math/BlockPos;)I", at = @At(value = "STORE"), ordinal = 0) private static int getLightmapCoordinatesModifySkyLight(int sky) { return Math.max(Modules.get().get(Fullbright.class).getLuminance(LightType.SKY), sky); diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/indium/AbstractBlockRenderContextMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/indium/AbstractBlockRenderContextMixin.java index 8ead45ba5e..07a433d3a4 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/indium/AbstractBlockRenderContextMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/indium/AbstractBlockRenderContextMixin.java @@ -16,7 +16,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(value = AbstractBlockRenderContext.class, remap = false) -public class AbstractBlockRenderContextMixin { +public abstract class AbstractBlockRenderContextMixin { @Shadow protected BlockRenderInfo blockInfo; diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/sodium/SodiumBiomeColorCacheMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/sodium/SodiumBiomeColorCacheMixin.java index 92af282d68..28ed15a500 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/sodium/SodiumBiomeColorCacheMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/sodium/SodiumBiomeColorCacheMixin.java @@ -16,7 +16,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(value = BiomeColorCache.class, remap = false) -public class SodiumBiomeColorCacheMixin { +public abstract class SodiumBiomeColorCacheMixin { @Unique private Ambience ambience; diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/sodium/SodiumBlockOcclusionCacheMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/sodium/SodiumBlockOcclusionCacheMixin.java index fc3473eee9..8e57991da8 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/sodium/SodiumBlockOcclusionCacheMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/sodium/SodiumBlockOcclusionCacheMixin.java @@ -20,7 +20,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(value = BlockOcclusionCache.class, remap = false) -public class SodiumBlockOcclusionCacheMixin { +public abstract class SodiumBlockOcclusionCacheMixin { @Unique private Xray xray; diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/sodium/SodiumBlockRendererMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/sodium/SodiumBlockRendererMixin.java index 370de60cc2..3863c5f5a1 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/sodium/SodiumBlockRendererMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/sodium/SodiumBlockRendererMixin.java @@ -15,7 +15,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(value = BlockRenderer.class, remap = false) -public class SodiumBlockRendererMixin { +public abstract class SodiumBlockRendererMixin { @Inject(method = "renderModel", at = @At("HEAD"), cancellable = true) private void onRenderModel(BlockRenderContext ctx, ChunkBuildBuffers buffers, CallbackInfo info) { int alpha = Xray.getAlpha(ctx.state(), ctx.pos()); diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/sodium/SodiumFluidRendererMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/sodium/SodiumFluidRendererMixin.java index 2ac8a24812..32ac55f6d1 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/sodium/SodiumFluidRendererMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/sodium/SodiumFluidRendererMixin.java @@ -31,7 +31,7 @@ import java.util.Arrays; @Mixin(value = FluidRenderer.class, remap = false) -public class SodiumFluidRendererMixin { +public abstract class SodiumFluidRendererMixin { @Final @Shadow private int[] quadColors; diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/sodium/SodiumLightDataAccessMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/sodium/SodiumLightDataAccessMixin.java index 215bd3de49..61bf0faed8 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/sodium/SodiumLightDataAccessMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/sodium/SodiumLightDataAccessMixin.java @@ -23,7 +23,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(value = LightDataAccess.class, remap = false) -public class SodiumLightDataAccessMixin { +public abstract class SodiumLightDataAccessMixin { @Unique private static final int FULL_LIGHT = 15 | 15 << 4 | 15 << 8; diff --git a/src/main/java/meteordevelopment/meteorclient/mixininterface/IAttributeContainer.java b/src/main/java/meteordevelopment/meteorclient/mixininterface/IAttributeContainer.java deleted file mode 100644 index 019578179c..0000000000 --- a/src/main/java/meteordevelopment/meteorclient/mixininterface/IAttributeContainer.java +++ /dev/null @@ -1,16 +0,0 @@ -/* - * This file is part of the Meteor Client distribution (https://github.com/MeteorDevelopment/meteor-client). - * Copyright (c) Meteor Development. - */ - -package meteordevelopment.meteorclient.mixininterface; - -import net.minecraft.entity.attribute.AttributeContainer; -import net.minecraft.entity.attribute.EntityAttributeInstance; - -public interface IAttributeContainer { - /** - * Copy the {@link EntityAttributeInstance} of the other {@link AttributeContainer} into this one, copying their modifiers if there's a duplicate - */ - void meteor$copyFrom(AttributeContainer other); -} diff --git a/src/main/java/meteordevelopment/meteorclient/mixininterface/IChatHudLine.java b/src/main/java/meteordevelopment/meteorclient/mixininterface/IChatHudLine.java index de081990db..96c25fe22e 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixininterface/IChatHudLine.java +++ b/src/main/java/meteordevelopment/meteorclient/mixininterface/IChatHudLine.java @@ -11,8 +11,10 @@ public interface IChatHudLine { String meteor$getText(); int meteor$getId(); + void meteor$setId(int id); GameProfile meteor$getSender(); + void meteor$setSender(GameProfile profile); } diff --git a/src/main/java/meteordevelopment/meteorclient/mixininterface/IClientPlayerInteractionManager.java b/src/main/java/meteordevelopment/meteorclient/mixininterface/IClientPlayerInteractionManager.java index 0495f24ab4..7ee8ac3944 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixininterface/IClientPlayerInteractionManager.java +++ b/src/main/java/meteordevelopment/meteorclient/mixininterface/IClientPlayerInteractionManager.java @@ -6,5 +6,5 @@ package meteordevelopment.meteorclient.mixininterface; public interface IClientPlayerInteractionManager { - void syncSelected(); + void meteor$syncSelected(); } diff --git a/src/main/java/meteordevelopment/meteorclient/mixininterface/IEntityAttributeInstance.java b/src/main/java/meteordevelopment/meteorclient/mixininterface/IEntityAttributeInstance.java deleted file mode 100644 index 558a0a42cc..0000000000 --- a/src/main/java/meteordevelopment/meteorclient/mixininterface/IEntityAttributeInstance.java +++ /dev/null @@ -1,15 +0,0 @@ -/* - * This file is part of the Meteor Client distribution (https://github.com/MeteorDevelopment/meteor-client). - * Copyright (c) Meteor Development. - */ - -package meteordevelopment.meteorclient.mixininterface; - -import net.minecraft.entity.attribute.EntityAttributeInstance; - -public interface IEntityAttributeInstance { - /** - * Adds the modifiers of the other {@link EntityAttributeInstance} to this one, replacing them if there's a duplicate - */ - void meteor$copyFrom(EntityAttributeInstance other); -} diff --git a/src/main/java/meteordevelopment/meteorclient/mixininterface/IText.java b/src/main/java/meteordevelopment/meteorclient/mixininterface/IText.java new file mode 100644 index 0000000000..dd867af2bd --- /dev/null +++ b/src/main/java/meteordevelopment/meteorclient/mixininterface/IText.java @@ -0,0 +1,10 @@ +/* + * This file is part of the Meteor Client distribution (https://github.com/MeteorDevelopment/meteor-client). + * Copyright (c) Meteor Development. + */ + +package meteordevelopment.meteorclient.mixininterface; + +public interface IText { + void meteor$invalidateCache(); +} diff --git a/src/main/java/meteordevelopment/meteorclient/mixininterface/IVec3d.java b/src/main/java/meteordevelopment/meteorclient/mixininterface/IVec3d.java index e812323789..79d201262b 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixininterface/IVec3d.java +++ b/src/main/java/meteordevelopment/meteorclient/mixininterface/IVec3d.java @@ -14,6 +14,7 @@ public interface IVec3d { default void set(Vec3i vec) { set(vec.getX(), vec.getY(), vec.getZ()); } + default void set(Vector3d vec) { set(vec.x, vec.y, vec.z); } diff --git a/src/main/java/meteordevelopment/meteorclient/pathing/BaritoneSettings.java b/src/main/java/meteordevelopment/meteorclient/pathing/BaritoneSettings.java index cc790ceec5..d900c6419a 100644 --- a/src/main/java/meteordevelopment/meteorclient/pathing/BaritoneSettings.java +++ b/src/main/java/meteordevelopment/meteorclient/pathing/BaritoneSettings.java @@ -13,9 +13,7 @@ import net.minecraft.item.Item; import java.awt.*; -import java.lang.reflect.Field; -import java.lang.reflect.ParameterizedType; -import java.lang.reflect.Type; +import java.lang.reflect.*; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -77,6 +75,8 @@ private void createWrappers() { Class klass = BaritoneAPI.getSettings().getClass(); for (Field field : klass.getDeclaredFields()) { + if (Modifier.isStatic(field.getModifiers())) continue; + Object obj = field.get(BaritoneAPI.getSettings()); if (!(obj instanceof baritone.api.Settings.Setting setting)) continue; diff --git a/src/main/java/meteordevelopment/meteorclient/pathing/BaritoneUtils.java b/src/main/java/meteordevelopment/meteorclient/pathing/BaritoneUtils.java index 7830aafad9..b270b2392f 100644 --- a/src/main/java/meteordevelopment/meteorclient/pathing/BaritoneUtils.java +++ b/src/main/java/meteordevelopment/meteorclient/pathing/BaritoneUtils.java @@ -10,6 +10,9 @@ public class BaritoneUtils { public static boolean IS_AVAILABLE = false; + private BaritoneUtils() { + } + public static String getPrefix() { if (IS_AVAILABLE) { return BaritoneAPI.getSettings().prefix.value; diff --git a/src/main/java/meteordevelopment/meteorclient/renderer/Fonts.java b/src/main/java/meteordevelopment/meteorclient/renderer/Fonts.java index d14498f0cc..cea83f3db9 100644 --- a/src/main/java/meteordevelopment/meteorclient/renderer/Fonts.java +++ b/src/main/java/meteordevelopment/meteorclient/renderer/Fonts.java @@ -32,6 +32,9 @@ public class Fonts { public static final List FONT_FAMILIES = new ArrayList<>(); public static CustomTextRenderer RENDERER; + private Fonts() { + } + @PreInit(dependencies = Shaders.class) public static void refresh() { FONT_FAMILIES.clear(); diff --git a/src/main/java/meteordevelopment/meteorclient/renderer/GL.java b/src/main/java/meteordevelopment/meteorclient/renderer/GL.java index 6047ac64c9..21b6ffeeae 100644 --- a/src/main/java/meteordevelopment/meteorclient/renderer/GL.java +++ b/src/main/java/meteordevelopment/meteorclient/renderer/GL.java @@ -37,6 +37,9 @@ public class GL { public static int CURRENT_IBO; private static int prevIbo; + private GL() { + } + @PreInit public static void init() { if (FabricLoader.getInstance().isModLoaded("canvas")) changeBufferRenderer = false; diff --git a/src/main/java/meteordevelopment/meteorclient/renderer/Mesh.java b/src/main/java/meteordevelopment/meteorclient/renderer/Mesh.java index 4ac1b2a396..47bd3ba575 100644 --- a/src/main/java/meteordevelopment/meteorclient/renderer/Mesh.java +++ b/src/main/java/meteordevelopment/meteorclient/renderer/Mesh.java @@ -10,6 +10,7 @@ import meteordevelopment.meteorclient.utils.render.color.Color; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.util.math.Vec3d; +import org.joml.Matrix4fStack; import org.lwjgl.BufferUtils; import java.nio.ByteBuffer; @@ -252,13 +253,13 @@ public void beginRender(MatrixStack matrices) { GL.enableLineSmooth(); if (rendering3D) { - MatrixStack matrixStack = RenderSystem.getModelViewStack(); - matrixStack.push(); + Matrix4fStack matrixStack = RenderSystem.getModelViewStack(); + matrixStack.pushMatrix(); - if (matrices != null) matrixStack.multiplyPositionMatrix(matrices.peek().getPositionMatrix()); + if (matrices != null) matrixStack.mul(matrices.peek().getPositionMatrix()); Vec3d cameraPos = mc.gameRenderer.getCamera().getPos(); - matrixStack.translate(0, -cameraPos.y, 0); + matrixStack.translate(0, (float) -cameraPos.y, 0); } beganRendering = true; @@ -288,7 +289,7 @@ public void render(MatrixStack matrices) { } public void endRender() { - if (rendering3D) RenderSystem.getModelViewStack().pop(); + if (rendering3D) RenderSystem.getModelViewStack().popMatrix(); GL.restoreState(); diff --git a/src/main/java/meteordevelopment/meteorclient/renderer/PostProcessRenderer.java b/src/main/java/meteordevelopment/meteorclient/renderer/PostProcessRenderer.java index 578f6af092..bff8e8b3ad 100644 --- a/src/main/java/meteordevelopment/meteorclient/renderer/PostProcessRenderer.java +++ b/src/main/java/meteordevelopment/meteorclient/renderer/PostProcessRenderer.java @@ -12,6 +12,9 @@ public class PostProcessRenderer { private static Mesh mesh; private static final MatrixStack matrices = new MatrixStack(); + private PostProcessRenderer() { + } + @PreInit public static void init() { mesh = new Mesh(DrawMode.Triangles, Mesh.Attrib.Vec2); diff --git a/src/main/java/meteordevelopment/meteorclient/renderer/Shader.java b/src/main/java/meteordevelopment/meteorclient/renderer/Shader.java index dd3cf4aecc..c32961df57 100644 --- a/src/main/java/meteordevelopment/meteorclient/renderer/Shader.java +++ b/src/main/java/meteordevelopment/meteorclient/renderer/Shader.java @@ -104,6 +104,6 @@ public void set(String name, Matrix4f mat) { public void setDefaults() { set("u_Proj", RenderSystem.getProjectionMatrix()); - set("u_ModelView", RenderSystem.getModelViewStack().peek().getPositionMatrix()); + set("u_ModelView", RenderSystem.getModelViewStack()); } } diff --git a/src/main/java/meteordevelopment/meteorclient/renderer/Shaders.java b/src/main/java/meteordevelopment/meteorclient/renderer/Shaders.java index 982aba0373..9e8093b06b 100644 --- a/src/main/java/meteordevelopment/meteorclient/renderer/Shaders.java +++ b/src/main/java/meteordevelopment/meteorclient/renderer/Shaders.java @@ -12,6 +12,9 @@ public class Shaders { public static Shader POS_TEX_COLOR; public static Shader TEXT; + private Shaders() { + } + @PreInit public static void init() { POS_COLOR = new Shader("pos_color.vert", "pos_color.frag"); diff --git a/src/main/java/meteordevelopment/meteorclient/renderer/text/CustomTextRenderer.java b/src/main/java/meteordevelopment/meteorclient/renderer/text/CustomTextRenderer.java index 447b17753d..878fbe80fb 100644 --- a/src/main/java/meteordevelopment/meteorclient/renderer/text/CustomTextRenderer.java +++ b/src/main/java/meteordevelopment/meteorclient/renderer/text/CustomTextRenderer.java @@ -36,7 +36,7 @@ public CustomTextRenderer(FontFace fontFace) { fonts = new Font[5]; for (int i = 0; i < fonts.length; i++) { - fonts[i] = new Font(buffer, (int) Math.round(18 * ((i * 0.5) + 1))); + fonts[i] = new Font(buffer, (int) Math.round(27 * ((i * 0.5) + 1))); } } @@ -70,7 +70,7 @@ public void begin(double scale, boolean scaleOnly, boolean big) { this.building = true; this.scaleOnly = scaleOnly; - this.fontScale = font.getHeight() / 18.0; + this.fontScale = font.getHeight() / 27.0; this.scale = 1 + (scale - fontScale) / fontScale; } @@ -79,13 +79,13 @@ public double getWidth(String text, int length, boolean shadow) { if (text.isEmpty()) return 0; Font font = building ? this.font : fonts[0]; - return (font.getWidth(text, length) + (shadow ? 1 : 0)) * scale; + return (font.getWidth(text, length) + (shadow ? 1 : 0)) * scale / 1.5; } @Override public double getHeight(boolean shadow) { Font font = building ? this.font : fonts[0]; - return (font.getHeight() + 1 + (shadow ? 1 : 0)) * scale; + return (font.getHeight() + 1 + (shadow ? 1 : 0)) * scale / 1.5; } @Override @@ -98,13 +98,13 @@ public double render(String text, double x, double y, Color color, boolean shado int preShadowA = SHADOW_COLOR.a; SHADOW_COLOR.a = (int) (color.a / 255.0 * preShadowA); - width = font.render(mesh, text, x + fontScale * scale, y + fontScale * scale, SHADOW_COLOR, scale); - font.render(mesh, text, x, y, color, scale); + width = font.render(mesh, text, x + fontScale * scale / 1.5, y + fontScale * scale / 1.5, SHADOW_COLOR, scale / 1.5); + font.render(mesh, text, x, y, color, scale / 1.5); SHADOW_COLOR.a = preShadowA; } else { - width = font.render(mesh, text, x, y, color, scale); + width = font.render(mesh, text, x, y, color, scale / 1.5); } if (!wasBuilding) end(); diff --git a/src/main/java/meteordevelopment/meteorclient/renderer/text/VanillaTextRenderer.java b/src/main/java/meteordevelopment/meteorclient/renderer/text/VanillaTextRenderer.java index 5e41938cbc..33d8855e1b 100644 --- a/src/main/java/meteordevelopment/meteorclient/renderer/text/VanillaTextRenderer.java +++ b/src/main/java/meteordevelopment/meteorclient/renderer/text/VanillaTextRenderer.java @@ -13,6 +13,7 @@ import net.minecraft.client.render.VertexConsumerProvider; import net.minecraft.client.util.math.MatrixStack; import org.joml.Matrix4f; +import org.joml.Matrix4fStack; import static meteordevelopment.meteorclient.MeteorClient.mc; @@ -98,17 +99,17 @@ public boolean isBuilding() { public void end(MatrixStack matrices) { if (!building) throw new RuntimeException("VanillaTextRenderer.end() called without calling begin()"); - MatrixStack matrixStack = RenderSystem.getModelViewStack(); + Matrix4fStack matrixStack = RenderSystem.getModelViewStack(); RenderSystem.disableDepthTest(); - matrixStack.push(); - if (matrices != null) matrixStack.multiplyPositionMatrix(matrices.peek().getPositionMatrix()); + matrixStack.pushMatrix(); + if (matrices != null) matrixStack.mul(matrices.peek().getPositionMatrix()); if (!scaleIndividually) matrixStack.scale((float) scale, (float) scale, 1); RenderSystem.applyModelViewMatrix(); immediate.draw(); - matrixStack.pop(); + matrixStack.popMatrix(); RenderSystem.enableDepthTest(); RenderSystem.applyModelViewMatrix(); diff --git a/src/main/java/meteordevelopment/meteorclient/settings/EntityTypeListSetting.java b/src/main/java/meteordevelopment/meteorclient/settings/EntityTypeListSetting.java index 06a925b879..648df04541 100644 --- a/src/main/java/meteordevelopment/meteorclient/settings/EntityTypeListSetting.java +++ b/src/main/java/meteordevelopment/meteorclient/settings/EntityTypeListSetting.java @@ -17,8 +17,10 @@ import net.minecraft.registry.Registries; import net.minecraft.util.Identifier; +import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; +import java.util.List; import java.util.Map; import java.util.Set; import java.util.function.Consumer; @@ -26,6 +28,8 @@ public class EntityTypeListSetting extends Setting>> { public final Predicate> filter; + private static List suggestions; + private final static List groups = List.of("animal", "wateranimal", "monster", "ambient", "misc"); public EntityTypeListSetting(String name, String description, Set> defaultValue, Consumer>> onChanged, Consumer>>> onModuleActivated, IVisible visible, Predicate> filter) { super(name, description, defaultValue, onChanged, onModuleActivated, visible); @@ -47,6 +51,33 @@ protected Set> parseImpl(String str) { for (String value : values) { EntityType entity = parseId(Registries.ENTITY_TYPE, value); if (entity != null) entities.add(entity); + else { + String lowerValue = value.trim().toLowerCase(); + if (!groups.contains(lowerValue)) continue; + + Registries.ENTITY_TYPE.forEach(entityType -> { + switch (lowerValue) { + case "animal" -> { + if (entityType.getSpawnGroup() == SpawnGroup.CREATURE) entities.add(entityType); + } + case "wateranimal" -> { + if (entityType.getSpawnGroup() == SpawnGroup.WATER_AMBIENT + || entityType.getSpawnGroup() == SpawnGroup.WATER_CREATURE + || entityType.getSpawnGroup() == SpawnGroup.UNDERGROUND_WATER_CREATURE + || entityType.getSpawnGroup() == SpawnGroup.AXOLOTLS) entities.add(entityType); + } + case "monster" -> { + if (entityType.getSpawnGroup() == SpawnGroup.MONSTER) entities.add(entityType); + } + case "ambient" -> { + if (entityType.getSpawnGroup() == SpawnGroup.AMBIENT) entities.add(entityType); + } + case "misc" -> { + if (entityType.getSpawnGroup() == SpawnGroup.MISC) entities.add(entityType); + } + } + }); + } } } catch (Exception ignored) {} @@ -59,8 +90,13 @@ protected boolean isValueValid(Set> value) { } @Override - public Iterable getIdentifierSuggestions() { - return Registries.ENTITY_TYPE.getIds(); + public List getSuggestions() { + if (suggestions == null) { + suggestions = new ArrayList<>(groups); + Registries.ENTITY_TYPE.getIds().forEach(id -> suggestions.add(id.toString())); + } + + return suggestions; } @Override diff --git a/src/main/java/meteordevelopment/meteorclient/settings/KeybindSetting.java b/src/main/java/meteordevelopment/meteorclient/settings/KeybindSetting.java index dc926de11e..8bee87d929 100644 --- a/src/main/java/meteordevelopment/meteorclient/settings/KeybindSetting.java +++ b/src/main/java/meteordevelopment/meteorclient/settings/KeybindSetting.java @@ -14,6 +14,7 @@ import meteordevelopment.orbit.EventHandler; import meteordevelopment.orbit.EventPriority; import net.minecraft.nbt.NbtCompound; +import org.lwjgl.glfw.GLFW; import java.util.function.Consumer; @@ -30,24 +31,26 @@ public KeybindSetting(String name, String description, Keybind defaultValue, Con @EventHandler(priority = EventPriority.HIGHEST) private void onKeyBinding(KeyEvent event) { - if (event.action == KeyAction.Release && widget != null && widget.onAction(true, event.key)) event.cancel(); + if (widget == null) return; + if (event.action == KeyAction.Press && event.key == GLFW.GLFW_KEY_ESCAPE && widget.onClear()) event.cancel(); + else if (event.action == KeyAction.Release && widget.onAction(true, event.key, event.modifiers)) event.cancel(); } @EventHandler(priority = EventPriority.HIGHEST) private void onMouseButtonBinding(MouseButtonEvent event) { - if (event.action == KeyAction.Release && widget != null && widget.onAction(false, event.button)) event.cancel(); + if (event.action == KeyAction.Press && widget != null && widget.onAction(false, event.button, 0)) event.cancel(); } @EventHandler(priority = EventPriority.HIGH) private void onKey(KeyEvent event) { - if (event.action == KeyAction.Release && get().matches(true, event.key) && (module == null || module.isActive()) && action != null) { + if (event.action == KeyAction.Release && get().matches(true, event.key, event.modifiers) && (module == null || module.isActive()) && action != null) { action.run(); } } @EventHandler(priority = EventPriority.HIGH) private void onMouseButton(MouseButtonEvent event) { - if (event.action == KeyAction.Release && get().matches(false, event.button) && (module == null || module.isActive()) && action != null) { + if (event.action == KeyAction.Release && get().matches(false, event.button, 0) && (module == null || module.isActive()) && action != null) { action.run(); } } diff --git a/src/main/java/meteordevelopment/meteorclient/settings/SettingGroup.java b/src/main/java/meteordevelopment/meteorclient/settings/SettingGroup.java index 7a24ba4aa3..073db9d7e6 100644 --- a/src/main/java/meteordevelopment/meteorclient/settings/SettingGroup.java +++ b/src/main/java/meteordevelopment/meteorclient/settings/SettingGroup.java @@ -9,6 +9,7 @@ import net.minecraft.nbt.NbtCompound; import net.minecraft.nbt.NbtElement; import net.minecraft.nbt.NbtList; +import org.jetbrains.annotations.NotNull; import java.util.ArrayList; import java.util.Iterator; @@ -44,7 +45,7 @@ public Setting getByIndex(int index) { } @Override - public Iterator> iterator() { + public @NotNull Iterator> iterator() { return settings.iterator(); } diff --git a/src/main/java/meteordevelopment/meteorclient/settings/Settings.java b/src/main/java/meteordevelopment/meteorclient/settings/Settings.java index 63c3aea065..f8ab30951e 100644 --- a/src/main/java/meteordevelopment/meteorclient/settings/Settings.java +++ b/src/main/java/meteordevelopment/meteorclient/settings/Settings.java @@ -15,6 +15,7 @@ import net.minecraft.nbt.NbtCompound; import net.minecraft.nbt.NbtElement; import net.minecraft.nbt.NbtList; +import org.jetbrains.annotations.NotNull; import java.util.ArrayList; import java.util.Iterator; @@ -120,7 +121,7 @@ public void tick(WContainer settings, GuiTheme theme) { } @Override - public Iterator iterator() { + public @NotNull Iterator iterator() { return groups.iterator(); } diff --git a/src/main/java/meteordevelopment/meteorclient/settings/SoundEventListSetting.java b/src/main/java/meteordevelopment/meteorclient/settings/SoundEventListSetting.java index b5513aa4d7..b656b6ffef 100644 --- a/src/main/java/meteordevelopment/meteorclient/settings/SoundEventListSetting.java +++ b/src/main/java/meteordevelopment/meteorclient/settings/SoundEventListSetting.java @@ -78,8 +78,6 @@ public List load(NbtCompound tag) { return get(); } - - public static class Builder extends SettingBuilder, SoundEventListSetting> { public Builder() { super(new ArrayList<>(0)); diff --git a/src/main/java/meteordevelopment/meteorclient/settings/StatusEffectAmplifierMapSetting.java b/src/main/java/meteordevelopment/meteorclient/settings/StatusEffectAmplifierMapSetting.java index a4047536a2..cd2f90c5fe 100644 --- a/src/main/java/meteordevelopment/meteorclient/settings/StatusEffectAmplifierMapSetting.java +++ b/src/main/java/meteordevelopment/meteorclient/settings/StatusEffectAmplifierMapSetting.java @@ -5,9 +5,9 @@ package meteordevelopment.meteorclient.settings; -import it.unimi.dsi.fastutil.objects.Object2IntArrayMap; -import it.unimi.dsi.fastutil.objects.Object2IntMap; -import meteordevelopment.meteorclient.utils.Utils; +import it.unimi.dsi.fastutil.objects.Reference2IntArrayMap; +import it.unimi.dsi.fastutil.objects.Reference2IntMap; +import it.unimi.dsi.fastutil.objects.Reference2IntOpenHashMap; import net.minecraft.entity.effect.StatusEffect; import net.minecraft.nbt.NbtCompound; import net.minecraft.registry.Registries; @@ -15,20 +15,22 @@ import java.util.function.Consumer; -public class StatusEffectAmplifierMapSetting extends Setting> { - public StatusEffectAmplifierMapSetting(String name, String description, Object2IntMap defaultValue, Consumer> onChanged, Consumer>> onModuleActivated, IVisible visible) { +public class StatusEffectAmplifierMapSetting extends Setting> { + public static final Reference2IntMap EMPTY_STATUS_EFFECT_MAP = createStatusEffectMap(); + + public StatusEffectAmplifierMapSetting(String name, String description, Reference2IntMap defaultValue, Consumer> onChanged, Consumer>> onModuleActivated, IVisible visible) { super(name, description, defaultValue, onChanged, onModuleActivated, visible); } @Override public void resetImpl() { - value = new Object2IntArrayMap<>(defaultValue); + value = new Reference2IntOpenHashMap<>(defaultValue); } @Override - protected Object2IntMap parseImpl(String str) { + protected Reference2IntMap parseImpl(String str) { String[] values = str.split(","); - Object2IntMap effects = Utils.createStatusEffectMap(); + Reference2IntMap effects = new Reference2IntOpenHashMap<>(EMPTY_STATUS_EFFECT_MAP); try { for (String value : values) { @@ -45,7 +47,7 @@ protected Object2IntMap parseImpl(String str) { } @Override - protected boolean isValueValid(Object2IntMap value) { + protected boolean isValueValid(Reference2IntMap value) { return true; } @@ -61,8 +63,16 @@ public NbtCompound save(NbtCompound tag) { return tag; } + private static Reference2IntMap createStatusEffectMap() { + Reference2IntMap map = new Reference2IntArrayMap<>(Registries.STATUS_EFFECT.getIds().size()); + + Registries.STATUS_EFFECT.forEach(potion -> map.put(potion, 0)); + + return map; + } + @Override - public Object2IntMap load(NbtCompound tag) { + public Reference2IntMap load(NbtCompound tag) { get().clear(); NbtCompound valueTag = tag.getCompound("value"); @@ -74,9 +84,9 @@ public Object2IntMap load(NbtCompound tag) { return get(); } - public static class Builder extends SettingBuilder, StatusEffectAmplifierMapSetting> { + public static class Builder extends SettingBuilder, StatusEffectAmplifierMapSetting> { public Builder() { - super(new Object2IntArrayMap<>(0)); + super(new Reference2IntOpenHashMap<>(0)); } @Override diff --git a/src/main/java/meteordevelopment/meteorclient/settings/StorageBlockListSetting.java b/src/main/java/meteordevelopment/meteorclient/settings/StorageBlockListSetting.java index d9379d4cae..7b364efde6 100644 --- a/src/main/java/meteordevelopment/meteorclient/settings/StorageBlockListSetting.java +++ b/src/main/java/meteordevelopment/meteorclient/settings/StorageBlockListSetting.java @@ -146,11 +146,6 @@ public BlockEntityType get(@Nullable Identifier id) { return null; } - @Override - public Lifecycle getEntryLifecycle(BlockEntityType object) { - return null; - } - @Override public Lifecycle getLifecycle() { return null; diff --git a/src/main/java/meteordevelopment/meteorclient/settings/StringSetting.java b/src/main/java/meteordevelopment/meteorclient/settings/StringSetting.java index 419c1af051..1c675f49de 100644 --- a/src/main/java/meteordevelopment/meteorclient/settings/StringSetting.java +++ b/src/main/java/meteordevelopment/meteorclient/settings/StringSetting.java @@ -54,7 +54,7 @@ public static class Builder extends SettingBuilder renderer) { diff --git a/src/main/java/meteordevelopment/meteorclient/systems/accounts/Account.java b/src/main/java/meteordevelopment/meteorclient/systems/accounts/Account.java index 70ca1ac710..3e1b5859f4 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/accounts/Account.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/accounts/Account.java @@ -5,7 +5,6 @@ package meteordevelopment.meteorclient.systems.accounts; -import com.mojang.authlib.exceptions.AuthenticationException; import com.mojang.authlib.minecraft.MinecraftSessionService; import com.mojang.authlib.minecraft.UserApiService; import com.mojang.authlib.yggdrasil.ServicesKeyType; diff --git a/src/main/java/meteordevelopment/meteorclient/systems/accounts/Accounts.java b/src/main/java/meteordevelopment/meteorclient/systems/accounts/Accounts.java index 30c6bb09c6..e09a4963b8 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/accounts/Accounts.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/accounts/Accounts.java @@ -15,6 +15,7 @@ import meteordevelopment.meteorclient.utils.misc.NbtUtils; import meteordevelopment.meteorclient.utils.network.MeteorExecutor; import net.minecraft.nbt.NbtCompound; +import org.jetbrains.annotations.NotNull; import java.util.ArrayList; import java.util.Iterator; @@ -51,7 +52,7 @@ public int size() { } @Override - public Iterator> iterator() { + public @NotNull Iterator> iterator() { return accounts.iterator(); } diff --git a/src/main/java/meteordevelopment/meteorclient/systems/accounts/MicrosoftLogin.java b/src/main/java/meteordevelopment/meteorclient/systems/accounts/MicrosoftLogin.java index cc0bdf877c..bc0590358d 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/accounts/MicrosoftLogin.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/accounts/MicrosoftLogin.java @@ -22,6 +22,9 @@ import java.util.function.Consumer; public class MicrosoftLogin { + private MicrosoftLogin() { + } + public static class LoginData { public String mcToken; public String newRefreshToken; diff --git a/src/main/java/meteordevelopment/meteorclient/systems/accounts/TokenAccount.java b/src/main/java/meteordevelopment/meteorclient/systems/accounts/TokenAccount.java new file mode 100644 index 0000000000..0a314485e6 --- /dev/null +++ b/src/main/java/meteordevelopment/meteorclient/systems/accounts/TokenAccount.java @@ -0,0 +1,10 @@ +/* + * This file is part of the Meteor Client distribution (https://github.com/MeteorDevelopment/meteor-client). + * Copyright (c) Meteor Development. + */ + +package meteordevelopment.meteorclient.systems.accounts; + +public interface TokenAccount { + String getToken(); +} diff --git a/src/main/java/meteordevelopment/meteorclient/systems/accounts/types/EasyMCAccount.java b/src/main/java/meteordevelopment/meteorclient/systems/accounts/types/EasyMCAccount.java index 52b1aeeef7..26f3e6e143 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/accounts/types/EasyMCAccount.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/accounts/types/EasyMCAccount.java @@ -12,20 +12,29 @@ import meteordevelopment.meteorclient.mixin.YggdrasilMinecraftSessionServiceAccessor; import meteordevelopment.meteorclient.systems.accounts.Account; import meteordevelopment.meteorclient.systems.accounts.AccountType; +import meteordevelopment.meteorclient.systems.accounts.TokenAccount; +import meteordevelopment.meteorclient.utils.misc.NbtException; import meteordevelopment.meteorclient.utils.network.Http; import net.minecraft.client.session.Session; +import net.minecraft.nbt.NbtCompound; import java.util.Optional; import static meteordevelopment.meteorclient.MeteorClient.mc; -public class EasyMCAccount extends Account { +public class EasyMCAccount extends Account implements TokenAccount { private static final Environment ENVIRONMENT = new Environment("https://sessionserver.easymc.io", "https://authserver.mojang.com", "EasyMC"); private static final YggdrasilAuthenticationService SERVICE = new YggdrasilAuthenticationService(((MinecraftClientAccessor) mc).getProxy(), ENVIRONMENT); + private String token; public EasyMCAccount(String token) { super(AccountType.EasyMC, token); + this.token = token; + } + + public String getToken() { + return token; } @Override @@ -64,4 +73,27 @@ private static class AuthResponse { public String session; public String message; } + + @Override + public NbtCompound toTag() { + NbtCompound tag = new NbtCompound(); + + tag.putString("type", type.name()); + tag.putString("name", name); + tag.putString("token", token); + tag.put("cache", cache.toTag()); + + return tag; + } + + @Override + public EasyMCAccount fromTag(NbtCompound tag) { + if (!tag.contains("name") || !tag.contains("cache") || !tag.contains("token")) throw new NbtException(); + + name = tag.getString("name"); + token = tag.getString("token"); + cache.fromTag(tag.getCompound("cache")); + + return this; + } } diff --git a/src/main/java/meteordevelopment/meteorclient/systems/accounts/types/TheAlteningAccount.java b/src/main/java/meteordevelopment/meteorclient/systems/accounts/types/TheAlteningAccount.java index 57f2df4bc2..51f63bba3c 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/accounts/types/TheAlteningAccount.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/accounts/types/TheAlteningAccount.java @@ -14,18 +14,23 @@ import meteordevelopment.meteorclient.mixin.YggdrasilMinecraftSessionServiceAccessor; import meteordevelopment.meteorclient.systems.accounts.Account; import meteordevelopment.meteorclient.systems.accounts.AccountType; +import meteordevelopment.meteorclient.systems.accounts.TokenAccount; +import meteordevelopment.meteorclient.utils.misc.NbtException; import net.minecraft.client.session.Session; +import net.minecraft.nbt.NbtCompound; import java.util.Optional; import static meteordevelopment.meteorclient.MeteorClient.mc; -public class TheAlteningAccount extends Account { +public class TheAlteningAccount extends Account implements TokenAccount { private static final Environment ENVIRONMENT = new Environment("http://sessionserver.thealtening.com", "http://authserver.thealtening.com", "The Altening"); private static final YggdrasilAuthenticationService SERVICE = new YggdrasilAuthenticationService(((MinecraftClientAccessor) mc).getProxy(), ENVIRONMENT); + private String token; public TheAlteningAccount(String token) { super(AccountType.TheAltening, token); + this.token = token; } @Override @@ -75,4 +80,32 @@ private WaybackAuthLib getAuth() { return auth; } + + @Override + public String getToken() { + return token; + } + + @Override + public NbtCompound toTag() { + NbtCompound tag = new NbtCompound(); + + tag.putString("type", type.name()); + tag.putString("name", name); + tag.putString("token", token); + tag.put("cache", cache.toTag()); + + return tag; + } + + @Override + public TheAlteningAccount fromTag(NbtCompound tag) { + if (!tag.contains("name") || !tag.contains("cache") || !tag.contains("token")) throw new NbtException(); + + name = tag.getString("name"); + token = tag.getString("token"); + cache.fromTag(tag.getCompound("cache")); + + return this; + } } diff --git a/src/main/java/meteordevelopment/meteorclient/systems/hud/Hud.java b/src/main/java/meteordevelopment/meteorclient/systems/hud/Hud.java index c6ed95fc29..200af97d3b 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/hud/Hud.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/hud/Hud.java @@ -96,6 +96,7 @@ public class Hud extends System implements Iterable { ); // Keybindings + @SuppressWarnings("unused") private final Setting keybind = sgKeybind.add(new KeybindSetting.Builder() .name("bind") .defaultValue(Keybind.none()) diff --git a/src/main/java/meteordevelopment/meteorclient/systems/hud/HudElementInfo.java b/src/main/java/meteordevelopment/meteorclient/systems/hud/HudElementInfo.java index 63c927adbf..3da6cabf6a 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/hud/HudElementInfo.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/hud/HudElementInfo.java @@ -46,7 +46,7 @@ public Preset addPreset(String title, Consumer callback) { } public boolean hasPresets() { - return presets.size() > 0; + return !presets.isEmpty(); } public HudElement create() { diff --git a/src/main/java/meteordevelopment/meteorclient/systems/hud/HudGroup.java b/src/main/java/meteordevelopment/meteorclient/systems/hud/HudGroup.java index c87d137cec..39a28fe394 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/hud/HudGroup.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/hud/HudGroup.java @@ -5,25 +5,5 @@ package meteordevelopment.meteorclient.systems.hud; -import java.util.Objects; - -public class HudGroup { - public final String title; - - public HudGroup(String title) { - this.title = title; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - HudGroup hudGroup = (HudGroup) o; - return Objects.equals(title, hudGroup.title); - } - - @Override - public int hashCode() { - return Objects.hash(title); - } +public record HudGroup(String title) { } diff --git a/src/main/java/meteordevelopment/meteorclient/systems/hud/HudRenderer.java b/src/main/java/meteordevelopment/meteorclient/systems/hud/HudRenderer.java index 0095854292..4711f60792 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/hud/HudRenderer.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/hud/HudRenderer.java @@ -46,7 +46,7 @@ public class HudRenderer { .maximumSize(4) .expireAfterAccess(Duration.ofMinutes(10)) .removalListener(notification -> { - if (notification.wasEvicted()) //noinspection ConstantConditions + if (notification.wasEvicted()) ((FontHolder) notification.getValue()).destroy(); }) .build(CacheLoader.from(HudRenderer::loadFont)); diff --git a/src/main/java/meteordevelopment/meteorclient/systems/hud/elements/CombatHud.java b/src/main/java/meteordevelopment/meteorclient/systems/hud/elements/CombatHud.java index fe2e31086f..77d66f3206 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/hud/elements/CombatHud.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/hud/elements/CombatHud.java @@ -23,7 +23,7 @@ import meteordevelopment.meteorclient.utils.render.color.Color; import meteordevelopment.meteorclient.utils.render.color.SettingColor; import net.minecraft.client.gui.screen.ingame.InventoryScreen; -import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.component.type.ItemEnchantmentsComponent; import net.minecraft.enchantment.Enchantment; import net.minecraft.enchantment.EnchantmentHelper; import net.minecraft.entity.player.PlayerEntity; @@ -33,6 +33,7 @@ import net.minecraft.item.SwordItem; import net.minecraft.registry.Registries; import net.minecraft.util.math.MathHelper; +import org.joml.Matrix4fStack; import java.util.ArrayList; import java.util.HashMap; @@ -333,9 +334,9 @@ public void render(HudRenderer renderer) { int slot = 5; // Drawing armor - MatrixStack matrices = RenderSystem.getModelViewStack(); + Matrix4fStack matrices = RenderSystem.getModelViewStack(); - matrices.push(); + matrices.pushMatrix(); matrices.scale(scale.get().floatValue(), scale.get().floatValue(), 1); x /= scale.get(); @@ -353,12 +354,12 @@ public void render(HudRenderer renderer) { armorY += 18; - Map enchantments = EnchantmentHelper.get(itemStack); + ItemEnchantmentsComponent enchantments = EnchantmentHelper.getEnchantments(itemStack); Map enchantmentsToShow = new HashMap<>(); for (Enchantment enchantment : displayedEnchantments.get()) { - if (enchantments.containsKey(enchantment)) { - enchantmentsToShow.put(enchantment, enchantments.get(enchantment)); + if (enchantments.getEnchantments().contains(Registries.ENCHANTMENT.getEntry(enchantment))) { + enchantmentsToShow.put(enchantment, enchantments.getLevel(enchantment)); } } @@ -414,7 +415,7 @@ public void render(HudRenderer renderer) { Renderer2D.COLOR.quad(x + healthWidth, y, absorbWidth, 7, healthColor2.get(), healthColor3.get(), healthColor3.get(), healthColor2.get()); Renderer2D.COLOR.render(null); - matrices.pop(); + matrices.popMatrix(); }); } diff --git a/src/main/java/meteordevelopment/meteorclient/systems/hud/elements/InventoryHud.java b/src/main/java/meteordevelopment/meteorclient/systems/hud/elements/InventoryHud.java index b22006bd66..acd8dbd52d 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/hud/elements/InventoryHud.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/hud/elements/InventoryHud.java @@ -12,7 +12,6 @@ import meteordevelopment.meteorclient.systems.hud.HudRenderer; import meteordevelopment.meteorclient.utils.Utils; import meteordevelopment.meteorclient.utils.misc.MeteorIdentifier; -import meteordevelopment.meteorclient.utils.render.RenderUtils; import meteordevelopment.meteorclient.utils.render.color.Color; import meteordevelopment.meteorclient.utils.render.color.SettingColor; import net.minecraft.item.ItemStack; diff --git a/src/main/java/meteordevelopment/meteorclient/systems/hud/elements/MeteorTextHud.java b/src/main/java/meteordevelopment/meteorclient/systems/hud/elements/MeteorTextHud.java index 9188959a38..16259d95e2 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/hud/elements/MeteorTextHud.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/hud/elements/MeteorTextHud.java @@ -15,6 +15,7 @@ public class MeteorTextHud { public static final HudElementInfo.Preset TPS; public static final HudElementInfo.Preset PING; public static final HudElementInfo.Preset SPEED; + public static final HudElementInfo.Preset GAME_MODE; public static final HudElementInfo.Preset DURABILITY; public static final HudElementInfo.Preset POSITION; public static final HudElementInfo.Preset OPPOSITE_POSITION; @@ -37,6 +38,7 @@ public class MeteorTextHud { TPS = addPreset("TPS", "TPS: #1{round(server.tps, 1)}"); PING = addPreset("Ping", "Ping: #1{ping}"); SPEED = addPreset("Speed", "Speed: #1{round(player.speed, 1)}", 0); + GAME_MODE = addPreset("Game mode", "Game mode: #1{player.gamemode}", 0); DURABILITY = addPreset("Durability", "Durability: #1{player.hand_or_offhand.durability}"); POSITION = addPreset("Position", "Pos: #1{floor(camera.pos.x)}, {floor(camera.pos.y)}, {floor(camera.pos.z)}", 0); OPPOSITE_POSITION = addPreset("Opposite Position", "{player.opposite_dimension != \"End\" ? player.opposite_dimension + \":\" : \"\"} #1{player.opposite_dimension != \"End\" ? \"\" + floor(camera.opposite_dim_pos.x) + \", \" + floor(camera.opposite_dim_pos.y) + \", \" + floor(camera.opposite_dim_pos.z) : \"\"}", 0); diff --git a/src/main/java/meteordevelopment/meteorclient/systems/hud/elements/PotionTimersHud.java b/src/main/java/meteordevelopment/meteorclient/systems/hud/elements/PotionTimersHud.java index fce248dca8..07f2f06012 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/hud/elements/PotionTimersHud.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/hud/elements/PotionTimersHud.java @@ -185,7 +185,7 @@ public void tick(HudRenderer renderer) { texts.clear(); for (StatusEffectInstance statusEffectInstance : mc.player.getStatusEffects()) { - if (hiddenEffects.get().contains(statusEffectInstance.getEffectType())) continue; + if (hiddenEffects.get().contains(statusEffectInstance.getEffectType().value())) continue; if (!showAmbient.get() && statusEffectInstance.isAmbient()) continue; String text = getString(statusEffectInstance); texts.add(new ObjectObjectImmutablePair<>(statusEffectInstance, text)); @@ -219,7 +219,7 @@ public void render(HudRenderer renderer) { for (Pair potionEffectEntry : texts) { Color color = switch (colorMode.get()) { case Effect -> { - int c = potionEffectEntry.left().getEffectType().getColor(); + int c = potionEffectEntry.left().getEffectType().value().getColor(); yield new Color(c).a(255); } case Flat -> { @@ -241,7 +241,7 @@ public void render(HudRenderer renderer) { } private String getString(StatusEffectInstance statusEffectInstance) { - return String.format("%s %d (%s)", Names.get(statusEffectInstance.getEffectType()), statusEffectInstance.getAmplifier() + 1, StatusEffectUtil.getDurationText(statusEffectInstance, 1, mc.world.getTickManager().getTickRate()).getString()); + return String.format("%s %d (%s)", Names.get(statusEffectInstance.getEffectType().value()), statusEffectInstance.getAmplifier() + 1, StatusEffectUtil.getDurationText(statusEffectInstance, 1, mc.world.getTickManager().getTickRate()).getString()); } private double getScale() { @@ -250,7 +250,7 @@ private double getScale() { private boolean hasNoVisibleEffects() { for (StatusEffectInstance statusEffectInstance : mc.player.getStatusEffects()) { - if (hiddenEffects.get().contains(statusEffectInstance.getEffectType())) continue; + if (hiddenEffects.get().contains(statusEffectInstance.getEffectType().value())) continue; if (!showAmbient.get() && statusEffectInstance.isAmbient()) continue; return false; } diff --git a/src/main/java/meteordevelopment/meteorclient/systems/hud/elements/TextHud.java b/src/main/java/meteordevelopment/meteorclient/systems/hud/elements/TextHud.java index 687276c6c5..35a0ec99a7 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/hud/elements/TextHud.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/hud/elements/TextHud.java @@ -89,7 +89,6 @@ public class TextHud extends HudElement { .name("condition") .description("Condition to check when shown is not Always.") .visible(() -> shown.get() != Shown.Always) - .defaultValue("") .onChanged(s -> recompile()) .renderer(StarscriptTextBoxRenderer.class) .build() @@ -196,7 +195,7 @@ private void runTick(HudRenderer renderer) { if (result.hasErrors()) { script = null; - section = new Section(0, result.errors.get(0).toString()); + section = new Section(0, result.errors.getFirst().toString()); calculateSize(renderer); } else script = Compiler.compile(result); diff --git a/src/main/java/meteordevelopment/meteorclient/systems/hud/screens/AddHudElementScreen.java b/src/main/java/meteordevelopment/meteorclient/systems/hud/screens/AddHudElementScreen.java index b4ac74cbfe..23657e77ae 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/hud/screens/AddHudElementScreen.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/hud/screens/AddHudElementScreen.java @@ -71,7 +71,7 @@ public void initWidgets() { // Create widgets for (HudGroup group : grouped.keySet()) { - WSection section = add(theme.section(group.title)).expandX().widget(); + WSection section = add(theme.section(group.title())).expandX().widget(); for (Item item : grouped.get(group)) { WHorizontalList l = section.add(theme.horizontalList()).expandX().widget(); diff --git a/src/main/java/meteordevelopment/meteorclient/systems/macros/Macro.java b/src/main/java/meteordevelopment/meteorclient/systems/macros/Macro.java index 81d7f31e6a..f01d904cf0 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/macros/Macro.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/macros/Macro.java @@ -29,7 +29,6 @@ public class Macro implements ISerializable { public Setting name = sgGeneral.add(new StringSetting.Builder() .name("name") .description("The name of the macro.") - .defaultValue("") .build() ); @@ -55,8 +54,8 @@ public Macro(NbtElement tag) { fromTag((NbtCompound) tag); } - public boolean onAction(boolean isKey, int value) { - if (!keybind.get().matches(isKey, value) || mc.currentScreen != null) return false; + public boolean onAction(boolean isKey, int value, int modifiers) { + if (!keybind.get().matches(isKey, value, modifiers) || mc.currentScreen != null) return false; return onAction(); } diff --git a/src/main/java/meteordevelopment/meteorclient/systems/macros/Macros.java b/src/main/java/meteordevelopment/meteorclient/systems/macros/Macros.java index 5cd469baa3..fba8cbb281 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/macros/Macros.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/macros/Macros.java @@ -15,6 +15,7 @@ import meteordevelopment.orbit.EventHandler; import meteordevelopment.orbit.EventPriority; import net.minecraft.nbt.NbtCompound; +import org.jetbrains.annotations.NotNull; import java.util.ArrayList; import java.util.Iterator; @@ -61,7 +62,7 @@ private void onKey(KeyEvent event) { if (event.action == KeyAction.Release) return; for (Macro macro : macros) { - if (macro.onAction(true, event.key)) return; + if (macro.onAction(true, event.key, event.modifiers)) return; } } @@ -70,7 +71,7 @@ private void onButton(MouseButtonEvent event) { if (event.action == KeyAction.Release) return; for (Macro macro : macros) { - if (macro.onAction(false, event.button)) return; + if (macro.onAction(false, event.button, 0)) return; } } @@ -79,7 +80,7 @@ public boolean isEmpty() { } @Override - public Iterator iterator() { + public @NotNull Iterator iterator() { return macros.iterator(); } diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/Module.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/Module.java index d864fddfa6..2b20b44d57 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/Module.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/Module.java @@ -131,7 +131,6 @@ public NbtCompound toTag() { tag.putBoolean("chatFeedback", chatFeedback); tag.putBoolean("favorite", favorite); tag.put("settings", settings.toTag()); - tag.putBoolean("active", active); return tag; @@ -140,9 +139,7 @@ public NbtCompound toTag() { @Override public Module fromTag(NbtCompound tag) { // General - if (tag.contains("key")) keybind.set(true, tag.getInt("key")); - else keybind.fromTag(tag.getCompound("keybind")); - + keybind.fromTag(tag.getCompound("keybind")); toggleOnBindRelease = tag.getBoolean("toggleOnKeyRelease"); chatFeedback = !tag.contains("chatFeedback") || tag.getBoolean("chatFeedback"); favorite = tag.getBoolean("favorite"); diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/Modules.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/Modules.java index 65125c1d8e..801118426a 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/Modules.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/Modules.java @@ -52,6 +52,7 @@ import net.minecraft.registry.tag.TagKey; import net.minecraft.util.Identifier; import net.minecraft.util.math.random.Random; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.lwjgl.glfw.GLFW; @@ -225,19 +226,19 @@ public boolean isBinding() { @EventHandler(priority = EventPriority.HIGHEST) private void onKeyBinding(KeyEvent event) { - if (event.action == KeyAction.Press && onBinding(true, event.key)) event.cancel(); + if (event.action == KeyAction.Release && onBinding(true, event.key, event.modifiers)) event.cancel(); } @EventHandler(priority = EventPriority.HIGHEST) private void onButtonBinding(MouseButtonEvent event) { - if (event.action == KeyAction.Press && onBinding(false, event.button)) event.cancel(); + if (event.action == KeyAction.Release && onBinding(false, event.button, 0)) event.cancel(); } - private boolean onBinding(boolean isKey, int value) { + private boolean onBinding(boolean isKey, int value, int modifiers) { if (!isBinding()) return false; - if (moduleToBind.keybind.canBindTo(isKey, value)) { - moduleToBind.keybind.set(isKey, value); + if (moduleToBind.keybind.canBindTo(isKey, value, modifiers)) { + moduleToBind.keybind.set(isKey, value, modifiers); moduleToBind.info("Bound to (highlight)%s(default).", moduleToBind.keybind); } else if (value == GLFW.GLFW_KEY_ESCAPE) { @@ -255,22 +256,22 @@ else if (value == GLFW.GLFW_KEY_ESCAPE) { @EventHandler(priority = EventPriority.HIGH) private void onKey(KeyEvent event) { if (event.action == KeyAction.Repeat) return; - onAction(true, event.key, event.action == KeyAction.Press); + onAction(true, event.key, event.modifiers, event.action == KeyAction.Press); } @EventHandler(priority = EventPriority.HIGH) private void onMouseButton(MouseButtonEvent event) { if (event.action == KeyAction.Repeat) return; - onAction(false, event.button, event.action == KeyAction.Press); + onAction(false, event.button, 0, event.action == KeyAction.Press); } - private void onAction(boolean isKey, int value, boolean isPress) { - if (mc.currentScreen == null && !Input.isKeyPressed(GLFW.GLFW_KEY_F3)) { - for (Module module : moduleInstances.values()) { - if (module.keybind.matches(isKey, value) && (isPress || module.toggleOnBindRelease)) { - module.toggle(); - module.sendToggledMsg(); - } + private void onAction(boolean isKey, int value, int modifiers, boolean isPress) { + if (mc.currentScreen != null || Input.isKeyPressed(GLFW.GLFW_KEY_F3)) return; + + for (Module module : moduleInstances.values()) { + if (module.keybind.matches(isKey, value, modifiers) && (isPress || module.toggleOnBindRelease)) { + module.toggle(); + module.sendToggledMsg(); } } } @@ -424,6 +425,7 @@ private void initPlayer() { add(new FakePlayer()); add(new FastUse()); add(new GhostHand()); + add(new InstaMine()); add(new LiquidInteract()); add(new MiddleClickExtra()); add(new BreakDelay()); @@ -605,11 +607,6 @@ public Module get(Identifier id) { return null; } - @Override - public Lifecycle getEntryLifecycle(Module object) { - return null; - } - @Override public Lifecycle getLifecycle() { return null; @@ -631,7 +628,7 @@ public Module get(int index) { } @Override - public Iterator iterator() { + public @NotNull Iterator iterator() { return new ModuleIterator(); } diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/combat/AntiAnvil.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/combat/AntiAnvil.java index fde09c0dd2..3285309807 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/combat/AntiAnvil.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/combat/AntiAnvil.java @@ -41,7 +41,7 @@ public AntiAnvil() { @EventHandler private void onTick(TickEvent.Pre event) { - for (int i = 0; i <= mc.interactionManager.getReachDistance(); i++) { + for (int i = 0; i <= mc.player.getBlockInteractionRange(); i++) { BlockPos pos = mc.player.getBlockPos().add(0, i + 3, 0); if (mc.world.getBlockState(pos).getBlock() == Blocks.ANVIL && mc.world.getBlockState(pos.down()).isAir()) { diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/combat/ArrowDodge.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/combat/ArrowDodge.java index ed08eee3d5..8c2d51e4a3 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/combat/ArrowDodge.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/combat/ArrowDodge.java @@ -119,7 +119,7 @@ private void onTick(TickEvent.Pre event) { UUID owner = ((ProjectileEntityAccessor) e).getOwnerUuid(); if (owner != null && owner.equals(mc.player.getUuid())) continue; } - if (!simulator.set(e, accurate.get(), 0.5D)) continue; + if (!simulator.set(e, accurate.get())) continue; for (int i = 0; i < (simulationSteps.get() > 0 ? simulationSteps.get() : Integer.MAX_VALUE); i++) { points.add(vec3s.get().set(simulator.pos)); if (simulator.tick() != null) break; diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/combat/AutoArmor.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/combat/AutoArmor.java index 24bc1e8add..40906739c9 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/combat/AutoArmor.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/combat/AutoArmor.java @@ -170,8 +170,8 @@ private int getScore(ItemStack itemStack) { score += enchantments.getInt(Enchantments.PROJECTILE_PROTECTION); score += enchantments.getInt(Enchantments.UNBREAKING); score += 2 * enchantments.getInt(Enchantments.MENDING); - score += itemStack.getItem() instanceof ArmorItem ? ((ArmorItem) itemStack.getItem()).getProtection() : 0; - score += itemStack.getItem() instanceof ArmorItem ? ((ArmorItem) itemStack.getItem()).getToughness() : 0; + score += itemStack.getItem() instanceof ArmorItem armorItem ? armorItem.getProtection() : 0; + score += itemStack.getItem() instanceof ArmorItem armorItem ? (int) armorItem.getToughness() : 0; return score; } diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/combat/AutoTrap.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/combat/AutoTrap.java index 613bbca1ee..09291ac369 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/combat/AutoTrap.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/combat/AutoTrap.java @@ -180,8 +180,8 @@ private void onTick(TickEvent.Pre event) { fillPlaceArray(target); - if (timer >= delay.get() && placePositions.size() > 0) { - BlockPos blockPos = placePositions.get(placePositions.size() - 1); + if (timer >= delay.get() && !placePositions.isEmpty()) { + BlockPos blockPos = placePositions.getLast(); if (BlockUtils.place(blockPos, itemResult, rotate.get(), 50, true)) { placePositions.remove(blockPos); @@ -201,7 +201,7 @@ private void onRender(Render3DEvent event) { if (!render.get() || placePositions.isEmpty()) return; for (BlockPos pos : placePositions) { - boolean isFirst = pos.equals(placePositions.get(placePositions.size() - 1)); + boolean isFirst = pos.equals(placePositions.getLast()); Color side = isFirst ? nextSideColor.get() : sideColor.get(); Color line = isFirst ? nextLineColor.get() : lineColor.get(); diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/combat/AutoWeapon.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/combat/AutoWeapon.java index 99ba212131..c8341f6e25 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/combat/AutoWeapon.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/combat/AutoWeapon.java @@ -13,7 +13,7 @@ import meteordevelopment.meteorclient.utils.player.InvUtils; import meteordevelopment.orbit.EventHandler; import net.minecraft.enchantment.EnchantmentHelper; -import net.minecraft.entity.EntityGroup; +import net.minecraft.entity.EntityType; import net.minecraft.item.AxeItem; import net.minecraft.item.ItemStack; import net.minecraft.item.SwordItem; @@ -51,7 +51,7 @@ private void onAttack(AttackEntityEvent event) { InvUtils.swap(getBestWeapon(EntityUtils.getGroup(event.entity)), false); } - private int getBestWeapon(EntityGroup group) { + private int getBestWeapon(EntityType group) { int slotS = mc.player.getInventory().selectedSlot; int slotA = mc.player.getInventory().selectedSlot; double damageS = 0; diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/combat/CrystalAura.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/combat/CrystalAura.java index af9915d787..433777833a 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/combat/CrystalAura.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/combat/CrystalAura.java @@ -26,7 +26,10 @@ import meteordevelopment.meteorclient.utils.entity.EntityUtils; import meteordevelopment.meteorclient.utils.entity.Target; import meteordevelopment.meteorclient.utils.misc.Keybind; -import meteordevelopment.meteorclient.utils.player.*; +import meteordevelopment.meteorclient.utils.player.FindItemResult; +import meteordevelopment.meteorclient.utils.player.InvUtils; +import meteordevelopment.meteorclient.utils.player.PlayerUtils; +import meteordevelopment.meteorclient.utils.player.Rotations; import meteordevelopment.meteorclient.utils.render.NametagUtils; import meteordevelopment.meteorclient.utils.render.RenderUtils; import meteordevelopment.meteorclient.utils.render.color.Color; @@ -38,6 +41,8 @@ import meteordevelopment.orbit.EventPriority; import net.minecraft.block.Blocks; import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityType; +import net.minecraft.entity.LivingEntity; import net.minecraft.entity.decoration.EndCrystalEntity; import net.minecraft.entity.effect.StatusEffectInstance; import net.minecraft.entity.effect.StatusEffects; @@ -53,6 +58,7 @@ import java.util.ArrayList; import java.util.List; +import java.util.Set; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; @@ -138,6 +144,14 @@ public class CrystalAura extends Module { .build() ); + private final Setting>> entities = sgGeneral.add(new EntityTypeListSetting.Builder() + .name("entities") + .description("Entities to attack.") + .onlyAttackable() + .defaultValue(EntityType.PLAYER, EntityType.WARDEN, EntityType.WITHER) + .build() + ); + // Switch private final Setting autoSwitch = sgSwitch.add(new EnumSetting.Builder() @@ -541,7 +555,7 @@ public class CrystalAura extends Module { private Item mainItem, offItem; private int breakTimer, placeTimer, switchTimer, ticksPassed; - private final List targets = new ArrayList<>(); + private final List targets = new ArrayList<>(); private final Vec3d vec3d = new Vec3d(0, 0, 0); private final Vec3d playerEyePos = new Vec3d(0, 0, 0); @@ -565,7 +579,7 @@ public class CrystalAura extends Module { private double serverYaw; - private PlayerEntity bestTarget; + private LivingEntity bestTarget; private double bestTargetDamage; private int bestTargetTimer; @@ -685,7 +699,7 @@ private void onPreTick(TickEvent.Pre event) { // Find targets, break and place findTargets(); - if (targets.size() > 0) { + if (!targets.isEmpty()) { if (!didRotateThisTick) doBreak(); if (!didRotateThisTick) doPlace(); } @@ -1105,7 +1119,7 @@ private boolean shouldFacePlace() { if (forceFacePlace.get().isPressed()) return true; // Checks if the provided crystal position should face place to any target - for (PlayerEntity target : targets) { + for (LivingEntity target : targets) { if (EntityUtils.getTotalHealth(target) <= facePlaceHealth.get()) return true; for (ItemStack itemStack : target.getArmorItems()) { @@ -1144,11 +1158,11 @@ private boolean isOutOfRange(Vec3d vec3d, BlockPos blockPos, boolean place) { return !PlayerUtils.isWithin(vec3d, (place ? placeRange : breakRange).get()); } - private PlayerEntity getNearestTarget() { - PlayerEntity nearestTarget = null; + private LivingEntity getNearestTarget() { + LivingEntity nearestTarget = null; double nearestDistance = Double.MAX_VALUE; - for (PlayerEntity target : targets) { + for (LivingEntity target : targets) { double distance = PlayerUtils.squaredDistanceTo(target); if (distance < nearestDistance) { @@ -1164,11 +1178,11 @@ private float getDamageToTargets(Vec3d vec3d, BlockPos obsidianPos, boolean brea float damage = 0; if (fast) { - PlayerEntity target = getNearestTarget(); + LivingEntity target = getNearestTarget(); if (!(smartDelay.get() && breaking && target.hurtTime > 0)) damage = DamageUtils.crystalDamage(target, vec3d, predictMovement.get(), obsidianPos); } else { - for (PlayerEntity target : targets) { + for (LivingEntity target : targets) { if (smartDelay.get() && breaking && target.hurtTime > 0) continue; float dmg = DamageUtils.crystalDamage(target, vec3d, predictMovement.get(), obsidianPos); @@ -1189,29 +1203,40 @@ private float getDamageToTargets(Vec3d vec3d, BlockPos obsidianPos, boolean brea @Override public String getInfoString() { - return bestTarget != null && bestTargetTimer > 0 ? bestTarget.getGameProfile().getName() : null; + return bestTarget != null && bestTargetTimer > 0 ? EntityUtils.getName(bestTarget) : null; } private void findTargets() { targets.clear(); - // Players - for (PlayerEntity player : mc.world.getPlayers()) { - if (player.getAbilities().creativeMode || player == mc.player) continue; - if (!player.isAlive() || !Friends.get().shouldAttack(player)) continue; - if (player.squaredDistanceTo(mc.player) > Math.pow(targetRange.get(), 2)) continue; - - if (ignoreNakeds.get()) { - if (player.getOffHandStack().isEmpty() - && player.getMainHandStack().isEmpty() - && player.getInventory().armor.get(0).isEmpty() - && player.getInventory().armor.get(1).isEmpty() - && player.getInventory().armor.get(2).isEmpty() - && player.getInventory().armor.get(3).isEmpty() - ) continue; + // Living Entities + for (Entity entity : mc.world.getEntities()) { + // Ignore non-living + if (!(entity instanceof LivingEntity livingEntity)) continue; + + // Player + if (livingEntity instanceof PlayerEntity player) { + if (player.getAbilities().creativeMode || livingEntity == mc.player) continue; + if (!player.isAlive() || !Friends.get().shouldAttack(player)) continue; + + if (ignoreNakeds.get()) { + if (player.getOffHandStack().isEmpty() + && player.getMainHandStack().isEmpty() + && player.getInventory().armor.get(0).isEmpty() + && player.getInventory().armor.get(1).isEmpty() + && player.getInventory().armor.get(2).isEmpty() + && player.getInventory().armor.get(3).isEmpty() + ) continue; + } } - targets.add(player); + // Animals, water animals, monsters, bats, misc + if (!(entities.get().contains(livingEntity.getType()))) continue; + + // Close enough to damage + if (livingEntity.squaredDistanceTo(mc.player) > targetRange.get() * targetRange.get()) continue; + + targets.add(livingEntity); } } diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/combat/KillAura.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/combat/KillAura.java index d81285d8af..8c0a798bc4 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/combat/KillAura.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/combat/KillAura.java @@ -30,7 +30,6 @@ import net.minecraft.entity.mob.EndermanEntity; import net.minecraft.entity.mob.ZombifiedPiglinEntity; import net.minecraft.entity.passive.AnimalEntity; -import net.minecraft.entity.passive.LlamaEntity; import net.minecraft.entity.passive.WolfEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.AxeItem; @@ -236,6 +235,7 @@ public class KillAura extends Module { private final List targets = new ArrayList<>(); private int switchTimer, hitTimer; private boolean wasPathing = false; + public boolean attacking; public KillAura() { super(Categories.Combat, "kill-aura", "Attacks specified entities around you."); @@ -244,6 +244,7 @@ public KillAura() { @Override public void onDeactivate() { targets.clear(); + attacking = false; } @EventHandler @@ -268,6 +269,7 @@ private void onTick(TickEvent.Pre event) { } if (targets.isEmpty()) { + attacking = false; if (wasPathing) { PathManagers.get().resume(); wasPathing = false; @@ -275,7 +277,7 @@ private void onTick(TickEvent.Pre event) { return; } - Entity primary = targets.get(0); + Entity primary = targets.getFirst(); if (autoSwitch.get()) { Predicate predicate = switch (weapon.get()) { @@ -296,6 +298,7 @@ private void onTick(TickEvent.Pre event) { if (!itemInHand()) return; + attacking = true; if (rotation.get() == RotationMode.Always) Rotations.rotate(Rotations.getYaw(primary), Rotations.getPitch(primary, Target.Body)); if (pauseOnCombat.get() && PathManagers.get().isPathing() && !wasPathing) { PathManagers.get().pause(); @@ -346,10 +349,9 @@ private boolean entityCheck(Entity entity) { ) return false; } if (ignorePassive.get()) { - if (entity instanceof EndermanEntity enderman && !enderman.isAngryAt(mc.player)) return false; - if (entity instanceof ZombifiedPiglinEntity piglin && !piglin.isAngryAt(mc.player)) return false; + if (entity instanceof EndermanEntity enderman && !enderman.isAngry()) return false; + if (entity instanceof ZombifiedPiglinEntity piglin && !piglin.isAttacking()) return false; if (entity instanceof WolfEntity wolf && !wolf.isAttacking()) return false; - if (entity instanceof LlamaEntity llama && !llama.isAttacking()) return false; } if (entity instanceof PlayerEntity player) { if (player.isCreative()) return false; @@ -404,7 +406,7 @@ private boolean itemInHand() { } public Entity getTarget() { - if (!targets.isEmpty()) return targets.get(0); + if (!targets.isEmpty()) return targets.getFirst(); return null; } diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/combat/Offhand.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/combat/Offhand.java index 54851c022f..53a262fb59 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/combat/Offhand.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/combat/Offhand.java @@ -16,6 +16,7 @@ import meteordevelopment.meteorclient.utils.player.InvUtils; import meteordevelopment.meteorclient.utils.player.PlayerUtils; import meteordevelopment.orbit.EventHandler; +import net.minecraft.component.DataComponentTypes; import net.minecraft.entity.EquipmentSlot; import net.minecraft.item.*; @@ -144,7 +145,7 @@ public void onActivate() { } @EventHandler(priority = HIGHEST + 999) - private void onTick(TickEvent.Pre event) throws InterruptedException { + private void onTick(TickEvent.Pre event) { FindItemResult result = InvUtils.find(Items.TOTEM_OF_UNDYING); totems = result.count(); @@ -245,7 +246,7 @@ private boolean usableItem() { return mc.player.getMainHandStack().getItem() == Items.BOW || mc.player.getMainHandStack().getItem() == Items.TRIDENT || mc.player.getMainHandStack().getItem() == Items.CROSSBOW - || mc.player.getMainHandStack().getItem().isFood(); + || mc.player.getMainHandStack().getItem().getComponents().contains(DataComponentTypes.FOOD); } @Override @@ -261,7 +262,7 @@ public enum Item { Totem(Items.TOTEM_OF_UNDYING), Shield(Items.SHIELD), Potion(Items.POTION); - net.minecraft.item.Item item; + final net.minecraft.item.Item item; Item(net.minecraft.item.Item item) { this.item = item; } diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/combat/Quiver.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/combat/Quiver.java index c0efef35bd..981ba9b1ce 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/combat/Quiver.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/combat/Quiver.java @@ -17,6 +17,7 @@ import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; +import net.minecraft.component.DataComponentTypes; import net.minecraft.entity.effect.StatusEffect; import net.minecraft.entity.effect.StatusEffectInstance; import net.minecraft.entity.effect.StatusEffects; @@ -25,11 +26,11 @@ import net.minecraft.item.ItemStack; import net.minecraft.item.Items; import net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket; -import net.minecraft.potion.PotionUtil; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Direction; import java.util.ArrayList; +import java.util.Iterator; import java.util.List; public class Quiver extends Module { @@ -40,7 +41,7 @@ public class Quiver extends Module { private final Setting> effects = sgGeneral.add(new StatusEffectListSetting.Builder() .name("effects") .description("Which effects to shoot you with.") - .defaultValue(StatusEffects.STRENGTH) + .defaultValue(StatusEffects.STRENGTH.value()) .build() ); @@ -136,11 +137,11 @@ public void onActivate() { if (item.getItem() != Items.TIPPED_ARROW) continue; - List effects = PotionUtil.getPotionEffects(item); + Iterator effects = item.getItem().getComponents().get(DataComponentTypes.POTION_CONTENTS).getEffects().iterator(); - if (effects.isEmpty()) continue; + if (!effects.hasNext()) continue; - StatusEffect effect = effects.get(0).getEffectType(); + StatusEffect effect = effects.next().getEffectType().value(); if (this.effects.get().contains(effect) && !usedEffects.contains(effect) @@ -176,12 +177,12 @@ private void onTick(TickEvent.Pre event) { boolean charging = mc.options.useKey.isPressed(); if (!charging) { - InvUtils.move().from(arrowSlots.get(0)).to(9); + InvUtils.move().from(arrowSlots.getFirst()).to(9); mc.options.useKey.setPressed(true); } else { if (BowItem.getPullProgress(mc.player.getItemUseTime()) >= 0.12) { - int targetSlot = arrowSlots.get(0); - arrowSlots.remove(0); + int targetSlot = arrowSlots.getFirst(); + arrowSlots.removeFirst(); mc.getNetworkHandler().sendPacket(new PlayerMoveC2SPacket.LookAndOnGround(mc.player.getYaw(), -90, mc.player.isOnGround())); mc.options.useKey.setPressed(false); @@ -239,7 +240,7 @@ private boolean headIsOpen() { private boolean hasEffect(StatusEffect effect) { for (StatusEffectInstance statusEffect : mc.player.getStatusEffects()) { - if (statusEffect.getEffectType() == effect) return true; + if (statusEffect.getEffectType().value().equals(effect)) return true; } return false; diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/combat/SelfTrap.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/combat/SelfTrap.java index d9504f4126..d1706de6b9 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/combat/SelfTrap.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/combat/SelfTrap.java @@ -156,8 +156,8 @@ private void onTick(TickEvent.Pre event) { findPlacePos(currentBlock); - if (delay >= delaySetting.get() && placePositions.size() > 0) { - BlockPos blockPos = placePositions.get(placePositions.size() - 1); + if (delay >= delaySetting.get() && !placePositions.isEmpty()) { + BlockPos blockPos = placePositions.getLast(); if (BlockUtils.place(blockPos, itemResult, rotate.get(), 50)) { placePositions.remove(blockPos); diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/combat/Surround.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/combat/Surround.java index 2584880c19..6e41fcdd76 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/combat/Surround.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/combat/Surround.java @@ -397,7 +397,7 @@ private boolean place(CardinalDirection direction, int y) { @EventHandler private void onPacketReceive(PacketEvent.Receive event) { if (event.packet instanceof DeathMessageS2CPacket packet) { - Entity entity = mc.world.getEntityById(packet.getEntityId()); + Entity entity = mc.world.getEntityById(packet.playerId()); if (entity == mc.player && toggleOnDeath.get()) { toggle(); info("Toggled off because you died."); diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/misc/BookBot.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/misc/BookBot.java index e3f6980b8b..8f3223a2d9 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/misc/BookBot.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/misc/BookBot.java @@ -20,15 +20,14 @@ import meteordevelopment.meteorclient.utils.player.InvUtils; import meteordevelopment.orbit.EventHandler; import net.minecraft.client.font.TextHandler; -import net.minecraft.item.*; +import net.minecraft.component.DataComponentTypes; +import net.minecraft.component.type.WritableBookContentComponent; +import net.minecraft.component.type.WrittenBookContentComponent; +import net.minecraft.item.ItemStack; +import net.minecraft.item.Items; import net.minecraft.nbt.NbtCompound; -import net.minecraft.nbt.NbtList; -import net.minecraft.nbt.NbtString; import net.minecraft.network.packet.c2s.play.BookUpdateC2SPacket; -import net.minecraft.text.ClickEvent; -import net.minecraft.text.MutableText; -import net.minecraft.text.Style; -import net.minecraft.text.Text; +import net.minecraft.text.*; import net.minecraft.util.Formatting; import org.lwjgl.BufferUtils; import org.lwjgl.PointerBuffer; @@ -40,7 +39,10 @@ import java.io.FileReader; import java.io.IOException; import java.nio.ByteBuffer; -import java.util.*; +import java.util.ArrayList; +import java.util.Optional; +import java.util.PrimitiveIterator; +import java.util.Random; import java.util.function.Predicate; public class BookBot extends Module { @@ -165,8 +167,10 @@ public void onActivate() { @EventHandler private void onTick(TickEvent.Post event) { - Predicate bookPredicate = i -> - i.getItem() == Items.WRITABLE_BOOK && (i.getNbt() == null || i.getNbt().get("pages") == null || ((NbtList) i.getNbt().get("pages")).isEmpty()); + Predicate bookPredicate = i -> { + WritableBookContentComponent component = i.get(DataComponentTypes.WRITABLE_BOOK_CONTENT); + return i.getItem() == Items.WRITABLE_BOOK && (component != null || component.pages().isEmpty()); + }; FindItemResult writableBook = InvUtils.find(bookPredicate); @@ -217,8 +221,8 @@ private void onTick(TickEvent.Post event) { message.append(Text.literal("The bookbot file is empty! ").formatted(Formatting.RED)); message.append(Text.literal("Click here to edit it.") .setStyle(Style.EMPTY - .withFormatting(Formatting.UNDERLINE, Formatting.RED) - .withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_FILE, file.getAbsolutePath())) + .withFormatting(Formatting.UNDERLINE, Formatting.RED) + .withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_FILE, file.getAbsolutePath())) ) ); info(message); @@ -247,6 +251,7 @@ private void onTick(TickEvent.Post event) { private void writeBook(PrimitiveIterator.OfInt chars) { ArrayList pages = new ArrayList<>(); + ArrayList> filteredPages = new ArrayList<>(); TextHandler.WidthRetriever widthRetriever = ((TextHandlerAccessor) mc.textRenderer.getTextHandler()).getWidthRetriever(); int maxPages = mode.get() == Mode.File ? 100 : this.pages.get(); @@ -285,6 +290,7 @@ private void writeBook(PrimitiveIterator.OfInt chars) { // Reached end of page if (lineIndex == 14) { + filteredPages.add(RawFilteredPair.of(Text.of(page.toString()))); pages.add(page.toString()); page.setLength(0); pageIndex++; @@ -302,6 +308,7 @@ private void writeBook(PrimitiveIterator.OfInt chars) { // No more characters, end current page if (!page.isEmpty() && pageIndex != maxPages) { + filteredPages.add(RawFilteredPair.of(Text.of(page.toString()))); pages.add(page.toString()); } @@ -310,13 +317,7 @@ private void writeBook(PrimitiveIterator.OfInt chars) { if (count.get() && bookCount != 0) title += " #" + bookCount; // Write data to book - mc.player.getMainHandStack().setSubNbt("title", NbtString.of(title)); - mc.player.getMainHandStack().setSubNbt("author", NbtString.of(mc.player.getGameProfile().getName())); - - // Write pages NBT - NbtList pageNbt = new NbtList(); - pages.stream().map(NbtString::of).forEach(pageNbt::add); - if (!pages.isEmpty()) mc.player.getMainHandStack().setSubNbt("pages", pageNbt); + mc.player.getMainHandStack().set(DataComponentTypes.WRITTEN_BOOK_CONTENT, new WrittenBookContentComponent(RawFilteredPair.of(title), mc.player.getGameProfile().getName(), 0, filteredPages, true)); // Send book update to server mc.player.networkHandler.sendPacket(new BookUpdateC2SPacket(mc.player.getInventory().selectedSlot, pages, sign.get() ? Optional.of(title) : Optional.empty())); diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/misc/InventoryTweaks.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/misc/InventoryTweaks.java index c7bc6311ca..5c3b7b72d2 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/misc/InventoryTweaks.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/misc/InventoryTweaks.java @@ -36,7 +36,6 @@ import net.minecraft.screen.slot.Slot; import org.lwjgl.glfw.GLFW; -import java.util.Arrays; import java.util.List; import java.util.concurrent.ThreadLocalRandom; @@ -141,7 +140,7 @@ public class InventoryTweaks extends Module { public final Setting>> stealScreens = sgStealDump.add(new ScreenHandlerListSetting.Builder() .name("steal-screens") .description("Select the screens to display buttons and auto steal.") - .defaultValue(Arrays.asList(ScreenHandlerType.GENERIC_9X3, ScreenHandlerType.GENERIC_9X6)) + .defaultValue(List.of(ScreenHandlerType.GENERIC_9X3, ScreenHandlerType.GENERIC_9X6)) .build() ); @@ -263,7 +262,7 @@ public void onDeactivate() { private void onKey(KeyEvent event) { if (event.action != KeyAction.Press) return; - if (sortingKey.get().matches(true, event.key)) { + if (sortingKey.get().matches(true, event.key, event.modifiers)) { if (sort()) event.cancel(); } } @@ -272,7 +271,7 @@ private void onKey(KeyEvent event) { private void onMouseButton(MouseButtonEvent event) { if (event.action != KeyAction.Press) return; - if (sortingKey.get().matches(false, event.button)) { + if (sortingKey.get().matches(false, event.button, 0)) { if (sort()) event.cancel(); } } diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/misc/NameProtect.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/misc/NameProtect.java index a1bb503b55..fc5987e75e 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/misc/NameProtect.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/misc/NameProtect.java @@ -57,7 +57,7 @@ public String replaceName(String string) { } public String getName(String original) { - if (name.get().length() > 0 && isActive()) { + if (!name.get().isEmpty() && isActive()) { return name.get(); } diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/misc/Notebot.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/misc/Notebot.java index 00caf88242..0bc2c6009c 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/misc/Notebot.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/misc/Notebot.java @@ -36,9 +36,9 @@ import net.minecraft.block.Blocks; import net.minecraft.block.NoteBlock; import net.minecraft.block.enums.Instrument; +import net.minecraft.entity.attribute.EntityAttributes; import net.minecraft.network.packet.c2s.play.PlayerActionC2SPacket; import net.minecraft.network.packet.c2s.play.PlayerInteractBlockC2SPacket; -import net.minecraft.server.network.ServerPlayNetworkHandler; import net.minecraft.sound.SoundEvents; import net.minecraft.util.Hand; import net.minecraft.util.hit.BlockHitResult; @@ -483,7 +483,7 @@ private void setupNoteblocksMap() { if (uniqueNotesToUse.contains(note)) { // Add correct noteblock position to a noteBlockPositions - noteBlockPositions.put(note, noteblocks.remove(0)); + noteBlockPositions.put(note, noteblocks.removeFirst()); uniqueNotesToUse.remove(note); } @@ -514,7 +514,7 @@ private void setupNoteblocksMap() { for (BlockPos pos : positions) { if (foundNotes.isEmpty()) break; - Note note = foundNotes.remove(0); + Note note = foundNotes.removeFirst(); noteBlockPositions.put(note, pos); uniqueNotesToUse.remove(note); @@ -523,7 +523,7 @@ private void setupNoteblocksMap() { for (BlockPos pos : positions) { if (uniqueNotesToUse.isEmpty()) break; - Note note = uniqueNotesToUse.remove(0); + Note note = uniqueNotesToUse.removeFirst(); noteBlockPositions.put(note, pos); } } @@ -766,8 +766,8 @@ public boolean loadFileToMap(File file, Runnable callback) { private void scanForNoteblocks() { if (mc.interactionManager == null || mc.world == null || mc.player == null) return; scannedNoteblocks.clear(); - int min = (int) (-mc.interactionManager.getReachDistance()) - 2; - int max = (int) mc.interactionManager.getReachDistance() + 2; + int min = (int) (-mc.player.getBlockInteractionRange()) - 2; + int max = (int) mc.player.getBlockInteractionRange() + 2; // Scan for noteblocks horizontally // 6^3 kek @@ -782,7 +782,7 @@ private void scanForNoteblocks() { // Copied from ServerPlayNetworkHandler#onPlayerInteractBlock Vec3d vec3d2 = Vec3d.ofCenter(pos); double sqDist = mc.player.getEyePos().squaredDistanceTo(vec3d2); - if (sqDist > ServerPlayNetworkHandler.MAX_BREAK_SQUARED_DISTANCE) continue; + if (sqDist > mc.player.getAttributeValue(EntityAttributes.PLAYER_BLOCK_INTERACTION_RANGE)) continue; if (!isValidScanSpot(pos)) continue; diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/misc/ServerSpoof.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/misc/ServerSpoof.java index dd0b910d15..d279b2ae1f 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/misc/ServerSpoof.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/misc/ServerSpoof.java @@ -5,16 +5,15 @@ package meteordevelopment.meteorclient.systems.modules.misc; -import io.netty.buffer.Unpooled; -import meteordevelopment.meteorclient.MeteorClient; import meteordevelopment.meteorclient.events.packets.PacketEvent; import meteordevelopment.meteorclient.settings.*; import meteordevelopment.meteorclient.systems.modules.Categories; import meteordevelopment.meteorclient.systems.modules.Module; +import meteordevelopment.meteorclient.utils.misc.text.RunnableClickEvent; import meteordevelopment.orbit.EventHandler; -import net.minecraft.network.PacketByteBuf; import net.minecraft.network.packet.BrandCustomPayload; import net.minecraft.network.packet.c2s.common.CustomPayloadC2SPacket; +import net.minecraft.network.packet.c2s.common.ResourcePackStatusC2SPacket; import net.minecraft.network.packet.s2c.common.ResourcePackSendS2CPacket; import net.minecraft.text.ClickEvent; import net.minecraft.text.HoverEvent; @@ -61,7 +60,7 @@ public class ServerSpoof extends Module { private final Setting> channels = sgGeneral.add(new StringListSetting.Builder() .name("channels") .description("If the channel contains the keyword, this outgoing channel will be blocked.") - .defaultValue("minecraft:register") + .defaultValue("fabric", "minecraft:register") .visible(blockChannels::get) .build() ); @@ -69,49 +68,60 @@ public class ServerSpoof extends Module { public ServerSpoof() { super(Categories.Misc, "server-spoof", "Spoof client brand, resource pack and channels."); - MeteorClient.EVENT_BUS.subscribe(new Listener()); + runInMainMenu = true; } - private class Listener { - @EventHandler - private void onPacketSend(PacketEvent.Send event) { - if (!isActive()) return; - if (!(event.packet instanceof CustomPayloadC2SPacket)) return; - Identifier id = ((CustomPayloadC2SPacket) event.packet).payload().id(); - - if (spoofBrand.get() && id.equals(BrandCustomPayload.ID)) - event.packet.write(new PacketByteBuf(Unpooled.buffer()).writeString(brand.get())); - - if (blockChannels.get()) { - for (String channel : channels.get()) { - if (StringUtils.containsIgnoreCase(channel, id.toString())) { - event.cancel(); - return; - } + @EventHandler + private void onPacketSend(PacketEvent.Send event) { + if (!isActive() || !(event.packet instanceof CustomPayloadC2SPacket)) return; + Identifier id = ((CustomPayloadC2SPacket) event.packet).payload().getId().id(); + + if (spoofBrand.get() && id.equals(BrandCustomPayload.ID.id())) + event.packet = new CustomPayloadC2SPacket(new BrandCustomPayload(brand.get())); + + if (blockChannels.get()) { + for (String channel : channels.get()) { + if (StringUtils.containsIgnoreCase(id.toString(), channel)) { + event.cancel(); + return; } } } + } - @EventHandler - private void onPacketRecieve(PacketEvent.Receive event) { - if (!isActive()) return; - - if (resourcePack.get()) { - if (!(event.packet instanceof ResourcePackSendS2CPacket packet)) return; - event.cancel(); - MutableText msg = Text.literal("This server has "); - msg.append(packet.required() ? "a required " : "an optional "); - MutableText link = Text.literal("resource pack"); - link.setStyle(link.getStyle() - .withColor(Formatting.BLUE) - .withUnderline(true) - .withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, packet.url())) - .withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Text.literal("Click to download"))) - ); - msg.append(link); - msg.append("."); - info(msg); - } + @EventHandler + private void onPacketReceive(PacketEvent.Receive event) { + if (!isActive()) return; + + if (resourcePack.get()) { + if (!(event.packet instanceof ResourcePackSendS2CPacket packet)) return; + event.cancel(); + + MutableText msg = Text.literal("This server has "); + msg.append(packet.required() ? "a required " : "an optional ").append("resource pack. "); + + MutableText link = Text.literal("[Download]"); + link.setStyle(link.getStyle() + .withColor(Formatting.BLUE) + .withUnderline(true) + .withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, packet.url())) + .withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Text.literal("Click to download"))) + ); + + MutableText acceptance = Text.literal("[Spoof Acceptance]"); + acceptance.setStyle(acceptance.getStyle() + .withColor(Formatting.DARK_GREEN) + .withUnderline(true) + .withClickEvent(new RunnableClickEvent(() -> { + event.connection.send(new ResourcePackStatusC2SPacket(packet.id(), ResourcePackStatusC2SPacket.Status.ACCEPTED)); + event.connection.send(new ResourcePackStatusC2SPacket(packet.id(), ResourcePackStatusC2SPacket.Status.SUCCESSFULLY_LOADED)); + })) + .withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Text.literal("Click to spoof accepting the recourse pack."))) + ); + + msg.append(link).append(" "); + msg.append(acceptance).append("."); + info(msg); } } } diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/movement/Blink.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/movement/Blink.java index ee95718c4a..c23b5f6a7f 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/movement/Blink.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/movement/Blink.java @@ -33,6 +33,7 @@ public class Blink extends Module { .build() ); + @SuppressWarnings("unused") private final Setting cancelBlink = sgGeneral.add(new KeybindSetting.Builder() .name("cancel-blink") .description("Cancels sending packets and sends you back to your original position.") @@ -84,7 +85,7 @@ private void onSendPacket(PacketEvent.Send event) { if (!(event.packet instanceof PlayerMoveC2SPacket p)) return; event.cancel(); - PlayerMoveC2SPacket prev = packets.size() == 0 ? null : packets.get(packets.size() - 1); + PlayerMoveC2SPacket prev = packets.isEmpty() ? null : packets.getLast(); if (prev != null && p.isOnGround() == prev.isOnGround() && diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/movement/ClickTP.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/movement/ClickTP.java index 64fe9dd512..64b555feef 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/movement/ClickTP.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/movement/ClickTP.java @@ -49,7 +49,7 @@ private void onTick(TickEvent.Post event) { BlockPos pos = ((BlockHitResult) hitResult).getBlockPos(); Direction side = ((BlockHitResult) hitResult).getSide(); - if (mc.world.getBlockState(pos).onUse(mc.world, mc.player, Hand.MAIN_HAND, (BlockHitResult) hitResult) != ActionResult.PASS) return; + if (mc.world.getBlockState(pos).onUse(mc.world, mc.player, (BlockHitResult) hitResult) != ActionResult.PASS) return; BlockState state = mc.world.getBlockState(pos); diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/movement/ElytraBoost.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/movement/ElytraBoost.java index 4248fadda2..493e3d0d9b 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/movement/ElytraBoost.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/movement/ElytraBoost.java @@ -13,6 +13,8 @@ import meteordevelopment.meteorclient.utils.Utils; import meteordevelopment.meteorclient.utils.misc.Keybind; import meteordevelopment.orbit.EventHandler; +import net.minecraft.component.DataComponentTypes; +import net.minecraft.component.type.FireworksComponent; import net.minecraft.entity.Entity; import net.minecraft.entity.projectile.FireworkRocketEntity; import net.minecraft.item.FireworkRocketItem; @@ -51,6 +53,7 @@ public class ElytraBoost extends Module { .build() ); + @SuppressWarnings("unused") private final Setting keybind = sgGeneral.add(new KeybindSetting.Builder() .name("keybind") .description("The keybind to boost.") @@ -90,7 +93,7 @@ private void boost() { if (mc.player.isFallFlying() && mc.currentScreen == null) { ItemStack itemStack = Items.FIREWORK_ROCKET.getDefaultStack(); - itemStack.getOrCreateSubNbt("Fireworks").putByte("Flight", fireworkLevel.get().byteValue()); + itemStack.set(DataComponentTypes.FIREWORKS, new FireworksComponent(fireworkLevel.get(), itemStack.get(DataComponentTypes.FIREWORKS).explosions())); FireworkRocketEntity entity = new FireworkRocketEntity(mc.world, itemStack, mc.player); fireworks.add(entity); diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/movement/Flight.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/movement/Flight.java index bd0d1b6599..3706dcddcd 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/movement/Flight.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/movement/Flight.java @@ -50,6 +50,14 @@ public class Flight extends Module { .build() ); + private final Setting noSneak = sgGeneral.add(new BoolSetting.Builder() + .name("no-sneak") + .description("Prevents you from sneaking while flying.") + .defaultValue(false) + .visible(() -> mode.get() == Mode.Velocity) + .build() + ); + private final Setting antiKickMode = sgAntiKick.add(new EnumSetting.Builder() .name("mode") .description("The mode for anti kick.") @@ -148,11 +156,15 @@ private void onPostTick(TickEvent.Post event) { case Velocity -> { mc.player.getAbilities().flying = false; mc.player.setVelocity(0, 0, 0); - Vec3d initialVelocity = mc.player.getVelocity(); + Vec3d playerVelocity = mc.player.getVelocity(); if (mc.options.jumpKey.isPressed()) - mc.player.setVelocity(initialVelocity.add(0, speed.get() * (verticalSpeedMatch.get() ? 10f : 5f), 0)); + playerVelocity = playerVelocity.add(0, speed.get() * (verticalSpeedMatch.get() ? 10f : 5f), 0); if (mc.options.sneakKey.isPressed()) - mc.player.setVelocity(initialVelocity.subtract(0, speed.get() * (verticalSpeedMatch.get() ? 10f : 5f), 0)); + playerVelocity = playerVelocity.subtract(0, speed.get() * (verticalSpeedMatch.get() ? 10f : 5f), 0); + mc.player.setVelocity(playerVelocity); + if (noSneak.get()) { + mc.player.setOnGround(false); + } } case Abilities -> { if (mc.player.isSpectator()) return; @@ -238,6 +250,10 @@ public float getOffGroundSpeed() { return speed.get().floatValue() * (mc.player.isSprinting() ? 15f : 10f); } + public boolean noSneak() { + return isActive() && mode.get() == Mode.Velocity && noSneak.get(); + } + public enum Mode { Abilities, Velocity diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/movement/Jesus.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/movement/Jesus.java index ff0ab134df..a3d6a73ba2 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/movement/Jesus.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/movement/Jesus.java @@ -28,6 +28,7 @@ import net.minecraft.network.packet.Packet; import net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket; import net.minecraft.registry.tag.FluidTags; +import net.minecraft.state.property.Properties; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Box; import net.minecraft.util.math.MathHelper; @@ -149,6 +150,8 @@ public class Jesus extends Module { private boolean prePathManagerWalkOnWater; private boolean prePathManagerWalkOnLava; + public boolean isInBubbleColumn = false; + public Jesus() { super(Categories.Movement, "jesus", "Walk on liquids and powder snow like Jesus."); } @@ -170,6 +173,9 @@ public void onDeactivate() { @EventHandler private void onTick(TickEvent.Post event) { + boolean bubbleColumn = isInBubbleColumn; + isInBubbleColumn = false; + if ((waterMode.get() == Mode.Bob && mc.player.isTouchingWater()) || (lavaMode.get() == Mode.Bob && mc.player.isInLava())) { double fluidHeight; if (mc.player.isInLava()) fluidHeight = mc.player.getFluidHeight(FluidTags.LAVA); @@ -188,8 +194,15 @@ private void onTick(TickEvent.Post event) { } if (mc.player.isTouchingWater() && !waterShouldBeSolid()) return; + if (mc.player.isInSwimmingPose()) return; if (mc.player.isInLava() && !lavaShouldBeSolid()) return; + // Move up in bubble columns + if (bubbleColumn) { + if (mc.options.jumpKey.isPressed() && mc.player.getVelocity().getY() < 0.11) ((IVec3d) mc.player.getVelocity()).setY(0.11); + return; + } + // Move up if (mc.player.isTouchingWater() || mc.player.isInLava()) { ((IVec3d) mc.player.getVelocity()).setY(0.11); @@ -197,15 +210,24 @@ private void onTick(TickEvent.Post event) { return; } + BlockState blockBelowState = mc.world.getBlockState(mc.player.getBlockPos().down()); + boolean waterLogger = false; + try { + waterLogger = blockBelowState.get(Properties.WATERLOGGED); + } catch (Exception ignored) {} + + // Simulate jumping out of water if (tickTimer == 0) ((IVec3d) mc.player.getVelocity()).setY(0.30); - else if (tickTimer == 1) ((IVec3d) mc.player.getVelocity()).setY(0); + else if (tickTimer == 1 && (blockBelowState == Blocks.WATER.getDefaultState() || blockBelowState == Blocks.LAVA.getDefaultState() || waterLogger)) + ((IVec3d) mc.player.getVelocity()).setY(0); tickTimer++; } @EventHandler private void onCanWalkOnFluid(CanWalkOnFluidEvent event) { + if (mc.player != null && mc.player.isInSwimmingPose()) return; if ((event.fluidState.getFluid() == Fluids.WATER || event.fluidState.getFluid() == Fluids.FLOWING_WATER) && waterShouldBeSolid()) { event.walkOnFluid = true; } @@ -218,9 +240,9 @@ else if ((event.fluidState.getFluid() == Fluids.LAVA || event.fluidState.getFlui private void onFluidCollisionShape(CollisionShapeEvent event) { if (event.state.getFluidState().isEmpty()) return; - if ((event.state.getBlock() == Blocks.WATER | event.state.getFluidState().getFluid() == Fluids.WATER) && !mc.player.isTouchingWater() && waterShouldBeSolid()) { + if ((event.state.getBlock() == Blocks.WATER | event.state.getFluidState().getFluid() == Fluids.WATER) && !mc.player.isTouchingWater() && waterShouldBeSolid() && event.pos.getY() <= mc.player.getY() - 1) { event.shape = VoxelShapes.fullCube(); - } else if (event.state.getBlock() == Blocks.LAVA && !mc.player.isInLava() && lavaShouldBeSolid()) { + } else if (event.state.getBlock() == Blocks.LAVA && !mc.player.isInLava() && lavaShouldBeSolid() && (!lavaIsSafe() || event.pos.getY() <= mc.player.getY() - 1)) { event.shape = VoxelShapes.fullCube(); } } diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/movement/Scaffold.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/movement/Scaffold.java index ed77f35ab9..3a9fa6ab3a 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/movement/Scaffold.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/movement/Scaffold.java @@ -133,7 +133,7 @@ public class Scaffold extends Module { .defaultValue(0) .min(0) .max(6) - .visible(() -> airPlace.get()) + .visible(airPlace::get) .build() ); @@ -142,7 +142,7 @@ public class Scaffold extends Module { .description("How many blocks to place in one tick.") .defaultValue(3) .min(1) - .visible(() -> airPlace.get()) + .visible(airPlace::get) .build() ); @@ -229,13 +229,11 @@ private void onTick(TickEvent.Pre event) { } } } - if (blockPosArray.size() == 0) { - return; - } + if (blockPosArray.isEmpty()) return; blockPosArray.sort(Comparator.comparingDouble((blockPos) -> blockPos.getSquaredDistance(targetBlock))); - bp.set(blockPosArray.get(0)); + bp.set(blockPosArray.getFirst()); } if (airPlace.get()) { diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/movement/Step.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/movement/Step.java index 04a9f24bf9..f10f65065f 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/movement/Step.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/movement/Step.java @@ -14,6 +14,7 @@ import meteordevelopment.meteorclient.utils.entity.DamageUtils; import meteordevelopment.orbit.EventHandler; import net.minecraft.entity.Entity; +import net.minecraft.entity.attribute.EntityAttributes; import net.minecraft.entity.decoration.EndCrystalEntity; import java.util.OptionalDouble; @@ -73,16 +74,16 @@ private void onTick(TickEvent.Post event) { boolean work = (activeWhen.get() == ActiveWhen.Always) || (activeWhen.get() == ActiveWhen.Sneaking && mc.player.isSneaking()) || (activeWhen.get() == ActiveWhen.NotSneaking && !mc.player.isSneaking()); mc.player.setBoundingBox(mc.player.getBoundingBox().offset(0, 1, 0)); if (work && (!safeStep.get() || (getHealth() > stepHealth.get() && getHealth() - getExplosionDamage() > stepHealth.get()))){ - mc.player.setStepHeight(height.get().floatValue()); + mc.player.getAttributeInstance(EntityAttributes.GENERIC_STEP_HEIGHT).setBaseValue(height.get()); } else { - mc.player.setStepHeight(prevStepHeight); + mc.player.getAttributeInstance(EntityAttributes.GENERIC_STEP_HEIGHT).setBaseValue(prevStepHeight); } mc.player.setBoundingBox(mc.player.getBoundingBox().offset(0, -1, 0)); } @Override public void onDeactivate() { - mc.player.setStepHeight(prevStepHeight); + mc.player.getAttributeInstance(EntityAttributes.GENERIC_STEP_HEIGHT).setBaseValue(prevStepHeight); PathManagers.get().getSettings().getStep().set(prevPathManagerStep); } diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/movement/Velocity.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/movement/Velocity.java index 1687e6ca20..f10a263548 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/movement/Velocity.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/movement/Velocity.java @@ -150,7 +150,7 @@ private void onTick(TickEvent.Post event) { @EventHandler private void onPacketReceive(PacketEvent.Receive event) { if (knockback.get() && event.packet instanceof EntityVelocityUpdateS2CPacket packet - && ((EntityVelocityUpdateS2CPacket) event.packet).getId() == mc.player.getId()) { + && packet.getId() == mc.player.getId()) { double velX = (packet.getVelocityX() / 8000d - mc.player.getVelocity().x) * knockbackHorizontal.get(); double velY = (packet.getVelocityY() / 8000d - mc.player.getVelocity().y) * knockbackVertical.get(); double velZ = (packet.getVelocityZ() / 8000d - mc.player.getVelocity().z) * knockbackHorizontal.get(); diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/movement/elytrafly/ElytraFly.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/movement/elytrafly/ElytraFly.java index 35f20b7a5e..0fccaba54e 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/movement/elytrafly/ElytraFly.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/movement/elytrafly/ElytraFly.java @@ -24,6 +24,7 @@ import meteordevelopment.orbit.EventHandler; import net.minecraft.block.Block; import net.minecraft.block.BlockState; +import net.minecraft.component.DataComponentTypes; import net.minecraft.entity.EquipmentSlot; import net.minecraft.item.ElytraItem; import net.minecraft.item.Items; @@ -264,8 +265,8 @@ public class ElytraFly extends Module { .name("replace-durability") .description("The durability threshold your elytra will be replaced at.") .defaultValue(2) - .range(1, Items.ELYTRA.getMaxDamage() - 1) - .sliderRange(1, Items.ELYTRA.getMaxDamage() - 1) + .range(1, Items.ELYTRA.getComponents().get(DataComponentTypes.MAX_DAMAGE) - 1) + .sliderRange(1, Items.ELYTRA.getComponents().get(DataComponentTypes.MAX_DAMAGE) - 1) .visible(replace::get) .build() ); diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/movement/elytrafly/modes/Bounce.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/movement/elytrafly/modes/Bounce.java index deceb1f5a5..380ba802fd 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/movement/elytrafly/modes/Bounce.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/movement/elytrafly/modes/Bounce.java @@ -12,7 +12,6 @@ import meteordevelopment.meteorclient.events.packets.PacketEvent; import meteordevelopment.meteorclient.systems.modules.movement.elytrafly.ElytraFlightMode; import meteordevelopment.meteorclient.systems.modules.movement.elytrafly.ElytraFlightModes; -import meteordevelopment.meteorclient.systems.modules.player.Rotation; import meteordevelopment.meteorclient.utils.misc.input.Input; import net.minecraft.client.network.ClientPlayerEntity; import net.minecraft.client.option.KeyBinding; diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/player/AutoEat.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/player/AutoEat.java index 307854c048..d41edba613 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/player/AutoEat.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/player/AutoEat.java @@ -21,6 +21,8 @@ import meteordevelopment.meteorclient.utils.player.SlotUtils; import meteordevelopment.orbit.EventHandler; import meteordevelopment.orbit.EventPriority; +import net.minecraft.component.DataComponentTypes; +import net.minecraft.component.type.FoodComponent; import net.minecraft.item.Item; import net.minecraft.item.Items; @@ -29,7 +31,7 @@ import java.util.function.BiPredicate; public class AutoEat extends Module { - private static final Class[] AURAS = new Class[] { KillAura.class, CrystalAura.class, AnchorAura.class, BedAura.class }; + private static final Class[] AURAS = new Class[]{KillAura.class, CrystalAura.class, AnchorAura.class, BedAura.class}; private final SettingGroup sgGeneral = settings.getDefaultGroup(); private final SettingGroup sgThreshold = settings.createGroup("Threshold"); @@ -50,7 +52,7 @@ public class AutoEat extends Module { Items.SPIDER_EYE, Items.SUSPICIOUS_STEW ) - .filter(Item::isFood) + .filter(item -> item.getComponents().get(DataComponentTypes.FOOD) != null) .build() ); @@ -118,10 +120,10 @@ private void onTick(TickEvent.Pre event) { if (Modules.get().get(AutoGap.class).isEating()) return; if (eating) { - // If we are eating check if we should still be still eating + // If we are eating check if we should still be eating if (shouldEat()) { // Check if the item in current slot is not food - if (!mc.player.getInventory().getStack(slot).isFood()) { + if (mc.player.getInventory().getStack(slot).get(DataComponentTypes.FOOD) != null) { // If not try finding a new slot int slot = findSlot(); @@ -143,8 +145,7 @@ private void onTick(TickEvent.Pre event) { else { stopEating(); } - } - else { + } else { // If we are not eating check if we should start eating if (shouldEat()) { // Try to find a valid slot @@ -240,10 +241,11 @@ private int findSlot() { for (int i = 0; i < 9; i++) { // Skip if item isn't food Item item = mc.player.getInventory().getStack(i).getItem(); - if (!item.isFood()) continue; + FoodComponent foodComponent = item.getComponents().get(DataComponentTypes.FOOD); + if (foodComponent == null) continue; // Check if hunger value is better - int hunger = item.getFoodComponent().getHunger(); + int hunger = foodComponent.nutrition(); if (hunger > bestHunger) { // Skip if item is in blacklist if (blacklist.get().contains(item)) continue; @@ -255,7 +257,8 @@ private int findSlot() { } Item offHandItem = mc.player.getOffHandStack().getItem(); - if (offHandItem.isFood() && !blacklist.get().contains(offHandItem) && offHandItem.getFoodComponent().getHunger() > bestHunger) slot = SlotUtils.OFFHAND; + if (offHandItem.getComponents().get(DataComponentTypes.FOOD) != null && !blacklist.get().contains(offHandItem) && offHandItem.getComponents().get(DataComponentTypes.FOOD).nutrition() > bestHunger) + slot = SlotUtils.OFFHAND; return slot; } diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/player/AutoGap.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/player/AutoGap.java index 5ce30960c1..053e933072 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/player/AutoGap.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/player/AutoGap.java @@ -28,6 +28,7 @@ import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; +import net.minecraft.registry.entry.RegistryEntry; import java.util.ArrayList; import java.util.List; @@ -250,7 +251,7 @@ private boolean shouldEat() { } private boolean shouldEatPotions() { - Map effects = mc.player.getActiveStatusEffects(); + Map, StatusEffectInstance> effects = mc.player.getActiveStatusEffects(); // Regeneration if (potionsRegeneration.get() && !effects.containsKey(StatusEffects.REGENERATION)) return true; diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/player/AutoMend.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/player/AutoMend.java index ed2fa04905..243e67a35a 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/player/AutoMend.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/player/AutoMend.java @@ -14,6 +14,7 @@ import meteordevelopment.meteorclient.systems.modules.Module; import meteordevelopment.meteorclient.utils.player.InvUtils; import meteordevelopment.orbit.EventHandler; +import net.minecraft.component.DataComponentTypes; import net.minecraft.enchantment.EnchantmentHelper; import net.minecraft.enchantment.Enchantments; import net.minecraft.item.Item; @@ -27,7 +28,7 @@ public class AutoMend extends Module { private final Setting> blacklist = sgGeneral.add(new ItemListSetting.Builder() .name("blacklist") .description("Item blacklist.") - .filter(Item::isDamageable) + .filter(item -> item.getComponents().get(DataComponentTypes.DAMAGE) != null) .build() ); @@ -73,8 +74,7 @@ private void onTick(TickEvent.Pre event) { toggle(); } - } - else { + } else { InvUtils.move().from(slot).toOffhand(); didMove = true; } diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/player/AutoReplenish.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/player/AutoReplenish.java index a96403e2f7..943b60ed80 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/player/AutoReplenish.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/player/AutoReplenish.java @@ -147,7 +147,7 @@ private int findItem(ItemStack itemStack, int excludedSlot, int goodEnoughCount) for (int i = mc.player.getInventory().size() - 2; i >= (searchHotbar.get() ? 0 : 9); i--) { ItemStack stack = mc.player.getInventory().getStack(i); - if (i != excludedSlot && stack.getItem() == itemStack.getItem() && ItemStack.canCombine(itemStack, stack)) { + if (i != excludedSlot && stack.getItem() == itemStack.getItem() && ItemStack.areItemsAndComponentsEqual(itemStack, stack)) { if (stack.getCount() > count) { slot = i; count = stack.getCount(); @@ -184,7 +184,7 @@ private void setItem(int slot, ItemStack stack) { ItemStack s = items[slot]; ((ItemStackAccessor) (Object) s).setItem(stack.getItem()); s.setCount(stack.getCount()); - s.setNbt(stack.getNbt()); + s.applyComponentsFrom(stack.getComponents()); if (stack.isEmpty()) ((ItemStackAccessor) (Object) s).setItem(Items.AIR); } } diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/player/AutoTool.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/player/AutoTool.java index b9b9b08b12..a292ca9ccf 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/player/AutoTool.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/player/AutoTool.java @@ -19,9 +19,11 @@ import meteordevelopment.orbit.EventHandler; import meteordevelopment.orbit.EventPriority; import net.minecraft.block.*; +import net.minecraft.component.DataComponentTypes; import net.minecraft.enchantment.EnchantmentHelper; import net.minecraft.enchantment.Enchantments; import net.minecraft.item.*; +import net.minecraft.registry.tag.BlockTags; import java.util.List; import java.util.function.Predicate; @@ -189,7 +191,7 @@ private boolean shouldStopUsing(ItemStack itemStack) { public static double getScore(ItemStack itemStack, BlockState state, boolean silkTouchEnderChest, boolean fortuneOre, EnchantPreference enchantPreference, Predicate good) { if (!good.test(itemStack) || !isTool(itemStack)) return -1; - if (!itemStack.isSuitableFor(state) && !(itemStack.getItem() instanceof SwordItem && (state.getBlock() instanceof BambooBlock || state.getBlock() instanceof BambooShootBlock))) return -1; + if (!itemStack.isSuitableFor(state) && !(itemStack.getItem() instanceof SwordItem && (state.getBlock() instanceof BambooBlock || state.getBlock() instanceof BambooShootBlock)) && !(itemStack.getItem() instanceof ShearsItem && state.getBlock() instanceof LeavesBlock || state.isIn(BlockTags.WOOL))) return -1; if (silkTouchEnderChest && state.getBlock() == Blocks.ENDER_CHEST @@ -214,8 +216,7 @@ && isFortunable(state.getBlock()) if (enchantPreference == EnchantPreference.SilkTouch) score += EnchantmentHelper.getLevel(Enchantments.SILK_TOUCH, itemStack); if (itemStack.getItem() instanceof SwordItem item && (state.getBlock() instanceof BambooBlock || state.getBlock() instanceof BambooShootBlock)) - score += 9000 + (item.getMaterial().getMiningLevel() * 1000); - + score += 9000 + (item.getComponents().get(DataComponentTypes.TOOL).getSpeed(state) * 1000); return score; } @@ -227,6 +228,7 @@ public static boolean isTool(ItemStack itemStack) { return isTool(itemStack.getItem()); } + private static boolean isFortunable(Block block) { if (block == Blocks.ANCIENT_DEBRIS) return false; return Xray.ORES.contains(block) || block instanceof CropBlock; diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/player/GhostHand.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/player/GhostHand.java index 7c3afe395e..1e9f5a7a42 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/player/GhostHand.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/player/GhostHand.java @@ -29,7 +29,7 @@ public GhostHand() { private void onTick(TickEvent.Pre event) { if (!mc.options.useKey.isPressed() || mc.player.isSneaking()) return; - if (mc.world.getBlockState(BlockPos.ofFloored(mc.player.raycast(mc.interactionManager.getReachDistance(), mc.getTickDelta(), false).getPos())).hasBlockEntity()) return; + if (mc.world.getBlockState(BlockPos.ofFloored(mc.player.raycast(mc.player.getBlockInteractionRange(), mc.getTickDelta(), false).getPos())).hasBlockEntity()) return; Vec3d direction = new Vec3d(0, 0, 0.1) .rotateX(-(float) Math.toRadians(mc.player.getPitch())) @@ -37,7 +37,7 @@ private void onTick(TickEvent.Pre event) { posList.clear(); - for (int i = 1; i < mc.interactionManager.getReachDistance() * 10; i++) { + for (int i = 1; i < mc.player.getBlockInteractionRange() * 10; i++) { BlockPos pos = BlockPos.ofFloored(mc.player.getCameraPosVec(mc.getTickDelta()).add(direction.multiply(i))); if (posList.contains(pos)) continue; diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/player/InstaMine.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/player/InstaMine.java new file mode 100644 index 0000000000..71efa7ea0f --- /dev/null +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/player/InstaMine.java @@ -0,0 +1,135 @@ +/* + * This file is part of the Meteor Client distribution (https://github.com/MeteorDevelopment/meteor-client). + * Copyright (c) Meteor Development. + */ + +package meteordevelopment.meteorclient.systems.modules.player; + +import meteordevelopment.meteorclient.events.entity.player.StartBreakingBlockEvent; +import meteordevelopment.meteorclient.events.render.Render3DEvent; +import meteordevelopment.meteorclient.events.world.TickEvent; +import meteordevelopment.meteorclient.renderer.ShapeMode; +import meteordevelopment.meteorclient.settings.*; +import meteordevelopment.meteorclient.systems.modules.Categories; +import meteordevelopment.meteorclient.systems.modules.Module; +import meteordevelopment.meteorclient.utils.player.Rotations; +import meteordevelopment.meteorclient.utils.render.color.SettingColor; +import meteordevelopment.meteorclient.utils.world.BlockUtils; +import meteordevelopment.orbit.EventHandler; +import net.minecraft.item.PickaxeItem; +import net.minecraft.network.packet.c2s.play.HandSwingC2SPacket; +import net.minecraft.network.packet.c2s.play.PlayerActionC2SPacket; +import net.minecraft.util.Hand; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Direction; + +public class InstaMine extends Module { + private final SettingGroup sgGeneral = settings.getDefaultGroup(); + private final SettingGroup sgRender = settings.createGroup("Render"); + + private final Setting tickDelay = sgGeneral.add(new IntSetting.Builder() + .name("delay") + .description("The delay between break attempts.") + .defaultValue(0) + .min(0) + .sliderMax(20) + .build() + ); + + private final Setting pick = sgGeneral.add(new BoolSetting.Builder() + .name("only-pick") + .description("Only tries to mine the block if you are holding a pickaxe.") + .defaultValue(true) + .build() + ); + + private final Setting rotate = sgGeneral.add(new BoolSetting.Builder() + .name("rotate") + .description("Faces the block being mined server side.") + .defaultValue(true) + .build() + ); + + // Render + + private final Setting render = sgRender.add(new BoolSetting.Builder() + .name("render") + .description("Renders an overlay on the block being broken.") + .defaultValue(true) + .build() + ); + + private final Setting shapeMode = sgRender.add(new EnumSetting.Builder() + .name("shape-mode") + .description("How the shapes are rendered.") + .defaultValue(ShapeMode.Both) + .build() + ); + + private final Setting sideColor = sgRender.add(new ColorSetting.Builder() + .name("side-color") + .description("The color of the sides of the blocks being rendered.") + .defaultValue(new SettingColor(204, 0, 0, 10)) + .build() + ); + + private final Setting lineColor = sgRender.add(new ColorSetting.Builder() + .name("line-color") + .description("The color of the lines of the blocks being rendered.") + .defaultValue(new SettingColor(204, 0, 0, 255)) + .build() + ); + + public final BlockPos.Mutable blockPos = new BlockPos.Mutable(0, Integer.MIN_VALUE, 0); + private int ticks; + private Direction direction; + + public InstaMine() { + super(Categories.Player, "insta-mine", "Instantly re-breaks blocks in the same position."); + } + + @Override + public void onActivate() { + ticks = 0; + blockPos.set(0, -1, 0); + } + + @EventHandler + private void onStartBreakingBlock(StartBreakingBlockEvent event) { + direction = event.direction; + blockPos.set(event.blockPos); + } + + @EventHandler + private void onTick(TickEvent.Pre event) { + if (ticks >= tickDelay.get()) { + ticks = 0; + + if (shouldMine()) { + if (rotate.get()) Rotations.rotate(Rotations.getYaw(blockPos), Rotations.getPitch(blockPos), this::sendPacket); + else sendPacket(); + + mc.getNetworkHandler().sendPacket(new HandSwingC2SPacket(Hand.MAIN_HAND)); + } + } else { + ticks++; + } + } + + public void sendPacket() { + mc.getNetworkHandler().sendPacket(new PlayerActionC2SPacket(PlayerActionC2SPacket.Action.STOP_DESTROY_BLOCK, blockPos, direction)); + } + + public boolean shouldMine() { + if (mc.world.isOutOfHeightLimit(blockPos) || !BlockUtils.canBreak(blockPos)) return false; + + return !pick.get() || mc.player.getMainHandStack().getItem() instanceof PickaxeItem; + } + + @EventHandler + private void onRender(Render3DEvent event) { + if (!render.get() || !shouldMine()) return; + + event.renderer.box(blockPos, sideColor.get(), lineColor.get(), shapeMode.get(), 0); + } +} diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/player/PotionSaver.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/player/PotionSaver.java index d833f12131..44e2079955 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/player/PotionSaver.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/player/PotionSaver.java @@ -25,20 +25,20 @@ public class PotionSaver extends Module { .name("effects") .description("The effects to preserve.") .defaultValue( - STRENGTH, - ABSORPTION, - RESISTANCE, - FIRE_RESISTANCE, - SPEED, - HASTE, - REGENERATION, - WATER_BREATHING, - SATURATION, - LUCK, - SLOW_FALLING, - DOLPHINS_GRACE, - CONDUIT_POWER, - HERO_OF_THE_VILLAGE + STRENGTH.value(), + ABSORPTION.value(), + RESISTANCE.value(), + FIRE_RESISTANCE.value(), + SPEED.value(), + HASTE.value(), + REGENERATION.value(), + WATER_BREATHING.value(), + SATURATION.value(), + LUCK.value(), + SLOW_FALLING.value(), + DOLPHINS_GRACE.value(), + CONDUIT_POWER.value(), + HERO_OF_THE_VILLAGE.value() ) .build() ); diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/player/PotionSpoof.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/player/PotionSpoof.java index 24af8ac2b4..a24a3271e5 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/player/PotionSpoof.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/player/PotionSpoof.java @@ -5,7 +5,7 @@ package meteordevelopment.meteorclient.systems.modules.player; -import it.unimi.dsi.fastutil.objects.Object2IntMap; +import it.unimi.dsi.fastutil.objects.Reference2IntMap; import meteordevelopment.meteorclient.events.world.TickEvent; import meteordevelopment.meteorclient.mixin.StatusEffectInstanceAccessor; import meteordevelopment.meteorclient.settings.*; @@ -15,6 +15,7 @@ import meteordevelopment.orbit.EventHandler; import net.minecraft.entity.effect.StatusEffect; import net.minecraft.entity.effect.StatusEffectInstance; +import net.minecraft.registry.Registries; import java.util.List; @@ -23,7 +24,7 @@ public class PotionSpoof extends Module { private final SettingGroup sgGeneral = settings.getDefaultGroup(); - private final Setting> spoofPotions = sgGeneral.add(new StatusEffectAmplifierMapSetting.Builder() + private final Setting> spoofPotions = sgGeneral.add(new StatusEffectAmplifierMapSetting.Builder() .name("spoofed-potions") .description("Potions to add.") .defaultValue(Utils.createStatusEffectMap()) @@ -41,21 +42,14 @@ public class PotionSpoof extends Module { .name("blocked-potions") .description("Potions to block.") .defaultValue( - LEVITATION, - JUMP_BOOST, - SLOW_FALLING, - DOLPHINS_GRACE + LEVITATION.value(), + JUMP_BOOST.value(), + SLOW_FALLING.value(), + DOLPHINS_GRACE.value() ) .build() ); - public final Setting applyGravity = sgGeneral.add(new BoolSetting.Builder() - .name("gravity") - .description("Applies gravity when levitating.") - .defaultValue(false) - .build() - ); - public PotionSpoof() { super(Categories.Player, "potion-spoof", "Spoofs potion statuses for you. SOME effects DO NOT work."); } @@ -64,24 +58,24 @@ public PotionSpoof() { public void onDeactivate() { if (!clearEffects.get() || !Utils.canUpdate()) return; - for (StatusEffect effect : spoofPotions.get().keySet()) { - if (spoofPotions.get().getInt(effect) <= 0) continue; - if (mc.player.hasStatusEffect(effect)) mc.player.removeStatusEffect(effect); + for (Reference2IntMap.Entry entry : spoofPotions.get().reference2IntEntrySet()) { + if (entry.getIntValue() <= 0) continue; + if (mc.player.hasStatusEffect(Registries.STATUS_EFFECT.getEntry(entry.getKey()))) mc.player.removeStatusEffect(Registries.STATUS_EFFECT.getEntry(entry.getKey())); } } @EventHandler private void onTick(TickEvent.Post event) { - for (StatusEffect statusEffect : spoofPotions.get().keySet()) { - int level = spoofPotions.get().getInt(statusEffect); + for (Reference2IntMap.Entry entry : spoofPotions.get().reference2IntEntrySet()) { + int level = entry.getIntValue(); if (level <= 0) continue; - if (mc.player.hasStatusEffect(statusEffect)) { - StatusEffectInstance instance = mc.player.getStatusEffect(statusEffect); + if (mc.player.hasStatusEffect(Registries.STATUS_EFFECT.getEntry(entry.getKey()))) { + StatusEffectInstance instance = mc.player.getStatusEffect(Registries.STATUS_EFFECT.getEntry(entry.getKey())); ((StatusEffectInstanceAccessor) instance).setAmplifier(level - 1); if (instance.getDuration() < 20) ((StatusEffectInstanceAccessor) instance).setDuration(20); } else { - mc.player.addStatusEffect(new StatusEffectInstance(statusEffect, 20, level - 1)); + mc.player.addStatusEffect(new StatusEffectInstance(Registries.STATUS_EFFECT.getEntry(entry.getKey()), 20, level - 1)); } } } diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/player/Reach.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/player/Reach.java index c280f6b58a..b85f72935a 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/player/Reach.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/player/Reach.java @@ -10,6 +10,7 @@ import meteordevelopment.meteorclient.settings.SettingGroup; import meteordevelopment.meteorclient.systems.modules.Categories; import meteordevelopment.meteorclient.systems.modules.Module; +import net.minecraft.entity.attribute.EntityAttributes; public class Reach extends Module { private final SettingGroup sgGeneral = settings.getDefaultGroup(); @@ -36,13 +37,13 @@ public Reach() { super(Categories.Player, "reach", "Gives you super long arms."); } - public float blockReach() { - if (!isActive()) return mc.interactionManager.getCurrentGameMode().isCreative() ? 5.0F : 4.5F; + public double blockReach() { + if (!isActive()) return mc.player.getAttributeValue(EntityAttributes.PLAYER_BLOCK_INTERACTION_RANGE); return blockReach.get().floatValue(); } - public float entityReach() { - if (!isActive()) return 3; + public double entityReach() { + if (!isActive()) return mc.player.getAttributeValue(EntityAttributes.PLAYER_ENTITY_INTERACTION_RANGE); return entityReach.get().floatValue(); } } diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/render/BetterTab.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/render/BetterTab.java index c48e8da88e..e0aa93a3d8 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/render/BetterTab.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/render/BetterTab.java @@ -3,7 +3,7 @@ * Copyright (c) Meteor Development. */ -package meteordevelopment.meteorclient.systems.modules.misc; +package meteordevelopment.meteorclient.systems.modules.render; import meteordevelopment.meteorclient.settings.*; import meteordevelopment.meteorclient.systems.config.Config; diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/render/BetterTooltips.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/render/BetterTooltips.java index dd22f2b97f..48fca09f5e 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/render/BetterTooltips.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/render/BetterTooltips.java @@ -23,24 +23,23 @@ import meteordevelopment.meteorclient.utils.render.color.Color; import meteordevelopment.meteorclient.utils.tooltip.*; import meteordevelopment.orbit.EventHandler; -import net.minecraft.block.entity.BannerPattern; -import net.minecraft.block.entity.BannerPatterns; +import net.minecraft.component.ComponentMap; +import net.minecraft.component.DataComponentTypes; +import net.minecraft.component.type.*; +import net.minecraft.component.type.BannerPatternsComponent.Layer; +import net.minecraft.component.type.SuspiciousStewEffectsComponent.StewEffect; import net.minecraft.entity.Bucketable; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityType; -import net.minecraft.entity.effect.StatusEffect; import net.minecraft.entity.effect.StatusEffectInstance; import net.minecraft.entity.effect.StatusEffectUtil; import net.minecraft.inventory.Inventories; import net.minecraft.item.*; -import net.minecraft.nbt.NbtCompound; -import net.minecraft.nbt.NbtElement; import net.minecraft.nbt.NbtList; -import net.minecraft.registry.Registries; -import net.minecraft.registry.entry.RegistryEntry; +import net.minecraft.registry.DynamicRegistryManager; import net.minecraft.text.MutableText; +import net.minecraft.text.RawFilteredPair; import net.minecraft.text.Text; -import net.minecraft.util.DyeColor; import net.minecraft.util.Formatting; import net.minecraft.util.collection.DefaultedList; @@ -217,6 +216,13 @@ public class BetterTooltips extends Module { .build() ); + private final Setting upgrades = sgHideFlags.add(new BoolSetting.Builder() + .name("armor-trim") + .description("Show armor trims when it's hidden.") + .defaultValue(false) + .build() + ); + public BetterTooltips() { super(Categories.Render, "better-tooltips", "Displays more useful tooltips for certain items."); } @@ -226,34 +232,17 @@ private void appendTooltip(ItemStackTooltipEvent event) { // Status effects if (statusEffects.get()) { if (event.itemStack.getItem() == Items.SUSPICIOUS_STEW) { - NbtCompound tag = event.itemStack.getNbt(); - - if (tag != null) { - NbtList effects = tag.getList("effects", 10); - - if (effects != null) { - for (int i = 0; i < effects.size(); i++) { - NbtCompound effectTag = effects.getCompound(i); - byte effectId = effectTag.getByte("EffectId"); - int effectDuration = effectTag.contains("EffectDuration") ? effectTag.getInt("EffectDuration") : 160; - StatusEffect type = Registries.STATUS_EFFECT.get(effectId); - - if (type != null) { - StatusEffectInstance effect = new StatusEffectInstance(type, effectDuration, 0); - event.list.add(1, getStatusText(effect)); - } - } + SuspiciousStewEffectsComponent stewEffectsComponent = event.itemStack.get(DataComponentTypes.SUSPICIOUS_STEW_EFFECTS); + if (stewEffectsComponent != null) { + for (StewEffect effectTag : stewEffectsComponent.effects()) { + StatusEffectInstance effect = new StatusEffectInstance(effectTag.effect(), effectTag.duration(), 0); + event.list.add(1, getStatusText(effect)); } } - } - else if (event.itemStack.getItem().isFood()) { - FoodComponent food = event.itemStack.getItem().getFoodComponent(); - + } else { + FoodComponent food = event.itemStack.get(DataComponentTypes.FOOD); if (food != null) { - food.getStatusEffects().forEach((e) -> { - StatusEffectInstance effect = e.getFirst(); - event.list.add(1, getStatusText(effect)); - }); + food.effects().forEach(e -> event.list.add(1, getStatusText(e.effect()))); } } } @@ -261,20 +250,17 @@ else if (event.itemStack.getItem().isFood()) { //Beehive if (beehive.get()) { if (event.itemStack.getItem() == Items.BEEHIVE || event.itemStack.getItem() == Items.BEE_NEST) { - NbtCompound tag = event.itemStack.getNbt(); - - if (tag != null) { - NbtCompound blockStateTag = tag.getCompound("BlockStateTag"); - if (blockStateTag != null) { - int level = blockStateTag.getInt("honey_level"); - event.list.add(1, Text.literal(String.format("%sHoney level: %s%d%s.", Formatting.GRAY, Formatting.YELLOW, level, Formatting.GRAY))); - } + ComponentMap components = event.itemStack.getComponents(); + BlockStateComponent blockStateComponent = components.get(DataComponentTypes.BLOCK_STATE); + if (blockStateComponent != null) { + String level = blockStateComponent.properties().get("honey_level"); + event.list.add(1, Text.literal(String.format("%sHoney level: %s%s%s.", Formatting.GRAY, Formatting.YELLOW, level, Formatting.GRAY))); + } - NbtCompound blockEntityTag = tag.getCompound("BlockEntityTag"); - if (blockEntityTag != null) { - NbtList beesTag = blockEntityTag.getList("Bees", 10); - event.list.add(1, Text.literal(String.format("%sBees: %s%d%s.", Formatting.GRAY, Formatting.YELLOW, beesTag.size(), Formatting.GRAY))); - } + NbtComponent nbtComponent = components.get(DataComponentTypes.BLOCK_ENTITY_DATA); + if (nbtComponent != null) { + NbtList beesTag = nbtComponent.copyNbt().getList("Bees", 10); + event.list.add(1, Text.literal(String.format("%sBees: %s%d%s.", Formatting.GRAY, Formatting.YELLOW, beesTag.size(), Formatting.GRAY))); } } } @@ -282,7 +268,7 @@ else if (event.itemStack.getItem().isFood()) { // Item size tooltip if (byteSize.get()) { try { - event.itemStack.writeNbt(new NbtCompound()).write(ByteCountDataOutput.INSTANCE); + event.itemStack.encode(mc.player.getRegistryManager()).write(ByteCountDataOutput.INSTANCE); int byteCount = ByteCountDataOutput.INSTANCE.getCount(); String count; @@ -306,7 +292,7 @@ else if (event.itemStack.getItem().isFood()) { || (event.itemStack.getItem() == Items.WRITTEN_BOOK && books.get() && !previewBooks()) || (event.itemStack.getItem() instanceof EntityBucketItem && entitiesInBuckets.get() && !previewEntities()) || (event.itemStack.getItem() instanceof BannerItem && banners.get() && !previewBanners()) - || (event.itemStack.getItem() instanceof BannerPatternItem && banners.get() && !previewBanners()) + || (event.itemStack.getItem() instanceof BannerPatternItem && banners.get() && !previewBanners()) || (event.itemStack.getItem() == Items.SHIELD && banners.get() && !previewBanners())) { event.list.add(Text.literal("")); event.list.add(Text.literal("Hold " + Formatting.YELLOW + keybind + Formatting.RESET + " to preview")); @@ -317,22 +303,25 @@ else if (event.itemStack.getItem().isFood()) { private void getTooltipData(TooltipDataEvent event) { // Container preview if (previewShulkers() && Utils.hasItems(event.itemStack)) { - NbtCompound compoundTag = event.itemStack.getSubNbt("BlockEntityTag"); - DefaultedList itemStacks = DefaultedList.ofSize(27, ItemStack.EMPTY); - Inventories.readNbt(compoundTag, itemStacks); - event.tooltipData = new ContainerTooltipComponent(itemStacks, Utils.getShulkerColor(event.itemStack)); + NbtComponent nbtComponent = event.itemStack.get(DataComponentTypes.BLOCK_ENTITY_DATA); + if (nbtComponent != null) { + DefaultedList itemStacks = DefaultedList.ofSize(27, ItemStack.EMPTY); + Inventories.readNbt(nbtComponent.copyNbt(), itemStacks, DynamicRegistryManager.EMPTY); + event.tooltipData = new ContainerTooltipComponent(itemStacks, Utils.getShulkerColor(event.itemStack)); + } } // EChest preview else if (event.itemStack.getItem() == Items.ENDER_CHEST && previewEChest()) { - event.tooltipData = EChestMemory.isKnown() ? new ContainerTooltipComponent(EChestMemory.ITEMS, ECHEST_COLOR) + event.tooltipData = EChestMemory.isKnown() + ? new ContainerTooltipComponent(EChestMemory.ITEMS, ECHEST_COLOR) : new TextTooltipComponent(Text.literal("Unknown ender chest inventory.").formatted(Formatting.DARK_RED)); } // Map preview else if (event.itemStack.getItem() == Items.FILLED_MAP && previewMaps()) { - Integer mapId = FilledMapItem.getMapId(event.itemStack); - if (mapId != null) event.tooltipData = new MapTooltipComponent(mapId); + MapIdComponent mapIdComponent = event.itemStack.get(DataComponentTypes.MAP_ID); + if (mapIdComponent != null) event.tooltipData = new MapTooltipComponent(mapIdComponent.id()); } // Book preview @@ -344,14 +333,12 @@ else if ((event.itemStack.getItem() == Items.WRITABLE_BOOK || event.itemStack.ge // Banner preview else if (event.itemStack.getItem() instanceof BannerItem && previewBanners()) { event.tooltipData = new BannerTooltipComponent(event.itemStack); - } - else if (event.itemStack.getItem() instanceof BannerPatternItem patternItem && previewBanners()) { - boolean present = Registries.BANNER_PATTERN.getEntryList(patternItem.getPattern()).isPresent() && Registries.BANNER_PATTERN.getEntryList(patternItem.getPattern()).get().size() != 0; - - RegistryEntry bannerPattern = (present ? Registries.BANNER_PATTERN.getEntryList(patternItem.getPattern()).get().get(0) : null); - if (bannerPattern != null) event.tooltipData = new BannerTooltipComponent(createBannerFromPattern(bannerPattern)); - } - else if (event.itemStack.getItem() == Items.SHIELD && previewBanners()) { + } else if (event.itemStack.getItem() instanceof BannerPatternItem patternItem && previewBanners()) { + BannerPatternsComponent bannerPatternsComponent = event.itemStack.get(DataComponentTypes.BANNER_PATTERNS); + if (bannerPatternsComponent != null) { + event.tooltipData = new BannerTooltipComponent(createBannerFromLayers(bannerPatternsComponent.layers())); + } + } else if (event.itemStack.getItem() == Items.SHIELD && previewBanners()) { ItemStack banner = createBannerFromShield(event.itemStack); if (banner != null) event.tooltipData = new BannerTooltipComponent(banner); } @@ -361,7 +348,7 @@ else if (event.itemStack.getItem() instanceof EntityBucketItem bucketItem && pre EntityType type = ((EntityBucketItemAccessor) bucketItem).getEntityType(); Entity entity = type.create(mc.world); if (entity != null) { - ((Bucketable) entity).copyDataFromNbt(event.itemStack.getOrCreateNbt()); + ((Bucketable) entity).copyDataFromNbt(event.itemStack.get(DataComponentTypes.BUCKET_ENTITY_DATA).copyNbt()); ((EntityAccessor) entity).setInWater(true); event.tooltipData = new EntityTooltipComponent(entity); } @@ -370,27 +357,29 @@ else if (event.itemStack.getItem() instanceof EntityBucketItem bucketItem && pre @EventHandler private void onSectionVisible(SectionVisibleEvent event) { - if (enchantments.get() && event.section == ItemStack.TooltipSection.ENCHANTMENTS || - modifiers.get() && event.section == ItemStack.TooltipSection.MODIFIERS || - unbreakable.get() && event.section == ItemStack.TooltipSection.UNBREAKABLE || - canDestroy.get() && event.section == ItemStack.TooltipSection.CAN_DESTROY || - canPlaceOn.get() && event.section == ItemStack.TooltipSection.CAN_PLACE || - additional.get() && event.section == ItemStack.TooltipSection.ADDITIONAL || - dye.get() && event.section == ItemStack.TooltipSection.DYE) + // todo investigate how section visibility works now + if (enchantments.get() && event.section == DataComponentTypes.STORED_ENCHANTMENTS || + modifiers.get() && event.section == DataComponentTypes.ATTRIBUTE_MODIFIERS || + unbreakable.get() && event.section == DataComponentTypes.UNBREAKABLE || + canDestroy.get() && event.section == DataComponentTypes.CAN_BREAK || + canPlaceOn.get() && event.section == DataComponentTypes.CAN_PLACE_ON || + //additional.get() && event.section == ItemStack.TooltipSection.ADDITIONAL || + dye.get() && event.section == DataComponentTypes.DYED_COLOR || + upgrades.get() && event.section == DataComponentTypes.TRIM) event.visible = true; } - public void applyCompactShulkerTooltip(ItemStack stack, List tooltip) { - NbtCompound tag = stack.getSubNbt("BlockEntityTag"); + public void applyCompactShulkerTooltip(ItemStack shulkerItem, List tooltip) { + NbtComponent nbtComponent = shulkerItem.get(DataComponentTypes.BLOCK_ENTITY_DATA); - if (tag != null) { - if (tag.contains("LootTable", 8)) { + if (nbtComponent != null) { + if (nbtComponent.contains("LootTable")) { tooltip.add(Text.literal("???????")); } - if (tag.contains("Items", 9)) { + if (nbtComponent.contains("Items")) { DefaultedList items = DefaultedList.ofSize(27, ItemStack.EMPTY); - Inventories.readNbt(tag, items); + Inventories.readNbt(nbtComponent.copyNbt(), items, DynamicRegistryManager.EMPTY); Object2IntMap counts = new Object2IntOpenHashMap<>(); @@ -418,51 +407,47 @@ private MutableText getStatusText(StatusEffectInstance effect) { MutableText text = Text.translatable(effect.getTranslationKey()); if (effect.getAmplifier() != 0) { text.append(String.format(" %d (%s)", effect.getAmplifier() + 1, StatusEffectUtil.getDurationText(effect, 1, mc.world.getTickManager().getTickRate()).getString())); - } - else { + } else { text.append(String.format(" (%s)", StatusEffectUtil.getDurationText(effect, 1, mc.world.getTickManager().getTickRate()).getString())); } - if (effect.getEffectType().isBeneficial()) return text.formatted(Formatting.BLUE); + if (effect.getEffectType().value().isBeneficial()) return text.formatted(Formatting.BLUE); return text.formatted(Formatting.RED); } - private Text getFirstPage(ItemStack stack) { - NbtCompound tag = stack.getNbt(); - if (tag == null) return null; + private Text getFirstPage(ItemStack bookItem) { + ComponentMap components = bookItem.getComponents(); + if (components == ComponentMap.EMPTY) return null; - NbtList pages = tag.getList("pages", 8); - if (pages.size() < 1) return null; - if (stack.getItem() == Items.WRITABLE_BOOK) return Text.literal(pages.getString(0)); + List> pages = components.get(DataComponentTypes.WRITABLE_BOOK_CONTENT).pages(); + if (pages.isEmpty()) return null; + if (bookItem.getItem() == Items.WRITABLE_BOOK) return Text.literal(pages.getFirst().get(false)); try { - return Text.Serialization.fromLenientJson(pages.getString(0)); + return Text.Serialization.fromLenientJson(pages.getFirst().get(false), DynamicRegistryManager.EMPTY); } catch (JsonParseException e) { return Text.literal("Invalid book data"); } } - private ItemStack createBannerFromPattern(RegistryEntry pattern) { - ItemStack itemStack = new ItemStack(Items.GRAY_BANNER); - NbtCompound nbt = itemStack.getOrCreateSubNbt("BlockEntityTag"); - NbtList listNbt = new BannerPattern.Patterns().add(BannerPatterns.BASE, DyeColor.BLACK).add(pattern, DyeColor.WHITE).toNbt(); - nbt.put("Patterns", listNbt); - return itemStack; + private ItemStack createBannerFromLayers(List pattern) { + ItemStack bannerItem = new ItemStack(Items.GRAY_BANNER); + BannerPatternsComponent bannerPatterns = bannerItem.get(DataComponentTypes.BANNER_PATTERNS); + bannerPatterns.layers().addAll(pattern); + bannerItem.set(DataComponentTypes.BANNER_PATTERNS, bannerPatterns); + return bannerItem; } - private ItemStack createBannerFromShield(ItemStack item) { - if (!item.hasNbt() - || !item.getNbt().contains("BlockEntityTag") - || !item.getNbt().getCompound("BlockEntityTag").contains("Base")) + private ItemStack createBannerFromShield(ItemStack shieldItem) { + if (!shieldItem.getComponents().isEmpty() + || shieldItem.get(DataComponentTypes.BLOCK_ENTITY_DATA) == null + || shieldItem.get(DataComponentTypes.BASE_COLOR) == null) return null; - NbtList listNbt = new BannerPattern.Patterns().add(BannerPatterns.BASE, ShieldItem.getColor(item)).toNbt(); - NbtCompound nbt = item.getOrCreateSubNbt("BlockEntityTag"); ItemStack bannerItem = new ItemStack(Items.GRAY_BANNER); - NbtCompound bannerTag = bannerItem.getOrCreateSubNbt("BlockEntityTag"); - bannerTag.put("Patterns", listNbt); - if (!nbt.contains("Patterns")) return bannerItem; - NbtList shieldPatterns = nbt.getList("Patterns", NbtElement.COMPOUND_TYPE); - listNbt.addAll(shieldPatterns); + BannerPatternsComponent bannerPatternsComponent = bannerItem.get(DataComponentTypes.BANNER_PATTERNS); + BannerPatternsComponent shieldPatternsComponent = shieldItem.get(DataComponentTypes.BANNER_PATTERNS); + if (shieldPatternsComponent == null) return bannerItem; + bannerPatternsComponent.layers().addAll(shieldPatternsComponent.layers()); return bannerItem; } diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/render/BlockSelection.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/render/BlockSelection.java index f2a392f56d..a45948b7bc 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/render/BlockSelection.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/render/BlockSelection.java @@ -12,8 +12,8 @@ import meteordevelopment.meteorclient.systems.modules.Module; import meteordevelopment.meteorclient.utils.render.color.SettingColor; import meteordevelopment.orbit.EventHandler; -import net.minecraft.block.BlockState; import net.minecraft.util.hit.BlockHitResult; +import net.minecraft.util.hit.HitResult; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Box; import net.minecraft.util.math.Direction; @@ -70,15 +70,14 @@ public BlockSelection() { @EventHandler private void onRender(Render3DEvent event) { - if (mc.crosshairTarget == null || !(mc.crosshairTarget instanceof BlockHitResult result)) return; + if (mc.crosshairTarget == null || !(mc.crosshairTarget instanceof BlockHitResult result) || result.getType() == HitResult.Type.MISS) return; if (hideInside.get() && result.isInsideBlock()) return; BlockPos bp = result.getBlockPos(); Direction side = result.getSide(); - BlockState state = mc.world.getBlockState(bp); - VoxelShape shape = state.getOutlineShape(mc.world, bp); + VoxelShape shape = mc.world.getBlockState(bp).getOutlineShape(mc.world, bp); if (shape.isEmpty()) return; Box box = shape.getBoundingBox(); diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/render/CameraTweaks.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/render/CameraTweaks.java index ffe10c9b24..234d41e432 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/render/CameraTweaks.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/render/CameraTweaks.java @@ -13,6 +13,7 @@ import meteordevelopment.meteorclient.utils.misc.Keybind; import meteordevelopment.orbit.EventHandler; import net.minecraft.client.option.Perspective; +import org.lwjgl.glfw.GLFW; public class CameraTweaks extends Module { private final SettingGroup sgGeneral = settings.getDefaultGroup(); @@ -39,26 +40,26 @@ public class CameraTweaks extends Module { // Scrolling private final Setting scrollingEnabled = sgScrolling.add(new BoolSetting.Builder() - .name("scrolling-enabled") + .name("scrolling") .description("Allows you to scroll to change camera distance.") .defaultValue(true) .build() ); - private final Setting scrollSensitivity = sgScrolling.add(new DoubleSetting.Builder() - .name("scroll-sensitivity") - .description("Scroll sensitivity when changing the cameras distance. 0 to disable.") + private final Setting scrollKeybind = sgScrolling.add(new KeybindSetting.Builder() + .name("bind") + .description("Binds camera distance scrolling to a key.") .visible(scrollingEnabled::get) - .defaultValue(1) - .min(0) + .defaultValue(Keybind.fromKey(GLFW.GLFW_KEY_LEFT_ALT)) .build() ); - private final Setting scrollKeybind = sgScrolling.add(new KeybindSetting.Builder() - .name("scroll-keybind") - .description("Makes it so a keybind needs to be pressed for scrolling to work.") + private final Setting scrollSensitivity = sgScrolling.add(new DoubleSetting.Builder() + .name("sensitivity") + .description("Sensitivity of the scroll wheel when changing the cameras distance.") .visible(scrollingEnabled::get) - .defaultValue(Keybind.none()) + .defaultValue(1) + .min(0.01) .build() ); @@ -80,7 +81,7 @@ private void onPerspectiveChanged(ChangePerspectiveEvent event) { @EventHandler private void onMouseScroll(MouseScrollEvent event) { - if (mc.options.getPerspective() == Perspective.FIRST_PERSON || mc.currentScreen != null || !scrollingEnabled.get() || (scrollKeybind.get().isValid() && !scrollKeybind.get().isPressed())) return; + if (mc.options.getPerspective() == Perspective.FIRST_PERSON || mc.currentScreen != null || !scrollingEnabled.get() || (scrollKeybind.get().isSet() && !scrollKeybind.get().isPressed())) return; if (scrollSensitivity.get() > 0) { distance -= event.value * 0.25 * (scrollSensitivity.get() * distance); diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/render/CityESP.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/render/CityESP.java index d12d1f0e83..6d9816db96 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/render/CityESP.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/render/CityESP.java @@ -56,9 +56,9 @@ public CityESP() { @EventHandler private void onTick(TickEvent.Post event) { - PlayerEntity targetEntity = TargetUtils.getPlayerTarget(mc.interactionManager.getReachDistance() + 2, SortPriority.LowestDistance); + PlayerEntity targetEntity = TargetUtils.getPlayerTarget(mc.player.getBlockInteractionRange() + 2, SortPriority.LowestDistance); - if (TargetUtils.isBadTarget(targetEntity, mc.interactionManager.getReachDistance() + 2)) { + if (TargetUtils.isBadTarget(targetEntity, mc.player.getBlockInteractionRange() + 2)) { target = null; } else { target = EntityUtils.getCityBlock(targetEntity); diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/render/ESP.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/render/ESP.java index 080d164d8e..40e8f3eb35 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/render/ESP.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/render/ESP.java @@ -74,6 +74,7 @@ public class ESP extends Module { public final Setting shapeMode = sgGeneral.add(new EnumSetting.Builder() .name("shape-mode") .description("How the shapes are rendered.") + .visible(() -> mode.get() != Mode.Glow) .defaultValue(ShapeMode.Both) .build() ); @@ -81,7 +82,7 @@ public class ESP extends Module { public final Setting fillOpacity = sgGeneral.add(new DoubleSetting.Builder() .name("fill-opacity") .description("The opacity of the shape fill.") - .visible(() -> shapeMode.get() != ShapeMode.Lines) + .visible(() -> shapeMode.get() != ShapeMode.Lines && mode.get() != Mode.Glow) .defaultValue(0.3) .range(0, 1) .sliderMax(1) @@ -349,11 +350,16 @@ public boolean isShader() { return isActive() && mode.get() == Mode.Shader; } + public boolean isGlow() { + return isActive() && mode.get() == Mode.Glow; + } + public enum Mode { Box, Wireframe, _2D, - Shader; + Shader, + Glow; @Override public String toString() { diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/render/Freecam.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/render/Freecam.java index 3d85e15f92..d224d919e5 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/render/Freecam.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/render/Freecam.java @@ -168,7 +168,7 @@ public void onDeactivate() { if (reloadChunks.get()) mc.worldRenderer.reload(); mc.options.setPerspective(perspective); if (staticView.get()) { - mc.options.getFovEffectScale().setValue((double)fovScale); + mc.options.getFovEffectScale().setValue(fovScale); mc.options.getBobView().setValue(bobView); } } @@ -374,7 +374,7 @@ private void onGameLeft(GameLeftEvent event) { @EventHandler private void onPacketReceive(PacketEvent.Receive event) { if (event.packet instanceof DeathMessageS2CPacket packet) { - Entity entity = mc.world.getEntityById(packet.getEntityId()); + Entity entity = mc.world.getEntityById(packet.playerId()); if (entity == mc.player && toggleOnDeath.get()) { toggle(); info("Toggled off because you died."); diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/render/LightOverlay.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/render/LightOverlay.java index 32b3f02be0..a7d080d128 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/render/LightOverlay.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/render/LightOverlay.java @@ -80,8 +80,6 @@ public class LightOverlay extends Module { private final Pool crossPool = new Pool<>(Cross::new); private final List crosses = new ArrayList<>(); - private final BlockPos.Mutable bp = new BlockPos.Mutable(); - private final Mesh mesh = new ShaderMesh(Shaders.POS_COLOR, DrawMode.Lines, Mesh.Attrib.Vec3, Mesh.Attrib.Color); public LightOverlay() { diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/render/Nametags.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/render/Nametags.java index 56ffb1e503..77bf49b9aa 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/render/Nametags.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/render/Nametags.java @@ -25,6 +25,7 @@ import meteordevelopment.meteorclient.utils.render.color.Color; import meteordevelopment.meteorclient.utils.render.color.SettingColor; import meteordevelopment.orbit.EventHandler; +import net.minecraft.component.type.ItemEnchantmentsComponent; import net.minecraft.enchantment.Enchantment; import net.minecraft.enchantment.EnchantmentHelper; import net.minecraft.enchantment.Enchantments; @@ -32,6 +33,7 @@ import net.minecraft.entity.decoration.ItemFrameEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; +import net.minecraft.registry.entry.RegistryEntry; import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Vec3d; import net.minecraft.world.GameMode; @@ -164,6 +166,14 @@ public class Nametags extends Module { .build() ); + private final Setting itemDurability = sgPlayers.add(new EnumSetting.Builder() + .name("durability") + .description("Displays item durability as either a total, percentage, or neither.") + .defaultValue(Durability.None) + .visible(displayItems::get) + .build() + ); + private final Setting displayEnchants = sgPlayers.add(new BoolSetting.Builder() .name("display-enchants") .description("Displays item enchantments on the items.") @@ -471,12 +481,12 @@ private void renderNametagPlayer(Render2DEvent event, PlayerEntity player, boole if (!itemStack.isEmpty()) hasItems = true; if (displayEnchants.get()) { - Map enchantments = EnchantmentHelper.get(itemStack); + ItemEnchantmentsComponent enchantments = EnchantmentHelper.getEnchantments(itemStack); int size = 0; - for (var enchantment : enchantments.keySet()) { - if (!shownEnchantments.get().contains(enchantment)) continue; - String enchantName = Utils.getEnchantSimpleName(enchantment, enchantLength.get()) + " " + enchantments.get(enchantment); + for (RegistryEntry enchantment : enchantments.getEnchantments()) { + if (!shownEnchantments.get().contains(enchantment.value())) continue; + String enchantName = Utils.getEnchantSimpleName(enchantment.value(), enchantLength.get()) + " " + enchantments.getLevel(enchantment.value()); itemWidths[i] = Math.max(itemWidths[i], (text.getWidth(enchantName, shadow) / 2)); size++; } @@ -499,15 +509,29 @@ private void renderNametagPlayer(Render2DEvent event, PlayerEntity player, boole RenderUtils.drawItem(event.drawContext, stack, (int) x, (int) y, 2, true); + if (stack.isDamageable() && itemDurability.get() != Durability.None) { + text.begin(0.75, false, true); + + String damageText = switch (itemDurability.get()) { + case Percentage -> String.format("%.0f%%", ((stack.getMaxDamage() - stack.getDamage()) * 100f) / (float) stack.getMaxDamage()); + case Total -> Integer.toString(stack.getMaxDamage() - stack.getDamage()); + default -> "err"; + }; + Color damageColor = new Color(stack.getItemBarColor()); + + text.render(damageText, (int) x, (int) y, damageColor.a(255), true); + text.end(); + } + if (maxEnchantCount > 0 && displayEnchants.get()) { text.begin(0.5 * enchantTextScale.get(), false, true); - Map enchantments = EnchantmentHelper.get(stack); + ItemEnchantmentsComponent enchantments = EnchantmentHelper.getEnchantments(stack); Map enchantmentsToShow = new HashMap<>(); - for (Enchantment enchantment : enchantments.keySet()) { - if (shownEnchantments.get().contains(enchantment)) { - enchantmentsToShow.put(enchantment, enchantments.get(enchantment)); + for (RegistryEntry enchantment : enchantments.getEnchantments()) { + if (shownEnchantments.get().contains(enchantment.value())) { + enchantmentsToShow.put(enchantment.value(), enchantments.getLevel(enchantment.value())); } } @@ -661,9 +685,15 @@ public enum Position { OnTop } + public enum Durability { + None, + Total, + Percentage + } + public enum DistanceColorMode { Gradient, - Flat; + Flat } public boolean excludeBots() { diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/render/StorageESP.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/render/StorageESP.java index 8633843ac7..9655ef5215 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/render/StorageESP.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/render/StorageESP.java @@ -5,7 +5,12 @@ package meteordevelopment.meteorclient.systems.modules.render; +import meteordevelopment.meteorclient.events.entity.player.InteractBlockEvent; import meteordevelopment.meteorclient.events.render.Render3DEvent; +import meteordevelopment.meteorclient.gui.GuiTheme; +import meteordevelopment.meteorclient.gui.widgets.WWidget; +import meteordevelopment.meteorclient.gui.widgets.containers.WVerticalList; +import meteordevelopment.meteorclient.gui.widgets.pressable.WButton; import meteordevelopment.meteorclient.renderer.*; import meteordevelopment.meteorclient.settings.*; import meteordevelopment.meteorclient.systems.modules.Categories; @@ -20,16 +25,22 @@ import meteordevelopment.meteorclient.utils.render.postprocess.PostProcessShaders; import meteordevelopment.meteorclient.utils.world.Dir; import meteordevelopment.orbit.EventHandler; +import net.minecraft.util.math.BlockPos; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; import net.minecraft.block.ChestBlock; import net.minecraft.block.entity.*; import net.minecraft.block.enums.ChestType; +import net.minecraft.util.math.Direction; +import java.util.HashSet; +import java.util.Set; import java.util.List; public class StorageESP extends Module { private final SettingGroup sgGeneral = settings.getDefaultGroup(); + private final SettingGroup sgOpened = settings.createGroup("Opened Rendering"); + private final Set interactedBlocks = new HashSet<>(); public final Setting mode = sgGeneral.add(new EnumSetting.Builder() .name("mode") @@ -141,6 +152,21 @@ public class StorageESP extends Module { .build() ); + private final Setting hideOpened = sgOpened.add(new BoolSetting.Builder() + .name("hide-opened") + .description("Hides opened containers.") + .defaultValue(false) + .build() + ); + + private final Setting openedColor = sgOpened.add(new ColorSetting.Builder() + .name("opened-color") + .description("Optional setting to change colors of opened chests, as opposed to not rendering. Disabled at zero opacity.") + .defaultValue(new SettingColor(203, 90, 203, 0)) /// TRANSPARENT BY DEFAULT. + .build() + ); + + private final Color lineColor = new Color(0, 0, 0, 0); private final Color sideColor = new Color(0, 0, 0, 0); private boolean render; @@ -177,6 +203,42 @@ private void getBlockEntityColor(BlockEntity blockEntity) { } } + @Override + public WWidget getWidget(GuiTheme theme) { + WVerticalList list = theme.verticalList(); + + // Button to Clear Interacted Blocks + WButton clear = list.add(theme.button("Clear Rendering Cache")).expandX().widget(); + + clear.action = () -> { + interactedBlocks.clear(); + }; + + return list; + } + + @EventHandler + private void onBlockInteract(InteractBlockEvent event) { + BlockPos pos = event.result.getBlockPos(); + BlockEntity blockEntity = mc.world.getBlockEntity(pos); + + if (blockEntity == null) return; + + interactedBlocks.add(pos); + if (blockEntity instanceof ChestBlockEntity chestBlockEntity) { + BlockState state = chestBlockEntity.getCachedState(); + ChestType chestType = state.get(ChestBlock.CHEST_TYPE); + + if (chestType == ChestType.LEFT || chestType == ChestType.RIGHT) { + // It's part of a double chest + Direction facing = state.get(ChestBlock.FACING); + BlockPos otherPartPos = pos.offset(chestType == ChestType.LEFT ? facing.rotateYClockwise() : facing.rotateYCounterclockwise()); + + interactedBlocks.add(otherPartPos); + } + } + } + @EventHandler private void onRender(Render3DEvent event) { count = 0; @@ -184,8 +246,20 @@ private void onRender(Render3DEvent event) { if (mode.get() == Mode.Shader) mesh.begin(); for (BlockEntity blockEntity : Utils.blockEntities()) { + // Check if the block has been interacted with (opened) + boolean interacted = interactedBlocks.contains(blockEntity.getPos()); + if (interacted && hideOpened.get()) continue; // Skip rendering if "hideOpened" is true + getBlockEntityColor(blockEntity); + // Set the color to openedColor if its alpha is greater than 0 + if (interacted && openedColor.get().a > 0) { + // openedColor takes precedence. + lineColor.set(openedColor.get()); + sideColor.set(openedColor.get()); + sideColor.a = fillOpacity.get(); // Maintain fill opacity setting for consistency + } + if (render) { double dist = PlayerUtils.squaredDistanceTo(blockEntity.getPos().getX() + 0.5, blockEntity.getPos().getY() + 0.5, blockEntity.getPos().getZ() + 0.5); double a = 1; @@ -211,10 +285,10 @@ private void onRender(Render3DEvent event) { count++; } } - if (mode.get() == Mode.Shader) PostProcessShaders.STORAGE_OUTLINE.endRender(() -> mesh.render(event.matrices)); } + private void renderBox(Render3DEvent event, BlockEntity blockEntity) { double x1 = blockEntity.getPos().getX(); double y1 = blockEntity.getPos().getY(); diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/render/Tracers.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/render/Tracers.java index d2c751ada8..e227505bf9 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/render/Tracers.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/render/Tracers.java @@ -41,7 +41,7 @@ public class Tracers extends Module { public enum TracerStyle { Lines, Offscreen - }; + } // General @@ -305,7 +305,7 @@ public void onRender2D(Render2DEvent event) { Vector2f newPoint = new Vector2f(screenCenter.x + distanceOffscreen.get() * (float) Math.cos(angleYawRad), screenCenter.y + distanceOffscreen.get() * (float) Math.sin(angleYawRad)); - Vector2f trianglePoints[] = { + Vector2f[] trianglePoints = { new Vector2f(newPoint.x - sizeOffscreen.get(), newPoint.y - sizeOffscreen.get()), new Vector2f(newPoint.x + sizeOffscreen.get() * 0.73205f, newPoint.y), new Vector2f(newPoint.x - sizeOffscreen.get(), newPoint.y + sizeOffscreen.get()) diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/render/Trajectories.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/render/Trajectories.java index 86cc51c39e..c20c13dba3 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/render/Trajectories.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/render/Trajectories.java @@ -27,6 +27,7 @@ import net.minecraft.util.hit.HitResult; import net.minecraft.util.math.Box; import net.minecraft.util.math.Direction; +import net.minecraft.util.math.MathHelper; import org.joml.Vector3d; import java.util.ArrayList; @@ -139,9 +140,10 @@ private void calculatePath(PlayerEntity player, double tickDelta) { // Get item ItemStack itemStack = player.getMainHandStack(); - if (itemStack == null) itemStack = player.getOffHandStack(); - if (itemStack == null) return; - if (!items.get().contains(itemStack.getItem())) return; + if (!items.get().contains(itemStack.getItem())) { + itemStack = player.getOffHandStack(); + if (!items.get().contains(itemStack.getItem())) return; + } // Calculate paths if (!simulator.set(player, itemStack, 0, accurate.get(), tickDelta)) return; @@ -160,8 +162,8 @@ private void calculateFiredPath(Entity entity, double tickDelta) { for (Path path : paths) path.clear(); // Calculate paths - if (!simulator.set(entity, accurate.get(), tickDelta)) return; - getEmptyPath().calculate(); + if (!simulator.set(entity, accurate.get())) return; + getEmptyPath().setStart(entity, tickDelta).calculate(); } @EventHandler @@ -189,14 +191,16 @@ private class Path { private boolean hitQuad, hitQuadHorizontal; private double hitQuadX1, hitQuadY1, hitQuadZ1, hitQuadX2, hitQuadY2, hitQuadZ2; - private Entity entity; + private Entity collidingEntity; + public Vector3d lastPoint; public void clear() { for (Vector3d point : points) vec3s.free(point); points.clear(); hitQuad = false; - entity = null; + collidingEntity = null; + lastPoint = null; } public void calculate() { @@ -212,7 +216,16 @@ public void calculate() { addPoint(); } + } + public Path setStart(Entity entity, double tickDelta) { + lastPoint = new Vector3d( + MathHelper.lerp(tickDelta, entity.lastRenderX, entity.getX()), + MathHelper.lerp(tickDelta, entity.lastRenderY, entity.getY()), + MathHelper.lerp(tickDelta, entity.lastRenderZ, entity.getZ()) + ); + + return this; } private void addPoint() { @@ -256,16 +269,14 @@ else if (r.getSide() == Direction.NORTH || r.getSide() == Direction.SOUTH) { points.add(Utils.set(vec3s.get(), result.getPos())); } else if (result.getType() == HitResult.Type.ENTITY) { - entity = ((EntityHitResult) result).getEntity(); + collidingEntity = ((EntityHitResult) result).getEntity(); - points.add(Utils.set(vec3s.get(), result.getPos()).add(0, entity.getHeight() / 2, 0)); + points.add(Utils.set(vec3s.get(), result.getPos()).add(0, collidingEntity.getHeight() / 2, 0)); } } public void render(Render3DEvent event) { // Render path - Vector3d lastPoint = null; - for (Vector3d point : points) { if (lastPoint != null) event.renderer.line(lastPoint.x, lastPoint.y, lastPoint.z, point.x, point.y, point.z, lineColor.get()); lastPoint = point; @@ -278,12 +289,12 @@ public void render(Render3DEvent event) { } // Render entity - if (entity != null) { - double x = (entity.getX() - entity.prevX) * event.tickDelta; - double y = (entity.getY() - entity.prevY) * event.tickDelta; - double z = (entity.getZ() - entity.prevZ) * event.tickDelta; + if (collidingEntity != null) { + double x = (collidingEntity.getX() - collidingEntity.prevX) * event.tickDelta; + double y = (collidingEntity.getY() - collidingEntity.prevY) * event.tickDelta; + double z = (collidingEntity.getZ() - collidingEntity.prevZ) * event.tickDelta; - Box box = entity.getBoundingBox(); + Box box = collidingEntity.getBoundingBox(); event.renderer.box(x + box.minX, y + box.minY, z + box.minZ, x + box.maxX, y + box.maxY, z + box.maxZ, sideColor.get(), lineColor.get(), shapeMode.get(), 0); } } diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/render/Xray.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/render/Xray.java index 2ab23b7150..1b33af413c 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/render/Xray.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/render/Xray.java @@ -31,7 +31,7 @@ public class Xray extends Module { private final SettingGroup sgGeneral = settings.getDefaultGroup(); - public static final List ORES = List.of(Blocks.COAL_ORE, Blocks.DEEPSLATE_COAL_ORE, Blocks.IRON_ORE, Blocks.DEEPSLATE_IRON_ORE, Blocks.GOLD_ORE, Blocks.DEEPSLATE_GOLD_ORE, Blocks.LAPIS_ORE, Blocks.DEEPSLATE_LAPIS_ORE, Blocks.REDSTONE_ORE, Blocks.REDSTONE_ORE, Blocks.DIAMOND_ORE, Blocks.DEEPSLATE_DIAMOND_ORE, Blocks.EMERALD_ORE, Blocks.DEEPSLATE_EMERALD_ORE, Blocks.COPPER_ORE, Blocks.DEEPSLATE_COPPER_ORE, Blocks.NETHER_GOLD_ORE, Blocks.NETHER_QUARTZ_ORE, Blocks.ANCIENT_DEBRIS); + public static final List ORES = List.of(Blocks.COAL_ORE, Blocks.DEEPSLATE_COAL_ORE, Blocks.IRON_ORE, Blocks.DEEPSLATE_IRON_ORE, Blocks.GOLD_ORE, Blocks.DEEPSLATE_GOLD_ORE, Blocks.LAPIS_ORE, Blocks.DEEPSLATE_LAPIS_ORE, Blocks.REDSTONE_ORE, Blocks.DEEPSLATE_REDSTONE_ORE, Blocks.DIAMOND_ORE, Blocks.DEEPSLATE_DIAMOND_ORE, Blocks.EMERALD_ORE, Blocks.DEEPSLATE_EMERALD_ORE, Blocks.COPPER_ORE, Blocks.DEEPSLATE_COPPER_ORE, Blocks.NETHER_GOLD_ORE, Blocks.NETHER_QUARTZ_ORE, Blocks.ANCIENT_DEBRIS); private final Setting> blocks = sgGeneral.add(new BlockListSetting.Builder() .name("whitelist") diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/render/blockesp/ESPBlock.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/render/blockesp/ESPBlock.java index 47e4f160a9..809ea49ed5 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/render/blockesp/ESPBlock.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/render/blockesp/ESPBlock.java @@ -59,16 +59,15 @@ public ESPBlock(int x, int y, int z) { } public ESPBlock getSideBlock(int side) { - switch (side) { - case FO: return blockEsp.getBlock(x, y, z + 1); - case BA: return blockEsp.getBlock(x, y, z - 1); - case LE: return blockEsp.getBlock(x - 1, y, z); - case RI: return blockEsp.getBlock(x + 1, y, z); - case TO: return blockEsp.getBlock(x, y + 1, z); - case BO: return blockEsp.getBlock(x, y - 1, z); - } - - return null; + return switch (side) { + case FO -> blockEsp.getBlock(x, y, z + 1); + case BA -> blockEsp.getBlock(x, y, z - 1); + case LE -> blockEsp.getBlock(x - 1, y, z); + case RI -> blockEsp.getBlock(x + 1, y, z); + case TO -> blockEsp.getBlock(x, y + 1, z); + case BO -> blockEsp.getBlock(x, y - 1, z); + default -> null; + }; } private void assignGroup() { diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/render/blockesp/ESPGroup.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/render/blockesp/ESPGroup.java index 6f4c109f2f..f103f75c79 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/render/blockesp/ESPGroup.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/render/blockesp/ESPGroup.java @@ -73,9 +73,9 @@ private void trySplit(ESPBlock block) { Set remainingBlocks = new ObjectOpenHashSet<>(blocks); Queue blocksToCheck = new ArrayDeque<>(); - blocksToCheck.offer(blocks.get(0)); - remainingBlocks.remove(blocks.get(0)); - neighbours.remove(blocks.get(0)); + blocksToCheck.offer(blocks.getFirst()); + remainingBlocks.remove(blocks.getFirst()); + neighbours.remove(blocks.getFirst()); loop: { while (!blocksToCheck.isEmpty()) { @@ -96,7 +96,7 @@ private void trySplit(ESPBlock block) { } } - if (neighbours.size() > 0) { + if (!neighbours.isEmpty()) { ESPGroup group = blockEsp.newGroup(this.block); group.blocks.ensureCapacity(remainingBlocks.size()); diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/render/marker/BaseMarker.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/render/marker/BaseMarker.java index f18dcc6c70..81617cd0cb 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/render/marker/BaseMarker.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/render/marker/BaseMarker.java @@ -24,14 +24,12 @@ public abstract class BaseMarker implements ISerializable { public final Setting name = sgBase.add(new StringSetting.Builder() .name("name") .description("Custom name for this marker.") - .defaultValue("") .build() ); protected final Setting description = sgBase.add(new StringSetting.Builder() .name("description") .description("Custom description for this marker.") - .defaultValue("") .build() ); diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/render/marker/Sphere2dMarker.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/render/marker/Sphere2dMarker.java index f638b90b1a..53b57e9a48 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/render/marker/Sphere2dMarker.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/render/marker/Sphere2dMarker.java @@ -105,6 +105,7 @@ public Block(int x, int y, int z) { // Keybinding + @SuppressWarnings("unused") private final Setting nextLayerKey = sgKeybinding.add(new KeybindSetting.Builder() .name("next-layer-keybind") .description("Keybind to increment layer") @@ -114,6 +115,7 @@ public Block(int x, int y, int z) { .build() ); + @SuppressWarnings("unused") private final Setting prevLayerKey = sgKeybinding.add(new KeybindSetting.Builder() .name("prev-layer-keybind") .description("Keybind to increment layer") diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/world/AirPlace.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/world/AirPlace.java index 16df2177f2..ac2729c18d 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/world/AirPlace.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/world/AirPlace.java @@ -81,23 +81,23 @@ public AirPlace() { @EventHandler private void onTick(TickEvent.Post event) { - double r = customRange.get() ? range.get() : mc.interactionManager.getReachDistance(); + double r = customRange.get() ? range.get() : mc.player.getBlockInteractionRange(); hitResult = mc.getCameraEntity().raycast(r, 0, false); - if (!(hitResult instanceof BlockHitResult) || !(mc.player.getMainHandStack().getItem() instanceof BlockItem) && !(mc.player.getMainHandStack().getItem() instanceof SpawnEggItem)) return; + if (!(hitResult instanceof BlockHitResult blockHitResult) || !(mc.player.getMainHandStack().getItem() instanceof BlockItem) && !(mc.player.getMainHandStack().getItem() instanceof SpawnEggItem)) return; if (mc.options.useKey.isPressed()) { - BlockUtils.place(((BlockHitResult) hitResult).getBlockPos(), Hand.MAIN_HAND, mc.player.getInventory().selectedSlot, false, 0, true, true, false); + BlockUtils.place(blockHitResult.getBlockPos(), Hand.MAIN_HAND, mc.player.getInventory().selectedSlot, false, 0, true, true, false); } } @EventHandler private void onRender(Render3DEvent event) { - if (!(hitResult instanceof BlockHitResult) - || !mc.world.getBlockState(((BlockHitResult) hitResult).getBlockPos()).isReplaceable() + if (!(hitResult instanceof BlockHitResult blockHitResult) + || !mc.world.getBlockState(blockHitResult.getBlockPos()).isReplaceable() || !(mc.player.getMainHandStack().getItem() instanceof BlockItem) && !(mc.player.getMainHandStack().getItem() instanceof SpawnEggItem) || !render.get()) return; - event.renderer.box(((BlockHitResult) hitResult).getBlockPos(), sideColor.get(), lineColor.get(), shapeMode.get(), 0); + event.renderer.box(blockHitResult.getBlockPos(), sideColor.get(), lineColor.get(), shapeMode.get(), 0); } } diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/world/AutoBrewer.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/world/AutoBrewer.java index e184be0104..212c4adc04 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/world/AutoBrewer.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/world/AutoBrewer.java @@ -13,10 +13,10 @@ import meteordevelopment.meteorclient.utils.misc.MyPotion; import meteordevelopment.meteorclient.utils.player.InvUtils; import net.minecraft.client.resource.language.I18n; +import net.minecraft.component.DataComponentTypes; import net.minecraft.item.Item; import net.minecraft.item.Items; import net.minecraft.potion.Potion; -import net.minecraft.potion.PotionUtil; import net.minecraft.potion.Potions; import net.minecraft.screen.BrewingStandScreenHandler; @@ -138,8 +138,8 @@ private boolean insertWaterBottles(BrewingStandScreenHandler c) { for (int slotI = 5; slotI < c.slots.size(); slotI++) { if (c.slots.get(slotI).getStack().getItem() == Items.POTION) { - Potion potion = PotionUtil.getPotion(c.slots.get(slotI).getStack()); - if (potion == Potions.WATER) { + Potion potion = c.slots.get(slotI).getStack().get(DataComponentTypes.POTION_CONTENTS).potion().get().value(); + if (potion == Potions.WATER.value()) { slot = slotI; break; } diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/world/AutoSmelter.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/world/AutoSmelter.java index f74847aa5b..fd07a778bf 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/world/AutoSmelter.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/world/AutoSmelter.java @@ -85,7 +85,7 @@ public void tick(AbstractFurnaceScreenHandler c) { } private void insertItems(AbstractFurnaceScreenHandler c) { - ItemStack inputItemStack = c.slots.get(0).getStack(); + ItemStack inputItemStack = c.slots.getFirst().getStack(); if (!inputItemStack.isEmpty()) return; int slot = -1; diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/world/EChestFarmer.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/world/EChestFarmer.java index dc4a2bded9..0f6667e89c 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/world/EChestFarmer.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/world/EChestFarmer.java @@ -187,7 +187,7 @@ private void onTick(TickEvent.Pre event) { private void onRender(Render3DEvent event) { if (target == null || !render.get() || Modules.get().get(PacketMine.class).isMiningBlock(target)) return; - Box box = SHAPE.getBoundingBoxes().get(0); + Box box = SHAPE.getBoundingBoxes().getFirst(); event.renderer.box(target.getX() + box.minX, target.getY() + box.minY, target.getZ() + box.minZ, target.getX() + box.maxX, target.getY() + box.maxY, target.getZ() + box.maxZ, sideColor.get(), lineColor.get(), shapeMode.get(), 0); } } diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/world/EndermanLook.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/world/EndermanLook.java index b0ab233df0..115e9d2c3b 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/world/EndermanLook.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/world/EndermanLook.java @@ -6,6 +6,7 @@ package meteordevelopment.meteorclient.systems.modules.world; import meteordevelopment.meteorclient.events.world.TickEvent; +import meteordevelopment.meteorclient.settings.BoolSetting; import meteordevelopment.meteorclient.settings.EnumSetting; import meteordevelopment.meteorclient.settings.Setting; import meteordevelopment.meteorclient.settings.SettingGroup; @@ -14,8 +15,10 @@ import meteordevelopment.meteorclient.utils.entity.Target; import meteordevelopment.meteorclient.utils.player.Rotations; import meteordevelopment.orbit.EventHandler; +import net.minecraft.block.Blocks; import net.minecraft.entity.Entity; import net.minecraft.entity.mob.EndermanEntity; +import net.minecraft.entity.player.PlayerEntity; import net.minecraft.util.math.Vec3d; public class EndermanLook extends Module { @@ -28,40 +31,42 @@ public class EndermanLook extends Module { .build() ); + private final Setting stun = sgGeneral.add(new BoolSetting.Builder() + .name("stun-hostiles") + .description("Automatically stares at hostile endermen to stun them in place.") + .defaultValue(true) + .visible(() -> lookMode.get() == Mode.Away) + .build() + ); + public EndermanLook() { super(Categories.World, "enderman-look", "Either looks at all Endermen or prevents you from looking at Endermen."); } @EventHandler private void onTick(TickEvent.Pre event) { - if (lookMode.get() == Mode.Away) { - if (mc.player.getAbilities().creativeMode || !shouldLook()) return; + // if either are true nothing happens when you look at an enderman + if (mc.player.getInventory().armor.get(3).isOf(Blocks.CARVED_PUMPKIN.asItem()) || mc.player.getAbilities().creativeMode) return; - Rotations.rotate(mc.player.getYaw(), 90, -75, null); - } - else { - for (Entity entity : mc.world.getEntities()) { - if (!(entity instanceof EndermanEntity enderman)) continue; - - if (enderman.isAngry() || !enderman.isAlive() || !mc.player.canSee(enderman)) continue; - - Rotations.rotate(Rotations.getYaw(enderman), Rotations.getPitch(enderman, Target.Head), -75, null); - break; - } - } - } - - private boolean shouldLook() { for (Entity entity : mc.world.getEntities()) { - if (!(entity instanceof EndermanEntity)) continue; - - if (entity.isAlive() && angleCheck(entity)) return true; + if (!(entity instanceof EndermanEntity enderman) || !enderman.isAlive() || !mc.player.canSee(enderman)) continue; + + switch (lookMode.get()) { + case Away -> { + if (enderman.isAngry() && stun.get()) Rotations.rotate(Rotations.getYaw(enderman), Rotations.getPitch(enderman, Target.Head), -75, null); + else if (angleCheck(enderman)) Rotations.rotate(mc.player.getYaw(), 90, -75, null); + } + case At -> { + if (!enderman.isAngry()) Rotations.rotate(Rotations.getYaw(enderman), Rotations.getPitch(enderman, Target.Head), -75, null); + } + } } - - return false; } - private boolean angleCheck(Entity entity) { + /** + * @see EndermanEntity#isPlayerStaring(PlayerEntity) + */ + private boolean angleCheck(EndermanEntity entity) { Vec3d vec3d = mc.player.getRotationVec(1.0F).normalize(); Vec3d vec3d2 = new Vec3d(entity.getX() - mc.player.getX(), entity.getEyeY() - mc.player.getEyeY(), entity.getZ() - mc.player.getZ()); @@ -69,7 +74,7 @@ private boolean angleCheck(Entity entity) { vec3d2 = vec3d2.normalize(); double e = vec3d.dotProduct(vec3d2); - return e > 1.0D - 0.025D / d && mc.player.canSee(entity); + return e > 1.0D - 0.025D / d; } public enum Mode { diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/world/Excavator.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/world/Excavator.java index 5f2f38a312..34f48d4b1e 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/world/Excavator.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/world/Excavator.java @@ -28,9 +28,9 @@ public class Excavator extends Module { private final SettingGroup sgRendering = settings.createGroup("Rendering"); // Keybindings - private final Setting selectionKey = sgGeneral.add(new KeybindSetting.Builder() - .name("selection-key") - .description("Key to draw the selection.") + private final Setting selectionBind = sgGeneral.add(new KeybindSetting.Builder() + .name("selection-bind") + .description("Bind to draw selection.") .defaultValue(Keybind.fromButton(GLFW.GLFW_MOUSE_BUTTON_RIGHT)) .build() ); @@ -94,7 +94,7 @@ public void onDeactivate() { @EventHandler private void onMouseButton(MouseButtonEvent event) { - if (event.action != KeyAction.Press || event.button != selectionKey.get().getValue() || mc.currentScreen != null) { + if (event.action != KeyAction.Press || !selectionBind.get().isPressed() || mc.currentScreen != null) { return; } selectCorners(); @@ -102,7 +102,7 @@ private void onMouseButton(MouseButtonEvent event) { @EventHandler private void onKey(KeyEvent event) { - if (event.action != KeyAction.Press || event.key != selectionKey.get().getValue() || mc.currentScreen != null) { + if (event.action != KeyAction.Press || !selectionBind.get().isPressed() || mc.currentScreen != null) { return; } selectCorners(); diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/world/HighwayBuilder.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/world/HighwayBuilder.java index 8908aac703..fb1acf7d63 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/world/HighwayBuilder.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/world/HighwayBuilder.java @@ -12,9 +12,11 @@ import meteordevelopment.meteorclient.systems.modules.Categories; import meteordevelopment.meteorclient.systems.modules.Module; import meteordevelopment.meteorclient.systems.modules.Modules; +import meteordevelopment.meteorclient.systems.modules.combat.KillAura; import meteordevelopment.meteorclient.systems.modules.player.AutoEat; import meteordevelopment.meteorclient.systems.modules.player.AutoGap; import meteordevelopment.meteorclient.systems.modules.player.AutoTool; +import meteordevelopment.meteorclient.systems.modules.player.InstaMine; import meteordevelopment.meteorclient.utils.misc.HorizontalDirection; import meteordevelopment.meteorclient.utils.misc.MBlockPos; import meteordevelopment.meteorclient.utils.player.CustomPlayerInput; @@ -25,6 +27,7 @@ import meteordevelopment.meteorclient.utils.render.color.SettingColor; import meteordevelopment.meteorclient.utils.world.BlockUtils; import meteordevelopment.meteorclient.utils.world.Dir; +import meteordevelopment.meteorclient.utils.world.TickRate; import meteordevelopment.orbit.EventHandler; import net.minecraft.block.Block; import net.minecraft.block.BlockState; @@ -34,10 +37,8 @@ import net.minecraft.enchantment.Enchantments; import net.minecraft.entity.Entity; import net.minecraft.entity.ItemEntity; -import net.minecraft.item.BlockItem; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.item.Items; +import net.minecraft.item.*; +import net.minecraft.network.packet.c2s.play.PlayerActionC2SPacket; import net.minecraft.text.MutableText; import net.minecraft.text.Text; import net.minecraft.util.Formatting; @@ -46,12 +47,14 @@ import net.minecraft.util.math.Box; import net.minecraft.util.math.Direction; import net.minecraft.util.math.Vec3d; +import net.minecraft.world.EmptyBlockView; import org.jetbrains.annotations.NotNull; import java.util.Iterator; import java.util.List; import java.util.function.Predicate; +@SuppressWarnings("ConstantConditions") public class HighwayBuilder extends Module { public enum Floor { Replace, @@ -64,7 +67,7 @@ public enum Rotation { Place(false, true), Both(true, true); - public boolean mine, place; + public final boolean mine, place; Rotation(boolean mine, boolean place) { this.mine = mine; @@ -75,8 +78,11 @@ public enum Rotation { private static final BlockPos ZERO = new BlockPos(0, 0, 0); private final SettingGroup sgGeneral = settings.getDefaultGroup(); - private final SettingGroup sgRenderMine = settings.createGroup("Render Mine"); - private final SettingGroup sgRenderPlace = settings.createGroup("Render Place"); + private final SettingGroup sgDigging = settings.createGroup("Digging"); + private final SettingGroup sgPaving = settings.createGroup("Paving"); + private final SettingGroup sgInventory = settings.createGroup("Inventory"); + private final SettingGroup sgRenderDigging = settings.createGroup("Render Digging"); + private final SettingGroup sgRenderPaving = settings.createGroup("Render Paving"); // General @@ -127,96 +133,183 @@ public enum Rotation { .build() ); - private final Setting> blocksToPlace = sgGeneral.add(new BlockListSetting.Builder() - .name("blocks-to-place") - .description("Blocks it is allowed to place.") - .defaultValue(Blocks.OBSIDIAN) - .filter(block -> Block.isShapeFullCube(block.getDefaultState().getCollisionShape(mc.world, ZERO))) + private final Setting disconnectOnToggle = sgGeneral.add(new BoolSetting.Builder() + .name("disconnect-on-toggle") + .description("Automatically disconnects when the module is turned off, for example for not having enough blocks.") + .defaultValue(false) .build() ); - private final Setting> trashItems = sgGeneral.add(new ItemListSetting.Builder() - .name("trash-items") - .description("Items that are considered trash and can be thrown out.") - .defaultValue(Items.NETHERRACK, Items.QUARTZ, Items.GOLD_NUGGET, Items.GLOWSTONE_DUST, Items.BLACKSTONE, Items.BASALT) + private final Setting pauseOnLag = sgGeneral.add(new BoolSetting.Builder() + .name("pause-on-lag") + .description("Pauses the current process while the server stops responding.") + .defaultValue(true) .build() ); - private final Setting dontBreakTools = sgGeneral.add(new BoolSetting.Builder() + // Digging + + private final Setting dontBreakTools = sgDigging.add(new BoolSetting.Builder() .name("dont-break-tools") .description("Don't break tools.") .defaultValue(false) .build() ); - private final Setting mineEnderChests = sgGeneral.add(new BoolSetting.Builder() + private final Setting savePickaxes = sgDigging.add(new IntSetting.Builder() + .name("save-pickaxes") + .description("How many pickaxes to ensure are saved.") + .defaultValue(0) + .range(0, 36) + .sliderRange(0, 36) + .visible(() -> !dontBreakTools.get()) + .build() + ); + + private final Setting breakDelay = sgDigging.add(new IntSetting.Builder() + .name("break-delay") + .description("The delay between breaking blocks.") + .defaultValue(0) + .min(0) + .build() + ); + + private final Setting blocksPerTick = sgDigging.add(new IntSetting.Builder() + .name("blocks-per-tick") + .description("The maximum amount of blocks that can be mined in a tick. Only applies to blocks instantly breakable.") + .defaultValue(1) + .range(1, 100) + .sliderRange(1, 25) + .build() + ); + + // Paving + + private final Setting> blocksToPlace = sgPaving.add(new BlockListSetting.Builder() + .name("blocks-to-place") + .description("Blocks it is allowed to place.") + .defaultValue(Blocks.OBSIDIAN) + .filter(block -> Block.isShapeFullCube(block.getDefaultState().getCollisionShape(EmptyBlockView.INSTANCE, ZERO))) + .build() + ); + + private final Setting placeDelay = sgPaving.add(new IntSetting.Builder() + .name("place-delay") + .description("The delay between placing blocks.") + .defaultValue(0) + .min(0) + .build() + ); + + private final Setting placementsPerTick = sgPaving.add(new IntSetting.Builder() + .name("placements-per-tick") + .description("The maximum amount of blocks that can be placed in a tick.") + .defaultValue(1) + .min(1) + .build() + ); + + // Inventory + + private final Setting> trashItems = sgInventory.add(new ItemListSetting.Builder() + .name("trash-items") + .description("Items that are considered trash and can be thrown out.") + .defaultValue( + Items.NETHERRACK, Items.QUARTZ, Items.GOLD_NUGGET, Items.GOLDEN_SWORD, Items.GLOWSTONE_DUST, + Items.GLOWSTONE, Items.BLACKSTONE, Items.BASALT, Items.GHAST_TEAR, Items.SOUL_SAND, Items.SOUL_SOIL, + Items.ROTTEN_FLESH + ) + .build() + ); + + private final Setting mineEnderChests = sgInventory.add(new BoolSetting.Builder() .name("mine-ender-chests") .description("Mines ender chests for obsidian.") .defaultValue(true) .build() ); - private final Setting disconnectOnToggle = sgGeneral.add(new BoolSetting.Builder() - .name("disconnect-on-toggle") - .description("Automatically disconnects when the module is turned off, for example for not having enough blocks.") + private final Setting saveEchests = sgInventory.add(new IntSetting.Builder() + .name("save-ender-chests") + .description("How many ender chests to ensure are saved.") + .defaultValue(1) + .range(0, 64) + .sliderRange(0, 64) + .visible(mineEnderChests::get) + .build() + ); + + private final Setting instamineEchests = sgInventory.add(new BoolSetting.Builder() + .name("instamine-echests") + .description("Whether or not to use the instamine exploit to break echests.") .defaultValue(false) + .visible(mineEnderChests::get) + .build() + ); + + private final Setting instamineDelay = sgInventory.add(new IntSetting.Builder() + .name("instamine-delay") + .description("Delay between instamine attempts.") + .defaultValue(0) + .sliderMax(20) + .visible(() -> mineEnderChests.get() && instamineEchests.get()) .build() ); - // Render Mine + // Render Digging - private final Setting renderMine = sgRenderMine.add(new BoolSetting.Builder() + private final Setting renderMine = sgRenderDigging.add(new BoolSetting.Builder() .name("render-blocks-to-mine") .description("Render blocks to be mined.") .defaultValue(true) .build() ); - private final Setting renderMineShape = sgRenderMine.add(new EnumSetting.Builder() + private final Setting renderMineShape = sgRenderDigging.add(new EnumSetting.Builder() .name("blocks-to-mine-shape-mode") .description("How the blocks to be mined are rendered.") .defaultValue(ShapeMode.Both) .build() ); - private final Setting renderMineSideColor = sgRenderMine.add(new ColorSetting.Builder() + private final Setting renderMineSideColor = sgRenderDigging.add(new ColorSetting.Builder() .name("blocks-to-mine-side-color") .description("Color of blocks to be mined.") .defaultValue(new SettingColor(225, 25, 25, 25)) .build() ); - private final Setting renderMineLineColor = sgRenderMine.add(new ColorSetting.Builder() + private final Setting renderMineLineColor = sgRenderDigging.add(new ColorSetting.Builder() .name("blocks-to-mine-line-color") .description("Color of blocks to be mined.") .defaultValue(new SettingColor(225, 25, 25)) .build() ); - // Render Place + // Render Paving - private final Setting renderPlace = sgRenderPlace.add(new BoolSetting.Builder() + private final Setting renderPlace = sgRenderPaving.add(new BoolSetting.Builder() .name("render-blocks-to-place") .description("Render blocks to be placed.") .defaultValue(true) .build() ); - private final Setting renderPlaceShape = sgRenderPlace.add(new EnumSetting.Builder() + private final Setting renderPlaceShape = sgRenderPaving.add(new EnumSetting.Builder() .name("blocks-to-place-shape-mode") .description("How the blocks to be placed are rendered.") .defaultValue(ShapeMode.Both) .build() ); - private final Setting renderPlaceSideColor = sgRenderPlace.add(new ColorSetting.Builder() + private final Setting renderPlaceSideColor = sgRenderPaving.add(new ColorSetting.Builder() .name("blocks-to-place-side-color") .description("Color of blocks to be placed.") .defaultValue(new SettingColor(25, 25, 225, 25)) .build() ); - private final Setting renderPlaceLineColor = sgRenderPlace.add(new ColorSetting.Builder() + private final Setting renderPlaceLineColor = sgRenderPaving.add(new ColorSetting.Builder() .name("blocks-to-place-line-color") .description("Color of blocks to be placed.") .defaultValue(new SettingColor(25, 25, 225)) @@ -235,6 +328,7 @@ public enum Rotation { public int blocksBroken, blocksPlaced; private final MBlockPos lastBreakingPos = new MBlockPos(); private boolean displayInfo; + private int placeTimer, breakTimer, count; private final MBlockPos posRender2 = new MBlockPos(); private final MBlockPos posRender3 = new MBlockPos(); @@ -243,6 +337,15 @@ public HighwayBuilder() { super(Categories.World, "highway-builder", "Automatically builds highways."); } + /*todo + - separate digging and paving more effectively + - better inventory management + - getting echests and picks from shulker boxes - refactor echest blockade to be more general purpose? + - access to your ec + - separate walking forwards from the current state to speed up actions + - fix issues related to y level changes + */ + @Override public void onActivate() { dir = HorizontalDirection.get(mc.player.getYaw()); @@ -260,6 +363,15 @@ public void onActivate() { blocksBroken = blocksPlaced = 0; lastBreakingPos.set(0, 0, 0); displayInfo = true; + + placeTimer = 0; + breakTimer = 0; + count = 0; + + if (blocksPerTick.get() > 1 && rotation.get().mine) warning("With rotations enabled, you can break at most 1 block per tick."); + if (placementsPerTick.get() > 1 && rotation.get().place) warning("With rotations enabled, you can place at most 1 block per tick."); + + if (Modules.get().get(InstaMine.class).isActive()) warning("It's recommended to disable the InstaMine module and instead use 'instamine-echests' to avoid errors."); } @Override @@ -301,8 +413,16 @@ private void onTick(TickEvent.Pre event) { if (Modules.get().get(AutoEat.class).eating) return; if (Modules.get().get(AutoGap.class).isEating()) return; + if (Modules.get().get(KillAura.class).attacking) return; + + if (pauseOnLag.get() && TickRate.INSTANCE.getTimeSinceLastTick() >= 2.0f) return; + + count = 0; state.tick(this); + + if (breakTimer > 0) breakTimer--; + if (placeTimer > 0) placeTimer--; } @EventHandler @@ -343,7 +463,7 @@ private void render(Render3DEvent event, MBPIterator it, Predicate pr it.restore(); } - event.renderer.box(posRender2.getMcPos(), sideColor, lineColor, shapeMode, excludeDir); + event.renderer.box(posRender2.getBlockPos(), sideColor, lineColor, shapeMode, excludeDir); } } } @@ -374,11 +494,11 @@ private int getWidthRight() { private boolean canMine(MBlockPos pos, boolean ignoreBlocksToPlace) { BlockState state = pos.getState(); - return BlockUtils.canBreak(pos.getMcPos(), state) && (ignoreBlocksToPlace || !blocksToPlace.get().contains(state.getBlock())); + return BlockUtils.canBreak(pos.getBlockPos(), state) && (ignoreBlocksToPlace || !blocksToPlace.get().contains(state.getBlock())); } private boolean canPlace(MBlockPos pos, boolean liquids) { - return liquids ? !pos.getState().getFluidState().isEmpty() : pos.getState().isAir(); + return liquids ? !pos.getState().getFluidState().isEmpty() : BlockUtils.canPlace(pos.getBlockPos()); } private void disconnect(String message, Object... args) { @@ -408,6 +528,8 @@ protected void tick(HighwayBuilder b) { boolean isZ = Math.abs(z) <= 0.1; if (isX && isZ) { + b.input.stop(); + b.mc.player.setVelocity(0, 0, 0); b.mc.player.setPosition((int) b.mc.player.getX() + (b.mc.player.getX() < 0 ? -0.5 : 0.5), b.mc.player.getY(), (int) b.mc.player.getZ() + (b.mc.player.getZ() < 0 ? -0.5 : 0.5)); b.setState(b.lastState); } @@ -443,16 +565,26 @@ protected void tick(HighwayBuilder b) { Forward { @Override - protected void tick(HighwayBuilder b) { + protected void start(HighwayBuilder b) { b.mc.player.setYaw(b.dir.yaw); + checkTasks(b); + } + + @Override + protected void tick(HighwayBuilder b) { + checkTasks(b); + + if (b.state == Forward) b.input.pressingForward = true; // Move + } + + private void checkTasks(HighwayBuilder b) { if (needsToPlace(b, b.blockPosProvider.getLiquids(), true)) b.setState(FillLiquids); // Fill Liquids else if (needsToMine(b, b.blockPosProvider.getFront(), true)) b.setState(MineFront); // Mine Front else if (b.floor.get() == Floor.Replace && needsToMine(b, b.blockPosProvider.getFloor(), false)) b.setState(MineFloor); // Mine Floor else if (b.railings.get() && needsToMine(b, b.blockPosProvider.getRailings(true), false)) b.setState(MineRailings); // Mine Railings else if (b.railings.get() && needsToPlace(b, b.blockPosProvider.getRailings(false), false)) b.setState(PlaceRailings); // Place Railings else if (needsToPlace(b, b.blockPosProvider.getFloor(), false)) b.setState(PlaceFloor); // Place Floor - else b.input.pressingForward = true; // Move } private boolean needsToMine(HighwayBuilder b, MBPIterator it, boolean ignoreBlocksToPlace) { @@ -485,31 +617,31 @@ protected void tick(HighwayBuilder b) { MineFront { @Override protected void tick(HighwayBuilder b) { - mine(b, b.blockPosProvider.getFront(), true); + mine(b, b.blockPosProvider.getFront(), true, MineFloor, this); } }, MineFloor { @Override - protected void tick(HighwayBuilder b) { - mine(b, b.blockPosProvider.getFloor(), false); + protected void start(HighwayBuilder b) { + mine(b, b.blockPosProvider.getFloor(), false, MineRailings, this); } - }, - PlaceFloor { @Override protected void tick(HighwayBuilder b) { - int slot = findBlocksToPlace(b); - if (slot == -1) return; - - place(b, b.blockPosProvider.getFloor(), slot, Forward); + mine(b, b.blockPosProvider.getFloor(), false, MineRailings, this); } }, MineRailings { + @Override + protected void start(HighwayBuilder b) { + mine(b, b.blockPosProvider.getRailings(true), false, PlaceRailings, this); + } + @Override protected void tick(HighwayBuilder b) { - mine(b, b.blockPosProvider.getRailings(true), false); + mine(b, b.blockPosProvider.getRailings(true), false, PlaceRailings, this); } }, @@ -523,6 +655,24 @@ protected void tick(HighwayBuilder b) { } }, + PlaceFloor { + @Override + protected void start(HighwayBuilder b) { + int slot = findBlocksToPlace(b); + if (slot == -1) return; + + place(b, b.blockPosProvider.getFloor(), slot, Forward); + } + + @Override + protected void tick(HighwayBuilder b) { + int slot = findBlocksToPlace(b); + if (slot == -1) return; + + place(b, b.blockPosProvider.getFloor(), slot, Forward); + } + }, + ThrowOutTrash { private int skipSlot; private boolean timerEnabled, firstTick; @@ -565,6 +715,11 @@ protected void tick(HighwayBuilder b) { return; } + if (!b.mc.player.currentScreenHandler.getCursorStack().isEmpty()) { + InvUtils.dropHand(); + return; + } + for (int i = 0; i < b.mc.player.getInventory().main.size(); i++) { if (i == skipSlot) continue; @@ -600,13 +755,10 @@ protected void tick(HighwayBuilder b) { MineEnderChests { private static final MBlockPos pos = new MBlockPos(); - private int minimumObsidian; - private boolean first; - private int moveTimer; - + private boolean first, primed; private boolean stopTimerEnabled; - private int stopTimer; + private int stopTimer, moveTimer, instamineTimer; @Override protected void start(HighwayBuilder b) { @@ -639,6 +791,7 @@ else if (b.lastState == ThrowOutTrash) { moveTimer = 0; stopTimerEnabled = false; + primed = false; } @Override @@ -682,35 +835,56 @@ protected void tick(HighwayBuilder b) { return; } + BlockPos bp = pos.getBlockPos(); + // Check block state - BlockState blockState = b.mc.world.getBlockState(pos.getMcPos()); + BlockState blockState = b.mc.world.getBlockState(bp); if (blockState.getBlock() == Blocks.ENDER_CHEST) { + if (first) { + moveTimer = 8; + first = false; + return; + } + // Mine ender chest - int slot = findAndMoveBestToolToHotbar(b, blockState, true, false); + int slot = findAndMoveBestToolToHotbar(b, blockState, true); if (slot == -1) { - b.error("Cannot find pickaxe with silk touch to mine ender chests."); + b.error("Cannot find pickaxe without silk touch to mine ender chests."); return; } InvUtils.swap(slot, false); - BlockUtils.breakBlock(pos.getMcPos(), true); + + if (b.instamineEchests.get() && primed) { + if (instamineTimer > 0) { + instamineTimer--; + return; + } + + PlayerActionC2SPacket p = new PlayerActionC2SPacket(PlayerActionC2SPacket.Action.STOP_DESTROY_BLOCK, bp, BlockUtils.getDirection(bp)); + instamineTimer = b.instamineDelay.get(); + + if (b.rotation.get().mine) Rotations.rotate(Rotations.getYaw(bp), Rotations.getPitch(bp), () -> b.mc.getNetworkHandler().sendPacket(p)); + else b.mc.getNetworkHandler().sendPacket(p); + } + else { + if (b.rotation.get().mine) Rotations.rotate(Rotations.getYaw(bp), Rotations.getPitch(bp), () -> BlockUtils.breakBlock(bp, true)); + else BlockUtils.breakBlock(bp, true); + } } else { // Place ender chest int slot = findAndMoveToHotbar(b, itemStack -> itemStack.getItem() == Items.ENDER_CHEST, false); - if (slot == -1) { + if (slot == -1 || countItem(b, stack -> stack.getItem().equals(Items.ENDER_CHEST)) <= b.saveEchests.get()) { stopTimerEnabled = true; stopTimer = 4; return; } - if (first) { - moveTimer = 8; - first = false; - } + if (!first) primed = true; - BlockUtils.place(pos.getMcPos(), Hand.MAIN_HAND, slot, true, 0, true, true, false); + BlockUtils.place(bp, Hand.MAIN_HAND, slot, b.rotation.get().place, 0, true, true, false); } } }; @@ -721,53 +895,69 @@ protected void start(HighwayBuilder b) {} protected void mine(HighwayBuilder b, MBPIterator it, boolean ignoreBlocksToPlace, State nextState, State lastState) { boolean breaking = false; + boolean finishedBreaking = false; // if you can multi break this lets you mine blocks between tasks in a single tick for (MBlockPos pos : it) { + if (b.count >= b.blocksPerTick.get()) return; + if (b.breakTimer > 0) return; + BlockState state = pos.getState(); if (state.isAir() || (!ignoreBlocksToPlace && b.blocksToPlace.get().contains(state.getBlock()))) continue; - int slot = findAndMoveBestToolToHotbar(b, state, false, true); + int slot = findAndMoveBestToolToHotbar(b, state, false); if (slot == -1) return; InvUtils.swap(slot, false); - BlockPos mcPos = pos.getMcPos(); + BlockPos mcPos = pos.getBlockPos(); if (BlockUtils.canBreak(mcPos)) { - if (b.rotation.get().mine) Rotations.rotate(Rotations.getYaw(mcPos), Rotations.getPitch(mcPos), () -> BlockUtils.breakBlock(pos.getMcPos(), true)); + if (b.rotation.get().mine) Rotations.rotate(Rotations.getYaw(mcPos), Rotations.getPitch(mcPos), () -> BlockUtils.breakBlock(mcPos, true)); else BlockUtils.breakBlock(mcPos, true); - breaking = true; + b.breakTimer = b.breakDelay.get(); + if (!b.lastBreakingPos.equals(pos)) { b.lastBreakingPos.set(pos); b.blocksBroken++; } - break; + b.count++; + + // can only multi break if we aren't rotating and the block can be instamined + if (b.blocksPerTick.get() == 1 || !BlockUtils.canInstaBreak(mcPos) || b.rotation.get().mine) break; } + + if (!it.hasNext() && BlockUtils.canInstaBreak(mcPos)) finishedBreaking = true; } - if (!breaking) { + if (finishedBreaking || !breaking) { b.setState(nextState); b.lastState = lastState; } } - protected void mine(HighwayBuilder b, MBPIterator it, boolean ignoreBlocksToPlace) { - mine(b, it, ignoreBlocksToPlace, Forward, b.state); - } protected void place(HighwayBuilder b, MBPIterator it, int slot, State nextState) { boolean placed = false; + boolean finishedPlacing = false; for (MBlockPos pos : it) { - if (BlockUtils.place(pos.getMcPos(), Hand.MAIN_HAND, slot, b.rotation.get().place, 0, true, true, true)) { + if (b.count >= b.placementsPerTick.get()) return; + if (b.placeTimer > 0) return; + + if (BlockUtils.place(pos.getBlockPos(), Hand.MAIN_HAND, slot, b.rotation.get().place, 0, true, true, true)) { placed = true; b.blocksPlaced++; - break; + b.placeTimer = b.placeDelay.get(); + + b.count++; + if (b.placementsPerTick.get() == 1) break; } + + if (!it.hasNext()) finishedPlacing = true; } - if (!placed) b.setState(nextState); + if (finishedPlacing || !placed) b.setState(nextState); } private int findSlot(HighwayBuilder b, Predicate predicate, boolean hotbar) { @@ -781,8 +971,8 @@ private int findSlot(HighwayBuilder b, Predicate predicate, boolean h private int findHotbarSlot(HighwayBuilder b, boolean replaceTools) { int thrashSlot = -1; int slotsWithBlocks = 0; - int slotWithLeastBlocks = 65; - int slowWithLeastBlocksCount = 0; + int slotWithLeastBlocks = -1; + int slotWithLeastBlocksCount = Integer.MAX_VALUE; // Loop hotbar for (int i = 0; i < 9; i++) { @@ -801,8 +991,8 @@ private int findHotbarSlot(HighwayBuilder b, boolean replaceTools) { if (itemStack.getItem() instanceof BlockItem blockItem && b.blocksToPlace.get().contains(blockItem.getBlock())) { slotsWithBlocks++; - if (itemStack.getCount() < slowWithLeastBlocksCount) { - slowWithLeastBlocksCount = itemStack.getCount(); + if (itemStack.getCount() < slotWithLeastBlocksCount) { + slotWithLeastBlocksCount = itemStack.getCount(); slotWithLeastBlocks = i; } } @@ -827,6 +1017,16 @@ private boolean hasItem(HighwayBuilder b, Item item) { return false; } + protected int countItem(HighwayBuilder b, Predicate predicate) { + int count = 0; + for (int i = 0; i < b.mc.player.getInventory().main.size(); i++) { + ItemStack stack = b.mc.player.getInventory().getStack(i); + if (predicate.test(stack)) count += stack.getCount(); + } + + return count; + } + protected int findAndMoveToHotbar(HighwayBuilder b, Predicate predicate, boolean required) { // Check hotbar int slot = findSlot(b, predicate, true); @@ -855,7 +1055,7 @@ protected int findAndMoveToHotbar(HighwayBuilder b, Predicate predica return hotbarSlot; } - protected int findAndMoveBestToolToHotbar(HighwayBuilder b, BlockState blockState, boolean noSilkTouch, boolean error) { + protected int findAndMoveBestToolToHotbar(HighwayBuilder b, BlockState blockState, boolean noSilkTouch) { // Check for creative if (b.mc.player.isCreative()) return b.mc.player.getInventory().selectedSlot; @@ -875,10 +1075,15 @@ protected int findAndMoveBestToolToHotbar(HighwayBuilder b, BlockState blockStat } } - // Stop if not found - if (bestSlot == -1) { - if (error) b.error("Failed to find suitable tool for mining."); - return -1; + if (bestSlot == -1) return b.mc.player.getInventory().selectedSlot; + + if (b.mc.player.getInventory().getStack(bestSlot).getItem() instanceof PickaxeItem ){ + int count = countItem(b, stack -> stack.getItem() instanceof PickaxeItem); + + if (count <= b.savePickaxes.get()) { + b.error("Found less than the selected amount of pickaxes required: " + count + "/" + (b.savePickaxes.get() + 1)); + return -1; + } } // Check if the tool is already in hotbar @@ -899,13 +1104,10 @@ protected int findBlocksToPlace(HighwayBuilder b) { int slot = findAndMoveToHotbar(b, itemStack -> itemStack.getItem() instanceof BlockItem blockItem && b.blocksToPlace.get().contains(blockItem.getBlock()), false); if (slot == -1) { - if (!b.mineEnderChests.get()) { + if (!b.mineEnderChests.get() || !hasItem(b, Items.ENDER_CHEST) || countItem(b, stack -> stack.getItem().equals(Items.ENDER_CHEST)) <= b.saveEchests.get()) { b.error("Out of blocks to place."); } - else { - if (hasItem(b, Items.ENDER_CHEST)) b.setState(MineEnderChests); - else b.error("Out of blocks to place."); - } + else b.setState(MineEnderChests); return -1; } @@ -1171,12 +1373,13 @@ private MBlockPos get(int i) { default -> pos.offset(dir.opposite()); case 1 -> pos.offset(leftDir); case 2 -> pos.offset(rightDir); + case 3 -> pos.offset(dir, 2); }; } @Override public boolean hasNext() { - return i < 3 && y < 2; + return i < 4 && y < 2; } @Override @@ -1464,12 +1667,13 @@ private MBlockPos get(int i) { default -> pos.offset(dir2); case 1 -> pos.offset(dir2.rotateLeftSkipOne()); case 2 -> pos.offset(dir2.rotateLeftSkipOne().opposite()); + case 3 -> pos.offset(dir2.opposite(), 2); }; } @Override public boolean hasNext() { - return i < 3 && y < 2; + return i < 4 && y < 2; } @Override diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/world/NoGhostBlocks.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/world/NoGhostBlocks.java index 8320bae903..e05462d3ae 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/world/NoGhostBlocks.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/world/NoGhostBlocks.java @@ -6,23 +6,50 @@ package meteordevelopment.meteorclient.systems.modules.world; import meteordevelopment.meteorclient.events.entity.player.BreakBlockEvent; +import meteordevelopment.meteorclient.events.entity.player.PlaceBlockEvent; +import meteordevelopment.meteorclient.settings.BoolSetting; +import meteordevelopment.meteorclient.settings.Setting; +import meteordevelopment.meteorclient.settings.SettingGroup; import meteordevelopment.meteorclient.systems.modules.Categories; import meteordevelopment.meteorclient.systems.modules.Module; import meteordevelopment.orbit.EventHandler; import net.minecraft.block.BlockState; public class NoGhostBlocks extends Module { + private final SettingGroup sgGeneral = settings.getDefaultGroup(); + + private final Setting breaking = sgGeneral.add(new BoolSetting.Builder() + .name("breaking") + .description("Whether to apply for block breaking actions.") + .defaultValue(true) + .build() + ); + + public final Setting placing = sgGeneral.add(new BoolSetting.Builder() + .name("placing") + .description("Whether to apply for block placement actions.") + .defaultValue(true) + .build() + ); + public NoGhostBlocks() { - super(Categories.World, "no-ghost-blocks", "Attempts to prevent ghost blocks arising from breaking blocks quickly. Especially useful with multiconnect."); + super(Categories.World, "no-ghost-blocks", "Attempts to prevent ghost blocks arising."); } @EventHandler - public void onBreakBlock(BreakBlockEvent event) { - if (mc.isInSingleplayer()) return; + private void onBreakBlock(BreakBlockEvent event) { + if (mc.isInSingleplayer() || !breaking.get()) return; event.cancel(); BlockState blockState = mc.world.getBlockState(event.blockPos); blockState.getBlock().onBreak(mc.world, event.blockPos, blockState, mc.player); } + + @EventHandler + private void onPlaceBlock(PlaceBlockEvent event) { + if (!placing.get()) return; + + event.cancel(); + } } diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/world/Nuker.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/world/Nuker.java index ff2eff1a99..42801dc61f 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/world/Nuker.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/world/Nuker.java @@ -389,11 +389,11 @@ else if (sortMode.get() != SortMode.None) } // Update timer - if (!firstBlock && !lastBlockPos.equals(blocks.get(0))) { + if (!firstBlock && !lastBlockPos.equals(blocks.getFirst())) { timer = delay.get(); firstBlock = false; - lastBlockPos.set(blocks.get(0)); + lastBlockPos.set(blocks.getFirst()); if (timer > 0) return; } diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/world/PacketMine.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/world/PacketMine.java index 43ec364019..98b8b7091f 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/world/PacketMine.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/world/PacketMine.java @@ -169,7 +169,7 @@ private void onTick(TickEvent.Pre event) { shouldUpdateSlot = false; } - if (!blocks.isEmpty()) blocks.get(0).mine(); + if (!blocks.isEmpty()) blocks.getFirst().mine(); if (!swapped && autoSwitch.get() && (!mc.player.isUsingItem() || !notOnUse.get())) { for (MyBlock block : blocks) { @@ -220,7 +220,7 @@ public MyBlock set(StartBreakingBlockEvent event) { } public boolean shouldRemove() { - boolean remove = mc.world.getBlockState(blockPos).getBlock() != block || Utils.distance(mc.player.getX() - 0.5, mc.player.getY() + mc.player.getEyeHeight(mc.player.getPose()), mc.player.getZ() - 0.5, blockPos.getX() + direction.getOffsetX(), blockPos.getY() + direction.getOffsetY(), blockPos.getZ() + direction.getOffsetZ()) > mc.interactionManager.getReachDistance(); + boolean remove = mc.world.getBlockState(blockPos).getBlock() != block || Utils.distance(mc.player.getX() - 0.5, mc.player.getY() + mc.player.getEyeHeight(mc.player.getPose()), mc.player.getZ() - 0.5, blockPos.getX() + direction.getOffsetX(), blockPos.getY() + direction.getOffsetY(), blockPos.getZ() + direction.getOffsetZ()) > mc.player.getBlockInteractionRange(); if (remove) { mc.getNetworkHandler().sendPacket(new PlayerActionC2SPacket(PlayerActionC2SPacket.Action.ABORT_DESTROY_BLOCK, blockPos, direction)); diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/world/SpawnProofer.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/world/SpawnProofer.java index 0e7354008a..6b586f93c4 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/world/SpawnProofer.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/world/SpawnProofer.java @@ -137,7 +137,7 @@ private void onTickPost(TickEvent.Post event) { // Find lowest light level int lowestLightLevel = 16; - BlockPos.Mutable selectedBlockPos = spawns.get(0); + BlockPos.Mutable selectedBlockPos = spawns.getFirst(); for (BlockPos blockPos : spawns) { int lightLevel = mc.world.getLightLevel(blockPos); @@ -150,7 +150,7 @@ private void onTickPost(TickEvent.Post event) { BlockUtils.place(selectedBlockPos, block, rotate.get(), -50, false); } else { - BlockUtils.place(spawns.get(0), block, rotate.get(), -50, false); + BlockUtils.place(spawns.getFirst(), block, rotate.get(), -50, false); } } diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/world/StashFinder.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/world/StashFinder.java index 92b79a7c65..6e9e89dc9a 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/world/StashFinder.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/world/StashFinder.java @@ -146,7 +146,7 @@ public WWidget getWidget(GuiTheme theme) { WButton clear = list.add(theme.button("Clear")).widget(); WTable table = new WTable(); - if (chunks.size() > 0) list.add(table); + if (!chunks.isEmpty()) list.add(table); clear.action = () -> { chunks.clear(); diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/world/VeinMiner.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/world/VeinMiner.java index ca985ce861..7dc22f6cf0 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/world/VeinMiner.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/world/VeinMiner.java @@ -62,7 +62,7 @@ public class VeinMiner extends Module { private final Setting mode = sgGeneral.add(new EnumSetting.Builder() .name("mode") .description("Selection mode.") - .defaultValue(ListMode.Whitelist) + .defaultValue(ListMode.Blacklist) .build() ); @@ -179,12 +179,12 @@ private void onTick(TickEvent.Pre event) { blocks.removeIf(MyBlock::shouldRemove); if (!blocks.isEmpty()) { - if (tick < delay.get() && !blocks.get(0).mining) { + if (tick < delay.get() && !blocks.getFirst().mining) { tick++; return; } tick = 0; - blocks.get(0).mine(); + blocks.getFirst().mine(); } } @@ -216,7 +216,7 @@ public void set(BlockPos pos, Direction dir) { } public boolean shouldRemove() { - return mc.world.getBlockState(blockPos).getBlock() != originalBlock || Utils.distance(mc.player.getX() - 0.5, mc.player.getY() + mc.player.getEyeHeight(mc.player.getPose()), mc.player.getZ() - 0.5, blockPos.getX() + direction.getOffsetX(), blockPos.getY() + direction.getOffsetY(), blockPos.getZ() + direction.getOffsetZ()) > mc.interactionManager.getReachDistance(); + return mc.world.getBlockState(blockPos).getBlock() != originalBlock || Utils.distance(mc.player.getX() - 0.5, mc.player.getY() + mc.player.getEyeHeight(mc.player.getPose()), mc.player.getZ() - 0.5, blockPos.getX() + direction.getOffsetX(), blockPos.getY() + direction.getOffsetY(), blockPos.getZ() + direction.getOffsetZ()) > mc.player.getBlockInteractionRange(); } public void mine() { @@ -259,7 +259,7 @@ private void mineNearbyBlocks(Item item, BlockPos pos, Direction dir, int depth) if (depth<=0) return; if (foundBlockPositions.contains(pos)) return; foundBlockPositions.add(pos); - if (Utils.distance(mc.player.getX() - 0.5, mc.player.getY() + mc.player.getEyeHeight(mc.player.getPose()), mc.player.getZ() - 0.5, pos.getX(), pos.getY(), pos.getZ()) > mc.interactionManager.getReachDistance()) return; + if (Utils.distance(mc.player.getX() - 0.5, mc.player.getY() + mc.player.getEyeHeight(mc.player.getPose()), mc.player.getZ() - 0.5, pos.getX(), pos.getY(), pos.getZ()) > mc.player.getBlockInteractionRange()) return; for(Vec3i neighbourOffset: blockNeighbours) { BlockPos neighbour = pos.add(neighbourOffset); if (mc.world.getBlockState(neighbour).getBlock().asItem() == item) { diff --git a/src/main/java/meteordevelopment/meteorclient/systems/profiles/Profile.java b/src/main/java/meteordevelopment/meteorclient/systems/profiles/Profile.java index 57fe89ce26..90827196f2 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/profiles/Profile.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/profiles/Profile.java @@ -30,7 +30,6 @@ public class Profile implements ISerializable { public Setting name = sgGeneral.add(new StringSetting.Builder() .name("name") .description("The name of the profile.") - .defaultValue("") .filter(Utils::nameFilter) .build() ); diff --git a/src/main/java/meteordevelopment/meteorclient/systems/profiles/Profiles.java b/src/main/java/meteordevelopment/meteorclient/systems/profiles/Profiles.java index 04ace37373..cbf7b80537 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/profiles/Profiles.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/profiles/Profiles.java @@ -13,6 +13,7 @@ import meteordevelopment.meteorclient.utils.misc.NbtUtils; import meteordevelopment.orbit.EventHandler; import net.minecraft.nbt.NbtCompound; +import org.jetbrains.annotations.NotNull; import java.io.File; import java.util.ArrayList; @@ -76,7 +77,7 @@ public boolean isEmpty() { } @Override - public Iterator iterator() { + public @NotNull Iterator iterator() { return profiles.iterator(); } diff --git a/src/main/java/meteordevelopment/meteorclient/systems/proxies/Proxy.java b/src/main/java/meteordevelopment/meteorclient/systems/proxies/Proxy.java index 0f9ddbe5b5..194b759235 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/proxies/Proxy.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/proxies/Proxy.java @@ -23,7 +23,6 @@ public class Proxy implements ISerializable { public Setting name = sgGeneral.add(new StringSetting.Builder() .name("name") .description("The name of the proxy.") - .defaultValue("") .build() ); @@ -37,7 +36,6 @@ public class Proxy implements ISerializable { public Setting address = sgGeneral.add(new StringSetting.Builder() .name("address") .description("The ip address of the proxy.") - .defaultValue("") .filter(Utils::ipFilter) .build() ); @@ -64,14 +62,12 @@ public class Proxy implements ISerializable { public Setting username = sgOptional.add(new StringSetting.Builder() .name("username") .description("The username of the proxy.") - .defaultValue("") .build() ); public Setting password = sgOptional.add(new StringSetting.Builder() .name("password") .description("The password of the proxy.") - .defaultValue("") .visible(() -> type.get().equals(ProxyType.Socks5)) .build() ); diff --git a/src/main/java/meteordevelopment/meteorclient/systems/waypoints/Waypoints.java b/src/main/java/meteordevelopment/meteorclient/systems/waypoints/Waypoints.java index 2c624f37e9..5c7e74932e 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/waypoints/Waypoints.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/waypoints/Waypoints.java @@ -21,6 +21,7 @@ import net.minecraft.client.texture.NativeImage; import net.minecraft.client.texture.NativeImageBackedTexture; import net.minecraft.nbt.NbtCompound; +import org.jetbrains.annotations.NotNull; import java.io.File; import java.io.FileInputStream; @@ -127,7 +128,7 @@ public boolean isEmpty() { } @Override - public Iterator iterator() { + public @NotNull Iterator iterator() { return waypoints.values().iterator(); } diff --git a/src/main/java/meteordevelopment/meteorclient/utils/ReflectInit.java b/src/main/java/meteordevelopment/meteorclient/utils/ReflectInit.java index 1a2564fefa..402264a9ba 100644 --- a/src/main/java/meteordevelopment/meteorclient/utils/ReflectInit.java +++ b/src/main/java/meteordevelopment/meteorclient/utils/ReflectInit.java @@ -20,6 +20,9 @@ public class ReflectInit { private static final List reflections = new ArrayList<>(); + private ReflectInit() { + } + public static void registerPackages() { add(MeteorClient.ADDON); @@ -46,7 +49,7 @@ public static void init(Class annotation) { Map, List> byClass = initTasks.stream().collect(Collectors.groupingBy(Method::getDeclaringClass)); Set left = new HashSet<>(initTasks); - for (Method m; (m = left.stream().findAny().orElse(null)) != null;) { + for (Method m; (m = left.stream().findAny().orElse(null)) != null; ) { reflectInit(m, annotation, left, byClass); } } @@ -75,13 +78,10 @@ private static void reflectInit(Method task, Class ann private static Class[] getDependencies(Method task, Class annotation) { T init = task.getAnnotation(annotation); - if (init instanceof PreInit pre) { - return pre.dependencies(); - } - else if (init instanceof PostInit post) { - return post.dependencies(); - } - - return new Class[]{}; + return switch (init) { + case PreInit pre -> pre.dependencies(); + case PostInit post -> post.dependencies(); + default -> new Class[]{}; + }; } } diff --git a/src/main/java/meteordevelopment/meteorclient/utils/Utils.java b/src/main/java/meteordevelopment/meteorclient/utils/Utils.java index 35e9dbb004..2cb5525606 100644 --- a/src/main/java/meteordevelopment/meteorclient/utils/Utils.java +++ b/src/main/java/meteordevelopment/meteorclient/utils/Utils.java @@ -9,11 +9,14 @@ import com.mojang.blaze3d.systems.VertexSorter; import it.unimi.dsi.fastutil.objects.Object2IntArrayMap; import it.unimi.dsi.fastutil.objects.Object2IntMap; +import it.unimi.dsi.fastutil.objects.Reference2IntArrayMap; +import it.unimi.dsi.fastutil.objects.Reference2IntMap; import meteordevelopment.meteorclient.MeteorClient; import meteordevelopment.meteorclient.events.world.TickEvent; import meteordevelopment.meteorclient.gui.tabs.TabScreen; import meteordevelopment.meteorclient.mixin.*; import meteordevelopment.meteorclient.mixininterface.IMinecraftClient; +import meteordevelopment.meteorclient.settings.StatusEffectAmplifierMapSetting; import meteordevelopment.meteorclient.systems.modules.Modules; import meteordevelopment.meteorclient.systems.modules.render.BetterTooltips; import meteordevelopment.meteorclient.systems.modules.world.Timer; @@ -33,16 +36,19 @@ import net.minecraft.client.gui.screen.world.SelectWorldScreen; import net.minecraft.client.resource.ResourceReloadLogger; import net.minecraft.client.resource.language.I18n; +import net.minecraft.component.ComponentMap; +import net.minecraft.component.DataComponentTypes; +import net.minecraft.component.type.ItemEnchantmentsComponent; +import net.minecraft.component.type.NbtComponent; import net.minecraft.enchantment.Enchantment; +import net.minecraft.enchantment.EnchantmentHelper; import net.minecraft.entity.Entity; import net.minecraft.entity.effect.StatusEffect; import net.minecraft.item.*; import net.minecraft.nbt.NbtCompound; -import net.minecraft.nbt.NbtElement; import net.minecraft.nbt.NbtList; -import net.minecraft.registry.Registries; +import net.minecraft.registry.entry.RegistryEntry; import net.minecraft.util.DyeColor; -import net.minecraft.util.Identifier; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Vec3d; @@ -57,10 +63,7 @@ import java.io.IOException; import java.io.InputStream; import java.net.InetSocketAddress; -import java.util.Arrays; -import java.util.Iterator; -import java.util.Locale; -import java.util.Random; +import java.util.*; import java.util.regex.Pattern; import java.util.stream.Collectors; @@ -79,6 +82,9 @@ public class Utils { public static Screen screenToOpen; public static VertexSorter vertexSorter; + private Utils() { + } + @PreInit public static void init() { MeteorClient.EVENT_BUS.subscribe(Utils.class); @@ -139,12 +145,12 @@ public static void getEnchantments(ItemStack itemStack, Object2IntMap> itemEnchantments = itemStack.getItem() == Items.ENCHANTED_BOOK + ? itemStack.get(DataComponentTypes.STORED_ENCHANTMENTS).getEnchantments() + : itemStack.getEnchantments().getEnchantments(); - Registries.ENCHANTMENT.getOrEmpty(Identifier.tryParse(tag.getString("id"))).ifPresent((enchantment) -> enchantments.put(enchantment, tag.getInt("lvl"))); + for (RegistryEntry itemEnchantment : itemEnchantments) { + enchantments.put(itemEnchantment.value(), itemStack.getEnchantments().getLevel(itemEnchantment.value())); } } } @@ -207,17 +213,18 @@ public static void getItemsInContainerItem(ItemStack itemStack, ItemStack[] item } Arrays.fill(items, ItemStack.EMPTY); - NbtCompound nbt = itemStack.getNbt(); + ComponentMap components = itemStack.getComponents(); - if (nbt != null && nbt.contains("BlockEntityTag")) { - NbtCompound nbt2 = nbt.getCompound("BlockEntityTag"); + if (components != null && components.contains(DataComponentTypes.BLOCK_ENTITY_DATA)) { + NbtComponent nbt2 = components.get(DataComponentTypes.BLOCK_ENTITY_DATA); if (nbt2.contains("Items")) { - NbtList nbt3 = (NbtList) nbt2.get("Items"); + NbtList nbt3 = (NbtList) nbt2.getNbt().get("Items"); for (int i = 0; i < nbt3.size(); i++) { int slot = nbt3.getCompound(i).getByte("Slot"); // Apparently shulker boxes can store more than 27 items, good job Mojang - if (slot >= 0 && slot < items.length) items[slot] = ItemStack.fromNbt(nbt3.getCompound(i)); + // now NPEs when mc.world == null + if (slot >= 0 && slot < items.length) items[slot] = ItemStack.fromNbtOrEmpty(mc.player.getRegistryManager(), nbt3.getCompound(i)); } } } @@ -238,20 +245,18 @@ public static Color getShulkerColor(ItemStack shulkerItem) { } public static boolean hasItems(ItemStack itemStack) { - NbtCompound compoundTag = itemStack.getSubNbt("BlockEntityTag"); + NbtCompound compoundTag = itemStack.getComponents().getOrDefault(DataComponentTypes.BLOCK_ENTITY_DATA, NbtComponent.DEFAULT).getNbt(); +// itemStack.getComponents().get(DataComponentTypes.CONTAINER).??? return compoundTag != null && compoundTag.contains("Items", 9); } - public static Object2IntMap createStatusEffectMap() { - Object2IntMap map = new Object2IntArrayMap<>(Registries.STATUS_EFFECT.getIds().size()); - - Registries.STATUS_EFFECT.forEach(potion -> map.put(potion, 0)); - - return map; + public static Reference2IntMap createStatusEffectMap() { + return new Reference2IntArrayMap<>(StatusEffectAmplifierMapSetting.EMPTY_STATUS_EFFECT_MAP); } public static String getEnchantSimpleName(Enchantment enchantment, int length) { - return I18n.translate(enchantment.getTranslationKey()).substring(0, length); + String name = I18n.translate(enchantment.getTranslationKey()); + return name.length() > length ? name.substring(0, length) : name; } public static boolean searchTextDefault(String text, String filter, boolean caseSensitive) { @@ -298,9 +303,9 @@ public static int levenshteinDistance(String from, String to, int insCost, int s // Find best route for (int i = 1; i <= textLength; i++) { for (int j = 1; j <= filterLength; j++) { - int sCost = d[i-1][j-1] + (from.charAt(i-1) == to.charAt(j-1) ? 0 : subCost); - int dCost = d[i-1][j] + delCost; - int iCost = d[i][j-1] + insCost; + int sCost = d[i - 1][j - 1] + (from.charAt(i - 1) == to.charAt(j - 1) ? 0 : subCost); + int dCost = d[i - 1][j] + delCost; + int iCost = d[i][j - 1] + insCost; d[i][j] = Math.min(Math.min(dCost, iCost), sCost); } } @@ -490,59 +495,18 @@ public static boolean isThrowable(Item item) { } public static void addEnchantment(ItemStack itemStack, Enchantment enchantment, int level) { - NbtCompound tag = itemStack.getOrCreateNbt(); - NbtList listTag; - - // Get list tag - if (!tag.contains("Enchantments", 9)) { - listTag = new NbtList(); - tag.put("Enchantments", listTag); - } else { - listTag = tag.getList("Enchantments", 10); - } - - // Check if item already has the enchantment and modify the level - String enchId = Registries.ENCHANTMENT.getId(enchantment).toString(); - - for (NbtElement _t : listTag) { - NbtCompound t = (NbtCompound) _t; + ItemEnchantmentsComponent.Builder b = new ItemEnchantmentsComponent.Builder(EnchantmentHelper.getEnchantments(itemStack)); + b.add(enchantment, level); - if (t.getString("id").equals(enchId)) { - t.putShort("lvl", (short) level); - return; - } - } - - // Add the enchantment if it doesn't already have it - NbtCompound enchTag = new NbtCompound(); - enchTag.putString("id", enchId); - enchTag.putShort("lvl", (short) level); - - listTag.add(enchTag); + EnchantmentHelper.set(itemStack, b.build()); } public static void clearEnchantments(ItemStack itemStack) { - NbtCompound nbt = itemStack.getNbt(); - if (nbt != null) nbt.remove("Enchantments"); + EnchantmentHelper.apply(itemStack, components -> components.remove(a -> true)); } public static void removeEnchantment(ItemStack itemStack, Enchantment enchantment) { - NbtCompound nbt = itemStack.getNbt(); - if (nbt == null) return; - - if (!nbt.contains("Enchantments", 9)) return; - NbtList list = nbt.getList("Enchantments", 10); - - String enchId = Registries.ENCHANTMENT.getId(enchantment).toString(); - - for (Iterator it = list.iterator(); it.hasNext();) { - NbtCompound ench = (NbtCompound) it.next(); - - if (ench.getString("id").equals(enchId)) { - it.remove(); - break; - } - } + EnchantmentHelper.apply(itemStack, components -> components.remove(enchantment1 -> enchantment1.value().equals(enchantment))); } public static Color lerp(Color first, Color second, @Range(from = 0, to = 1) float v) { @@ -565,8 +529,7 @@ public static int parsePort(String full) { try { port = Integer.parseInt(full.substring(full.lastIndexOf(':') + 1, full.length() - 1)); - } - catch (NumberFormatException ignored) { + } catch (NumberFormatException ignored) { port = -1; } diff --git a/src/main/java/meteordevelopment/meteorclient/utils/entity/DamageUtils.java b/src/main/java/meteordevelopment/meteorclient/utils/entity/DamageUtils.java index 55479ff535..fe0a0d2855 100644 --- a/src/main/java/meteordevelopment/meteorclient/utils/entity/DamageUtils.java +++ b/src/main/java/meteordevelopment/meteorclient/utils/entity/DamageUtils.java @@ -5,8 +5,8 @@ package meteordevelopment.meteorclient.utils.entity; -import meteordevelopment.meteorclient.mixininterface.IVec3d; import meteordevelopment.meteorclient.utils.entity.fakeplayer.FakePlayerEntity; +import meteordevelopment.meteorclient.utils.player.PlayerUtils; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; import net.minecraft.enchantment.EnchantmentHelper; @@ -27,44 +27,106 @@ import net.minecraft.world.explosion.Explosion; import org.jetbrains.annotations.Nullable; +import java.util.function.BiFunction; + import static meteordevelopment.meteorclient.MeteorClient.mc; +@SuppressWarnings("JavadocReference") public class DamageUtils { + private DamageUtils() { + } + // Explosion damage - public static float explosionDamage(LivingEntity target, Vec3d origin, float power, boolean predictMovement, BlockPos override, BlockState overrideState) { - if (target == null) return 0f; - if (target instanceof PlayerEntity player && EntityUtils.getGameMode(player) == GameMode.CREATIVE && !(player instanceof FakePlayerEntity)) return 0f; + /** + * It is recommended to use this {@link RaycastFactory} unless you implement custom behaviour, as soon:tm: it will be the + * target of optimizations to make it more performant. + * @see BlockView#raycast(RaycastContext) + */ + public static final RaycastFactory HIT_FACTORY = (context, blockPos) -> { + BlockState blockState = mc.world.getBlockState(blockPos); + if (blockState.getBlock().getBlastResistance() < 600) return null; - Vec3d position = predictMovement ? target.getPos().add(target.getVelocity()) : target.getPos(); + return blockState.getCollisionShape(mc.world, blockPos).raycast(context.start(), context.end(), blockPos); + }; - double modDistance = position.distanceTo(origin); - if (modDistance > power) return 0f; + public static float crystalDamage(LivingEntity target, Vec3d targetPos, Box targetBox, Vec3d explosionPos, RaycastFactory raycastFactory) { + return explosionDamage(target, targetPos, targetBox, explosionPos, 12f, raycastFactory); + } - Box box = target.getBoundingBox(); - if (predictMovement) box = box.offset(target.getVelocity()); + public static float bedDamage(LivingEntity target, Vec3d targetPos, Box targetBox, Vec3d explosionPos, RaycastFactory raycastFactory) { + return explosionDamage(target, targetPos, targetBox, explosionPos, 10f, raycastFactory); + } + + public static float anchorDamage(LivingEntity target, Vec3d targetPos, Box targetBox, Vec3d explosionPos, RaycastFactory raycastFactory) { + return explosionDamage(target, targetPos, targetBox, explosionPos, 10f, raycastFactory); + } + + /** + * Low level control of parameters without having to reimplement everything, for addon authors who wish to use their + * own predictions or other systems. + * @see net.minecraft.world.explosion.ExplosionBehavior#calculateDamage(Explosion, Entity) + */ + public static float explosionDamage(LivingEntity target, Vec3d targetPos, Box targetBox, Vec3d explosionPos, float power, RaycastFactory raycastFactory) { + double modDistance = PlayerUtils.distance(targetPos.x, targetPos.y, targetPos.z, explosionPos.x, explosionPos.y, explosionPos.z); + if (modDistance > power) return 0f; - double exposure = getExposure(origin, box, override, overrideState); + double exposure = getExposure(explosionPos, targetBox, raycastFactory); double impact = (1 - (modDistance / power)) * exposure; float damage = (int) ((impact * impact + impact) / 2 * 7 * 12 + 1); return calculateReductions(damage, target, mc.world.getDamageSources().explosion(null)); } + /** Meteor Client implementations */ + public static float crystalDamage(LivingEntity target, Vec3d crystal, boolean predictMovement, BlockPos obsidianPos) { - return explosionDamage(target, crystal, 12f, predictMovement, obsidianPos, Blocks.OBSIDIAN.getDefaultState()); + return overridingExplosionDamage(target, crystal, 12f, predictMovement, obsidianPos, Blocks.OBSIDIAN.getDefaultState()); } public static float crystalDamage(LivingEntity target, Vec3d crystal) { - return explosionDamage(target, crystal, 12f, false, null, null); + return explosionDamage(target, crystal, 12f, false); } public static float bedDamage(LivingEntity target, Vec3d bed) { - return explosionDamage(target, bed, 10f, false, null, null); + return explosionDamage(target, bed, 10f, false); } public static float anchorDamage(LivingEntity target, Vec3d anchor) { - return explosionDamage(target, anchor, 10f, false, BlockPos.ofFloored(anchor), Blocks.AIR.getDefaultState()); + return overridingExplosionDamage(target, anchor, 10f, false, BlockPos.ofFloored(anchor), Blocks.AIR.getDefaultState()); + } + + private static float overridingExplosionDamage(LivingEntity target, Vec3d explosionPos, float power, boolean predictMovement, BlockPos overridePos, BlockState overrideState) { + return explosionDamage(target, explosionPos, power, predictMovement, getOverridingHitFactory(overridePos, overrideState)); + } + + private static float explosionDamage(LivingEntity target, Vec3d explosionPos, float power, boolean predictMovement) { + return explosionDamage(target, explosionPos, power, predictMovement, HIT_FACTORY); + } + + private static float explosionDamage(LivingEntity target, Vec3d explosionPos, float power, boolean predictMovement, RaycastFactory raycastFactory) { + if (target == null) return 0f; + if (target instanceof PlayerEntity player && EntityUtils.getGameMode(player) == GameMode.CREATIVE && !(player instanceof FakePlayerEntity)) return 0f; + + Vec3d position = predictMovement ? target.getPos().add(target.getVelocity()) : target.getPos(); + + Box box = target.getBoundingBox(); + if (predictMovement) box = box.offset(target.getVelocity()); + + return explosionDamage(target, position, box, explosionPos, power, raycastFactory); + } + + public static RaycastFactory getOverridingHitFactory(BlockPos overridePos, BlockState overrideState) { + return (context, blockPos) -> { + BlockState blockState; + if (blockPos.equals(overridePos)) blockState = overrideState; + else { + blockState = mc.world.getBlockState(blockPos); + if (blockState.getBlock().getBlastResistance() < 600) return null; + } + + return blockState.getCollisionShape(mc.world, blockPos).raycast(context.start(), context.end(), blockPos); + }; } // Sword damage @@ -73,11 +135,11 @@ public static float anchorDamage(LivingEntity target, Vec3d anchor) { * @see PlayerEntity#attack(Entity) */ public static float getAttackDamage(LivingEntity attacker, LivingEntity target) { - float itemDamage = (float) EntityAttributeHelper.getAttributeValue(attacker, EntityAttributes.GENERIC_ATTACK_DAMAGE); + float itemDamage = (float) attacker.getAttributeValue(EntityAttributes.GENERIC_ATTACK_DAMAGE); // Get enchant damage ItemStack stack = attacker.getStackInHand(attacker.getActiveHand()); - float enchantDamage = EnchantmentHelper.getAttackDamage(stack, target.getGroup()); + float enchantDamage = EnchantmentHelper.getAttackDamage(stack, target.getType()); // Factor charge if (attacker instanceof PlayerEntity playerEntity) { @@ -96,7 +158,7 @@ public static float getAttackDamage(LivingEntity attacker, LivingEntity target) damage = calculateReductions(damage, target, attacker instanceof PlayerEntity player ? mc.world.getDamageSources().playerAttack(player) : mc.world.getDamageSources().mobAttack(attacker)); // Factor Fire Aspect - if (EnchantmentHelper.getFireAspect(attacker) > 0 && !StatusEffectHelper.hasStatusEffect(target, StatusEffects.FIRE_RESISTANCE)) { + if (EnchantmentHelper.getFireAspect(attacker) > 0 && !target.hasStatusEffect(StatusEffects.FIRE_RESISTANCE)) { damage++; } @@ -108,10 +170,9 @@ public static float getAttackDamage(LivingEntity attacker, LivingEntity target) /** * @see LivingEntity#computeFallDamage(float, float) (float, float, DamageSource) */ - @SuppressWarnings("JavadocReference") public static float fallDamage(LivingEntity entity) { if (entity instanceof PlayerEntity player && player.getAbilities().flying) return 0f; - if (StatusEffectHelper.hasStatusEffect(entity, StatusEffects.SLOW_FALLING) || StatusEffectHelper.hasStatusEffect(entity, StatusEffects.LEVITATION)) return 0f; + if (entity.hasStatusEffect(StatusEffects.SLOW_FALLING) || entity.hasStatusEffect(StatusEffects.LEVITATION)) return 0f; // Fast path - Above the surface int surface = mc.world.getWorldChunk(entity.getBlockPos()).getHeightmap(Heightmap.Type.MOTION_BLOCKING).get(entity.getBlockX() & 15, entity.getBlockZ() & 15); @@ -126,7 +187,7 @@ public static float fallDamage(LivingEntity entity) { private static float fallDamageReductions(LivingEntity entity, int surface) { int fallHeight = (int) (entity.getY() - surface + entity.fallDistance - 3d); - @Nullable StatusEffectInstance jumpBoostInstance = StatusEffectHelper.getStatusEffect(entity, StatusEffects.JUMP_BOOST); + @Nullable StatusEffectInstance jumpBoostInstance = entity.getStatusEffect(StatusEffects.JUMP_BOOST); if (jumpBoostInstance != null) fallHeight -= jumpBoostInstance.getAmplifier() + 1; return calculateReductions(fallHeight, entity, mc.world.getDamageSources().fall()); @@ -134,19 +195,19 @@ private static float fallDamageReductions(LivingEntity entity, int surface) { // Utils - private static float calculateReductions(float damage, LivingEntity entity, DamageSource damageSource) { + /** + * @see LivingEntity#applyDamage(DamageSource, float) + */ + public static float calculateReductions(float damage, LivingEntity entity, DamageSource damageSource) { if (damageSource.isScaledWithDifficulty()) { switch (mc.world.getDifficulty()) { - case PEACEFUL -> { - return 0; - } case EASY -> damage = Math.min(damage / 2 + 1, damage); case HARD -> damage *= 1.5f; } } // Armor reduction - damage = DamageUtil.getDamageLeft(damage, getArmor(entity), (float) EntityAttributeHelper.getAttributeValue(entity, EntityAttributes.GENERIC_ARMOR_TOUGHNESS)); + damage = DamageUtil.getDamageLeft(damage, damageSource, getArmor(entity), (float) entity.getAttributeValue(EntityAttributes.GENERIC_ARMOR_TOUGHNESS)); // Resistance reduction damage = resistanceReduction(entity, damage); @@ -158,14 +219,13 @@ private static float calculateReductions(float damage, LivingEntity entity, Dama } private static float getArmor(LivingEntity entity) { - return (float) Math.floor(EntityAttributeHelper.getAttributeValue(entity, EntityAttributes.GENERIC_ARMOR)); + return (float) Math.floor(entity.getAttributeValue(EntityAttributes.GENERIC_ARMOR)); } /** * @see LivingEntity#modifyAppliedDamage(DamageSource, float) */ - @SuppressWarnings("JavadocReference") - private static float protectionReduction(Entity player, float damage, DamageSource source) { + private static float protectionReduction(LivingEntity player, float damage, DamageSource source) { int protLevel = EnchantmentHelper.getProtectionAmount(player.getArmorItems(), source); return DamageUtil.getInflictedDamage(damage, protLevel); } @@ -173,9 +233,8 @@ private static float protectionReduction(Entity player, float damage, DamageSour /** * @see LivingEntity#modifyAppliedDamage(DamageSource, float) */ - @SuppressWarnings("JavadocReference") private static float resistanceReduction(LivingEntity player, float damage) { - StatusEffectInstance resistance = StatusEffectHelper.getStatusEffect(player, StatusEffects.RESISTANCE); + StatusEffectInstance resistance = player.getStatusEffect(StatusEffects.RESISTANCE); if (resistance != null) { int lvl = resistance.getAmplifier() + 1; damage *= (1 - (lvl * 0.2f)); @@ -187,19 +246,25 @@ private static float resistanceReduction(LivingEntity player, float damage) { /** * @see Explosion#getExposure(Vec3d, Entity) */ - private static float getExposure(Vec3d source, Box box, @Nullable BlockPos override, @Nullable BlockState overrideState) { - double xStep = 1 / ((box.maxX - box.minX) * 2 + 1); - double yStep = 1 / ((box.maxY - box.minY) * 2 + 1); + private static float getExposure(Vec3d source, Box box, RaycastFactory raycastFactory) { + double xDiff = box.maxX - box.minX; + double yDiff = box.maxY - box.minY; + double zDiff = box.maxZ - box.minZ; + + double xStep = 1 / (xDiff * 2 + 1); + double yStep = 1 / (yDiff * 2 + 1); + double zStep = 1 / (zDiff * 2 + 1); - if (xStep > 0 && yStep > 0) { + if (xStep > 0 && yStep > 0 && zStep > 0) { int misses = 0; int hits = 0; - xStep = xStep * (box.maxX - box.minX); - yStep = yStep * (box.maxY - box.minY); + double xOffset = (1 - Math.floor(1 / xStep) * xStep) * 0.5; + double zOffset = (1 - Math.floor(1 / zStep) * zStep) * 0.5; - double xOffset = (1 - Math.floor(1 / xStep) * xStep) / 2; - double zOffset = (1 - Math.floor(1 / yStep) * yStep) / 2; + xStep = xStep * xDiff; + yStep = yStep * yDiff; + zStep = zStep * zDiff; double startX = box.minX + xOffset; double startY = box.minY; @@ -208,14 +273,12 @@ private static float getExposure(Vec3d source, Box box, @Nullable BlockPos overr double endY = box.maxY; double endZ = box.maxZ + zOffset; - Vec3d position = new Vec3d(0, 0, 0); - for (double x = startX; x <= endX; x += xStep) { for (double y = startY; y <= endY; y += yStep) { - for (double z = startZ; z <= endZ; z += xStep) { - ((IVec3d) position).set(x, y, z); + for (double z = startZ; z <= endZ; z += zStep) { + Vec3d position = new Vec3d(x, y, z); - if ((override != null ? raycast(position, source, override, overrideState) : raycast(position, source)) == HitResult.Type.MISS) misses++; + if (raycast(new ExposureRaycastContext(position, source), raycastFactory) == null) misses++; hits++; } @@ -228,31 +291,14 @@ private static float getExposure(Vec3d source, Box box, @Nullable BlockPos overr return 0f; } - /** - * @see BlockView#raycast(RaycastContext) - */ - private static HitResult.Type raycast(Vec3d start, Vec3d end) { - return BlockView.raycast(start, end, null, (_null, blockPos) -> { - BlockState blockState = mc.world.getBlockState(blockPos); - if (blockState.getBlock().getBlastResistance() < 600) return null; - - BlockHitResult hitResult = blockState.getCollisionShape(mc.world, blockPos).raycast(start, end, blockPos); - return hitResult == null ? null : hitResult.getType(); - }, (_null) -> HitResult.Type.MISS); - } + /* Raycasts */ + private static BlockHitResult raycast(ExposureRaycastContext context, RaycastFactory raycastFactory) { + return BlockView.raycast(context.start, context.end, context, raycastFactory, ctx -> null); + } - private static HitResult.Type raycast(Vec3d start, Vec3d end, BlockPos override, BlockState overrideState) { - return BlockView.raycast(start, end, null, (_null, blockPos) -> { - BlockState blockState; - if (blockPos.equals(override)) blockState = overrideState; - else { - blockState = mc.world.getBlockState(blockPos); - if (blockState.getBlock().getBlastResistance() < 600) return null; - } + public record ExposureRaycastContext(Vec3d start, Vec3d end) {} - BlockHitResult hitResult = blockState.getCollisionShape(mc.world, blockPos).raycast(start, end, blockPos); - return hitResult == null ? null : hitResult.getType(); - }, (_null) -> HitResult.Type.MISS); - } + @FunctionalInterface + public interface RaycastFactory extends BiFunction {} } diff --git a/src/main/java/meteordevelopment/meteorclient/utils/entity/EntityAttributeHelper.java b/src/main/java/meteordevelopment/meteorclient/utils/entity/EntityAttributeHelper.java deleted file mode 100644 index 367ce2dcf4..0000000000 --- a/src/main/java/meteordevelopment/meteorclient/utils/entity/EntityAttributeHelper.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * This file is part of the Meteor Client distribution (https://github.com/MeteorDevelopment/meteor-client). - * Copyright (c) Meteor Development. - */ - -package meteordevelopment.meteorclient.utils.entity; - -import com.google.common.collect.Multimap; -import meteordevelopment.meteorclient.mixin.ShulkerEntityAccessor; -import meteordevelopment.meteorclient.mixininterface.IAttributeContainer; -import meteordevelopment.meteorclient.mixininterface.IEntityAttributeInstance; -import net.minecraft.entity.EntityType; -import net.minecraft.entity.EquipmentSlot; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.attribute.*; -import net.minecraft.entity.mob.ShulkerEntity; -import net.minecraft.item.ItemStack; -import org.jetbrains.annotations.Nullable; - -import java.util.function.Function; - -public class EntityAttributeHelper { - /** - * @see LivingEntity#getAttributes() - */ - public static AttributeContainer getAttributes(LivingEntity entity) { - AttributeContainer attributes = new AttributeContainer(getDefaultForEntity(entity)); - - // Equipment - for (var equipmentSlot : EquipmentSlot.values()) { - ItemStack stack = entity.getEquippedStack(equipmentSlot); - attributes.addTemporaryModifiers(stack.getAttributeModifiers(equipmentSlot)); - } - - // Status effects - for (var statusEffect : StatusEffectHelper.getStatusEffects(entity)) { - statusEffect.getEffectType().onApplied(attributes, statusEffect.getAmplifier()); - } - - handleSpecialCases(entity, attributes::getCustomInstance); - - // Copy tracked attributes - ((IAttributeContainer) attributes).meteor$copyFrom(entity.getAttributes()); - - return attributes; - } - - /** - * @see LivingEntity#getAttributeInstance(EntityAttribute) - */ - public static EntityAttributeInstance getAttributeInstance(LivingEntity entity, EntityAttribute attribute) { - double baseValue = getDefaultForEntity(entity).getBaseValue(attribute); - EntityAttributeInstance attributeInstance = new EntityAttributeInstance(attribute, o1 -> {}); - attributeInstance.setBaseValue(baseValue); - - // Equipment - for (var equipmentSlot : EquipmentSlot.values()) { - ItemStack stack = entity.getEquippedStack(equipmentSlot); - Multimap modifiers = stack.getAttributeModifiers(equipmentSlot); - for (var modifier : modifiers.get(attribute)) attributeInstance.addTemporaryModifier(modifier); - } - - // Status effects - for (var statusEffect : StatusEffectHelper.getStatusEffects(entity)) { - AttributeModifierCreator factory = statusEffect.getEffectType().getAttributeModifiers().get(attribute); - if (factory != null) attributeInstance.addPersistentModifier(factory.createAttributeModifier(statusEffect.getAmplifier())); - } - - handleSpecialCases(entity, someAttribute -> someAttribute == attribute ? attributeInstance : null); - - // Copy tracked modifiers - EntityAttributeInstance trackedInstance = entity.getAttributeInstance(attribute); - if (trackedInstance != null) ((IEntityAttributeInstance) attributeInstance).meteor$copyFrom(trackedInstance); - - return attributeInstance; - } - - /** - * @see LivingEntity#getAttributeValue(EntityAttribute) - */ - public static double getAttributeValue(LivingEntity entity, EntityAttribute attribute) { - return getAttributeInstance(entity, attribute).getValue(); - } - - private static void handleSpecialCases(LivingEntity entity, Function consumer) { - if (entity instanceof ShulkerEntity shulkerEntity) { - if (shulkerEntity.getDataTracker().get(ShulkerEntityAccessor.meteor$getPeekAmount()) == 0) { - @Nullable EntityAttributeInstance attributeInstance = consumer.apply(EntityAttributes.GENERIC_ARMOR); - if (attributeInstance != null) attributeInstance.addPersistentModifier(ShulkerEntityAccessor.meteor$getCoveredArmorBonus()); - } - } - } - - @SuppressWarnings("unchecked") - private static DefaultAttributeContainer getDefaultForEntity(T entity) { - return DefaultAttributeRegistry.get((EntityType) entity.getType()); - } -} diff --git a/src/main/java/meteordevelopment/meteorclient/utils/entity/EntityUtils.java b/src/main/java/meteordevelopment/meteorclient/utils/entity/EntityUtils.java index 3fa73c7704..6d74ed13f8 100644 --- a/src/main/java/meteordevelopment/meteorclient/utils/entity/EntityUtils.java +++ b/src/main/java/meteordevelopment/meteorclient/utils/entity/EntityUtils.java @@ -20,7 +20,6 @@ import net.minecraft.block.entity.BlockEntity; import net.minecraft.client.network.PlayerListEntry; import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityGroup; import net.minecraft.entity.EntityType; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.player.PlayerEntity; @@ -44,6 +43,9 @@ public class EntityUtils { private static BlockPos.Mutable testPos = new BlockPos.Mutable(); + private EntityUtils() { + } + public static boolean isAttackable(EntityType type) { return type != EntityType.AREA_EFFECT_CLOUD && type != EntityType.ARROW && type != EntityType.FALLING_BLOCK && type != EntityType.FIREWORK_ROCKET && type != EntityType.ITEM && type != EntityType.LLAMA_SPIT && type != EntityType.SPECTRAL_ARROW && type != EntityType.ENDER_PEARL && type != EntityType.EXPERIENCE_BOTTLE && type != EntityType.POTION && type != EntityType.TRIDENT && type != EntityType.LIGHTNING_BOLT && type != EntityType.FISHING_BOBBER && type != EntityType.EXPERIENCE_ORB && type != EntityType.EGG; } @@ -52,7 +54,7 @@ public static boolean isRideable(EntityType type) { return type == EntityType.MINECART || type == EntityType.BOAT || type == EntityType.CAMEL || type == EntityType.DONKEY || type == EntityType.HORSE || type == EntityType.LLAMA || type == EntityType.MULE || type == EntityType.PIG || type == EntityType.SKELETON_HORSE || type == EntityType.STRIDER || type == EntityType.ZOMBIE_HORSE; } - public static float getTotalHealth(PlayerEntity target) { + public static float getTotalHealth(LivingEntity target) { return target.getHealth() + target.getAbsorptionAmount(); } @@ -124,7 +126,7 @@ public static BlockPos getCityBlock(PlayerEntity player) { Block block = mc.world.getBlockState(testPos).getBlock(); if (block != Blocks.OBSIDIAN && block != Blocks.NETHERITE_BLOCK && block != Blocks.CRYING_OBSIDIAN - && block != Blocks.RESPAWN_ANCHOR && block != Blocks.ANCIENT_DEBRIS) continue; + && block != Blocks.RESPAWN_ANCHOR && block != Blocks.ANCIENT_DEBRIS) continue; double testDistanceSquared = PlayerUtils.squaredDistanceTo(testPos); if (testDistanceSquared < bestDistanceSquared) { @@ -159,8 +161,7 @@ public static Color getColorFromDistance(Entity entity) { if (percent < 0.5) { r = 255; g = (int) (255 * percent / 0.5); // Closer to 0.5, closer to yellow (255,255,0) - } - else { + } else { g = 255; r = 255 - (int) (255 * (percent - 0.5) / 0.5); // Closer to 1.0, closer to green (0,255,0) } @@ -220,8 +221,7 @@ public static boolean intersectsWithEntity(Box box, Predicate predicate) return found.get(); } - public static EntityGroup getGroup(Entity entity) { - if (entity instanceof LivingEntity livingEntity) return livingEntity.getGroup(); - else return EntityGroup.DEFAULT; + public static EntityType getGroup(Entity entity) { + return entity.getType(); } } diff --git a/src/main/java/meteordevelopment/meteorclient/utils/entity/ProjectileEntitySimulator.java b/src/main/java/meteordevelopment/meteorclient/utils/entity/ProjectileEntitySimulator.java index 555c6628ad..1c2b63f2de 100644 --- a/src/main/java/meteordevelopment/meteorclient/utils/entity/ProjectileEntitySimulator.java +++ b/src/main/java/meteordevelopment/meteorclient/utils/entity/ProjectileEntitySimulator.java @@ -10,6 +10,7 @@ import meteordevelopment.meteorclient.mixininterface.IVec3d; import meteordevelopment.meteorclient.utils.Utils; import meteordevelopment.meteorclient.utils.misc.MissHitResult; +import net.minecraft.component.DataComponentTypes; import net.minecraft.entity.Entity; import net.minecraft.entity.projectile.*; import net.minecraft.entity.projectile.thrown.*; @@ -17,10 +18,7 @@ import net.minecraft.fluid.Fluids; import net.minecraft.item.*; import net.minecraft.util.hit.HitResult; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.Box; -import net.minecraft.util.math.MathHelper; -import net.minecraft.util.math.Vec3d; +import net.minecraft.util.math.*; import net.minecraft.world.RaycastContext; import org.joml.Quaterniond; import org.joml.Vector3d; @@ -50,16 +48,16 @@ public boolean set(Entity user, ItemStack itemStack, double simulated, boolean a } else if (item instanceof CrossbowItem) { if (!CrossbowItem.isCharged(itemStack)) return false; - if (CrossbowItem.hasProjectile(itemStack, Items.FIREWORK_ROCKET)) { - set(user, 0, CrossbowItemAccessor.getSpeed(itemStack), simulated, 0, 0.6, accurate, tickDelta); + if (itemStack.get(DataComponentTypes.CHARGED_PROJECTILES).contains(Items.FIREWORK_ROCKET)) { + set(user, 0, CrossbowItemAccessor.getSpeed(itemStack.get(DataComponentTypes.CHARGED_PROJECTILES)), simulated, 0, 0.6, accurate, tickDelta); } - else set(user, 0, CrossbowItemAccessor.getSpeed(itemStack), simulated, 0.05000000074505806, 0.6, accurate, tickDelta); + else set(user, 0, CrossbowItemAccessor.getSpeed(itemStack.get(DataComponentTypes.CHARGED_PROJECTILES)), simulated, 0.05, 0.6, accurate, tickDelta); } else if (item instanceof FishingRodItem) { setFishingBobber(user, tickDelta); } else if (item instanceof TridentItem) { - set(user, 0, 2.5, simulated, 0.05000000074505806, 0.99, accurate, tickDelta); + set(user, 0, 2.5, simulated, 0.05, 0.99, accurate, tickDelta); } else if (item instanceof SnowballItem || item instanceof EggItem || item instanceof EnderPearlItem) { set(user, 0, 1.5, simulated, 0.03, 0.8, accurate, tickDelta); @@ -114,24 +112,30 @@ public void set(Entity user, double roll, double speed, double simulated, double this.waterDrag = waterDrag; } - public boolean set(Entity entity, boolean accurate, double tickDelta) { + public boolean set(Entity entity, boolean accurate) { // skip entities in ground - if (entity instanceof PersistentProjectileEntity && ((ProjectileInGroundAccessor) entity).getInGround()) return false; + if (entity instanceof ProjectileInGroundAccessor ppe && ppe.getInGround()) return false; - if (entity instanceof ArrowEntity arrow) { - // im not sure if arrow.getVelocity().length() is correct but it works ¯\_(ツ)_/¯ - set(entity, arrow.getVelocity().length(), 0.05000000074505806, 0.6, accurate, tickDelta); - } else if (entity instanceof EnderPearlEntity || entity instanceof SnowballEntity || entity instanceof EggEntity) { - set(entity, 1.5, 0.03, 0.8, accurate, tickDelta); + if (entity instanceof ArrowEntity) { + set(entity, 0.05, 0.6, accurate); } else if (entity instanceof TridentEntity) { - set(entity, 2.5, 0.05000000074505806, 0.99, accurate, tickDelta); + set(entity, 0.05, 0.99, accurate); + } + + else if (entity instanceof EnderPearlEntity || entity instanceof SnowballEntity || entity instanceof EggEntity) { + set(entity, 0.03, 0.8, accurate); } else if (entity instanceof ExperienceBottleEntity) { - set(entity, 0.7, 0.07, 0.8, accurate, tickDelta); - } else if (entity instanceof ThrownEntity) { - set(entity, 0.5, 0.05, 0.8, accurate, tickDelta); - } else if (entity instanceof WitherSkullEntity || entity instanceof FireballEntity || entity instanceof DragonFireballEntity) { - set(entity, 0.95, 0, 0.8, accurate, tickDelta); - } else { + set(entity, 0.07, 0.8, accurate); + } else if (entity instanceof PotionEntity) { + set(entity, 0.05, 0.8, accurate); + } + + else if (entity instanceof WitherSkullEntity || entity instanceof FireballEntity || entity instanceof DragonFireballEntity || entity instanceof WindChargeEntity) { + // drag isn't actually 1, but this provides accurate results in 99.9% in of real situations. + set(entity, 0, 1.0, accurate); + this.airDrag = 1.0; + } + else { return false; } @@ -142,9 +146,10 @@ public boolean set(Entity entity, boolean accurate, double tickDelta) { return true; } - public void set(Entity entity, double speed, double gravity, double waterDrag, boolean accurate, double tickDelta) { - Utils.set(pos, entity, tickDelta); + public void set(Entity entity, double gravity, double waterDrag, boolean accurate) { + pos.set(entity.getX(), entity.getY(), entity.getZ()); + double speed = entity.getVelocity().length(); velocity.set(entity.getVelocity().x, entity.getVelocity().y, entity.getVelocity().z).normalize().mul(speed); if (accurate) { @@ -191,12 +196,14 @@ public HitResult tick() { if (pos.y < mc.world.getBottomY()) return MissHitResult.INSTANCE; // Check if chunk is loaded - int chunkX = (int) (pos.x / 16); - int chunkZ = (int) (pos.z / 16); + int chunkX = ChunkSectionPos.getSectionCoord(pos.x); + int chunkZ = ChunkSectionPos.getSectionCoord(pos.z); if (!mc.world.getChunkManager().isChunkLoaded(chunkX, chunkZ)) return MissHitResult.INSTANCE; // Check for collision ((IVec3d) pos3d).set(pos); + if (pos3d.equals(prevPos3d)) return MissHitResult.INSTANCE; + HitResult hitResult = getCollision(); return hitResult.getType() == HitResult.Type.MISS ? null : hitResult; diff --git a/src/main/java/meteordevelopment/meteorclient/utils/entity/SortPriority.java b/src/main/java/meteordevelopment/meteorclient/utils/entity/SortPriority.java index b33d58d52b..835cc78652 100644 --- a/src/main/java/meteordevelopment/meteorclient/utils/entity/SortPriority.java +++ b/src/main/java/meteordevelopment/meteorclient/utils/entity/SortPriority.java @@ -5,10 +5,58 @@ package meteordevelopment.meteorclient.utils.entity; -public enum SortPriority { - LowestDistance, - HighestDistance, - LowestHealth, - HighestHealth, - ClosestAngle +import meteordevelopment.meteorclient.utils.player.PlayerUtils; +import meteordevelopment.meteorclient.utils.player.Rotations; +import net.minecraft.entity.Entity; +import net.minecraft.entity.LivingEntity; + +import java.util.Comparator; + +import static meteordevelopment.meteorclient.MeteorClient.mc; + +public enum SortPriority implements Comparator { + LowestDistance((e1, e2) -> Double.compare(PlayerUtils.squaredDistanceTo(e1), PlayerUtils.squaredDistanceTo(e2))), + HighestDistance((e1, e2) -> Double.compare(PlayerUtils.squaredDistanceTo(e2), PlayerUtils.squaredDistanceTo(e1))), + LowestHealth(SortPriority::sortHealth), + HighestHealth((e1, e2) -> sortHealth(e2, e1)), + ClosestAngle(SortPriority::sortAngle); + + private final Comparator comparator; + + SortPriority(Comparator comparator) { + this.comparator = comparator; + } + + @Override + public int compare(Entity o1, Entity o2) { + return comparator.compare(o1, o2); + } + + private static int sortHealth(Entity e1, Entity e2) { + boolean e1l = e1 instanceof LivingEntity; + boolean e2l = e2 instanceof LivingEntity; + + if (!e1l && !e2l) return 0; + else if (e1l && !e2l) return 1; + else if (!e1l) return -1; + + return Float.compare(((LivingEntity) e1).getHealth(), ((LivingEntity) e2).getHealth()); + } + + private static int sortAngle(Entity e1, Entity e2) { + boolean e1l = e1 instanceof LivingEntity; + boolean e2l = e2 instanceof LivingEntity; + + if (!e1l && !e2l) return 0; + else if (e1l && !e2l) return 1; + else if (!e1l) return -1; + + double e1yaw = Math.abs(Rotations.getYaw(e1) - mc.player.getYaw()); + double e2yaw = Math.abs(Rotations.getYaw(e2) - mc.player.getYaw()); + + double e1pitch = Math.abs(Rotations.getPitch(e1) - mc.player.getPitch()); + double e2pitch = Math.abs(Rotations.getPitch(e2) - mc.player.getPitch()); + + return Double.compare(e1yaw * e1yaw + e1pitch * e1pitch, e2yaw * e2yaw + e2pitch * e2pitch); + } } diff --git a/src/main/java/meteordevelopment/meteorclient/utils/entity/StatusEffectHelper.java b/src/main/java/meteordevelopment/meteorclient/utils/entity/StatusEffectHelper.java deleted file mode 100644 index d809b89c87..0000000000 --- a/src/main/java/meteordevelopment/meteorclient/utils/entity/StatusEffectHelper.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * This file is part of the Meteor Client distribution (https://github.com/MeteorDevelopment/meteor-client). - * Copyright (c) Meteor Development. - */ - -package meteordevelopment.meteorclient.utils.entity; - -import meteordevelopment.meteorclient.utils.entity.effects.EntityEffectCache; -import meteordevelopment.meteorclient.utils.entity.effects.StatusEffectBruteForce; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.effect.StatusEffect; -import net.minecraft.entity.effect.StatusEffectInstance; -import org.jetbrains.annotations.Nullable; - -import java.util.*; - -import static meteordevelopment.meteorclient.MeteorClient.mc; - -public class StatusEffectHelper { - @Nullable - public static StatusEffectInstance getStatusEffect(LivingEntity entity, StatusEffect effect) { - if (entity == mc.player) return entity.getStatusEffect(effect); - EntityEffectCache container = StatusEffectBruteForce.fetch(entity); - return container == null ? null : container.statusEffects.get(effect); - } - - public static boolean hasStatusEffect(LivingEntity entity, StatusEffect effect) { - if (entity == mc.player) return entity.hasStatusEffect(effect); - EntityEffectCache container = StatusEffectBruteForce.fetch(entity); - return container != null && container.statusEffects.containsKey(effect); - } - - public static Collection getStatusEffects(LivingEntity entity) { - if (entity == mc.player) return entity.getStatusEffects(); - EntityEffectCache container = StatusEffectBruteForce.fetch(entity); - return container == null ? List.of() : container.statusEffects.values(); - } - - public static Map getActiveStatusEffects(LivingEntity entity) { - if (entity == mc.player) return entity.getActiveStatusEffects(); - EntityEffectCache container = StatusEffectBruteForce.fetch(entity); - return container == null ? Map.of() : container.statusEffects; - } -} diff --git a/src/main/java/meteordevelopment/meteorclient/utils/entity/TargetUtils.java b/src/main/java/meteordevelopment/meteorclient/utils/entity/TargetUtils.java index b1721767ce..b0426d1fd7 100644 --- a/src/main/java/meteordevelopment/meteorclient/utils/entity/TargetUtils.java +++ b/src/main/java/meteordevelopment/meteorclient/utils/entity/TargetUtils.java @@ -10,12 +10,11 @@ import meteordevelopment.meteorclient.utils.entity.fakeplayer.FakePlayerEntity; import meteordevelopment.meteorclient.utils.entity.fakeplayer.FakePlayerManager; import meteordevelopment.meteorclient.utils.player.PlayerUtils; -import meteordevelopment.meteorclient.utils.player.Rotations; import net.minecraft.entity.Entity; -import net.minecraft.entity.LivingEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.world.GameMode; +import javax.annotation.Nullable; import java.util.ArrayList; import java.util.List; import java.util.function.Predicate; @@ -25,11 +24,15 @@ public class TargetUtils { private static final List ENTITIES = new ArrayList<>(); + private TargetUtils() { + } + + @Nullable public static Entity get(Predicate isGood, SortPriority sortPriority) { ENTITIES.clear(); getList(ENTITIES, isGood, sortPriority, 1); if (!ENTITIES.isEmpty()) { - return ENTITIES.get(0); + return ENTITIES.getFirst(); } return null; @@ -46,10 +49,12 @@ public static void getList(List targetList, Predicate isGood, So if (fp != null && isGood.test(fp)) targetList.add(fp); }); - targetList.sort((e1, e2) -> sort(e1, e2, sortPriority)); - targetList.removeIf(entity -> targetList.indexOf(entity) > maxCount -1); + targetList.sort(sortPriority); + // fast list trimming + for (int i = targetList.size() - 1; i >= maxCount; i--) targetList.remove(i); } + @Nullable public static PlayerEntity getPlayerTarget(double range, SortPriority priority) { if (!Utils.canUpdate()) return null; return (PlayerEntity) get(entity -> { @@ -65,42 +70,4 @@ public static boolean isBadTarget(PlayerEntity target, double range) { if (target == null) return true; return !PlayerUtils.isWithin(target, range) || !target.isAlive() || target.isDead() || target.getHealth() <= 0; } - - private static int sort(Entity e1, Entity e2, SortPriority priority) { - return switch (priority) { - case LowestDistance -> Double.compare(PlayerUtils.squaredDistanceTo(e1), PlayerUtils.squaredDistanceTo(e2)); - case HighestDistance -> Double.compare(PlayerUtils.squaredDistanceTo(e2), PlayerUtils.squaredDistanceTo(e1)); - case LowestHealth -> sortHealth(e1, e2); - case HighestHealth -> sortHealth(e2, e1); - case ClosestAngle -> sortAngle(e1, e2); - }; - } - - private static int sortHealth(Entity e1, Entity e2) { - boolean e1l = e1 instanceof LivingEntity; - boolean e2l = e2 instanceof LivingEntity; - - if (!e1l && !e2l) return 0; - else if (e1l && !e2l) return 1; - else if (!e1l) return -1; - - return Float.compare(((LivingEntity) e1).getHealth(), ((LivingEntity) e2).getHealth()); - } - - private static int sortAngle(Entity e1, Entity e2) { - boolean e1l = e1 instanceof LivingEntity; - boolean e2l = e2 instanceof LivingEntity; - - if (!e1l && !e2l) return 0; - else if (e1l && !e2l) return 1; - else if (!e1l) return -1; - - double e1yaw = Math.abs(Rotations.getYaw(e1) - mc.player.getYaw()); - double e2yaw = Math.abs(Rotations.getYaw(e2) - mc.player.getYaw()); - - double e1pitch = Math.abs(Rotations.getPitch(e1) - mc.player.getPitch()); - double e2pitch = Math.abs(Rotations.getPitch(e2) - mc.player.getPitch()); - - return Double.compare(e1yaw * e1yaw + e1pitch * e1pitch, e2yaw * e2yaw + e2pitch * e2pitch); - } } diff --git a/src/main/java/meteordevelopment/meteorclient/utils/entity/effects/EffectAttributeModifier.java b/src/main/java/meteordevelopment/meteorclient/utils/entity/effects/EffectAttributeModifier.java deleted file mode 100644 index 6245228704..0000000000 --- a/src/main/java/meteordevelopment/meteorclient/utils/entity/effects/EffectAttributeModifier.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * This file is part of the Meteor Client distribution (https://github.com/MeteorDevelopment/meteor-client). - * Copyright (c) Meteor Development. - */ - -package meteordevelopment.meteorclient.utils.entity.effects; - -import net.minecraft.entity.attribute.EntityAttribute; -import net.minecraft.entity.attribute.EntityAttributes; -import net.minecraft.entity.effect.StatusEffect; -import net.minecraft.entity.effect.StatusEffects; - -import java.util.UUID; - -public record EffectAttributeModifier(StatusEffect effect, EntityAttribute attribute, UUID id, double value) { - private static final EffectAttributeModifier SPEED = new EffectAttributeModifier(StatusEffects.SPEED, EntityAttributes.GENERIC_MOVEMENT_SPEED, "91AEAA56-376B-4498-935B-2F7F68070635", 0.20000000298023224d); - private static final EffectAttributeModifier SLOWNESS = new EffectAttributeModifier(StatusEffects.SLOWNESS, EntityAttributes.GENERIC_MOVEMENT_SPEED, "7107DE5E-7CE8-4030-940E-514C1F160890", -0.15000000596046448d); - private static final EffectAttributeModifier HASTE = new EffectAttributeModifier(StatusEffects.HASTE, EntityAttributes.GENERIC_ATTACK_SPEED, "AF8B6E3F-3328-4C0A-AA36-5BA2BB9DBEF3", 0.10000000149011612d); - private static final EffectAttributeModifier MINING_FATIGUE = new EffectAttributeModifier(StatusEffects.MINING_FATIGUE, EntityAttributes.GENERIC_ATTACK_SPEED, "55FCED67-E92A-486E-9800-B47F202C4386", -0.10000000149011612d); - private static final EffectAttributeModifier HEALTH_BOOST = new EffectAttributeModifier(StatusEffects.HEALTH_BOOST, EntityAttributes.GENERIC_MAX_HEALTH, "5D6F0BA2-1186-46AC-B896-C61C5CEE99CC", 4d); - private static final EffectAttributeModifier LUCK = new EffectAttributeModifier(StatusEffects.LUCK, EntityAttributes.GENERIC_LUCK, "03C3C89D-7037-4B42-869F-B146BCB64D2E", 1d); - private static final EffectAttributeModifier UNLUCK = new EffectAttributeModifier(StatusEffects.UNLUCK, EntityAttributes.GENERIC_LUCK, "CC5AF142-2BD2-4215-B636-2605AED11727", -1d); - - public static final EffectAttributeModifier[] ALL = new EffectAttributeModifier[]{SPEED, SLOWNESS, HASTE, MINING_FATIGUE, HEALTH_BOOST, LUCK, UNLUCK}; - public static final EffectAttributeModifier[] BEACON = new EffectAttributeModifier[]{SPEED, HASTE}; - - private EffectAttributeModifier(StatusEffect effect, EntityAttribute attribute, String id, double value) { - this(effect, attribute, UUID.fromString(id), value); - } -} diff --git a/src/main/java/meteordevelopment/meteorclient/utils/entity/effects/EntityEffectCache.java b/src/main/java/meteordevelopment/meteorclient/utils/entity/effects/EntityEffectCache.java deleted file mode 100644 index 77a1993697..0000000000 --- a/src/main/java/meteordevelopment/meteorclient/utils/entity/effects/EntityEffectCache.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * This file is part of the Meteor Client distribution (https://github.com/MeteorDevelopment/meteor-client). - * Copyright (c) Meteor Development. - */ - -package meteordevelopment.meteorclient.utils.entity.effects; - -import it.unimi.dsi.fastutil.objects.Reference2ReferenceOpenHashMap; -import net.minecraft.entity.effect.StatusEffect; -import net.minecraft.entity.effect.StatusEffectInstance; - -import java.util.Map; - -public class EntityEffectCache { - public final Map statusEffects = new Reference2ReferenceOpenHashMap<>(); - public int particleColor; - - public void add(StatusEffect effect, int amplifier) { - statusEffects.put(effect, new StatusEffectInstance(effect, amplifier - 1)); - } - - public void add(StatusEffect effect) { - add(effect, 1); - } -} diff --git a/src/main/java/meteordevelopment/meteorclient/utils/entity/effects/MutableParticleColor.java b/src/main/java/meteordevelopment/meteorclient/utils/entity/effects/MutableParticleColor.java deleted file mode 100644 index 779f5910e2..0000000000 --- a/src/main/java/meteordevelopment/meteorclient/utils/entity/effects/MutableParticleColor.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * This file is part of the Meteor Client distribution (https://github.com/MeteorDevelopment/meteor-client). - * Copyright (c) Meteor Development. - */ - -package meteordevelopment.meteorclient.utils.entity.effects; - -import net.minecraft.entity.effect.StatusEffect; - -import java.util.Objects; - -public class MutableParticleColor { - public static final MutableParticleColor EMPTY = new MutableParticleColor(); - - public float r, g, b; - public int a; - - public void add(StatusEffect effect, int amplifier) { - int color = effect.getColor(); - r += (float)(amplifier * (color >> 16 & 255)) / 255.0F; - g += (float)(amplifier * (color >> 8 & 255)) / 255.0F; - b += (float)(amplifier * (color & 255)) / 255.0F; - a += amplifier; - } - - public void add(StatusEffect effect) { - add(effect, 1); - } - - @Override - public int hashCode() { - return Objects.hash(r, g, b, a); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) return true; - if (obj instanceof MutableParticleColor other) { - return r == other.r && g == other.g && b == other.b && a == other.a; - } - return false; - } -} diff --git a/src/main/java/meteordevelopment/meteorclient/utils/entity/effects/StatusEffectBruteForce.java b/src/main/java/meteordevelopment/meteorclient/utils/entity/effects/StatusEffectBruteForce.java deleted file mode 100644 index 52e5856ce5..0000000000 --- a/src/main/java/meteordevelopment/meteorclient/utils/entity/effects/StatusEffectBruteForce.java +++ /dev/null @@ -1,247 +0,0 @@ -/* - * This file is part of the Meteor Client distribution (https://github.com/MeteorDevelopment/meteor-client). - * Copyright (c) Meteor Development. - */ - -package meteordevelopment.meteorclient.utils.entity.effects; - -import com.google.common.collect.Sets; -import it.unimi.dsi.fastutil.ints.IntObjectImmutablePair; -import it.unimi.dsi.fastutil.ints.IntObjectPair; -import it.unimi.dsi.fastutil.objects.*; -import meteordevelopment.meteorclient.MeteorClient; -import meteordevelopment.meteorclient.events.game.GameLeftEvent; -import meteordevelopment.meteorclient.mixin.LivingEntityAccessor; -import meteordevelopment.meteorclient.systems.config.Config; -import meteordevelopment.meteorclient.utils.PreInit; -import meteordevelopment.meteorclient.utils.entity.StatusEffectHelper; -import meteordevelopment.orbit.EventHandler; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.attribute.AttributeContainer; -import net.minecraft.entity.data.TrackedData; -import net.minecraft.entity.effect.StatusEffect; -import net.minecraft.entity.effect.StatusEffectInstance; -import net.minecraft.entity.effect.StatusEffects; -import net.minecraft.registry.Registries; -import org.jetbrains.annotations.Nullable; - -import java.util.Map; -import java.util.Set; - -/** - * @implNote status effect amplifiers, which are usually zero-indexed, are one-indexed here for ease of maths :thumbs_up: - * @author Crosby - */ -public class StatusEffectBruteForce { - private static final TrackedData POTION_SWIRLS_COLOR = LivingEntityAccessor.meteor$getPotionSwirlsColor(); - private static final TrackedData POTION_SWIRLS_AMBIENT = LivingEntityAccessor.meteor$getPotionSwirlsAmbient(); - private static final int EMPTY_COLOR = 3694022; - public static final Set ALL_ENTRIES = new ReferenceOpenHashSet<>(); - public static final Set BEACON_ENTRIES = new ReferenceOpenHashSet<>(); - private static final Map PLAYER_EFFECT_MAP = new Object2ObjectOpenHashMap<>(); - private static final Object2ObjectMap, Map> EFFECT_CACHE_MAP = new Object2ObjectOpenHashMap<>(); - private static final Set> NULL_COLORS = new ObjectOpenHashSet<>(); - - // status effects - - private static final StatusEffectEntry ABSORPTION = StatusEffectEntry.of(StatusEffects.ABSORPTION, 1); - private static final StatusEffectEntry ABSORPTION_STRONG = StatusEffectEntry.of(StatusEffects.ABSORPTION, 4); - - @PreInit - public static void initEntries() { - MeteorClient.EVENT_BUS.subscribe(StatusEffectHelper.class); - - BEACON_ENTRIES.add(StatusEffectEntry.of(StatusEffects.STRENGTH, 1)); - BEACON_ENTRIES.add(StatusEffectEntry.of(StatusEffects.STRENGTH, 2)); - BEACON_ENTRIES.add(StatusEffectEntry.of(StatusEffects.JUMP_BOOST, 1)); - BEACON_ENTRIES.add(StatusEffectEntry.of(StatusEffects.JUMP_BOOST, 2)); - BEACON_ENTRIES.add(StatusEffectEntry.of(StatusEffects.REGENERATION, 1)); - BEACON_ENTRIES.add(StatusEffectEntry.of(StatusEffects.REGENERATION, 2)); - BEACON_ENTRIES.add(StatusEffectEntry.of(StatusEffects.RESISTANCE, 1)); - BEACON_ENTRIES.add(StatusEffectEntry.of(StatusEffects.RESISTANCE, 2)); - - ALL_ENTRIES.add(StatusEffectEntry.of(StatusEffects.SPEED, 1)); - ALL_ENTRIES.add(StatusEffectEntry.of(StatusEffects.SPEED, 2)); - ALL_ENTRIES.add(StatusEffectEntry.of(StatusEffects.SLOWNESS, 1)); - ALL_ENTRIES.add(StatusEffectEntry.of(StatusEffects.SLOWNESS, 4)); - ALL_ENTRIES.add(StatusEffectEntry.of(StatusEffects.SLOWNESS, 6)); - ALL_ENTRIES.add(StatusEffectEntry.of(StatusEffects.HASTE, 1)); - ALL_ENTRIES.add(StatusEffectEntry.of(StatusEffects.HASTE, 2)); - ALL_ENTRIES.add(StatusEffectEntry.of(StatusEffects.MINING_FATIGUE, 1)); - ALL_ENTRIES.add(StatusEffectEntry.of(StatusEffects.STRENGTH, 1)); - ALL_ENTRIES.add(StatusEffectEntry.of(StatusEffects.STRENGTH, 2)); - ALL_ENTRIES.add(StatusEffectEntry.of(StatusEffects.JUMP_BOOST, 1)); - ALL_ENTRIES.add(StatusEffectEntry.of(StatusEffects.JUMP_BOOST, 2)); - ALL_ENTRIES.add(StatusEffectEntry.of(StatusEffects.NAUSEA, 1)); - ALL_ENTRIES.add(StatusEffectEntry.of(StatusEffects.REGENERATION, 1)); - ALL_ENTRIES.add(StatusEffectEntry.of(StatusEffects.REGENERATION, 2)); - ALL_ENTRIES.add(StatusEffectEntry.of(StatusEffects.RESISTANCE, 1)); - ALL_ENTRIES.add(StatusEffectEntry.of(StatusEffects.RESISTANCE, 2)); - ALL_ENTRIES.add(StatusEffectEntry.of(StatusEffects.FIRE_RESISTANCE, 1)); - ALL_ENTRIES.add(StatusEffectEntry.of(StatusEffects.WATER_BREATHING, 1)); - ALL_ENTRIES.add(StatusEffectEntry.of(StatusEffects.INVISIBILITY, 1)); - ALL_ENTRIES.add(StatusEffectEntry.of(StatusEffects.BLINDNESS, 1)); - ALL_ENTRIES.add(StatusEffectEntry.of(StatusEffects.NIGHT_VISION, 1)); - ALL_ENTRIES.add(StatusEffectEntry.of(StatusEffects.HUNGER, 1)); - ALL_ENTRIES.add(StatusEffectEntry.of(StatusEffects.WEAKNESS, 1)); - ALL_ENTRIES.add(StatusEffectEntry.of(StatusEffects.POISON, 1)); - ALL_ENTRIES.add(StatusEffectEntry.of(StatusEffects.POISON, 2)); - ALL_ENTRIES.add(StatusEffectEntry.of(StatusEffects.WITHER, 1)); - ALL_ENTRIES.add(StatusEffectEntry.of(StatusEffects.HEALTH_BOOST, 1)); - ALL_ENTRIES.add(StatusEffectEntry.of(StatusEffects.GLOWING, 1)); - ALL_ENTRIES.add(StatusEffectEntry.of(StatusEffects.LEVITATION, 1)); - ALL_ENTRIES.add(StatusEffectEntry.of(StatusEffects.LUCK, 1)); - ALL_ENTRIES.add(StatusEffectEntry.of(StatusEffects.UNLUCK, 1)); - ALL_ENTRIES.add(StatusEffectEntry.of(StatusEffects.SLOW_FALLING, 1)); - ALL_ENTRIES.add(StatusEffectEntry.of(StatusEffects.CONDUIT_POWER, 1)); - ALL_ENTRIES.add(StatusEffectEntry.of(StatusEffects.DOLPHINS_GRACE, 1)); - ALL_ENTRIES.add(StatusEffectEntry.of(StatusEffects.BAD_OMEN, 1)); - ALL_ENTRIES.add(StatusEffectEntry.of(StatusEffects.HERO_OF_THE_VILLAGE, 1)); - ALL_ENTRIES.add(StatusEffectEntry.of(StatusEffects.DARKNESS, 1)); - - for (var statusEffectEntry : Registries.STATUS_EFFECT.getEntrySet()) { - if (statusEffectEntry.getValue().isInstant()) continue; - IntObjectPair cacheKey = new IntObjectImmutablePair<>(statusEffectEntry.getValue().getColor(), MutableParticleColor.EMPTY); - EFFECT_CACHE_MAP.put(cacheKey, Map.of(statusEffectEntry.getValue(), new StatusEffectInstance(statusEffectEntry.getValue()))); - - // Primitive modded compat - if (!statusEffectEntry.getKey().getValue().getNamespace().equals("minecraft")) { - ALL_ENTRIES.add(StatusEffectEntry.of(statusEffectEntry.getValue(), 1)); - } - } - } - - /** - * Creates {@link EntityEffectCache} if missing, updates it if required. - */ - public static EntityEffectCache fetch(LivingEntity entity) { - int particleColor = entity.getDataTracker().get(POTION_SWIRLS_COLOR); - if (isEmpty(particleColor)) return null; - EntityEffectCache container = PLAYER_EFFECT_MAP.computeIfAbsent(entity, o -> new EntityEffectCache()); - if (particleColor != container.particleColor) update(particleColor, entity, container); - return container; - } - - private static void update(int particleColor, LivingEntity entity, EntityEffectCache container) { - container.statusEffects.clear(); - container.particleColor = particleColor; - - MutableParticleColor initialColor = new MutableParticleColor(); - Set possibleEntries; - EffectAttributeModifier[] possibleModifiers; - - if (entity.getDataTracker().get(POTION_SWIRLS_AMBIENT)) { // entity is only affected by effects from beacons - possibleEntries = BEACON_ENTRIES; - possibleModifiers = EffectAttributeModifier.BEACON; - } else { - // find status effects based on entity flags - if (entity.isGlowing()) { - initialColor.add(StatusEffects.GLOWING); - container.add(StatusEffects.GLOWING); - } - if (entity.isInvisible()) { - initialColor.add(StatusEffects.INVISIBILITY); - container.add(StatusEffects.INVISIBILITY); - } - - // find status effects based on tracked data - int absorptionLevel = Math.round(entity.getAbsorptionAmount() / 4f); - if (absorptionLevel <= 4) { - possibleEntries = new ReferenceOpenHashSet<>(ALL_ENTRIES); - possibleEntries.add(ABSORPTION_STRONG); - if (absorptionLevel <= 1) possibleEntries.add(ABSORPTION); - } else { - possibleEntries = ALL_ENTRIES; - } - - possibleModifiers = EffectAttributeModifier.ALL; - } - - // find status effects based on tracked attributes - AttributeContainer attributes = entity.getAttributes(); - for (var modifier : possibleModifiers) { - if (attributes.hasModifierForAttribute(modifier.attribute(), modifier.id())) { - double value = attributes.getModifierValue(modifier.attribute(), modifier.id()); - int amplifier = (int) Math.round(value / modifier.value()); - initialColor.add(modifier.effect(), amplifier); - container.add(modifier.effect(), amplifier); - } - } - - // In order to minimize collisions, we hash both the particle color, and the initial state (attributes, tracked data, etc.) via the initial color - IntObjectPair cacheKey = new IntObjectImmutablePair<>(particleColor, initialColor); - - // Map#computeIfAbsent(Object, Function) cannot cache null return values, so we use a separate cache for those - if (NULL_COLORS.contains(cacheKey)) return; - - @Nullable Map match = EFFECT_CACHE_MAP.get(cacheKey); - if (match == null && Config.get().heuristicCombatUtils.get()) { - match = bruteForce(possibleEntries, initialColor, particleColor); - if (match == null) NULL_COLORS.add(cacheKey); - } - - if (match != null) container.statusEffects.putAll(match); - } - - @Nullable - private static Map bruteForce(Set entries, MutableParticleColor initialColor, int particleColor) { - int maxDepth = Config.get().heuristicDepth.get(); - for (int depth = 2; depth <= maxDepth; depth++) { - for (var combination : Sets.combinations(entries, depth)) { - int color = blend(initialColor, combination); - if (color == particleColor) { - // If the amplifiers of all applied effects match, then it cannot be inferred and should be assumed to be 1 - boolean assumeLowestAmplifier = combination.stream().mapToInt(o -> o.amplifier).reduce((i1, i2) -> i1 == i2 ? i1 : -1).orElse(-1) != -1; - - Map map = new Reference2ObjectOpenHashMap<>(); - - for (var entry : combination) { - map.put(entry.effect, new StatusEffectInstance(entry.effect, 0, assumeLowestAmplifier ? 0 : entry.amplifier - 1)); - } - - return map; - } - } - } - return null; - } - - @EventHandler - private static void onLeave(GameLeftEvent event) { - PLAYER_EFFECT_MAP.clear(); - } - - private static boolean isEmpty(int particleColor) { - return particleColor == 0 || particleColor == EMPTY_COLOR; - } - - private static int blend(MutableParticleColor color, Iterable entries) { - float r = color.r; - float g = color.g; - float b = color.b; - int a = color.a; - - for (var entry : entries) { - r += entry.r; - g += entry.g; - b += entry.b; - a += entry.amplifier; - } - - r = r / (float) a * 255.0F; - g = g / (float) a * 255.0F; - b = b / (float) a * 255.0F; - - return (int) r << 16 | (int) g << 8 | (int) b; - } - - public record StatusEffectEntry(StatusEffect effect, int amplifier, float r, float g, float b) { - public static StatusEffectEntry of(StatusEffect effect, int amplifier) { - int color = effect.getColor(); - float r = (float)(amplifier * (color >> 16 & 255)) / 255.0F; - float g = (float)(amplifier * (color >> 8 & 255)) / 255.0F; - float b = (float)(amplifier * (color & 255)) / 255.0F; - return new StatusEffectEntry(effect, amplifier, r, g, b); - } - } -} diff --git a/src/main/java/meteordevelopment/meteorclient/utils/entity/fakeplayer/FakePlayerEntity.java b/src/main/java/meteordevelopment/meteorclient/utils/entity/fakeplayer/FakePlayerEntity.java index 858e65e862..381968a25a 100644 --- a/src/main/java/meteordevelopment/meteorclient/utils/entity/fakeplayer/FakePlayerEntity.java +++ b/src/main/java/meteordevelopment/meteorclient/utils/entity/fakeplayer/FakePlayerEntity.java @@ -6,7 +6,6 @@ package meteordevelopment.meteorclient.utils.entity.fakeplayer; import com.mojang.authlib.GameProfile; -import meteordevelopment.meteorclient.utils.entity.EntityAttributeHelper; import net.minecraft.client.network.OtherClientPlayerEntity; import net.minecraft.client.network.PlayerListEntry; import net.minecraft.entity.player.PlayerEntity; @@ -34,7 +33,7 @@ public FakePlayerEntity(PlayerEntity player, String name, float health, boolean Byte playerModel = player.getDataTracker().get(PlayerEntity.PLAYER_MODEL_PARTS); dataTracker.set(PlayerEntity.PLAYER_MODEL_PARTS, playerModel); - getAttributes().setFrom(EntityAttributeHelper.getAttributes(player)); + getAttributes().setFrom(player.getAttributes()); setPose(player.getPose()); capeX = getX(); diff --git a/src/main/java/meteordevelopment/meteorclient/utils/entity/fakeplayer/FakePlayerManager.java b/src/main/java/meteordevelopment/meteorclient/utils/entity/fakeplayer/FakePlayerManager.java index b05a47c29a..28cb33d22f 100644 --- a/src/main/java/meteordevelopment/meteorclient/utils/entity/fakeplayer/FakePlayerManager.java +++ b/src/main/java/meteordevelopment/meteorclient/utils/entity/fakeplayer/FakePlayerManager.java @@ -17,6 +17,9 @@ public class FakePlayerManager { private static final List ENTITIES = new ArrayList<>(); + private FakePlayerManager() { + } + public static List getFakePlayers() { return ENTITIES; } diff --git a/src/main/java/meteordevelopment/meteorclient/utils/files/StreamUtils.java b/src/main/java/meteordevelopment/meteorclient/utils/files/StreamUtils.java index b6b9c7bd0f..725d76616f 100644 --- a/src/main/java/meteordevelopment/meteorclient/utils/files/StreamUtils.java +++ b/src/main/java/meteordevelopment/meteorclient/utils/files/StreamUtils.java @@ -8,28 +8,22 @@ import java.io.*; public class StreamUtils { - public static void copy(File from, File to) { - try { - InputStream in = new FileInputStream(from); - OutputStream out = new FileOutputStream(to); + private StreamUtils() { + } + public static void copy(File from, File to) { + try (InputStream in = new FileInputStream(from); + OutputStream out = new FileOutputStream(to)) { copy(in, out); - - in.close(); - out.close(); } catch (IOException e) { e.printStackTrace(); } } public static void copy(InputStream in, File to) { - try { - OutputStream out = new FileOutputStream(to); - + try (OutputStream out = new FileOutputStream(to)) { copy(in, out); - in.close(); - out.close(); } catch (IOException e) { e.printStackTrace(); } diff --git a/src/main/java/meteordevelopment/meteorclient/utils/json/UUIDSerializer.java b/src/main/java/meteordevelopment/meteorclient/utils/json/UUIDSerializer.java deleted file mode 100644 index 1366bf5187..0000000000 --- a/src/main/java/meteordevelopment/meteorclient/utils/json/UUIDSerializer.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * This file is part of the Meteor Client distribution (https://github.com/MeteorDevelopment/meteor-client). - * Copyright (c) Meteor Development. - */ - -package meteordevelopment.meteorclient.utils.json; - -import com.google.gson.*; - -import java.lang.reflect.Type; -import java.util.UUID; - -public class UUIDSerializer implements JsonSerializer, JsonDeserializer { - @Override - public JsonElement serialize(UUID src, Type typeOfSrc, JsonSerializationContext context) { - return new JsonPrimitive(src.toString()); - } - - @Override - public UUID deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { - return UUID.fromString(json.getAsString()); - } -} diff --git a/src/main/java/meteordevelopment/meteorclient/utils/misc/CPSUtils.java b/src/main/java/meteordevelopment/meteorclient/utils/misc/CPSUtils.java index ecbc4c056c..23b03a105f 100644 --- a/src/main/java/meteordevelopment/meteorclient/utils/misc/CPSUtils.java +++ b/src/main/java/meteordevelopment/meteorclient/utils/misc/CPSUtils.java @@ -17,6 +17,9 @@ public class CPSUtils { private static int secondsClicking; private static long lastTime; + private CPSUtils() { + } + @PreInit public static void init() { MeteorClient.EVENT_BUS.subscribe(CPSUtils.class); diff --git a/src/main/java/meteordevelopment/meteorclient/utils/misc/FakeClientPlayer.java b/src/main/java/meteordevelopment/meteorclient/utils/misc/FakeClientPlayer.java index 7f5a9e8ab3..db117d1fab 100644 --- a/src/main/java/meteordevelopment/meteorclient/utils/misc/FakeClientPlayer.java +++ b/src/main/java/meteordevelopment/meteorclient/utils/misc/FakeClientPlayer.java @@ -30,6 +30,9 @@ public class FakeClientPlayer { private static UUID lastId; private static boolean needsNewEntry; + private FakeClientPlayer() { + } + @PreInit public static void init() { MeteorClient.EVENT_BUS.subscribe(FakeClientPlayer.class); @@ -41,11 +44,7 @@ public static PlayerEntity getPlayer() { if (player == null || (!id.equals(lastId))) { if (world == null) { world = new ClientWorld( - new ClientPlayNetworkHandler( - mc, - new ClientConnection(NetworkSide.CLIENTBOUND), - new ClientConnectionState(new GameProfile(mc.getSession().getUuidOrNull(), mc.getSession().getUsername()), null, null, null, null, mc.getCurrentServerEntry(), null) - ), // todo test this + new ClientPlayNetworkHandler(mc, new ClientConnection(NetworkSide.CLIENTBOUND), new ClientConnectionState(new GameProfile(mc.getSession().getUuidOrNull(), mc.getSession().getUsername()), null, null, null, null, mc.getCurrentServerEntry(), null, null, null, false)), new ClientWorld.Properties(Difficulty.NORMAL, false, false), world.getRegistryKey(), world.getDimensionEntry(), diff --git a/src/main/java/meteordevelopment/meteorclient/utils/misc/Keybind.java b/src/main/java/meteordevelopment/meteorclient/utils/misc/Keybind.java index 6593b59d50..a1f4f73e11 100644 --- a/src/main/java/meteordevelopment/meteorclient/utils/misc/Keybind.java +++ b/src/main/java/meteordevelopment/meteorclient/utils/misc/Keybind.java @@ -16,21 +16,26 @@ public class Keybind implements ISerializable, ICopyable { private boolean isKey; private int value; + private int modifiers; - private Keybind(boolean isKey, int value) { - set(isKey, value); + private Keybind(boolean isKey, int value, int modifiers) { + set(isKey, value, modifiers); } public static Keybind none() { - return new Keybind(true, -1); + return new Keybind(true, GLFW_KEY_UNKNOWN, 0); } public static Keybind fromKey(int key) { - return new Keybind(true, key); + return new Keybind(true, key, 0); + } + + public static Keybind fromKeys(int key, int modifiers) { + return new Keybind(true, key, modifiers); } public static Keybind fromButton(int button) { - return new Keybind(false, button); + return new Keybind(false, button, 0); } public int getValue() { @@ -38,53 +43,100 @@ public int getValue() { } public boolean isSet() { - return value != -1; + return value != GLFW_KEY_UNKNOWN; } - public boolean canBindTo(boolean isKey, int value) { - if (isKey) return value != GLFW_KEY_ESCAPE; - return value != GLFW_MOUSE_BUTTON_LEFT && value != GLFW_MOUSE_BUTTON_RIGHT; + public boolean isKey() { + return isKey; } - public void set(boolean isKey, int value) { + public boolean hasMods() { + return isKey && modifiers != 0; + } + + public void set(boolean isKey, int value, int modifiers) { this.isKey = isKey; this.value = value; + this.modifiers = modifiers; } @Override public Keybind set(Keybind value) { this.isKey = value.isKey; this.value = value.value; + this.modifiers = value.modifiers; return this; } - public boolean matches(boolean isKey, int value) { - if (this.isKey != isKey) return false; - return this.value == value; + public void reset() { + set(true, GLFW_KEY_UNKNOWN, 0); } - public boolean isValid() { - return value != -1; + public boolean canBindTo(boolean isKey, int value, int modifiers) { + if (isKey) { + if (modifiers != 0 && isKeyMod(value)) return false; + return value != GLFW_KEY_UNKNOWN && value != GLFW_KEY_ESCAPE; + } + return value != GLFW_MOUSE_BUTTON_LEFT && value != GLFW_MOUSE_BUTTON_RIGHT; } - public boolean isKey() { - return isKey; + public boolean matches(boolean isKey, int value, int modifiers) { + if (!this.isSet() || this.isKey != isKey) return false; + if (!hasMods()) return this.value == value; + return this.value == value && this.modifiers == modifiers; } public boolean isPressed() { - return isKey ? Input.isKeyPressed(value) : Input.isButtonPressed(value); + return isKey ? modifiersPressed() && Input.isKeyPressed(value) : Input.isButtonPressed(value); + } + + private boolean modifiersPressed() { + if (!hasMods()) return true; + + if (!isModPressed(GLFW_MOD_CONTROL, GLFW_KEY_LEFT_CONTROL, GLFW_KEY_RIGHT_CONTROL)) return false; + if (!isModPressed(GLFW_MOD_SUPER, GLFW_KEY_LEFT_SUPER, GLFW_KEY_RIGHT_SUPER)) return false; + if (!isModPressed(GLFW_MOD_ALT, GLFW_KEY_LEFT_ALT, GLFW_KEY_RIGHT_ALT)) return false; + if (!isModPressed(GLFW_MOD_SHIFT, GLFW_KEY_LEFT_SHIFT, GLFW_KEY_RIGHT_SHIFT)) return false; + + return true; + } + + private boolean isModPressed(int value, int... keys) { + if ((modifiers & value) == 0) return true; + + for (int key : keys) { + if (Input.isKeyPressed(key)) return true; + } + + return false; + } + + private boolean isKeyMod(int key) { + return key >= GLFW_KEY_LEFT_SHIFT && key <= GLFW_KEY_RIGHT_SUPER; } @Override public Keybind copy() { - return new Keybind(isKey, value); + return new Keybind(isKey, value, modifiers); } @Override public String toString() { - if (value == -1) return "None"; - return isKey ? Utils.getKeyName(value) : Utils.getButtonName(value); + if (!isSet()) return "None"; + if (!isKey) return Utils.getButtonName(value); + if (modifiers == 0) return Utils.getKeyName(value); + + StringBuilder label = new StringBuilder(); + if ((modifiers & GLFW_MOD_CONTROL) != 0) label.append("Ctrl + "); + if ((modifiers & GLFW_MOD_SUPER) != 0) label.append("Cmd + "); + if ((modifiers & GLFW_MOD_ALT) != 0) label.append("Alt + "); + if ((modifiers & GLFW_MOD_SHIFT) != 0) label.append("Shift + "); + if ((modifiers & GLFW_MOD_CAPS_LOCK) != 0) label.append("Caps Lock + "); + if ((modifiers & GLFW_MOD_NUM_LOCK) != 0) label.append("Num Lock + "); + label.append(Utils.getKeyName(value)); + + return label.toString(); } @Override @@ -92,12 +144,12 @@ public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Keybind keybind = (Keybind) o; - return isKey == keybind.isKey && value == keybind.value; + return isKey == keybind.isKey && value == keybind.value && modifiers == keybind.modifiers; } @Override public int hashCode() { - return Objects.hash(isKey, value); + return Objects.hash(isKey, value, modifiers); } // Serialization @@ -108,6 +160,7 @@ public NbtCompound toTag() { tag.putBoolean("isKey", isKey); tag.putInt("value", value); + tag.putInt("modifiers", modifiers); return tag; } @@ -116,6 +169,7 @@ public NbtCompound toTag() { public Keybind fromTag(NbtCompound tag) { isKey = tag.getBoolean("isKey"); value = tag.getInt("value"); + modifiers = tag.getInt("modifiers"); return this; } diff --git a/src/main/java/meteordevelopment/meteorclient/utils/misc/MBlockPos.java b/src/main/java/meteordevelopment/meteorclient/utils/misc/MBlockPos.java index 6ac88ebaa9..5aafaa0aac 100644 --- a/src/main/java/meteordevelopment/meteorclient/utils/misc/MBlockPos.java +++ b/src/main/java/meteordevelopment/meteorclient/utils/misc/MBlockPos.java @@ -51,12 +51,12 @@ public MBlockPos add(int x, int y, int z) { return this; } - public BlockPos getMcPos() { + public BlockPos getBlockPos() { return POS.set(x, y, z); } public BlockState getState() { - return mc.world.getBlockState(getMcPos()); + return mc.world.getBlockState(getBlockPos()); } @Override @@ -78,4 +78,9 @@ public int hashCode() { result = 31 * result + z; return result; } + + @Override + public String toString() { + return this.x + ", " + this.y + ", " + this.z; + } } diff --git a/src/main/java/meteordevelopment/meteorclient/utils/misc/MeteorStarscript.java b/src/main/java/meteordevelopment/meteorclient/utils/misc/MeteorStarscript.java index 6dad1e48ea..238ba347ac 100644 --- a/src/main/java/meteordevelopment/meteorclient/utils/misc/MeteorStarscript.java +++ b/src/main/java/meteordevelopment/meteorclient/utils/misc/MeteorStarscript.java @@ -45,6 +45,7 @@ import net.minecraft.network.packet.c2s.play.ClientStatusC2SPacket; import net.minecraft.registry.Registries; import net.minecraft.registry.RegistryKeys; +import net.minecraft.registry.entry.RegistryEntry; import net.minecraft.stat.Stat; import net.minecraft.stat.Stats; import net.minecraft.util.Identifier; @@ -60,6 +61,7 @@ import java.time.format.DateTimeFormatter; import java.time.format.FormatStyle; import java.util.Arrays; +import java.util.List; import java.util.Optional; import java.util.stream.Collectors; @@ -90,6 +92,7 @@ public static void init() { .set("active_modules", () -> Value.number(Modules.get().getActive().size())) .set("is_module_active", MeteorStarscript::isModuleActive) .set("get_module_info", MeteorStarscript::getModuleInfo) + .set("get_module_setting", MeteorStarscript::getModuleSetting) .set("prefix", MeteorStarscript::getMeteorPrefix) ); @@ -145,6 +148,8 @@ public static void init() { .set("dimension", () -> Value.string(PlayerUtils.getDimension().name())) .set("opposite_dimension", () -> Value.string(PlayerUtils.getDimension().opposite().name())) + .set("gamemode", () -> mc.player != null ? Value.string(StringUtils.capitalize(PlayerUtils.getGameMode().getName())) : Value.null_()) + .set("pos", new ValueMap() .set("_toString", () -> posString(false, false)) .set("x", () -> Value.number(mc.player != null ? mc.player.getX() : 0)) @@ -282,10 +287,10 @@ private static Value hasPotionEffect(Starscript ss, int argCount) { Identifier name = popIdentifier(ss, "First argument to player.has_potion_effect() needs to a string."); - StatusEffect effect = Registries.STATUS_EFFECT.get(name); - if (effect == null) return Value.bool(false); + Optional> effect = Registries.STATUS_EFFECT.getEntry(name); + if (effect.isEmpty()) return Value.bool(false); - StatusEffectInstance effectInstance = mc.player.getStatusEffect(effect); + StatusEffectInstance effectInstance = mc.player.getStatusEffect(effect.get()); return Value.bool(effectInstance != null); } @@ -295,10 +300,10 @@ private static Value getPotionEffect(Starscript ss, int argCount) { Identifier name = popIdentifier(ss, "First argument to player.get_potion_effect() needs to a string."); - StatusEffect effect = Registries.STATUS_EFFECT.get(name); - if (effect == null) return Value.null_(); + Optional> effect = Registries.STATUS_EFFECT.getEntry(name); + if (effect.isEmpty()) return Value.null_(); - StatusEffectInstance effectInstance = mc.player.getStatusEffect(effect); + StatusEffectInstance effectInstance = mc.player.getStatusEffect(effect.get()); if (effectInstance == null) return Value.null_(); return wrap(effectInstance); @@ -348,6 +353,29 @@ private static Value getModuleInfo(Starscript ss, int argCount) { return Value.string(""); } + private static Value getModuleSetting(Starscript ss, int argCount) { + if (argCount != 2) ss.error("meteor.get_module_setting() requires 2 arguments, got %d.", argCount); + + var settingName = ss.popString("Second argument to meteor.get_module_setting() needs to be a string."); + var moduleName = ss.popString("First argument to meteor.get_module_setting() needs to be a string."); + Module module = Modules.get().get(moduleName); + if (module == null) { + ss.error("Unable to get module %s for meteor.get_module_setting()", moduleName); + } + var setting = module.settings.get(settingName); + if (setting == null) { + ss.error("Unable to get setting %s for module %s for meteor.get_module_setting()", settingName, moduleName); + } + var value = setting.get(); + return switch (value) { + case Double d -> Value.number(d); + case Integer i -> Value.number(i); + case Boolean b -> Value.bool(b); + case List list -> Value.number(list.size()); + case null, default -> Value.string(value.toString()); + }; + } + private static Value isModuleActive(Starscript ss, int argCount) { if (argCount != 1) ss.error("meteor.is_module_active() requires 1 argument, got %d.", argCount); diff --git a/src/main/java/meteordevelopment/meteorclient/utils/misc/MyPotion.java b/src/main/java/meteordevelopment/meteorclient/utils/misc/MyPotion.java index d4b463a1c1..47187497ba 100644 --- a/src/main/java/meteordevelopment/meteorclient/utils/misc/MyPotion.java +++ b/src/main/java/meteordevelopment/meteorclient/utils/misc/MyPotion.java @@ -5,12 +5,13 @@ package meteordevelopment.meteorclient.utils.misc; +import net.minecraft.component.type.PotionContentsComponent; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; import net.minecraft.potion.Potion; -import net.minecraft.potion.PotionUtil; import net.minecraft.potion.Potions; +import net.minecraft.registry.entry.RegistryEntry; public enum MyPotion { Swiftness(Potions.SWIFTNESS, Items.NETHER_WART, Items.SUGAR), @@ -68,8 +69,8 @@ public enum MyPotion { public final ItemStack potion; public final Item[] ingredients; - MyPotion(Potion potion, Item... ingredients) { - this.potion = PotionUtil.setPotion(new ItemStack(Items.POTION), potion); + MyPotion(RegistryEntry potion, Item... ingredients) { + this.potion = PotionContentsComponent.createStack(Items.POTION, potion); this.ingredients = ingredients; } } diff --git a/src/main/java/meteordevelopment/meteorclient/utils/misc/Names.java b/src/main/java/meteordevelopment/meteorclient/utils/misc/Names.java index b8f0d611d8..cd84260b38 100644 --- a/src/main/java/meteordevelopment/meteorclient/utils/misc/Names.java +++ b/src/main/java/meteordevelopment/meteorclient/utils/misc/Names.java @@ -18,13 +18,13 @@ import net.minecraft.entity.effect.StatusEffect; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NbtElement; import net.minecraft.particle.ParticleEffect; import net.minecraft.particle.ParticleType; +import net.minecraft.registry.Registries; import net.minecraft.text.Text; import net.minecraft.util.Identifier; import net.minecraft.util.StringHelper; -import org.apache.commons.lang3.text.WordUtils; +import org.apache.commons.lang3.StringUtils; import java.util.HashMap; import java.util.Map; @@ -40,6 +40,9 @@ public class Names { private static final Map, String> particleTypesNames = new Reference2ObjectOpenHashMap<>(64); private static final Map soundNames = new HashMap<>(64); + private Names() { + } + @PreInit public static void init() { MeteorClient.EVENT_BUS.subscribe(Names.class); @@ -78,7 +81,7 @@ public static String get(EntityType entityType) { public static String get(ParticleType type) { if (!(type instanceof ParticleEffect)) return ""; - return particleTypesNames.computeIfAbsent(type, effect1 -> WordUtils.capitalize(((ParticleEffect) effect1).asString().substring(10).replace("_", " "))); + return particleTypesNames.computeIfAbsent(type, effect1 -> StringUtils.capitalize(Registries.PARTICLE_TYPE.getId(type).getPath().replace("_", " "))); } public static String getSoundName(Identifier id) { @@ -94,6 +97,6 @@ public static String getSoundName(Identifier id) { } public static String get(ItemStack stack) { - return stack.hasNbt() && stack.getNbt().contains("display", NbtElement.COMPOUND_TYPE) ? stack.getName().getString() : I18n.translate(stack.getTranslationKey()); + return stack.getName().getString(); // pretty sure this is the same as it was } } diff --git a/src/main/java/meteordevelopment/meteorclient/utils/misc/NbtUtils.java b/src/main/java/meteordevelopment/meteorclient/utils/misc/NbtUtils.java index 1b266d7fee..28335fadf0 100644 --- a/src/main/java/meteordevelopment/meteorclient/utils/misc/NbtUtils.java +++ b/src/main/java/meteordevelopment/meteorclient/utils/misc/NbtUtils.java @@ -18,6 +18,9 @@ import static meteordevelopment.meteorclient.MeteorClient.mc; public class NbtUtils { + private NbtUtils() { + } + public static > NbtList listToTag(Iterable list) { NbtList tag = new NbtList(); for (T item : list) tag.add(item.toTag()); diff --git a/src/main/java/meteordevelopment/meteorclient/utils/misc/Pool.java b/src/main/java/meteordevelopment/meteorclient/utils/misc/Pool.java index ec391a072b..a97025b955 100644 --- a/src/main/java/meteordevelopment/meteorclient/utils/misc/Pool.java +++ b/src/main/java/meteordevelopment/meteorclient/utils/misc/Pool.java @@ -17,7 +17,7 @@ public Pool(Producer producer) { } public synchronized T get() { - if (items.size() > 0) return items.poll(); + if (!items.isEmpty()) return items.poll(); return producer.create(); } diff --git a/src/main/java/meteordevelopment/meteorclient/utils/misc/input/Input.java b/src/main/java/meteordevelopment/meteorclient/utils/misc/input/Input.java index bf6f332e60..c556ae32b5 100644 --- a/src/main/java/meteordevelopment/meteorclient/utils/misc/input/Input.java +++ b/src/main/java/meteordevelopment/meteorclient/utils/misc/input/Input.java @@ -6,6 +6,7 @@ package meteordevelopment.meteorclient.utils.misc.input; import meteordevelopment.meteorclient.gui.GuiKeyEvents; +import meteordevelopment.meteorclient.mixin.KeyBindingAccessor; import meteordevelopment.meteorclient.utils.misc.CursorStyle; import net.minecraft.client.option.KeyBinding; import org.lwjgl.glfw.GLFW; @@ -18,6 +19,9 @@ public class Input { private static CursorStyle lastCursorStyle = CursorStyle.Default; + private Input() { + } + public static void setKeyState(int key, boolean pressed) { if (key >= 0 && key < keys.length) keys[key] = pressed; } @@ -26,12 +30,16 @@ public static void setButtonState(int button, boolean pressed) { if (button >= 0 && button < buttons.length) buttons[button] = pressed; } + public static int getKey(KeyBinding bind) { + return ((KeyBindingAccessor) bind).getKey().getCode(); + } + public static void setKeyState(KeyBinding bind, boolean pressed) { - setKeyState(KeyBinds.getKey(bind), pressed); + setKeyState(getKey(bind), pressed); } public static boolean isPressed(KeyBinding bind) { - return isKeyPressed(KeyBinds.getKey(bind)); + return isKeyPressed(getKey(bind)); } public static boolean isKeyPressed(int key) { diff --git a/src/main/java/meteordevelopment/meteorclient/utils/misc/input/KeyAction.java b/src/main/java/meteordevelopment/meteorclient/utils/misc/input/KeyAction.java index c9e6fda19e..33533f23d5 100644 --- a/src/main/java/meteordevelopment/meteorclient/utils/misc/input/KeyAction.java +++ b/src/main/java/meteordevelopment/meteorclient/utils/misc/input/KeyAction.java @@ -13,8 +13,10 @@ public enum KeyAction { Release; public static KeyAction get(int action) { - if (action == GLFW.GLFW_PRESS) return Press; - else if (action == GLFW.GLFW_RELEASE) return Release; - else return Repeat; + return switch (action) { + case GLFW.GLFW_PRESS -> Press; + case GLFW.GLFW_RELEASE -> Release; + default -> Repeat; + }; } } diff --git a/src/main/java/meteordevelopment/meteorclient/utils/misc/text/ColoredText.java b/src/main/java/meteordevelopment/meteorclient/utils/misc/text/ColoredText.java index e7cb34cc20..e85d040a61 100644 --- a/src/main/java/meteordevelopment/meteorclient/utils/misc/text/ColoredText.java +++ b/src/main/java/meteordevelopment/meteorclient/utils/misc/text/ColoredText.java @@ -7,38 +7,8 @@ import meteordevelopment.meteorclient.utils.render.color.Color; -import java.util.Objects; - /** * Encapsulates a string and the color it should have. See {@link TextUtils} */ -public class ColoredText { - private final String text; - private final Color color; - - public ColoredText(String text, Color color) { - this.text = text; - this.color = color; - } - - public String getText() { - return text; - } - - public Color getColor() { - return color; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - ColoredText that = (ColoredText) o; - return text.equals(that.text) && color.equals(that.color); - } - - @Override - public int hashCode() { - return Objects.hash(text, color); - } +public record ColoredText(String text, Color color) { } diff --git a/src/main/java/meteordevelopment/meteorclient/utils/misc/text/RunnableClickEvent.java b/src/main/java/meteordevelopment/meteorclient/utils/misc/text/RunnableClickEvent.java new file mode 100644 index 0000000000..706b8d1592 --- /dev/null +++ b/src/main/java/meteordevelopment/meteorclient/utils/misc/text/RunnableClickEvent.java @@ -0,0 +1,19 @@ +/* + * This file is part of the Meteor Client distribution (https://github.com/MeteorDevelopment/meteor-client). + * Copyright (c) Meteor Development. + */ + +package meteordevelopment.meteorclient.utils.misc.text; + +/** + * Allows arbitrary code execution in a click event + * @see + */ +public class RunnableClickEvent extends MeteorClickEvent { + public final Runnable runnable; + + public RunnableClickEvent(Runnable runnable) { + super(null, null); // Should ensure no vanilla code is triggered, and only we handle it + this.runnable = runnable; + } +} diff --git a/src/main/java/meteordevelopment/meteorclient/utils/misc/text/StringCharacterVisitor.java b/src/main/java/meteordevelopment/meteorclient/utils/misc/text/StringCharacterVisitor.java deleted file mode 100644 index a317401189..0000000000 --- a/src/main/java/meteordevelopment/meteorclient/utils/misc/text/StringCharacterVisitor.java +++ /dev/null @@ -1,20 +0,0 @@ -/* - * This file is part of the Meteor Client distribution (https://github.com/MeteorDevelopment/meteor-client). - * Copyright (c) Meteor Development. - */ - -package meteordevelopment.meteorclient.utils.misc.text; - -import net.minecraft.text.CharacterVisitor; -import net.minecraft.text.Style; - -public class StringCharacterVisitor implements CharacterVisitor { - - public StringBuilder result = new StringBuilder(); - - @Override - public boolean accept(int index, Style style, int j) { - result.append((char)j); - return true; - } -} diff --git a/src/main/java/meteordevelopment/meteorclient/utils/misc/text/TextUtils.java b/src/main/java/meteordevelopment/meteorclient/utils/misc/text/TextUtils.java index a89ab36e81..0a102348a8 100644 --- a/src/main/java/meteordevelopment/meteorclient/utils/misc/text/TextUtils.java +++ b/src/main/java/meteordevelopment/meteorclient/utils/misc/text/TextUtils.java @@ -19,11 +19,14 @@ * Some utilities for {@link Text} */ public class TextUtils { + private TextUtils() { + } + public static List toColoredTextList(Text text) { - Stack stack = new Stack<>(); + Deque stack = new ArrayDeque<>(); List coloredTexts = new ArrayList<>(); preOrderTraverse(text, stack, coloredTexts); - coloredTexts.removeIf(e -> e.getText().isEmpty()); + coloredTexts.removeIf(e -> e.text().isEmpty()); return coloredTexts; } @@ -70,12 +73,12 @@ public static Object2IntMap getColoredCharacterCount(List co Object2IntMap colorCount = new Object2IntOpenHashMap<>(); for (ColoredText coloredText : coloredTexts) { - if (colorCount.containsKey(coloredText.getColor())) { + if (colorCount.containsKey(coloredText.color())) { // Since color was already catalogued, simply update the record by adding the length of the new text segment to the old one - colorCount.put(coloredText.getColor(), colorCount.getInt(coloredText.getColor()) + coloredText.getText().length()); + colorCount.put(coloredText.color(), colorCount.getInt(coloredText.color()) + coloredText.text().length()); } else { // Add new entry to the hashmap - colorCount.put(coloredText.getColor(), coloredText.getText().length()); + colorCount.put(coloredText.color(), coloredText.text().length()); } } @@ -90,7 +93,7 @@ public static Object2IntMap getColoredCharacterCount(List co * @param stack An empty stack. This is used by the recursive algorithm to keep track of the parents of the current iteration * @param coloredTexts The list of colored text to return */ - private static void preOrderTraverse(Text text, Stack stack, List coloredTexts) { + private static void preOrderTraverse(Text text, Deque stack, List coloredTexts) { if (text == null) return; @@ -105,12 +108,12 @@ private static void preOrderTraverse(Text text, Stack stack, List(HttpRequest request) implements HttpResponse { + @Override + public int statusCode() { + return Http.BAD_REQUEST; + } + + @Override + public Optional> previousResponse() { + return Optional.empty(); + } + + @Override + public HttpHeaders headers() { + return HttpHeaders.of(Map.of(), (s1, s2) -> true); + } + + @Override + public T body() { + return null; + } + + @Override + public Optional sslSession() { + return Optional.empty(); + } + + @Override + public URI uri() { + return this.request.uri(); + } + + @Nullable + @Override + public HttpClient.Version version() { + return this.request.version().orElse(null); + } +} diff --git a/src/main/java/meteordevelopment/meteorclient/utils/network/Http.java b/src/main/java/meteordevelopment/meteorclient/utils/network/Http.java index 24fec46abe..c581e5f715 100644 --- a/src/main/java/meteordevelopment/meteorclient/utils/network/Http.java +++ b/src/main/java/meteordevelopment/meteorclient/utils/network/Http.java @@ -9,9 +9,9 @@ import com.google.gson.GsonBuilder; import meteordevelopment.meteorclient.utils.other.JsonDateDeserializer; +import javax.annotation.Nullable; import java.io.IOException; import java.io.InputStream; -import java.io.InputStreamReader; import java.lang.reflect.Type; import java.net.URI; import java.net.URISyntaxException; @@ -22,6 +22,12 @@ import java.util.stream.Stream; public class Http { + public static final int SUCCESS = 200; + public static final int BAD_REQUEST = 400; + public static final int UNAUTHORIZED = 401; + public static final int FORBIDDEN = 403; + public static final int NOT_FOUND = 404; + private static final HttpClient CLIENT = HttpClient.newHttpClient(); private static final Gson GSON = new GsonBuilder() @@ -34,18 +40,24 @@ private enum Method { } public static class Request { - private HttpRequest.Builder builder; + private final HttpRequest.Builder builder; private Method method; - public Request(Method method, String url) { + private Request(Method method, String url) { try { this.builder = HttpRequest.newBuilder().uri(new URI(url)).header("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36"); this.method = method; } catch (URISyntaxException e) { - e.printStackTrace(); + throw new IllegalArgumentException(e); } } + public Request header(String name, String value) { + builder.header(name, value); + + return this; + } + public Request bearer(String token) { builder.header("Authorization", "Bearer " + token); @@ -84,38 +96,68 @@ public Request bodyJson(Object object) { return this; } - private T _send(String accept, HttpResponse.BodyHandler responseBodyHandler) { + private HttpResponse _sendResponse(String accept, HttpResponse.BodyHandler responseBodyHandler) { builder.header("Accept", accept); if (method != null) builder.method(method.name(), HttpRequest.BodyPublishers.noBody()); + HttpRequest request = builder.build(); + try { - var res = CLIENT.send(builder.build(), responseBodyHandler); - return res.statusCode() == 200 ? res.body() : null; + return CLIENT.send(request, responseBodyHandler); } catch (IOException | InterruptedException e) { e.printStackTrace(); - return null; + return new FailedHttpResponse<>(request); } } + @Nullable + private T _send(String accept, HttpResponse.BodyHandler responseBodyHandler) { + HttpResponse res = _sendResponse(accept, responseBodyHandler); + return res.statusCode() == 200 ? res.body() : null; + } + public void send() { _send("*/*", HttpResponse.BodyHandlers.discarding()); } + public HttpResponse sendResponse() { + return _sendResponse("*/*", HttpResponse.BodyHandlers.discarding()); + } + + @Nullable public InputStream sendInputStream() { return _send("*/*", HttpResponse.BodyHandlers.ofInputStream()); } + public HttpResponse sendInputStreamResponse() { + return _sendResponse("*/*", HttpResponse.BodyHandlers.ofInputStream()); + } + + @Nullable public String sendString() { return _send("*/*", HttpResponse.BodyHandlers.ofString()); } + public HttpResponse sendStringResponse() { + return _sendResponse("*/*", HttpResponse.BodyHandlers.ofString()); + } + + @Nullable public Stream sendLines() { return _send("*/*", HttpResponse.BodyHandlers.ofLines()); } + public HttpResponse> sendLinesResponse() { + return _sendResponse("*/*", HttpResponse.BodyHandlers.ofLines()); + } + + @Nullable public T sendJson(Type type) { - InputStream in = _send("application/json", HttpResponse.BodyHandlers.ofInputStream()); - return in == null ? null : GSON.fromJson(new InputStreamReader(in), type); + return _send("application/json", JsonBodyHandler.ofJson(GSON, type)); + } + + public HttpResponse sendJsonResponse(Type type) { + return _sendResponse("*/*", JsonBodyHandler.ofJson(GSON, type)); } } diff --git a/src/main/java/meteordevelopment/meteorclient/utils/network/JsonBodyHandler.java b/src/main/java/meteordevelopment/meteorclient/utils/network/JsonBodyHandler.java new file mode 100644 index 0000000000..82a19411e0 --- /dev/null +++ b/src/main/java/meteordevelopment/meteorclient/utils/network/JsonBodyHandler.java @@ -0,0 +1,48 @@ +/* + * This file is part of the Meteor Client distribution (https://github.com/MeteorDevelopment/meteor-client). + * Copyright (c) Meteor Development. + */ + +package meteordevelopment.meteorclient.utils.network; + +import com.google.gson.Gson; + +import java.io.InputStream; +import java.io.InputStreamReader; +import java.lang.reflect.Type; +import java.net.http.HttpResponse; +import java.nio.ByteBuffer; +import java.util.List; +import java.util.concurrent.CompletionStage; +import java.util.concurrent.Flow; + +public record JsonBodyHandler(HttpResponse.BodySubscriber delegate, Gson gson, Type type) implements HttpResponse.BodySubscriber { + public static HttpResponse.BodyHandler ofJson(Gson gson, Type type) { + return responseInfo -> new JsonBodyHandler<>(HttpResponse.BodySubscribers.ofInputStream(), gson, type); + } + + @Override + public CompletionStage getBody() { + return this.delegate.getBody().thenApply(in -> in == null ? null : gson.fromJson(new InputStreamReader(in), type)); + } + + @Override + public void onSubscribe(Flow.Subscription subscription) { + this.delegate.onSubscribe(subscription); + } + + @Override + public void onNext(List item) { + this.delegate.onNext(item); + } + + @Override + public void onError(Throwable throwable) { + this.delegate.onError(throwable); + } + + @Override + public void onComplete() { + this.delegate.onComplete(); + } +} diff --git a/src/main/java/meteordevelopment/meteorclient/utils/network/MeteorExecutor.java b/src/main/java/meteordevelopment/meteorclient/utils/network/MeteorExecutor.java index d1ec0d8071..33b14478e9 100644 --- a/src/main/java/meteordevelopment/meteorclient/utils/network/MeteorExecutor.java +++ b/src/main/java/meteordevelopment/meteorclient/utils/network/MeteorExecutor.java @@ -14,6 +14,9 @@ public class MeteorExecutor { public static ExecutorService executor; + private MeteorExecutor() { + } + @PreInit public static void init() { AtomicInteger threadNumber = new AtomicInteger(1); diff --git a/src/main/java/meteordevelopment/meteorclient/utils/network/PacketUtils.java b/src/main/java/meteordevelopment/meteorclient/utils/network/PacketUtils.java index f20229eda3..37e406956c 100644 --- a/src/main/java/meteordevelopment/meteorclient/utils/network/PacketUtils.java +++ b/src/main/java/meteordevelopment/meteorclient/utils/network/PacketUtils.java @@ -18,11 +18,10 @@ import net.minecraft.util.Identifier; import net.minecraft.util.math.random.Random; import org.jetbrains.annotations.NotNull; - import java.util.*; import java.util.stream.Stream; -public abstract class PacketUtils { +public class PacketUtils { public static final Registry>> REGISTRY = new PacketRegistry(); private static final Map>, String> S2C_PACKETS = new HashMap<>(); @@ -54,10 +53,10 @@ public abstract class PacketUtils { C2S_PACKETS_R.put("QueryBlockNbtC2SPacket", net.minecraft.network.packet.c2s.play.QueryBlockNbtC2SPacket.class); C2S_PACKETS.put(net.minecraft.network.packet.c2s.play.PlayerInteractEntityC2SPacket.class, "PlayerInteractEntityC2SPacket"); C2S_PACKETS_R.put("PlayerInteractEntityC2SPacket", net.minecraft.network.packet.c2s.play.PlayerInteractEntityC2SPacket.class); - C2S_PACKETS.put(net.minecraft.network.packet.c2s.play.UpdatePlayerAbilitiesC2SPacket.class, "UpdatePlayerAbilitiesC2SPacket"); - C2S_PACKETS_R.put("UpdatePlayerAbilitiesC2SPacket", net.minecraft.network.packet.c2s.play.UpdatePlayerAbilitiesC2SPacket.class); C2S_PACKETS.put(net.minecraft.network.packet.c2s.play.RequestCommandCompletionsC2SPacket.class, "RequestCommandCompletionsC2SPacket"); C2S_PACKETS_R.put("RequestCommandCompletionsC2SPacket", net.minecraft.network.packet.c2s.play.RequestCommandCompletionsC2SPacket.class); + C2S_PACKETS.put(net.minecraft.network.packet.c2s.play.UpdatePlayerAbilitiesC2SPacket.class, "UpdatePlayerAbilitiesC2SPacket"); + C2S_PACKETS_R.put("UpdatePlayerAbilitiesC2SPacket", net.minecraft.network.packet.c2s.play.UpdatePlayerAbilitiesC2SPacket.class); C2S_PACKETS.put(net.minecraft.network.packet.c2s.play.AcknowledgeReconfigurationC2SPacket.class, "AcknowledgeReconfigurationC2SPacket"); C2S_PACKETS_R.put("AcknowledgeReconfigurationC2SPacket", net.minecraft.network.packet.c2s.play.AcknowledgeReconfigurationC2SPacket.class); C2S_PACKETS.put(net.minecraft.network.packet.c2s.query.QueryRequestC2SPacket.class, "QueryRequestC2SPacket"); @@ -92,24 +91,28 @@ public abstract class PacketUtils { C2S_PACKETS_R.put("PlayerMoveC2SPacket", net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket.class); C2S_PACKETS.put(net.minecraft.network.packet.c2s.common.ClientOptionsC2SPacket.class, "ClientOptionsC2SPacket"); C2S_PACKETS_R.put("ClientOptionsC2SPacket", net.minecraft.network.packet.c2s.common.ClientOptionsC2SPacket.class); - C2S_PACKETS.put(net.minecraft.network.packet.c2s.play.PickFromInventoryC2SPacket.class, "PickFromInventoryC2SPacket"); - C2S_PACKETS_R.put("PickFromInventoryC2SPacket", net.minecraft.network.packet.c2s.play.PickFromInventoryC2SPacket.class); C2S_PACKETS.put(net.minecraft.network.packet.c2s.common.CustomPayloadC2SPacket.class, "CustomPayloadC2SPacket"); C2S_PACKETS_R.put("CustomPayloadC2SPacket", net.minecraft.network.packet.c2s.common.CustomPayloadC2SPacket.class); + C2S_PACKETS.put(net.minecraft.network.packet.c2s.play.PickFromInventoryC2SPacket.class, "PickFromInventoryC2SPacket"); + C2S_PACKETS_R.put("PickFromInventoryC2SPacket", net.minecraft.network.packet.c2s.play.PickFromInventoryC2SPacket.class); C2S_PACKETS.put(net.minecraft.network.packet.c2s.play.PlayerSessionC2SPacket.class, "PlayerSessionC2SPacket"); C2S_PACKETS_R.put("PlayerSessionC2SPacket", net.minecraft.network.packet.c2s.play.PlayerSessionC2SPacket.class); C2S_PACKETS.put(net.minecraft.network.packet.c2s.play.CloseHandledScreenC2SPacket.class, "CloseHandledScreenC2SPacket"); C2S_PACKETS_R.put("CloseHandledScreenC2SPacket", net.minecraft.network.packet.c2s.play.CloseHandledScreenC2SPacket.class); - C2S_PACKETS.put(net.minecraft.network.packet.c2s.play.SlotChangedStateC2SPacket.class, "SlotChangedStateC2SPacket"); - C2S_PACKETS_R.put("SlotChangedStateC2SPacket", net.minecraft.network.packet.c2s.play.SlotChangedStateC2SPacket.class); + C2S_PACKETS.put(net.minecraft.network.packet.c2s.play.ChatCommandSignedC2SPacket.class, "ChatCommandSignedC2SPacket"); + C2S_PACKETS_R.put("ChatCommandSignedC2SPacket", net.minecraft.network.packet.c2s.play.ChatCommandSignedC2SPacket.class); C2S_PACKETS.put(net.minecraft.network.packet.c2s.config.ReadyC2SPacket.class, "ReadyC2SPacket"); C2S_PACKETS_R.put("ReadyC2SPacket", net.minecraft.network.packet.c2s.config.ReadyC2SPacket.class); + C2S_PACKETS.put(net.minecraft.network.packet.c2s.play.SlotChangedStateC2SPacket.class, "SlotChangedStateC2SPacket"); + C2S_PACKETS_R.put("SlotChangedStateC2SPacket", net.minecraft.network.packet.c2s.play.SlotChangedStateC2SPacket.class); C2S_PACKETS.put(net.minecraft.network.packet.c2s.play.BoatPaddleStateC2SPacket.class, "BoatPaddleStateC2SPacket"); C2S_PACKETS_R.put("BoatPaddleStateC2SPacket", net.minecraft.network.packet.c2s.play.BoatPaddleStateC2SPacket.class); - C2S_PACKETS.put(net.minecraft.network.packet.c2s.play.ChatMessageC2SPacket.class, "ChatMessageC2SPacket"); - C2S_PACKETS_R.put("ChatMessageC2SPacket", net.minecraft.network.packet.c2s.play.ChatMessageC2SPacket.class); C2S_PACKETS.put(net.minecraft.network.packet.c2s.play.ButtonClickC2SPacket.class, "ButtonClickC2SPacket"); C2S_PACKETS_R.put("ButtonClickC2SPacket", net.minecraft.network.packet.c2s.play.ButtonClickC2SPacket.class); + C2S_PACKETS.put(net.minecraft.network.packet.c2s.config.SelectKnownPacksC2SPacket.class, "SelectKnownPacksC2SPacket"); + C2S_PACKETS_R.put("SelectKnownPacksC2SPacket", net.minecraft.network.packet.c2s.config.SelectKnownPacksC2SPacket.class); + C2S_PACKETS.put(net.minecraft.network.packet.c2s.play.ChatMessageC2SPacket.class, "ChatMessageC2SPacket"); + C2S_PACKETS_R.put("ChatMessageC2SPacket", net.minecraft.network.packet.c2s.play.ChatMessageC2SPacket.class); C2S_PACKETS.put(net.minecraft.network.packet.c2s.play.UpdateBeaconC2SPacket.class, "UpdateBeaconC2SPacket"); C2S_PACKETS_R.put("UpdateBeaconC2SPacket", net.minecraft.network.packet.c2s.play.UpdateBeaconC2SPacket.class); C2S_PACKETS.put(net.minecraft.network.packet.c2s.play.UpdateSignC2SPacket.class, "UpdateSignC2SPacket"); @@ -130,8 +133,12 @@ public abstract class PacketUtils { C2S_PACKETS_R.put("UpdateJigsawC2SPacket", net.minecraft.network.packet.c2s.play.UpdateJigsawC2SPacket.class); C2S_PACKETS.put(net.minecraft.network.packet.c2s.query.QueryPingC2SPacket.class, "QueryPingC2SPacket"); C2S_PACKETS_R.put("QueryPingC2SPacket", net.minecraft.network.packet.c2s.query.QueryPingC2SPacket.class); + C2S_PACKETS.put(net.minecraft.network.packet.c2s.common.CookieResponseC2SPacket.class, "CookieResponseC2SPacket"); + C2S_PACKETS_R.put("CookieResponseC2SPacket", net.minecraft.network.packet.c2s.common.CookieResponseC2SPacket.class); C2S_PACKETS.put(net.minecraft.network.packet.c2s.play.MessageAcknowledgmentC2SPacket.class, "MessageAcknowledgmentC2SPacket"); C2S_PACKETS_R.put("MessageAcknowledgmentC2SPacket", net.minecraft.network.packet.c2s.play.MessageAcknowledgmentC2SPacket.class); + C2S_PACKETS.put(net.minecraft.network.packet.c2s.play.DebugSampleSubscriptionC2SPacket.class, "DebugSampleSubscriptionC2SPacket"); + C2S_PACKETS_R.put("DebugSampleSubscriptionC2SPacket", net.minecraft.network.packet.c2s.play.DebugSampleSubscriptionC2SPacket.class); C2S_PACKETS.put(net.minecraft.network.packet.c2s.common.KeepAliveC2SPacket.class, "KeepAliveC2SPacket"); C2S_PACKETS_R.put("KeepAliveC2SPacket", net.minecraft.network.packet.c2s.common.KeepAliveC2SPacket.class); C2S_PACKETS.put(net.minecraft.network.packet.c2s.play.CreativeInventoryActionC2SPacket.class, "CreativeInventoryActionC2SPacket"); @@ -142,10 +149,10 @@ public abstract class PacketUtils { C2S_PACKETS_R.put("BookUpdateC2SPacket", net.minecraft.network.packet.c2s.play.BookUpdateC2SPacket.class); C2S_PACKETS.put(net.minecraft.network.packet.c2s.play.RecipeBookDataC2SPacket.class, "RecipeBookDataC2SPacket"); C2S_PACKETS_R.put("RecipeBookDataC2SPacket", net.minecraft.network.packet.c2s.play.RecipeBookDataC2SPacket.class); - C2S_PACKETS.put(net.minecraft.network.packet.c2s.login.LoginQueryResponseC2SPacket.class, "LoginQueryResponseC2SPacket"); - C2S_PACKETS_R.put("LoginQueryResponseC2SPacket", net.minecraft.network.packet.c2s.login.LoginQueryResponseC2SPacket.class); C2S_PACKETS.put(net.minecraft.network.packet.c2s.handshake.HandshakeC2SPacket.class, "HandshakeC2SPacket"); C2S_PACKETS_R.put("HandshakeC2SPacket", net.minecraft.network.packet.c2s.handshake.HandshakeC2SPacket.class); + C2S_PACKETS.put(net.minecraft.network.packet.c2s.login.LoginQueryResponseC2SPacket.class, "LoginQueryResponseC2SPacket"); + C2S_PACKETS_R.put("LoginQueryResponseC2SPacket", net.minecraft.network.packet.c2s.login.LoginQueryResponseC2SPacket.class); C2S_PACKETS.put(net.minecraft.network.packet.c2s.play.UpdateDifficultyC2SPacket.class, "UpdateDifficultyC2SPacket"); C2S_PACKETS_R.put("UpdateDifficultyC2SPacket", net.minecraft.network.packet.c2s.play.UpdateDifficultyC2SPacket.class); C2S_PACKETS.put(net.minecraft.network.packet.c2s.play.CraftRequestC2SPacket.class, "CraftRequestC2SPacket"); @@ -154,10 +161,10 @@ public abstract class PacketUtils { C2S_PACKETS_R.put("PlayerMoveC2SPacket.LookAndOnGround", net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket.LookAndOnGround.class); C2S_PACKETS.put(net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket.OnGroundOnly.class, "PlayerMoveC2SPacket.OnGroundOnly"); C2S_PACKETS_R.put("PlayerMoveC2SPacket.OnGroundOnly", net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket.OnGroundOnly.class); - C2S_PACKETS.put(net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket.PositionAndOnGround.class, "PlayerMoveC2SPacket.PositionAndOnGround"); - C2S_PACKETS_R.put("PlayerMoveC2SPacket.PositionAndOnGround", net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket.PositionAndOnGround.class); C2S_PACKETS.put(net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket.Full.class, "PlayerMoveC2SPacket.Full"); C2S_PACKETS_R.put("PlayerMoveC2SPacket.Full", net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket.Full.class); + C2S_PACKETS.put(net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket.PositionAndOnGround.class, "PlayerMoveC2SPacket.PositionAndOnGround"); + C2S_PACKETS_R.put("PlayerMoveC2SPacket.PositionAndOnGround", net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket.PositionAndOnGround.class); S2C_PACKETS.put(net.minecraft.network.packet.s2c.play.WorldBorderSizeChangedS2CPacket.class, "WorldBorderSizeChangedS2CPacket"); S2C_PACKETS_R.put("WorldBorderSizeChangedS2CPacket", net.minecraft.network.packet.s2c.play.WorldBorderSizeChangedS2CPacket.class); @@ -201,12 +208,16 @@ public abstract class PacketUtils { S2C_PACKETS_R.put("ScoreboardObjectiveUpdateS2CPacket", net.minecraft.network.packet.s2c.play.ScoreboardObjectiveUpdateS2CPacket.class); S2C_PACKETS.put(net.minecraft.network.packet.s2c.play.StartChunkSendS2CPacket.class, "StartChunkSendS2CPacket"); S2C_PACKETS_R.put("StartChunkSendS2CPacket", net.minecraft.network.packet.s2c.play.StartChunkSendS2CPacket.class); + S2C_PACKETS.put(net.minecraft.network.packet.s2c.common.CookieRequestS2CPacket.class, "CookieRequestS2CPacket"); + S2C_PACKETS_R.put("CookieRequestS2CPacket", net.minecraft.network.packet.s2c.common.CookieRequestS2CPacket.class); S2C_PACKETS.put(net.minecraft.network.packet.s2c.play.EntitySetHeadYawS2CPacket.class, "EntitySetHeadYawS2CPacket"); S2C_PACKETS_R.put("EntitySetHeadYawS2CPacket", net.minecraft.network.packet.s2c.play.EntitySetHeadYawS2CPacket.class); S2C_PACKETS.put(net.minecraft.network.packet.s2c.play.SelectAdvancementTabS2CPacket.class, "SelectAdvancementTabS2CPacket"); S2C_PACKETS_R.put("SelectAdvancementTabS2CPacket", net.minecraft.network.packet.s2c.play.SelectAdvancementTabS2CPacket.class); S2C_PACKETS.put(net.minecraft.network.packet.s2c.play.SetTradeOffersS2CPacket.class, "SetTradeOffersS2CPacket"); S2C_PACKETS_R.put("SetTradeOffersS2CPacket", net.minecraft.network.packet.s2c.play.SetTradeOffersS2CPacket.class); + S2C_PACKETS.put(net.minecraft.network.packet.s2c.common.StoreCookieS2CPacket.class, "StoreCookieS2CPacket"); + S2C_PACKETS_R.put("StoreCookieS2CPacket", net.minecraft.network.packet.s2c.common.StoreCookieS2CPacket.class); S2C_PACKETS.put(net.minecraft.network.packet.s2c.play.PlaySoundS2CPacket.class, "PlaySoundS2CPacket"); S2C_PACKETS_R.put("PlaySoundS2CPacket", net.minecraft.network.packet.s2c.play.PlaySoundS2CPacket.class); S2C_PACKETS.put(net.minecraft.network.packet.s2c.play.BlockEventS2CPacket.class, "BlockEventS2CPacket"); @@ -235,12 +246,14 @@ public abstract class PacketUtils { S2C_PACKETS_R.put("CooldownUpdateS2CPacket", net.minecraft.network.packet.s2c.play.CooldownUpdateS2CPacket.class); S2C_PACKETS.put(net.minecraft.network.packet.s2c.play.OpenScreenS2CPacket.class, "OpenScreenS2CPacket"); S2C_PACKETS_R.put("OpenScreenS2CPacket", net.minecraft.network.packet.s2c.play.OpenScreenS2CPacket.class); - S2C_PACKETS.put(net.minecraft.network.packet.s2c.play.ExperienceOrbSpawnS2CPacket.class, "ExperienceOrbSpawnS2CPacket"); - S2C_PACKETS_R.put("ExperienceOrbSpawnS2CPacket", net.minecraft.network.packet.s2c.play.ExperienceOrbSpawnS2CPacket.class); S2C_PACKETS.put(net.minecraft.network.packet.s2c.play.EntityAnimationS2CPacket.class, "EntityAnimationS2CPacket"); S2C_PACKETS_R.put("EntityAnimationS2CPacket", net.minecraft.network.packet.s2c.play.EntityAnimationS2CPacket.class); + S2C_PACKETS.put(net.minecraft.network.packet.s2c.play.ExperienceOrbSpawnS2CPacket.class, "ExperienceOrbSpawnS2CPacket"); + S2C_PACKETS_R.put("ExperienceOrbSpawnS2CPacket", net.minecraft.network.packet.s2c.play.ExperienceOrbSpawnS2CPacket.class); S2C_PACKETS.put(net.minecraft.network.packet.s2c.play.PlayerAbilitiesS2CPacket.class, "PlayerAbilitiesS2CPacket"); S2C_PACKETS_R.put("PlayerAbilitiesS2CPacket", net.minecraft.network.packet.s2c.play.PlayerAbilitiesS2CPacket.class); + S2C_PACKETS.put(net.minecraft.network.packet.s2c.config.ResetChatS2CPacket.class, "ResetChatS2CPacket"); + S2C_PACKETS_R.put("ResetChatS2CPacket", net.minecraft.network.packet.s2c.config.ResetChatS2CPacket.class); S2C_PACKETS.put(net.minecraft.network.packet.s2c.play.WorldBorderWarningBlocksChangedS2CPacket.class, "WorldBorderWarningBlocksChangedS2CPacket"); S2C_PACKETS_R.put("WorldBorderWarningBlocksChangedS2CPacket", net.minecraft.network.packet.s2c.play.WorldBorderWarningBlocksChangedS2CPacket.class); S2C_PACKETS.put(net.minecraft.network.packet.s2c.play.EntitiesDestroyS2CPacket.class, "EntitiesDestroyS2CPacket"); @@ -283,10 +296,10 @@ public abstract class PacketUtils { S2C_PACKETS_R.put("DeathMessageS2CPacket", net.minecraft.network.packet.s2c.play.DeathMessageS2CPacket.class); S2C_PACKETS.put(net.minecraft.network.packet.s2c.play.MapUpdateS2CPacket.class, "MapUpdateS2CPacket"); S2C_PACKETS_R.put("MapUpdateS2CPacket", net.minecraft.network.packet.s2c.play.MapUpdateS2CPacket.class); - S2C_PACKETS.put(net.minecraft.network.packet.s2c.play.ScreenHandlerSlotUpdateS2CPacket.class, "ScreenHandlerSlotUpdateS2CPacket"); - S2C_PACKETS_R.put("ScreenHandlerSlotUpdateS2CPacket", net.minecraft.network.packet.s2c.play.ScreenHandlerSlotUpdateS2CPacket.class); S2C_PACKETS.put(net.minecraft.network.packet.s2c.play.BlockEntityUpdateS2CPacket.class, "BlockEntityUpdateS2CPacket"); S2C_PACKETS_R.put("BlockEntityUpdateS2CPacket", net.minecraft.network.packet.s2c.play.BlockEntityUpdateS2CPacket.class); + S2C_PACKETS.put(net.minecraft.network.packet.s2c.play.ScreenHandlerSlotUpdateS2CPacket.class, "ScreenHandlerSlotUpdateS2CPacket"); + S2C_PACKETS_R.put("ScreenHandlerSlotUpdateS2CPacket", net.minecraft.network.packet.s2c.play.ScreenHandlerSlotUpdateS2CPacket.class); S2C_PACKETS.put(net.minecraft.network.packet.s2c.play.PlayerSpawnPositionS2CPacket.class, "PlayerSpawnPositionS2CPacket"); S2C_PACKETS_R.put("PlayerSpawnPositionS2CPacket", net.minecraft.network.packet.s2c.play.PlayerSpawnPositionS2CPacket.class); S2C_PACKETS.put(net.minecraft.network.packet.s2c.play.EntityStatusEffectS2CPacket.class, "EntityStatusEffectS2CPacket"); @@ -311,6 +324,8 @@ public abstract class PacketUtils { S2C_PACKETS_R.put("InventoryS2CPacket", net.minecraft.network.packet.s2c.play.InventoryS2CPacket.class); S2C_PACKETS.put(net.minecraft.network.packet.s2c.play.PlayerActionResponseS2CPacket.class, "PlayerActionResponseS2CPacket"); S2C_PACKETS_R.put("PlayerActionResponseS2CPacket", net.minecraft.network.packet.s2c.play.PlayerActionResponseS2CPacket.class); + S2C_PACKETS.put(net.minecraft.network.packet.s2c.play.DebugSampleS2CPacket.class, "DebugSampleS2CPacket"); + S2C_PACKETS_R.put("DebugSampleS2CPacket", net.minecraft.network.packet.s2c.play.DebugSampleS2CPacket.class); S2C_PACKETS.put(net.minecraft.network.packet.s2c.play.ChunkBiomeDataS2CPacket.class, "ChunkBiomeDataS2CPacket"); S2C_PACKETS_R.put("ChunkBiomeDataS2CPacket", net.minecraft.network.packet.s2c.play.ChunkBiomeDataS2CPacket.class); S2C_PACKETS.put(net.minecraft.network.packet.s2c.play.WorldBorderWarningTimeChangedS2CPacket.class, "WorldBorderWarningTimeChangedS2CPacket"); @@ -379,6 +394,8 @@ public abstract class PacketUtils { S2C_PACKETS_R.put("EntityTrackerUpdateS2CPacket", net.minecraft.network.packet.s2c.play.EntityTrackerUpdateS2CPacket.class); S2C_PACKETS.put(net.minecraft.network.packet.s2c.play.EntityStatusS2CPacket.class, "EntityStatusS2CPacket"); S2C_PACKETS_R.put("EntityStatusS2CPacket", net.minecraft.network.packet.s2c.play.EntityStatusS2CPacket.class); + S2C_PACKETS.put(net.minecraft.network.packet.s2c.config.SelectKnownPacksS2CPacket.class, "SelectKnownPacksS2CPacket"); + S2C_PACKETS_R.put("SelectKnownPacksS2CPacket", net.minecraft.network.packet.s2c.config.SelectKnownPacksS2CPacket.class); S2C_PACKETS.put(net.minecraft.network.packet.s2c.config.DynamicRegistriesS2CPacket.class, "DynamicRegistriesS2CPacket"); S2C_PACKETS_R.put("DynamicRegistriesS2CPacket", net.minecraft.network.packet.s2c.config.DynamicRegistriesS2CPacket.class); S2C_PACKETS.put(net.minecraft.network.packet.s2c.common.CustomPayloadS2CPacket.class, "CustomPayloadS2CPacket"); @@ -399,12 +416,18 @@ public abstract class PacketUtils { S2C_PACKETS_R.put("EntityAttachS2CPacket", net.minecraft.network.packet.s2c.play.EntityAttachS2CPacket.class); S2C_PACKETS.put(net.minecraft.network.packet.s2c.play.BossBarS2CPacket.class, "BossBarS2CPacket"); S2C_PACKETS_R.put("BossBarS2CPacket", net.minecraft.network.packet.s2c.play.BossBarS2CPacket.class); + S2C_PACKETS.put(net.minecraft.network.packet.s2c.common.ServerTransferS2CPacket.class, "ServerTransferS2CPacket"); + S2C_PACKETS_R.put("ServerTransferS2CPacket", net.minecraft.network.packet.s2c.common.ServerTransferS2CPacket.class); S2C_PACKETS.put(net.minecraft.network.packet.s2c.play.EntityPositionS2CPacket.class, "EntityPositionS2CPacket"); S2C_PACKETS_R.put("EntityPositionS2CPacket", net.minecraft.network.packet.s2c.play.EntityPositionS2CPacket.class); S2C_PACKETS.put(net.minecraft.network.packet.s2c.play.ChunkDataS2CPacket.class, "ChunkDataS2CPacket"); S2C_PACKETS_R.put("ChunkDataS2CPacket", net.minecraft.network.packet.s2c.play.ChunkDataS2CPacket.class); + S2C_PACKETS.put(net.minecraft.network.packet.s2c.play.ProjectilePowerS2CPacket.class, "ProjectilePowerS2CPacket"); + S2C_PACKETS_R.put("ProjectilePowerS2CPacket", net.minecraft.network.packet.s2c.play.ProjectilePowerS2CPacket.class); S2C_PACKETS.put(net.minecraft.network.packet.s2c.play.GameStateChangeS2CPacket.class, "GameStateChangeS2CPacket"); S2C_PACKETS_R.put("GameStateChangeS2CPacket", net.minecraft.network.packet.s2c.play.GameStateChangeS2CPacket.class); + S2C_PACKETS.put(net.minecraft.network.packet.s2c.play.BundleDelimiterS2CPacket.class, "BundleDelimiterS2CPacket"); + S2C_PACKETS_R.put("BundleDelimiterS2CPacket", net.minecraft.network.packet.s2c.play.BundleDelimiterS2CPacket.class); S2C_PACKETS.put(net.minecraft.network.packet.s2c.play.BundleS2CPacket.class, "BundleS2CPacket"); S2C_PACKETS_R.put("BundleS2CPacket", net.minecraft.network.packet.s2c.play.BundleS2CPacket.class); S2C_PACKETS.put(net.minecraft.network.packet.s2c.play.EntityS2CPacket.RotateAndMoveRelative.class, "EntityS2CPacket.RotateAndMoveRelative"); @@ -415,6 +438,9 @@ public abstract class PacketUtils { S2C_PACKETS_R.put("EntityS2CPacket.MoveRelative", net.minecraft.network.packet.s2c.play.EntityS2CPacket.MoveRelative.class); } + private PacketUtils() { + } + public static String getName(Class> packetClass) { String name = S2C_PACKETS.get(packetClass); if (name != null) return name; @@ -470,11 +496,6 @@ public Class> get(Identifier id) { return null; } - @Override - public Lifecycle getEntryLifecycle(Class> object) { - return null; - } - @Override public Lifecycle getLifecycle() { return null; @@ -482,7 +503,7 @@ public Lifecycle getLifecycle() { @Override public Set getIds() { - return null; + return Collections.emptySet(); } @Override diff --git a/src/main/java/meteordevelopment/meteorclient/utils/network/PacketUtilsUtil.java b/src/main/java/meteordevelopment/meteorclient/utils/network/PacketUtilsUtil.java index c296a947e4..2c983f232a 100644 --- a/src/main/java/meteordevelopment/meteorclient/utils/network/PacketUtilsUtil.java +++ b/src/main/java/meteordevelopment/meteorclient/utils/network/PacketUtilsUtil.java @@ -16,7 +16,7 @@ import java.io.IOException; import java.util.Set; -public abstract class PacketUtilsUtil { +public class PacketUtilsUtil { private static final String packetRegistryClass = """ private static class PacketRegistry extends SimpleRegistry>> { public PacketRegistry() { @@ -53,11 +53,6 @@ public Class> get(Identifier id) { return null; } - @Override - public Lifecycle getEntryLifecycle(Class> object) { - return null; - } - @Override public Lifecycle getLifecycle() { return null; @@ -65,7 +60,7 @@ public Lifecycle getLifecycle() { @Override public Set getIds() { - return null; + return Collections.emptySet(); } @Override @@ -157,6 +152,9 @@ public Set>>> getKeys() { } """; + private PacketUtilsUtil() { + } + public static void main(String[] args) { try { init(); @@ -201,7 +199,7 @@ public static void init() throws IOException { writer.write("import java.util.stream.Stream;\n"); // Write class - writer.write("\npublic abstract class PacketUtils {\n"); + writer.write("\npublic class PacketUtils {\n"); // Write fields writer.write(" public static final Registry>> REGISTRY = new PacketRegistry();\n\n"); @@ -244,6 +242,9 @@ public static void init() throws IOException { writer.write(" }\n\n"); + writer.write(" private PacketUtils() {\n"); + writer.write(" }\n\n"); + // Write getName method writer.write(" public static String getName(Class> packetClass) {\n"); writer.write(" String name = S2C_PACKETS.get(packetClass);\n"); diff --git a/src/main/java/meteordevelopment/meteorclient/utils/player/ChatUtils.java b/src/main/java/meteordevelopment/meteorclient/utils/player/ChatUtils.java index ba05ab99f3..91107bdb15 100644 --- a/src/main/java/meteordevelopment/meteorclient/utils/player/ChatUtils.java +++ b/src/main/java/meteordevelopment/meteorclient/utils/player/ChatUtils.java @@ -30,6 +30,9 @@ public class ChatUtils { private static Text PREFIX; + private ChatUtils() { + } + @PostInit public static void init() { PREFIX = Text.empty() @@ -43,7 +46,9 @@ public static Text getMeteorPrefix() { return PREFIX; } - /** Registers a custom prefix to be used when calling from a class in the specified package. When null is returned from the supplier the default Meteor prefix is used. */ + /** + * Registers a custom prefix to be used when calling from a class in the specified package. When null is returned from the supplier the default Meteor prefix is used. + */ public static void registerCustomPrefix(String packageName, Supplier supplier) { for (Pair> pair : customPrefixes) { if (pair.getLeft().equals(packageName)) { @@ -55,7 +60,9 @@ public static void registerCustomPrefix(String packageName, Supplier suppl customPrefixes.add(new Pair<>(packageName, supplier)); } - /** The package name must match exactly to the one provided through {@link #registerCustomPrefix(String, Supplier)}. */ + /** + * The package name must match exactly to the one provided through {@link #registerCustomPrefix(String, Supplier)}. + */ public static void unregisterCustomPrefix(String packageName) { customPrefixes.removeIf(pair -> pair.getLeft().equals(packageName)); } @@ -66,7 +73,9 @@ public static void forceNextPrefixClass(Class klass) { // Player - /** Sends the message as if the user typed it into chat. */ + /** + * Sends the message as if the user typed it into chat. + */ public static void sendPlayerMsg(String message) { mc.inGameHud.getChatHud().addToMessageHistory(message); @@ -172,8 +181,7 @@ private static Text getPrefix() { if (forcedPrefixClassName != null) { className = forcedPrefixClassName; forcedPrefixClassName = null; - } - else { + } else { for (StackTraceElement element : Thread.currentThread().getStackTrace()) { if (foundChatUtils) { if (!element.getClassName().equals(ChatUtils.class.getName())) { @@ -228,6 +236,10 @@ private static MutableText formatMsg(String message, Formatting defaultColor) { style = style.withFormatting(Formatting.UNDERLINE); result.setLength(0); } + case "(bold)" -> { + style = style.withFormatting(Formatting.BOLD); + result.setLength(0); + } } formatting = false; } @@ -243,19 +255,20 @@ public static MutableText formatCoords(Vec3d pos) { String coordsString = String.format("(highlight)(underline)%.0f, %.0f, %.0f(default)", pos.x, pos.y, pos.z); MutableText coordsText = formatMsg(coordsString, Formatting.GRAY); - Style style = coordsText.getStyle().withFormatting(Formatting.BOLD).withHoverEvent(new HoverEvent( - HoverEvent.Action.SHOW_TEXT, - Text.literal("Set as Baritone goal") - )); - if (BaritoneUtils.IS_AVAILABLE) { - style = style.withClickEvent(new MeteorClickEvent( - ClickEvent.Action.RUN_COMMAND, - String.format("%sgoto %d %d %d", BaritoneUtils.getPrefix(), (int) pos.x, (int) pos.y, (int) pos.z) - )); + Style style = coordsText.getStyle().withFormatting(Formatting.BOLD) + .withHoverEvent(new HoverEvent( + HoverEvent.Action.SHOW_TEXT, + Text.literal("Set as Baritone goal") + )) + .withClickEvent(new MeteorClickEvent( + ClickEvent.Action.RUN_COMMAND, + String.format("%sgoto %d %d %d", BaritoneUtils.getPrefix(), (int) pos.x, (int) pos.y, (int) pos.z) + )); + + coordsText.setStyle(style); } - coordsText.setStyle(style); return coordsText; } } diff --git a/src/main/java/meteordevelopment/meteorclient/utils/player/EChestMemory.java b/src/main/java/meteordevelopment/meteorclient/utils/player/EChestMemory.java index f806c712fb..af84a0e2bb 100644 --- a/src/main/java/meteordevelopment/meteorclient/utils/player/EChestMemory.java +++ b/src/main/java/meteordevelopment/meteorclient/utils/player/EChestMemory.java @@ -25,6 +25,9 @@ public class EChestMemory { private static int echestOpenedState; private static boolean isKnown = false; + private EChestMemory() { + } + @PreInit public static void init() { MeteorClient.EVENT_BUS.subscribe(EChestMemory.class); diff --git a/src/main/java/meteordevelopment/meteorclient/utils/player/FindItemResult.java b/src/main/java/meteordevelopment/meteorclient/utils/player/FindItemResult.java index 02b0ab44ae..4e7586d0a7 100644 --- a/src/main/java/meteordevelopment/meteorclient/utils/player/FindItemResult.java +++ b/src/main/java/meteordevelopment/meteorclient/utils/player/FindItemResult.java @@ -16,7 +16,7 @@ public boolean found() { public Hand getHand() { if (slot == SlotUtils.OFFHAND) return Hand.OFF_HAND; - else if (slot == mc.player.getInventory().selectedSlot) return Hand.MAIN_HAND; + if (slot == mc.player.getInventory().selectedSlot) return Hand.MAIN_HAND; return null; } diff --git a/src/main/java/meteordevelopment/meteorclient/utils/player/InvUtils.java b/src/main/java/meteordevelopment/meteorclient/utils/player/InvUtils.java index 620b77adc0..1b8aa88bbd 100644 --- a/src/main/java/meteordevelopment/meteorclient/utils/player/InvUtils.java +++ b/src/main/java/meteordevelopment/meteorclient/utils/player/InvUtils.java @@ -20,6 +20,9 @@ public class InvUtils { private static final Action ACTION = new Action(); public static int previousSlot = -1; + private InvUtils() { + } + // Predicates public static boolean testInMainHand(Predicate predicate) { @@ -155,7 +158,7 @@ public static boolean swap(int slot, boolean swapBack) { else if (!swapBack) previousSlot = -1; mc.player.getInventory().selectedSlot = slot; - ((IClientPlayerInteractionManager) mc.interactionManager).syncSelected(); + ((IClientPlayerInteractionManager) mc.interactionManager).meteor$syncSelected(); return true; } @@ -212,7 +215,8 @@ public static class Action { private boolean isRecursive = false; - private Action() {} + private Action() { + } // From @@ -306,8 +310,8 @@ private void run() { } if (type != null && from != -1 && to != -1) { - click(from); - if (two) click(to); + click(from); + if (two) click(to); } SlotActionType preType = type; diff --git a/src/main/java/meteordevelopment/meteorclient/utils/player/InventorySorter.java b/src/main/java/meteordevelopment/meteorclient/utils/player/InventorySorter.java index f0796035fd..75fd01b111 100644 --- a/src/main/java/meteordevelopment/meteorclient/utils/player/InventorySorter.java +++ b/src/main/java/meteordevelopment/meteorclient/utils/player/InventorySorter.java @@ -207,8 +207,8 @@ private static class SlotMap { private final List>> map = new ArrayList<>(); public List get(ItemStack itemStack) { - for (var entry : map) { - if (areEqual(itemStack, entry.getLeft())) { + for (Pair> entry : map) { + if (ItemStack.areItemsEqual(itemStack, entry.getLeft())) { return entry.getRight(); } } @@ -217,12 +217,6 @@ public List get(ItemStack itemStack) { map.add(new Pair<>(itemStack, list)); return list; } - - private boolean areEqual(ItemStack i1, ItemStack i2) { - if (!i1.isOf(i2.getItem()) || (i1.getNbt() == null && i2.getNbt() != null)) return false; - - return i1.getNbt() == null || i1.getNbt().equals(i2.getNbt()); - } } private record Action(int from, int to) {} diff --git a/src/main/java/meteordevelopment/meteorclient/utils/player/PathFinder.java b/src/main/java/meteordevelopment/meteorclient/utils/player/PathFinder.java index 5ec128dc2e..08fda11305 100644 --- a/src/main/java/meteordevelopment/meteorclient/utils/player/PathFinder.java +++ b/src/main/java/meteordevelopment/meteorclient/utils/player/PathFinder.java @@ -21,8 +21,8 @@ import static meteordevelopment.meteorclient.MeteorClient.mc; public class PathFinder { - private final static int PATH_AHEAD = 3; - private final static int QUAD_1 = 1, QUAD_2 = 2, SOUTH = 0, NORTH = 180; + private static final int PATH_AHEAD = 3; + private static final int QUAD_1 = 1, QUAD_2 = 2, SOUTH = 0, NORTH = 180; private final ArrayList path = new ArrayList<>(PATH_AHEAD); private Entity target; private PathBlock currentPathBlock; diff --git a/src/main/java/meteordevelopment/meteorclient/utils/player/PlayerUtils.java b/src/main/java/meteordevelopment/meteorclient/utils/player/PlayerUtils.java index 203cd5340f..f05e1a5bfb 100644 --- a/src/main/java/meteordevelopment/meteorclient/utils/player/PlayerUtils.java +++ b/src/main/java/meteordevelopment/meteorclient/utils/player/PlayerUtils.java @@ -21,6 +21,7 @@ import net.minecraft.block.entity.BedBlockEntity; import net.minecraft.block.entity.BlockEntity; import net.minecraft.client.network.PlayerListEntry; +import net.minecraft.component.DataComponentTypes; import net.minecraft.entity.Entity; import net.minecraft.entity.decoration.EndCrystalEntity; import net.minecraft.entity.player.PlayerEntity; @@ -43,6 +44,9 @@ public class PlayerUtils { private static final Color color = new Color(); + private PlayerUtils() { + } + public static Color getPlayerColor(PlayerEntity entity, Color defaultColor) { if (Friends.get().isFriend(entity)) { return color.set(Config.get().friendColor.get()).a(defaultColor.a); @@ -135,7 +139,7 @@ public static float[] calculateAngle(Vec3d target) { public static boolean shouldPause(boolean ifBreaking, boolean ifEating, boolean ifDrinking) { if (ifBreaking && mc.interactionManager.isBreakingBlock()) return true; - if (ifEating && (mc.player.isUsingItem() && (mc.player.getMainHandStack().getItem().isFood() || mc.player.getOffHandStack().getItem().isFood()))) return true; + if (ifEating && (mc.player.isUsingItem() && (mc.player.getMainHandStack().getItem().getComponents().contains(DataComponentTypes.FOOD) || mc.player.getOffHandStack().getItem().getComponents().contains(DataComponentTypes.FOOD)))) return true; return ifDrinking && (mc.player.isUsingItem() && (mc.player.getMainHandStack().getItem() instanceof PotionItem || mc.player.getOffHandStack().getItem() instanceof PotionItem)); } @@ -227,6 +231,10 @@ else if (entity instanceof PlayerEntity player && !Friends.get().isFriend(player return damageTaken; } + public static double distance(double x1, double y1, double z1, double x2, double y2, double z2) { + return Math.sqrt(squaredDistance(x1, y1, z1, x2, y2, z2)); + } + public static double distanceTo(Entity entity) { return distanceTo(entity.getX(), entity.getY(), entity.getZ()); } @@ -256,9 +264,9 @@ public static double squaredDistanceTo(double x, double y, double z) { } public static double squaredDistance(double x1, double y1, double z1, double x2, double y2, double z2) { - float f = (float) (x1 - x2); - float g = (float) (y1 - y2); - float h = (float) (z1 - z2); + double f = x1 - x2; + double g = y1 - y2; + double h = z1 - z2; return org.joml.Math.fma(f, f, org.joml.Math.fma(g, g, h * h)); } @@ -324,7 +332,7 @@ public static boolean isWithinReach(BlockPos blockPos) { } public static boolean isWithinReach(double x, double y, double z) { - return squaredDistance(mc.player.getX(), mc.player.getEyeY(), mc.player.getZ(), x, y, z) <= mc.interactionManager.getReachDistance() * mc.interactionManager.getReachDistance(); + return squaredDistance(mc.player.getX(), mc.player.getEyeY(), mc.player.getZ(), x, y, z) <= mc.player.getBlockInteractionRange() * mc.player.getBlockInteractionRange(); } public static Dimension getDimension() { diff --git a/src/main/java/meteordevelopment/meteorclient/utils/player/Rotations.java b/src/main/java/meteordevelopment/meteorclient/utils/player/Rotations.java index 1990b96c7a..4e7f8e9c15 100644 --- a/src/main/java/meteordevelopment/meteorclient/utils/player/Rotations.java +++ b/src/main/java/meteordevelopment/meteorclient/utils/player/Rotations.java @@ -38,6 +38,9 @@ public class Rotations { private static boolean sentLastRotation; public static boolean rotating = false; + private Rotations() { + } + @PreInit public static void init() { MeteorClient.EVENT_BUS.subscribe(Rotations.class); diff --git a/src/main/java/meteordevelopment/meteorclient/utils/player/SlotUtils.java b/src/main/java/meteordevelopment/meteorclient/utils/player/SlotUtils.java index a41583964f..375a657af5 100644 --- a/src/main/java/meteordevelopment/meteorclient/utils/player/SlotUtils.java +++ b/src/main/java/meteordevelopment/meteorclient/utils/player/SlotUtils.java @@ -32,6 +32,9 @@ public class SlotUtils { public static final int ARMOR_START = 36; public static final int ARMOR_END = 39; + private SlotUtils() { + } + public static int indexToId(int i) { if (mc.player == null) return -1; ScreenHandler handler = mc.player.currentScreenHandler; @@ -140,12 +143,10 @@ private static int horse(ScreenHandler handler, int i) { int strength = llamaEntity.getStrength(); if (isHotbar(i)) return (2 + 3 * strength) + 28 + i; if (isMain(i)) return (2 + 3 * strength) + 1 + (i - 9); - } - else if (entity instanceof HorseEntity || entity instanceof SkeletonHorseEntity || entity instanceof ZombieHorseEntity) { + } else if (entity instanceof HorseEntity || entity instanceof SkeletonHorseEntity || entity instanceof ZombieHorseEntity) { if (isHotbar(i)) return 29 + i; if (isMain(i)) return 2 + (i - 9); - } - else if (entity instanceof AbstractDonkeyEntity abstractDonkeyEntity) { + } else if (entity instanceof AbstractDonkeyEntity abstractDonkeyEntity) { boolean chest = abstractDonkeyEntity.hasChest(); if (isHotbar(i)) return (chest ? 44 : 29) + i; if (isMain(i)) return (chest ? 17 : 2) + (i - 9); diff --git a/src/main/java/meteordevelopment/meteorclient/utils/player/TitleScreenCredits.java b/src/main/java/meteordevelopment/meteorclient/utils/player/TitleScreenCredits.java index e86b163bd0..1481b9e137 100644 --- a/src/main/java/meteordevelopment/meteorclient/utils/player/TitleScreenCredits.java +++ b/src/main/java/meteordevelopment/meteorclient/utils/player/TitleScreenCredits.java @@ -11,22 +11,29 @@ import meteordevelopment.meteorclient.addons.MeteorAddon; import meteordevelopment.meteorclient.gui.GuiThemes; import meteordevelopment.meteorclient.gui.screens.CommitsScreen; +import meteordevelopment.meteorclient.mixininterface.IText; import meteordevelopment.meteorclient.utils.network.Http; import meteordevelopment.meteorclient.utils.network.MeteorExecutor; +import meteordevelopment.meteorclient.utils.render.MeteorToast; import net.minecraft.client.gui.DrawContext; +import net.minecraft.item.Items; import net.minecraft.text.MutableText; import net.minecraft.text.Text; import net.minecraft.util.Formatting; +import java.net.http.HttpResponse; import java.util.ArrayList; import java.util.Comparator; import java.util.List; import static meteordevelopment.meteorclient.MeteorClient.mc; -public abstract class TitleScreenCredits { +public class TitleScreenCredits { private static final List credits = new ArrayList<>(); + private TitleScreenCredits() { + } + private static void init() { // Add addons add(MeteorClient.ADDON); @@ -41,10 +48,35 @@ private static void init() { if (credit.addon.getRepo() == null || credit.addon.getCommit() == null) continue; GithubRepo repo = credit.addon.getRepo(); - Response res = Http.get("https://api.github.com/repos/%s/branches/%s".formatted(repo.getOwnerName(), repo.branch())).sendJson(Response.class); - - if (res != null && !credit.addon.getCommit().equals(res.commit.sha)) { - credit.text.append(Text.literal("*").formatted(Formatting.RED)); + Http.Request request = Http.get("https://api.github.com/repos/%s/branches/%s".formatted(repo.getOwnerName(), repo.branch())); + repo.authenticate(request); + HttpResponse res = request.sendJsonResponse(Response.class); + + switch (res.statusCode()) { + case Http.UNAUTHORIZED -> { + String message = "Invalid authentication token for repository '%s'".formatted(repo.getOwnerName()); + mc.getToastManager().add(new MeteorToast(Items.BARRIER, "GitHub: Unauthorized", message)); + MeteorClient.LOG.warn(message); + if (System.getenv("meteor.github.authorization") == null) { + MeteorClient.LOG.info("Consider setting an authorization " + + "token with the 'meteor.github.authorization' environment variable."); + MeteorClient.LOG.info("See: https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens"); + } + } + case Http.FORBIDDEN -> { + MeteorClient.LOG.warn("Could not fetch updates for addon '%s': Rate-limited by GitHub.".formatted(credit.addon.name)); + } + case Http.NOT_FOUND -> { + MeteorClient.LOG.warn("Could not fetch updates for addon '%s': GitHub repository '%s' not found.".formatted(credit.addon.name, repo.getOwnerName())); + } + case Http.SUCCESS -> { + if (!credit.addon.getCommit().equals(res.body().commit.sha)) { + synchronized (credit.text) { + credit.text.append(Text.literal("*").formatted(Formatting.RED)); + ((IText) credit.text).meteor$invalidateCache(); + } + } + } } } }); @@ -72,9 +104,11 @@ public static void render(DrawContext context) { int y = 3; for (Credit credit : credits) { - int x = mc.currentScreen.width - 3 - mc.textRenderer.getWidth(credit.text); + synchronized (credit.text) { + int x = mc.currentScreen.width - 3 - mc.textRenderer.getWidth(credit.text); - context.drawTextWithShadow(mc.textRenderer, credit.text, x, y, -1); + context.drawTextWithShadow(mc.textRenderer, credit.text, x, y, -1); + } y += mc.textRenderer.fontHeight + 2; } @@ -83,9 +117,14 @@ public static void render(DrawContext context) { public static boolean onClicked(double mouseX, double mouseY) { int y = 3; for (Credit credit : credits) { - int x = mc.currentScreen.width - 3 - mc.textRenderer.getWidth(credit.text); + int width; + synchronized (credit.text) { + width = mc.textRenderer.getWidth(credit.text); + } + + int x = mc.currentScreen.width - 3 - width; - if (mouseX >= x && mouseX <= x + mc.textRenderer.getWidth(credit.text) && mouseY >= y && mouseY <= y + mc.textRenderer.fontHeight + 2) { + if (mouseX >= x && mouseX <= x + width && mouseY >= y && mouseY <= y + mc.textRenderer.fontHeight + 2) { if (credit.addon.getRepo() != null && credit.addon.getCommit() != null) { mc.setScreen(new CommitsScreen(GuiThemes.get(), credit.addon)); return true; diff --git a/src/main/java/meteordevelopment/meteorclient/utils/render/FontUtils.java b/src/main/java/meteordevelopment/meteorclient/utils/render/FontUtils.java index 473c266562..6fe61ad6d4 100644 --- a/src/main/java/meteordevelopment/meteorclient/utils/render/FontUtils.java +++ b/src/main/java/meteordevelopment/meteorclient/utils/render/FontUtils.java @@ -25,6 +25,8 @@ import java.util.Set; public class FontUtils { + private FontUtils() { + } public static FontInfo getSysFontInfo(File file) { return getFontInfo(stream(file)); diff --git a/src/main/java/meteordevelopment/meteorclient/utils/render/NametagUtils.java b/src/main/java/meteordevelopment/meteorclient/utils/render/NametagUtils.java index 124c124c6f..5c39aa3aa1 100644 --- a/src/main/java/meteordevelopment/meteorclient/utils/render/NametagUtils.java +++ b/src/main/java/meteordevelopment/meteorclient/utils/render/NametagUtils.java @@ -11,6 +11,7 @@ import net.minecraft.client.util.math.MatrixStack; import net.minecraft.util.math.MathHelper; import org.joml.Matrix4f; +import org.joml.Matrix4fStack; import org.joml.Vector3d; import org.joml.Vector4f; @@ -22,15 +23,18 @@ public class NametagUtils { private static final Vector4f pmMat4 = new Vector4f(); private static final Vector3d camera = new Vector3d(); private static final Vector3d cameraNegated = new Vector3d(); - private static Matrix4f model; - private static Matrix4f projection; + private static final Matrix4f model = new Matrix4f(); + private static final Matrix4f projection = new Matrix4f(); private static double windowScale; public static double scale; - public static void onRender(MatrixStack matrices, Matrix4f projection) { - model = new Matrix4f(matrices.peek().getPositionMatrix()); - NametagUtils.projection = projection; + private NametagUtils() { + } + + public static void onRender(Matrix4f modelView) { + model.set(modelView); + NametagUtils.projection.set(RenderSystem.getProjectionMatrix()); Utils.set(camera, mc.gameRenderer.getCamera().getPos()); cameraNegated.set(camera); @@ -78,23 +82,27 @@ public static boolean to2D(Vector3d pos, double scale, boolean distanceScaling, } public static void begin(Vector3d pos) { - MatrixStack matrices = RenderSystem.getModelViewStack(); + Matrix4fStack matrices = RenderSystem.getModelViewStack(); begin(matrices, pos); } public static void begin(Vector3d pos, DrawContext drawContext) { begin(pos); - begin(drawContext.getMatrices(), pos); - } - private static void begin(MatrixStack matrices, Vector3d pos) { + MatrixStack matrices = drawContext.getMatrices(); matrices.push(); - matrices.translate(pos.x, pos.y, 0); + matrices.translate((float) pos.x, (float) pos.y, 0); + matrices.scale((float) scale, (float) scale, 1); + } + + private static void begin(Matrix4fStack matrices, Vector3d pos) { + matrices.pushMatrix(); + matrices.translate((float) pos.x, (float) pos.y, 0); matrices.scale((float) scale, (float) scale, 1); } public static void end() { - RenderSystem.getModelViewStack().pop(); + RenderSystem.getModelViewStack().popMatrix(); } public static void end(DrawContext drawContext) { diff --git a/src/main/java/meteordevelopment/meteorclient/utils/render/PlayerHeadUtils.java b/src/main/java/meteordevelopment/meteorclient/utils/render/PlayerHeadUtils.java index 132cf8f5ff..0a5b69d560 100644 --- a/src/main/java/meteordevelopment/meteorclient/utils/render/PlayerHeadUtils.java +++ b/src/main/java/meteordevelopment/meteorclient/utils/render/PlayerHeadUtils.java @@ -12,6 +12,9 @@ public class PlayerHeadUtils { public static PlayerHeadTexture STEVE_HEAD; + private PlayerHeadUtils() { + } + @PostInit public static void init() { STEVE_HEAD = new PlayerHeadTexture(); diff --git a/src/main/java/meteordevelopment/meteorclient/utils/render/RenderUtils.java b/src/main/java/meteordevelopment/meteorclient/utils/render/RenderUtils.java index 99dfc3c3a5..b6896e02f8 100644 --- a/src/main/java/meteordevelopment/meteorclient/utils/render/RenderUtils.java +++ b/src/main/java/meteordevelopment/meteorclient/utils/render/RenderUtils.java @@ -37,6 +37,9 @@ public class RenderUtils { private static final Pool renderBlockPool = new Pool<>(RenderBlock::new); private static final List renderBlocks = new ArrayList<>(); + private RenderUtils() { + } + @PostInit public static void init() { MeteorClient.EVENT_BUS.subscribe(RenderUtils.class); @@ -164,12 +167,13 @@ public void render(Render3DEvent event) { double x1 = pos.getX(), y1 = pos.getY(), z1 = pos.getZ(), x2 = pos.getX() + 1, y2 = pos.getY() + 1, z2 = pos.getZ() + 1; + double d = (double) (ticks - event.tickDelta) / duration; + if (fade) { - sideColor.a *= (double) ticks / duration; - lineColor.a *= (double) ticks / duration; + sideColor.a = (int) (sideColor.a * d); + lineColor.a = (int) (lineColor.a * d); } if (shrink) { - double d = (double) ticks / duration; x1 += d; y1 += d; z1 += d; x2 -= d; y2 -= d; z2 -= d; } diff --git a/src/main/java/meteordevelopment/meteorclient/utils/render/SimpleBlockRenderer.java b/src/main/java/meteordevelopment/meteorclient/utils/render/SimpleBlockRenderer.java index 607203ec84..dcd40f1e96 100644 --- a/src/main/java/meteordevelopment/meteorclient/utils/render/SimpleBlockRenderer.java +++ b/src/main/java/meteordevelopment/meteorclient/utils/render/SimpleBlockRenderer.java @@ -28,6 +28,9 @@ public class SimpleBlockRenderer { private static final Direction[] DIRECTIONS = Direction.values(); private static final Random RANDOM = Random.create(); + private SimpleBlockRenderer() { + } + public static void renderWithBlockEntity(BlockEntity blockEntity, float tickDelta, IVertexConsumerProvider vertexConsumerProvider) { SimpleBlockRenderer.render(blockEntity.getPos(), blockEntity.getCachedState(), vertexConsumerProvider); diff --git a/src/main/java/meteordevelopment/meteorclient/utils/render/WireframeEntityRenderer.java b/src/main/java/meteordevelopment/meteorclient/utils/render/WireframeEntityRenderer.java index f808114a21..75e20acc87 100644 --- a/src/main/java/meteordevelopment/meteorclient/utils/render/WireframeEntityRenderer.java +++ b/src/main/java/meteordevelopment/meteorclient/utils/render/WireframeEntityRenderer.java @@ -42,6 +42,9 @@ public class WireframeEntityRenderer { private static Color sideColor, lineColor; private static ShapeMode shapeMode; + private WireframeEntityRenderer() { + } + public static void render(Render3DEvent event, Entity entity, double scale, Color sideColor, Color lineColor, ShapeMode shapeMode) { WireframeEntityRenderer.sideColor = sideColor; WireframeEntityRenderer.lineColor = lineColor; @@ -120,7 +123,7 @@ public static void render(Render3DEvent event, Entity entity, double scale, Colo model.animateModel(livingEntity, limbAngle, limbDistance, event.tickDelta); model.setAngles(livingEntity, limbAngle, limbDistance, animationProgress, yaw, pitch); - renderer.setupTransforms(livingEntity, matrices, animationProgress, bodyYaw, event.tickDelta); + renderer.setupTransforms(livingEntity, matrices, animationProgress, bodyYaw, event.tickDelta, livingEntity.getScale()); matrices.scale(-1, -1, 1); renderer.scale(livingEntity, matrices, event.tickDelta); matrices.translate(0, -1.5010000467300415, 0); diff --git a/src/main/java/meteordevelopment/meteorclient/utils/render/color/RainbowColors.java b/src/main/java/meteordevelopment/meteorclient/utils/render/color/RainbowColors.java index 042a0256c7..70ea373156 100644 --- a/src/main/java/meteordevelopment/meteorclient/utils/render/color/RainbowColors.java +++ b/src/main/java/meteordevelopment/meteorclient/utils/render/color/RainbowColors.java @@ -32,6 +32,9 @@ public class RainbowColors { public static final RainbowColor GLOBAL = new RainbowColor(); + private RainbowColors() { + } + @PostInit public static void init() { MeteorClient.EVENT_BUS.subscribe(RainbowColors.class); diff --git a/src/main/java/meteordevelopment/meteorclient/utils/render/postprocess/PostProcessShaders.java b/src/main/java/meteordevelopment/meteorclient/utils/render/postprocess/PostProcessShaders.java index afd5f59763..6541ad83ca 100644 --- a/src/main/java/meteordevelopment/meteorclient/utils/render/postprocess/PostProcessShaders.java +++ b/src/main/java/meteordevelopment/meteorclient/utils/render/postprocess/PostProcessShaders.java @@ -12,6 +12,9 @@ public class PostProcessShaders { public static boolean rendering; + private PostProcessShaders() { + } + @PreInit public static void init() { CHAMS = new ChamsShader(); diff --git a/src/main/java/meteordevelopment/meteorclient/utils/render/prompts/OkPrompt.java b/src/main/java/meteordevelopment/meteorclient/utils/render/prompts/OkPrompt.java index 39d8e09f11..6ec2986500 100644 --- a/src/main/java/meteordevelopment/meteorclient/utils/render/prompts/OkPrompt.java +++ b/src/main/java/meteordevelopment/meteorclient/utils/render/prompts/OkPrompt.java @@ -26,6 +26,7 @@ public class OkPrompt { private String title = ""; private final List messages = new ArrayList<>(); + private boolean dontShowAgainCheckboxVisible = true; private String id = null; private Runnable onOk = () -> {}; @@ -62,6 +63,11 @@ public OkPrompt message(String message, Object... args) { return this; } + public OkPrompt dontShowAgainCheckboxVisible(boolean visible) { + this.dontShowAgainCheckboxVisible = visible; + return this; + } + public OkPrompt id(String from) { this.id = from; return this; @@ -72,9 +78,9 @@ public OkPrompt onOk(Runnable action) { return this; } - public void show() { + public boolean show() { if (id == null) this.id(this.title); - if (Config.get().dontShowAgainPrompts.contains(id)) return; + if (Config.get().dontShowAgainPrompts.contains(id)) return false; if (!RenderSystem.isOnRenderThread()) { RenderSystem.recordRenderCall(() -> mc.setScreen(new PromptScreen(theme))); @@ -82,6 +88,8 @@ public void show() { else { mc.setScreen(new PromptScreen(theme)); } + + return true; } private class PromptScreen extends WindowScreen { @@ -96,14 +104,18 @@ public void initWidgets() { for (String line : messages) add(theme.label(line)).expandX(); add(theme.horizontalSeparator()).expandX(); - WHorizontalList checkboxContainer = add(theme.horizontalList()).expandX().widget(); - WCheckbox dontShowAgainCheckbox = checkboxContainer.add(theme.checkbox(false)).widget(); - checkboxContainer.add(theme.label("Don't show this again.")).expandX(); + WCheckbox dontShowAgainCheckbox; + + if (dontShowAgainCheckboxVisible) { + WHorizontalList checkboxContainer = add(theme.horizontalList()).expandX().widget(); + dontShowAgainCheckbox = checkboxContainer.add(theme.checkbox(false)).widget(); + checkboxContainer.add(theme.label("Don't show this again.")).expandX(); + } else dontShowAgainCheckbox = null; WHorizontalList list = add(theme.horizontalList()).expandX().widget(); WButton okButton = list.add(theme.button("Ok")).expandX().widget(); okButton.action = () -> { - if (dontShowAgainCheckbox.checked) Config.get().dontShowAgainPrompts.add(id); + if (dontShowAgainCheckbox != null && dontShowAgainCheckbox.checked) Config.get().dontShowAgainPrompts.add(id); onOk.run(); close(); }; diff --git a/src/main/java/meteordevelopment/meteorclient/utils/render/prompts/YesNoPrompt.java b/src/main/java/meteordevelopment/meteorclient/utils/render/prompts/YesNoPrompt.java index 131028b9b9..edf8d4e9fb 100644 --- a/src/main/java/meteordevelopment/meteorclient/utils/render/prompts/YesNoPrompt.java +++ b/src/main/java/meteordevelopment/meteorclient/utils/render/prompts/YesNoPrompt.java @@ -26,6 +26,7 @@ public class YesNoPrompt { private String title = ""; private final List messages = new ArrayList<>(); + private boolean dontShowAgainCheckboxVisible = true; private String id = null; private Runnable onYes = () -> {}; @@ -63,6 +64,11 @@ public YesNoPrompt message(String message, Object... args) { return this; } + public YesNoPrompt dontShowAgainCheckboxVisible(boolean visible) { + this.dontShowAgainCheckboxVisible = visible; + return this; + } + public YesNoPrompt id(String from) { this.id = from; return this; @@ -78,9 +84,9 @@ public YesNoPrompt onNo(Runnable action) { return this; } - public void show() { + public boolean show() { if (id == null) this.id(this.title); - if (Config.get().dontShowAgainPrompts.contains(id)) return; + if (Config.get().dontShowAgainPrompts.contains(id)) return false; if (!RenderSystem.isOnRenderThread()) { RenderSystem.recordRenderCall(() -> mc.setScreen(new PromptScreen(theme))); @@ -88,6 +94,8 @@ public void show() { else { mc.setScreen(new PromptScreen(theme)); } + + return true; } private class PromptScreen extends WindowScreen { @@ -102,22 +110,26 @@ public void initWidgets() { for (String line : messages) add(theme.label(line)).expandX(); add(theme.horizontalSeparator()).expandX(); - WHorizontalList checkboxContainer = add(theme.horizontalList()).expandX().widget(); - WCheckbox dontShowAgainCheckbox = checkboxContainer.add(theme.checkbox(false)).widget(); - checkboxContainer.add(theme.label("Don't show this again.")).expandX(); + WCheckbox dontShowAgainCheckbox; + + if (dontShowAgainCheckboxVisible) { + WHorizontalList checkboxContainer = add(theme.horizontalList()).expandX().widget(); + dontShowAgainCheckbox = checkboxContainer.add(theme.checkbox(false)).widget(); + checkboxContainer.add(theme.label("Don't show this again.")).expandX(); + } else dontShowAgainCheckbox = null; WHorizontalList list = add(theme.horizontalList()).expandX().widget(); WButton yesButton = list.add(theme.button("Yes")).expandX().widget(); yesButton.action = () -> { - if (dontShowAgainCheckbox.checked) Config.get().dontShowAgainPrompts.add(id); + if (dontShowAgainCheckbox != null && dontShowAgainCheckbox.checked) Config.get().dontShowAgainPrompts.add(id); onYes.run(); close(); }; WButton noButton = list.add(theme.button("No")).expandX().widget(); noButton.action = () -> { - if (dontShowAgainCheckbox.checked) Config.get().dontShowAgainPrompts.add(id); + if (dontShowAgainCheckbox != null && dontShowAgainCheckbox.checked) Config.get().dontShowAgainPrompts.add(id); onNo.run(); close(); }; diff --git a/src/main/java/meteordevelopment/meteorclient/utils/tooltip/BannerTooltipComponent.java b/src/main/java/meteordevelopment/meteorclient/utils/tooltip/BannerTooltipComponent.java index 765c4dce0e..bcc844fa4a 100644 --- a/src/main/java/meteordevelopment/meteorclient/utils/tooltip/BannerTooltipComponent.java +++ b/src/main/java/meteordevelopment/meteorclient/utils/tooltip/BannerTooltipComponent.java @@ -5,7 +5,6 @@ package meteordevelopment.meteorclient.utils.tooltip; -import net.minecraft.block.entity.BannerBlockEntity; import net.minecraft.client.font.TextRenderer; import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.tooltip.TooltipComponent; @@ -17,6 +16,7 @@ import net.minecraft.client.render.entity.model.EntityModelLayers; import net.minecraft.client.render.model.ModelLoader; import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.component.DataComponentTypes; import net.minecraft.item.BannerItem; import net.minecraft.item.ItemStack; @@ -71,10 +71,8 @@ public void drawItems(TextRenderer textRenderer, int x, int y, DrawContext conte bannerField, ModelLoader.BANNER_BASE, true, - BannerBlockEntity.getPatternsFromNbt( - ((BannerItem) banner.getItem()).getColor(), - BannerBlockEntity.getPatternListNbt(banner) - ) + ((BannerItem) banner.getItem()).getColor(), + banner.get(DataComponentTypes.BANNER_PATTERNS) ); matrices.pop(); matrices.pop(); diff --git a/src/main/java/meteordevelopment/meteorclient/utils/tooltip/MapTooltipComponent.java b/src/main/java/meteordevelopment/meteorclient/utils/tooltip/MapTooltipComponent.java index 2b1f991f18..ffbfbec6f2 100644 --- a/src/main/java/meteordevelopment/meteorclient/utils/tooltip/MapTooltipComponent.java +++ b/src/main/java/meteordevelopment/meteorclient/utils/tooltip/MapTooltipComponent.java @@ -14,6 +14,7 @@ import net.minecraft.client.render.GameRenderer; import net.minecraft.client.render.VertexConsumerProvider; import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.component.type.MapIdComponent; import net.minecraft.item.FilledMapItem; import net.minecraft.item.map.MapState; import net.minecraft.util.Identifier; @@ -61,13 +62,13 @@ public void drawItems(TextRenderer textRenderer, int x, int y, DrawContext conte // Contents VertexConsumerProvider.Immediate consumer = mc.getBufferBuilders().getEntityVertexConsumers(); - MapState mapState = FilledMapItem.getMapState(mapId, mc.world); + MapState mapState = FilledMapItem.getMapState(new MapIdComponent(mapId), mc.world); if (mapState == null) return; matrices.push(); matrices.translate(x, y, 0); matrices.scale((float) scale, (float) scale, 0); matrices.translate(8, 8, 0); - mc.gameRenderer.getMapRenderer().draw(matrices, consumer, mapId, mapState, false, 0xF000F0); + mc.gameRenderer.getMapRenderer().draw(matrices, consumer, new MapIdComponent(mapId), mapState, false, 0xF000F0); consumer.draw(); matrices.pop(); } diff --git a/src/main/java/meteordevelopment/meteorclient/utils/world/BlockEntityIterator.java b/src/main/java/meteordevelopment/meteorclient/utils/world/BlockEntityIterator.java index 07f8c82e6d..42c0353e38 100644 --- a/src/main/java/meteordevelopment/meteorclient/utils/world/BlockEntityIterator.java +++ b/src/main/java/meteordevelopment/meteorclient/utils/world/BlockEntityIterator.java @@ -29,7 +29,7 @@ private void nextChunk() { Map blockEntityMap = ((ChunkAccessor) chunks.next()).getBlockEntities(); - if (blockEntityMap.size() > 0) { + if (!blockEntityMap.isEmpty()) { blockEntities = blockEntityMap.values().iterator(); break; } diff --git a/src/main/java/meteordevelopment/meteorclient/utils/world/BlockIterator.java b/src/main/java/meteordevelopment/meteorclient/utils/world/BlockIterator.java index a66fa68655..89d192fda4 100644 --- a/src/main/java/meteordevelopment/meteorclient/utils/world/BlockIterator.java +++ b/src/main/java/meteordevelopment/meteorclient/utils/world/BlockIterator.java @@ -33,6 +33,9 @@ public class BlockIterator { private static boolean disableCurrent; + private BlockIterator() { + } + @PreInit public static void init() { MeteorClient.EVENT_BUS.subscribe(BlockIterator.class); diff --git a/src/main/java/meteordevelopment/meteorclient/utils/world/BlockUtils.java b/src/main/java/meteordevelopment/meteorclient/utils/world/BlockUtils.java index 4149068d9b..ef5cc93a1e 100644 --- a/src/main/java/meteordevelopment/meteorclient/utils/world/BlockUtils.java +++ b/src/main/java/meteordevelopment/meteorclient/utils/world/BlockUtils.java @@ -7,10 +7,10 @@ import meteordevelopment.meteorclient.MeteorClient; import meteordevelopment.meteorclient.events.world.TickEvent; +import meteordevelopment.meteorclient.systems.modules.Modules; +import meteordevelopment.meteorclient.systems.modules.player.InstaMine; import meteordevelopment.meteorclient.utils.PreInit; -import meteordevelopment.meteorclient.utils.player.FindItemResult; -import meteordevelopment.meteorclient.utils.player.InvUtils; -import meteordevelopment.meteorclient.utils.player.Rotations; +import meteordevelopment.meteorclient.utils.player.*; import meteordevelopment.orbit.EventHandler; import meteordevelopment.orbit.EventPriority; import net.minecraft.block.*; @@ -20,6 +20,7 @@ import net.minecraft.enchantment.Enchantments; import net.minecraft.entity.effect.StatusEffectUtil; import net.minecraft.entity.effect.StatusEffects; +import net.minecraft.item.BlockItem; import net.minecraft.item.ItemStack; import net.minecraft.network.packet.c2s.play.HandSwingC2SPacket; import net.minecraft.registry.tag.FluidTags; @@ -35,10 +36,14 @@ import static meteordevelopment.meteorclient.MeteorClient.mc; +@SuppressWarnings("ConstantConditions") public class BlockUtils { public static boolean breaking; private static boolean breakingThisTick; + private BlockUtils() { + } + @PreInit public static void init() { MeteorClient.EVENT_BUS.subscribe(BlockUtils.class); @@ -77,7 +82,11 @@ public static boolean place(BlockPos blockPos, FindItemResult findItemResult, bo public static boolean place(BlockPos blockPos, Hand hand, int slot, boolean rotate, int rotationPriority, boolean swingHand, boolean checkEntities, boolean swapBack) { if (slot < 0 || slot > 8) return false; - if (!canPlace(blockPos, checkEntities)) return false; + + Block toPlace = Blocks.OBSIDIAN; + ItemStack i = hand == Hand.MAIN_HAND ? mc.player.getInventory().getStack(slot) : mc.player.getInventory().getStack(SlotUtils.OFFHAND); + if (i.getItem() instanceof BlockItem blockItem) toPlace = blockItem.getBlock(); + if (!canPlaceBlock(blockPos, checkEntities, toPlace)) return false; Vec3d hitPos = Vec3d.ofCenter(blockPos); @@ -128,7 +137,7 @@ public static void interact(BlockHitResult blockHitResult, Hand hand, boolean sw mc.player.input.sneaking = wasSneaking; } - public static boolean canPlace(BlockPos blockPos, boolean checkEntities) { + public static boolean canPlaceBlock(BlockPos blockPos, boolean checkEntities, Block block) { if (blockPos == null) return false; // Check y level @@ -138,7 +147,11 @@ public static boolean canPlace(BlockPos blockPos, boolean checkEntities) { if (!mc.world.getBlockState(blockPos).isReplaceable()) return false; // Check if intersects entities - return !checkEntities || mc.world.canPlace(Blocks.OBSIDIAN.getDefaultState(), blockPos, ShapeContext.absent()); + return !checkEntities || mc.world.canPlace(block.getDefaultState(), blockPos, ShapeContext.absent()); + } + + public static boolean canPlace(BlockPos blockPos, boolean checkEntities) { + return canPlaceBlock(blockPos, checkEntities, Blocks.OBSIDIAN); } public static boolean canPlace(BlockPos blockPos) { @@ -146,6 +159,10 @@ public static boolean canPlace(BlockPos blockPos) { } public static Direction getPlaceSide(BlockPos blockPos) { + Vec3d lookVec = blockPos.toCenterPos().subtract(mc.player.getEyePos()); + double bestRelevancy = -Double.MAX_VALUE; + Direction bestSide = null; + for (Direction side : Direction.values()) { BlockPos neighbor = blockPos.offset(side); BlockState state = mc.world.getBlockState(neighbor); @@ -156,15 +173,20 @@ public static Direction getPlaceSide(BlockPos blockPos) { // Check if neighbour is a fluid if (!state.getFluidState().isEmpty()) continue; - return side; + double relevancy = side.getAxis().choose(lookVec.getX(), lookVec.getY(), lookVec.getZ()) * side.getDirection().offset(); + if (relevancy > bestRelevancy) { + bestRelevancy = relevancy; + bestSide = side; + } } - return null; + return bestSide; } public static Direction getClosestPlaceSide(BlockPos blockPos) { return getClosestPlaceSide(blockPos, mc.player.getEyePos()); } + public static Direction getClosestPlaceSide(BlockPos blockPos, Vec3d pos) { Direction closestSide = null; double closestDistance = Double.MAX_VALUE; @@ -210,9 +232,15 @@ private static void onTickPost(TickEvent.Post event) { public static boolean breakBlock(BlockPos blockPos, boolean swing) { if (!canBreak(blockPos, mc.world.getBlockState(blockPos))) return false; - // Creating new instance of block pos because minecraft assigns the parameter to a field and we don't want it to change when it has been stored in a field somewhere + // Creating new instance of block pos because minecraft assigns the parameter to a field, and we don't want it to change when it has been stored in a field somewhere BlockPos pos = blockPos instanceof BlockPos.Mutable ? new BlockPos(blockPos) : blockPos; + InstaMine im = Modules.get().get(InstaMine.class); + if (im != null && im.isActive() && im.blockPos.equals(pos) && im.shouldMine()) { + im.sendPacket(); + return true; + } + if (mc.interactionManager.isBreakingBlock()) mc.interactionManager.updateBlockBreakingProgress(pos, getDirection(blockPos)); else mc.interactionManager.attackBlock(pos, getDirection(blockPos)); @@ -260,6 +288,10 @@ public static float calcBlockBreakingDelta2(BlockPos blockPos, float breakSpeed) public static boolean isClickable(Block block) { return block instanceof CraftingTableBlock || block instanceof AnvilBlock + || block instanceof LoomBlock + || block instanceof CartographyTableBlock + || block instanceof GrindstoneBlock + || block instanceof StonecutterBlock || block instanceof ButtonBlock || block instanceof AbstractPressurePlateBlock || block instanceof BlockWithEntity diff --git a/src/main/java/meteordevelopment/meteorclient/utils/world/Dir.java b/src/main/java/meteordevelopment/meteorclient/utils/world/Dir.java index 452b4c7b3f..5ad585067e 100644 --- a/src/main/java/meteordevelopment/meteorclient/utils/world/Dir.java +++ b/src/main/java/meteordevelopment/meteorclient/utils/world/Dir.java @@ -15,6 +15,9 @@ public class Dir { public static final byte WEST = 1 << 5; public static final byte EAST = 1 << 6; + private Dir() { + } + public static byte get(Direction dir) { return switch (dir) { case UP -> UP; diff --git a/src/main/java/meteordevelopment/meteorclient/utils/world/TickRate.java b/src/main/java/meteordevelopment/meteorclient/utils/world/TickRate.java index 14a43dbc6c..7acd5637e8 100644 --- a/src/main/java/meteordevelopment/meteorclient/utils/world/TickRate.java +++ b/src/main/java/meteordevelopment/meteorclient/utils/world/TickRate.java @@ -34,7 +34,7 @@ private TickRate() { private void onReceivePacket(PacketEvent.Receive event) { if (event.packet instanceof WorldTimeUpdateS2CPacket) { long now = System.currentTimeMillis(); - float timeElapsed = (float) (now - timeLastTimeUpdate) / 1000.0F; + float timeElapsed = (now - timeLastTimeUpdate) / 1000.0F; tickRates[nextIndex] = MathHelper.clamp(20.0f / timeElapsed, 0.0f, 20.0f); nextIndex = (nextIndex + 1) % tickRates.length; timeLastTimeUpdate = now; diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index c6253b2dc1..ee4cf8bf52 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -35,14 +35,14 @@ "fabric-api:module-lifecycle": "stable" }, "depends": { - "java": ">=17", - "minecraft": "${minecraft_version}", + "java": ">=21", + "minecraft": ["1.20.5", "${minecraft_version}"], "fabricloader": ">=${loader_version}" }, "breaks": { "optifabric": "*", "feather": "*", - "sodium": "<0.5.6", + "sodium": "<0.5.8", "morechathistory": "*", "quilt_loader": "*" } diff --git a/src/main/resources/meteor-client-baritone.mixins.json b/src/main/resources/meteor-client-baritone.mixins.json index 7f20eb9675..8242f6d2c3 100644 --- a/src/main/resources/meteor-client-baritone.mixins.json +++ b/src/main/resources/meteor-client-baritone.mixins.json @@ -1,7 +1,7 @@ { "required": true, "package": "meteordevelopment.meteorclient.mixin.baritone", - "compatibilityLevel": "JAVA_17", + "compatibilityLevel": "JAVA_21", "plugin": "meteordevelopment.meteorclient.MixinPlugin", "client": [ "ComeCommandMixin" diff --git a/src/main/resources/meteor-client-canvas.mixins.json b/src/main/resources/meteor-client-canvas.mixins.json index 9926bc6d9e..66b34ff386 100644 --- a/src/main/resources/meteor-client-canvas.mixins.json +++ b/src/main/resources/meteor-client-canvas.mixins.json @@ -1,7 +1,7 @@ { "required": false, "package": "meteordevelopment.meteorclient.mixin.canvas", - "compatibilityLevel": "JAVA_17", + "compatibilityLevel": "JAVA_21", "plugin": "meteordevelopment.meteorclient.MixinPlugin", "client": [ ], diff --git a/src/main/resources/meteor-client-indigo.mixins.json b/src/main/resources/meteor-client-indigo.mixins.json index 5bce3e25ad..45ebec59a0 100644 --- a/src/main/resources/meteor-client-indigo.mixins.json +++ b/src/main/resources/meteor-client-indigo.mixins.json @@ -1,7 +1,7 @@ { "required": false, "package": "meteordevelopment.meteorclient.mixin.indigo", - "compatibilityLevel": "JAVA_17", + "compatibilityLevel": "JAVA_21", "plugin": "meteordevelopment.meteorclient.MixinPlugin", "client": [ "AbstractBlockRenderContextMixin", diff --git a/src/main/resources/meteor-client-indium.mixins.json b/src/main/resources/meteor-client-indium.mixins.json index 536550283b..6e2db25f32 100644 --- a/src/main/resources/meteor-client-indium.mixins.json +++ b/src/main/resources/meteor-client-indium.mixins.json @@ -1,7 +1,7 @@ { "required": true, "package": "meteordevelopment.meteorclient.mixin.indium", - "compatibilityLevel": "JAVA_17", + "compatibilityLevel": "JAVA_21", "plugin": "meteordevelopment.meteorclient.MixinPlugin", "client": [ "AbstractBlockRenderContextMixin" diff --git a/src/main/resources/meteor-client-lithium.mixins.json b/src/main/resources/meteor-client-lithium.mixins.json index 53450f38f3..fcad6bd961 100644 --- a/src/main/resources/meteor-client-lithium.mixins.json +++ b/src/main/resources/meteor-client-lithium.mixins.json @@ -1,7 +1,7 @@ { "required": false, "package": "meteordevelopment.meteorclient.mixin.lithium", - "compatibilityLevel": "JAVA_17", + "compatibilityLevel": "JAVA_21", "plugin": "meteordevelopment.meteorclient.MixinPlugin", "client": [ "ChunkAwareBlockCollisionSweeperMixin" diff --git a/src/main/resources/meteor-client-sodium.mixins.json b/src/main/resources/meteor-client-sodium.mixins.json index 6e78228a3d..c41ff42c6d 100644 --- a/src/main/resources/meteor-client-sodium.mixins.json +++ b/src/main/resources/meteor-client-sodium.mixins.json @@ -1,7 +1,7 @@ { "required": false, "package": "meteordevelopment.meteorclient.mixin.sodium", - "compatibilityLevel": "JAVA_17", + "compatibilityLevel": "JAVA_21", "plugin": "meteordevelopment.meteorclient.MixinPlugin", "client": [ "SodiumLightDataAccessMixin", diff --git a/src/main/resources/meteor-client.accesswidener b/src/main/resources/meteor-client.accesswidener index 121a2c6331..15a8b56f6c 100644 --- a/src/main/resources/meteor-client.accesswidener +++ b/src/main/resources/meteor-client.accesswidener @@ -16,7 +16,7 @@ accessible class net/minecraft/client/model/ModelPart$Quad accessible class net/minecraft/client/model/ModelPart$Vertex accessible field net/minecraft/client/model/ModelPart$Cuboid sides [Lnet/minecraft/client/model/ModelPart$Quad; accessible method net/minecraft/client/render/entity/PlayerEntityRenderer getArmPose (Lnet/minecraft/client/network/AbstractClientPlayerEntity;Lnet/minecraft/util/Hand;)Lnet/minecraft/client/render/entity/model/BipedEntityModel$ArmPose; -accessible method net/minecraft/client/render/entity/LivingEntityRenderer setupTransforms (Lnet/minecraft/entity/LivingEntity;Lnet/minecraft/client/util/math/MatrixStack;FFF)V +accessible method net/minecraft/client/render/entity/LivingEntityRenderer setupTransforms (Lnet/minecraft/entity/LivingEntity;Lnet/minecraft/client/util/math/MatrixStack;FFFF)V accessible method net/minecraft/client/render/entity/LivingEntityRenderer scale (Lnet/minecraft/entity/LivingEntity;Lnet/minecraft/client/util/math/MatrixStack;F)V accessible method net/minecraft/client/render/entity/LivingEntityRenderer getAnimationProgress (Lnet/minecraft/entity/LivingEntity;F)F @@ -75,3 +75,5 @@ accessible field net/minecraft/item/ItemGroups INVENTORY Lnet/minecraft/regi accessible field net/minecraft/client/render/item/ItemRenderer TRIDENT Lnet/minecraft/client/util/ModelIdentifier; accessible field net/minecraft/client/render/item/ItemRenderer SPYGLASS Lnet/minecraft/client/util/ModelIdentifier; + +accessible class net/minecraft/entity/effect/StatusEffect$EffectAttributeModifierCreator diff --git a/src/main/resources/meteor-client.mixins.json b/src/main/resources/meteor-client.mixins.json index 0c67ec2902..fdc5299987 100644 --- a/src/main/resources/meteor-client.mixins.json +++ b/src/main/resources/meteor-client.mixins.json @@ -1,7 +1,7 @@ { "required": true, "package": "meteordevelopment.meteorclient.mixin", - "compatibilityLevel": "JAVA_17", + "compatibilityLevel": "JAVA_21", "plugin": "meteordevelopment.meteorclient.MixinPlugin", "client": [ "AbstractBlockAccessor", @@ -13,7 +13,6 @@ "AbstractSignEditScreenAccessor", "AbstractSignEditScreenMixin", "ArmorFeatureRendererMixin", - "AttributeContainerMixin", "BackgroundRendererMixin", "BakedQuadMixin", "BannerBlockEntityRendererMixin", @@ -67,15 +66,14 @@ "CreativeInventoryScreenAccessor", "CreativeSlotMixin", "CrossbowItemAccessor", - "CustomPayloadS2CPacketMixin", "DefaultSkinHelperMixin", "DisconnectedScreenMixin", "DrawContextMixin", "EnchantingTableBlockEntityRendererMixin", "EndCrystalEntityRendererMixin", "EntityAccessor", - "EntityAttributeInstanceMixin", "EntityBucketItemAccessor", + "EntityEffectParticleEffectAccessor", "EntityMixin", "EntityRenderDispatcherMixin", "EntityRendererMixin", @@ -123,6 +121,7 @@ "MobSpawnerBlockEntityRendererMixin", "MouseMixin", "MultiplayerScreenMixin", + "MutableTextMixin", "PacketByteBufMixin", "ParticleManagerMixin", "PlayerArmorSlotMixin", @@ -148,18 +147,19 @@ "SectionedEntityCacheAccessor", "ShapeIndexBufferAccessor", "ShulkerBoxBlockMixin", - "ShulkerEntityAccessor", "SignBlockEntityRendererMixin", "SimpleEntityLookupAccessor", "SimpleOptionMixin", "SlimeBlockMixin", "SlotMixin", "SoundSystemMixin", + "StatusEffectAccessor", "StatusEffectInstanceAccessor", "StatusEffectInstanceMixin", "StringHelperMixin", "SweetBerryBushBlockMixin", "TextHandlerAccessor", + "TextMixin", "TextRendererMixin", "TextVisitFactoryMixin", "TransformationMixin",