feat: added speed control to vanilla flight

This commit is contained in:
əlemi 2023-01-31 01:46:20 +01:00
parent 963c67aeae
commit f03ba40760
No known key found for this signature in database
GPG key ID: BBCBFE5D7244634E
2 changed files with 34 additions and 6 deletions

View file

@ -25,14 +25,14 @@ public class QuickModule extends Module {
@SubscribeEvent
public void onKeyPress(InputEvent.KeyInputEvent event) {
if (this.key.isDown()) {
this.mod.toggle();
this.mod.toggle(); // TODO debounce this
}
}
@SubscribeEvent
public void onKeyPress(InputEvent.MouseInputEvent event) {
if (this.key.isDown()) {
this.mod.toggle();
this.mod.toggle(); // TODO debounce this
}
}

View file

@ -1,10 +1,14 @@
package co.fantabos.bscv.module.motion;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.BoolArgumentType;
import com.mojang.brigadier.arguments.DoubleArgumentType;
import co.fantabos.bscv.BoSCoVicino;
import co.fantabos.bscv.module.QuickModule;
import net.minecraft.client.entity.player.ClientPlayerEntity;
import net.minecraft.command.CommandSource;
import net.minecraft.util.math.vector.Vector3d;
import net.minecraftforge.common.ForgeConfigSpec;
import net.minecraftforge.event.TickEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
@ -12,19 +16,37 @@ import net.minecraftforge.eventbus.api.SubscribeEvent;
public class VanillaFlight extends QuickModule {
public final ForgeConfigSpec.ConfigValue<Boolean> force;
public final ForgeConfigSpec.ConfigValue<Double> speed;
public VanillaFlight(ForgeConfigSpec.Builder builder, CommandDispatcher<CommandSource> dispatcher) {
super("VanillaFlight", Group.MOTION, -1, builder, dispatcher);
this.force = this.option(
"force", "force enable flight on user", true,
BoolArgumentType.bool(), Boolean.class,
builder, dispatcher
);
this.speed = this.option(
"speed", "flight speed to set", 0.05,
DoubleArgumentType.doubleArg(0.0), Double.class,
builder, dispatcher
);
}
private boolean couldFlyBefore = false;
private float flyingSpeedBefore = 0.05f;
@SubscribeEvent
public void onTick(TickEvent.ClientTickEvent event) {
if (BoSCoVicino.minecraft.player != null) {
BoSCoVicino.minecraft.player.abilities.mayfly = true;
ClientPlayerEntity player = BoSCoVicino.minecraft.player;
if (player == null) return;
player.abilities.mayfly = true;
player.abilities.setFlyingSpeed(this.speed.get().floatValue());
if (this.force.get()) {
player.abilities.flying = true;
}
}
@ -32,13 +54,19 @@ public class VanillaFlight extends QuickModule {
protected void onEnabled() {
if (BoSCoVicino.minecraft.player != null) {
this.couldFlyBefore = BoSCoVicino.minecraft.player.abilities.mayfly;
this.flyingSpeedBefore = BoSCoVicino.minecraft.player.abilities.getFlyingSpeed();
}
}
@Override
protected void onDisabled() {
if (BoSCoVicino.minecraft.player != null) {
BoSCoVicino.minecraft.player.abilities.mayfly = this.couldFlyBefore;
ClientPlayerEntity player = BoSCoVicino.minecraft.player;
if (player != null) {
player.abilities.mayfly = this.couldFlyBefore;
player.abilities.setFlyingSpeed(this.flyingSpeedBefore);
if (this.force.get()) {
player.abilities.flying = false;
}
}
}
}