remove static world registration

This commit is contained in:
dfsek
2022-03-23 21:44:54 -07:00
parent f16bd6cc61
commit 0529a5017e
3 changed files with 8 additions and 75 deletions

View File

@@ -62,16 +62,10 @@ public class PlatformImpl extends AbstractPlatform {
private final WorldHandle worldHandle = new FabricWorldHandle();
private final Lazy<File> dataFolder = Lazy.lazy(() -> new File(FabricLoader.getInstance().getConfigDir().toFile(), "Terra"));
private final Set<ServerWorld> worlds = new HashSet<>();
public PlatformImpl() {
load();
}
public void addWorld(ServerWorld world) {
worlds.add(world);
}
private MinecraftServer server;
public void setServer(MinecraftServer server) {
@@ -90,16 +84,15 @@ public class PlatformImpl extends AbstractPlatform {
LOGGER.warn("Failed to execute reload", throwable);
return null;
}).join();
}
worlds.forEach(world -> {
FabricChunkGeneratorWrapper chunkGeneratorWrapper = ((FabricChunkGeneratorWrapper) world.getChunkManager().getChunkGenerator());
getConfigRegistry().get(chunkGeneratorWrapper.getPack().getRegistryKey()).ifPresent(pack -> {
chunkGeneratorWrapper.setPack(pack);
LOGGER.info("Replaced pack in chunk generator for world {}", world);
server.getWorlds().forEach(world -> {
if(world.getChunkManager().getChunkGenerator() instanceof FabricChunkGeneratorWrapper chunkGeneratorWrapper) {
getConfigRegistry().get(chunkGeneratorWrapper.getPack().getRegistryKey()).ifPresent(pack -> {
chunkGeneratorWrapper.setPack(pack);
LOGGER.info("Replaced pack in chunk generator for world {}", world);
});
}
});
});
}
return succeed;
}

View File

@@ -1,59 +0,0 @@
/*
* This file is part of Terra.
*
* Terra is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Terra is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
*/
package com.dfsek.terra.fabric.mixin;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.WorldGenerationProgressListener;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.registry.RegistryEntry;
import net.minecraft.util.registry.RegistryKey;
import net.minecraft.world.World;
import net.minecraft.world.dimension.DimensionType;
import net.minecraft.world.gen.chunk.ChunkGenerator;
import net.minecraft.world.level.ServerWorldProperties;
import net.minecraft.world.level.storage.LevelStorage;
import net.minecraft.world.spawner.Spawner;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import java.util.List;
import java.util.concurrent.Executor;
import com.dfsek.terra.fabric.FabricEntryPoint;
import com.dfsek.terra.fabric.generation.FabricChunkGeneratorWrapper;
@Mixin(ServerWorld.class)
public abstract class ServerWorldMixin {
private static final Logger logger = LoggerFactory.getLogger(ServerWorld.class);
@Inject(method = "<init>", at = @At("RETURN"))
public void injectConstructor(MinecraftServer server, Executor workerExecutor, LevelStorage.Session session,
ServerWorldProperties properties, RegistryKey<World> worldKey, RegistryEntry<DimensionType> registryEntry,
WorldGenerationProgressListener worldGenerationProgressListener, ChunkGenerator chunkGenerator,
boolean debugWorld, long seed, List<Spawner> spawners, boolean shouldTickTime, CallbackInfo ci) {
if(chunkGenerator instanceof FabricChunkGeneratorWrapper) {
FabricEntryPoint.getPlatform().addWorld((ServerWorld) (Object) this);
logger.info("Registered world {}", this);
}
}
}

View File

@@ -4,7 +4,6 @@
"package": "com.dfsek.terra.fabric.mixin",
"compatibilityLevel": "JAVA_16",
"mixins": [
"ServerWorldMixin",
"access.BiomeEffectsAccessor",
"access.MobSpawnerLogicAccessor",
"access.StateAccessor",