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

    • SLOT DEMO PRINCESS 1000 : DEMO SLOT STARLIGHT PRINCESS x 1000 RUPIAH GRATIS TANPA DEPOSIT KLIK DISINI DAFTAR DISINI SLOT VVIP << KLIK DISINI DAFTAR DISINI SLOT VVIP << KLIK DISINI DAFTAR DISINI SLOT VVIP << KLIK DISINI DAFTAR DISINI SLOT VVIP << SITUS SLOT GACOR 88 MAXWIN X500 HARI INI TERBAIK DAN TERPERCAYA GAMPANG MENANG Dunia Game gacor terus bertambah besar seiring berjalannya waktu, dan sudah tentu dunia itu terus berkembang serta merta bersamaan dengan berkembangnya SLOT GACOR sebagai website number #1 yang pernah ada dan tidak pernah mengecewakan sekalipun. Dengan banyaknya member yang sudah mempercayakan untuk terus menghasilkan uang bersama dengan SLOT GACOR pastinya mereka sudah percaya untuk bermain Game online bersama dengan kami dengan banyaknya testimoni yang sudah membuktikan betapa seringnya member mendapatkan jackpot besar yang bisa mencapai ratusan juta rupiah. Best online Game website that give you more money everyday, itu lah slogan yang tepat untuk bermain bersama SLOT GACOR yang sudah pasti menang setiap harinya dan bisa menjadikan bandar ini sebagai patokan untuk mendapatkan penghasilan tambahan yang efisien dan juga sesuatu hal yang fix setiap hari nya. Kami juga mendapatkan julukan sebagai Number #1 website bocor yang berarti terus memberikan member uang asli dan jackpot setiap hari nya, tidak lupa bocor itu juga bisa diartikan dalam bentuk berbagi promosi untuk para official member yang terus setia bermain bersama dengan kami. Berbagai provider Game terus bertambah banyak setiap harinya dan terus melakukan support untuk membuat para official member terus bisa menang dan terus maxwin dalam bentuk apapun maka itu langsung untuk feel free to try yourself, play with SLOT GACOR now or never !
    • FREEBET SLOT : SLOT FREEBET TANPA DEPOSIT FREECHIP 20K 30K 50K TO KECIL RENDAH x2 x3 x4 x5 - SLOT GRATIS TANPA DEPOSIT KLIK DISINI DAFTAR DISINI SLOT VVIP << KLIK DISINI DAFTAR DISINI SLOT VVIP << KLIK DISINI DAFTAR DISINI SLOT VVIP << KLIK DISINI DAFTAR DISINI SLOT VVIP << SITUS SLOT GACOR 88 MAXWIN X500 HARI INI TERBAIK DAN TERPERCAYA GAMPANG MENANG Dunia Game gacor terus bertambah besar seiring berjalannya waktu, dan sudah tentu dunia itu terus berkembang serta merta bersamaan dengan berkembangnya SLOT GACOR sebagai website number #1 yang pernah ada dan tidak pernah mengecewakan sekalipun. Dengan banyaknya member yang sudah mempercayakan untuk terus menghasilkan uang bersama dengan SLOT GACOR pastinya mereka sudah percaya untuk bermain Game online bersama dengan kami dengan banyaknya testimoni yang sudah membuktikan betapa seringnya member mendapatkan jackpot besar yang bisa mencapai ratusan juta rupiah. Best online Game website that give you more money everyday, itu lah slogan yang tepat untuk bermain bersama SLOT GACOR yang sudah pasti menang setiap harinya dan bisa menjadikan bandar ini sebagai patokan untuk mendapatkan penghasilan tambahan yang efisien dan juga sesuatu hal yang fix setiap hari nya. Kami juga mendapatkan julukan sebagai Number #1 website bocor yang berarti terus memberikan member uang asli dan jackpot setiap hari nya, tidak lupa bocor itu juga bisa diartikan dalam bentuk berbagi promosi untuk para official member yang terus setia bermain bersama dengan kami. Berbagai provider Game terus bertambah banyak setiap harinya dan terus melakukan support untuk membuat para official member terus bisa menang dan terus maxwin dalam bentuk apapun maka itu langsung untuk feel free to try yourself, play with SLOT GACOR now or never !
    • 🤑DAFTAR & LOGIN🤑 🤑DAFTAR & LOGIN🤑 🤑DAFTAR & LOGIN🤑   Daftar Slot Ratuasia77 adalah bocoran slot rekomendasi gacor dari Ratuasia77 yang bisa anda temukan di SLOT Ratuasia77. Situs SLOT Ratuasia77 hari ini yang kami bagikan di sini adalah yang terbaik dan bersiaplah untuk mengalami sensasi tak terlupakan dalam permainan slot online. Temukan game SLOT Ratuasia77 terbaik dengan 100 pilihan provider ternama yang dipercaya akan memberikan kepuasan dan kemenangan hari ini untuk meraih x500. RTP SLOT Ratuasia77 merupakan SLOT Ratuasia77 hari ini yang telah menjadi pilihan utama bagi pemain judi online di seluruh Indonesia. Setiap harinya jutaan pemain memasuki dunia maya untuk memperoleh hiburan seru dan kemenangan besar dalam bermain slot dengan adanya bocoran RTP SLOT Ratuasia77. Tidak ada yang lebih menyenangkan daripada mengungguli mesin slot dan meraih jackpot x500 yang menggiurkan di situs SLOT Ratuasia77 hari ini yang telah disediakan SLOT Ratuasia77. Menangkan jackpot besar x500 rajanya maxwin dari segala slot dan raih kemenangan spektakuler di situs Ratuasia77 terbaik 2024 adalah tempat yang menyediakan mesin slot dengan peluang kemenangan lebih tinggi daripada situs slot lainnya. Bagi anda yang mencari pengalaman judi slot paling seru dan mendebarkan, situs bo SLOT Ratuasia77 terbaik 2024 adalah pilihan yang tepat. Jelajahi dunia slot online melalui situs SLOT Ratuasia77 di link SLOT Ratuasia77.
    • 20 SLOT DEMO GRATIS PRAGMATIC PLAY x500 RUPIAH ANTI LAG & 20 DEMO SLOT MAHJONG WAYS PG SOFT GRATIS ANTI RUNGKAD KLIK DISINI DAFTAR DISINI SLOT VVIP << KLIK DISINI DAFTAR DISINI SLOT VVIP << KLIK DISINI DAFTAR DISINI SLOT VVIP << KLIK DISINI DAFTAR DISINI SLOT VVIP << SITUS SLOT GACOR 88 MAXWIN X500 HARI INI TERBAIK DAN TERPERCAYA GAMPANG MENANG Dunia Game gacor terus bertambah besar seiring berjalannya waktu, dan sudah tentu dunia itu terus berkembang serta merta bersamaan dengan berkembangnya SLOT GACOR sebagai website number #1 yang pernah ada dan tidak pernah mengecewakan sekalipun. Dengan banyaknya member yang sudah mempercayakan untuk terus menghasilkan uang bersama dengan SLOT GACOR pastinya mereka sudah percaya untuk bermain Game online bersama dengan kami dengan banyaknya testimoni yang sudah membuktikan betapa seringnya member mendapatkan jackpot besar yang bisa mencapai ratusan juta rupiah. Best online Game website that give you more money everyday, itu lah slogan yang tepat untuk bermain bersama SLOT GACOR yang sudah pasti menang setiap harinya dan bisa menjadikan bandar ini sebagai patokan untuk mendapatkan penghasilan tambahan yang efisien dan juga sesuatu hal yang fix setiap hari nya. Kami juga mendapatkan julukan sebagai Number #1 website bocor yang berarti terus memberikan member uang asli dan jackpot setiap hari nya, tidak lupa bocor itu juga bisa diartikan dalam bentuk berbagi promosi untuk para official member yang terus setia bermain bersama dengan kami. Berbagai provider Game terus bertambah banyak setiap harinya dan terus melakukan support untuk membuat para official member terus bisa menang dan terus maxwin dalam bentuk apapun maka itu langsung untuk feel free to try yourself, play with SLOT GACOR now or never !
    • BOCORAN POLA SLOT GACOR MAHJONG WAYS MAXWIN x500 PETIR MERAH HARI INI HINGGA MALAM INI KLIK DISINI DAFTAR SLOT VVIP << KLIK DISINI DAFTAR SLOT VVIP << KLIK DISINI DAFTAR SLOT VVIP << KLIK DISINI DAFTAR SLOT VVIP << SITUS SLOT GACOR 88 MAXWIN X500 HARI INI TERBAIK DAN TERPERCAYA GAMPANG MENANG Dunia Game gacor terus bertambah besar seiring berjalannya waktu, dan sudah tentu dunia itu terus berkembang serta merta bersamaan dengan berkembangnya SLOT GACOR sebagai website number #1 yang pernah ada dan tidak pernah mengecewakan sekalipun. Dengan banyaknya member yang sudah mempercayakan untuk terus menghasilkan uang bersama dengan SLOT GACOR pastinya mereka sudah percaya untuk bermain Game online bersama dengan kami dengan banyaknya testimoni yang sudah membuktikan betapa seringnya member mendapatkan jackpot besar yang bisa mencapai ratusan juta rupiah. Best online Game website that give you more money everyday, itu lah slogan yang tepat untuk bermain bersama SLOT GACOR yang sudah pasti menang setiap harinya dan bisa menjadikan bandar ini sebagai patokan untuk mendapatkan penghasilan tambahan yang efisien dan juga sesuatu hal yang fix setiap hari nya. Kami juga mendapatkan julukan sebagai Number #1 website bocor yang berarti terus memberikan member uang asli dan jackpot setiap hari nya, tidak lupa bocor itu juga bisa diartikan dalam bentuk berbagi promosi untuk para official member yang terus setia bermain bersama dengan kami. Berbagai provider Game terus bertambah banyak setiap harinya dan terus melakukan support untuk membuat para official member terus bisa menang dan terus maxwin dalam bentuk apapun maka itu langsung untuk feel free to try yourself, play with SLOT GACOR now or never !
  • Topics

×
×
  • Create New...

Important Information

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