-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(code): Update project to 24w34a.
Closes #106
- Loading branch information
Showing
15 changed files
with
242 additions
and
71 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
13 changes: 13 additions & 0 deletions
13
kore/src/main/kotlin/io/github/ayfri/kore/arguments/components/consumable/ApplyEffects.kt
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,13 @@ | ||
package io.github.ayfri.kore.arguments.components.consumable | ||
|
||
import io.github.ayfri.kore.arguments.components.types.Effect | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class ApplyEffects( | ||
var effects: List<Effect>, | ||
var probability: Float, | ||
) : ConsumeEffect() | ||
|
||
fun ConsumeEffects.applyEffects(probability: Float, vararg effects: Effect) = | ||
apply { this.effects += ApplyEffects(effects.toList(), probability) } |
8 changes: 8 additions & 0 deletions
8
kore/src/main/kotlin/io/github/ayfri/kore/arguments/components/consumable/ClearAllEffects.kt
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,8 @@ | ||
package io.github.ayfri.kore.arguments.components.consumable | ||
|
||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data object ClearAllEffects : ConsumeEffect() | ||
|
||
fun ConsumeEffects.clearAllEffects() = apply { effects += ClearAllEffects } |
11 changes: 11 additions & 0 deletions
11
kore/src/main/kotlin/io/github/ayfri/kore/arguments/components/consumable/ConsumeEffect.kt
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,11 @@ | ||
package io.github.ayfri.kore.arguments.components.consumable | ||
|
||
import io.github.ayfri.kore.serializers.NamespacedPolymorphicSerializer | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable(with = ConsumeEffect.Companion.ConsumeEffectSerializer::class) | ||
sealed class ConsumeEffect { | ||
companion object { | ||
data object ConsumeEffectSerializer : NamespacedPolymorphicSerializer<ConsumeEffect>(ConsumeEffect::class, skipOutputName = true) | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
kore/src/main/kotlin/io/github/ayfri/kore/arguments/components/consumable/ConsumeEffects.kt
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,8 @@ | ||
package io.github.ayfri.kore.arguments.components.consumable | ||
|
||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class ConsumeEffects( | ||
var effects: List<ConsumeEffect> = emptyList(), | ||
) |
11 changes: 11 additions & 0 deletions
11
kore/src/main/kotlin/io/github/ayfri/kore/arguments/components/consumable/PlaySound.kt
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,11 @@ | ||
package io.github.ayfri.kore.arguments.components.consumable | ||
|
||
import io.github.ayfri.kore.arguments.types.resources.SoundEventArgument | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class PlaySound( | ||
var sound: SoundEventArgument, | ||
) : ConsumeEffect() | ||
|
||
fun ConsumeEffects.playSound(sound: SoundEventArgument) = apply { effects += PlaySound(sound) } |
11 changes: 11 additions & 0 deletions
11
kore/src/main/kotlin/io/github/ayfri/kore/arguments/components/consumable/RemoveEffects.kt
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,11 @@ | ||
package io.github.ayfri.kore.arguments.components.consumable | ||
|
||
import io.github.ayfri.kore.arguments.components.types.Effect | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class RemoveEffects( | ||
var effects: List<Effect> = emptyList(), | ||
) : ConsumeEffect() | ||
|
||
fun ConsumeEffects.removeEffects(vararg effects: Effect) = apply { this.effects += RemoveEffects(effects.toList()) } |
10 changes: 10 additions & 0 deletions
10
.../src/main/kotlin/io/github/ayfri/kore/arguments/components/consumable/TeleportRandomly.kt
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,10 @@ | ||
package io.github.ayfri.kore.arguments.components.consumable | ||
|
||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class TeleportRandomly( | ||
var diameter: Float, | ||
) : ConsumeEffect() | ||
|
||
fun ConsumeEffects.teleportRandomly(diameter: Float) = apply { effects += TeleportRandomly(diameter) } |
62 changes: 62 additions & 0 deletions
62
kore/src/main/kotlin/io/github/ayfri/kore/arguments/components/types/Consumable.kt
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,62 @@ | ||
package io.github.ayfri.kore.arguments.components.types | ||
|
||
import io.github.ayfri.kore.arguments.components.ComponentsScope | ||
import io.github.ayfri.kore.arguments.components.consumable.ConsumeEffect | ||
import io.github.ayfri.kore.arguments.components.consumable.ConsumeEffects | ||
import io.github.ayfri.kore.arguments.types.resources.SoundEventArgument | ||
import io.github.ayfri.kore.generated.ComponentTypes | ||
import io.github.ayfri.kore.serializers.LowercaseSerializer | ||
import io.github.ayfri.kore.utils.snakeCase | ||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable(with = ConsumeAnimation.Companion.ConsumeAnimationSerializer::class) | ||
enum class ConsumeAnimation { | ||
NONE, | ||
EAT, | ||
DRINK, | ||
BLOCK, | ||
BOW, | ||
SPEAR, | ||
CROSSBOW, | ||
SPYGLASS, | ||
TOOT_HORN, | ||
BRUSH; | ||
|
||
companion object { | ||
data object ConsumeAnimationSerializer : LowercaseSerializer<ConsumeAnimation>(entries) | ||
} | ||
} | ||
|
||
@Serializable | ||
data class ConsumableComponent( | ||
@SerialName("consume_seconds") | ||
var consumeSeconds: Float, | ||
var animation: ConsumeAnimation, | ||
var sound: SoundEventArgument, | ||
@SerialName("has_consume_particles") | ||
var hasConsumeParticles: Boolean, | ||
@SerialName("on_consume_effects") | ||
var onConsumeEffects: Map<String, ConsumeEffect>? = null, | ||
) : Component() | ||
|
||
fun ComponentsScope.consumable( | ||
consumeSeconds: Float, | ||
animation: ConsumeAnimation, | ||
sound: SoundEventArgument, | ||
hasConsumeParticles: Boolean = true, | ||
block: ConsumableComponent.() -> Unit = {}, | ||
) = apply { | ||
this[ComponentTypes.CONSUMABLE] = ConsumableComponent( | ||
consumeSeconds, | ||
animation, | ||
sound, | ||
hasConsumeParticles | ||
).apply(block) | ||
} | ||
|
||
fun ConsumableComponent.onConsumeEffects(block: ConsumeEffects.() -> Unit) = apply { | ||
onConsumeEffects = ConsumeEffects().apply(block).effects.associateBy { | ||
"minecraft:${it.javaClass.simpleName.snakeCase()}" | ||
} | ||
} |
55 changes: 3 additions & 52 deletions
55
kore/src/main/kotlin/io/github/ayfri/kore/arguments/components/types/FoodComponent.kt
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,72 +1,23 @@ | ||
package io.github.ayfri.kore.arguments.components.types | ||
|
||
import io.github.ayfri.kore.arguments.components.ComponentsScope | ||
import io.github.ayfri.kore.arguments.types.resources.EffectArgument | ||
import io.github.ayfri.kore.arguments.types.resources.ItemArgument | ||
import io.github.ayfri.kore.data.item.ItemStack | ||
import io.github.ayfri.kore.generated.ComponentTypes | ||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class FoodEffect( | ||
var effect: Effect, | ||
var probability: Float, | ||
) | ||
|
||
@Serializable | ||
data class FoodComponent( | ||
var nutrition: Int, | ||
var nutrition: Float, | ||
var saturation: Float, | ||
@SerialName("is_meat") | ||
var isMeat: Boolean? = null, | ||
@SerialName("can_always_eat") | ||
var canAlwaysEat: Boolean? = null, | ||
@SerialName("eat_seconds") | ||
var eatSeconds: Float? = null, | ||
var effects: List<FoodEffect>? = null, | ||
@SerialName("using_converts_to") | ||
var usingConvertsTo: ItemStack? = null, | ||
) : Component() | ||
|
||
fun ComponentsScope.food( | ||
nutrition: Int, | ||
saturation: Float, | ||
isMeat: Boolean? = null, | ||
canAlwaysEat: Boolean? = null, | ||
eatSeconds: Float? = null, | ||
effects: List<FoodEffect>, | ||
block: FoodComponent.() -> Unit = {}, | ||
) = apply { | ||
this[ComponentTypes.FOOD] = FoodComponent(nutrition, saturation, isMeat, canAlwaysEat, eatSeconds, effects).apply(block) | ||
} | ||
|
||
fun ComponentsScope.food( | ||
nutrition: Int, | ||
nutrition: Float, | ||
saturation: Float, | ||
isMeat: Boolean? = null, | ||
canAlwaysEat: Boolean? = null, | ||
eatSeconds: Float? = null, | ||
vararg effects: FoodEffect, | ||
block: FoodComponent.() -> Unit = {}, | ||
) = food(nutrition, saturation, isMeat, canAlwaysEat, eatSeconds, effects.toList(), block) | ||
|
||
fun FoodComponent.effect(probability: Float, effect: Effect) = apply { | ||
effects = (effects ?: mutableListOf()) + FoodEffect(effect, probability) | ||
} | ||
|
||
fun FoodComponent.effect( | ||
probability: Float, | ||
id: EffectArgument, | ||
duration: Int, | ||
amplifier: Byte, | ||
ambient: Boolean, | ||
showParticles: Boolean, | ||
showIcon: Boolean, | ||
) = apply { | ||
effects = (effects ?: mutableListOf()) + FoodEffect(Effect(id, duration, amplifier, ambient, showParticles, showIcon), probability) | ||
} | ||
|
||
fun FoodComponent.convertsTo(id: ItemArgument, block: ItemStack.() -> Unit = {}) = apply { | ||
usingConvertsTo = ItemStack(id).apply(block) | ||
this[ComponentTypes.FOOD] = FoodComponent(nutrition, saturation, canAlwaysEat).apply(block) | ||
} |
30 changes: 30 additions & 0 deletions
30
kore/src/main/kotlin/io/github/ayfri/kore/arguments/components/types/UseCooldown.kt
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,30 @@ | ||
package io.github.ayfri.kore.arguments.components.types | ||
|
||
import io.github.ayfri.kore.arguments.components.ComponentsScope | ||
import io.github.ayfri.kore.arguments.types.ConsumeCooldownGroupArgument | ||
import io.github.ayfri.kore.generated.ComponentTypes | ||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class UseCooldownComponent( | ||
var seconds: Float, | ||
@SerialName("cooldown_group") | ||
var cooldownGroup: ConsumeCooldownGroupArgument, | ||
) : Component() | ||
|
||
fun ComponentsScope.useCooldown( | ||
seconds: Float, | ||
cooldownGroup: ConsumeCooldownGroupArgument, | ||
block: UseCooldownComponent.() -> Unit = {}, | ||
) = apply { | ||
this[ComponentTypes.USE_COOLDOWN] = UseCooldownComponent(seconds, cooldownGroup).apply(block) | ||
} | ||
|
||
fun ComponentsScope.useCooldown( | ||
seconds: Float, | ||
cooldownGroup: String, | ||
block: UseCooldownComponent.() -> Unit = {}, | ||
) = apply { | ||
this[ComponentTypes.USE_COOLDOWN] = UseCooldownComponent(seconds, ConsumeCooldownGroupArgument(cooldownGroup)).apply(block) | ||
} |
15 changes: 15 additions & 0 deletions
15
kore/src/main/kotlin/io/github/ayfri/kore/arguments/components/types/UseRemainder.kt
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,15 @@ | ||
package io.github.ayfri.kore.arguments.components.types | ||
|
||
import io.github.ayfri.kore.arguments.components.ComponentsScope | ||
import io.github.ayfri.kore.data.item.ItemStack | ||
import io.github.ayfri.kore.generated.ComponentTypes | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class UseRemainderComponent( | ||
var item: ItemStack, | ||
) : Component() | ||
|
||
fun ComponentsScope.useRemainder(item: ItemStack) = apply { | ||
this[ComponentTypes.USE_REMAINDER] = UseRemainderComponent(item) | ||
} |
14 changes: 14 additions & 0 deletions
14
kore/src/main/kotlin/io/github/ayfri/kore/arguments/types/ConsumeCooldownGroupArgument.kt
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,14 @@ | ||
package io.github.ayfri.kore.arguments.types | ||
|
||
import io.github.ayfri.kore.arguments.Argument | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable(with = Argument.ArgumentSerializer::class) | ||
interface ConsumeCooldownGroupArgument : ResourceLocationArgument { | ||
companion object { | ||
operator fun invoke(name: String, namespace: String = "minecraft") = object : ConsumeCooldownGroupArgument { | ||
override val name = name | ||
override val namespace = namespace | ||
} | ||
} | ||
} |
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
1 change: 1 addition & 0 deletions
1
kore/src/test/kotlin/io/github/ayfri/kore/arguments/components/ComponentTests.kt
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 @@ | ||
|