Jump to content

[1.12.2] Capability Won't Load/Update in Custom HUD Element


TristanaGW

Recommended Posts

Hey, I'm working on a mod based on Dark Souls, just as a little project for fun and to teach myself a little about Java. I'm trying to make a Humanity counter and I've looked all over different tutorials and the documentation, but I can't figure out for the life of me what the problem might be. It could be a quirk I'm missing about Java, or it could just be I've implemented my capabilities bad. I honestly have no clue.
Anyhow, here's the code that I'm using for my HUD element renderer: (apologies for the sloppy and silly code quirks of mine lmao. i'll rewrite it if i wanna get serious with it)

Spoiler

package com.tristanagw.soulsmod.gui;

import java.awt.Color;

import com.tristanagw.soulsmod.HumanityProvider;
import com.tristanagw.soulsmod.capabilities.IHumanity;

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.eventhandler.SubscribeEvent;

public class GuiHumanity extends Gui {
    Minecraft mc = Minecraft.getMinecraft();
	private static final ResourceLocation texture = new ResourceLocation("soulsmod", "textures/gui/humanity_bg.png");
	private final int tex_width = 40, tex_height = 40;
	public GuiHumanity(Minecraft mc) {
		super();
		this.mc = mc;
	}
	
	@SubscribeEvent
    public void renderOverlay(RenderGameOverlayEvent event) {
        if (event.getType() == RenderGameOverlayEvent.ElementType.TEXT) {
            mc.renderEngine.bindTexture(texture);
            drawTexturedModalRect(4, 4, 0, 0, tex_width, tex_height);
        	IHumanity Humanity = mc.player.getCapability(HumanityProvider.CAPABILITY_HUMANITY, null);
        	int humanityAmount = Humanity.getHumanity();
            


    		String string = String.format("%02d",humanityAmount);
//    		String string = String.format("%02d",(int) mc.player.getHealth());
    		int xPos = (4 - (this.mc.fontRenderer.getStringWidth(string)/2))+(tex_width/2);
    		int yPos = (4 - 4) + (tex_height/2);
    		this.mc.fontRenderer.drawString(string, xPos, yPos, new Color(255, 255, 255).getRGB());
        }
    }
}

 

As you can see in the code, I've added a test line to swap out with the Humanity variable get with the player health, and that works just fine. I run the debugger, swap it to that and it goes to twenty and counts down when damaged, and goes back up when regen'd. But swapping the Humanity variable back in pops it back down to 0. (I just tried it while on a server too and Humanity didn't work on that either...)

If the Humanity scripts need to be seen, let me know, but just know that it's largely based off of the MCHorse code here. (I should mention my event handler doesn't work either, but the methods I have for adding and reducing Humanity work just fine and send my test messages and saves the Humanity to the playerdata NBT (or world data in the case of single player which may be its own problem but I wont worry about it for now.))

Anyway, knowing me I've probably missed something, but hopefully you've got enough to help me troubleshoot my way out of this. Thanks in advance!

Link to comment
Share on other sites

You need to sync your capability data from server to client.

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

Apologies if this is a really silly question, but the storage stuff is handled by the writeNBT/readNBT stuff right? I've had that class up for the whole time and it's still not worked. Or is that *just* for read/writing on the client? Do I need to do some intense reading into the SimplImpl stuff?

Link to comment
Share on other sites

1 hour ago, TristanaGW said:

Apologies if this is a really silly question, but the storage stuff is handled by the writeNBT/readNBT stuff right? I've had that class up for the whole time and it's still not worked. Or is that *just* for read/writing on the client? Do I need to do some intense reading into the SimplImpl stuff?

writeNBT/readNBT is for the server so that the data can be saved and loaded from the hard drive. That's it.

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

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 depo 5k merupakan situs slot depo 5k yang menyediakan slot minimal deposit 5rb atau 5k via dana yang super gacor, dimana para pemain hanya butuh modal depo sebesar 5k untuk bisa bermain di link slot gacor thailand terbaru tahun 2024 yang gampang menang ini.   DAFTAR & LOGIN AKUN PRO SLOT DEPO 5K ⭐⭐⭐ KLIK DISINI ⭐⭐⭐  
    • Slot deposit 3000 adalah situs slot deposit 3000 via dana yang super gacor dimana para pemain dijamin garansi wd hari ini juga hanya dengan modal receh berupa deposit sebesar 3000 baik via dana, ovo, gopay maupun linkaja untuk para pemain pengguna e-wallet di seluruh Indonesia.   DAFTAR & LOGIN AKUN PRO SLOT DEPOSIT 3000 ⭐⭐⭐ KLIK DISINI ⭐⭐⭐  
    • OLXTOTO: Menikmati Sensasi Bermain Togel dan Slot dengan Aman dan Mengasyikkan Dunia perjudian daring terus berkembang dengan cepat, dan salah satu situs yang telah menonjol dalam pasar adalah OLXTOTO. Sebagai platform resmi untuk permainan togel dan slot, OLXTOTO telah memenangkan kepercayaan banyak pemain dengan menyediakan pengalaman bermain yang aman, adil, dan mengasyikkan. DAFTAR OLXTOTO DISINI <a href="https://imgbb.com/"><img src="https://i.ibb.co/GnjSVpx/daftar1-480x480.webp" alt="daftar1-480x480" border="0" /></a> Keamanan Sebagai Prioritas Utama Salah satu aspek utama yang membuat OLXTOTO begitu menonjol adalah komitmennya terhadap keamanan pemain. Dengan menggunakan teknologi enkripsi terkini, situs ini memastikan bahwa semua informasi pribadi dan keuangan para pemain tetap aman dan terlindungi dari akses yang tidak sah. Beragam Permainan yang Menarik Di OLXTOTO, pemain dapat menemukan beragam permainan yang menarik untuk dinikmati. Mulai dari permainan klasik seperti togel hingga slot modern dengan fitur-fitur inovatif, ada sesuatu untuk setiap selera dan preferensi. Grafik yang memukau dan efek suara yang mengagumkan menambah keseruan setiap putaran. Peluang Menang yang Tinggi Salah satu hal yang paling menarik bagi para pemain adalah peluang menang yang tinggi yang ditawarkan oleh OLXTOTO. Dengan pembayaran yang adil dan peluang yang setara bagi semua pemain, setiap taruhan memberikan kesempatan nyata untuk memenangkan hadiah besar. Layanan Pelanggan yang Responsif Tim layanan pelanggan OLXTOTO siap membantu para pemain dengan setiap pertanyaan atau masalah yang mereka hadapi. Dengan layanan yang ramah dan responsif, pemain dapat yakin bahwa mereka akan mendapatkan bantuan yang mereka butuhkan dengan cepat dan efisien. Kesimpulan OLXTOTO telah membuktikan dirinya sebagai salah satu situs terbaik untuk penggemar togel dan slot online. Dengan fokus pada keamanan, beragam permainan yang menarik, peluang menang yang tinggi, dan layanan pelanggan yang luar biasa, tidak mengherankan bahwa situs ini telah menjadi pilihan utama bagi banyak pemain. Jadi, jika Anda mencari pengalaman bermain yang aman, adil, dan mengasyikkan, jangan ragu untuk bergabung dengan OLXTOTO hari ini dan rasakan sensasi kemenangan!
    • Slot deposit dana adalah situs slot deposit dana yang juga menerima dari e-wallet lain seperti deposit via dana, ovo, gopay & linkaja terlengkap saat ini, sehingga para pemain yang tidak memiliki rekening bank lokal bisa tetap bermain slot dan terbantu dengan adanya fitur tersebut.   DAFTAR & LOGIN AKUN PRO SLOT DEPOSIT DANA ⭐⭐⭐ KLIK DISINI ⭐⭐⭐  
    • Slot deposit dana adalah situs slot deposit dana minimal 5000 yang dijamin garansi super gacor dan gampang menang, dimana para pemain yang tidak memiliki rekening bank lokal tetap dalam bermain slot dengan melakukan deposit dana serta e-wallet lainnya seperti ovo, gopay maupun linkaja lengkap. Agar para pecinta slot di seluruh Indonesia tetap dapat menikmati permainan tanpa halangan apapun khususnya metode deposit, dimana ketersediaan cara deposit saat ini yang lebih beragam tentunya sangat membantu para pecinta slot.   DAFTAR & LOGIN AKUN PRO SLOT DEPOSIT DANA ⭐⭐⭐ KLIK DISINI ⭐⭐⭐  
  • Topics

×
×
  • Create New...

Important Information

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