-
Notifications
You must be signed in to change notification settings - Fork 99
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Position based gravity among other things #648
Open
DatCoder464
wants to merge
5
commits into
ValkyrienSkies:1.18.x/main
Choose a base branch
from
DatCoder464:1.18.x/main
base: 1.18.x/main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
5fbd797
MATH
DatCoder464 21f441b
AAAAAAHHHHHHHH
DatCoder464 20fba71
Merge branch '1.18.x/main' of https://github.com/DatCoder464/Valkyrie…
DatCoder464 a59386b
i have 0 idea if this will work
DatCoder464 6b697eb
grav block real??
DatCoder464 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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
123 changes: 123 additions & 0 deletions
123
common/src/main/kotlin/org/valkyrienskies/mod/api/PositionGravity.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,123 @@ | ||
package org.valkyrienskies.mod.api | ||
|
||
import net.minecraft.world.entity.LivingEntity | ||
import net.minecraft.world.entity.player.Player | ||
import net.minecraft.world.phys.Vec3 | ||
import org.joml.Vector3d | ||
import org.joml.Vector3dc | ||
import org.valkyrienskies.core.api.ships.ServerShip | ||
import org.valkyrienskies.core.util.x | ||
import org.valkyrienskies.core.util.y | ||
import org.valkyrienskies.core.util.z | ||
import org.valkyrienskies.mod.common.entity.MobWeights | ||
|
||
class PositionGravity { | ||
private lateinit var instances: Map<Vector3dc?, Double> | ||
fun PositionGravity( | ||
pos: Vector3dc, | ||
mass: Double | ||
) { | ||
instances + Pair(pos, mass) | ||
} | ||
|
||
fun removePosition( | ||
pos: Vector3dc | ||
) { | ||
instances - pos | ||
} | ||
|
||
fun entityEffect( | ||
entity: LivingEntity | ||
): Vector3d { | ||
lateinit var forces: List<Vector3d> | ||
instances.forEach{ | ||
val distance: Double = | ||
entity.getPosition(0.0F).distanceTo(Vec3(it.key!!.x, it.key!!.x, it.key!!.x)) | ||
Vector3d( | ||
force( | ||
entity.deltaMovement.x, distance, | ||
MobWeights.NORMAL_PLAYER.weight, it.value, | ||
entity.position().x - it.key!!.x | ||
), | ||
force( | ||
entity.deltaMovement.y, distance, | ||
MobWeights.NORMAL_PLAYER.weight, it.value, | ||
entity.position().y - it.key!!.y | ||
), | ||
force( | ||
entity.deltaMovement.z, distance, | ||
MobWeights.NORMAL_PLAYER.weight, it.value, | ||
entity.position().z - it.key!!.z | ||
) | ||
) | ||
} | ||
lateinit var totalForce: Vector3d | ||
forces.forEach { | ||
totalForce.add(it.x, it.y, it.z) | ||
} | ||
return totalForce | ||
} | ||
|
||
fun playerEffect( | ||
player: Player | ||
): Vector3d { | ||
lateinit var forces: List<Vector3d> | ||
instances.forEach{ | ||
val distance: Double = | ||
player.getPosition(0.0F).distanceTo(Vec3(it.key!!.x, it.key!!.x, it.key!!.x)) | ||
Vector3d( | ||
force( | ||
player.deltaMovement.x, distance, | ||
MobWeights.NORMAL_PLAYER.weight, it.value, | ||
player.position().x - it.key!!.x | ||
), | ||
force( | ||
player.deltaMovement.y, distance, | ||
MobWeights.NORMAL_PLAYER.weight, it.value, | ||
player.position().y - it.key!!.y | ||
), | ||
force( | ||
player.deltaMovement.z, distance, | ||
MobWeights.NORMAL_PLAYER.weight, it.value, | ||
player.position().z - it.key!!.z | ||
) | ||
) | ||
} | ||
lateinit var totalForce: Vector3d | ||
forces.forEach { | ||
totalForce.add(it.x, it.y, it.z) | ||
} | ||
return totalForce | ||
} | ||
fun shipEffect( | ||
ship: ServerShip | ||
): Vector3d { | ||
lateinit var forces: List<Vector3d> | ||
instances.forEach { | ||
val distance: Double = ship.inertiaData.centerOfMassInShip.distance(it.key) | ||
forces + Vector3d( | ||
force( | ||
ship.velocity.x, distance, ship.inertiaData.mass, it.value, | ||
ship.inertiaData.centerOfMassInShip.x - it.key!!.x | ||
), | ||
force( | ||
ship.velocity.y, distance, ship.inertiaData.mass, it.value, | ||
ship.inertiaData.centerOfMassInShip.y - it.key!!.y | ||
), | ||
force( | ||
ship.velocity.z, distance, ship.inertiaData.mass, it.value, | ||
ship.inertiaData.centerOfMassInShip.z - it.key!!.z | ||
) | ||
) | ||
} | ||
lateinit var totalForce: Vector3d | ||
forces.forEach { | ||
totalForce.add(it.x, it.y, it.z) | ||
} | ||
return totalForce | ||
} | ||
|
||
private fun force(axis: Double, distance: Double, mass1: Double, mass2: Double, axisDistance: Double): Double { | ||
return axis - ((mass1 * axisDistance) / distance) | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should not add public functions to mixins, unless you are implementing an interface.