Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

I can't figure out what I'm doing wrong. Menu is not called up.
 

Reg screen

Spoiler
@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD, value = Dist.CLIENT)
public class ForgeModScreens {
    @SubscribeEvent
    public static void clientLoad(FMLClientSetupEvent event) {
        event.enqueueWork(() -> {
            MenuScreens.register(ForgeModMenus.Gun_Menu.get(), Gun_Screen::new);
        });
    }

}

 

Reg menu

Spoiler
public class ForgeModMenus {
    public static final DeferredRegister<MenuType<?>> REGISTRY = DeferredRegister.create(ForgeRegistries.MENU_TYPES, Main.MODID);
    public static final RegistryObject<MenuType<Gun_Menu>> Gun_Menu = REGISTRY.register("gun_menu", () -> new MenuType<>(Gun_Menu::new));


}

 

Menu class

Spoiler
public class Gun_Menu extends AbstractContainerMenu {
    public Gun_Menu(int containerId, Inventory playerInventory) {
        this(containerId, playerInventory, new ItemStackHandler(5), DataSlot.standalone());
    }

    // Server menu constructor
    public Gun_Menu(int containerId, Inventory playerInventory, IItemHandler dataInventory, DataSlot dataSingle) {
        super(ForgeModMenus.Gun_Menu.get(), containerId);
        // Check if the data inventory size is some fixed value
        // Then, add slots for data inventory
        this.addSlot(new SlotItemHandler(dataInventory,0,5,6));

        // Add slots for player inventory
        this.addSlot(new Slot(playerInventory,0,8,10));

        // Add data slots for handled integers
        this.addDataSlot(dataSingle);

        // ...
    }
    @Override
    public ItemStack quickMoveStack(Player p_38941_, int p_38942_) {
        return null;
    }

    @Override
    public boolean stillValid(Player p_38874_) {
        return false;
    }
}

 

Screen class

Spoiler
public class Gun_Screen extends AbstractContainerScreen<Gun_Menu> {
    //private final static HashMap<String, Object> guistate = Gun_Menu.guistate;


    public Gun_Screen(Gun_Menu container, Inventory inventory, Component text) {
        super(container, inventory, text);
        this.imageWidth = 176;
        this.imageHeight = 166;
    }


    private static final ResourceLocation texture = new ResourceLocation(Main.MODID,"textures/screens/Gun_Screen.png");

    @Override
    public void render(PoseStack ms, int mouseX, int mouseY, float partialTicks) {
        this.renderBackground(ms);
        super.render(ms, mouseX, mouseY, partialTicks);
        this.renderTooltip(ms, mouseX, mouseY);
    }

    @Override
    protected void renderBg(PoseStack ms, float partialTicks, int gx, int gy) {
        RenderSystem.setShaderColor(1, 1, 1, 1);
        RenderSystem.enableBlend();
        RenderSystem.defaultBlendFunc();
        RenderSystem.setShaderTexture(0, texture);
        this.blit(ms, this.leftPos, this.topPos, 0, 0, this.imageWidth, this.imageHeight, this.imageWidth, this.imageHeight);
        RenderSystem.disableBlend();
    }

    @Override
    public boolean keyPressed(int key, int b, int c) {
        if (key == 256) {
            this.minecraft.player.closeContainer();
            return true;
        }
        return super.keyPressed(key, b, c);
    }

    @Override
    public void containerTick() {
        super.containerTick();
    }

    @Override
    protected void renderLabels(PoseStack poseStack, int mouseX, int mouseY) {
    }

    @Override
    public void onClose() {
        super.onClose();

    }

    @Override
    public void init() {
        super.init();
    }



}

 

Item class

Spoiler
public class TESTITEM extends ProjectileWeaponItem {
    public TESTITEM(Properties p_43009_) {
        super(p_43009_);
    }

    @Override
    public Predicate<ItemStack> getAllSupportedProjectiles() {
        return null;
    }

    @Override
    public int getDefaultProjectileRange() {
        return 0;
    }
    @Override
    public InteractionResultHolder<ItemStack> use(Level world, Player entity, InteractionHand hand) {
        if (entity instanceof ServerPlayer serverPlayer) {
            NetworkHooks.openScreen(serverPlayer, new SimpleMenuProvider(
                    (containerId, playerInventory, player) -> new Gun_Menu(containerId, playerInventory),
                    Component.translatable("menu.title.examplemod.mymenu")
            ));
        }
        return new InteractionResultHolder(InteractionResult.SUCCESS, entity.getItemInHand(hand));
    }
}

 


 

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.