mirror of
https://github.com/FabricMC/fabric.git
synced 2024-11-14 19:25:23 -05:00
Remove all inter-module dependencies on fabric-networking-v0 (#1291)
This migrates all uses of v0 networking to v1 api, and changes the readme to not mention networking-v0 in the example for dependencies.
This effectively makes v0 removable if it breaks in the future beyond repair. Though I expect v0 to last quite a bit longer.
(cherry picked from commit bf770ed853
)
This commit is contained in:
parent
2992645b97
commit
6692ae6057
9 changed files with 56 additions and 47 deletions
|
@ -49,7 +49,7 @@ Set<String> apiModules = [
|
|||
"fabric-api-base",
|
||||
"fabric-command-api-v1",
|
||||
"fabric-lifecycle-events-v1",
|
||||
"fabric-networking-v0"
|
||||
"fabric-networking-api-v1"
|
||||
]
|
||||
|
||||
// Add each module as a dependency
|
||||
|
@ -66,7 +66,7 @@ setOf(
|
|||
"fabric-api-base",
|
||||
"fabric-command-api-v1",
|
||||
"fabric-lifecycle-events-v1",
|
||||
"fabric-networking-v0"
|
||||
"fabric-networking-api-v1"
|
||||
).forEach {
|
||||
// Add each module as a dependency
|
||||
modImplementation(fabricApi.module(it, FABRIC_API_VERSION))
|
||||
|
|
|
@ -3,5 +3,5 @@ version = getSubprojectVersion(project, "0.1.10")
|
|||
|
||||
moduleDependencies(project, [
|
||||
'fabric-api-base',
|
||||
'fabric-networking-v0'
|
||||
'fabric-networking-api-v1'
|
||||
])
|
||||
|
|
|
@ -22,15 +22,15 @@ import java.util.Map;
|
|||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.network.ClientPlayerEntity;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.client.gui.screen.ingame.HandledScreen;
|
||||
import net.minecraft.screen.ScreenHandler;
|
||||
|
||||
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
|
||||
import net.fabricmc.fabric.api.client.screen.ContainerScreenFactory;
|
||||
import net.fabricmc.fabric.api.client.screen.ScreenProviderRegistry;
|
||||
import net.fabricmc.fabric.api.container.ContainerFactory;
|
||||
import net.fabricmc.fabric.api.network.ClientSidePacketRegistry;
|
||||
import net.fabricmc.fabric.impl.container.ContainerProviderImpl;
|
||||
|
||||
public class ScreenProviderRegistryImpl implements ScreenProviderRegistry {
|
||||
|
@ -67,12 +67,14 @@ public class ScreenProviderRegistryImpl implements ScreenProviderRegistry {
|
|||
}
|
||||
|
||||
public static void init() {
|
||||
ClientSidePacketRegistry.INSTANCE.register(ContainerProviderImpl.OPEN_CONTAINER, (packetContext, packetByteBuf) -> {
|
||||
Identifier identifier = packetByteBuf.readIdentifier();
|
||||
int syncId = packetByteBuf.readUnsignedByte();
|
||||
packetByteBuf.retain();
|
||||
ClientPlayNetworking.registerGlobalReceiver(ContainerProviderImpl.OPEN_CONTAINER, (client, handler, buf, responseSender) -> {
|
||||
Identifier identifier = buf.readIdentifier();
|
||||
int syncId = buf.readUnsignedByte();
|
||||
|
||||
MinecraftClient.getInstance().execute(() -> {
|
||||
// Retain the buf since we must open the screen handler with it's extra modded data on the client thread
|
||||
buf.retain();
|
||||
|
||||
client.execute(() -> {
|
||||
try {
|
||||
ContainerFactory<HandledScreen> factory = FACTORIES.get(identifier);
|
||||
|
||||
|
@ -81,11 +83,13 @@ public class ScreenProviderRegistryImpl implements ScreenProviderRegistry {
|
|||
return;
|
||||
}
|
||||
|
||||
HandledScreen gui = factory.create(syncId, identifier, packetContext.getPlayer(), packetByteBuf);
|
||||
packetContext.getPlayer().currentScreenHandler = gui.getScreenHandler();
|
||||
MinecraftClient.getInstance().openScreen(gui);
|
||||
ClientPlayerEntity player = client.player;
|
||||
HandledScreen<?> gui = factory.create(syncId, identifier, player, buf);
|
||||
|
||||
player.currentScreenHandler = gui.getScreenHandler();
|
||||
client.openScreen(gui);
|
||||
} finally {
|
||||
packetByteBuf.release();
|
||||
buf.release();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
"depends": {
|
||||
"fabricloader": ">=0.4.0",
|
||||
"fabric-api-base": "*",
|
||||
"fabric-networking-v0": "*"
|
||||
"fabric-networking-api-v1": "*"
|
||||
},
|
||||
"description": "Adds hooks for containers.",
|
||||
"mixins": [
|
||||
|
|
|
@ -6,9 +6,7 @@
|
|||
"depends": {
|
||||
"fabricloader": ">=0.4.0",
|
||||
"minecraft": ">=1.16-rc.3",
|
||||
"fabric-api-base": "*",
|
||||
"fabric-registry-sync-v0": "*",
|
||||
"fabric-networking-v0": "*"
|
||||
"fabric-api-base": "*"
|
||||
},
|
||||
"mixins": [
|
||||
"fabric-dimensions-v1.mixins.json"
|
||||
|
|
|
@ -12,5 +12,5 @@ dependencies {
|
|||
|
||||
moduleDependencies(project, [
|
||||
'fabric-api-base',
|
||||
'fabric-networking-v0'
|
||||
'fabric-networking-api-v1'
|
||||
])
|
||||
|
|
|
@ -28,7 +28,7 @@ import net.minecraft.server.network.ServerPlayerEntity;
|
|||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
|
||||
import net.fabricmc.fabric.api.network.ServerSidePacketRegistry;
|
||||
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
|
||||
import net.fabricmc.fabric.api.screenhandler.v1.ExtendedScreenHandlerFactory;
|
||||
|
||||
public final class Networking {
|
||||
|
@ -67,6 +67,6 @@ public final class Networking {
|
|||
buf.writeText(factory.getDisplayName());
|
||||
factory.writeScreenOpeningData(player, buf);
|
||||
|
||||
ServerSidePacketRegistry.INSTANCE.sendToPlayer(player, OPEN_ID, buf);
|
||||
ServerPlayNetworking.send(player, OPEN_ID, buf);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ import net.minecraft.util.registry.Registry;
|
|||
import net.fabricmc.api.ClientModInitializer;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.fabricmc.fabric.api.network.ClientSidePacketRegistry;
|
||||
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
|
||||
import net.fabricmc.fabric.impl.screenhandler.ExtendedScreenHandlerType;
|
||||
import net.fabricmc.fabric.impl.screenhandler.Networking;
|
||||
|
||||
|
@ -43,45 +43,52 @@ public final class ClientNetworking implements ClientModInitializer {
|
|||
|
||||
@Override
|
||||
public void onInitializeClient() {
|
||||
ClientSidePacketRegistry.INSTANCE.register(Networking.OPEN_ID, (ctx, buf) -> {
|
||||
ClientPlayNetworking.registerGlobalReceiver(Networking.OPEN_ID, (client, handler, buf, responseSender) -> {
|
||||
Identifier typeId = buf.readIdentifier();
|
||||
int syncId = buf.readVarInt();
|
||||
Text title = buf.readText();
|
||||
// Retain the buf since we must open the screen handler with it's extra modded data on the client thread
|
||||
// The buf will be released after the screen is opened
|
||||
buf.retain();
|
||||
ctx.getTaskQueue().execute(() -> openScreen(typeId, syncId, title, buf));
|
||||
|
||||
client.execute(() -> this.openScreen(typeId, syncId, title, buf));
|
||||
});
|
||||
}
|
||||
|
||||
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||
private void openScreen(Identifier typeId, int syncId, Text title, PacketByteBuf buf) {
|
||||
ScreenHandlerType<?> type = Registry.SCREEN_HANDLER.get(typeId);
|
||||
try {
|
||||
ScreenHandlerType<?> type = Registry.SCREEN_HANDLER.get(typeId);
|
||||
|
||||
if (type == null) {
|
||||
LOGGER.warn("Unknown screen handler ID: {}", typeId);
|
||||
return;
|
||||
}
|
||||
if (type == null) {
|
||||
LOGGER.warn("Unknown screen handler ID: {}", typeId);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(type instanceof ExtendedScreenHandlerType<?>)) {
|
||||
LOGGER.warn("Received extended opening packet for non-extended screen handler {}", typeId);
|
||||
return;
|
||||
}
|
||||
if (!(type instanceof ExtendedScreenHandlerType<?>)) {
|
||||
LOGGER.warn("Received extended opening packet for non-extended screen handler {}", typeId);
|
||||
return;
|
||||
}
|
||||
|
||||
HandledScreens.Provider screenFactory = HandledScreens.getProvider(type);
|
||||
HandledScreens.Provider screenFactory = HandledScreens.getProvider(type);
|
||||
|
||||
if (screenFactory != null) {
|
||||
MinecraftClient client = MinecraftClient.getInstance();
|
||||
PlayerEntity player = client.player;
|
||||
if (screenFactory != null) {
|
||||
MinecraftClient client = MinecraftClient.getInstance();
|
||||
PlayerEntity player = client.player;
|
||||
|
||||
Screen screen = screenFactory.create(
|
||||
((ExtendedScreenHandlerType<?>) type).create(syncId, player.getInventory(), buf),
|
||||
player.getInventory(),
|
||||
title
|
||||
);
|
||||
Screen screen = screenFactory.create(
|
||||
((ExtendedScreenHandlerType<?>) type).create(syncId, player.inventory, buf),
|
||||
player.getInventory(),
|
||||
title
|
||||
);
|
||||
|
||||
player.currentScreenHandler = ((ScreenHandlerProvider<?>) screen).getScreenHandler();
|
||||
client.openScreen(screen);
|
||||
} else {
|
||||
LOGGER.warn("Screen not registered for screen handler {}!", typeId);
|
||||
player.currentScreenHandler = ((ScreenHandlerProvider<?>) screen).getScreenHandler();
|
||||
client.openScreen(screen);
|
||||
} else {
|
||||
LOGGER.warn("Screen not registered for screen handler {}!", typeId);
|
||||
}
|
||||
} finally {
|
||||
buf.release(); // Release the buf
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
"depends": {
|
||||
"fabricloader": ">=0.8.0",
|
||||
"fabric-api-base": "*",
|
||||
"fabric-networking-v0": "*"
|
||||
"fabric-networking-api-v1": "*"
|
||||
},
|
||||
"entrypoints": {
|
||||
"client": ["net.fabricmc.fabric.impl.screenhandler.client.ClientNetworking"]
|
||||
|
|
Loading…
Reference in a new issue