sFXprt Posted May 1, 2023 Posted May 1, 2023 (edited) I have a working container that displays a screen, however if I try to interact with that screen it causes the error in the title, the container is called from entity#mobInteract using the networkhooks.opengui method. Like I mentioned the screen displays perfectly its just when I click a button it throws this exception SOLVED - I wasn't properly invoking FriendlyByteBuf in my packets on the screen class, infact I didnt call packets at all like an idiot knowing damn well its client side only. Log [02:14:52] [Render thread/FATAL]: Error executing task on Client java.lang.NullPointerException: Cannot invoke "net.minecraft.network.FriendlyByteBuf.m_130135_()" because "extraData" is null at TRANSFORMER/[email protected]/net.xprt.knights.Containers.Container.GuardMenu.<init>(GuardMenu.java:21) at TRANSFORMER/[email protected]/net.minecraftforge.network.IContainerFactory.m_39994_(IContainerFactory.java:20) at TRANSFORMER/[email protected]/net.minecraft.world.inventory.MenuType.m_39985_(MenuType.java:44) at TRANSFORMER/[email protected]/net.minecraft.client.gui.screens.MenuScreens$ScreenConstructor.m_96209_(MenuScreens.java:115) at TRANSFORMER/[email protected]/net.minecraft.client.gui.screens.MenuScreens.lambda$create$0(MenuScreens.java:43) at java.base/java.util.Optional.ifPresent(Optional.java:178) at TRANSFORMER/[email protected]/net.minecraft.client.gui.screens.MenuScreens.m_96201_(MenuScreens.java:43) at TRANSFORMER/[email protected]/net.minecraft.client.multiplayer.ClientPacketListener.m_5980_(ClientPacketListener.java:941) at TRANSFORMER/[email protected]/net.minecraft.network.protocol.game.ClientboundOpenScreenPacket.m_5797_(ClientboundOpenScreenPacket.java:37) at TRANSFORMER/[email protected]/net.minecraft.network.protocol.game.ClientboundOpenScreenPacket.m_5797_(ClientboundOpenScreenPacket.java:11) at TRANSFORMER/[email protected]/net.minecraft.network.protocol.PacketUtils.lambda$checkThreadAndEnqueue$0(PacketUtils.java:40) at TRANSFORMER/net.optifine/net.optifine.util.PacketRunnable.run(PacketRunnable.java:28) at TRANSFORMER/[email protected]/net.minecraft.util.thread.BlockableEventLoop.m_6367_(BlockableEventLoop.java:198) at TRANSFORMER/[email protected]/net.minecraft.util.thread.ReentrantBlockableEventLoop.m_6367_(ReentrantBlockableEventLoop.java:23) at TRANSFORMER/[email protected]/net.minecraft.util.thread.BlockableEventLoop.m_7245_(BlockableEventLoop.java:163) at TRANSFORMER/[email protected]/net.minecraft.util.thread.BlockableEventLoop.m_18699_(BlockableEventLoop.java:140) at TRANSFORMER/[email protected]/net.minecraft.client.Minecraft.m_91383_(Minecraft.java:1015) at TRANSFORMER/[email protected]/net.minecraft.client.Minecraft.m_91374_(Minecraft.java:665) at TRANSFORMER/[email protected]/net.minecraft.client.main.Main.main(Main.java:205) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:568) at MC-BOOTSTRAP/[email protected]/net.minecraftforge.fml.loading.targets.CommonClientLaunchHandler.lambda$launchService$0(CommonClientLaunchHandler.java:31) at MC-BOOTSTRAP/[email protected]/cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:37) at MC-BOOTSTRAP/[email protected]/cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:53) at MC-BOOTSTRAP/[email protected]/cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:71) at MC-BOOTSTRAP/[email protected]/cpw.mods.modlauncher.Launcher.run(Launcher.java:106) at MC-BOOTSTRAP/[email protected]/cpw.mods.modlauncher.Launcher.main(Launcher.java:77) at MC-BOOTSTRAP/[email protected]/cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:26) at MC-BOOTSTRAP/[email protected]/cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:23) at [email protected]/cpw.mods.bootstraplauncher.BootstrapLauncher.main(BootstrapLauncher.java:149) Container public class GuardMenu extends AbstractContainerMenu { private Knight knight; private Player p; public GuardMenu(int pContainerId, Inventory inv, Knight k, Player player) { this(pContainerId, inv); this.knight = k; this.p = player; } public GuardMenu(int pContainerId, Inventory inv) { super(ContainerInit.GUARD_MENU.get(), pContainerId); } public Player getPlayer(){ return this.p; } public Knight getKnight(){ return this.knight; } @Override public boolean stillValid(Player pPlayer) { return true; } } Screen public class GuardScreen extends AbstractContainerScreen<GuardMenu> { private Knight knight; private Player p; public GuardScreen(GuardMenu pMenu, Inventory pPlayerInventory, Component pTitle) { super(pMenu, pPlayerInventory, pTitle); this.knight = pMenu.getKnight(); this.p = pMenu.getPlayer(); this.init(); } @Override public void init() { this.addRenderableWidget(new Button(this.width / 2 + 5, this.height / 6 - 12 + 24, 70, 20, Component.nullToEmpty("Stay"), (p_96278_) -> { if(knight.getOwner() != null) { if (knight.getOwner().equals(p) || knight.getOwner().getId() == p.getId()) { knight.setStay(); knight.getPersistentData().putBoolean(XprtData.KNIGHT_STAYING, true); Utils.MessageEx(p, ChatFormatting.GREEN + "Knight will now stay", true); } else { Utils.MessageEx(p, ChatFormatting.RED + "You have not hired this Knight", true); } } else { Utils.MessageEx(p, ChatFormatting.RED + "Knight has not yet been hired", true); } })); this.addRenderableWidget(new Button(this.width / 2 + 5, this.height / 6 - 12 + 60, 70, 20, Component.nullToEmpty("Move Freely"), (p_96278_) -> { if(knight.getOwner() != null) { if (knight.getOwner().equals(p) || knight.getOwner().getId() == p.getId()) { knight.moveFreely(); knight.getPersistentData().putBoolean(XprtData.KNIGHT_STAYING, false); Utils.MessageEx(p, ChatFormatting.GREEN + "Knight will now move freely", true); } else { Utils.MessageEx(p, ChatFormatting.RED + "You have not hired this Knight", true); } } else { Utils.MessageEx(p, ChatFormatting.RED + "Knight has not yet been hired", true); } })); this.addRenderableWidget(new Button(this.width / 2 + 5, this.height / 6 - 12 + 96 , 70, 20, Component.nullToEmpty("Ignore Nearby"), (p_96278_) -> { if(knight.getOwner() != null) { if (knight.getOwner().equals(p) || knight.getOwner().getId() == p.getId()) { if(!knight.getPersistentData().contains(XprtData.KNIGHT_IGNORE_NEARBY) || !knight.getIgnoreNearby()){ knight.setIgnoreNearby(true); knight.getPersistentData().putBoolean(XprtData.KNIGHT_IGNORE_NEARBY, true); Utils.MessageEx(p, ChatFormatting.GREEN + "Knight will now ignore nearby enemies", true); } else{ if(knight.getPersistentData().getBoolean(XprtData.KNIGHT_IGNORE_NEARBY) || knight.getIgnoreNearby()){ knight.setIgnoreNearby(false); knight.getPersistentData().remove(XprtData.KNIGHT_IGNORE_NEARBY); Utils.MessageEx(p, ChatFormatting.RED + "Knight will no longer ignore nearby enemies", true); } } } else { Utils.MessageEx(p, ChatFormatting.RED + "You have not hired this Knight", true); } } else { Utils.MessageEx(p, ChatFormatting.RED + "Knight has not been hired", true); } })); this.addRenderableWidget(new Button(this.width / 2 + 5, this.height / 6 - 12 + 132 , 70, 20, Component.nullToEmpty("Hire Guard"), (p_96278_) -> { boolean hasItem = false; if(knight.getOwner() == null){ for(ItemStack items : p.getInventory().items){ if(items.getItem().equals(ModItems.GOLD_COIN.get())){ hasItem = true; items.setCount(items.getCount()-1); } } if(hasItem){ knight.setOwner(p); Utils.MessageEx(p, ChatFormatting.GREEN + "You have hired a Knight!", true); } else{ Utils.MessageEx(p, ChatFormatting.RED + "You do not have any gold coins!", true); } } else { Utils.MessageEx(p, ChatFormatting.RED + "This Guard is already hired!", true); } this.minecraft.setScreen(null); })); super.init(); } @Override public boolean shouldCloseOnEsc() { return true; } @Override public void render(PoseStack pPoseStack, int pMouseX, int pMouseY, float pPartialTick) { this.renderBackground(pPoseStack); super.render(pPoseStack, pMouseX, pMouseY, pPartialTick); } @Override protected void renderBg(PoseStack pPoseStack, float pPartialTick, int pMouseX, int pMouseY) { } @Override public boolean isPauseScreen() { return true; } @Override public void onClose() { this.minecraft.setScreen(null); } } Attaching Screen @Mod.EventBusSubscriber(modid = Main.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD, value = Dist.CLIENT) public class ClientSetup { @SubscribeEvent public static void doSetup(FMLClientSetupEvent event) { event.enqueueWork( () -> { MenuScreens.register(ContainerInit.GUARD_MENU.get(), GuardScreen::new); }); EntityRenderers.register(EntityInit.KNIGHT.get(), KnightRenderer::new); EntityRenderers.register(EntityInit.ARCHER.get(), ArcherRenderer::new); } } I followed a tutorial perfectly except they are using BlockEntity and im using entity mobInteract and calling player.openMenu Edited May 2, 2023 by sFXprt Quote
warjort Posted May 1, 2023 Posted May 1, 2023 Quote ava.lang.NullPointerException: Cannot invoke "net.minecraft.network.FriendlyByteBuf.m_130135_()" because "extraData" is null at TRANSFORMER/[email protected]/net.xprt.knights.Containers.Container.GuardMenu.<init>(GuardMenu.java:21) I don't see where line 21 could possibly be from what you posted? In general, if you post random code in the forums most people will just ignore your question unless the problem is obvious from what you post. So don't post snippets in the forum, put all the relevant code necessary to reproduce the problem on github. In this case, you don't show 2 of the most important pieces. The code that opens the menu or how you register the MenuType. https://docs.minecraftforge.net/en/latest/gui/menus/#opening-a-menu Quote Boilerplate: If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one. If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install Large files should be posted to a file sharing site like https://gist.github.com You should also read the support forum sticky post.
sFXprt Posted May 2, 2023 Author Posted May 2, 2023 @warjort //Calling if(!pPlayer.getLevel().isClientSide()) NetworkHooks.openGui((ServerPlayer) pPlayer, new SimpleMenuProvider(this.getContainer(), Component.nullToEmpty("Container"))); //Register public static final RegistryObject<MenuType<GuardMenu>> GUARD_MENU = CONTAINERS.register("guard_menu", () -> new MenuType(GuardMenu::new)); Quote
sFXprt Posted May 2, 2023 Author Posted May 2, 2023 13 hours ago, warjort said: I don't see where line 21 could possibly be from what you posted? In general, if you post random code in the forums most people will just ignore your question unless the problem is obvious from what you post. So don't post snippets in the forum, put all the relevant code necessary to reproduce the problem on github. In this case, you don't show 2 of the most important pieces. The code that opens the menu or how you register the MenuType. https://docs.minecraftforge.net/en/latest/gui/menus/#opening-a-menu Im trying to pass an reference to my custom Knight entity to my screen so I can process things Quote
Recommended Posts
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.