This commit is contained in:
dfsek
2021-11-17 16:28:40 -07:00
parent 172006f2f6
commit 3737e3510d
46 changed files with 133 additions and 152 deletions
@@ -2,10 +2,6 @@ package com.dfsek.terra.fabric;
import com.dfsek.tectonic.exception.LoadException;
import com.dfsek.tectonic.loading.TypeRegistry;
import com.dfsek.terra.fabric.generation.FabricChunkGeneratorWrapper;
import com.dfsek.terra.fabric.util.FabricUtil;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.Identifier;
@@ -14,16 +10,15 @@ import org.apache.logging.log4j.LogManager;
import java.io.File;
import java.util.HashSet;
import java.util.Optional;
import java.util.Set;
import com.dfsek.terra.AbstractPlatform;
import com.dfsek.terra.api.util.Logger;
import com.dfsek.terra.api.addon.TerraAddon;
import com.dfsek.terra.api.handle.ItemHandle;
import com.dfsek.terra.api.handle.WorldHandle;
import com.dfsek.terra.api.util.Logger;
import com.dfsek.terra.api.util.generic.Lazy;
import com.dfsek.terra.config.lang.LangUtil;
import com.dfsek.terra.fabric.generation.FabricChunkGeneratorWrapper;
import com.dfsek.terra.fabric.handle.FabricItemHandle;
import com.dfsek.terra.fabric.handle.FabricWorldHandle;
import com.dfsek.terra.fabric.util.ProtoBiome;
@@ -37,20 +32,20 @@ public class PlatformImpl extends AbstractPlatform {
private final Set<ServerWorld> worlds = new HashSet<>();
public void addWorld(ServerWorld world) {
worlds.add(world);
}
public PlatformImpl() {
load();
}
public void addWorld(ServerWorld world) {
worlds.add(world);
}
@Override
public boolean reload() {
getTerraConfig().load(this);
LangUtil.load(getTerraConfig().getLanguage(), this); // Load language.
boolean succeed = getRawConfigRegistry().loadAll(this);
worlds.forEach(world -> {
FabricChunkGeneratorWrapper chunkGeneratorWrapper = ((FabricChunkGeneratorWrapper) world.getChunkManager().getChunkGenerator());
chunkGeneratorWrapper.setPack(getConfigRegistry().get(chunkGeneratorWrapper.getPack().getID()));
@@ -60,9 +60,8 @@ public class FabricChunkGeneratorWrapper extends net.minecraft.world.gen.chunk.C
);
private final long seed;
private ChunkGenerator delegate;
private final TerraBiomeSource biomeSource;
private ChunkGenerator delegate;
private ConfigPack pack;
private ServerWorld world;
@@ -77,14 +76,6 @@ public class FabricChunkGeneratorWrapper extends net.minecraft.world.gen.chunk.C
this.seed = seed;
}
public void setPack(ConfigPack pack) {
this.pack = pack;
this.delegate = pack.getGeneratorProvider().newInstance(pack);
biomeSource.setPack(pack);
delegate.getPlatform().logger().info("Loading world with config pack " + pack.getID());
}
@Override
protected Codec<? extends net.minecraft.world.gen.chunk.ChunkGenerator> getCodec() {
return CODEC;
@@ -235,6 +226,14 @@ public class FabricChunkGeneratorWrapper extends net.minecraft.world.gen.chunk.C
return pack;
}
public void setPack(ConfigPack pack) {
this.pack = pack;
this.delegate = pack.getGeneratorProvider().newInstance(pack);
biomeSource.setPack(pack);
delegate.getPlatform().logger().info("Loading world with config pack " + pack.getID());
}
public void setWorld(ServerWorld world) {
this.world = world;
}
@@ -36,10 +36,6 @@ public class TerraBiomeSource extends BiomeSource {
private final long seed;
private ConfigPack pack;
public void setPack(ConfigPack pack) {
this.pack = pack;
}
public TerraBiomeSource(Registry<Biome> biomes, long seed, ConfigPack pack) {
super(biomes.stream()
.filter(biome -> Objects.requireNonNull(biomes.getId(biome))
@@ -51,6 +47,10 @@ public class TerraBiomeSource extends BiomeSource {
this.pack = pack;
}
public void setPack(ConfigPack pack) {
this.pack = pack;
}
@Override
protected Codec<? extends BiomeSource> getCodec() {
return CODEC;
@@ -18,6 +18,7 @@ public class ServerMainMixin {
"Lnet/minecraft/util/registry/DynamicRegistryManager$Impl;"))
private static void injectConstructor(String[] args, CallbackInfo ci) {
FabricEntryPoint.getPlatform().getEventManager().callEvent(
new PlatformInitializationEvent()); // Load during MinecraftServer construction, after other mods have registered blocks and stuff
new PlatformInitializationEvent()); // Load during MinecraftServer construction, after other mods have registered blocks
// and stuff
}
}