Jump to content

Recommended Posts

Posted (edited)

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!

Edited by CaptainSwag101
Beta 1.9, not release 1.9
Posted

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

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.?

Posted (edited)

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);
        }
    }

 

Edited by CaptainSwag101
Added additional error info

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.