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

The Mod Protocol API, aka better validation of mod presence of both-side mods with extra protocol version syncing #4011

Open
wants to merge 12 commits into
base: 1.21.1
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
* @see ModProtocolIds
*/
public final class ClientModProtocolLookup {
/**
* A protocol version returned by {@code getSupportedProtocol} methods, when the server doesn't support the requested protocol.
*/
public static final int UNSUPPORTED = -1;
Patbox marked this conversation as resolved.
Show resolved Hide resolved
private ClientModProtocolLookup() { }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import net.minecraft.util.Identifier;

import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.networking.v1.ClientConfigurationNetworking;
import net.fabricmc.fabric.impl.modprotocol.ModProtocolImpl;
import net.fabricmc.fabric.impl.modprotocol.ModProtocolInit;
Expand All @@ -28,8 +29,8 @@
import net.fabricmc.fabric.impl.modprotocol.payload.ModProtocolRequestS2CPayload;
import net.fabricmc.fabric.impl.modprotocol.payload.ModProtocolResponseC2SPayload;

public final class ClientModProtocolInit {
public static void clientInit() {
public final class ClientModProtocolInit implements ClientModInitializer {
public void onInitializeClient() {
ClientConfigurationNetworking.registerGlobalReceiver(ModProtocolRequestS2CPayload.ID, (payload, context) -> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please use @Override.

var map = new HashMap<Identifier, ModProtocolImpl>(payload.modProtocol().size());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
* See {@link ModProtocolIds} for more information.</p>
*/
public final class ServerModProtocolLookup {
/**
* A protocol version returned by {@code getSupportedProtocol} methods, when the player doesn't support the requested protocol.
*/
public static final int UNSUPPORTED = -1;

private ServerModProtocolLookup() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,20 @@

import net.minecraft.util.Identifier;

import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.event.Event;
import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry;
import net.fabricmc.fabric.api.networking.v1.ServerConfigurationConnectionEvents;
import net.fabricmc.fabric.api.networking.v1.ServerConfigurationNetworking;
import net.fabricmc.fabric.impl.modprotocol.payload.ModProtocolRequestS2CPayload;
import net.fabricmc.fabric.impl.modprotocol.payload.ModProtocolResponseC2SPayload;

public final class ModProtocolInit {
public final class ModProtocolInit implements ModInitializer {
public static final String MOD_ID = "fabric-mod-protocol-api-v1";
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);
public static boolean frozen = false;

public static void init() {
public void onInitialize() {
Identifier phase = Identifier.of("fabric", "mod_protocol");
Identifier registrySync = Identifier.of("fabric", "registry_sync");

Expand Down
18 changes: 9 additions & 9 deletions fabric-mod-protocol-api-v1/src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"schemaVersion": 1,
"id": "fabric-mod-protocol-api-v1",
"name": "Fabric Mod Protocol API (v1)",
"description": "Versioned network protocol sync, validation and requirement system.",
"version": "${version}",
"environment": "*",
"license": "Apache-2.0",
Expand All @@ -17,25 +18,24 @@
],
"entrypoints": {
"main": [
"net.fabricmc.fabric.impl.modprotocol.ModProtocolInit::init"
"net.fabricmc.fabric.impl.modprotocol.ModProtocolInit"
],
"client": [
"net.fabricmc.fabric.impl.modprotocol.client.ClientModProtocolInit::clientInit"
"net.fabricmc.fabric.impl.modprotocol.client.ClientModProtocolInit"
]
},
"mixins": [
"fabric-mod-protocol-api-v1.mixins.json",
{
"config": "fabric-mod-protocol-api-v1.client.mixins.json",
"environment": "client"
}
],
"fabric-mod-protocol-api-v1.mixins.json",
{
"config": "fabric-mod-protocol-api-v1.client.mixins.json",
"environment": "client"
}
],
"depends": {
"fabricloader": ">=0.15.11",
"fabric-api-base": "*",
"fabric-networking-api-v1": "*"
},
"description": "Low-level, vanilla protocol oriented networking hooks.",
"custom": {
"fabric-api:module-lifecycle": "experimental"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import net.minecraft.util.Identifier;

import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.modprotocol.v1.ModProtocolIds;
import net.fabricmc.fabric.api.modprotocol.v1.ModProtocolRegistry;
import net.fabricmc.fabric.api.modprotocol.v1.ServerModProtocolLookup;
Expand All @@ -32,15 +33,15 @@
import net.fabricmc.loader.api.ModContainer;
import net.fabricmc.loader.api.metadata.CustomValue;

public final class ModProtocolTestmods {
public final class ModProtocolTestmods implements ModInitializer {
public static final String ID = "fabric-mod-protocol-api-v1-testmod";
public static final Logger LOGGER = LoggerFactory.getLogger(ID);

public static Identifier id(String name) {
return Identifier.of(ID, name);
}

public static void init() {
public void onInitialize() {
ModContainer modContainer = FabricLoader.getInstance().getModContainer(ID).get();

ModProtocolRegistry.register(ModProtocolIds.special("test_modification"), "Hello there", "1.12.2", IntList.of(1, 2, 3), true, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@
},
"entrypoints": {
"main": [
"net.fabricmc.fabric.test.modprotocol.ModProtocolTestmods::init"
],
"client": [

"net.fabricmc.fabric.test.modprotocol.ModProtocolTestmods"
]
},
"custom": {
Expand Down
Loading