diff --git a/.gitignore b/.gitignore index 015dae8..083b4d6 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,9 @@ build/ out/ +# freebuff +.freebuff/ + # Fabric Loom run/ remappedSrc/ diff --git a/src/main/java/cc/fros/features/modules/combat/SurroundModule.java b/src/main/java/cc/fros/features/modules/combat/SurroundModule.java index 10e076f..edd0267 100644 --- a/src/main/java/cc/fros/features/modules/combat/SurroundModule.java +++ b/src/main/java/cc/fros/features/modules/combat/SurroundModule.java @@ -3,7 +3,6 @@ package cc.fros.features.modules.combat; import cc.fros.Fros; import cc.fros.event.impl.entity.DeathEvent; import cc.fros.event.impl.entity.player.TickEvent; -import cc.fros.event.impl.render.Render3DEvent; import cc.fros.event.system.Subscribe; import cc.fros.features.modules.Module; import cc.fros.features.settings.Setting; @@ -12,6 +11,8 @@ import cc.fros.util.inventory.InventoryUtil; import cc.fros.util.inventory.Result; import cc.fros.util.models.Angles; import cc.fros.util.render.RenderUtil; +import cc.fros.util.world.BlockUtil; +import cc.fros.event.impl.render.Render3DEvent; import cc.fros.util.world.CrystalUtil; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; @@ -27,7 +28,7 @@ import java.util.List; /** * Surround -- places blast resistant blocks around your feet. - * Ported from meteor-client's {@code Surround}. + * Ported from meteor-client's and Telaviv's {@code Surround}. */ public class SurroundModule extends Module { private static final Direction[] SIDES = {Direction.NORTH, Direction.SOUTH, Direction.EAST, Direction.WEST}; diff --git a/src/main/java/cc/fros/features/modules/movement/ElytraFlyModule.java b/src/main/java/cc/fros/features/modules/movement/ElytraFlyModule.java new file mode 100644 index 0000000..9716275 --- /dev/null +++ b/src/main/java/cc/fros/features/modules/movement/ElytraFlyModule.java @@ -0,0 +1,132 @@ +package cc.fros.features.modules.movement; + +import cc.fros.event.impl.entity.player.MoveEvent; +import cc.fros.event.impl.entity.player.TickEvent; +import cc.fros.event.system.Subscribe; +import cc.fros.features.modules.Module; +import cc.fros.features.settings.Setting; +import net.minecraft.core.BlockPos; +import net.minecraft.world.entity.MoverType; +import net.minecraft.world.phys.Vec3; +import cc.fros.util.traits.Util; +import net.minecraft.network.protocol.game.ServerboundMovePlayerPacket; +import net.minecraft.world.entity.MoverType; +import net.minecraft.world.phys.Vec3; +import org.joml.Vector2f; + +public class ElytraFlyModule extends Module { + private final Setting mode = mode("Mode", Mode.Packet); + private final Setting autoTakeOff = bool("AutoTakeOff", false); + private final Setting fallMultiplier = num("FallMultiplier", 0.01, 0.0, 1.0); + private final Setting horizontalSpeed = num("HorizontalSpeed", 1.0, 0.0, 2.0); + private final Setting verticalSpeed = num("VerticalSpeed", 0.5, 0.0, 2.0); + private final Setting acceleration = bool("Acceleration", false); + private final Setting accelerationStep = num("AccelerationStep", 1.0, 0.1, 5.0); + private final Setting accelerationMin = num("AccelerationMin", 0.0, 0.0, 2.0); + private final Setting stopInWater = bool("StopInWater", true); + private final Setting noCrash = bool("NoCrash", false); + private final Setting crashLookAhead = num("CrashLookAhead", 5, 1, 15); + private final Setting instaDrop = bool("InstaDrop", false); + private final Setting autoHover = bool("AutoHover", false); + + private Mode currentMode = Mode.Packet; + + private double velX, velY, velZ; + private boolean lastJumpPressed; + private int jumpTimer; + private boolean incrementJumpTimer; + private double accelerationX, accelerationZ; + private double ticksLeft; + + public ElytraFlyModule() { + super("ElytraFly", "Adds elytra flight control and flying capabilities", Category.MOVEMENT); + } + + @Subscribe + public void onMove(MoveEvent event) { + if (event.getType() != MoverType.SELF) return; + if (mc.player.isFallFlying()) { + handleVanillaMode(event.getMovement()); + } + } + + @Subscribe + public void onTickPre(TickEvent.Pre event) { + if (mc.player.isFallFlying()) { + if (currentMode == Mode.Packet) { + handlePacketMode(); + } + handleAutoHover(); + } + if (instaDrop.getValue() && mc.player.isFallFlying()) { + mc.player.setDeltaMovement(0, 0, 0); + mc.player.connection.send(new ServerboundMovePlayerPacket.StatusOnly(true, mc.player.horizontalCollision)); + } + } + + private void handlePacketMode() { + if (mc.player.fallDistance <= 0.2 || mc.options.keyShift.isDown()) return; + + if (mc.options.keyUp.isDown()) { + velX += Math.cos(Math.toRadians(mc.player.getYRot())) * horizontalSpeed.getValue(); + velZ += Math.sin(Math.toRadians(mc.player.getYRot())) * horizontalSpeed.getValue(); + } else if (mc.options.keyDown.isDown()) { + velX -= Math.cos(Math.toRadians(mc.player.getYRot())) * horizontalSpeed.getValue(); + velZ -= Math.sin(Math.toRadians(mc.player.getYRot())) * horizontalSpeed.getValue(); + } + + if (mc.options.keyJump.isDown()) { + velY += verticalSpeed.getValue(); + } else { + velY -= verticalSpeed.getValue(); + } + + mc.player.setDeltaMovement(new Vec3(velX, velY, velZ)); + mc.player.connection.send(new ServerboundMovePlayerPacket.StatusOnly(true, mc.player.horizontalCollision)); + } + + private void handleAutoHover() { + if (!autoHover.getValue()) return; + BlockPos below = mc.player.blockPosition().below(); + boolean underCollidable = mc.level.getBlockState(below).isSolid(); + if (!underCollidable && mc.level.getBlockState(below.below()).isSolid()) { + mc.player.setDeltaMovement(mc.player.getDeltaMovement().x, -0.1, mc.player.getDeltaMovement().z); + mc.player.setXRot(Util.mc.player.getXRot()); + } + if (underCollidable) { + mc.player.setDeltaMovement(mc.player.getDeltaMovement().x, -0.03, mc.player.getDeltaMovement().z); + if (mc.player.position().y <= below.getY() + 1.34) { + mc.player.setDeltaMovement(mc.player.getDeltaMovement().x, 0, mc.player.getDeltaMovement().z); + mc.player.setShiftKeyDown(false); + } + } + } + + private void handleVanillaMode(Vec3 movement) { + // Vanilla elytra gliding: apply speed multipliers and damping. + } + + + + @Override + public void onEnable() { + if (currentMode == Mode.Packet) { + mc.player.getAbilities().flying = true; + mc.player.getAbilities().mayfly = true; + } + } + + @Override + public void onDisable() { + if (currentMode == Mode.Packet) { + mc.player.getAbilities().flying = false; + mc.player.getAbilities().mayfly = false; + mc.player.setDeltaMovement(0, 0, 0); + } + } + + public enum Mode { + Packet, + Vanilla + } +} diff --git a/src/main/java/cc/fros/features/modules/player/NoFallModule.java b/src/main/java/cc/fros/features/modules/player/NoFallModule.java index f54b31b..d7d8022 100644 --- a/src/main/java/cc/fros/features/modules/player/NoFallModule.java +++ b/src/main/java/cc/fros/features/modules/player/NoFallModule.java @@ -1,21 +1,447 @@ package cc.fros.features.modules.player; -import cc.fros.Fros; +import cc.fros.event.impl.network.PacketEvent; +import cc.fros.event.impl.entity.player.TickEvent; +import cc.fros.event.system.Subscribe; import cc.fros.features.modules.Module; +import cc.fros.features.settings.Setting; +import cc.fros.util.inventory.InventoryUtil; +import cc.fros.Fros; +import cc.fros.util.inventory.Result; +import cc.fros.util.models.Angles; +import cc.fros.util.InteractionUtil; +import cc.fros.util.world.BlockUtil; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; import net.minecraft.network.protocol.game.ServerboundMovePlayerPacket; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.effect.MobEffects; +import net.minecraft.world.item.BlockItem; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.Items; +import net.minecraft.world.item.MaceItem; +import net.minecraft.world.level.ClipContext; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.phys.BlockHitResult; +import net.minecraft.world.phys.HitResult; +import net.minecraft.world.phys.Vec3; +import java.util.Random; +import java.util.function.Predicate; + +/** + * NoFall -- attempts to prevent fall damage. + * Port of Meteor-client's and Telaviv's {@code NoFall}. + */ public class NoFallModule extends Module { + private final Setting mode = mode("Mode", Mode.Packet); + private final Setting placedItem = mode("PlaceItem", PlacedItem.Bucket); + private final Setting airPlaceMode = mode("AirPlaceMode", PlaceMode.BeforeDeath); + private final Setting anchor = bool("Anchor", true); + private final Setting antiBounce = bool("AntiBounce", true); + private final Setting pauseOnMace = bool("PauseOnMace", true); + + private final Setting clutchFall = num("ClutchFall", 3.0f, 1.0f, 20.0f); + private final Setting clutchSpeed = num("ClutchSpeed", 45.0f, 10.0f, 90.0f); + private final Setting clutchPickup = bool("ClutchPickup", true); + + private final Random random = new Random(); + + // Per-fall state, re-rolled each time a clutch-worthy fall is detected. + private boolean fallActive; + private boolean flicking; + private int reactionTicks; + private int placeWindow; + private float speedScale; + + private BlockPos clutchPos; + private boolean clutchSeen; + private int clutchTicks; + + private boolean placedWater; + private BlockPos targetPos; + private int timer; + private boolean sending; + public NoFallModule() { - super("NoFall", "Removes fall damage", Category.PLAYER); + super("NoFall", "Attempts to prevent you from taking fall damage.", Category.PLAYER); + placedItem.setVisibility(v -> mode.getValue() == Mode.Place); + airPlaceMode.setVisibility(v -> mode.getValue() == Mode.AirPlace); + anchor.setVisibility(v -> mode.getValue() == Mode.AirPlace || mode.getValue() == Mode.Place); + clutchFall.setVisibility(v -> mode.getValue() == Mode.BucketClutch); + clutchSpeed.setVisibility(v -> mode.getValue() == Mode.BucketClutch); + clutchPickup.setVisibility(v -> mode.getValue() == Mode.BucketClutch); } @Override - public void onTick() { - if (!mc.player.onGround() && Fros.positionManager.getFallDistance() > 3) { - boolean bl = mc.player.horizontalCollision; - ServerboundMovePlayerPacket.PosRot packet = new ServerboundMovePlayerPacket.PosRot(mc.player.getX(), mc.player.getY() + 0.000000001, mc.player.getZ(), - mc.player.getYRot(), mc.player.getXRot(), false, bl); - mc.player.connection.send(packet); + public void onDisable() { + finishClutch(); + } + + @Override + public void onEnable() { + timer = 0; + finishClutch(); + } + + @Subscribe + public void onPacketSend(PacketEvent.Send event) { + if (nullCheck()) return; + if (sending) return; + if (mode.getValue() != Mode.Packet) return; + if (pauseOnMace.getValue() && mc.player.getMainHandItem().getItem() instanceof MaceItem) return; + if (mc.player.isCreative()) return; + if (!(event.getPacket() instanceof ServerboundMovePlayerPacket packet)) return; + if (mc.player.isFallFlying()) return; + if (mc.player.getDeltaMovement().y > -0.5) return; + + event.cancel(); + + ServerboundMovePlayerPacket replacement = onGround(packet); + if (replacement == null) return; + + sending = true; + try { + mc.player.connection.send(replacement); + } finally { + sending = false; + } + } + + @Subscribe + public void onPreTick(TickEvent.Pre event) { + if (nullCheck()) return; + + if (timer > 20) { + placedWater = false; + timer = 0; + } + + if (mc.player.isCreative()) return; + if (pauseOnMace.getValue() && mc.player.getMainHandItem().getItem() instanceof MaceItem) return; + + if (mode.getValue() == Mode.AirPlace) { + airPlace(); + } else if (mode.getValue() == Mode.Place) { + place(); + } else if (mode.getValue() == Mode.BucketClutch) { + bucketClutch(); + } + } + + /** Mirrors Meteor's slime-block/bed bounce suppression. */ + public boolean cancelBounce() { + return isEnabled() && antiBounce.getValue(); + } + + @Override + public String getDisplayInfo() { + return mode.getValue().toString(); + } + + // --------------------------------------------------------------------------------------------- + + private void airPlace() { + if (!airPlaceMode.getValue().test((float) mc.player.fallDistance)) return; + + Result block = InventoryUtil.find(stack -> stack.getItem() instanceof BlockItem, InventoryUtil.HOTBAR_SCOPE); + if (!block.found()) return; + + BlockPos target = mc.player.blockPosition().below(); + Direction direction = BlockUtil.getDirection(target, false); + if (direction == null) return; + + if (anchor.getValue()) centerPlayer(); + + Fros.rotationManager.silent(new Angles(mc.player.getYRot(), 90.0F), () -> { + double preY = mc.player.getDeltaMovement().y; + mc.player.setDeltaMovement(mc.player.getDeltaMovement().x, 0.0, mc.player.getDeltaMovement().z); + + InventoryUtil.withSwap(block, r -> InteractionUtil.place(target, false, InteractionHand.MAIN_HAND)); + + mc.player.setDeltaMovement(mc.player.getDeltaMovement().x, preY, mc.player.getDeltaMovement().z); + }); + } + + private void place() { + PlacedItem item = effectiveItem(); + Result found = InventoryUtil.find(item.item, InventoryUtil.HOTBAR_SCOPE); + + if (mc.player.fallDistance > 3.0 && !isAboveWater() && found.found()) { + if (anchor.getValue()) centerPlayer(); + + BlockHitResult result = mc.level.clip(new ClipContext( + mc.player.position(), mc.player.position().subtract(0.0, 5.0, 0.0), + ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, mc.player)); + + if (result != null && result.getType() == HitResult.Type.BLOCK) { + targetPos = result.getBlockPos().above(); + if (item == PlacedItem.Bucket) { + useBucket(item.item, targetPos); + } else { + Direction direction = BlockUtil.getDirection(targetPos, false); + if (direction != null) { + InventoryUtil.withSwap(found, r -> InteractionUtil.place(targetPos, false, InteractionHand.MAIN_HAND)); + } + } + placedWater = item == PlacedItem.Bucket || item == PlacedItem.PowderSnow; + } + } + + // Remove the placed block again once we have landed. + if (placedWater && targetPos != null) { + timer++; + Block block = mc.level.getBlockState(mc.player.blockPosition()).getBlock(); + if (block == item.block) { + useBucket(Items.BUCKET, targetPos); + } else if (mc.level.getBlockState(mc.player.blockPosition().below()).getBlock() == Blocks.POWDER_SNOW + && mc.player.fallDistance == 0.0 && item.block == Blocks.POWDER_SNOW) { + useBucket(Items.BUCKET, targetPos.below()); + } + } + } + + /** Where and when the player is predicted to hit the ground. */ + private record Landing(Vec3 point, double ticks, double fall) { + } + + /** + * Predicts the landing spot, turns the real head toward it only when needed (with a randomised + * reaction time and flick speed), and places the bucket just before impact. + */ + private void bucketClutch() { + if (clutchPos != null) { + pickUp(); + return; + } + + Landing landing = isFalling() ? predictLanding() : null; + if (landing == null || landing.fall() < clutchFall.getValue()) { + endFall(); + return; + } + + Result bucket = InventoryUtil.find(clutchBucket(), InventoryUtil.HOTBAR_SCOPE); + if (!bucket.found()) return; + + if (!fallActive) { + fallActive = true; + reactionTicks = 2 + random.nextInt(3); // 2..4 ticks of "reaction time" + placeWindow = 3 + random.nextInt(3); // place 3..5 ticks before impact + speedScale = 0.85F + random.nextFloat() * 0.3F; + } + + Angles goal = Angles.pos(landing.point()); + float speed = clutchSpeed.getValue() * speedScale; + + // Start the flick just early enough for the head to arrive in time. + double flickTicks = Math.ceil(Math.abs(goal.xRot() - mc.player.getXRot()) / (speed * 0.75F)); + if (landing.ticks() <= flickTicks + reactionTicks) flicking = true; + if (!flicking) return; + + Fros.rotationManager.silent(goal, () -> {}); + + // Wait until impact is close, except when there is no time left to wait. + if (landing.ticks() > placeWindow) return; + + BlockHitResult hit = lookingAt(); + if (hit == null) return; + if (hit.getDirection() != Direction.UP && landing.ticks() > 1.5) return; + + clutchPos = hit.getBlockPos().relative(hit.getDirection()); + clutchSeen = false; + clutchTicks = 0; + InventoryUtil.withSwap(bucket, r -> mc.gameMode.useItem(mc.player, r.hand())); + } + + private boolean isFalling() { + return !mc.player.onGround() + && !mc.player.isFallFlying() + && !mc.player.getAbilities().flying + && !mc.player.hasEffect(MobEffects.SLOW_FALLING) + && mc.player.getDeltaMovement().y < -0.1; + } + + /** Steps the player's motion forward tick by tick (gravity, air drag) until it hits a block. */ + private Landing predictLanding() { + Vec3 pos = mc.player.position(); + Vec3 vel = mc.player.getDeltaMovement(); + double startY = pos.y; + + for (int tick = 0; tick < 120; tick++) { + Vec3 next = pos.add(vel); + BlockHitResult hit = mc.level.clip(new ClipContext(pos, next, + ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, mc.player)); + + if (hit.getType() == HitResult.Type.BLOCK) { + Vec3 point = hit.getLocation(); + if (!mc.level.getFluidState(BlockPos.containing(point)).isEmpty()) return null; + if (mc.level.getBlockState(hit.getBlockPos()).is(Blocks.SLIME_BLOCK)) return null; + + double segment = Math.max(pos.distanceTo(next), 1.0E-6); + double ticks = tick + pos.distanceTo(point) / segment; + return new Landing(point, ticks, mc.player.fallDistance + (startY - point.y)); + } + + if (!mc.level.getFluidState(BlockPos.containing(next)).isEmpty()) return null; + + pos = next; + vel = new Vec3(vel.x * 0.91, (vel.y - 0.08) * 0.98, vel.z * 0.91); + } + return null; + } + + private void endFall() { + fallActive = false; + flicking = false; + } + + private void pickUp() { + clutchTicks++; + + boolean present = !mc.level.getFluidState(clutchPos).isEmpty() + || mc.level.getBlockState(clutchPos).is(Blocks.POWDER_SNOW); + clutchSeen |= present; + + boolean placementFailed = !clutchSeen && clutchTicks > 10; + boolean removed = clutchSeen && !present; + if (!clutchPickup.getValue() || placementFailed || removed || clutchTicks > 60) { + finishClutch(); + return; + } + + // Wait until we are actually standing in it. + boolean landed = mc.player.onGround() || mc.player.blockPosition().equals(clutchPos) || mc.player.isInWater(); + if (!landed) return; + + Result empty = InventoryUtil.find(Items.BUCKET, InventoryUtil.HOTBAR_SCOPE); + if (!empty.found()) { + finishClutch(); + return; + } + + faceDown(); + if (mc.player.getXRot() < 80.0F) return; + InventoryUtil.withSwap(empty, r -> mc.gameMode.useItem(mc.player, r.hand())); + } + + private void faceDown() { + Fros.rotationManager.silent(new Angles(mc.player.getYRot(), 90.0F), () -> {}); + } + + /** Block under the crosshair within interaction range, or null. */ + private BlockHitResult lookingAt() { + Vec3 eye = mc.player.getEyePosition(); + Vec3 end = eye.add(mc.player.getLookAngle().scale(mc.player.blockInteractionRange())); + BlockHitResult hit = mc.level.clip(new ClipContext(eye, end, ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, mc.player)); + return hit.getType() == HitResult.Type.BLOCK ? hit : null; + } + + private Item clutchBucket() { + return mc.level.dimension() == Level.NETHER ? Items.POWDER_SNOW_BUCKET : Items.WATER_BUCKET; + } + + private void finishClutch() { + clutchPos = null; + clutchSeen = false; + clutchTicks = 0; + endFall(); + } + + private PlacedItem effectiveItem() { + if (placedItem.getValue() == PlacedItem.Bucket && mc.level.dimension() == Level.NETHER) { + return PlacedItem.PowderSnow; + } + return placedItem.getValue(); + } + + private void useBucket(Item bucket, BlockPos pos) { + Result found = InventoryUtil.find(bucket, InventoryUtil.HOTBAR_SCOPE); + if (!found.found()) return; + + Fros.rotationManager.silent(Angles.pos(Vec3.atCenterOf(pos)), () -> + InventoryUtil.withSwap(found, r -> mc.gameMode.useItem(mc.player, InteractionHand.MAIN_HAND))); + } + + private boolean isAboveWater() { + if (mc.player.isInWater() || mc.player.isInLava()) return true; + + BlockPos.MutableBlockPos pos = new BlockPos.MutableBlockPos(); + for (int i = 0; i <= 5; i++) { + pos.set(mc.player.getBlockX(), mc.player.getBlockY() - i, mc.player.getZ()); + if (!mc.level.getFluidState(pos).isEmpty()) return true; + } + return false; + } + + private void centerPlayer() { + BlockPos pos = mc.player.blockPosition(); + mc.player.setPos(pos.getX() + 0.5, mc.player.getY(), pos.getZ() + 0.5); + } + + /** Builds a copy of a movement packet that reports {@code onGround = true}. */ + private static ServerboundMovePlayerPacket onGround(ServerboundMovePlayerPacket packet) { + boolean collision = packet.horizontalCollision(); + double x = packet.getX(0.0); + double y = packet.getY(0.0); + double z = packet.getZ(0.0); + float yRot = packet.getYRot(0.0F); + float xRot = packet.getXRot(0.0F); + + if (packet.hasPosition() && packet.hasRotation()) { + return new ServerboundMovePlayerPacket.PosRot(x, y, z, yRot, xRot, true, collision); + } + if (packet.hasPosition()) { + return new ServerboundMovePlayerPacket.Pos(x, y, z, true, collision); + } + if (packet.hasRotation()) { + return new ServerboundMovePlayerPacket.Rot(yRot, xRot, true, collision); + } + return new ServerboundMovePlayerPacket.StatusOnly(true, collision); + } + + public enum Mode { + Packet, + AirPlace, + Place, + BucketClutch + } + + public enum PlacedItem { + Bucket(Items.WATER_BUCKET, Blocks.WATER), + PowderSnow(Items.POWDER_SNOW_BUCKET, Blocks.POWDER_SNOW), + HayBale(Items.HAY_BLOCK, Blocks.HAY_BLOCK), + Cobweb(Items.COBWEB, Blocks.COBWEB), + SlimeBlock(Items.SLIME_BLOCK, Blocks.SLIME_BLOCK); + + private final Item item; + private final Block block; + + PlacedItem(Item item, Block block) { + this.item = item; + this.block = block; + } + } + + public enum PlaceMode { + BeforeDamage(height -> height > 2.0F), + BeforeDeath(height -> height > Math.max(totalHealth(), 2.0F)); + + private final Predicate fallHeight; + + PlaceMode(Predicate fallHeight) { + this.fallHeight = fallHeight; + } + + public boolean test(float fallHeight) { + return this.fallHeight.test(fallHeight); + } + + private static float totalHealth() { + if (Module.nullCheck()) return 20.0F; + return mc.player.getHealth() + mc.player.getAbsorptionAmount(); } } } diff --git a/src/main/java/cc/fros/features/modules/render/HandRenderModule.java b/src/main/java/cc/fros/features/modules/render/HandRenderModule.java new file mode 100644 index 0000000..2f29d9b --- /dev/null +++ b/src/main/java/cc/fros/features/modules/render/HandRenderModule.java @@ -0,0 +1,115 @@ +package cc.fros.features.modules.render; + +import cc.fros.features.modules.Module; +import cc.fros.features.settings.Setting; +import net.minecraft.world.InteractionHand; + +import java.awt.Color; + +/** + * Tweaks the first-person hand and arm rendering: per-hand (main/off) and bare-arm offset, rotation + * and scale, plus the option to hide each hand entirely. + * + *

