From b02b567de342bb4146f0d85bf7b94f3b98018036 Mon Sep 17 00:00:00 2001 From: asie Date: Fri, 24 May 2019 21:54:43 +0200 Subject: [PATCH] fix custom containers not working with new fabric-networking --- fabric-containers-v0/build.gradle | 2 +- .../gui/ScreenProviderRegistryImpl.java | 20 ++++++++++++------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/fabric-containers-v0/build.gradle b/fabric-containers-v0/build.gradle index 6a4b7f359..4a1b4225e 100644 --- a/fabric-containers-v0/build.gradle +++ b/fabric-containers-v0/build.gradle @@ -1,5 +1,5 @@ archivesBaseName = "fabric-containers-v0" -version = getSubprojectVersion(project, "0.1.0") +version = getSubprojectVersion(project, "0.1.1") dependencies { compile project(path: ':fabric-api-base', configuration: 'dev') diff --git a/fabric-containers-v0/src/main/java/net/fabricmc/fabric/impl/client/gui/ScreenProviderRegistryImpl.java b/fabric-containers-v0/src/main/java/net/fabricmc/fabric/impl/client/gui/ScreenProviderRegistryImpl.java index 6a1edee2a..bf18e7ba2 100644 --- a/fabric-containers-v0/src/main/java/net/fabricmc/fabric/impl/client/gui/ScreenProviderRegistryImpl.java +++ b/fabric-containers-v0/src/main/java/net/fabricmc/fabric/impl/client/gui/ScreenProviderRegistryImpl.java @@ -66,15 +66,21 @@ public class ScreenProviderRegistryImpl implements ScreenProviderRegistry { ClientSidePacketRegistry.INSTANCE.register(PacketTypes.OPEN_CONTAINER, (packetContext, packetByteBuf) -> { Identifier identifier = packetByteBuf.readIdentifier(); int syncId = packetByteBuf.readUnsignedByte(); + packetByteBuf.retain(); + MinecraftClient.getInstance().execute(() -> { - ContainerFactory factory = FACTORIES.get(identifier); - if (factory == null) { - LOGGER.error("No GUI factory found for {}!", identifier.toString()); - return; + try { + ContainerFactory factory = FACTORIES.get(identifier); + if (factory == null) { + LOGGER.error("No GUI factory found for {}!", identifier.toString()); + return; + } + AbstractContainerScreen gui = factory.create(syncId, identifier, packetContext.getPlayer(), packetByteBuf); + packetContext.getPlayer().container = gui.getContainer(); + MinecraftClient.getInstance().openScreen(gui); + } finally { + packetByteBuf.release(); } - AbstractContainerScreen gui = factory.create(syncId, identifier, packetContext.getPlayer(), packetByteBuf); - packetContext.getPlayer().container = gui.getContainer(); - MinecraftClient.getInstance().openScreen(gui); }); }); }