Jump to content

[1.12.2] Overlay Crashes Server


JonIsPatented

Recommended Posts

I have a custom gui overlay that tells the player the durability of the gas mask item while they are wearing it. It works perfectly in single player, but the server crashes when it loads. I know that this is because the server is trying to load the overlay, despite the fact that it is only able to be loaded on the client side. I know that I need to tell the server to not try to load it but I can't figure out how to do that. I've read a few different answers to similar questions and problems, but none of them fixed it. I don't know if I was doing it right when I tried to do what they said. My relevant code is

Quote

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

import com.jonispatented.moarmor.init.ModItems;
import com.jonispatented.moarmor.util.Reference;

public class GasMaskBar extends Gui {

    private final ResourceLocation bar = new ResourceLocation(Reference.MOD_ID, "textures/gui/gasmaskbar.png");
    private final int tex_width = 102, tex_height = 8, bar_width = 100, bar_height = 6;
    
    @SubscribeEvent
    public void renderOverlay(RenderGameOverlayEvent event) {
        if (event.getType() == RenderGameOverlayEvent.ElementType.TEXT) {
            Minecraft mc = Minecraft.getMinecraft();
            mc.renderEngine.bindTexture(bar);
            float oneUnit = (float)bar_width / mc.player.inventory.armorItemInSlot(3).getMaxDamage();
            int currentWidth = (int)(oneUnit * (mc.player.inventory.armorItemInSlot(3).getMaxDamage() - mc.player.inventory.armorItemInSlot(3).getItemDamage()));
            
            if (mc.player.inventory.armorItemInSlot(3).getItem() == (ModItems.GAS_MASK))
            {
                drawTexturedModalRect(0, 0, 0, 0, tex_width, tex_height);
                drawTexturedModalRect(1, 0, 1, tex_height, currentWidth, tex_height);
            }
        }
    }
}

and also the way I register it is

Quote

@EventHandler
    public static void Postinit(FMLPostInitializationEvent event)
    {
        MinecraftForge.EVENT_BUS.register(new GasMaskBar());
    }

 

Link to comment
Share on other sites

1 hour ago, eatthenight said:

@SideOnly(Side.CLIENT) also register your gui in your client proxy

This does not do what you think it does. Adding this to the Gui class will just cause a class not found exception in another place.

Omitting it and registering the gui only from the client proxy, meanwhile, works just fine.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

7 minutes ago, Draco18s said:

This does not do what you think it does. Adding this to the Gui class will just cause a class not found exception in another place.

Omitting it and registering the gui only from the client proxy, meanwhile, works just fine.

i answered his question how you load something on only one side. i know that registering the gui in the client proxy is enough. and well no you can set the side of the event too with SideOnly(Side.Client) so the event will only be called on the client side but you’re right registering in a client proxy would be the most convenient way probably..

Link to comment
Share on other sites

32 minutes ago, eatthenight said:

you can set the side of the event too with SideOnly(Side.Client) so the event will only be called on the client side

Again, that's not what side only does.

If you want an event to only be registered on one side, you use the value=Dist.CLIENT parameter in the @EventBusSubscriber annotation.

Also, its not called SideOnly any more. Its OnlyIn now.

.

  • Thanks 1

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

5 hours ago, eatthenight said:

i answered his question how you load something on only one side. i know that registering the gui in the client proxy is enough. and well no you can set the side of the event too with SideOnly(Side.Client) so the event will only be called on the client side but you’re right registering in a client proxy would be the most convenient way probably..

No.

The @SideOnly is used if the associated object should not exist on sides not specified in the parameters.

This means classes annotated with @SideOnly(Side.Client) will not exist on the server side.

It does nothing in loading something only on one side.

Annotating an event subscriber with @SideOnly might work, but only due to the absence of the annotated object on the other side (which is considered hacky). One should use a side-specific event bus subscriber instead.

 

9 hours ago, JonIsPatented said:

and also the way I register it is

Quote

@EventHandler
    public static void Postinit(FMLPostInitializationEvent event)
    {
        MinecraftForge.EVENT_BUS.register(new GasMaskBar());
    }

GasMaskBar is client only. Assuming your event handler is triggered on both sides, this will cause a crash on the server.

Either register your GUI in a client proxy or create a client-side event subscriber and register it there.

  • Thanks 1

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

2 hours ago, DavidM said:

GasMaskBar is client only. Assuming your event handler is triggered on both sides, this will cause a crash on the server.

Either register your GUI in a client proxy or create a client-side event subscriber and register it there.

I can't figure out how to create a client side event subscriber. Could you explain that? Also, I tried registering it in my client proxy, but I don't think i am doing it right. Would I just do it the same way i did it in my main as I showed above?

Link to comment
Share on other sites

6 hours ago, diesieben07 said:

Read the documentation on events. Then use @EventBusSubscriber with Side parameter.

I tried this:

Quote

