Skip to content

Commit

Permalink
fix: Fix references and remove server world chunk manager enabled con…
Browse files Browse the repository at this point in the history
…fig option
  • Loading branch information
Steveplays28 committed Jul 16, 2024
1 parent 7948b0d commit 958e969
Show file tree
Hide file tree
Showing 24 changed files with 66 additions and 53 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//file:noinspection GroovyAccessibility
//file:noinspection GroovyAssignabilityCheck
//file:noinspection DependencyNotationArgument

plugins {
id "architectury-plugin" version "${architectury_plugin_version}"
Expand Down
1 change: 1 addition & 0 deletions common/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//file:noinspection GroovyAccessibility
//file:noinspection GroovyAssignabilityCheck
//file:noinspection DependencyNotationArgument

architectury {
common(rootProject.enabled_platforms.split(","))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.github.steveplays28.noisiumchunkmanager;

import io.github.steveplays28.noisiumchunkmanager.server.NoisiumChunkManagerServerInitialiser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -11,6 +12,6 @@ public class NoisiumChunkManager {
public static void initialize() {
LOGGER.info("Loading {}.", MOD_NAME);

io.github.steveplays28.noisiumchunkmanager.experimental.server.NoisiumChunkManagerServerInitialiser.initialise();
NoisiumChunkManagerServerInitialiser.initialise();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import dev.isxander.yacl3.config.v2.api.SerialEntry;
import dev.isxander.yacl3.config.v2.api.autogen.AutoGen;
import dev.isxander.yacl3.config.v2.api.autogen.IntField;
import dev.isxander.yacl3.config.v2.api.autogen.TickBox;
import dev.isxander.yacl3.config.v2.api.serializer.GsonConfigSerializerBuilder;
import io.github.steveplays28.noisiumchunkmanager.util.ModLoaderUtil;
import net.minecraft.util.Identifier;
Expand All @@ -23,10 +22,6 @@ public class NoisiumChunkManagerConfig {
private static final @NotNull String SERVER_CATEGORY = "server";
private static final @NotNull String SERVER_WORLD_CHUNK_MANAGER_GROUP = "serverWorldChunkManager";

@AutoGen(category = SERVER_CATEGORY, group = SERVER_WORLD_CHUNK_MANAGER_GROUP)
@SerialEntry(comment = "A re-implementation of the server world's chunk manager. Every world has its own chunk manager. After changing this option you MUST restart Minecraft.")
@TickBox
public boolean serverWorldChunkManagerEnabled = false;
@AutoGen(category = SERVER_CATEGORY, group = SERVER_WORLD_CHUNK_MANAGER_GROUP)
@SerialEntry(comment = "The amount of threads used by a server world's chunk manager. Every world has its own chunk manager, and thus its own threads. After changing this option you MUST restart the server.")
@IntField(min = 1, format = "%i threads")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.steveplays28.noisiumchunkmanager.experimental.extension.world.chunk;
package io.github.steveplays28.noisiumchunkmanager.extension.world.chunk;

import java.util.BitSet;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.github.steveplays28.noisiumchunkmanager.mixin.client.gui.hud;

import io.github.steveplays28.noisiumchunkmanager.extension.world.server.ServerWorldExtension;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.gui.hud.DebugHud;
Expand Down Expand Up @@ -34,7 +35,7 @@ public abstract class DebugHudMixin {
return;
}

@NotNull var noisiumServerWorldChunkManager = ((io.github.steveplays28.noisiumchunkmanager.experimental.extension.world.server.ServerWorldExtension) serverWorld).noisiumchunkmanager$getServerWorldChunkManager();
@NotNull var noisiumServerWorldChunkManager = ((ServerWorldExtension) serverWorld).noisiumchunkmanager$getServerWorldChunkManager();
if (!noisiumServerWorldChunkManager.isChunkLoaded(playerChunkPosition)) {
cir.setReturnValue(null);
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import com.mojang.authlib.GameProfile;
import io.github.steveplays28.noisiumchunkmanager.extension.world.server.ServerWorldExtension;
import io.github.steveplays28.noisiumchunkmanager.mixin.accessor.server.network.SpawnLocatingAccessor;
import io.github.steveplays28.noisiumchunkmanager.server.world.ServerWorldChunkManager;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerPlayerEntity;
Expand Down Expand Up @@ -37,13 +39,13 @@ public ServerPlayerEntityMixin(World world, BlockPos pos, float yaw, GameProfile

@WrapOperation(method = "<init>", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/network/ServerPlayerEntity;moveToSpawn(Lnet/minecraft/server/world/ServerWorld;)V"))
private void noisiumchunkmanager$moveToSpawnWrapGetChunkAsyncWhenComplete(@NotNull ServerPlayerEntity instance, @NotNull ServerWorld serverWorld, @NotNull Operation<Void> original) {
((io.github.steveplays28.noisiumchunkmanager.experimental.extension.world.server.ServerWorldExtension) serverWorld).noisiumchunkmanager$getServerWorldChunkManager().getChunkAsync(
((ServerWorldExtension) serverWorld).noisiumchunkmanager$getServerWorldChunkManager().getChunkAsync(
new ChunkPos(serverWorld.getSpawnPos())).whenComplete((worldChunk, throwable) -> original.call(instance, serverWorld));
}

/**
* @author Steveplays28
* @reason Wait for {@link net.minecraft.world.chunk.WorldChunk}s from the {@link ServerWorld}'s {@link io.github.steveplays28.noisiumchunkmanager.experimental.server.world.ServerWorldChunkManager} asynchronously.
* @reason Wait for {@link net.minecraft.world.chunk.WorldChunk}s from the {@link ServerWorld}'s {@link ServerWorldChunkManager} asynchronously.
*/
@Overwrite
private void moveToSpawn(@NotNull ServerWorld serverWorld) {
Expand Down Expand Up @@ -78,7 +80,7 @@ private void moveToSpawn(@NotNull ServerWorld serverWorld) {
int s = q / (worldSpawnRadius * 2 + 1);
var searchPositionX = worldSpawnBlockPosition.getX() + r - worldSpawnRadius;
var searchPositionZ = worldSpawnBlockPosition.getZ() + s - worldSpawnRadius;
((io.github.steveplays28.noisiumchunkmanager.experimental.extension.world.server.ServerWorldExtension) serverWorld).noisiumchunkmanager$getServerWorldChunkManager().getChunkAsync(
((ServerWorldExtension) serverWorld).noisiumchunkmanager$getServerWorldChunkManager().getChunkAsync(
new ChunkPos(searchPositionX, searchPositionZ)).whenComplete((worldChunk, throwable) -> {
@Nullable var overworldSpawnBlockPosition = SpawnLocatingAccessor.invokeFindOverworldSpawn(
serverWorld, searchPositionX, searchPositionZ);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.github.steveplays28.noisiumchunkmanager.mixin.server.network;

import io.github.steveplays28.noisiumchunkmanager.extension.world.server.ServerWorldExtension;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.server.network.SpawnLocating;
Expand All @@ -19,18 +20,18 @@ public class SpawnLocatingMixin {
// TODO: Change to an @Inject at HEAD
/**
* @author Steveplays28
* @reason
* @reason TODO
*/
@Overwrite
public static @Nullable BlockPos findOverworldSpawn(@NotNull ServerWorld serverWorld, int searchBlockPosX, int searchBlockPosZ) {
var noisiumServerWorldChunkManager = ((io.github.steveplays28.noisiumchunkmanager.experimental.extension.world.server.ServerWorldExtension) serverWorld).noisiumchunkmanager$getServerWorldChunkManager();
var noisiumServerWorldChunkManager = ((ServerWorldExtension) serverWorld).noisiumchunkmanager$getServerWorldChunkManager();
var chunkPosition = new ChunkPos(
ChunkSectionPos.getSectionCoord(searchBlockPosX), ChunkSectionPos.getSectionCoord(searchBlockPosZ));
if (!noisiumServerWorldChunkManager.isChunkLoaded(chunkPosition)) {
return null;
}

var chunk = ((io.github.steveplays28.noisiumchunkmanager.experimental.extension.world.server.ServerWorldExtension) serverWorld).noisiumchunkmanager$getServerWorldChunkManager().getChunk(chunkPosition);
var chunk = noisiumServerWorldChunkManager.getChunk(chunkPosition);
int i = serverWorld.getDimension().hasCeiling() ? serverWorld.getChunkManager().getChunkGenerator().getSpawnHeight(
serverWorld) : chunk.sampleHeightmap(Heightmap.Type.MOTION_BLOCKING, searchBlockPosX & 15, searchBlockPosZ & 15);
if (i < serverWorld.getBottomY()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package io.github.steveplays28.noisiumchunkmanager.mixin.server.world;

import com.mojang.datafixers.DataFixer;
import io.github.steveplays28.noisiumchunkmanager.experimental.util.world.chunk.networking.packet.PacketUtil;
import io.github.steveplays28.noisiumchunkmanager.extension.world.server.ServerWorldExtension;
import io.github.steveplays28.noisiumchunkmanager.server.world.ServerWorldChunkManager;
import io.github.steveplays28.noisiumchunkmanager.server.world.chunk.event.ServerChunkEvent;
import io.github.steveplays28.noisiumchunkmanager.server.world.event.ServerTickEvent;
import io.github.steveplays28.noisiumchunkmanager.util.world.chunk.networking.packet.PacketUtil;
import net.minecraft.entity.Entity;
import net.minecraft.network.packet.Packet;
import net.minecraft.network.packet.s2c.play.BlockUpdateS2CPacket;
Expand Down Expand Up @@ -40,7 +44,7 @@

/**
* {@link Mixin} into {@link ServerChunkManager}.
* This {@link Mixin} redirects all method calls from the {@link ServerWorld}'s {@link ServerChunkManager} to the {@link ServerWorld}'s {@link io.github.steveplays28.noisiumchunkmanager.experimental.server.world.ServerWorldChunkManager}.
* This {@link Mixin} redirects all method calls from the {@link ServerWorld}'s {@link ServerChunkManager} to the {@link ServerWorld}'s {@link ServerWorldChunkManager}.
*/
@Mixin(ServerChunkManager.class)
public abstract class ServerChunkManagerMixin {
Expand Down Expand Up @@ -80,7 +84,7 @@ public abstract class ServerChunkManagerMixin {

@Inject(method = "tick(Ljava/util/function/BooleanSupplier;Z)V", at = @At(value = "HEAD"), cancellable = true)
private void noisiumchunkmanager$stopServerChunkManagerFromTicking(@NotNull BooleanSupplier shouldKeepTicking, boolean tickChunks, @NotNull CallbackInfo ci) {
io.github.steveplays28.noisiumchunkmanager.experimental.server.world.event.ServerTickEvent.SERVER_ENTITY_MOVEMENT_TICK.invoker().onServerEntityMovementTick();
ServerTickEvent.SERVER_ENTITY_MOVEMENT_TICK.invoker().onServerEntityMovementTick();
ci.cancel();
}

Expand All @@ -92,7 +96,7 @@ public abstract class ServerChunkManagerMixin {
// TODO: Fix infinite loop
@Inject(method = "getChunk(IILnet/minecraft/world/chunk/ChunkStatus;Z)Lnet/minecraft/world/chunk/Chunk;", at = @At(value = "HEAD"), cancellable = true)
private void noisiumchunkmanager$getChunkFromNoisiumServerWorldChunkManager(int chunkX, int chunkZ, ChunkStatus leastStatus, boolean create, CallbackInfoReturnable<Chunk> cir) {
var noisiumServerWorldChunkManager = ((io.github.steveplays28.noisiumchunkmanager.experimental.extension.world.server.ServerWorldExtension) this.getWorld()).noisiumchunkmanager$getServerWorldChunkManager();
var noisiumServerWorldChunkManager = ((ServerWorldExtension) this.getWorld()).noisiumchunkmanager$getServerWorldChunkManager();
var chunkPosition = new ChunkPos(chunkX, chunkZ);
if (!noisiumServerWorldChunkManager.isChunkLoaded(chunkPosition)) {
cir.setReturnValue(noisiumServerWorldChunkManager.getIoWorldChunk(chunkPosition));
Expand All @@ -104,7 +108,7 @@ public abstract class ServerChunkManagerMixin {

@Inject(method = "getChunk(II)Lnet/minecraft/world/chunk/light/LightSourceView;", at = @At(value = "HEAD"), cancellable = true)
private void noisiumchunkmanager$getChunkFromNoisiumServerWorldChunkManager(int chunkX, int chunkZ, CallbackInfoReturnable<WorldChunk> cir) {
var noisiumServerWorldChunkManager = ((io.github.steveplays28.noisiumchunkmanager.experimental.extension.world.server.ServerWorldExtension) this.getWorld()).noisiumchunkmanager$getServerWorldChunkManager();
var noisiumServerWorldChunkManager = ((ServerWorldExtension) this.getWorld()).noisiumchunkmanager$getServerWorldChunkManager();
var chunkPosition = new ChunkPos(chunkX, chunkZ);
if (!noisiumServerWorldChunkManager.isChunkLoaded(chunkPosition)) {
cir.setReturnValue(noisiumServerWorldChunkManager.getIoWorldChunk(chunkPosition));
Expand All @@ -116,7 +120,7 @@ public abstract class ServerChunkManagerMixin {

@Inject(method = "getWorldChunk", at = @At(value = "HEAD"), cancellable = true)
private void noisiumchunkmanager$getWorldChunkFromNoisiumServerWorldChunkManager(int chunkX, int chunkZ, CallbackInfoReturnable<WorldChunk> cir) {
var noisiumServerWorldChunkManager = ((io.github.steveplays28.noisiumchunkmanager.experimental.extension.world.server.ServerWorldExtension) this.getWorld()).noisiumchunkmanager$getServerWorldChunkManager();
var noisiumServerWorldChunkManager = ((ServerWorldExtension) this.getWorld()).noisiumchunkmanager$getServerWorldChunkManager();
var chunkPosition = new ChunkPos(chunkX, chunkZ);
if (!noisiumServerWorldChunkManager.isChunkLoaded(chunkPosition)) {
cir.setReturnValue(noisiumServerWorldChunkManager.getIoWorldChunk(chunkPosition));
Expand Down Expand Up @@ -186,7 +190,7 @@ public abstract class ServerChunkManagerMixin {

@Inject(method = "onLightUpdate", at = @At(value = "HEAD"), cancellable = true)
private void noisiumchunkmanager$updateLightingViaNoisiumServerWorldChunkManager(LightType lightType, ChunkSectionPos chunkSectionPos, CallbackInfo ci) {
io.github.steveplays28.noisiumchunkmanager.experimental.server.world.chunk.event.ServerChunkEvent.LIGHT_UPDATE.invoker().onLightUpdate(lightType, chunkSectionPos);
ServerChunkEvent.LIGHT_UPDATE.invoker().onLightUpdate(lightType, chunkSectionPos);
ci.cancel();
}

Expand All @@ -197,7 +201,7 @@ public abstract class ServerChunkManagerMixin {

@Inject(method = "isChunkLoaded", at = @At(value = "HEAD"), cancellable = true)
private void noisiumchunkmanager$isChunkLoadedInNoisiumServerWorldChunkManager(int chunkX, int chunkZ, CallbackInfoReturnable<Boolean> cir) {
cir.setReturnValue(((io.github.steveplays28.noisiumchunkmanager.experimental.extension.world.server.ServerWorldExtension) this.getWorld()).noisiumchunkmanager$getServerWorldChunkManager().isChunkLoaded(
cir.setReturnValue(((ServerWorldExtension) this.getWorld()).noisiumchunkmanager$getServerWorldChunkManager().isChunkLoaded(
new ChunkPos(chunkX, chunkZ)));
}

Expand All @@ -213,12 +217,12 @@ public abstract class ServerChunkManagerMixin {

@Inject(method = "getNoiseConfig", at = @At(value = "HEAD"), cancellable = true)
private void noisiumchunkmanager$getNoiseConfigFromServerChunkManager(@NotNull CallbackInfoReturnable<NoiseConfig> cir) {
cir.setReturnValue(((io.github.steveplays28.noisiumchunkmanager.experimental.extension.world.server.ServerWorldExtension) this.getWorld()).noisiumchunkmanager$getNoiseConfig());
cir.setReturnValue(((ServerWorldExtension) this.getWorld()).noisiumchunkmanager$getNoiseConfig());
}

@Inject(method = "getChunkIoWorker", at = @At(value = "HEAD"), cancellable = true)
private void noisiumchunkmanager$getChunkIoWorkerFromNoisiumServerWorldChunkManager(@NotNull CallbackInfoReturnable<NbtScannable> cir) {
cir.setReturnValue(((io.github.steveplays28.noisiumchunkmanager.experimental.extension.world.server.ServerWorldExtension) this.getWorld()).noisiumchunkmanager$getServerWorldChunkManager().getChunkIoWorker());
cir.setReturnValue(((ServerWorldExtension) this.getWorld()).noisiumchunkmanager$getServerWorldChunkManager().getChunkIoWorker());
}

@Inject(method = {"getLoadedChunkCount", "getTotalChunksLoadedCount"}, at = @At(value = "HEAD"), cancellable = true)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.github.steveplays28.noisiumchunkmanager.mixin.server.world;

import io.github.steveplays28.noisiumchunkmanager.server.world.entity.event.ServerEntityEvent;
import net.minecraft.entity.Entity;
import net.minecraft.server.world.ServerEntityManager;
import net.minecraft.world.entity.EntityLike;
Expand All @@ -8,7 +9,6 @@
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import io.github.steveplays28.noisiumchunkmanager.experimental.server.world.entity.event.ServerEntityEvent;

@Mixin(value = ServerEntityManager.class, priority = 500)
public class ServerEntityManagerMixin<T extends EntityLike> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@ public abstract class ServerWorldMixin implements ServerWorldExtension {
/**
* Keeps a reference to this {@link ServerWorld}'s {@link ServerWorldEntityTracker}, to make sure it doesn't get garbage collected until the object is no longer necessary.
*/
@SuppressWarnings({"unused", "FieldCanBeLocal"})
@SuppressWarnings("unused")
@Unique
private ServerWorldEntityTracker noisiumchunkmanager$serverWorldEntityManager;
/**
* Keeps a reference to this {@link ServerWorld}'s {@link ServerWorldPlayerChunkLoader}, to make sure it doesn't get garbage collected until the object is no longer necessary.
*/
@SuppressWarnings({"unused", "FieldCanBeLocal"})
@SuppressWarnings("unused")
@Unique
private ServerWorldPlayerChunkLoader noisiumchunkmanager$serverWorldPlayerChunkLoader;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package io.github.steveplays28.noisiumchunkmanager.mixin.world.chunk;

import io.github.steveplays28.noisiumchunkmanager.extension.world.chunk.WorldChunkExtension;
import net.minecraft.world.chunk.WorldChunk;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;

import java.util.BitSet;

@Mixin(WorldChunk.class)
public class WorldChunkMixin implements io.github.steveplays28.noisiumchunkmanager.experimental.extension.world.chunk.WorldChunkExtension {
public class WorldChunkMixin implements WorldChunkExtension {
@Unique
private final BitSet noisiumchunkmanager$blockLightBits = new BitSet();
@Unique
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.github.steveplays28.noisiumchunkmanager.mixin.world.gen.chunk;

import io.github.steveplays28.noisiumchunkmanager.server.world.ServerWorldChunkManager;
import it.unimi.dsi.fastutil.ints.IntArraySet;
import it.unimi.dsi.fastutil.ints.IntSet;
import it.unimi.dsi.fastutil.objects.ObjectArraySet;
Expand Down Expand Up @@ -66,7 +67,7 @@ private static BlockBox getBlockBoxForChunk(Chunk chunk) {

/**
* Replaces {@link ChunkGenerator#addStructureReferences} with a simpler one, that only checks the center chunk, instead of iterating outwards.
* This fixes an infinite loop with {@link io.github.steveplays28.noisiumchunkmanager.experimental.server.world.ServerWorldChunkManager}.
* This fixes an infinite loop with {@link ServerWorldChunkManager}.
*/
@Inject(method = "addStructureReferences", at = @At(value = "HEAD"), cancellable = true)
public void noisiumchunkmanager$replaceAddStructureReferencesToFixAnInfiniteLoop(StructureWorldAccess world, StructureAccessor structureAccessor, Chunk chunk, CallbackInfo ci) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package io.github.steveplays28.noisiumchunkmanager.server;

import dev.architectury.event.events.common.LifecycleEvent;
import io.github.steveplays28.noisiumchunkmanager.server.player.ServerPlayerBlockUpdater;

public class NoisiumChunkManagerServerInitialiser {
/**
* Keeps a reference to the {@link io.github.steveplays28.noisiumchunkmanager.experimental.server.player.ServerPlayerBlockUpdater}, to make sure it doesn't get garbage collected until the object is no longer necessary.
* Keeps a reference to the {@link ServerPlayerBlockUpdater}, to make sure it doesn't get garbage collected until the object is no longer necessary.
*/
@SuppressWarnings("unused")
private static io.github.steveplays28.noisiumchunkmanager.experimental.server.player.ServerPlayerBlockUpdater serverPlayerBlockUpdater;
private static ServerPlayerBlockUpdater serverPlayerBlockUpdater;

public static void initialise() {
LifecycleEvent.SERVER_STARTED.register(instance -> serverPlayerBlockUpdater = new io.github.steveplays28.noisiumchunkmanager.experimental.server.player.ServerPlayerBlockUpdater());
LifecycleEvent.SERVER_STARTED.register(instance -> serverPlayerBlockUpdater = new ServerPlayerBlockUpdater());
LifecycleEvent.SERVER_STOPPING.register(instance -> serverPlayerBlockUpdater = null);
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package io.github.steveplays28.noisiumchunkmanager.experimental.server.player;
package io.github.steveplays28.noisiumchunkmanager.server.player;

import dev.architectury.event.EventResult;
import dev.architectury.event.events.common.BlockEvent;
import io.github.steveplays28.noisiumchunkmanager.experimental.util.world.chunk.ChunkUtil;
import io.github.steveplays28.noisiumchunkmanager.util.world.chunk.ChunkUtil;
import net.minecraft.block.Blocks;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.BlockPos;
Expand Down
Loading

0 comments on commit 958e969

Please sign in to comment.