mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-04-04 14:56:28 +00:00
refactor FabricEntryPoint#getPlatform
This commit is contained in:
@@ -22,7 +22,7 @@ public class FabricEntryPoint implements ModInitializer {
|
||||
Decorator.NOPE.configure(NopeDecoratorConfig.INSTANCE));
|
||||
private static final PlatformImpl TERRA_PLUGIN = new PlatformImpl();
|
||||
|
||||
public static PlatformImpl getTerraPlugin() {
|
||||
public static PlatformImpl getPlatform() {
|
||||
return TERRA_PLUGIN;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,13 +2,19 @@ package com.dfsek.terra.fabric;
|
||||
|
||||
import com.dfsek.tectonic.exception.LoadException;
|
||||
import com.dfsek.tectonic.loading.TypeRegistry;
|
||||
|
||||
import com.dfsek.terra.fabric.util.FabricUtil;
|
||||
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.registry.BuiltinRegistries;
|
||||
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;
|
||||
@@ -28,6 +34,12 @@ 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 void addWorld(ServerWorld world) {
|
||||
worlds.add(world);
|
||||
}
|
||||
|
||||
public PlatformImpl() {
|
||||
load();
|
||||
}
|
||||
@@ -37,6 +49,7 @@ public class PlatformImpl extends AbstractPlatform {
|
||||
getTerraConfig().load(this);
|
||||
LangUtil.load(getTerraConfig().getLanguage(), this); // Load language.
|
||||
boolean succeed = getRawConfigRegistry().loadAll(this);
|
||||
|
||||
return succeed;
|
||||
}
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ public class FabricChunkGeneratorWrapper extends net.minecraft.world.gen.chunk.C
|
||||
config -> config.group(
|
||||
Codec.STRING.fieldOf("pack")
|
||||
.forGetter(ConfigPack::getID)
|
||||
).apply(config, config.stable(FabricEntryPoint.getTerraPlugin().getConfigRegistry()::get)));
|
||||
).apply(config, config.stable(FabricEntryPoint.getPlatform().getConfigRegistry()::get)));
|
||||
|
||||
public static final Codec<FabricChunkGeneratorWrapper> CODEC = RecordCodecBuilder.create(
|
||||
instance -> instance.group(
|
||||
|
||||
@@ -23,7 +23,7 @@ public class TerraBiomeSource extends BiomeSource {
|
||||
Codec.STRING.fieldOf("pack").forGetter(ConfigPack::getID)
|
||||
)
|
||||
.apply(config, config.stable(
|
||||
FabricEntryPoint.getTerraPlugin()
|
||||
FabricEntryPoint.getPlatform()
|
||||
.getConfigRegistry()::get))));
|
||||
public static final Codec<TerraBiomeSource> CODEC = RecordCodecBuilder.create(instance -> instance.group(
|
||||
RegistryLookupCodec.of(Registry.BIOME_KEY).forGetter(source -> source.biomeRegistry),
|
||||
|
||||
@@ -28,7 +28,7 @@ public class TerraGeneratorType extends GeneratorType {
|
||||
public GeneratorOptions createDefaultOptions(DynamicRegistryManager.Impl registryManager, long seed, boolean generateStructures,
|
||||
boolean bonusChest) {
|
||||
GeneratorOptions options = super.createDefaultOptions(registryManager, seed, generateStructures, bonusChest);
|
||||
FabricEntryPoint.getTerraPlugin().getEventManager().callEvent(new BiomeRegistrationEvent(registryManager)); // register biomes
|
||||
FabricEntryPoint.getPlatform().getEventManager().callEvent(new BiomeRegistrationEvent(registryManager)); // register biomes
|
||||
return options;
|
||||
}
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ public abstract class CommandManagerMixin {
|
||||
target = "Lcom/mojang/brigadier/CommandDispatcher;findAmbiguities(Lcom/mojang/brigadier/AmbiguityConsumer;)V",
|
||||
remap = false))
|
||||
private void injectTerraCommands(CommandManager.RegistrationEnvironment environment, CallbackInfo ci) {
|
||||
com.dfsek.terra.api.command.CommandManager manager = FabricEntryPoint.getTerraPlugin().getManager();
|
||||
com.dfsek.terra.api.command.CommandManager manager = FabricEntryPoint.getPlatform().getManager();
|
||||
int max = manager.getMaxArgumentDepth();
|
||||
RequiredArgumentBuilder<ServerCommandSource, String> arg = argument("arg" + (max - 1), StringArgumentType.word());
|
||||
for(int i = 0; i < max; i++) {
|
||||
|
||||
@@ -31,7 +31,8 @@ public abstract class ServerWorldMixin {
|
||||
boolean debugWorld, long l, List<Spawner> list, boolean bl, CallbackInfo ci) {
|
||||
if(chunkGenerator instanceof FabricChunkGeneratorWrapper) {
|
||||
((FabricChunkGeneratorWrapper) chunkGenerator).setWorld((ServerWorld) (Object) this);
|
||||
FabricEntryPoint.getTerraPlugin().logger().info("Registered world " + this);
|
||||
FabricEntryPoint.getPlatform().addWorld((ServerWorld) (Object) this);
|
||||
FabricEntryPoint.getPlatform().logger().info("Registered world " + this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ public abstract class ConfiguredFeatureMixin {
|
||||
@SuppressWarnings({ "ConstantConditions", "try" })
|
||||
public boolean terra$plant(Vector3 l, World world, Random r) {
|
||||
String id = BuiltinRegistries.CONFIGURED_FEATURE.getId((ConfiguredFeature<?, ?>) (Object) this).toString();
|
||||
try(ProfileFrame ignore = FabricEntryPoint.getTerraPlugin().getProfiler().profile("fabric_tree:" + id.toLowerCase(Locale.ROOT))) {
|
||||
try(ProfileFrame ignore = FabricEntryPoint.getPlatform().getProfiler().profile("fabric_tree:" + id.toLowerCase(Locale.ROOT))) {
|
||||
StructureWorldAccess fabricWorldAccess = ((StructureWorldAccess) world);
|
||||
ChunkGenerator generatorWrapper = ((ServerWorldAccess) world).toServerWorld().getChunkManager().getChunkGenerator();
|
||||
return generate(fabricWorldAccess, generatorWrapper, r, new BlockPos(l.getBlockX(), l.getBlockY(), l.getBlockZ()));
|
||||
@@ -41,8 +41,8 @@ public abstract class ConfiguredFeatureMixin {
|
||||
}
|
||||
|
||||
public Set<BlockType> terra$getSpawnable() {
|
||||
return MaterialSet.get(FabricEntryPoint.getTerraPlugin().getWorldHandle().createBlockData("minecraft:grass_block"),
|
||||
FabricEntryPoint.getTerraPlugin().getWorldHandle().createBlockData("minecraft:podzol"),
|
||||
FabricEntryPoint.getTerraPlugin().getWorldHandle().createBlockData("minecraft:mycelium"));
|
||||
return MaterialSet.get(FabricEntryPoint.getPlatform().getWorldHandle().createBlockData("minecraft:grass_block"),
|
||||
FabricEntryPoint.getPlatform().getWorldHandle().createBlockData("minecraft:podzol"),
|
||||
FabricEntryPoint.getPlatform().getWorldHandle().createBlockData("minecraft:mycelium"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ public abstract class MobSpawnerBlockEntityMixin extends BlockEntity {
|
||||
public void terra$applyState(String state) {
|
||||
SerialState.parse(state).forEach((k, v) -> {
|
||||
switch(k) {
|
||||
case "type" -> terra$setSpawnedType(FabricEntryPoint.getTerraPlugin().getWorldHandle().getEntity(v));
|
||||
case "type" -> terra$setSpawnedType(FabricEntryPoint.getPlatform().getWorldHandle().getEntity(v));
|
||||
case "delay" -> terra$setDelay(Integer.parseInt(v));
|
||||
case "min_delay" -> terra$setMinSpawnDelay(Integer.parseInt(v));
|
||||
case "max_delay" -> terra$setMaxSpawnDelay(Integer.parseInt(v));
|
||||
|
||||
@@ -24,8 +24,8 @@ public class MinecraftClientMixin {
|
||||
// sorta arbitrary position, after mod init, before window opens
|
||||
shift = At.Shift.BEFORE))
|
||||
public void injectConstructor(RunArgs args, CallbackInfo callbackInfo) {
|
||||
FabricEntryPoint.getTerraPlugin().getEventManager().callEvent(new PlatformInitializationEvent());
|
||||
FabricEntryPoint.getTerraPlugin().getConfigRegistry().forEach(pack -> {
|
||||
FabricEntryPoint.getPlatform().getEventManager().callEvent(new PlatformInitializationEvent());
|
||||
FabricEntryPoint.getPlatform().getConfigRegistry().forEach(pack -> {
|
||||
final GeneratorType generatorType = new TerraGeneratorType(pack);
|
||||
//noinspection ConstantConditions
|
||||
((GeneratorTypeAccessor) generatorType).setTranslationKey(new LiteralText("Terra:" + pack.getID()));
|
||||
|
||||
@@ -37,7 +37,7 @@ public abstract class GeneratorOptionsMixin {
|
||||
return;
|
||||
}
|
||||
|
||||
PlatformImpl main = FabricEntryPoint.getTerraPlugin();
|
||||
PlatformImpl main = FabricEntryPoint.getPlatform();
|
||||
|
||||
String prop = properties.get("level-type").toString().trim();
|
||||
if(prop.startsWith("Terra")) {
|
||||
|
||||
@@ -17,7 +17,7 @@ public class ServerMainMixin {
|
||||
target = "Lnet/minecraft/util/registry/DynamicRegistryManager;create()" +
|
||||
"Lnet/minecraft/util/registry/DynamicRegistryManager$Impl;"))
|
||||
private static void injectConstructor(String[] args, CallbackInfo ci) {
|
||||
FabricEntryPoint.getTerraPlugin().getEventManager().callEvent(
|
||||
FabricEntryPoint.getPlatform().getEventManager().callEvent(
|
||||
new PlatformInitializationEvent()); // Load during MinecraftServer construction, after other mods have registered blocks and stuff
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user