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

  • Author
On 4/14/2020 at 7:42 PM, diesieben07 said:

You can set RangedAttribute#maximumValue using reflection.

Hey, so I have tried this now and set the maximum health to 2000. When I sysout getHealth() now it outputs this, the mob is also one hit. Do you know why?

Screenshot_82.png

  • Author
17 minutes ago, diesieben07 said:

Show your code.

		try {
			ReflectionUtil.setFieldValue(SharedMonsterAttributes.MAX_HEALTH.getClass().getDeclaredField("maximumValue"),
					SharedMonsterAttributes.MAX_HEALTH, 100000);
		} catch (NoSuchFieldException e) {
			e.printStackTrace();
		} catch (SecurityException e) {
			e.printStackTrace();
		}
		this.getAttributeMap().getAttributeInstance(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(robotHealth); //robotHealth = 2000

 

  • Author
4 minutes ago, diesieben07 said:
  1. That is not how you handle exceptions, ever.
  2. You need to use ObfuscationReflectionHelper and provide it with SRG names.
  3. Provide more context. Just a code snippet without surroundings is not helpful.

How else should I handle them?

  • Author
1 minute ago, diesieben07 said:

Do you expect them to ever happen?

If so: Decide how to continue. Can you continue on normally, maybe by doing an alternative action? Can you continue on normally with the action having failed? If you can't: re-throw the exception to signify that something fatal has continued and your code cannot carry on.

 

If you don't expect them to happen: Throw an exception signifying that something terrible has happened (your expectations of the exceptions not happening has failed).

 

"Just log and carry on blindly" is almost never the answer.

Okay. Either way, here's my full code of the function. Apparently the field isn't found even though it should be the correct field 

	@Override
	protected void applyEntityAttributes() {
		super.applyEntityAttributes();
		ObfuscationReflectionHelper.setPrivateValue(IAttribute.class, SharedMonsterAttributes.MAX_HEALTH, 1000,
				"field_111118_b");

		this.getAttributeMap().getAttributeInstance(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(robotHealth);
		this.getAttributeMap().getAttributeInstance(SharedMonsterAttributes.ATTACK_DAMAGE)
				.setBaseValue(this.attackDamage);
	}

 

  • Author
23 minutes ago, diesieben07 said:

IAttribute is an interface and thus does not have fields.

Oh yea, oops. Did it like this now and it still doesn't work.

	@Override
	protected void applyEntityAttributes() {
		super.applyEntityAttributes();
		ObfuscationReflectionHelper.setPrivateValue(RangedAttribute.class,
				(RangedAttribute) SharedMonsterAttributes.MAX_HEALTH, 1000, "field_111118_b");

		this.getAttributeMap().getAttributeInstance(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(robotHealth);
		this.getAttributeMap().getAttributeInstance(SharedMonsterAttributes.ATTACK_DAMAGE)
				.setBaseValue(this.attackDamage);
	}

 

  • Author
2 minutes ago, diesieben07 said:

Define "doesn't work".

It does the same thing as before. The health is outputted as "1.4E-45" and the mob is one hit

  • Author
13 minutes ago, diesieben07 said:

Where does robotHealth come from in your code above?

	public float robotHealth = 2000;

	@Override
	protected void applyEntityAttributes() {
		super.applyEntityAttributes();
		ObfuscationReflectionHelper.setPrivateValue(RangedAttribute.class,
				(RangedAttribute) SharedMonsterAttributes.MAX_HEALTH, 1000, "field_111118_b");

		this.getAttributeMap().getAttributeInstance(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(robotHealth);
		this.getAttributeMap().getAttributeInstance(SharedMonsterAttributes.ATTACK_DAMAGE)
				.setBaseValue(this.attackDamage);
	}

 

21 minutes ago, RobinCirex said:

ObfuscationReflectionHelper.setPrivateValue(RangedAttribute.class, (RangedAttribute) SharedMonsterAttributes.MAX_HEALTH, 1000, "field_111118_b");

You do know you are setting it to 1,000 right?

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

  • Author
1 minute ago, Animefan8888 said:

You do know you are setting it to 1,000 right?

oh, yea, that was a typo, but when setting it higher it still doesnt work

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.