From 19e311d9250f7f3030e1827fa709152d037558a5 Mon Sep 17 00:00:00 2001 From: Alexander01998 Date: Tue, 5 Mar 2024 18:54:53 +0100 Subject: [PATCH] Update to 24w09a --- .../clickgui/screens/AddBookOfferScreen.java | 2 + .../clickgui/screens/EditBlockListScreen.java | 2 + .../clickgui/screens/EditBookOfferScreen.java | 2 +- .../screens/EditBookOffersScreen.java | 2 + .../clickgui/screens/EditItemListScreen.java | 2 + .../net/wurstclient/commands/AuthorCmd.java | 21 ++-- .../net/wurstclient/commands/EnchantCmd.java | 3 +- .../net/wurstclient/commands/GiveCmd.java | 4 +- .../net/wurstclient/commands/ModifyCmd.java | 24 ++-- .../net/wurstclient/commands/PotionCmd.java | 108 ++++++++---------- .../net/wurstclient/commands/RenameCmd.java | 9 +- .../net/wurstclient/commands/ViewNbtCmd.java | 12 +- .../net/wurstclient/hacks/AntiSpamHack.java | 14 ++- .../wurstclient/hacks/AutoLibrarianHack.java | 22 ++-- .../net/wurstclient/hacks/AutoPotionHack.java | 22 +--- .../net/wurstclient/hacks/AutoSwordHack.java | 18 ++- .../net/wurstclient/hacks/CrashChestHack.java | 6 +- .../net/wurstclient/hacks/KillPotionHack.java | 26 +++-- .../wurstclient/hacks/TrollPotionHack.java | 33 +++--- .../wurstclient/mixin/StatsScreenMixin.java | 41 +++++-- .../java/net/wurstclient/util/ItemUtils.java | 57 +++++---- .../java/net/wurstclient/util/ListWidget.java | 21 ++-- src/main/resources/fabric.mod.json | 6 +- 23 files changed, 248 insertions(+), 209 deletions(-) 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 64613ad158..9f55986852 100644 --- a/src/main/java/net/wurstclient/commands/PotionCmd.java +++ b/src/main/java/net/wurstclient/commands/PotionCmd.java @@ -7,15 +7,18 @@ */ package net.wurstclient.commands; -import java.util.List; +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.nbt.NbtCompound; -import net.minecraft.nbt.NbtList; +import net.minecraft.potion.Potion; 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; @@ -58,16 +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 - NbtList effects; + ArrayList effects; + Optional> potion; switch(args[0].toLowerCase()) { case "add": - effects = convertEffectsToNbt(stack); + effects = new ArrayList<>(oldContents.customEffects()); + potion = oldContents.potion(); break; case "set": - effects = new NbtList(); + effects = new ArrayList<>(); + potion = Optional.empty(); break; default: @@ -77,76 +87,54 @@ public void call(String[] args) throws CmdException // add new effects for(int i = 0; i < (args.length - 1) / 3; i++) { - NbtCompound effect = new NbtCompound(); - - effect.putString("id", parseEffectId(args[1 + i * 3])); - effect.putInt("amplifier", parseInt(args[2 + i * 3]) - 1); - effect.putInt("duration", parseInt(args[3 + i * 3]) * 20); + 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(effect); + effects.add(new StatusEffectInstance(effect, duration, amplifier)); } - NbtCompound nbt = new NbtCompound(); - nbt.put("custom_potion_effects", effects); - stack.setNbt(nbt); + stack.set(DataComponentTypes.POTION_CONTENTS, + new PotionContentsComponent(potion, oldContents.customColor(), + effects)); ChatUtils.message("Potion modified."); } - private NbtList convertEffectsToNbt(ItemStack stack) - { - NbtList nbt = new NbtList(); - List effects = - PotionContentsComponent.getCustomPotionEffects(stack); - - for(StatusEffectInstance effect : effects) - { - NbtCompound tag = new NbtCompound(); - - String id = Registries.STATUS_EFFECT - .getId(effect.getEffectType().value()).toString(); - tag.putString("id", id); - tag.putInt("amplifier", effect.getAmplifier()); - tag.putInt("duration", effect.getDuration()); - - nbt.add(tag); - } - - return nbt; - } - private void remove(ItemStack stack, String[] args) throws CmdSyntaxError { if(args.length != 2) throw new CmdSyntaxError(); - String id = parseEffectId(args[1]); + RegistryEntry targetEffect = parseEffect(args[1]); - List oldEffects = - PotionContentsComponent.getCustomPotionEffects(stack); + PotionContentsComponent oldContents = stack.getComponents() + .getOrDefault(DataComponentTypes.POTION_CONTENTS, + PotionContentsComponent.DEFAULT); - NbtList newEffects = new NbtList(); - for(StatusEffectInstance oldEffect : oldEffects) - { - String oldId = Registries.STATUS_EFFECT - .getId(oldEffect.getEffectType().value()).toString(); - - if(oldId.equals(id)) - continue; - - NbtCompound effect = new NbtCompound(); - effect.putString("id", oldId); - effect.putInt("amplifier", oldEffect.getAmplifier()); - effect.putInt("duration", oldEffect.getDuration()); - newEffects.add(effect); - } + boolean mainPotionContainsTargetEffect = + oldContents.potion().isPresent() + && oldContents.potion().get().value().getEffects().stream() + .anyMatch(effect -> effect.getEffectType() == targetEffect); + + ArrayList newEffects = new ArrayList<>(); + if(mainPotionContainsTargetEffect) + oldContents.getEffects().forEach(newEffects::add); + else + oldContents.customEffects().forEach(newEffects::add); + newEffects.removeIf(effect -> effect.getEffectType() == targetEffect); + + Optional> newPotion = + mainPotionContainsTargetEffect ? Optional.empty() + : oldContents.potion(); + stack.set(DataComponentTypes.POTION_CONTENTS, + new PotionContentsComponent(newPotion, oldContents.customColor(), + newEffects)); - NbtCompound nbt = new NbtCompound(); - nbt.put("custom_potion_effects", newEffects); - stack.setNbt(nbt); ChatUtils.message("Effect removed."); } - private String parseEffectId(String input) throws CmdSyntaxError + private RegistryEntry parseEffect(String input) + throws CmdSyntaxError { StatusEffect effect; @@ -166,7 +154,7 @@ private String parseEffectId(String input) throws CmdSyntaxError if(effect == null) throw new CmdSyntaxError("Invalid effect: " + input); - return Registries.STATUS_EFFECT.getId(effect).toString(); + 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/hacks/AntiSpamHack.java b/src/main/java/net/wurstclient/hacks/AntiSpamHack.java index efae48f64a..16aed8079b 100644 --- a/src/main/java/net/wurstclient/hacks/AntiSpamHack.java +++ b/src/main/java/net/wurstclient/hacks/AntiSpamHack.java @@ -135,7 +135,17 @@ public void onReceivedMessage(ChatInputEvent event) } if(spamCounter > 1) - event.setComponent(((MutableText)event.getComponent()) - .append(" [x" + spamCounter + "]")); + { + // Someone, somewhere, is creating a MutableText object with an + // immutable List siblings parameter, which causes the game to + // crash when calling append(). So we always have to create a new + // MutableText object to avoid that. + MutableText oldText = (MutableText)event.getComponent(); + MutableText newText = MutableText.of(oldText.getContent()); + newText.setStyle(oldText.getStyle()); + oldText.getSiblings().forEach(newText::append); + + event.setComponent(newText.append(" [x" + spamCounter + "]")); + } } } diff --git a/src/main/java/net/wurstclient/hacks/AutoLibrarianHack.java b/src/main/java/net/wurstclient/hacks/AutoLibrarianHack.java index be89bccc4e..ed5a4d5c95 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; @@ -421,20 +426,23 @@ private BookOffer findEnchantedBookOffer(TradeOfferList tradeOffers) if(!(stack.getItem() instanceof EnchantedBookItem book)) 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"); + 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 aa2504fb48..1507af046f 100644 --- a/src/main/java/net/wurstclient/hacks/AutoPotionHack.java +++ b/src/main/java/net/wurstclient/hacks/AutoPotionHack.java @@ -7,19 +7,16 @@ */ package net.wurstclient.hacks; -import net.minecraft.component.type.PotionContentsComponent; -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.registry.entry.RegistryEntry; 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", @@ -112,25 +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, - RegistryEntry effect) - { - for(StatusEffectInstance effectInstance : PotionContentsComponent - .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 49760deb9a..f545df726d 100644 --- a/src/main/java/net/wurstclient/hacks/AutoSwordHack.java +++ b/src/main/java/net/wurstclient/hacks/AutoSwordHack.java @@ -11,10 +11,9 @@ import net.minecraft.entity.Entity; 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,17 +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: EntityType group = entity.getType(); - 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; + 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/CrashChestHack.java b/src/main/java/net/wurstclient/hacks/CrashChestHack.java index e76ce26dc9..f6b9555926 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 @@ public 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 48a4322614..e241e88c38 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/TrollPotionHack.java b/src/main/java/net/wurstclient/hacks/TrollPotionHack.java index 29a8e49944..21398d1d75 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/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/util/ItemUtils.java b/src/main/java/net/wurstclient/util/ItemUtils.java index 22829a1e32..f3916bbef7 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,29 @@ 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().getValue()) + .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/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 af79f50ee0..51fc8ca8a1 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -29,9 +29,9 @@ "accessWidener" : "wurst.accesswidener", "depends": { - "fabricloader": ">=0.15.6", - "fabric-api": ">=0.95.6", - "minecraft": "~1.20.5-alpha.24.6.a", + "fabricloader": ">=0.15.7", + "fabric-api": ">=0.96.6", + "minecraft": "~1.20.5-alpha.24.9.a", "java": ">=17" }, "suggests": {