Jump to content

Access Transformer not working - I would like to use some protected methods


Recommended Posts

Posted (edited)
public net.minecraft.entity.LivingEntity func_184583_d(Lnet/minecraft/util/DamageSource;)Z # isDamageSourceBlocked
public net.minecraft.entity.LivingEntity func_184590_k(F)V # hurtCurrentlyUsedShield
public net.minecraft.entity.LivingEntity func_190629_c(Lnet/minecraft/entity/LivingEntity;)V # blockUsingShield

I'm trying to use these methods in LivingEntity.java, but I'm getting the following error: 

"attempting to assign weaker access privileges; was public"

 

I would like to use these methods in my Hooks.java class (location: /src/main/java/mod/mores/util/Hooks.java),

so that I can change how much incoming damage my custom shields can block.

 

My question is, why am I getting this error?

And also, what would be the correct way of achieving what I want?

 

GitRepository: https://github.com/Leronus/mOres

 

Edited by Leronus
Forgot gitRepo
Posted (edited)
1 hour ago, diesieben07 said:

Protected methods cannot easily be made public, you have to list all methods that override them. Only the actual method you list will be transformed, so the overriding methods now produce errors (you cannot override a public method with a protected one).

Firstly, isDamageSourceBlocked is already public.

Why do you want to call these methods?

 

I'm trying to modify the amount of damage blocked. For example, the vanilla shield currently blocks 100% of incoming damage, I would like to change that to 60%.

For my other custom shields I want to increase this numbers, which depends on the material the shield is made out of.

To do so, I require access to

1. LivingEntity.isDamageSourceBlocked(DamageSource p_184583_1_)

2. LivingEntity.blockUsingShield(LivingEntity p_190629_1_) 

3. LivingEntity.hurtCurrentlyUsedShield(float p_184590_1_)

When I look at LivingEntity.isDamageSourceBlocked(DamageSource p_184583_1_) it is most definitely private.

The other two methods are indeed protected.

I am currently using Forge 36.2.6

 

Any way to accomplish this or should I just accept the vanilla shield functionality?

 

 

Edited by Leronus
Further explanation
Posted
10 minutes ago, diesieben07 said:

I was looking at the latest version, because you did not specify. In 1.17 this method is public.

You can call the methods using reflection.

My bad sorry. I solved it by using the accesstransformers for PlayerEntity as well. Thanks though!

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.