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