Jump to content

Recommended Posts

Posted
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

Posted
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

 

Posted
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?

Posted
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);
	}

 

Posted
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);
	}

 

Posted
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);
	}

 

Posted
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.

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.