@Mod.EventBusSubscriber(Side.CLIENT)
public class ClientEventHandler {

    @EventHandler
    public static void Postinit(FMLPostInitializationEvent event)
    {
        MinecraftForge.EVENT_BUS.register(new GasMaskBar());
    }
}

Is this correct? Because it didn't work. Now the overlay doesn't happen at all.

Link to comment
Share on other sites

6 minutes ago, JonIsPatented said:

Is this correct? Because it didn't work. Now the overlay doesn't happen at all.

Read the documentation on EventBusSubscriber again.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

3 hours ago, Animefan8888 said:

Read the documentation on EventBusSubscriber again.

I went and read it again and then reread it again. I Also went and read Jabelar's related tutorials again. I still can't figure it out. I tried adding the Side.CLIENT thing into a Mod.EventBusSubscriber annotation on the client proxy and all that. I tried making my own client event subscriber and that didn't work because I don't know how to do it and the explanations always gloss over the parts I actually need help with. I can't figure out at all how I'm supposed to register it if I'm not already doing it right. Could you please just tell me what I have to do.

Link to comment
Share on other sites

8 minutes ago, JonIsPatented said:

Could you please just tell me what I have to do.

Put the EventBusSubscriber annotation on your gui class. And change your event method to a static method.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

23 minutes ago, Animefan8888 said:

Put the EventBusSubscriber annotation on your gui class. And change your event method to a static method.

Quote

@Mod.EventBusSubscriber(value = Side.CLIENT)
public class GasMaskBar extends Gui {

    private static final ResourceLocation bar = new ResourceLocation(Reference.MOD_ID, "textures/gui/gasmaskbar.png");
    private static final int tex_width = 102;
    private static final int tex_height = 8;
    private static final int bar_width = 100;
    private static final int bar_height = 6;
    
    @SubscribeEvent
    public static void renderOverlay(RenderGameOverlayEvent event) {
        if (event.getType() == RenderGameOverlayEvent.ElementType.TEXT) {
            Minecraft mc = Minecraft.getMinecraft();
            mc.renderEngine.bindTexture(bar);
            float oneUnit = (float)bar_width / mc.player.inventory.armorItemInSlot(3).getMaxDamage();
            int currentWidth = (int)(oneUnit * (mc.player.inventory.armorItemInSlot(3).getMaxDamage() - mc.player.inventory.armorItemInSlot(3).getItemDamage()));
            
            if (mc.player.inventory.armorItemInSlot(3).getItem() == (ModItems.GAS_MASK))
            {
                drawTexturedModalRect(0, 0, 0, 0, tex_width, tex_height);
                drawTexturedModalRect(1, 0, 1, tex_height, currentWidth, tex_height);
            }
        }
    }
}

When I do this, the drawTexturedModalRect() stuff gives me an error saying that it can't make a static reference to the non-static method.

Link to comment
Share on other sites

2 hours ago, JonIsPatented said:

extends Gui

This is a Gui class. You call this class FROM the event handler, you don't MAKE it the event handler.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

6 hours ago, JonIsPatented said:

When I do this, the drawTexturedModalRect() stuff gives me an error saying that it can't make a static reference to the non-static method.

