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

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!

 

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.

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.