[creativeflight] new module
This commit is contained in:
parent
459375083e
commit
0d3d243259
|
@ -2,11 +2,11 @@ package dev.coredoes.clientmod;
|
|||
|
||||
import dev.coredoes.clientmod.hud.HudManager;
|
||||
import dev.coredoes.clientmod.modmenu.ModMenu;
|
||||
import dev.coredoes.clientmod.modules.CreativeFlight;
|
||||
import dev.coredoes.clientmod.modules.Jetpack;
|
||||
import dev.coredoes.clientmod.modules.ModuleManager;
|
||||
import dev.coredoes.clientmod.modules.NoFall;
|
||||
import net.fabricmc.api.ClientModInitializer;
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
|
||||
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
|
||||
import net.minecraft.client.option.KeyBinding;
|
||||
|
@ -48,6 +48,7 @@ public class ClientMod implements ClientModInitializer {
|
|||
|
||||
moduleManager.registerModule(new Jetpack());
|
||||
moduleManager.registerModule(new NoFall());
|
||||
moduleManager.registerModule(new CreativeFlight());
|
||||
|
||||
LOGGER.info("[Stage 3/3: EventInit] Registered modules; registering module event system");
|
||||
moduleManager.registerEvents();
|
||||
|
|
|
@ -0,0 +1,172 @@
|
|||
package dev.coredoes.clientmod.modules;
|
||||
|
||||
import dev.coredoes.clientmod.ClientMod;
|
||||
import dev.coredoes.clientmod.hud.HudColor;
|
||||
import dev.coredoes.clientmod.hud.HudMessage;
|
||||
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.client.gui.widget.ButtonWidget;
|
||||
import net.minecraft.client.gui.widget.SliderWidget;
|
||||
import net.minecraft.client.gui.widget.TextFieldWidget;
|
||||
import net.minecraft.client.option.GameOptions;
|
||||
import net.minecraft.client.option.KeyBinding;
|
||||
import net.minecraft.client.util.InputUtil;
|
||||
import net.minecraft.entity.player.PlayerAbilities;
|
||||
import net.minecraft.screen.ScreenTexts;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
|
||||
public class CreativeFlight implements Module {
|
||||
|
||||
protected boolean isEnabled = false;
|
||||
protected boolean isVanillaBypassEnabled = true;
|
||||
|
||||
protected boolean doOnDisable = false;
|
||||
|
||||
protected int tickCounter = 0;
|
||||
|
||||
private static KeyBinding toggleBinding;
|
||||
|
||||
@Override
|
||||
public void postRegister() {
|
||||
Module.super.postRegister();
|
||||
|
||||
toggleBinding = KeyBindingHelper.registerKeyBinding(new KeyBinding(
|
||||
"key.clientmod.creativeflight",
|
||||
InputUtil.Type.KEYSYM,
|
||||
GLFW.GLFW_KEY_UNKNOWN,
|
||||
"category.clientmod.modules"
|
||||
));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endTick(MinecraftClient client) {
|
||||
Module.super.endTick(client);
|
||||
|
||||
while (toggleBinding.wasPressed()) {
|
||||
this.isEnabled = !this.isEnabled;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disable() {
|
||||
this.isEnabled = false;
|
||||
doOnDisable = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enable() {
|
||||
this.isEnabled = true;
|
||||
tickCounter = 0;
|
||||
ClientMod.moduleManager.getModuleById("jetpack").disable();
|
||||
ClientMod.moduleManager.getModuleById("nofall").disable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startTick(MinecraftClient client) {
|
||||
Module.super.startTick(client);
|
||||
|
||||
tickCounter += 1;
|
||||
|
||||
if (client.player != null) {
|
||||
if (this.isEnabled) {
|
||||
ClientMod.hudManager.setMesssage("CreativeFlight", new HudMessage(String.format("CreativeFlight: Enabled (VanillaBypass %s)", (this.isVanillaBypassEnabled) ? "on" : "off"), HudColor.Green));
|
||||
|
||||
client.player.getAbilities().allowFlying = true;
|
||||
|
||||
if (isVanillaBypassEnabled && client.player.getAbilities().flying) {
|
||||
vanillaBypass(client);
|
||||
}
|
||||
} else {
|
||||
ClientMod.hudManager.clearMessage("CreativeFlight");
|
||||
|
||||
if (doOnDisable) {
|
||||
doOnDisable = false;
|
||||
PlayerAbilities abilities = client.player.getAbilities();
|
||||
boolean is_creative = client.player.isCreative();
|
||||
|
||||
abilities.flying = is_creative && !client.player.isOnGround();
|
||||
abilities.allowFlying = is_creative;
|
||||
|
||||
client.options.jumpKey.setPressed(false);
|
||||
client.options.sneakKey.setPressed(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void vanillaBypass(MinecraftClient client) {
|
||||
if (tickCounter > 60 + 2) {
|
||||
tickCounter = 0;
|
||||
}
|
||||
|
||||
if (tickCounter == 0) {
|
||||
if (client.options.sneakKey.isPressed() && !client.options.jumpKey.isPressed()) {
|
||||
tickCounter = 3;
|
||||
} else {
|
||||
setYVel(client, -0.032);
|
||||
}
|
||||
} else if (tickCounter == 1) {
|
||||
setYVel(client, 0.032);
|
||||
} else if (tickCounter == 2) {
|
||||
setYVel(client, 0);
|
||||
} else if (tickCounter == 3) {
|
||||
client.options.jumpKey.setPressed(false);
|
||||
client.options.sneakKey.setPressed(false);
|
||||
}
|
||||
}
|
||||
|
||||
private void setYVel(MinecraftClient client, double yvel) {
|
||||
client.options.sneakKey.setPressed(false);
|
||||
client.options.jumpKey.setPressed(false);
|
||||
Vec3d old_vel = client.player.getVelocity();
|
||||
client.player.setVelocity(old_vel.x, yvel, old_vel.z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return "CreativeFlight";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getVersion() {
|
||||
return "1.0.0";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Screen getUI(Screen parent, GameOptions options) {
|
||||
return new ModuleUI(parent, options, this);
|
||||
}
|
||||
class ModuleUI extends Screen {
|
||||
private final Screen parent;
|
||||
private final GameOptions settings;
|
||||
private CreativeFlight parentModule;
|
||||
|
||||
public ModuleUI(Screen parent, GameOptions gameOptions, CreativeFlight parentModule) {
|
||||
super(Text.of("CreativeFlightModule"));
|
||||
this.parent = parent;
|
||||
this.settings = gameOptions;
|
||||
this.parentModule = parentModule;
|
||||
}
|
||||
|
||||
protected void init() {
|
||||
this.addDrawableChild(new ButtonWidget(5, 5, 70, 20, Text.of("Enabled: " + (this.parentModule.isEnabled ? "yes" : "no")), (button) -> {
|
||||
this.parentModule.isEnabled = !this.parentModule.isEnabled;
|
||||
button.setMessage(Text.of("Enabled: " + (this.parentModule.isEnabled ? "yes" : "no")));
|
||||
}));
|
||||
|
||||
this.addDrawableChild(new ButtonWidget(5, 30, 170, 20, Text.of("Vanilla Bypass Enabled: " + (this.parentModule.isVanillaBypassEnabled ? "yes" : "no")), (button) -> {
|
||||
this.parentModule.isVanillaBypassEnabled = !this.parentModule.isVanillaBypassEnabled;
|
||||
button.setMessage(Text.of("Vanilla Bypass Enabled: " + (this.parentModule.isVanillaBypassEnabled ? "yes" : "no")));
|
||||
}));
|
||||
|
||||
this.addDrawableChild(new ButtonWidget(5, this.height - 25, 40, 20, ScreenTexts.BACK, (button) -> {
|
||||
this.client.setScreen(this.parent);
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -219,4 +219,16 @@ public class Jetpack implements Module {
|
|||
}));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disable() {
|
||||
this.isEnabled = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enable() {
|
||||
this.isEnabled = true;
|
||||
ClientMod.moduleManager.getModuleById("creativeflight").disable();
|
||||
ClientMod.moduleManager.getModuleById("nofall").disable();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,6 +19,9 @@ public interface Module {
|
|||
default void startTick(MinecraftClient client) {}
|
||||
default void endTick(MinecraftClient client) {}
|
||||
|
||||
default void disable() {}
|
||||
default void enable() {}
|
||||
|
||||
// Manager stuff
|
||||
String getId();
|
||||
String getVersion();
|
||||
|
|
|
@ -61,7 +61,7 @@ public class NoFall implements Module {
|
|||
if (client.player.fallDistance <= (client.player.isFallFlying() ? 1 : 2)) return;
|
||||
|
||||
// Can we even take fall damage right now?
|
||||
if (client.player.isFallFlying() && client.player.isSneaking() && client.player.getVelocity().getY() >= -0.5) return;
|
||||
if (client.player.isFallFlying() && client.player.isSneaking() && client.player.getVelocity().getY() >= -0.4) return;
|
||||
|
||||
// Need to cancel fall damage
|
||||
client.player.networkHandler.sendPacket(new PlayerMoveC2SPacket.OnGroundOnly(true));
|
||||
|
@ -77,6 +77,18 @@ public class NoFall implements Module {
|
|||
return "1.0.0";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disable() {
|
||||
this.isEnabled = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enable() {
|
||||
this.isEnabled = true;
|
||||
ClientMod.moduleManager.getModuleById("jetpack").disable();
|
||||
ClientMod.moduleManager.getModuleById("creativeflight").disable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Screen getUI(Screen parent, GameOptions options) {
|
||||
return new ModuleUI(parent, options, this);
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
{
|
||||
"category.clientmod.menues": "ClientMod: Menues",
|
||||
"key.clientmod.modmenu": "Toggle ModMenu",
|
||||
|
||||
"category.clientmod.modules": "ClientMod: Modules",
|
||||
|
||||
"key.clientmod.modmenu": "Toggle ModMenu",
|
||||
"key.clientmod.jetpack": "Toggle Jetpack",
|
||||
"key.clientmod.nofall": "Toggle NoFall"
|
||||
"key.clientmod.nofall": "Toggle NoFall",
|
||||
"key.clientmod.creativeflight": "Toggle CreativeFlight"
|
||||
}
|
Loading…
Reference in New Issue