diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index dda22acd3f..2dc2726028 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -28,10 +28,10 @@ jobs: - name: Validate Gradle wrapper uses: gradle/actions/wrapper-validation@v3 - - name: Set up Java 17 + - name: Set up Java 21 uses: actions/setup-java@v4 with: - java-version: '17' + java-version: '21' distribution: 'microsoft' - name: Grant execute permission for gradlew diff --git a/README.md b/README.md index c0b9e6447d..10645cfc62 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ ## Setup (for developers) -(This assumes that you are using Windows with [Eclipse](https://www.eclipse.org/downloads/) and [Java Development Kit 17](https://adoptium.net/?variant=openjdk17&jvmVariant=hotspot) already installed.) +(This assumes that you are using Windows with [Eclipse](https://www.eclipse.org/downloads/) and [Java Development Kit 21](https://adoptium.net/?variant=openjdk21&jvmVariant=hotspot) already installed.) 1. Run this command in PowerShell: diff --git a/build.gradle b/build.gradle index 9cd0d081ae..f09b401d66 100644 --- a/build.gradle +++ b/build.gradle @@ -12,8 +12,8 @@ plugins { def ENV = System.getenv() -sourceCompatibility = JavaVersion.VERSION_17 -targetCompatibility = JavaVersion.VERSION_17 +sourceCompatibility = JavaVersion.VERSION_21 +targetCompatibility = JavaVersion.VERSION_21 archivesBaseName = project.archives_base_name version = project.mod_version @@ -58,8 +58,8 @@ processResources { } tasks.withType(JavaCompile).configureEach { - // Minecraft 1.18 (1.18-pre2) upwards uses Java 17. - it.options.release = 17 + // Minecraft 1.20.5 (24w14a) upwards uses Java 21. + it.options.release = 21 } java { diff --git a/gradle.properties b/gradle.properties index dd92071f71..4f2a8c12d2 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,15 +5,15 @@ org.gradle.parallel=true # Fabric Properties # check these at https://fabricmc.net/develop/ and # https://www.curseforge.com/minecraft/mc-mods/fabric-api -minecraft_version=1.20.4 -yarn_mappings=1.20.4+build.3 +minecraft_version=1.20.6 +yarn_mappings=1.20.6+build.1 loader_version=0.15.10 #Fabric api -fabric_version=0.97.0+1.20.4 +fabric_version=0.97.8+1.20.6 # Mod Properties -mod_version = v7.42pre2-MC1.20.4 +mod_version = v7.42pre2-MC1.20.6 maven_group = net.wurstclient archives_base_name = Wurst-Client diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index d64cd49177..7f93135c49 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/src/main/java/net/wurstclient/WurstClient.java b/src/main/java/net/wurstclient/WurstClient.java index 206983b3bf..e01bddb93d 100644 --- a/src/main/java/net/wurstclient/WurstClient.java +++ b/src/main/java/net/wurstclient/WurstClient.java @@ -59,7 +59,7 @@ public enum WurstClient public static IMinecraftClient IMC; public static final String VERSION = "7.42pre2"; - public static final String MC_VERSION = "1.20.4"; + public static final String MC_VERSION = "1.20.6"; private WurstAnalytics analytics; private EventManager eventManager; diff --git a/src/main/java/net/wurstclient/altmanager/MicrosoftLoginManager.java b/src/main/java/net/wurstclient/altmanager/MicrosoftLoginManager.java index f5fbbd10f3..8179146cea 100644 --- a/src/main/java/net/wurstclient/altmanager/MicrosoftLoginManager.java +++ b/src/main/java/net/wurstclient/altmanager/MicrosoftLoginManager.java @@ -14,6 +14,7 @@ import java.io.OutputStream; import java.net.HttpURLConnection; import java.net.MalformedURLException; +import java.net.URI; import java.net.URL; import java.net.URLConnection; import java.net.URLDecoder; @@ -197,7 +198,7 @@ private static String microsoftLogin(String email, String password, try { - URL url = new URL(urlPost); + URL url = URI.create(urlPost).toURL(); HttpURLConnection connection = (HttpURLConnection)url.openConnection(); @@ -504,7 +505,7 @@ private static URL createURL(String url) { try { - return new URL(url); + return URI.create(url).toURL(); }catch(MalformedURLException e) { diff --git a/src/main/java/net/wurstclient/analytics/dmurph/JGoogleAnalyticsTracker.java b/src/main/java/net/wurstclient/analytics/dmurph/JGoogleAnalyticsTracker.java index 0fd3d8146d..e558257bca 100644 --- a/src/main/java/net/wurstclient/analytics/dmurph/JGoogleAnalyticsTracker.java +++ b/src/main/java/net/wurstclient/analytics/dmurph/JGoogleAnalyticsTracker.java @@ -30,6 +30,7 @@ import java.net.Proxy; import java.net.Proxy.Type; import java.net.SocketAddress; +import java.net.URI; import java.net.URL; import java.util.LinkedList; import java.util.Scanner; @@ -532,7 +533,7 @@ private static void dispatchRequest(String argURL, String userAgent) { try { - URL url = new URL(argURL); + URL url = URI.create(argURL).toURL(); HttpURLConnection connection = (HttpURLConnection)url.openConnection(proxy); connection.setRequestMethod("GET"); diff --git a/src/main/java/net/wurstclient/clickgui/screens/AddBookOfferScreen.java b/src/main/java/net/wurstclient/clickgui/screens/AddBookOfferScreen.java index 505c960fc1..0322c2d69d 100644 --- a/src/main/java/net/wurstclient/clickgui/screens/AddBookOfferScreen.java +++ b/src/main/java/net/wurstclient/clickgui/screens/AddBookOfferScreen.java @@ -291,6 +291,8 @@ public void render(DrawContext context, int mouseX, int mouseY, float partialTicks) { MatrixStack matrixStack = context.getMatrices(); + renderBackground(context, mouseX, mouseY, partialTicks); + listGui.render(context, mouseX, mouseY, partialTicks); matrixStack.push(); diff --git a/src/main/java/net/wurstclient/clickgui/screens/EditBlockListScreen.java b/src/main/java/net/wurstclient/clickgui/screens/EditBlockListScreen.java index eaf1a46be6..feaefa5949 100644 --- a/src/main/java/net/wurstclient/clickgui/screens/EditBlockListScreen.java +++ b/src/main/java/net/wurstclient/clickgui/screens/EditBlockListScreen.java @@ -165,6 +165,8 @@ public void render(DrawContext context, int mouseX, int mouseY, float partialTicks) { MatrixStack matrixStack = context.getMatrices(); + renderBackground(context, mouseX, mouseY, partialTicks); + listGui.render(context, mouseX, mouseY, partialTicks); context.drawCenteredTextWithShadow(client.textRenderer, diff --git a/src/main/java/net/wurstclient/clickgui/screens/EditBookOfferScreen.java b/src/main/java/net/wurstclient/clickgui/screens/EditBookOfferScreen.java index f54aeb74f5..5b33aeb40a 100644 --- a/src/main/java/net/wurstclient/clickgui/screens/EditBookOfferScreen.java +++ b/src/main/java/net/wurstclient/clickgui/screens/EditBookOfferScreen.java @@ -254,7 +254,7 @@ public void render(DrawContext context, int mouseX, int mouseY, float partialTicks) { MatrixStack matrixStack = context.getMatrices(); - renderBackgroundTexture(context); + renderBackground(context, mouseX, mouseY, partialTicks); matrixStack.push(); matrixStack.translate(0, 0, 300); diff --git a/src/main/java/net/wurstclient/clickgui/screens/EditBookOffersScreen.java b/src/main/java/net/wurstclient/clickgui/screens/EditBookOffersScreen.java index 1e8c0abab6..d834e1150f 100644 --- a/src/main/java/net/wurstclient/clickgui/screens/EditBookOffersScreen.java +++ b/src/main/java/net/wurstclient/clickgui/screens/EditBookOffersScreen.java @@ -183,6 +183,8 @@ public void render(DrawContext context, int mouseX, int mouseY, float partialTicks) { MatrixStack matrixStack = context.getMatrices(); + renderBackground(context, mouseX, mouseY, partialTicks); + listGui.render(context, mouseX, mouseY, partialTicks); matrixStack.push(); diff --git a/src/main/java/net/wurstclient/clickgui/screens/EditItemListScreen.java b/src/main/java/net/wurstclient/clickgui/screens/EditItemListScreen.java index 3153aedf7b..a1a21b0e2a 100644 --- a/src/main/java/net/wurstclient/clickgui/screens/EditItemListScreen.java +++ b/src/main/java/net/wurstclient/clickgui/screens/EditItemListScreen.java @@ -167,6 +167,8 @@ public void render(DrawContext context, int mouseX, int mouseY, float partialTicks) { MatrixStack matrixStack = context.getMatrices(); + renderBackground(context, mouseX, mouseY, partialTicks); + listGui.render(context, mouseX, mouseY, partialTicks); context.drawCenteredTextWithShadow(client.textRenderer, diff --git a/src/main/java/net/wurstclient/commands/AuthorCmd.java b/src/main/java/net/wurstclient/commands/AuthorCmd.java index cc8d58eab6..2e988b009a 100644 --- a/src/main/java/net/wurstclient/commands/AuthorCmd.java +++ b/src/main/java/net/wurstclient/commands/AuthorCmd.java @@ -7,10 +7,10 @@ */ package net.wurstclient.commands; -import net.minecraft.item.Item; +import net.minecraft.component.DataComponentTypes; +import net.minecraft.component.type.WrittenBookContentComponent; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; -import net.minecraft.nbt.NbtString; import net.wurstclient.command.CmdError; import net.wurstclient.command.CmdException; import net.wurstclient.command.CmdSyntaxError; @@ -33,15 +33,20 @@ public void call(String[] args) throws CmdException if(!MC.player.getAbilities().creativeMode) throw new CmdError("Creative mode only."); - ItemStack heldItem = MC.player.getInventory().getMainHandStack(); - int heldItemID = Item.getRawId(heldItem.getItem()); - int writtenBookID = Item.getRawId(Items.WRITTEN_BOOK); - - if(heldItemID != writtenBookID) + ItemStack heldStack = MC.player.getInventory().getMainHandStack(); + if(!heldStack.isOf(Items.WRITTEN_BOOK)) throw new CmdError( "You must hold a written book in your main hand."); + WrittenBookContentComponent oldData = heldStack.getComponents() + .get(DataComponentTypes.WRITTEN_BOOK_CONTENT); + if(oldData == null) + throw new CmdError("Can't find book data."); + String author = String.join(" ", args); - heldItem.setSubNbt("author", NbtString.of(author)); + WrittenBookContentComponent newData = + new WrittenBookContentComponent(oldData.title(), author, + oldData.generation(), oldData.pages(), oldData.resolved()); + heldStack.set(DataComponentTypes.WRITTEN_BOOK_CONTENT, newData); } } diff --git a/src/main/java/net/wurstclient/commands/EnchantCmd.java b/src/main/java/net/wurstclient/commands/EnchantCmd.java index f8c745ca53..121000ca2b 100644 --- a/src/main/java/net/wurstclient/commands/EnchantCmd.java +++ b/src/main/java/net/wurstclient/commands/EnchantCmd.java @@ -16,7 +16,6 @@ import net.wurstclient.command.CmdSyntaxError; import net.wurstclient.command.Command; import net.wurstclient.util.ChatUtils; -import net.wurstclient.util.ItemUtils; public final class EnchantCmd extends Command { @@ -71,7 +70,7 @@ private void enchant(ItemStack stack, int level) continue; } - ItemUtils.addEnchantment(stack, enchantment, level); + stack.addEnchantment(enchantment, level); } } diff --git a/src/main/java/net/wurstclient/commands/GiveCmd.java b/src/main/java/net/wurstclient/commands/GiveCmd.java index a55604bb98..8cfc07ecf4 100644 --- a/src/main/java/net/wurstclient/commands/GiveCmd.java +++ b/src/main/java/net/wurstclient/commands/GiveCmd.java @@ -11,6 +11,8 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException; +import net.minecraft.component.DataComponentTypes; +import net.minecraft.component.type.NbtComponent; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; @@ -83,7 +85,7 @@ public void call(String[] args) throws CmdException try { NbtCompound tag = StringNbtReader.parse(nbt); - stack.setNbt(tag); + NbtComponent.set(DataComponentTypes.CUSTOM_DATA, stack, tag); }catch(CommandSyntaxException e) { diff --git a/src/main/java/net/wurstclient/commands/ModifyCmd.java b/src/main/java/net/wurstclient/commands/ModifyCmd.java index 675921b32d..5fe1f81cfd 100644 --- a/src/main/java/net/wurstclient/commands/ModifyCmd.java +++ b/src/main/java/net/wurstclient/commands/ModifyCmd.java @@ -12,6 +12,8 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException; import net.minecraft.client.network.ClientPlayerEntity; +import net.minecraft.component.DataComponentTypes; +import net.minecraft.component.type.NbtComponent; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NbtCompound; import net.minecraft.nbt.StringNbtReader; @@ -77,16 +79,19 @@ public void call(String[] args) throws CmdException private void add(ItemStack stack, String[] args) throws CmdError { - String nbt = String.join(" ", Arrays.copyOfRange(args, 1, args.length)); - nbt = nbt.replace("$", "\u00a7").replace("\u00a7\u00a7", "$"); + String nbtString = + String.join(" ", Arrays.copyOfRange(args, 1, args.length)) + .replace("$", "\u00a7").replace("\u00a7\u00a7", "$"); - if(!stack.hasNbt()) - stack.setNbt(new NbtCompound()); + NbtCompound itemNbt = stack + .getOrDefault(DataComponentTypes.CUSTOM_DATA, NbtComponent.DEFAULT) + .copyNbt(); try { - NbtCompound tag = StringNbtReader.parse(nbt); - stack.getNbt().copyFrom(tag); + NbtCompound parsedNbt = StringNbtReader.parse(nbtString); + itemNbt.copyFrom(parsedNbt); + stack.set(DataComponentTypes.CUSTOM_DATA, NbtComponent.of(itemNbt)); }catch(CommandSyntaxException e) { @@ -103,7 +108,7 @@ private void set(ItemStack stack, String[] args) throws CmdError try { NbtCompound tag = StringNbtReader.parse(nbt); - stack.setNbt(tag); + stack.set(DataComponentTypes.CUSTOM_DATA, NbtComponent.of(tag)); }catch(CommandSyntaxException e) { @@ -117,12 +122,15 @@ private void remove(ItemStack stack, String[] args) throws CmdException if(args.length > 2) throw new CmdSyntaxError(); - NbtPath path = parseNbtPath(stack.getNbt(), args[1]); + NbtPath path = parseNbtPath(stack + .getOrDefault(DataComponentTypes.CUSTOM_DATA, NbtComponent.DEFAULT) + .copyNbt(), args[1]); if(path == null) throw new CmdError("The path does not exist."); path.base.remove(path.key); + stack.set(DataComponentTypes.CUSTOM_DATA, NbtComponent.of(path.base)); } private NbtPath parseNbtPath(NbtCompound tag, String path) diff --git a/src/main/java/net/wurstclient/commands/PotionCmd.java b/src/main/java/net/wurstclient/commands/PotionCmd.java index a2c3d05655..9f55986852 100644 --- a/src/main/java/net/wurstclient/commands/PotionCmd.java +++ b/src/main/java/net/wurstclient/commands/PotionCmd.java @@ -8,15 +8,17 @@ package net.wurstclient.commands; import java.util.ArrayList; +import java.util.Optional; +import net.minecraft.component.DataComponentTypes; +import net.minecraft.component.type.PotionContentsComponent; import net.minecraft.entity.effect.StatusEffect; import net.minecraft.entity.effect.StatusEffectInstance; import net.minecraft.item.ItemStack; import net.minecraft.item.PotionItem; import net.minecraft.potion.Potion; -import net.minecraft.potion.PotionUtil; -import net.minecraft.potion.Potions; import net.minecraft.registry.Registries; +import net.minecraft.registry.entry.RegistryEntry; import net.minecraft.util.Identifier; import net.minecraft.util.InvalidIdentifierException; import net.wurstclient.command.CmdError; @@ -59,19 +61,23 @@ public void call(String[] args) throws CmdException if((args.length - 1) % 3 != 0) throw new CmdSyntaxError(); + PotionContentsComponent oldContents = stack.getComponents() + .getOrDefault(DataComponentTypes.POTION_CONTENTS, + PotionContentsComponent.DEFAULT); + // get effects to start with ArrayList effects; - Potion potion; + Optional> potion; switch(args[0].toLowerCase()) { case "add": - effects = new ArrayList<>(PotionUtil.getCustomPotionEffects(stack)); - potion = PotionUtil.getPotion(stack); + effects = new ArrayList<>(oldContents.customEffects()); + potion = oldContents.potion(); break; case "set": effects = new ArrayList<>(); - potion = Potions.EMPTY; + potion = Optional.empty(); break; default: @@ -81,15 +87,16 @@ public void call(String[] args) throws CmdException // add new effects for(int i = 0; i < (args.length - 1) / 3; i++) { - StatusEffect effect = parseEffect(args[1 + i * 3]); + RegistryEntry effect = parseEffect(args[1 + i * 3]); int amplifier = parseInt(args[2 + i * 3]) - 1; int duration = parseInt(args[3 + i * 3]) * 20; effects.add(new StatusEffectInstance(effect, duration, amplifier)); } - PotionUtil.setPotion(stack, potion); - setCustomPotionEffects(stack, effects); + stack.set(DataComponentTypes.POTION_CONTENTS, + new PotionContentsComponent(potion, oldContents.customColor(), + effects)); ChatUtils.message("Potion modified."); } @@ -98,28 +105,36 @@ private void remove(ItemStack stack, String[] args) throws CmdSyntaxError if(args.length != 2) throw new CmdSyntaxError(); - StatusEffect targetEffect = parseEffect(args[1]); + RegistryEntry targetEffect = parseEffect(args[1]); + + PotionContentsComponent oldContents = stack.getComponents() + .getOrDefault(DataComponentTypes.POTION_CONTENTS, + PotionContentsComponent.DEFAULT); - Potion oldPotion = PotionUtil.getPotion(stack); - boolean mainPotionContainsTargetEffect = oldPotion.getEffects().stream() - .anyMatch(effect -> effect.getEffectType() == targetEffect); + boolean mainPotionContainsTargetEffect = + oldContents.potion().isPresent() + && oldContents.potion().get().value().getEffects().stream() + .anyMatch(effect -> effect.getEffectType() == targetEffect); ArrayList newEffects = new ArrayList<>(); if(mainPotionContainsTargetEffect) - PotionUtil.getPotionEffects(stack).forEach(newEffects::add); + oldContents.getEffects().forEach(newEffects::add); else - PotionUtil.getCustomPotionEffects(stack).forEach(newEffects::add); + oldContents.customEffects().forEach(newEffects::add); newEffects.removeIf(effect -> effect.getEffectType() == targetEffect); - Potion newPotion = - mainPotionContainsTargetEffect ? Potions.EMPTY : oldPotion; + Optional> newPotion = + mainPotionContainsTargetEffect ? Optional.empty() + : oldContents.potion(); + stack.set(DataComponentTypes.POTION_CONTENTS, + new PotionContentsComponent(newPotion, oldContents.customColor(), + newEffects)); - PotionUtil.setPotion(stack, newPotion); - setCustomPotionEffects(stack, newEffects); ChatUtils.message("Effect removed."); } - private StatusEffect parseEffect(String input) throws CmdSyntaxError + private RegistryEntry parseEffect(String input) + throws CmdSyntaxError { StatusEffect effect; @@ -139,17 +154,7 @@ private StatusEffect parseEffect(String input) throws CmdSyntaxError if(effect == null) throw new CmdSyntaxError("Invalid effect: " + input); - return Registries.STATUS_EFFECT.getEntry(effect).value(); - } - - private void setCustomPotionEffects(ItemStack stack, - ArrayList effects) - { - // PotionUtil doesn't remove effects when passing an empty list to it - if(effects.isEmpty()) - stack.removeSubNbt("custom_potion_effects"); - else - PotionUtil.setCustomPotionEffects(stack, effects); + return Registries.STATUS_EFFECT.getEntry(effect); } private int parseInt(String s) throws CmdSyntaxError diff --git a/src/main/java/net/wurstclient/commands/RenameCmd.java b/src/main/java/net/wurstclient/commands/RenameCmd.java index d7c96a0827..cf7c7eef56 100644 --- a/src/main/java/net/wurstclient/commands/RenameCmd.java +++ b/src/main/java/net/wurstclient/commands/RenameCmd.java @@ -7,6 +7,7 @@ */ package net.wurstclient.commands; +import net.minecraft.component.DataComponentTypes; import net.minecraft.item.ItemStack; import net.minecraft.text.Text; import net.wurstclient.command.CmdError; @@ -38,12 +39,12 @@ public void call(String[] args) throws CmdException message += " " + args[i]; message = message.replace("$", "\u00a7").replace("\u00a7\u00a7", "$"); - ItemStack item = MC.player.getInventory().getMainHandStack(); + ItemStack stack = MC.player.getInventory().getMainHandStack(); - if(item == null) + if(stack == null) throw new CmdError("There is no item in your hand."); - item.setCustomName(Text.literal(message)); - ChatUtils.message("Renamed item to \"" + message + "\u00a7r\"."); + stack.set(DataComponentTypes.CUSTOM_NAME, Text.literal(message)); + ChatUtils.message("Renamed item to \"\u00a7o" + message + "\u00a7r\"."); } } diff --git a/src/main/java/net/wurstclient/commands/ViewNbtCmd.java b/src/main/java/net/wurstclient/commands/ViewNbtCmd.java index da69ec56cc..241868bfa9 100644 --- a/src/main/java/net/wurstclient/commands/ViewNbtCmd.java +++ b/src/main/java/net/wurstclient/commands/ViewNbtCmd.java @@ -8,6 +8,8 @@ package net.wurstclient.commands; import net.minecraft.client.network.ClientPlayerEntity; +import net.minecraft.component.DataComponentTypes; +import net.minecraft.component.type.NbtComponent; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NbtCompound; import net.wurstclient.SearchTags; @@ -34,17 +36,19 @@ public void call(String[] args) throws CmdException if(stack.isEmpty()) throw new CmdError("You must hold an item in your main hand."); - NbtCompound tag = stack.getNbt(); - String nbt = tag == null ? "" : tag.asString(); + NbtCompound tag = stack + .getOrDefault(DataComponentTypes.CUSTOM_DATA, NbtComponent.DEFAULT) + .copyNbt(); + String nbtString = tag.asString(); switch(String.join(" ", args).toLowerCase()) { case "": - ChatUtils.message("NBT: " + nbt); + ChatUtils.message("NBT: " + nbtString); break; case "copy": - MC.keyboard.setClipboard(nbt); + MC.keyboard.setClipboard(nbtString); ChatUtils.message("NBT data copied to clipboard."); break; diff --git a/src/main/java/net/wurstclient/events/HitResultRayTraceListener.java b/src/main/java/net/wurstclient/events/HitResultRayTraceListener.java deleted file mode 100644 index e67b2d42e6..0000000000 --- a/src/main/java/net/wurstclient/events/HitResultRayTraceListener.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2014-2024 Wurst-Imperium and contributors. - * - * This source code is subject to the terms of the GNU General Public - * License, version 3. If a copy of the GPL was not distributed with this - * file, You can obtain one at: https://www.gnu.org/licenses/gpl-3.0.txt - */ -package net.wurstclient.events; - -import java.util.ArrayList; - -import net.wurstclient.event.Event; -import net.wurstclient.event.Listener; - -public interface HitResultRayTraceListener extends Listener -{ - public void onHitResultRayTrace(float partialTicks); - - public static class HitResultRayTraceEvent - extends Event - { - private float partialTicks; - - public HitResultRayTraceEvent(float partialTicks) - { - this.partialTicks = partialTicks; - } - - @Override - public void fire(ArrayList listeners) - { - for(HitResultRayTraceListener listener : listeners) - listener.onHitResultRayTrace(partialTicks); - } - - @Override - public Class getListenerType() - { - return HitResultRayTraceListener.class; - } - } -} diff --git a/src/main/java/net/wurstclient/hacks/AutoArmorHack.java b/src/main/java/net/wurstclient/hacks/AutoArmorHack.java index 4a2ae1d80b..d3db46f828 100644 --- a/src/main/java/net/wurstclient/hacks/AutoArmorHack.java +++ b/src/main/java/net/wurstclient/hacks/AutoArmorHack.java @@ -175,8 +175,8 @@ private int getArmorValue(ArmorItem item, ItemStack stack) { int armorPoints = item.getProtection(); int prtPoints = 0; - int armorToughness = (int)item.toughness; - int armorType = item.getMaterial().getProtection(Type.LEGGINGS); + int armorToughness = (int)item.getToughness(); + int armorType = item.getMaterial().value().getProtection(Type.LEGGINGS); if(useEnchantments.isChecked()) { diff --git a/src/main/java/net/wurstclient/hacks/AutoEatHack.java b/src/main/java/net/wurstclient/hacks/AutoEatHack.java index 5a4c19d9f6..edff4edfb8 100644 --- a/src/main/java/net/wurstclient/hacks/AutoEatHack.java +++ b/src/main/java/net/wurstclient/hacks/AutoEatHack.java @@ -11,23 +11,23 @@ import java.util.Comparator; import java.util.stream.Stream; -import com.mojang.datafixers.util.Pair; - import net.minecraft.block.Block; import net.minecraft.block.BlockWithEntity; import net.minecraft.block.CraftingTableBlock; import net.minecraft.client.network.ClientPlayerEntity; +import net.minecraft.component.DataComponentTypes; +import net.minecraft.component.type.FoodComponent; +import net.minecraft.component.type.FoodComponent.StatusEffectEntry; +import net.minecraft.component.type.FoodComponents; import net.minecraft.entity.Entity; import net.minecraft.entity.effect.StatusEffect; -import net.minecraft.entity.effect.StatusEffectInstance; import net.minecraft.entity.effect.StatusEffects; import net.minecraft.entity.passive.TameableEntity; import net.minecraft.entity.passive.VillagerEntity; import net.minecraft.entity.player.HungerManager; import net.minecraft.entity.player.PlayerInventory; -import net.minecraft.item.FoodComponent; -import net.minecraft.item.FoodComponents; -import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.registry.entry.RegistryEntry; import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.hit.EntityHitResult; import net.minecraft.util.hit.HitResult; @@ -216,21 +216,21 @@ private int findBestFoodSlot(int maxPoints) .forEach(i -> slots.add(i)); Comparator comparator = - Comparator.comparingDouble(FoodComponent::getSaturationModifier); + Comparator.comparingDouble(FoodComponent::saturation); for(int slot : slots) { - Item item = inventory.getStack(slot).getItem(); + ItemStack stack = inventory.getStack(slot); // filter out non-food items - if(!item.isFood()) + if(!stack.contains(DataComponentTypes.FOOD)) continue; - FoodComponent food = item.getFoodComponent(); + FoodComponent food = stack.get(DataComponentTypes.FOOD); if(!isAllowedFood(food)) continue; - if(maxPoints >= 0 && food.getHunger() > maxPoints) + if(maxPoints >= 0 && food.nutrition() > maxPoints) continue; // compare to previously found food @@ -274,9 +274,9 @@ private boolean isAllowedFood(FoodComponent food) if(!allowChorus.isChecked() && food == FoodComponents.CHORUS_FRUIT) return false; - for(Pair pair : food.getStatusEffects()) + for(StatusEffectEntry entry : food.effects()) { - StatusEffect effect = pair.getFirst().getEffectType(); + RegistryEntry effect = entry.effect().getEffectType(); if(!allowHunger.isChecked() && effect == StatusEffects.HUNGER) return false; diff --git a/src/main/java/net/wurstclient/hacks/AutoLibrarianHack.java b/src/main/java/net/wurstclient/hacks/AutoLibrarianHack.java index dd5776d9f6..77836a7761 100644 --- a/src/main/java/net/wurstclient/hacks/AutoLibrarianHack.java +++ b/src/main/java/net/wurstclient/hacks/AutoLibrarianHack.java @@ -9,6 +9,7 @@ import java.util.Comparator; import java.util.HashSet; +import java.util.Set; import java.util.stream.Stream; import java.util.stream.StreamSupport; @@ -16,17 +17,21 @@ import com.mojang.blaze3d.systems.RenderSystem; +import it.unimi.dsi.fastutil.objects.Object2IntMap; +import it.unimi.dsi.fastutil.objects.Object2IntMap.Entry; import net.minecraft.block.Blocks; import net.minecraft.client.gui.screen.ingame.MerchantScreen; import net.minecraft.client.network.ClientPlayerEntity; import net.minecraft.client.network.ClientPlayerInteractionManager; import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.enchantment.Enchantment; +import net.minecraft.enchantment.EnchantmentHelper; import net.minecraft.entity.passive.VillagerEntity; import net.minecraft.item.EnchantedBookItem; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; -import net.minecraft.nbt.NbtList; import net.minecraft.network.packet.c2s.play.SelectMerchantTradeC2SPacket; +import net.minecraft.registry.entry.RegistryEntry; import net.minecraft.screen.slot.SlotActionType; import net.minecraft.util.ActionResult; import net.minecraft.util.Hand; @@ -415,20 +420,23 @@ private BookOffer findEnchantedBookOffer(TradeOfferList tradeOffers) if(!(stack.getItem() instanceof EnchantedBookItem)) continue; - NbtList enchantmentNbt = EnchantedBookItem.getEnchantmentNbt(stack); - if(enchantmentNbt.isEmpty()) + Set>> enchantmentLevelMap = + EnchantmentHelper.getEnchantments(stack).getEnchantmentsMap(); + if(enchantmentLevelMap.isEmpty()) continue; - NbtList bookNbt = EnchantedBookItem.getEnchantmentNbt(stack); - String enchantment = bookNbt.getCompound(0).getString("id"); - int level = bookNbt.getCompound(0).getInt("lvl"); - int price = tradeOffer.getAdjustedFirstBuyItem().getCount(); + Object2IntMap.Entry> firstEntry = + enchantmentLevelMap.stream().findFirst().orElseThrow(); + + String enchantment = firstEntry.getKey().getIdAsString(); + int level = firstEntry.getIntValue(); + int price = tradeOffer.getDisplayedFirstBuyItem().getCount(); BookOffer bookOffer = new BookOffer(enchantment, level, price); if(!bookOffer.isValid()) { System.out.println("Found invalid enchanted book offer.\n" - + "NBT data: " + stack.getNbt()); + + "Component data: " + enchantmentLevelMap); continue; } diff --git a/src/main/java/net/wurstclient/hacks/AutoPotionHack.java b/src/main/java/net/wurstclient/hacks/AutoPotionHack.java index cd9ba86a48..1f4f74b183 100644 --- a/src/main/java/net/wurstclient/hacks/AutoPotionHack.java +++ b/src/main/java/net/wurstclient/hacks/AutoPotionHack.java @@ -7,18 +7,16 @@ */ package net.wurstclient.hacks; -import net.minecraft.entity.effect.StatusEffect; -import net.minecraft.entity.effect.StatusEffectInstance; import net.minecraft.entity.effect.StatusEffects; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; -import net.minecraft.potion.PotionUtil; import net.wurstclient.Category; import net.wurstclient.SearchTags; import net.wurstclient.events.UpdateListener; import net.wurstclient.hack.Hack; import net.wurstclient.settings.SliderSetting; import net.wurstclient.settings.SliderSetting.ValueDisplay; +import net.wurstclient.util.ItemUtils; import net.wurstclient.util.Rotation; @SearchTags({"AutoPotion", "auto potion", "AutoSplashPotion", @@ -111,24 +109,10 @@ private int findPotion(int startSlot, int endSlot) continue; // search for instant health effects - if(hasEffect(stack, StatusEffects.INSTANT_HEALTH)) + if(ItemUtils.hasEffect(stack, StatusEffects.INSTANT_HEALTH)) return i; } return -1; } - - private boolean hasEffect(ItemStack stack, StatusEffect effect) - { - for(StatusEffectInstance effectInstance : PotionUtil - .getPotionEffects(stack)) - { - if(effectInstance.getEffectType() != effect) - continue; - - return true; - } - - return false; - } } diff --git a/src/main/java/net/wurstclient/hacks/AutoSwordHack.java b/src/main/java/net/wurstclient/hacks/AutoSwordHack.java index 5bb9b29478..49efbf9186 100644 --- a/src/main/java/net/wurstclient/hacks/AutoSwordHack.java +++ b/src/main/java/net/wurstclient/hacks/AutoSwordHack.java @@ -9,12 +9,11 @@ import net.minecraft.enchantment.EnchantmentHelper; import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityGroup; +import net.minecraft.entity.EntityType; import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.attribute.EntityAttributes; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; -import net.minecraft.item.MiningToolItem; -import net.minecraft.item.SwordItem; import net.minecraft.item.ToolItem; import net.minecraft.item.TridentItem; import net.minecraft.util.hit.EntityHitResult; @@ -153,18 +152,16 @@ private float getValue(ItemStack stack, Entity entity) switch(priority.getSelected()) { case SPEED: - return ItemUtils.getAttackSpeed(item); + return (float)ItemUtils + .getAttribute(item, EntityAttributes.GENERIC_ATTACK_SPEED) + .orElseThrow(); case DAMAGE: - EntityGroup group = entity instanceof LivingEntity le - ? le.getGroup() : EntityGroup.DEFAULT; - float dmg = EnchantmentHelper.getAttackDamage(stack, group); - if(item instanceof SwordItem sword) - dmg += sword.getAttackDamage(); - if(item instanceof MiningToolItem tool) - dmg += tool.getAttackDamage(); - if(item instanceof TridentItem) - dmg += TridentItem.ATTACK_DAMAGE; + EntityType group = entity.getType(); + float dmg = (float)ItemUtils + .getAttribute(item, EntityAttributes.GENERIC_ATTACK_DAMAGE) + .orElseThrow(); + dmg += EnchantmentHelper.getAttackDamage(stack, group); return dmg; } diff --git a/src/main/java/net/wurstclient/hacks/AutoToolHack.java b/src/main/java/net/wurstclient/hacks/AutoToolHack.java index 60d93745ad..f320307198 100644 --- a/src/main/java/net/wurstclient/hacks/AutoToolHack.java +++ b/src/main/java/net/wurstclient/hacks/AutoToolHack.java @@ -191,7 +191,7 @@ private float getMiningSpeed(ItemStack stack, BlockState state) private boolean isDamageable(ItemStack stack) { - return !stack.isEmpty() && stack.getItem().isDamageable(); + return !stack.isEmpty() && stack.isDamageable(); } private boolean isTooDamaged(ItemStack stack, int repairMode) diff --git a/src/main/java/net/wurstclient/hacks/CrashChestHack.java b/src/main/java/net/wurstclient/hacks/CrashChestHack.java index 9c229838ce..b71eb1fc00 100644 --- a/src/main/java/net/wurstclient/hacks/CrashChestHack.java +++ b/src/main/java/net/wurstclient/hacks/CrashChestHack.java @@ -8,6 +8,8 @@ package net.wurstclient.hacks; import net.minecraft.block.Blocks; +import net.minecraft.component.DataComponentTypes; +import net.minecraft.component.type.NbtComponent; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NbtCompound; import net.minecraft.nbt.NbtList; @@ -51,8 +53,8 @@ protected void onEnable() for(int i = 0; i < 40000; i++) nbtList.add(new NbtList()); nbtCompound.put("www.wurstclient.net", nbtList); - stack.setNbt(nbtCompound); - stack.setCustomName(Text.literal("Copy Me")); + stack.set(DataComponentTypes.CUSTOM_DATA, NbtComponent.of(nbtCompound)); + stack.set(DataComponentTypes.CUSTOM_NAME, Text.literal("Copy Me")); // give item MC.player.getInventory().armor.set(0, stack); diff --git a/src/main/java/net/wurstclient/hacks/KillPotionHack.java b/src/main/java/net/wurstclient/hacks/KillPotionHack.java index 5fd392b248..368ed414e3 100644 --- a/src/main/java/net/wurstclient/hacks/KillPotionHack.java +++ b/src/main/java/net/wurstclient/hacks/KillPotionHack.java @@ -7,11 +7,16 @@ */ package net.wurstclient.hacks; +import java.util.List; +import java.util.Optional; + +import net.minecraft.component.DataComponentTypes; +import net.minecraft.component.type.PotionContentsComponent; +import net.minecraft.entity.effect.StatusEffectInstance; +import net.minecraft.entity.effect.StatusEffects; import net.minecraft.item.Item; 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.c2s.play.CreativeInventoryActionC2SPacket; import net.minecraft.text.Text; import net.wurstclient.Category; @@ -106,21 +111,18 @@ public ItemStack createPotionStack() { ItemStack stack = new ItemStack(item); - NbtCompound effect = new NbtCompound(); - effect.putInt("amplifier", 125); - effect.putInt("duration", 2000); - effect.putString("id", "instant_health"); + StatusEffectInstance effect = new StatusEffectInstance( + StatusEffects.INSTANT_HEALTH, 2000, 125); - NbtList effects = new NbtList(); - effects.add(effect); + PotionContentsComponent potionContents = + new PotionContentsComponent(Optional.empty(), Optional.empty(), + List.of(effect)); - NbtCompound nbt = new NbtCompound(); - nbt.put("custom_potion_effects", effects); - stack.setNbt(nbt); + stack.set(DataComponentTypes.POTION_CONTENTS, potionContents); String name = "\u00a7f" + itemName + " of \u00a74\u00a7lINSTANT DEATH"; - stack.setCustomName(Text.literal(name)); + stack.set(DataComponentTypes.CUSTOM_NAME, Text.literal(name)); return stack; } diff --git a/src/main/java/net/wurstclient/hacks/LiquidsHack.java b/src/main/java/net/wurstclient/hacks/LiquidsHack.java index aa35148c47..f9b03b7228 100644 --- a/src/main/java/net/wurstclient/hacks/LiquidsHack.java +++ b/src/main/java/net/wurstclient/hacks/LiquidsHack.java @@ -8,10 +8,9 @@ package net.wurstclient.hacks; import net.wurstclient.Category; -import net.wurstclient.events.HitResultRayTraceListener; import net.wurstclient.hack.Hack; -public final class LiquidsHack extends Hack implements HitResultRayTraceListener +public final class LiquidsHack extends Hack { public LiquidsHack() { @@ -19,23 +18,5 @@ public LiquidsHack() setCategory(Category.BLOCKS); } - @Override - protected void onEnable() - { - EVENTS.add(HitResultRayTraceListener.class, this); - } - - @Override - protected void onDisable() - { - EVENTS.remove(HitResultRayTraceListener.class, this); - } - - @Override - public void onHitResultRayTrace(float partialTicks) - { - float reach = MC.interactionManager.getReachDistance(); - MC.crosshairTarget = - MC.getCameraEntity().raycast(reach, partialTicks, true); - } + // See GameRendererMixin.liquidsRaycast() } diff --git a/src/main/java/net/wurstclient/hacks/ReachHack.java b/src/main/java/net/wurstclient/hacks/ReachHack.java index 80f36baf0f..28f90cb258 100644 --- a/src/main/java/net/wurstclient/hacks/ReachHack.java +++ b/src/main/java/net/wurstclient/hacks/ReachHack.java @@ -13,6 +13,7 @@ import net.wurstclient.settings.SliderSetting; import net.wurstclient.settings.SliderSetting.ValueDisplay; +// TODO: Remove this hack in 1.20.5, as it seems to be patched. @SearchTags({"range"}) public final class ReachHack extends Hack { @@ -26,11 +27,11 @@ public ReachHack() addSetting(range); } - public float getReachDistance() + public double getReachDistance() { - return range.getValueF(); + return range.getValue(); } - // See ClientPlayerInteractionManagerMixin.onGetReachDistance() and - // ClientPlayerInteractionManagerMixin.hasExtendedReach() + // See ClientPlayerEntityMixin.method_55754() and + // ClientPlayerEntityMixin.method_55755() } diff --git a/src/main/java/net/wurstclient/hacks/SafeWalkHack.java b/src/main/java/net/wurstclient/hacks/SafeWalkHack.java index 0bdd5230d7..4e5267191c 100644 --- a/src/main/java/net/wurstclient/hacks/SafeWalkHack.java +++ b/src/main/java/net/wurstclient/hacks/SafeWalkHack.java @@ -67,7 +67,7 @@ public void onClipAtLedge(boolean clipping) } Box box = player.getBoundingBox(); - Box adjustedBox = box.stretch(0, -player.stepHeight, 0) + Box adjustedBox = box.stretch(0, -player.getStepHeight(), 0) .expand(-edgeDistance.getValue(), 0, -edgeDistance.getValue()); if(MC.world.isSpaceEmpty(player, adjustedBox)) diff --git a/src/main/java/net/wurstclient/hacks/StepHack.java b/src/main/java/net/wurstclient/hacks/StepHack.java index 9adaccd414..276a1af712 100644 --- a/src/main/java/net/wurstclient/hacks/StepHack.java +++ b/src/main/java/net/wurstclient/hacks/StepHack.java @@ -48,23 +48,15 @@ protected void onEnable() protected void onDisable() { EVENTS.remove(UpdateListener.class, this); - MC.player.stepHeight = 0.5F; } @Override public void onUpdate() { if(mode.getSelected() == Mode.SIMPLE) - { - // simple mode - MC.player.stepHeight = height.getValueF(); return; - } - // legit mode ClientPlayerEntity player = MC.player; - player.stepHeight = 0.5F; - if(!player.horizontalCollision) return; @@ -80,7 +72,6 @@ public void onUpdate() return; Box box = player.getBoundingBox().offset(0, 0.05, 0).expand(0.05); - if(!MC.world.isSpaceEmpty(player, box.offset(0, 1, 0))) return; @@ -106,6 +97,14 @@ public void onUpdate() player.getZ()); } + public float adjustStepHeight(float stepHeight) + { + if(isEnabled() && mode.getSelected() == Mode.SIMPLE) + return height.getValueF(); + + return stepHeight; + } + public boolean isAutoJumpAllowed() { return !isEnabled() && !WURST.getCmds().goToCmd.isActive(); diff --git a/src/main/java/net/wurstclient/hacks/TrollPotionHack.java b/src/main/java/net/wurstclient/hacks/TrollPotionHack.java index 89cc5aa87b..672e5fef20 100644 --- a/src/main/java/net/wurstclient/hacks/TrollPotionHack.java +++ b/src/main/java/net/wurstclient/hacks/TrollPotionHack.java @@ -7,13 +7,19 @@ */ package net.wurstclient.hacks; +import java.util.ArrayList; +import java.util.Optional; + +import net.minecraft.component.DataComponentTypes; +import net.minecraft.component.type.PotionContentsComponent; +import net.minecraft.entity.effect.StatusEffect; +import net.minecraft.entity.effect.StatusEffectInstance; import net.minecraft.item.Item; 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.c2s.play.CreativeInventoryActionC2SPacket; import net.minecraft.registry.Registries; +import net.minecraft.registry.entry.RegistryEntry; import net.minecraft.text.Text; import net.wurstclient.Category; import net.wurstclient.SearchTags; @@ -104,25 +110,24 @@ public ItemStack createPotionStack() { ItemStack stack = new ItemStack(item); - NbtList effects = new NbtList(); + ArrayList effects = new ArrayList<>(); for(int i = 1; i <= 23; i++) { - String id = Registries.STATUS_EFFECT.getEntry(i).get().getKey() - .get().getValue().toString(); + StatusEffect effect = + Registries.STATUS_EFFECT.getEntry(i).get().value(); + RegistryEntry entry = + Registries.STATUS_EFFECT.getEntry(effect); - NbtCompound effect = new NbtCompound(); - effect.putInt("amplifier", Integer.MAX_VALUE); - effect.putInt("duration", Integer.MAX_VALUE); - effect.putString("id", id); - effects.add(effect); + effects.add(new StatusEffectInstance(entry, Integer.MAX_VALUE, + Integer.MAX_VALUE)); } - NbtCompound nbt = new NbtCompound(); - nbt.put("custom_potion_effects", effects); - stack.setNbt(nbt); + stack.set(DataComponentTypes.POTION_CONTENTS, + new PotionContentsComponent(Optional.empty(), Optional.empty(), + effects)); String name = "\u00a7f" + itemName + " of Trolling"; - stack.setCustomName(Text.literal(name)); + stack.set(DataComponentTypes.CUSTOM_NAME, Text.literal(name)); return stack; } diff --git a/src/main/java/net/wurstclient/hacks/TunnellerHack.java b/src/main/java/net/wurstclient/hacks/TunnellerHack.java index 133e267494..81c6078e14 100644 --- a/src/main/java/net/wurstclient/hacks/TunnellerHack.java +++ b/src/main/java/net/wurstclient/hacks/TunnellerHack.java @@ -713,7 +713,6 @@ private Vec3d toVec3d(BlockPos pos) private class PlaceTorchTask extends Task { - @SuppressWarnings("deprecation") @Override public boolean canRun() { @@ -755,10 +754,9 @@ public boolean canRun() BlockState state = BlockUtils.getState(nextTorch); if(!state.isReplaceable()) return false; - - // Can't see why canPlaceAt() is deprecated. Still seems to be - // widely used with no replacement. - return Blocks.TORCH.canPlaceAt(state, MC.world, nextTorch); + + return Blocks.TORCH.getDefaultState().canPlaceAt(MC.world, + nextTorch); } @Override diff --git a/src/main/java/net/wurstclient/hacks/XRayHack.java b/src/main/java/net/wurstclient/hacks/XRayHack.java index 3a01171a73..2e762de3fe 100644 --- a/src/main/java/net/wurstclient/hacks/XRayHack.java +++ b/src/main/java/net/wurstclient/hacks/XRayHack.java @@ -42,12 +42,12 @@ public final class XRayHack extends Hack implements UpdateListener, "A list of blocks that X-Ray will show. They don't have to be just ores" + " - you can add any block you want.\n\n" + "Remember to restart X-Ray when changing this setting.", - "minecraft:ancient_debris", "minecraft:anvil", "minecraft:beacon", - "minecraft:bone_block", "minecraft:bookshelf", - "minecraft:brewing_stand", "minecraft:chain_command_block", - "minecraft:chest", "minecraft:clay", "minecraft:coal_block", - "minecraft:coal_ore", "minecraft:command_block", "minecraft:copper_ore", - "minecraft:crafter", "minecraft:crafting_table", + "minecraft:amethyst_cluster", "minecraft:ancient_debris", + "minecraft:anvil", "minecraft:beacon", "minecraft:bone_block", + "minecraft:bookshelf", "minecraft:brewing_stand", + "minecraft:chain_command_block", "minecraft:chest", "minecraft:clay", + "minecraft:coal_block", "minecraft:coal_ore", "minecraft:command_block", + "minecraft:copper_ore", "minecraft:crafter", "minecraft:crafting_table", "minecraft:decorated_pot", "minecraft:deepslate_coal_ore", "minecraft:deepslate_copper_ore", "minecraft:deepslate_diamond_ore", "minecraft:deepslate_emerald_ore", "minecraft:deepslate_gold_ore", @@ -68,7 +68,8 @@ public final class XRayHack extends Hack implements UpdateListener, "minecraft:redstone_ore", "minecraft:repeating_command_block", "minecraft:spawner", "minecraft:suspicious_gravel", "minecraft:suspicious_sand", "minecraft:tnt", "minecraft:torch", - "minecraft:trapped_chest", "minecraft:water"); + "minecraft:trapped_chest", "minecraft:trial_spawner", "minecraft:vault", + "minecraft:water"); private final CheckboxSetting onlyExposed = new CheckboxSetting( "Only show exposed", diff --git a/src/main/java/net/wurstclient/hacks/autocomplete/OobaboogaMessageCompleter.java b/src/main/java/net/wurstclient/hacks/autocomplete/OobaboogaMessageCompleter.java index d68479702a..575c98d676 100644 --- a/src/main/java/net/wurstclient/hacks/autocomplete/OobaboogaMessageCompleter.java +++ b/src/main/java/net/wurstclient/hacks/autocomplete/OobaboogaMessageCompleter.java @@ -10,6 +10,7 @@ import java.io.IOException; import java.io.OutputStream; import java.net.HttpURLConnection; +import java.net.URI; import java.net.URL; import com.google.gson.JsonArray; @@ -50,7 +51,8 @@ protected WsonObject requestCompletion(JsonObject parameters) throws IOException, JsonException { // set up the API request - URL url = new URL(modelSettings.oobaboogaEndpoint.getValue()); + URL url = + URI.create(modelSettings.oobaboogaEndpoint.getValue()).toURL(); HttpURLConnection conn = (HttpURLConnection)url.openConnection(); conn.setRequestMethod("POST"); conn.setRequestProperty("Content-Type", "application/json"); diff --git a/src/main/java/net/wurstclient/hacks/autocomplete/OpenAiMessageCompleter.java b/src/main/java/net/wurstclient/hacks/autocomplete/OpenAiMessageCompleter.java index 2b74290c60..9555c613ad 100644 --- a/src/main/java/net/wurstclient/hacks/autocomplete/OpenAiMessageCompleter.java +++ b/src/main/java/net/wurstclient/hacks/autocomplete/OpenAiMessageCompleter.java @@ -10,6 +10,7 @@ import java.io.IOException; import java.io.OutputStream; import java.net.HttpURLConnection; +import java.net.URI; import java.net.URL; import com.google.gson.JsonArray; @@ -64,9 +65,10 @@ protected WsonObject requestCompletion(JsonObject parameters) throws IOException, JsonException { // get the API URL - URL url = modelSettings.openAiModel.getSelected().isChatModel() - ? new URL(modelSettings.openaiChatEndpoint.getValue()) - : new URL(modelSettings.openaiLegacyEndpoint.getValue()); + URL url = + URI.create(modelSettings.openAiModel.getSelected().isChatModel() + ? modelSettings.openaiChatEndpoint.getValue() + : modelSettings.openaiLegacyEndpoint.getValue()).toURL(); // set up the API request HttpURLConnection conn = (HttpURLConnection)url.openConnection(); diff --git a/src/main/java/net/wurstclient/mixin/AbstractBlockStateMixin.java b/src/main/java/net/wurstclient/mixin/AbstractBlockStateMixin.java index 885abc2a35..9596fa2946 100644 --- a/src/main/java/net/wurstclient/mixin/AbstractBlockStateMixin.java +++ b/src/main/java/net/wurstclient/mixin/AbstractBlockStateMixin.java @@ -13,9 +13,9 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import com.google.common.collect.ImmutableMap; import com.mojang.serialization.MapCodec; +import it.unimi.dsi.fastutil.objects.Reference2ObjectArrayMap; import net.minecraft.block.AbstractBlock.AbstractBlockState; import net.minecraft.block.Block; import net.minecraft.block.BlockState; @@ -37,11 +37,11 @@ @Mixin(AbstractBlockState.class) public abstract class AbstractBlockStateMixin extends State { - private AbstractBlockStateMixin(WurstClient wurst, Block object, - ImmutableMap, Comparable> immutableMap, - MapCodec mapCodec) + private AbstractBlockStateMixin(WurstClient wurst, Block owner, + Reference2ObjectArrayMap, Comparable> propertyMap, + MapCodec codec) { - super(object, immutableMap, mapCodec); + super(owner, propertyMap, codec); } @Inject(at = @At("TAIL"), diff --git a/src/main/java/net/wurstclient/mixin/ChatHudMixin.java b/src/main/java/net/wurstclient/mixin/ChatHudMixin.java index 65793b3d7f..e3ab4af83d 100644 --- a/src/main/java/net/wurstclient/mixin/ChatHudMixin.java +++ b/src/main/java/net/wurstclient/mixin/ChatHudMixin.java @@ -17,7 +17,9 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import net.minecraft.client.MinecraftClient; +import com.llamalad7.mixinextras.sugar.Local; +import com.llamalad7.mixinextras.sugar.ref.LocalRef; + import net.minecraft.client.gui.hud.ChatHud; import net.minecraft.client.gui.hud.ChatHudLine; import net.minecraft.client.gui.hud.MessageIndicator; @@ -33,16 +35,14 @@ public class ChatHudMixin @Shadow @Final private List visibleMessages; - @Shadow - @Final - private MinecraftClient client; @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, @Nullable MessageSignatureData signature, - @Nullable MessageIndicator indicator, CallbackInfo ci) + @Nullable MessageIndicator indicatorDontUse, CallbackInfo ci, + @Local LocalRef indicator) { ChatInputEvent event = new ChatInputEvent(message, visibleMessages); @@ -54,28 +54,7 @@ private void onAddMessage(Text message, } message = event.getComponent(); - indicator = WurstClient.INSTANCE.getOtfs().noChatReportsOtf - .modifyIndicator(message, signature, indicator); - - shadow$logChatMessage(message, indicator); - shadow$addMessage(message, signature, client.inGameHud.getTicks(), - indicator, false); - - ci.cancel(); - } - - @Shadow - private void shadow$logChatMessage(Text message, - @Nullable MessageIndicator indicator) - { - - } - - @Shadow - private void shadow$addMessage(Text message, - @Nullable MessageSignatureData signature, int ticks, - @Nullable MessageIndicator indicator, boolean refresh) - { - + indicator.set(WurstClient.INSTANCE.getOtfs().noChatReportsOtf + .modifyIndicator(message, signature, indicator.get())); } } diff --git a/src/main/java/net/wurstclient/mixin/ChatScreenMixin.java b/src/main/java/net/wurstclient/mixin/ChatScreenMixin.java index 8b2e457bd5..a46962294d 100644 --- a/src/main/java/net/wurstclient/mixin/ChatScreenMixin.java +++ b/src/main/java/net/wurstclient/mixin/ChatScreenMixin.java @@ -12,7 +12,6 @@ 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.CallbackInfoReturnable; import net.minecraft.client.gui.screen.ChatScreen; import net.minecraft.client.gui.screen.Screen; @@ -41,10 +40,10 @@ protected void onInit(CallbackInfo ci) } @Inject(at = @At("HEAD"), - method = "sendMessage(Ljava/lang/String;Z)Z", + method = "sendMessage(Ljava/lang/String;Z)V", cancellable = true) public void onSendMessage(String message, boolean addToHistory, - CallbackInfoReturnable cir) + CallbackInfo ci) { // Ignore empty messages just like vanilla if((message = normalize(message)).isEmpty()) @@ -61,7 +60,7 @@ public void onSendMessage(String message, boolean addToHistory, return; // Otherwise, cancel the vanilla method and handle the message here - cir.setReturnValue(true); + ci.cancel(); // Add the message to history, even if it was cancelled // Otherwise the up/down arrows won't work correctly diff --git a/src/main/java/net/wurstclient/mixin/ClientPlayNetworkHandlerMixin.java b/src/main/java/net/wurstclient/mixin/ClientPlayNetworkHandlerMixin.java index e61a7246cc..d96de5e3da 100644 --- a/src/main/java/net/wurstclient/mixin/ClientPlayNetworkHandlerMixin.java +++ b/src/main/java/net/wurstclient/mixin/ClientPlayNetworkHandlerMixin.java @@ -23,7 +23,7 @@ import net.minecraft.network.packet.s2c.play.BlockUpdateS2CPacket; import net.minecraft.network.packet.s2c.play.ChunkData; import net.minecraft.network.packet.s2c.play.ChunkDeltaUpdateS2CPacket; -import net.minecraft.network.packet.s2c.play.ServerMetadataS2CPacket; +import net.minecraft.network.packet.s2c.play.GameJoinS2CPacket; import net.minecraft.text.MutableText; import net.minecraft.text.Text; import net.wurstclient.WurstClient; @@ -42,16 +42,15 @@ private ClientPlayNetworkHandlerMixin(WurstClient wurst, } @Inject(at = @At("TAIL"), - method = "onServerMetadata(Lnet/minecraft/network/packet/s2c/play/ServerMetadataS2CPacket;)V") - public void onOnServerMetadata(ServerMetadataS2CPacket packet, - CallbackInfo ci) + method = "onGameJoin(Lnet/minecraft/network/packet/s2c/play/GameJoinS2CPacket;)V") + public void onOnGameJoin(GameJoinS2CPacket packet, CallbackInfo ci) { WurstClient wurst = WurstClient.INSTANCE; if(!wurst.isEnabled()) return; // Remove Mojang's dishonest warning toast on safe servers - if(!packet.isSecureChatEnforced()) + if(!packet.enforcesSecureChat()) { client.getToastManager().toastQueue.removeIf(toast -> toast .getType() == SystemToast.Type.UNSECURE_SERVER_WARNING); diff --git a/src/main/java/net/wurstclient/mixin/ClientPlayerEntityMixin.java b/src/main/java/net/wurstclient/mixin/ClientPlayerEntityMixin.java index 1ea2489817..8ea4175bb3 100644 --- a/src/main/java/net/wurstclient/mixin/ClientPlayerEntityMixin.java +++ b/src/main/java/net/wurstclient/mixin/ClientPlayerEntityMixin.java @@ -29,6 +29,7 @@ import net.minecraft.entity.MovementType; import net.minecraft.entity.effect.StatusEffect; import net.minecraft.entity.effect.StatusEffects; +import net.minecraft.registry.entry.RegistryEntry; import net.minecraft.util.math.Vec3d; import net.wurstclient.WurstClient; import net.wurstclient.event.EventManager; @@ -289,7 +290,7 @@ protected Vec3d adjustMovementForSneaking(Vec3d movement, MovementType type) } @Override - public boolean hasStatusEffect(StatusEffect effect) + public boolean hasStatusEffect(RegistryEntry effect) { HackList hax = WurstClient.INSTANCE.getHax(); @@ -306,4 +307,33 @@ public boolean hasStatusEffect(StatusEffect effect) return super.hasStatusEffect(effect); } + + @Override + public float getStepHeight() + { + return WurstClient.INSTANCE.getHax().stepHack + .adjustStepHeight(super.getStepHeight()); + } + + // getter for GENERIC_BLOCK_INTERACTION_RANGE + @Override + public double getBlockInteractionRange() + { + HackList hax = WurstClient.INSTANCE.getHax(); + if(hax == null || !hax.reachHack.isEnabled()) + return super.getBlockInteractionRange(); + + return hax.reachHack.getReachDistance(); + } + + // getter for GENERIC_ENTITY_INTERACTION_RANGE + @Override + public double getEntityInteractionRange() + { + HackList hax = WurstClient.INSTANCE.getHax(); + if(hax == null || !hax.reachHack.isEnabled()) + return super.getEntityInteractionRange(); + + return hax.reachHack.getReachDistance(); + } } diff --git a/src/main/java/net/wurstclient/mixin/ClientPlayerInteractionManagerMixin.java b/src/main/java/net/wurstclient/mixin/ClientPlayerInteractionManagerMixin.java index caa51a00b3..7dde6be245 100644 --- a/src/main/java/net/wurstclient/mixin/ClientPlayerInteractionManagerMixin.java +++ b/src/main/java/net/wurstclient/mixin/ClientPlayerInteractionManagerMixin.java @@ -31,12 +31,9 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Direction; import net.minecraft.util.math.Vec3d; -import net.wurstclient.WurstClient; import net.wurstclient.event.EventManager; import net.wurstclient.events.BlockBreakingProgressListener.BlockBreakingProgressEvent; import net.wurstclient.events.StopUsingItemListener.StopUsingItemEvent; -import net.wurstclient.hack.HackList; -import net.wurstclient.hacks.ReachHack; import net.wurstclient.mixinterface.IClientPlayerInteractionManager; @Mixin(ClientPlayerInteractionManager.class) @@ -57,32 +54,6 @@ private void onPlayerDamageBlock(BlockPos pos, Direction direction, EventManager.fire(new BlockBreakingProgressEvent(pos, direction)); } - @Inject(at = @At("HEAD"), - method = "getReachDistance()F", - cancellable = true) - private void onGetReachDistance(CallbackInfoReturnable ci) - { - HackList hax = WurstClient.INSTANCE.getHax(); - if(hax == null) - return; - - ReachHack reach = hax.reachHack; - if(reach.isEnabled()) - ci.setReturnValue(reach.getReachDistance()); - } - - @Inject(at = @At("HEAD"), - method = "hasExtendedReach()Z", - cancellable = true) - private void hasExtendedReach(CallbackInfoReturnable cir) - { - HackList hax = WurstClient.INSTANCE.getHax(); - if(hax == null || !hax.reachHack.isEnabled()) - return; - - cir.setReturnValue(true); - } - @Inject(at = @At("HEAD"), method = "stopUsingItem(Lnet/minecraft/entity/player/PlayerEntity;)V") private void onStopUsingItem(PlayerEntity player, CallbackInfo ci) diff --git a/src/main/java/net/wurstclient/mixin/EntityRendererMixin.java b/src/main/java/net/wurstclient/mixin/EntityRendererMixin.java index a1b39ea3d0..3b6e050ed8 100644 --- a/src/main/java/net/wurstclient/mixin/EntityRendererMixin.java +++ b/src/main/java/net/wurstclient/mixin/EntityRendererMixin.java @@ -35,11 +35,11 @@ public abstract class EntityRendererMixin protected EntityRenderDispatcher dispatcher; @Inject(at = @At("HEAD"), - method = "renderLabelIfPresent(Lnet/minecraft/entity/Entity;Lnet/minecraft/text/Text;Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;I)V", + method = "renderLabelIfPresent(Lnet/minecraft/entity/Entity;Lnet/minecraft/text/Text;Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;IF)V", cancellable = true) private void onRenderLabelIfPresent(T entity, Text text, MatrixStack matrixStack, VertexConsumerProvider vertexConsumerProvider, - int i, CallbackInfo ci) + int i, float tickDelta, CallbackInfo ci) { // add HealthTags info if(entity instanceof LivingEntity) @@ -48,7 +48,7 @@ private void onRenderLabelIfPresent(T entity, Text text, // do NameTags adjustments wurstRenderLabelIfPresent(entity, text, matrixStack, - vertexConsumerProvider, i); + vertexConsumerProvider, i, tickDelta); ci.cancel(); } @@ -57,7 +57,8 @@ private void onRenderLabelIfPresent(T entity, Text text, * an infinite loop. Also makes it easier to modify. */ protected void wurstRenderLabelIfPresent(T entity, Text text, - MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light) + MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, + float tickDelta) { NameTagsHack nameTags = WurstClient.INSTANCE.getHax().nameTagsHack; diff --git a/src/main/java/net/wurstclient/mixin/GameMenuScreenMixin.java b/src/main/java/net/wurstclient/mixin/GameMenuScreenMixin.java index 19797948fa..d7e72da5a7 100644 --- a/src/main/java/net/wurstclient/mixin/GameMenuScreenMixin.java +++ b/src/main/java/net/wurstclient/mixin/GameMenuScreenMixin.java @@ -77,6 +77,8 @@ private void onRender(DrawContext context, int mouseX, int mouseY, float u = 0; float v = 0; context.drawTexture(WURST_TEXTURE, x, y, u, v, w, h, fw, fh); + + GL11.glDisable(GL11.GL_BLEND); } private void addWurstOptionsButton() diff --git a/src/main/java/net/wurstclient/mixin/GameRendererMixin.java b/src/main/java/net/wurstclient/mixin/GameRendererMixin.java index f363dfdc25..172024d8d3 100644 --- a/src/main/java/net/wurstclient/mixin/GameRendererMixin.java +++ b/src/main/java/net/wurstclient/mixin/GameRendererMixin.java @@ -7,23 +7,27 @@ */ package net.wurstclient.mixin; +import org.joml.Matrix4f; import org.objectweb.asm.Opcodes; import org.spongepowered.asm.mixin.Mixin; 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.CallbackInfoReturnable; +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; +import com.llamalad7.mixinextras.sugar.Local; + import net.minecraft.client.render.Camera; import net.minecraft.client.render.GameRenderer; import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.entity.Entity; import net.minecraft.entity.LivingEntity; -import net.minecraft.util.math.MathHelper; +import net.minecraft.util.hit.HitResult; import net.wurstclient.WurstClient; import net.wurstclient.event.EventManager; import net.wurstclient.events.CameraTransformViewBobbingListener.CameraTransformViewBobbingEvent; -import net.wurstclient.events.HitResultRayTraceListener.HitResultRayTraceEvent; import net.wurstclient.events.RenderListener.RenderEvent; import net.wurstclient.hacks.FullbrightHack; @@ -38,10 +42,9 @@ public abstract class GameRendererMixin implements AutoCloseable */ @Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/GameRenderer;bobView(Lnet/minecraft/client/util/math/MatrixStack;F)V", - ordinal = 0), - method = "renderWorld(FJLnet/minecraft/client/util/math/MatrixStack;)V") + ordinal = 0), method = "renderWorld(FJ)V") private void onRenderWorldViewBobbing(float tickDelta, long limitTime, - MatrixStack matrices, CallbackInfo ci) + CallbackInfo ci) { CameraTransformViewBobbingEvent event = new CameraTransformViewBobbingEvent(); @@ -74,9 +77,9 @@ private void onBobView(MatrixStack matrices, float tickDelta, * after the view-bobbing call. */ @Inject(at = @At("HEAD"), - method = "renderHand(Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/Camera;F)V") - private void onRenderHand(MatrixStack matrices, Camera camera, - float tickDelta, CallbackInfo ci) + method = "renderHand(Lnet/minecraft/client/render/Camera;FLorg/joml/Matrix4f;)V") + private void onRenderHand(Camera camera, float tickDelta, Matrix4f matrix4f, + CallbackInfo ci) { cancelNextBobView = false; } @@ -86,11 +89,13 @@ private void onRenderHand(MatrixStack matrices, Camera camera, target = "Lnet/minecraft/client/render/GameRenderer;renderHand:Z", opcode = Opcodes.GETFIELD, ordinal = 0), - method = "renderWorld(FJLnet/minecraft/client/util/math/MatrixStack;)V") - private void onRenderWorld(float tickDelta, long limitTime, - MatrixStack matrices, CallbackInfo ci) + method = "renderWorld(FJ)V") + private void onRenderWorld(float tickDelta, long limitTime, CallbackInfo ci, + @Local(ordinal = 1) Matrix4f matrix4f2) { - RenderEvent event = new RenderEvent(matrices, tickDelta); + MatrixStack matrixStack = new MatrixStack(); + matrixStack.multiplyPositionMatrix(matrix4f2); + RenderEvent event = new RenderEvent(matrixStack, tickDelta); EventManager.fire(event); } @@ -104,25 +109,33 @@ private void onGetFov(Camera camera, float tickDelta, boolean changingFov, .changeFovBasedOnZoom(cir.getReturnValueD())); } - @Inject(at = @At(value = "INVOKE", - target = "Lnet/minecraft/entity/Entity;getCameraPosVec(F)Lnet/minecraft/util/math/Vec3d;", - opcode = Opcodes.INVOKEVIRTUAL, - ordinal = 0), method = "updateTargetedEntity(F)V") - private void onHitResultRayTrace(float tickDelta, CallbackInfo ci) + /** + * This is the part that makes Liquids work. + */ + @WrapOperation(at = @At(value = "INVOKE", + target = "Lnet/minecraft/entity/Entity;raycast(DFZ)Lnet/minecraft/util/hit/HitResult;", + ordinal = 0), + method = "findCrosshairTarget(Lnet/minecraft/entity/Entity;DDF)Lnet/minecraft/util/hit/HitResult;") + private HitResult liquidsRaycast(Entity instance, double maxDistance, + float tickDelta, boolean includeFluids, Operation original) { - HitResultRayTraceEvent event = new HitResultRayTraceEvent(tickDelta); - EventManager.fire(event); + if(!WurstClient.INSTANCE.getHax().liquidsHack.isEnabled()) + return original.call(instance, maxDistance, tickDelta, + includeFluids); + + return original.call(instance, maxDistance, tickDelta, true); } - @Redirect( + @WrapOperation( at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/MathHelper;lerp(FFF)F", ordinal = 0), - method = "renderWorld(FJLnet/minecraft/client/util/math/MatrixStack;)V") - private float wurstNauseaLerp(float delta, float start, float end) + method = "renderWorld(FJ)V") + private float wurstNauseaLerp(float delta, float start, float end, + Operation original) { if(!WurstClient.INSTANCE.getHax().antiWobbleHack.isEnabled()) - return MathHelper.lerp(delta, start, end); + return original.call(delta, start, end); return 0; } diff --git a/src/main/java/net/wurstclient/mixin/IngameHudMixin.java b/src/main/java/net/wurstclient/mixin/IngameHudMixin.java index 1e8a81b553..395b783029 100644 --- a/src/main/java/net/wurstclient/mixin/IngameHudMixin.java +++ b/src/main/java/net/wurstclient/mixin/IngameHudMixin.java @@ -29,13 +29,12 @@ public class IngameHudMixin @Final private DebugHud debugHud; - @Inject( - at = @At(value = "INVOKE", - target = "Lcom/mojang/blaze3d/systems/RenderSystem;enableBlend()V", - remap = false, - ordinal = 3), - method = "render(Lnet/minecraft/client/gui/DrawContext;F)V") - private void onRender(DrawContext context, float tickDelta, CallbackInfo ci) + // runs after renderScoreboardSidebar() + // and before playerListHud.setVisible() + @Inject(at = @At("HEAD"), + method = "renderPlayerList(Lnet/minecraft/client/gui/DrawContext;F)V") + private void onRenderPlayerList(DrawContext context, float tickDelta, + CallbackInfo ci) { if(debugHud.shouldShowDebugHud()) return; diff --git a/src/main/java/net/wurstclient/mixin/StatsScreenMixin.java b/src/main/java/net/wurstclient/mixin/StatsScreenMixin.java index b445e13ab1..2335f03a85 100644 --- a/src/main/java/net/wurstclient/mixin/StatsScreenMixin.java +++ b/src/main/java/net/wurstclient/mixin/StatsScreenMixin.java @@ -8,13 +8,13 @@ package net.wurstclient.mixin; 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; import net.fabricmc.fabric.api.client.screen.v1.Screens; import net.minecraft.client.gui.screen.Screen; -import net.minecraft.client.gui.screen.StatsListener; import net.minecraft.client.gui.screen.StatsScreen; import net.minecraft.client.gui.widget.ButtonWidget; import net.minecraft.client.gui.widget.ClickableWidget; @@ -23,8 +23,11 @@ import net.wurstclient.WurstClient; @Mixin(StatsScreen.class) -public abstract class StatsScreenMixin extends Screen implements StatsListener +public abstract class StatsScreenMixin extends Screen { + @Unique + private ButtonWidget toggleWurstButton; + private StatsScreenMixin(WurstClient wurst, Text title) { super(title); @@ -36,24 +39,39 @@ private void onCreateButtons(CallbackInfo ci) if(WurstClient.INSTANCE.getOtfs().disableOtf.shouldHideEnableButton()) return; - ButtonWidget toggleWurstButton = - ButtonWidget.builder(Text.literal(""), this::toggleWurst) - .dimensions(width / 2 - 152, height - 28, 150, 20).build(); + toggleWurstButton = ButtonWidget + .builder(Text.literal(""), this::toggleWurst).width(150).build(); updateWurstButtonText(toggleWurstButton); addDrawableChild(toggleWurstButton); + } + + @Inject(at = @At("TAIL"), method = "initTabNavigation()V") + private void onInitTabNavigation(CallbackInfo ci) + { + if(toggleWurstButton == null) + return; + ClickableWidget doneButton = wurst_getDoneButton(); + doneButton.setX(width / 2 + 2); + doneButton.setWidth(150); + + toggleWurstButton.setPosition(width / 2 - 152, doneButton.getY()); + } + + @Unique + private ClickableWidget wurst_getDoneButton() + { for(ClickableWidget button : Screens.getButtons(this)) - { - if(!button.getMessage().getString() + if(button.getMessage().getString() .equals(I18n.translate("gui.done"))) - continue; + return button; - button.setX(width / 2 + 2); - button.setWidth(150); - } + throw new IllegalStateException( + "Can't find the done button on the statistics screen."); } + @Unique private void toggleWurst(ButtonWidget button) { WurstClient wurst = WurstClient.INSTANCE; @@ -62,6 +80,7 @@ private void toggleWurst(ButtonWidget button) updateWurstButtonText(button); } + @Unique private void updateWurstButtonText(ButtonWidget button) { WurstClient wurst = WurstClient.INSTANCE; diff --git a/src/main/java/net/wurstclient/serverfinder/WurstServerPinger.java b/src/main/java/net/wurstclient/serverfinder/WurstServerPinger.java index 9bcf1947af..04bb0d120b 100644 --- a/src/main/java/net/wurstclient/serverfinder/WurstServerPinger.java +++ b/src/main/java/net/wurstclient/serverfinder/WurstServerPinger.java @@ -41,7 +41,7 @@ private void pingInCurrentThread(String ip, int port) try { - pinger.add(server, () -> {}); + pinger.add(server, () -> {}, () -> {}); System.out.println("Ping successful: " + ip + ":" + port); }catch(UnknownHostException e) diff --git a/src/main/java/net/wurstclient/util/GoogleTranslate.java b/src/main/java/net/wurstclient/util/GoogleTranslate.java index e3414e0625..705ca85b2f 100644 --- a/src/main/java/net/wurstclient/util/GoogleTranslate.java +++ b/src/main/java/net/wurstclient/util/GoogleTranslate.java @@ -12,6 +12,7 @@ import java.io.InputStreamReader; import java.io.UnsupportedEncodingException; import java.net.MalformedURLException; +import java.net.URI; import java.net.URL; import java.net.URLConnection; import java.net.URLEncoder; @@ -69,7 +70,7 @@ private static URL createURL(String text, String langFrom, String langTo) "https://translate.google.com/m?hl=en&sl=%s&tl=%s&ie=UTF-8&prev=_m&q=%s", langFrom, langTo, encodedText); - return new URL(urlString); + return URI.create(urlString).toURL(); }catch(MalformedURLException | UnsupportedEncodingException e) { diff --git a/src/main/java/net/wurstclient/util/ItemUtils.java b/src/main/java/net/wurstclient/util/ItemUtils.java index 22829a1e32..4150aacc84 100644 --- a/src/main/java/net/wurstclient/util/ItemUtils.java +++ b/src/main/java/net/wurstclient/util/ItemUtils.java @@ -7,16 +7,18 @@ */ package net.wurstclient.util; -import net.minecraft.enchantment.Enchantment; -import net.minecraft.enchantment.EnchantmentHelper; -import net.minecraft.entity.EquipmentSlot; -import net.minecraft.entity.attribute.EntityAttributes; +import java.util.OptionalDouble; + +import net.minecraft.component.DataComponentTypes; +import net.minecraft.component.type.AttributeModifiersComponent; +import net.minecraft.component.type.PotionContentsComponent; +import net.minecraft.entity.attribute.EntityAttribute; +import net.minecraft.entity.effect.StatusEffect; +import net.minecraft.entity.effect.StatusEffectInstance; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; -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.Identifier; import net.minecraft.util.InvalidIdentifierException; @@ -55,32 +57,28 @@ public static Item getItemFromNameOrID(String nameOrId) } } - public static float getAttackSpeed(Item item) + public static OptionalDouble getAttribute(Item item, + RegistryEntry attribute) { - return (float)item.getAttributeModifiers(EquipmentSlot.MAINHAND) - .get(EntityAttributes.GENERIC_ATTACK_SPEED).stream().findFirst() - .orElseThrow().getValue(); + return item.getComponents() + .getOrDefault(DataComponentTypes.ATTRIBUTE_MODIFIERS, + AttributeModifiersComponent.DEFAULT) + .modifiers().stream() + .filter(modifier -> modifier.attribute() == attribute) + .mapToDouble(modifier -> modifier.modifier().value()).findFirst(); } - /** - * Adds the specified enchantment to the specified item stack. Unlike - * {@link ItemStack#addEnchantment(Enchantment, int)}, this method doesn't - * limit the level to 127. - */ - public static void addEnchantment(ItemStack stack, Enchantment enchantment, - int level) + public static boolean hasEffect(ItemStack stack, + RegistryEntry effect) { - Identifier id = EnchantmentHelper.getEnchantmentId(enchantment); - NbtList nbt = getOrCreateNbtList(stack, ItemStack.ENCHANTMENTS_KEY); - nbt.add(EnchantmentHelper.createNbt(id, level)); - } - - public static NbtList getOrCreateNbtList(ItemStack stack, String key) - { - NbtCompound nbt = stack.getOrCreateNbt(); - if(!nbt.contains(key, NbtElement.LIST_TYPE)) - nbt.put(key, new NbtList()); + PotionContentsComponent potionContents = stack.getComponents() + .getOrDefault(DataComponentTypes.POTION_CONTENTS, + PotionContentsComponent.DEFAULT); - return nbt.getList(key, NbtElement.COMPOUND_TYPE); + for(StatusEffectInstance effectInstance : potionContents.getEffects()) + if(effectInstance.getEffectType() == effect) + return true; + + return false; } } diff --git a/src/main/java/net/wurstclient/util/LastServerRememberer.java b/src/main/java/net/wurstclient/util/LastServerRememberer.java index 0daae3b343..49d2f806c5 100644 --- a/src/main/java/net/wurstclient/util/LastServerRememberer.java +++ b/src/main/java/net/wurstclient/util/LastServerRememberer.java @@ -49,6 +49,6 @@ public static void reconnect(Screen prevScreen) return; ConnectScreen.connect(prevScreen, WurstClient.MC, - ServerAddress.parse(lastServer.address), lastServer, false); + ServerAddress.parse(lastServer.address), lastServer, false, null); } } diff --git a/src/main/java/net/wurstclient/util/ListWidget.java b/src/main/java/net/wurstclient/util/ListWidget.java index 236a8011d4..83060fdde1 100644 --- a/src/main/java/net/wurstclient/util/ListWidget.java +++ b/src/main/java/net/wurstclient/util/ListWidget.java @@ -21,18 +21,21 @@ import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.Drawable; import net.minecraft.client.gui.Element; -import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.render.BufferBuilder; import net.minecraft.client.render.GameRenderer; import net.minecraft.client.render.Tessellator; import net.minecraft.client.render.VertexFormat; import net.minecraft.client.render.VertexFormats; import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.util.Identifier; import net.minecraft.util.math.MathHelper; public abstract class ListWidget extends AbstractParentElement implements Drawable { + private static final Identifier MENU_LIST_BACKGROUND_TEXTURE = + new Identifier("textures/gui/menu_list_background.png"); + protected final MinecraftClient client; protected int width; protected int height; @@ -144,7 +147,8 @@ public void render(DrawContext context, int mouseX, int mouseY, float delta) capYPosition(); Tessellator tessellator = Tessellator.getInstance(); BufferBuilder bufferBuilder = tessellator.getBuffer(); - RenderSystem.setShaderTexture(0, Screen.OPTIONS_BACKGROUND_TEXTURE); + RenderSystem.enableBlend(); + RenderSystem.setShaderTexture(0, MENU_LIST_BACKGROUND_TEXTURE); RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); RenderSystem.setShader(GameRenderer::getPositionTexColorProgram); bufferBuilder.begin(VertexFormat.DrawMode.QUADS, @@ -167,7 +171,9 @@ public void render(DrawContext context, int mouseX, int mouseY, float delta) if(renderHeader) renderHeader(k, l, tessellator); + context.enableScissor(left, top, right, bottom); renderList(context, k, l, mouseX, mouseY, delta); + context.disableScissor(); RenderSystem.disableDepthTest(); renderHoleBackground(0, top, 255, 255); renderHoleBackground(bottom, height, 255, 255); @@ -175,9 +181,6 @@ public void render(DrawContext context, int mouseX, int mouseY, float delta) RenderSystem.blendFuncSeparate(GlStateManager.SrcFactor.SRC_ALPHA, GlStateManager.DstFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SrcFactor.ZERO, GlStateManager.DstFactor.ONE); - // RenderSystem.disableAlphaTest(); - // RenderSystem.shadeModel(7425); - // RenderSystem.disableTexture(); RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); bufferBuilder.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_TEXTURE_COLOR); @@ -246,9 +249,6 @@ public void render(DrawContext context, int mouseX, int mouseY, float delta) } renderDecorations(mouseX, mouseY); - // RenderSystem.enableTexture(); - // RenderSystem.shadeModel(7424); - // RenderSystem.enableAlphaTest(); RenderSystem.disableBlend(); } } @@ -392,7 +392,6 @@ protected void renderList(DrawContext context, int i, int j, int k, int l, { int q = left + width / 2 - getRowWidth() / 2; int r = left + width / 2 + getRowWidth() / 2; - // RenderSystem.disableTexture(); float g = isFocused() ? 1.0F : 0.5F; RenderSystem.setShaderColor(g, g, g, 1.0F); bufferBuilder.begin(VertexFormat.DrawMode.QUADS, @@ -410,7 +409,6 @@ protected void renderList(DrawContext context, int i, int j, int k, int l, bufferBuilder.vertex(r - 1, o - 1, 0.0D).next(); bufferBuilder.vertex(q + 1, o - 1, 0.0D).next(); tessellator.draw(); - // RenderSystem.enableTexture(); } RenderSystem.setShaderColor(1, 1, 1, 1); @@ -435,7 +433,8 @@ protected void renderHoleBackground(int top, int bottom, int topAlpha, { Tessellator tessellator = Tessellator.getInstance(); BufferBuilder bufferBuilder = tessellator.getBuffer(); - RenderSystem.setShaderTexture(0, Screen.OPTIONS_BACKGROUND_TEXTURE); + RenderSystem.enableBlend(); + RenderSystem.setShaderTexture(0, MENU_LIST_BACKGROUND_TEXTURE); RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); RenderSystem.setShader(GameRenderer::getPositionTexColorProgram); bufferBuilder.begin(VertexFormat.DrawMode.QUADS, diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index e1e2d737db..69f539f117 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -30,9 +30,9 @@ "depends": { "fabricloader": ">=0.15.9", - "fabric-api": ">=0.91.1", - "minecraft": "~1.20.3-beta.3", - "java": ">=17" + "fabric-api": ">=0.97.1", + "minecraft": "~1.20.5-alpha.24.13.a", + "java": ">=21" }, "suggests": { "mo_glass": "*" diff --git a/src/main/resources/wurst.accesswidener b/src/main/resources/wurst.accesswidener index 9085fb6356..fb5d63f683 100644 --- a/src/main/resources/wurst.accesswidener +++ b/src/main/resources/wurst.accesswidener @@ -18,6 +18,4 @@ accessible field net/minecraft/client/network/ClientPlayerInteractionManager bre accessible field net/minecraft/client/network/ClientPlayerInteractionManager currentBreakingProgress F accessible field net/minecraft/client/toast/ToastManager toastQueue Ljava/util/Deque; accessible field net/minecraft/entity/Entity movementMultiplier Lnet/minecraft/util/math/Vec3d; -accessible field net/minecraft/entity/Entity stepHeight F -accessible field net/minecraft/item/ArmorItem toughness F accessible field net/minecraft/network/packet/s2c/play/ChunkDeltaUpdateS2CPacket sectionPos Lnet/minecraft/util/math/ChunkSectionPos;