/// api_version=2
var script = registerScript({
    name: "RedeSpeed",
    version: "1.0.0",
    authors: ["noom#0681"]
});

script.registerModule({
    name: "RedeSpeed",
    category: "Fun",
    description: "Custom speed for redesky.",
	settings: {
	RedeSpeedMode: Setting.list({
		name: "Mode",
		default: "CustomHop",
		values: ["CustomHop", "Boost"]
	}),
	RedeSpeedBoostValue: Setting.float({
		name: "BoostVal",
		default: 0.1,
		min: 0.02,
		max:0.5
	}),
	RedeSpeedOnGround: Setting.float({
		name: "SpeedOnGround",
		default: 1.4,
		min: 0.5,
		max:3
	}),
	RedeSpeedNoGround: Setting.float({
		name: "SpeedNoGround",
		default: 0.02,
		min: 0.02,
		max:0.5
	}),
	RedeTimerOnGround: Setting.float({
		name: "TimerOnGround",
		default: 1,
		min: 0.5,
		max:3
	}),
	RedeTimerNoGround: Setting.float({
		name: "TimerNoGround",
		default: 1,
		min: 0.1,
		max:3
	}),
	RSpeed: Setting.boolean({
			name: "SpeedNoGround",
			default: true
		}),
	RSpeed2: Setting.boolean({
		name: "SpeedOnGround",
		default: true
	}),
	RTimer: Setting.boolean({
			name: "TimerNoGround",
			default: true
		}),
	RTimer2: Setting.boolean({
		name: "TimerOnGround",
		default: true
	}),
	RedeSpeedMoveCheck: Setting.boolean({
			name: "MoveCheck",
			default: true
		}),
	RedeSpeedAutoJump: Setting.boolean({
		name: "AutoJump",
		default: true
	}),
	RedeSpeedCollideCheck: Setting.boolean({
			name: "CollideCheck",
			default: true
		})
	}
}, function (module) {
	var delay = 0;
	var strafe = moduleManager.getModule("Strafe");
    module.on("update", function() {
			delay++;
			if(!mc.gameSettings.keyBindForward.pressed && module.settings.RedeSpeedMoveCheck.get()){
				return;
			}
			if(module.settings.RedeSpeedMode.get() == "CustomHop"){
			
			if(mc.thePlayer.onGround){
				if(module.settings.RedeSpeedAutoJump.get() == true){
			mc.thePlayer.jump();
				}
			if(module.settings.RTimer2.get() == true){
			mc.timer.timerSpeed = module.settings.RedeTimerOnGround.get();
			}
			if(module.settings.RSpeed2.get() == true){
				if(module.settings.RedeSpeedCollideCheck.get() == true){
			if(mc.thePlayer.isCollidedHorizontally == false){
			mc.thePlayer.motionX = mc.thePlayer.motionX * module.settings.RedeSpeedOnGround.get();
			mc.thePlayer.motionZ = mc.thePlayer.motionZ * module.settings.RedeSpeedOnGround.get();
			}
				}else{
			mc.thePlayer.motionX = mc.thePlayer.motionX * module.settings.RedeSpeedOnGround.get();
			mc.thePlayer.motionZ = mc.thePlayer.motionZ * module.settings.RedeSpeedOnGround.get();
				}
			}
			}else{
			if(module.settings.RTimer.get() == true){
			mc.timer.timerSpeed = module.settings.RedeTimerNoGround.get();
			}
			if(module.settings.RSpeed.get() == true){
			mc.thePlayer.jumpMovementFactor = module.settings.RedeSpeedNoGround.get();
			}
			}
			}
			if(module.settings.RedeSpeedMode.get() == "Boost"){
				if(mc.thePlayer.onGround){
					mc.thePlayer.jump();
					delay = 0;
				}else{
					if(delay > 2 && !(delay > 4)){
				  mc.thePlayer.jumpMovementFactor = module.settings.RedeSpeedBoostValue.get();
					}
				}
			}
			
    });
    module.on("enable", function() {
		delay = 0;
    });
    module.on("disable", function() {
		delay = 0;
    mc.thePlayer.capabilities.isFlying = false;
    mc.timer.timerSpeed = 1;
    });
});