Posted October 6, 201212 yr As I'm porting my mod to Forge, the mod now has its own package package.drzhark.mocreatures; import net.minecraft.src.*; There are many places in my code where I need to access or change the value of a protected variable, i.e entitymob.entityToAttack in the following method: public static void repelMobs(Entity entity1, Double dist, World worldObj) { List list = worldObj.getEntitiesWithinAABBExcludingEntity(entity1, entity1.boundingBox.expand(dist, 4D, dist)); for(int i = 0; i < list.size(); i++) { Entity entity = (Entity) list.get(i); if(!(entity instanceof EntityMob)) { continue; } EntityMob entitymob = (EntityMob) entity; entitymob.entityToAttack = null; entitymob.setPathToEntity(null); } } However that variable entityToAttack is now unaccessible from my package, as it is a protected variable that does not have a Getter/Setter. Is there a way around this? I guess it could be done with reflection (which I'm not too familiar with). Or if there is an easier way, I'm all ears. Thanks in advance!
October 6, 201212 yr A child class of a base class can always access the protected members of that base class. Reflection can access other protected vars, but has a speed cost. If you ever need to do it in a speed sensitive area of code (hundreds of times in a tight loop for example), then submit a patch to have forge change it to public. There are a few other things, but that is the gist.
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.