Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Method override is not being remapped for subclasses in different modules #83

Open
willkroboth opened this issue Aug 11, 2022 · 1 comment

Comments

@willkroboth
Copy link

willkroboth commented Aug 11, 2022

I have some classes set up like this:

Before mapping:

Module 1_19-common

pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <artifactId>ConfigCommands-nms</artifactId>
        <groupId>me.willkroboth</groupId>
        <version>3.0.0</version>
    </parent>

    <artifactId>ConfigCommands-1_19-common</artifactId>

    <properties>
        <spigot.version>1.19-R0.1-SNAPSHOT</spigot.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.spigotmc</groupId>
            <artifactId>spigot</artifactId>
            <version>${spigot.version}</version>
            <classifier>remapped-mojang</classifier>
            <scope>provided</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <executions>
                    <execution>
                        <id>Mojang-Mapped</id>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                        <configuration>
                            <classifier>mojang-mapped</classifier>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>net.md-5</groupId>
                <artifactId>specialsource-maven-plugin</artifactId>
                <version>1.2.4</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>remap</goal>
                        </goals>
                        <id>remap-obf</id>
                        <configuration>
                            <srgIn>org.spigotmc:minecraft-server:${spigot.version}:txt:maps-mojang</srgIn>
                            <reverse>true</reverse>
                            <remappedDependencies>org.spigotmc:spigot:${spigot.version}:jar:remapped-mojang</remappedDependencies>
                            <remappedArtifactAttached>true</remappedArtifactAttached>
                            <remappedClassifierName>remapped-obf</remappedClassifierName>
                        </configuration>
                    </execution>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>remap</goal>
                        </goals>
                        <id>remap-spigot</id>
                        <configuration>
                            <inputFile>${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar</inputFile>
                            <srgIn>org.spigotmc:minecraft-server:${spigot.version}:csrg:maps-spigot</srgIn>
                            <remappedDependencies>org.spigotmc:spigot:${spigot.version}:jar:remapped-obf</remappedDependencies>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

PlayerOpSender1_19_common.java:

import net.minecraft.server.level.ServerPlayer;

public abstract class PlayerOpSender1_19_common ... {
    ...
    protected abstract static class ServerPlayerOpWrapper extends ServerPlayer {
        ...
    }
    ...
}

Module 1_19

pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <artifactId>ConfigCommands-nms</artifactId>
        <groupId>me.willkroboth</groupId>
        <version>3.0.0</version>
    </parent>

    <artifactId>ConfigCommands-1_19</artifactId>

    <properties>
        <spigot.version>1.19-R0.1-SNAPSHOT</spigot.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.spigotmc</groupId>
            <artifactId>spigot</artifactId>
            <version>${spigot.version}</version>
            <classifier>remapped-mojang</classifier>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>me.willkroboth</groupId>
            <artifactId>ConfigCommands-1_19-common</artifactId>
            <version>${project.version}</version>
            <classifier>mojang-mapped</classifier>
            <scope>provided</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>net.md-5</groupId>
                <artifactId>specialsource-maven-plugin</artifactId>
                <version>1.2.4</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>remap</goal>
                        </goals>
                        <id>remap-obf</id>
                        <configuration>
                            <srgIn>org.spigotmc:minecraft-server:${spigot.version}:txt:maps-mojang</srgIn>
                            <reverse>true</reverse>
                            <remappedDependencies>org.spigotmc:spigot:${spigot.version}:jar:remapped-mojang</remappedDependencies>
                            <remappedArtifactAttached>true</remappedArtifactAttached>
                            <remappedClassifierName>remapped-obf</remappedClassifierName>
                        </configuration>
                    </execution>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>remap</goal>
                        </goals>
                        <id>remap-spigot</id>
                        <configuration>
                            <inputFile>${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar</inputFile>
                            <srgIn>org.spigotmc:minecraft-server:${spigot.version}:csrg:maps-spigot</srgIn>
                            <remappedDependencies>org.spigotmc:spigot:${spigot.version}:jar:remapped-obf</remappedDependencies>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

PlayerOpSender1_19.java:

public class PlayerOpSender1_19 extends PlayerOpSender1_19_common ... {
    ...
    protected static class ServerPlayerOpWrapper extends PlayerOpSender1_19_common.ServerPlayerOpWrapper{
        ...
        @Override
        public CommandSourceStack createCommandSourceStack() {
            return OpSender1_19_common.modifyStack(super.createCommandSourceStack(), source);
        }
    }
}

Module 1_19_1

pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <artifactId>ConfigCommands-nms</artifactId>
        <groupId>me.willkroboth</groupId>
        <version>3.0.0</version>
    </parent>

    <artifactId>ConfigCommands-1_19_1</artifactId>
    <properties>
        <spigot.version>1.19.1-R0.1-SNAPSHOT</spigot.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.spigotmc</groupId>
            <artifactId>spigot</artifactId>
            <version>${spigot.version}</version>
            <classifier>remapped-mojang</classifier>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>me.willkroboth</groupId>
            <artifactId>ConfigCommands-1_19-common</artifactId>
            <version>${project.version}</version>
            <classifier>mojang-mapped</classifier>
            <scope>provided</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>net.md-5</groupId>
                <artifactId>specialsource-maven-plugin</artifactId>
                <version>1.2.4</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>remap</goal>
                        </goals>
                        <id>remap-obf</id>
                        <configuration>
                            <srgIn>org.spigotmc:minecraft-server:${spigot.version}:txt:maps-mojang</srgIn>
                            <reverse>true</reverse>
                            <remappedDependencies>org.spigotmc:spigot:${spigot.version}:jar:remapped-mojang</remappedDependencies>
                            <remappedArtifactAttached>true</remappedArtifactAttached>
                            <remappedClassifierName>remapped-obf</remappedClassifierName>
                        </configuration>
                    </execution>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>remap</goal>
                        </goals>
                        <id>remap-spigot</id>
                        <configuration>
                            <inputFile>${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar</inputFile>
                            <srgIn>org.spigotmc:minecraft-server:${spigot.version}:csrg:maps-spigot</srgIn>
                            <remappedDependencies>org.spigotmc:spigot:${spigot.version}:jar:remapped-obf</remappedDependencies>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

PlayerOpSender1_19_1.java:

public class PlayerOpSender1_19_1 extends PlayerOpSender1_19_common ... {
    ...
    protected static class ServerPlayerOpWrapper extends PlayerOpSender1_19_common.ServerPlayerOpWrapper{
        ...
        @Override
        public CommandSourceStack createCommandSourceStack() {
            return OpSender1_19_common.modifyStack(super.createCommandSourceStack(), source);
        }
    }
}

After mapping:

PlayerOpSender1_19_common.java:

import net.minecraft.server.level.EntityPlayer;

public abstract class PlayerOpSender1_19_common ... {
    ...
    // ServerPlayer has become EntityPlayer
    protected abstract static class ServerPlayerOpWrapper extends EntityPlayer {
        ...
    }
    ...
}

PlayerOpSender1_19.java:

public class PlayerOpSender1_19 extends PlayerOpSender1_19_common ... {
    ...
    protected static class ServerPlayerOpWrapper extends PlayerOpSender1_19_common.ServerPlayerOpWrapper{
        ...
        // CommandSourceStack is now CommandListenerWrapper
        // createCommandSourceStack should have become cU
        @Override
        public CommandListenerWrapper createCommandSourceStack() {
            return OpSender1_19_common.modifyStack(super.createCommandSourceStack(), source);
        }
    }
}

PlayerOpSender1_19_1.java:

public class PlayerOpSender1_19_1 extends PlayerOpSender1_19_common ... {
    ...
    protected static class ServerPlayerOpWrapper extends PlayerOpSender1_19_common.ServerPlayerOpWrapper{
        ...
        // CommandSourceStack is now CommandListenerWrapper
        // createCommandSourceStack should have become cT
        @Override
        public CommandListenerWrapper createCommandSourceStack() {
            return OpSender1_19_common.modifyStack(super.createCommandSourceStack(), source);
        }
    }
}

I've set up special source to map PlayerOpSender1_19 with 1.19 mappings and PlayerOpSender1_19_1 with 1.19.1 mappings.

However, the method overrides for createCommandSourceStack aren't being mapped correctly. In 1.19 it should become cU, while in 1.19.1 is should become cT. Parts of the file are being remapped, such as CommandSourceStack becoming CommmandListenerWrapper, but the method override is not changing.

It seems that the way the classes are inherited is preventing special source from realizing it needs to change these methods. It might also have something to do with the way the classes are split up across maven modules.

@willkroboth willkroboth changed the title Method override is not being remapped for sub-subclass Method override is not being remapped for sub-subclass in different module Aug 13, 2022
@willkroboth willkroboth changed the title Method override is not being remapped for sub-subclass in different module Method override is not being remapped for subclasses in different modules Aug 13, 2022
@willkroboth
Copy link
Author

willkroboth commented Aug 13, 2022

I figured this out on my side by shading 1_19-common into 1_19 and 1_19_1. This seems to help special source realize that ServerPlayerOpWrapper extends ServerPlayer and it remaps the method override.

I'll leave this issue open for now because it seems that there is a problem where special source is not considering dependencies when finding classes and methods to remap. Doing it the shading way I found requires quite a bit of hacky finagling that really shouldn't happen.

willkroboth referenced this issue in willkroboth/ConfigCommands Aug 13, 2022
Special source wasn't remapping createCommandSourceStack() in ServerPlayerOpWrapper because it didn't know it extended ServerPlayer (See SpecialSource#83). This was fixed by shading 1_19-common into 1_19 and 1_19_1.

Maven was then complaining about 1_19-common and 1_19-common-mojang-mapped classes being included multiple times, so that was fixed by filtering them out of the shaded version of nms-dependency.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant