/// api_version=2
var script = registerScript({
	name: "ScaffoldAddon",
	version: "2.1",
	authors: ["As丶One","liulihaocai", "CH"]
});

var RotationUtils = Java.type('net.ccbluex.liquidbounce.utils.RotationUtils')
var Rotation = Java.type('net.ccbluex.liquidbounce.utils.Rotation')
var Scaffold = moduleManager.getModule('Scaffold')
var C09=Java.type('net.minecraft.network.play.client.C09PacketHeldItemChange')

script.registerModule({
	name: "ScaffoldAddon",
	description: "Improve Scaffold for redesky",
        category: "World",
	settings: {
        yMot: Setting.float({
            name: "YMotion",
            default: 0.10,
            min: 0.00,
            max: 0.20
        }),
        maxYMot: Setting.float({
            name: "MaxYMotion",
            default: 0.8,
            min: 0.00,
            max: 2.00
        }),
		ts: Setting.boolean({
			name: "TowerScaffold",
			default: true
		})
	}
}, function (module) {
	function isMoving() {
		var corrYaw=Math.abs(mc.thePlayer.rotationYaw%360)
        return (corrYaw%90)>70||(corrYaw%90)<20;
	}
	function canTower(){
		return !(!mc.gameSettings.keyBindJump.isKeyDown()||mc.gameSettings.keyBindLeft.isKeyDown()||mc.gameSettings.keyBindRight.isKeyDown()||mc.gameSettings.keyBindForward.isKeyDown()||mc.gameSettings.keyBindBack.isKeyDown());
	}
	module.on("update", function () {
		Scaffold.setState(true);
		if(module.settings.ts.get()&&canTower()){
			module.tag="Tower"
			mc.thePlayer.motionY += module.settings.yMot.get();
			if(mc.thePlayer.motionY>module.settings.maxYMot.get()){
				mc.thePlayer.motionY=module.settings.maxYMot.get();
			}
			RotationUtils.setTargetRotation(new Rotation(mc.thePlayer.rotationYaw,90));
		}else{
			module.tag="Scaffold"
			if(isMoving()){
				Scaffold.getValue('Rotations').set(true)
			}else{
				Scaffold.getValue('Rotations').set(true)
			}
		}
	})
	module.on("disable", function () {
		Scaffold.setState(false);
    })
})