Jump to content

Take screenshot on client and send to server


The Box

Recommended Posts

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.

 

 

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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

    • Yes - maybe a conflict/incompatibility with another mod
    • LINK ADA DI BAWAH INI  LINK LOGIN LINK DAFTAR EXTRAWD ADALAH AGEN SLOT , TOGEL DAN BOLA TERBESAR INDONESIA YANG MERUPAKAN SITUS ONLINE PERTAMA YANG MENYEDIAKAN BERBAGAI JENIS PERMAINAN DAN BETTING ONLINE TELENGKAP, SEPERTI PERMAINAN CASINO ONLINE, SLOT ONLINE, TOGEL ONLINE, BOLA ONLINE, DAN MASIH BANYAK JENIS PILIHAN PERMAINAN LAINNYA. PROVIDER TERLENGKAP DAN TERNAMA UNTUK SLOT : PRAGMATIC PLAY-PG SOFT-NOLIMIT CITY-JOKER-PNG SLOT-BIG TIM GAMING-NETENT-TIGER PROVIDDER TERLENGKAP LIVEGAME : PRAGMATIC PLAY - VEGAS LOUNGE - SA GAMING - BG LIVE - EVOLUTION GAMING SWEET BONANZA CANDYLAND, MEGAWHEEL X 500, BACCARAT, ROULETTE PELAYANAN TERBAIK DARI OPERATOR KAMI YANG SIAP MELAYANI ANDA SELAMA 24 JAM
    • LINK ADA DI BAWAH INI  LINK LOGIN LINK DAFTAR EXTRAWD ADALAH AGEN SLOT , TOGEL DAN BOLA TERBESAR INDONESIA YANG MERUPAKAN SITUS ONLINE PERTAMA YANG MENYEDIAKAN BERBAGAI JENIS PERMAINAN DAN BETTING ONLINE TELENGKAP, SEPERTI PERMAINAN CASINO ONLINE, SLOT ONLINE, TOGEL ONLINE, BOLA ONLINE, DAN MASIH BANYAK JENIS PILIHAN 
    • Platform tempat untuk melangsungkan perjudian togel yang paling aman saat ini dan bisa merasakan sensasi hadiah JP jeda tentunya hanya bisa menggunakan situs agen toto togel resmi EXTRAWD . Bersama website agen togel ini anda akan mendapatkan jaminan bahwa hadiah kemenangan pasti dibayar tanpa ada potongan biaya administrasi. Hal terpenting di dalam permainan judi togel melalui situs EXTRAWD adalah wajib memiliki legalitas demi menghindari risiko terhadap hadiah kemenangan. Legalitas tersebut merupakan badan hukum untuk mengawasi terjadinya proses pengundian, sehingga cita-cita untuk mendapatkan JP togel semakin mudah untuk direalisasikan.  
    • I'm having trouble updating my mod Primal Magick to MC1.20.4 on Forge 49.0.48 with JEI 17.3.0.49. I believe I've followed the Forge and JEI instructions correctly, but I'm getting the following exception when I try to run the data generator: java.lang.module.ResolutionException: Modules jei._1._20._4.common.api and jei export package mezz.jei.api.runtime to module primalmagick Full output sample here, and the build.gradle file in question is here. Trying to run the game client results in a different type of exception, but with the same inner error. It looks like I'm getting two separate JEI modules which are interfering with each other, but I'm not sure why that would be. Things I've discovered in my investigations so far: Blowing away my repository and re-cloning from remote does not fix the error, even in combination with nuking my entire gradle cache.  I'm *mostly* sure that it's not just because my workspace is in a bad state. Commenting out line 144 of the build.gradle file, where it specifies the runtime-only deobf dependency of JEI makes the exception not get thrown, but means that JEI is not active in my debug runtime.  While this is a partial workaround for the issue, it leaves me unable to debug any of my JEI integration code, and so is far from ideal. Most maddeningly, running the client and/or data generator from the gradle CLI *also* causes the bug to not reproduce.  Data files get generated, and the client even runs with JEI; it just leaves me unable to trace through the code. I've already reached out to Mezz on the JEI Discord and he's stumped as well.  If I didn't know better, I'd say that one of the "compileOnly" or "runtimeOnly" directives are being executed when they shouldn't be, but why that would be happening now, or happening only when run in Eclipse, is beyond me.  If anyone knows how to resolve this issue, I would be very grateful.  Thank you, and stay safe.
  • Topics

×
×
  • Create New...

Important Information

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