Skip to content

Commit

Permalink
Flight (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronhowser1 committed Jun 25, 2024
1 parent 942e213 commit cdfd86f
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 12 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
- 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
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit cdfd86f

Please sign in to comment.