mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-05-20 08:40:26 +00:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 69ae803074 | |||
| 8f9fc3e08f | |||
| 92339c904d | |||
| 56fb510d96 | |||
| 5821302eb8 | |||
| 901677d2c3 |
@@ -7,6 +7,7 @@ import com.dfsek.terra.api.platform.handle.WorldHandle;
|
||||
import com.dfsek.terra.api.platform.world.World;
|
||||
import com.dfsek.terra.api.registry.CheckedRegistry;
|
||||
import com.dfsek.terra.api.registry.LockedRegistry;
|
||||
import com.dfsek.terra.api.task.TaskScheduler;
|
||||
import com.dfsek.terra.api.util.JarUtil;
|
||||
import com.dfsek.terra.api.util.logging.DebugLogger;
|
||||
import com.dfsek.terra.api.util.logging.Logger;
|
||||
@@ -75,4 +76,6 @@ public interface TerraPlugin extends LoaderRegistrar {
|
||||
default JarFile getModJar() throws URISyntaxException, IOException {
|
||||
return JarUtil.getJarFile();
|
||||
}
|
||||
|
||||
TaskScheduler getScheduler();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.dfsek.terra.api.task;
|
||||
|
||||
public interface TaskScheduler {
|
||||
/**
|
||||
* Run a task synchronously on the next tick.
|
||||
* Functionally equivalent to {@link #runTask(Runnable, long)}
|
||||
* @param task Task to run.
|
||||
*/
|
||||
default void runTask(Runnable task) {
|
||||
runTask(task, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedule a task asynchronously immediately.
|
||||
* Functionally equivalent to {@link #runTaskAsynchronously(Runnable)} (Runnable, long)}
|
||||
* @param task Task to run.
|
||||
*/
|
||||
default void runTaskAsynchronously(Runnable task) {
|
||||
runTaskAsynchronously(task, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Run a task asynchronously after a number of ticks.
|
||||
* @param task Task to run.
|
||||
* @param ticks Delay before running the task, in ticks.
|
||||
*/
|
||||
void runTaskAsynchronously(Runnable task, long ticks);
|
||||
|
||||
/**
|
||||
* Run a task synchronously after a number of ticks.
|
||||
* @param task Task to run.
|
||||
* @param ticks Delay before running the task, in ticks.
|
||||
*/
|
||||
void runTask(Runnable task, long ticks);
|
||||
}
|
||||
@@ -49,4 +49,21 @@ public final class Either<L, R> {
|
||||
public boolean hasRight() {
|
||||
return !leftPresent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
if(hasLeft()) return left.hashCode();
|
||||
return right.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if(!(o instanceof Either<?, ?>)) return false;
|
||||
|
||||
Either<?, ?> that = (Either<?, ?>) o;
|
||||
|
||||
if(hasLeft() && that.hasLeft()) return left.equals(that.left);
|
||||
if(hasRight() && that.hasRight()) return right.equals(that.right);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.dfsek.terra.api.util.generic.pair;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class ImmutablePair<L, R> {
|
||||
private final L left;
|
||||
private final R right;
|
||||
@@ -24,4 +26,15 @@ public class ImmutablePair<L, R> {
|
||||
public Pair<L, R> mutable() {
|
||||
return new Pair<>(left, right);
|
||||
}
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(left, right);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if(!(o instanceof ImmutablePair)) return false;
|
||||
ImmutablePair<?, ?> that = (ImmutablePair<?, ?>) o;
|
||||
return that.left.equals(left) && that.right.equals(right);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.dfsek.terra.api.util.generic.pair;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class Pair<L, R> {
|
||||
private L left;
|
||||
private R right;
|
||||
@@ -32,4 +34,16 @@ public class Pair<L, R> {
|
||||
public ImmutablePair<L, R> immutable() {
|
||||
return new ImmutablePair<>(left, right);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(left, right);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if(!(o instanceof Pair)) return false;
|
||||
Pair<?, ?> that = (Pair<?, ?>) o;
|
||||
return that.left.equals(left) && that.right.equals(right);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,16 +4,20 @@ import com.dfsek.tectonic.annotations.Abstractable;
|
||||
import com.dfsek.tectonic.annotations.Default;
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
import com.dfsek.tectonic.config.ConfigTemplate;
|
||||
import com.dfsek.tectonic.config.ValidatedConfigTemplate;
|
||||
import com.dfsek.tectonic.exception.ValidationException;
|
||||
import com.dfsek.terra.api.math.GridSpawn;
|
||||
import com.dfsek.terra.api.math.Range;
|
||||
import com.dfsek.terra.api.structures.script.StructureScript;
|
||||
import com.dfsek.terra.api.util.GlueList;
|
||||
import com.dfsek.terra.api.util.collections.ProbabilityCollection;
|
||||
import org.checkerframework.checker.units.qual.A;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.List;
|
||||
|
||||
@SuppressWarnings({"unused", "FieldMayBeFinal"})
|
||||
public class StructureTemplate extends AbstractableTemplate implements ConfigTemplate {
|
||||
public class StructureTemplate extends AbstractableTemplate implements ValidatedConfigTemplate {
|
||||
@Value("id")
|
||||
private String id;
|
||||
|
||||
@@ -34,6 +38,21 @@ public class StructureTemplate extends AbstractableTemplate implements ConfigTem
|
||||
@Default
|
||||
private List<Void> features = new GlueList<>();
|
||||
|
||||
@Value("repeat.scripts")
|
||||
@Default
|
||||
@Abstractable
|
||||
private ProbabilityCollection<StructureScript> repeatScripts = new ProbabilityCollection<>();
|
||||
|
||||
@Value("repeat.ticks.min")
|
||||
@Default
|
||||
@Abstractable
|
||||
private long minRepeat = 20;
|
||||
|
||||
@Value("repeat.ticks.max")
|
||||
@Default
|
||||
@Abstractable
|
||||
private long maxRepeat = 20;
|
||||
|
||||
public String getID() {
|
||||
return id;
|
||||
}
|
||||
@@ -53,4 +72,10 @@ public class StructureTemplate extends AbstractableTemplate implements ConfigTem
|
||||
public GridSpawn getSpawn() {
|
||||
return spawn;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean validate() throws ValidationException {
|
||||
if(maxRepeat < minRepeat) throw new ValidationException("repeat.ticks.max must be greater than repeat.ticks.min");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ import com.dfsek.terra.api.platform.world.Biome;
|
||||
import com.dfsek.terra.api.platform.world.World;
|
||||
import com.dfsek.terra.api.registry.CheckedRegistry;
|
||||
import com.dfsek.terra.api.registry.LockedRegistry;
|
||||
import com.dfsek.terra.api.task.TaskScheduler;
|
||||
import com.dfsek.terra.api.util.collections.ProbabilityCollection;
|
||||
import com.dfsek.terra.api.util.logging.DebugLogger;
|
||||
import com.dfsek.terra.api.util.logging.JavaLogger;
|
||||
@@ -138,6 +139,11 @@ public class DistributionTest {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TaskScheduler getScheduler() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Profiler getProfiler() {
|
||||
return null;
|
||||
|
||||
@@ -18,6 +18,7 @@ import com.dfsek.terra.api.platform.world.Biome;
|
||||
import com.dfsek.terra.api.platform.world.World;
|
||||
import com.dfsek.terra.api.registry.CheckedRegistry;
|
||||
import com.dfsek.terra.api.registry.LockedRegistry;
|
||||
import com.dfsek.terra.api.task.TaskScheduler;
|
||||
import com.dfsek.terra.api.util.logging.DebugLogger;
|
||||
import com.dfsek.terra.api.util.logging.JavaLogger;
|
||||
import com.dfsek.terra.api.util.logging.Logger;
|
||||
@@ -32,6 +33,7 @@ import com.dfsek.terra.bukkit.listeners.CommonListener;
|
||||
import com.dfsek.terra.bukkit.listeners.PaperListener;
|
||||
import com.dfsek.terra.bukkit.listeners.SpigotListener;
|
||||
import com.dfsek.terra.bukkit.listeners.TerraListener;
|
||||
import com.dfsek.terra.bukkit.task.BukkitTaskScheduler;
|
||||
import com.dfsek.terra.bukkit.util.PaperUtil;
|
||||
import com.dfsek.terra.bukkit.world.BukkitBiome;
|
||||
import com.dfsek.terra.bukkit.world.BukkitWorld;
|
||||
@@ -69,6 +71,8 @@ public class TerraBukkitPlugin extends JavaPlugin implements TerraPlugin {
|
||||
|
||||
private final Profiler profiler = new ProfilerImpl();
|
||||
|
||||
private final TaskScheduler scheduler = new BukkitTaskScheduler(this);
|
||||
|
||||
private final ConfigRegistry registry = new ConfigRegistry();
|
||||
private final CheckedRegistry<ConfigPack> checkedRegistry = new CheckedRegistry<>(registry);
|
||||
|
||||
@@ -151,6 +155,11 @@ public class TerraBukkitPlugin extends JavaPlugin implements TerraPlugin {
|
||||
return profiler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TaskScheduler getScheduler() {
|
||||
return scheduler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
BukkitChunkGeneratorWrapper.saveAll();
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.dfsek.terra.bukkit.task;
|
||||
|
||||
import com.dfsek.terra.api.task.TaskScheduler;
|
||||
import com.dfsek.terra.bukkit.TerraBukkitPlugin;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
public class BukkitTaskScheduler implements TaskScheduler {
|
||||
private final TerraBukkitPlugin plugin;
|
||||
|
||||
public BukkitTaskScheduler(TerraBukkitPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runTaskAsynchronously(Runnable task, long ticks) {
|
||||
Bukkit.getScheduler().runTaskLaterAsynchronously(plugin, task, ticks);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runTask(Runnable task, long ticks) {
|
||||
Bukkit.getScheduler().runTaskLater(plugin, task, ticks);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runTask(Runnable task) {
|
||||
Bukkit.getScheduler().runTask(plugin, task);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runTaskAsynchronously(Runnable task) {
|
||||
Bukkit.getScheduler().runTask(plugin, task);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.dfsek.terra.fabric;
|
||||
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.dedicated.MinecraftDedicatedServer;
|
||||
|
||||
public class FabricUtil {
|
||||
@SuppressWarnings("deprecation")
|
||||
public static MinecraftServer getServer() {
|
||||
Object game = FabricLoader.getInstance().getGameInstance();
|
||||
if(game instanceof MinecraftDedicatedServer) {
|
||||
return (MinecraftDedicatedServer) game;
|
||||
} else if(game instanceof MinecraftClient) {
|
||||
MinecraftClient client = (MinecraftClient) game;
|
||||
if(!client.isIntegratedServerRunning()) {
|
||||
throw new IllegalStateException("Client is not running integrated server: " + client);
|
||||
}
|
||||
return client.getServer();
|
||||
}
|
||||
throw new IllegalStateException("No MinecraftServer initialized: " + game);
|
||||
}
|
||||
}
|
||||
@@ -25,6 +25,7 @@ import com.dfsek.terra.api.platform.world.Tree;
|
||||
import com.dfsek.terra.api.platform.world.World;
|
||||
import com.dfsek.terra.api.registry.CheckedRegistry;
|
||||
import com.dfsek.terra.api.registry.LockedRegistry;
|
||||
import com.dfsek.terra.api.task.TaskScheduler;
|
||||
import com.dfsek.terra.api.transform.NotNullValidator;
|
||||
import com.dfsek.terra.api.transform.Transformer;
|
||||
import com.dfsek.terra.api.util.logging.DebugLogger;
|
||||
@@ -37,13 +38,14 @@ 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.config.templates.BiomeTemplate;
|
||||
import com.dfsek.terra.fabric.generation.FabricChunkGeneratorWrapper;
|
||||
import com.dfsek.terra.fabric.generation.PopulatorFeature;
|
||||
import com.dfsek.terra.fabric.generation.TerraBiomeSource;
|
||||
import com.dfsek.terra.fabric.handle.FabricItemHandle;
|
||||
import com.dfsek.terra.fabric.handle.FabricWorldHandle;
|
||||
import com.dfsek.terra.fabric.mixin.access.BiomeEffectsAccessor;
|
||||
import com.dfsek.terra.fabric.mixin.access.GeneratorTypeAccessor;
|
||||
import com.dfsek.terra.fabric.generation.TerraBiomeSource;
|
||||
import com.dfsek.terra.fabric.generation.PopulatorFeature;
|
||||
import com.dfsek.terra.fabric.generation.FabricChunkGeneratorWrapper;
|
||||
import com.dfsek.terra.fabric.task.FabricTaskScheduler;
|
||||
import com.dfsek.terra.profiler.Profiler;
|
||||
import com.dfsek.terra.profiler.ProfilerImpl;
|
||||
import com.dfsek.terra.registry.exception.DuplicateEntryException;
|
||||
@@ -97,7 +99,6 @@ import static net.minecraft.server.command.CommandManager.literal;
|
||||
|
||||
|
||||
public class TerraFabricPlugin implements TerraPlugin, ModInitializer {
|
||||
|
||||
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));
|
||||
private static TerraFabricPlugin instance;
|
||||
@@ -136,6 +137,8 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer {
|
||||
private final Transformer<String, Biome> biomeFixer = new Transformer.Builder<String, Biome>()
|
||||
.addTransform(id -> BuiltinRegistries.BIOME.get(Identifier.tryParse(id)), new NotNullValidator<>())
|
||||
.addTransform(id -> BuiltinRegistries.BIOME.get(Identifier.tryParse("minecraft:" + id.toLowerCase())), new NotNullValidator<>()).build();
|
||||
|
||||
private final TaskScheduler scheduler = new FabricTaskScheduler();
|
||||
private File dataFolder;
|
||||
|
||||
public static TerraFabricPlugin getInstance() {
|
||||
@@ -407,11 +410,15 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer {
|
||||
return profiler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TaskScheduler getScheduler() {
|
||||
return scheduler;
|
||||
}
|
||||
|
||||
@Addon("Terra-Fabric")
|
||||
@Author("Terra")
|
||||
@Version("1.0.0")
|
||||
private static final class FabricAddon extends TerraAddon implements EventListener {
|
||||
|
||||
private final TerraPlugin main;
|
||||
|
||||
private FabricAddon(TerraPlugin main) {
|
||||
@@ -448,7 +455,6 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer {
|
||||
injectTree(treeRegistry, "WARPED_FUNGUS", ConfiguredFeatures.WARPED_FUNGI);
|
||||
}
|
||||
|
||||
|
||||
private void injectTree(CheckedRegistry<Tree> registry, String id, ConfiguredFeature<?, ?> tree) {
|
||||
try {
|
||||
registry.add(id, (Tree) tree);
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.dfsek.terra.fabric.task;
|
||||
|
||||
import com.dfsek.terra.api.task.TaskScheduler;
|
||||
import com.dfsek.terra.fabric.FabricUtil;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.ServerTask;
|
||||
import net.minecraft.util.Util;
|
||||
|
||||
public class FabricTaskScheduler implements TaskScheduler {
|
||||
@Override
|
||||
public void runTaskAsynchronously(Runnable task, long ticks) {
|
||||
runTask(() -> Util.getMainWorkerExecutor().execute(task), ticks);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runTaskAsynchronously(Runnable task) {
|
||||
Util.getMainWorkerExecutor().execute(task);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runTask(Runnable task, long ticks) {
|
||||
MinecraftServer server = FabricUtil.getServer();
|
||||
server.send(new ServerTask(server.getTicks() + (int) ticks, task));
|
||||
}
|
||||
}
|
||||
@@ -24,6 +24,7 @@ import com.dfsek.terra.api.platform.world.Tree;
|
||||
import com.dfsek.terra.api.platform.world.World;
|
||||
import com.dfsek.terra.api.registry.CheckedRegistry;
|
||||
import com.dfsek.terra.api.registry.LockedRegistry;
|
||||
import com.dfsek.terra.api.task.TaskScheduler;
|
||||
import com.dfsek.terra.api.transform.NotNullValidator;
|
||||
import com.dfsek.terra.api.transform.Transformer;
|
||||
import com.dfsek.terra.api.util.JarUtil;
|
||||
@@ -311,6 +312,11 @@ public class TerraForgePlugin implements TerraPlugin {
|
||||
return JarUtil.getJarFile();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TaskScheduler getScheduler() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public TerraWorld getWorld(long seed) {
|
||||
TerraWorld world = worldMap.get(seed);
|
||||
if(world == null) throw new IllegalArgumentException("No world exists with seed " + seed);
|
||||
|
||||
@@ -12,6 +12,7 @@ import com.dfsek.terra.api.platform.world.Biome;
|
||||
import com.dfsek.terra.api.platform.world.World;
|
||||
import com.dfsek.terra.api.registry.CheckedRegistry;
|
||||
import com.dfsek.terra.api.registry.LockedRegistry;
|
||||
import com.dfsek.terra.api.task.TaskScheduler;
|
||||
import com.dfsek.terra.api.util.logging.DebugLogger;
|
||||
import com.dfsek.terra.api.util.logging.JavaLogger;
|
||||
import com.dfsek.terra.config.GenericLoaders;
|
||||
@@ -156,4 +157,9 @@ public class StandalonePlugin implements TerraPlugin {
|
||||
public Profiler getProfiler() {
|
||||
return profiler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TaskScheduler getScheduler() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import com.dfsek.terra.api.platform.handle.WorldHandle;
|
||||
import com.dfsek.terra.api.platform.world.World;
|
||||
import com.dfsek.terra.api.registry.CheckedRegistry;
|
||||
import com.dfsek.terra.api.registry.LockedRegistry;
|
||||
import com.dfsek.terra.api.task.TaskScheduler;
|
||||
import com.dfsek.terra.api.util.logging.DebugLogger;
|
||||
import com.dfsek.terra.config.PluginConfig;
|
||||
import com.dfsek.terra.config.lang.Language;
|
||||
@@ -140,6 +141,11 @@ public class TerraSpongePlugin implements TerraPlugin {
|
||||
return eventManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TaskScheduler getScheduler() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Profiler getProfiler() {
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user