mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-04-22 16:18:32 +00:00
registry stuff
This commit is contained in:
@@ -32,6 +32,8 @@ import com.dfsek.terra.config.lang.LangUtil;
|
||||
import com.dfsek.terra.config.lang.Language;
|
||||
import com.dfsek.terra.config.pack.ConfigPack;
|
||||
import com.dfsek.terra.debug.DebugLogger;
|
||||
import com.dfsek.terra.registry.CheckedRegistry;
|
||||
import com.dfsek.terra.registry.LockedRegistry;
|
||||
import com.dfsek.terra.registry.master.AddonRegistry;
|
||||
import com.dfsek.terra.registry.master.ConfigRegistry;
|
||||
import com.dfsek.terra.world.TerraWorld;
|
||||
@@ -55,7 +57,10 @@ public class TerraBukkitPlugin extends JavaPlugin implements TerraPlugin {
|
||||
private final Map<String, DefaultChunkGenerator3D> generatorMap = new HashMap<>();
|
||||
private final Map<World, TerraWorld> worldMap = new HashMap<>();
|
||||
private final Map<String, ConfigPack> worlds = new HashMap<>();
|
||||
|
||||
private final ConfigRegistry registry = new ConfigRegistry();
|
||||
private final CheckedRegistry<ConfigPack> checkedRegistry = new CheckedRegistry<>(registry);
|
||||
|
||||
private final PluginConfig config = new PluginConfig();
|
||||
private final ItemHandle itemHandle = new BukkitItemHandle();
|
||||
private WorldHandle handle = new BukkitWorldHandle();
|
||||
@@ -76,9 +81,14 @@ public class TerraBukkitPlugin extends JavaPlugin implements TerraPlugin {
|
||||
}
|
||||
|
||||
private final AddonRegistry addonRegistry = new AddonRegistry(new BukkitAddon(this), this);
|
||||
private final LockedRegistry<TerraAddon> addonLockedRegistry = new LockedRegistry<>(addonRegistry);
|
||||
|
||||
|
||||
public void reload() {
|
||||
|
||||
public boolean reload() {
|
||||
config.load(this);
|
||||
LangUtil.load(config.getLanguage(), this); // Load language.
|
||||
boolean succeed = registry.loadAll(this);
|
||||
Map<World, TerraWorld> newMap = new HashMap<>();
|
||||
worldMap.forEach((world, tw) -> {
|
||||
((BukkitChunkGeneratorWrapper) world.getGenerator().getHandle()).getHandle().getCache().clear();
|
||||
@@ -87,6 +97,7 @@ public class TerraBukkitPlugin extends JavaPlugin implements TerraPlugin {
|
||||
});
|
||||
worldMap.clear();
|
||||
worldMap.putAll(newMap);
|
||||
return succeed;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -221,8 +232,8 @@ public class TerraBukkitPlugin extends JavaPlugin implements TerraPlugin {
|
||||
return LangUtil.getLanguage();
|
||||
}
|
||||
|
||||
public ConfigRegistry getRegistry() {
|
||||
return registry;
|
||||
public CheckedRegistry<ConfigPack> getConfigRegistry() {
|
||||
return checkedRegistry;
|
||||
}
|
||||
|
||||
public TerraWorld getWorld(World w) {
|
||||
@@ -258,8 +269,8 @@ public class TerraBukkitPlugin extends JavaPlugin implements TerraPlugin {
|
||||
}
|
||||
|
||||
@Override
|
||||
public AddonRegistry getAddons() {
|
||||
return addonRegistry;
|
||||
public LockedRegistry<TerraAddon> getAddons() {
|
||||
return addonLockedRegistry;
|
||||
}
|
||||
|
||||
public enum BukkitVersion {
|
||||
|
||||
@@ -3,7 +3,9 @@ package com.dfsek.terra.bukkit.command.command;
|
||||
import com.dfsek.terra.bukkit.BukkitCommandSender;
|
||||
import com.dfsek.terra.bukkit.command.Command;
|
||||
import com.dfsek.terra.config.lang.LangUtil;
|
||||
import com.dfsek.terra.config.pack.ConfigPack;
|
||||
import com.dfsek.terra.config.pack.ConfigPackTemplate;
|
||||
import com.dfsek.terra.registry.CheckedRegistry;
|
||||
import com.dfsek.terra.registry.master.ConfigRegistry;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -29,7 +31,7 @@ public class PacksCommand extends Command {
|
||||
@Override
|
||||
public boolean execute(@NotNull CommandSender commandSender, org.bukkit.command.@NotNull Command command, @NotNull String s, @NotNull String[] strings) {
|
||||
|
||||
ConfigRegistry registry = getMain().getRegistry();
|
||||
CheckedRegistry<ConfigPack> registry = getMain().getConfigRegistry();
|
||||
|
||||
if(registry.entries().size() == 0) {
|
||||
LangUtil.send("command.packs.none", new BukkitCommandSender(commandSender));
|
||||
|
||||
@@ -28,13 +28,10 @@ public class ReloadCommand extends Command implements DebugCommand {
|
||||
|
||||
@Override
|
||||
public boolean execute(@NotNull CommandSender sender, org.bukkit.command.@NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||
getMain().getTerraConfig().load(getMain());
|
||||
LangUtil.load(getMain().getTerraConfig().getLanguage(), getMain()); // Load language.
|
||||
if(!getMain().getRegistry().loadAll(getMain())) {
|
||||
if(!getMain().reload()) {
|
||||
LangUtil.send("command.reload-error", new BukkitCommandSender(sender));
|
||||
return true;
|
||||
}
|
||||
getMain().reload();
|
||||
LangUtil.send("command.reload", new BukkitCommandSender(sender));
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.dfsek.terra.fabric;
|
||||
|
||||
import com.dfsek.tectonic.loading.TypeRegistry;
|
||||
import com.dfsek.terra.addons.addon.TerraAddon;
|
||||
import com.dfsek.terra.api.core.TerraPlugin;
|
||||
import com.dfsek.terra.api.core.event.EventManager;
|
||||
import com.dfsek.terra.api.core.event.TerraEventManager;
|
||||
@@ -26,6 +27,8 @@ import com.dfsek.terra.fabric.world.FabricWorldHandle;
|
||||
import com.dfsek.terra.fabric.world.TerraBiomeSource;
|
||||
import com.dfsek.terra.fabric.world.features.PopulatorFeature;
|
||||
import com.dfsek.terra.fabric.world.generator.FabricChunkGeneratorWrapper;
|
||||
import com.dfsek.terra.registry.CheckedRegistry;
|
||||
import com.dfsek.terra.registry.LockedRegistry;
|
||||
import com.dfsek.terra.registry.master.AddonRegistry;
|
||||
import com.dfsek.terra.registry.master.ConfigRegistry;
|
||||
import com.dfsek.terra.world.TerraWorld;
|
||||
@@ -86,8 +89,12 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer {
|
||||
private final ItemHandle itemHandle = new FabricItemHandle();
|
||||
private final WorldHandle worldHandle = new FabricWorldHandle();
|
||||
private final ConfigRegistry registry = new ConfigRegistry();
|
||||
private final CheckedRegistry<ConfigPack> checkedRegistry = new CheckedRegistry<>(registry);
|
||||
|
||||
private final AddonRegistry addonRegistry = new AddonRegistry(this);
|
||||
private final LockedRegistry<TerraAddon> addonLockedRegistry = new LockedRegistry<>(addonRegistry);
|
||||
|
||||
|
||||
private File config;
|
||||
private static final Transformer<String, ConfiguredFeature<?, ?>> TREE_TRANSFORMER = new Transformer.Builder<String, ConfiguredFeature<?, ?>>()
|
||||
.addTransform(TerraFabricPlugin::getFeature)
|
||||
@@ -127,7 +134,7 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer {
|
||||
public TerraWorld getWorld(World world) {
|
||||
return worldMap.computeIfAbsent(world.getSeed(), w -> {
|
||||
logger.info("Loading world " + w);
|
||||
return new TerraWorld(world, getRegistry().get("DEFAULT"), this);
|
||||
return new TerraWorld(world, getConfigRegistry().get("DEFAULT"), this);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -161,18 +168,18 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigRegistry getRegistry() {
|
||||
return registry;
|
||||
public CheckedRegistry<ConfigPack> getConfigRegistry() {
|
||||
return checkedRegistry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AddonRegistry getAddons() {
|
||||
return addonRegistry;
|
||||
public LockedRegistry<TerraAddon> getAddons() {
|
||||
return addonLockedRegistry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reload() {
|
||||
|
||||
public boolean reload() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -18,7 +18,7 @@ import java.util.stream.Collectors;
|
||||
public class TerraBiomeSource extends BiomeSource {
|
||||
public static final Codec<ConfigPack> PACK_CODEC = (RecordCodecBuilder.create(config -> config.group(
|
||||
Codec.STRING.fieldOf("pack").forGetter(pack -> pack.getTemplate().getID())
|
||||
).apply(config, config.stable(TerraFabricPlugin.getInstance().getRegistry()::get))));
|
||||
).apply(config, config.stable(TerraFabricPlugin.getInstance().getConfigRegistry()::get))));
|
||||
public static final Codec<TerraBiomeSource> CODEC = RecordCodecBuilder.create(instance -> instance.group(
|
||||
RegistryLookupCodec.of(Registry.BIOME_KEY).forGetter(source -> source.biomeRegistry),
|
||||
Codec.LONG.fieldOf("seed").stable().forGetter(source -> source.seed),
|
||||
|
||||
@@ -35,7 +35,7 @@ public class FabricChunkGeneratorWrapper extends ChunkGenerator implements com.d
|
||||
private final TerraBiomeSource biomeSource;
|
||||
public static final Codec<ConfigPack> PACK_CODEC = (RecordCodecBuilder.create(config -> config.group(
|
||||
Codec.STRING.fieldOf("pack").forGetter(pack -> pack.getTemplate().getID())
|
||||
).apply(config, config.stable(TerraFabricPlugin.getInstance().getRegistry()::get))));
|
||||
).apply(config, config.stable(TerraFabricPlugin.getInstance().getConfigRegistry()::get))));
|
||||
public static final Codec<FabricChunkGeneratorWrapper> CODEC = RecordCodecBuilder.create(instance -> instance.group(
|
||||
TerraBiomeSource.CODEC.fieldOf("biome_source").forGetter(generator -> generator.biomeSource),
|
||||
Codec.LONG.fieldOf("seed").stable().forGetter(generator -> generator.seed),
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.dfsek.terra;
|
||||
|
||||
import com.dfsek.tectonic.loading.TypeRegistry;
|
||||
import com.dfsek.terra.addons.addon.TerraAddon;
|
||||
import com.dfsek.terra.api.core.TerraPlugin;
|
||||
import com.dfsek.terra.api.core.event.EventManager;
|
||||
import com.dfsek.terra.api.core.event.TerraEventManager;
|
||||
@@ -14,9 +15,12 @@ import com.dfsek.terra.config.GenericLoaders;
|
||||
import com.dfsek.terra.config.PluginConfig;
|
||||
import com.dfsek.terra.config.lang.LangUtil;
|
||||
import com.dfsek.terra.config.lang.Language;
|
||||
import com.dfsek.terra.config.pack.ConfigPack;
|
||||
import com.dfsek.terra.debug.DebugLogger;
|
||||
import com.dfsek.terra.platform.RawBiome;
|
||||
import com.dfsek.terra.platform.RawWorldHandle;
|
||||
import com.dfsek.terra.registry.CheckedRegistry;
|
||||
import com.dfsek.terra.registry.LockedRegistry;
|
||||
import com.dfsek.terra.registry.master.AddonRegistry;
|
||||
import com.dfsek.terra.registry.master.ConfigRegistry;
|
||||
import com.dfsek.terra.world.TerraWorld;
|
||||
@@ -28,6 +32,9 @@ import java.util.logging.Logger;
|
||||
public class StandalonePlugin implements TerraPlugin {
|
||||
private final ConfigRegistry registry = new ConfigRegistry();
|
||||
private final AddonRegistry addonRegistry = new AddonRegistry(this);
|
||||
|
||||
private final LockedRegistry<TerraAddon> addonLockedRegistry = new LockedRegistry<>(addonRegistry);
|
||||
|
||||
private final PluginConfig config = new PluginConfig();
|
||||
private final RawWorldHandle worldHandle = new RawWorldHandle();
|
||||
private final EventManager eventManager = new TerraEventManager(this);
|
||||
@@ -77,17 +84,17 @@ public class StandalonePlugin implements TerraPlugin {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigRegistry getRegistry() {
|
||||
return registry;
|
||||
public CheckedRegistry<ConfigPack> getConfigRegistry() {
|
||||
return new CheckedRegistry<>(registry);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AddonRegistry getAddons() {
|
||||
return addonRegistry;
|
||||
public LockedRegistry<TerraAddon> getAddons() {
|
||||
return addonLockedRegistry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reload() {
|
||||
public boolean reload() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ public class Generator {
|
||||
structurePopulator = new StructurePopulator(plugin);
|
||||
treePopulator = new TreePopulator(plugin);
|
||||
orePopulator = new OrePopulator(plugin);
|
||||
generator = new DefaultChunkGenerator3D(plugin.getRegistry().get("DEFAULT"), plugin, new SamplerCache(plugin));
|
||||
generator = new DefaultChunkGenerator3D(plugin.getConfigRegistry().get("DEFAULT"), plugin, new SamplerCache(plugin));
|
||||
this.seed = seed;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user