Jump to content

[1.8] check if full Armor is worn (SOLVED)


YoungErtu

Recommended Posts

SOLUTION

 

onArmorTick:

 

I changed the code and put it into onArmorTick Method, so if you don't want to use TickEvents you can use this

@Override
public void onArmorTick(World world, EntityPlayer player, ItemStack itemStack) {
	tick++;
	if(tick > 1000){

		if (player.inventory.armorItemInSlot(2) != null && player.inventory.armorItemInSlot(2).getItem() == YOURMODID.chestplate&& player.inventory.armorItemInSlot(1) != null && player.inventory.armorItemInSlot(1).getItem() ==  YOURMODID.leggings&& player.inventory.armorItemInSlot(0) != null && player.inventory.armorItemInSlot(0).getItem() ==  YOURMODID.boots) { 

//This line only execute the code once
		if(itemStack.getItem() == YourModID.anyArmorPiece){
		//YOUR CODE STUFF
			tick = 0;
			}
		}
	}

 

 

I have a problem im using onArmorTick to consume Mana from player, this armor will be summoned by the player when he use 10 mana, after 1000 ticks it should consume 10 mana again and this everytime when wearing the summoned armor and when the current mana is lower than the costs it will be deleted from inventory, but i have the problem that it consumes 30 mana every time when the ticks are higher than 1000, so the console execute the code 3 times.

 

here the console log:

 

[22:07:46] [server thread/INFO] [sTDOUT]: [youngertu.fairytail.items.spells.ItemHeartkreuzArmor:onArmorTick:48]: Consuming Mana [ARMOR]
[22:07:46] [server thread/INFO] [sTDOUT]: [youngertu.fairytail.items.spells.ItemHeartkreuzArmor:onArmorTick:48]: Consuming Mana [ARMOR]
[22:07:46] [server thread/INFO] [sTDOUT]: [youngertu.fairytail.items.spells.ItemHeartkreuzArmor:onArmorTick:48]: Consuming Mana [ARMOR]
[22:07:46] [server thread/INFO] [sTDOUT]: [youngertu.fairytail.network.server.UpdatePropsStats:process:62]: CONSUMED MANA
[22:07:46] [server thread/INFO] [sTDOUT]: [youngertu.fairytail.network.server.UpdatePropsStats:process:62]: CONSUMED MANA
[22:07:46] [server thread/INFO] [sTDOUT]: [youngertu.fairytail.network.server.UpdatePropsStats:process:62]: CONSUMED MANA

 

 

 

and here the code of onArmorTick:

 

@Override
public void onArmorTick(World world, EntityPlayer player, ItemStack itemStack) {
	ExtendedPlayer props = ExtendedPlayer.get(player);
	tick++;
	if(tick > 1000){

		if(props.getCurrentMana() >= 10){
			PacketDispatcher.sendToServer(new UpdatePropsStats(1, 10));
			System.out.println("Consuming Mana [ARMOR]");

		}
		else if(props.getCurrentMana() < 10){
			player.inventory.armorInventory[2] = null;
			player.inventory.armorInventory[1] = null;
			player.inventory.armorInventory[0] = null;
			player.inventory.consumeInventoryItem(FairyTail.HeartkreuzSword);
		}
		tick = 0;
	}
}

 

 

PacketDispatcher.sendToServer(new UpdatePropsStats(1, 10));

is just a method to update players stats from client side.

 

also here the code in the UpdatePropsStats class:

 

//CONSUME MANA
	if(what == 1){
		props.consumeMana(amount);
		System.out.println("CONSUMED MANA");
	}

 

 

"My Crew is World Wide." 「ヤング • エルトウ」

Link to comment
Share on other sites

onArmorTick will be called for every equipped armor piece, I assume that's what you are experiencing.

 

Ah ok yes that makes sense, thanks! how could i change that? Should i use a TickHandler for it or can i change that from onArmorTick Method, if yes how can i do this.

"My Crew is World Wide." 「ヤング • エルトウ」

Link to comment
Share on other sites

SOLVED:

 

Solution is creating a TickEvent with an if statement which checks if the full armor is worn and if yes what he should do.

 

 

here an example for the code

 

//First of all armorItemInSlot checks the current Slots 3 is helmet but my armor has no helmet, slot 2 chestplate, slot 1 leggings and slot 0 boots.
if (
		player.inventory.armorItemInSlot(2) != null && player.inventory.armorItemInSlot(2).getItem() == YOURMODID.ArmorChestplate &&
		player.inventory.armorItemInSlot(1) != null && player.inventory.armorItemInSlot(1).getItem() == YOURMODID.ArmorLeggings &&
		player.inventory.armorItemInSlot(0) != null && player.inventory.armorItemInSlot(0).getItem() == YOURMODID.ArmorBoots) { //WHAT SHOULD HAPPEN WHEN FULL ARMOR IS WORN? }

 

 

"My Crew is World Wide." 「ヤング • エルトウ」

Link to comment
Share on other sites

So you have a method available that runs every tick, but you subscribe to a TickEvent and do it in there... Seems a bit illogical to me, or not?

 

You only want your mana to run down when you have three pieces of armor equipped. So in the

onArmorTick 

method, check if the player has each of those three armor pieces equipped. You already have that. Now your issue is that the method is called 3 times? Maybe that's because you have 3 armor pieces equipped... So a simple if-statement to check if

ItemStack#getItem() == Mod.YourItem

should suffice. Why so complicated with tick events?

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Link to comment
Share on other sites

So you have a method available that runs every tick, but you subscribe to a TickEvent and do it in there... Seems a bit illogical to me, or not?

 

You only want your mana to run down when you have three pieces of armor equipped. So in the

onArmorTick 

method, check if the player has each of those three armor pieces equipped. You already have that. Now your issue is that the method is called 3 times? Maybe that's because you have 3 armor pieces equipped... So a simple if-statement to check if

ItemStack#getItem() == Mod.YourItem

should suffice. Why so complicated with tick events?

 

because how you said before, the method is called 3 times for every armor piece, and making an if statement wouldn't solve this, because everytime when the method is called the if statement would be true and that means it would still be executed 3 times.

"My Crew is World Wide." 「ヤング • エルトウ」

Link to comment
Share on other sites

So you have a method available that runs every tick, but you subscribe to a TickEvent and do it in there... Seems a bit illogical to me, or not?

 

You only want your mana to run down when you have three pieces of armor equipped. So in the

onArmorTick 

method, check if the player has each of those three armor pieces equipped. You already have that. Now your issue is that the method is called 3 times? Maybe that's because you have 3 armor pieces equipped... So a simple if-statement to check if

ItemStack#getItem() == Mod.YourItem

should suffice. Why so complicated with tick events?

 

because how you said before, the method is called 3 times for every armor piece, and making an if statement wouldn't solve this, because everytime when the method is called the if statement would be true and that means it would still be executed 3 times.

 

No, it wouldn't. What he's saying is that if the player is wearing all three armor pieces, then you check if the currently-running code is from, say, just the helemet or just the chestpiece or whatever before consuming mana. This way, although the armor will check for all three pieces, only one of those pieces (whichever you test for) will actually consume the mana, not all three.

Whatever Minecraft needs, it is most likely not yet another tool tier.

Link to comment
Share on other sites

So you have a method available that runs every tick, but you subscribe to a TickEvent and do it in there... Seems a bit illogical to me, or not?

 

You only want your mana to run down when you have three pieces of armor equipped. So in the

onArmorTick 

method, check if the player has each of those three armor pieces equipped. You already have that. Now your issue is that the method is called 3 times? Maybe that's because you have 3 armor pieces equipped... So a simple if-statement to check if

ItemStack#getItem() == Mod.YourItem

should suffice. Why so complicated with tick events?

 

because how you said before, the method is called 3 times for every armor piece, and making an if statement wouldn't solve this, because everytime when the method is called the if statement would be true and that means it would still be executed 3 times.

 

No, it wouldn't. What he's saying is that if the player is wearing all three armor pieces, then you check if the currently-running code is from, say, just the helemet or just the chestpiece or whatever before consuming mana. This way, although the armor will check for all three pieces, only one of those pieces (whichever you test for) will actually consume the mana, not all three.

 

ah ok got it, that would be possible ;D

"My Crew is World Wide." 「ヤング • エルトウ」

Link to comment
Share on other sites

I changed the code and put it into onArmorTick Method, so if you don't want to use TickEvents you can use this

 

 

@Override
public void onArmorTick(World world, EntityPlayer player, ItemStack itemStack) {
	tick++;
	if(tick > 1000){

		if (player.inventory.armorItemInSlot(2) != null && player.inventory.armorItemInSlot(2).getItem() == YOURMODID.chestplate&& player.inventory.armorItemInSlot(1) != null && player.inventory.armorItemInSlot(1).getItem() ==  YOURMODID.leggings&& player.inventory.armorItemInSlot(0) != null && player.inventory.armorItemInSlot(0).getItem() ==  YOURMODID.boots) { 

//This line only execute the code once
		if(itemStack.getItem() == YourModID.anyArmorPiece){
		//YOUR CODE STUFF
			tick = 0;
			}
		}
	}

 

"My Crew is World Wide." 「ヤング • エルトウ」

Link to comment
Share on other sites

I'd highly recommend you use this method over the Tick Handler. A tick handler will run once every tick, regardless of any other factors. The onArmorTick method, however, is *only* called when the armor item is being worn. So it's much more efficient than using a tick handler if you don't need one.

Whatever Minecraft needs, it is most likely not yet another tool tier.

Link to comment
Share on other sites

I'd highly recommend you use this method over the Tick Handler. A tick handler will run once every tick, regardless of any other factors. The onArmorTick method, however, is *only* called when the armor item is being worn. So it's much more efficient than using a tick handler if you don't need one.

 

Yes, already changed that.  ;D

"My Crew is World Wide." 「ヤング • エルトウ」

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



×
×
  • Create New...

Important Information

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