Skip to content

Commit

Permalink
Initial NeoForge port
Browse files Browse the repository at this point in the history
Gets into world with no other mods. Currently nukes a bunch of API calls.
  • Loading branch information
jpenilla committed Aug 5, 2024
1 parent 6a2c6d2 commit dd4b03e
Show file tree
Hide file tree
Showing 15 changed files with 117 additions and 25 deletions.
18 changes: 13 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -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'
}
Expand Down Expand Up @@ -30,6 +33,10 @@ repositories {
includeModule("ca.spottedleaf", "concurrentutil")
}
}
maven {
name = 'NeoForged'
url = 'https://maven.neoforged.net/releases/'
}
}

configurations.implementation {
Expand All @@ -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')
Expand All @@ -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
}
}
Expand Down Expand Up @@ -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'
}
Expand All @@ -108,3 +115,4 @@ publishing {
}
}

Aw2At.setup(getProject(), tasks.remapJar)
2 changes: 2 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
17 changes: 15 additions & 2 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -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/'
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public void removeTicket(final long pos, final Ticket<?> ticket) {
* @author Spottedleaf
*/
@Overwrite
public <T> void addRegionTicket(final TicketType<T> type, final ChunkPos pos, final int radius, final T identifier) {
public <T> void addRegionTicket(final TicketType<T> 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);
}

Expand All @@ -155,7 +155,7 @@ public <T> void addRegionTicket(final TicketType<T> type, final ChunkPos pos, fi
* @author Spottedleaf
*/
@Overwrite
public <T> void removeRegionTicket(final TicketType<T> type, final ChunkPos pos, final int radius, final T identifier) {
public <T> void removeRegionTicket(final TicketType<T> 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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ private static <S> void initHook(Function<Thread, S> function, CallbackInfoRetur
* @reason Make server thread an instance of TickThread for thread checks
* @author Spottedleaf
*/
/* TODO NeoForge adds ThreadGroup
@Redirect(
method = "spin",
at = @At(
Expand All @@ -200,6 +201,22 @@ private static <S> void initHook(Function<Thread, S> 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);
}


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
@Mixin(ServerChunkCache.MainThreadExecutor.class)
public abstract class ServerChunkCache$MainThreadExecutorMixin extends BlockableEventLoop<Runnable> {

@Shadow
@Shadow(aliases = "this$0")
@Final
ServerChunkCache field_18810;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -446,7 +452,7 @@ private void redirectAutoSave(final PersistentEntitySectionManager<Entity> 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 <T extends EntityAccess> boolean redirectAddPlayerEntity(final PersistentEntitySectionManager<T> instance, final T entity) {
Expand Down Expand Up @@ -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<Entity> instance) {
return this.moonrise$getEntityLookup().getEntityCount();
private CrashReportCategory redirectCrashCount(final CrashReportCategory instance, final String s, final CrashReportDetail<String> string, final Operation<CrashReportCategory> original) {
return original.call(instance, s, (CrashReportDetail<String>) () -> String.valueOf(this.moonrise$getEntityLookup().getEntityCount()));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;"
Expand Down
31 changes: 31 additions & 0 deletions src/main/resources/META-INF/neoforge.mods.toml
Original file line number Diff line number Diff line change
@@ -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"
File renamed without changes.

0 comments on commit dd4b03e

Please sign in to comment.