Posted April 16, 20196 yr I'm trying to take a screenshot and then save that in Item nbt with a byte array: @Override public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) { if (!worldIn.isRemote) { ItemStack stack = new ItemStack(ModItems.PICTURE); NBTTagCompound nbt; if (stack.hasTagCompound()) { nbt = stack.getTagCompound(); } else { nbt = new NBTTagCompound(); } BufferedImage screenshot = new ScreenShotHelper().createScreenshot(Main.mc.displayWidth, Main.mc.displayHeight, Main.mc.getFramebuffer()); byte[] bytes = null; try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); boolean foundWriter; foundWriter = ImageIO.write(screenshot, "jpg", baos); assert foundWriter; bytes = baos.toByteArray(); } catch (IOException e) { e.printStackTrace(); } nbt.setByteArray("Picture", bytes); stack.setTagCompound(nbt); } return super.onItemRightClick(worldIn, playerIn, handIn); } But I get the error: java.util.concurrent.ExecutionException: java.lang.RuntimeException: No OpenGL context found in the current thread. at java.util.concurrent.FutureTask.report(Unknown Source) ~[?:1.8.0_192] at java.util.concurrent.FutureTask.get(Unknown Source) ~[?:1.8.0_192] at net.minecraft.util.Util.runTask(Util.java:54) [Util.class:?] at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:798) [MinecraftServer.class:?] at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:743) [MinecraftServer.class:?] at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:192) [IntegratedServer.class:?] at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:592) [MinecraftServer.class:?] at java.lang.Thread.run(Unknown Source) [?:1.8.0_192] Caused by: java.lang.RuntimeException: No OpenGL context found in the current thread. at org.lwjgl.opengl.GLContext.getCapabilities(GLContext.java:124) ~[lwjgl-2.9.4-nightly-20150209.jar:?] at org.lwjgl.opengl.GL11.glPixelStorei(GL11.java:2155) ~[lwjgl-2.9.4-nightly-20150209.jar:?] at net.minecraft.client.renderer.GlStateManager.glPixelStorei(GlStateManager.java:806) ~[GlStateManager.class:?] at net.minecraft.util.ScreenShotHelper.createScreenshot(ScreenShotHelper.java:99) ~[ScreenShotHelper.class:?] at com.thebox.guac.items.ItemCamera.onItemRightClick(ItemCamera.java:53) ~[ItemCamera.class:?] at net.minecraft.item.ItemStack.useItemRightClick(ItemStack.java:234) ~[ItemStack.class:?] at net.minecraft.server.management.PlayerInteractionManager.processRightClick(PlayerInteractionManager.java:384) ~[PlayerInteractionManager.class:?] at net.minecraft.network.NetHandlerPlayServer.processTryUseItem(NetHandlerPlayServer.java:796) ~[NetHandlerPlayServer.class:?] at net.minecraft.network.play.client.CPacketPlayerTryUseItem.processPacket(CPacketPlayerTryUseItem.java:43) ~[CPacketPlayerTryUseItem.class:?] at net.minecraft.network.play.client.CPacketPlayerTryUseItem.processPacket(CPacketPlayerTryUseItem.java:9) ~[CPacketPlayerTryUseItem.class:?] at net.minecraft.network.PacketThreadUtil$1.run(PacketThreadUtil.java:21) ~[PacketThreadUtil$1.class:?] at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) ~[?:1.8.0_192] at java.util.concurrent.FutureTask.run(Unknown Source) ~[?:1.8.0_192] at net.minecraft.util.Util.runTask(Util.java:53) ~[Util.class:?] ... 5 more Anyone know why? (I'm new to Java/Modding)
April 17, 20196 yr 20 minutes ago, The Box said: I fixed this by removing the "!" on "!worldIn.isRemote" The screenshot should only happen on the client side; therefore, you want to check for the isRemote value being true. Some tips: Spoiler Modder Support: Spoiler 1. Do not follow tutorials on YouTube, especially TechnoVision (previously called Loremaster) and HarryTalks, due to their promotion of bad practice and usage of outdated code. 2. Always post your code. 3. Never copy and paste code. You won't learn anything from doing that. 4. Quote Programming via Eclipse's hotfixes will get you nowhere 5. Learn to use your IDE, especially the debugger. 6. Quote The "picture that's worth 1000 words" only works if there's an obvious problem or a freehand red circle around it. Support & Bug Reports: Spoiler 1. Read the EAQ before asking for help. Remember to provide the appropriate log(s). 2. Versions below 1.11 are no longer supported due to their age. Update to a modern version of Minecraft to receive support.
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.