Skip to content

Commit

Permalink
Update to 24w18a
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander01998 committed May 5, 2024
1 parent 70f6111 commit 509fc58
Show file tree
Hide file tree
Showing 12 changed files with 197 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,16 @@
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.registry.DynamicRegistryManager;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.registry.tag.EnchantmentTags;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import net.minecraft.util.Util;
import net.wurstclient.WurstClient;
import net.wurstclient.hacks.autolibrarian.BookOffer;
import net.wurstclient.settings.BookOffersSetting;
import net.wurstclient.util.ListWidget;
Expand Down Expand Up @@ -352,8 +358,11 @@ public ListGui(MinecraftClient mc, AddBookOfferScreen screen)
super(mc, screen.width, screen.height, 32, screen.height - 80, 30);
this.mc = mc;
this.screen = screen;
list = Registries.ENCHANTMENT.stream().map(BookOffer::create)
.filter(BookOffer::isValid).sorted()
DynamicRegistryManager drm =
WurstClient.MC.world.getRegistryManager();
Registry<Enchantment> registry = drm.get(RegistryKeys.ENCHANTMENT);
list = registry.stream().map(BookOffer::create)
.filter(BookOffer::isFullyValid).sorted()
.collect(Collectors.toList());
}

Expand Down Expand Up @@ -410,16 +419,18 @@ protected void renderItem(DrawContext context, int index, int x, int y,

TextRenderer tr = mc.textRenderer;
BookOffer bookOffer = list.get(index);
Enchantment enchantment = bookOffer.getEnchantment();
RegistryEntry<Enchantment> enchantment =
bookOffer.getEnchantmentEntry().get();

String name = bookOffer.getEnchantmentName();
int nameColor = enchantment.isCursed() ? 0xff5555 : 0xf0f0f0;
int nameColor =
enchantment.isIn(EnchantmentTags.CURSE) ? 0xff5555 : 0xf0f0f0;
context.drawText(tr, name, x + 28, y, nameColor, false);

context.drawText(tr, bookOffer.id(), x + 28, y + 9, 0xa0a0a0,
false);

int maxLevel = enchantment.getMaxLevel();
int maxLevel = enchantment.value().getMaxLevel();
String levels = maxLevel + (maxLevel == 1 ? " level" : " levels");
context.drawText(tr, levels, x + 28, y + 18, 0xa0a0a0, false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.registry.Registries;
import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.registry.tag.EnchantmentTags;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import net.wurstclient.hacks.autolibrarian.BookOffer;
Expand Down Expand Up @@ -126,7 +128,7 @@ public void init()

addDrawableChild(
saveButton = ButtonWidget.builder(Text.literal("Save"), b -> {
if(offerToSave == null || !offerToSave.isValid())
if(offerToSave == null || !offerToSave.isFullyValid())
return;

bookOffers.replace(index, offerToSave);
Expand Down Expand Up @@ -274,8 +276,10 @@ public void render(DrawContext context, int mouseX, int mouseY,
BookOffer bookOffer = offerToSave;
String name = bookOffer.getEnchantmentNameWithLevel();

Enchantment enchantment = bookOffer.getEnchantment();
int nameColor = enchantment.isCursed() ? 0xff5555 : 0xffffff;
RegistryEntry<Enchantment> enchantment =
bookOffer.getEnchantmentEntry().get();
int nameColor =
enchantment.isIn(EnchantmentTags.CURSE) ? 0xff5555 : 0xffffff;
context.drawTextWithShadow(tr, name, x + 28, y, nameColor);

context.drawText(tr, bookOffer.id(), x + 28, y + 9, 0xa0a0a0, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.registry.Registries;
import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.registry.tag.EnchantmentTags;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import net.wurstclient.hacks.autolibrarian.BookOffer;
Expand Down Expand Up @@ -270,8 +272,10 @@ protected void renderItem(DrawContext context, int index, int x, int y,
BookOffer bookOffer = list.get(index);
String name = bookOffer.getEnchantmentNameWithLevel();

Enchantment enchantment = bookOffer.getEnchantment();
int nameColor = enchantment.isCursed() ? 0xff5555 : 0xf0f0f0;
RegistryEntry<Enchantment> enchantment =
bookOffer.getEnchantmentEntry().get();
int nameColor =
enchantment.isIn(EnchantmentTags.CURSE) ? 0xff5555 : 0xf0f0f0;
context.drawText(tr, name, x + 28, y, nameColor, false);

context.drawText(tr, bookOffer.id(), x + 28, y + 9, 0xa0a0a0,
Expand Down
21 changes: 14 additions & 7 deletions src/main/java/net/wurstclient/commands/EnchantCmd.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.Enchantments;
import net.minecraft.item.ItemStack;
import net.minecraft.registry.Registries;
import net.minecraft.registry.DynamicRegistryManager;
import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.registry.tag.EnchantmentTags;
import net.wurstclient.command.CmdError;
import net.wurstclient.command.CmdException;
import net.wurstclient.command.CmdSyntaxError;
Expand Down Expand Up @@ -53,24 +57,27 @@ private ItemStack getHeldItem() throws CmdError

private void enchant(ItemStack stack, int level)
{
for(Enchantment enchantment : Registries.ENCHANTMENT)
DynamicRegistryManager drm = MC.world.getRegistryManager();
Registry<Enchantment> registry = drm.get(RegistryKeys.ENCHANTMENT);

for(RegistryEntry<Enchantment> entry : registry.getIndexedEntries())
{
// Skip curses
if(enchantment.isCursed())
if(entry.isIn(EnchantmentTags.CURSE))
continue;

// Skip Silk Touch so it doesn't remove Fortune
if(enchantment == Enchantments.SILK_TOUCH)
if(entry.getKey().orElse(null) == Enchantments.SILK_TOUCH)
continue;

// Limit Quick Charge to level 5 so it doesn't break
if(enchantment == Enchantments.QUICK_CHARGE)
if(entry.getKey().orElse(null) == Enchantments.QUICK_CHARGE)
{
stack.addEnchantment(enchantment, Math.min(level, 5));
stack.addEnchantment(entry, Math.min(level, 5));
continue;
}

stack.addEnchantment(enchantment, level);
stack.addEnchantment(entry, level);
}
}

Expand Down
30 changes: 23 additions & 7 deletions src/main/java/net/wurstclient/hacks/AutoArmorHack.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,26 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Optional;

import net.minecraft.client.gui.screen.ingame.HandledScreen;
import net.minecraft.client.gui.screen.ingame.InventoryScreen;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.enchantment.Enchantments;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.item.ArmorItem;
import net.minecraft.item.ArmorItem.Type;
import net.minecraft.item.ItemStack;
import net.minecraft.network.packet.c2s.play.ClickSlotC2SPacket;
import net.minecraft.registry.DynamicRegistryManager;
import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.registry.entry.RegistryEntry.Reference;
import net.wurstclient.Category;
import net.wurstclient.SearchTags;
import net.wurstclient.WurstClient;
import net.wurstclient.events.PacketOutputListener;
import net.wurstclient.events.UpdateListener;
import net.wurstclient.hack.Hack;
Expand Down Expand Up @@ -180,13 +185,24 @@ private int getArmorValue(ArmorItem item, ItemStack stack)

if(useEnchantments.isChecked())
{
Enchantment protection = Enchantments.PROTECTION;
int prtLvl = EnchantmentHelper.getLevel(protection, stack);
DynamicRegistryManager drm =
WurstClient.MC.world.getRegistryManager();
Registry<Enchantment> registry = drm.get(RegistryKeys.ENCHANTMENT);

ClientPlayerEntity player = MC.player;
DamageSource dmgSource =
player.getDamageSources().playerAttack(player);
prtPoints = protection.getProtectionAmount(prtLvl, dmgSource);
Optional<Reference<Enchantment>> protection =
registry.getEntry(Enchantments.PROTECTION);
int prtLvl = protection
.map(entry -> EnchantmentHelper.getLevel(entry, stack))
.orElse(0);

// TODO: Only the server can calculate protection amount as of
// 24w18a. Might change back in later snapshots.

// ClientPlayerEntity player = MC.player;
// DamageSource dmgSource =
// player.getDamageSources().playerAttack(player);
// prtPoints = protection.getProtectionAmount(prtLvl, dmgSource);
prtPoints = prtLvl;
}

return armorPoints * 5 + prtPoints * 3 + armorToughness + armorType;
Expand Down
11 changes: 6 additions & 5 deletions src/main/java/net/wurstclient/hacks/AutoLibrarianHack.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,11 @@ public final class AutoLibrarianHack extends Hack
+ "You can also set a maximum price for each book, in case you"
+ " already have a villager selling it but you want it for a"
+ " cheaper price.",
"minecraft:depth_strider", "minecraft:efficiency",
"minecraft:feather_falling", "minecraft:fortune", "minecraft:looting",
"minecraft:mending", "minecraft:protection", "minecraft:respiration",
"minecraft:sharpness", "minecraft:silk_touch", "minecraft:unbreaking");
"minecraft:depth_strider;3", "minecraft:efficiency;5",
"minecraft:feather_falling;4", "minecraft:fortune;3",
"minecraft:looting;3", "minecraft:mending;1", "minecraft:protection;4",
"minecraft:respiration;3", "minecraft:sharpness;5",
"minecraft:silk_touch;1", "minecraft:unbreaking;3");

private final CheckboxSetting lockInTrade = new CheckboxSetting(
"Lock in trade",
Expand Down Expand Up @@ -433,7 +434,7 @@ private BookOffer findEnchantedBookOffer(TradeOfferList tradeOffers)
int price = tradeOffer.getDisplayedFirstBuyItem().getCount();
BookOffer bookOffer = new BookOffer(enchantment, level, price);

if(!bookOffer.isValid())
if(!bookOffer.isFullyValid())
{
System.out.println("Found invalid enchanted book offer.\n"
+ "Component data: " + enchantmentLevelMap);
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/net/wurstclient/hacks/AutoSwordHack.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
*/
package net.wurstclient.hacks;

import net.minecraft.enchantment.EnchantmentHelper;
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;
Expand Down Expand Up @@ -156,12 +154,16 @@ private float getValue(ItemStack stack, Entity entity)
.getAttribute(item, EntityAttributes.GENERIC_ATTACK_SPEED)
.orElseThrow();

// TODO: Client-side item-specific attack damage calculation no
// longer exists as of 24w18a. Seems to be a bug, as this would make
// the damage tooltip inaccurate. Check if they add it back in later
// snapshots.
case DAMAGE:
EntityType<?> group = entity.getType();
// EntityType<?> group = entity.getType();
float dmg = (float)ItemUtils
.getAttribute(item, EntityAttributes.GENERIC_ATTACK_DAMAGE)
.orElseThrow();
dmg += EnchantmentHelper.getAttackDamage(stack, group);
// dmg += EnchantmentHelper.getAttackDamage(stack, group);
return dmg;
}

Expand Down
24 changes: 20 additions & 4 deletions src/main/java/net/wurstclient/hacks/AutoToolHack.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,24 @@
*/
package net.wurstclient.hacks;

import java.util.Optional;

import net.minecraft.block.BlockState;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.enchantment.Enchantments;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.item.SwordItem;
import net.minecraft.registry.DynamicRegistryManager;
import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.registry.entry.RegistryEntry.Reference;
import net.minecraft.util.math.BlockPos;
import net.wurstclient.Category;
import net.wurstclient.SearchTags;
import net.wurstclient.WurstClient;
import net.wurstclient.events.BlockBreakingProgressListener;
import net.wurstclient.events.UpdateListener;
import net.wurstclient.hack.Hack;
Expand Down Expand Up @@ -180,10 +188,18 @@ private float getMiningSpeed(ItemStack stack, BlockState state)

if(speed > 1)
{
int efficiency =
EnchantmentHelper.getLevel(Enchantments.EFFICIENCY, stack);
if(efficiency > 0 && !stack.isEmpty())
speed += efficiency * efficiency + 1;
DynamicRegistryManager drm =
WurstClient.MC.world.getRegistryManager();
Registry<Enchantment> registry = drm.get(RegistryKeys.ENCHANTMENT);

Optional<Reference<Enchantment>> efficiency =
registry.getEntry(Enchantments.EFFICIENCY);
int effLvl = efficiency
.map(entry -> EnchantmentHelper.getLevel(entry, stack))
.orElse(0);

if(effLvl > 0 && !stack.isEmpty())
speed += effLvl * effLvl + 1;
}

return speed;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,22 @@
*/
package net.wurstclient.hacks.autofish;

import java.util.Optional;
import java.util.stream.IntStream;
import java.util.stream.Stream;

import net.minecraft.client.MinecraftClient;
import net.minecraft.component.EnchantmentEffectComponentTypes;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.enchantment.Enchantments;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.item.FishingRodItem;
import net.minecraft.item.ItemStack;
import net.minecraft.registry.DynamicRegistryManager;
import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.registry.entry.RegistryEntry.Reference;
import net.wurstclient.WurstClient;
import net.wurstclient.hacks.AutoFishHack;
import net.wurstclient.settings.CheckboxSetting;
Expand Down Expand Up @@ -128,14 +135,31 @@ private int getRodValue(ItemStack stack)
if(stack.isEmpty() || !(stack.getItem() instanceof FishingRodItem))
return -1;

int luckOTSLvl =
EnchantmentHelper.getLevel(Enchantments.LUCK_OF_THE_SEA, stack);
int lureLvl = EnchantmentHelper.getLevel(Enchantments.LURE, stack);
int unbreakingLvl =
EnchantmentHelper.getLevel(Enchantments.UNBREAKING, stack);
int mendingBonus =
EnchantmentHelper.getLevel(Enchantments.MENDING, stack);
int noVanishBonus = EnchantmentHelper.hasVanishingCurse(stack) ? 0 : 1;
DynamicRegistryManager drm = MC.world.getRegistryManager();
Registry<Enchantment> registry = drm.get(RegistryKeys.ENCHANTMENT);

Optional<Reference<Enchantment>> luckOTS =
registry.getEntry(Enchantments.LUCK_OF_THE_SEA);
int luckOTSLvl = luckOTS
.map(entry -> EnchantmentHelper.getLevel(entry, stack)).orElse(0);

Optional<Reference<Enchantment>> lure =
registry.getEntry(Enchantments.LURE);
int lureLvl = lure
.map(entry -> EnchantmentHelper.getLevel(entry, stack)).orElse(0);

Optional<Reference<Enchantment>> unbreaking =
registry.getEntry(Enchantments.UNBREAKING);
int unbreakingLvl = unbreaking
.map(entry -> EnchantmentHelper.getLevel(entry, stack)).orElse(0);

Optional<Reference<Enchantment>> mending =
registry.getEntry(Enchantments.MENDING);
int mendingBonus = mending
.map(entry -> EnchantmentHelper.getLevel(entry, stack)).orElse(0);

int noVanishBonus = EnchantmentHelper.hasAnyEnchantmentsWith(stack,
EnchantmentEffectComponentTypes.PREVENT_EQUIPMENT_DROP) ? 0 : 1;

return luckOTSLvl * 9 + lureLvl * 9 + unbreakingLvl * 2 + mendingBonus
+ noVanishBonus;
Expand Down
Loading

0 comments on commit 509fc58

Please sign in to comment.