Solved Need help with NMS in 1.17.1

Discussion in 'Spigot Plugin Development' started by Peepersoak, Jul 18, 2021.

  1. Hey,

    I have started playing around with nms, basically just creating my own npc with their own path finder goal.

    I have been seen a lot of tutorial on nms, and the weird part is that nms stands for net.minecraft.server but intellij is importing net.minecraft.world?

    Because of this, I can't build my project. It's throwing the "cannot access net.minecraft.world..."

    I think net.minecraft.world is not the correct import?

    As per the other thread, they suggest that installing the latest buildtools will fix the problem but unfortunately it did not fix it.

    Code (Text):
    <?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>

        <groupId>me.peepersoak</groupId>
        <artifactId>AdventureCraftCore</artifactId>
        <version>3.0</version>
        <packaging>jar</packaging>

        <name>AdventureCraftCore</name>

        <description>The main core plugin of AdventureCraft SMP Server</description>
        <properties>
            <java.version>1.8</java.version>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        </properties>

        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.8.1</version>
                    <configuration>
                        <source>${java.version}</source>
                        <target>${java.version}</target>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-shade-plugin</artifactId>
                    <version>3.2.4</version>
                    <executions>
                        <execution>
                            <phase>package</phase>
                            <goals>
                                <goal>shade</goal>
                            </goals>
                            <configuration>
                                <createDependencyReducedPom>false</createDependencyReducedPom>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
            <resources>
                <resource>
                    <directory>src/main/resources</directory>
                    <filtering>true</filtering>
                </resource>
            </resources>
        </build>

        <repositories>
            <repository>
                <id>spigotmc-repo</id>
                <url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
            </repository>
            <repository>
                <id>sonatype</id>
                <url>https://oss.sonatype.org/content/groups/public/</url>
            </repository>
        </repositories>

        <dependencies>
            <dependency>
                <groupId>org.spigotmc</groupId>
                <artifactId>spigot</artifactId>
                <version>1.17-R0.1-SNAPSHOT</version>
                <scope>provided</scope>
            </dependency>
        </dependencies>
    </project>

    Code (Text):
    package me.peepersoak.adventurecraftcore.protocol;

    import net.minecraft.server.level.EntityPlayer;
    import net.minecraft.world.entity.EntityTypes;
    import net.minecraft.world.entity.ai.goal.PathfinderGoalRandomStroll;
    import net.minecraft.world.entity.ai.goal.target.PathfinderGoalNearestAttackableTarget;
    import net.minecraft.world.entity.npc.EntityVillager;

    import org.bukkit.Location;
    import org.bukkit.craftbukkit.v1_17_R1.CraftWorld;

    public class Sukuna extends EntityVillager {

        public Sukuna(Location loc) {
            super(EntityTypes.aV, ((CraftWorld) loc.getWorld()).getHandle());
            this.setPosition(loc.getX(), loc.getY(), loc.getZ());
            this.bP.a(new PathfinderGoalRandomStroll(this, 0.8D));
            this.bP.a(new PathfinderGoalNearestAttackableTarget<EntityPlayer>(this, EntityPlayer.class, false));
        }
    }

    Basically, I'm trying to spawn a villager that will attack the nearest player.

    Screen Shot of the error
    https://prnt.sc/1cqvtax

    I just started using maven for about a month therefore I just have few knowledge about it.

    Thank you in advance


    EDIT:

    FIXED!!
    The problem was that IntelliJ is actually trying to build my project using 1.8, changing this via POM won't actually fix it because I still need to change it in the actual settings. I finally manage to build it.
     
    #1 Peepersoak, Jul 18, 2021
    Last edited: Jul 18, 2021
  2. Package name of 1.17+ have changed for a better comprehension. Before it was something like "net.minecraft.server.v1_16_R1.EntityTypes" but in 1.17 it's "net.minecraft.world.entity.EntityTypes". You can compile buildtools and check the differences to see by your eyes, bu you're not wrong with those package ! (Well "NMS" is not NMS anymore, since it's not "net.minecraft.server" only ahah)

    All details about the mojang mapping and the spigot policy about 1.17 :
    https://www.spigotmc.org/threads/spigot-bungeecord-1-17-1-17-1.510208/