Skip to content

Commit cff8007

Browse files
committed
Added GameProfile DataType, InterpolatedFloat, InterpolatedDouble, updated dependencies
1 parent bfb933f commit cff8007

File tree

11 files changed

+144
-11
lines changed

11 files changed

+144
-11
lines changed

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,7 @@ gradle-app.setting
112112
**/build/
113113

114114
# Common working directory
115-
run/
116-
run_server/
115+
runs/
117116

118117
# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
119118
!gradle-wrapper.jar

build.gradle

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ plugins {
55
id 'java'
66
id 'idea'
77
id 'maven-publish'
8-
id 'net.neoforged.moddev' version "2.0.91"
8+
id 'net.neoforged.moddev' version "2.0.106"
99
}
1010

1111
ext.ENV = System.getenv()
@@ -45,14 +45,14 @@ neoForge {
4545
}
4646

4747
jvmArguments.addAll("-XX:+IgnoreUnrecognizedVMOptions", "-XX:+AllowEnhancedClassRedefinition")
48-
gameDirectory = file 'run'
48+
gameDirectory = file 'runs/client'
4949
}
5050

5151
server {
5252
ideName = 'Server'
5353
server()
5454
programArgument("--nogui")
55-
gameDirectory = file 'run_server'
55+
gameDirectory = file 'runs/server'
5656
}
5757
}
5858

@@ -150,5 +150,28 @@ idea {
150150
module {
151151
downloadSources = true
152152
downloadJavadoc = true
153+
154+
["client", "server"].each {
155+
[
156+
"config",
157+
"crash-reports",
158+
"debug",
159+
"downloads",
160+
"flashback",
161+
"local",
162+
"logs",
163+
"mods",
164+
"pack-sync",
165+
"profilekeys",
166+
"saves",
167+
"voicechat_recordings",
168+
"command_history.txt",
169+
"options.txt",
170+
"server.properties",
171+
"world",
172+
].each { ext ->
173+
excludeDirs.add(file("runs/$it/$ext"))
174+
}
175+
}
153176
}
154177
}

gradle.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ mod_author=latvian.dev
1010

1111
mod_version=2105.1.0
1212

13-
neoforge_version=21.5.75
13+
neoforge_version=21.5.89
1414
neoForge.parchment.minecraftVersion=1.21.5
15-
neoForge.parchment.mappingsVersion=2025.06.01
15+
neoForge.parchment.mappingsVersion=2025.06.15

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12.1-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14-all.zip
44
networkTimeout=10000
55
validateDistributionUrl=true
66
zipStoreBase=GRADLE_USER_HOME

settings.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ pluginManagement {
99
}
1010

1111
plugins {
12-
id 'org.gradle.toolchains.foojay-resolver-convention' version '0.8.0'
12+
id 'org.gradle.toolchains.foojay-resolver-convention' version '1.0.0'
1313
}
1414

1515
rootProject.name = 'klib'

src/main/java/dev/latvian/mods/klib/codec/MCCodecs.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package dev.latvian.mods.klib.codec;
22

3+
import com.mojang.authlib.GameProfile;
34
import com.mojang.datafixers.util.Either;
45
import com.mojang.serialization.Codec;
6+
import com.mojang.serialization.codecs.RecordCodecBuilder;
57
import dev.latvian.mods.klib.math.KMath;
68
import net.minecraft.Util;
79
import net.minecraft.core.SectionPos;
@@ -30,4 +32,9 @@ public interface MCCodecs {
3032
Codec<SoundSource> SOUND_SOURCE = KLibCodecs.anyEnumCodec(SoundSource.values(), SoundSource::getName);
3133
Codec<BlockState> BLOCK_STATE = Codec.either(BlockState.CODEC, BuiltInRegistries.BLOCK.byNameCodec()).xmap(either -> either.map(Function.identity(), Block::defaultBlockState), state -> state == state.getBlock().defaultBlockState() ? Either.right(state.getBlock()) : Either.left(state));
3234
Codec<FluidState> FLUID_STATE = Codec.either(FluidState.CODEC, BuiltInRegistries.FLUID.byNameCodec()).xmap(either -> either.map(Function.identity(), Fluid::defaultFluidState), state -> state == state.getType().defaultFluidState() ? Either.right(state.getType()) : Either.left(state));
35+
36+
Codec<GameProfile> GAME_PROFILE = RecordCodecBuilder.create(instance -> instance.group(
37+
KLibCodecs.UUID.fieldOf("uuid").forGetter(GameProfile::getId),
38+
Codec.STRING.fieldOf("name").forGetter(GameProfile::getName)
39+
).apply(instance, GameProfile::new));
3340
}

src/main/java/dev/latvian/mods/klib/codec/MCStreamCodecs.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package dev.latvian.mods.klib.codec;
22

