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.

Xie Peng

Members
  • Joined

  • Last visited

  1. This is not my entire codebase. I haven't added the `DeferredRegister` to the mod event bus via `#register` and I think this is where the problem is. I send the packet via keybinding, when I press a key, the packet will be sent. I haven't used `FriendlyByteBuf` because I am still studying how to use it. UPDATE: I made it after I added "Menu.REGISTER.register(FMLJavaModLoadingContext.get().getModEventBus());" in the main entry. Thanks.
  2. public class OpenFiltListScreenC2SPacket { private FriendlyByteBuf buf; public OpenFiltListScreenC2SPacket(){} public OpenFiltListScreenC2SPacket(FriendlyByteBuf buf){ this.buf = buf; } public void encode(FriendlyByteBuf buf){} public void handle(Supplier<NetworkEvent.Context> supplier){ NetworkEvent.Context context = supplier.get(); context.enqueueWork(()->{ context.getSender().getCapability(FiltListProvider.FILT_LIST).ifPresent(serverFiltList -> { //Server Logic context.getSender().sendSystemMessage(Component.literal("Open Screen")); NetworkHooks.openScreen(context.getSender(), new SimpleMenuProvider( (containerId, playerInventory, player) -> new Menu(containerId, playerInventory, buf), Component.translatable("menu.title.filtpick"))); }); }); context.setPacketHandled(true); } } public class Menu extends AbstractContainerMenu { private Inventory inventory; private final Level level; private static final DeferredRegister<MenuType<?>> REGISTER = DeferredRegister.create(ForgeRegistries.MENU_TYPES, FiltPick.MOD_ID); public static final RegistryObject<MenuType<Menu>> MENU_TYPE = REGISTER.register("filtlist", ()-> IForgeMenuType.create(Menu::new)); // Client menu constructor public Menu(int containerId, Inventory playerInventory, FriendlyByteBuf buf) { this(containerId, playerInventory, new ItemStackHandler(27), new SimpleContainerData(2)); } // Server menu constructor public Menu(int containerId, Inventory playerInventory, IItemHandler dataInventory, SimpleContainerData dataMultiple) { super(MENU_TYPE.get(),containerId); checkContainerSize(playerInventory,2); this.level = playerInventory.player.level; // Check if the data inventory size is some fixed value // Then, add slots for data inventory this.addSlot(new SlotItemHandler(dataInventory, 0, 0, 0)); // Add slots for player inventory this.addSlot(new Slot(playerInventory, 0, 0 ,0)); // Add data slots for handled integers this.addDataSlots(dataMultiple); // ... } @Override public ItemStack quickMoveStack(Player player, int quickMovedSlotIndex) { return ItemStack.EMPTY; } @Override public boolean stillValid(Player player) { return true; } } public class FiltContainerScreen extends AbstractContainerScreen<Menu> { public FiltContainerScreen(Menu menu, Inventory playerInventory, Component title) { super(menu, playerInventory, title); this.titleLabelX = 10; this.inventoryLabelX = 10; } @Override protected void init() { super.init(); } @Override public void render(PoseStack pose, int mouseX, int mouseY, float partialTick) { this.renderBackground(pose); super.render(pose, mouseX, mouseY, partialTick); /* * This method is added by the container screen to render * a tooltip for whatever slot is hovered over. */ this.renderTooltip(pose, mouseX, mouseY); } @Override protected void renderBg(PoseStack pose, float p_97788_, int p_97789_, int p_97790_) { /* * Sets the texture location for the shader to use. While up to * 12 textures can be set, the shader used within 'blit' only * looks at the first texture index. */ RenderSystem.setShaderTexture(0, BACKGROUND_LOCATION); /* * Renders the background texture to the screen. 'leftPos' and * 'topPos' should already represent the top left corner of where * the texture should be rendered as it was precomputed from the * 'imageWidth' and 'imageHeight'. The two zeros represent the * integer u/v coordinates inside the 256 x 256 PNG file. */ this.blit(pose, this.leftPos, this.topPos, 0, 0, this.imageWidth, this.imageHeight); } } @Mod.EventBusSubscriber(modid = FiltPick.MOD_ID, value = Dist.CLIENT, bus = Mod.EventBusSubscriber.Bus.MOD) public class ClientModEvents{ @SubscribeEvent public static void onKeyRegister(RegisterKeyMappingsEvent event){ event.register(KeyBinding.SET_ITEM_MAP); event.register(KeyBinding.OPEN_FILTLIST_MAP); } @SubscribeEvent public static void gatherData(GatherDataEvent event) { } @SubscribeEvent public static void clientSetup(FMLClientSetupEvent event) { event.enqueueWork( // Assume RegistryObject<MenuType<MyMenu>> MY_MENU // Assume MyContainerScreen<MyMenu> which takes in three parameters () -> MenuScreens.register(Menu.MENU_TYPE.get(), FiltContainerScreen::new) ); } } This is what I want to implement: When I press a key, client will sent the above packet to server, then the server will make my client to open the screen. But: My client only gets the systemMessage, "Open Screen", but no screen is opened... Why?
  3. public class ClientEvents { @Mod.EventBusSubscriber(modid = Mymod.MOD_ID, value = Dist.CLIENT, bus = Mod.EventBusSubscriber.Bus.FORGE) public static class ClientForgeEvents{ @SubscribeEvent // Event is on the Forge event bus only on the physical client public void onClientTick(TickEvent.ClientTickEvent event) { if (event.phase == TickEvent.Phase.END) { // Only call code once as the tick event is called twice every tick while (KeyBinding.SET_ITEM_KEY.consumeClick()) { // Execute logic to perform on click here Minecraft.getInstance().player.sendSystemMessage(Component.literal("Key is pressed!")); } } } } @Mod.EventBusSubscriber(modid = Mymod.MOD_ID, value = Dist.CLIENT, bus = Mod.EventBusSubscriber.Bus.MOD) public static class ClientModEvents{ @SubscribeEvent public static void onKeyRegister(RegisterKeyMappingsEvent event){ event.register(KeyBinding.SET_ITEM_KEY); } @SubscribeEvent public void gatherData(GatherDataEvent event) { } } } Nothing appends when I press the key I set. I followed the forge docs. Did I make mistakes? Help needed. THANK YOU!
  4. I tried to set `ItemPickupEvent` to canceled, but it's invalid. HELP NEEDED. THANK YOU!

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.