Add a speed hack :)

main
Charlotte Som 2022-02-03 22:09:18 +00:00
parent 085c1d14f4
commit 5e1cb85754
5 changed files with 43 additions and 2 deletions

View File

@ -1,12 +1,17 @@
package codes.som.hibiscus.mixins;
import codes.som.hibiscus.HibiscusMod;
import codes.som.hibiscus.events.MovePlayerEvent;
import codes.som.hibiscus.events.PlayerTickEvent;
import codes.som.hibiscus.events.SendChatEvent;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.entity.MovementType;
import net.minecraft.util.math.Vec3d;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyVariable;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(ClientPlayerEntity.class)
@ -23,4 +28,19 @@ public abstract class MixinClientPlayerEntity {
if (event.isCancelled())
ci.cancel();
}
@Unique
private MovementType movementType;
@Inject(method = "move", at = @At("HEAD"))
private void onMovePlayerWhatIsTheMovementType(MovementType type, Vec3d movement, CallbackInfo ci) {
this.movementType = type;
}
@ModifyVariable(method = "move", at = @At(value = "HEAD", shift = At.Shift.AFTER), argsOnly = true)
private Vec3d onMovePlayer(Vec3d movement) {
var event = new MovePlayerEvent(movement.x, movement.y, movement.z, this.movementType);
HibiscusMod.bus().fire(event);
return new Vec3d(event.getX(), event.getY(), event.getZ());
}
}

View File

@ -31,8 +31,6 @@ object HibiscusMod : ModInitializer {
commands.register(feature.createFeatureCommand())
}
keybinds.register(GLFW.GLFW_KEY_R, "flight")
bus.register { event: KeyEvent ->
if (event.key != GLFW_KEY_RIGHT_SHIFT || event.action != GLFW.GLFW_PRESS)
return@register

View File

@ -2,6 +2,8 @@ package codes.som.hibiscus.events
import codes.som.hibiscus.api.event.Cancellable
import codes.som.hibiscus.api.event.Event
import net.minecraft.entity.MovementType
object PlayerTickEvent : Event
class SendChatEvent(val message: String) : Cancellable(), Event
data class MovePlayerEvent(var x: Double, var y: Double, var z: Double, val movementType: MovementType) : Event

View File

@ -2,6 +2,7 @@ package codes.som.hibiscus.features
import codes.som.hibiscus.api.feature.Feature
import codes.som.hibiscus.features.movement.Flight
import codes.som.hibiscus.features.movement.Speed
import codes.som.hibiscus.features.overlay.FeatureList
import codes.som.hibiscus.features.player.NoFallDamage
@ -9,4 +10,5 @@ val ALL_FEATURES: Array<() -> Feature> = arrayOf(
::NoFallDamage,
::Flight,
::FeatureList,
::Speed,
)

View File

@ -0,0 +1,19 @@
package codes.som.hibiscus.features.movement
import codes.som.hibiscus.api.feature.Feature
import codes.som.hibiscus.api.feature.FeatureCategory
import codes.som.hibiscus.events.MovePlayerEvent
import net.minecraft.entity.MovementType
class Speed : Feature("Speed", FeatureCategory.MOVEMENT) {
init {
val speed by values.float("Speed", 2f, 0.05f, 10f)
on { event: MovePlayerEvent ->
if (event.movementType == MovementType.SELF) {
event.x *= speed
event.z *= speed
}
}
}
}