From cdfd86f8a312a7a80d56bc0b16ed4e6442e22a47 Mon Sep 17 00:00:00 2001 From: Aaron Howser Date: Tue, 25 Jun 2024 03:20:56 -0500 Subject: [PATCH] Flight (#10) --- CHANGELOG.md | 3 ++- .../event/entity/GeneEvents.kt | 3 +-- .../gene/behavior/AttributeGenes.kt | 21 +++++++++++++++++++ .../gene/behavior/TickGenes.kt | 9 -------- 4 files changed, 24 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c767df71..7a9d521d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,4 +10,5 @@ - Improved command response messages, for example "Added Claws to Dev" instead of "Added Claws to 1 entities". - Efficiency Attribute now uses modifiers instead of modifying the attribute base value. No idea why I was doing that originally, that's awful. - Support Slime now only checks if it should despawn once every 40 ticks rather than every tick, which should improve performance. -- Changed the machines' energy texture to one made by TJKraft \ No newline at end of file +- Changed the machines' energy texture to one made by TJKraft +- The Flight gene now is an Attribute, rather than changing the player's ability to fly. Fixes #10 \ No newline at end of file diff --git a/src/main/kotlin/dev/aaronhowser/mods/geneticsresequenced/event/entity/GeneEvents.kt b/src/main/kotlin/dev/aaronhowser/mods/geneticsresequenced/event/entity/GeneEvents.kt index dc44b2d9..5fb102c5 100644 --- a/src/main/kotlin/dev/aaronhowser/mods/geneticsresequenced/event/entity/GeneEvents.kt +++ b/src/main/kotlin/dev/aaronhowser/mods/geneticsresequenced/event/entity/GeneEvents.kt @@ -40,11 +40,10 @@ object GeneEvents { ModGenes.stepAssist -> AttributeGenes.setStepAssist(livingEntity, wasAdded) ModGenes.wallClimbing -> AttributeGenes.setWallClimbing(livingEntity, wasAdded) ModGenes.knockback -> AttributeGenes.setKnockback(livingEntity, wasAdded) + ModGenes.flight -> AttributeGenes.setFlight(livingEntity, wasAdded) ModGenes.moreHearts -> AttributeGenes.setMoreHearts(livingEntity, 1, wasAdded) ModGenes.moreHeartsTwo -> AttributeGenes.setMoreHearts(livingEntity, 2, wasAdded) - - ModGenes.flight -> TickGenes.handleFlight(livingEntity, wasAdded) } } diff --git a/src/main/kotlin/dev/aaronhowser/mods/geneticsresequenced/gene/behavior/AttributeGenes.kt b/src/main/kotlin/dev/aaronhowser/mods/geneticsresequenced/gene/behavior/AttributeGenes.kt index 56e2cec3..f58135a4 100644 --- a/src/main/kotlin/dev/aaronhowser/mods/geneticsresequenced/gene/behavior/AttributeGenes.kt +++ b/src/main/kotlin/dev/aaronhowser/mods/geneticsresequenced/gene/behavior/AttributeGenes.kt @@ -9,6 +9,7 @@ import net.minecraft.world.entity.LivingEntity import net.minecraft.world.entity.ai.attributes.AttributeModifier import net.minecraft.world.entity.ai.attributes.Attributes import net.minecraft.world.entity.player.Player +import net.neoforged.neoforge.common.NeoForgeMod import net.neoforged.neoforge.event.entity.player.PlayerEvent object AttributeGenes { @@ -179,4 +180,24 @@ object AttributeGenes { } } + private val flightRl = OtherUtil.modResource("flight") + private val flightAttributeModifier = AttributeModifier( + flightRl, + 1.0, + AttributeModifier.Operation.ADD_VALUE + ) + + fun setFlight(player: Player, adding: Boolean) { + if (!ModGenes.flight.isActive) return + if (player.level().isClientSide) return + + val attribute = player.getAttribute(NeoForgeMod.CREATIVE_FLIGHT) ?: return + + if (adding) { + attribute.addPermanentModifier(flightAttributeModifier) + } else { + attribute.removeModifier(flightAttributeModifier) + } + } + } \ No newline at end of file diff --git a/src/main/kotlin/dev/aaronhowser/mods/geneticsresequenced/gene/behavior/TickGenes.kt b/src/main/kotlin/dev/aaronhowser/mods/geneticsresequenced/gene/behavior/TickGenes.kt index 6843bfe0..344bc9d3 100644 --- a/src/main/kotlin/dev/aaronhowser/mods/geneticsresequenced/gene/behavior/TickGenes.kt +++ b/src/main/kotlin/dev/aaronhowser/mods/geneticsresequenced/gene/behavior/TickGenes.kt @@ -251,15 +251,6 @@ object TickGenes { } } - fun handleFlight(player: Player, adding: Boolean) { - if (!ModGenes.flight.isActive) return - if (player.level().isClientSide) return - - player.abilities.mayfly = adding - player.abilities.flying = adding - player.onUpdateAbilities() - } - fun handleItemMagnet(player: Player) { // if (!ModGenes.itemMagnet.isActive) return // if (player.isCrouching || player.isDeadOrDying || player.isSpectator) return