diff --git a/src/main/java/meteordevelopment/meteorclient/gui/widgets/WAccount.java b/src/main/java/meteordevelopment/meteorclient/gui/widgets/WAccount.java index 1c4d3ef640..45458bb974 100644 --- a/src/main/java/meteordevelopment/meteorclient/gui/widgets/WAccount.java +++ b/src/main/java/meteordevelopment/meteorclient/gui/widgets/WAccount.java @@ -58,7 +58,7 @@ public void init() { screen.locked = true; MeteorExecutor.execute(() -> { - if (account.login()) { + if (account.fetchInfo() && account.login()) { name.set(account.getUsername()); Accounts.get().save(); diff --git a/src/main/java/meteordevelopment/meteorclient/pathing/BaritoneSettings.java b/src/main/java/meteordevelopment/meteorclient/pathing/BaritoneSettings.java index d900c6419a..8294edaa12 100644 --- a/src/main/java/meteordevelopment/meteorclient/pathing/BaritoneSettings.java +++ b/src/main/java/meteordevelopment/meteorclient/pathing/BaritoneSettings.java @@ -24,6 +24,8 @@ public class BaritoneSettings implements IPathManager.ISettings { private Setting walkOnWater, walkOnLava; private Setting step, noFall; + private static final Map SETTING_MAX_VALUES = new HashMap<>(); + public BaritoneSettings() { createWrappers(); } @@ -58,6 +60,10 @@ public void save() { SettingsUtil.save(BaritoneAPI.getSettings()); } + static { + SETTING_MAX_VALUES.put("pathCutoffFactor", 1.0); + } + // Wrappers @SuppressWarnings({"rawtypes", "unchecked"}) @@ -103,6 +109,8 @@ else if (value instanceof Double) { .name(setting.getName()) .description(getDescription(setting.getName())) .defaultValue((double) setting.defaultValue) + .max(SETTING_MAX_VALUES.getOrDefault(setting.getName(), 10.0)) + .sliderMax(SETTING_MAX_VALUES.getOrDefault(setting.getName(), 10.0)) .onChanged(aDouble -> setting.value = aDouble) .onModuleActivated(doubleSetting -> doubleSetting.set((Double) setting.value)) .build() @@ -113,6 +121,8 @@ else if (value instanceof Float) { .name(setting.getName()) .description(getDescription(setting.getName())) .defaultValue(((Float) setting.defaultValue).doubleValue()) + .max(SETTING_MAX_VALUES.getOrDefault(setting.getName(), 10.0)) + .sliderMax(SETTING_MAX_VALUES.getOrDefault(setting.getName(), 10.0)) .onChanged(aDouble -> setting.value = aDouble.floatValue()) .onModuleActivated(doubleSetting -> doubleSetting.set(((Float) setting.value).doubleValue())) .build() diff --git a/src/main/java/meteordevelopment/meteorclient/systems/accounts/Accounts.java b/src/main/java/meteordevelopment/meteorclient/systems/accounts/Accounts.java index 7a675043c3..829e4dee67 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/accounts/Accounts.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/accounts/Accounts.java @@ -73,18 +73,14 @@ public Accounts fromTag(NbtCompound tag) { AccountType type = AccountType.valueOf(t.getString("type")); try { - Account account = switch (type) { + return switch (type) { case Cracked -> new CrackedAccount(null).fromTag(t); case Microsoft -> new MicrosoftAccount(null).fromTag(t); case TheAltening -> new TheAlteningAccount(null).fromTag(t); }; - - if (account.fetchInfo()) return account; } catch (NbtException e) { return null; } - - return null; })); return this; diff --git a/src/main/java/meteordevelopment/meteorclient/systems/accounts/types/MicrosoftAccount.java b/src/main/java/meteordevelopment/meteorclient/systems/accounts/types/MicrosoftAccount.java index ba0804ba71..025b4ec167 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/accounts/types/MicrosoftAccount.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/accounts/types/MicrosoftAccount.java @@ -10,33 +10,34 @@ import meteordevelopment.meteorclient.systems.accounts.AccountType; import meteordevelopment.meteorclient.systems.accounts.MicrosoftLogin; import net.minecraft.client.session.Session; +import org.jetbrains.annotations.Nullable; import java.util.Optional; public class MicrosoftAccount extends Account { + private @Nullable String token; public MicrosoftAccount(String refreshToken) { super(AccountType.Microsoft, refreshToken); } @Override public boolean fetchInfo() { - return auth() != null; + token = auth(); + return token != null; } @Override public boolean login() { - super.login(); - - String token = auth(); if (token == null) return false; + super.login(); cache.loadHead(); setSession(new Session(cache.username, UndashedUuid.fromStringLenient(cache.uuid), token, Optional.empty(), Optional.empty(), Session.AccountType.MSA)); return true; } - private String auth() { + private @Nullable String auth() { MicrosoftLogin.LoginData data = MicrosoftLogin.login(name); if (!data.isGood()) return null; diff --git a/src/main/java/meteordevelopment/meteorclient/systems/accounts/types/TheAlteningAccount.java b/src/main/java/meteordevelopment/meteorclient/systems/accounts/types/TheAlteningAccount.java index 51f63bba3c..226a085dda 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/accounts/types/TheAlteningAccount.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/accounts/types/TheAlteningAccount.java @@ -18,6 +18,7 @@ import meteordevelopment.meteorclient.utils.misc.NbtException; import net.minecraft.client.session.Session; import net.minecraft.nbt.NbtCompound; +import org.jetbrains.annotations.Nullable; import java.util.Optional; @@ -27,6 +28,7 @@ public class TheAlteningAccount extends Account implements T private static final Environment ENVIRONMENT = new Environment("http://sessionserver.thealtening.com", "http://authserver.thealtening.com", "The Altening"); private static final YggdrasilAuthenticationService SERVICE = new YggdrasilAuthenticationService(((MinecraftClientAccessor) mc).getProxy(), ENVIRONMENT); private String token; + private @Nullable WaybackAuthLib auth; public TheAlteningAccount(String token) { super(AccountType.TheAltening, token); @@ -35,37 +37,33 @@ public TheAlteningAccount(String token) { @Override public boolean fetchInfo() { - WaybackAuthLib auth = getAuth(); + auth = getAuth(); try { auth.logIn(); cache.username = auth.getCurrentProfile().getName(); cache.uuid = auth.getCurrentProfile().getId().toString(); + cache.loadHead(); return true; + } catch (InvalidCredentialsException e) { + MeteorClient.LOG.error("Invalid TheAltening credentials."); + return false; } catch (Exception e) { + MeteorClient.LOG.error("Failed to fetch info for TheAltening account!"); return false; } } @Override public boolean login() { + if (auth == null) return false; applyLoginEnvironment(SERVICE, YggdrasilMinecraftSessionServiceAccessor.createYggdrasilMinecraftSessionService(SERVICE.getServicesKeySet(), SERVICE.getProxy(), ENVIRONMENT)); - WaybackAuthLib auth = getAuth(); - try { - auth.logIn(); setSession(new Session(auth.getCurrentProfile().getName(), auth.getCurrentProfile().getId(), auth.getAccessToken(), Optional.empty(), Optional.empty(), Session.AccountType.MOJANG)); - - cache.username = auth.getCurrentProfile().getName(); - cache.loadHead(); - return true; - } catch (InvalidCredentialsException e) { - MeteorClient.LOG.error("Invalid TheAltening credentials."); - return false; } catch (Exception e) { MeteorClient.LOG.error("Failed to login with TheAltening."); return false; diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/combat/AutoWeapon.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/combat/AutoWeapon.java index e1326e99b2..d925420966 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/combat/AutoWeapon.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/combat/AutoWeapon.java @@ -9,10 +9,10 @@ import meteordevelopment.meteorclient.settings.*; import meteordevelopment.meteorclient.systems.modules.Categories; import meteordevelopment.meteorclient.systems.modules.Module; -import meteordevelopment.meteorclient.utils.entity.EntityUtils; +import meteordevelopment.meteorclient.utils.entity.DamageUtils; import meteordevelopment.meteorclient.utils.player.InvUtils; import meteordevelopment.orbit.EventHandler; -import net.minecraft.entity.EntityType; +import net.minecraft.entity.LivingEntity; import net.minecraft.item.AxeItem; import net.minecraft.item.ItemStack; import net.minecraft.item.SwordItem; @@ -47,10 +47,12 @@ public AutoWeapon() { @EventHandler private void onAttack(AttackEntityEvent event) { - InvUtils.swap(getBestWeapon(EntityUtils.getGroup(event.entity)), false); + if (event.entity instanceof LivingEntity livingEntity) { + InvUtils.swap(getBestWeapon(livingEntity), false); + } } - private int getBestWeapon(EntityType group) { + private int getBestWeapon(LivingEntity target) { int slotS = mc.player.getInventory().selectedSlot; int slotA = mc.player.getInventory().selectedSlot; double damageS = 0; @@ -59,16 +61,16 @@ private int getBestWeapon(EntityType group) { double currentDamageA; for (int i = 0; i < 9; i++) { ItemStack stack = mc.player.getInventory().getStack(i); - if (stack.getItem() instanceof SwordItem swordItem + if (stack.getItem() instanceof SwordItem && (!antiBreak.get() || (stack.getMaxDamage() - stack.getDamage()) > 10)) { - currentDamageS = swordItem.getMaterial().getAttackDamage() /*fixme + EnchantmentHelper.getAttackDamage(stack, group)*/ + 2; + currentDamageS = DamageUtils.getAttackDamage(mc.player, target, stack); if (currentDamageS > damageS) { damageS = currentDamageS; slotS = i; } - } else if (stack.getItem() instanceof AxeItem axeItem + } else if (stack.getItem() instanceof AxeItem && (!antiBreak.get() || (stack.getMaxDamage() - stack.getDamage()) > 10)) { - currentDamageA = axeItem.getMaterial().getAttackDamage() /*fixme + EnchantmentHelper.getAttackDamage(stack, group)*/ + 2; + currentDamageA = DamageUtils.getAttackDamage(mc.player, target, stack); if (currentDamageA > damageA) { damageA = currentDamageA; slotA = i; diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/combat/BowAimbot.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/combat/BowAimbot.java index 5c586bba44..26c5104288 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/combat/BowAimbot.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/combat/BowAimbot.java @@ -24,6 +24,7 @@ import net.minecraft.entity.passive.AnimalEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ArrowItem; +import net.minecraft.item.BowItem; import net.minecraft.item.Items; import net.minecraft.util.math.Vec3d; @@ -130,23 +131,16 @@ private boolean itemInHand() { return InvUtils.testInMainHand(Items.BOW, Items.CROSSBOW); } - private void aim(double tickDelta) { + private void aim(float tickDelta) { // Velocity based on bow charge. - float velocity = (mc.player.getItemUseTime() - mc.player.getItemUseTimeLeft()) / 20f; - velocity = (velocity * velocity + velocity * 2) / 3; - if (velocity > 1) velocity = 1; + float velocity = BowItem.getPullProgress(mc.player.getItemUseTime()); // Positions - double posX = target.getPos().getX() + (target.getPos().getX() - target.prevX) * tickDelta; - double posY = target.getPos().getY() + (target.getPos().getY() - target.prevY) * tickDelta; - double posZ = target.getPos().getZ() + (target.getPos().getZ() - target.prevZ) * tickDelta; + Vec3d pos = target.getLerpedPos(tickDelta); - // Adjusting for hitbox heights - posY -= 1.9f - target.getHeight(); - - double relativeX = posX - mc.player.getX(); - double relativeY = posY - mc.player.getY(); - double relativeZ = posZ - mc.player.getZ(); + double relativeX = pos.x - mc.player.getX(); + double relativeY = pos.y + (target.getHeight() / 2) - mc.player.getEyeY(); + double relativeZ = pos.z - mc.player.getZ(); // Calculate the pitch double hDistance = Math.sqrt(relativeX * relativeX + relativeZ * relativeZ); @@ -159,7 +153,7 @@ private void aim(double tickDelta) { if (Float.isNaN(pitch)) { Rotations.rotate(Rotations.getYaw(target), Rotations.getPitch(target)); } else { - Rotations.rotate(Rotations.getYaw(new Vec3d(posX, posY, posZ)), pitch); + Rotations.rotate(Rotations.getYaw(new Vec3d(pos.x, pos.y, pos.z)), pitch); } } diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/combat/BowSpam.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/combat/BowSpam.java index 64b8fc3566..1b6e7b9cca 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/combat/BowSpam.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/combat/BowSpam.java @@ -67,7 +67,6 @@ private void onTick(TickEvent.Post event) { if (!isBow) return; if (mc.player.getItemUseTime() >= charge.get()) { - mc.player.stopUsingItem(); mc.interactionManager.stopUsingItem(mc.player); } else { setPressed(true); diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/player/PotionSpoof.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/player/PotionSpoof.java index a24a3271e5..95f92ca728 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/player/PotionSpoof.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/player/PotionSpoof.java @@ -50,6 +50,15 @@ public class PotionSpoof extends Module { .build() ); + private final Setting effectDuration = sgGeneral.add(new IntSetting.Builder() + .name("effect-duration") + .description("How many ticks to spoof the effect for.") + .range(1, 32767) + .sliderRange(20, 500) + .defaultValue(420) + .build() + ); + public PotionSpoof() { super(Categories.Player, "potion-spoof", "Spoofs potion statuses for you. SOME effects DO NOT work."); } @@ -73,9 +82,9 @@ private void onTick(TickEvent.Post event) { if (mc.player.hasStatusEffect(Registries.STATUS_EFFECT.getEntry(entry.getKey()))) { StatusEffectInstance instance = mc.player.getStatusEffect(Registries.STATUS_EFFECT.getEntry(entry.getKey())); ((StatusEffectInstanceAccessor) instance).setAmplifier(level - 1); - if (instance.getDuration() < 20) ((StatusEffectInstanceAccessor) instance).setDuration(20); + if (instance.getDuration() < effectDuration.get()) ((StatusEffectInstanceAccessor) instance).setDuration(effectDuration.get()); } else { - mc.player.addStatusEffect(new StatusEffectInstance(Registries.STATUS_EFFECT.getEntry(entry.getKey()), 20, level - 1)); + mc.player.addStatusEffect(new StatusEffectInstance(Registries.STATUS_EFFECT.getEntry(entry.getKey()), effectDuration.get(), level - 1)); } } } diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/render/Fullbright.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/render/Fullbright.java index d039356086..5a0fa0fa2b 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/render/Fullbright.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/render/Fullbright.java @@ -5,12 +5,18 @@ package meteordevelopment.meteorclient.systems.modules.render; +import meteordevelopment.meteorclient.events.world.TickEvent; +import meteordevelopment.meteorclient.mixin.StatusEffectInstanceAccessor; import meteordevelopment.meteorclient.settings.EnumSetting; import meteordevelopment.meteorclient.settings.IntSetting; import meteordevelopment.meteorclient.settings.Setting; import meteordevelopment.meteorclient.settings.SettingGroup; import meteordevelopment.meteorclient.systems.modules.Categories; import meteordevelopment.meteorclient.systems.modules.Module; +import meteordevelopment.orbit.EventHandler; +import net.minecraft.entity.effect.StatusEffectInstance; +import net.minecraft.entity.effect.StatusEffects; +import net.minecraft.registry.Registries; import net.minecraft.world.LightType; public class Fullbright extends Module { @@ -21,7 +27,10 @@ public class Fullbright extends Module { .description("The mode to use for Fullbright.") .defaultValue(Mode.Gamma) .onChanged(mode -> { - if (mc.worldRenderer != null && isActive()) mc.worldRenderer.reload(); + if (isActive()) { + if (mode != Mode.Potion) disableNightVision(); + if (mc.worldRenderer != null) mc.worldRenderer.reload(); + } }) .build() ); @@ -62,6 +71,7 @@ public void onActivate() { @Override public void onDeactivate() { if (mode.get() == Mode.Luminance) mc.worldRenderer.reload(); + else if (mode.get() == Mode.Potion) disableNightVision(); } public int getLuminance(LightType type) { @@ -73,8 +83,27 @@ public boolean getGamma() { return isActive() && mode.get() == Mode.Gamma; } + @EventHandler + private void onTick(TickEvent.Post event) { + if (mc.player == null || !mode.get().equals(Mode.Potion)) return; + if (mc.player.hasStatusEffect(Registries.STATUS_EFFECT.getEntry(StatusEffects.NIGHT_VISION.value()))) { + StatusEffectInstance instance = mc.player.getStatusEffect(Registries.STATUS_EFFECT.getEntry(StatusEffects.NIGHT_VISION.value())); + if (instance != null && instance.getDuration() < 420) ((StatusEffectInstanceAccessor) instance).setDuration(420); + } else { + mc.player.addStatusEffect(new StatusEffectInstance(Registries.STATUS_EFFECT.getEntry(StatusEffects.NIGHT_VISION.value()), 420, 0)); + } + } + + private void disableNightVision() { + if (mc.player == null) return; + if (mc.player.hasStatusEffect(Registries.STATUS_EFFECT.getEntry(StatusEffects.NIGHT_VISION.value()))) { + mc.player.removeStatusEffect(Registries.STATUS_EFFECT.getEntry(StatusEffects.NIGHT_VISION.value())); + } + } + public enum Mode { Gamma, + Potion, Luminance } } diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/render/Trajectories.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/render/Trajectories.java index 06df6370e4..f357b9df48 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/render/Trajectories.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/render/Trajectories.java @@ -167,7 +167,7 @@ private Path getEmptyPath() { return path; } - private void calculatePath(PlayerEntity player, double tickDelta) { + private void calculatePath(PlayerEntity player, float tickDelta) { // Clear paths for (Path path : paths) path.clear(); diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/render/WaypointsModule.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/render/WaypointsModule.java index 132754c0ef..752bc1dfa7 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/render/WaypointsModule.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/render/WaypointsModule.java @@ -107,7 +107,7 @@ private void onRender2D(Render2DEvent event) { // Continue if this waypoint should not be rendered if (dist > waypoint.maxVisible.get()) continue; - if (!NametagUtils.to2D(pos, 1)) continue; + if (!NametagUtils.to2D(pos, waypoint.scale.get() - 0.2)) continue; // Calculate alpha and distance to center of the screen double distToCenter = pos.distance(center); @@ -119,7 +119,6 @@ private void onRender2D(Render2DEvent event) { } // Render - NametagUtils.scale = waypoint.scale.get() - 0.2; NametagUtils.begin(pos); // Render icon @@ -129,7 +128,7 @@ private void onRender2D(Render2DEvent event) { if (distToCenter <= textRenderDist) { // Setup text rendering int preTextA = TEXT.a; - TEXT.a *= a; + TEXT.a *= (int) a; text.begin(); // Render name diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/render/Zoom.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/render/Zoom.java index 82453def96..ab96938886 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/render/Zoom.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/render/Zoom.java @@ -97,7 +97,7 @@ private void onTick(TickEvent.Post event) { mc.options.smoothCameraEnabled = cinematic.get(); if (!cinematic.get()) { - mc.options.getMouseSensitivity().setValue(preMouseSensitivity / Math.max(value() * 0.5, 1)); + mc.options.getMouseSensitivity().setValue(preMouseSensitivity / Math.max(getScaling() * 0.5, 1)); } if (time == 0) { @@ -133,13 +133,13 @@ private void onRender3D(Render3DEvent event) { @EventHandler private void onGetFov(GetFovEvent event) { - event.fov /= value(); + event.fov /= getScaling(); if (lastFov != event.fov) mc.worldRenderer.scheduleTerrainUpdate(); lastFov = event.fov; } - private double value() { + public double getScaling() { double delta = time < 0.5 ? 4 * time * time * time : 1 - Math.pow(-2 * time + 2, 3) / 2; // Ease in out cubic return MathHelper.lerp(delta, 1, value); } diff --git a/src/main/java/meteordevelopment/meteorclient/utils/entity/DamageUtils.java b/src/main/java/meteordevelopment/meteorclient/utils/entity/DamageUtils.java index cfe0ac6f4e..e81cc4310e 100644 --- a/src/main/java/meteordevelopment/meteorclient/utils/entity/DamageUtils.java +++ b/src/main/java/meteordevelopment/meteorclient/utils/entity/DamageUtils.java @@ -5,10 +5,17 @@ package meteordevelopment.meteorclient.utils.entity; +import it.unimi.dsi.fastutil.objects.Object2IntMap; +import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; +import meteordevelopment.meteorclient.utils.Utils; import meteordevelopment.meteorclient.utils.entity.fakeplayer.FakePlayerEntity; import meteordevelopment.meteorclient.utils.player.PlayerUtils; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; +import net.minecraft.component.DataComponentTypes; +import net.minecraft.component.type.AttributeModifiersComponent; +import net.minecraft.enchantment.Enchantment; +import net.minecraft.enchantment.Enchantments; import net.minecraft.entity.*; import net.minecraft.entity.attribute.*; import net.minecraft.entity.damage.DamageSource; @@ -16,6 +23,9 @@ import net.minecraft.entity.effect.StatusEffects; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.*; +import net.minecraft.registry.entry.RegistryEntry; +import net.minecraft.registry.tag.DamageTypeTags; +import net.minecraft.registry.tag.EntityTypeTags; import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.hit.HitResult; import net.minecraft.util.math.*; @@ -30,7 +40,6 @@ import static meteordevelopment.meteorclient.MeteorClient.mc; -@SuppressWarnings("JavadocReference") public class DamageUtils { private DamageUtils() { } @@ -137,27 +146,82 @@ public static float getAttackDamage(LivingEntity attacker, LivingEntity target) float itemDamage = (float) attacker.getAttributeValue(EntityAttributes.ATTACK_DAMAGE); DamageSource damageSource = attacker instanceof PlayerEntity player ? mc.world.getDamageSources().playerAttack(player) : mc.world.getDamageSources().mobAttack(attacker); + float damage = modifyAttackDamage(attacker, target, attacker.getWeaponStack(), damageSource, itemDamage); + return calculateReductions(damage, target, damageSource); + } + + public static float getAttackDamage(LivingEntity attacker, LivingEntity target, ItemStack weapon) { + EntityAttributeInstance original = attacker.getAttributeInstance(EntityAttributes.GENERIC_ATTACK_DAMAGE); + EntityAttributeInstance copy = new EntityAttributeInstance(EntityAttributes.GENERIC_ATTACK_DAMAGE, o -> {}); + + copy.setBaseValue(original.getBaseValue()); + for (EntityAttributeModifier modifier : original.getModifiers()) { + copy.addTemporaryModifier(modifier); + } + copy.removeModifier(Item.BASE_ATTACK_DAMAGE_MODIFIER_ID); + + AttributeModifiersComponent attributeModifiers = weapon.get(DataComponentTypes.ATTRIBUTE_MODIFIERS); + if (attributeModifiers != null) { + attributeModifiers.applyModifiers(EquipmentSlot.MAINHAND, (entry, modifier) -> { + if (entry == EntityAttributes.GENERIC_ATTACK_DAMAGE) copy.updateModifier(modifier); + }); + } + + float itemDamage = (float) copy.getValue(); + DamageSource damageSource = attacker instanceof PlayerEntity player ? mc.world.getDamageSources().playerAttack(player) : mc.world.getDamageSources().mobAttack(attacker); + + float damage = modifyAttackDamage(attacker, target, weapon, damageSource, itemDamage); + return calculateReductions(damage, target, damageSource); + } + + private static float modifyAttackDamage(LivingEntity attacker, LivingEntity target, ItemStack weapon, DamageSource damageSource, float damage) { // Get enchant damage - ItemStack stack = attacker.getWeaponStack(); - float enchantDamage = /*fixme EnchantmentHelper.getDamage(attacker.getWorld() instanceof ServerWorld serverWorld ? serverWorld : null, stack, target, damageSource, itemDamage) - itemDamage*/ 0; + Object2IntMap> enchantments = new Object2IntOpenHashMap<>(); + Utils.getEnchantments(weapon, enchantments); + float enchantDamage = 0f; + + int sharpness = Utils.getEnchantmentLevel(enchantments, Enchantments.SHARPNESS); + if (sharpness > 0) { + enchantDamage += 1 + 0.5f * (sharpness - 1); + } + + int baneOfArthropods = Utils.getEnchantmentLevel(enchantments, Enchantments.BANE_OF_ARTHROPODS); + if (baneOfArthropods > 0 && target.getType().isIn(EntityTypeTags.SENSITIVE_TO_BANE_OF_ARTHROPODS)) { + enchantDamage += 2.5f * baneOfArthropods; + } + + int impaling = Utils.getEnchantmentLevel(enchantments, Enchantments.IMPALING); + if (impaling > 0 && target.getType().isIn(EntityTypeTags.SENSITIVE_TO_IMPALING)) { + enchantDamage += 2.5f * impaling; + } + + int smite = Utils.getEnchantmentLevel(enchantments, Enchantments.SMITE); + if (smite > 0 && target.getType().isIn(EntityTypeTags.SENSITIVE_TO_SMITE)) { + enchantDamage += 2.5f * smite; + } // Factor charge if (attacker instanceof PlayerEntity playerEntity) { float charge = playerEntity.getAttackCooldownProgress(0.5f); - itemDamage *= 0.2f + charge * charge * 0.8f; + damage *= 0.2f + charge * charge * 0.8f; enchantDamage *= charge; + if (weapon.getItem() instanceof MaceItem item) { + float bonusDamage = item.getBonusAttackDamage(target, damage, damageSource); + if (bonusDamage > 0f) { + int density = Utils.getEnchantmentLevel(weapon, Enchantments.DENSITY); + if (density > 0) bonusDamage += 0.5f * attacker.fallDistance; + damage += bonusDamage; + } + } + // Factor critical hit if (charge > 0.9f && attacker.fallDistance > 0f && !attacker.isOnGround() && !attacker.isClimbing() && !attacker.isTouchingWater() && !attacker.hasStatusEffect(StatusEffects.BLINDNESS) && !attacker.hasVehicle()) { - itemDamage *= 1.5f; + damage *= 1.5f; } } - float damage = itemDamage + enchantDamage; - - damage = calculateReductions(damage, target, damageSource); - - return damage; + return damage + enchantDamage; } // Fall Damage @@ -221,8 +285,41 @@ private static float getArmor(LivingEntity entity) { * @see LivingEntity#modifyAppliedDamage(DamageSource, float) */ private static float protectionReduction(LivingEntity player, float damage, DamageSource source) { - //fixme float protLevel = EnchantmentHelper.getProtectionAmount(player.getWorld() instanceof ServerWorld serverWorld ? serverWorld : null, player, source); - return DamageUtil.getInflictedDamage(damage, /*protLevel*/ 0); + if (source.isIn(DamageTypeTags.BYPASSES_INVULNERABILITY)) return damage; + + int damageProtection = 0; + + for (ItemStack stack : player.getAllArmorItems()) { + Object2IntMap> enchantments = new Object2IntOpenHashMap<>(); + Utils.getEnchantments(stack, enchantments); + + int protection = Utils.getEnchantmentLevel(enchantments, Enchantments.PROTECTION); + if (protection > 0) { + damageProtection += protection; + } + + int fireProtection = Utils.getEnchantmentLevel(enchantments, Enchantments.FIRE_PROTECTION); + if (fireProtection > 0 && source.isIn(DamageTypeTags.IS_FIRE)) { + damageProtection += 2 * fireProtection; + } + + int blastProtection = Utils.getEnchantmentLevel(enchantments, Enchantments.BLAST_PROTECTION); + if (blastProtection > 0 && source.isIn(DamageTypeTags.IS_EXPLOSION)) { + damageProtection += 2 * blastProtection; + } + + int projectileProtection = Utils.getEnchantmentLevel(enchantments, Enchantments.PROJECTILE_PROTECTION); + if (projectileProtection > 0 && source.isIn(DamageTypeTags.IS_PROJECTILE)) { + damageProtection += 2 * projectileProtection; + } + + int featherFalling = Utils.getEnchantmentLevel(enchantments, Enchantments.FEATHER_FALLING); + if (featherFalling > 0 && source.isIn(DamageTypeTags.IS_FALL)) { + damageProtection += 3 * featherFalling; + } + } + + return DamageUtil.getInflictedDamage(damage, damageProtection); } /** diff --git a/src/main/java/meteordevelopment/meteorclient/utils/entity/ProjectileEntitySimulator.java b/src/main/java/meteordevelopment/meteorclient/utils/entity/ProjectileEntitySimulator.java index f62176cb3e..d112dedb71 100644 --- a/src/main/java/meteordevelopment/meteorclient/utils/entity/ProjectileEntitySimulator.java +++ b/src/main/java/meteordevelopment/meteorclient/utils/entity/ProjectileEntitySimulator.java @@ -10,6 +10,7 @@ import meteordevelopment.meteorclient.mixininterface.IVec3d; import meteordevelopment.meteorclient.utils.Utils; import meteordevelopment.meteorclient.utils.misc.MissHitResult; +import meteordevelopment.meteorclient.utils.player.Rotations; import net.minecraft.component.DataComponentTypes; import net.minecraft.component.type.ChargedProjectilesComponent; import net.minecraft.entity.Entity; @@ -44,7 +45,7 @@ public class ProjectileEntitySimulator { // held items - public boolean set(Entity user, ItemStack itemStack, double simulated, boolean accurate, double tickDelta) { + public boolean set(Entity user, ItemStack itemStack, double simulated, boolean accurate, float tickDelta) { Item item = itemStack.getItem(); switch (item) { @@ -82,11 +83,19 @@ public boolean set(Entity user, ItemStack itemStack, double simulated, boolean a return true; } - public void set(Entity user, double roll, double speed, double simulated, double gravity, double waterDrag, boolean accurate, double tickDelta, EntityType type) { + public void set(Entity user, double roll, double speed, double simulated, double gravity, double waterDrag, boolean accurate, float tickDelta, EntityType type) { Utils.set(pos, user, tickDelta).add(0, user.getEyeHeight(user.getPose()), 0); - double yaw = MathHelper.lerp(tickDelta, user.prevYaw, user.getYaw()); - double pitch = MathHelper.lerp(tickDelta, user.prevPitch, user.getPitch()); + double yaw; + double pitch; + + if (user == mc.player && Rotations.rotating) { + yaw = Rotations.serverYaw; + pitch = Rotations.serverPitch; + } else { + yaw = user.getYaw(tickDelta); + pitch = user.getPitch(tickDelta); + } double x, y, z; @@ -178,9 +187,17 @@ public void set(Entity entity, double gravity, double waterDrag, boolean accurat this.height = entity.getHeight(); } - public void setFishingBobber(Entity user, double tickDelta) { - double yaw = MathHelper.lerp(tickDelta, user.prevYaw, user.getYaw()); - double pitch = MathHelper.lerp(tickDelta, user.prevPitch, user.getPitch()); + public void setFishingBobber(Entity user, float tickDelta) { + double yaw; + double pitch; + + if (user == mc.player && Rotations.rotating) { + yaw = Rotations.serverYaw; + pitch = Rotations.serverPitch; + } else { + yaw = user.getYaw(tickDelta); + pitch = user.getPitch(tickDelta); + } double h = Math.cos(-yaw * 0.017453292F - 3.1415927F); double i = Math.sin(-yaw * 0.017453292F - 3.1415927F); diff --git a/src/main/java/meteordevelopment/meteorclient/utils/entity/SortPriority.java b/src/main/java/meteordevelopment/meteorclient/utils/entity/SortPriority.java index 835cc78652..5c1c272054 100644 --- a/src/main/java/meteordevelopment/meteorclient/utils/entity/SortPriority.java +++ b/src/main/java/meteordevelopment/meteorclient/utils/entity/SortPriority.java @@ -15,7 +15,7 @@ import static meteordevelopment.meteorclient.MeteorClient.mc; public enum SortPriority implements Comparator { - LowestDistance((e1, e2) -> Double.compare(PlayerUtils.squaredDistanceTo(e1), PlayerUtils.squaredDistanceTo(e2))), + LowestDistance(Comparator.comparingDouble(PlayerUtils::squaredDistanceTo)), HighestDistance((e1, e2) -> Double.compare(PlayerUtils.squaredDistanceTo(e2), PlayerUtils.squaredDistanceTo(e1))), LowestHealth(SortPriority::sortHealth), HighestHealth((e1, e2) -> sortHealth(e2, e1)), diff --git a/src/main/java/meteordevelopment/meteorclient/utils/render/NametagUtils.java b/src/main/java/meteordevelopment/meteorclient/utils/render/NametagUtils.java index 5c39aa3aa1..7ecaed2db5 100644 --- a/src/main/java/meteordevelopment/meteorclient/utils/render/NametagUtils.java +++ b/src/main/java/meteordevelopment/meteorclient/utils/render/NametagUtils.java @@ -6,6 +6,8 @@ package meteordevelopment.meteorclient.utils.render; import com.mojang.blaze3d.systems.RenderSystem; +import meteordevelopment.meteorclient.systems.modules.Modules; +import meteordevelopment.meteorclient.systems.modules.render.Zoom; import meteordevelopment.meteorclient.utils.Utils; import net.minecraft.client.gui.DrawContext; import net.minecraft.client.util.math.MatrixStack; @@ -52,7 +54,8 @@ public static boolean to2D(Vector3d pos, double scale, boolean distanceScaling) } public static boolean to2D(Vector3d pos, double scale, boolean distanceScaling, boolean allowBehind) { - NametagUtils.scale = scale; + Zoom zoom = Modules.get().get(Zoom.class); + NametagUtils.scale = scale * zoom.getScaling(); if (distanceScaling) { NametagUtils.scale *= getScale(pos); } diff --git a/src/main/java/meteordevelopment/meteorclient/utils/world/BlockUtils.java b/src/main/java/meteordevelopment/meteorclient/utils/world/BlockUtils.java index cf8534965f..8ba8023730 100644 --- a/src/main/java/meteordevelopment/meteorclient/utils/world/BlockUtils.java +++ b/src/main/java/meteordevelopment/meteorclient/utils/world/BlockUtils.java @@ -21,6 +21,7 @@ import net.minecraft.block.enums.BlockHalf; import net.minecraft.block.enums.SlabType; import net.minecraft.enchantment.Enchantments; +import net.minecraft.entity.attribute.EntityAttributes; import net.minecraft.entity.effect.StatusEffectUtil; import net.minecraft.entity.effect.StatusEffects; import net.minecraft.item.BlockItem; @@ -368,6 +369,9 @@ public static double getBreakDelta(int slot, BlockState state) { } } + /** + * @see net.minecraft.entity.player.PlayerEntity#getBlockBreakingSpeed(BlockState) + */ private static double getBlockBreakingSpeed(int slot, BlockState block) { double speed = mc.player.getInventory().main.get(slot).getMiningSpeedMultiplier(block); @@ -394,8 +398,8 @@ private static double getBlockBreakingSpeed(int slot, BlockState block) { speed *= k; } - if (mc.player.isSubmergedIn(FluidTags.WATER) /*fixme && !EnchantmentHelper.hasAquaAffinity(mc.player)*/) { - speed /= 5.0F; + if (mc.player.isSubmergedIn(FluidTags.WATER)) { + speed *= mc.player.getAttributeValue(EntityAttributes.PLAYER_SUBMERGED_MINING_SPEED); } if (!mc.player.isOnGround()) {