3+
import com.mojang.authlib.GameProfile;
34
import dev.latvian.mods.klib.math.KMath;
45
import dev.latvian.mods.klib.util.Empty;
56
import io.netty.buffer.ByteBuf;
@@ -104,4 +105,11 @@ public void encode(ByteBuf buf, CompoundTag value) {
104105
StreamCodec<ByteBuf, FluidState> FLUID_STATE = ByteBufCodecs.VAR_INT.map(Fluid.FLUID_STATE_REGISTRY::byId, Fluid.FLUID_STATE_REGISTRY::getId);
105106

106107
StreamCodec<ByteBuf, ResourceKey<Level>> DIMENSION = KLibStreamCodecs.resourceKey(Registries.DIMENSION);
108+
109+
StreamCodec<ByteBuf, GameProfile> GAME_PROFILE = CompositeStreamCodec.of(
110+
KLibStreamCodecs.UUID, GameProfile::getId,
111+
ByteBufCodecs.STRING_UTF8, GameProfile::getName,
112+
GameProfile::new
113+
);
114+
107115
}

src/main/java/dev/latvian/mods/klib/data/DataType.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,7 @@ public static <C, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T
424424
private final Class<T> typeClass;
425425
private DataType<List<T>> listType;
426426
private DataType<Set<T>> setType;
427+
private DataType<?> componentType;
427428

428429
private DataType(Codec<T> codec, StreamCodec<? super RegistryFriendlyByteBuf, T> streamCodec, Class<T> typeClass) {
429430
this.codec = codec;
@@ -458,6 +459,7 @@ public <C> DataTypeField<C, T> optionalField(String name, Function<C, T> getter,
458459
public DataType<List<T>> listOf() {
459460
if (listType == null) {
460461
listType = of(codec.listOf(), KLibStreamCodecs.listOf(streamCodec), Cast.to(List.class));
462+
listType.componentType = this;
461463
}
462464

463465
return listType;
@@ -466,11 +468,17 @@ public DataType<List<T>> listOf() {
466468
public DataType<Set<T>> setOf() {
467469
if (setType == null) {
468470
setType = of(KLibCodecs.setOf(codec), KLibStreamCodecs.setOf(streamCodec), Cast.to(Set.class));
471+
setType.componentType = this;
469472
}
470473

471474
return setType;
472475
}
473476

477+
@Nullable
478+
public DataType<?> getComponentType() {
479+
return componentType;
480+
}
481+
474482
@Nullable
475483
public Number toNumber(T value) {
476484
return switch (value) {
@@ -491,7 +499,9 @@ public Number toNumber(T value) {
491499
};
492500
}
493501

494-
public <R> DataType<R> map(Function<T, R> mapper, Function<R, T> reverseMapper, Class<R> typeClass) {
495-
return of(codec.xmap(mapper, reverseMapper), streamCodec.map(mapper, reverseMapper), typeClass);
502+
@Nullable
503+
public ResourceLocation getId() {
504+
var t = RegisteredDataType.BY_TYPE.get(this);
505+
return t == null ? null : t.id();
496506
}
497507
}

src/main/java/dev/latvian/mods/klib/data/DataTypes.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package dev.latvian.mods.klib.data;
22

3+
import com.mojang.authlib.GameProfile;
34
import com.mojang.brigadier.arguments.BoolArgumentType;
45
import com.mojang.brigadier.arguments.DoubleArgumentType;
56
import com.mojang.brigadier.arguments.FloatArgumentType;
@@ -16,6 +17,8 @@
1617
import dev.latvian.mods.klib.color.Gradient;
1718
import dev.latvian.mods.klib.easing.Easing;
1819
import dev.latvian.mods.klib.easing.EasingGroup;
20+
import dev.latvian.mods.klib.math.InterpolatedDouble;
21+
import dev.latvian.mods.klib.math.InterpolatedFloat;
1922
import dev.latvian.mods.klib.math.Line;
2023
import dev.latvian.mods.klib.math.MovementType;
2124
import dev.latvian.mods.klib.math.Range;
@@ -25,6 +28,8 @@
2528
import dev.latvian.mods.klib.util.IntOrUUID;
2629
import dev.latvian.mods.klib.util.ParsedEntitySelector;
2730
import net.minecraft.commands.arguments.ComponentArgument;
31+
import net.minecraft.commands.arguments.DimensionArgument;
32+
import net.minecraft.commands.arguments.GameProfileArgument;
2833
import net.minecraft.commands.arguments.ParticleArgument;
2934
import net.minecraft.commands.arguments.ResourceLocationArgument;
3035
import net.minecraft.commands.arguments.UuidArgument;
@@ -37,13 +42,17 @@
3742
import net.minecraft.core.Holder;
3843
import net.minecraft.core.particles.ParticleOptions;
3944
import net.minecraft.core.particles.ParticleTypes;
45+
import net.minecraft.core.registries.Registries;
4046
import net.minecraft.network.chat.Component;
4147
import net.minecraft.network.chat.ComponentSerialization;
4248
import net.minecraft.network.codec.ByteBufCodecs;
49+
import net.minecraft.resources.ResourceKey;
50+
import net.minecraft.resources.ResourceLocation;
4351
import net.minecraft.sounds.SoundEvent;
4452
import net.minecraft.sounds.SoundSource;
4553
import net.minecraft.world.InteractionHand;
4654
import net.minecraft.world.item.ItemStack;
55+
import net.minecraft.world.level.Level;
4756
import net.minecraft.world.level.block.Mirror;
4857
import net.minecraft.world.level.block.Rotation;
4958
import net.minecraft.world.level.block.state.BlockState;
@@ -81,6 +90,8 @@ public interface DataTypes {
8190
DataType<Vec3> VEC3S = DataType.of(MCCodecs.VEC3S, MCStreamCodecs.VEC3S, Vec3.class);
8291
DataType<BlockPos> BLOCK_POS = DataType.of(BlockPos.CODEC, BlockPos.STREAM_CODEC, BlockPos.class);
8392
DataType<Integer> TICKS = DataType.of(KLibCodecs.TICKS, ByteBufCodecs.VAR_INT, Integer.class);
93+
DataType<GameProfile> GAME_PROFILE = DataType.of(MCCodecs.GAME_PROFILE, MCStreamCodecs.GAME_PROFILE, GameProfile.class);
94+
DataType<ResourceKey<Level>> DIMENSION = DataType.of(MCCodecs.DIMENSION, MCStreamCodecs.DIMENSION, (Class) ResourceKey.class);
8495

8596
static void register() {
8697
DataType.register(ID.java("bool"), BOOL, BoolArgumentType::bool, BoolArgumentType::getBool);
@@ -109,6 +120,11 @@ static void register() {
109120
DataType.register(ID.mc("vec3s"), VEC3S, () -> Vec3Argument.vec3(), Vec3Argument::getVec3);
110121
DataType.register(ID.mc("block_pos"), BLOCK_POS, BlockPosArgument::blockPos, BlockPosArgument::getBlockPos);
111122
DataType.register(ID.mc("ticks"), TICKS, () -> KLibCodecs.TIME_ARGUMENT, IntegerArgumentType::getInteger);
123+
DataType.register(ID.mc("game_profile"), GAME_PROFILE, GameProfileArgument::gameProfile, (ctx, name) -> {
124+
var profiles = GameProfileArgument.getGameProfiles(ctx, name);
125+
return profiles.isEmpty() ? null : profiles.iterator().next();
126+
});
127+
DataType.register(ID.mc("dimension"), DIMENSION, DimensionArgument::dimension, (ctx, name) -> ResourceKey.create(Registries.DIMENSION, ctx.getArgument(name, ResourceLocation.class)));
112128

113129
DataType.register(KLibMod.id("color"), Color.DATA_TYPE);
114130
DataType.register(KLibMod.id("gradient"), Gradient.DATA_TYPE);
@@ -125,5 +141,7 @@ static void register() {
125141
DataType.register(KLibMod.id("easing_group"), EasingGroup.DATA_TYPE);
126142
DataType.register(KLibMod.id("int_or_uuid"), IntOrUUID.DATA_TYPE);
127143
DataType.register(KLibMod.id("line"), Line.DATA_TYPE);
144+
DataType.register(KLibMod.id("interpolated_float"), InterpolatedFloat.DATA_TYPE);
145+
DataType.register(KLibMod.id("interpolated_double"), InterpolatedDouble.DATA_TYPE);
128146
}
129147
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package dev.latvian.mods.klib.math;
2+
3+
import com.mojang.serialization.Codec;
4+
import com.mojang.serialization.codecs.RecordCodecBuilder;
5+
import dev.latvian.mods.klib.codec.CompositeStreamCodec;
6+
import dev.latvian.mods.klib.data.DataType;
7+
import net.minecraft.network.codec.ByteBufCodecs;
8+
9+
public record InterpolatedDouble(long start, long end, double from, double to) {
10+
public static final InterpolatedDouble DEFAULT = new InterpolatedDouble(0L, 0L, 0D, 0D);
11+
12+
public static final DataType<InterpolatedDouble> DATA_TYPE = DataType.of(RecordCodecBuilder.create(instance -> instance.group(
13+
Codec.LONG.fieldOf("start").forGetter(InterpolatedDouble::start),
14+
Codec.LONG.fieldOf("end").forGetter(InterpolatedDouble::end),
15+
Codec.DOUBLE.fieldOf("from").forGetter(InterpolatedDouble::from),
16+
Codec.DOUBLE.fieldOf("to").forGetter(InterpolatedDouble::to)
17+
).apply(instance, InterpolatedDouble::new)), CompositeStreamCodec.of(
18+
ByteBufCodecs.VAR_LONG, InterpolatedDouble::start,
19+
ByteBufCodecs.VAR_LONG, InterpolatedDouble::end,
20+
ByteBufCodecs.DOUBLE, InterpolatedDouble::from,
21+
ByteBufCodecs.DOUBLE, InterpolatedDouble::to,
22+
InterpolatedDouble::new
23+
), InterpolatedDouble.class);
24+
25+
public double get(long now, double delta) {
26+
if (now > end) {
27+
return to;
28+
} else if (now < start) {
29+
return from;
30+
}
31+
32+
return KMath.clerp(((now - start - 1L) + delta) / (double) (end - start), from, to);
33+
}
34+
}

0 commit comments

Comments
 (0)