mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-02-16 10:30:42 +00:00
format
This commit is contained in:
@@ -4,5 +4,5 @@ import com.dfsek.terra.api.util.StringIdentifiable;
|
||||
|
||||
|
||||
public interface BaseAddon extends StringIdentifiable {
|
||||
default void initialize() {}
|
||||
default void initialize() { }
|
||||
}
|
||||
|
||||
@@ -1,15 +1,17 @@
|
||||
package com.dfsek.terra.api.addon.bootstrap;
|
||||
|
||||
import com.dfsek.terra.api.addon.BaseAddon;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
||||
import com.dfsek.terra.api.addon.BaseAddon;
|
||||
|
||||
|
||||
public interface BootstrapBaseAddon<T extends BaseAddon> extends BaseAddon {
|
||||
/**
|
||||
* Load all the relevant addons in the specified path.
|
||||
*
|
||||
* @param addonsFolder Path containing addons.
|
||||
* @param parent
|
||||
*
|
||||
* @return Loaded addons
|
||||
*/
|
||||
Iterable<T> loadAddons(Path addonsFolder, ClassLoader parent);
|
||||
|
||||
@@ -3,7 +3,6 @@ package com.dfsek.terra.api;
|
||||
import java.io.File;
|
||||
|
||||
import com.dfsek.terra.api.addon.BaseAddon;
|
||||
import com.dfsek.terra.api.addon.TerraAddon;
|
||||
import com.dfsek.terra.api.config.ConfigPack;
|
||||
import com.dfsek.terra.api.config.PluginConfig;
|
||||
import com.dfsek.terra.api.event.EventManager;
|
||||
|
||||
@@ -7,6 +7,7 @@ import com.dfsek.terra.api.registry.CheckedRegistry;
|
||||
public interface AddonLoader {
|
||||
/**
|
||||
* Load all addons.
|
||||
*
|
||||
* @param platform TerraPlugin instance.
|
||||
*/
|
||||
void load(Platform platform, CheckedRegistry<Addon> addons);
|
||||
|
||||
@@ -11,17 +11,17 @@ public interface EnumProperty<T extends Enum<T>> extends Property<T> {
|
||||
static <T extends Enum<T>> EnumProperty<T> of(String name, Class<T> clazz) {
|
||||
return new EnumProperty<>() {
|
||||
private final Lazy<Collection<T>> constants = Lazy.lazy(() -> Arrays.asList(clazz.getEnumConstants()));
|
||||
|
||||
|
||||
@Override
|
||||
public Collection<T> values() {
|
||||
return constants.value();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Class<T> getType() {
|
||||
return clazz;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
|
||||
@@ -5,13 +5,13 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.dfsek.terra.api.util.StringIdentifiable;
|
||||
import com.dfsek.terra.api.addon.TerraAddon;
|
||||
import com.dfsek.terra.api.registry.CheckedRegistry;
|
||||
import com.dfsek.terra.api.registry.meta.RegistryFactory;
|
||||
import com.dfsek.terra.api.registry.meta.RegistryHolder;
|
||||
import com.dfsek.terra.api.tectonic.LoaderHolder;
|
||||
import com.dfsek.terra.api.tectonic.LoaderRegistrar;
|
||||
import com.dfsek.terra.api.util.StringIdentifiable;
|
||||
import com.dfsek.terra.api.util.reflection.TypeKey;
|
||||
import com.dfsek.terra.api.world.World;
|
||||
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
|
||||
|
||||
@@ -2,8 +2,8 @@ package com.dfsek.terra.api.config;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import com.dfsek.terra.api.util.StringIdentifiable;
|
||||
import com.dfsek.terra.api.registry.Registry;
|
||||
import com.dfsek.terra.api.util.StringIdentifiable;
|
||||
import com.dfsek.terra.api.world.World;
|
||||
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
|
||||
import com.dfsek.terra.api.world.generator.SamplerCache;
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.dfsek.terra.api.event.functional;
|
||||
|
||||
import com.dfsek.terra.api.addon.BaseAddon;
|
||||
import com.dfsek.terra.api.addon.TerraAddon;
|
||||
import com.dfsek.terra.api.event.EventHandler;
|
||||
import com.dfsek.terra.api.event.events.Event;
|
||||
import com.dfsek.terra.api.util.reflection.TypeKey;
|
||||
|
||||
@@ -2,9 +2,9 @@ package com.dfsek.terra.api.structure;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import com.dfsek.terra.api.util.StringIdentifiable;
|
||||
import com.dfsek.terra.api.structure.buffer.Buffer;
|
||||
import com.dfsek.terra.api.structure.rotation.Rotation;
|
||||
import com.dfsek.terra.api.util.StringIdentifiable;
|
||||
import com.dfsek.terra.api.util.vector.Vector3;
|
||||
import com.dfsek.terra.api.world.Chunk;
|
||||
import com.dfsek.terra.api.world.World;
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package com.dfsek.terra.api.structure.buffer.buffers;
|
||||
|
||||
import com.dfsek.terra.api.structure.buffer.items.Cell;
|
||||
|
||||
import net.jafama.FastMath;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
@@ -9,6 +7,7 @@ import java.util.Map;
|
||||
|
||||
import com.dfsek.terra.api.structure.buffer.Buffer;
|
||||
import com.dfsek.terra.api.structure.buffer.BufferedItem;
|
||||
import com.dfsek.terra.api.structure.buffer.items.Cell;
|
||||
import com.dfsek.terra.api.util.vector.Vector3;
|
||||
import com.dfsek.terra.api.world.Chunk;
|
||||
import com.dfsek.terra.api.world.World;
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package com.dfsek.terra.api.structure.configured;
|
||||
|
||||
import com.dfsek.terra.api.util.StringIdentifiable;
|
||||
import com.dfsek.terra.api.structure.Structure;
|
||||
import com.dfsek.terra.api.structure.StructureSpawn;
|
||||
import com.dfsek.terra.api.util.Range;
|
||||
import com.dfsek.terra.api.util.StringIdentifiable;
|
||||
import com.dfsek.terra.api.util.collection.ProbabilityCollection;
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,14 @@
|
||||
package com.dfsek.terra.api.structure.feature;
|
||||
|
||||
public interface Distributor {
|
||||
static Distributor yes() {
|
||||
return (x, z, seed) -> true;
|
||||
}
|
||||
|
||||
static Distributor no() {
|
||||
return (x, z, seed) -> false;
|
||||
}
|
||||
|
||||
boolean matches(int x, int z, long seed);
|
||||
|
||||
default Distributor and(Distributor other) {
|
||||
@@ -10,12 +18,4 @@ public interface Distributor {
|
||||
default Distributor or(Distributor other) {
|
||||
return (x, z, seed) -> this.matches(x, z, seed) || other.matches(x, z, seed);
|
||||
}
|
||||
|
||||
static Distributor yes() {
|
||||
return (x, z, seed) -> true;
|
||||
}
|
||||
|
||||
static Distributor no() {
|
||||
return (x, z, seed) -> false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,8 +16,10 @@ public final class RotationUtil {
|
||||
|
||||
/**
|
||||
* Rotate and mirror a coordinate pair.
|
||||
* @param orig Vector to rotate.
|
||||
*
|
||||
* @param orig Vector to rotate.
|
||||
* @param r Rotation
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static Vector2 rotateVector(Vector2 orig, Rotation r) {
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package com.dfsek.terra.api.world;
|
||||
|
||||
import java.util.function.IntConsumer;
|
||||
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.api.structure.feature.BinaryColumn;
|
||||
|
||||
import java.util.function.IntConsumer;
|
||||
|
||||
|
||||
/**
|
||||
* A single vertical column of a world.
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.dfsek.terra.api.world.generator;
|
||||
|
||||
import com.dfsek.terra.api.util.math.Sampler;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
@@ -9,6 +8,7 @@ import java.util.Random;
|
||||
import com.dfsek.terra.api.Platform;
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.api.config.ConfigPack;
|
||||
import com.dfsek.terra.api.util.math.Sampler;
|
||||
import com.dfsek.terra.api.util.vector.Vector3;
|
||||
import com.dfsek.terra.api.world.BiomeGrid;
|
||||
import com.dfsek.terra.api.world.World;
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.dfsek.terra.api.world.generator;
|
||||
|
||||
import com.dfsek.terra.api.util.math.Sampler;
|
||||
|
||||
|
||||
public interface SamplerCache {
|
||||
Sampler get(int x, int z);
|
||||
|
||||
|
||||
@@ -13,6 +13,10 @@ import com.dfsek.terra.api.inject.impl.InjectorImpl;
|
||||
* @param <T> Type of object to inject.
|
||||
*/
|
||||
public interface Injector<T> {
|
||||
static <T1> Injector<T1> get(T1 value) {
|
||||
return new InjectorImpl<>(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an explicit class as a target. Useful for applications where subclasses may cause issues with DI.
|
||||
*
|
||||
@@ -38,8 +42,4 @@ public interface Injector<T> {
|
||||
* </ul>
|
||||
*/
|
||||
void inject(Object object) throws InjectionException;
|
||||
|
||||
static <T1> Injector<T1> get(T1 value) {
|
||||
return new InjectorImpl<>(value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ import com.dfsek.terra.api.event.EventManager;
|
||||
import com.dfsek.terra.api.event.events.platform.PlatformInitializationEvent;
|
||||
import com.dfsek.terra.api.event.functional.FunctionalEventHandler;
|
||||
import com.dfsek.terra.api.inject.Injector;
|
||||
import com.dfsek.terra.api.inject.impl.InjectorImpl;
|
||||
import com.dfsek.terra.api.lang.Language;
|
||||
import com.dfsek.terra.api.profiler.Profiler;
|
||||
import com.dfsek.terra.api.registry.CheckedRegistry;
|
||||
@@ -41,7 +42,6 @@ import com.dfsek.terra.config.GenericLoaders;
|
||||
import com.dfsek.terra.config.PluginConfigImpl;
|
||||
import com.dfsek.terra.config.lang.LangUtil;
|
||||
import com.dfsek.terra.event.EventManagerImpl;
|
||||
import com.dfsek.terra.api.inject.impl.InjectorImpl;
|
||||
import com.dfsek.terra.profiler.ProfilerImpl;
|
||||
import com.dfsek.terra.registry.CheckedRegistryImpl;
|
||||
import com.dfsek.terra.registry.LockedRegistryImpl;
|
||||
|
||||
@@ -1,12 +1,6 @@
|
||||
package com.dfsek.terra;
|
||||
|
||||
import com.dfsek.terra.api.addon.BaseAddon;
|
||||
import com.dfsek.terra.api.addon.TerraAddon;
|
||||
import com.dfsek.terra.api.addon.annotations.Addon;
|
||||
import com.dfsek.terra.api.addon.annotations.Author;
|
||||
import com.dfsek.terra.api.addon.annotations.Version;
|
||||
import com.dfsek.terra.api.event.events.platform.PlatformInitializationEvent;
|
||||
import com.dfsek.terra.api.event.functional.FunctionalEventHandler;
|
||||
|
||||
|
||||
public class InternalAddon implements BaseAddon {
|
||||
|
||||
@@ -27,6 +27,7 @@ public class PacksCommand implements CommandTemplate {
|
||||
}
|
||||
|
||||
LangUtil.send("command.packs.main", sender);
|
||||
registry.entries().forEach(entry -> LangUtil.send("command.packs.pack", sender, entry.getID(), entry.getAuthor(), entry.getVersion()));
|
||||
registry.entries().forEach(
|
||||
entry -> LangUtil.send("command.packs.pack", sender, entry.getID(), entry.getAuthor(), entry.getVersion()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package com.dfsek.terra.commands;
|
||||
|
||||
import com.dfsek.terra.api.Platform;
|
||||
|
||||
import net.jafama.FastMath;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
@@ -14,6 +12,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.dfsek.terra.api.Platform;
|
||||
import com.dfsek.terra.api.command.CommandManager;
|
||||
import com.dfsek.terra.api.command.CommandTemplate;
|
||||
import com.dfsek.terra.api.command.annotation.Argument;
|
||||
@@ -35,8 +34,8 @@ import com.dfsek.terra.api.command.tab.TabCompleter;
|
||||
import com.dfsek.terra.api.entity.CommandSender;
|
||||
import com.dfsek.terra.api.entity.Player;
|
||||
import com.dfsek.terra.api.inject.exception.InjectionException;
|
||||
import com.dfsek.terra.api.util.reflection.ReflectionUtil;
|
||||
import com.dfsek.terra.api.inject.impl.InjectorImpl;
|
||||
import com.dfsek.terra.api.util.reflection.ReflectionUtil;
|
||||
|
||||
|
||||
public class TerraCommandManager implements CommandManager {
|
||||
|
||||
@@ -6,7 +6,6 @@ import java.util.LinkedHashMap;
|
||||
|
||||
import com.dfsek.terra.api.Platform;
|
||||
import com.dfsek.terra.api.addon.BaseAddon;
|
||||
import com.dfsek.terra.api.addon.TerraAddon;
|
||||
import com.dfsek.terra.api.block.BlockType;
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.api.tectonic.LoaderRegistrar;
|
||||
|
||||
@@ -13,8 +13,8 @@ import java.io.IOException;
|
||||
import java.io.UncheckedIOException;
|
||||
import java.time.Duration;
|
||||
|
||||
import com.dfsek.terra.api.util.Logger;
|
||||
import com.dfsek.terra.api.Platform;
|
||||
import com.dfsek.terra.api.util.Logger;
|
||||
|
||||
|
||||
@SuppressWarnings("FieldMayBeFinal")
|
||||
|
||||
@@ -3,10 +3,10 @@ package com.dfsek.terra.config.lang;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import com.dfsek.terra.api.util.Logger;
|
||||
import com.dfsek.terra.api.Platform;
|
||||
import com.dfsek.terra.api.entity.CommandSender;
|
||||
import com.dfsek.terra.api.lang.Language;
|
||||
import com.dfsek.terra.api.util.Logger;
|
||||
|
||||
|
||||
public final class LangUtil {
|
||||
|
||||
@@ -10,6 +10,7 @@ import java.util.Set;
|
||||
import com.dfsek.terra.api.addon.TerraAddon;
|
||||
|
||||
|
||||
@SuppressWarnings("FieldMayBeFinal")
|
||||
public class ConfigPackAddonsTemplate implements ConfigTemplate {
|
||||
@Value("addons")
|
||||
@Default
|
||||
|
||||
@@ -123,7 +123,8 @@ public class ConfigPackImpl implements ConfigPack {
|
||||
selfLoader.load(addonsTemplate, configuration);
|
||||
this.addons = addonsTemplate.getAddons();
|
||||
|
||||
platform.getEventManager().callEvent(new ConfigPackPreLoadEvent(this, template -> selfLoader.load(template, configuration)));
|
||||
platform.getEventManager().callEvent(
|
||||
new ConfigPackPreLoadEvent(this, template -> selfLoader.load(template, configuration)));
|
||||
|
||||
selfLoader.load(template, configuration);
|
||||
|
||||
@@ -173,7 +174,8 @@ public class ConfigPackImpl implements ConfigPack {
|
||||
selfLoader.load(addonsTemplate, configuration);
|
||||
this.addons = addonsTemplate.getAddons();
|
||||
|
||||
platform.getEventManager().callEvent(new ConfigPackPreLoadEvent(this, template -> selfLoader.load(template, configuration)));
|
||||
platform.getEventManager().callEvent(
|
||||
new ConfigPackPreLoadEvent(this, template -> selfLoader.load(template, configuration)));
|
||||
|
||||
|
||||
selfLoader.load(template, configuration);
|
||||
@@ -364,11 +366,13 @@ public class ConfigPackImpl implements ConfigPack {
|
||||
private void checkDeadEntries(Platform platform) {
|
||||
registryMap.forEach((clazz, pair) -> ((OpenRegistryImpl<?>) pair.getLeft()).getDeadEntries()
|
||||
.forEach((id, value) -> platform.getDebugLogger()
|
||||
.warning("Dead entry in '" +
|
||||
ReflectionUtil.typeToString(
|
||||
clazz) +
|
||||
"' registry: '" +
|
||||
id + "'")));
|
||||
.warning(
|
||||
"Dead entry in" +
|
||||
" '" +
|
||||
ReflectionUtil.typeToString(
|
||||
clazz) +
|
||||
"' registry: '" +
|
||||
id + "'")));
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package com.dfsek.terra.event;
|
||||
|
||||
import com.dfsek.terra.api.addon.BaseAddon;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
@@ -9,7 +7,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import com.dfsek.terra.api.addon.TerraAddon;
|
||||
import com.dfsek.terra.api.addon.BaseAddon;
|
||||
import com.dfsek.terra.api.event.events.Event;
|
||||
import com.dfsek.terra.api.event.events.FailThroughEvent;
|
||||
import com.dfsek.terra.api.event.functional.EventContext;
|
||||
|
||||
@@ -12,7 +12,6 @@ import java.util.Map;
|
||||
|
||||
import com.dfsek.terra.api.Platform;
|
||||
import com.dfsek.terra.api.addon.BaseAddon;
|
||||
import com.dfsek.terra.api.addon.TerraAddon;
|
||||
import com.dfsek.terra.api.event.events.Event;
|
||||
import com.dfsek.terra.api.event.events.FailThroughEvent;
|
||||
import com.dfsek.terra.api.event.events.PackEvent;
|
||||
|
||||
@@ -25,9 +25,8 @@ import com.dfsek.terra.api.registry.exception.DuplicateEntryException;
|
||||
*/
|
||||
public class OpenRegistryImpl<T> implements OpenRegistry<T> {
|
||||
private static final Entry<?> NULL = new Entry<>(null);
|
||||
private final Map<String, Entry<T>> objects;
|
||||
|
||||
private static final Pattern ID_PATTERN = Pattern.compile("^[a-zA-Z0-9_-]*$");
|
||||
private final Map<String, Entry<T>> objects;
|
||||
|
||||
public OpenRegistryImpl() {
|
||||
objects = new HashMap<>();
|
||||
@@ -69,7 +68,9 @@ public class OpenRegistryImpl<T> implements OpenRegistry<T> {
|
||||
|
||||
public boolean register(String identifier, Entry<T> value) {
|
||||
if(!ID_PATTERN.matcher(identifier).matches())
|
||||
throw new IllegalArgumentException("Registry ID must only contain alphanumeric characters, hyphens, and underscores. \"" + identifier + "\" is not a valid ID.");
|
||||
throw new IllegalArgumentException(
|
||||
"Registry ID must only contain alphanumeric characters, hyphens, and underscores. \"" + identifier +
|
||||
"\" is not a valid ID.");
|
||||
boolean exists = objects.containsKey(identifier);
|
||||
objects.put(identifier, value);
|
||||
return exists;
|
||||
|
||||
@@ -14,8 +14,8 @@ import com.dfsek.terra.addon.exception.AddonLoadException;
|
||||
import com.dfsek.terra.api.Platform;
|
||||
import com.dfsek.terra.api.addon.TerraAddon;
|
||||
import com.dfsek.terra.api.inject.exception.InjectionException;
|
||||
import com.dfsek.terra.api.registry.exception.DuplicateEntryException;
|
||||
import com.dfsek.terra.api.inject.impl.InjectorImpl;
|
||||
import com.dfsek.terra.api.registry.exception.DuplicateEntryException;
|
||||
import com.dfsek.terra.registry.OpenRegistryImpl;
|
||||
|
||||
|
||||
|
||||
@@ -1,16 +1,15 @@
|
||||
package com.dfsek.terra.world;
|
||||
|
||||
import com.dfsek.terra.api.Platform;
|
||||
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.cache.CacheLoader;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
import net.jafama.FastMath;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import com.dfsek.terra.api.Platform;
|
||||
import com.dfsek.terra.api.util.MathUtil;
|
||||
import com.dfsek.terra.api.world.World;
|
||||
import com.dfsek.terra.api.util.math.Sampler;
|
||||
import com.dfsek.terra.api.world.World;
|
||||
|
||||
|
||||
public class SamplerCacheImpl implements com.dfsek.terra.api.world.generator.SamplerCache {
|
||||
|
||||
@@ -1,40 +1,14 @@
|
||||
package profiler;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import com.dfsek.terra.api.profiler.Profiler;
|
||||
import com.dfsek.terra.profiler.ProfilerImpl;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
|
||||
public class ProfilerTest {
|
||||
private static final Profiler PROFILER = new ProfilerImpl();
|
||||
|
||||
@Test
|
||||
public void testProfiler() throws InterruptedException {
|
||||
//PROFILER.start();
|
||||
for(int i = 0; i < 100; i++) {
|
||||
doThing();
|
||||
}
|
||||
|
||||
for(int i = 0; i < 100; i++) {
|
||||
doThirdOtherThing();
|
||||
}
|
||||
|
||||
for(int i = 0; i < 100; i++) {
|
||||
doOtherThing();
|
||||
}
|
||||
PROFILER.stop();
|
||||
PROFILER.push("thing");
|
||||
PROFILER.push("thing2");
|
||||
PROFILER.start();
|
||||
PROFILER.pop("thing2");
|
||||
PROFILER.pop("thing");
|
||||
PROFILER.push("thing4");
|
||||
PROFILER.pop("thing4");
|
||||
|
||||
PROFILER.getTimings().forEach((id, timings) -> System.out.println(id + ": " + timings.toString()));
|
||||
}
|
||||
|
||||
private static void doThing() throws InterruptedException {
|
||||
PROFILER.push("thing");
|
||||
Thread.sleep(1);
|
||||
@@ -62,4 +36,30 @@ public class ProfilerTest {
|
||||
Thread.sleep(2);
|
||||
PROFILER.pop("thing4");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProfiler() throws InterruptedException {
|
||||
//PROFILER.start();
|
||||
for(int i = 0; i < 100; i++) {
|
||||
doThing();
|
||||
}
|
||||
|
||||
for(int i = 0; i < 100; i++) {
|
||||
doThirdOtherThing();
|
||||
}
|
||||
|
||||
for(int i = 0; i < 100; i++) {
|
||||
doOtherThing();
|
||||
}
|
||||
PROFILER.stop();
|
||||
PROFILER.push("thing");
|
||||
PROFILER.push("thing2");
|
||||
PROFILER.start();
|
||||
PROFILER.pop("thing2");
|
||||
PROFILER.pop("thing");
|
||||
PROFILER.push("thing4");
|
||||
PROFILER.pop("thing4");
|
||||
|
||||
PROFILER.getTimings().forEach((id, timings) -> System.out.println(id + ": " + timings.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
package registry;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import com.dfsek.terra.api.registry.CheckedRegistry;
|
||||
import com.dfsek.terra.api.registry.OpenRegistry;
|
||||
|
||||
import com.dfsek.terra.api.registry.exception.DuplicateEntryException;
|
||||
import com.dfsek.terra.registry.CheckedRegistryImpl;
|
||||
import com.dfsek.terra.registry.OpenRegistryImpl;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
|
||||
@@ -25,7 +24,7 @@ public class RegistryTest {
|
||||
@Test
|
||||
public void openRegistryChecked() {
|
||||
OpenRegistry<String> test = new OpenRegistryImpl<>();
|
||||
|
||||
|
||||
test.registerChecked("test", "bazinga");
|
||||
|
||||
try {
|
||||
@@ -41,7 +40,7 @@ public class RegistryTest {
|
||||
CheckedRegistry<String> test = new CheckedRegistryImpl<>(new OpenRegistryImpl<>());
|
||||
|
||||
test.register("test", "bazinga");
|
||||
|
||||
|
||||
assertEquals(test.get("test"), "bazinga");
|
||||
|
||||
try {
|
||||
|
||||
@@ -1,10 +1,5 @@
|
||||
package com.dfsek.terra.addon;
|
||||
|
||||
import com.dfsek.terra.addon.exception.AddonLoadException;
|
||||
import com.dfsek.terra.api.Platform;
|
||||
import com.dfsek.terra.api.addon.bootstrap.BootstrapBaseAddon;
|
||||
import com.dfsek.terra.api.inject.Injector;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.UncheckedIOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
@@ -14,6 +9,10 @@ import java.nio.file.Path;
|
||||
import java.util.jar.JarFile;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.dfsek.terra.addon.exception.AddonLoadException;
|
||||
import com.dfsek.terra.api.Platform;
|
||||
import com.dfsek.terra.api.addon.bootstrap.BootstrapBaseAddon;
|
||||
|
||||
|
||||
public class BootstrapAddonLoader implements BootstrapBaseAddon<BootstrapBaseAddon<?>> {
|
||||
private final Platform platform;
|
||||
@@ -32,13 +31,13 @@ public class BootstrapAddonLoader implements BootstrapBaseAddon<BootstrapBaseAdd
|
||||
platform.logger().info("Loading bootstrap addon from JAR " + path);
|
||||
JarFile jar = new JarFile(path.toFile());
|
||||
String entry = jar.getManifest().getMainAttributes().getValue("Bootstrap-Addon-Entry-Point");
|
||||
|
||||
|
||||
if(entry == null) {
|
||||
throw new AddonLoadException("No Bootstrap-Addon-Entry-Point attribute defined in addon manifest.");
|
||||
}
|
||||
|
||||
AddonClassLoader loader = new AddonClassLoader(new URL[] {path.toUri().toURL()}, parent);
|
||||
|
||||
|
||||
AddonClassLoader loader = new AddonClassLoader(new URL[]{ path.toUri().toURL() }, parent);
|
||||
|
||||
try {
|
||||
Object in = loader.loadClass(entry).getConstructor().newInstance();
|
||||
if(!(in instanceof BootstrapBaseAddon)) {
|
||||
@@ -53,7 +52,7 @@ public class BootstrapAddonLoader implements BootstrapBaseAddon<BootstrapBaseAdd
|
||||
} catch(ClassNotFoundException e) {
|
||||
throw new AddonLoadException("Entry point " + entry + " not found in JAR.");
|
||||
}
|
||||
|
||||
|
||||
} catch(IOException e) {
|
||||
throw new UncheckedIOException(e);
|
||||
}
|
||||
|
||||
@@ -7,14 +7,12 @@ import org.bukkit.entity.EntityType;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Locale;
|
||||
import java.util.Optional;
|
||||
|
||||
import com.dfsek.terra.AbstractPlatform;
|
||||
import com.dfsek.terra.api.util.Logger;
|
||||
import com.dfsek.terra.api.addon.TerraAddon;
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.api.handle.ItemHandle;
|
||||
import com.dfsek.terra.api.handle.WorldHandle;
|
||||
import com.dfsek.terra.api.util.Logger;
|
||||
import com.dfsek.terra.api.world.biome.Biome;
|
||||
import com.dfsek.terra.bukkit.handles.BukkitItemHandle;
|
||||
import com.dfsek.terra.bukkit.handles.BukkitWorldHandle;
|
||||
@@ -83,11 +81,6 @@ public class PlatformImpl extends AbstractPlatform {
|
||||
return new JavaLogger(plugin.getLogger());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Optional<TerraAddon> getPlatformAddon() {
|
||||
return Optional.of(new BukkitAddon(this));
|
||||
}
|
||||
|
||||
private BukkitBiome parseBiome(String id) throws LoadException {
|
||||
if(!id.startsWith("minecraft:")) throw new LoadException("Invalid biome identifier " + id);
|
||||
return new BukkitBiome(org.bukkit.block.Biome.valueOf(id.toUpperCase(Locale.ROOT).substring(10)));
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package com.dfsek.terra.bukkit.listeners;
|
||||
|
||||
import com.dfsek.terra.api.Platform;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.TreeType;
|
||||
import org.bukkit.block.Block;
|
||||
@@ -11,6 +9,7 @@ import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.world.StructureGrowEvent;
|
||||
|
||||
import com.dfsek.terra.api.Platform;
|
||||
import com.dfsek.terra.api.config.WorldConfig;
|
||||
import com.dfsek.terra.api.util.vector.Vector3;
|
||||
import com.dfsek.terra.api.world.Tree;
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package com.dfsek.terra.bukkit.listeners;
|
||||
|
||||
import com.dfsek.terra.api.Platform;
|
||||
|
||||
import io.papermc.paper.event.world.StructureLocateEvent;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
import com.dfsek.terra.api.Platform;
|
||||
|
||||
|
||||
public class PaperListener implements Listener {
|
||||
private final Platform platform;
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package com.dfsek.terra.bukkit.listeners;
|
||||
|
||||
import com.dfsek.terra.api.Platform;
|
||||
|
||||
import org.bukkit.entity.Villager;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
@@ -10,6 +8,8 @@ import org.bukkit.event.entity.EntitySpawnEvent;
|
||||
import org.bukkit.event.entity.VillagerAcquireTradeEvent;
|
||||
import org.bukkit.event.entity.VillagerCareerChangeEvent;
|
||||
|
||||
import com.dfsek.terra.api.Platform;
|
||||
|
||||
|
||||
/**
|
||||
* Listener to load on Spigot servers, contains Villager crash prevention and hacky ender eye redirection.
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package com.dfsek.terra.bukkit.population;
|
||||
|
||||
import com.dfsek.terra.api.Platform;
|
||||
|
||||
import org.bukkit.generator.BlockPopulator;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -10,6 +8,7 @@ import java.io.IOException;
|
||||
import java.util.HashSet;
|
||||
import java.util.Random;
|
||||
|
||||
import com.dfsek.terra.api.Platform;
|
||||
import com.dfsek.terra.api.profiler.ProfileFrame;
|
||||
import com.dfsek.terra.api.world.Chunk;
|
||||
import com.dfsek.terra.api.world.World;
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
package com.dfsek.terra.bukkit.world;
|
||||
|
||||
import com.dfsek.terra.api.Platform;
|
||||
|
||||
import org.bukkit.TreeType;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.Random;
|
||||
|
||||
import com.dfsek.terra.api.Platform;
|
||||
import com.dfsek.terra.api.handle.WorldHandle;
|
||||
import com.dfsek.terra.api.profiler.ProfileFrame;
|
||||
import com.dfsek.terra.api.util.collection.MaterialSet;
|
||||
|
||||
@@ -2,10 +2,6 @@ package com.dfsek.terra.fabric;
|
||||
|
||||
import com.dfsek.tectonic.exception.LoadException;
|
||||
import com.dfsek.tectonic.loading.TypeRegistry;
|
||||
|
||||
import com.dfsek.terra.fabric.generation.FabricChunkGeneratorWrapper;
|
||||
import com.dfsek.terra.fabric.util.FabricUtil;
|
||||
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.util.Identifier;
|
||||
@@ -14,16 +10,15 @@ 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;
|
||||
import com.dfsek.terra.api.addon.TerraAddon;
|
||||
import com.dfsek.terra.api.handle.ItemHandle;
|
||||
import com.dfsek.terra.api.handle.WorldHandle;
|
||||
import com.dfsek.terra.api.util.Logger;
|
||||
import com.dfsek.terra.api.util.generic.Lazy;
|
||||
import com.dfsek.terra.config.lang.LangUtil;
|
||||
import com.dfsek.terra.fabric.generation.FabricChunkGeneratorWrapper;
|
||||
import com.dfsek.terra.fabric.handle.FabricItemHandle;
|
||||
import com.dfsek.terra.fabric.handle.FabricWorldHandle;
|
||||
import com.dfsek.terra.fabric.util.ProtoBiome;
|
||||
@@ -37,20 +32,20 @@ public class PlatformImpl extends AbstractPlatform {
|
||||
|
||||
private final Set<ServerWorld> worlds = new HashSet<>();
|
||||
|
||||
public void addWorld(ServerWorld world) {
|
||||
worlds.add(world);
|
||||
}
|
||||
|
||||
public PlatformImpl() {
|
||||
load();
|
||||
}
|
||||
|
||||
public void addWorld(ServerWorld world) {
|
||||
worlds.add(world);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean reload() {
|
||||
getTerraConfig().load(this);
|
||||
LangUtil.load(getTerraConfig().getLanguage(), this); // Load language.
|
||||
boolean succeed = getRawConfigRegistry().loadAll(this);
|
||||
|
||||
|
||||
worlds.forEach(world -> {
|
||||
FabricChunkGeneratorWrapper chunkGeneratorWrapper = ((FabricChunkGeneratorWrapper) world.getChunkManager().getChunkGenerator());
|
||||
chunkGeneratorWrapper.setPack(getConfigRegistry().get(chunkGeneratorWrapper.getPack().getID()));
|
||||
|
||||
@@ -60,9 +60,8 @@ public class FabricChunkGeneratorWrapper extends net.minecraft.world.gen.chunk.C
|
||||
);
|
||||
|
||||
private final long seed;
|
||||
private ChunkGenerator delegate;
|
||||
private final TerraBiomeSource biomeSource;
|
||||
|
||||
private ChunkGenerator delegate;
|
||||
private ConfigPack pack;
|
||||
private ServerWorld world;
|
||||
|
||||
@@ -77,14 +76,6 @@ public class FabricChunkGeneratorWrapper extends net.minecraft.world.gen.chunk.C
|
||||
this.seed = seed;
|
||||
}
|
||||
|
||||
public void setPack(ConfigPack pack) {
|
||||
this.pack = pack;
|
||||
this.delegate = pack.getGeneratorProvider().newInstance(pack);
|
||||
biomeSource.setPack(pack);
|
||||
|
||||
delegate.getPlatform().logger().info("Loading world with config pack " + pack.getID());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Codec<? extends net.minecraft.world.gen.chunk.ChunkGenerator> getCodec() {
|
||||
return CODEC;
|
||||
@@ -235,6 +226,14 @@ public class FabricChunkGeneratorWrapper extends net.minecraft.world.gen.chunk.C
|
||||
return pack;
|
||||
}
|
||||
|
||||
public void setPack(ConfigPack pack) {
|
||||
this.pack = pack;
|
||||
this.delegate = pack.getGeneratorProvider().newInstance(pack);
|
||||
biomeSource.setPack(pack);
|
||||
|
||||
delegate.getPlatform().logger().info("Loading world with config pack " + pack.getID());
|
||||
}
|
||||
|
||||
public void setWorld(ServerWorld world) {
|
||||
this.world = world;
|
||||
}
|
||||
|
||||
@@ -36,10 +36,6 @@ public class TerraBiomeSource extends BiomeSource {
|
||||
private final long seed;
|
||||
private ConfigPack pack;
|
||||
|
||||
public void setPack(ConfigPack pack) {
|
||||
this.pack = pack;
|
||||
}
|
||||
|
||||
public TerraBiomeSource(Registry<Biome> biomes, long seed, ConfigPack pack) {
|
||||
super(biomes.stream()
|
||||
.filter(biome -> Objects.requireNonNull(biomes.getId(biome))
|
||||
@@ -51,6 +47,10 @@ public class TerraBiomeSource extends BiomeSource {
|
||||
this.pack = pack;
|
||||
}
|
||||
|
||||
public void setPack(ConfigPack pack) {
|
||||
this.pack = pack;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Codec<? extends BiomeSource> getCodec() {
|
||||
return CODEC;
|
||||
|
||||
@@ -18,6 +18,7 @@ public class ServerMainMixin {
|
||||
"Lnet/minecraft/util/registry/DynamicRegistryManager$Impl;"))
|
||||
private static void injectConstructor(String[] args, CallbackInfo ci) {
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ public class DirectWorld implements World {
|
||||
|
||||
@Override
|
||||
public void setBlockData(int x, int y, int z, BlockState data, boolean physics) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -5,9 +5,9 @@ import org.spongepowered.api.Sponge;
|
||||
import java.io.File;
|
||||
|
||||
import com.dfsek.terra.AbstractPlatform;
|
||||
import com.dfsek.terra.api.util.Logger;
|
||||
import com.dfsek.terra.api.handle.ItemHandle;
|
||||
import com.dfsek.terra.api.handle.WorldHandle;
|
||||
import com.dfsek.terra.api.util.Logger;
|
||||
import com.dfsek.terra.sponge.handle.SpongeWorldHandle;
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user