-
Notifications
You must be signed in to change notification settings - Fork 507
Debug API #5136
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
sylv256
wants to merge
4
commits into
FabricMC:26.1
Choose a base branch
from
sylv256:debug-api
base: 26.1
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.
+981
−0
Open
Debug API #5136
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| version = getSubprojectVersion(project) | ||
|
|
||
| moduleDependencies(project, [ | ||
| 'fabric-api-base' | ||
| ]) | ||
|
|
||
| testDependencies(project, [ | ||
| ]) | ||
|
|
||
| loom { | ||
| accessWidenerPath = file("src/main/resources/fabric-debug-api-v1.accesswidener") | ||
| } |
62 changes: 62 additions & 0 deletions
62
.../client/java/net/fabricmc/fabric/api/debug/v1/client/ClientDebugSubscriptionRegistry.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,62 @@ | ||
| /* | ||
| * 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.v1.client; | ||
|
|
||
| import java.util.Objects; | ||
|
|
||
| import net.minecraft.util.debug.DebugSubscription; | ||
|
|
||
| import net.fabricmc.fabric.impl.debug.client.ClientDebugSubscriptionRegistryImpl; | ||
|
|
||
| /// A registry for [debug subscriptions][DebugSubscription] on the client, | ||
| /// allowing listening to registered debug subscriptions on the client. | ||
| public final class ClientDebugSubscriptionRegistry { | ||
| /// Registers a [DebugSubscription] on the client. | ||
| /// | ||
| /// **Note:** this will register **outside development environments** if it | ||
| /// is not checked. Surround calls to this method with | ||
| /// [net.fabricmc.loader.api.FabricLoader#isDevelopmentEnvironment] if you | ||
| /// do not intend for a debug feature to be present in production. | ||
| /// | ||
| /// @param <T> the inner type of the [DebugSubscription]. | ||
| /// @param debugSubscription the [DebugSubscription] to register. | ||
| public static <T> void register(DebugSubscription<T> debugSubscription) { | ||
| Objects.requireNonNull(debugSubscription); | ||
| ClientDebugSubscriptionRegistryImpl.register(debugSubscription); | ||
| } | ||
|
|
||
| /// Registers a [DebugSubscription] on the client if the `isEnabledFlag` | ||
| /// parameter is `true`. | ||
| /// | ||
| /// **Note:** this will register **outside development environments** if it | ||
| /// is not checked. Surround calls to this method with | ||
| /// [net.fabricmc.loader.api.FabricLoader#isDevelopmentEnvironment] if you | ||
| /// do not intend for a debug feature to be present in production. | ||
| /// | ||
| /// @param <T> the inner type of the [DebugSubscription]. | ||
| /// @param debugSubscription the [DebugSubscription] to register. | ||
| /// @param isEnabledFlag the flag determining whether to register this | ||
| /// [DebugSubscription]. | ||
| public static <T> void register( | ||
| DebugSubscription<T> debugSubscription, | ||
| boolean isEnabledFlag | ||
| ) { | ||
| if (isEnabledFlag) { | ||
| register(debugSubscription); | ||
| } | ||
| } | ||
| } |
29 changes: 29 additions & 0 deletions
29
...rc/client/java/net/fabricmc/fabric/api/debug/v1/client/renderer/DebugRendererFactory.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.api.debug.v1.client.renderer; | ||
|
|
||
| import net.minecraft.client.Minecraft; | ||
| import net.minecraft.client.renderer.debug.DebugRenderer; | ||
|
|
||
| /// A constructor for a | ||
| /// [debug subscription][net.minecraft.util.debug.DebugSubscription] renderer. | ||
| @FunctionalInterface | ||
| public interface DebugRendererFactory { | ||
| /// @return a new renderer for a | ||
| /// [debug subscription][net.minecraft.util.debug.DebugSubscription]. | ||
| DebugRenderer.SimpleDebugRenderer create(Minecraft minecraft); | ||
| } | ||
58 changes: 58 additions & 0 deletions
58
...c/client/java/net/fabricmc/fabric/api/debug/v1/client/renderer/DebugRendererRegistry.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,58 @@ | ||
| /* | ||
| * 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.v1.client.renderer; | ||
|
|
||
| import java.util.Objects; | ||
|
|
||
| import net.minecraft.util.debug.DebugSubscription; | ||
|
|
||
| import net.fabricmc.fabric.impl.debug.client.renderer.DebugRendererRegistryImpl; | ||
|
|
||
| /// Registry for custom | ||
| /// [debug renderers][net.minecraft.client.renderer.debug.DebugRenderer.SimpleDebugRenderer]. | ||
| public final class DebugRendererRegistry { | ||
| /// Registers a debug renderer for the given [DebugSubscription]. | ||
| /// | ||
| /// @param <T> the inner type of the [DebugSubscription]. | ||
| /// @param debugSubscription the [DebugSubscription]. | ||
| /// @param rendererFactory the factory/constructor for the debug renderer. | ||
| public static <T> void register( | ||
| DebugSubscription<T> debugSubscription, | ||
| DebugRendererFactory rendererFactory | ||
| ) { | ||
| Objects.requireNonNull(debugSubscription); | ||
| DebugRendererRegistryImpl.register(debugSubscription, rendererFactory); | ||
| } | ||
|
|
||
| /// Registers a debug renderer for the given [DebugSubscription] if | ||
| /// `isEnabledFlag` is `true`. | ||
| /// | ||
| /// @param <T> the inner type of the [DebugSubscription]. | ||
| /// @param debugSubscription the [DebugSubscription]. | ||
| /// @param rendererFactory the factory/constructor for the debug renderer. | ||
| /// @param isEnabledFlag the flag determining whether to register this debug | ||
| /// renderer. | ||
| public static <T> void register( | ||
| DebugSubscription<T> debugSubscription, | ||
| DebugRendererFactory rendererFactory, | ||
| boolean isEnabledFlag | ||
| ) { | ||
| if (isEnabledFlag) { | ||
| register(debugSubscription, rendererFactory); | ||
| } | ||
| } | ||
| } |
30 changes: 30 additions & 0 deletions
30
...lient/java/net/fabricmc/fabric/impl/debug/client/ClientDebugSubscriptionRegistryImpl.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,30 @@ | ||
| /* | ||
| * 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.client; | ||
|
|
||
| import java.util.HashSet; | ||
| import java.util.Set; | ||
|
|
||
| import net.minecraft.util.debug.DebugSubscription; | ||
|
|
||
| public final class ClientDebugSubscriptionRegistryImpl { | ||
| public static final Set<DebugSubscription<?>> DEBUG_SUBSCRIPTIONS = new HashSet<>(); | ||
|
|
||
| public static <T> void register(DebugSubscription<T> debugSubscription) { | ||
| DEBUG_SUBSCRIPTIONS.add(debugSubscription); | ||
| } | ||
| } |
59 changes: 59 additions & 0 deletions
59
...client/java/net/fabricmc/fabric/impl/debug/client/renderer/DebugRendererRegistryImpl.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,59 @@ | ||
| /* | ||
| * 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.client.renderer; | ||
|
|
||
| import java.util.HashSet; | ||
| import java.util.Objects; | ||
| import java.util.Set; | ||
|
|
||
| import net.minecraft.util.debug.DebugSubscription; | ||
|
|
||
| import net.fabricmc.fabric.api.debug.v1.client.renderer.DebugRendererFactory; | ||
|
|
||
| public final class DebugRendererRegistryImpl { | ||
| public static final Set<Entry> RENDERERS = new HashSet<>(); | ||
|
|
||
| public static <T> void register( | ||
| DebugSubscription<T> debugSubscription, | ||
| DebugRendererFactory rendererFactory | ||
| ) { | ||
| RENDERERS.add(new Entry(debugSubscription, rendererFactory)); | ||
| } | ||
|
|
||
| public record Entry( | ||
| DebugSubscription<?> debugSubscription, | ||
| DebugRendererFactory rendererFactory | ||
| ) { | ||
| // Ensure DebugSubscriptions with different values don't both | ||
| // get into the Set, causing undesirable behavior | ||
|
|
||
| @Override | ||
| public boolean equals(Object o) { | ||
| if (o == null || getClass() != o.getClass()) return false; | ||
| Entry entry = (Entry) o; | ||
| return Objects.equals( | ||
| debugSubscription, | ||
| entry.debugSubscription | ||
| ); | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hashCode(debugSubscription); | ||
| } | ||
| } | ||
| } |
44 changes: 44 additions & 0 deletions
44
...v1/src/client/java/net/fabricmc/fabric/mixin/debug/client/ClientDebugSubscriberMixin.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,44 @@ | ||
| /* | ||
| * 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.mixin.debug.client; | ||
|
|
||
| import java.util.Set; | ||
|
|
||
| import com.llamalad7.mixinextras.sugar.Local; | ||
| import org.spongepowered.asm.mixin.Mixin; | ||
| import org.spongepowered.asm.mixin.injection.At; | ||
| import org.spongepowered.asm.mixin.injection.Inject; | ||
| import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
|
|
||
| import net.minecraft.client.multiplayer.ClientDebugSubscriber; | ||
| import net.minecraft.util.debug.DebugSubscription; | ||
|
|
||
| import net.fabricmc.fabric.impl.debug.client.ClientDebugSubscriptionRegistryImpl; | ||
|
|
||
| @Mixin(ClientDebugSubscriber.class) | ||
| public abstract class ClientDebugSubscriberMixin { | ||
| @Inject( | ||
| method = "requestedSubscriptions", | ||
| at = @At("RETURN") | ||
| ) | ||
| private void addSubscribers( | ||
| CallbackInfoReturnable<Set<DebugSubscription<?>>> cir, | ||
| @Local(name = "subscriptions") Set<DebugSubscription<?>> subscriptions | ||
| ) { | ||
| subscriptions.addAll(ClientDebugSubscriptionRegistryImpl.DEBUG_SUBSCRIPTIONS); | ||
| } | ||
| } |
52 changes: 52 additions & 0 deletions
52
...bug-api-v1/src/client/java/net/fabricmc/fabric/mixin/debug/client/DebugRendererMixin.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,52 @@ | ||
| /* | ||
| * 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.mixin.debug.client; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import org.spongepowered.asm.mixin.Final; | ||
| import org.spongepowered.asm.mixin.Mixin; | ||
| import org.spongepowered.asm.mixin.Shadow; | ||
| import org.spongepowered.asm.mixin.injection.At; | ||
| import org.spongepowered.asm.mixin.injection.Inject; | ||
| import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
|
||
| import net.minecraft.client.Minecraft; | ||
| import net.minecraft.client.renderer.debug.DebugRenderer; | ||
|
|
||
| import net.fabricmc.fabric.impl.debug.client.renderer.DebugRendererRegistryImpl; | ||
|
|
||
| @Mixin(DebugRenderer.class) | ||
| public abstract class DebugRendererMixin { | ||
| @Shadow | ||
| @Final | ||
| private List<DebugRenderer.SimpleDebugRenderer> renderers; | ||
|
|
||
| private DebugRendererMixin() { | ||
| } | ||
|
|
||
| @Inject(method = "refreshRendererList", at = @At("RETURN")) | ||
| private void registerRenderers(CallbackInfo ci) { | ||
| Minecraft minecraft = Minecraft.getInstance(); | ||
|
|
||
| for (DebugRendererRegistryImpl.Entry entry : DebugRendererRegistryImpl.RENDERERS) { | ||
| // a Stream#map would make the most sense here, but they're banned | ||
| // so you have to suffer with me now | ||
| renderers.add(entry.rendererFactory().create(minecraft)); | ||
| } | ||
| } | ||
| } |
18 changes: 18 additions & 0 deletions
18
fabric-debug-api-v1/src/client/resources/fabric-debug-api-v1.client.mixins.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,18 @@ | ||
| { | ||
| "required": true, | ||
| "package": "net.fabricmc.fabric.mixin.debug.client", | ||
| "compatibilityLevel": "JAVA_25", | ||
| "client": [ | ||
| "ClientDebugSubscriberMixin", | ||
| "DebugRendererMixin" | ||
| ], | ||
| "injectors": { | ||
| "defaultRequire": 1 | ||
| }, | ||
| "overwrites": { | ||
| "requireAnnotations": true | ||
| }, | ||
| "mixinextras": { | ||
| "minVersion": "0.5.0" | ||
| } | ||
| } |
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.
Nitpick: I would never call or describe an interface as "a constructor", this word has already a very specific meaning in Java, and we should stick to it.
This is a factory interface, and should be described as such.
We could instead say
A factory to create a [debug subscription][...] renderer.instead.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.
I'll try to fix this when I get time (probably this Saturday EST) as I have university starting tomorrow.