From 5293427da948c431dd92d2a9faca73baee1c6c96 Mon Sep 17 00:00:00 2001 From: Alexander01998 Date: Sun, 24 Mar 2024 02:06:40 +0100 Subject: [PATCH 1/7] Update Formatter and Clean Up settings for Eclipse 2024-03 --- codestyle/cleanup.xml | 259 +++++++++--------- codestyle/formatter.xml | 3 + .../wurstclient/hacks/AutoLibrarianHack.java | 2 +- 3 files changed, 135 insertions(+), 129 deletions(-) diff --git a/codestyle/cleanup.xml b/codestyle/cleanup.xml index 70a36773..a6aa8d3e 100644 --- a/codestyle/cleanup.xml +++ b/codestyle/cleanup.xml @@ -1,144 +1,147 @@ - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - + + - - - - - - - - - - - - - - - - - - + + + + + + + + + - - - - - - - - - + - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/codestyle/formatter.xml b/codestyle/formatter.xml index b44984ad..3c2ecb64 100644 --- a/codestyle/formatter.xml +++ b/codestyle/formatter.xml @@ -200,6 +200,7 @@ + @@ -280,6 +281,7 @@ + @@ -310,6 +312,7 @@ + diff --git a/src/main/java/net/wurstclient/hacks/AutoLibrarianHack.java b/src/main/java/net/wurstclient/hacks/AutoLibrarianHack.java index 0f1345be..2f49d3c2 100644 --- a/src/main/java/net/wurstclient/hacks/AutoLibrarianHack.java +++ b/src/main/java/net/wurstclient/hacks/AutoLibrarianHack.java @@ -418,7 +418,7 @@ public final class AutoLibrarianHack extends Hack for(TradeOffer tradeOffer : tradeOffers) { ItemStack stack = tradeOffer.getSellItem(); - if(!(stack.getItem() instanceof EnchantedBookItem book)) + if(!(stack.getItem() instanceof EnchantedBookItem)) continue; NbtList enchantmentNbt = EnchantedBookItem.getEnchantmentNbt(stack); From 8ab404269bc3cb8f3fa30fad5c18a59fcffe00e0 Mon Sep 17 00:00:00 2001 From: Alexander01998 Date: Mon, 25 Mar 2024 17:09:26 +0100 Subject: [PATCH 2/7] Update stale.yml --- .github/workflows/stale.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml index 6373e4bc..f3942d43 100644 --- a/.github/workflows/stale.yml +++ b/.github/workflows/stale.yml @@ -11,7 +11,7 @@ jobs: stale: runs-on: ubuntu-latest steps: - - uses: actions/stale@main + - uses: actions/stale@v9 with: stale-issue-message: | This issue has been open for a while with no recent activity. If this issue is still important to you, please add a comment within the next 7 days to keep it open. Otherwise, the issue will be automatically closed to free up time for other tasks. @@ -31,7 +31,9 @@ jobs: - They have bugs or conflicts that won't be resolved days-before-stale: 60 days-before-close: 7 + exempt-issue-labels: "status:never-stale" + exempt-pr-labels: "status:never-stale" stale-issue-label: "status:stale" stale-pr-label: "status:stale" - operations-per-run: 50 + operations-per-run: 200 enable-statistics: true From 334a3a2024a5f109da2129329f5a76e4cde3b083 Mon Sep 17 00:00:00 2001 From: Alexander01998 Date: Wed, 27 Mar 2024 04:00:47 +0100 Subject: [PATCH 3/7] Fix Wurst Capes not showing on cracked servers --- .../mixin/PlayerSkinProviderMixin.java | 46 ++++++++++++++----- 1 file changed, 34 insertions(+), 12 deletions(-) diff --git a/src/main/java/net/wurstclient/mixin/PlayerSkinProviderMixin.java b/src/main/java/net/wurstclient/mixin/PlayerSkinProviderMixin.java index 9af40e2b..49456f00 100644 --- a/src/main/java/net/wurstclient/mixin/PlayerSkinProviderMixin.java +++ b/src/main/java/net/wurstclient/mixin/PlayerSkinProviderMixin.java @@ -7,10 +7,11 @@ */ package net.wurstclient.mixin; -import java.io.InputStreamReader; -import java.net.URL; +import java.util.HashMap; +import java.util.Map.Entry; import java.util.UUID; import java.util.concurrent.CompletableFuture; +import java.util.regex.Pattern; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -18,18 +19,19 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.ModifyVariable; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import com.google.gson.JsonObject; -import com.google.gson.JsonParser; import com.mojang.authlib.minecraft.MinecraftProfileTexture; import com.mojang.authlib.minecraft.MinecraftProfileTextures; import net.minecraft.client.texture.PlayerSkinProvider; import net.minecraft.client.util.SkinTextures; +import net.minecraft.util.Uuids; +import net.wurstclient.util.json.JsonUtils; +import net.wurstclient.util.json.WsonObject; @Mixin(PlayerSkinProvider.class) public abstract class PlayerSkinProviderMixin { - private static JsonObject capes; + private static HashMap capes; private MinecraftProfileTexture currentCape; @Inject(at = @At("HEAD"), @@ -45,9 +47,9 @@ public abstract class PlayerSkinProviderMixin if(capes == null) setupWurstCapes(); - if(capes.has(uuidString)) + if(capes.containsKey(uuidString)) { - String capeURL = capes.get(uuidString).getAsString(); + String capeURL = capes.get(uuidString); currentCape = new MinecraftProfileTexture(capeURL, null); }else @@ -81,12 +83,32 @@ public abstract class PlayerSkinProviderMixin { try { - // TODO: download capes to file - URL url = new URL("https://www.wurstclient.net/api/v1/capes.json"); + // download cape list from wurstclient.net + WsonObject rawCapes = JsonUtils.parseURLToObject( + "https://www.wurstclient.net/api/v1/capes.json"); - capes = - JsonParser.parseReader(new InputStreamReader(url.openStream())) - .getAsJsonObject(); + Pattern uuidPattern = Pattern.compile( + "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}"); + + // convert names to offline UUIDs + capes = new HashMap<>(); + for(Entry entry : rawCapes.getAllStrings() + .entrySet()) + { + String name = entry.getKey(); + String capeURL = entry.getValue(); + + // check if name is already a UUID + if(uuidPattern.matcher(name).matches()) + { + capes.put(name, capeURL); + continue; + } + + // convert name to offline UUID + String offlineUUID = "" + Uuids.getOfflinePlayerUuid(name); + capes.put(offlineUUID, capeURL); + } }catch(Exception e) { From 7297743b20155cefb23fa2a23459c9dea4a0ffc2 Mon Sep 17 00:00:00 2001 From: Alexander01998 Date: Wed, 27 Mar 2024 04:03:54 +0100 Subject: [PATCH 4/7] Port AntiSpam fix from 1.20.5 snapshots --- .../java/net/wurstclient/hacks/AntiSpamHack.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/wurstclient/hacks/AntiSpamHack.java b/src/main/java/net/wurstclient/hacks/AntiSpamHack.java index efae48f6..16aed807 100644 --- a/src/main/java/net/wurstclient/hacks/AntiSpamHack.java +++ b/src/main/java/net/wurstclient/hacks/AntiSpamHack.java @@ -135,7 +135,17 @@ public final class AntiSpamHack extends Hack implements ChatInputListener } 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 + "]")); + } } } From 877576494e379c18fcd641dc43c549ae20aa0598 Mon Sep 17 00:00:00 2001 From: Alexander01998 Date: Wed, 27 Mar 2024 13:41:01 +0100 Subject: [PATCH 5/7] Fix PotionCmd --- .../net/wurstclient/commands/PotionCmd.java | 109 +++++++----------- 1 file changed, 43 insertions(+), 66 deletions(-) diff --git a/src/main/java/net/wurstclient/commands/PotionCmd.java b/src/main/java/net/wurstclient/commands/PotionCmd.java index 9a478c36..75f9cc83 100644 --- a/src/main/java/net/wurstclient/commands/PotionCmd.java +++ b/src/main/java/net/wurstclient/commands/PotionCmd.java @@ -7,15 +7,15 @@ */ package net.wurstclient.commands; -import java.util.List; +import java.util.ArrayList; 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.potion.PotionUtil; +import net.minecraft.potion.Potions; import net.minecraft.registry.Registries; import net.minecraft.util.Identifier; import net.minecraft.util.InvalidIdentifierException; @@ -60,15 +60,15 @@ public final class PotionCmd extends Command throw new CmdSyntaxError(); // get effects to start with - NbtList effects; + ArrayList effects; switch(args[0].toLowerCase()) { case "add": - effects = convertEffectsToNbt(stack); + effects = new ArrayList<>(PotionUtil.getCustomPotionEffects(stack)); break; case "set": - effects = new NbtList(); + effects = new ArrayList<>(); break; default: @@ -78,97 +78,74 @@ public final class PotionCmd extends Command // add new effects for(int i = 0; i < (args.length - 1) / 3; i++) { - NbtCompound effect = new NbtCompound(); + StatusEffect effect = parseEffect(args[1 + i * 3]); + int amplifier = parseInt(args[2 + i * 3]) - 1; + int duration = parseInt(args[3 + i * 3]) * 20; - effect.putInt("id", parseEffectId(args[1 + i * 3])); - effect.putInt("amplifier", parseInt(args[2 + i * 3]) - 1); - effect.putInt("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); + setCustomPotionEffects(stack, effects); ChatUtils.message("Potion modified."); } - private NbtList convertEffectsToNbt(ItemStack stack) - { - NbtList nbt = new NbtList(); - List effects = - PotionUtil.getCustomPotionEffects(stack); - - for(StatusEffectInstance effect : effects) - { - NbtCompound tag = new NbtCompound(); - - int id = Registries.STATUS_EFFECT.getRawId(effect.getEffectType()); - tag.putInt("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(); - int id = parseEffectId(args[1]); + StatusEffect targetEffect = parseEffect(args[1]); - List oldEffects = - PotionUtil.getCustomPotionEffects(stack); + Potion oldPotion = PotionUtil.getPotion(stack); + boolean mainPotionContainsTargetEffect = oldPotion.getEffects().stream() + .anyMatch(effect -> effect.getEffectType() == targetEffect); - NbtList newEffects = new NbtList(); - for(StatusEffectInstance oldEffect : oldEffects) - { - int oldId = - Registries.STATUS_EFFECT.getRawId(oldEffect.getEffectType()); - - if(oldId == id) - continue; - - NbtCompound effect = new NbtCompound(); - effect.putInt("id", oldId); - effect.putInt("amplifier", oldEffect.getAmplifier()); - effect.putInt("duration", oldEffect.getDuration()); - newEffects.add(effect); - } + ArrayList newEffects = new ArrayList<>(); + if(mainPotionContainsTargetEffect) + PotionUtil.getPotionEffects(stack).forEach(newEffects::add); + else + PotionUtil.getCustomPotionEffects(stack).forEach(newEffects::add); + newEffects.removeIf(effect -> effect.getEffectType() == targetEffect); - NbtCompound nbt = new NbtCompound(); - nbt.put("custom_potion_effects", newEffects); - stack.setNbt(nbt); + Potion newPotion = + mainPotionContainsTargetEffect ? Potions.EMPTY : oldPotion; + + PotionUtil.setPotion(stack, newPotion); + setCustomPotionEffects(stack, newEffects); ChatUtils.message("Effect removed."); } - private int parseEffectId(String input) throws CmdSyntaxError + private StatusEffect parseEffect(String input) throws CmdSyntaxError { - int id = 0; + StatusEffect effect; if(MathUtils.isInteger(input)) - id = Integer.parseInt(input); + effect = Registries.STATUS_EFFECT.get(Integer.parseInt(input)); else try { Identifier identifier = new Identifier(input); - StatusEffect effect = Registries.STATUS_EFFECT.get(identifier); - - id = Registries.STATUS_EFFECT.getRawId(effect); + effect = Registries.STATUS_EFFECT.get(identifier); }catch(InvalidIdentifierException e) { throw new CmdSyntaxError("Invalid effect: " + input); } - if(id < 1) - throw new CmdSyntaxError(); + if(effect == null) + throw new CmdSyntaxError("Invalid effect: " + input); - return id; + 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); } private int parseInt(String s) throws CmdSyntaxError From ff959168f74f25dee597d21a52eabf5b982429cf Mon Sep 17 00:00:00 2001 From: Alexander01998 Date: Wed, 27 Mar 2024 14:15:38 +0100 Subject: [PATCH 6/7] Update Fabric stuff --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 6c674e7f..caa312c0 100644 --- a/gradle.properties +++ b/gradle.properties @@ -10,7 +10,7 @@ yarn_mappings=1.20.4+build.3 loader_version=0.15.7 #Fabric api -fabric_version=0.96.4+1.20.4 +fabric_version=0.96.11+1.20.4 # Mod Properties mod_version = v7.41.2-MC1.20.4 From c4e22b94347374912a02ed6ccb8ee6e936e57d20 Mon Sep 17 00:00:00 2001 From: Alexander01998 Date: Wed, 27 Mar 2024 15:21:32 +0100 Subject: [PATCH 7/7] Fix PotionCmd still not behaving correctly --- src/main/java/net/wurstclient/commands/PotionCmd.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/net/wurstclient/commands/PotionCmd.java b/src/main/java/net/wurstclient/commands/PotionCmd.java index 75f9cc83..a2c3d056 100644 --- a/src/main/java/net/wurstclient/commands/PotionCmd.java +++ b/src/main/java/net/wurstclient/commands/PotionCmd.java @@ -61,14 +61,17 @@ public final class PotionCmd extends Command // get effects to start with ArrayList effects; + Potion potion; switch(args[0].toLowerCase()) { case "add": effects = new ArrayList<>(PotionUtil.getCustomPotionEffects(stack)); + potion = PotionUtil.getPotion(stack); break; case "set": effects = new ArrayList<>(); + potion = Potions.EMPTY; break; default: @@ -85,6 +88,7 @@ public final class PotionCmd extends Command effects.add(new StatusEffectInstance(effect, duration, amplifier)); } + PotionUtil.setPotion(stack, potion); setCustomPotionEffects(stack, effects); ChatUtils.message("Potion modified."); }