Skip to content

Commit ccdc61d

Browse files
committed
feat: add ModifyEntityGenesEvent to handle gene weight modifications and update changelog
1 parent 009a238 commit ccdc61d

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77
- `getGene()` gets the ResourceKey of the Gene whose requirements are being modified
88
- `getRequirements()` gets the set of ResourceKeys of Genes that are required
99
- Add or remove from this set to change the requirements
10+
- ModifyEntityGenesEvent
11+
- Can be accessed via KubeJS
12+
- `getEntityType()` gets the ResourceKey of the EntityType whose gene weights are being modified
13+
- `getGeneWeights()` gets the map of ResourceKeys of Genes to their weights
14+
- Modify this map to change the gene weights
15+
- After this event fires, if the map is empty, it is set to have the Basic Gene with weight 1
1016

1117
### Changed
1218

src/main/kotlin/dev/aaronhowser/mods/geneticsresequenced/data/EntityGenes.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package dev.aaronhowser.mods.geneticsresequenced.data
33
import com.mojang.serialization.Codec
44
import com.mojang.serialization.codecs.RecordCodecBuilder
55
import dev.aaronhowser.mods.geneticsresequenced.GeneticsResequenced
6+
import dev.aaronhowser.mods.geneticsresequenced.event.custom.ModifyEntityGenesEvent
67
import dev.aaronhowser.mods.geneticsresequenced.gene.Gene
78
import dev.aaronhowser.mods.geneticsresequenced.registry.ModGenes
89
import dev.aaronhowser.mods.geneticsresequenced.registry.ModGenes.getHolderOrThrow
@@ -14,6 +15,7 @@ import net.minecraft.core.registries.Registries
1415
import net.minecraft.resources.ResourceKey
1516
import net.minecraft.resources.ResourceLocation
1617
import net.minecraft.world.entity.EntityType
18+
import thedarkcolour.kotlinforforge.neoforge.forge.FORGE_BUS
1719
import kotlin.jvm.optionals.getOrNull
1820

1921
data class EntityGenes(
@@ -72,6 +74,9 @@ data class EntityGenes(
7274
result[geneHolder] = weight
7375
}
7476

77+
val event = ModifyEntityGenesEvent(entityRk, resultRks)
78+
FORGE_BUS.post(event)
79+
7580
if (result.isEmpty()) {
7681
val basic = ModGenes.BASIC.getHolderOrThrow(registries)
7782
result[basic] = 1
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package dev.aaronhowser.mods.geneticsresequenced.event.custom
2+
3+
import dev.aaronhowser.mods.geneticsresequenced.gene.Gene
4+
import net.minecraft.resources.ResourceKey
5+
import net.minecraft.world.entity.EntityType
6+
import net.neoforged.bus.api.Event
7+
8+
data class ModifyEntityGenesEvent(
9+
val entityType: ResourceKey<EntityType<*>>,
10+
val geneWeights: MutableMap<ResourceKey<Gene>, Int>
11+
) : Event()

0 commit comments

Comments
 (0)