mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-06-15 21:31:05 +00:00
use dimensiontype to get world
This commit is contained in:
@@ -26,6 +26,7 @@ import com.dfsek.terra.api.registry.CheckedRegistry;
|
|||||||
import com.dfsek.terra.api.registry.LockedRegistry;
|
import com.dfsek.terra.api.registry.LockedRegistry;
|
||||||
import com.dfsek.terra.api.transform.Transformer;
|
import com.dfsek.terra.api.transform.Transformer;
|
||||||
import com.dfsek.terra.api.transform.Validator;
|
import com.dfsek.terra.api.transform.Validator;
|
||||||
|
import com.dfsek.terra.api.util.generic.pair.Pair;
|
||||||
import com.dfsek.terra.api.util.logging.DebugLogger;
|
import com.dfsek.terra.api.util.logging.DebugLogger;
|
||||||
import com.dfsek.terra.api.util.logging.Logger;
|
import com.dfsek.terra.api.util.logging.Logger;
|
||||||
import com.dfsek.terra.commands.CommandUtil;
|
import com.dfsek.terra.commands.CommandUtil;
|
||||||
@@ -49,6 +50,7 @@ import com.dfsek.terra.registry.master.ConfigRegistry;
|
|||||||
import com.dfsek.terra.world.TerraWorld;
|
import com.dfsek.terra.world.TerraWorld;
|
||||||
import net.fabricmc.api.ModInitializer;
|
import net.fabricmc.api.ModInitializer;
|
||||||
import net.fabricmc.loader.api.FabricLoader;
|
import net.fabricmc.loader.api.FabricLoader;
|
||||||
|
import net.minecraft.server.world.ServerWorld;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
import net.minecraft.util.registry.BuiltinRegistries;
|
import net.minecraft.util.registry.BuiltinRegistries;
|
||||||
import net.minecraft.util.registry.Registry;
|
import net.minecraft.util.registry.Registry;
|
||||||
@@ -77,7 +79,12 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer {
|
|||||||
public static final PopulatorFeature POPULATOR_FEATURE = new PopulatorFeature(DefaultFeatureConfig.CODEC);
|
public static final PopulatorFeature POPULATOR_FEATURE = new PopulatorFeature(DefaultFeatureConfig.CODEC);
|
||||||
public static final ConfiguredFeature<?, ?> POPULATOR_CONFIGURED_FEATURE = POPULATOR_FEATURE.configure(FeatureConfig.DEFAULT).decorate(Decorator.NOPE.configure(NopeDecoratorConfig.INSTANCE));
|
public static final ConfiguredFeature<?, ?> POPULATOR_CONFIGURED_FEATURE = POPULATOR_FEATURE.configure(FeatureConfig.DEFAULT).decorate(Decorator.NOPE.configure(NopeDecoratorConfig.INSTANCE));
|
||||||
private static TerraFabricPlugin instance;
|
private static TerraFabricPlugin instance;
|
||||||
private final Map<DimensionType, TerraWorld> worldMap = new HashMap<>();
|
private final Map<DimensionType, Pair<ServerWorld, TerraWorld>> worldMap = new HashMap<>();
|
||||||
|
|
||||||
|
public Map<DimensionType, Pair<ServerWorld, TerraWorld>> getWorldMap() {
|
||||||
|
return worldMap;
|
||||||
|
}
|
||||||
|
|
||||||
private final EventManager eventManager = new TerraEventManager(this);
|
private final EventManager eventManager = new TerraEventManager(this);
|
||||||
private final GenericLoaders genericLoaders = new GenericLoaders(this);
|
private final GenericLoaders genericLoaders = new GenericLoaders(this);
|
||||||
|
|
||||||
@@ -133,14 +140,11 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TerraWorld getWorld(World world) {
|
public TerraWorld getWorld(World world) {
|
||||||
return worldMap.computeIfAbsent(((WorldAccess) world).getDimension(), w -> {
|
return getWorld(((WorldAccess) world).getDimension());
|
||||||
logger.info("Loading world " + w);
|
|
||||||
return new TerraWorld(world, ((FabricChunkGeneratorWrapper) world.getGenerator()).getPack(), this);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public TerraWorld getWorld(DimensionType type) {
|
public TerraWorld getWorld(DimensionType type) {
|
||||||
TerraWorld world = worldMap.get(type);
|
TerraWorld world = worldMap.get(type).getRight();
|
||||||
if(world == null) throw new IllegalArgumentException("No world exists with dimension type " + type);
|
if(world == null) throw new IllegalArgumentException("No world exists with dimension type " + type);
|
||||||
return world;
|
return world;
|
||||||
}
|
}
|
||||||
@@ -185,14 +189,11 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer {
|
|||||||
config.load(this);
|
config.load(this);
|
||||||
LangUtil.load(config.getLanguage(), this); // Load language.
|
LangUtil.load(config.getLanguage(), this); // Load language.
|
||||||
boolean succeed = registry.loadAll(this);
|
boolean succeed = registry.loadAll(this);
|
||||||
Map<DimensionType, TerraWorld> newMap = new HashMap<>();
|
worldMap.forEach((seed, pair) -> {
|
||||||
worldMap.forEach((seed, tw) -> {
|
pair.getRight().getConfig().getSamplerCache().clear();
|
||||||
tw.getConfig().getSamplerCache().clear();
|
String packID = pair.getRight().getConfig().getTemplate().getID();
|
||||||
String packID = tw.getConfig().getTemplate().getID();
|
pair.setRight(new TerraWorld(pair.getRight().getWorld(), registry.get(packID), this));
|
||||||
newMap.put(seed, new TerraWorld(tw.getWorld(), registry.get(packID), this));
|
|
||||||
});
|
});
|
||||||
worldMap.clear();
|
|
||||||
worldMap.putAll(newMap);
|
|
||||||
return succeed;
|
return succeed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
package com.dfsek.terra.fabric.mixin;
|
||||||
|
|
||||||
|
import com.dfsek.terra.api.util.generic.pair.Pair;
|
||||||
|
import com.dfsek.terra.fabric.TerraFabricPlugin;
|
||||||
|
import com.dfsek.terra.fabric.generation.FabricChunkGeneratorWrapper;
|
||||||
|
import com.dfsek.terra.world.TerraWorld;
|
||||||
|
import net.minecraft.server.MinecraftServer;
|
||||||
|
import net.minecraft.server.WorldGenerationProgressListener;
|
||||||
|
import net.minecraft.server.world.ServerWorld;
|
||||||
|
import net.minecraft.util.registry.RegistryKey;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
import net.minecraft.world.dimension.DimensionType;
|
||||||
|
import net.minecraft.world.gen.Spawner;
|
||||||
|
import net.minecraft.world.gen.chunk.ChunkGenerator;
|
||||||
|
import net.minecraft.world.level.ServerWorldProperties;
|
||||||
|
import net.minecraft.world.level.storage.LevelStorage;
|
||||||
|
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;
|
||||||
|
|
||||||
|
@Mixin(ServerWorld.class)
|
||||||
|
public abstract class ServerWorldMixin {
|
||||||
|
@Inject(method = "<init>", at = @At(value = "RETURN"))
|
||||||
|
public void injectConstructor(MinecraftServer server, Executor workerExecutor, LevelStorage.Session session, ServerWorldProperties properties, RegistryKey<World> registryKey, DimensionType dimensionType, WorldGenerationProgressListener worldGenerationProgressListener, ChunkGenerator chunkGenerator, boolean debugWorld, long l, List<Spawner> list, boolean bl, CallbackInfo ci) {
|
||||||
|
if(chunkGenerator instanceof FabricChunkGeneratorWrapper) {
|
||||||
|
TerraFabricPlugin.getInstance().getWorldMap().put(dimensionType, Pair.of((ServerWorld) (Object) this, new TerraWorld((com.dfsek.terra.api.platform.world.World) this, ((FabricChunkGeneratorWrapper) chunkGenerator).getPack(), TerraFabricPlugin.getInstance())));
|
||||||
|
TerraFabricPlugin.getInstance().logger().info("Registered world " + this + " to dimension type " + dimensionType);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,6 +6,7 @@
|
|||||||
"mixins": [
|
"mixins": [
|
||||||
"CommandManagerMixin",
|
"CommandManagerMixin",
|
||||||
"GeneratorOptionsMixin",
|
"GeneratorOptionsMixin",
|
||||||
|
"ServerWorldMixin",
|
||||||
"access.BiomeEffectsAccessor",
|
"access.BiomeEffectsAccessor",
|
||||||
"access.MobSpawnerLogicAccessor",
|
"access.MobSpawnerLogicAccessor",
|
||||||
"access.StateAccessor",
|
"access.StateAccessor",
|
||||||
|
|||||||
Reference in New Issue
Block a user