feat(MoveEvent): add move event and sample module using it
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
package me.alpha432.oyvey.event.impl.entity.player;
|
||||
|
||||
import me.alpha432.oyvey.event.Event;
|
||||
import net.minecraft.world.entity.MoverType;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
|
||||
public class MoveEvent extends Event {
|
||||
private final MoverType type;
|
||||
private Vec3 movement;
|
||||
|
||||
public MoveEvent(MoverType type, Vec3 movement) {
|
||||
this.type = type;
|
||||
this.movement = movement;
|
||||
}
|
||||
|
||||
public MoverType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public Vec3 getMovement() {
|
||||
return movement;
|
||||
}
|
||||
|
||||
public void setMovement(Vec3 movement) {
|
||||
this.movement = movement;
|
||||
}
|
||||
|
||||
public void setMovement(double x, double y, double z) {
|
||||
this.movement = new Vec3(x, y, z);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package me.alpha432.oyvey.features.modules.movement;
|
||||
|
||||
import me.alpha432.oyvey.event.impl.entity.player.MoveEvent;
|
||||
import me.alpha432.oyvey.event.system.Subscribe;
|
||||
import me.alpha432.oyvey.features.modules.Module;
|
||||
import me.alpha432.oyvey.features.settings.Setting;
|
||||
import me.alpha432.oyvey.util.MovementUtil;
|
||||
import net.minecraft.world.entity.MoverType;
|
||||
import org.joml.Vector2f;
|
||||
|
||||
public class FastAccelModule extends Module {
|
||||
private final Setting<Float> speed = num("Speed", 1f, 0.5f, 2f);
|
||||
private final Setting<Boolean> slowness = bool("Slowness", true);
|
||||
|
||||
public FastAccelModule() {
|
||||
super("FastAccel", "Makes the player accelerate faster while walking", Category.MOVEMENT);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
private void onMove(MoveEvent event) {
|
||||
if (nullCheck() || event.getType() != MoverType.SELF) return;
|
||||
if (mc.player.isInLiquid() || mc.player.isFallFlying()
|
||||
|| mc.player.getAbilities().flying || mc.player.isSpectator()) return;
|
||||
|
||||
double speed = MovementUtil.SPRINT_SPEED * this.speed.getValue() * MovementUtil.getSpeedFactor(true, slowness.getValue());
|
||||
|
||||
if (event.getMovement().horizontalDistance() > speed) {
|
||||
speed = event.getMovement().horizontalDistance();
|
||||
}
|
||||
|
||||
Vector2f motion = MovementUtil.calcMoveVector(mc.player.getYRot(), speed);
|
||||
event.setMovement(motion.x, event.getMovement().y, motion.y);
|
||||
}
|
||||
}
|
||||
@@ -37,6 +37,7 @@ public class EventManager extends Feature {
|
||||
public void onTick(TickEvent.Post event) {
|
||||
if (nullCheck())
|
||||
return;
|
||||
OyVey.speedManager.update();
|
||||
OyVey.moduleManager.onTick();
|
||||
Set<Integer> dead = new HashSet<>();
|
||||
for (Player player : mc.level.players()) {
|
||||
|
||||
@@ -20,6 +20,7 @@ import me.alpha432.oyvey.features.modules.combat.KeyPearlModule;
|
||||
import me.alpha432.oyvey.features.modules.hud.CoordinatesHudModule;
|
||||
import me.alpha432.oyvey.features.modules.hud.WatermarkHudModule;
|
||||
import me.alpha432.oyvey.features.modules.misc.MCFModule;
|
||||
import me.alpha432.oyvey.features.modules.movement.FastAccelModule;
|
||||
import me.alpha432.oyvey.features.modules.movement.ReverseStepModule;
|
||||
import me.alpha432.oyvey.features.modules.movement.StepModule;
|
||||
import me.alpha432.oyvey.features.modules.player.FastPlaceModule;
|
||||
@@ -56,6 +57,7 @@ public class ModuleManager implements Jsonable, Util {
|
||||
register(new NoFallModule());
|
||||
register(new KeyPearlModule());
|
||||
register(new KillAuraModule());
|
||||
register(new FastAccelModule());
|
||||
|
||||
LOGGER.info("Registered {} modules", modules.size());
|
||||
|
||||
|
||||
@@ -1,9 +1,14 @@
|
||||
package me.alpha432.oyvey.mixin.entity;
|
||||
|
||||
import me.alpha432.oyvey.event.Stage;
|
||||
import com.llamalad7.mixinextras.injector.wrapmethod.WrapMethod;
|
||||
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
|
||||
import me.alpha432.oyvey.event.impl.entity.player.MoveEvent;
|
||||
import me.alpha432.oyvey.event.impl.entity.player.TickEvent;
|
||||
import me.alpha432.oyvey.event.impl.entity.player.UpdateWalkingPlayerEvent;
|
||||
import net.minecraft.client.player.LocalPlayer;
|
||||
import net.minecraft.world.entity.MoverType;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
@@ -32,4 +37,12 @@ public class MixinClientPlayerEntity {
|
||||
private void tickHook3(CallbackInfo ci) {
|
||||
EVENT_BUS.post(new UpdateWalkingPlayerEvent(Stage.POST));
|
||||
}
|
||||
|
||||
@WrapMethod(method = "move")
|
||||
private void moveHook(MoverType type, Vec3 movement, Operation<Void> original) {
|
||||
MoveEvent event = new MoveEvent(type, movement);
|
||||
EVENT_BUS.post(event);
|
||||
if (event.isCancelled()) return;
|
||||
original.call(type, event.getMovement());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
package me.alpha432.oyvey.util;
|
||||
|
||||
import me.alpha432.oyvey.util.traits.Util;
|
||||
import net.minecraft.client.player.ClientInput;
|
||||
import net.minecraft.world.effect.MobEffectInstance;
|
||||
import net.minecraft.world.effect.MobEffects;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.entity.ai.attributes.Attributes;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import org.joml.Vector2f;
|
||||
|
||||
public class MovementUtil implements Util {
|
||||
public static final double SPRINT_SPEED = 0.2873;
|
||||
|
||||
public static Vector2f calcMoveVector(float yaw, Vector2f input, double speed) {
|
||||
Vector2f direction = new Vector2f(input);
|
||||
|
||||
if (direction.lengthSquared() < 1.0E-8f) {
|
||||
return direction.zero();
|
||||
}
|
||||
|
||||
direction.normalize();
|
||||
|
||||
float rad = (float) Math.toRadians(yaw);
|
||||
float sin = (float) Math.sin(rad);
|
||||
float cos = (float) Math.cos(rad);
|
||||
|
||||
float x = (direction.x * cos - direction.y * sin) * (float) speed;
|
||||
float z = (direction.y * cos + direction.x * sin) * (float) speed;
|
||||
|
||||
return direction.set(x, z);
|
||||
}
|
||||
|
||||
public static Vector2f calcMoveVector(float yaw, ClientInput input, double speed) {
|
||||
return calcMoveVector(yaw, new Vector2f(input.getMoveVector().x, input.getMoveVector().y), speed);
|
||||
}
|
||||
|
||||
public static Vector2f calcMoveVector(float yaw, double speed) {
|
||||
return calcMoveVector(yaw, mc.player.input, speed);
|
||||
}
|
||||
|
||||
public static double getSpeedFactor(boolean swiftness, boolean slowness) {
|
||||
double factor = 1.0;
|
||||
|
||||
MobEffectInstance speedEffect = mc.player.getEffect(MobEffects.SPEED);
|
||||
if (swiftness && speedEffect != null) {
|
||||
factor *= 1.0 + 0.2 * (speedEffect.getAmplifier() + 1);
|
||||
}
|
||||
|
||||
MobEffectInstance slowEffect = mc.player.getEffect(MobEffects.SLOWNESS);
|
||||
if (slowness && slowEffect != null) {
|
||||
factor *= Math.max(0.0, 1.0 - 0.15 * (slowEffect.getAmplifier() + 1));
|
||||
}
|
||||
|
||||
return factor;
|
||||
}
|
||||
|
||||
public static double getJumpBoost() {
|
||||
return mc.player.getJumpBoostPower();
|
||||
}
|
||||
|
||||
public static double getJumpSpeed() {
|
||||
return mc.player.getAttributeValue(Attributes.JUMP_STRENGTH) * getBlockJumpFactor(mc.player) + getJumpBoost();
|
||||
}
|
||||
|
||||
public static double getJumpHeight() {
|
||||
return mc.player.getAttributeValue(Attributes.JUMP_STRENGTH) + getJumpBoost();
|
||||
}
|
||||
|
||||
private static float getBlockJumpFactor(LivingEntity entity) {
|
||||
BlockState inside = entity.level().getBlockState(entity.blockPosition());
|
||||
float factor = inside.getBlock().getJumpFactor();
|
||||
if (factor != 1.0f) return factor;
|
||||
return entity.level().getBlockState(entity.getBlockPosBelowThatAffectsMyMovement()).getBlock().getJumpFactor();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user