mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-06-16 22:01:07 +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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.dfsek.terra.addons.tree;
|
||||
|
||||
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;
|
||||
import com.dfsek.terra.api.registry.exception.DuplicateEntryException;
|
||||
import com.dfsek.terra.api.world.generator.GenerationStageProvider;
|
||||
|
||||
@Addon("core-tree-config")
|
||||
@Author("Terra")
|
||||
@Version("1.0.0")
|
||||
public class TreeAddon extends TerraAddon implements EventListener {
|
||||
@Inject
|
||||
private TerraPlugin main;
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
main.getEventManager().registerListener(this, this);
|
||||
}
|
||||
|
||||
public void onPackLoad(ConfigPackPreLoadEvent event) throws DuplicateEntryException {
|
||||
event.getPack().registerConfigType(new TreeConfigType(event.getPack()), "TREE", 2);
|
||||
event.getPack().getOrCreateRegistry(GenerationStageProvider.class).register("TREE", pack -> new TreePopulator(main));
|
||||
}
|
||||
}
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
package com.dfsek.terra.addons.tree;
|
||||
|
||||
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.Tree;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class TreeConfigType implements ConfigType<TreeTemplate, Tree> {
|
||||
private final TreeFactory factory = new TreeFactory();
|
||||
private final ConfigPack pack;
|
||||
|
||||
public TreeConfigType(ConfigPack pack) {
|
||||
this.pack = pack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TreeTemplate getTemplate(ConfigPack pack, TerraPlugin main) {
|
||||
return new TreeTemplate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigFactory<TreeTemplate, Tree> getFactory() {
|
||||
return factory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<Tree> getTypeClass() {
|
||||
return Tree.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Supplier<OpenRegistry<Tree>> registrySupplier() {
|
||||
return pack.getRegistryFactory()::create;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.dfsek.terra.addons.tree;
|
||||
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.config.ConfigFactory;
|
||||
import com.dfsek.terra.api.world.Tree;
|
||||
import com.dfsek.terra.addons.tree.tree.TerraTree;
|
||||
|
||||
public class TreeFactory implements ConfigFactory<TreeTemplate, Tree> {
|
||||
@Override
|
||||
public Tree build(TreeTemplate config, TerraPlugin main) {
|
||||
return new TerraTree(config.getSpawnable(), config.getyOffset(), config.getStructures());
|
||||
}
|
||||
}
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
package com.dfsek.terra.addons.tree;
|
||||
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.profiler.ProfileFrame;
|
||||
import com.dfsek.terra.api.util.PopulationUtil;
|
||||
import com.dfsek.terra.api.world.Chunk;
|
||||
import com.dfsek.terra.api.world.TerraWorld;
|
||||
import com.dfsek.terra.api.world.World;
|
||||
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
|
||||
import com.dfsek.terra.api.world.generator.TerraGenerationStage;
|
||||
import net.jafama.FastMath;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
|
||||
public class TreePopulator implements TerraGenerationStage {
|
||||
private final TerraPlugin main;
|
||||
|
||||
public TreePopulator(TerraPlugin main) {
|
||||
this.main = main;
|
||||
}
|
||||
|
||||
private static int offset(Random r, int i) {
|
||||
return FastMath.min(FastMath.max(i + r.nextInt(3) - 1, 0), 15);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("try")
|
||||
public void populate(@NotNull World world, @NotNull Chunk chunk) {
|
||||
TerraWorld tw = main.getWorld(world);
|
||||
try(ProfileFrame ignore = main.getProfiler().profile("tree")) {
|
||||
if(tw.getConfig().disableTrees()) return;
|
||||
|
||||
if(!tw.isSafe()) return;
|
||||
BiomeProvider provider = tw.getBiomeProvider();
|
||||
Random random = PopulationUtil.getRandom(chunk);
|
||||
for(int x = 0; x < 16; x += 2) {
|
||||
for(int z = 0; z < 16; z += 2) {
|
||||
/*
|
||||
UserDefinedBiome biome = (UserDefinedBiome) provider.getBiome((chunk.getX() << 4) + x, (chunk.getZ() << 4) + z);
|
||||
for(TreeLayer layer : biome.getConfig().getTrees()) {
|
||||
if(layer.getDensity() >= random.nextDouble() * 100) {
|
||||
layer.place(chunk, new Vector2(offset(random, x), offset(random, z)));
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.dfsek.terra.addons.tree;
|
||||
|
||||
import com.dfsek.tectonic.annotations.Abstractable;
|
||||
import com.dfsek.tectonic.annotations.Default;
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
import com.dfsek.terra.api.config.AbstractableTemplate;
|
||||
import com.dfsek.terra.api.structure.Structure;
|
||||
import com.dfsek.terra.api.util.collection.MaterialSet;
|
||||
import com.dfsek.terra.api.util.collection.ProbabilityCollection;
|
||||
|
||||
@SuppressWarnings({"unused", "FieldMayBeFinal"})
|
||||
public class TreeTemplate implements AbstractableTemplate {
|
||||
@Value("scripts")
|
||||
@Abstractable
|
||||
private ProbabilityCollection<Structure> structure;
|
||||
|
||||
@Value("id")
|
||||
private String id;
|
||||
|
||||
@Value("y-offset")
|
||||
@Abstractable
|
||||
@Default
|
||||
private int yOffset = 0;
|
||||
|
||||
@Value("spawnable")
|
||||
@Abstractable
|
||||
private MaterialSet spawnable;
|
||||
|
||||
public ProbabilityCollection<Structure> getStructures() {
|
||||
return structure;
|
||||
}
|
||||
|
||||
public String getID() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public int getyOffset() {
|
||||
return yOffset;
|
||||
}
|
||||
|
||||
public MaterialSet getSpawnable() {
|
||||
return spawnable;
|
||||
}
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
package com.dfsek.terra.addons.tree.tree;
|
||||
|
||||
import com.dfsek.terra.api.structure.Structure;
|
||||
import com.dfsek.terra.api.structure.rotation.Rotation;
|
||||
import com.dfsek.terra.api.util.collection.MaterialSet;
|
||||
import com.dfsek.terra.api.util.collection.ProbabilityCollection;
|
||||
import com.dfsek.terra.api.vector.Vector3;
|
||||
import com.dfsek.terra.api.world.Tree;
|
||||
import com.dfsek.terra.api.world.World;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class TerraTree implements Tree {
|
||||
private final MaterialSet spawnable;
|
||||
private final int yOffset;
|
||||
private final ProbabilityCollection<Structure> structure;
|
||||
|
||||
public TerraTree(MaterialSet spawnable, int yOffset, ProbabilityCollection<Structure> structure) {
|
||||
this.spawnable = spawnable;
|
||||
this.yOffset = yOffset;
|
||||
this.structure = structure;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized boolean plant(Vector3 location, World world, Random random) {
|
||||
return structure.get(random).generateDirect(location.clone().add(0, yOffset, 0), world, random, Rotation.fromDegrees(90 * random.nextInt(4)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public MaterialSet getSpawnable() {
|
||||
return spawnable;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user