Jump to content

Recommended Posts

Posted

I have a problem with the code:
I was trying to create a repair gem compatible with baubles, the problem is when I try to check the metadata of the item. The item is unlocalized with "repair_gem" and it has 4 different variants (weak, normal, advanced and extreme) which have less cooldown between 2 repair

public boolean canRepair() {
		for (int i = 0; i < RepairGemTypes.values().length; i++) {
			// weak = 0;
			// normal = 1;
			// advanced = 2;
			// extreme = 3;
			ItemStack stack = new ItemStack(InitItems.REPAIR_GEM, 1, i);
			if (stack.getItemDamage() == 0) {
				if (r.tickCount >= 200) {
					r.tickCount = 0;
					r.shouldUpdate = false;
					return true;
				}
			} else if (stack.getItemDamage() == 1) {
				if (r.tickCount >= 120) {
					r.tickCount = 0;
					r.shouldUpdate = false;
					return true;
				}
			} else if (stack.getItemDamage() == 2) {
				if (r.tickCount >= 60) {
					r.tickCount = 0;
					r.shouldUpdate = false;
					return true;
				}
			} else if (stack.getItemDamage() == 3) {
				if (r.tickCount >= 20) {
					r.tickCount = 0;
					r.shouldUpdate = false;
					return true;
				}
			}
		}
		return false;
	}

but it always prints the metadata 0

How can I fix this?

Posted (edited)
56 minutes ago, X_Khan_X said:

How can I fix this?

1. Use Item#getMetadata Stack#getMetadata and pass in the ItemStack you want to check.

2. Your else ifs are rather messy and unnecessary. Use math to generalize the relationship between tiers and cool downs.

3.

56 minutes ago, X_Khan_X said:

I was trying to create a repair gem compatible with baubles

If you are talking about this: https://minecraft.curseforge.com/projects/repair-gem, then I am making it baubles compatible (I almost forgot about that mod...).

Edited by DavidM

Some tips:

Spoiler

Modder Support:

Spoiler

1. Do not follow tutorials on YouTube, especially TechnoVision (previously called Loremaster) and HarryTalks, due to their promotion of bad practice and usage of outdated code.

2. Always post your code.

3. Never copy and paste code. You won't learn anything from doing that.

4. 

Quote

Programming via Eclipse's hotfixes will get you nowhere

5. Learn to use your IDE, especially the debugger.

6.

Quote

The "picture that's worth 1000 words" only works if there's an obvious problem or a freehand red circle around it.

Support & Bug Reports:

Spoiler

1. Read the EAQ before asking for help. Remember to provide the appropriate log(s).

2. Versions below 1.11 are no longer supported due to their age. Update to a modern version of Minecraft to receive support.

 

 

Posted
 
 
 
3 minutes ago, DavidM said:

1. Use Item#getMetadata and pass in the ItemStack you want to check.

Do you mean: 

