Jump to content

[1.12.2] Item Property Overrides Changes All Item Textures


Triphion

Recommended Posts

So the problem is very simple, i want the item i'm holding to change, and not the other ones of the same item in my inventory. Here is the class with the method. Any ideas?

	EntityLightningBolt lightning;
	
	private int lightning_index;
	
	public ItemZeusLightningCharged(String unlocalizedName) 
	{
		super(unlocalizedName);
		this.setCreativeTab(CreativeTabs.COMBAT);
		this.lightning_index = 0;
		
		this.addPropertyOverride(new ResourceLocation(Reference.MODID, "zeus_mode"), new IItemPropertyGetter() 
		{
			@Override
			public float apply(ItemStack stack, World worldIn, EntityLivingBase entityIn) 
			{
				Utils.getLogger().info("Itemstack: " + stack);
				if (entityIn != null && entityIn.getHeldItem(EnumHand.MAIN_HAND).getItem() == ModItems.ZEUS_LIGHTNING_CHARGED)
				{
					Utils.getLogger().info("Player has Item.");
					return (float)((ItemZeusLightningCharged)entityIn.getHeldItem(EnumHand.MAIN_HAND).getItem()).lightning_index;
				}
				else 
				{
					return 0.0F;
				}
			}
		});
	}

To clarify, the lightning index is an int that resembles the different modes. 

 

Edit: This doesn't actually work serverside either.

Edited by Triphion
Link to comment
Share on other sites

Thank you for the advice. I have tried to make something like that. However, the problem is that the player doesn't register the active itemstack, and instead has it as simple air. And i don't really know how to fix that. 

			((ItemZeusLightningCharged)player.getHeldItemMainhand().getItem()).setLightningIndex(player.getActiveItemStack(), +1);

This is the function that i'm calling when the player presses a button to change the firing mode. After that, the lightning index is going up, and then the item property is supposed to override and give the item a new texture. 

	public static int getLightningIndex(ItemStack item) 
	{
	    NBTTagCompound nbtTagCompound = item.getTagCompound();
	    
	    if(nbtTagCompound != null)
		    return nbtTagCompound.getInteger("lIndex");
	   
	   return 0;
    }
   
    public static void setLightningIndex(ItemStack item, int lightningValue) 
    {
	    NBTTagCompound nbtTagCompound = item.getTagCompound();
	    
	    if (lightningValue < 2) 
	    {
	    }
	    else if (lightningValue == 2) 
	    {
	    	lightningValue = 0;
	    }
	    
	    nbtTagCompound.setInteger("lIndex", lightningValue);
	   
	    ItemZeusLightningCharged.lightningIndex = lightningValue;
	    
	    Utils.getLogger().info(lightningValue);
	}

This is the methods i'm using to get the index number. 

	public static int lightningIndex;

This is the int/float i'm using to check if the item should override. 

Link to comment
Share on other sites

I do in-fact know how static works, this was actually me being frustrated and just trying everything(which is never a good thing). Static is a declaration that has the same value for the class, including all individual objects that stem from the class has the same value. I have now removed those. I realized now aswell, but i don't know how to get that specific itemstack and then use the method since i cannot cast directly to an itemstack. This is what i have for now, and it is not valid/or working method, just starting the method. 

		if (player.getHeldItem(EnumHand.MAIN_HAND).getItem() == ModItems.ZEUS_LIGHTNING_CHARGED) 
		{
			System.out.println("Succesfully retrieved Item.");
			
			ItemStack weapon = player.getHeldItem(EnumHand.MAIN_HAND);
			((ItemZeusLightningCharged)weapon).setLightningIndex(weapon, + 1);
		}

How do i cast directly to the itemstack and not the item class as a whole? Because i can get the itemstack, but not cast it directly to the itemstack and change that specific itemstack. 

