-
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement aiStep and rewrite input code
- Loading branch information
1 parent
1ecaf99
commit 8e341b9
Showing
20 changed files
with
847 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
server/src/main/java/com/soulfiremc/server/protocol/bot/state/InputState.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* SoulFire | ||
* Copyright (C) 2024 AlexProgrammerDE | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
package com.soulfiremc.server.protocol.bot.state; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.cloudburstmc.math.vector.Vector2d; | ||
|
||
@RequiredArgsConstructor | ||
public class InputState { | ||
private final ControlState state; | ||
public KeyPresses keyPresses = KeyPresses.EMPTY; | ||
public float leftImpulse; | ||
public float forwardImpulse; | ||
|
||
private static float calculateImpulse(boolean input, boolean otherInput) { | ||
if (input == otherInput) { | ||
return 0.0F; | ||
} else { | ||
return input ? 1.0F : -1.0F; | ||
} | ||
} | ||
|
||
public Vector2d getMoveVector() { | ||
return Vector2d.from(this.leftImpulse, this.forwardImpulse); | ||
} | ||
|
||
public boolean hasForwardImpulse() { | ||
return this.forwardImpulse > 1.0E-5F; | ||
} | ||
|
||
public void makeJump() { | ||
this.keyPresses = new KeyPresses( | ||
this.keyPresses.forward(), | ||
this.keyPresses.backward(), | ||
this.keyPresses.left(), | ||
this.keyPresses.right(), | ||
true, | ||
this.keyPresses.shift(), | ||
this.keyPresses.sprint() | ||
); | ||
} | ||
|
||
public void tick(boolean movingSlowly, float amount) { | ||
this.keyPresses = state.toKeyPresses(); | ||
this.forwardImpulse = calculateImpulse(this.keyPresses.forward(), this.keyPresses.backward()); | ||
this.leftImpulse = calculateImpulse(this.keyPresses.left(), this.keyPresses.right()); | ||
if (movingSlowly) { | ||
this.leftImpulse *= amount; | ||
this.forwardImpulse *= amount; | ||
} | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
server/src/main/java/com/soulfiremc/server/protocol/bot/state/KeyPresses.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* SoulFire | ||
* Copyright (C) 2024 AlexProgrammerDE | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
package com.soulfiremc.server.protocol.bot.state; | ||
|
||
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.level.ServerboundPlayerInputPacket; | ||
|
||
public record KeyPresses( | ||
boolean forward, | ||
boolean backward, | ||
boolean left, | ||
boolean right, | ||
boolean jump, | ||
boolean shift, | ||
boolean sprint | ||
) { | ||
public static final KeyPresses EMPTY = new KeyPresses(false, false, false, false, false, false, false); | ||
|
||
public ServerboundPlayerInputPacket toServerboundPlayerInputPacket() { | ||
return new ServerboundPlayerInputPacket(forward, backward, left, right, jump, shift, sprint); | ||
} | ||
} |
Oops, something went wrong.