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

Misc Additions #67

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

solonovamax
Copy link

@solonovamax solonovamax commented Oct 7, 2024

A bunch of misc additions split off from #59 that I wasn't sure how else to group.

Adds:

  • extensions for World for getting entities by class/type/collision with AABB
  • extensions for MinecraftServer for getting a world by their identifier (ResourceLocation)
  • an extension for AbstractContainerScreen to get the focused slot
  • functions to create an Ingredient
  • extensions checking what items a Container contains & iterating through them
    the .iterator() extension allows for
    for (item in container.iterator()) {
        // use item here
    }

solonovamax added a commit to solonovamax/silk that referenced this pull request Oct 7, 2024
These will be re-added in other PRs (SilkMC#66 and SilkMC#67)

Signed-off-by: solonovamax <[email protected]>
Copy link
Member

Choose a reason for hiding this comment

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

is this really needed, I feel like it is kind of unnecessary?

Copy link
Author

Choose a reason for hiding this comment

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

It's not strictly necessary, however it does make it feel a bit nicer imo

import net.minecraft.world.inventory.Slot
import net.silkmc.silk.core.mixin.client.AbstractContainerScreenAccessor

val AbstractContainerScreen<*>.focusedSlot: Slot?
Copy link
Member

Choose a reason for hiding this comment

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

is there a reason the extension is not called hoveredSlot as well?

Copy link
Author

Choose a reason for hiding this comment

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

the reason is I forgored to update it

Comment on lines +19 to +53
fun CollisionGetter.entityCollisions(
entity: Entity? = null,
box: AABB,
): List<VoxelShape> {
return getEntityCollisions(entity, box)
}

fun CollisionGetter.collisions(
entity: Entity? = null,
box: AABB,
): Iterable<VoxelShape> {
return getCollisions(entity, box)
}

fun CollisionGetter.blockCollisions(
entity: Entity? = null,
box: AABB,
): Iterable<VoxelShape> {
return getBlockCollisions(entity, box)
}

fun EntityGetter.entityCollisions(
entity: Entity? = null,
box: AABB,
): List<VoxelShape> {
return getEntityCollisions(entity, box)
}

fun EntityGetter.entities(
except: Entity? = null,
box: AABB,
predicate: (Entity) -> Boolean = EntitySelector.NO_SPECTATORS::test,
): List<Entity> {
return getEntities(except, box, predicate)
}
Copy link
Member

Choose a reason for hiding this comment

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

don't these functions just remove "get" from the name of the original function?

Copy link
Author

Choose a reason for hiding this comment

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

yeah basically, though it does also make them have an optional parameter for the Entity, which for all those methods if none is provided then it's ignored (I forget if there is an overload for this or not by default. I'd have to check.)

also, imo it feels a lot nicer without the get, but that's just me

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