[16:42:22] [Netty Server IO #1/INFO] [STDOUT]: [com.etauricstaff.etauricmod.network.MessageGetPlayer:handleServerSide:36]: Succesfully retrieved Item.
[16:42:22] [Netty Server IO #1/INFO] [STDOUT]: [com.etauricstaff.etauricmod.network.MessageGetPlayer:handleServerSide:39]: Itemstack: 1xitem.zeus_lightning_charged@0

 

Link to comment
Share on other sites

EDIT: I realized that there is actually the setLightningIndex function that gets the server to crash. And this is the error i get everytime:

Quote

[19:52:05] [Netty Server IO #1/ERROR] [FML]: There was a critical exception handling a packet on channel etauric
java.lang.NullPointerException: null
    at com.etauricstaff.etauricmod.items.ItemZeusLightningCharged.setLightningIndex(ItemZeusLightningCharged.java:92) ~[ItemZeusLightningCharged.class:?]
    at com.etauricstaff.etauricmod.network.MessageGetPlayer.handleServerSide(MessageGetPlayer.java:43) ~[MessageGetPlayer.class:?]
    at com.etauricstaff.etauricmod.network.MessageBase.onMessage(MessageBase.java:17) ~[MessageBase.class:?]

And this is how my setLightningFunction looks right now:

Quote

    public void setLightningIndex(ItemStack item, int lightningValue) 
    {
        NBTTagCompound nbtTagCompound = item.getTagCompound();
        
        if (lightningValue < 2) 
        {
        }
        else if (lightningValue == 2) 
        {
            lightningValue = 0;
        }
        
        nbtTagCompound.setInteger("lIndex", lightningValue);
        
        Utils.getLogger().info(lightningValue);
    }

 

Edited by Triphion
Link to comment
Share on other sites

3 minutes ago, diesieben07 said:

This can be null if the ItemStack does not have an NBT tag yet. Your code does not handle that case.

I SOLVED IT! Thank you so much diesieben! ❤️

This is how i did it: 

Quote

    public void setLightningIndex(ItemStack item, int lightningValue) 
    {
        NBTTagCompound nbtTagCompound = item.getTagCompound();
        System.out.println(nbtTagCompound);
        
        if (nbtTagCompound == null) 
        {
            nbtTagCompound = new NBTTagCompound();
            item.setTagCompound(nbtTagCompound);
        }
        
        if (lightningValue < 2) 
        {
        }
        else if (lightningValue == 2) 
        {
            lightningValue = 0;
        }
        
        nbtTagCompound.setInteger("lIndex", lightningValue);
        System.out.println("Lightning Value: " + lightningValue);
    }

Link to comment
Share on other sites

8 hours ago, Triphion said:

System.out.println(nbtTagCompound);

1) remove this

2) use the logger the FMLPreInitializationEvent gives you

 

8 hours ago, Triphion said:

if (lightningValue < 2) 
        {
        }

Did you mean to leave this empty?

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

2 hours ago, Draco18s said:

1) remove this

2) use the logger the FMLPreInitializationEvent gives you

 

Did you mean to leave this empty?

I have removed the printlns, and i usually use the logger, but for this i used the printlns because of a whim i guess? ?

And that check is actually not needed, so i removed it. I always add +1 as the lightning index, so it always goes up, then i check if it goes up to 2, and if it does, it resets the value. But thanks for pointing those out. ?

Link to comment
Share on other sites

7 hours ago, Triphion said:

I always add +1 as the lightning index, so it always goes up, then i check if it goes up to 2, and if it does, it resets the value. But thanks for pointing those out. 

So, it will do this:

 

0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0...

 

Yes?

 

If so, why do you need an integer? Or an if statement at all?

 

1 - currentValue will do this just fine. So will (currentValue + 1) % maximum

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

14 minutes ago, Draco18s said:

So, it will do this:

 

0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0...

 

Yes?

 

If so, why do you need an integer? Or an if statement at all?

 

