-
-
Notifications
You must be signed in to change notification settings - Fork 179
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[1.21] Implement common networking with config tasks (#1483)
- Loading branch information
1 parent
38ed034
commit 659d33f
Showing
6 changed files
with
113 additions
and
30 deletions.
There are no files selected for viewing
This file contains 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 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 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
37 changes: 37 additions & 0 deletions
37
src/main/java/net/neoforged/neoforge/network/configuration/CommonRegisterTask.java
This file contains 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,37 @@ | ||
/* | ||
* Copyright (c) NeoForged and contributors | ||
* SPDX-License-Identifier: LGPL-2.1-only | ||
*/ | ||
|
||
package net.neoforged.neoforge.network.configuration; | ||
|
||
import java.util.function.Consumer; | ||
import net.minecraft.network.ConnectionProtocol; | ||
import net.minecraft.network.protocol.PacketFlow; | ||
import net.minecraft.network.protocol.common.custom.CustomPacketPayload; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.neoforged.neoforge.internal.versions.neoforge.NeoForgeVersion; | ||
import net.neoforged.neoforge.network.payload.CommonRegisterPayload; | ||
import net.neoforged.neoforge.network.registration.NetworkRegistry; | ||
import org.jetbrains.annotations.ApiStatus; | ||
|
||
/** | ||
* Common Register configuration task. After completion of {@link CommonVersionTask}, sends a {@link CommonRegisterPayload} to the client | ||
* containing all known serverbound channels, and awaits a response containing the client's known clientbound channels. | ||
*/ | ||
@ApiStatus.Internal | ||
public record CommonRegisterTask() implements ICustomConfigurationTask { | ||
public static final Type TYPE = new Type(ResourceLocation.fromNamespaceAndPath(NeoForgeVersion.MOD_ID, "common_register")); | ||
|
||
@Override | ||
public Type type() { | ||
return TYPE; | ||
} | ||
|
||
@Override | ||
public void run(Consumer<CustomPacketPayload> sender) { | ||
// There is currently no implementation for a version handshake, and the only existing version is 1, so we only send 1. | ||
// Version negotiation will have to be implemented properly if a version 2 is ever added. | ||
sender.accept(new CommonRegisterPayload(1, ConnectionProtocol.PLAY, NetworkRegistry.getCommonPlayChannels(PacketFlow.SERVERBOUND))); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/main/java/net/neoforged/neoforge/network/configuration/CommonVersionTask.java
This file contains 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,32 @@ | ||
/* | ||
* Copyright (c) NeoForged and contributors | ||
* SPDX-License-Identifier: LGPL-2.1-only | ||
*/ | ||
|
||
package net.neoforged.neoforge.network.configuration; | ||
|
||
import java.util.function.Consumer; | ||
import net.minecraft.network.protocol.common.custom.CustomPacketPayload; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.neoforged.neoforge.internal.versions.neoforge.NeoForgeVersion; | ||
import net.neoforged.neoforge.network.payload.CommonVersionPayload; | ||
import org.jetbrains.annotations.ApiStatus; | ||
|
||
/** | ||
* Common Version configuration task. Initiated after registry sync to begin the c:register handshake. | ||
* The server will start the task, send c:version to the client, and await a reply. Upon reply, we transition to {@link CommonRegisterTask}. | ||
*/ | ||
@ApiStatus.Internal | ||
public record CommonVersionTask() implements ICustomConfigurationTask { | ||
public static final Type TYPE = new Type(ResourceLocation.fromNamespaceAndPath(NeoForgeVersion.MOD_ID, "common_version")); | ||
|
||
@Override | ||
public Type type() { | ||
return TYPE; | ||
} | ||
|
||
@Override | ||
public void run(Consumer<CustomPacketPayload> sender) { | ||
sender.accept(new CommonVersionPayload()); | ||
} | ||
} |
This file contains 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