Skip to content

Commit ef6567f

Browse files
committed
Merge branch 'master' into feature/renderer
2 parents 991d9a1 + 71934cb commit ef6567f

File tree

75 files changed

+1558
-537
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+1558
-537
lines changed

build.gradle.kts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
22
import net.fabricmc.loom.task.RemapJarTask
3+
import java.util.*
4+
5+
val targets = listOf("META-INF/*.toml", "fabric.mod.json")
6+
val replacements = file("gradle.properties").inputStream().use { stream ->
7+
Properties().apply { load(stream) }
8+
}.map { (k, v) -> k.toString() to v.toString() }.toMap()
39

410
val modId = property("mod_id").toString()
511
val modVersion = property("mod_version").toString()
@@ -13,7 +19,7 @@ plugins {
1319
kotlin("jvm") version "1.9.23"
1420
id("org.jetbrains.dokka") version "1.9.20"
1521
id("architectury-plugin") version "3.4-SNAPSHOT"
16-
id("dev.architectury.loom") version "1.5-SNAPSHOT" apply false
22+
id("dev.architectury.loom") version "1.6-SNAPSHOT" apply false
1723
id("com.github.johnrengelman.shadow") version "8.1.1" apply false
1824
}
1925

@@ -30,15 +36,12 @@ subprojects {
3036
"mappings"("net.fabricmc:yarn:$yarnMappings:v2")
3137
}
3238

33-
repositories {
34-
maven("https://babbaj.github.io/maven/")
35-
}
36-
3739
if (path == ":common") return@subprojects
3840

3941
apply(plugin = "com.github.johnrengelman.shadow")
4042

4143
val versionWithMCVersion = "$modVersion+$minecraftVersion"
44+
4245
tasks {
4346
val shadowCommon by configurations.creating {
4447
isCanBeConsumed = false
@@ -61,6 +64,13 @@ subprojects {
6164
jar {
6265
enabled = false
6366
}
67+
68+
processResources {
69+
// Replaces placeholders in the mod info files
70+
filesMatching(targets) {
71+
expand(replacements)
72+
}
73+
}
6474
}
6575
}
6676

@@ -79,7 +89,9 @@ allprojects {
7989
maven("https://jitpack.io")
8090
maven("https://maven.shedaniel.me/") { name = "Architectury" }
8191
maven("https://maven.terraformersmc.com/releases/")
92+
maven("https://babbaj.github.io/maven/")
8293

94+
// Allow the use of local libraries
8395
flatDir {
8496
dirs(libs)
8597
}

common/build.gradle.kts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1-
import java.util.Properties
2-
31
val fabricLoaderVersion = property("fabric_loader_version").toString()
42
val mixinExtrasVersion = property("mixinextras_version").toString()
53
val kotlinVersion = property("kotlin_version").toString()
64
val kotlinxCoroutinesVersion = property("kotlinx_coroutines_version").toString()
75

8-
architectury { common("fabric", "forge", "neoforge", "quilt") }
6+
architectury { common("fabric", "forge", "neoforge") }
97

108
loom {
119
silentMojangMappingsLicense()
12-
accessWidenerPath.set(File("src/main/resources/lambda.accesswidener"))
10+
accessWidenerPath = File("src/main/resources/lambda.accesswidener")
1311
}
1412

1513
repositories {
@@ -33,16 +31,9 @@ dependencies {
3331
}
3432

3533
tasks {
34+
// Prevent recursive libraries
3635
remapJar {
3736
enabled = false
3837
}
39-
40-
processResources {
41-
Properties().apply {
42-
load(project.rootProject.file("gradle.properties").inputStream())
43-
}.forEach { key, value ->
44-
inputs.property(key.toString(), value)
45-
}
46-
}
4738
}
4839

common/src/main/java/com/lambda/mixin/entity/ClientPlayerEntityMixin.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ void processMovement(Input input, boolean slowDown, float slowDownFactor) {
6161
EventFlow.post(new MovementEvent.InputUpdate(input, slowDown, slowDownFactor));
6262
}
6363

64+
@Redirect(method = "tickMovement", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;isSprinting()Z"))
65+
boolean isSprinting(ClientPlayerEntity entity) {
66+
return EventFlow.post(new MovementEvent.Sprint(entity.isSprinting())).getSprint();
67+
}
68+
6469
@Inject(method = "sendMovementPackets", at = @At(value = "HEAD"), cancellable = true)
6570
void sendBegin(CallbackInfo ci) {
6671
ci.cancel();
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
/*
2+
* Copyright 2023 The Quilt Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
/*
18+
* Preserve binary compatibility when moving extensions between files
19+
*/
20+
@file:JvmMultifileClass
21+
@file:JvmName("ArgumentsKt")
22+
23+
package com.lambda.brigadier.argument
24+
25+
import com.lambda.brigadier.*
26+
import com.lambda.brigadier.assumeSourceNotUsed
27+
import com.mojang.brigadier.arguments.ArgumentType
28+
import com.mojang.brigadier.arguments.IntegerArgumentType
29+
30+
import com.mojang.brigadier.builder.LiteralArgumentBuilder
31+
import net.minecraft.command.argument.TimeArgumentType
32+
import net.minecraft.command.argument.UuidArgumentType
33+
import java.util.*
34+
35+
/**
36+
* Descriptor for a literal argument.
37+
*
38+
* Separate from [DefaultArgumentDescriptor]
39+
* to stand out more in type hints.
40+
*/
41+
object LiteralDescriptor : ArgumentDescriptor<ArgumentType<*>>
42+
43+
/**
44+
* Reads the integer value in ticks from the
45+
* argument in the receiver [ArgumentReader].
46+
*/
47+
@JvmName("valueTimeArg")
48+
@BrigadierDsl
49+
fun DefaultArgumentReader<TimeArgumentType>.value(): Int {
50+
return IntegerArgumentType.getInteger(context, name)
51+
} // TimeArgumentType does not provide an accessor, defaulting to int
52+
53+
/**
54+
* Reads the [UUID] value from the
55+
* argument in the receiver [ArgumentReader].
56+
*
57+
* @see UuidArgumentType.getUuid
58+
*/
59+
@JvmName("valueUuidArg")
60+
@BrigadierDsl
61+
fun DefaultArgumentReader<UuidArgumentType>.value(): UUID {
62+
return UuidArgumentType.getUuid(context.assumeSourceNotUsed(), name)
63+
}
64+
65+
/**
66+
* Creates a time argument with [name] as the parameter name.
67+
*
68+
* @see TimeArgumentType.time
69+
*/
70+
@BrigadierDsl
71+
fun <S> time(
72+
name: String,
73+
minimumTicks: Int = 0
74+
): DefaultArgumentConstructor<S, TimeArgumentType> {
75+
return argument(name, TimeArgumentType.time(minimumTicks))
76+
}
77+
78+
/**
79+
* Creates a UUID argument with [name] as the parameter name.
80+
*/
81+
@BrigadierDsl
82+
fun <S> uuid(
83+
name: String
84+
): RequiredArgumentConstructor<
85+
S,
86+
DefaultArgumentDescriptor<
87+
UuidArgumentType>
88+
> {
89+
return argument(name, UuidArgumentType.uuid())
90+
}
91+
92+
/**
93+
* Creates a literal argument with [name] as the literal.
94+
*
95+
* Like other arguments, literal arguments create accessors,
96+
* which can be checked for presence of [optional] literals.
97+
* However, [ArgumentReader]s produced from those accessors
98+
* serve no purpose due to the argument not having a value.
99+
*/
100+
@BrigadierDsl
101+
fun <S> literal(
102+
name: String
103+
): ArgumentConstructor<
104+
S,
105+
LiteralArgumentBuilder<S>,
106+
LiteralDescriptor
107+
> {
108+
return ArgumentConstructor(LiteralArgumentBuilder.literal(name), name, LiteralDescriptor)
109+
}

common/src/main/kotlin/com/lambda/command/CommandManager.kt

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,9 @@ object CommandManager : Configurable(LambdaConfig), Loadable {
3131
val prefix by setting("prefix", ';')
3232

3333
val commands = mutableSetOf<LambdaCommand>()
34-
private val dispatcher by lazy { CommandDispatcher<CommandSource>() }
34+
val dispatcher by lazy { CommandDispatcher<CommandSource>() }
3535
private const val ERROR_PADDING = 10
3636

37-
fun register(
38-
command: String,
39-
vararg alias: String,
40-
action: LiteralArgumentBuilder<CommandSource>.() -> Unit,
41-
) {
42-
(listOf(command) + alias).forEach {
43-
dispatcher.register(it, action)
44-
}
45-
}
46-
4737
fun executeCommand(command: String) {
4838
runSafe {
4939
val isolatedCommand = command.drop(1)
Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,25 @@
11
package com.lambda.command
22

3+
import com.lambda.command.CommandManager.dispatcher
34
import com.lambda.util.Nameable
5+
import com.lambda.util.primitives.extension.CommandBuilder
6+
import com.mojang.brigadier.builder.LiteralArgumentBuilder
7+
import net.minecraft.command.CommandSource
48

5-
interface LambdaCommand : Nameable
9+
abstract class LambdaCommand(
10+
final override val name: String,
11+
val aliases: Set<String> = emptySet(),
12+
val usage: String = "",
13+
val description: String = "",
14+
) : Nameable {
15+
// ToDo: Include usage and description in the help command
16+
init {
17+
(listOf(name) + aliases).forEach {
18+
val argument = LiteralArgumentBuilder.literal<CommandSource>(it)
19+
argument.create()
20+
dispatcher.register(argument)
21+
}
22+
}
23+
24+
abstract fun CommandBuilder.create()
25+
}

common/src/main/kotlin/com/lambda/command/commands/ConfigCommand.kt

Lines changed: 20 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,30 @@
11
package com.lambda.command.commands
22

3-
import com.lambda.brigadier.CommandResult.Companion.failure
4-
import com.lambda.brigadier.CommandResult.Companion.success
5-
import com.lambda.brigadier.argument.string
6-
import com.lambda.brigadier.argument.value
7-
import com.lambda.brigadier.argument.word
8-
import com.lambda.brigadier.executeWithResult
9-
import com.lambda.brigadier.optional
3+
import com.lambda.brigadier.argument.literal
4+
import com.lambda.brigadier.execute
105
import com.lambda.brigadier.required
11-
import com.lambda.command.CommandManager.register
126
import com.lambda.command.LambdaCommand
137
import com.lambda.config.Configuration
8+
import com.lambda.util.primitives.extension.CommandBuilder
149

15-
object ConfigCommand : LambdaCommand {
16-
override val name = "config"
17-
18-
init {
19-
register(name, "cfg") {
20-
required(word("action")) { action ->
21-
val actions = listOf("save", "load")
22-
23-
suggests { _, builder ->
24-
actions.forEach {
25-
builder.suggest(it)
26-
}
27-
builder.buildFuture()
10+
object ConfigCommand : LambdaCommand(
11+
name = "config",
12+
aliases = setOf("cfg"),
13+
usage = "config <save|load>",
14+
description = "Save or load the configuration files"
15+
) {
16+
override fun CommandBuilder.create() {
17+
required(literal("save")) {
18+
execute {
19+
Configuration.configurations.forEach {
20+
it.trySave()
2821
}
29-
30-
executeWithResult {
31-
val action = action().value()
32-
if (action !in actions) {
33-
return@executeWithResult failure("Invalid action $action. Did you mean ${actions.joinToString()}?")
34-
}
35-
36-
Configuration.configurations.forEach {
37-
when (action) {
38-
"save" -> it.trySave()
39-
else -> it.tryLoad()
40-
}
41-
}
42-
43-
success()
22+
}
23+
}
24+
required(literal("load")) {
25+
execute {
26+
Configuration.configurations.forEach {
27+
it.tryLoad()
4428
}
4529
}
4630
}

0 commit comments

Comments
 (0)