Jump to content

Question about a method


Schottky

Recommended Posts

Hey everyone,

 

I am new to modding and therefore not so familiar with how i should write my mods, please be gentle :/

 

I have written this method in an event class and there seems something to be odd about it:

first of all: is this the best way to achieve what i want (If the player stands in water, the armor should loose durability)? What i have done seems a bit inperformant..

second: If i try this out everything works as expected but sometimes the durability value increases by 1 even thou it should decrease every time. Is this normal?

 

Thanks in advance,

Schottky

 

Here is the code:

 

private static int ticks = 0;
	
	private static final LinkedList<Item> DIRT_ARMOR_SET = ModItems.getDirtArmorSet();
	
	
	
	@SubscribeEvent
	public static void armorInFluid(TickEvent.PlayerTickEvent event)
	{
		if(ticks == 200)
		{
			
			EntityPlayer player = event.player;
			if(player.isInWater())
			{
				for(ItemStack armor: player.getArmorInventoryList())
				{
					if(DIRT_ARMOR_SET.contains(armor.getItem()))
					{
						int armorDamage = armor.getItemDamage();
						if((armor.getMaxDamage() - armorDamage) <= 1)
						{
							armor.setCount(0);
							player.playSound(SoundEvents.ENTITY_ITEM_BREAK, 1.0f, 0);
						} else
						{
							armor.setItemDamage(armorDamage +1);
						}
					}
				}
					ticks = 0;
				}
			} else
		{
			++ticks;
		}
			
	}

 

Link to comment
Share on other sites

Don't use setItemDamage, instead use damageItem.

That allows the item stack to resist the damage (unbreakable) as well as a few other things.

Edited by Draco18s

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

The code you posted should never result in that effect.

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

1 hour ago, Schottky said:

thanks a lot, but still this doesn't solve the problem that the durability decreases but sometimes also increases :( even thou i have no method that should increase it... any solutions for that?

stack.damageItem(1, playerIn);

should do. Otherwise, if it updates to full durability after it is damaged, you need to execute the method server-side.

Link to comment
Share on other sites

Sry for not writing so long!

Thank you so much for that tip, after that everything worked as intended (and i hopefully understand now the difference between Client and Server :P)

Just one more question: why shouldn't i use LinkedLists's? In this content off it doesn't make a lot of sense but if i want to make something different where i might need Lists, what should i use instead?

 

thx, Schottky

Link to comment
Share on other sites

Use an ArrayList.

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.



×
×
  • Create New...

Important Information

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