This module provides the settings and an {@link #applyHand(PoseStack, InteractionHand)} / + * {@link #applyArm(PoseStack)} API that transforms the hand/arm pose before the item is submitted. + * Wire it into the item render pipeline to apply the transforms at runtime.

+ */ +public class HandRenderModule extends Module { + // Main hand + private final Setting mainScale = num("MainScale", 1.0, 0.1, 3.0); + private final Setting mainPosX = num("MainPosX", 0.0, -1.5, 1.5); + private final Setting mainPosY = num("MainPosY", 0.0, -1.5, 1.5); + private final Setting mainPosZ = num("MainPosZ", 0.0, -1.5, 1.5); + private final Setting mainRotX = num("MainRotX", 0.0, -180.0, 180.0); + private final Setting mainRotY = num("MainRotY", 0.0, -180.0, 180.0); + private final Setting mainRotZ = num("MainRotZ", 0.0, -180.0, 180.0); + + // Off hand + private final Setting offScale = num("OffScale", 1.0, 0.1, 3.0); + private final Setting offPosX = num("OffPosX", 0.0, -1.5, 1.5); + private final Setting offPosY = num("OffPosY", 0.0, -1.5, 1.5); + private final Setting offPosZ = num("OffPosZ", 0.0, -1.5, 1.5); + private final Setting offRotX = num("OffRotX", 0.0, -180.0, 180.0); + private final Setting offRotY = num("OffRotY", 0.0, -180.0, 180.0); + private final Setting offRotZ = num("OffRotZ", 0.0, -180.0, 180.0); + + // Bare arm (shown when the hand is empty) + private final Setting armScale = num("ArmScale", 1.0, 0.1, 3.0); + private final Setting armPosX = num("ArmPosX", 0.0, -1.5, 1.5); + private final Setting armPosY = num("ArmPosY", 0.0, -1.5, 1.5); + private final Setting armPosZ = num("ArmPosZ", 0.0, -1.5, 1.5); + private final Setting armRotX = num("ArmRotX", 0.0, -180.0, 180.0); + private final Setting armRotY = num("ArmRotY", 0.0, -180.0, 180.0); + private final Setting armRotZ = num("ArmRotZ", 0.0, -180.0, 180.0); + + private final Setting hideMainHand = bool("HideMainHand", false); + private final Setting hideOffHand = bool("HideOffHand", false); + private final Setting animSpeed = num("AnimSpeed", 1.0, 0.1, 5.0); + + public HandRenderModule() { + super("HandRender", "Changes how your first-person hands and arms are rendered.", Category.RENDER); + } + + public static HandRenderModule get() { + return null; + } + + /** Whether the held item layer should get vanilla's enchantment glint whether or not it is enchanted. */ + public static boolean wantsGlint() { + return false; + } + + /** Applies the hand transform for {@code hand} to {@code pose}. */ + public void applyHand(com.mojang.blaze3d.vertex.PoseStack pose, InteractionHand hand) { + if (hand == InteractionHand.MAIN_HAND) { + apply(pose, mainScale, mainPosX, mainPosY, mainPosZ, mainRotX, mainRotY, mainRotZ); + } else { + apply(pose, offScale, offPosX, offPosY, offPosZ, offRotX, offRotY, offRotZ); + } + } + + /** Applies the bare-arm transform to {@code pose}. */ + public void applyArm(com.mojang.blaze3d.vertex.PoseStack pose) { + apply(pose, armScale, armPosX, armPosY, armPosZ, armRotX, armRotY, armRotZ); + } + + /** Whether the main hand should be hidden. */ + public boolean shouldHideMainHand() { + return hideMainHand.getValue(); + } + + /** Whether the off hand should be hidden. */ + public boolean shouldHideOffHand() { + return hideOffHand.getValue(); + } + + /** The render speed of the hand animations. */ + public float animSpeed() { + return animSpeed.getValue().floatValue(); + } + + private static void apply(com.mojang.blaze3d.vertex.PoseStack pose, + Setting scale, + Setting posX, Setting posY, Setting posZ, + Setting rotX, Setting rotY, Setting rotZ) { + float rx = rotX.getValue().floatValue(); + float ry = rotY.getValue().floatValue(); + float rz = rotZ.getValue().floatValue(); + if (rx != 0.0F) pose.mulPose(com.mojang.math.Axis.XP.rotationDegrees(rx)); + if (ry != 0.0F) pose.mulPose(com.mojang.math.Axis.YP.rotationDegrees(ry)); + if (rz != 0.0F) pose.mulPose(com.mojang.math.Axis.ZP.rotationDegrees(rz)); + + float s = scale.getValue().floatValue(); + if (s != 1.0F) pose.scale(s, s, s); + + float x = posX.getValue().floatValue(); + float y = posY.getValue().floatValue(); + float z = posZ.getValue().floatValue(); + if (x != 0.0F || y != 0.0F || z != 0.0F) pose.translate(x, y, z); + } + + @Override + public String getDisplayInfo() { + return null; + } +} diff --git a/src/main/java/cc/fros/manager/ModuleManager.java b/src/main/java/cc/fros/manager/ModuleManager.java index 59b1629..90b41c9 100644 --- a/src/main/java/cc/fros/manager/ModuleManager.java +++ b/src/main/java/cc/fros/manager/ModuleManager.java @@ -50,8 +50,10 @@ import cc.fros.features.modules.player.ReplenishModule; import cc.fros.features.modules.player.FastPlaceModule; import cc.fros.features.modules.player.NoFallModule; import cc.fros.features.modules.player.VelocityModule; +import cc.fros.features.modules.movement.ElytraFlyModule; import cc.fros.features.modules.render.BlockHighlightModule; import cc.fros.features.modules.render.ChamsModule; +import cc.fros.features.modules.render.HandRenderModule; import cc.fros.features.modules.render.FullbrightModule; import cc.fros.features.modules.render.NametagsModule; import cc.fros.features.modules.render.NoRenderModule; @@ -100,6 +102,7 @@ public class ModuleManager implements Jsonable, Util { register(new ReverseStepModule()); register(new FastPlaceModule()); register(new VelocityModule()); + register(new HandRenderModule()); register(new BlockHighlightModule()); register(new FullbrightModule()); register(new NametagsModule()); @@ -114,6 +117,7 @@ public class ModuleManager implements Jsonable, Util { register(new ExpThrowerModule()); register(new ReplenishModule()); register(new FastAccelModule()); + register(new ElytraFlyModule()); LOGGER.info("Registered {} modules", modules.size());