Add internal API to get the configuration channels the client accepts during play. ()

* Add internal API to get the configuration channels the client accpets during play.

* Actually rerun configuration when using the debugconfig command.
This commit is contained in:
modmuss 2025-03-09 13:45:30 +00:00 committed by GitHub
parent 4a1de890dd
commit 97e245f913
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 141 additions and 0 deletions
fabric-networking-api-v1/src

View file

@ -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.networking;
import java.util.Set;
import org.jetbrains.annotations.Nullable;
import net.minecraft.util.Identifier;
public interface FabricRegistryByteBuf {
void fabric_setSendableConfigurationChannels(Set<Identifier> globalChannels);
@Nullable
Set<Identifier> fabric_getSendableConfigurationChannels();
}

View file

@ -0,0 +1,33 @@
/*
* 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.networking;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
import net.minecraft.server.command.DebugConfigCommand;
import net.minecraft.server.network.ServerConfigurationNetworkHandler;
@Mixin(DebugConfigCommand.class)
public class DebugConfigCommandMixin {
// endConfiguration() does not re-run the configuration tasks. This means we loose the state such as what channels we can send on when in the play phase.
@Redirect(method = "executeUnconfig", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/network/ServerConfigurationNetworkHandler;endConfiguration()V"))
private static void sendConfigurations(ServerConfigurationNetworkHandler networkHandler) {
networkHandler.sendConfigurations();
}
}

View file

@ -0,0 +1,45 @@
/*
* 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.networking;
import java.util.Objects;
import java.util.Set;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import net.minecraft.network.RegistryByteBuf;
import net.minecraft.util.Identifier;
import net.fabricmc.fabric.impl.networking.FabricRegistryByteBuf;
@Mixin(RegistryByteBuf.class)
public class RegistryByteBufMixin implements FabricRegistryByteBuf {
@Unique
private Set<Identifier> sendableConfigurationChannels = null;
@Override
public void fabric_setSendableConfigurationChannels(Set<Identifier> globalChannels) {
this.sendableConfigurationChannels = Objects.requireNonNull(globalChannels);
}
@Override
public @Nullable Set<Identifier> fabric_getSendableConfigurationChannels() {
return this.sendableConfigurationChannels;
}
}

View file

@ -17,7 +17,12 @@
package net.fabricmc.fabric.mixin.networking;
import java.util.Queue;
import java.util.Set;
import java.util.function.Function;
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import io.netty.buffer.ByteBuf;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
@ -28,6 +33,8 @@ import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import net.minecraft.network.ClientConnection;
import net.minecraft.network.RegistryByteBuf;
import net.minecraft.registry.DynamicRegistryManager;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ConnectedClientData;
import net.minecraft.server.network.ServerCommonNetworkHandler;
@ -35,6 +42,7 @@ import net.minecraft.server.network.ServerConfigurationNetworkHandler;
import net.minecraft.server.network.ServerPlayerConfigurationTask;
import net.fabricmc.fabric.api.networking.v1.FabricServerConfigurationNetworkHandler;
import net.fabricmc.fabric.impl.networking.FabricRegistryByteBuf;
import net.fabricmc.fabric.impl.networking.NetworkHandlerExtensions;
import net.fabricmc.fabric.impl.networking.server.ServerConfigurationNetworkAddon;
@ -163,4 +171,13 @@ public abstract class ServerConfigurationNetworkHandlerMixin extends ServerCommo
this.currentTask = null;
sendConfigurations();
}
@WrapOperation(method = "onReady", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/RegistryByteBuf;makeFactory(Lnet/minecraft/registry/DynamicRegistryManager;)Ljava/util/function/Function;"))
private Function<ByteBuf, RegistryByteBuf> bindChannelInfo(DynamicRegistryManager registryManager, Operation<Function<ByteBuf, RegistryByteBuf>> original) {
return original.call(registryManager).andThen(registryByteBuf -> {
FabricRegistryByteBuf fabricRegistryByteBuf = (FabricRegistryByteBuf) registryByteBuf;
fabricRegistryByteBuf.fabric_setSendableConfigurationChannels(Set.copyOf(addon.getSendableChannels()));
return registryByteBuf;
});
}
}

View file

@ -9,10 +9,12 @@
"CustomPayloadC2SPacketMixin",
"CustomPayloadS2CPacketMixin",
"CustomPayloadPacketCodecMixin",
"DebugConfigCommandMixin",
"EntityTrackerEntryMixin",
"LoginQueryRequestS2CPacketMixin",
"LoginQueryResponseC2SPacketMixin",
"PlayerManagerMixin",
"RegistryByteBufMixin",
"ServerCommonNetworkHandlerMixin",
"ServerConfigurationNetworkHandlerMixin",
"ServerLoginNetworkHandlerMixin",

View file

@ -20,7 +20,9 @@ import static com.mojang.brigadier.arguments.StringArgumentType.string;
import static net.minecraft.server.command.CommandManager.argument;
import static net.minecraft.server.command.CommandManager.literal;
import java.util.Collection;
import java.util.List;
import java.util.Objects;
import com.mojang.brigadier.Command;
import com.mojang.brigadier.CommandDispatcher;
@ -37,6 +39,7 @@ import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;
import net.minecraft.text.TextCodecs;
import net.minecraft.util.Identifier;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.ModInitializer;
@ -45,7 +48,9 @@ import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry;
import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
import net.fabricmc.fabric.impl.networking.FabricRegistryByteBuf;
import net.fabricmc.fabric.test.networking.NetworkingTestmods;
import net.fabricmc.fabric.test.networking.common.NetworkingCommonTest;
import net.fabricmc.loader.api.FabricLoader;
public final class NetworkingPlayPacketTest implements ModInitializer {
@ -132,6 +137,15 @@ public final class NetworkingPlayPacketTest implements ModInitializer {
}
public void write(RegistryByteBuf buf) {
// Test that we can get the configuration channels that the client accepts
FabricRegistryByteBuf fabricRegistryByteBuf = (FabricRegistryByteBuf) buf;
Collection<Identifier> channels = fabricRegistryByteBuf.fabric_getSendableConfigurationChannels();
Objects.requireNonNull(channels);
if (!channels.contains(NetworkingCommonTest.CommonPayload.ID.id())) {
throw new IllegalStateException("Expected common payload channel to be sent");
}
TextCodecs.REGISTRY_PACKET_CODEC.encode(buf, this.message);
}