1 - currentValue will do this just fine. So will (currentValue + 1) % maximum

I need the integer since i have added more than just 2 modes. This is how it looks now:

    public void setLightningIndex(ItemStack item, int lightningValue) 
    {
	    NBTTagCompound nbtTagCompound = item.getTagCompound();
	    
	    if (nbtTagCompound == null) 
	    {
	    	nbtTagCompound = new NBTTagCompound();
	    	item.setTagCompound(nbtTagCompound);
	    }
	    
	    if (lightningValue == 4) 
	    {
	    	lightningValue = 0;
	    }
	    
	    nbtTagCompound.setInteger("lIndex", lightningValue);
	}

And this works just fine for this case. 

But i am very appreciative of the advice however. ^^

 

EDIT: Actually, i do not need that integer parameter, my bad, thanks for pointing that out.

Quote

    public void setLightningIndex(ItemStack item) 
    {
        NBTTagCompound nbtTagCompound = item.getTagCompound();
        
        if (nbtTagCompound == null) 
        {
            nbtTagCompound = new NBTTagCompound();
            item.setTagCompound(nbtTagCompound);
        }
        
        nbtTagCompound.setInteger("lIndex", nbtTagCompound.getInteger("lIndex") + 1);
        
        if (nbtTagCompound.getInteger("lIndex") == 4) 
        {
            nbtTagCompound.setInteger("lIndex", 0);
        }
    }

This works easier than the above mentioned, thanks Draco. ^^

Edited by Triphion
Link to comment
Share on other sites

I can replace this:

11 hours ago, Triphion said:

        nbtTagCompound.setInteger("lIndex", nbtTagCompound.getInteger("lIndex") + 1);
        
        if (nbtTagCompound.getInteger("lIndex") == 4) 
        {
            nbtTagCompound.setInteger("lIndex", 0);
        }

 

With this:

nbtTagCompound.setInteger("lIndex", (nbtTagCompound.getInteger("lIndex") + 1) % 4);

  • Like 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

7 hours ago, Draco18s said:

I can replace this:

With this:

nbtTagCompound.setInteger("lIndex", (nbtTagCompound.getInteger("lIndex") + 1) % 4);

Oh wow! Worked wonders, didn't know you could actually do it like that. Thanks for tellinig me. ?

Link to comment
Share on other sites

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

    • 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 ⭐⭐⭐  
    • Slot deposit pulsa adalah situs slot deposit pulsa tanpa potongan apapun yang dijamin garansi terpercaya, dimana kamu bisa bermain slot dengan melakukan deposit pulsa dan tanpa dikenakan potongan apapun sehingga dana yang masuk ke dalam akun akan 100% utuh. Proses penarikan dana juga dijamin gampang dan tidak sulit sehingga kamu tidak perlu khawatir akan kemenangan yang akan kamu peroleh dengan sangat mudah jika bermain disini.   DAFTAR & LOGIN AKUN PRO SLOT DEPOSIT PULSA TANPA POTONGAN ⭐⭐⭐ KLIK DISINI ⭐⭐⭐  
    • Slot deposit pulsa merupakan situs slot deposit pulsa tanpa potongan apapun yang dijamin 100% garansi bebas biaya dimana deposit pulsa yang masuk ke dalam akun tidak akan dikenakan potongan apapun sehingga para pemain tidak akan terbebani dan bisa memanfaatkan modal bermain mereka dengan lebih maksimal. Sebab slot deposit pulsa tanpa potongan ini bertujuan untuk membantu para pecinta slot yang gemar bermain tetapi terhalang oleh keterbatasan akses dan modal, yang maka dari itu kami hadirkan fasilitas terbaru ini.   DAFTAR & LOGIN AKUN PRO SLOT DEPOSIT PULSA TANPA POTONGAN ⭐⭐⭐ KLIK DISINI ⭐⭐⭐  
  • Topics

×
×
  • Create New...

Important Information

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