Skip to content

Fabric API Lookup #1234

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

Merged
merged 38 commits into from
Mar 8, 2021
Merged

Fabric API Lookup #1234

merged 38 commits into from
Mar 8, 2021

Conversation

Technici4n
Copy link
Member

@Technici4n Technici4n commented Dec 21, 2020

Fabric API Lookup API v1

Introduction

This module allows Api instances to be associated with game objects without specifying how the association is implemented. This is useful when the same Api could be implemented more than once or implemented in different ways.

Many thanks to @grondag for providing the original concept (#1072).
Thanks also go to @i509VCB, @Pyrofab, @sfPlayer1 and the others who were involved with the design of this module.

This is the foundation upon which can be built for example a fluid transfer api (#1166). Closes #1199.

Flexible Api Querying

Block Api Usage example

Building blocks

This PR was changed a lot, please have a look at the README, the package info, and the javadoc for BlockApiLookup and ApiLookupMap for up-to-date documentation.

More usage examples

FastTransferLib (https://github.com/Technici4n/FastTransferLib) is an experiment to build an item, fluid and energy transfer api on top of this module. (Which was until recently called fabric-provider-api-v1.)

Missing things?

I could add an overload of BlockApiLookup#find with nullable BlockState and BlockEntity parameters, so that the caller can directly provide them if they are available for some reason. Added in later commits.

There is no module to retrieve apis from items or entities yet because there were unsolved issues with those. The community can use the provided building blocks to experiment with their own implementations of ItemStackApiLookup and EntityApiLookup until the way forward becomes clear, but let's please not delay the BlockApiLookup because of that.

Copy link
Contributor

@CoolMineman CoolMineman left a comment

Choose a reason for hiding this comment

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

Has been nice to use and works well

@i509VCB i509VCB added enhancement New feature or request new module Pull requests that introduce new modules reviews needed This PR needs more reviews tests PR has tests labels Dec 21, 2020
@i509VCB i509VCB requested review from i509VCB, modmuss50, Player3324 and a team December 21, 2020 01:36
* @Nullable
* A find(ItemStack stack, C context);
* // Expose the API for some item.
* void register(ItemStackApiProvider<A, C> provider, Item item);
Copy link
Contributor

Choose a reason for hiding this comment

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

the reason checkstyle complained here is you need to use the html entity codes for < and >

Copy link
Member Author

Choose a reason for hiding this comment

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

Then it fails to render correctly as the {@code} tag already escapes them, I tried that first...

Copy link
Contributor

Choose a reason for hiding this comment

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

It won't render in IDE but the doclet will render it

Copy link
Member Author

Choose a reason for hiding this comment

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

gradlew javadoc was unable to render them correctly when I tried on my laptop - just disable the inspection and be done with it, there are more important things in life and javadoc escaping is weird anyway. :P

Copy link
Member Author

Choose a reason for hiding this comment

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

Fun fact: the symbol in the javadoc is not a regular @ 😆 (https://stackoverflow.com/a/46332643/13567109).

@modmuss50 modmuss50 requested review from modmuss50 and liach February 22, 2021 00:38
@modmuss50
Copy link
Member

Oops sorry @liach i didn’t mean to add you as a reviewer again. Feel free to though :)

Copy link
Contributor

@liach liach left a comment

Choose a reason for hiding this comment

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

My previous questions are addressed already. Just a side note that when we add apiNote etc. command line tags, we should probably move <p>Note: to those tags.

@Technici4n
Copy link
Member Author

Technici4n commented Feb 22, 2021

I moved away from using @apiNote because gradlew javadoc tool didn't seem to recognize it.

@liach
Copy link
Contributor

liach commented Feb 22, 2021

I moved away from using @apiNote because gradlew javadoc tool didn't seem to recognize it.

This is what you need https://github.com/FabricMC/yarn/blob/0025fbf845a27efa50d44ba1e2bac7c028eea57d/build.gradle#L722-L726

@Technici4n
Copy link
Member Author

I moved away from using @apiNote because gradlew javadoc tool didn't seem to recognize it.

This is what you need https://github.com/FabricMC/yarn/blob/0025fbf845a27efa50d44ba1e2bac7c028eea57d/build.gradle#L722-L726

Ok that's interesting, will be good to have eventually.

@Technici4n Technici4n changed the title Fabric Api Lookup Fabric API Lookup Feb 22, 2021
@grondag
Copy link
Contributor

grondag commented Feb 28, 2021

I've scanned through this briefly and it seems consistent with the original intent and well-considered in its implementation. Nice job.

Would it support client-side lookups? From what I read it appeared it may be server-side only.

@Technici4n
Copy link
Member Author

Thanks! Client-side lookups are possible, it's just that the BlockApiCache will not be usable with them because it takes a ServerWorld.
The regular BlockApiLookup takes a World and should work fine.

Copy link
Contributor

@Player3324 Player3324 left a comment

Choose a reason for hiding this comment

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

Good now as far as I can tell. Thanks!

@Player3324 Player3324 added status: last call If you care, make yourself heard right away! and removed reviews needed This PR needs more reviews labels Mar 2, 2021
* Use "may not" instead of "cannot", and end sentences with a period.
* Remove null checks for vararg parameters: passing a null vararg is unlikely and will cause an NPE directly anyway.
@modmuss50 modmuss50 added the status: merge me please Pull requests that are ready to merge label Mar 8, 2021
@modmuss50 modmuss50 merged commit dc716ea into FabricMC:1.16 Mar 8, 2021
modmuss50 pushed a commit that referenced this pull request Mar 8, 2021
# Fabric API Lookup API v1
## Introduction
This module allows Api instances to be associated with game objects without specifying how the association is implemented. This is useful when the same Api could be implemented more than once or implemented in different ways.

Many thanks to @grondag for providing the original concept (#1072).
Thanks also go to @i509VCB, @Pyrofab, @sfPlayer1 and the others who were involved with the design of this module.

This is the foundation upon which can be built for example a fluid transfer api (#1166). Closes #1199.

## Flexible Api Querying
## Block Api Usage example
## Building blocks
This PR was changed a lot, please have a look at the README, the package info, and the javadoc for `BlockApiLookup` and `ApiLookupMap` for up-to-date documentation.

## More usage examples
FastTransferLib (https://github.com/Technici4n/FastTransferLib) is an experiment to build an item, fluid and energy transfer api on top of this module. (Which was until recently called `fabric-provider-api-v1`.)

## Missing things?
~~I could add an overload of `BlockApiLookup#find` with nullable `BlockState` and `BlockEntity` parameters, so that the caller can directly provide them if they are available for some reason.~~ Added in later commits.

There is no module to retrieve apis from items or entities yet because there were unsolved issues with those. The community can use the provided building blocks to experiment with their own implementations of `ItemStackApiLookup` and `EntityApiLookup` until the way forward becomes clear, but let's please not delay the `BlockApiLookup` because of that.

Co-authored-by: i509VCB <[email protected]>
Co-authored-by: PepperBell <[email protected]>
(cherry picked from commit dc716ea)
modmuss50 pushed a commit to modmuss50/fabric that referenced this pull request Apr 2, 2021
# Fabric API Lookup API v1
## Introduction
This module allows Api instances to be associated with game objects without specifying how the association is implemented. This is useful when the same Api could be implemented more than once or implemented in different ways.

Many thanks to @grondag for providing the original concept (FabricMC#1072).
Thanks also go to @i509VCB, @Pyrofab, @sfPlayer1 and the others who were involved with the design of this module.

This is the foundation upon which can be built for example a fluid transfer api (FabricMC#1166). Closes FabricMC#1199.

## Flexible Api Querying
## Block Api Usage example
## Building blocks
This PR was changed a lot, please have a look at the README, the package info, and the javadoc for `BlockApiLookup` and `ApiLookupMap` for up-to-date documentation.

## More usage examples
FastTransferLib (https://github.com/Technici4n/FastTransferLib) is an experiment to build an item, fluid and energy transfer api on top of this module. (Which was until recently called `fabric-provider-api-v1`.)

## Missing things?
~~I could add an overload of `BlockApiLookup#find` with nullable `BlockState` and `BlockEntity` parameters, so that the caller can directly provide them if they are available for some reason.~~ Added in later commits.

There is no module to retrieve apis from items or entities yet because there were unsolved issues with those. The community can use the provided building blocks to experiment with their own implementations of `ItemStackApiLookup` and `EntityApiLookup` until the way forward becomes clear, but let's please not delay the `BlockApiLookup` because of that.

Co-authored-by: i509VCB <[email protected]>
Co-authored-by: PepperBell <[email protected]>
ThalusA pushed a commit to ThalusA/fabric that referenced this pull request May 31, 2022
# Fabric API Lookup API v1
## Introduction
This module allows Api instances to be associated with game objects without specifying how the association is implemented. This is useful when the same Api could be implemented more than once or implemented in different ways.

Many thanks to @grondag for providing the original concept (FabricMC#1072).
Thanks also go to @i509VCB, @Pyrofab, @sfPlayer1 and the others who were involved with the design of this module.

This is the foundation upon which can be built for example a fluid transfer api (FabricMC#1166). Closes FabricMC#1199.

## Flexible Api Querying
## Block Api Usage example
## Building blocks
This PR was changed a lot, please have a look at the README, the package info, and the javadoc for `BlockApiLookup` and `ApiLookupMap` for up-to-date documentation.

## More usage examples
FastTransferLib (https://github.com/Technici4n/FastTransferLib) is an experiment to build an item, fluid and energy transfer api on top of this module. (Which was until recently called `fabric-provider-api-v1`.)

## Missing things?
~~I could add an overload of `BlockApiLookup#find` with nullable `BlockState` and `BlockEntity` parameters, so that the caller can directly provide them if they are available for some reason.~~ Added in later commits.

There is no module to retrieve apis from items or entities yet because there were unsolved issues with those. The community can use the provided building blocks to experiment with their own implementations of `ItemStackApiLookup` and `EntityApiLookup` until the way forward becomes clear, but let's please not delay the `BlockApiLookup` because of that.

Co-authored-by: i509VCB <[email protected]>
Co-authored-by: PepperBell <[email protected]>
(cherry picked from commit dc716ea)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request new module Pull requests that introduce new modules priority: low Low priority PRs that don't immediately need to be resolved status: last call If you care, make yourself heard right away! status: merge me please Pull requests that are ready to merge tests PR has tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CCA&LBA-like APIs should be considered in Fabric API