elytrafly
This commit is contained in:
@@ -6,127 +6,161 @@ 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.EquipmentSlot;
|
||||
import net.minecraft.world.entity.MoverType;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Items;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import org.joml.Vector2f;
|
||||
|
||||
/**
|
||||
* ElytraFly -- gives more control over elytra flight.
|
||||
* Ported from Telaviv's {@code ElytraFlyModule} (Vanilla + Packet modes).
|
||||
*/
|
||||
public class ElytraFlyModule extends Module {
|
||||
private final Setting<Mode> mode = mode("Mode", Mode.Packet);
|
||||
private final Setting<Mode> mode = mode("Mode", Mode.Vanilla);
|
||||
private final Setting<Boolean> autoTakeOff = bool("AutoTakeOff", false);
|
||||
private final Setting<Double> fallMultiplier = num("FallMultiplier", 0.01, 0.0, 1.0);
|
||||
private final Setting<Double> horizontalSpeed = num("HorizontalSpeed", 1.0, 0.0, 2.0);
|
||||
private final Setting<Double> verticalSpeed = num("VerticalSpeed", 0.5, 0.0, 2.0);
|
||||
private final Setting<Boolean> acceleration = bool("Acceleration", false);
|
||||
private final Setting<Double> accelerationStep = num("AccelerationStep", 1.0, 0.1, 5.0);
|
||||
private final Setting<Double> accelerationMin = num("AccelerationMin", 0.0, 0.0, 2.0);
|
||||
private final Setting<Double> horizontalSpeed = num("HorizontalSpeed", 1.0, 0.0, 10.0);
|
||||
private final Setting<Double> verticalSpeed = num("VerticalSpeed", 1.0, 0.0, 10.0);
|
||||
private final Setting<Boolean> stopInWater = bool("StopInWater", true);
|
||||
private final Setting<Boolean> noCrash = bool("NoCrash", false);
|
||||
private final Setting<Integer> crashLookAhead = num("CrashLookAhead", 5, 1, 15);
|
||||
private final Setting<Boolean> instaDrop = bool("InstaDrop", false);
|
||||
private final Setting<Boolean> noUnloadedChunks = bool("NoUnloadedChunks", true);
|
||||
private final Setting<Boolean> autoHover = bool("AutoHover", false);
|
||||
|
||||
private Mode currentMode = Mode.Packet;
|
||||
private final Setting<Boolean> instaDrop = bool("InstaDrop", false);
|
||||
|
||||
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);
|
||||
super("ElytraFly", "Gives you more control over your elytra.", Category.MOVEMENT);
|
||||
noUnloadedChunks.setVisibility(v -> true);
|
||||
autoHover.setVisibility(v -> mode.getValue() != Mode.Packet);
|
||||
}
|
||||
|
||||
@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()) {
|
||||
@Override
|
||||
public void onDisable() {
|
||||
if (nullCheck()) return;
|
||||
if (mc.player.isFallFlying() && instaDrop.getValue()) {
|
||||
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;
|
||||
@Subscribe
|
||||
public void onMove(MoveEvent event) {
|
||||
if (nullCheck()) return;
|
||||
if (event.getType() != MoverType.SELF) return;
|
||||
if (!hasElytra()) 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 (autoTakeOff.getValue() && !mc.player.isFallFlying() && mc.options.keyJump.isDown()) {
|
||||
mc.player.setJumping(true);
|
||||
mc.player.connection.send(new ServerboundMovePlayerPacket.StatusOnly(true, mc.player.horizontalCollision));
|
||||
}
|
||||
|
||||
if (mc.options.keyJump.isDown()) {
|
||||
velY += verticalSpeed.getValue();
|
||||
} else {
|
||||
velY -= verticalSpeed.getValue();
|
||||
}
|
||||
if (!mc.player.isFallFlying()) return;
|
||||
|
||||
mc.player.setDeltaMovement(new Vec3(velX, velY, velZ));
|
||||
mc.player.connection.send(new ServerboundMovePlayerPacket.StatusOnly(true, mc.player.horizontalCollision));
|
||||
}
|
||||
if (mode.getValue() == Mode.Vanilla) {
|
||||
Vec3 movement = event.getMovement();
|
||||
velX = 0.0;
|
||||
velY = movement.y;
|
||||
velZ = 0.0;
|
||||
|
||||
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);
|
||||
// Stop flying in liquids (vanilla elytra stops near water; reset the boost).
|
||||
if ((mc.player.isInWater() || mc.player.isInLava()) && stopInWater.getValue()) {
|
||||
mc.player.connection.send(new ServerboundMovePlayerPacket.StatusOnly(true, mc.player.horizontalCollision));
|
||||
return;
|
||||
}
|
||||
|
||||
// Dampen the downward velocity instead of adding gravity on top of it.
|
||||
if (velY < 0.0) {
|
||||
velY *= fallMultiplier.getValue();
|
||||
} else if (velY > 0.0) {
|
||||
velY = 0.0;
|
||||
}
|
||||
|
||||
float yaw = mc.player.getYRot();
|
||||
Vec3 forward = Vec3.directionFromRotation(0, yaw).scale(0.1);
|
||||
Vec3 right = Vec3.directionFromRotation(0, yaw + 90.0f).scale(0.1);
|
||||
|
||||
double speed = horizontalSpeed.getValue();
|
||||
boolean strafing = false;
|
||||
if (mc.options.keyUp.isDown()) {
|
||||
velX += forward.x * speed * 10.0;
|
||||
velZ += forward.z * speed * 10.0;
|
||||
} else if (mc.options.keyDown.isDown()) {
|
||||
velX -= forward.x * speed * 10.0;
|
||||
velZ -= forward.z * speed * 10.0;
|
||||
}
|
||||
if (mc.options.keyRight.isDown()) {
|
||||
velX += right.x * speed * 10.0;
|
||||
velZ += right.z * speed * 10.0;
|
||||
strafing = true;
|
||||
} else if (mc.options.keyLeft.isDown()) {
|
||||
velX -= right.x * speed * 10.0;
|
||||
velZ -= right.z * speed * 10.0;
|
||||
strafing = true;
|
||||
}
|
||||
if (strafing && (mc.options.keyUp.isDown() || mc.options.keyDown.isDown())) {
|
||||
double diagonal = 1.0 / Math.sqrt(2.0);
|
||||
velX *= diagonal;
|
||||
velZ *= diagonal;
|
||||
}
|
||||
|
||||
if (mc.options.keyJump.isDown()) {
|
||||
velY += 0.5 * verticalSpeed.getValue();
|
||||
} else if (mc.options.keyShift.isDown()) {
|
||||
velY -= 0.5 * verticalSpeed.getValue();
|
||||
}
|
||||
|
||||
int chunkX = (int) ((mc.player.getX() + velX) / 16.0);
|
||||
int chunkZ = (int) ((mc.player.getZ() + velZ) / 16.0);
|
||||
if (noUnloadedChunks.getValue() && !mc.level.hasChunk(chunkX, chunkZ)) {
|
||||
event.setMovement(0, velY, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
event.setMovement(velX, velY, velZ);
|
||||
|
||||
if (autoHover.getValue() && mc.options.keyShift.isDown()) {
|
||||
BlockPos below = mc.player.blockPosition().below();
|
||||
if (mc.level.getBlockState(below).getCollisionShape(mc.level, below).isEmpty()) {
|
||||
event.setMovement(event.getMovement().x, -0.1, event.getMovement().z);
|
||||
mc.player.setXRot((float) Math.max(-50, Math.min(20, mc.player.getXRot())));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void handleVanillaMode(Vec3 movement) {
|
||||
// Vanilla elytra gliding: apply speed multipliers and damping.
|
||||
@Subscribe
|
||||
public void onTickPost(TickEvent.Post event) {
|
||||
if (nullCheck()) return;
|
||||
if (mode.getValue() != Mode.Packet) return;
|
||||
if (!hasElytra()) return;
|
||||
if (mc.player.fallDistance <= 0.2 || mc.options.keyShift.isDown()) return;
|
||||
|
||||
double x = 0, y = 0, z = 0;
|
||||
if (mc.options.keyUp.isDown()) z += horizontalSpeed.getValue();
|
||||
else if (mc.options.keyDown.isDown()) z -= horizontalSpeed.getValue();
|
||||
|
||||
if (mc.options.keyJump.isDown()) y += verticalSpeed.getValue();
|
||||
else y -= verticalSpeed.getValue();
|
||||
|
||||
Vec3 velocity = new Vec3(x, y, z).yRot(-(float) Math.toRadians(mc.player.getYRot()));
|
||||
mc.player.setDeltaMovement(velocity);
|
||||
mc.player.connection.send(new ServerboundMovePlayerPacket.StatusOnly(true, mc.player.horizontalCollision));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
if (currentMode == Mode.Packet) {
|
||||
mc.player.getAbilities().flying = true;
|
||||
mc.player.getAbilities().mayfly = true;
|
||||
}
|
||||
private boolean hasElytra() {
|
||||
ItemStack chest = mc.player.getItemBySlot(EquipmentSlot.CHEST);
|
||||
return chest.is(Items.ELYTRA);
|
||||
}
|
||||
|
||||
@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 String getDisplayInfo() {
|
||||
return mode.getValue().name();
|
||||
}
|
||||
|
||||
public enum Mode {
|
||||
Packet,
|
||||
Vanilla
|
||||
Vanilla,
|
||||
Packet
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,115 +0,0 @@
|
||||
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.
|
||||
*
|
||||
* <p>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.</p>
|
||||
*/
|
||||
public class HandRenderModule extends Module {
|
||||
// Main hand
|
||||
private final Setting<Double> mainScale = num("MainScale", 1.0, 0.1, 3.0);
|
||||
private final Setting<Double> mainPosX = num("MainPosX", 0.0, -1.5, 1.5);
|
||||
private final Setting<Double> mainPosY = num("MainPosY", 0.0, -1.5, 1.5);
|
||||
private final Setting<Double> mainPosZ = num("MainPosZ", 0.0, -1.5, 1.5);
|
||||
private final Setting<Double> mainRotX = num("MainRotX", 0.0, -180.0, 180.0);
|
||||
private final Setting<Double> mainRotY = num("MainRotY", 0.0, -180.0, 180.0);
|
||||
private final Setting<Double> mainRotZ = num("MainRotZ", 0.0, -180.0, 180.0);
|
||||
|
||||
// Off hand
|
||||
private final Setting<Double> offScale = num("OffScale", 1.0, 0.1, 3.0);
|
||||
private final Setting<Double> offPosX = num("OffPosX", 0.0, -1.5, 1.5);
|
||||
private final Setting<Double> offPosY = num("OffPosY", 0.0, -1.5, 1.5);
|
||||
private final Setting<Double> offPosZ = num("OffPosZ", 0.0, -1.5, 1.5);
|
||||
private final Setting<Double> offRotX = num("OffRotX", 0.0, -180.0, 180.0);
|
||||
private final Setting<Double> offRotY = num("OffRotY", 0.0, -180.0, 180.0);
|
||||
private final Setting<Double> offRotZ = num("OffRotZ", 0.0, -180.0, 180.0);
|
||||
|
||||
// Bare arm (shown when the hand is empty)
|
||||
private final Setting<Double> armScale = num("ArmScale", 1.0, 0.1, 3.0);
|
||||
private final Setting<Double> armPosX = num("ArmPosX", 0.0, -1.5, 1.5);
|
||||
private final Setting<Double> armPosY = num("ArmPosY", 0.0, -1.5, 1.5);
|
||||
private final Setting<Double> armPosZ = num("ArmPosZ", 0.0, -1.5, 1.5);
|
||||
private final Setting<Double> armRotX = num("ArmRotX", 0.0, -180.0, 180.0);
|
||||
private final Setting<Double> armRotY = num("ArmRotY", 0.0, -180.0, 180.0);
|
||||
private final Setting<Double> armRotZ = num("ArmRotZ", 0.0, -180.0, 180.0);
|
||||
|
||||
private final Setting<Boolean> hideMainHand = bool("HideMainHand", false);
|
||||
private final Setting<Boolean> hideOffHand = bool("HideOffHand", false);
|
||||
private final Setting<Double> 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<Double> scale,
|
||||
Setting<Double> posX, Setting<Double> posY, Setting<Double> posZ,
|
||||
Setting<Double> rotX, Setting<Double> rotY, Setting<Double> 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;
|
||||
}
|
||||
}
|
||||
@@ -50,10 +50,8 @@ 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;
|
||||
@@ -102,7 +100,6 @@ 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());
|
||||
@@ -117,8 +114,6 @@ public class ModuleManager implements Jsonable, Util {
|
||||
register(new ExpThrowerModule());
|
||||
register(new ReplenishModule());
|
||||
register(new FastAccelModule());
|
||||
register(new ElytraFlyModule());
|
||||
|
||||
LOGGER.info("Registered {} modules", modules.size());
|
||||
|
||||
// Create a command for each module for modules to be configurable via command line
|
||||
|
||||
Reference in New Issue
Block a user