Fix screen handler test mod crashing on dedicated server. ()

This commit is contained in:
i509VCB 2020-06-18 13:45:04 -07:00 committed by GitHub
parent 28a9468044
commit c10360a765
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 2 deletions
fabric-screen-handler-api-v1/src
main/java/net/fabricmc/fabric/api/screenhandler/v1
testmod/java/net/fabricmc/fabric/test/screenhandler

View file

@ -81,7 +81,8 @@ public final class ScreenHandlerRegistry {
*/
public static <T extends ScreenHandler> ScreenHandlerType<T> registerSimple(Identifier id, SimpleClientHandlerFactory<T> factory) {
// Wrap our factory in vanilla's factory; it will not be public for users.
ScreenHandlerType<T> type = new ScreenHandlerType<>(factory::create);
// noinspection Convert2MethodRef - Must be a lambda or else dedicated server will crash
ScreenHandlerType<T> type = new ScreenHandlerType<>((syncId, inventory) -> factory.create(syncId, inventory));
return Registry.register(Registry.SCREEN_HANDLER, id, type);
}

View file

@ -44,7 +44,7 @@ public class ScreenHandlerTest implements ModInitializer {
public static final Item POSITIONED_BAG = new PositionedBagItem(new Item.Settings().group(ItemGroup.TOOLS).maxCount(1));
public static final Block BOX = new BoxBlock(AbstractBlock.Settings.copy(Blocks.OAK_WOOD));
public static final Item BOX_ITEM = new BlockItem(BOX, new Item.Settings().group(ItemGroup.DECORATIONS));
public static final BlockEntityType<?> BOX_ENTITY = BlockEntityType.Builder.create(BoxBlockEntity::new, BOX).build(null);
public static final BlockEntityType<BoxBlockEntity> BOX_ENTITY = BlockEntityType.Builder.create(BoxBlockEntity::new, BOX).build(null);
public static final ScreenHandlerType<BagScreenHandler> BAG_SCREEN_HANDLER = ScreenHandlerRegistry.registerSimple(id("bag"), BagScreenHandler::new);
public static final ScreenHandlerType<PositionedBagScreenHandler> POSITIONED_BAG_SCREEN_HANDLER = ScreenHandlerRegistry.registerExtended(id("positioned_bag"), PositionedBagScreenHandler::new);
public static final ScreenHandlerType<BoxScreenHandler> BOX_SCREEN_HANDLER = ScreenHandlerRegistry.registerExtended(id("box"), BoxScreenHandler::new);