mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-06-19 07:11:14 +00:00
move modules to better directory structure
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
import com.dfsek.terra.configureCompilation
|
||||
import com.dfsek.terra.configureDependencies
|
||||
|
||||
plugins {
|
||||
`java-library`
|
||||
`maven-publish`
|
||||
idea
|
||||
}
|
||||
|
||||
configureCompilation()
|
||||
configureDependencies()
|
||||
|
||||
group = "com.dfsek.terra.common"
|
||||
|
||||
dependencies {
|
||||
"shadedApi"(project(":common:api"))
|
||||
|
||||
"shadedApi"("org.apache.commons:commons-rng-core:1.3")
|
||||
"shadedApi"("commons-io:commons-io:2.4")
|
||||
|
||||
"shadedApi"("com.dfsek:Paralithic:0.3.2")
|
||||
"shadedApi"("com.dfsek:Tectonic:1.4.0")
|
||||
"shadedApi"("net.jafama:jafama:2.3.2")
|
||||
"shadedApi"("org.yaml:snakeyaml:1.27")
|
||||
"shadedApi"("org.ow2.asm:asm:9.0")
|
||||
"shadedApi"("commons-io:commons-io:2.6")
|
||||
|
||||
"shadedApi"("com.googlecode.json-simple:json-simple:1.1.1")
|
||||
"shadedApi"("org.yaml:snakeyaml:1.27")
|
||||
|
||||
"compileOnly"("com.google.guava:guava:30.0-jre")
|
||||
|
||||
"testImplementation"("com.google.guava:guava:30.0-jre")
|
||||
}
|
||||
|
||||
publishing {
|
||||
publications {
|
||||
create<MavenPublication>("mavenJava") {
|
||||
artifact(tasks["sourcesJar"])
|
||||
artifact(tasks["jar"])
|
||||
}
|
||||
}
|
||||
|
||||
repositories {
|
||||
val mavenUrl = "https://repo.codemc.io/repository/maven-releases/"
|
||||
val mavenSnapshotUrl = "https://repo.codemc.io/repository/maven-snapshots/"
|
||||
|
||||
maven(mavenUrl) {
|
||||
val mavenUsername: String? by project
|
||||
val mavenPassword: String? by project
|
||||
if (mavenUsername != null && mavenPassword != null) {
|
||||
credentials {
|
||||
username = mavenUsername
|
||||
password = mavenPassword
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
package com.dfsek.terra.addons.palette;
|
||||
|
||||
import com.dfsek.terra.addons.palette.palette.PaletteLayerHolder;
|
||||
import com.dfsek.terra.addons.palette.palette.PaletteLayerLoader;
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.addon.TerraAddon;
|
||||
import com.dfsek.terra.api.addon.annotations.Addon;
|
||||
import com.dfsek.terra.api.addon.annotations.Author;
|
||||
import com.dfsek.terra.api.addon.annotations.Version;
|
||||
import com.dfsek.terra.api.event.EventListener;
|
||||
import com.dfsek.terra.api.event.events.config.ConfigPackPreLoadEvent;
|
||||
import com.dfsek.terra.api.injection.annotations.Inject;
|
||||
|
||||
@Addon("core-palette-config")
|
||||
@Author("Terra")
|
||||
@Version("1.0.0")
|
||||
public class PaletteAddon extends TerraAddon implements EventListener {
|
||||
@Inject
|
||||
private TerraPlugin main;
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
main.getEventManager().registerListener(this, this);
|
||||
main.applyLoader(PaletteLayerHolder.class, new PaletteLayerLoader());
|
||||
}
|
||||
|
||||
public void onPackLoad(ConfigPackPreLoadEvent event) {
|
||||
event.getPack().registerConfigType(new PaletteConfigType(event.getPack(), main), "PALETTE", 2);
|
||||
}
|
||||
}
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
package com.dfsek.terra.addons.palette;
|
||||
|
||||
import com.dfsek.tectonic.exception.LoadException;
|
||||
import com.dfsek.tectonic.loading.ConfigLoader;
|
||||
import com.dfsek.tectonic.loading.TypeLoader;
|
||||
import com.dfsek.terra.addons.palette.palette.PaletteImpl;
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.config.ConfigFactory;
|
||||
import com.dfsek.terra.api.config.ConfigPack;
|
||||
import com.dfsek.terra.api.config.ConfigType;
|
||||
import com.dfsek.terra.api.registry.OpenRegistry;
|
||||
import com.dfsek.terra.api.world.generator.Palette;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class PaletteConfigType implements ConfigType<PaletteTemplate, Palette> {
|
||||
private final PaletteFactory factory = new PaletteFactory();
|
||||
private final ConfigPack pack;
|
||||
private final TerraPlugin main;
|
||||
|
||||
public PaletteConfigType(ConfigPack pack, TerraPlugin main) {
|
||||
this.pack = pack;
|
||||
this.main = main;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PaletteTemplate getTemplate(ConfigPack pack, TerraPlugin main) {
|
||||
return new PaletteTemplate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigFactory<PaletteTemplate, Palette> getFactory() {
|
||||
return factory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<Palette> getTypeClass() {
|
||||
return Palette.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Supplier<OpenRegistry<Palette>> registrySupplier() {
|
||||
return () -> pack.getRegistryFactory().create(registry -> (TypeLoader<Palette>) (t, c, loader) -> {
|
||||
if(((String) c).startsWith("BLOCK:"))
|
||||
return new PaletteImpl.Singleton(main.getWorldHandle().createBlockData(((String) c).substring(6))); // Return single palette for BLOCK: shortcut.
|
||||
Palette obj = registry.get((String) c);
|
||||
if(obj == null)
|
||||
throw new LoadException("No such " + t.getTypeName() + " matching \"" + c + "\" was found in this registry.");
|
||||
return obj;
|
||||
});
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
package com.dfsek.terra.addons.palette;
|
||||
|
||||
import com.dfsek.terra.addons.palette.palette.NoisePalette;
|
||||
import com.dfsek.terra.addons.palette.palette.PaletteLayerHolder;
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.config.ConfigFactory;
|
||||
import com.dfsek.terra.api.world.generator.Palette;
|
||||
|
||||
public class PaletteFactory implements ConfigFactory<PaletteTemplate, Palette> {
|
||||
@Override
|
||||
public Palette build(PaletteTemplate config, TerraPlugin main) {
|
||||
NoisePalette palette = new NoisePalette(config.getNoise().apply(2403L), config.getNoise().getDimensions() == 2);
|
||||
for(PaletteLayerHolder layer : config.getPalette()) {
|
||||
palette.add(layer.getLayer(), layer.getSize(), layer.getSampler());
|
||||
}
|
||||
return palette;
|
||||
}
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
package com.dfsek.terra.addons.palette;
|
||||
|
||||
import com.dfsek.tectonic.annotations.Abstractable;
|
||||
import com.dfsek.tectonic.annotations.Default;
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
import com.dfsek.terra.addons.palette.palette.PaletteLayerHolder;
|
||||
import com.dfsek.terra.api.config.AbstractableTemplate;
|
||||
import com.dfsek.terra.api.util.seeded.NoiseSeeded;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@SuppressWarnings({"FieldMayBeFinal", "unused"})
|
||||
public class PaletteTemplate implements AbstractableTemplate {
|
||||
@Value("noise")
|
||||
@Abstractable
|
||||
@Default
|
||||
private NoiseSeeded noise = NoiseSeeded.zero(2);
|
||||
|
||||
@Value("id")
|
||||
private String id;
|
||||
|
||||
@Value("layers")
|
||||
@Abstractable
|
||||
private List<PaletteLayerHolder> palette;
|
||||
|
||||
public String getID() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public List<PaletteLayerHolder> getPalette() {
|
||||
return palette;
|
||||
}
|
||||
|
||||
public NoiseSeeded getNoise() {
|
||||
return noise;
|
||||
}
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
package com.dfsek.terra.addons.palette.palette;
|
||||
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.api.noise.NoiseSampler;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class NoisePalette extends PaletteImpl {
|
||||
private final NoiseSampler sampler;
|
||||
private final boolean is2D;
|
||||
|
||||
public NoisePalette(NoiseSampler sampler, boolean is2D) {
|
||||
this.sampler = sampler;
|
||||
this.is2D = is2D;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState get(int layer, double x, double y, double z) {
|
||||
PaletteLayer paletteLayer;
|
||||
if(layer > this.getSize()) paletteLayer = this.getLayers().get(this.getLayers().size() - 1);
|
||||
else {
|
||||
List<PaletteLayer> pl = getLayers();
|
||||
if(layer >= pl.size()) paletteLayer = pl.get(pl.size() - 1);
|
||||
else paletteLayer = pl.get(layer);
|
||||
}
|
||||
NoiseSampler paletteSampler = paletteLayer.getSampler();
|
||||
return paletteLayer.get(paletteSampler == null ? sampler : paletteSampler, x, y, z, is2D);
|
||||
}
|
||||
}
|
||||
+122
@@ -0,0 +1,122 @@
|
||||
package com.dfsek.terra.addons.palette.palette;
|
||||
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.api.noise.NoiseSampler;
|
||||
import com.dfsek.terra.api.util.collection.ProbabilityCollection;
|
||||
import com.dfsek.terra.api.world.generator.Palette;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* A class representation of a "slice" of the world.
|
||||
* Used to get a section of blocks, based on the depth at which they are found.
|
||||
*/
|
||||
public abstract class PaletteImpl implements com.dfsek.terra.api.world.generator.Palette {
|
||||
private final List<PaletteLayer> pallet = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Constructs a blank palette.
|
||||
*/
|
||||
public PaletteImpl() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Palette add(BlockState m, int layers, NoiseSampler sampler) {
|
||||
for(int i = 0; i < layers; i++) {
|
||||
pallet.add(new PaletteLayer(m, sampler));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Palette add(ProbabilityCollection<BlockState> m, int layers, NoiseSampler sampler) {
|
||||
for(int i = 0; i < layers; i++) {
|
||||
pallet.add(new PaletteLayer(m, sampler));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getSize() {
|
||||
return pallet.size();
|
||||
}
|
||||
|
||||
public List<PaletteLayer> getLayers() {
|
||||
return pallet;
|
||||
}
|
||||
|
||||
/**
|
||||
* Class representation of a layer of a BlockPalette.
|
||||
*/
|
||||
public static class PaletteLayer {
|
||||
private final boolean col; // Is layer using a collection?
|
||||
private ProbabilityCollection<BlockState> collection;
|
||||
private final NoiseSampler sampler;
|
||||
private BlockState m;
|
||||
|
||||
/**
|
||||
* Constructs a PaletteLayerHolder with a ProbabilityCollection of materials and a number of layers.
|
||||
*
|
||||
* @param type The collection of materials to choose from.
|
||||
* @param sampler Noise sampler to use
|
||||
*/
|
||||
public PaletteLayer(ProbabilityCollection<BlockState> type, NoiseSampler sampler) {
|
||||
this.sampler = sampler;
|
||||
this.col = true;
|
||||
this.collection = type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a PaletteLayerHolder with a single Material and a number of layers.
|
||||
*
|
||||
* @param type The material to use.
|
||||
* @param sampler Noise sampler to use
|
||||
*/
|
||||
public PaletteLayer(BlockState type, NoiseSampler sampler) {
|
||||
this.sampler = sampler;
|
||||
this.col = false;
|
||||
this.m = type;
|
||||
}
|
||||
|
||||
public NoiseSampler getSampler() {
|
||||
return sampler;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a material from the layer.
|
||||
*
|
||||
* @return Material - the material..
|
||||
*/
|
||||
public BlockState get(Random random) {
|
||||
if(col) return this.collection.get(random);
|
||||
return m;
|
||||
}
|
||||
|
||||
public BlockState get(NoiseSampler random, double x, double y, double z, boolean is2D) {
|
||||
if(col && is2D) return this.collection.get(random, x, z);
|
||||
else if(col) return this.collection.get(random, x, y, z);
|
||||
return m;
|
||||
}
|
||||
|
||||
public ProbabilityCollection<BlockState> getCollection() {
|
||||
return collection;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Singleton extends PaletteImpl {
|
||||
private final BlockState item;
|
||||
|
||||
public Singleton(BlockState item) {
|
||||
this.item = item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState get(int layer, double x, double y, double z) {
|
||||
return item;
|
||||
}
|
||||
}
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
package com.dfsek.terra.addons.palette.palette;
|
||||
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.api.noise.NoiseSampler;
|
||||
import com.dfsek.terra.api.util.collection.ProbabilityCollection;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class PaletteLayerHolder {
|
||||
private final ProbabilityCollection<BlockState> layer;
|
||||
private final NoiseSampler sampler;
|
||||
private final int size;
|
||||
|
||||
public PaletteLayerHolder(@NotNull ProbabilityCollection<BlockState> layer, NoiseSampler sampler, int size) {
|
||||
this.layer = layer;
|
||||
this.sampler = sampler;
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ProbabilityCollection<BlockState> getLayer() {
|
||||
return layer;
|
||||
}
|
||||
|
||||
public int getSize() {
|
||||
return size;
|
||||
}
|
||||
|
||||
public NoiseSampler getSampler() {
|
||||
return sampler;
|
||||
}
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
package com.dfsek.terra.addons.palette.palette;
|
||||
|
||||
import com.dfsek.tectonic.exception.LoadException;
|
||||
import com.dfsek.tectonic.loading.ConfigLoader;
|
||||
import com.dfsek.tectonic.loading.TypeLoader;
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.api.noise.NoiseSampler;
|
||||
import com.dfsek.terra.api.util.collection.ProbabilityCollection;
|
||||
import com.dfsek.terra.api.util.seeded.NoiseSeeded;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Map;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public class PaletteLayerLoader implements TypeLoader<PaletteLayerHolder> {
|
||||
private static final Type BLOCK_DATA_PROBABILITY_COLLECTION_TYPE;
|
||||
@SuppressWarnings("unused")
|
||||
private ProbabilityCollection<BlockState> blockStateProbabilityCollection;
|
||||
|
||||
static {
|
||||
try {
|
||||
BLOCK_DATA_PROBABILITY_COLLECTION_TYPE = PaletteLayerLoader.class.getDeclaredField("blockStateProbabilityCollection").getGenericType();
|
||||
} catch(NoSuchFieldException e) {
|
||||
throw new Error("this should never happen. i dont know what you did to make this happen but something is very wrong.", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public PaletteLayerHolder load(Type type, Object o, ConfigLoader configLoader) throws LoadException {
|
||||
Map<String, Object> map = (Map<String, Object>) o;
|
||||
ProbabilityCollection<BlockState> collection = (ProbabilityCollection<BlockState>) configLoader.loadType(BLOCK_DATA_PROBABILITY_COLLECTION_TYPE, map.get("materials"));
|
||||
|
||||
NoiseSampler sampler = null;
|
||||
if(map.containsKey("noise")) {
|
||||
sampler = configLoader.loadClass(NoiseSeeded.class, map.get("noise")).apply(2403L);
|
||||
}
|
||||
|
||||
if(collection == null) throw new LoadException("Collection is null: " + map.get("materials"));
|
||||
return new PaletteLayerHolder(collection, sampler, (Integer) map.get("layers"));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user