Skip to content
This repository has been archived by the owner on Oct 24, 2024. It is now read-only.

Commit

Permalink
Merge v7.41.2 into 1.20.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander01998 committed Mar 27, 2024
1 parent a95b7d3 commit b92772a
Show file tree
Hide file tree
Showing 7 changed files with 222 additions and 201 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/stale.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
239 changes: 121 additions & 118 deletions codestyle/cleanup.xml

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions codestyle/formatter.xml
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@
<setting id="org.eclipse.jdt.core.formatter.wrap_before_additive_operator" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.keep_simple_getter_setter_on_one_line" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_while" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_block_in_case_after_arrow" value="next_line"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_parameters" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_string_concatenation" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_lambda_arrow" value="insert"/>
Expand Down Expand Up @@ -280,6 +281,7 @@
<setting id="org.eclipse.jdt.core.formatter.alignment_for_relational_operator" value="0"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.number_of_empty_lines_to_preserve" value="1"/>
<setting id="org.eclipse.jdt.core.formatter.align_arrows_in_switch_on_columns" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_case" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_additive_operator" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_if" value="do not insert"/>
Expand Down Expand Up @@ -310,6 +312,7 @@
<setting id="org.eclipse.jdt.core.formatter.wrap_before_conditional_operator" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_cases" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_allocation_expression" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.join_line_comments" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_synchronized" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_shift_operator" value="0"/>
<setting id="org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations" value="false"/>
Expand Down
113 changes: 47 additions & 66 deletions src/main/java/net/wurstclient/commands/PotionCmd.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -60,15 +60,18 @@ public void call(String[] args) throws CmdException
throw new CmdSyntaxError();

// get effects to start with
NbtList effects;
ArrayList<StatusEffectInstance> effects;
Potion potion;
switch(args[0].toLowerCase())
{
case "add":
effects = convertEffectsToNbt(stack);
effects = new ArrayList<>(PotionUtil.getCustomPotionEffects(stack));
potion = PotionUtil.getPotion(stack);
break;

case "set":
effects = new NbtList();
effects = new ArrayList<>();
potion = Potions.EMPTY;
break;

default:
Expand All @@ -78,97 +81,75 @@ public void call(String[] args) throws CmdException
// 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);
PotionUtil.setPotion(stack, potion);
setCustomPotionEffects(stack, effects);
ChatUtils.message("Potion modified.");
}

private NbtList convertEffectsToNbt(ItemStack stack)
{
NbtList nbt = new NbtList();
List<StatusEffectInstance> 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<StatusEffectInstance> 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<StatusEffectInstance> newEffects = new ArrayList<>();
if(mainPotionContainsTargetEffect)
PotionUtil.getPotionEffects(stack).forEach(newEffects::add);
else
PotionUtil.getCustomPotionEffects(stack).forEach(newEffects::add);
newEffects.removeIf(effect -> effect.getEffectType() == targetEffect);

Potion newPotion =
mainPotionContainsTargetEffect ? Potions.EMPTY : oldPotion;

NbtCompound nbt = new NbtCompound();
nbt.put("custom_potion_effects", newEffects);
stack.setNbt(nbt);
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<StatusEffectInstance> 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
Expand Down
14 changes: 12 additions & 2 deletions src/main/java/net/wurstclient/hacks/AntiSpamHack.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Text> 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 + "]"));
}
}
}
2 changes: 1 addition & 1 deletion src/main/java/net/wurstclient/hacks/AutoLibrarianHack.java
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ private BookOffer findEnchantedBookOffer(TradeOfferList tradeOffers)
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);
Expand Down
46 changes: 34 additions & 12 deletions src/main/java/net/wurstclient/mixin/PlayerSkinProviderMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,31 @@
*/
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;
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<String, String> capes;
private MinecraftProfileTexture currentCape;

@Inject(at = @At("HEAD"),
Expand All @@ -45,9 +47,9 @@ private void onFetchSkinTextures(UUID uuid,
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
Expand Down Expand Up @@ -81,12 +83,32 @@ private void setupWurstCapes()
{
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<String, String> 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)
{
Expand Down

0 comments on commit b92772a

Please sign in to comment.