Jump to content

Recommended Posts

Posted (edited)

How do I take a screenshot on the client when an item is right clicked and then send that image over to the server in a packet and use it there?

Edited by The Box
Posted

What are you going to do with the image?

Keep in mind that the client can always lie and send a fake image to the server.

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.

 

 

Posted (edited)

This is continued from discord. @The Box is trying to make a multiplayer-compatible camera mod.

Quote

I'm basically trying to make a camera mod. I'm stuck where I'm getting an error stating OpenGL is missing. Here is the function having the problem.

```java
  @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);
  }
```
This is where an item is supposed to be given with the pictures stored in the nbt. But on the line taking the screenshot with the helper I get this error:

java.util.concurrent.ExecutionException: java.lang.RuntimeException: No OpenGL context found in the current thread.

I said that this was because the code was being run on the server thread, and that I couldn’t think of a way to do what they wanted, so they should ask on the forums. The easiest solution would to just run everything on the client, but this will cause desyncs even in singleplayer.

Edited by Cadiboo

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Posted
21 minutes ago, Cadiboo said:

The easiest solution would to just run everything on the client, but this will cause desyncs even in singleplayer.

Client thread isn't nececcairly the same as the render thread, and all rendering-related stuff must be done on the rendering thread unless you are using vulkan. 

What they need to do is enqueue the action on the client, aka have a static field changed to true on the onItemRightClick method, then in any kind of render event(RenderTickEvent, RenderWorldLastEvent, etc) check for that field being true and if it is do the gl related things and create an image there. Then yeah, a packet to send it to the server is needed, I *think* that if the packet is too big it will be split into multiple smaller packets, but I am not sure, you might just crash right away because of the packet size limit, in that case you would need to compress the image before sending it. And unfortunately clients will be able to abuse this packet and send extremely long byte arrays to the server regardless, and I don't think much can be done about it.

 

24 minutes ago, Cadiboo said:

foundWriter = ImageIO.write(screenshot, "jpg", baos);
  assert foundWriter;

You don't need this assertion. This is not the usecase for the statement.

 

25 minutes ago, Cadiboo said:

but this will cause desyncs even in singleplayer

I am not sure what do you mean here?

Posted
1 hour ago, V0idWa1k3r said:

I am not sure what do you mean here?

I was thinking of only updating the data on the logical client which obviously wouldn’t work well

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • It is a rendering issue with embeddium/oculus
    • So, I have a minecraft world hosted with essential on forge 1.20.1, there's 149 mods, and the forge version is 47.3.0, and it's been like that for a good 2-3 weeks, and all of a sudden, it stopped loading, and I have 0 clue as to why, and this world means A LOT to me, so if anyone out there is able to help, I would GLADLY appreciate it. here's the link if ya wanna help:   [04Dec2024 22:42:24.552] [Worker-ResourceReload-3/ERROR][net.minecraft.server.packs.resources.SimpleJsonResourceReloadListener/]: Couldn't parse data file slabsexpanded:snow_blockblocktoslab from slabsexpanded:recipes/snow_blockblocktoslab.json com.google.gson.JsonParseException: com.google.gson.stream.MalformedJsonException: Expected name at line 16 column 4 path $.result.item at net.minecraft.util.GsonHelper.m_13780_(GsonHelper.java:526) ~[client-1.20.1-20230612.114412-srg.jar%23490!/:?] at net.minecraft.util.GsonHelper.m_263475_(GsonHelper.java:531) ~[client-1.20.1-20230612.114412-srg.jar%23490!/:?] at net.minecraft.util.GsonHelper.m_13776_(GsonHelper.java:581) ~[client-1.20.1-20230612.114412-srg.jar%23490!/:?] at net.minecraft.server.packs.resources.SimpleJsonResourceReloadListener.m_278771_(SimpleJsonResourceReloadListener.java:41) ~[client-1.20.1-20230612.114412-srg.jar%23490!/:?] at net.minecraft.server.packs.resources.SimpleJsonResourceReloadListener.m_5944_(SimpleJsonResourceReloadListener.java:29) ~[client-1.20.1-20230612.114412-srg.jar%23490!/:?] at net.minecraft.server.packs.resources.SimpleJsonResourceReloadListener.m_5944_(SimpleJsonResourceReloadListener.java:17) ~[client-1.20.1-20230612.114412-srg.jar%23490!/:?] at net.minecraft.server.packs.resources.SimplePreparableReloadListener.m_10786_(SimplePreparableReloadListener.java:11) ~[client-1.20.1-20230612.114412-srg.jar%23490!/:?] at java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1768) ~[?:?] at java.util.concurrent.CompletableFuture$AsyncSupply.exec(CompletableFuture.java:1760) ~[?:?] at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:373) ~[?:?] at java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1182) ~[?:?] at java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1655) ~[?:?] at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1622) ~[?:?] at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:165) ~[?:?] Caused by: com.google.gson.stream.MalformedJsonException: Expected name at line 16 column 4 path $.result.item at com.google.gson.stream.JsonReader.syntaxError(JsonReader.java:1657) ~[gson-2.10.jar%23107!/:?] at com.google.gson.stream.JsonReader.doPeek(JsonReader.java:514) ~[gson-2.10.jar%23107!/:?] at com.google.gson.stream.JsonReader.hasNext(JsonReader.java:422) ~[gson-2.10.jar%23107!/:?] at com.google.gson.internal.bind.TypeAdapters$28.read(TypeAdapters.java:779) ~[gson-2.10.jar%23107!/:?] at com.google.gson.internal.bind.TypeAdapters$28.read(TypeAdapters.java:725) ~[gson-2.10.jar%23107!/:?] at com.google.gson.internal.bind.TypeAdapters$34$1.read(TypeAdapters.java:1007) ~[gson-2.10.jar%23107!/:?] at net.minecraft.util.GsonHelper.m_13780_(GsonHelper.java:524) ~[client-1.20.1-20230612.114412-srg.jar%23490!/:?]
    • Hello! I have been having a problem with Forgematica, Embeddium, Oculus, and create. I wanted to download litematica so I could see which blocks are in my creative mode build, so that I could collect them all in survival. However, litematica is a fabric mod. I found a port called forgematica, which I added (along with it's dependency) to my mods folder. I loaded into a new world, and built a structure. Then, I added a part from the create mod, and the game crashed instantly, with exit code -1. Thanks for any help! Crash Report and mods list: https://pastebin.com/rtzh6LAi
  • Topics

×
×
  • Create New...

Important Information

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