java - Modifying code within a protected method -
i wondering if possible override protected method in 3rd party jar file. guessing can invoke method using reflection, how overwrite it?
the method is
protected void a(world world, int i, int j, int k, itemstack itemstack) { if (!world.isstatic && world.getgamerules().getboolean("dotiledrops")) { float f = 0.7f; double d0 = (double) (world.random.nextfloat() * f) + (double) (1.0f - f) * 0.5d; double d1 = (double) (world.random.nextfloat() * f) + (double) (1.0f - f) * 0.5d; double d2 = (double) (world.random.nextfloat() * f) + (double) (1.0f - f) * 0.5d; entityitem entityitem = new entityitem(world, (double) + d0, (double) j + d1, (double) k + d2, itemstack); entityitem.pickupdelay = 10; world.addentity(entityitem); } }
yes, point of protected
methods can overridden subclass implementations in different packages/modules (the default access mode allows same package).
it subclass decide if wants call super method or not.
so have
class myversion extends theclass { @override protected void a(world world, int i, int j, int k, itemstack itemstack) { // else } }
of course, more interesting question how make rest of application use new version instead of original. if code drives instantiation of object, no problem. otherwise, may have find configuration setting or change more code.
Comments
Post a Comment