Ok make a static field in your class of your gui class. Then use that field to call drawTexturedModelRect or look into the Gui class and peek at its drawing methods.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

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

    • LOGIN DAN DAFTAR DISINI CEPAT!! AYUTOGEL adalah situs judi online yang memudahkan para pemainnya, dengan menggunakan deposit pulsa terbilang cukup memudahkan para pemainnya dikarenakan setiap orang pasti bisa mengisi pulsa di mana pun dengan agen agen pulsa, dengan mudah di dapat kan dimana mana jika para pemain tidak memiliki e-money atau m-banking anda tidak perlu khawatir lagi di karenakan AYUTOGEL adalah situs slot deposit pulsa. Slot Deposit pulsa adalah sebuah situs judi slot online yang melayani deposit menggunakan transfer pulsa atau menggunakan pulsa ponsel yang tersedia.
    • DAFTAR DAN LOGIN DISINI   Hantogel atau handogel adalah bentuk pengumpulan duka uang yang populer di dunia judi online, khususnya dalam permainan slot gacor. Banyak situs judi online yang menawarkan handogel slot gacor, dan sebagai pemain, penting untuk mengetahui cara memilih dan mengakses situs tersebut dengan aman dan amanah. Dalam artikel ini, kami akan membahas cara memilih situs slot gacor online yang berkualitas dan tahu cara mengakses handogelnya.
    • DAFTAR & LOGIN SIRITOGEL Siritogel adalah kumpulan kata yang mungkin baru saja dikenal oleh masyarakat, namun dengan perkembangan teknologi dan banyaknya informasi yang tersedia di internet, kalau kita siritogel (mencari informasi dengan cara yang cermat dan rinci) tentang situs slot gacor online, maka kita akan menemukan banyak hal yang menarik dan membahayakan sama sekali. Dalam artikel ini, kita akan mencoba menjelaskan apa itu situs slot gacor online dan bagaimana cara mengatasi dampaknya yang negatif.
    • This honestly might just work for you @SubscribeEvent public static void onScreenRender(ScreenEvent.Render.Post event) { final var player = Minecraft.getInstance().player; final var options = Minecraft.getInstance().options; if(!hasMyEffect(player)) return; // TODO: You provide hasMyEffect float f = Mth.lerp(event.getPartialTick(), player.oSpinningEffectIntensity, player.spinningEffectIntensity); float f1 = ((Double)options.screenEffectScale().get()).floatValue(); if(f <= 0F || f1 >= 1F) return; float p_282656_ = f * (1.0F - f1); final var p_282460_ = event.getGuiGraphics(); int i = p_282460_.guiWidth(); int j = p_282460_.guiHeight(); p_282460_.pose().pushPose(); float f5 = Mth.lerp(p_282656_, 2.0F, 1.0F); p_282460_.pose().translate((float)i / 2.0F, (float)j / 2.0F, 0.0F); p_282460_.pose().scale(f5, f5, f5); p_282460_.pose().translate((float)(-i) / 2.0F, (float)(-j) / 2.0F, 0.0F); float f4 = 0.2F * p_282656_; float f2 = 0.4F * p_282656_; float f3 = 0.2F * p_282656_; RenderSystem.disableDepthTest(); RenderSystem.depthMask(false); RenderSystem.enableBlend(); RenderSystem.blendFuncSeparate(GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ONE, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ONE); p_282460_.setColor(f4, f2, f3, 1.0F); p_282460_.blit(new ResourceLocation("textures/misc/nausea.png"), 0, 0, -90, 0.0F, 0.0F, i, j, i, j); p_282460_.setColor(1.0F, 1.0F, 1.0F, 1.0F); RenderSystem.defaultBlendFunc(); RenderSystem.disableBlend(); RenderSystem.depthMask(true); RenderSystem.enableDepthTest(); p_282460_.pose().popPose(); }   Note: Most of this is directly copied from GameRenderer as you pointed out you found. The only thing you'll have to likely do is update the `oSpinningEffectIntensity` + `spinningEffectIntensity` variables on the player when your effect is applied. Which values should be there? Not 100% sure, might be a game of guess and check, but `handleNetherPortalClient` in LocalPlayer has some hard coded you might be able to start with.
    • Dalam dunia perjudian online yang berkembang pesat, mencari platform yang dapat memberikan kemenangan maksimal dan hasil terbaik adalah impian setiap penjudi. OLXTOTO, dengan bangga, mempersembahkan dirinya sebagai jawaban atas pencarian itu. Sebagai platform terbesar untuk kemenangan maksimal dan hasil optimal, OLXTOTO telah menciptakan gelombang besar di komunitas perjudian online. Satu dari banyak keunggulan yang dimiliki OLXTOTO adalah koleksi permainan yang luas dan beragam. Dari togel hingga slot online, dari live casino hingga permainan kartu klasik, OLXTOTO memiliki sesuatu untuk setiap pemain. Dibangun dengan teknologi terkini dan dikembangkan oleh para ahli industri, setiap permainan di platform ini dirancang untuk memberikan pengalaman yang tak tertandingi bagi para penjudi. Namun, keunggulan OLXTOTO tidak hanya terletak pada variasi permainan yang mereka tawarkan. Mereka juga menonjol karena komitmen mereka terhadap keamanan dan keadilan. Dengan sistem keamanan tingkat tinggi dan proses audit yang ketat, OLXTOTO memastikan bahwa setiap putaran permainan berjalan dengan adil dan transparan. Para pemain dapat merasa aman dan yakin bahwa pengalaman berjudi mereka di OLXTOTO tidak akan terganggu oleh masalah keamanan atau keadilan. Tak hanya itu, OLXTOTO juga terkenal karena layanan pelanggan yang luar biasa. Tim dukungan mereka selalu siap sedia untuk membantu para pemain dengan segala pertanyaan atau masalah yang mereka hadapi. Dengan respon cepat dan solusi yang efisien, OLXTOTO memastikan bahwa pengalaman berjudi para pemain tetap mulus dan menyenangkan. Dengan semua fitur dan keunggulan yang ditawarkannya, tidak mengherankan bahwa OLXTOTO telah menjadi pilihan utama bagi jutaan penjudi online di seluruh dunia. Jika Anda mencari platform yang dapat memberikan kemenangan maksimal dan hasil optimal, tidak perlu mencari lebih jauh dari OLXTOTO. Bergabunglah dengan OLXTOTO hari ini dan mulailah petualangan Anda menuju kemenangan besar dan hasil terbaik!
  • Topics

×
×
  • Create New...

Important Information

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