Skip to content
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

Improved Math Extensions/Functions #59

Open
wants to merge 16 commits into
base: main
Choose a base branch
from

Conversation

solonovamax
Copy link

@solonovamax solonovamax commented Aug 3, 2024

This PR contains a bunch of additional math extensions/functions, such as:

  • vector operations for Vector3i, Vector3f, Vector3d, Vector2i, Vector2f, and Vector2d
  • conversion functions for Pos{2,3}{i,d,f} (ie. convert from mc Vec*, BlockPos, and joml Vector* classes to the Pos* classes)
  • operator overloads for common number types (Int, Long, Float, and Double. this is to avoid the overhead that comes with boxing & unboxing when using Number. the Number overload is still provided if, for whatever reason, someone has like a Byte or Short or smth and wants to multiply it)
  • infix functions for the cross product and dot product
  • functions for pos*Of, vec*Of, and vector*Of (eg. pos3dOf(x, y, z): Pos3d, vec3Of(x, y, z): Vec3, vector3dOf(x, y, z): Vector3d, etc.)
  • a couple of functions just to make things slightly nicer on yarn (eg. toMcVec3d, which is an alias for toMcVec3, as Vec3 is named Vec3d on yarn)
  • matrix operations for Matrix2f, Matrix2d, Matrix3f, Matrix3d, Matrix3x2f, Matrix3x2d, Matrix4f, Matrix4d, Matrix4x3f, and Matrix4x3d
  • some convenience functions for AABB/Box
  • convenience extensions for World. Split of into a separate PR. See Misc Additions #67.
  • convenience extensions for Registry, allowing for things like~~
    val MY_ITEM = Registries.ITEM.register("mymod:myid", MyItem())
    I just find this slightly cleaner for registering things.
    Split off into a separate PR. See Adds extensions for registration #66.

@solonovamax
Copy link
Author

oops, hit enter before writing the description lol

@solonovamax solonovamax marked this pull request as draft August 3, 2024 04:00
@solonovamax solonovamax force-pushed the feature/utility-extensions branch from b5e4ce8 to b183d4e Compare August 27, 2024 18:21
@solonovamax
Copy link
Author

@jakobkmar is there any possibility I could get some feedback on this?

because I'd love to see it merged soon-ish, if possible

@solonovamax
Copy link
Author

I'm probably actually gonna split this into two PRs:

  1. a PR with all the math-related changes
  2. a PR with all the other stuff (may possibly split this further)

- Add operators for
  - Vector3i
  - Vector3f
  - Vector3d
  - Vector2i
  - Vector2f
  - Vector2d
- Add new operators
  - cross product & dot product
  - overloads to avoid boxing & unboxing
- initialization functions similar to listOf() for vectors
- conversion functions for `Vec*`/`Vector*` -> `Pos*`
- some function aliases for yarn mappings
- Add operators for all JOML matrix types
- Utility extensions for registering so you can do smth like
    val MY_ITEM = Registries.ITEM.register("mymod:myid", MyItem())
- convenience methods for getting entities in an area

Signed-off-by: solonovamax <[email protected]>
Also suppress some warnings in the other *Operations files

Signed-off-by: solonovamax <[email protected]>
Soft depends on fabric-permissions-api-v0.
Falls back to vanilla permission checks if it's not present

Signed-off-by: solonovamax <[email protected]>
See: FabricMC/fabric-loom#1153
Using layered mappings with a custom mapping is preferred.
@solonovamax solonovamax force-pushed the feature/utility-extensions branch from b183d4e to 7899710 Compare October 7, 2024 03:31
solonovamax added a commit to solonovamax/silk that referenced this pull request Oct 7, 2024
This was referenced Oct 7, 2024
@solonovamax solonovamax marked this pull request as ready for review October 7, 2024 04:23
These will be re-added in other PRs (SilkMC#66 and SilkMC#67)

Signed-off-by: solonovamax <[email protected]>
@solonovamax solonovamax force-pushed the feature/utility-extensions branch from d648345 to 66a2d96 Compare October 7, 2024 04:27
@solonovamax solonovamax changed the title Utility Extensions Improved Math Extensions/Functions Oct 7, 2024
@solonovamax solonovamax requested a review from kxmpxtxnt October 7, 2024 04:38
Copy link
Author

@solonovamax solonovamax left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just making this review to remind myself for later.

Also add kdoc comments to all elements.

Comment on lines +218 to +222
operator fun Vector3i.plus(n: Int): Vector3i = n.let { nInt -> Vector3i(this).add(nInt, nInt, nInt) }
operator fun Vector3i.plus(n: Long): Vector3i = n.toInt().let { nInt -> Vector3i(this).add(nInt, nInt, nInt) }
operator fun Vector3i.plus(n: Float): Vector3i = n.toInt().let { nInt -> Vector3i(this).add(nInt, nInt, nInt) }
operator fun Vector3i.plus(n: Double): Vector3i = n.toInt().let { nInt -> Vector3i(this).add(nInt, nInt, nInt) }
operator fun Vector3i.plus(n: Number): Vector3i = n.toInt().let { nInt -> Vector3i(this).add(nInt, nInt, nInt) }
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add Number.plus(Vector3i), etc. methods for parity with matrix extensions

Comment on lines +26 to +28
fun BlockPos.toPos3i(): Pos3i = Pos3i(x, y, z)
fun BlockPos.toPos3f(): Pos3f = Pos3f(x.toFloat(), y.toFloat(), z.toFloat())
fun BlockPos.toPos3d(): Pos3d = Pos3d(x.toDouble(), y.toDouble(), z.toDouble())
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add BlockPos.toVec3i(), etc. methods for completeness.

Comment on lines +2 to +14
"package": "net.silkmc.silk.core.mixin",
"required": true,
"compatibilityLevel": "JAVA_21",
"mixins": [
"block.AbstractBlockAccessor",
"entity.MixinEntity",
"entity.MixinLivingEntity",
"server.MixinMinecraftServer",
"server.MixinPlayerList",
"server.MixinServerConfigurationPacketListenerImpl",
"server.MixinServerGamePacketListenerImpl",
"server.MixinServerLoginPacketListenerImpl"
]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

revert this change completely (changes nothing, artifact of not properly reverting another other change)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants