Skip to content

Commit

Permalink
feat: RailroadPlayer, refactors
Browse files Browse the repository at this point in the history
  • Loading branch information
andantet committed Nov 16, 2024
1 parent 84573ca commit 2d51524
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 33 deletions.
15 changes: 0 additions & 15 deletions src/main/java/net/mcbrawls/railroad/mixin/ExampleMixin.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package net.mcbrawls.railroad.mixin;

import com.mojang.authlib.GameProfile;
import net.mcbrawls.railroad.player.RailroadPlayer;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;

@Mixin(ServerPlayerEntity.class)
public abstract class ServerPlayerEntityMixin extends PlayerEntity implements RailroadPlayer {
private ServerPlayerEntityMixin(World world, BlockPos pos, float yaw, GameProfile gameProfile) {
super(world, pos, yaw, gameProfile);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package net.mcbrawls.railroad.player;

public interface RailroadPlayer {
}
11 changes: 9 additions & 2 deletions src/main/kotlin/net/mcbrawls/railroad/CameraTrack.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,25 @@ package net.mcbrawls.railroad

import com.mojang.serialization.Codec
import com.mojang.serialization.codecs.RecordCodecBuilder
import net.mcbrawls.railroad.codec.ExtraCodecs
import kotlin.time.Duration

/**
* A camera track which can be played to a player.
*/
data class CameraTrack(
val keyframes: List<TrackKeyframe>,
) {
/**
* The total duration of the track.
*/
val duration: Duration = keyframes.lastOrNull()?.time ?: Duration.ZERO

data class TrackKeyframe(
/**
* The time at which the keyframe is played on the track.
*/
val seconds: Float,
val time: Duration,

/**
* The keyframe to be played.
Expand All @@ -26,7 +33,7 @@ data class CameraTrack(
*/
val CODEC: Codec<TrackKeyframe> = RecordCodecBuilder.create { instance ->
instance.group(
Codec.FLOAT.fieldOf("seconds").forGetter(TrackKeyframe::seconds),
ExtraCodecs.DURATION.fieldOf("time").forGetter(TrackKeyframe::time),
Keyframe.CODEC.fieldOf("keyframe").forGetter(TrackKeyframe::keyframe),
).apply(instance, ::TrackKeyframe)
}
Expand Down
5 changes: 3 additions & 2 deletions src/main/kotlin/net/mcbrawls/railroad/Keyframe.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package net.mcbrawls.railroad

import com.mojang.serialization.Codec
import com.mojang.serialization.codecs.RecordCodecBuilder
import net.mcbrawls.railroad.codec.ExtraCodecs
import org.joml.Vector2f
import org.joml.Vector3d

Expand All @@ -18,8 +19,8 @@ data class Keyframe(
*/
val CODEC: Codec<Keyframe> = RecordCodecBuilder.create { instance ->
instance.group(
Vectors.VECTOR_3D.fieldOf("position").forGetter(Keyframe::pos),
Vectors.VECTOR_2F.fieldOf("rotation").forGetter(Keyframe::rotation),
ExtraCodecs.VECTOR_3D.fieldOf("position").forGetter(Keyframe::pos),
ExtraCodecs.VECTOR_2F.fieldOf("rotation").forGetter(Keyframe::rotation),
).apply(instance, ::Keyframe)
}
}
Expand Down
11 changes: 0 additions & 11 deletions src/main/kotlin/net/mcbrawls/railroad/Vectors.kt
Original file line number Diff line number Diff line change
@@ -1,20 +1,9 @@
package net.mcbrawls.railroad

import com.mojang.serialization.Codec
import org.joml.Vector2f
import org.joml.Vector3d

object Vectors {
val VECTOR_3D: Codec<Vector3d> = Codec.DOUBLE.listOf().xmap(
{ list -> Vector3d(list[0], list[1], list[2]) },
{ vect -> listOf(vect.x, vect.y, vect.z) }
)

val VECTOR_2F: Codec<Vector2f> = Codec.FLOAT.listOf().xmap(
{ list -> Vector2f(list[0], list[1]) },
{ vect -> listOf(vect.x, vect.y) }
)

fun Vector3d.cubicInterpolate(end: Vector3d, delta: Float): Vector3d {
val start = this

Expand Down
20 changes: 20 additions & 0 deletions src/main/kotlin/net/mcbrawls/railroad/codec/ExtraCodecs.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package net.mcbrawls.railroad.codec

import com.mojang.serialization.Codec
import org.joml.Vector2f
import org.joml.Vector3d
import kotlin.time.Duration

object ExtraCodecs {
val VECTOR_3D: Codec<Vector3d> = Codec.DOUBLE.listOf().xmap(
{ list -> Vector3d(list[0], list[1], list[2]) },
{ vect -> listOf(vect.x, vect.y, vect.z) }
)

val VECTOR_2F: Codec<Vector2f> = Codec.FLOAT.listOf().xmap(
{ list -> Vector2f(list[0], list[1]) },
{ vect -> listOf(vect.x, vect.y) }
)

val DURATION: Codec<Duration> = Codec.STRING.xmap(Duration::parse, Duration::toString)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package net.mcbrawls.railroad.player

import net.mcbrawls.railroad.CameraTrack

class HandledCameraTrack(val cameraTrack: CameraTrack) {
//
}
2 changes: 1 addition & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"custom": {
"loom:injected_interfaces": {
"net/minecraft/class_3222": [
"net/mcbrawls/railroad/RailroadPlayer"
"net/mcbrawls/railroad/player/RailroadPlayer"
]
}
},
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/railroad.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"package": "net.mcbrawls.railroad.mixin",
"compatibilityLevel": "JAVA_21",
"mixins": [
"ExampleMixin"
"ServerPlayerEntityMixin"
],
"injectors": {
"defaultRequire": 1
}
}
}

0 comments on commit 2d51524

Please sign in to comment.