Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

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?

  On 4/26/2019 at 11:44 PM, 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.

  On 4/26/2019 at 11:44 PM, 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:

Reveal hidden contents

 

  • Author
 
 
 
  On 4/27/2019 at 12:22 AM, 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) {

 

 
 
 
  On 4/27/2019 at 12:22 AM, 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 

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:

Reveal hidden contents

 

  • Author
  On 4/27/2019 at 12:43 AM, 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

  On 4/27/2019 at 12:58 AM, 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:

Reveal hidden contents

 

  • Author
  On 4/27/2019 at 1:29 AM, 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

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:

Reveal hidden contents

 

  • Author
 
 
 
  On 4/27/2019 at 2:48 AM, DavidM said:

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

How can I do this?

  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:

Reveal hidden contents

 

  • Author
  On 4/27/2019 at 3:34 AM, 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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.