Fix crash opening GUIs on dedicated servers (#2139)

ExtendedClientHandlerFactory.create() is client-only.
Simply copy the relevant code into createMenu().

This is pretty terrible like the rest of the GUI code in GuiType.java, but this fixes the issue for now.

Fixes #2138.
This commit is contained in:
Raul Tambre 2020-06-24 07:27:16 +03:00 committed by GitHub
parent 07f06cb27a
commit b309635eaa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -144,14 +144,12 @@ public final class GuiType<T extends BlockEntity> implements IMachineGuiHandler
private final Identifier identifier;
private final Supplier<Supplier<GuiFactory<T>>> guiFactory;
private final ScreenHandlerRegistry.ExtendedClientHandlerFactory<BuiltScreenHandler> screenHandlerFactory;
private final ScreenHandlerType<BuiltScreenHandler> screenHandlerType;
private GuiType(Identifier identifier, Supplier<Supplier<GuiFactory<T>>> factorySupplierMeme) {
this.identifier = identifier;
this.guiFactory = factorySupplierMeme;
this.screenHandlerFactory = getScreenHandlerFactory();
this.screenHandlerType = ScreenHandlerRegistry.registerExtended(identifier, screenHandlerFactory);
this.screenHandlerType = ScreenHandlerRegistry.registerExtended(identifier, getScreenHandlerFactory());
RebornCore.clientOnly(() -> () -> ScreenRegistry.register(screenHandlerType, getGuiFactory()));
}
@ -190,9 +188,10 @@ public final class GuiType<T extends BlockEntity> implements IMachineGuiHandler
@Nullable
@Override
public ScreenHandler createMenu(int syncId, PlayerInventory inv, PlayerEntity player) {
PacketByteBuf buf = new PacketByteBuf(Unpooled.buffer());
buf.writeBlockPos(pos);
return screenHandlerFactory.create(syncId, inv, buf);
final BlockEntity blockEntity = player.world.getBlockEntity(pos);
BuiltScreenHandler screenHandler = ((BuiltScreenHandlerProvider) blockEntity).createScreenHandler(syncId, player);
screenHandler.setType(screenHandlerType);
return screenHandler;
}
});
}