raven-bs-v2/src/main/java/keystrokesmod/module/impl/movement/Fly.java

186 lines
6.5 KiB
Java

package keystrokesmod.module.impl.movement;
import keystrokesmod.event.PostMotionEvent;
import keystrokesmod.event.PreMotionEvent;
import keystrokesmod.event.PrePlayerInputEvent;
import keystrokesmod.module.Module;
import keystrokesmod.module.ModuleManager;
import keystrokesmod.module.setting.impl.ButtonSetting;
import keystrokesmod.module.setting.impl.SliderSetting;
import keystrokesmod.utility.RenderUtils;
import keystrokesmod.utility.Utils;
import net.minecraftforge.fml.common.eventhandler.EventPriority;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent;
import org.apache.commons.lang3.RandomUtils;
public class Fly extends Module {
public SliderSetting mode;
public static SliderSetting horizontalSpeed;
private SliderSetting verticalSpeed;
private ButtonSetting showBPS;
private ButtonSetting stopMotion;
private boolean d;
private boolean a = false;
private float firstYaw, firstPitch;
private String[] modes = new String[]{"Vanilla", "Fast", "Fast 2", "Freeze"};
public Fly() {
super("Fly", category.movement);
this.registerSetting(mode = new SliderSetting("Fly", 0, modes));
this.registerSetting(horizontalSpeed = new SliderSetting("Horizontal speed", 2.0, 0.0, 9.0, 0.1));
this.registerSetting(verticalSpeed = new SliderSetting("Vertical speed", 2.0, 0.0, 9.0, 0.1));
this.registerSetting(showBPS = new ButtonSetting("Show BPS", false));
this.registerSetting(stopMotion = new ButtonSetting("Stop motion", false));
}
public void guiUpdate() {
horizontalSpeed.setVisible(mode.getInput() < 3, this);
this.verticalSpeed.setVisible(mode.getInput() < 3, this);
}
public void onEnable() {
this.d = mc.thePlayer.capabilities.isFlying;
firstYaw = mc.thePlayer.rotationYaw;
firstPitch = mc.thePlayer.rotationPitch;
}
public void onUpdate() {
switch ((int) mode.getInput()) {
case 0:
mc.thePlayer.motionY = 0.0;
mc.thePlayer.capabilities.setFlySpeed((float)(0.05000000074505806 * horizontalSpeed.getInput()));
mc.thePlayer.capabilities.isFlying = true;
break;
case 1:
mc.thePlayer.onGround = true;
if (mc.currentScreen == null) {
if (Utils.jumpDown()) {
mc.thePlayer.motionY = 0.3 * verticalSpeed.getInput();
}
else if (Utils.jumpDown()) {
mc.thePlayer.motionY = -0.3 * verticalSpeed.getInput();
}
else {
mc.thePlayer.motionY = 0.0;
}
}
else {
mc.thePlayer.motionY = 0.0;
}
mc.thePlayer.capabilities.setFlySpeed(0.2f);
mc.thePlayer.capabilities.isFlying = true;
setSpeed(0.85 * horizontalSpeed.getInput());
break;
case 2:
double nextDouble = RandomUtils.nextDouble(1.0E-7, 1.2E-7);
if (mc.thePlayer.ticksExisted % 2 == 0) {
nextDouble = -nextDouble;
}
if (!mc.thePlayer.onGround) {
mc.thePlayer.setPosition(mc.thePlayer.posX, mc.thePlayer.posY + nextDouble, mc.thePlayer.posZ);
}
mc.thePlayer.motionY = 0.0;
setSpeed(0.4 * horizontalSpeed.getInput());
break;
case 3:
mc.thePlayer.motionX = 0;
mc.thePlayer.motionY = 0;
mc.thePlayer.motionZ = 0;
Utils.setSpeed(0);
break;
}
}
@SubscribeEvent(priority = EventPriority.LOWEST) // called last in order to apply fix
public void onMoveInput(PrePlayerInputEvent e) {
if (mode.getInput() == 3) {
e.setForward(0);
e.setStrafe(0);
}
}
@SubscribeEvent
public void onPreMotion(PreMotionEvent e) {
if (mode.getInput() == 3) {
e.setYaw(firstYaw);
e.setPitch(firstPitch);
}
}
public void onDisable() {
if (mc.thePlayer.capabilities.allowFlying) {
mc.thePlayer.capabilities.isFlying = this.d;
}
else {
mc.thePlayer.capabilities.isFlying = false;
}
this.d = false;
switch ((int) mode.getInput()) {
case 0:
case 1: {
mc.thePlayer.capabilities.setFlySpeed(0.05F);
break;
}
case 2: {
a = false;
break;
}
}
if (stopMotion.isToggled()) {
mc.thePlayer.motionZ = 0;
mc.thePlayer.motionY = 0;
mc.thePlayer.motionX = 0;
}
}
@SubscribeEvent
public void onRenderTick(TickEvent.RenderTickEvent e) {
if (!showBPS.isToggled() || e.phase != TickEvent.Phase.END || !Utils.nullCheck()) {
return;
}
if (mc.currentScreen != null || mc.gameSettings.showDebugInfo) {
return;
}
RenderUtils.renderBPS(true, false);
}
public static void setSpeed(final double n) {
if (n == 0.0) {
mc.thePlayer.motionZ = 0;
mc.thePlayer.motionX = 0;
return;
}
double n3 = mc.thePlayer.movementInput.moveForward;
double n4 = mc.thePlayer.movementInput.moveStrafe;
float rotationYaw = mc.thePlayer.rotationYaw;
if (n3 == 0.0 && n4 == 0.0) {
mc.thePlayer.motionZ = 0;
mc.thePlayer.motionX = 0;
}
else {
if (n3 != 0.0) {
if (n4 > 0.0) {
rotationYaw += ((n3 > 0.0) ? -45 : 45);
}
else if (n4 < 0.0) {
rotationYaw += ((n3 > 0.0) ? 45 : -45);
}
n4 = 0.0;
if (n3 > 0.0) {
n3 = 1.0;
}
else if (n3 < 0.0) {
n3 = -1.0;
}
}
final double radians = Math.toRadians(rotationYaw + 90.0f);
final double sin = Math.sin(radians);
final double cos = Math.cos(radians);
mc.thePlayer.motionX = n3 * n * cos + n4 * n * sin;
mc.thePlayer.motionZ = n3 * n * sin - n4 * n * cos;
}
}
}