Skip to content

Instantly share code, notes, and snippets.

@phase
Last active June 11, 2020 00:22
Show Gist options
  • Save phase/49845927d41806a609a3e35935c52ea0 to your computer and use it in GitHub Desktop.
Save phase/49845927d41806a609a3e35935c52ea0 to your computer and use it in GitHub Desktop.

Idea for @Proxy:

@Shadow
public abstract void renderNameTag(String arg);

@Proxy("renderNameTag")
public void proxy$renderNameTag(String arg) {
    if (CONDITION) {
        this.renderNameTag(arg);
    } else {
        for (int i = 0; i < 5; i++) {
            this.renderNameTag(arg + " " + i);
        }
    }
}

target class contains this after mixin application:

public void renderNameTag(String arg) {
    if (CONDITION) {
        this.original$renderNameTag(arg);
    } else {
        for (int i = 0; i < 5; i++) {
            this.original$renderNameTag(arg + " " + i);
        }
    }
}

public void original$renderNameTag(String arg) {
    // original renderNameTag()
}

Target class contains this:

    public void setAngles(float var1, float var2) {
        float var3 = this.z;
        float var4 = this.y;
        this.y = (float)((double)this.y + (double)var1 * 0.15D);
        this.z = (float)((double)this.z - (double)var2 * 0.15D);
        if (this.z < -90.0F) {
            this.z = -90.0F;
        }

        if (this.z > 90.0F) {
            this.z = 90.0F;
        }

        this.B += this.z - var3;
        this.A += this.y - var4;
    }

we want to add a cancellable event to the top and modify the arguments to be the result of the event call

    @Shadow public abstract void setAngles(float v, float v1);

    @Proxy("setAngles(FF)V")
    public void proxy$setAngles(float yaw, float pitch) {
        EventAngles event = new EventAngles(this, yaw, pitch);
        EventBus.getBus().post(event);
        if (event.isCancelled()) {
            return;
        }
        this.setAngles(event.getYaw(), event.getPitch());
    }

target class becomes

    public void original+setAngles(float var1, float var2) {
        float var3 = this.z;
        float var4 = this.y;
        this.y = (float)((double)this.y + (double)var1 * 0.15D);
        this.z = (float)((double)this.z - (double)var2 * 0.15D);
        if (this.z < -90.0F) {
            this.z = -90.0F;
        }

        if (this.z > 90.0F) {
            this.z = 90.0F;
        }

        this.B += this.z - var3;
        this.A += this.y - var4;
    }

    @Proxy("setAngles(FF)V")
    @MixinMerged(
        mixin = "EntityMixin",
        priority = 1000,
        sessionId = "e5bb6c81-d875-40f0-9763-ae8c77a55b19"
    )
    public void setAngles(float yaw, float pitch) {
        EventAngles event = new EventAngles(this, yaw, pitch);
        EventBus.getBus().post(event);
        if (!event.isCancelled()) {
            this.original+setAngles(event.getYaw(), event.getPitch());
        }
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment