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.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander01998 committed Mar 27, 2024
1 parent 59842ca commit 1eac7d4
Show file tree
Hide file tree
Showing 7 changed files with 199 additions and 202 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
112 changes: 47 additions & 65 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,96 +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("CustomPotionEffects", 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 = StatusEffect.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 = StatusEffect.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("CustomPotionEffects", 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 = StatusEffect.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("CustomPotionEffects");
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
25 changes: 11 additions & 14 deletions src/main/java/net/wurstclient/mixin/PlayerSkinProviderMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
*/
package net.wurstclient.mixin;

import java.io.InputStreamReader;
import java.net.URL;
import java.util.HashMap;

import javax.annotation.Nullable;
Expand All @@ -22,8 +20,6 @@

import com.google.common.collect.ImmutableList;
import com.google.common.collect.Maps;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.minecraft.InsecurePublicKeyException;
import com.mojang.authlib.minecraft.MinecraftProfileTexture;
Expand All @@ -35,6 +31,8 @@
import net.minecraft.client.texture.PlayerSkinProvider;
import net.minecraft.util.Identifier;
import net.minecraft.util.Util;
import net.wurstclient.util.json.JsonUtils;
import net.wurstclient.util.json.WsonObject;

@Mixin(PlayerSkinProvider.class)
public abstract class PlayerSkinProviderMixin
Expand All @@ -43,7 +41,7 @@ public abstract class PlayerSkinProviderMixin
@Final
private MinecraftSessionService sessionService;

private static JsonObject capes;
private static HashMap<String, String> capes;

@Inject(at = @At("HEAD"),
method = "loadSkin(Lcom/mojang/authlib/GameProfile;Lnet/minecraft/client/texture/PlayerSkinProvider$SkinTextureAvailableCallback;Z)V",
Expand Down Expand Up @@ -116,14 +114,14 @@ private void addWurstCape(GameProfile profile,
if(capes == null)
setupWurstCapes();

if(capes.has(name))
if(capes.containsKey(name))
{
String capeURL = capes.get(name).getAsString();
String capeURL = capes.get(name);
map.put(Type.CAPE, new MinecraftProfileTexture(capeURL, null));

}else if(capes.has(uuid))
}else if(capes.containsKey(uuid))
{
String capeURL = capes.get(uuid).getAsString();
String capeURL = capes.get(uuid);
map.put(Type.CAPE, new MinecraftProfileTexture(capeURL, null));
}

Expand All @@ -140,12 +138,11 @@ 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();
capes = rawCapes.getAllStrings();

}catch(Exception e)
{
Expand Down

0 comments on commit 1eac7d4

Please sign in to comment.