Jump to content

Recommended Posts

Posted

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)

Posted
  On 4/17/2019 at 12:37 AM, The Box said:

I fixed this by removing the "!" on "!worldIn.isRemote"

Expand  

The screenshot should only happen on the client side; therefore, you want to check for the isRemote value being true.

Some tips:

  Reveal hidden contents

 

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.

Announcements



×
×
  • Create New...

Important Information

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