fix custom containers not working with new fabric-networking

This commit is contained in:
asie 2019-05-24 21:54:43 +02:00
parent d36c5fcf8e
commit b02b567de3
2 changed files with 14 additions and 8 deletions

View file

@ -1,5 +1,5 @@
archivesBaseName = "fabric-containers-v0" archivesBaseName = "fabric-containers-v0"
version = getSubprojectVersion(project, "0.1.0") version = getSubprojectVersion(project, "0.1.1")
dependencies { dependencies {
compile project(path: ':fabric-api-base', configuration: 'dev') compile project(path: ':fabric-api-base', configuration: 'dev')

View file

@ -66,15 +66,21 @@ public class ScreenProviderRegistryImpl implements ScreenProviderRegistry {
ClientSidePacketRegistry.INSTANCE.register(PacketTypes.OPEN_CONTAINER, (packetContext, packetByteBuf) -> { ClientSidePacketRegistry.INSTANCE.register(PacketTypes.OPEN_CONTAINER, (packetContext, packetByteBuf) -> {
Identifier identifier = packetByteBuf.readIdentifier(); Identifier identifier = packetByteBuf.readIdentifier();
int syncId = packetByteBuf.readUnsignedByte(); int syncId = packetByteBuf.readUnsignedByte();
packetByteBuf.retain();
MinecraftClient.getInstance().execute(() -> { MinecraftClient.getInstance().execute(() -> {
ContainerFactory<AbstractContainerScreen> factory = FACTORIES.get(identifier); try {
if (factory == null) { ContainerFactory<AbstractContainerScreen> factory = FACTORIES.get(identifier);
LOGGER.error("No GUI factory found for {}!", identifier.toString()); if (factory == null) {
return; 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);
}); });
}); });
} }