-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a1ccfce
commit 5bf37e5
Showing
21 changed files
with
659 additions
and
72 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
Binary file not shown.
5 changes: 5 additions & 0 deletions
5
src/main/java/dev/emortal/minestom/parkourtag/Main.java
100644 → 100755
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
2 changes: 1 addition & 1 deletion
2
...kourtag/ParkourTagDoubleJumpListener.java → ...steners/ParkourTagDoubleJumpListener.java
100644 → 100755
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
3 changes: 2 additions & 1 deletion
3
src/main/java/dev/emortal/minestom/parkourtag/map/LoadedMap.java
100644 → 100755
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 |
---|---|---|
@@ -1,7 +1,8 @@ | ||
package dev.emortal.minestom.parkourtag.map; | ||
|
||
import dev.emortal.minestom.parkourtag.physics.MinecraftPhysicsHandler; | ||
import net.minestom.server.instance.Instance; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public record LoadedMap(@NotNull Instance instance, @NotNull MapData mapData) { | ||
public record LoadedMap(@NotNull Instance instance, @NotNull MapData mapData, @NotNull MinecraftPhysicsHandler physicsHandler) { | ||
} |
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
75 changes: 75 additions & 0 deletions
75
src/main/java/dev/emortal/minestom/parkourtag/physics/MinecraftPhysicsHandler.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,75 @@ | ||
package dev.emortal.minestom.parkourtag.physics; | ||
|
||
import com.jme3.bullet.PhysicsSpace; | ||
import com.jme3.bullet.collision.PhysicsCollisionObject; | ||
import com.jme3.math.Vector3f; | ||
import dev.emortal.minestom.parkourtag.physics.objects.MinecraftPhysicsObject; | ||
import net.minestom.server.instance.Instance; | ||
import net.minestom.server.timer.TaskSchedule; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.util.List; | ||
import java.util.concurrent.CopyOnWriteArrayList; | ||
|
||
public class MinecraftPhysicsHandler { | ||
private static final Logger LOGGER = LoggerFactory.getLogger(MinecraftPhysicsHandler.class); | ||
|
||
private @Nullable PhysicsSpace physicsSpace; | ||
|
||
private final @NotNull List<MinecraftPhysicsObject> objects = new CopyOnWriteArrayList<>(); | ||
|
||
public MinecraftPhysicsHandler(@NotNull Instance instance, @NotNull List<PhysicsCollisionObject> chunkMeshes) { | ||
|
||
// Wrap in scheduler to avoid "WARNING: invoked from wrong thread" | ||
instance.scheduleNextTick((i) -> { | ||
System.out.println("Physics space no longer null"); | ||
this.physicsSpace = new PhysicsSpace(PhysicsSpace.BroadphaseType.DBVT); | ||
|
||
// Default: -9.81f | ||
// Minecraft: -31.36f | ||
this.physicsSpace.setGravity(new Vector3f(0, -17f, 0)); | ||
|
||
for (PhysicsCollisionObject chunkMesh : chunkMeshes) { | ||
this.physicsSpace.add(chunkMesh); | ||
} | ||
}); | ||
|
||
instance.scheduler().buildTask(new Runnable() { | ||
long lastRan = System.nanoTime(); | ||
@Override | ||
public void run() { | ||
long diff = System.nanoTime() - lastRan; | ||
float deltaTime = diff / 1_000_000_000f; | ||
|
||
lastRan = System.nanoTime(); | ||
update(deltaTime); | ||
} | ||
}).delay(TaskSchedule.tick(1)).repeat(TaskSchedule.tick(1)).schedule(); | ||
} | ||
|
||
public void update(float delta) { | ||
if (physicsSpace == null) return; | ||
|
||
physicsSpace.update(delta); | ||
for (MinecraftPhysicsObject object : objects) { | ||
object.updateEntity(); | ||
} | ||
} | ||
|
||
public void cleanup() { | ||
if (physicsSpace == null) return; | ||
physicsSpace.destroy(); | ||
physicsSpace = null; | ||
} | ||
|
||
public void addObject(MinecraftPhysicsObject object) { | ||
objects.add(object); | ||
} | ||
|
||
public PhysicsSpace getPhysicsSpace() { | ||
return physicsSpace; | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
src/main/java/dev/emortal/minestom/parkourtag/physics/PlayerDisplayPart.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,34 @@ | ||
package dev.emortal.minestom.parkourtag.physics; | ||
|
||
import com.jme3.math.Vector3f; | ||
import dev.emortal.minestom.parkourtag.physics.objects.RagdollPhysics; | ||
|
||
public enum PlayerDisplayPart { | ||
HEAD(0, 9, RagdollPhysics.HEAD_SIZE), | ||
RIGHT_ARM(-1024, 12, RagdollPhysics.LIMB_SIZE), | ||
LEFT_ARM(-2048, 11, RagdollPhysics.LIMB_SIZE), | ||
TORSO(-3072, 4, RagdollPhysics.TORSO_SIZE), | ||
RIGHT_LEG(-4096, 12, RagdollPhysics.LIMB_SIZE), | ||
LEFT_LEG(-5120, 13, RagdollPhysics.LIMB_SIZE); | ||
|
||
private final double yTranslation; | ||
private final int customModelData; | ||
private final Vector3f size; | ||
PlayerDisplayPart(double yTranslation, int customModelData, Vector3f size) { | ||
this.yTranslation = yTranslation; | ||
this.customModelData = customModelData; | ||
this.size = size; | ||
} | ||
|
||
public double getYTranslation() { | ||
return yTranslation; | ||
} | ||
|
||
public int getCustomModelData() { | ||
return customModelData; | ||
} | ||
|
||
public Vector3f getSize() { | ||
return size; | ||
} | ||
} |
Oops, something went wrong.