Initial NeoForge port

Gets into world with no other mods. Currently nukes a bunch of API calls.
This commit is contained in:
Jason Penilla
2024-08-04 17:01:05 -07:00
parent 4442452c52
commit f463fbeb23
15 changed files with 117 additions and 24 deletions

View File

@@ -77,11 +77,15 @@ public class TickThread extends Thread {
}
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;
}

View File

@@ -11,7 +11,7 @@ import java.util.concurrent.Executor;
@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;

View File

@@ -146,7 +146,7 @@ public abstract class DistanceManagerMixin implements ChunkSystemDistanceManager
* @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);
}
@@ -155,7 +155,7 @@ public abstract class DistanceManagerMixin implements ChunkSystemDistanceManager
* @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);
}

View File

@@ -233,7 +233,11 @@ public abstract class LevelMixin implements ChunkSystemLevel, ChunkSystemEntityG
* @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"

View File

@@ -178,6 +178,7 @@ public abstract class MinecraftServerMixin extends ReentrantBlockableEventLoop<T
* @reason Make server thread an instance of TickThread for thread checks
* @author Spottedleaf
*/
/* TODO NeoForge adds ThreadGroup
@Redirect(
method = "spin",
at = @At(
@@ -188,6 +189,22 @@ public abstract class MinecraftServerMixin extends ReentrantBlockableEventLoop<T
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);
}
/**

View File

@@ -11,7 +11,7 @@ import org.spongepowered.asm.mixin.Shadow;
@Mixin(ServerChunkCache.MainThreadExecutor.class)
public abstract class ServerChunkCache$MainThreadExecutorMixin extends BlockableEventLoop<Runnable> {
@Shadow
@Shadow(aliases = "this$0")
@Final
ServerChunkCache field_18810;

View File

@@ -17,6 +17,10 @@ import ca.spottedleaf.moonrise.patches.chunk_system.scheduling.ChunkTaskSchedule
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;
@@ -379,7 +383,10 @@ public abstract class ServerLevelMixin extends Level implements ChunkSystemServe
* @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"
@@ -447,7 +454,7 @@ public abstract class ServerLevelMixin extends Level implements ChunkSystemServe
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) {
@@ -685,15 +692,15 @@ public abstract class ServerLevelMixin extends Level implements ChunkSystemServe
* @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()));
}
/**

View File

@@ -16,6 +16,7 @@ import org.spongepowered.asm.mixin.Overwrite;
@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

View File

@@ -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",

View File

@@ -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;"

View File

@@ -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"