diff --git a/build.gradle b/build.gradle index bf7bb2a1..4cb26cff 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,8 @@ +import net.fabricmc.loom.task.RemapJarTask +import net.fabricmc.loom.util.aw2at.Aw2At + plugins { - id 'fabric-loom' version '1.7.3' + id("xyz.jpenilla.quiet-architectury-loom") version "1.7-SNAPSHOT" id 'maven-publish' id 'io.github.goooler.shadow' version '8.1.8' } @@ -30,6 +33,10 @@ repositories { includeModule("ca.spottedleaf", "concurrentutil") } } + maven { + name = 'NeoForged' + url = 'https://maven.neoforged.net/releases/' + } } configurations.implementation { @@ -39,7 +46,8 @@ configurations.implementation { dependencies { minecraft "com.mojang:minecraft:${project.minecraft_version}" mappings loom.officialMojangMappings() - modImplementation "net.fabricmc:fabric-loader:${project.loader_version}" + // modImplementation "net.fabricmc:fabric-loader:${project.loader_version}" + neoForge 'net.neoforged:neoforge:21.0.153' shadow('ca.spottedleaf:concurrentutil:0.0.1-SNAPSHOT') shadow('org.yaml:snakeyaml:2.2') @@ -48,7 +56,7 @@ dependencies { processResources { inputs.property "version", project.version - filesMatching("fabric.mod.json") { + filesMatching("META-INF/neoforge.mods.toml") { expand "version": project.version, "minecraft_version": minecraft_version, "loader_version": loader_version, "mod_version": mod_version } } @@ -89,9 +97,8 @@ jar { shadowJar { archiveClassifier = "dev-all" - destinationDirectory = layout.buildDirectory.dir("devlibs") + destinationDirectory = layout.buildDirectory.dir("libs") configurations = [project.configurations.shadow] - exclude("META-INF") relocate 'ca.spottedleaf.concurrentutil', 'ca.spottedleaf.moonrise.libs.ca.spottedleaf.concurrentutil' relocate 'org.yaml.snakeyaml', 'ca.spottedleaf.moonrise.libs.org.yaml.snakeyaml' } @@ -108,3 +115,4 @@ publishing { } } +Aw2At.setup(getProject(), tasks.remapJar) diff --git a/gradle.properties b/gradle.properties index 1f3dfd86..9fb0c9df 100644 --- a/gradle.properties +++ b/gradle.properties @@ -10,3 +10,5 @@ loader_version=0.15.11 mod_version=1.0.0 maven_group=ca.spottedleaf.moonrise archives_base_name=moonrise + +loom.platform=neoforge diff --git a/settings.gradle b/settings.gradle index 9050597e..94b92392 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,11 +1,24 @@ pluginManagement { repositories { + mavenCentral() + gradlePluginPortal() maven { name = 'Fabric' url = 'https://maven.fabricmc.net/' } - mavenCentral() - gradlePluginPortal() + maven { + name = 'NeoForged' + url = 'https://maven.neoforged.net/releases/' + } + maven { + name = 'jmp' + url = 'https://repo.jpenilla.xyz/snapshots' + mavenContent { snapshotsOnly() } + } + maven { + name = 'architectury' + url = 'https://maven.architectury.dev/' + } } } diff --git a/src/main/java/ca/spottedleaf/moonrise/common/util/TickThread.java b/src/main/java/ca/spottedleaf/moonrise/common/util/TickThread.java index 11b7f157..b0960203 100644 --- a/src/main/java/ca/spottedleaf/moonrise/common/util/TickThread.java +++ b/src/main/java/ca/spottedleaf/moonrise/common/util/TickThread.java @@ -77,11 +77,15 @@ public TickThread(final String name) { } public TickThread(final Runnable run, final String name) { - this(run, name, ID_GENERATOR.incrementAndGet()); + this(run, name, null); } - private TickThread(final Runnable run, final String name, final int id) { - super(run, name); + public TickThread(final Runnable run, final String name, final ThreadGroup group) { + this(run, name, group, ID_GENERATOR.incrementAndGet()); + } + + private TickThread(final Runnable run, final String name, final ThreadGroup group, final int id) { + super(group, run, name); this.id = id; } diff --git a/src/main/java/ca/spottedleaf/moonrise/mixin/chunk_system/ChunkMap$DistanceManagerMixin.java b/src/main/java/ca/spottedleaf/moonrise/mixin/chunk_system/ChunkMap$DistanceManagerMixin.java index db4d1afa..7b1a2d63 100644 --- a/src/main/java/ca/spottedleaf/moonrise/mixin/chunk_system/ChunkMap$DistanceManagerMixin.java +++ b/src/main/java/ca/spottedleaf/moonrise/mixin/chunk_system/ChunkMap$DistanceManagerMixin.java @@ -11,7 +11,7 @@ @Mixin(ChunkMap.DistanceManager.class) public abstract class ChunkMap$DistanceManagerMixin extends net.minecraft.server.level.DistanceManager implements ChunkSystemDistanceManager { - @Shadow + @Shadow(aliases = "this$0") @Final ChunkMap field_17443; diff --git a/src/main/java/ca/spottedleaf/moonrise/mixin/chunk_system/DistanceManagerMixin.java b/src/main/java/ca/spottedleaf/moonrise/mixin/chunk_system/DistanceManagerMixin.java index af78d2a5..1905a5cc 100644 --- a/src/main/java/ca/spottedleaf/moonrise/mixin/chunk_system/DistanceManagerMixin.java +++ b/src/main/java/ca/spottedleaf/moonrise/mixin/chunk_system/DistanceManagerMixin.java @@ -146,7 +146,7 @@ public void removeTicket(final long pos, final Ticket ticket) { * @author Spottedleaf */ @Overwrite - public void addRegionTicket(final TicketType type, final ChunkPos pos, final int radius, final T identifier) { + public void addRegionTicket(final TicketType type, final ChunkPos pos, final int radius, final T identifier, boolean forceTicks) { // TODO: Neo added param this.getChunkHolderManager().addTicketAtLevel(type, pos, ChunkLevel.byStatus(FullChunkStatus.FULL) - radius, identifier); } @@ -155,7 +155,7 @@ public void addRegionTicket(final TicketType type, final ChunkPos pos, fi * @author Spottedleaf */ @Overwrite - public void removeRegionTicket(final TicketType type, final ChunkPos pos, final int radius, final T identifier) { + public void removeRegionTicket(final TicketType type, final ChunkPos pos, final int radius, final T identifier, boolean forceTicks) { // TODO: Neo added param this.getChunkHolderManager().removeTicketAtLevel(type, pos, ChunkLevel.byStatus(FullChunkStatus.FULL) - radius, identifier); } diff --git a/src/main/java/ca/spottedleaf/moonrise/mixin/chunk_system/LevelMixin.java b/src/main/java/ca/spottedleaf/moonrise/mixin/chunk_system/LevelMixin.java index 36e6511a..e191acaf 100644 --- a/src/main/java/ca/spottedleaf/moonrise/mixin/chunk_system/LevelMixin.java +++ b/src/main/java/ca/spottedleaf/moonrise/mixin/chunk_system/LevelMixin.java @@ -233,7 +233,11 @@ public BlockPos getHeightmapPos(Heightmap.Types types, BlockPos blockPos) { * @author Spottedleaf */ @Redirect( - method = "setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;II)Z", + method = { + "setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;II)Z", + // NeoForge splits logic from the original method into this one + "markAndNotifyBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/chunk/LevelChunk;Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/level/block/state/BlockState;II)V" + }, at = @At( value = "INVOKE", target = "Lnet/minecraft/server/level/FullChunkStatus;isOrAfter(Lnet/minecraft/server/level/FullChunkStatus;)Z" diff --git a/src/main/java/ca/spottedleaf/moonrise/mixin/chunk_system/MinecraftServerMixin.java b/src/main/java/ca/spottedleaf/moonrise/mixin/chunk_system/MinecraftServerMixin.java index cea99780..d198c676 100644 --- a/src/main/java/ca/spottedleaf/moonrise/mixin/chunk_system/MinecraftServerMixin.java +++ b/src/main/java/ca/spottedleaf/moonrise/mixin/chunk_system/MinecraftServerMixin.java @@ -190,6 +190,7 @@ private static void initHook(Function function, CallbackInfoRetur * @reason Make server thread an instance of TickThread for thread checks * @author Spottedleaf */ + /* TODO NeoForge adds ThreadGroup @Redirect( method = "spin", at = @At( @@ -200,6 +201,22 @@ private static void initHook(Function function, CallbackInfoRetur private static Thread createTickThread(final Runnable target, final String name) { return new TickThread(target, name); } + */ + + /** + * @reason Make server thread an instance of TickThread for thread checks + * @author Spottedleaf + */ + @Redirect( + method = "spin", + at = @At( + value = "NEW", + target = "(Ljava/lang/ThreadGroup;Ljava/lang/Runnable;Ljava/lang/String;)Ljava/lang/Thread;" + ) + ) + private static Thread createTickThreadNeo(final ThreadGroup group, final Runnable task, final String name) { + return new TickThread(task, name, group); + } /** diff --git a/src/main/java/ca/spottedleaf/moonrise/mixin/chunk_system/ServerChunkCache$MainThreadExecutorMixin.java b/src/main/java/ca/spottedleaf/moonrise/mixin/chunk_system/ServerChunkCache$MainThreadExecutorMixin.java index b0fd6507..9357ba70 100644 --- a/src/main/java/ca/spottedleaf/moonrise/mixin/chunk_system/ServerChunkCache$MainThreadExecutorMixin.java +++ b/src/main/java/ca/spottedleaf/moonrise/mixin/chunk_system/ServerChunkCache$MainThreadExecutorMixin.java @@ -11,7 +11,7 @@ @Mixin(ServerChunkCache.MainThreadExecutor.class) public abstract class ServerChunkCache$MainThreadExecutorMixin extends BlockableEventLoop { - @Shadow + @Shadow(aliases = "this$0") @Final ServerChunkCache field_18810; diff --git a/src/main/java/ca/spottedleaf/moonrise/mixin/chunk_system/ServerLevelMixin.java b/src/main/java/ca/spottedleaf/moonrise/mixin/chunk_system/ServerLevelMixin.java index 4de7bfad..db92dbf9 100644 --- a/src/main/java/ca/spottedleaf/moonrise/mixin/chunk_system/ServerLevelMixin.java +++ b/src/main/java/ca/spottedleaf/moonrise/mixin/chunk_system/ServerLevelMixin.java @@ -18,6 +18,10 @@ import ca.spottedleaf.moonrise.patches.chunk_system.scheduling.NewChunkHolder; import ca.spottedleaf.moonrise.patches.chunk_system.scheduling.ThreadedTicketLevelPropagator; import ca.spottedleaf.moonrise.patches.chunk_system.server.ChunkSystemMinecraftServer; +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; +import net.minecraft.CrashReportCategory; +import net.minecraft.CrashReportDetail; import net.minecraft.core.BlockPos; import net.minecraft.core.Holder; import net.minecraft.core.RegistryAccess; @@ -34,7 +38,6 @@ import net.minecraft.world.level.ChunkPos; import net.minecraft.world.level.CustomSpawner; import net.minecraft.world.level.Level; -import net.minecraft.world.level.LevelAccessor; import net.minecraft.world.level.WorldGenLevel; import net.minecraft.world.level.chunk.ChunkAccess; import net.minecraft.world.level.chunk.LevelChunk; @@ -378,7 +381,10 @@ public LevelChunk getChunk(final int x, final int z) { * @author Spottedleaf */ @Redirect( - method = "method_31420", + method = { + "method_31420", + "*(Lnet/minecraft/world/TickRateManager;Lnet/minecraft/util/profiling/ProfilerFiller;Lnet/minecraft/world/entity/Entity;)V" + }, at = @At( value = "INVOKE", target = "Lnet/minecraft/server/level/DistanceManager;inEntityTickingRange(J)Z" @@ -446,7 +452,7 @@ private void redirectAutoSave(final PersistentEntitySectionManager insta method = "addPlayer", at = @At( value = "INVOKE", - target = "Lnet/minecraft/world/level/entity/PersistentEntitySectionManager;addNewEntity(Lnet/minecraft/world/level/entity/EntityAccess;)Z" + target = "Lnet/minecraft/world/level/entity/PersistentEntitySectionManager;*(Lnet/minecraft/world/level/entity/EntityAccess;)Z" ) ) private boolean redirectAddPlayerEntity(final PersistentEntitySectionManager instance, final T entity) { @@ -684,15 +690,15 @@ public boolean isNaturalSpawningAllowed(final ChunkPos pos) { * @reason Redirect to new entity manager * @author Spottedleaf */ - @Redirect( - method = "method_54438", + @WrapOperation( + method = "fillReportDetails", at = @At( value = "INVOKE", - target = "Lnet/minecraft/world/level/entity/PersistentEntitySectionManager;count()I" + target = "Lnet/minecraft/CrashReportCategory;setDetail(Ljava/lang/String;Lnet/minecraft/CrashReportDetail;)Lnet/minecraft/CrashReportCategory;" ) ) - private int redirectCrashCount(final PersistentEntitySectionManager instance) { - return this.moonrise$getEntityLookup().getEntityCount(); + private CrashReportCategory redirectCrashCount(final CrashReportCategory instance, final String s, final CrashReportDetail string, final Operation original) { + return original.call(instance, s, (CrashReportDetail) () -> String.valueOf(this.moonrise$getEntityLookup().getEntityCount())); } /** diff --git a/src/main/java/ca/spottedleaf/moonrise/mixin/farm_block/FarmBlockMixin.java b/src/main/java/ca/spottedleaf/moonrise/mixin/farm_block/FarmBlockMixin.java index 5f87ca0d..c7dce607 100644 --- a/src/main/java/ca/spottedleaf/moonrise/mixin/farm_block/FarmBlockMixin.java +++ b/src/main/java/ca/spottedleaf/moonrise/mixin/farm_block/FarmBlockMixin.java @@ -16,6 +16,7 @@ @Mixin(FarmBlock.class) public abstract class FarmBlockMixin { + // TODO: NeoForge - APIs this method calls require a BlockPos, so is there much advantage to not using betweenClosed anymore? /** * @reason Avoid usage of betweenClosed, this can become very hot when * there are significant numbers of farm blocks in the world diff --git a/src/main/java/ca/spottedleaf/moonrise/mixin/poi_lookup/AcquirePoiMixin.java b/src/main/java/ca/spottedleaf/moonrise/mixin/poi_lookup/AcquirePoiMixin.java index 9ca3e4ef..7a3ed941 100644 --- a/src/main/java/ca/spottedleaf/moonrise/mixin/poi_lookup/AcquirePoiMixin.java +++ b/src/main/java/ca/spottedleaf/moonrise/mixin/poi_lookup/AcquirePoiMixin.java @@ -23,7 +23,10 @@ public abstract class AcquirePoiMixin { * @author Spottedleaf */ @Redirect( - method = "method_46885", + method = { + "method_46885", + "*(ZLorg/apache/commons/lang3/mutable/MutableLong;Lit/unimi/dsi/fastutil/longs/Long2ObjectMap;Ljava/util/function/Predicate;Lnet/minecraft/world/entity/ai/behavior/declarative/MemoryAccessor;Ljava/util/Optional;Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/world/entity/PathfinderMob;J)Z" + }, at = @At( target = "Lnet/minecraft/world/entity/ai/village/poi/PoiManager;findAllClosestFirstWithType(Ljava/util/function/Predicate;Ljava/util/function/Predicate;Lnet/minecraft/core/BlockPos;ILnet/minecraft/world/entity/ai/village/poi/PoiManager$Occupancy;)Ljava/util/stream/Stream;", value = "INVOKE", diff --git a/src/main/java/ca/spottedleaf/moonrise/mixin/serverlist/ServerAddressResolverMixin.java b/src/main/java/ca/spottedleaf/moonrise/mixin/serverlist/ServerAddressResolverMixin.java index fa630bae..0a7433a2 100644 --- a/src/main/java/ca/spottedleaf/moonrise/mixin/serverlist/ServerAddressResolverMixin.java +++ b/src/main/java/ca/spottedleaf/moonrise/mixin/serverlist/ServerAddressResolverMixin.java @@ -18,7 +18,10 @@ public interface ServerAddressResolverMixin { * @author Spottedleaf */ @Redirect( - method = "method_36903", + method = { + "method_36903", + "*(Lnet/minecraft/client/multiplayer/resolver/ServerAddress;)Ljava/util/Optional;" + }, at = @At( value = "INVOKE", target = "Ljava/net/InetAddress;getByName(Ljava/lang/String;)Ljava/net/InetAddress;" diff --git a/src/main/resources/META-INF/neoforge.mods.toml b/src/main/resources/META-INF/neoforge.mods.toml new file mode 100644 index 00000000..ea76a652 --- /dev/null +++ b/src/main/resources/META-INF/neoforge.mods.toml @@ -0,0 +1,31 @@ +modLoader = "javafml" +loaderVersion = "[1,)" +license = "GPLv3" +issueTrackerURL = "https://github.com/Tuinity/Moonrise" +showAsResourcePack = false + +[[mods]] +modId = "moonrise" +version = "${version}" +displayName = "Moonrise" +displayURL = "https://github.com/Tuinity/Moonrise" +authors = "Spottedleaf" +description = "Moonrise NeoForge" +displayTest = "IGNORE_ALL_VERSION" + +[[dependencies.moonrise]] +modId = "neoforge" +type = "required" +versionRange = "[21.0,)" +ordering = "NONE" +side = "BOTH" + +[[dependencies.moonrise]] +modId = "minecraft" +type = "required" +versionRange = "[1.21,1.22)" +ordering = "NONE" +side = "BOTH" + +[[mixins]] +config = "moonrise.mixins.json" diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json.disabled similarity index 100% rename from src/main/resources/fabric.mod.json rename to src/main/resources/fabric.mod.json.disabled