Skip to content

Commit 743911b

Browse files
committed
Merge branch 'master' into feature/combat
2 parents 0b6eff3 + bed66e9 commit 743911b

File tree

30 files changed

+931
-746
lines changed

30 files changed

+931
-746
lines changed

.github/CONTRIBUTING.md

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -103,18 +103,7 @@ First of all, make sure to read or simply check the [Official Kotlin Coding Conv
103103

104104
This is required for pull requests to be accepted, or even reviewed.
105105

106-
You will need the following before contributing:
107-
- GitHub CLI / Desktop
108-
- IntelliJ IDEA
109-
- Java 17 SDK
110-
- [Minecraft Development Plugin](https://plugins.jetbrains.com/plugin/8327-minecraft-development)
111-
112-
After you have everything you can do the following:
113-
- Clone the repository `git clone https://github.com/lambda-client/lambda`
114-
- Open the project, **inside the project folder**, in IntelliJ IDEA
115-
- Set the java runtime in `File > Project Structure > SDK > JDK 17`
116-
- Wait for Gradle to resolve dependencies and to set up the project.
117-
- And you should now be able to run the project using the [run configurations](https://www.jetbrains.com/help/idea/run-debug-configuration.html)
106+
After this, you can read the [getting started](https://github.com/lambda-client/wiki/Getting-Started) section in the wiki
118107

119108
### Improving The Documentation
120109
If you believe that some documentation can be improved or added, please discuss with us on our [Discord](https://discord.gg/QjfBxJzE5x)

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,35 @@
11
# Pull Request Guidelines
2+
23
### This is a template, modify before submitting your PR
34

45
Please ensure that your PR title follows this format:
5-
- `[Minecraft Version] [Mod loader] Feat, Fix, Ref, Docs, ..., : Description`
6+
- `[Minecraft Version] <Mod loader> Feat, Fix, Ref, Docs, ..., : Description`
67

78
**Examples:**
8-
- `[1.20.x] [Forge] Feat: Add new block types`
9-
- `[1.19.x] [All] Fix: Crash on startup`
10-
- `[1.20.x] [Fabric] Refactor: Optimize rendering engine`
9+
- `[1.20.4] Feat: Add new block types`
10+
- `[1.21.4] [All] Fix: Crash on startup`
11+
- `[1.21.3] [Forge] Fix: GUI does not render`
12+
- `[1.20.1] Ref: Optimize rendering engine`
1113

12-
# Issue Link
13-
Please create an issue if there are none applicable before submitting this pull request.
14+
### Issue Link
15+
If your PR addresses one or more issues, be sure to link them. Use appropriate keywords like `closes`, `fixes`, or `resolves` to automatically close the linked issues when the PR is merged.
1416

15-
Then link the issue as follows:`Closes #123`
17+
#### **Examples:**
18+
- `This PR fixes a memory leak in foo() and closes #4. It also resolves #5, which is a duplicate issue.`
19+
- `Closes #1, resolves #2, and fixes #3`
20+
- `Fixes #1`
1621

17-
# Description
22+
### Description
23+
Provide a concise yet detailed summary of the changes introduced in this PR. Include the purpose of the changes and any relevant context.
1824

19-
Provide a brief description of the changes made in this PR:
25+
#### **Examples:**
26+
- `This pull request improves compatibility with version 1.21.4 by addressing rendering issues and adding support for new block types.`
27+
- `Refactors the rendering engine to enhance performance and reduce memory usage.`
28+
- `Adds a new feature for biome-specific block spawning to align with gameplay mechanics introduced in version 1.20.4.`
2029

21-
- **What does this PR do?**
22-
- **Why is this change needed?**
30+
### Checklist Before Submitting
31+
To ensure the quality and maintainability of your PR, confirm the following before submission:
32+
1. Code adheres to the project's style guide and conventions.
33+
2. All tests pass, including newly added tests.
34+
3. Documentation has been updated to reflect any new features or changes.
35+
4. Your PR is limited to a single purpose, avoiding unrelated changes.

common/src/main/kotlin/com/lambda/config/AbstractSetting.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,4 +127,7 @@ abstract class AbstractSetting<T : Any>(
127127
class ValueListener<T>(val requiresValueChange: Boolean, val execute: (from: T, to: T) -> Unit)
128128

129129
override fun toString() = "Setting $name: $value of type ${type.typeName}"
130+
131+
override fun equals(other: Any?) = other is AbstractSetting<*> && name == other.name
132+
override fun hashCode() = name.hashCode()
130133
}

common/src/main/kotlin/com/lambda/config/Configurable.kt

Lines changed: 22 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,15 @@ abstract class Configurable(
5555
val settings = mutableSetOf<AbstractSetting<*>>()
5656

5757
init {
58-
register()
58+
registerConfigurable()
5959
}
6060

61-
private fun register() = configuration.configurables.add(this)
61+
private fun registerConfigurable() = configuration.configurables.add(this)
62+
63+
inline fun <reified T : AbstractSetting<*>> T.register(): T {
64+
check(settings.add(this)) { "Setting with name $name already exists for configurable: ${this@Configurable.name}" }
65+
return this
66+
}
6267

6368
override fun toJson() =
6469
JsonObject().apply {
@@ -99,9 +104,7 @@ abstract class Configurable(
99104
defaultValue: Boolean,
100105
description: String = "",
101106
visibility: () -> Boolean = { true },
102-
) = BooleanSetting(name, defaultValue, description, visibility).also {
103-
settings.add(it)
104-
}
107+
) = BooleanSetting(name, defaultValue, description, visibility).register()
105108

106109
/**
107110
* Creates an [EnumSetting] with the provided parameters and adds it to the [settings].
@@ -124,9 +127,7 @@ abstract class Configurable(
124127
defaultValue: T,
125128
description: String = "",
126129
noinline visibility: () -> Boolean = { true },
127-
) = EnumSetting(name, defaultValue, description, visibility).also {
128-
settings.add(it)
129-
}
130+
) = EnumSetting(name, defaultValue, description, visibility).register()
130131

131132
/**
132133
* Creates a [CharSetting] with the provided parameters and adds it to the [settings].
@@ -143,9 +144,7 @@ abstract class Configurable(
143144
defaultValue: Char,
144145
description: String = "",
145146
visibility: () -> Boolean = { true },
146-
) = CharSetting(name, defaultValue, description, visibility).also {
147-
settings.add(it)
148-
}
147+
) = CharSetting(name, defaultValue, description, visibility).register()
149148

150149
/**
151150
* Creates a [StringSetting] with the provided parameters and adds it to the [settings].
@@ -166,9 +165,7 @@ abstract class Configurable(
166165
defaultValue: String,
167166
description: String = "",
168167
visibility: () -> Boolean = { true },
169-
) = StringSetting(name, defaultValue, description, visibility).also {
170-
settings.add(it)
171-
}
168+
) = StringSetting(name, defaultValue, description, visibility).register()
172169

173170
/**
174171
* Constructs a [ListSetting] instance with the specified parameters and appends it to the [settings] collection.
@@ -193,17 +190,13 @@ abstract class Configurable(
193190
defaultValue: List<T>,
194191
description: String = "",
195192
noinline visibility: () -> Boolean = { true },
196-
hackDelegates: Boolean = false,
197193
) = ListSetting(
198194
name,
199195
defaultValue.toMutableList(),
200196
TypeToken.getParameterized(MutableList::class.java, T::class.java).type,
201197
description,
202-
hackDelegates,
203198
visibility,
204-
).also {
205-
settings.add(it)
206-
}
199+
).register()
207200

208201
/**
209202
* Constructs a [MapSetting] instance with the specified parameters and appends it to the [settings] collection.
@@ -227,18 +220,14 @@ abstract class Configurable(
227220
name: String,
228221
defaultValue: Map<K, V>,
229222
description: String = "",
230-
hackDelegates: Boolean,
231223
noinline visibility: () -> Boolean = { true },
232224
) = MapSetting(
233225
name,
234226
defaultValue.toMutableMap(),
235227
TypeToken.getParameterized(MutableMap::class.java, K::class.java, V::class.java).type,
236228
description,
237-
hackDelegates,
238229
visibility
239-
).also {
240-
settings.add(it)
241-
}
230+
).register()
242231

243232
/**
244233
* Constructs a [SetSetting] instance with the specified parameters and appends it to the [settings] collection.
@@ -268,36 +257,7 @@ abstract class Configurable(
268257
TypeToken.getParameterized(MutableSet::class.java, T::class.java).type,
269258
description,
270259
visibility,
271-
).also {
272-
settings.add(it)
273-
}
274-
275-
/**
276-
* Creates a [ByteSetting] with the provided parameters and adds it to the [settings].
277-
*
278-
* The value of the setting is coerced into the specified [range] and rounded to the nearest [step].
279-
*
280-
* @param name The unique identifier for the setting.
281-
* @param defaultValue The default [Byte] value of the setting.
282-
* @param range The range within which the setting's value must fall.
283-
* @param step The step to which the setting's value is rounded.
284-
* @param description A brief explanation of the setting's purpose and behavior.
285-
* @param visibility A lambda expression that determines the visibility status of the setting.
286-
* @param unit The unit of the setting. E.g. "°C", "m/s", "ms", "ticks", etc.
287-
*
288-
* @return The created [ByteSetting].
289-
*/
290-
fun setting(
291-
name: String,
292-
defaultValue: Byte,
293-
range: ClosedRange<Byte>,
294-
step: Byte = 1,
295-
description: String = "",
296-
unit: String = "",
297-
visibility: () -> Boolean = { true },
298-
) = ByteSetting(name, defaultValue, range, step, description, visibility, unit).also {
299-
settings.add(it)
300-
}
260+
).register()
301261

302262
/**
303263
* Creates a [DoubleSetting] with the provided parameters and adds it to the [settings].
@@ -322,9 +282,7 @@ abstract class Configurable(
322282
description: String = "",
323283
unit: String = "",
324284
visibility: () -> Boolean = { true },
325-
) = DoubleSetting(name, defaultValue, range, step, description, visibility, unit).also {
326-
settings.add(it)
327-
}
285+
) = DoubleSetting(name, defaultValue, range, step, description, visibility, unit).register()
328286

329287
/**
330288
* Creates a [FloatSetting] with the provided parameters and adds it to the [settings].
@@ -349,9 +307,7 @@ abstract class Configurable(
349307
description: String = "",
350308
unit: String = "",
351309
visibility: () -> Boolean = { true },
352-
) = FloatSetting(name, defaultValue, range, step, description, visibility, unit).also {
353-
settings.add(it)
354-
}
310+
) = FloatSetting(name, defaultValue, range, step, description, visibility, unit).register()
355311

356312
/**
357313
* Creates an [IntegerSetting] with the provided parameters and adds it to the [settings].
@@ -376,9 +332,7 @@ abstract class Configurable(
376332
description: String = "",
377333
unit: String = "",
378334
visibility: () -> Boolean = { true },
379-
) = IntegerSetting(name, defaultValue, range, step, description, visibility, unit).also {
380-
settings.add(it)
381-
}
335+
) = IntegerSetting(name, defaultValue, range, step, description, visibility, unit).register()
382336

383337
/**
384338
* Creates a [LongSetting] with the provided parameters and adds it to the [settings].
@@ -403,36 +357,7 @@ abstract class Configurable(
403357
description: String = "",
404358
unit: String = "",
405359
visibility: () -> Boolean = { true },
406-
) = LongSetting(name, defaultValue, range, step, description, visibility, unit).also {
407-
settings.add(it)
408-
}
409-
410-
/**
411-
* Creates a [ShortSetting] with the provided parameters and adds it to the [settings].
412-
*
413-
* The value of the setting is coerced into the specified [range] and rounded to the nearest [step].
414-
*
415-
* @param name The unique identifier for the setting.
416-
* @param defaultValue The default [Short] value of the setting.
417-
* @param range The range within which the setting's value must fall.
418-
* @param step The step to which the setting's value is rounded.
419-
* @param description A brief explanation of the setting's purpose and behavior.
420-
* @param visibility A lambda expression that determines the visibility status of the setting.
421-
* @param unit The unit of the setting. E.g. "°C", "m/s", "ms", "ticks", etc.
422-
*
423-
* @return The created [ShortSetting].
424-
*/
425-
fun setting(
426-
name: String,
427-
defaultValue: Short,
428-
range: ClosedRange<Short>,
429-
step: Short = 1,
430-
description: String = "",
431-
unit: String = "",
432-
visibility: () -> Boolean = { true },
433-
) = ShortSetting(name, defaultValue, range, step, description, visibility, unit).also {
434-
settings.add(it)
435-
}
360+
) = LongSetting(name, defaultValue, range, step, description, visibility, unit).register()
436361

437362
/**
438363
* Creates a [KeyBindSetting] with the provided parameters and adds it to the [settings].
@@ -449,9 +374,7 @@ abstract class Configurable(
449374
defaultValue: KeyCode,
450375
description: String = "",
451376
visibility: () -> Boolean = { true },
452-
) = KeyBindSetting(name, defaultValue, description, visibility).also {
453-
settings.add(it)
454-
}
377+
) = KeyBindSetting(name, defaultValue, description, visibility).register()
455378

456379
/**
457380
* Creates a [ColorSetting] with the provided parameters and adds it to the [settings].
@@ -468,9 +391,7 @@ abstract class Configurable(
468391
defaultValue: Color,
469392
description: String = "",
470393
visibility: () -> Boolean = { true },
471-
) = ColorSetting(name, defaultValue, description, visibility).also {
472-
settings.add(it)
473-
}
394+
) = ColorSetting(name, defaultValue, description, visibility).register()
474395

475396
/**
476397
* Creates a [BlockPosSetting] with the provided parameters and adds it to the [settings].
@@ -487,9 +408,7 @@ abstract class Configurable(
487408
defaultValue: BlockPos,
488409
description: String = "",
489410
visibility: () -> Boolean = { true },
490-
) = BlockPosSetting(name, defaultValue, description, visibility).also {
491-
settings.add(it)
492-
}
411+
) = BlockPosSetting(name, defaultValue, description, visibility).register()
493412

494413
/**
495414
* Creates a [BlockSetting] with the provided parameters and adds it to the [settings].
@@ -506,7 +425,5 @@ abstract class Configurable(
506425
defaultValue: Block,
507426
description: String = "",
508427
visibility: () -> Boolean = { true },
509-
) = BlockSetting(name, defaultValue, description, visibility).also {
510-
settings.add(it)
511-
}
428+
) = BlockSetting(name, defaultValue, description, visibility).register()
512429
}

common/src/main/kotlin/com/lambda/config/settings/collections/ListSetting.kt

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717

1818
package com.lambda.config.settings.collections
1919

20-
import com.google.gson.JsonElement
21-
import com.lambda.Lambda.gson
2220
import com.lambda.config.AbstractSetting
2321
import java.lang.reflect.Type
2422

@@ -27,26 +25,13 @@ import java.lang.reflect.Type
2725
*/
2826
class ListSetting<T : Any>(
2927
override val name: String,
30-
private val defaultValue: MutableList<T>,
28+
defaultValue: MutableList<T>,
3129
type: Type,
3230
description: String,
33-
private val hackDelegates: Boolean,
3431
visibility: () -> Boolean,
3532
) : AbstractSetting<MutableList<T>>(
3633
defaultValue,
3734
type,
3835
description,
3936
visibility
40-
) {
41-
override fun toJson(): JsonElement {
42-
return if (hackDelegates) gson.toJsonTree(defaultValue, type)
43-
else super.toJson()
44-
}
45-
46-
override fun loadFromJson(serialized: JsonElement) {
47-
if (hackDelegates) {
48-
defaultValue.addAll(gson.fromJson(serialized, type))
49-
setValue(this, ::value, defaultValue.distinct().toMutableList())
50-
} else super.loadFromJson(serialized)
51-
}
52-
}
37+
)

0 commit comments

Comments
 (0)