Jump to content

Failed to create screen for menu type


OutsiderH

Recommended Posts

Here is my code

@Mod(Main.modId)
public final class Main {
    public static final String modId = "tfcworldmap";
    public static final Logger logger = LogManager.getLogger(modId);
    private static final DeferredRegister<Item> itemRegister = DeferredRegister.create(ForgeRegistries.ITEMS, modId);
    private static final DeferredRegister<CreativeModeTab> creativeModTabRegister = DeferredRegister.create(Registries.CREATIVE_MODE_TAB, modId);
    private static final DeferredRegister<MenuType<?>> menuRegister = DeferredRegister.create(ForgeRegistries.MENU_TYPES, modId);
    public Main() {
        IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();
        itemRegister.register(modEventBus);
        creativeModTabRegister.register(modEventBus);
        menuRegister.register(modEventBus);
        RegistryObjects.mapItem = itemRegister.register("map", MapItem::new);
        RegistryObjects.atlasItem = itemRegister.register("atlas", AtlasItem::new);
        RegistryObjects.mainCreativeModTab = creativeModTabRegister.register("main", () -> CreativeModeTab.builder()
            .title(Component.translatable(String.format("creative_mod_tab.%s.main", Main.modId)))
            .icon(() -> new ItemStack(RegistryObjects.atlasItem.get()))
            .displayItems((param, output) -> {
                output.accept(RegistryObjects.mapItem.get());
                output.accept(RegistryObjects.atlasItem.get());
            })
            .build());
        RegistryObjects.atlasMenu = menuRegister.register("atlas", () -> IForgeMenuType.create(AtlasMenu::new));
    }
    public static class RegistryObjects {
        public static RegistryObject<Item> mapItem;
        public static RegistryObject<Item> atlasItem;
        public static RegistryObject<CreativeModeTab> mainCreativeModTab;
        public static RegistryObject<MenuType<AtlasMenu>> atlasMenu;
    }
}
public class AtlasMenu extends AbstractContainerMenu {
    protected AtlasMenu(int id, Inventory inventory) {
        super(Main.RegistryObjects.atlasMenu.get(), id);
    }
    protected AtlasMenu(int id, Inventory inventory, FriendlyByteBuf buf) {
        super(Main.RegistryObjects.atlasMenu.get(), id);
    }
    @Override
    public ItemStack quickMoveStack(@Nonnull Player player, int index) {
        throw new UnsupportedOperationException("Unimplemented method 'quickMoveStack'");
    }
    @Override
    public boolean stillValid(@Nonnull Player player) {
        return true;
    }
    public static class Provider implements MenuProvider {
        @Override
        @Nullable
        public AbstractContainerMenu createMenu(int id, @Nonnull Inventory inventory, @Nonnull Player player) {
            return new AtlasMenu(id , inventory);
        }
        @Override
        public Component getDisplayName() {
            return Component.translatable("menu.tfcworldmap.atlas.title");
        }

    }
}
public class AtlasScreen extends AbstractContainerScreen<AtlasMenu> {
    public AtlasScreen(AtlasMenu menu, Inventory inventory, Component title) {
        super(menu, inventory, title);
    }
    @Override
    public boolean isPauseScreen() {
        return false;
    }
    @Override
    protected void renderBg(@Nonnull GuiGraphics guiGraphics, float partialTick, int mouseX, int mouseY) {
        return;
    }
}
public class AtlasItem extends Item {
    public AtlasItem() {
        super(new Item.Properties()
            .rarity(Rarity.UNCOMMON)
            .stacksTo(1));
    }
    @Override
    public InteractionResultHolder<ItemStack> use(@Nonnull Level level, @Nonnull Player player, @Nonnull InteractionHand usedHand) {
        ItemStack itemStack = player.getItemInHand(usedHand);
        if (itemStack.getTagElement("countMap") == null) {
            itemStack.addTagElement("countMap", IntTag.valueOf(0));
        }
        if (itemStack.getTagElement("countInk") == null) {
            itemStack.addTagElement("countInk", DoubleTag.valueOf(0));
        }
        if (!level.isClientSide) {
            ServerPlayer serverPlayer = (ServerPlayer)player;
            NetworkHooks.openScreen(serverPlayer, new AtlasMenu.Provider());
        }
        return InteractionResultHolder.sidedSuccess(itemStack, level.isClientSide);
    }
}
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.