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

    • Slot Gacor >> Mudah Maxwin Bersama Djarum4D   Slot gacor adalah salah satu jenis permainan judi online yang sangat populer di Indonesia. Bermain slot gacor berarti bermain permainan slot dengan kemungkinan keluaran yang lebih tinggi daripada slot tradisional. Dalam artikel ini, kami akan membahas secara lengkap tentang slot gacor, mulai dari pengertian dasar, cara bermain, strategi pemain, serta aspek keamanan dan etika dalam bermain.
    • DAFTAR & LOGIN TAYO4D   Slot gacor online adalah permainan yang menarik dan menghasilkan keuntungan untuk banyak pemain di seluruh dunia. Dalam artikel ini, kita akan membahas tentang cara memilih dan memainkan slot gacor online terbaik.
    • Tayo4D : Bandar Online Togel Dan Slot Terbesar Di Indonesia     Pemain taruhan Tayo4D yang berkualitas memerlukan platform yang aman, terpercaya, dan mudah digunakan. Dalam era teknologi ini, banyak situs online yang menawarkan layanan taruhan togel 4D, tetapi memilih yang tepat menjadi tuntas. Berikut adalah cara untuk membuat artikel yang membahas tentang situs online terpercaya untuk permainan taruhan togel 4D.  
    • OLXTOTO: Platform Maxwin dan Gacor Terbesar Sepanjang Masa OLXTOTO telah menetapkan standar baru dalam dunia perjudian dengan menjadi platform terbesar untuk pengalaman gaming yang penuh kemenangan dan kegacoran, sepanjang masa. Dengan fokus yang kuat pada menyediakan permainan yang menghadirkan kesenangan tanpa batas dan peluang kemenangan besar, OLXTOTO telah menjadi pilihan utama bagi para pencinta judi berani di Indonesia. Maxwin: Mengejar Kemenangan Terbesar Maxwin bukan sekadar kata-kata kosong di OLXTOTO. Ini adalah konsep yang ditanamkan dalam setiap aspek permainan yang mereka tawarkan. Dari permainan slot yang menghadirkan jackpot besar hingga berbagai opsi permainan togel dengan hadiah fantastis, para pemain dapat memperoleh peluang nyata untuk mencapai kemenangan terbesar dalam setiap taruhan yang mereka lakukan. OLXTOTO tidak hanya menawarkan kesempatan untuk menang, tetapi juga menjadi wadah bagi para pemain untuk meraih impian mereka dalam perjudian yang berani. Gacor: Keberuntungan yang Tak Tertandingi Keberuntungan seringkali menjadi faktor penting dalam perjudian, dan OLXTOTO memahami betul akan hal ini. Dengan berbagai strategi dan analisis yang disediakan, pemain dapat menemukan peluang gacor yang tidak tertandingi dalam setiap taruhan. Dari hasil togel yang tepat hingga putaran slot yang menguntungkan, OLXTOTO memastikan bahwa setiap taruhan memiliki potensi untuk menjadi momen yang mengubah hidup. Inovasi dan Kualitas Tanpa Batas Tidak puas dengan prestasi masa lalu, OLXTOTO terus berinovasi untuk memberikan pengalaman gaming terbaik kepada para pengguna. Dengan menggabungkan teknologi terbaru dengan desain yang ramah pengguna, platform ini menyajikan antarmuka yang mudah digunakan tanpa mengorbankan kualitas. Setiap pembaruan dan peningkatan dilakukan dengan tujuan tunggal: memberikan pengalaman gaming yang tanpa kompromi kepada setiap pengguna. Komitmen Terhadap Kepuasan Pelanggan Di balik kesuksesan OLXTOTO adalah komitmen mereka terhadap kepuasan pelanggan. Tim dukungan pelanggan yang profesional siap membantu para pemain dalam setiap langkah perjalanan gaming mereka. Dari pertanyaan teknis hingga bantuan dengan transaksi keuangan, OLXTOTO selalu siap memberikan pelayanan terbaik kepada para pengguna mereka. Penutup: Mengukir Sejarah dalam Dunia Perjudian Daring OLXTOTO bukan sekadar platform perjudian berani biasa. Ini adalah ikon dalam dunia perjudian daring Indonesia, sebuah destinasi yang menyatukan kemenangan dan keberuntungan dalam satu tempat yang mengasyikkan. Dengan komitmen mereka terhadap kualitas, inovasi, dan kepuasan pelanggan, OLXTOTO terus mengukir sejarah dalam perjudian dunia berani, menjadi nama yang tak terpisahkan dari pengalaman gaming terbaik. Bersiaplah untuk mengalami sensasi kemenangan terbesar dan keberuntungan tak terduga di OLXTOTO - platform maxwin dan gacor terbesar sepanjang masa.
    • OLXTOTO - Bandar Togel Online Dan Slot Terbesar Di Indonesia OLXTOTO telah lama dikenal sebagai salah satu bandar online terkemuka di Indonesia, terutama dalam pasar togel dan slot. Dengan reputasi yang solid dan pengalaman bertahun-tahun, OLXTOTO menawarkan platform yang aman dan andal bagi para penggemar perjudian daring. DAFTAR OLXTOTO DISINI DAFTAR OLXTOTO DISINI DAFTAR OLXTOTO DISINI Beragam Permainan Togel Sebagai bandar online terbesar di Indonesia, OLXTOTO menawarkan berbagai macam permainan togel. Mulai dari togel Singapura, togel Hongkong, hingga togel Sidney, pemain memiliki banyak pilihan untuk mencoba keberuntungan mereka. Dengan sistem yang transparan dan hasil yang adil, OLXTOTO memastikan bahwa setiap taruhan diproses dengan cepat dan tanpa keadaan. Slot Online Berkualitas Selain togel, OLXTOTO juga menawarkan berbagai permainan slot online yang menarik. Dari slot klasik hingga slot video modern, pemain dapat menemukan berbagai opsi permainan yang sesuai dengan preferensi mereka. Dengan grafis yang memukau dan fitur bonus yang menggiurkan, pengalaman bermain slot di OLXTOTO tidak akan pernah membosankan. Keamanan dan Kepuasan Pelanggan Terjamin Keamanan dan kepuasan pelanggan merupakan prioritas utama di OLXTOTO. Mereka menggunakan teknologi enkripsi terbaru untuk melindungi data pribadi dan keuangan para pemain. Tim dukungan pelanggan yang ramah dan responsif siap membantu pemain dengan setiap pertanyaan atau masalah yang mereka hadapi. Promosi dan Bonus Menarik OLXTOTO sering menawarkan promosi dan bonus menarik kepada para pemainnya. Mulai dari bonus selamat datang hingga bonus deposit, pemain memiliki kesempatan untuk meningkatkan kemenangan mereka dengan memanfaatkan berbagai penawaran yang tersedia. Penutup Dengan reputasi yang solid, beragam permainan berkualitas, dan komitmen terhadap keamanan dan kepuasan pelanggan, OLXTOTO tetap menjadi salah satu pilihan utama bagi para pecinta judi online di Indonesia. Jika Anda mencari pengalaman berjudi yang menyenangkan dan terpercaya, OLXTOTO layak dipertimbangkan.
  • Topics

×
×
  • Create New...

Important Information

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