mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-05-20 16:50:28 +00:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 69ae803074 | |||
| 8f9fc3e08f | |||
| 92339c904d | |||
| 56fb510d96 | |||
| 5821302eb8 | |||
| 901677d2c3 |
@@ -7,7 +7,7 @@ to your specifications, with no knowledge of Java required.
|
||||
|
||||
* Paper+ servers (Paper, Tuinity, Purpur, etc): [SpigotMC](https://www.spigotmc.org/resources/85151/)
|
||||
* Fabric: [Modrinth](https://modrinth.com/mod/terra) / [CurseForge](https://www.curseforge.com/minecraft/mc-mods/terra-world-generator)
|
||||
* Forge **(ALPHA - NOT PRODUCTION-READY)**: [Modrinth](https://modrinth.com/mod/terra) / [CurseForge](https://www.curseforge.com/minecraft/mc-mods/terra-world-generator)
|
||||
* Forge: [Modrinth](https://modrinth.com/mod/terra) / [CurseForge](https://www.curseforge.com/minecraft/mc-mods/terra-world-generator)
|
||||
|
||||
## Building and Running Terra
|
||||
|
||||
@@ -32,15 +32,15 @@ To run Minecraft with Terra in the IDE (for testing) use the following tasks:
|
||||
* `runPaper` - Run the Paper test server with Terra (`installPaper` must have been run previously).
|
||||
* `runPurpur` - Run the Purpur test server with Terra (`installPurpur` must have been run previously).
|
||||
* Fabric
|
||||
* `runClient` - Run a Minecraft Fabric client with Terra installed.
|
||||
* `runServer` - Run a Minecraft Fabric server with Terra installed.
|
||||
* `runClient` - Run a Minecraft client with Terra installed.
|
||||
* `runServer` - Run a Minecraft server with Terra installed.
|
||||
* Forge
|
||||
* `runClient` - Run a Minecraft Forge client with Terra installed.
|
||||
* `runServer` - Run a Minecraft Forge server with Terra installed.
|
||||
* `runClient` - Run a Minecraft client with Terra installed.
|
||||
* `runServer` - Run a Minecraft server with Terra installed.
|
||||
## Contributing
|
||||
Contributions are welcome! If you want to see a feature in Terra, please, open an issue, or implement it yourself and
|
||||
submit a PR!
|
||||
Join the discord [here](https://discord.gg/PXUEbbF) if you would like to talk more about the project!
|
||||
|
||||
## Beta
|
||||
Terra is still in beta! While it is stable, it is not feature-complete. There is a lot to be added!
|
||||
Terra is still in beta! While it is stable, it is not feature-complete. There is a lot to be added!
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
import com.dfsek.terra.getGitHash
|
||||
|
||||
val versionObj = Version("5", "3", "3", true)
|
||||
val versionObj = Version("5", "3", "0", true)
|
||||
|
||||
allprojects {
|
||||
version = versionObj
|
||||
|
||||
@@ -29,12 +29,7 @@ fun Project.configureCompilation() {
|
||||
include("**/*.*")
|
||||
filter<org.apache.tools.ant.filters.ReplaceTokens>(
|
||||
"tokens" to mapOf(
|
||||
"VERSION" to project.version.toString(),
|
||||
"DESCRIPTION" to project.properties["terra.description"],
|
||||
"WIKI" to project.properties["terra.wiki"],
|
||||
"SOURCE" to project.properties["terra.source"],
|
||||
"ISSUES" to project.properties["terra.issues"],
|
||||
"LICENSE" to project.properties["terra.license"]
|
||||
"VERSION" to project.version.toString()
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -4,10 +4,10 @@ import com.dfsek.terra.api.addons.TerraAddon;
|
||||
import com.dfsek.terra.api.event.EventManager;
|
||||
import com.dfsek.terra.api.platform.handle.ItemHandle;
|
||||
import com.dfsek.terra.api.platform.handle.WorldHandle;
|
||||
import com.dfsek.terra.api.platform.modloader.Mod;
|
||||
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;
|
||||
@@ -20,8 +20,6 @@ import com.dfsek.terra.world.TerraWorld;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
import java.util.jar.JarFile;
|
||||
|
||||
/**
|
||||
@@ -79,7 +77,5 @@ public interface TerraPlugin extends LoaderRegistrar {
|
||||
return JarUtil.getJarFile();
|
||||
}
|
||||
|
||||
default Set<Mod> getMods() {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
TaskScheduler getScheduler();
|
||||
}
|
||||
|
||||
+1
-25
@@ -1,9 +1,6 @@
|
||||
package com.dfsek.terra.api.event.events.config;
|
||||
|
||||
import com.dfsek.tectonic.config.ConfigTemplate;
|
||||
import com.dfsek.tectonic.exception.ConfigException;
|
||||
import com.dfsek.terra.api.event.events.PackEvent;
|
||||
import com.dfsek.terra.config.fileloaders.Loader;
|
||||
import com.dfsek.terra.config.pack.ConfigPack;
|
||||
|
||||
/**
|
||||
@@ -11,34 +8,13 @@ import com.dfsek.terra.config.pack.ConfigPack;
|
||||
*/
|
||||
public abstract class ConfigPackLoadEvent implements PackEvent {
|
||||
private final ConfigPack pack;
|
||||
private final ExceptionalConsumer<ConfigTemplate> configLoader;
|
||||
private final Loader loader;
|
||||
|
||||
public ConfigPackLoadEvent(ConfigPack pack, ExceptionalConsumer<ConfigTemplate> configLoader, Loader loader) {
|
||||
public ConfigPackLoadEvent(ConfigPack pack) {
|
||||
this.pack = pack;
|
||||
this.configLoader = configLoader;
|
||||
this.loader = loader;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigPack getPack() {
|
||||
return pack;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a custom {@link ConfigTemplate} using the pack manifest.
|
||||
*
|
||||
* @param template Template to register.
|
||||
*/
|
||||
public void loadTemplate(ConfigTemplate template) throws ConfigException {
|
||||
configLoader.accept(template);
|
||||
}
|
||||
|
||||
public interface ExceptionalConsumer<T extends ConfigTemplate> {
|
||||
void accept(T value) throws ConfigException;
|
||||
}
|
||||
|
||||
public Loader getLoader() {
|
||||
return loader;
|
||||
}
|
||||
}
|
||||
|
||||
+2
-4
@@ -1,14 +1,12 @@
|
||||
package com.dfsek.terra.api.event.events.config;
|
||||
|
||||
import com.dfsek.tectonic.config.ConfigTemplate;
|
||||
import com.dfsek.terra.config.fileloaders.Loader;
|
||||
import com.dfsek.terra.config.pack.ConfigPack;
|
||||
|
||||
/**
|
||||
* Called when a config pack has finished loading.
|
||||
*/
|
||||
public class ConfigPackPostLoadEvent extends ConfigPackLoadEvent {
|
||||
public ConfigPackPostLoadEvent(ConfigPack pack, ExceptionalConsumer<ConfigTemplate> configTemplateLoader, Loader loader) {
|
||||
super(pack, configTemplateLoader, loader);
|
||||
public ConfigPackPostLoadEvent(ConfigPack pack) {
|
||||
super(pack);
|
||||
}
|
||||
}
|
||||
|
||||
+2
-4
@@ -1,14 +1,12 @@
|
||||
package com.dfsek.terra.api.event.events.config;
|
||||
|
||||
import com.dfsek.tectonic.config.ConfigTemplate;
|
||||
import com.dfsek.terra.config.fileloaders.Loader;
|
||||
import com.dfsek.terra.config.pack.ConfigPack;
|
||||
|
||||
/**
|
||||
* Called before a config pack's registries are filled. At this point, the pack manifest has been loaded, and all registries are empty.
|
||||
*/
|
||||
public class ConfigPackPreLoadEvent extends ConfigPackLoadEvent {
|
||||
public ConfigPackPreLoadEvent(ConfigPack pack, ExceptionalConsumer<ConfigTemplate> configLoader, Loader loader) {
|
||||
super(pack, configLoader, loader);
|
||||
public ConfigPackPreLoadEvent(ConfigPack pack) {
|
||||
super(pack);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
package com.dfsek.terra.api.platform.modloader;
|
||||
|
||||
public interface Mod {
|
||||
String getID();
|
||||
|
||||
String getVersion();
|
||||
|
||||
String getName();
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.dfsek.terra.api.transform;
|
||||
|
||||
public class NotNullValidator<T> implements Validator<T> {
|
||||
@Override
|
||||
public boolean validate(T value) {
|
||||
return !(value == null);
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,6 @@
|
||||
package com.dfsek.terra.api.transform;
|
||||
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public interface Validator<T> {
|
||||
boolean validate(T value) throws TransformException;
|
||||
|
||||
static <T> Validator<T> notNull() {
|
||||
return Objects::nonNull;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,8 +46,6 @@ import com.dfsek.terra.config.loaders.config.sampler.templates.ImageSamplerTempl
|
||||
import com.dfsek.terra.config.loaders.config.sampler.templates.normalizer.ClampNormalizerTemplate;
|
||||
import com.dfsek.terra.config.loaders.config.sampler.templates.normalizer.LinearNormalizerTemplate;
|
||||
import com.dfsek.terra.config.loaders.config.sampler.templates.normalizer.NormalNormalizerTemplate;
|
||||
import com.dfsek.terra.config.loaders.mod.ModDependentConfigSection;
|
||||
import com.dfsek.terra.config.loaders.mod.ModDependentConfigSectionLoader;
|
||||
import com.dfsek.terra.config.loaders.palette.CarverPaletteLoader;
|
||||
import com.dfsek.terra.config.loaders.palette.PaletteHolderLoader;
|
||||
import com.dfsek.terra.config.loaders.palette.PaletteLayerLoader;
|
||||
@@ -110,8 +108,7 @@ public class GenericLoaders implements LoaderRegistrar {
|
||||
|
||||
if(main != null) {
|
||||
registry.registerLoader(TerraAddon.class, main.getAddons())
|
||||
.registerLoader(BlockType.class, (t, object, cf) -> main.getWorldHandle().createBlockData((String) object).getBlockType())
|
||||
.registerLoader(ModDependentConfigSection.class, new ModDependentConfigSectionLoader(main));
|
||||
.registerLoader(BlockType.class, (t, object, cf) -> main.getWorldHandle().createBlockData((String) object).getBlockType());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,147 @@
|
||||
package com.dfsek.terra.config.builder;
|
||||
|
||||
import com.dfsek.paralithic.eval.parser.Scope;
|
||||
import com.dfsek.paralithic.eval.tokenizer.ParseException;
|
||||
import com.dfsek.terra.api.math.noise.NoiseSampler;
|
||||
import com.dfsek.terra.api.math.noise.samplers.ExpressionSampler;
|
||||
import com.dfsek.terra.api.math.noise.samplers.noise.ConstantSampler;
|
||||
import com.dfsek.terra.api.util.seeded.NoiseSeeded;
|
||||
import com.dfsek.terra.api.world.palette.holder.PaletteHolder;
|
||||
import com.dfsek.terra.config.loaders.config.function.FunctionTemplate;
|
||||
import com.dfsek.terra.world.generation.WorldGenerator;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class GeneratorBuilder {
|
||||
private final Map<Long, WorldGenerator> gens = Collections.synchronizedMap(new HashMap<>());
|
||||
|
||||
private String noiseEquation;
|
||||
|
||||
private String elevationEquation;
|
||||
|
||||
private String carvingEquation;
|
||||
|
||||
private Scope varScope;
|
||||
|
||||
private Map<String, NoiseSeeded> noiseBuilderMap;
|
||||
|
||||
private Map<String, FunctionTemplate> functionTemplateMap;
|
||||
|
||||
private PaletteHolder palettes;
|
||||
|
||||
private PaletteHolder slantPalettes;
|
||||
|
||||
private boolean preventInterpolation;
|
||||
|
||||
private boolean interpolateElevation;
|
||||
|
||||
private NoiseSeeded biomeNoise;
|
||||
|
||||
private double elevationWeight;
|
||||
|
||||
private int blendDistance;
|
||||
|
||||
private int blendStep;
|
||||
|
||||
private double blendWeight;
|
||||
|
||||
public WorldGenerator build(long seed) {
|
||||
synchronized(gens) {
|
||||
return gens.computeIfAbsent(seed, k -> {
|
||||
NoiseSampler noise;
|
||||
NoiseSampler elevation;
|
||||
NoiseSampler carving;
|
||||
try {
|
||||
noise = new ExpressionSampler(noiseEquation, varScope, seed, noiseBuilderMap, functionTemplateMap);
|
||||
elevation = elevationEquation == null ? new ConstantSampler(0) : new ExpressionSampler(elevationEquation, varScope, seed, noiseBuilderMap, functionTemplateMap);
|
||||
carving = new ExpressionSampler(carvingEquation, varScope, seed, noiseBuilderMap, functionTemplateMap);
|
||||
} catch(ParseException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return new WorldGenerator(palettes, slantPalettes, noise, elevation, carving, biomeNoise.apply(seed), elevationWeight, blendDistance, blendStep, blendWeight);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public void setBlendWeight(double blendWeight) {
|
||||
this.blendWeight = blendWeight;
|
||||
}
|
||||
|
||||
public void setFunctionTemplateMap(Map<String, FunctionTemplate> functionTemplateMap) {
|
||||
this.functionTemplateMap = functionTemplateMap;
|
||||
}
|
||||
|
||||
public void setBlendStep(int blendStep) {
|
||||
this.blendStep = blendStep;
|
||||
}
|
||||
|
||||
public void setBlendDistance(int blendDistance) {
|
||||
this.blendDistance = blendDistance;
|
||||
}
|
||||
|
||||
public void setBiomeNoise(NoiseSeeded biomeNoise) {
|
||||
this.biomeNoise = biomeNoise;
|
||||
}
|
||||
|
||||
public void setElevationWeight(double elevationWeight) {
|
||||
this.elevationWeight = elevationWeight;
|
||||
}
|
||||
|
||||
public void setNoiseEquation(String noiseEquation) {
|
||||
this.noiseEquation = noiseEquation;
|
||||
}
|
||||
|
||||
public void setElevationEquation(String elevationEquation) {
|
||||
this.elevationEquation = elevationEquation;
|
||||
}
|
||||
|
||||
public void setCarvingEquation(String carvingEquation) {
|
||||
this.carvingEquation = carvingEquation;
|
||||
}
|
||||
|
||||
public Scope getVarScope() {
|
||||
return varScope;
|
||||
}
|
||||
|
||||
public void setVarScope(Scope varScope) {
|
||||
this.varScope = varScope;
|
||||
}
|
||||
|
||||
public void setNoiseBuilderMap(Map<String, NoiseSeeded> noiseBuilderMap) {
|
||||
this.noiseBuilderMap = noiseBuilderMap;
|
||||
}
|
||||
|
||||
public PaletteHolder getPalettes() {
|
||||
return palettes;
|
||||
}
|
||||
|
||||
public void setPalettes(PaletteHolder palettes) {
|
||||
this.palettes = palettes;
|
||||
}
|
||||
|
||||
public PaletteHolder getSlantPalettes() {
|
||||
return slantPalettes;
|
||||
}
|
||||
|
||||
public void setSlantPalettes(PaletteHolder slantPalettes) {
|
||||
this.slantPalettes = slantPalettes;
|
||||
}
|
||||
|
||||
public boolean isPreventInterpolation() {
|
||||
return preventInterpolation;
|
||||
}
|
||||
|
||||
public void setPreventInterpolation(boolean preventInterpolation) {
|
||||
this.preventInterpolation = preventInterpolation;
|
||||
}
|
||||
|
||||
public void setInterpolateElevation(boolean interpolateElevation) {
|
||||
this.interpolateElevation = interpolateElevation;
|
||||
}
|
||||
|
||||
public boolean interpolateElevation() {
|
||||
return interpolateElevation;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.dfsek.terra.config.fileloaders;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Enumeration;
|
||||
@@ -21,7 +20,7 @@ public class ZIPLoader extends Loader {
|
||||
ZipEntry entry = entries.nextElement();
|
||||
if(!entry.isDirectory() && entry.getName().equals(singleFile)) return file.getInputStream(entry);
|
||||
}
|
||||
throw new FileNotFoundException("No such file: " + singleFile);
|
||||
throw new IllegalArgumentException("No such file: " + singleFile);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
-46
@@ -1,46 +0,0 @@
|
||||
package com.dfsek.terra.config.loaders.mod;
|
||||
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.platform.modloader.Mod;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class ModDependentConfigSection<T> {
|
||||
private static final Object NULL = new Object(); // Null object
|
||||
private final TerraPlugin main;
|
||||
private final Map<String, T> results = new HashMap<>();
|
||||
private final T defaultValue;
|
||||
@SuppressWarnings("unchecked")
|
||||
private T value = (T) NULL;
|
||||
|
||||
protected ModDependentConfigSection(TerraPlugin main, T defaultValue) {
|
||||
this.main = main;
|
||||
this.defaultValue = defaultValue;
|
||||
}
|
||||
|
||||
public void add(String id, T value) {
|
||||
results.put(id, value);
|
||||
}
|
||||
|
||||
public static <T1> ModDependentConfigSection<T1> withDefault(T1 defaultValue) {
|
||||
return new ModDependentConfigSection<>(null, defaultValue);
|
||||
}
|
||||
|
||||
public T get() {
|
||||
if(value == NULL) value = compute(); // Cache the value.
|
||||
return value;
|
||||
}
|
||||
|
||||
private T compute() {
|
||||
if(main != null) {
|
||||
Set<String> mods = main.getMods().stream().map(Mod::getID).collect(Collectors.toSet());
|
||||
for(Map.Entry<String, T> entry : results.entrySet()) {
|
||||
if(mods.contains(entry.getKey())) return entry.getValue();
|
||||
}
|
||||
}
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
-43
@@ -1,43 +0,0 @@
|
||||
package com.dfsek.terra.config.loaders.mod;
|
||||
|
||||
import com.dfsek.tectonic.exception.LoadException;
|
||||
import com.dfsek.tectonic.loading.ConfigLoader;
|
||||
import com.dfsek.tectonic.loading.TypeLoader;
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Map;
|
||||
|
||||
public class ModDependentConfigSectionLoader implements TypeLoader<ModDependentConfigSection<?>> {
|
||||
private final TerraPlugin main;
|
||||
|
||||
public ModDependentConfigSectionLoader(TerraPlugin main) {
|
||||
this.main = main;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public ModDependentConfigSection<?> load(Type type, Object c, ConfigLoader loader) throws LoadException {
|
||||
if(type instanceof ParameterizedType) {
|
||||
ParameterizedType pType = (ParameterizedType) type;
|
||||
Type generic = pType.getActualTypeArguments()[0];
|
||||
|
||||
if(c instanceof Map && ((Map<?, ?>) c).containsKey("default")) {
|
||||
Map<String, ?> map = (Map<String, ?>) c;
|
||||
|
||||
ModDependentConfigSection<Object> configSection = new ModDependentConfigSection<>(main, loader.loadType(generic, map.get("default")));
|
||||
|
||||
if(map.containsKey("mods")) {
|
||||
for(Map.Entry<String, ?> modEntry : ((Map<String, ?>) map.get("mods")).entrySet()) {
|
||||
configSection.add(modEntry.getKey(), loader.loadType(generic, modEntry.getValue()));
|
||||
}
|
||||
}
|
||||
|
||||
return configSection;
|
||||
} else {
|
||||
return ModDependentConfigSection.withDefault(loader.loadType(generic, c)); // Load the original type otherwise.
|
||||
}
|
||||
} else throw new LoadException("Unable to load config! Could not retrieve parameterized type: " + type);
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,6 @@ package com.dfsek.terra.config.pack;
|
||||
|
||||
import com.dfsek.paralithic.eval.parser.Scope;
|
||||
import com.dfsek.tectonic.abstraction.AbstractConfigLoader;
|
||||
import com.dfsek.tectonic.config.Configuration;
|
||||
import com.dfsek.tectonic.exception.ConfigException;
|
||||
import com.dfsek.tectonic.exception.LoadException;
|
||||
import com.dfsek.tectonic.loading.ConfigLoader;
|
||||
@@ -111,8 +110,6 @@ public class ConfigPack implements LoaderRegistrar {
|
||||
private final TerraPlugin main;
|
||||
private final Loader loader;
|
||||
|
||||
private final Configuration configuration;
|
||||
|
||||
private final BiomeProvider.BiomeProviderBuilder biomeProviderBuilder;
|
||||
|
||||
|
||||
@@ -133,15 +130,11 @@ public class ConfigPack implements LoaderRegistrar {
|
||||
File pack = new File(folder, "pack.yml");
|
||||
|
||||
try {
|
||||
configuration = new Configuration(new FileInputStream(pack));
|
||||
selfLoader.load(template, configuration);
|
||||
selfLoader.load(template, new FileInputStream(pack));
|
||||
|
||||
main.logger().info("Loading config pack \"" + template.getID() + "\"");
|
||||
|
||||
main.getEventManager().callEvent(new ConfigPackPreLoadEvent(this, template -> selfLoader.load(template, configuration), loader));
|
||||
|
||||
load(l, main);
|
||||
|
||||
ConfigPackPostTemplate packPostTemplate = new ConfigPackPostTemplate();
|
||||
selfLoader.load(packPostTemplate, new FileInputStream(pack));
|
||||
biomeProviderBuilder = packPostTemplate.getProviderBuilder();
|
||||
@@ -181,12 +174,9 @@ public class ConfigPack implements LoaderRegistrar {
|
||||
|
||||
if(pack == null) throw new LoadException("No pack.yml file found in " + file.getName());
|
||||
|
||||
configuration = new Configuration(file.getInputStream(pack));
|
||||
selfLoader.load(template, configuration);
|
||||
selfLoader.load(template, file.getInputStream(pack));
|
||||
main.logger().info("Loading config pack \"" + template.getID() + "\"");
|
||||
|
||||
main.getEventManager().callEvent(new ConfigPackPreLoadEvent(this, template -> selfLoader.load(template, configuration), loader));
|
||||
|
||||
load(l, main);
|
||||
|
||||
ConfigPackPostTemplate packPostTemplate = new ConfigPackPostTemplate();
|
||||
@@ -221,6 +211,8 @@ public class ConfigPack implements LoaderRegistrar {
|
||||
|
||||
|
||||
private void load(long start, TerraPlugin main) throws ConfigException {
|
||||
main.getEventManager().callEvent(new ConfigPackPreLoadEvent(this));
|
||||
|
||||
for(Map.Entry<String, Double> var : template.getVariables().entrySet()) {
|
||||
varScope.create(var.getKey(), var.getValue());
|
||||
}
|
||||
@@ -253,7 +245,7 @@ public class ConfigPack implements LoaderRegistrar {
|
||||
.open("flora", ".yml").then(configs -> buildAll(new FloraFactory(), floraRegistry, abstractConfigLoader.loadConfigs(configs, FloraTemplate::new), main)).close()
|
||||
.open("biomes", ".yml").then(configs -> buildAll(new BiomeFactory(this), biomeRegistry, abstractConfigLoader.loadConfigs(configs, () -> new BiomeTemplate(this, main)), main)).close();
|
||||
|
||||
main.getEventManager().callEvent(new ConfigPackPostLoadEvent(this, template -> selfLoader.load(template, configuration), loader));
|
||||
main.getEventManager().callEvent(new ConfigPackPostLoadEvent(this));
|
||||
main.logger().info("Loaded config pack \"" + template.getID() + "\" v" + template.getVersion() + " by " + template.getAuthor() + " in " + (System.nanoTime() - start) / 1000000D + "ms.");
|
||||
}
|
||||
|
||||
|
||||
@@ -6,14 +6,12 @@ import com.dfsek.tectonic.config.ConfigTemplate;
|
||||
import com.dfsek.terra.api.addons.TerraAddon;
|
||||
import com.dfsek.terra.api.util.seeded.NoiseSeeded;
|
||||
import com.dfsek.terra.config.loaders.config.function.FunctionTemplate;
|
||||
import com.dfsek.terra.config.loaders.mod.ModDependentConfigSection;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@SuppressWarnings({"unused", "FieldMayBeFinal"})
|
||||
public class ConfigPackTemplate implements ConfigTemplate {
|
||||
@@ -41,7 +39,7 @@ public class ConfigPackTemplate implements ConfigTemplate {
|
||||
|
||||
@Value("structures.locatable")
|
||||
@Default
|
||||
private Map<String, ModDependentConfigSection<String>> locatable = new HashMap<>();
|
||||
private Map<String, String> locatable = new HashMap<>();
|
||||
|
||||
@Value("blend.terrain.elevation")
|
||||
@Default
|
||||
@@ -49,19 +47,19 @@ public class ConfigPackTemplate implements ConfigTemplate {
|
||||
|
||||
@Value("vanilla.mobs")
|
||||
@Default
|
||||
private ModDependentConfigSection<Boolean> vanillaMobs = ModDependentConfigSection.withDefault(true);
|
||||
private boolean vanillaMobs = true;
|
||||
|
||||
@Value("vanilla.caves")
|
||||
@Default
|
||||
private ModDependentConfigSection<Boolean> vanillaCaves = ModDependentConfigSection.withDefault(false);
|
||||
private boolean vanillaCaves = false;
|
||||
|
||||
@Value("vanilla.decorations")
|
||||
@Default
|
||||
private ModDependentConfigSection<Boolean> vanillaDecorations = ModDependentConfigSection.withDefault(false);
|
||||
private boolean vanillaDecorations = false;
|
||||
|
||||
@Value("vanilla.structures")
|
||||
@Default
|
||||
private ModDependentConfigSection<Boolean> vanillaStructures = ModDependentConfigSection.withDefault(false);
|
||||
private boolean vanillaStructures = false;
|
||||
|
||||
@Value("author")
|
||||
@Default
|
||||
@@ -69,7 +67,7 @@ public class ConfigPackTemplate implements ConfigTemplate {
|
||||
|
||||
@Value("disable.sapling")
|
||||
@Default
|
||||
private ModDependentConfigSection<Boolean> disableSaplings = ModDependentConfigSection.withDefault(false);
|
||||
private boolean disableSaplings = false;
|
||||
|
||||
@Value("version")
|
||||
@Default
|
||||
@@ -77,42 +75,42 @@ public class ConfigPackTemplate implements ConfigTemplate {
|
||||
|
||||
@Value("disable.carvers")
|
||||
@Default
|
||||
private ModDependentConfigSection<Boolean> disableCarvers = ModDependentConfigSection.withDefault(false);
|
||||
private boolean disableCarvers = false;
|
||||
|
||||
@Value("disable.structures")
|
||||
@Default
|
||||
private ModDependentConfigSection<Boolean> disableStructures = ModDependentConfigSection.withDefault(false);
|
||||
private boolean disableStructures = false;
|
||||
|
||||
@Value("disable.ores")
|
||||
@Default
|
||||
private ModDependentConfigSection<Boolean> disableOres = ModDependentConfigSection.withDefault(false);
|
||||
private boolean disableOres = false;
|
||||
|
||||
@Value("disable.trees")
|
||||
@Default
|
||||
private ModDependentConfigSection<Boolean> disableTrees = ModDependentConfigSection.withDefault(false);
|
||||
private boolean disableTrees = false;
|
||||
|
||||
@Value("disable.flora")
|
||||
@Default
|
||||
private ModDependentConfigSection<Boolean> disableFlora = ModDependentConfigSection.withDefault(false);
|
||||
private boolean disableFlora = false;
|
||||
|
||||
public boolean disableCarvers() {
|
||||
return disableCarvers.get();
|
||||
return disableCarvers;
|
||||
}
|
||||
|
||||
public boolean disableFlora() {
|
||||
return disableFlora.get();
|
||||
return disableFlora;
|
||||
}
|
||||
|
||||
public boolean disableOres() {
|
||||
return disableOres.get();
|
||||
return disableOres;
|
||||
}
|
||||
|
||||
public boolean disableStructures() {
|
||||
return disableStructures.get();
|
||||
return disableStructures;
|
||||
}
|
||||
|
||||
public boolean disableTrees() {
|
||||
return disableTrees.get();
|
||||
return disableTrees;
|
||||
}
|
||||
|
||||
public LinkedHashMap<String, FunctionTemplate> getFunctions() {
|
||||
@@ -124,7 +122,7 @@ public class ConfigPackTemplate implements ConfigTemplate {
|
||||
}
|
||||
|
||||
public boolean isDisableSaplings() {
|
||||
return disableSaplings.get();
|
||||
return disableSaplings;
|
||||
}
|
||||
|
||||
public String getID() {
|
||||
@@ -136,19 +134,19 @@ public class ConfigPackTemplate implements ConfigTemplate {
|
||||
}
|
||||
|
||||
public boolean vanillaMobs() {
|
||||
return vanillaMobs.get();
|
||||
return vanillaMobs;
|
||||
}
|
||||
|
||||
public boolean vanillaCaves() {
|
||||
return vanillaCaves.get();
|
||||
return vanillaCaves;
|
||||
}
|
||||
|
||||
public boolean vanillaDecorations() {
|
||||
return vanillaDecorations.get();
|
||||
return vanillaDecorations;
|
||||
}
|
||||
|
||||
public boolean vanillaStructures() {
|
||||
return vanillaStructures.get();
|
||||
return vanillaStructures;
|
||||
}
|
||||
|
||||
public Map<String, NoiseSeeded> getNoiseBuilderMap() {
|
||||
@@ -164,7 +162,7 @@ public class ConfigPackTemplate implements ConfigTemplate {
|
||||
}
|
||||
|
||||
public Map<String, String> getLocatable() {
|
||||
return locatable.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, entry -> entry.getValue().get()));
|
||||
return locatable;
|
||||
}
|
||||
|
||||
public boolean doBetaCarvers() {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ public class TerraWorld {
|
||||
double noise = sampler.sample(fdX, y, fdZ);
|
||||
if(noise > 0) {
|
||||
int level = 0;
|
||||
for(int yi = world.getMaxHeight()-1; yi > y; yi--) {
|
||||
for(int yi = world.getMaxHeight(); yi > y; yi--) {
|
||||
if(sampler.sample(fdX, yi, fdZ) > 0) level++;
|
||||
else level = 0;
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ cache:
|
||||
carver: 512
|
||||
structure: 32
|
||||
sampler: 128
|
||||
biome-provider: 32
|
||||
master-disable:
|
||||
caves: false
|
||||
script:
|
||||
max-recursion: 1000
|
||||
@@ -1,122 +0,0 @@
|
||||
enable:
|
||||
- "Pokud se vám líbí Terra, můžete nás podpořit na Patreon!"
|
||||
- "Získáte přístup k experimentálním funkcím, než budou vydány!"
|
||||
- "Podpořit projekt můžete zde: https://www.patreon.com/dfsek"
|
||||
disable:
|
||||
- "Děkujeme, že používáte Terra!"
|
||||
command:
|
||||
debug-only: "Tento příkaz musí být použit se zapnutým debug modem!"
|
||||
player-only: "Tento příkaz je pouze pro hráče!"
|
||||
invalid: "Neznámý příkaz. (Očekáváno %1$s argumentů, nalezeno %2$s)."
|
||||
players-only: "Příkaz je pouze pro použití hráčem."
|
||||
world: "Tento příkaz musí být použit v Terra světě!"
|
||||
reload: "Obnoven Terra konfig."
|
||||
reload-error: "Nastaly chyby při obnově Terra konfigurace. Podívejte se do logů pro více informací."
|
||||
version: "Na tomto serveru běží Terra verze \"%1$s\", na platformě \"%2$s\""
|
||||
main-menu:
|
||||
- "--------------------Terra--------------------"
|
||||
- "reload - Obnoví konfigurační data"
|
||||
- "biome - Ukáže aktuální biom"
|
||||
- "ore - Generuje žílu rud v lokaci, ve směru kam se koukáte (Pro debugging)"
|
||||
- "save-data - Uložit populační data"
|
||||
- "structure - Nahrát a exportovat struktury"
|
||||
- "profile - Profiler možnosti"
|
||||
- "image - Obrázek/GUI možnosti"
|
||||
biome:
|
||||
biome-found: "Lokalizován biom na (%1$s, %2$s)"
|
||||
unable-to-locate: "Nelze lokalizovat biom."
|
||||
invalid-radius: "Nesprávný radius: \"%s\""
|
||||
invalid: "Nesprávné ID bomu: \"%s\""
|
||||
in: "Jste v \"%s\""
|
||||
packs:
|
||||
main: "Aktuální instalované konfigurační balíčky:"
|
||||
pack: " - %1$s v%3$s od %2$s"
|
||||
none: "Žádné konfigurační balíčky nejsou nainstalovány."
|
||||
ore:
|
||||
main-menu:
|
||||
- "---------------Terra/ore---------------"
|
||||
- "Generuje žílu rud na bloku, na který koukáte."
|
||||
out-of-range: "Blok mimo dosah"
|
||||
invalid-ore: "Nelze nalézt Rudu \"%s\""
|
||||
geometry:
|
||||
main-menu:
|
||||
- "---------------Terra/geometry----------------"
|
||||
- "Různé voxel geometrické debugging příkazy"
|
||||
- "sphere - Generuje kouli"
|
||||
- "deformsphere - Generuje deformovanou kouli"
|
||||
- "tube - Generuje válec"
|
||||
deform:
|
||||
invalid-radius: "Nesprávný radius: \"%s\""
|
||||
invalid-deform: "Nesprávná deformace: \"%s\""
|
||||
invalid-frequency: "Nesprávná frekvence: \"%s\""
|
||||
sphere:
|
||||
invalid-radius: "Nesprávný radius: \"%s\""
|
||||
tube:
|
||||
invalid-radius: "Nesprávný radius: \"%s\""
|
||||
image:
|
||||
main-menu:
|
||||
- "---------------Terra/image---------------"
|
||||
- "render - Vykreslí obrázek s danou šířkou a výškou, který může být později importován jako svět."
|
||||
- "gui - Otevřít debug GUI (Musí být zapnuto v konfigu)"
|
||||
gui:
|
||||
main-menu:
|
||||
- "-------------Terra/image/gui-------------"
|
||||
- "raw - Otevře GUI s raw Biom daty"
|
||||
- "step - Znovu vykreslí data k lepšímu zobrazení borderu"
|
||||
debug: "Debug mod musí být zapnutý pro použití této možnosti! Debug GUI NENÍ PRODUKČNĚ BEZPEČNÉ!"
|
||||
render:
|
||||
save: "Uložen obrázek jako \"%s\""
|
||||
error: "Nastala chyba při generování obrázku!"
|
||||
profile:
|
||||
main-menu:
|
||||
- "---------------Terra/profile---------------"
|
||||
- "start - Zapne profiler"
|
||||
- "stop - Vypne profiler"
|
||||
- "query - Ukáže profiler data"
|
||||
- "reset - Resetuje profiler data"
|
||||
reset: "Profiler byl resetován."
|
||||
start: "Profiler byl zapnut."
|
||||
stop: "Profiler byl vypnut."
|
||||
structure:
|
||||
main-menu:
|
||||
- "---------------Terra/structure---------------"
|
||||
- "export - Export vašeho výběru WorldEdit jako Terra struktura."
|
||||
- "load - Načíst Terra strukturu"
|
||||
invalid-radius: "Nesprávný radius: \"%s\""
|
||||
invalid-rotation: "Nesprávná rotace: \"%s\""
|
||||
invalid: "Nesprávné ID struktury: \"%s\""
|
||||
export: "Uložena struktura do \"%s\""
|
||||
world-config:
|
||||
load: "Načteny konfigurační hodnoty světa pro svět \"%s\"..."
|
||||
not-found: "Konfigurace pro svět \"%s\" nenalezena. Kopíruji defaultní konfig."
|
||||
using-image: "Načítám svět z obrázku."
|
||||
error: "Nelze načíst konfigurace pro svět %s"
|
||||
done: "Načítání světa \"%1$s\" dokončeno. Uplynulý čas: %2$sms"
|
||||
config-pack:
|
||||
loaded: "Konfigurační balíček %1$s v%4$s od %3$s byl načten za %2$sms."
|
||||
config:
|
||||
loaded: "Načten %1$s ze souboru %2$s"
|
||||
loaded-all: "Načteno %1$s %2$s(s) za %3$sms."
|
||||
error:
|
||||
invalid-failover: "Nesprávný typ failover: \"%s\""
|
||||
duplicate: "Duplikační ID nalezeno v souboru: %s"
|
||||
file:
|
||||
- "Konfigurační chyba pro Terra objekt. Soubor: %1$s"
|
||||
- "%2$s"
|
||||
- "Opravte jej před pokračováním!"
|
||||
generic:
|
||||
- "Nastala chyba při načítání konfigurace."
|
||||
- "Prosíme nahlašte to na Terra."
|
||||
warning:
|
||||
no-population: "Žádné populační chunky nebyly načteny. Pokud je to poprvé, co zapínáte server s Terra, či vytváříte nový svět, je tohle normální."
|
||||
error:
|
||||
severe-config: "Vážná konfigurační chyba zabránila Terra ze správné generace terénu na koordinátech: %1$s, %2$s. Prosíme zkontrolujte konfiguraci pro chyby. Jakékoli konfigurační chyby jsou vypsány výše."
|
||||
debug:
|
||||
data-save : "Uložena populační data."
|
||||
use-paper:
|
||||
- "Vypadá to, že používáte Spigot/CraftBukkit."
|
||||
- "Ačkoli Terra &ofunguje&r na Spigot, některé funkce budou ztraceny. (Terra je netestována na CraftBukkit; žádná podpora nebude dána pro CraftBukkit)."
|
||||
- "Pro nejvíce funkcí s Terra, použijte Paper."
|
||||
- "Navíc, Paper přináší obrovské výkonnostní zlepešení než Spigot, a všechny Spigot pluginy by měli fungovat s Paper!"
|
||||
- "Pro nejlepší zážitek s Terra a všemi pluginy, použijte prosím Paper."
|
||||
- "Více info najdete na stránce Paperu: https://papermc.io/"
|
||||
@@ -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;
|
||||
|
||||
+1
-6
@@ -7,9 +7,4 @@ org.gradle.parallel=true
|
||||
org.gradle.caching=true
|
||||
org.gradle.warning.mode=all
|
||||
#org.gradle.logging.level=info
|
||||
# Project information
|
||||
terra.description=A fast, modern, extensible, platform-agnostic data-driven world generator
|
||||
terra.source=https://github.com/PolyhedralDev/Terra
|
||||
terra.issues=https://github.com/PolyhedralDev/Terra/issues
|
||||
terra.wiki=https://github.com/PolyhedralDev/Terra/wiki
|
||||
terra.license=GNU General Public License, version 3.0
|
||||
org.gradle.configureondemand=true
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
package com.dfsek.terra.bukkit;
|
||||
|
||||
import com.dfsek.terra.api.platform.modloader.Mod;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
public class BukkitPlugin implements Mod {
|
||||
private final Plugin plugin;
|
||||
|
||||
public BukkitPlugin(Plugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getID() {
|
||||
return plugin.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getVersion() {
|
||||
return plugin.getDescription().getVersion();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return plugin.getName();
|
||||
}
|
||||
}
|
||||
@@ -14,11 +14,11 @@ import com.dfsek.terra.api.event.TerraEventManager;
|
||||
import com.dfsek.terra.api.platform.block.BlockData;
|
||||
import com.dfsek.terra.api.platform.handle.ItemHandle;
|
||||
import com.dfsek.terra.api.platform.handle.WorldHandle;
|
||||
import com.dfsek.terra.api.platform.modloader.Mod;
|
||||
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;
|
||||
@@ -33,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;
|
||||
@@ -58,12 +59,9 @@ import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
public class TerraBukkitPlugin extends JavaPlugin implements TerraPlugin {
|
||||
@@ -73,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);
|
||||
|
||||
@@ -155,6 +155,11 @@ public class TerraBukkitPlugin extends JavaPlugin implements TerraPlugin {
|
||||
return profiler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TaskScheduler getScheduler() {
|
||||
return scheduler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
BukkitChunkGeneratorWrapper.saveAll();
|
||||
@@ -310,11 +315,6 @@ public class TerraBukkitPlugin extends JavaPlugin implements TerraPlugin {
|
||||
genericLoaders.register(registry);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Mod> getMods() {
|
||||
return Arrays.stream(Bukkit.getPluginManager().getPlugins()).map(BukkitPlugin::new).collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
@Override
|
||||
public LockedRegistry<TerraAddon> getAddons() {
|
||||
return addonLockedRegistry;
|
||||
|
||||
@@ -19,6 +19,7 @@ public class PaperListener implements Listener {
|
||||
@EventHandler
|
||||
public void onStructureLocate(StructureLocateEvent e) {
|
||||
if(!BukkitAdapter.adapt(e.getWorld()).isTerraWorld()) return;
|
||||
e.setResult(null); // Assume no result.
|
||||
String name = "minecraft:" + e.getType().getName();
|
||||
main.getDebugLogger().info("Overriding structure location for \"" + name + "\"");
|
||||
TerraWorld tw = main.getWorld(BukkitAdapter.adapt(e.getWorld()));
|
||||
@@ -31,8 +32,10 @@ public class PaperListener implements Listener {
|
||||
}, main);
|
||||
finder.run(); // Do this synchronously.
|
||||
} else {
|
||||
e.setResult(e.getOrigin());
|
||||
main.logger().warning("No overrides are defined for \"" + name + "\". Locating this structure will NOT work properly!");
|
||||
main.logger().warning("No overrides are defined for \"" + name + "\"");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -3,13 +3,16 @@ main: "com.dfsek.terra.bukkit.TerraBukkitPlugin"
|
||||
version: "@VERSION@"
|
||||
load: "STARTUP"
|
||||
author: dfsek
|
||||
website: "@WIKI@"
|
||||
api-version: "1.13"
|
||||
description: "@DESCRIPTION@"
|
||||
description: "An insanely powerful free & open-source data-driven world generator."
|
||||
softdepend: [ "WorldEdit" ]
|
||||
commands:
|
||||
terra:
|
||||
description: "Terra base command"
|
||||
usage: "/terra "
|
||||
aliases: [ "te" ]
|
||||
permission: "terra.command"
|
||||
permission: "terra.command"
|
||||
locate:
|
||||
description: "Locate a Terra Structure"
|
||||
usage: "/locate <STRUCTURE_ID> <radius>"
|
||||
permission: "terra.locate"
|
||||
@@ -27,13 +27,7 @@ dependencies {
|
||||
"mappings"("net.fabricmc:yarn:1.16.5+build.5:v2")
|
||||
"modImplementation"("net.fabricmc:fabric-loader:0.11.2")
|
||||
|
||||
"modCompileOnly"("com.sk89q.worldedit:worldedit-fabric-mc1.16:7.2.0-SNAPSHOT") {
|
||||
exclude(group = "com.google.guava", module = "guava")
|
||||
exclude(group = "com.google.code.gson", module = "gson")
|
||||
exclude(group = "it.unimi.dsi", module = "fastutil")
|
||||
exclude(group = "org.apache.logging.log4j", module = "log4j-api")
|
||||
exclude(group = "org.apache.logging.log4j", module = "log4j-core")
|
||||
}
|
||||
"modImplementation"("net.fabricmc.fabric-api:fabric-api:0.31.0+1.16")
|
||||
}
|
||||
|
||||
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.dfsek.terra.fabric.util;
|
||||
package com.dfsek.terra.fabric;
|
||||
|
||||
import com.dfsek.terra.api.math.vector.Vector3;
|
||||
import com.dfsek.terra.api.platform.block.Axis;
|
||||
@@ -1,28 +0,0 @@
|
||||
package com.dfsek.terra.fabric;
|
||||
|
||||
import com.dfsek.terra.api.platform.modloader.Mod;
|
||||
import net.fabricmc.loader.api.ModContainer;
|
||||
|
||||
|
||||
public class FabricMod implements Mod {
|
||||
private final ModContainer mod;
|
||||
|
||||
public FabricMod(ModContainer mod) {
|
||||
this.mod = mod;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getID() {
|
||||
return mod.getMetadata().getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getVersion() {
|
||||
return mod.getMetadata().getVersion().getFriendlyString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return mod.getMetadata().getName();
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,5 @@
|
||||
package com.dfsek.terra.fabric;
|
||||
|
||||
import com.dfsek.tectonic.config.Configuration;
|
||||
import com.dfsek.tectonic.exception.ConfigException;
|
||||
import com.dfsek.tectonic.exception.LoadException;
|
||||
import com.dfsek.tectonic.loading.ConfigLoader;
|
||||
import com.dfsek.tectonic.loading.TypeRegistry;
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.addons.TerraAddon;
|
||||
@@ -12,135 +8,147 @@ import com.dfsek.terra.api.addons.annotations.Author;
|
||||
import com.dfsek.terra.api.addons.annotations.Version;
|
||||
import com.dfsek.terra.api.command.CommandManager;
|
||||
import com.dfsek.terra.api.command.TerraCommandManager;
|
||||
import com.dfsek.terra.api.command.exception.CommandException;
|
||||
import com.dfsek.terra.api.command.exception.MalformedCommandException;
|
||||
import com.dfsek.terra.api.event.EventListener;
|
||||
import com.dfsek.terra.api.event.EventManager;
|
||||
import com.dfsek.terra.api.event.TerraEventManager;
|
||||
import com.dfsek.terra.api.event.annotations.Global;
|
||||
import com.dfsek.terra.api.event.annotations.Priority;
|
||||
import com.dfsek.terra.api.event.events.config.ConfigPackPostLoadEvent;
|
||||
import com.dfsek.terra.api.event.events.config.ConfigPackPreLoadEvent;
|
||||
import com.dfsek.terra.api.platform.CommandSender;
|
||||
import com.dfsek.terra.api.platform.block.BlockData;
|
||||
import com.dfsek.terra.api.platform.entity.Entity;
|
||||
import com.dfsek.terra.api.platform.handle.ItemHandle;
|
||||
import com.dfsek.terra.api.platform.handle.WorldHandle;
|
||||
import com.dfsek.terra.api.platform.modloader.Mod;
|
||||
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.transform.Validator;
|
||||
import com.dfsek.terra.api.util.generic.pair.Pair;
|
||||
import com.dfsek.terra.api.util.logging.DebugLogger;
|
||||
import com.dfsek.terra.api.util.logging.Logger;
|
||||
import com.dfsek.terra.commands.CommandUtil;
|
||||
import com.dfsek.terra.config.GenericLoaders;
|
||||
import com.dfsek.terra.config.PluginConfig;
|
||||
import com.dfsek.terra.config.builder.BiomeBuilder;
|
||||
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.fabric.config.PostLoadCompatibilityOptions;
|
||||
import com.dfsek.terra.fabric.config.PreLoadCompatibilityOptions;
|
||||
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.util.FabricUtil;
|
||||
import com.dfsek.terra.fabric.mixin.access.BiomeEffectsAccessor;
|
||||
import com.dfsek.terra.fabric.mixin.access.GeneratorTypeAccessor;
|
||||
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;
|
||||
import com.dfsek.terra.registry.master.AddonRegistry;
|
||||
import com.dfsek.terra.registry.master.ConfigRegistry;
|
||||
import com.dfsek.terra.world.TerraWorld;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.client.world.GeneratorType;
|
||||
import net.minecraft.server.command.ServerCommandSource;
|
||||
import net.minecraft.text.LiteralText;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.registry.BuiltinRegistries;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.util.registry.RegistryKey;
|
||||
import net.minecraft.world.WorldAccess;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
import net.minecraft.world.dimension.DimensionType;
|
||||
import net.minecraft.world.biome.BiomeEffects;
|
||||
import net.minecraft.world.biome.GenerationSettings;
|
||||
import net.minecraft.world.gen.GenerationStep;
|
||||
import net.minecraft.world.gen.chunk.ChunkGenerator;
|
||||
import net.minecraft.world.gen.chunk.ChunkGeneratorSettings;
|
||||
import net.minecraft.world.gen.decorator.Decorator;
|
||||
import net.minecraft.world.gen.decorator.NopeDecoratorConfig;
|
||||
import net.minecraft.world.gen.feature.ConfiguredFeature;
|
||||
import net.minecraft.world.gen.feature.ConfiguredFeatures;
|
||||
import net.minecraft.world.gen.feature.DefaultFeatureConfig;
|
||||
import net.minecraft.world.gen.feature.FeatureConfig;
|
||||
import net.minecraft.world.gen.surfacebuilder.SurfaceBuilder;
|
||||
import net.minecraft.world.gen.surfacebuilder.TernarySurfaceConfig;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static net.minecraft.server.command.CommandManager.argument;
|
||||
import static net.minecraft.server.command.CommandManager.literal;
|
||||
|
||||
|
||||
public class TerraFabricPlugin implements TerraPlugin, ModInitializer {
|
||||
private final org.apache.logging.log4j.Logger log4jLogger = LogManager.getLogger();
|
||||
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;
|
||||
private final Map<DimensionType, Pair<ServerWorld, TerraWorld>> worldMap = new HashMap<>();
|
||||
|
||||
public Map<DimensionType, Pair<ServerWorld, TerraWorld>> getWorldMap() {
|
||||
return worldMap;
|
||||
}
|
||||
|
||||
private final Map<Long, TerraWorld> worldMap = new HashMap<>();
|
||||
private final EventManager eventManager = new TerraEventManager(this);
|
||||
private final GenericLoaders genericLoaders = new GenericLoaders(this);
|
||||
|
||||
private final Profiler profiler = new ProfilerImpl();
|
||||
|
||||
private final Logger logger = new Logger() {
|
||||
private final org.apache.logging.log4j.Logger logger = LogManager.getLogger();
|
||||
|
||||
@Override
|
||||
public void info(String message) {
|
||||
log4jLogger.info(message);
|
||||
logger.info(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void warning(String message) {
|
||||
log4jLogger.warn(message);
|
||||
logger.warn(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void severe(String message) {
|
||||
log4jLogger.error(message);
|
||||
logger.error(message);
|
||||
}
|
||||
};
|
||||
|
||||
private final DebugLogger debugLogger = new DebugLogger(logger);
|
||||
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 FabricAddon fabricAddon = new FabricAddon(this);
|
||||
private final AddonRegistry addonRegistry = new AddonRegistry(fabricAddon, this);
|
||||
private final AddonRegistry addonRegistry = new AddonRegistry(new FabricAddon(this), this);
|
||||
private final LockedRegistry<TerraAddon> addonLockedRegistry = new LockedRegistry<>(addonRegistry);
|
||||
|
||||
private final PluginConfig config = new PluginConfig();
|
||||
|
||||
private final Transformer<String, Biome> biomeFixer = new Transformer.Builder<String, Biome>()
|
||||
.addTransform(id -> BuiltinRegistries.BIOME.get(Identifier.tryParse(id)), Validator.notNull())
|
||||
.addTransform(id -> BuiltinRegistries.BIOME.get(Identifier.tryParse("minecraft:" + id.toLowerCase())), Validator.notNull()).build();
|
||||
private File dataFolder;
|
||||
private final CommandManager manager = new TerraCommandManager(this);
|
||||
.addTransform(id -> BuiltinRegistries.BIOME.get(Identifier.tryParse(id)), new NotNullValidator<>())
|
||||
.addTransform(id -> BuiltinRegistries.BIOME.get(Identifier.tryParse("minecraft:" + id.toLowerCase())), new NotNullValidator<>()).build();
|
||||
|
||||
public CommandManager getManager() {
|
||||
return manager;
|
||||
}
|
||||
private final TaskScheduler scheduler = new FabricTaskScheduler();
|
||||
private File dataFolder;
|
||||
|
||||
public static TerraFabricPlugin getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public static String createBiomeID(ConfigPack pack, String biomeID) {
|
||||
return pack.getTemplate().getID().toLowerCase() + "/" + biomeID.toLowerCase(Locale.ROOT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public WorldHandle getWorldHandle() {
|
||||
return worldHandle;
|
||||
@@ -148,12 +156,15 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer {
|
||||
|
||||
@Override
|
||||
public TerraWorld getWorld(World world) {
|
||||
return getWorld(((WorldAccess) world).getDimension());
|
||||
return worldMap.computeIfAbsent(world.getSeed(), w -> {
|
||||
logger.info("Loading world " + w);
|
||||
return new TerraWorld(world, ((FabricChunkGeneratorWrapper) world.getGenerator()).getPack(), this);
|
||||
});
|
||||
}
|
||||
|
||||
public TerraWorld getWorld(DimensionType type) {
|
||||
TerraWorld world = worldMap.get(type).getRight();
|
||||
if(world == null) throw new IllegalArgumentException("No world exists with dimension type " + type);
|
||||
public TerraWorld getWorld(long seed) {
|
||||
TerraWorld world = worldMap.get(seed);
|
||||
if(world == null) throw new IllegalArgumentException("No world exists with seed " + seed);
|
||||
return world;
|
||||
}
|
||||
|
||||
@@ -174,7 +185,7 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer {
|
||||
|
||||
@Override
|
||||
public boolean isDebug() {
|
||||
return config.isDebug();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -197,11 +208,14 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer {
|
||||
config.load(this);
|
||||
LangUtil.load(config.getLanguage(), this); // Load language.
|
||||
boolean succeed = registry.loadAll(this);
|
||||
worldMap.forEach((seed, pair) -> {
|
||||
pair.getRight().getConfig().getSamplerCache().clear();
|
||||
String packID = pair.getRight().getConfig().getTemplate().getID();
|
||||
pair.setRight(new TerraWorld(pair.getRight().getWorld(), registry.get(packID), this));
|
||||
Map<Long, TerraWorld> newMap = new HashMap<>();
|
||||
worldMap.forEach((seed, tw) -> {
|
||||
tw.getConfig().getSamplerCache().clear();
|
||||
String packID = tw.getConfig().getTemplate().getID();
|
||||
newMap.put(seed, new TerraWorld(tw.getWorld(), registry.get(packID), this));
|
||||
});
|
||||
worldMap.clear();
|
||||
worldMap.putAll(newMap);
|
||||
return succeed;
|
||||
}
|
||||
|
||||
@@ -235,21 +249,50 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer {
|
||||
genericLoaders.register(registry);
|
||||
registry
|
||||
.registerLoader(BlockData.class, (t, o, l) -> worldHandle.createBlockData((String) o))
|
||||
.registerLoader(com.dfsek.terra.api.platform.world.Biome.class, (t, o, l) -> biomeFixer.translate((String) o))
|
||||
.registerLoader(Identifier.class, (t, o, l) -> {
|
||||
Identifier identifier = Identifier.tryParse((String) o);
|
||||
if(identifier == null) throw new LoadException("Invalid identifier: " + o);
|
||||
return identifier;
|
||||
});
|
||||
.registerLoader(com.dfsek.terra.api.platform.world.Biome.class, (t, o, l) -> biomeFixer.translate((String) o));
|
||||
}
|
||||
|
||||
public void packInit() {
|
||||
logger.info("Loading config packs...");
|
||||
registry.loadAll(this);
|
||||
private Biome createBiome(BiomeBuilder biome) {
|
||||
BiomeTemplate template = biome.getTemplate();
|
||||
Map<String, Integer> colors = template.getColors();
|
||||
|
||||
registry.forEach(pack -> pack.getBiomeRegistry().forEach((id, biome) -> Registry.register(BuiltinRegistries.BIOME, new Identifier("terra", FabricUtil.createBiomeID(pack, id)), FabricUtil.createBiome(fabricAddon, biome, pack)))); // Register all Terra biomes.
|
||||
Biome vanilla = (Biome) (new ArrayList<>(biome.getVanillaBiomes().getContents()).get(0)).getHandle();
|
||||
|
||||
logger.info("Loaded packs.");
|
||||
GenerationSettings.Builder generationSettings = new GenerationSettings.Builder();
|
||||
generationSettings.surfaceBuilder(SurfaceBuilder.DEFAULT.withConfig(new TernarySurfaceConfig(Blocks.GRASS_BLOCK.getDefaultState(), Blocks.DIRT.getDefaultState(), Blocks.GRAVEL.getDefaultState()))); // It needs a surfacebuilder, even though we dont use it.
|
||||
generationSettings.feature(GenerationStep.Feature.VEGETAL_DECORATION, POPULATOR_CONFIGURED_FEATURE);
|
||||
|
||||
|
||||
BiomeEffectsAccessor accessor = (BiomeEffectsAccessor) vanilla.getEffects();
|
||||
BiomeEffects.Builder effects = new BiomeEffects.Builder()
|
||||
.waterColor(colors.getOrDefault("water", accessor.getWaterColor()))
|
||||
.waterFogColor(colors.getOrDefault("water-fog", accessor.getWaterFogColor()))
|
||||
.fogColor(colors.getOrDefault("fog", accessor.getFogColor()))
|
||||
.skyColor(colors.getOrDefault("sky", accessor.getSkyColor()))
|
||||
.grassColorModifier(accessor.getGrassColorModifier());
|
||||
|
||||
if(colors.containsKey("grass")) {
|
||||
effects.grassColor(colors.get("grass"));
|
||||
} else {
|
||||
accessor.getGrassColor().ifPresent(effects::grassColor);
|
||||
}
|
||||
if(colors.containsKey("foliage")) {
|
||||
effects.foliageColor(colors.get("foliage"));
|
||||
} else {
|
||||
accessor.getFoliageColor().ifPresent(effects::foliageColor);
|
||||
}
|
||||
|
||||
return new Biome.Builder()
|
||||
.precipitation(vanilla.getPrecipitation())
|
||||
.category(vanilla.getCategory())
|
||||
.depth(vanilla.getDepth())
|
||||
.scale(vanilla.getScale())
|
||||
.temperature(vanilla.getTemperature())
|
||||
.downfall(vanilla.getDownfall())
|
||||
.effects(effects.build())
|
||||
.spawnSettings(vanilla.getSpawnSettings())
|
||||
.generationSettings(generationSettings.build())
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -259,7 +302,6 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer {
|
||||
this.dataFolder = new File(FabricLoader.getInstance().getConfigDir().toFile(), "Terra");
|
||||
saveDefaultConfig();
|
||||
config.load(this);
|
||||
debugLogger.setDebug(config.isDebug());
|
||||
LangUtil.load(config.getLanguage(), this);
|
||||
logger.info("Initializing Terra...");
|
||||
|
||||
@@ -268,21 +310,93 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer {
|
||||
}
|
||||
logger.info("Loaded addons.");
|
||||
|
||||
registry.loadAll(this);
|
||||
|
||||
Registry.register(Registry.FEATURE, new Identifier("terra", "populator"), POPULATOR_FEATURE);
|
||||
RegistryKey<ConfiguredFeature<?, ?>> floraKey = RegistryKey.of(Registry.CONFIGURED_FEATURE_WORLDGEN, new Identifier("terra", "populator"));
|
||||
logger.info("Loaded packs.");
|
||||
|
||||
Registry.register(Registry.FEATURE, new Identifier("terra", "flora_populator"), POPULATOR_FEATURE);
|
||||
RegistryKey<ConfiguredFeature<?, ?>> floraKey = RegistryKey.of(Registry.CONFIGURED_FEATURE_WORLDGEN, new Identifier("terra", "flora_populator"));
|
||||
Registry.register(BuiltinRegistries.CONFIGURED_FEATURE, floraKey.getValue(), POPULATOR_CONFIGURED_FEATURE);
|
||||
|
||||
registry.forEach(pack -> pack.getBiomeRegistry().forEach((id, biome) -> Registry.register(BuiltinRegistries.BIOME, new Identifier("terra", createBiomeID(pack, id)), createBiome(biome)))); // Register all Terra biomes.
|
||||
Registry.register(Registry.CHUNK_GENERATOR, new Identifier("terra:terra"), FabricChunkGeneratorWrapper.CODEC);
|
||||
Registry.register(Registry.BIOME_SOURCE, new Identifier("terra:terra"), TerraBiomeSource.CODEC);
|
||||
|
||||
if(FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) {
|
||||
registry.forEach(pack -> {
|
||||
final GeneratorType generatorType = new GeneratorType("terra." + pack.getTemplate().getID()) {
|
||||
@Override
|
||||
protected ChunkGenerator getChunkGenerator(Registry<Biome> biomeRegistry, Registry<ChunkGeneratorSettings> chunkGeneratorSettingsRegistry, long seed) {
|
||||
return new FabricChunkGeneratorWrapper(new TerraBiomeSource(biomeRegistry, seed, pack), seed, pack);
|
||||
}
|
||||
};
|
||||
//noinspection ConstantConditions
|
||||
((GeneratorTypeAccessor) generatorType).setTranslationKey(new LiteralText("Terra:" + pack.getTemplate().getID()));
|
||||
GeneratorTypeAccessor.getValues().add(generatorType);
|
||||
});
|
||||
}
|
||||
|
||||
CommandManager manager = new TerraCommandManager(this);
|
||||
try {
|
||||
CommandUtil.registerAll(manager);
|
||||
} catch(MalformedCommandException e) {
|
||||
e.printStackTrace(); // TODO do something here even though this should literally never happen
|
||||
}
|
||||
|
||||
logger.info("Finished initialization.");
|
||||
|
||||
CommandRegistrationCallback.EVENT.register((dispatcher, dedicated) -> {
|
||||
int max = manager.getMaxArgumentDepth();
|
||||
RequiredArgumentBuilder<ServerCommandSource, String> arg = argument("arg" + (max - 1), StringArgumentType.word());
|
||||
for(int i = 0; i < max; i++) {
|
||||
RequiredArgumentBuilder<ServerCommandSource, String> next = argument("arg" + (max - i - 1), StringArgumentType.word());
|
||||
|
||||
arg = next.then(assemble(arg, manager));
|
||||
}
|
||||
|
||||
dispatcher.register(literal("terra").executes(context -> 1).then(assemble(arg, manager)));
|
||||
dispatcher.register(literal("te").executes(context -> 1).then(assemble(arg, manager)));
|
||||
//dispatcher.register(literal("te").redirect(root));
|
||||
}
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
private RequiredArgumentBuilder<ServerCommandSource, String> assemble(RequiredArgumentBuilder<ServerCommandSource, String> in, CommandManager manager) {
|
||||
return in.suggests((context, builder) -> {
|
||||
List<String> args = parseCommand(context.getInput());
|
||||
CommandSender sender = (CommandSender) context.getSource();
|
||||
try {
|
||||
sender = (Entity) context.getSource().getEntityOrThrow();
|
||||
} catch(CommandSyntaxException ignore) {
|
||||
}
|
||||
try {
|
||||
manager.tabComplete(args.remove(0), sender, args).forEach(builder::suggest);
|
||||
} catch(CommandException e) {
|
||||
sender.sendMessage(e.getMessage());
|
||||
}
|
||||
return builder.buildFuture();
|
||||
}).executes(context -> {
|
||||
List<String> args = parseCommand(context.getInput());
|
||||
CommandSender sender = (CommandSender) context.getSource();
|
||||
try {
|
||||
sender = (Entity) context.getSource().getEntityOrThrow();
|
||||
} catch(CommandSyntaxException ignore) {
|
||||
}
|
||||
try {
|
||||
manager.execute(args.remove(0), sender, args);
|
||||
} catch(CommandException e) {
|
||||
context.getSource().sendError(new LiteralText(e.getMessage()));
|
||||
}
|
||||
return 1;
|
||||
});
|
||||
}
|
||||
|
||||
private List<String> parseCommand(String command) {
|
||||
if(command.startsWith("/terra ")) command = command.substring("/terra ".length());
|
||||
else if(command.startsWith("/te ")) command = command.substring("/te ".length());
|
||||
List<String> c = new ArrayList<>(Arrays.asList(command.split(" ")));
|
||||
if(command.endsWith(" ")) c.add("");
|
||||
return c;
|
||||
}
|
||||
|
||||
|
||||
@@ -292,31 +406,23 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Mod> getMods() {
|
||||
return FabricLoader.getInstance().getAllMods().stream().map(FabricMod::new).collect(Collectors.toSet());
|
||||
public Profiler getProfiler() {
|
||||
return profiler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Profiler getProfiler() {
|
||||
return profiler;
|
||||
public TaskScheduler getScheduler() {
|
||||
return scheduler;
|
||||
}
|
||||
|
||||
@Addon("Terra-Fabric")
|
||||
@Author("Terra")
|
||||
@Version("1.0.0")
|
||||
public static final class FabricAddon extends TerraAddon implements EventListener {
|
||||
|
||||
private static final class FabricAddon extends TerraAddon implements EventListener {
|
||||
private final TerraPlugin main;
|
||||
|
||||
private final Map<ConfigPack, Pair<PreLoadCompatibilityOptions, PostLoadCompatibilityOptions>> templates = new HashMap<>();
|
||||
|
||||
private final Map<ConfigPack, Configuration> compatConfigs = new HashMap<>();
|
||||
|
||||
private final ConfigLoader compatLoader = new ConfigLoader();
|
||||
|
||||
private FabricAddon(TerraPlugin main) {
|
||||
this.main = main;
|
||||
main.register(compatLoader);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -347,68 +453,13 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer {
|
||||
injectTree(treeRegistry, "MEGA_SPRUCE", ConfiguredFeatures.MEGA_SPRUCE);
|
||||
injectTree(treeRegistry, "CRIMSON_FUNGUS", ConfiguredFeatures.CRIMSON_FUNGI);
|
||||
injectTree(treeRegistry, "WARPED_FUNGUS", ConfiguredFeatures.WARPED_FUNGI);
|
||||
|
||||
Configuration compat;
|
||||
|
||||
try {
|
||||
compat = new Configuration(event.getLoader().get("compat.yml"));
|
||||
main.logger().info("Loading compatibility options from compat.yml.");
|
||||
} catch(FileNotFoundException e) {
|
||||
compat = new Configuration(new HashMap<>()); // blank config
|
||||
main.logger().info("No compat.yml found, not loading compatibility options.");
|
||||
} catch(IOException e) {
|
||||
throw new RuntimeException("Failed to load compatibility config", e); // Something went wrong.
|
||||
}
|
||||
|
||||
compatConfigs.put(event.getPack(), compat);
|
||||
|
||||
PreLoadCompatibilityOptions template = new PreLoadCompatibilityOptions();
|
||||
|
||||
try {
|
||||
compatLoader.load(template, compat);
|
||||
} catch(ConfigException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if(template.doRegistryInjection()) {
|
||||
BuiltinRegistries.CONFIGURED_FEATURE.getEntries().forEach(entry -> {
|
||||
if(!template.getExcludedRegistryFeatures().contains(entry.getKey().getValue())) {
|
||||
try {
|
||||
event.getPack().getTreeRegistry().add(entry.getKey().getValue().toString(), (Tree) entry.getValue());
|
||||
main.getDebugLogger().info("Injected ConfiguredFeature " + entry.getKey().getValue() + " as Tree.");
|
||||
} catch(DuplicateEntryException ignored) {
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
templates.put(event.getPack(), Pair.of(template, null));
|
||||
|
||||
}
|
||||
|
||||
@Priority(Priority.HIGHEST)
|
||||
@Global
|
||||
public void createInjectionOptions(ConfigPackPostLoadEvent event) {
|
||||
PostLoadCompatibilityOptions template = new PostLoadCompatibilityOptions();
|
||||
|
||||
try {
|
||||
compatLoader.load(template, compatConfigs.get(event.getPack()));
|
||||
} catch(ConfigException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
templates.get(event.getPack()).setRight(template);
|
||||
}
|
||||
|
||||
|
||||
private void injectTree(CheckedRegistry<Tree> registry, String id, ConfiguredFeature<?, ?> tree) {
|
||||
try {
|
||||
registry.add(id, (Tree) tree);
|
||||
} catch(DuplicateEntryException ignore) {
|
||||
}
|
||||
}
|
||||
|
||||
public Map<ConfigPack, Pair<PreLoadCompatibilityOptions, PostLoadCompatibilityOptions>> getTemplates() {
|
||||
return templates;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import com.dfsek.terra.api.platform.block.BlockFace;
|
||||
import com.dfsek.terra.api.platform.block.BlockType;
|
||||
import com.dfsek.terra.api.platform.block.state.BlockState;
|
||||
import com.dfsek.terra.api.platform.world.World;
|
||||
import com.dfsek.terra.fabric.util.FabricAdapter;
|
||||
import com.dfsek.terra.fabric.FabricAdapter;
|
||||
import net.minecraft.block.FluidBlock;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.WorldAccess;
|
||||
|
||||
+1
-1
@@ -2,8 +2,8 @@ package com.dfsek.terra.fabric.block.data;
|
||||
|
||||
import com.dfsek.terra.api.platform.block.BlockFace;
|
||||
import com.dfsek.terra.api.platform.block.data.Directional;
|
||||
import com.dfsek.terra.fabric.FabricAdapter;
|
||||
import com.dfsek.terra.fabric.block.FabricBlockData;
|
||||
import com.dfsek.terra.fabric.util.FabricAdapter;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.state.property.DirectionProperty;
|
||||
|
||||
|
||||
+1
-1
@@ -2,8 +2,8 @@ package com.dfsek.terra.fabric.block.data;
|
||||
|
||||
import com.dfsek.terra.api.platform.block.Axis;
|
||||
import com.dfsek.terra.api.platform.block.data.Orientable;
|
||||
import com.dfsek.terra.fabric.FabricAdapter;
|
||||
import com.dfsek.terra.fabric.block.FabricBlockData;
|
||||
import com.dfsek.terra.fabric.util.FabricAdapter;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.state.property.EnumProperty;
|
||||
import net.minecraft.util.math.Direction;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.dfsek.terra.fabric.block.data;
|
||||
|
||||
import com.dfsek.terra.api.platform.block.data.Slab;
|
||||
import com.dfsek.terra.fabric.util.FabricAdapter;
|
||||
import com.dfsek.terra.fabric.FabricAdapter;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.state.property.Properties;
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ package com.dfsek.terra.fabric.block.data;
|
||||
|
||||
import com.dfsek.terra.api.platform.block.BlockFace;
|
||||
import com.dfsek.terra.api.platform.block.data.Stairs;
|
||||
import com.dfsek.terra.fabric.util.FabricAdapter;
|
||||
import com.dfsek.terra.fabric.FabricAdapter;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.state.property.Properties;
|
||||
|
||||
|
||||
-30
@@ -1,30 +0,0 @@
|
||||
package com.dfsek.terra.fabric.config;
|
||||
|
||||
import com.dfsek.tectonic.annotations.Default;
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
import com.dfsek.tectonic.config.ConfigTemplate;
|
||||
import com.dfsek.terra.config.builder.BiomeBuilder;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@SuppressWarnings("FieldMayBeFinal")
|
||||
public class PostLoadCompatibilityOptions implements ConfigTemplate {
|
||||
@Value("structures.inject-biome.exclude-biomes")
|
||||
@Default
|
||||
private Map<BiomeBuilder, Set<Identifier>> excludedPerBiomeStructures = new HashMap<>();
|
||||
|
||||
@Value("features.inject-biome.exclude-biomes")
|
||||
@Default
|
||||
private Map<BiomeBuilder, Set<Identifier>> excludedPerBiomeFeatures = new HashMap<>();
|
||||
|
||||
public Map<BiomeBuilder, Set<Identifier>> getExcludedPerBiomeFeatures() {
|
||||
return excludedPerBiomeFeatures;
|
||||
}
|
||||
|
||||
public Map<BiomeBuilder, Set<Identifier>> getExcludedPerBiomeStructures() {
|
||||
return excludedPerBiomeStructures;
|
||||
}
|
||||
}
|
||||
-45
@@ -1,45 +0,0 @@
|
||||
package com.dfsek.terra.fabric.config;
|
||||
|
||||
import com.dfsek.tectonic.annotations.Default;
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
import com.dfsek.tectonic.config.ConfigTemplate;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
@SuppressWarnings("FieldMayBeFinal")
|
||||
public class PreLoadCompatibilityOptions implements ConfigTemplate {
|
||||
@Value("features.inject-registry.enable")
|
||||
@Default
|
||||
private boolean doRegistryInjection = false;
|
||||
|
||||
@Value("features.inject-namespaces")
|
||||
@Default
|
||||
private Set<String> featureNamespaces = new HashSet<>();
|
||||
|
||||
@Value("structures.inject-namespaces")
|
||||
@Default
|
||||
private Set<String> structureNamespaces = new HashSet<>();
|
||||
|
||||
@Value("features.inject-registry.excluded-features")
|
||||
@Default
|
||||
private Set<Identifier> excludedRegistryFeatures = new HashSet<>();
|
||||
|
||||
|
||||
public Set<String> getFeatureNamespaces() {
|
||||
return featureNamespaces;
|
||||
}
|
||||
|
||||
public Set<String> getStructureNamespaces() {
|
||||
return structureNamespaces;
|
||||
}
|
||||
|
||||
public boolean doRegistryInjection() {
|
||||
return doRegistryInjection;
|
||||
}
|
||||
|
||||
public Set<Identifier> getExcludedRegistryFeatures() {
|
||||
return excludedRegistryFeatures;
|
||||
}
|
||||
}
|
||||
+36
-74
@@ -4,13 +4,11 @@ import com.dfsek.terra.api.platform.world.World;
|
||||
import com.dfsek.terra.api.platform.world.generator.ChunkData;
|
||||
import com.dfsek.terra.api.platform.world.generator.GeneratorWrapper;
|
||||
import com.dfsek.terra.api.util.FastRandom;
|
||||
import com.dfsek.terra.api.world.biome.UserDefinedBiome;
|
||||
import com.dfsek.terra.api.world.generation.TerraChunkGenerator;
|
||||
import com.dfsek.terra.api.world.locate.AsyncStructureFinder;
|
||||
import com.dfsek.terra.config.pack.ConfigPack;
|
||||
import com.dfsek.terra.fabric.FabricAdapter;
|
||||
import com.dfsek.terra.fabric.TerraFabricPlugin;
|
||||
import com.dfsek.terra.fabric.block.FabricBlockData;
|
||||
import com.dfsek.terra.fabric.util.FabricAdapter;
|
||||
import com.dfsek.terra.world.TerraWorld;
|
||||
import com.dfsek.terra.world.generation.generators.DefaultChunkGenerator3D;
|
||||
import com.dfsek.terra.world.generation.math.samplers.Sampler;
|
||||
@@ -20,7 +18,6 @@ import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||
import net.jafama.FastMath;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.entity.SpawnGroup;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.structure.StructureManager;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
@@ -30,14 +27,9 @@ import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.world.BlockView;
|
||||
import net.minecraft.world.ChunkRegion;
|
||||
import net.minecraft.world.Heightmap;
|
||||
import net.minecraft.world.SpawnHelper;
|
||||
import net.minecraft.world.WorldAccess;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
import net.minecraft.world.biome.SpawnSettings;
|
||||
import net.minecraft.world.biome.source.BiomeAccess;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
import net.minecraft.world.dimension.DimensionType;
|
||||
import net.minecraft.world.gen.ChunkRandom;
|
||||
import net.minecraft.world.gen.GenerationStep;
|
||||
import net.minecraft.world.gen.StructureAccessor;
|
||||
import net.minecraft.world.gen.chunk.ChunkGenerator;
|
||||
@@ -46,7 +38,6 @@ import net.minecraft.world.gen.chunk.VerticalBlockSample;
|
||||
import net.minecraft.world.gen.feature.StructureFeature;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
@@ -64,14 +55,13 @@ public class FabricChunkGeneratorWrapper extends ChunkGenerator implements Gener
|
||||
PACK_CODEC.fieldOf("pack").stable().forGetter(generator -> generator.pack))
|
||||
.apply(instance, instance.stable(FabricChunkGeneratorWrapper::new)));
|
||||
private final ConfigPack pack;
|
||||
private DimensionType dimensionType;
|
||||
|
||||
public ConfigPack getPack() {
|
||||
return pack;
|
||||
}
|
||||
|
||||
public FabricChunkGeneratorWrapper(TerraBiomeSource biomeSource, long seed, ConfigPack configPack) {
|
||||
super(biomeSource, new StructuresConfig(configPack.getTemplate().vanillaStructures()));
|
||||
super(biomeSource, new StructuresConfig(false));
|
||||
this.pack = configPack;
|
||||
|
||||
this.delegate = new DefaultChunkGenerator3D(pack, TerraFabricPlugin.getInstance());
|
||||
@@ -97,31 +87,31 @@ public class FabricChunkGeneratorWrapper extends ChunkGenerator implements Gener
|
||||
|
||||
}
|
||||
|
||||
public void setDimensionType(DimensionType dimensionType) {
|
||||
this.dimensionType = dimensionType;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public BlockPos locateStructure(ServerWorld world, StructureFeature<?> feature, BlockPos center, int radius, boolean skipExistingChunks) {
|
||||
if(!pack.getTemplate().disableStructures()) {
|
||||
String name = Objects.requireNonNull(Registry.STRUCTURE_FEATURE.getId(feature)).toString();
|
||||
TerraWorld terraWorld = TerraFabricPlugin.getInstance().getWorld((World) world);
|
||||
TerraStructure located = pack.getStructure(pack.getTemplate().getLocatable().get(name));
|
||||
if(located != null) {
|
||||
CompletableFuture<BlockPos> result = new CompletableFuture<>();
|
||||
AsyncStructureFinder finder = new AsyncStructureFinder(terraWorld.getBiomeProvider(), located, FabricAdapter.adapt(center).toLocation((World) world), 0, 500, location -> {
|
||||
result.complete(FabricAdapter.adapt(location));
|
||||
}, TerraFabricPlugin.getInstance());
|
||||
finder.run(); // Do this synchronously.
|
||||
try {
|
||||
return result.get();
|
||||
} catch(InterruptedException | ExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
String name = Objects.requireNonNull(Registry.STRUCTURE_FEATURE.getId(feature)).toString();
|
||||
TerraWorld terraWorld = TerraFabricPlugin.getInstance().getWorld((World) world);
|
||||
TerraStructure located = pack.getStructure(pack.getTemplate().getLocatable().get(name));
|
||||
if(located != null) {
|
||||
CompletableFuture<BlockPos> result = new CompletableFuture<>();
|
||||
AsyncStructureFinder finder = new AsyncStructureFinder(terraWorld.getBiomeProvider(), located, FabricAdapter.adapt(center).toLocation((World) world), 0, 500, location -> {
|
||||
result.complete(FabricAdapter.adapt(location));
|
||||
}, TerraFabricPlugin.getInstance());
|
||||
finder.run(); // Do this synchronously.
|
||||
try {
|
||||
return result.get();
|
||||
} catch(InterruptedException | ExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
return super.locateStructure(world, feature, center, radius, skipExistingChunks);
|
||||
TerraFabricPlugin.getInstance().logger().warning("No overrides are defined for \"" + name + "\"");
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void generateFeatures(ChunkRegion region, StructureAccessor accessor) {
|
||||
super.generateFeatures(region, accessor);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -131,39 +121,44 @@ public class FabricChunkGeneratorWrapper extends ChunkGenerator implements Gener
|
||||
|
||||
@Override
|
||||
public void carve(long seed, BiomeAccess access, Chunk chunk, GenerationStep.Carver carver) {
|
||||
if(pack.getTemplate().vanillaCaves()) super.carve(seed, access, chunk, carver);
|
||||
// No caves
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStructureStarts(DynamicRegistryManager dynamicRegistryManager, StructureAccessor structureAccessor, Chunk chunk, StructureManager structureManager, long worldSeed) {
|
||||
if(pack.getTemplate().vanillaStructures())
|
||||
super.setStructureStarts(dynamicRegistryManager, structureAccessor, chunk, structureManager, worldSeed);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isStrongholdStartingChunk(ChunkPos chunkPos) {
|
||||
if(pack.getTemplate().vanillaStructures()) return super.isStrongholdStartingChunk(chunkPos);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeight(int x, int z, Heightmap.Type heightmapType) {
|
||||
TerraWorld world = TerraFabricPlugin.getInstance().getWorld(dimensionType);
|
||||
TerraWorld world = TerraFabricPlugin.getInstance().getWorld(seed);
|
||||
Sampler sampler = world.getConfig().getSamplerCache().getChunk(FastMath.floorDiv(x, 16), FastMath.floorDiv(z, 16));
|
||||
int cx = FastMath.floorMod(x, 16);
|
||||
int cz = FastMath.floorMod(z, 16);
|
||||
|
||||
int height = world.getWorld().getMaxHeight();
|
||||
while(height >= 0 && !heightmapType.getBlockPredicate().test(((FabricBlockData) world.getUngeneratedBlock(x, height - 1, z)).getHandle())) {
|
||||
|
||||
while (height >= 0 && sampler.sample(cx, height - 1, cz) < 0) {
|
||||
height--;
|
||||
}
|
||||
|
||||
return height;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockView getColumnSample(int x, int z) {
|
||||
TerraWorld world = TerraFabricPlugin.getInstance().getWorld(dimensionType);
|
||||
int height = getHeight(x, z, Heightmap.Type.WORLD_SURFACE);
|
||||
int height = 64; // TODO: implementation
|
||||
BlockState[] array = new BlockState[256];
|
||||
for(int y = 255; y >= 0; y--) {
|
||||
if(y > height) {
|
||||
if(y > ((UserDefinedBiome) world.getBiomeProvider().getBiome(x, z)).getConfig().getSeaLevel()) {
|
||||
if(y > getSeaLevel()) {
|
||||
array[y] = Blocks.AIR.getDefaultState();
|
||||
} else {
|
||||
array[y] = Blocks.WATER.getDefaultState();
|
||||
@@ -176,39 +171,6 @@ public class FabricChunkGeneratorWrapper extends ChunkGenerator implements Gener
|
||||
return new VerticalBlockSample(array);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SpawnSettings.SpawnEntry> getEntitySpawnList(Biome biome, StructureAccessor accessor, SpawnGroup group, BlockPos pos) {
|
||||
if(pack.getTemplate().vanillaStructures()) {
|
||||
if(accessor.getStructureAt(pos, true, StructureFeature.SWAMP_HUT).hasChildren()) {
|
||||
if(group == SpawnGroup.MONSTER) return StructureFeature.SWAMP_HUT.getMonsterSpawns();
|
||||
if(group == SpawnGroup.CREATURE) return StructureFeature.SWAMP_HUT.getCreatureSpawns();
|
||||
}
|
||||
|
||||
if(group == SpawnGroup.MONSTER) {
|
||||
if(accessor.getStructureAt(pos, false, StructureFeature.PILLAGER_OUTPOST).hasChildren()) {
|
||||
return StructureFeature.PILLAGER_OUTPOST.getMonsterSpawns();
|
||||
} else if(accessor.getStructureAt(pos, false, StructureFeature.MONUMENT).hasChildren()) {
|
||||
return StructureFeature.MONUMENT.getMonsterSpawns();
|
||||
} else if(accessor.getStructureAt(pos, true, StructureFeature.FORTRESS).hasChildren()) {
|
||||
return StructureFeature.FORTRESS.getMonsterSpawns();
|
||||
}
|
||||
}
|
||||
}
|
||||
return super.getEntitySpawnList(biome, accessor, group, pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void populateEntities(ChunkRegion region) {
|
||||
if(pack.getTemplate().vanillaMobs()) {
|
||||
int cx = region.getCenterChunkX();
|
||||
int cy = region.getCenterChunkZ();
|
||||
Biome biome = region.getBiome((new ChunkPos(cx, cy)).getStartPos());
|
||||
ChunkRandom chunkRandom = new ChunkRandom();
|
||||
chunkRandom.setPopulationSeed(region.getSeed(), cx << 4, cy << 4);
|
||||
SpawnHelper.populateEntities(region, biome, cx, cy, chunkRandom);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public TerraChunkGenerator getHandle() {
|
||||
return delegate;
|
||||
|
||||
+1
-1
@@ -2,6 +2,7 @@ package com.dfsek.terra.fabric.generation;
|
||||
|
||||
import com.dfsek.terra.api.platform.world.Chunk;
|
||||
import com.dfsek.terra.api.platform.world.World;
|
||||
import com.dfsek.terra.fabric.generation.FabricChunkGeneratorWrapper;
|
||||
import com.mojang.serialization.Codec;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.StructureWorldAccess;
|
||||
@@ -21,7 +22,6 @@ public class PopulatorFeature extends Feature<DefaultFeatureConfig> {
|
||||
|
||||
@Override
|
||||
public boolean generate(StructureWorldAccess world, ChunkGenerator chunkGenerator, Random random, BlockPos pos, DefaultFeatureConfig config) {
|
||||
if(!(chunkGenerator instanceof FabricChunkGeneratorWrapper)) return true;
|
||||
FabricChunkGeneratorWrapper gen = (FabricChunkGeneratorWrapper) chunkGenerator;
|
||||
gen.getHandle().getPopulators().forEach(populator -> populator.populate((World) world, (Chunk) world));
|
||||
return true;
|
||||
|
||||
+11
-6
@@ -4,7 +4,6 @@ import com.dfsek.terra.api.world.biome.UserDefinedBiome;
|
||||
import com.dfsek.terra.api.world.biome.provider.BiomeProvider;
|
||||
import com.dfsek.terra.config.pack.ConfigPack;
|
||||
import com.dfsek.terra.fabric.TerraFabricPlugin;
|
||||
import com.dfsek.terra.fabric.util.FabricUtil;
|
||||
import com.mojang.serialization.Codec;
|
||||
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||
import net.minecraft.util.Identifier;
|
||||
@@ -12,8 +11,8 @@ import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.util.registry.RegistryLookupCodec;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
import net.minecraft.world.biome.source.BiomeSource;
|
||||
import net.minecraft.world.gen.feature.StructureFeature;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class TerraBiomeSource extends BiomeSource {
|
||||
@@ -32,9 +31,7 @@ public class TerraBiomeSource extends BiomeSource {
|
||||
private final ConfigPack pack;
|
||||
|
||||
public TerraBiomeSource(Registry<Biome> biomes, long seed, ConfigPack pack) {
|
||||
super(biomes.stream()
|
||||
.filter(biome -> Objects.requireNonNull(biomes.getId(biome)).getNamespace().equals("terra")) // Filter out non-Terra biomes.
|
||||
.collect(Collectors.toList()));
|
||||
super(biomes.stream().collect(Collectors.toList()));
|
||||
this.biomeRegistry = biomes;
|
||||
this.seed = seed;
|
||||
this.grid = pack.getBiomeProviderBuilder().build(seed);
|
||||
@@ -54,6 +51,14 @@ public class TerraBiomeSource extends BiomeSource {
|
||||
@Override
|
||||
public Biome getBiomeForNoiseGen(int biomeX, int biomeY, int biomeZ) {
|
||||
UserDefinedBiome biome = (UserDefinedBiome) grid.getBiome(biomeX << 2, biomeZ << 2);
|
||||
return biomeRegistry.get(new Identifier("terra", FabricUtil.createBiomeID(pack, biome.getID())));
|
||||
return biomeRegistry.get(new Identifier("terra", TerraFabricPlugin.createBiomeID(pack, biome.getID())));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean hasStructureFeature(StructureFeature<?> feature) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
-22
@@ -1,22 +0,0 @@
|
||||
package com.dfsek.terra.fabric.generation;
|
||||
|
||||
import com.dfsek.terra.config.pack.ConfigPack;
|
||||
import net.minecraft.client.world.GeneratorType;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
import net.minecraft.world.gen.chunk.ChunkGenerator;
|
||||
import net.minecraft.world.gen.chunk.ChunkGeneratorSettings;
|
||||
|
||||
public class TerraGeneratorType extends GeneratorType {
|
||||
private final ConfigPack pack;
|
||||
|
||||
public TerraGeneratorType(ConfigPack pack) {
|
||||
super("terra." + pack.getTemplate().getID());
|
||||
this.pack = pack;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ChunkGenerator getChunkGenerator(Registry<Biome> biomeRegistry, Registry<ChunkGeneratorSettings> chunkGeneratorSettingsRegistry, long seed) {
|
||||
return new FabricChunkGeneratorWrapper(new TerraBiomeSource(biomeRegistry, seed, pack), seed, pack);
|
||||
}
|
||||
}
|
||||
+1
-15
@@ -1,13 +1,9 @@
|
||||
package com.dfsek.terra.fabric.handle;
|
||||
|
||||
import com.dfsek.terra.api.math.vector.Location;
|
||||
import com.dfsek.terra.api.platform.entity.EntityType;
|
||||
import com.dfsek.terra.api.platform.entity.Player;
|
||||
import com.dfsek.terra.api.platform.handle.WorldHandle;
|
||||
import com.dfsek.terra.api.util.generic.pair.Pair;
|
||||
import com.dfsek.terra.fabric.FabricAdapter;
|
||||
import com.dfsek.terra.fabric.block.FabricBlockData;
|
||||
import com.dfsek.terra.fabric.util.FabricAdapter;
|
||||
import com.dfsek.terra.fabric.util.WorldEditUtil;
|
||||
import com.mojang.brigadier.StringReader;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import net.minecraft.block.BlockState;
|
||||
@@ -37,14 +33,4 @@ public class FabricWorldHandle implements WorldHandle {
|
||||
if(identifier == null) identifier = Identifier.tryParse("minecraft:" + id.toLowerCase(Locale.ROOT));
|
||||
return (EntityType) Registry.ENTITY_TYPE.get(identifier);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pair<Location, Location> getSelectedLocation(Player player) {
|
||||
try {
|
||||
Class.forName("com.sk89q.worldedit.WorldEdit");
|
||||
} catch(ClassNotFoundException e) {
|
||||
throw new IllegalStateException("WorldEdit is not installed.");
|
||||
}
|
||||
return WorldEditUtil.getSelection(player);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,86 +0,0 @@
|
||||
package com.dfsek.terra.fabric.mixin;
|
||||
|
||||
import com.dfsek.terra.api.command.exception.CommandException;
|
||||
import com.dfsek.terra.api.platform.CommandSender;
|
||||
import com.dfsek.terra.api.platform.entity.Entity;
|
||||
import com.dfsek.terra.fabric.TerraFabricPlugin;
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import net.minecraft.server.command.CommandManager;
|
||||
import net.minecraft.server.command.ServerCommandSource;
|
||||
import net.minecraft.text.LiteralText;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static net.minecraft.server.command.CommandManager.argument;
|
||||
import static net.minecraft.server.command.CommandManager.literal;
|
||||
|
||||
@Mixin(CommandManager.class)
|
||||
public abstract class CommandManagerMixin {
|
||||
@Shadow
|
||||
@Final
|
||||
private CommandDispatcher<ServerCommandSource> dispatcher;
|
||||
|
||||
@Inject(method = "<init>", at = @At(value = "INVOKE", 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 = TerraFabricPlugin.getInstance().getManager();
|
||||
int max = manager.getMaxArgumentDepth();
|
||||
RequiredArgumentBuilder<ServerCommandSource, String> arg = argument("arg" + (max - 1), StringArgumentType.word());
|
||||
for(int i = 0; i < max; i++) {
|
||||
RequiredArgumentBuilder<ServerCommandSource, String> next = argument("arg" + (max - i - 1), StringArgumentType.word());
|
||||
|
||||
arg = next.then(assemble(arg, manager));
|
||||
}
|
||||
|
||||
dispatcher.register(literal("terra").executes(context -> 1).then(assemble(arg, manager)));
|
||||
dispatcher.register(literal("te").executes(context -> 1).then(assemble(arg, manager)));
|
||||
}
|
||||
|
||||
private RequiredArgumentBuilder<ServerCommandSource, String> assemble(RequiredArgumentBuilder<ServerCommandSource, String> in, com.dfsek.terra.api.command.CommandManager manager) {
|
||||
return in.suggests((context, builder) -> {
|
||||
List<String> args = parseCommand(context.getInput());
|
||||
CommandSender sender = (CommandSender) context.getSource();
|
||||
try {
|
||||
sender = (Entity) context.getSource().getEntityOrThrow();
|
||||
} catch(CommandSyntaxException ignore) {
|
||||
}
|
||||
try {
|
||||
manager.tabComplete(args.remove(0), sender, args).forEach(builder::suggest);
|
||||
} catch(CommandException e) {
|
||||
sender.sendMessage(e.getMessage());
|
||||
}
|
||||
return builder.buildFuture();
|
||||
}).executes(context -> {
|
||||
List<String> args = parseCommand(context.getInput());
|
||||
CommandSender sender = (CommandSender) context.getSource();
|
||||
try {
|
||||
sender = (Entity) context.getSource().getEntityOrThrow();
|
||||
} catch(CommandSyntaxException ignore) {
|
||||
}
|
||||
try {
|
||||
manager.execute(args.remove(0), sender, args);
|
||||
} catch(CommandException e) {
|
||||
context.getSource().sendError(new LiteralText(e.getMessage()));
|
||||
}
|
||||
return 1;
|
||||
});
|
||||
}
|
||||
|
||||
private List<String> parseCommand(String command) {
|
||||
if(command.startsWith("/terra ")) command = command.substring("/terra ".length());
|
||||
else if(command.startsWith("/te ")) command = command.substring("/te ".length());
|
||||
List<String> c = new ArrayList<>(Arrays.asList(command.split(" ")));
|
||||
if(command.endsWith(" ")) c.add("");
|
||||
return c;
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
package com.dfsek.terra.fabric.mixin;
|
||||
|
||||
import com.dfsek.terra.api.util.generic.pair.Pair;
|
||||
import com.dfsek.terra.fabric.TerraFabricPlugin;
|
||||
import com.dfsek.terra.fabric.generation.FabricChunkGeneratorWrapper;
|
||||
import com.dfsek.terra.world.TerraWorld;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.WorldGenerationProgressListener;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.util.registry.RegistryKey;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.dimension.DimensionType;
|
||||
import net.minecraft.world.gen.Spawner;
|
||||
import net.minecraft.world.gen.chunk.ChunkGenerator;
|
||||
import net.minecraft.world.level.ServerWorldProperties;
|
||||
import net.minecraft.world.level.storage.LevelStorage;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
@Mixin(ServerWorld.class)
|
||||
public abstract class ServerWorldMixin {
|
||||
@Inject(method = "<init>", at = @At(value = "RETURN"))
|
||||
public void injectConstructor(MinecraftServer server, Executor workerExecutor, LevelStorage.Session session, ServerWorldProperties properties, RegistryKey<World> registryKey, DimensionType dimensionType, WorldGenerationProgressListener worldGenerationProgressListener, ChunkGenerator chunkGenerator, boolean debugWorld, long l, List<Spawner> list, boolean bl, CallbackInfo ci) {
|
||||
if(chunkGenerator instanceof FabricChunkGeneratorWrapper) {
|
||||
TerraFabricPlugin.getInstance().getWorldMap().put(dimensionType, Pair.of((ServerWorld) (Object) this, new TerraWorld((com.dfsek.terra.api.platform.world.World) this, ((FabricChunkGeneratorWrapper) chunkGenerator).getPack(), TerraFabricPlugin.getInstance())));
|
||||
((FabricChunkGeneratorWrapper) chunkGenerator).setDimensionType(dimensionType);
|
||||
TerraFabricPlugin.getInstance().logger().info("Registered world " + this + " to dimension type " + dimensionType);
|
||||
}
|
||||
}
|
||||
}
|
||||
-2
@@ -3,13 +3,11 @@ package com.dfsek.terra.fabric.mixin.implementations;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
import org.spongepowered.asm.mixin.Implements;
|
||||
import org.spongepowered.asm.mixin.Interface;
|
||||
import org.spongepowered.asm.mixin.Intrinsic;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
|
||||
@Mixin(Biome.class)
|
||||
@Implements(@Interface(iface = com.dfsek.terra.api.platform.world.Biome.class, prefix = "terra$", remap = Interface.Remap.NONE))
|
||||
public abstract class BiomeMixin {
|
||||
@Intrinsic
|
||||
public Object terra$getHandle() {
|
||||
return this;
|
||||
}
|
||||
|
||||
-2
@@ -3,13 +3,11 @@ package com.dfsek.terra.fabric.mixin.implementations;
|
||||
import net.minecraft.world.gen.chunk.ChunkGenerator;
|
||||
import org.spongepowered.asm.mixin.Implements;
|
||||
import org.spongepowered.asm.mixin.Interface;
|
||||
import org.spongepowered.asm.mixin.Intrinsic;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
|
||||
@Mixin(ChunkGenerator.class)
|
||||
@Implements(@Interface(iface = com.dfsek.terra.api.platform.world.generator.ChunkGenerator.class, prefix = "terra$", remap = Interface.Remap.NONE))
|
||||
public abstract class ChunkGeneratorMixin {
|
||||
@Intrinsic
|
||||
public Object terra$getHandle() {
|
||||
return this;
|
||||
}
|
||||
|
||||
+1
-3
@@ -3,15 +3,14 @@ package com.dfsek.terra.fabric.mixin.implementations.block;
|
||||
import com.dfsek.terra.api.platform.block.Block;
|
||||
import com.dfsek.terra.api.platform.block.BlockData;
|
||||
import com.dfsek.terra.api.platform.block.state.BlockState;
|
||||
import com.dfsek.terra.fabric.FabricAdapter;
|
||||
import com.dfsek.terra.fabric.block.FabricBlock;
|
||||
import com.dfsek.terra.fabric.util.FabricAdapter;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.spongepowered.asm.mixin.Implements;
|
||||
import org.spongepowered.asm.mixin.Interface;
|
||||
import org.spongepowered.asm.mixin.Intrinsic;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
|
||||
@@ -30,7 +29,6 @@ public abstract class BlockEntityMixin {
|
||||
@Shadow
|
||||
public abstract boolean hasWorld();
|
||||
|
||||
@Intrinsic
|
||||
public Object terra$getHandle() {
|
||||
return this;
|
||||
}
|
||||
|
||||
+1
-3
@@ -2,13 +2,12 @@ package com.dfsek.terra.fabric.mixin.implementations.block;
|
||||
|
||||
import com.dfsek.terra.api.platform.block.BlockData;
|
||||
import com.dfsek.terra.api.platform.block.BlockType;
|
||||
import com.dfsek.terra.fabric.util.FabricAdapter;
|
||||
import com.dfsek.terra.fabric.FabricAdapter;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
import org.spongepowered.asm.mixin.Implements;
|
||||
import org.spongepowered.asm.mixin.Interface;
|
||||
import org.spongepowered.asm.mixin.Intrinsic;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
|
||||
@@ -18,7 +17,6 @@ public abstract class BlockMixin {
|
||||
@Shadow
|
||||
private BlockState defaultState;
|
||||
|
||||
@Intrinsic
|
||||
public Object terra$getHandle() {
|
||||
return this;
|
||||
}
|
||||
|
||||
-2
@@ -6,7 +6,6 @@ import com.dfsek.terra.fabric.mixin.implementations.block.BlockEntityMixin;
|
||||
import net.minecraft.block.entity.LootableContainerBlockEntity;
|
||||
import org.spongepowered.asm.mixin.Implements;
|
||||
import org.spongepowered.asm.mixin.Interface;
|
||||
import org.spongepowered.asm.mixin.Intrinsic;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
|
||||
@Mixin(LootableContainerBlockEntity.class)
|
||||
@@ -16,7 +15,6 @@ public abstract class LootableContainerBlockEntityMixin extends BlockEntityMixin
|
||||
return (Inventory) this;
|
||||
}
|
||||
|
||||
@Intrinsic
|
||||
public Object terra$getHandle() {
|
||||
return this;
|
||||
}
|
||||
|
||||
+3
-1
@@ -51,5 +51,7 @@ public abstract class ChunkRegionMixin {
|
||||
((ChunkRegion) (Object) this).setBlockState(new BlockPos(x + (centerChunkX << 4), y, z + (centerChunkZ << 4)), ((FabricBlockData) blockData).getHandle(), 0);
|
||||
}
|
||||
|
||||
// getHandle already added in world/ChunkRegionMixin.
|
||||
public Object terra$getHandle() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
-2
@@ -12,7 +12,6 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Implements;
|
||||
import org.spongepowered.asm.mixin.Interface;
|
||||
import org.spongepowered.asm.mixin.Intrinsic;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
|
||||
@@ -48,7 +47,6 @@ public abstract class WorldChunkMixin {
|
||||
((net.minecraft.world.chunk.Chunk) this).setBlockState(new BlockPos(x, y, z), ((FabricBlockData) blockData).getHandle(), false);
|
||||
}
|
||||
|
||||
@Intrinsic
|
||||
public Object terra$getHandle() {
|
||||
return this;
|
||||
}
|
||||
|
||||
-2
@@ -9,7 +9,6 @@ import net.minecraft.world.chunk.ProtoChunk;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.spongepowered.asm.mixin.Implements;
|
||||
import org.spongepowered.asm.mixin.Interface;
|
||||
import org.spongepowered.asm.mixin.Intrinsic;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
|
||||
@@ -27,7 +26,6 @@ public abstract class ProtoChunkMixin {
|
||||
((net.minecraft.world.chunk.Chunk) this).setBlockState(new BlockPos(x, y, z), ((FabricBlockData) blockData).getHandle(), false);
|
||||
}
|
||||
|
||||
@Intrinsic
|
||||
public Object terra$getHandle() {
|
||||
return this;
|
||||
}
|
||||
|
||||
+1
-3
@@ -2,14 +2,13 @@ package com.dfsek.terra.fabric.mixin.implementations.entity;
|
||||
|
||||
import com.dfsek.terra.api.math.vector.Location;
|
||||
import com.dfsek.terra.api.platform.world.World;
|
||||
import com.dfsek.terra.fabric.util.FabricAdapter;
|
||||
import com.dfsek.terra.fabric.FabricAdapter;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.text.LiteralText;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import org.spongepowered.asm.mixin.Implements;
|
||||
import org.spongepowered.asm.mixin.Interface;
|
||||
import org.spongepowered.asm.mixin.Intrinsic;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
|
||||
@@ -30,7 +29,6 @@ public abstract class EntityMixin {
|
||||
@Shadow
|
||||
public abstract void sendSystemMessage(Text message, UUID senderUuid);
|
||||
|
||||
@Intrinsic
|
||||
public Object terra$getHandle() {
|
||||
return this;
|
||||
}
|
||||
|
||||
-2
@@ -3,13 +3,11 @@ package com.dfsek.terra.fabric.mixin.implementations.entity;
|
||||
import net.minecraft.entity.EntityType;
|
||||
import org.spongepowered.asm.mixin.Implements;
|
||||
import org.spongepowered.asm.mixin.Interface;
|
||||
import org.spongepowered.asm.mixin.Intrinsic;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
|
||||
@Mixin(EntityType.class)
|
||||
@Implements(@Interface(iface = com.dfsek.terra.api.platform.entity.EntityType.class, prefix = "terra$", remap = Interface.Remap.NONE))
|
||||
public abstract class EntityTypeMixin {
|
||||
@Intrinsic
|
||||
public Object terra$getHandle() {
|
||||
return this;
|
||||
}
|
||||
|
||||
-2
@@ -6,7 +6,6 @@ import net.minecraft.text.LiteralText;
|
||||
import net.minecraft.text.Text;
|
||||
import org.spongepowered.asm.mixin.Implements;
|
||||
import org.spongepowered.asm.mixin.Interface;
|
||||
import org.spongepowered.asm.mixin.Intrinsic;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
|
||||
@@ -20,7 +19,6 @@ public abstract class ServerCommandSourceMixin {
|
||||
sendFeedback(new LiteralText(message), true);
|
||||
}
|
||||
|
||||
@Intrinsic
|
||||
public Object terra$getHandle() {
|
||||
return this;
|
||||
}
|
||||
|
||||
-2
@@ -6,13 +6,11 @@ import net.minecraft.block.entity.LockableContainerBlockEntity;
|
||||
import net.minecraft.item.Items;
|
||||
import org.spongepowered.asm.mixin.Implements;
|
||||
import org.spongepowered.asm.mixin.Interface;
|
||||
import org.spongepowered.asm.mixin.Intrinsic;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
|
||||
@Mixin(LockableContainerBlockEntity.class)
|
||||
@Implements(@Interface(iface = Inventory.class, prefix = "terra$", remap = Interface.Remap.NONE))
|
||||
public class LockableContainerBlockEntityMixin {
|
||||
@Intrinsic
|
||||
public Object terra$getHandle() {
|
||||
return this;
|
||||
}
|
||||
|
||||
-2
@@ -4,7 +4,6 @@ import com.dfsek.terra.api.platform.inventory.ItemStack;
|
||||
import net.minecraft.item.Item;
|
||||
import org.spongepowered.asm.mixin.Implements;
|
||||
import org.spongepowered.asm.mixin.Interface;
|
||||
import org.spongepowered.asm.mixin.Intrinsic;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
|
||||
@@ -14,7 +13,6 @@ public abstract class ItemMixin {
|
||||
@Shadow
|
||||
public abstract int getMaxDamage();
|
||||
|
||||
@Intrinsic
|
||||
public Object terra$getHandle() {
|
||||
return this;
|
||||
}
|
||||
|
||||
-1
@@ -50,7 +50,6 @@ public abstract class ItemStackMixin {
|
||||
setTag(((ItemStack) (Object) meta).getTag());
|
||||
}
|
||||
|
||||
@Intrinsic
|
||||
public Object terra$getHandle() {
|
||||
return this;
|
||||
}
|
||||
|
||||
-2
@@ -5,7 +5,6 @@ import net.minecraft.enchantment.Enchantment;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import org.spongepowered.asm.mixin.Implements;
|
||||
import org.spongepowered.asm.mixin.Interface;
|
||||
import org.spongepowered.asm.mixin.Intrinsic;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
|
||||
@@ -20,7 +19,6 @@ public abstract class EnchantmentMixin {
|
||||
@Shadow
|
||||
public abstract boolean canCombine(Enchantment other);
|
||||
|
||||
@Intrinsic
|
||||
public Object terra$getHandle() {
|
||||
return this;
|
||||
}
|
||||
|
||||
-1
@@ -28,7 +28,6 @@ public abstract class ItemStackMetaMixin {
|
||||
@Shadow
|
||||
public abstract void addEnchantment(net.minecraft.enchantment.Enchantment enchantment, int level);
|
||||
|
||||
@Intrinsic
|
||||
public Object terra$getHandle() {
|
||||
return this;
|
||||
}
|
||||
|
||||
-1
@@ -67,7 +67,6 @@ public abstract class ChunkRegionMixin {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Intrinsic
|
||||
public Object terra$getHandle() {
|
||||
return this;
|
||||
}
|
||||
|
||||
-1
@@ -58,7 +58,6 @@ public abstract class ServerWorldMixin {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Intrinsic
|
||||
public Object terra$getHandle() {
|
||||
return this;
|
||||
}
|
||||
|
||||
-29
@@ -1,29 +0,0 @@
|
||||
package com.dfsek.terra.fabric.mixin.init;
|
||||
|
||||
import com.dfsek.terra.fabric.TerraFabricPlugin;
|
||||
import com.dfsek.terra.fabric.generation.TerraGeneratorType;
|
||||
import com.dfsek.terra.fabric.mixin.access.GeneratorTypeAccessor;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.RunArgs;
|
||||
import net.minecraft.client.world.GeneratorType;
|
||||
import net.minecraft.text.LiteralText;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(MinecraftClient.class)
|
||||
public class MinecraftClientMixin {
|
||||
@Inject(method = "<init>", at = @At(value = "INVOKE",
|
||||
target = "Lnet/minecraft/client/util/WindowProvider;createWindow(Lnet/minecraft/client/WindowSettings;Ljava/lang/String;Ljava/lang/String;)Lnet/minecraft/client/util/Window;", // sorta arbitrary position, after mod init, before window opens
|
||||
shift = At.Shift.BEFORE))
|
||||
public void injectConstructor(RunArgs args, CallbackInfo callbackInfo) {
|
||||
TerraFabricPlugin.getInstance().packInit(); // Load during MinecraftClient construction, after other mods have registered blocks and stuff
|
||||
TerraFabricPlugin.getInstance().getConfigRegistry().forEach(pack -> {
|
||||
final GeneratorType generatorType = new TerraGeneratorType(pack);
|
||||
//noinspection ConstantConditions
|
||||
((GeneratorTypeAccessor) generatorType).setTranslationKey(new LiteralText("Terra:" + pack.getTemplate().getID()));
|
||||
GeneratorTypeAccessor.getValues().add(1, generatorType);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
package com.dfsek.terra.fabric.mixin.init;
|
||||
|
||||
import com.dfsek.terra.fabric.TerraFabricPlugin;
|
||||
import net.minecraft.server.Main;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(Main.class)
|
||||
public class ServerMainMixin {
|
||||
@Inject(method = "main([Ljava/lang/String;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/registry/DynamicRegistryManager;create()Lnet/minecraft/util/registry/DynamicRegistryManager$Impl;"))
|
||||
private static void injectConstructor(String[] args, CallbackInfo ci) {
|
||||
TerraFabricPlugin.getInstance().packInit(); // Load during MinecraftServer construction, after other mods have registered blocks and stuff
|
||||
}
|
||||
}
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
@@ -1,118 +0,0 @@
|
||||
package com.dfsek.terra.fabric.util;
|
||||
|
||||
import com.dfsek.terra.api.util.generic.pair.Pair;
|
||||
import com.dfsek.terra.config.builder.BiomeBuilder;
|
||||
import com.dfsek.terra.config.pack.ConfigPack;
|
||||
import com.dfsek.terra.config.templates.BiomeTemplate;
|
||||
import com.dfsek.terra.fabric.TerraFabricPlugin;
|
||||
import com.dfsek.terra.fabric.config.PostLoadCompatibilityOptions;
|
||||
import com.dfsek.terra.fabric.config.PreLoadCompatibilityOptions;
|
||||
import com.dfsek.terra.fabric.mixin.access.BiomeEffectsAccessor;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.registry.BuiltinRegistries;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
import net.minecraft.world.biome.BiomeEffects;
|
||||
import net.minecraft.world.biome.GenerationSettings;
|
||||
import net.minecraft.world.gen.GenerationStep;
|
||||
import net.minecraft.world.gen.carver.ConfiguredCarver;
|
||||
import net.minecraft.world.gen.feature.ConfiguredFeature;
|
||||
import net.minecraft.world.gen.feature.ConfiguredStructureFeature;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public final class FabricUtil {
|
||||
public static String createBiomeID(ConfigPack pack, String biomeID) {
|
||||
return pack.getTemplate().getID().toLowerCase() + "/" + biomeID.toLowerCase(Locale.ROOT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clones a Vanilla biome and injects Terra data to create a Terra-vanilla biome delegate.
|
||||
*
|
||||
* @param fabricAddon The Fabric addon instance.
|
||||
* @param biome The Terra BiomeBuilder.
|
||||
* @param pack The ConfigPack this biome belongs to.
|
||||
* @return The Minecraft delegate biome.
|
||||
*/
|
||||
public static Biome createBiome(TerraFabricPlugin.FabricAddon fabricAddon, BiomeBuilder biome, ConfigPack pack) {
|
||||
BiomeTemplate template = biome.getTemplate();
|
||||
Map<String, Integer> colors = template.getColors();
|
||||
|
||||
Biome vanilla = (Biome) (new ArrayList<>(biome.getVanillaBiomes().getContents()).get(0)).getHandle();
|
||||
|
||||
GenerationSettings.Builder generationSettings = new GenerationSettings.Builder();
|
||||
|
||||
generationSettings.surfaceBuilder(vanilla.getGenerationSettings().getSurfaceBuilder()); // It needs a surfacebuilder, even though we dont use it.
|
||||
|
||||
generationSettings.feature(GenerationStep.Feature.VEGETAL_DECORATION, TerraFabricPlugin.POPULATOR_CONFIGURED_FEATURE);
|
||||
|
||||
if(pack.getTemplate().vanillaCaves()) {
|
||||
for(GenerationStep.Carver carver : GenerationStep.Carver.values()) {
|
||||
for(Supplier<ConfiguredCarver<?>> configuredCarverSupplier : vanilla.getGenerationSettings().getCarversForStep(carver)) {
|
||||
generationSettings.carver(carver, configuredCarverSupplier.get());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Pair<PreLoadCompatibilityOptions, PostLoadCompatibilityOptions> pair = fabricAddon.getTemplates().get(pack);
|
||||
PreLoadCompatibilityOptions compatibilityOptions = pair.getLeft();
|
||||
PostLoadCompatibilityOptions postLoadCompatibilityOptions = pair.getRight();
|
||||
|
||||
TerraFabricPlugin.getInstance().getDebugLogger().info("Injecting Vanilla structures and features into Terra biome " + biome.getTemplate().getID());
|
||||
|
||||
for(Supplier<ConfiguredStructureFeature<?, ?>> structureFeature : vanilla.getGenerationSettings().getStructureFeatures()) {
|
||||
Identifier key = Objects.requireNonNull(BuiltinRegistries.CONFIGURED_STRUCTURE_FEATURE.getId(structureFeature.get()));
|
||||
if(compatibilityOptions.getStructureNamespaces().contains(key.getNamespace()) && !postLoadCompatibilityOptions.getExcludedPerBiomeStructures().getOrDefault(biome, Collections.emptySet()).contains(key)) {
|
||||
generationSettings.structureFeature(structureFeature.get());
|
||||
TerraFabricPlugin.getInstance().getDebugLogger().info("Injected structure " + key);
|
||||
}
|
||||
}
|
||||
|
||||
for(int step = 0; step < vanilla.getGenerationSettings().getFeatures().size(); step++) {
|
||||
for(Supplier<ConfiguredFeature<?, ?>> featureSupplier : vanilla.getGenerationSettings().getFeatures().get(step)) {
|
||||
Identifier key = Objects.requireNonNull(BuiltinRegistries.CONFIGURED_FEATURE.getId(featureSupplier.get()));
|
||||
if(compatibilityOptions.getFeatureNamespaces().contains(key.getNamespace()) && !postLoadCompatibilityOptions.getExcludedPerBiomeFeatures().getOrDefault(biome, Collections.emptySet()).contains(key)) {
|
||||
generationSettings.feature(step, featureSupplier);
|
||||
TerraFabricPlugin.getInstance().getDebugLogger().info("Injected feature " + key + " at stage " + step);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
BiomeEffectsAccessor accessor = (BiomeEffectsAccessor) vanilla.getEffects();
|
||||
BiomeEffects.Builder effects = new BiomeEffects.Builder()
|
||||
.waterColor(colors.getOrDefault("water", accessor.getWaterColor()))
|
||||
.waterFogColor(colors.getOrDefault("water-fog", accessor.getWaterFogColor()))
|
||||
.fogColor(colors.getOrDefault("fog", accessor.getFogColor()))
|
||||
.skyColor(colors.getOrDefault("sky", accessor.getSkyColor()))
|
||||
.grassColorModifier(accessor.getGrassColorModifier());
|
||||
|
||||
if(colors.containsKey("grass")) {
|
||||
effects.grassColor(colors.get("grass"));
|
||||
} else {
|
||||
accessor.getGrassColor().ifPresent(effects::grassColor);
|
||||
}
|
||||
if(colors.containsKey("foliage")) {
|
||||
effects.foliageColor(colors.get("foliage"));
|
||||
} else {
|
||||
accessor.getFoliageColor().ifPresent(effects::foliageColor);
|
||||
}
|
||||
|
||||
return new Biome.Builder()
|
||||
.precipitation(vanilla.getPrecipitation())
|
||||
.category(vanilla.getCategory())
|
||||
.depth(vanilla.getDepth())
|
||||
.scale(vanilla.getScale())
|
||||
.temperature(vanilla.getTemperature())
|
||||
.downfall(vanilla.getDownfall())
|
||||
.effects(effects.build())
|
||||
.spawnSettings(vanilla.getSpawnSettings())
|
||||
.generationSettings(generationSettings.build())
|
||||
.build();
|
||||
}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
package com.dfsek.terra.fabric.util;
|
||||
|
||||
import com.dfsek.terra.api.math.vector.Location;
|
||||
import com.dfsek.terra.api.platform.entity.Player;
|
||||
import com.dfsek.terra.api.util.generic.pair.Pair;
|
||||
import com.sk89q.worldedit.IncompleteRegionException;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public final class WorldEditUtil {
|
||||
public static Pair<Location, Location> getSelection(Player player) {
|
||||
WorldEdit worldEdit = WorldEdit.getInstance();
|
||||
try {
|
||||
Region selection = worldEdit.getSessionManager()
|
||||
.get(com.sk89q.worldedit.fabric.FabricAdapter.adaptPlayer((ServerPlayerEntity) player))
|
||||
.getSelection(com.sk89q.worldedit.fabric.FabricAdapter.adapt((World) player.getWorld()));
|
||||
BlockVector3 min = selection.getMinimumPoint();
|
||||
BlockVector3 max = selection.getMaximumPoint();
|
||||
Location l1 = new Location(player.getWorld(), min.getBlockX(), min.getBlockY(), min.getBlockZ());
|
||||
Location l2 = new Location(player.getWorld(), max.getBlockX(), max.getBlockY(), max.getBlockZ());
|
||||
return Pair.of(l1, l2);
|
||||
} catch(IncompleteRegionException e) {
|
||||
throw new IllegalStateException("No selection has been made", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,16 +3,15 @@
|
||||
"id": "terra",
|
||||
"version": "@VERSION@",
|
||||
"name": "Terra",
|
||||
"description": "@DESCRIPTION@",
|
||||
"description": "An insanely powerful free & open-source data-driven world generator.",
|
||||
"authors": [
|
||||
"dfsek"
|
||||
],
|
||||
"contact": {
|
||||
"homepage": "@WIKI@",
|
||||
"sources": "@SOURCE@",
|
||||
"issues": "@ISSUES@"
|
||||
"homepage": "https://github.com/PolyhedralDev/Terra/wiki",
|
||||
"sources": "https://github.com/PolyhedralDev/Terra"
|
||||
},
|
||||
"license": "@LICENSE@",
|
||||
"license": "GPL-3.0",
|
||||
"icon": "assets/terra/icon.png",
|
||||
"environment": "*",
|
||||
"entrypoints": {
|
||||
@@ -25,6 +24,7 @@
|
||||
],
|
||||
"depends": {
|
||||
"fabricloader": ">=0.7.4",
|
||||
"fabric": "*",
|
||||
"minecraft": "1.16.x"
|
||||
},
|
||||
"accessWidener": "terra.accesswidener"
|
||||
|
||||
@@ -4,9 +4,7 @@
|
||||
"package": "com.dfsek.terra.fabric.mixin",
|
||||
"compatibilityLevel": "JAVA_8",
|
||||
"mixins": [
|
||||
"CommandManagerMixin",
|
||||
"GeneratorOptionsMixin",
|
||||
"ServerWorldMixin",
|
||||
"access.BiomeEffectsAccessor",
|
||||
"access.MobSpawnerLogicAccessor",
|
||||
"access.StateAccessor",
|
||||
@@ -35,12 +33,9 @@
|
||||
"implementations.world.ServerWorldMixin"
|
||||
],
|
||||
"client": [
|
||||
"access.GeneratorTypeAccessor",
|
||||
"init.MinecraftClientMixin"
|
||||
],
|
||||
"server": [
|
||||
"init.ServerMainMixin"
|
||||
"access.GeneratorTypeAccessor"
|
||||
],
|
||||
"server": [],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
},
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import com.dfsek.terra.configureCommon
|
||||
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
|
||||
import net.minecraftforge.gradle.common.util.RunConfig
|
||||
import net.minecraftforge.gradle.mcp.task.GenerateSRG
|
||||
import net.minecraftforge.gradle.userdev.UserDevExtension
|
||||
import net.minecraftforge.gradle.userdev.tasks.RenameJarInPlace
|
||||
|
||||
@@ -55,17 +55,11 @@ if ("true" == System.getProperty("idea.sync.active")) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
tasks.named<ShadowJar>("shadowJar") {
|
||||
archiveBaseName.set(tasks.getByName<Jar>("jar").archiveBaseName.orNull) // Pain. Agony, even.
|
||||
archiveClassifier.set("") // Suffering, if you will.
|
||||
}
|
||||
|
||||
afterEvaluate {
|
||||
tasks.named<RenameJarInPlace>("reobfJar") {
|
||||
val shadow = tasks.getByName<ShadowJar>("shadowJar");
|
||||
dependsOn(shadow)
|
||||
input = shadow.archiveFile.orNull?.asFile
|
||||
val reobf = extensions.getByName<NamedDomainObjectContainer<RenameJarInPlace>>("reobf")
|
||||
reobf.maybeCreate("shadowJar").run {
|
||||
group = "forge"
|
||||
mappings = tasks.getByName<GenerateSRG>("createMcpToSrg").output
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,7 +71,7 @@ configure<UserDevExtension> {
|
||||
runs {
|
||||
val runConfig = Action<RunConfig> {
|
||||
properties(mapOf(
|
||||
//"forge.logging.markers" to "SCAN,REGISTRIES,REGISTRYDUMP",
|
||||
"forge.logging.markers" to "SCAN,REGISTRIES,REGISTRYDUMP",
|
||||
"forge.logging.console.level" to "debug"
|
||||
))
|
||||
arg("-mixin.config=terra.mixins.json")
|
||||
@@ -130,12 +124,12 @@ tasks.jar {
|
||||
}
|
||||
|
||||
tasks.register<com.modrinth.minotaur.TaskModrinthUpload>("publishModrinthForge") {
|
||||
dependsOn("reobfJar")
|
||||
dependsOn("reobfShadowJar")
|
||||
group = "forge"
|
||||
token = System.getenv("MODRINTH_SECRET")
|
||||
projectId = "FIlZB9L0"
|
||||
versionNumber = "${project.version}-forge"
|
||||
uploadFile = tasks.named<RenameJarInPlace>("reobfJar").get().input.absoluteFile
|
||||
uploadFile = tasks.named<RenameJarInPlace>("reobfShadowJar").get().input.absoluteFile
|
||||
releaseType = "alpha"
|
||||
addGameVersion("1.16.5")
|
||||
addLoader("forge")
|
||||
|
||||
@@ -1,90 +0,0 @@
|
||||
package com.dfsek.terra.forge;
|
||||
|
||||
import com.dfsek.terra.api.math.vector.Vector3;
|
||||
import com.dfsek.terra.api.platform.block.BlockFace;
|
||||
import com.dfsek.terra.api.platform.block.state.Container;
|
||||
import com.dfsek.terra.api.platform.block.state.MobSpawner;
|
||||
import com.dfsek.terra.api.platform.block.state.Sign;
|
||||
import com.dfsek.terra.forge.block.ForgeBlockData;
|
||||
import com.dfsek.terra.forge.block.data.ForgeDirectional;
|
||||
import com.dfsek.terra.forge.block.data.ForgeMultipleFacing;
|
||||
import com.dfsek.terra.forge.block.data.ForgeOrientable;
|
||||
import com.dfsek.terra.forge.block.data.ForgeRotatable;
|
||||
import com.dfsek.terra.forge.block.data.ForgeSlab;
|
||||
import com.dfsek.terra.forge.block.data.ForgeStairs;
|
||||
import com.dfsek.terra.forge.block.data.ForgeWaterlogged;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.state.properties.BlockStateProperties;
|
||||
import net.minecraft.tileentity.LockableLootTileEntity;
|
||||
import net.minecraft.tileentity.MobSpawnerTileEntity;
|
||||
import net.minecraft.tileentity.SignTileEntity;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IWorld;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public final class ForgeAdapter {
|
||||
public static BlockPos adapt(Vector3 v) {
|
||||
return new BlockPos(v.getBlockX(), v.getBlockY(), v.getBlockZ());
|
||||
}
|
||||
|
||||
public static Vector3 adapt(BlockPos pos) {
|
||||
return new Vector3(pos.getX(), pos.getY(), pos.getZ());
|
||||
}
|
||||
|
||||
public static ForgeBlockData adapt(BlockState state) {
|
||||
if(state.hasProperty(BlockStateProperties.STAIRS_SHAPE)) return new ForgeStairs(state);
|
||||
|
||||
if(state.hasProperty(BlockStateProperties.SLAB_TYPE)) return new ForgeSlab(state);
|
||||
|
||||
if(state.hasProperty(BlockStateProperties.AXIS)) return new ForgeOrientable(state, BlockStateProperties.AXIS);
|
||||
if(state.hasProperty(BlockStateProperties.HORIZONTAL_AXIS)) return new ForgeOrientable(state, BlockStateProperties.HORIZONTAL_AXIS);
|
||||
|
||||
if(state.hasProperty(BlockStateProperties.ROTATION_16)) return new ForgeRotatable(state);
|
||||
|
||||
if(state.hasProperty(BlockStateProperties.FACING)) return new ForgeDirectional(state, BlockStateProperties.FACING);
|
||||
if(state.hasProperty(BlockStateProperties.FACING_HOPPER)) return new ForgeDirectional(state, BlockStateProperties.FACING_HOPPER);
|
||||
if(state.hasProperty(BlockStateProperties.HORIZONTAL_FACING))
|
||||
return new ForgeDirectional(state, BlockStateProperties.HORIZONTAL_FACING);
|
||||
|
||||
if(state.getProperties().containsAll(Arrays.asList(BlockStateProperties.NORTH, BlockStateProperties.SOUTH, BlockStateProperties.EAST, BlockStateProperties.WEST)))
|
||||
return new ForgeMultipleFacing(state);
|
||||
if(state.hasProperty(BlockStateProperties.WATERLOGGED)) return new ForgeWaterlogged(state);
|
||||
return new ForgeBlockData(state);
|
||||
}
|
||||
|
||||
public static com.dfsek.terra.api.platform.block.state.BlockState adapt(com.dfsek.terra.api.platform.block.Block block) {
|
||||
IWorld worldAccess = (IWorld) block.getLocation().getWorld();
|
||||
|
||||
TileEntity entity = worldAccess.getBlockEntity(adapt(block.getLocation().toVector()));
|
||||
if(entity instanceof SignTileEntity) {
|
||||
return (Sign) entity;
|
||||
} else if(entity instanceof MobSpawnerTileEntity) {
|
||||
return (MobSpawner) entity;
|
||||
} else if(entity instanceof LockableLootTileEntity) {
|
||||
return (Container) entity;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Direction adapt(BlockFace face) {
|
||||
switch(face) {
|
||||
case NORTH:
|
||||
return Direction.NORTH;
|
||||
case WEST:
|
||||
return Direction.WEST;
|
||||
case SOUTH:
|
||||
return Direction.SOUTH;
|
||||
case EAST:
|
||||
return Direction.EAST;
|
||||
case UP:
|
||||
return Direction.UP;
|
||||
case DOWN:
|
||||
return Direction.DOWN;
|
||||
default:
|
||||
throw new IllegalArgumentException("Illegal direction: " + face);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
package com.dfsek.terra.forge;
|
||||
|
||||
import com.dfsek.terra.api.platform.modloader.Mod;
|
||||
import net.minecraftforge.fml.loading.moddiscovery.ModInfo;
|
||||
|
||||
public class ForgeMod implements Mod {
|
||||
private final ModInfo mod;
|
||||
|
||||
public ForgeMod(ModInfo mod) {
|
||||
this.mod = mod;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getID() {
|
||||
return mod.getModId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getVersion() {
|
||||
return mod.getVersion().getQualifier();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return mod.getDisplayName();
|
||||
}
|
||||
}
|
||||
@@ -1,109 +0,0 @@
|
||||
package com.dfsek.terra.forge;
|
||||
|
||||
import com.dfsek.terra.api.util.generic.pair.Pair;
|
||||
import com.dfsek.terra.config.builder.BiomeBuilder;
|
||||
import com.dfsek.terra.config.pack.ConfigPack;
|
||||
import com.dfsek.terra.config.templates.BiomeTemplate;
|
||||
import com.dfsek.terra.forge.config.PostLoadCompatibilityOptions;
|
||||
import com.dfsek.terra.forge.config.PreLoadCompatibilityOptions;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.registry.WorldGenRegistries;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
import net.minecraft.world.biome.BiomeAmbience;
|
||||
import net.minecraft.world.biome.BiomeGenerationSettings;
|
||||
import net.minecraft.world.gen.GenerationStage;
|
||||
import net.minecraft.world.gen.carver.ConfiguredCarver;
|
||||
import net.minecraft.world.gen.feature.ConfiguredFeature;
|
||||
import net.minecraft.world.gen.feature.StructureFeature;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public final class ForgeUtil {
|
||||
public static String createBiomeID(ConfigPack pack, String biomeID) {
|
||||
return pack.getTemplate().getID().toLowerCase() + "/" + biomeID.toLowerCase(Locale.ROOT);
|
||||
}
|
||||
|
||||
public static Biome createBiome(BiomeBuilder biome, ConfigPack pack, TerraForgePlugin.ForgeAddon forgeAddon) {
|
||||
BiomeTemplate template = biome.getTemplate();
|
||||
Map<String, Integer> colors = template.getColors();
|
||||
|
||||
Biome vanilla = (Biome) (new ArrayList<>(biome.getVanillaBiomes().getContents()).get(0)).getHandle();
|
||||
|
||||
BiomeGenerationSettings.Builder generationSettings = new BiomeGenerationSettings.Builder();
|
||||
|
||||
generationSettings.surfaceBuilder(vanilla.getGenerationSettings().getSurfaceBuilder()); // It needs a surfacebuilder, even though we dont use it.
|
||||
|
||||
generationSettings.addFeature(GenerationStage.Decoration.VEGETAL_DECORATION, TerraForgePlugin.POPULATOR_CONFIGURED_FEATURE);
|
||||
|
||||
if(pack.getTemplate().vanillaCaves()) {
|
||||
for(GenerationStage.Carving carver : GenerationStage.Carving.values()) {
|
||||
for(Supplier<ConfiguredCarver<?>> configuredCarverSupplier : vanilla.getGenerationSettings().getCarvers(carver)) {
|
||||
generationSettings.addCarver(carver, configuredCarverSupplier.get());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Pair<PreLoadCompatibilityOptions, PostLoadCompatibilityOptions> pair = forgeAddon.getTemplates().get(pack);
|
||||
PreLoadCompatibilityOptions compatibilityOptions = pair.getLeft();
|
||||
PostLoadCompatibilityOptions postLoadCompatibilityOptions = pair.getRight();
|
||||
|
||||
TerraForgePlugin.getInstance().getDebugLogger().info("Injecting Vanilla structures and features into Terra biome " + biome.getTemplate().getID());
|
||||
|
||||
for(Supplier<StructureFeature<?, ?>> structureFeature : vanilla.getGenerationSettings().structures()) {
|
||||
ResourceLocation key = WorldGenRegistries.CONFIGURED_STRUCTURE_FEATURE.getKey(structureFeature.get());
|
||||
if(!compatibilityOptions.getExcludedBiomeStructures().contains(key) && !postLoadCompatibilityOptions.getExcludedPerBiomeStructures().getOrDefault(biome, Collections.emptySet()).contains(key)) {
|
||||
generationSettings.addStructureStart(structureFeature.get());
|
||||
TerraForgePlugin.getInstance().getDebugLogger().info("Injected structure " + key);
|
||||
}
|
||||
}
|
||||
|
||||
if(compatibilityOptions.doBiomeInjection()) {
|
||||
for(int step = 0; step < vanilla.getGenerationSettings().features().size(); step++) {
|
||||
for(Supplier<ConfiguredFeature<?, ?>> featureSupplier : vanilla.getGenerationSettings().features().get(step)) {
|
||||
ResourceLocation key = WorldGenRegistries.CONFIGURED_FEATURE.getKey(featureSupplier.get());
|
||||
if(!compatibilityOptions.getExcludedBiomeFeatures().contains(key) && !postLoadCompatibilityOptions.getExcludedPerBiomeFeatures().getOrDefault(biome, Collections.emptySet()).contains(key)) {
|
||||
generationSettings.addFeature(step, featureSupplier);
|
||||
TerraForgePlugin.getInstance().getDebugLogger().info("Injected feature " + key + " at stage " + step);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BiomeAmbience vanillaEffects = vanilla.getSpecialEffects();
|
||||
BiomeAmbience.Builder effects = new BiomeAmbience.Builder()
|
||||
.waterColor(colors.getOrDefault("water", vanillaEffects.getWaterColor()))
|
||||
.waterFogColor(colors.getOrDefault("water-fog", vanillaEffects.getWaterFogColor()))
|
||||
.fogColor(colors.getOrDefault("fog", vanillaEffects.getFogColor()))
|
||||
.skyColor(colors.getOrDefault("sky", vanillaEffects.getSkyColor()))
|
||||
.grassColorModifier(vanillaEffects.getGrassColorModifier());
|
||||
|
||||
if(colors.containsKey("grass")) {
|
||||
effects.grassColorOverride(colors.get("grass"));
|
||||
} else {
|
||||
vanillaEffects.getGrassColorOverride().ifPresent(effects::grassColorOverride);
|
||||
}
|
||||
|
||||
if(colors.containsKey("foliage")) {
|
||||
effects.foliageColorOverride(colors.get("foliage"));
|
||||
} else {
|
||||
vanillaEffects.getFoliageColorOverride().ifPresent(effects::foliageColorOverride);
|
||||
}
|
||||
|
||||
return new Biome.Builder()
|
||||
.precipitation(vanilla.getPrecipitation())
|
||||
.biomeCategory(vanilla.getBiomeCategory())
|
||||
.depth(vanilla.getDepth())
|
||||
.scale(vanilla.getScale())
|
||||
.temperature(vanilla.getBaseTemperature())
|
||||
.downfall(vanilla.getDownfall())
|
||||
.specialEffects(effects.build())
|
||||
.mobSpawnSettings(vanilla.getMobSettings())
|
||||
.generationSettings(generationSettings.build())
|
||||
.build()
|
||||
.setRegistryName("terra", createBiomeID(template.getPack(), template.getID()));
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,5 @@
|
||||
package com.dfsek.terra.forge;
|
||||
|
||||
import com.dfsek.tectonic.exception.ConfigException;
|
||||
import com.dfsek.tectonic.exception.LoadException;
|
||||
import com.dfsek.tectonic.loading.TypeRegistry;
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.addons.TerraAddon;
|
||||
@@ -10,14 +8,15 @@ import com.dfsek.terra.api.addons.annotations.Author;
|
||||
import com.dfsek.terra.api.addons.annotations.Version;
|
||||
import com.dfsek.terra.api.command.CommandManager;
|
||||
import com.dfsek.terra.api.command.TerraCommandManager;
|
||||
import com.dfsek.terra.api.command.exception.CommandException;
|
||||
import com.dfsek.terra.api.command.exception.MalformedCommandException;
|
||||
import com.dfsek.terra.api.event.EventListener;
|
||||
import com.dfsek.terra.api.event.EventManager;
|
||||
import com.dfsek.terra.api.event.TerraEventManager;
|
||||
import com.dfsek.terra.api.event.annotations.Global;
|
||||
import com.dfsek.terra.api.event.annotations.Priority;
|
||||
import com.dfsek.terra.api.event.events.config.ConfigPackPostLoadEvent;
|
||||
import com.dfsek.terra.api.event.events.config.ConfigPackPreLoadEvent;
|
||||
import com.dfsek.terra.api.platform.CommandSender;
|
||||
import com.dfsek.terra.api.platform.block.BlockData;
|
||||
import com.dfsek.terra.api.platform.handle.ItemHandle;
|
||||
import com.dfsek.terra.api.platform.handle.WorldHandle;
|
||||
@@ -25,48 +24,68 @@ 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.transform.Validator;
|
||||
import com.dfsek.terra.api.util.JarUtil;
|
||||
import com.dfsek.terra.api.util.generic.pair.Pair;
|
||||
import com.dfsek.terra.api.util.logging.DebugLogger;
|
||||
import com.dfsek.terra.api.util.mutable.MutableInteger;
|
||||
import com.dfsek.terra.commands.CommandUtil;
|
||||
import com.dfsek.terra.config.GenericLoaders;
|
||||
import com.dfsek.terra.config.PluginConfig;
|
||||
import com.dfsek.terra.config.builder.BiomeBuilder;
|
||||
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.forge.config.PostLoadCompatibilityOptions;
|
||||
import com.dfsek.terra.forge.config.PreLoadCompatibilityOptions;
|
||||
import com.dfsek.terra.forge.generation.ForgeChunkGeneratorWrapper;
|
||||
import com.dfsek.terra.forge.generation.PopulatorFeature;
|
||||
import com.dfsek.terra.forge.generation.TerraBiomeSource;
|
||||
import com.dfsek.terra.forge.handle.ForgeItemHandle;
|
||||
import com.dfsek.terra.forge.handle.ForgeWorldHandle;
|
||||
import com.dfsek.terra.config.templates.BiomeTemplate;
|
||||
import com.dfsek.terra.forge.inventory.ForgeItemHandle;
|
||||
import com.dfsek.terra.forge.world.ForgeAdapter;
|
||||
import com.dfsek.terra.forge.world.ForgeBiome;
|
||||
import com.dfsek.terra.forge.world.ForgeTree;
|
||||
import com.dfsek.terra.forge.world.ForgeWorldHandle;
|
||||
import com.dfsek.terra.forge.world.features.PopulatorFeature;
|
||||
import com.dfsek.terra.forge.world.generator.ForgeChunkGenerator;
|
||||
import com.dfsek.terra.forge.world.generator.ForgeChunkGeneratorWrapper;
|
||||
import com.dfsek.terra.forge.world.generator.config.TerraLevelType;
|
||||
import com.dfsek.terra.profiler.Profiler;
|
||||
import com.dfsek.terra.profiler.ProfilerImpl;
|
||||
import com.dfsek.terra.registry.exception.DuplicateEntryException;
|
||||
import com.dfsek.terra.registry.master.AddonRegistry;
|
||||
import com.dfsek.terra.registry.master.ConfigRegistry;
|
||||
import com.dfsek.terra.world.TerraWorld;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import com.mojang.brigadier.builder.ArgumentBuilder;
|
||||
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.client.gui.widget.button.Button;
|
||||
import net.minecraft.command.CommandSource;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.util.registry.WorldGenRegistries;
|
||||
import net.minecraft.world.DimensionType;
|
||||
import net.minecraft.world.IWorld;
|
||||
import net.minecraft.util.text.StringTextComponent;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
import net.minecraft.world.biome.BiomeAmbience;
|
||||
import net.minecraft.world.biome.BiomeGenerationSettings;
|
||||
import net.minecraft.world.gen.GenerationStage;
|
||||
import net.minecraft.world.gen.feature.ConfiguredFeature;
|
||||
import net.minecraft.world.gen.feature.Feature;
|
||||
import net.minecraft.world.gen.feature.Features;
|
||||
import net.minecraft.world.gen.feature.IFeatureConfig;
|
||||
import net.minecraft.world.gen.feature.NoFeatureConfig;
|
||||
import net.minecraft.world.gen.placement.DecoratedPlacement;
|
||||
import net.minecraft.world.gen.placement.NoPlacementConfig;
|
||||
import net.minecraft.world.server.ServerWorld;
|
||||
import net.minecraft.world.gen.surfacebuilders.SurfaceBuilder;
|
||||
import net.minecraft.world.gen.surfacebuilders.SurfaceBuilderConfig;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.client.ForgeWorldTypeScreens;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.common.world.ForgeWorldType;
|
||||
import net.minecraftforge.event.RegisterCommandsEvent;
|
||||
import net.minecraftforge.event.RegistryEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
|
||||
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import net.minecraftforge.registries.ForgeRegistry;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.objectweb.asm.Type;
|
||||
@@ -76,14 +95,20 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URISyntaxException;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.jar.JarFile;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.zip.ZipFile;
|
||||
|
||||
import static com.mojang.brigadier.builder.LiteralArgumentBuilder.literal;
|
||||
import static com.mojang.brigadier.builder.RequiredArgumentBuilder.argument;
|
||||
|
||||
@Mod("terra")
|
||||
@Mod.EventBusSubscriber(modid = "terra", bus = Mod.EventBusSubscriber.Bus.MOD)
|
||||
public class TerraForgePlugin implements TerraPlugin {
|
||||
@@ -91,7 +116,7 @@ public class TerraForgePlugin implements TerraPlugin {
|
||||
public static final ConfiguredFeature<?, ?> POPULATOR_CONFIGURED_FEATURE = POPULATOR_FEATURE.configured(IFeatureConfig.NONE).decorated(DecoratedPlacement.NOPE.configured(NoPlacementConfig.INSTANCE));
|
||||
|
||||
private static TerraForgePlugin INSTANCE;
|
||||
private final Map<DimensionType, Pair<ServerWorld, TerraWorld>> worldMap = new HashMap<>();
|
||||
private final Map<Long, TerraWorld> worldMap = new HashMap<>();
|
||||
private final EventManager eventManager = new TerraEventManager(this);
|
||||
private final GenericLoaders genericLoaders = new GenericLoaders(this);
|
||||
private final Profiler profiler = new ProfilerImpl();
|
||||
@@ -116,51 +141,129 @@ public class TerraForgePlugin implements TerraPlugin {
|
||||
logger.error(message);
|
||||
}
|
||||
};
|
||||
|
||||
private final DebugLogger debugLogger = new DebugLogger(logger);
|
||||
private final ItemHandle itemHandle = new ForgeItemHandle();
|
||||
private final WorldHandle worldHandle = new ForgeWorldHandle();
|
||||
private final ConfigRegistry registry = new ConfigRegistry();
|
||||
private final CheckedRegistry<ConfigPack> checkedRegistry = new CheckedRegistry<>(registry);
|
||||
|
||||
private final ForgeAddon addon = new ForgeAddon(this);
|
||||
|
||||
private final AddonRegistry addonRegistry = new AddonRegistry(addon, this);
|
||||
private final AddonRegistry addonRegistry = new AddonRegistry(new ForgeAddon(this), this);
|
||||
private final LockedRegistry<TerraAddon> addonLockedRegistry = new LockedRegistry<>(addonRegistry);
|
||||
private final PluginConfig config = new PluginConfig();
|
||||
private final Transformer<String, Biome> biomeFixer = new Transformer.Builder<String, Biome>()
|
||||
.addTransform(id -> ForgeRegistries.BIOMES.getValue(ResourceLocation.tryParse(id)), Validator.notNull())
|
||||
.addTransform(id -> ForgeRegistries.BIOMES.getValue(ResourceLocation.tryParse("minecraft:" + id.toLowerCase())), Validator.notNull()).build();
|
||||
private final File dataFolder;
|
||||
.addTransform(id -> ForgeRegistries.BIOMES.getValue(ResourceLocation.tryParse(id)), new NotNullValidator<>())
|
||||
.addTransform(id -> ForgeRegistries.BIOMES.getValue(ResourceLocation.tryParse("minecraft:" + id.toLowerCase())), new NotNullValidator<>()).build();
|
||||
private File dataFolder;
|
||||
|
||||
public TerraForgePlugin() {
|
||||
if(INSTANCE != null) throw new IllegalStateException("Only one TerraPlugin instance may exist.");
|
||||
INSTANCE = this;
|
||||
this.dataFolder = Paths.get("config", "Terra").toFile();
|
||||
saveDefaultConfig();
|
||||
config.load(this);
|
||||
debugLogger.setDebug(config.isDebug());
|
||||
LangUtil.load(config.getLanguage(), this);
|
||||
try {
|
||||
CommandUtil.registerAll(manager);
|
||||
} catch(MalformedCommandException e) {
|
||||
e.printStackTrace(); // TODO do something here even though this should literally never happen
|
||||
}
|
||||
MinecraftForge.EVENT_BUS.register(ClientEvents.class);
|
||||
MinecraftForge.EVENT_BUS.register(getClass());
|
||||
MinecraftForge.EVENT_BUS.register(ForgeEvents.class);
|
||||
}
|
||||
|
||||
public static TerraForgePlugin getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void setupListener(FMLCommonSetupEvent event) {
|
||||
event.enqueueWork(() -> {
|
||||
Registry.register(Registry.BIOME_SOURCE, "terra:biome", TerraBiomeSource.CODEC);
|
||||
Registry.register(Registry.CHUNK_GENERATOR, "terra:generator", ForgeChunkGeneratorWrapper.CODEC);
|
||||
public static String createBiomeID(ConfigPack pack, String biomeID) {
|
||||
return pack.getTemplate().getID().toLowerCase() + "/" + biomeID.toLowerCase(Locale.ROOT);
|
||||
}
|
||||
|
||||
private static RequiredArgumentBuilder<CommandSource, String> assemble(RequiredArgumentBuilder<CommandSource, String> in, CommandManager manager) {
|
||||
return in.suggests((context, builder) -> {
|
||||
List<String> args = parseCommand(context.getInput());
|
||||
CommandSender sender = ForgeAdapter.adapt(context.getSource());
|
||||
try {
|
||||
manager.tabComplete(args.remove(0), sender, args).forEach(builder::suggest);
|
||||
} catch(CommandException e) {
|
||||
sender.sendMessage(e.getMessage());
|
||||
}
|
||||
return builder.buildFuture();
|
||||
}).executes(context -> {
|
||||
List<String> args = parseCommand(context.getInput());
|
||||
try {
|
||||
manager.execute(args.remove(0), ForgeAdapter.adapt(context.getSource()), args);
|
||||
} catch(CommandException e) {
|
||||
context.getSource().sendFailure(new StringTextComponent(e.getMessage()));
|
||||
}
|
||||
return 1;
|
||||
});
|
||||
}
|
||||
|
||||
public void init() {
|
||||
private static List<String> parseCommand(String command) {
|
||||
if(command.startsWith("/terra ")) command = command.substring("/terra ".length());
|
||||
else if(command.startsWith("/te ")) command = command.substring("/te ".length());
|
||||
List<String> c = new ArrayList<>(Arrays.asList(command.split(" ")));
|
||||
if(command.endsWith(" ")) c.add("");
|
||||
return c;
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void register(RegistryEvent.Register<Biome> event) {
|
||||
INSTANCE.setup(); // Setup now because we need the biomes, and this event happens after blocks n stuff
|
||||
INSTANCE.getConfigRegistry().forEach(pack -> pack.getBiomeRegistry().forEach((id, biome) -> event.getRegistry().register(INSTANCE.createBiome(biome)))); // Register all Terra biomes.
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void registerLevels(RegistryEvent.Register<ForgeWorldType> event) {
|
||||
INSTANCE.logger().info("Registering level types...");
|
||||
event.getRegistry().register(TerraLevelType.FORGE_WORLD_TYPE);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void registerPop(RegistryEvent.Register<Feature<?>> event) {
|
||||
event.getRegistry().register(POPULATOR_FEATURE);
|
||||
}
|
||||
|
||||
public Biome createBiome(BiomeBuilder biome) {
|
||||
BiomeTemplate template = biome.getTemplate();
|
||||
Map<String, Integer> colors = template.getColors();
|
||||
|
||||
Biome vanilla = ((ForgeBiome) new ArrayList<>(biome.getVanillaBiomes().getContents()).get(0)).getHandle();
|
||||
|
||||
BiomeGenerationSettings.Builder generationSettings = new BiomeGenerationSettings.Builder();
|
||||
generationSettings.surfaceBuilder(SurfaceBuilder.DEFAULT.configured(new SurfaceBuilderConfig(Blocks.GRASS_BLOCK.defaultBlockState(), Blocks.DIRT.defaultBlockState(), Blocks.GRAVEL.defaultBlockState()))); // It needs a surfacebuilder, even though we dont use it.
|
||||
generationSettings.addFeature(GenerationStage.Decoration.VEGETAL_DECORATION, POPULATOR_CONFIGURED_FEATURE);
|
||||
|
||||
BiomeAmbience vanillaEffects = vanilla.getSpecialEffects();
|
||||
BiomeAmbience.Builder effects = new BiomeAmbience.Builder()
|
||||
.waterColor(colors.getOrDefault("water", vanillaEffects.getWaterColor()))
|
||||
.waterFogColor(colors.getOrDefault("water-fog", vanillaEffects.getWaterFogColor()))
|
||||
.fogColor(colors.getOrDefault("fog", vanillaEffects.getFogColor()))
|
||||
.skyColor(colors.getOrDefault("sky", vanillaEffects.getSkyColor()))
|
||||
.grassColorModifier(vanillaEffects.getGrassColorModifier());
|
||||
|
||||
if(colors.containsKey("grass")) {
|
||||
effects.grassColorOverride(colors.get("grass"));
|
||||
} else {
|
||||
vanillaEffects.getGrassColorOverride().ifPresent(effects::grassColorOverride);
|
||||
}
|
||||
vanillaEffects.getFoliageColorOverride().ifPresent(effects::foliageColorOverride);
|
||||
if(colors.containsKey("foliage")) {
|
||||
effects.foliageColorOverride(colors.get("foliage"));
|
||||
} else {
|
||||
vanillaEffects.getFoliageColorOverride().ifPresent(effects::foliageColorOverride);
|
||||
}
|
||||
|
||||
return new Biome.Builder()
|
||||
.precipitation(vanilla.getPrecipitation())
|
||||
.biomeCategory(vanilla.getBiomeCategory())
|
||||
.depth(vanilla.getDepth())
|
||||
.scale(vanilla.getScale())
|
||||
.temperature(vanilla.getBaseTemperature())
|
||||
.downfall(vanilla.getDownfall())
|
||||
.specialEffects(effects.build())
|
||||
.mobSpawnSettings(vanilla.getMobSettings())
|
||||
.generationSettings(generationSettings.build())
|
||||
.build().setRegistryName("terra", createBiomeID(template.getPack(), template.getID()));
|
||||
}
|
||||
|
||||
public void setup() {
|
||||
this.dataFolder = Paths.get("config", "Terra").toFile();
|
||||
saveDefaultConfig();
|
||||
config.load(this);
|
||||
LangUtil.load(config.getLanguage(), this);
|
||||
logger.info("Initializing Terra...");
|
||||
|
||||
if(!addonRegistry.loadAll()) {
|
||||
@@ -169,11 +272,15 @@ public class TerraForgePlugin implements TerraPlugin {
|
||||
logger.info("Loaded addons.");
|
||||
|
||||
registry.loadAll(this);
|
||||
|
||||
logger.info("Loaded packs.");
|
||||
|
||||
((ForgeRegistry<Biome>) ForgeRegistries.BIOMES).unfreeze(); // Evil
|
||||
getConfigRegistry().forEach(pack -> pack.getBiomeRegistry().forEach((id, biome) -> ForgeRegistries.BIOMES.register(ForgeUtil.createBiome(biome, pack, addon)))); // Register all Terra biomes.
|
||||
((ForgeRegistry<Biome>) ForgeRegistries.BIOMES).freeze();
|
||||
|
||||
try {
|
||||
CommandUtil.registerAll(manager);
|
||||
} catch(MalformedCommandException e) {
|
||||
e.printStackTrace(); // TODO do something here even though this should literally never happen
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -183,22 +290,12 @@ public class TerraForgePlugin implements TerraPlugin {
|
||||
|
||||
@Override
|
||||
public TerraWorld getWorld(World world) {
|
||||
return getWorld(((IWorld) world).dimensionType());
|
||||
return worldMap.computeIfAbsent(world.getSeed(), w -> {
|
||||
logger.info("Loading world " + w);
|
||||
return new TerraWorld(world, ((ForgeChunkGeneratorWrapper) ((ForgeChunkGenerator) world.getGenerator()).getHandle()).getPack(), this);
|
||||
});
|
||||
}
|
||||
|
||||
public TerraWorld getWorld(DimensionType type) {
|
||||
TerraWorld world = worldMap.get(type).getRight();
|
||||
if(world == null) throw new IllegalArgumentException("No world exists with dimension type " + type);
|
||||
return world;
|
||||
}
|
||||
|
||||
/**
|
||||
* evil code brought to you by Forge Mod Loader
|
||||
* <p>
|
||||
* Forge changes the JAR URI to something that cannot
|
||||
* be resolved back to the original JAR, so we have to
|
||||
* do this to get our JAR.
|
||||
*/
|
||||
@Override
|
||||
public JarFile getModJar() throws URISyntaxException, IOException {
|
||||
File modsDir = new File("./mods");
|
||||
@@ -215,6 +312,17 @@ 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);
|
||||
return world;
|
||||
}
|
||||
|
||||
@Override
|
||||
public com.dfsek.terra.api.util.logging.Logger logger() {
|
||||
return logger;
|
||||
@@ -232,7 +340,7 @@ public class TerraForgePlugin implements TerraPlugin {
|
||||
|
||||
@Override
|
||||
public boolean isDebug() {
|
||||
return config.isDebug();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -255,11 +363,14 @@ public class TerraForgePlugin implements TerraPlugin {
|
||||
config.load(this);
|
||||
LangUtil.load(config.getLanguage(), this); // Load language.
|
||||
boolean succeed = registry.loadAll(this);
|
||||
worldMap.forEach((seed, pair) -> {
|
||||
pair.getRight().getConfig().getSamplerCache().clear();
|
||||
String packID = pair.getRight().getConfig().getTemplate().getID();
|
||||
pair.setRight(new TerraWorld(pair.getRight().getWorld(), registry.get(packID), this));
|
||||
Map<Long, TerraWorld> newMap = new HashMap<>();
|
||||
worldMap.forEach((seed, tw) -> {
|
||||
tw.getConfig().getSamplerCache().clear();
|
||||
String packID = tw.getConfig().getTemplate().getID();
|
||||
newMap.put(seed, new TerraWorld(tw.getWorld(), registry.get(packID), this));
|
||||
});
|
||||
worldMap.clear();
|
||||
worldMap.putAll(newMap);
|
||||
return succeed;
|
||||
}
|
||||
|
||||
@@ -293,12 +404,7 @@ public class TerraForgePlugin implements TerraPlugin {
|
||||
genericLoaders.register(registry);
|
||||
registry
|
||||
.registerLoader(BlockData.class, (t, o, l) -> worldHandle.createBlockData((String) o))
|
||||
.registerLoader(com.dfsek.terra.api.platform.world.Biome.class, (t, o, l) -> biomeFixer.translate((String) o))
|
||||
.registerLoader(ResourceLocation.class, (t, o, l) -> {
|
||||
ResourceLocation identifier = ResourceLocation.tryParse((String) o);
|
||||
if(identifier == null) throw new LoadException("Invalid identifier: " + o);
|
||||
return identifier;
|
||||
});
|
||||
.registerLoader(com.dfsek.terra.api.platform.world.Biome.class, (t, o, l) -> new ForgeBiome(biomeFixer.translate((String) o)));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -306,30 +412,33 @@ public class TerraForgePlugin implements TerraPlugin {
|
||||
return eventManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<com.dfsek.terra.api.platform.modloader.Mod> getMods() {
|
||||
return net.minecraftforge.fml.ModList.get().getMods().stream().map(ForgeMod::new).collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Profiler getProfiler() {
|
||||
return profiler;
|
||||
}
|
||||
|
||||
public CommandManager getManager() {
|
||||
return manager;
|
||||
}
|
||||
@Mod.EventBusSubscriber(modid = "terra", bus = Mod.EventBusSubscriber.Bus.FORGE)
|
||||
public static final class ForgeEvents {
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
@SubscribeEvent
|
||||
public static void registerCommands(RegisterCommandsEvent event) {
|
||||
int max = INSTANCE.manager.getMaxArgumentDepth();
|
||||
RequiredArgumentBuilder<CommandSource, String> arg = argument("arg" + (max - 1), StringArgumentType.word());
|
||||
for(int i = 0; i < max; i++) {
|
||||
RequiredArgumentBuilder<CommandSource, String> next = argument("arg" + (max - i - 1), StringArgumentType.word());
|
||||
|
||||
public Map<DimensionType, Pair<ServerWorld, TerraWorld>> getWorldMap() {
|
||||
return worldMap;
|
||||
arg = next.then(assemble(arg, INSTANCE.manager));
|
||||
}
|
||||
|
||||
event.getDispatcher().register(literal("terra").executes(context -> 1).then((ArgumentBuilder) assemble(arg, INSTANCE.manager)));
|
||||
event.getDispatcher().register(literal("te").executes(context -> 1).then((ArgumentBuilder) assemble(arg, INSTANCE.manager)));
|
||||
}
|
||||
}
|
||||
|
||||
@Addon("Terra-Forge")
|
||||
@Author("Terra")
|
||||
@Version("1.0.0")
|
||||
public static final class ForgeAddon extends TerraAddon implements EventListener {
|
||||
|
||||
private final Map<ConfigPack, Pair<PreLoadCompatibilityOptions, PostLoadCompatibilityOptions>> templates = new HashMap<>();
|
||||
private static final class ForgeAddon extends TerraAddon implements EventListener {
|
||||
|
||||
private final TerraPlugin main;
|
||||
|
||||
@@ -365,51 +474,43 @@ public class TerraForgePlugin implements TerraPlugin {
|
||||
injectTree(treeRegistry, "MEGA_SPRUCE", Features.MEGA_SPRUCE);
|
||||
injectTree(treeRegistry, "CRIMSON_FUNGUS", Features.CRIMSON_FUNGI);
|
||||
injectTree(treeRegistry, "WARPED_FUNGUS", Features.WARPED_FUNGI);
|
||||
PreLoadCompatibilityOptions template = new PreLoadCompatibilityOptions();
|
||||
try {
|
||||
event.loadTemplate(template);
|
||||
} catch(ConfigException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if(template.doRegistryInjection()) {
|
||||
WorldGenRegistries.CONFIGURED_FEATURE.entrySet().forEach(entry -> {
|
||||
if(!template.getExcludedRegistryFeatures().contains(entry.getKey().getRegistryName())) {
|
||||
try {
|
||||
event.getPack().getTreeRegistry().add(entry.getKey().getRegistryName().toString(), (Tree) entry.getValue());
|
||||
main.getDebugLogger().info("Injected ConfiguredFeature " + entry.getKey().getRegistryName() + " as Tree: " + entry.getValue());
|
||||
} catch(DuplicateEntryException ignored) {
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
templates.put(event.getPack(), Pair.of(template, null));
|
||||
}
|
||||
|
||||
@Priority(Priority.HIGHEST)
|
||||
@Global
|
||||
public void createInjectionOptions(ConfigPackPostLoadEvent event) {
|
||||
PostLoadCompatibilityOptions template = new PostLoadCompatibilityOptions();
|
||||
|
||||
try {
|
||||
event.loadTemplate(template);
|
||||
} catch(ConfigException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
templates.get(event.getPack()).setRight(template);
|
||||
}
|
||||
|
||||
|
||||
private void injectTree(CheckedRegistry<Tree> registry, String id, ConfiguredFeature<?, ?> tree) {
|
||||
try {
|
||||
registry.add(id, (Tree) tree);
|
||||
registry.add(id, new ForgeTree(tree, id, TerraForgePlugin.getInstance()));
|
||||
} catch(DuplicateEntryException ignore) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Map<ConfigPack, Pair<PreLoadCompatibilityOptions, PostLoadCompatibilityOptions>> getTemplates() {
|
||||
return templates;
|
||||
@Mod.EventBusSubscriber(value = Dist.CLIENT, bus = Mod.EventBusSubscriber.Bus.MOD)
|
||||
public static final class ClientEvents {
|
||||
@SubscribeEvent
|
||||
public static void register(FMLClientSetupEvent event) {
|
||||
INSTANCE.logger.info("Client setup...");
|
||||
|
||||
ForgeWorldType world = TerraLevelType.FORGE_WORLD_TYPE;
|
||||
ForgeWorldTypeScreens.registerFactory(world, (returnTo, dimensionGeneratorSettings) -> new Screen(world.getDisplayName()) {
|
||||
private final MutableInteger num = new MutableInteger(0);
|
||||
private final List<ConfigPack> packs = new ArrayList<>();
|
||||
private final Button toggle = new Button(0, 25, 120, 20, new StringTextComponent(""), button -> {
|
||||
num.increment();
|
||||
if(num.get() >= packs.size()) num.set(0);
|
||||
button.setMessage(new StringTextComponent("Pack: " + packs.get(num.get()).getTemplate().getID()));
|
||||
});
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
packs.clear();
|
||||
INSTANCE.registry.forEach((Consumer<ConfigPack>) packs::add);
|
||||
addButton(new Button(0, 0, 120, 20, new StringTextComponent("Close"), btn -> Minecraft.getInstance().setScreen(returnTo)));
|
||||
toggle.setMessage(new StringTextComponent("Pack: " + packs.get(num.get()).getTemplate().getID()));
|
||||
addButton(toggle);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
-30
@@ -1,30 +0,0 @@
|
||||
package com.dfsek.terra.forge.config;
|
||||
|
||||
import com.dfsek.tectonic.annotations.Default;
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
import com.dfsek.tectonic.config.ConfigTemplate;
|
||||
import com.dfsek.terra.config.builder.BiomeBuilder;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@SuppressWarnings("FieldMayBeFinal")
|
||||
public class PostLoadCompatibilityOptions implements ConfigTemplate {
|
||||
@Value("structures.inject-biome.exclude-biomes")
|
||||
@Default
|
||||
private Map<BiomeBuilder, Set<ResourceLocation>> excludedPerBiomeStructures = new HashMap<>();
|
||||
|
||||
@Value("features.inject-biome.exclude-biomes")
|
||||
@Default
|
||||
private Map<BiomeBuilder, Set<ResourceLocation>> excludedPerBiomeFeatures = new HashMap<>();
|
||||
|
||||
public Map<BiomeBuilder, Set<ResourceLocation>> getExcludedPerBiomeFeatures() {
|
||||
return excludedPerBiomeFeatures;
|
||||
}
|
||||
|
||||
public Map<BiomeBuilder, Set<ResourceLocation>> getExcludedPerBiomeStructures() {
|
||||
return excludedPerBiomeStructures;
|
||||
}
|
||||
}
|
||||
-52
@@ -1,52 +0,0 @@
|
||||
package com.dfsek.terra.forge.config;
|
||||
|
||||
import com.dfsek.tectonic.annotations.Default;
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
import com.dfsek.tectonic.config.ConfigTemplate;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
@SuppressWarnings("FieldMayBeFinal")
|
||||
public class PreLoadCompatibilityOptions implements ConfigTemplate {
|
||||
@Value("features.inject-registry.enable")
|
||||
@Default
|
||||
private boolean doRegistryInjection = false;
|
||||
|
||||
@Value("features.inject-biome.enable")
|
||||
@Default
|
||||
private boolean doBiomeInjection = false;
|
||||
|
||||
@Value("features.inject-registry.excluded-features")
|
||||
@Default
|
||||
private Set<ResourceLocation> excludedRegistryFeatures = new HashSet<>();
|
||||
|
||||
@Value("features.inject-biome.excluded-features")
|
||||
@Default
|
||||
private Set<ResourceLocation> excludedBiomeFeatures = new HashSet<>();
|
||||
|
||||
@Value("structures.inject-biome.excluded-features")
|
||||
@Default
|
||||
private Set<ResourceLocation> excludedBiomeStructures = new HashSet<>();
|
||||
|
||||
public boolean doBiomeInjection() {
|
||||
return doBiomeInjection;
|
||||
}
|
||||
|
||||
public boolean doRegistryInjection() {
|
||||
return doRegistryInjection;
|
||||
}
|
||||
|
||||
public Set<ResourceLocation> getExcludedBiomeFeatures() {
|
||||
return excludedBiomeFeatures;
|
||||
}
|
||||
|
||||
public Set<ResourceLocation> getExcludedRegistryFeatures() {
|
||||
return excludedRegistryFeatures;
|
||||
}
|
||||
|
||||
public Set<ResourceLocation> getExcludedBiomeStructures() {
|
||||
return excludedBiomeStructures;
|
||||
}
|
||||
}
|
||||
-202
@@ -1,202 +0,0 @@
|
||||
package com.dfsek.terra.forge.generation;
|
||||
|
||||
import com.dfsek.terra.api.platform.world.World;
|
||||
import com.dfsek.terra.api.platform.world.generator.ChunkData;
|
||||
import com.dfsek.terra.api.platform.world.generator.GeneratorWrapper;
|
||||
import com.dfsek.terra.api.util.FastRandom;
|
||||
import com.dfsek.terra.api.world.biome.UserDefinedBiome;
|
||||
import com.dfsek.terra.api.world.generation.TerraChunkGenerator;
|
||||
import com.dfsek.terra.api.world.locate.AsyncStructureFinder;
|
||||
import com.dfsek.terra.config.pack.ConfigPack;
|
||||
import com.dfsek.terra.forge.ForgeAdapter;
|
||||
import com.dfsek.terra.forge.TerraForgePlugin;
|
||||
import com.dfsek.terra.forge.block.ForgeBlockData;
|
||||
import com.dfsek.terra.world.TerraWorld;
|
||||
import com.dfsek.terra.world.generation.generators.DefaultChunkGenerator3D;
|
||||
import com.dfsek.terra.world.generation.math.samplers.Sampler;
|
||||
import com.dfsek.terra.world.population.items.TerraStructure;
|
||||
import com.mojang.serialization.Codec;
|
||||
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||
import net.jafama.FastMath;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.entity.EntityClassification;
|
||||
import net.minecraft.util.SharedSeedRandom;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.ChunkPos;
|
||||
import net.minecraft.util.registry.DynamicRegistries;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.world.Blockreader;
|
||||
import net.minecraft.world.DimensionType;
|
||||
import net.minecraft.world.IBlockReader;
|
||||
import net.minecraft.world.IWorld;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
import net.minecraft.world.biome.BiomeManager;
|
||||
import net.minecraft.world.biome.MobSpawnInfo;
|
||||
import net.minecraft.world.chunk.IChunk;
|
||||
import net.minecraft.world.gen.ChunkGenerator;
|
||||
import net.minecraft.world.gen.GenerationStage;
|
||||
import net.minecraft.world.gen.Heightmap;
|
||||
import net.minecraft.world.gen.WorldGenRegion;
|
||||
import net.minecraft.world.gen.feature.structure.Structure;
|
||||
import net.minecraft.world.gen.feature.structure.StructureManager;
|
||||
import net.minecraft.world.gen.feature.template.TemplateManager;
|
||||
import net.minecraft.world.gen.settings.DimensionStructuresSettings;
|
||||
import net.minecraft.world.server.ServerWorld;
|
||||
import net.minecraft.world.spawner.WorldEntitySpawner;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
public class ForgeChunkGeneratorWrapper extends ChunkGenerator implements GeneratorWrapper {
|
||||
private final long seed;
|
||||
private final DefaultChunkGenerator3D delegate;
|
||||
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(TerraForgePlugin.getInstance().getConfigRegistry()::get))));
|
||||
public static final Codec<ForgeChunkGeneratorWrapper> CODEC = RecordCodecBuilder.create(instance -> instance.group(
|
||||
TerraBiomeSource.CODEC.fieldOf("biome_source").forGetter(generator -> generator.biomeSource),
|
||||
Codec.LONG.fieldOf("seed").stable().forGetter(generator -> generator.seed),
|
||||
PACK_CODEC.fieldOf("pack").stable().forGetter(generator -> generator.pack))
|
||||
.apply(instance, instance.stable(ForgeChunkGeneratorWrapper::new)));
|
||||
private final ConfigPack pack;
|
||||
|
||||
public ConfigPack getPack() {
|
||||
return pack;
|
||||
}
|
||||
|
||||
private DimensionType dimensionType;
|
||||
|
||||
public ForgeChunkGeneratorWrapper(TerraBiomeSource biomeSource, long seed, ConfigPack configPack) {
|
||||
super(biomeSource, new DimensionStructuresSettings(configPack.getTemplate().vanillaStructures()));
|
||||
this.pack = configPack;
|
||||
|
||||
this.delegate = new DefaultChunkGenerator3D(pack, TerraForgePlugin.getInstance());
|
||||
delegate.getMain().logger().info("Loading world with config pack " + pack.getTemplate().getID());
|
||||
this.biomeSource = biomeSource;
|
||||
|
||||
this.seed = seed;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @NotNull Codec<? extends ChunkGenerator> codec() {
|
||||
return CODEC;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull ChunkGenerator withSeed(long seed) {
|
||||
return new ForgeChunkGeneratorWrapper((TerraBiomeSource) this.biomeSource.withSeed(seed), seed, pack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buildSurfaceAndBedrock(@NotNull WorldGenRegion p_225551_1_, @NotNull IChunk p_225551_2_) {
|
||||
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public BlockPos findNearestMapFeature(@NotNull ServerWorld world, @NotNull Structure<?> feature, @NotNull BlockPos center, int radius, boolean skipExistingChunks) {
|
||||
if(!pack.getTemplate().disableStructures()) {
|
||||
String name = Objects.requireNonNull(Registry.STRUCTURE_FEATURE.getKey(feature)).toString();
|
||||
TerraWorld terraWorld = TerraForgePlugin.getInstance().getWorld((World) world);
|
||||
TerraStructure located = pack.getStructure(pack.getTemplate().getLocatable().get(name));
|
||||
if(located != null) {
|
||||
CompletableFuture<BlockPos> result = new CompletableFuture<>();
|
||||
AsyncStructureFinder finder = new AsyncStructureFinder(terraWorld.getBiomeProvider(), located, ForgeAdapter.adapt(center).toLocation((World) world), 0, 500, location -> {
|
||||
result.complete(ForgeAdapter.adapt(location));
|
||||
}, TerraForgePlugin.getInstance());
|
||||
finder.run(); // Do this synchronously.
|
||||
try {
|
||||
return result.get();
|
||||
} catch(InterruptedException | ExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
return super.findNearestMapFeature(world, feature, center, radius, skipExistingChunks);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasStronghold(@NotNull ChunkPos p_235952_1_) {
|
||||
if(pack.getTemplate().vanillaStructures()) return super.hasStronghold(p_235952_1_);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createStructures(@NotNull DynamicRegistries dynamicRegistries, @NotNull StructureManager manager, @NotNull IChunk chunk, @NotNull TemplateManager templateManager, long p_242707_5_) {
|
||||
if(pack.getTemplate().vanillaStructures()) super.createStructures(dynamicRegistries, manager, chunk, templateManager, p_242707_5_);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyCarvers(long p_230350_1_, @NotNull BiomeManager biomeManager, @NotNull IChunk chunk, GenerationStage.@NotNull Carving carving) {
|
||||
if(pack.getTemplate().vanillaCaves()) super.applyCarvers(p_230350_1_, biomeManager, chunk, carving);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fillFromNoise(@NotNull IWorld world, @NotNull StructureManager p_230352_2_, @NotNull IChunk chunk) {
|
||||
delegate.generateChunkData((World) world, new FastRandom(), chunk.getPos().x, chunk.getPos().z, (ChunkData) chunk);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBaseHeight(int x, int z, Heightmap.@NotNull Type type) {
|
||||
TerraWorld world = TerraForgePlugin.getInstance().getWorld(dimensionType);
|
||||
int height = world.getWorld().getMaxHeight();
|
||||
while(height >= 0 && !type.isOpaque().test(((ForgeBlockData) world.getUngeneratedBlock(x, height - 1, z)).getHandle())) {
|
||||
height--;
|
||||
}
|
||||
return height;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull IBlockReader getBaseColumn(int x, int z) {
|
||||
TerraWorld world = TerraForgePlugin.getInstance().getWorld(dimensionType);
|
||||
int height = getBaseHeight(x, z, Heightmap.Type.WORLD_SURFACE);
|
||||
BlockState[] array = new BlockState[256];
|
||||
for(int y = 255; y >= 0; y--) {
|
||||
if(y > height) {
|
||||
if(y > ((UserDefinedBiome) world.getBiomeProvider().getBiome(x, z)).getConfig().getSeaLevel()) {
|
||||
array[y] = Blocks.AIR.defaultBlockState();
|
||||
} else {
|
||||
array[y] = Blocks.WATER.defaultBlockState();
|
||||
}
|
||||
} else {
|
||||
array[y] = Blocks.STONE.defaultBlockState();
|
||||
}
|
||||
}
|
||||
|
||||
return new Blockreader(array);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void spawnOriginalMobs(WorldGenRegion region) {
|
||||
if(pack.getTemplate().vanillaMobs()) {
|
||||
int cx = region.getCenterX();
|
||||
int cy = region.getCenterZ();
|
||||
Biome biome = region.getBiome((new ChunkPos(cx, cy)).getWorldPosition());
|
||||
SharedSeedRandom chunkRandom = new SharedSeedRandom();
|
||||
chunkRandom.setDecorationSeed(region.getSeed(), cx << 4, cy << 4);
|
||||
WorldEntitySpawner.spawnMobsForChunkGeneration(region, biome, cx, cy, chunkRandom);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MobSpawnInfo.Spawners> getMobsAt(Biome p_230353_1_, StructureManager p_230353_2_, EntityClassification p_230353_3_, BlockPos p_230353_4_) {
|
||||
List<MobSpawnInfo.Spawners> spawns = net.minecraftforge.common.world.StructureSpawnManager.getStructureSpawns(p_230353_2_, p_230353_3_, p_230353_4_);
|
||||
if(spawns != null) return spawns;
|
||||
return super.getMobsAt(p_230353_1_, p_230353_2_, p_230353_3_, p_230353_4_);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TerraChunkGenerator getHandle() {
|
||||
return delegate;
|
||||
}
|
||||
|
||||
public void setDimensionType(DimensionType dimensionType) {
|
||||
this.dimensionType = dimensionType;
|
||||
}
|
||||
}
|
||||
-24
@@ -1,24 +0,0 @@
|
||||
package com.dfsek.terra.forge.generation;
|
||||
|
||||
import com.dfsek.terra.config.pack.ConfigPack;
|
||||
import net.minecraft.client.gui.screen.BiomeGeneratorTypeScreens;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.util.text.StringTextComponent;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
import net.minecraft.world.gen.ChunkGenerator;
|
||||
import net.minecraft.world.gen.DimensionSettings;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class TerraGeneratorType extends BiomeGeneratorTypeScreens {
|
||||
private final ConfigPack pack;
|
||||
|
||||
public TerraGeneratorType(ConfigPack pack) {
|
||||
super(new StringTextComponent("Terra:" + pack.getTemplate().getID()));
|
||||
this.pack = pack;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @NotNull ChunkGenerator generator(@NotNull Registry<Biome> biomeRegistry, @NotNull Registry<DimensionSettings> chunkGeneratorSettingsRegistry, long seed) {
|
||||
return new ForgeChunkGeneratorWrapper(new TerraBiomeSource(biomeRegistry, seed, pack), seed, pack);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.dfsek.terra.forge.inventory;
|
||||
|
||||
import com.dfsek.terra.api.platform.inventory.ItemStack;
|
||||
import com.dfsek.terra.api.platform.inventory.item.Enchantment;
|
||||
import com.dfsek.terra.forge.world.ForgeAdapter;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class ForgeEnchantment implements Enchantment {
|
||||
private final net.minecraft.enchantment.Enchantment enchantment;
|
||||
|
||||
public ForgeEnchantment(net.minecraft.enchantment.Enchantment enchantment) {
|
||||
this.enchantment = enchantment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public net.minecraft.enchantment.Enchantment getHandle() {
|
||||
return enchantment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canEnchantItem(ItemStack itemStack) {
|
||||
return enchantment.canEnchant(ForgeAdapter.adapt(itemStack));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getID() {
|
||||
return Objects.requireNonNull(ForgeRegistries.ENCHANTMENTS.getKey(enchantment)).toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean conflictsWith(Enchantment other) {
|
||||
return !enchantment.isCompatibleWith(ForgeAdapter.adapt(other));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxLevel() {
|
||||
return enchantment.getMaxLevel();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.dfsek.terra.forge.inventory;
|
||||
|
||||
import com.dfsek.terra.api.platform.inventory.Inventory;
|
||||
import com.dfsek.terra.api.platform.inventory.ItemStack;
|
||||
import com.dfsek.terra.forge.world.ForgeAdapter;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.Items;
|
||||
|
||||
public class ForgeInventory implements Inventory {
|
||||
private final net.minecraft.inventory.IInventory delegate;
|
||||
|
||||
public ForgeInventory(IInventory delegate) {
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public net.minecraft.inventory.IInventory getHandle() {
|
||||
return delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSize() {
|
||||
return delegate.getContainerSize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItem(int slot) {
|
||||
net.minecraft.item.ItemStack itemStack = delegate.getItem(slot);
|
||||
return itemStack.getItem() == Items.AIR ? null : ForgeAdapter.adapt(itemStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItem(int slot, ItemStack newStack) {
|
||||
delegate.setItem(slot, ForgeAdapter.adapt(newStack));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.dfsek.terra.forge.inventory;
|
||||
|
||||
import com.dfsek.terra.api.platform.inventory.Item;
|
||||
import com.dfsek.terra.api.platform.inventory.ItemStack;
|
||||
|
||||
public class ForgeItem implements Item {
|
||||
private final net.minecraft.item.Item delegate;
|
||||
|
||||
public ForgeItem(net.minecraft.item.Item delegate) {
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public net.minecraft.item.Item getHandle() {
|
||||
return delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack newItemStack(int amount) {
|
||||
return new ForgeItemStack(new net.minecraft.item.ItemStack(delegate, amount));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getMaxDurability() {
|
||||
return delegate.getMaxDamage();
|
||||
}
|
||||
}
|
||||
+6
-4
@@ -1,12 +1,14 @@
|
||||
package com.dfsek.terra.forge.handle;
|
||||
package com.dfsek.terra.forge.inventory;
|
||||
|
||||
import com.dfsek.terra.api.platform.handle.ItemHandle;
|
||||
import com.dfsek.terra.api.platform.inventory.Item;
|
||||
import com.dfsek.terra.api.platform.inventory.item.Enchantment;
|
||||
import com.dfsek.terra.forge.world.ForgeAdapter;
|
||||
import com.mojang.brigadier.StringReader;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import net.minecraft.command.arguments.ItemArgument;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
|
||||
import java.util.Set;
|
||||
@@ -17,7 +19,7 @@ public class ForgeItemHandle implements ItemHandle {
|
||||
@Override
|
||||
public Item createItem(String data) {
|
||||
try {
|
||||
return (Item) new ItemArgument().parse(new StringReader(data)).getItem();
|
||||
return ForgeAdapter.adapt(new ItemArgument().parse(new StringReader(data)).getItem());
|
||||
} catch(CommandSyntaxException e) {
|
||||
throw new IllegalArgumentException("Invalid item data \"" + data + "\"", e);
|
||||
}
|
||||
@@ -25,11 +27,11 @@ public class ForgeItemHandle implements ItemHandle {
|
||||
|
||||
@Override
|
||||
public Enchantment getEnchantment(String id) {
|
||||
return (Enchantment) ForgeRegistries.ENCHANTMENTS.getValue(ResourceLocation.tryParse(id));
|
||||
return ForgeAdapter.adapt(ForgeRegistries.ENCHANTMENTS.getValue(ResourceLocation.tryParse(id)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Enchantment> getEnchantments() {
|
||||
return ForgeRegistries.ENCHANTMENTS.getEntries().stream().map(entry -> (Enchantment) entry.getValue()).collect(Collectors.toSet());
|
||||
return ForgeRegistries.ENCHANTMENTS.getEntries().stream().map(entry -> ForgeAdapter.adapt(entry.getValue())).collect(Collectors.toSet());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.dfsek.terra.forge.inventory;
|
||||
|
||||
import com.dfsek.terra.api.platform.inventory.Item;
|
||||
import com.dfsek.terra.api.platform.inventory.ItemStack;
|
||||
import com.dfsek.terra.api.platform.inventory.item.ItemMeta;
|
||||
import com.dfsek.terra.forge.inventory.meta.ForgeDamageable;
|
||||
import com.dfsek.terra.forge.inventory.meta.ForgeItemMeta;
|
||||
|
||||
public class ForgeItemStack implements ItemStack {
|
||||
private net.minecraft.item.ItemStack delegate;
|
||||
|
||||
public ForgeItemStack(net.minecraft.item.ItemStack delegate) {
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAmount() {
|
||||
return delegate.getCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAmount(int i) {
|
||||
delegate.setCount(i);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Item getType() {
|
||||
return new ForgeItem(delegate.getItem());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemMeta getItemMeta() {
|
||||
if(delegate.isDamageableItem()) return new ForgeDamageable(delegate.copy());
|
||||
return new ForgeItemMeta(delegate.copy());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItemMeta(ItemMeta meta) {
|
||||
this.delegate = ((ForgeItemMeta) meta).getHandle();
|
||||
}
|
||||
|
||||
@Override
|
||||
public net.minecraft.item.ItemStack getHandle() {
|
||||
return delegate;
|
||||
}
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
package com.dfsek.terra.forge.inventory.meta;
|
||||
|
||||
import com.dfsek.terra.api.platform.inventory.item.Damageable;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class ForgeDamageable extends ForgeItemMeta implements Damageable {
|
||||
public ForgeDamageable(ItemStack delegate) {
|
||||
super(delegate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDamage() {
|
||||
return delegate.getDamageValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDamage(int damage) {
|
||||
delegate.setDamageValue(damage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasDamage() {
|
||||
return delegate.isDamaged();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.dfsek.terra.forge.inventory.meta;
|
||||
|
||||
import com.dfsek.terra.api.platform.inventory.item.Enchantment;
|
||||
import com.dfsek.terra.api.platform.inventory.item.ItemMeta;
|
||||
import com.dfsek.terra.forge.world.ForgeAdapter;
|
||||
import net.minecraft.command.arguments.NBTCompoundTagArgument;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class ForgeItemMeta implements ItemMeta {
|
||||
protected final ItemStack delegate;
|
||||
|
||||
public ForgeItemMeta(ItemStack delegate) {
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getHandle() {
|
||||
return delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Enchantment, Integer> getEnchantments() {
|
||||
if(!delegate.isEnchanted()) return Collections.emptyMap();
|
||||
Map<Enchantment, Integer> map = new HashMap<>();
|
||||
|
||||
delegate.getEnchantmentTags().forEach(enchantment -> {
|
||||
CompoundNBT eTag = (CompoundNBT) enchantment;
|
||||
map.put(ForgeAdapter.adapt(Registry.ENCHANTMENT.byId(eTag.getInt("id"))), eTag.getInt("lvl"));
|
||||
});
|
||||
return map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addEnchantment(Enchantment enchantment, int level) {
|
||||
delegate.enchant(ForgeAdapter.adapt(enchantment), level);
|
||||
}
|
||||
}
|
||||
@@ -1,81 +0,0 @@
|
||||
package com.dfsek.terra.forge.listener;
|
||||
|
||||
import com.dfsek.terra.api.command.CommandManager;
|
||||
import com.dfsek.terra.api.command.exception.CommandException;
|
||||
import com.dfsek.terra.api.platform.CommandSender;
|
||||
import com.dfsek.terra.api.platform.entity.Entity;
|
||||
import com.dfsek.terra.forge.TerraForgePlugin;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import com.mojang.brigadier.builder.ArgumentBuilder;
|
||||
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import net.minecraft.command.CommandSource;
|
||||
import net.minecraft.util.text.StringTextComponent;
|
||||
import net.minecraftforge.event.RegisterCommandsEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static com.mojang.brigadier.builder.LiteralArgumentBuilder.literal;
|
||||
import static com.mojang.brigadier.builder.RequiredArgumentBuilder.argument;
|
||||
|
||||
@Mod.EventBusSubscriber(modid = "terra", bus = Mod.EventBusSubscriber.Bus.FORGE)
|
||||
public class ForgeListener {
|
||||
private static final TerraForgePlugin INSTANCE = TerraForgePlugin.getInstance();
|
||||
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
@SubscribeEvent
|
||||
public static void registerCommands(RegisterCommandsEvent event) {
|
||||
int max = INSTANCE.getManager().getMaxArgumentDepth();
|
||||
RequiredArgumentBuilder<CommandSource, String> arg = argument("arg" + (max - 1), StringArgumentType.word());
|
||||
for(int i = 0; i < max; i++) {
|
||||
RequiredArgumentBuilder<CommandSource, String> next = argument("arg" + (max - i - 1), StringArgumentType.word());
|
||||
|
||||
arg = next.then(assemble(arg, INSTANCE.getManager()));
|
||||
}
|
||||
|
||||
event.getDispatcher().register(literal("terra").executes(context -> 1).then((ArgumentBuilder) assemble(arg, INSTANCE.getManager())));
|
||||
event.getDispatcher().register(literal("te").executes(context -> 1).then((ArgumentBuilder) assemble(arg, INSTANCE.getManager())));
|
||||
}
|
||||
|
||||
public static RequiredArgumentBuilder<CommandSource, String> assemble(RequiredArgumentBuilder<CommandSource, String> in, CommandManager manager) {
|
||||
return in.suggests((context, builder) -> {
|
||||
List<String> args = parseCommand(context.getInput());
|
||||
CommandSender sender = (CommandSender) context.getSource();
|
||||
try {
|
||||
sender = (Entity) context.getSource().getEntityOrException();
|
||||
} catch(CommandSyntaxException ignore) {
|
||||
}
|
||||
try {
|
||||
manager.tabComplete(args.remove(0), sender, args).forEach(builder::suggest);
|
||||
} catch(CommandException e) {
|
||||
sender.sendMessage(e.getMessage());
|
||||
}
|
||||
return builder.buildFuture();
|
||||
}).executes(context -> {
|
||||
List<String> args = parseCommand(context.getInput());
|
||||
try {
|
||||
CommandSender sender = (CommandSender) context.getSource();
|
||||
try {
|
||||
sender = (Entity) context.getSource().getEntityOrException();
|
||||
} catch(CommandSyntaxException ignore) {
|
||||
}
|
||||
manager.execute(args.remove(0), sender, args);
|
||||
} catch(CommandException e) {
|
||||
context.getSource().sendFailure(new StringTextComponent(e.getMessage()));
|
||||
}
|
||||
return 1;
|
||||
});
|
||||
}
|
||||
|
||||
private static List<String> parseCommand(String command) {
|
||||
if(command.startsWith("/terra ")) command = command.substring("/terra ".length());
|
||||
else if(command.startsWith("/te ")) command = command.substring("/te ".length());
|
||||
List<String> c = new ArrayList<>(Arrays.asList(command.split(" ")));
|
||||
if(command.endsWith(" ")) c.add("");
|
||||
return c;
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
package com.dfsek.terra.forge.listener;
|
||||
|
||||
import com.dfsek.terra.forge.TerraForgePlugin;
|
||||
import net.minecraft.world.gen.feature.Feature;
|
||||
import net.minecraftforge.event.RegistryEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
|
||||
@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD)
|
||||
public class RegistryListener {
|
||||
@SubscribeEvent
|
||||
public static void registerPop(RegistryEvent.Register<Feature<?>> event) {
|
||||
event.getRegistry().register(TerraForgePlugin.POPULATOR_FEATURE);
|
||||
}
|
||||
}
|
||||
-64
@@ -1,64 +0,0 @@
|
||||
package com.dfsek.terra.forge.mixin;
|
||||
|
||||
import com.dfsek.terra.config.pack.ConfigPack;
|
||||
import com.dfsek.terra.forge.TerraForgePlugin;
|
||||
import com.dfsek.terra.forge.generation.ForgeChunkGeneratorWrapper;
|
||||
import com.dfsek.terra.forge.generation.TerraBiomeSource;
|
||||
import com.google.common.base.MoreObjects;
|
||||
import net.minecraft.util.registry.DynamicRegistries;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.util.registry.SimpleRegistry;
|
||||
import net.minecraft.world.Dimension;
|
||||
import net.minecraft.world.DimensionType;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
import net.minecraft.world.gen.DimensionSettings;
|
||||
import net.minecraft.world.gen.settings.DimensionGeneratorSettings;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
import java.util.Properties;
|
||||
import java.util.Random;
|
||||
|
||||
@Mixin(DimensionGeneratorSettings.class)
|
||||
public abstract class DimensionGeneratorSettingsMixin {
|
||||
@Inject(method = "create(Lnet/minecraft/util/registry/DynamicRegistries;Ljava/util/Properties;)Lnet/minecraft/world/gen/settings/DimensionGeneratorSettings;", at = @At("HEAD"), cancellable = true)
|
||||
private static void fromProperties(DynamicRegistries dynamicRegistries, Properties properties, CallbackInfoReturnable<DimensionGeneratorSettings> cir) {
|
||||
if(properties.get("level-type") == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
String prop = properties.get("level-type").toString().trim();
|
||||
if(prop.startsWith("Terra")) {
|
||||
String seed = (String) MoreObjects.firstNonNull(properties.get("level-seed"), "");
|
||||
long l = new Random().nextLong();
|
||||
if(!seed.isEmpty()) {
|
||||
try {
|
||||
long m = Long.parseLong(seed);
|
||||
if(m != 0L) {
|
||||
l = m;
|
||||
}
|
||||
} catch(NumberFormatException exception) {
|
||||
l = seed.hashCode();
|
||||
}
|
||||
}
|
||||
|
||||
String generate_structures = (String) properties.get("generate-structures");
|
||||
boolean generateStructures = generate_structures == null || Boolean.parseBoolean(generate_structures);
|
||||
Registry<DimensionType> dimensionTypes = dynamicRegistries.registryOrThrow(Registry.DIMENSION_TYPE_REGISTRY);
|
||||
Registry<Biome> biomes = dynamicRegistries.registryOrThrow(Registry.BIOME_REGISTRY);
|
||||
Registry<DimensionSettings> chunkGeneratorSettings = dynamicRegistries.registryOrThrow(Registry.NOISE_GENERATOR_SETTINGS_REGISTRY);
|
||||
SimpleRegistry<Dimension> dimensionOptions = DimensionType.defaultDimensions(dimensionTypes, biomes, chunkGeneratorSettings, l);
|
||||
|
||||
prop = prop.substring(prop.indexOf(":") + 1);
|
||||
|
||||
ConfigPack pack = TerraForgePlugin.getInstance().getConfigRegistry().get(prop);
|
||||
|
||||
if(pack == null) throw new IllegalArgumentException("No such pack " + prop);
|
||||
|
||||
TerraForgePlugin.getInstance().logger().info("Using config pack " + pack.getTemplate().getID());
|
||||
cir.setReturnValue(new DimensionGeneratorSettings(l, generateStructures, false, DimensionGeneratorSettings.withOverworld(dimensionTypes, dimensionOptions, new ForgeChunkGeneratorWrapper(new TerraBiomeSource(biomes, l, pack), l, pack))));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
package com.dfsek.terra.forge.mixin;
|
||||
|
||||
import com.dfsek.terra.api.util.generic.pair.Pair;
|
||||
import com.dfsek.terra.forge.TerraForgePlugin;
|
||||
import com.dfsek.terra.forge.generation.ForgeChunkGeneratorWrapper;
|
||||
import com.dfsek.terra.world.TerraWorld;
|
||||
import net.minecraft.world.DimensionType;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.server.ServerChunkProvider;
|
||||
import net.minecraft.world.server.ServerWorld;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
|
||||
@Mixin(ServerWorld.class)
|
||||
public abstract class ServerWorldMixin {
|
||||
@Shadow
|
||||
@Final
|
||||
private ServerChunkProvider chunkSource;
|
||||
|
||||
@Shadow
|
||||
protected abstract void initCapabilities();
|
||||
|
||||
@Redirect(method = "<init>", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/server/ServerWorld;initCapabilities()V"))
|
||||
public void injectConstructor(ServerWorld serverWorld) {
|
||||
if(chunkSource.getGenerator() instanceof ForgeChunkGeneratorWrapper) {
|
||||
ForgeChunkGeneratorWrapper chunkGeneratorWrapper = (ForgeChunkGeneratorWrapper) chunkSource.getGenerator();
|
||||
DimensionType dimensionType = ((World) (Object) this).dimensionType();
|
||||
TerraForgePlugin.getInstance().getWorldMap().put(dimensionType, Pair.of((ServerWorld) (Object) this, new TerraWorld((com.dfsek.terra.api.platform.world.World) this, chunkGeneratorWrapper.getPack(), TerraForgePlugin.getInstance())));
|
||||
chunkGeneratorWrapper.setDimensionType(dimensionType);
|
||||
TerraForgePlugin.getInstance().logger().info("Registered world " + this + " to dimension type " + dimensionType);
|
||||
}
|
||||
initCapabilities();
|
||||
}
|
||||
}
|
||||
-12
@@ -1,12 +0,0 @@
|
||||
package com.dfsek.terra.forge.mixin.access;
|
||||
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.world.spawner.AbstractSpawner;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Invoker;
|
||||
|
||||
@Mixin(AbstractSpawner.class)
|
||||
public interface AbstractSpawnerAccessor {
|
||||
@Invoker("getEntityId")
|
||||
ResourceLocation callGetEntityId();
|
||||
}
|
||||
-21
@@ -1,21 +0,0 @@
|
||||
package com.dfsek.terra.forge.mixin.access;
|
||||
|
||||
import net.minecraft.client.gui.screen.BiomeGeneratorTypeScreens;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Mutable;
|
||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mixin(BiomeGeneratorTypeScreens.class)
|
||||
public interface BiomeGeneratorTypeScreensAccessor {
|
||||
@Accessor("PRESETS")
|
||||
static List<BiomeGeneratorTypeScreens> getPresets() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Mutable
|
||||
@Accessor
|
||||
void setDescription(ITextComponent description);
|
||||
}
|
||||
-14
@@ -1,14 +0,0 @@
|
||||
package com.dfsek.terra.forge.mixin.implementations;
|
||||
|
||||
import net.minecraft.world.biome.Biome;
|
||||
import org.spongepowered.asm.mixin.Implements;
|
||||
import org.spongepowered.asm.mixin.Interface;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
|
||||
@Mixin(Biome.class)
|
||||
@Implements(@Interface(iface = com.dfsek.terra.api.platform.world.Biome.class, prefix = "terra$", remap = Interface.Remap.NONE))
|
||||
public abstract class BiomeMixin {
|
||||
public Object terra$getHandle() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
-14
@@ -1,14 +0,0 @@
|
||||
package com.dfsek.terra.forge.mixin.implementations;
|
||||
|
||||
import net.minecraft.world.gen.ChunkGenerator;
|
||||
import org.spongepowered.asm.mixin.Implements;
|
||||
import org.spongepowered.asm.mixin.Interface;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
|
||||
@Mixin(ChunkGenerator.class)
|
||||
@Implements(@Interface(iface = com.dfsek.terra.api.platform.world.generator.ChunkGenerator.class, prefix = "terra$", remap = Interface.Remap.NONE))
|
||||
public abstract class ChunkGeneratorMixin {
|
||||
public Object terra$getHandle() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user