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

Introduce proxyable and non-proxyable block capabilities #1446

Draft
wants to merge 1 commit into
base: 1.21.x
Choose a base branch
from

Conversation

Technici4n
Copy link
Member

Some capabilities are not safe to forward to another block. For example, AE2 has such a capability (that is used to find ME Network components). This can result in nonsensical connections, and even in crashes in some cases with mods like Capability Proxy.
This PR proposes that block capabilities may be marked as not being proxyable. Mods like Capability Proxy should stop proxying such capabilities. cc @rubensworks

@neoforged-pr-publishing
Copy link

neoforged-pr-publishing bot commented Aug 12, 2024

  • Publish PR to GitHub Packages

Last commit published: c312629e710d451aa01c34e39518f0af32497541.

PR Publishing

The artifacts published by this PR:

Repository Declaration

In order to use the artifacts published by the PR, add the following repository to your buildscript:

repositories {
    maven {
        name 'Maven for PR #1446' // https://github.com/neoforged/NeoForge/pull/1446
        url 'https://prmaven.neoforged.net/NeoForge/pr1446'
        content {
            includeModule('net.neoforged', 'neoforge')
            includeModule('net.neoforged', 'testframework')
        }
    }
}

MDK installation

In order to setup a MDK using the latest PR version, run the following commands in a terminal.
The script works on both *nix and Windows as long as you have the JDK bin folder on the path.
The script will clone the MDK in a folder named NeoForge-pr1446.
On Powershell you will need to remove the -L flag from the curl invocation.

mkdir NeoForge-pr1446
cd NeoForge-pr1446
curl -L https://prmaven.neoforged.net/NeoForge/pr1446/net/neoforged/neoforge/21.1.10-pr-1446-non-proxyable-block-caps/mdk-pr1446.zip -o mdk.zip
jar xf mdk.zip
rm mdk.zip || del mdk.zip

To test a production environment, you can download the installer from here.

@HenryLoenwind
Copy link
Contributor

I don't agree with this approach. Forwarding any capability you don't know the semantics of is a Very Bad Idea and should not be done.

Explicitly allowing other mods to handle unknown capabilities in random ways only opens the door for even more semantics-breaking uses. I see no way I would ever not set proxyable to false even when making a capability that would be proxyable using the correct capability-specific semantics.

A better solution would be to include an original target specifier to getCapability, which would allow proper handling of requests for capabilities that were forwarded (this is how http handles this). That way, the code that knows the semantics of a capability (because it hands it out) can properly handle forwarded requests if it needs to. This also would enable bidirectional requests like they are required for cable connections (although those would be tricky to implement as it breaks the assumption that each block side can have exactly one connection, something that will remain true in rendering the connection).

@Matyrobbrt Matyrobbrt added enhancement New (or improvement to existing) feature or request request for comments For gathering opinions on some topic or subject 1.21.2 Targeted at Minecraft 1.21.2 labels Aug 13, 2024
@Technici4n
Copy link
Member Author

Forwarding any capability you don't know the semantics of is a Very Bad Idea and should not be done.

Mods have been doing this for some time, for example Capability Proxy or Entangled. It is quite clearly useful for the capabilities where it is safe.

I see no way I would ever not set proxyable to false even when making a capability that would be proxyable using the correct capability-specific semantics.

The point here is that a lot of "transfer" capabilities, which are the ones that players generally want to proxy, are completely safe to proxy. This includes for example all of NeoForge's builtin block capabilities, as well as Mekanism gasses for example.

A better solution would be to include an original target specifier to getCapability

This would make the capability provider interface more complicated for everyone, in order to address what is pretty much a niche feature. There might be other solutions to this problem, but that doesn't feel like one.


An alternative is to flip the default: make capabilities non-proxyable by default, and require opt-in for capabilities where it makes sense.

@rubensworks
Copy link
Contributor

This approach looks good to me, should be straightforward to implement into Capability Proxy.

A better solution would be to include an original target specifier to getCapability

I agree this could be beneficial. But given the invasiveness of such changes, it would probably be better to keep it as a future (possible breaking) change, and continue with this PR here in the short-term.

*
* @see BlockCapability#isProxyable()
*/
public void setNonProxyable(BlockCapability<?, ?> capability) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this possible to be made to be chained so that we could call something like

    BlockCapability<SomeClass, Void> BLOCK = BlockCapability.createVoid(resource("some_handler"), SomeClass.class).nonProxyable();

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not a fan for the reason that it is dependent on classloading, and might be called at any time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1.21.2 Targeted at Minecraft 1.21.2 enhancement New (or improvement to existing) feature or request request for comments For gathering opinions on some topic or subject
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants