-
[1.10.2] How to replace an entity's doLivingUpdate() method?
This doesn't seem to work properly for me, I keep getting a this error: java.lang.IllegalAccessException: no private access for invokespecial: class net.minecraft.entity.monster.EntityMob, from net.minecraft.entity.monster.EntityMob/public at java.lang.invoke.MemberName.makeAccessException(MemberName.java:850) ~[?:1.8.0_131] at java.lang.invoke.MethodHandles$Lookup.checkSpecialCaller(MethodHandles.java:1572) ~[?:1.8.0_131] at java.lang.invoke.MethodHandles$Lookup.findSpecial(MethodHandles.java:1002) ~[?:1.8.0_131] Here's the relevant code: // static and final are important, they ensure this can be optimized by the JVM protected static final MethodHandle mobLivingUpdate; static { try { // with lookup().in(EntityMob.class) we obtain access to things that are "private" in EntityMob. // findSpecial invokes the method in EntityMob.class without checking for overriding methods (such as the one in EntityEnderman) mobLivingUpdate = MethodHandles.lookup().in(EntityMob.class).findSpecial(EntityMob.class, "onLivingUpdate", MethodType.methodType(void.class), EntityMob.class); } catch (Exception e) { throw new RuntimeException(e); } } /** * Called frequently so the entity can update its state every tick as required. For example, zombies and skeletons * use this to react to sunlight and start to burn. */ @Override public void onLivingUpdate() { if (this.world.isRemote) { for (int i = 0; i < 2; ++i) { if (oldAppearance) { this.world.spawnParticle(EnumParticleTypes.SMOKE_LARGE, this.posX + (this.rand.nextDouble() - 0.5D) * (double)this.width, this.posY + this.rand.nextDouble() * (double)this.height, this.posZ + (this.rand.nextDouble() - 0.5D) * (double)this.width, 0.0D, 0.0D, 0.0D); } else { this.world.spawnParticle(EnumParticleTypes.PORTAL, this.posX + (this.rand.nextDouble() - 0.5D) * (double)this.width, this.posY + this.rand.nextDouble() * (double)this.height - 0.25D, this.posZ + (this.rand.nextDouble() - 0.5D) * (double)this.width, (this.rand.nextDouble() - 0.5D) * 2.0D, -this.rand.nextDouble(), (this.rand.nextDouble() - 0.5D) * 2.0D, new int[0]); } } } this.isJumping = false; try { // invokeExact is important, it ensures that this can be optimized by the JVM mobLivingUpdate.invokeExact((EntityMob) this); } catch (Throwable x) { throw new RuntimeException(x); } }
-
[1.10.2] How to replace an entity's doLivingUpdate() method?
I see. In that case, what would you recommend I do to solve this issue? Should I just copy/paste the whole EntityEnderman class and extend EntityMob instead, or should I use ASM to modify the vanilla class, etc.?
-
[1.10.2] How to replace an entity's doLivingUpdate() method?
Hello, I'm trying to make a mod which changes the Enderman's default particles with clouds of smoke particles, so they look like they did back in the Beta 1.9 prereleases. I'm making a custom class "CustomEnderman" which extends EntityEnderman so I don't have to duplicate tons code that I don't want to modify. However, the doLivingUpdate() method where the vanilla class spawns the particles also needs to call its parent method EntityMob.doLivingUpdate(), but I can't do that in my custom class because that would call the vanilla particle-spawning code that I want to disable. I could just make a complete duplicate of the EntityEnderman class and extend EntityMob instead, but that means I have to copy hundreds of lines of code every time I want to change 3 lines, and I feel like there must be a better way of doing it. I've also looked into Access Transformers and Coremods, but all the tutorials are very out-of-date, and they don't really explain how to modify their sample code to use it in other situations. tl;dr Basically, my CustomEnderman class extends EntityEnderman, which extends EntityMob. So, is there any way I can call EntityMob.doLivingUpdate() without having to call EntityEnderman.doLivingUpdate()? Any help would be appreciated!
IPS spam blocked by CleanTalk.