ItemStack stack = new ItemStack(InitItems.REPAIR_GEM, 1, i);
			if (stack.getMetadata() == 0) {

 

 
 
 
3 minutes ago, DavidM said:

If you are talking about this: https://minecraft.curseforge.com/projects/repair-gem, then I am making it baubles compatible (I almost forgot I have that mod...).

Oh... No no, I was trying to implement a repair gem (an original name lol) into my mod 

Posted

Yes basically (I posted the wrong method).

Don't obtain the ItemStack in such a way though; use the one that is passed in.

Some tips:

Spoiler

Modder Support:

Spoiler

1. Do not follow tutorials on YouTube, especially TechnoVision (previously called Loremaster) and HarryTalks, due to their promotion of bad practice and usage of outdated code.

2. Always post your code.

3. Never copy and paste code. You won't learn anything from doing that.

4. 

Quote

Programming via Eclipse's hotfixes will get you nowhere

5. Learn to use your IDE, especially the debugger.

6.

Quote

The "picture that's worth 1000 words" only works if there's an obvious problem or a freehand red circle around it.

Support & Bug Reports:

Spoiler

1. Read the EAQ before asking for help. Remember to provide the appropriate log(s).

2. Versions below 1.11 are no longer supported due to their age. Update to a modern version of Minecraft to receive support.

 

 

Posted
13 minutes ago, DavidM said:

Yes basically (I posted the wrong method).

Don't obtain the ItemStack in such a way though; use the one that is passed in.

Can you help me to do it? I don't know how to do it

Posted
23 minutes ago, X_Khan_X said:

Can you help me to do it? I don't know how to do it

I'm not going to write your code for you, as you won't learn that way.

If you want your repair gem to repair items while the gem is in the player's inventory, you will probably need to override Item#onUpdate, which is defined as:

public void onUpdate(ItemStack stack, World world, Entity entity, int itemSlot, boolean isSelected)

See the ItemStack in the parameter? You should use that stack instead of creating a new one, so you should call stack.getMetaData() on that ItemStack.

Some tips:

Spoiler

Modder Support:

Spoiler

1. Do not follow tutorials on YouTube, especially TechnoVision (previously called Loremaster) and HarryTalks, due to their promotion of bad practice and usage of outdated code.

2. Always post your code.

3. Never copy and paste code. You won't learn anything from doing that.

4. 

Quote

Programming via Eclipse's hotfixes will get you nowhere

5. Learn to use your IDE, especially the debugger.

6.

Quote

The "picture that's worth 1000 words" only works if there's an obvious problem or a freehand red circle around it.

Support & Bug Reports:

Spoiler

1. Read the EAQ before asking for help. Remember to provide the appropriate log(s).

2. Versions below 1.11 are no longer supported due to their age. Update to a modern version of Minecraft to receive support.

 

 

Posted (edited)
23 minutes ago, DavidM said:

I'm not going to write your code for you, as you won't learn that way.

If you want your repair gem to repair items while the gem is in the player's inventory, you will probably need to override Item#onUpdate, which is defined as:


public void onUpdate(ItemStack stack, World world, Entity entity, int itemSlot, boolean isSelected)

See the ItemStack in the parameter? You should use that stack instead of creating a new one, so you should call stack.getMetaData() on that ItemStack.

I know but I have it in another class that manage my cooldowns and I cant add "ItemStack stack" to that method, that's why I need to get the itemstack and the item damage

Edited by X_Khan_X
Posted

Why do you need another class for the cool down?

Just store the cool down value in the NBTTag of the stack or something.

Alternatively, you can get the meta from the stack and pass it to methods in the other class.

Some tips:

Spoiler

Modder Support:

Spoiler

1. Do not follow tutorials on YouTube, especially TechnoVision (previously called Loremaster) and HarryTalks, due to their promotion of bad practice and usage of outdated code.

2. Always post your code.

3. Never copy and paste code. You won't learn anything from doing that.

4. 

Quote

Programming via Eclipse's hotfixes will get you nowhere

5. Learn to use your IDE, especially the debugger.

6.

Quote

The "picture that's worth 1000 words" only works if there's an obvious problem or a freehand red circle around it.

Support & Bug Reports:

Spoiler

1. Read the EAQ before asking for help. Remember to provide the appropriate log(s).

2. Versions below 1.11 are no longer supported due to their age. Update to a modern version of Minecraft to receive support.

 

 

Posted
Quote

How can I do this?

This should be basic Java.

If you do not know how to pass objects as parameters, then I'm afraid you are not ready to make a mod.

Learn Java first.

Some tips:

Spoiler

Modder Support:

Spoiler

1. Do not follow tutorials on YouTube, especially TechnoVision (previously called Loremaster) and HarryTalks, due to their promotion of bad practice and usage of outdated code.

2. Always post your code.

3. Never copy and paste code. You won't learn anything from doing that.

4. 

Quote

Programming via Eclipse's hotfixes will get you nowhere

5. Learn to use your IDE, especially the debugger.

6.

Quote

The "picture that's worth 1000 words" only works if there's an obvious problem or a freehand red circle around it.

Support & Bug Reports:

Spoiler

1. Read the EAQ before asking for help. Remember to provide the appropriate log(s).

2. Versions below 1.11 are no longer supported due to their age. Update to a modern version of Minecraft to receive support.

 

 

Posted
47 minutes ago, DavidM said:

This should be basic Java.

If you do not know how to pass objects as parameters, then I'm afraid you are not ready to make a mod.

Learn Java first.

LOL. I've solved, was really stupid and thanks for your help, you really helped me.

For mods: This thread can be closed

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.