-
Notifications
You must be signed in to change notification settings - Fork 528
Add test-api-v1 (feat: Scoped Events) #5285
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
Open
Kilip1000
wants to merge
61
commits into
FabricMC:26.1.2
Choose a base branch
from
FabulabsMC:debug-api
base: 26.1.2
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 47 commits
Commits
Show all changes
61 commits
Select commit
Hold shift + click to select a range
33da0f8
Add testable events
Earthcomputer 278ac4c
feat: Debug API
sylv256 c22b43f
Merge remote-tracking branch 'origin/26.1' into debug-api
sylv256 b7ec842
docs(EntityDebugSubscriptionRegistry): clarify it's server-side only
sylv256 9f343f0
chore: apply licenses
sylv256 2309980
docs: `Constructor` -> `Factory` terminology on factory interfaces
sylv256 1edea23
Merge remote-tracking branch 'origin/26.1' into debug-api
sylv256 f0a43db
fix: depend `fabricloader` `>=0.18.4`
sylv256 9754e49
refactor: merge `MobMixin` & `EntityMixin`
sylv256 c3ac770
use @apiNote in javadoc and use package-private Mixins
sylv256 9f77b0b
Merge remote-tracking branch 'origin/debug-api' into debug-api
sylv256 d3271d8
refactor!: `net.fabricmc.fabric.api.debug.v1.client` -> `….api.client…
sylv256 77e5364
Merge remote-tracking branch 'origin/26.1' into debug-api
sylv256 a4ed9e8
Merge branch '26.1' into debug-api
sylv256 651b2d8
Merge remote-tracking branch 'origin/26.1' into debug-api
sylv256 d7a70e9
Merge branch 'test-event-scopes' into debug-api
Kilip1000 dffdb53
Move event scopes to debug api
Kilip1000 2cc663f
refactor: ServerMobEffectsGameTest now uses EventScopes
Kilip1000 14c1700
Merge branch '26.1' into debug-api
Kilip1000 64235c9
spotless apply
Kilip1000 6abca36
fix: checkstyle
Kilip1000 21584f0
chore: more descriptive exceptions
Kilip1000 55d1173
chore: remove unnecessary code
Kilip1000 6320f81
refactor: use EventScopes more
Kilip1000 83b205e
safer updating because less hardcoding
Kilip1000 61092fc
prettify code
Kilip1000 981c514
chore: javadoc
Kilip1000 2e6e6f5
chore: fix grammar
Kilip1000 a9e2332
Move changes to module `fabric-dev-debug-api-v1`
Kilip1000 542113a
fix wrong classname
Kilip1000 aed9993
remove redundant file
Kilip1000 5bf2f56
Merge branch '26.1' into debug-api
sylv256 7718a8d
refactor: remove EventScope usage, we can PR that later
sylv256 7b8f853
fix: dependencies
sylv256 860f2f6
docs: change description to accurately reflect purpose
sylv256 16cfcf3
fix: don't include dev debug api
sylv256 0a7f5dd
refactor: move dev debug api to packages matching debug api
sylv256 452e8b5
docs: javadoc for EventScope
Kilip1000 d90e87e
docs: clarify listener type parameter doc
sylv256 60397ac
docs: use @linkplain's and @see, fix docs
sylv256 6615de7
fix: class name check of TestableEventFactoryImpl
sylv256 28aa464
fix: move everything to `debug.dev` packages to avoid javadoc errors
sylv256 32effd1
docs(EventScope): nitpick changes to phrasing and word choice
sylv256 bddd1d5
test: add tests for `EventScope`
sylv256 8cd5b48
docs: change description of Debug API to more accurately reflect its …
sylv256 1fc8725
fix: remove unnecessary dev env check
sylv256 08382c5
refactor: move merge EventTestingImpl with EventScopeImpl
sylv256 c5753e1
chore: spotless apply
sylv256 6e715f3
refactor: `EventScope#registerScoped` -> `#register`
sylv256 52d19fd
Merge branch '26.1' into debug-api
sylv256 6ea9b07
remove hacky inheritor verification
Kilip1000 85b6147
mark api as stable
Kilip1000 a8e7e0e
Revert "remove hacky inheritor verification"
Kilip1000 39d745f
fix: remove inheritance check & ServiceLoader jank, use custom FMJ value
sylv256 b6c31d4
chore: mark API experimental
sylv256 68e2541
Revert "docs: change description of Debug API to more accurately refl…
sylv256 371d949
refactor: remove reliance on Debug API, convert to `test-api`
sylv256 903bb29
Merge branch '26.1.1' into debug-api
sylv256 c146b32
test: convert gametest to unit test
sylv256 0f5b19e
Merge branch '26.1.1' into debug-api
sylv256 8e85fa8
Merge branch '26.1.2' into debug-api
sylv256 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,10 @@ | ||
| version = getSubprojectVersion(project) | ||
|
|
||
| moduleDependencies(project, [ | ||
| 'fabric-api-base', | ||
| 'fabric-debug-api-v1' | ||
| ]) | ||
|
|
||
| testDependencies(project, [ | ||
| 'fabric-gametest-api-v1' | ||
| ]) |
60 changes: 60 additions & 0 deletions
60
fabric-dev-debug-api-v1/src/main/java/net/fabricmc/fabric/api/debug/dev/v1/EventScope.java
This file contains hidden or 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,60 @@ | ||
| /* | ||
| * Copyright (c) 2016, 2017, 2018, 2019 FabricMC | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package net.fabricmc.fabric.api.debug.dev.v1; | ||
|
|
||
| import java.util.function.Function; | ||
|
|
||
| import org.jetbrains.annotations.ApiStatus; | ||
|
|
||
| import net.minecraft.resources.Identifier; | ||
|
|
||
| import net.fabricmc.fabric.api.event.Event; | ||
| import net.fabricmc.fabric.api.event.EventFactory; | ||
| import net.fabricmc.fabric.impl.debug.dev.EventScopeImpl; | ||
|
|
||
| /** | ||
| * Represents a wrapper around a short-lived {@link Event}. | ||
| * This class implements {@link AutoCloseable} and is intended to be used in a try-with-resources block. | ||
| * When closed, the event will be unregistered. | ||
| */ | ||
| @ApiStatus.NonExtendable | ||
| public interface EventScope extends AutoCloseable { | ||
| @Override | ||
| void close(); | ||
|
|
||
| /** | ||
| * @param event The {@link Event} to be registered in an {@link EventScope} | ||
| * @param listener The event listener | ||
| * @param <T> is the type parameter for the event's listener | ||
| * @return a new {@link EventScope} instance holding the event, its listener and the event phase {@link Event#DEFAULT_PHASE} | ||
| */ | ||
| static <T> EventScope registerScoped(Event<T> event, T listener) { | ||
Kilip1000 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return registerScoped(event, Event.DEFAULT_PHASE, listener); | ||
| } | ||
|
|
||
| /** | ||
| * @param event The {@link Event} to be registered in an {@link EventScope} | ||
| * @param phase The {@linkplain EventFactory#createWithPhases(Class, Function, Identifier...) event phase} | ||
| * @param listener The event listener | ||
| * @param <T> is the type parameter for the event's listener | ||
| * @return a new {@link EventScope} instance holding the event, its listener and the event phase | ||
| * @see EventFactory#createWithPhases(Class, Function, Identifier...) | ||
| */ | ||
| static <T> EventScope registerScoped(Event<T> event, Identifier phase, T listener) { | ||
| return EventScopeImpl.registerScoped(event, phase, listener); | ||
| } | ||
| } | ||
48 changes: 48 additions & 0 deletions
48
fabric-dev-debug-api-v1/src/main/java/net/fabricmc/fabric/impl/debug/dev/EventScopeImpl.java
This file contains hidden or 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,48 @@ | ||
| /* | ||
| * Copyright (c) 2016, 2017, 2018, 2019 FabricMC | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package net.fabricmc.fabric.impl.debug.dev; | ||
|
|
||
| import net.minecraft.resources.Identifier; | ||
|
|
||
| import net.fabricmc.fabric.api.debug.dev.v1.EventScope; | ||
| import net.fabricmc.fabric.api.event.Event; | ||
|
|
||
| public class EventScopeImpl<T> implements EventScope { | ||
| private final TestableArrayBackedEvent<T> event; | ||
| private final Identifier phase; | ||
| private final T listener; | ||
|
|
||
| public EventScopeImpl(TestableArrayBackedEvent<T> event, Identifier phase, T listener) { | ||
| this.event = event; | ||
| this.phase = phase; | ||
| this.listener = listener; | ||
| } | ||
|
|
||
| public static <T> EventScope registerScoped(Event<T> event, Identifier phase, T listener) { | ||
| if (!(event instanceof TestableArrayBackedEvent<T> testableEvent)) { | ||
| throw new IllegalArgumentException("Event is not testable, something has gone very wrong!"); | ||
| } | ||
|
|
||
| event.register(phase, listener); | ||
| return new EventScopeImpl<>(testableEvent, phase, listener); | ||
| } | ||
|
|
||
| @Override | ||
| public void close() { | ||
| event.unregister(phase, listener); | ||
| } | ||
| } |
41 changes: 41 additions & 0 deletions
41
...bug-api-v1/src/main/java/net/fabricmc/fabric/impl/debug/dev/TestableArrayBackedEvent.java
This file contains hidden or 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,41 @@ | ||
| /* | ||
| * Copyright (c) 2016, 2017, 2018, 2019 FabricMC | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package net.fabricmc.fabric.impl.debug.dev; | ||
|
|
||
| import java.util.Objects; | ||
| import java.util.function.Function; | ||
|
|
||
| import net.minecraft.resources.Identifier; | ||
|
|
||
| import net.fabricmc.fabric.impl.base.event.ArrayBackedEvent; | ||
|
|
||
| public class TestableArrayBackedEvent<T> extends ArrayBackedEvent<T> { | ||
| TestableArrayBackedEvent(Class<? super T> type, Function<T[], T> invokerFactory) { | ||
| super(type, invokerFactory); | ||
| } | ||
|
|
||
| public void unregister(Identifier phaseIdentifier, T listener) { | ||
| Objects.requireNonNull(phaseIdentifier, "Tried to unregister a listener for a null phase!"); | ||
| Objects.requireNonNull(listener, "Tried to unregister a null listener!"); | ||
|
|
||
| synchronized (lock) { | ||
| if (getOrCreatePhase(phaseIdentifier, false).removeListener(listener)) { | ||
| rebuildInvoker(handlers.length - 1); | ||
| } | ||
| } | ||
| } | ||
| } |
29 changes: 29 additions & 0 deletions
29
...bug-api-v1/src/main/java/net/fabricmc/fabric/impl/debug/dev/TestableEventFactoryImpl.java
This file contains hidden or 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,29 @@ | ||
| /* | ||
| * Copyright (c) 2016, 2017, 2018, 2019 FabricMC | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package net.fabricmc.fabric.impl.debug.dev; | ||
|
|
||
| import java.util.function.Function; | ||
|
|
||
| import net.fabricmc.fabric.impl.base.event.ArrayBackedEvent; | ||
| import net.fabricmc.fabric.impl.base.event.EventFactoryImpl; | ||
|
|
||
| public class TestableEventFactoryImpl extends EventFactoryImpl { | ||
| @Override | ||
| protected <T> ArrayBackedEvent<T> doCreateArrayBacked(Class<? super T> type, Function<T[], T> invokerFactory) { | ||
| return new TestableArrayBackedEvent<>(type, invokerFactory); | ||
| } | ||
| } |
1 change: 1 addition & 0 deletions
1
...src/main/resources/META-INF/services/net.fabricmc.fabric.impl.base.event.EventFactoryImpl
This file contains hidden or 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 @@ | ||
| net.fabricmc.fabric.impl.debug.dev.TestableEventFactoryImpl |
Binary file added
BIN
+1.52 KB
fabric-dev-debug-api-v1/src/main/resources/assets/fabric-dev-debug-api-v1/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions
21
fabric-dev-debug-api-v1/src/main/resources/fabric.mod.json
This file contains hidden or 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,21 @@ | ||
| { | ||
| "schemaVersion": 1, | ||
| "id": "fabric-dev-debug-api-v1", | ||
| "name": "Fabric Dev Debug API (v1)", | ||
| "version": "${version}", | ||
| "environment": "*", | ||
| "license": "Apache-2.0", | ||
| "icon": "assets/fabric-dev-debug-api-v1/icon.png", | ||
| "authors": [ | ||
| "FabricMC" | ||
| ], | ||
| "depends": { | ||
| "fabricloader": ">=0.18.4", | ||
| "fabric-api-base": "*", | ||
| "fabric-debug-api-v1": "*" | ||
| }, | ||
| "description": "An extension of Debug API with features only available in development environments.", | ||
Kilip1000 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| "custom": { | ||
| "fabric-api:module-lifecycle": "experimental" | ||
Kilip1000 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.