mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-05-20 08:40:26 +00:00
Compare commits
15 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 8d01059833 | |||
| 500cf3c0b5 | |||
| 0507978c87 | |||
| d810cad8d0 | |||
| 4e7de501c0 | |||
| 9e60db4b0d | |||
| 4536767794 | |||
| 3fa4b21247 | |||
| 17acde09a3 | |||
| dd272bce64 | |||
| 01e011a9ed | |||
| 94949c9120 | |||
| c52ad56ccc | |||
| f3476c5cc8 | |||
| 9c181f7ee1 |
@@ -18,10 +18,10 @@ jobs:
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
|
||||
- name: Set up JDK 17
|
||||
- name: Set up JDK 21
|
||||
uses: actions/setup-java@387ac29b308b003ca37ba93a6cab5eb57c8f5f93
|
||||
with:
|
||||
java-version: '17'
|
||||
java-version: '21'
|
||||
distribution: 'temurin'
|
||||
server-id: github # Value of the distributionManagement/repository/id field of the pom.xml
|
||||
settings-path: ${{ github.workspace }} # location for the settings.xml file
|
||||
|
||||
@@ -9,7 +9,7 @@ repositories {
|
||||
maven("https://repo.codemc.org/repository/maven-public") {
|
||||
name = "CodeMC"
|
||||
}
|
||||
maven("https://papermc.io/repo/repository/maven-public/") {
|
||||
maven("https://repo.papermc.io/repository/maven-public/") {
|
||||
name = "PaperMC"
|
||||
}
|
||||
}
|
||||
@@ -17,10 +17,10 @@ repositories {
|
||||
dependencies {
|
||||
//TODO Allow pulling from Versions.kt
|
||||
implementation("com.github.johnrengelman", "shadow", "8.1.1")
|
||||
implementation("io.papermc.paperweight.userdev", "io.papermc.paperweight.userdev.gradle.plugin", "1.5.11")
|
||||
implementation("io.papermc.paperweight.userdev", "io.papermc.paperweight.userdev.gradle.plugin", "1.7.1")
|
||||
|
||||
implementation("org.ow2.asm", "asm", "9.6")
|
||||
implementation("org.ow2.asm", "asm-tree", "9.6")
|
||||
implementation("org.ow2.asm", "asm", "9.7")
|
||||
implementation("org.ow2.asm", "asm-tree", "9.7")
|
||||
implementation("com.dfsek.tectonic", "common", "4.2.1")
|
||||
implementation("org.yaml", "snakeyaml", "2.2")
|
||||
}
|
||||
@@ -22,8 +22,8 @@ fun Project.configureCompilation() {
|
||||
apply<TectonicDocPlugin>()
|
||||
|
||||
configure<JavaPluginExtension> {
|
||||
sourceCompatibility = JavaVersion.VERSION_17
|
||||
targetCompatibility = JavaVersion.VERSION_17
|
||||
sourceCompatibility = JavaVersion.VERSION_21
|
||||
targetCompatibility = JavaVersion.VERSION_21
|
||||
}
|
||||
|
||||
tasks.withType<JavaCompile> {
|
||||
|
||||
@@ -36,7 +36,7 @@ fun Project.configureDependencies() {
|
||||
maven("https://repo.codemc.org/repository/maven-public") {
|
||||
name = "CodeMC"
|
||||
}
|
||||
maven("https://papermc.io/repo/repository/maven-public/") {
|
||||
maven("https://repo.papermc.io/repository/maven-public/") {
|
||||
name = "PaperMC"
|
||||
}
|
||||
maven("https://files.minecraftforge.net/maven/") {
|
||||
|
||||
@@ -27,8 +27,7 @@ fun Project.configureDistribution() {
|
||||
group = "terra"
|
||||
doFirst {
|
||||
file("${buildDir}/resources/main/packs/").deleteRecursively()
|
||||
val defaultPackUrl =
|
||||
URL("https://github.com/PolyhedralDev/TerraOverworldConfig/releases/download/" + Versions.Terra.overworldConfig + "/default.zip")
|
||||
val defaultPackUrl = URL("https://github.com/PolyhedralDev/TerraOverworldConfig/releases/download/" + Versions.Terra.overworldConfig + "/default.zip")
|
||||
downloadPack(defaultPackUrl, project)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,23 +12,22 @@ object Versions {
|
||||
|
||||
const val caffeine = "3.1.8"
|
||||
|
||||
const val slf4j = "2.0.9"
|
||||
const val log4j_slf4j_impl = "2.20.0"
|
||||
|
||||
const val slf4j = "2.0.13"
|
||||
|
||||
object Internal {
|
||||
const val shadow = "8.1.1"
|
||||
const val apacheText = "1.11.0"
|
||||
const val apacheIO = "2.15.1"
|
||||
const val guava = "32.1.3-jre"
|
||||
const val asm = "9.6"
|
||||
const val apacheText = "1.12.0"
|
||||
const val apacheIO = "2.16.1"
|
||||
const val guava = "33.1.0-jre"
|
||||
const val asm = "9.7"
|
||||
const val snakeYml = "2.2"
|
||||
const val jetBrainsAnnotations = "24.1.0"
|
||||
const val junit = "5.10.1"
|
||||
const val junit = "5.10.2"
|
||||
}
|
||||
}
|
||||
|
||||
object Fabric {
|
||||
const val fabricAPI = "0.91.2+${Mod.minecraft}"
|
||||
const val fabricAPI = "0.97.8+${Mod.minecraft}"
|
||||
}
|
||||
//
|
||||
// object Quilt {
|
||||
@@ -39,12 +38,12 @@ object Versions {
|
||||
object Mod {
|
||||
const val mixin = "0.12.5+mixin.0.8.5"
|
||||
|
||||
const val minecraft = "1.20.4"
|
||||
const val minecraft = "1.20.6"
|
||||
const val yarn = "$minecraft+build.1"
|
||||
const val fabricLoader = "0.15.1"
|
||||
const val fabricLoader = "0.15.10"
|
||||
|
||||
const val architecuryLoom = "1.4.369"
|
||||
const val architecturyPlugin = "3.4.151"
|
||||
const val architecuryLoom = "1.6.395"
|
||||
const val architecturyPlugin = "3.4.155"
|
||||
}
|
||||
//
|
||||
// object Forge {
|
||||
@@ -53,14 +52,14 @@ object Versions {
|
||||
// }
|
||||
|
||||
object Bukkit {
|
||||
const val minecraft = "1.20.4"
|
||||
const val paperBuild = "$minecraft-R0.1-20231209.173338-2"
|
||||
const val minecraft = "1.20.6"
|
||||
const val paperBuild = "$minecraft-R0.1-20240602.222958-107"
|
||||
const val paper = paperBuild
|
||||
const val paperLib = "1.0.8"
|
||||
const val reflectionRemapper = "0.1.0"
|
||||
const val paperDevBundle = paperBuild
|
||||
const val runPaper = "2.2.2"
|
||||
const val paperWeight = "1.5.11"
|
||||
const val reflectionRemapper = "0.1.1"
|
||||
const val paperDevBundle = "$minecraft-R0.1-20240601.143523-105"
|
||||
const val runPaper = "2.3.0"
|
||||
const val paperWeight = "1.7.1"
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
+2
-2
@@ -1,9 +1,9 @@
|
||||
package com.dfsek.terra.addons.biome.pipeline.v2.api.biome;
|
||||
|
||||
import com.dfsek.terra.api.world.biome.Biome;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import com.dfsek.terra.api.world.biome.Biome;
|
||||
|
||||
|
||||
public final class DelegatedPipelineBiome implements PipelineBiome {
|
||||
private final Biome biome;
|
||||
|
||||
+5
-5
@@ -7,17 +7,17 @@
|
||||
|
||||
package com.dfsek.terra.addons.biome.pipeline.v2.stage.mutators;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import com.dfsek.terra.addons.biome.pipeline.v2.api.Stage;
|
||||
import com.dfsek.terra.addons.biome.pipeline.v2.api.biome.PipelineBiome;
|
||||
import com.dfsek.terra.addons.biome.pipeline.v2.pipeline.BiomeChunkImpl;
|
||||
import com.dfsek.terra.api.noise.NoiseSampler;
|
||||
import com.dfsek.terra.api.util.collection.ProbabilityCollection;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
|
||||
public class ReplaceListStage implements Stage {
|
||||
private final Map<PipelineBiome, ProbabilityCollection<PipelineBiome>> replace;
|
||||
|
||||
+2
-1
@@ -58,7 +58,8 @@ public class NoiseChunkGenerator3DAddon implements AddonInitializer {
|
||||
pack -> new NoiseChunkGenerator3D(pack, platform, config.getElevationBlend(),
|
||||
config.getHorizontalRes(),
|
||||
config.getVerticalRes(), noisePropertiesPropertyKey,
|
||||
paletteInfoPropertyKey, config.getSlantCalculationMethod()));
|
||||
paletteInfoPropertyKey, config.getSlantCalculationMethod(),
|
||||
config.isSlantPalettesEnabled()));
|
||||
event.getPack()
|
||||
.applyLoader(SlantHolder.Layer.class, SlantLayerTemplate::new);
|
||||
})
|
||||
|
||||
+8
@@ -26,6 +26,10 @@ public class NoiseChunkGeneratorPackConfigTemplate implements ConfigTemplate, Pr
|
||||
@Default
|
||||
private @Meta SlantCalculationMethod slantCalculationMethod = SlantCalculationMethod.Derivative;
|
||||
|
||||
@Value("slant.disable-palettes")
|
||||
@Default
|
||||
private @Meta boolean disableSlantPalettes = false;
|
||||
|
||||
public int getElevationBlend() {
|
||||
return elevationBlend;
|
||||
}
|
||||
@@ -41,4 +45,8 @@ public class NoiseChunkGeneratorPackConfigTemplate implements ConfigTemplate, Pr
|
||||
public SlantCalculationMethod getSlantCalculationMethod() {
|
||||
return slantCalculationMethod;
|
||||
}
|
||||
|
||||
public boolean isSlantPalettesEnabled() {
|
||||
return !disableSlantPalettes;
|
||||
}
|
||||
}
|
||||
|
||||
+6
-2
@@ -47,10 +47,13 @@ public class NoiseChunkGenerator3D implements ChunkGenerator {
|
||||
|
||||
private final SlantCalculationMethod slantCalculationMethod;
|
||||
|
||||
private final boolean useSlantPalettes;
|
||||
|
||||
public NoiseChunkGenerator3D(ConfigPack pack, Platform platform, int elevationBlend, int carverHorizontalResolution,
|
||||
int carverVerticalResolution,
|
||||
PropertyKey<BiomeNoiseProperties> noisePropertiesKey,
|
||||
PropertyKey<BiomePaletteInfo> paletteInfoPropertyKey, SlantCalculationMethod slantCalculationMethod) {
|
||||
PropertyKey<BiomePaletteInfo> paletteInfoPropertyKey,
|
||||
SlantCalculationMethod slantCalculationMethod, boolean useSlantPalettes) {
|
||||
this.platform = platform;
|
||||
this.air = platform.getWorldHandle().air();
|
||||
this.carverHorizontalResolution = carverHorizontalResolution;
|
||||
@@ -58,6 +61,7 @@ public class NoiseChunkGenerator3D implements ChunkGenerator {
|
||||
this.paletteInfoPropertyKey = paletteInfoPropertyKey;
|
||||
this.noisePropertiesKey = noisePropertiesKey;
|
||||
this.slantCalculationMethod = slantCalculationMethod;
|
||||
this.useSlantPalettes = useSlantPalettes;
|
||||
int maxBlend = pack
|
||||
.getBiomeProvider()
|
||||
.stream()
|
||||
@@ -71,7 +75,7 @@ public class NoiseChunkGenerator3D implements ChunkGenerator {
|
||||
|
||||
private Palette paletteAt(int x, int y, int z, Sampler3D sampler, BiomePaletteInfo paletteInfo, int depth) {
|
||||
SlantHolder slantHolder = paletteInfo.slantHolder();
|
||||
if(slantHolder.isAboveDepth(depth)) {
|
||||
if(useSlantPalettes && slantHolder.isAboveDepth(depth)) {
|
||||
double slant = slantCalculationMethod.slant(sampler, x, y, z);
|
||||
if(slantHolder.isInSlantThreshold(slant)) {
|
||||
return slantHolder.getPalette(slant).getPalette(y);
|
||||
|
||||
+2
-7
@@ -6,8 +6,7 @@ import cloud.commandframework.arguments.standard.EnumArgument;
|
||||
import cloud.commandframework.arguments.standard.LongArgument;
|
||||
import cloud.commandframework.context.CommandContext;
|
||||
|
||||
import java.util.random.RandomGenerator;
|
||||
import java.util.random.RandomGeneratorFactory;
|
||||
import java.util.Random;
|
||||
|
||||
import com.dfsek.terra.addons.manifest.api.AddonInitializer;
|
||||
import com.dfsek.terra.api.Platform;
|
||||
@@ -57,11 +56,7 @@ public class StructureCommandAddon implements AddonInitializer {
|
||||
structure.generate(
|
||||
sender.position().toInt(),
|
||||
sender.world(),
|
||||
((Long) context.get("seed") == 0)
|
||||
? RandomGeneratorFactory.<RandomGenerator.SplittableGenerator>of("Xoroshiro128PlusPlus")
|
||||
.create()
|
||||
: RandomGeneratorFactory.<RandomGenerator.SplittableGenerator>of("Xoroshiro128PlusPlus")
|
||||
.create(context.get("seed")),
|
||||
((Long) context.get("seed") == 0) ? new Random() : new Random(context.get("seed")),
|
||||
context.get("rotation")
|
||||
);
|
||||
})
|
||||
|
||||
+2
-4
@@ -1,7 +1,6 @@
|
||||
package com.dfsek.terra.addons.feature.distributor.distributors;
|
||||
|
||||
import java.util.random.RandomGenerator;
|
||||
import java.util.random.RandomGeneratorFactory;
|
||||
import java.util.Random;
|
||||
|
||||
import com.dfsek.terra.api.structure.feature.Distributor;
|
||||
import com.dfsek.terra.api.util.MathUtil;
|
||||
@@ -25,8 +24,7 @@ public class PaddedGridDistributor implements Distributor {
|
||||
int cellX = Math.floorDiv(x, cellWidth);
|
||||
int cellZ = Math.floorDiv(z, cellWidth);
|
||||
|
||||
RandomGenerator random = RandomGeneratorFactory.<RandomGenerator.SplittableGenerator>of("Xoroshiro128PlusPlus").create(
|
||||
(MathUtil.murmur64(MathUtil.squash(cellX, cellZ)) ^ seed) + salt);
|
||||
Random random = new Random((MathUtil.murmur64(MathUtil.squash(cellX, cellZ)) ^ seed) + salt);
|
||||
|
||||
int pointX = random.nextInt(width) + cellX * cellWidth;
|
||||
int pointZ = random.nextInt(width) + cellZ * cellWidth;
|
||||
|
||||
+3
-6
@@ -10,8 +10,7 @@ package com.dfsek.terra.addons.flora.flora.gen;
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.random.RandomGenerator;
|
||||
import java.util.random.RandomGeneratorFactory;
|
||||
import java.util.Random;
|
||||
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.api.block.state.properties.enums.Direction;
|
||||
@@ -72,7 +71,7 @@ public class TerraFlora implements Structure {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean generate(Vector3Int location, WritableWorld world, RandomGenerator random, Rotation rotation) {
|
||||
public boolean generate(Vector3Int location, WritableWorld world, Random random, Rotation rotation) {
|
||||
boolean doRotation = testRotation.size() > 0;
|
||||
int size = layers.size();
|
||||
int c = ceiling ? -1 : 1;
|
||||
@@ -87,9 +86,7 @@ public class TerraFlora implements Structure {
|
||||
location.getZ(), world.getSeed());
|
||||
if(doRotation) {
|
||||
Direction oneFace = new ArrayList<>(faces).get(
|
||||
RandomGeneratorFactory.<RandomGenerator.SplittableGenerator>of("Xoroshiro128PlusPlus")
|
||||
.create(location.getX() ^ location.getZ())
|
||||
.nextInt(faces.size())); // Get RandomGenerator face.
|
||||
new Random(location.getX() ^ location.getZ()).nextInt(faces.size())); // Get random face.
|
||||
}
|
||||
world.setBlockState(location.mutable().add(0, i + c, 0).immutable(), data, physics);
|
||||
}
|
||||
|
||||
+2
-3
@@ -7,8 +7,7 @@
|
||||
|
||||
package com.dfsek.terra.addons.feature.locator.locators;
|
||||
|
||||
import java.util.random.RandomGenerator;
|
||||
import java.util.random.RandomGeneratorFactory;
|
||||
import java.util.Random;
|
||||
|
||||
import com.dfsek.terra.api.structure.feature.BinaryColumn;
|
||||
import com.dfsek.terra.api.structure.feature.Locator;
|
||||
@@ -41,7 +40,7 @@ public class GaussianRandomLocator implements Locator {
|
||||
seed = 31 * seed + column.getZ();
|
||||
seed += salt;
|
||||
|
||||
RandomGenerator r = RandomGeneratorFactory.<RandomGenerator.SplittableGenerator>of("Xoroshiro128PlusPlus").create(seed);
|
||||
Random r = new Random(seed);
|
||||
|
||||
int size = points.get(r);
|
||||
|
||||
|
||||
+2
-3
@@ -7,8 +7,7 @@
|
||||
|
||||
package com.dfsek.terra.addons.feature.locator.locators;
|
||||
|
||||
import java.util.random.RandomGenerator;
|
||||
import java.util.random.RandomGeneratorFactory;
|
||||
import java.util.Random;
|
||||
|
||||
import com.dfsek.terra.api.structure.feature.BinaryColumn;
|
||||
import com.dfsek.terra.api.structure.feature.Locator;
|
||||
@@ -37,7 +36,7 @@ public class RandomLocator implements Locator {
|
||||
seed = 31 * seed + column.getZ();
|
||||
seed += salt;
|
||||
|
||||
RandomGenerator r = RandomGeneratorFactory.<RandomGenerator.SplittableGenerator>of("Xoroshiro128PlusPlus").create(seed);
|
||||
Random r = new Random(seed);
|
||||
|
||||
int size = points.get(r);
|
||||
|
||||
|
||||
+2
-2
@@ -9,7 +9,7 @@ package com.dfsek.terra.addons.ore.ores;
|
||||
|
||||
import java.util.BitSet;
|
||||
import java.util.Map;
|
||||
import java.util.random.RandomGenerator;
|
||||
import java.util.Random;
|
||||
|
||||
import com.dfsek.terra.api.block.BlockType;
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
@@ -44,7 +44,7 @@ public class VanillaOre implements Structure {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean generate(Vector3Int location, WritableWorld world, RandomGenerator random, Rotation rotation) {
|
||||
public boolean generate(Vector3Int location, WritableWorld world, Random random, Rotation rotation) {
|
||||
float randomRadian = random.nextFloat() * (float) Math.PI;
|
||||
double eighthSize = size / 8.0F;
|
||||
|
||||
|
||||
+4
-4
@@ -1,7 +1,7 @@
|
||||
package com.dfsek.terra.addons.ore.ores;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.random.RandomGenerator;
|
||||
import java.util.Random;
|
||||
|
||||
import com.dfsek.terra.api.block.BlockType;
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
@@ -24,7 +24,7 @@ public class VanillaScatteredOre extends VanillaOre {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean generate(Vector3Int location, WritableWorld world, RandomGenerator random, Rotation rotation) {
|
||||
public boolean generate(Vector3Int location, WritableWorld world, Random random, Rotation rotation) {
|
||||
int i = random.nextInt((int) (size + 1));
|
||||
Vector3Int.Mutable mutable = Vector3Int.zero().mutable();
|
||||
|
||||
@@ -39,7 +39,7 @@ public class VanillaScatteredOre extends VanillaOre {
|
||||
return true;
|
||||
}
|
||||
|
||||
private void setPos(Vector3Int.Mutable mutable, RandomGenerator random, Vector3Int location, int spread) {
|
||||
private void setPos(Vector3Int.Mutable mutable, Random random, Vector3Int location, int spread) {
|
||||
int x = this.getSpread(random, spread);
|
||||
int y = this.getSpread(random, spread);
|
||||
int z = this.getSpread(random, spread);
|
||||
@@ -48,7 +48,7 @@ public class VanillaScatteredOre extends VanillaOre {
|
||||
mutable.setZ(location.getZ() + z);
|
||||
}
|
||||
|
||||
private int getSpread(RandomGenerator random, int spread) {
|
||||
private int getSpread(Random random, int spread) {
|
||||
return Math.round((random.nextFloat() - random.nextFloat()) * (float) spread);
|
||||
}
|
||||
}
|
||||
|
||||
+3
-4
@@ -1,6 +1,6 @@
|
||||
package com.dfsek.terra.addons.ore.utils;
|
||||
|
||||
import java.util.random.RandomGenerator;
|
||||
import java.util.Random;
|
||||
|
||||
import com.dfsek.terra.api.block.BlockType;
|
||||
import com.dfsek.terra.api.util.collection.MaterialSet;
|
||||
@@ -8,14 +8,13 @@ import com.dfsek.terra.api.world.WritableWorld;
|
||||
|
||||
|
||||
public class VanillaOreUtils {
|
||||
private static boolean shouldExpose(RandomGenerator random, double exposedChance) {
|
||||
private static boolean shouldExpose(Random random, double exposedChance) {
|
||||
if(exposedChance >= 1.0F) return true;
|
||||
if(exposedChance <= 0.0F) return false;
|
||||
return random.nextFloat() < exposedChance;
|
||||
}
|
||||
|
||||
public static boolean shouldPlace(MaterialSet replaceable, BlockType type, Double exposedChance, RandomGenerator random,
|
||||
WritableWorld world,
|
||||
public static boolean shouldPlace(MaterialSet replaceable, BlockType type, Double exposedChance, Random random, WritableWorld world,
|
||||
int x,
|
||||
int y, int z) {
|
||||
if(!replaceable.contains(type)) return false;
|
||||
|
||||
+3
-3
@@ -12,7 +12,7 @@ import org.json.simple.JSONObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.random.RandomGenerator;
|
||||
import java.util.Random;
|
||||
|
||||
import com.dfsek.terra.addons.structure.structures.loot.functions.AmountFunction;
|
||||
import com.dfsek.terra.addons.structure.structures.loot.functions.DamageFunction;
|
||||
@@ -85,11 +85,11 @@ public class Entry {
|
||||
/**
|
||||
* Fetches a single ItemStack from the Entry, applying all functions to it.
|
||||
*
|
||||
* @param r The RandomGenerator instance to apply functions with
|
||||
* @param r The Random instance to apply functions with
|
||||
*
|
||||
* @return ItemStack - The ItemStack with all functions applied.
|
||||
*/
|
||||
public ItemStack getItem(RandomGenerator r) {
|
||||
public ItemStack getItem(Random r) {
|
||||
ItemStack item = this.item.newItemStack(1);
|
||||
for(LootFunction f : functions) {
|
||||
item = f.apply(item, r);
|
||||
|
||||
+3
-3
@@ -14,7 +14,7 @@ import org.json.simple.parser.ParseException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.random.RandomGenerator;
|
||||
import java.util.Random;
|
||||
|
||||
import com.dfsek.terra.api.Platform;
|
||||
import com.dfsek.terra.api.inventory.Inventory;
|
||||
@@ -44,7 +44,7 @@ public class LootTableImpl implements com.dfsek.terra.api.structure.LootTable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fillInventory(Inventory i, RandomGenerator r) {
|
||||
public void fillInventory(Inventory i, Random r) {
|
||||
List<ItemStack> loot = getLoot(r);
|
||||
for(ItemStack stack : loot) {
|
||||
int attempts = 0;
|
||||
@@ -70,7 +70,7 @@ public class LootTableImpl implements com.dfsek.terra.api.structure.LootTable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ItemStack> getLoot(RandomGenerator r) {
|
||||
public List<ItemStack> getLoot(Random r) {
|
||||
List<ItemStack> itemList = new ArrayList<>();
|
||||
for(Pool pool : pools) {
|
||||
itemList.addAll(pool.getItems(r));
|
||||
|
||||
+4
-4
@@ -12,7 +12,7 @@ import org.json.simple.JSONObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.random.RandomGenerator;
|
||||
import java.util.Random;
|
||||
|
||||
import com.dfsek.terra.api.Platform;
|
||||
import com.dfsek.terra.api.inventory.ItemStack;
|
||||
@@ -50,13 +50,13 @@ public class Pool {
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches a list of items from the pool using the provided RandomGenerator instance.
|
||||
* Fetches a list of items from the pool using the provided Random instance.
|
||||
*
|
||||
* @param r The RandomGenerator instance to use.
|
||||
* @param r The Random instance to use.
|
||||
*
|
||||
* @return List<ItemStack> - The list of items fetched.
|
||||
*/
|
||||
public List<ItemStack> getItems(RandomGenerator r) {
|
||||
public List<ItemStack> getItems(Random r) {
|
||||
|
||||
int rolls = r.nextInt(max - min + 1) + min;
|
||||
List<ItemStack> items = new ArrayList<>();
|
||||
|
||||
+3
-3
@@ -8,7 +8,7 @@
|
||||
package com.dfsek.terra.addons.structure.structures.loot.functions;
|
||||
|
||||
|
||||
import java.util.random.RandomGenerator;
|
||||
import java.util.Random;
|
||||
|
||||
import com.dfsek.terra.api.inventory.ItemStack;
|
||||
|
||||
@@ -35,12 +35,12 @@ public class AmountFunction implements LootFunction {
|
||||
* Applies the function to an ItemStack.
|
||||
*
|
||||
* @param original The ItemStack on which to apply the function.
|
||||
* @param r The RandomGenerator instance to use.
|
||||
* @param r The Random instance to use.
|
||||
*
|
||||
* @return - ItemStack - The mutated ItemStack.
|
||||
*/
|
||||
@Override
|
||||
public ItemStack apply(ItemStack original, RandomGenerator r) {
|
||||
public ItemStack apply(ItemStack original, Random r) {
|
||||
original.setAmount(r.nextInt(max - min + 1) + min);
|
||||
return original;
|
||||
}
|
||||
|
||||
+3
-3
@@ -7,7 +7,7 @@
|
||||
|
||||
package com.dfsek.terra.addons.structure.structures.loot.functions;
|
||||
|
||||
import java.util.random.RandomGenerator;
|
||||
import java.util.Random;
|
||||
|
||||
import com.dfsek.terra.api.inventory.ItemStack;
|
||||
import com.dfsek.terra.api.inventory.item.Damageable;
|
||||
@@ -36,12 +36,12 @@ public class DamageFunction implements LootFunction {
|
||||
* Applies the function to an ItemStack.
|
||||
*
|
||||
* @param original The ItemStack on which to apply the function.
|
||||
* @param r The RandomGenerator instance to use.
|
||||
* @param r The Random instance to use.
|
||||
*
|
||||
* @return - ItemStack - The mutated ItemStack.
|
||||
*/
|
||||
@Override
|
||||
public ItemStack apply(ItemStack original, RandomGenerator r) {
|
||||
public ItemStack apply(ItemStack original, Random r) {
|
||||
if(original == null) return null;
|
||||
if(!original.isDamageable()) return original;
|
||||
ItemMeta meta = original.getItemMeta();
|
||||
|
||||
+3
-3
@@ -14,7 +14,7 @@ import org.slf4j.LoggerFactory;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.random.RandomGenerator;
|
||||
import java.util.Random;
|
||||
|
||||
import com.dfsek.terra.api.Platform;
|
||||
import com.dfsek.terra.api.inventory.ItemStack;
|
||||
@@ -41,12 +41,12 @@ public class EnchantFunction implements LootFunction {
|
||||
* Applies the function to an ItemStack.
|
||||
*
|
||||
* @param original The ItemStack on which to apply the function.
|
||||
* @param r The RandomGenerator instance to use.
|
||||
* @param r The Random instance to use.
|
||||
*
|
||||
* @return - ItemStack - The mutated ItemStack.
|
||||
*/
|
||||
@Override
|
||||
public ItemStack apply(ItemStack original, RandomGenerator r) {
|
||||
public ItemStack apply(ItemStack original, Random r) {
|
||||
if(original.getItemMeta() == null) return original;
|
||||
|
||||
double enchant = (r.nextDouble() * (max - min)) + min;
|
||||
|
||||
+3
-3
@@ -8,7 +8,7 @@
|
||||
package com.dfsek.terra.addons.structure.structures.loot.functions;
|
||||
|
||||
|
||||
import java.util.random.RandomGenerator;
|
||||
import java.util.Random;
|
||||
|
||||
import com.dfsek.terra.api.inventory.ItemStack;
|
||||
|
||||
@@ -21,9 +21,9 @@ public interface LootFunction {
|
||||
* Applies the function to an ItemStack.
|
||||
*
|
||||
* @param original The ItemStack on which to apply the function.
|
||||
* @param r The RandomGenerator instance to use.
|
||||
* @param r The Random instance to use.
|
||||
*
|
||||
* @return - ItemStack - The mutated ItemStack.
|
||||
*/
|
||||
ItemStack apply(ItemStack original, RandomGenerator r);
|
||||
ItemStack apply(ItemStack original, Random r);
|
||||
}
|
||||
|
||||
+15
-7
@@ -8,11 +8,11 @@
|
||||
package com.dfsek.terra.addons.generation.feature;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.random.RandomGenerator;
|
||||
import java.util.random.RandomGeneratorFactory;
|
||||
import java.util.Random;
|
||||
|
||||
import com.dfsek.terra.addons.generation.feature.config.BiomeFeatures;
|
||||
import com.dfsek.terra.api.Platform;
|
||||
import com.dfsek.terra.api.noise.NoiseSampler;
|
||||
import com.dfsek.terra.api.properties.PropertyKey;
|
||||
import com.dfsek.terra.api.registry.key.StringIdentifiable;
|
||||
import com.dfsek.terra.api.util.Rotation;
|
||||
@@ -32,13 +32,20 @@ public class FeatureGenerationStage implements GenerationStage, StringIdentifiab
|
||||
|
||||
private final int resolution;
|
||||
private final PropertyKey<BiomeFeatures> biomeFeaturesKey;
|
||||
private final NoiseSampler blendSampler;
|
||||
private final boolean doBlending;
|
||||
private final double blendAmplitude;
|
||||
|
||||
public FeatureGenerationStage(Platform platform, String id, int resolution, PropertyKey<BiomeFeatures> biomeFeaturesKey) {
|
||||
public FeatureGenerationStage(Platform platform, String id, int resolution, PropertyKey<BiomeFeatures> biomeFeaturesKey,
|
||||
NoiseSampler blendSampler, double blendAmplitude) {
|
||||
this.platform = platform;
|
||||
this.id = id;
|
||||
this.profile = "feature_stage:" + id;
|
||||
this.resolution = resolution;
|
||||
this.biomeFeaturesKey = biomeFeaturesKey;
|
||||
this.blendSampler = blendSampler;
|
||||
this.doBlending = blendAmplitude != 0d;
|
||||
this.blendAmplitude = blendAmplitude;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -53,7 +60,10 @@ public class FeatureGenerationStage implements GenerationStage, StringIdentifiab
|
||||
int tx = cx + chunkX;
|
||||
int tz = cz + chunkZ;
|
||||
world.getBiomeProvider()
|
||||
.getColumn(tx, tz, world)
|
||||
.getColumn(
|
||||
tx + (doBlending ? (int) (blendSampler.noise(seed, tx, tz) * blendAmplitude) : 0),
|
||||
tz + (doBlending ? (int) (blendSampler.noise(seed+1, tx, tz) * blendAmplitude) : 0),
|
||||
world)
|
||||
.forRanges(resolution, (min, max, biome) -> {
|
||||
for(int subChunkX = 0; subChunkX < resolution; subChunkX++) {
|
||||
for(int subChunkZ = 0; subChunkZ < resolution; subChunkZ++) {
|
||||
@@ -73,9 +83,7 @@ public class FeatureGenerationStage implements GenerationStage, StringIdentifiab
|
||||
.forEach(y -> feature.getStructure(world, x, y, z)
|
||||
.generate(Vector3Int.of(x, y, z),
|
||||
world,
|
||||
RandomGeneratorFactory.<RandomGenerator.SplittableGenerator>of(
|
||||
"Xoroshiro128PlusPlus")
|
||||
.create(coordinateSeed * 31 + y),
|
||||
new Random(coordinateSeed * 31 + y),
|
||||
Rotation.NONE)
|
||||
);
|
||||
}
|
||||
|
||||
+20
-1
@@ -8,6 +8,7 @@ import com.dfsek.tectonic.api.exception.ValidationException;
|
||||
|
||||
import com.dfsek.terra.addons.generation.feature.FeatureGenerationStage;
|
||||
import com.dfsek.terra.api.Platform;
|
||||
import com.dfsek.terra.api.noise.NoiseSampler;
|
||||
import com.dfsek.terra.api.properties.PropertyKey;
|
||||
import com.dfsek.terra.api.world.chunk.generation.stage.GenerationStage;
|
||||
|
||||
@@ -22,6 +23,24 @@ public class FeatureStageTemplate implements ObjectTemplate<GenerationStage>, Va
|
||||
@Default
|
||||
private int resolution = 4;
|
||||
|
||||
@Value("blend.sampler")
|
||||
@Default
|
||||
private NoiseSampler blendSampler = new NoiseSampler() {
|
||||
@Override
|
||||
public double noise(long seed, double x, double y) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(long seed, double x, double y, double z) {
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
@Value("blend.amplitude")
|
||||
@Default
|
||||
private double blendAmplitude = 0d;
|
||||
|
||||
public FeatureStageTemplate(Platform platform, PropertyKey<BiomeFeatures> biomeFeaturesKey) {
|
||||
this.platform = platform;
|
||||
this.biomeFeaturesKey = biomeFeaturesKey;
|
||||
@@ -30,7 +49,7 @@ public class FeatureStageTemplate implements ObjectTemplate<GenerationStage>, Va
|
||||
|
||||
@Override
|
||||
public FeatureGenerationStage get() {
|
||||
return new FeatureGenerationStage(platform, id, resolution, biomeFeaturesKey);
|
||||
return new FeatureGenerationStage(platform, id, resolution, biomeFeaturesKey, blendSampler, blendAmplitude);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+4
-19
@@ -11,16 +11,12 @@ import com.dfsek.tectonic.yaml.YamlConfiguration;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
|
||||
import com.dfsek.terra.addons.manifest.api.AddonInitializer;
|
||||
import com.dfsek.terra.api.Platform;
|
||||
import com.dfsek.terra.api.addon.BaseAddon;
|
||||
import com.dfsek.terra.api.event.events.config.ConfigurationDiscoveryEvent;
|
||||
import com.dfsek.terra.api.event.functional.FunctionalEventHandler;
|
||||
import com.dfsek.terra.api.inject.annotations.Inject;
|
||||
import com.dfsek.terra.api.util.FileUtil;
|
||||
|
||||
|
||||
public class YamlAddon implements AddonInitializer {
|
||||
@@ -37,21 +33,10 @@ public class YamlAddon implements AddonInitializer {
|
||||
platform.getEventManager()
|
||||
.getHandler(FunctionalEventHandler.class)
|
||||
.register(addon, ConfigurationDiscoveryEvent.class)
|
||||
.then(event -> {
|
||||
try {
|
||||
FileUtil.filesWithExtension(event.getPack().getRootPath(), ".yml")
|
||||
.forEach((key, value) -> {
|
||||
LOGGER.debug("Discovered config {}", key);
|
||||
try {
|
||||
event.register(key, new YamlConfiguration(Files.newInputStream(value), key));
|
||||
} catch(IOException e) {
|
||||
throw new RuntimeException("Failed to load config " + key, e);
|
||||
}
|
||||
});
|
||||
} catch(IOException e) {
|
||||
throw new RuntimeException("Error occurred while reading config pack files", e);
|
||||
}
|
||||
})
|
||||
.then(event -> event.getLoader().open("", ".yml").thenEntries(entries -> entries.forEach(entry -> {
|
||||
LOGGER.debug("Discovered config {}", entry.getKey());
|
||||
event.register(entry.getKey(), new YamlConfiguration(entry.getValue(), entry.getKey()));
|
||||
})).close())
|
||||
.failThrough();
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -60,8 +60,8 @@ public class ImageLibraryAddon implements AddonInitializer {
|
||||
.then(event -> {
|
||||
ConfigPack pack = event.getPack();
|
||||
CheckedRegistry<Supplier<ObjectTemplate<Image>>> imageRegistry = pack.getOrCreateRegistry(IMAGE_REGISTRY_KEY);
|
||||
imageRegistry.register(addon.key("BITMAP"), () -> new ImageTemplate(pack));
|
||||
imageRegistry.register(addon.key("STITCHED_BITMAP"), () -> new StitchedImageTemplate(pack));
|
||||
imageRegistry.register(addon.key("BITMAP"), () -> new ImageTemplate(pack.getLoader(), pack));
|
||||
imageRegistry.register(addon.key("STITCHED_BITMAP"), () -> new StitchedImageTemplate(pack.getLoader(), pack));
|
||||
})
|
||||
.then(event -> {
|
||||
event.getPack()
|
||||
|
||||
+16
-8
@@ -4,10 +4,8 @@ import com.github.benmanes.caffeine.cache.Caffeine;
|
||||
import com.github.benmanes.caffeine.cache.LoadingCache;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import com.dfsek.terra.addons.image.config.ImageLibraryPackConfigTemplate;
|
||||
@@ -15,6 +13,7 @@ import com.dfsek.terra.addons.image.image.BufferedImageWrapper;
|
||||
import com.dfsek.terra.addons.image.image.Image;
|
||||
import com.dfsek.terra.addons.image.image.SuppliedImage;
|
||||
import com.dfsek.terra.api.config.ConfigPack;
|
||||
import com.dfsek.terra.api.config.Loader;
|
||||
import com.dfsek.terra.api.properties.Properties;
|
||||
import com.dfsek.terra.api.util.generic.Lazy;
|
||||
|
||||
@@ -23,13 +22,13 @@ import com.dfsek.terra.api.util.generic.Lazy;
|
||||
* Cache prevents configs from loading the same image multiple times into memory
|
||||
*/
|
||||
record ImageCache(LoadingCache<String, Image> cache) implements Properties {
|
||||
public static Image load(String path, ConfigPack pack) throws IOException {
|
||||
public static Image load(String path, ConfigPack pack, Loader files) throws IOException {
|
||||
ImageLibraryPackConfigTemplate config = pack.getContext().get(ImageLibraryPackConfigTemplate.class);
|
||||
ImageCache images;
|
||||
if(!pack.getContext().has(ImageCache.class)) {
|
||||
var cacheBuilder = Caffeine.newBuilder();
|
||||
if(config.unloadOnTimeout()) cacheBuilder.expireAfterAccess(config.getCacheTimeout(), TimeUnit.SECONDS);
|
||||
images = new ImageCache(cacheBuilder.build(s -> loadImage(s, pack.getRootPath())));
|
||||
images = new ImageCache(cacheBuilder.build(s -> loadImage(s, files)));
|
||||
pack.getContext().put(images);
|
||||
} else images = pack.getContext().get(ImageCache.class);
|
||||
|
||||
@@ -46,8 +45,17 @@ record ImageCache(LoadingCache<String, Image> cache) implements Properties {
|
||||
return images.cache.get(path);
|
||||
}
|
||||
|
||||
private static Image loadImage(String path, Path directory) throws IOException {
|
||||
InputStream is = Files.newInputStream(directory.resolve(path));
|
||||
return new BufferedImageWrapper(ImageIO.read(is));
|
||||
private static Image loadImage(String path, Loader files) throws IOException {
|
||||
try {
|
||||
return new BufferedImageWrapper(ImageIO.read(files.get(path)));
|
||||
} catch(IllegalArgumentException e) {
|
||||
throw new IllegalArgumentException("Unable to load image (image might be too large?)", e);
|
||||
} catch(IOException e) {
|
||||
if(e instanceof FileNotFoundException) {
|
||||
// Rethrow using nicer message
|
||||
throw new IOException("Unable to load image: No such file or directory: " + path, e);
|
||||
}
|
||||
throw new IOException("Unable to load image", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+5
-2
@@ -7,22 +7,25 @@ import java.io.IOException;
|
||||
|
||||
import com.dfsek.terra.addons.image.image.Image;
|
||||
import com.dfsek.terra.api.config.ConfigPack;
|
||||
import com.dfsek.terra.api.config.Loader;
|
||||
|
||||
|
||||
public class ImageTemplate implements ObjectTemplate<Image> {
|
||||
|
||||
private final Loader files;
|
||||
private final ConfigPack pack;
|
||||
@Value("path")
|
||||
private String path;
|
||||
|
||||
public ImageTemplate(ConfigPack pack) {
|
||||
public ImageTemplate(Loader files, ConfigPack pack) {
|
||||
this.files = files;
|
||||
this.pack = pack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Image get() {
|
||||
try {
|
||||
return ImageCache.load(path, pack);
|
||||
return ImageCache.load(path, pack, files);
|
||||
} catch(IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
+5
-2
@@ -11,10 +11,12 @@ import java.io.IOException;
|
||||
import com.dfsek.terra.addons.image.image.Image;
|
||||
import com.dfsek.terra.addons.image.image.StitchedImage;
|
||||
import com.dfsek.terra.api.config.ConfigPack;
|
||||
import com.dfsek.terra.api.config.Loader;
|
||||
|
||||
|
||||
public class StitchedImageTemplate implements ObjectTemplate<Image>, ValidatedConfigTemplate {
|
||||
|
||||
private final Loader files;
|
||||
private final ConfigPack pack;
|
||||
@Value("path-format")
|
||||
private String path;
|
||||
@@ -26,7 +28,8 @@ public class StitchedImageTemplate implements ObjectTemplate<Image>, ValidatedCo
|
||||
@Default
|
||||
private boolean zeroIndexed = false;
|
||||
|
||||
public StitchedImageTemplate(ConfigPack pack) {
|
||||
public StitchedImageTemplate(Loader files, ConfigPack pack) {
|
||||
this.files = files;
|
||||
this.pack = pack;
|
||||
}
|
||||
|
||||
@@ -36,7 +39,7 @@ public class StitchedImageTemplate implements ObjectTemplate<Image>, ValidatedCo
|
||||
for(int i = 0; i < rows; i++) {
|
||||
for(int j = 0; j < cols; j++) {
|
||||
try {
|
||||
grid[i][j] = ImageCache.load(getFormattedPath(i, j), pack);
|
||||
grid[i][j] = ImageCache.load(getFormattedPath(i, j), pack, files);
|
||||
} catch(IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
package com.dfsek.terra.addons.palette.shortcut.block;
|
||||
|
||||
import java.util.random.RandomGenerator;
|
||||
import java.util.Random;
|
||||
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.api.structure.Structure;
|
||||
@@ -17,7 +17,7 @@ public class SingletonStructure implements Structure {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean generate(Vector3Int location, WritableWorld world, RandomGenerator random, Rotation rotation) {
|
||||
public boolean generate(Vector3Int location, WritableWorld world, Random random, Rotation rotation) {
|
||||
world.setBlockState(location, blockState);
|
||||
return true;
|
||||
}
|
||||
|
||||
+3
-3
@@ -1,5 +1,7 @@
|
||||
package com.dfsek.terra.addons.structure.mutator;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import com.dfsek.terra.api.registry.key.Keyed;
|
||||
import com.dfsek.terra.api.registry.key.RegistryKey;
|
||||
import com.dfsek.terra.api.structure.Structure;
|
||||
@@ -9,8 +11,6 @@ import com.dfsek.terra.api.world.WritableWorld;
|
||||
import com.dfsek.terra.api.world.util.ReadInterceptor;
|
||||
import com.dfsek.terra.api.world.util.WriteInterceptor;
|
||||
|
||||
import java.util.random.RandomGenerator;
|
||||
|
||||
|
||||
public class MutatedStructure implements Structure, Keyed<MutatedStructure> {
|
||||
private final RegistryKey key;
|
||||
@@ -32,7 +32,7 @@ public class MutatedStructure implements Structure, Keyed<MutatedStructure> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean generate(Vector3Int location, WritableWorld world, RandomGenerator random, Rotation rotation) {
|
||||
public boolean generate(Vector3Int location, WritableWorld world, Random random, Rotation rotation) {
|
||||
return base.generate(location,
|
||||
world
|
||||
.buffer()
|
||||
|
||||
+7
-16
@@ -16,7 +16,6 @@ import net.querz.nbt.tag.Tag;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.PushbackInputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
@@ -30,7 +29,7 @@ import com.dfsek.terra.api.event.functional.FunctionalEventHandler;
|
||||
import com.dfsek.terra.api.inject.annotations.Inject;
|
||||
import com.dfsek.terra.api.registry.CheckedRegistry;
|
||||
import com.dfsek.terra.api.structure.Structure;
|
||||
import com.dfsek.terra.api.util.FileUtil;
|
||||
import com.dfsek.terra.api.util.StringUtil;
|
||||
import com.dfsek.terra.api.util.vector.Vector3Int;
|
||||
|
||||
|
||||
@@ -59,21 +58,13 @@ public class SpongeSchematicAddon implements AddonInitializer {
|
||||
.register(addon, ConfigPackPreLoadEvent.class)
|
||||
.then(event -> {
|
||||
CheckedRegistry<Structure> structureRegistry = event.getPack().getOrCreateRegistry(Structure.class);
|
||||
try {
|
||||
FileUtil.filesWithExtension(event.getPack().getRootPath(), ".schem")
|
||||
.entrySet()
|
||||
event.getPack()
|
||||
.getLoader()
|
||||
.open("", ".schem")
|
||||
.thenEntries(entries -> entries
|
||||
.stream()
|
||||
.map(entry -> {
|
||||
try {
|
||||
return convert(Files.newInputStream(entry.getValue()), FileUtil.fileName(entry.getKey()));
|
||||
} catch(IOException e) {
|
||||
throw new RuntimeException("Failed to load config " + entry.getKey(), e);
|
||||
}
|
||||
})
|
||||
.forEach(structureRegistry::register);
|
||||
} catch(IOException e) {
|
||||
throw new RuntimeException("Error occurred while reading config pack files", e);
|
||||
}
|
||||
.map(entry -> convert(entry.getValue(), StringUtil.fileName(entry.getKey())))
|
||||
.forEach(structureRegistry::register)).close();
|
||||
})
|
||||
.failThrough();
|
||||
}
|
||||
|
||||
+2
-2
@@ -7,7 +7,7 @@
|
||||
|
||||
package com.dfsek.terra.addons.sponge;
|
||||
|
||||
import java.util.random.RandomGenerator;
|
||||
import java.util.Random;
|
||||
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.api.registry.key.Keyed;
|
||||
@@ -36,7 +36,7 @@ public class SpongeStructure implements Structure, Keyed<SpongeStructure> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean generate(Vector3Int location, WritableWorld world, RandomGenerator random, Rotation rotation) {
|
||||
public boolean generate(Vector3Int location, WritableWorld world, Random random, Rotation rotation) {
|
||||
int bX = location.getX();
|
||||
int bY = location.getY();
|
||||
int bZ = location.getZ();
|
||||
|
||||
+21
-26
@@ -7,9 +7,6 @@
|
||||
|
||||
package com.dfsek.terra.addons.terrascript;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
|
||||
import com.dfsek.terra.addons.manifest.api.AddonInitializer;
|
||||
import com.dfsek.terra.addons.terrascript.parser.exceptions.ParseException;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.functions.FunctionBuilder;
|
||||
@@ -22,7 +19,7 @@ import com.dfsek.terra.api.inject.annotations.Inject;
|
||||
import com.dfsek.terra.api.registry.CheckedRegistry;
|
||||
import com.dfsek.terra.api.structure.LootTable;
|
||||
import com.dfsek.terra.api.structure.Structure;
|
||||
import com.dfsek.terra.api.util.FileUtil;
|
||||
import com.dfsek.terra.api.util.StringUtil;
|
||||
|
||||
|
||||
public class TerraScriptAddon implements AddonInitializer {
|
||||
@@ -40,28 +37,26 @@ public class TerraScriptAddon implements AddonInitializer {
|
||||
.then(event -> {
|
||||
CheckedRegistry<Structure> structureRegistry = event.getPack().getOrCreateRegistry(Structure.class);
|
||||
CheckedRegistry<LootTable> lootRegistry = event.getPack().getOrCreateRegistry(LootTable.class);
|
||||
try {
|
||||
FileUtil.filesWithExtension(event.getPack().getRootPath(), ".tesf")
|
||||
.entrySet()
|
||||
.stream()
|
||||
.parallel()
|
||||
.map(entry -> {
|
||||
try {
|
||||
String id = FileUtil.fileName(entry.getKey());
|
||||
return new StructureScript(Files.newInputStream(entry.getValue()),
|
||||
addon.key(id),
|
||||
platform,
|
||||
structureRegistry,
|
||||
lootRegistry,
|
||||
event.getPack().getOrCreateRegistry(FunctionBuilder.class));
|
||||
} catch(ParseException | IOException e) {
|
||||
throw new RuntimeException("Failed to load script \"" + entry.getKey() + "\"", e);
|
||||
}
|
||||
})
|
||||
.forEach(structureRegistry::register);
|
||||
} catch(IOException e) {
|
||||
throw new RuntimeException("Error occurred while reading config pack files", e);
|
||||
}
|
||||
event.getPack().getLoader().open("", ".tesf").thenEntries(
|
||||
entries ->
|
||||
entries.stream()
|
||||
.parallel()
|
||||
.map(entry -> {
|
||||
try {
|
||||
String id = StringUtil.fileName(entry.getKey());
|
||||
return new StructureScript(entry.getValue(),
|
||||
addon.key(id),
|
||||
platform,
|
||||
structureRegistry,
|
||||
lootRegistry,
|
||||
event.getPack().getOrCreateRegistry(FunctionBuilder.class));
|
||||
} catch(ParseException e) {
|
||||
throw new RuntimeException("Failed to load script \"" + entry.getKey() + "\"", e);
|
||||
}
|
||||
})
|
||||
.toList()
|
||||
.forEach(structureRegistry::register))
|
||||
.close();
|
||||
})
|
||||
.priority(100)
|
||||
.failThrough();
|
||||
|
||||
+3
-3
@@ -14,7 +14,7 @@ import org.slf4j.LoggerFactory;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.random.RandomGenerator;
|
||||
import java.util.Random;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.parser.Parser;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Executable;
|
||||
@@ -131,14 +131,14 @@ public class StructureScript implements Structure, Keyed<StructureScript> {
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("try")
|
||||
public boolean generate(Vector3Int location, WritableWorld world, RandomGenerator random, Rotation rotation) {
|
||||
public boolean generate(Vector3Int location, WritableWorld world, Random random, Rotation rotation) {
|
||||
platform.getProfiler().push(profile);
|
||||
boolean result = applyBlock(new TerraImplementationArguments(location, rotation, random, world, 0));
|
||||
platform.getProfiler().pop(profile);
|
||||
return result;
|
||||
}
|
||||
|
||||
public boolean generate(Vector3Int location, WritableWorld world, RandomGenerator random, Rotation rotation, int recursions) {
|
||||
public boolean generate(Vector3Int location, WritableWorld world, Random random, Rotation rotation, int recursions) {
|
||||
platform.getProfiler().push(profile);
|
||||
boolean result = applyBlock(new TerraImplementationArguments(location, rotation, random, world, recursions));
|
||||
platform.getProfiler().pop(profile);
|
||||
|
||||
+4
-4
@@ -9,7 +9,7 @@ package com.dfsek.terra.addons.terrascript.script;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.random.RandomGenerator;
|
||||
import java.util.Random;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.api.util.Rotation;
|
||||
@@ -20,14 +20,14 @@ import com.dfsek.terra.api.world.WritableWorld;
|
||||
|
||||
public class TerraImplementationArguments implements ImplementationArguments {
|
||||
private final Rotation rotation;
|
||||
private final RandomGenerator random;
|
||||
private final Random random;
|
||||
private final WritableWorld world;
|
||||
private final Map<Vector3, String> marks = new HashMap<>();
|
||||
private final int recursions;
|
||||
private final Vector3Int origin;
|
||||
private boolean waterlog = false;
|
||||
|
||||
public TerraImplementationArguments(Vector3Int origin, Rotation rotation, RandomGenerator random, WritableWorld world, int recursions) {
|
||||
public TerraImplementationArguments(Vector3Int origin, Rotation rotation, Random random, WritableWorld world, int recursions) {
|
||||
this.rotation = rotation;
|
||||
this.random = random;
|
||||
this.world = world;
|
||||
@@ -39,7 +39,7 @@ public class TerraImplementationArguments implements ImplementationArguments {
|
||||
return recursions;
|
||||
}
|
||||
|
||||
public RandomGenerator getRandom() {
|
||||
public Random getRandom() {
|
||||
return random;
|
||||
}
|
||||
|
||||
|
||||
+2
-4
@@ -10,8 +10,7 @@ package com.dfsek.terra.addons.terrascript.script.functions;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.random.RandomGenerator;
|
||||
import java.util.random.RandomGeneratorFactory;
|
||||
import java.util.Random;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Returnable;
|
||||
@@ -85,8 +84,7 @@ public class LootFunction implements Function<Void> {
|
||||
if(event.isCancelled()) return;
|
||||
|
||||
event.getTable().fillInventory(container.getInventory(),
|
||||
RandomGeneratorFactory.<RandomGenerator.SplittableGenerator>of(
|
||||
"Xoroshiro128PlusPlus").create(apply.hashCode()));
|
||||
new Random(apply.hashCode()));
|
||||
data.update(false);
|
||||
} catch(Exception e) {
|
||||
LOGGER.error("Could not apply loot at {}", apply, e);
|
||||
|
||||
@@ -14,7 +14,6 @@ import java.io.File;
|
||||
|
||||
import com.dfsek.terra.api.addon.BaseAddon;
|
||||
import com.dfsek.terra.api.config.ConfigPack;
|
||||
import com.dfsek.terra.api.config.MetaPack;
|
||||
import com.dfsek.terra.api.config.PluginConfig;
|
||||
import com.dfsek.terra.api.event.EventManager;
|
||||
import com.dfsek.terra.api.handle.ItemHandle;
|
||||
@@ -62,10 +61,6 @@ public interface Platform extends LoaderRegistrar {
|
||||
@Contract(pure = true)
|
||||
CheckedRegistry<ConfigPack> getConfigRegistry();
|
||||
|
||||
@NotNull
|
||||
@Contract(pure = true)
|
||||
CheckedRegistry<MetaPack> getMetaConfigRegistry();
|
||||
|
||||
@NotNull
|
||||
@Contract(pure = true)
|
||||
Registry<BaseAddon> getAddons();
|
||||
|
||||
@@ -10,7 +10,6 @@ package com.dfsek.terra.api.config;
|
||||
import ca.solostudios.strata.version.Version;
|
||||
import ca.solostudios.strata.version.VersionRange;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -44,7 +43,7 @@ public interface ConfigPack extends LoaderRegistrar,
|
||||
|
||||
List<GenerationStage> getStages();
|
||||
|
||||
Path getRootPath();
|
||||
Loader getLoader();
|
||||
|
||||
String getAuthor();
|
||||
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2023 Polyhedral Development
|
||||
*
|
||||
* The Terra API is licensed under the terms of the MIT License. For more details,
|
||||
* reference the LICENSE file in the common/api directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.api.config;
|
||||
|
||||
import com.dfsek.tectonic.api.exception.ConfigException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
|
||||
public interface Loader {
|
||||
|
||||
Loader thenNames(Consumer<List<String>> consumer) throws ConfigException;
|
||||
|
||||
Loader thenEntries(Consumer<Set<Map.Entry<String, InputStream>>> consumer) throws ConfigException;
|
||||
|
||||
/**
|
||||
* Get a single file from this Loader.
|
||||
*
|
||||
* @param singleFile File to get
|
||||
*
|
||||
* @return InputStream from file.
|
||||
*/
|
||||
InputStream get(String singleFile) throws IOException;
|
||||
|
||||
/**
|
||||
* Open a subdirectory.
|
||||
*
|
||||
* @param directory Directory to open
|
||||
* @param extension File extension
|
||||
*/
|
||||
Loader open(String directory, String extension);
|
||||
|
||||
/**
|
||||
* Close all InputStreams opened.
|
||||
*/
|
||||
Loader close();
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
package com.dfsek.terra.api.config;
|
||||
|
||||
import ca.solostudios.strata.version.Version;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import com.dfsek.terra.api.properties.PropertyHolder;
|
||||
import com.dfsek.terra.api.registry.key.Keyed;
|
||||
import com.dfsek.terra.api.registry.meta.CheckedRegistryHolder;
|
||||
import com.dfsek.terra.api.registry.meta.RegistryProvider;
|
||||
import com.dfsek.terra.api.tectonic.ConfigLoadingDelegate;
|
||||
import com.dfsek.terra.api.tectonic.LoaderRegistrar;
|
||||
|
||||
|
||||
public interface MetaPack extends LoaderRegistrar,
|
||||
ConfigLoadingDelegate,
|
||||
CheckedRegistryHolder,
|
||||
RegistryProvider,
|
||||
Keyed<MetaPack>,
|
||||
PropertyHolder {
|
||||
|
||||
Map<String, ConfigPack> packs();
|
||||
|
||||
String getAuthor();
|
||||
|
||||
Version getVersion();
|
||||
}
|
||||
+8
-1
@@ -12,6 +12,7 @@ import com.dfsek.tectonic.api.config.Configuration;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
import com.dfsek.terra.api.config.ConfigPack;
|
||||
import com.dfsek.terra.api.config.Loader;
|
||||
import com.dfsek.terra.api.event.events.FailThroughEvent;
|
||||
import com.dfsek.terra.api.event.events.PackEvent;
|
||||
|
||||
@@ -24,11 +25,13 @@ import com.dfsek.terra.api.event.events.PackEvent;
|
||||
*/
|
||||
public class ConfigurationDiscoveryEvent implements PackEvent, FailThroughEvent {
|
||||
private final ConfigPack pack;
|
||||
private final Loader loader;
|
||||
|
||||
private final BiConsumer<String, Configuration> consumer;
|
||||
|
||||
public ConfigurationDiscoveryEvent(ConfigPack pack, BiConsumer<String, Configuration> consumer) {
|
||||
public ConfigurationDiscoveryEvent(ConfigPack pack, Loader loader, BiConsumer<String, Configuration> consumer) {
|
||||
this.pack = pack;
|
||||
this.loader = loader;
|
||||
this.consumer = consumer;
|
||||
}
|
||||
|
||||
@@ -40,4 +43,8 @@ public class ConfigurationDiscoveryEvent implements PackEvent, FailThroughEvent
|
||||
public ConfigPack getPack() {
|
||||
return pack;
|
||||
}
|
||||
|
||||
public Loader getLoader() {
|
||||
return loader;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ package com.dfsek.terra.api.structure;
|
||||
import org.jetbrains.annotations.ApiStatus.Experimental;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.random.RandomGenerator;
|
||||
import java.util.Random;
|
||||
|
||||
import com.dfsek.terra.api.inventory.Inventory;
|
||||
import com.dfsek.terra.api.inventory.ItemStack;
|
||||
@@ -22,16 +22,16 @@ public interface LootTable {
|
||||
* Fills an Inventory with loot.
|
||||
*
|
||||
* @param i The Inventory to fill.
|
||||
* @param r The The RandomGenerator instance to use.
|
||||
* @param r The The Random instance to use.
|
||||
*/
|
||||
void fillInventory(Inventory i, RandomGenerator r);
|
||||
void fillInventory(Inventory i, Random r);
|
||||
|
||||
/**
|
||||
* Fetches a list of ItemStacks from the loot table using the given RandomGenerator instance.
|
||||
* Fetches a list of ItemStacks from the loot table using the given Random instance.
|
||||
*
|
||||
* @param r The RandomGenerator instance to use.
|
||||
* @param r The Random instance to use.
|
||||
*
|
||||
* @return List<ItemStack> - The list of loot fetched.
|
||||
*/
|
||||
List<ItemStack> getLoot(RandomGenerator r);
|
||||
List<ItemStack> getLoot(Random r);
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
package com.dfsek.terra.api.structure;
|
||||
|
||||
import java.util.random.RandomGenerator;
|
||||
import java.util.Random;
|
||||
|
||||
import com.dfsek.terra.api.util.Rotation;
|
||||
import com.dfsek.terra.api.util.vector.Vector3Int;
|
||||
@@ -15,5 +15,5 @@ import com.dfsek.terra.api.world.WritableWorld;
|
||||
|
||||
|
||||
public interface Structure {
|
||||
boolean generate(Vector3Int location, WritableWorld world, RandomGenerator random, Rotation rotation);
|
||||
boolean generate(Vector3Int location, WritableWorld world, Random random, Rotation rotation);
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ package com.dfsek.terra.api.util;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.random.RandomGenerator;
|
||||
import java.util.Random;
|
||||
|
||||
|
||||
public class ConstantRange implements Range {
|
||||
@@ -36,7 +36,7 @@ public class ConstantRange implements Range {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int get(RandomGenerator r) {
|
||||
public int get(Random r) {
|
||||
return r.nextInt(min, max);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
package com.dfsek.terra.api.util;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static java.util.function.Function.identity;
|
||||
|
||||
|
||||
public class FileUtil {
|
||||
public static Map<String, Path> filesWithExtension(Path start, String... extensions) throws IOException {
|
||||
if(Files.notExists(start) || !Files.isDirectory(start)) return Collections.emptyMap();
|
||||
try(Stream<Path> paths = Files.walk(start)) {
|
||||
return paths
|
||||
.filter(Files::isRegularFile)
|
||||
.filter(p -> Arrays.stream(extensions).anyMatch(e -> p.getFileName().toString().endsWith(e)))
|
||||
.collect(Collectors.toMap(p -> start.relativize(p).toString(), identity()));
|
||||
}
|
||||
}
|
||||
|
||||
public static String fileName(String path) {
|
||||
if(path.contains(File.separator)) {
|
||||
return path.substring(path.lastIndexOf(File.separatorChar) + 1, path.lastIndexOf('.'));
|
||||
} else if(path.contains("/")) {
|
||||
return path.substring(path.lastIndexOf("/") + 1, path.lastIndexOf('.'));
|
||||
} else if(path.contains(".")) {
|
||||
return path.substring(0, path.lastIndexOf('.'));
|
||||
} else {
|
||||
return path;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,20 +7,18 @@
|
||||
|
||||
package com.dfsek.terra.api.util;
|
||||
|
||||
import java.util.random.RandomGenerator;
|
||||
import java.util.random.RandomGeneratorFactory;
|
||||
import java.util.Random;
|
||||
|
||||
import com.dfsek.terra.api.world.chunk.Chunk;
|
||||
|
||||
|
||||
public final class PopulationUtil {
|
||||
public static RandomGenerator getRandom(Chunk c) {
|
||||
public static Random getRandom(Chunk c) {
|
||||
return getRandom(c, 0);
|
||||
}
|
||||
|
||||
public static RandomGenerator getRandom(Chunk c, long salt) {
|
||||
return RandomGeneratorFactory.<RandomGenerator.SplittableGenerator>of("Xoroshiro128PlusPlus").create(
|
||||
getCarverChunkSeed(c.getX(), c.getZ(), c.getWorld().getSeed() + salt));
|
||||
public static Random getRandom(Chunk c, long salt) {
|
||||
return new Random(getCarverChunkSeed(c.getX(), c.getZ(), c.getWorld().getSeed() + salt));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -33,7 +31,7 @@ public final class PopulationUtil {
|
||||
* @return long - The carver seed.
|
||||
*/
|
||||
public static long getCarverChunkSeed(int chunkX, int chunkZ, long seed) {
|
||||
RandomGenerator r = RandomGeneratorFactory.<RandomGenerator.SplittableGenerator>of("Xoroshiro128PlusPlus").create(seed);
|
||||
Random r = new Random(seed);
|
||||
return chunkX * r.nextLong() ^ chunkZ * r.nextLong() ^ seed;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,8 +10,8 @@ package com.dfsek.terra.api.util;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Random;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.random.RandomGenerator;
|
||||
|
||||
|
||||
public interface Range extends Iterable<Integer> {
|
||||
@@ -19,7 +19,7 @@ public interface Range extends Iterable<Integer> {
|
||||
|
||||
Range reflect(int pt);
|
||||
|
||||
int get(RandomGenerator r);
|
||||
int get(Random r);
|
||||
|
||||
Range intersects(Range other);
|
||||
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2023 Polyhedral Development
|
||||
*
|
||||
* The Terra API is licensed under the terms of the MIT License. For more details,
|
||||
* reference the LICENSE file in the common/api directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.api.util;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
|
||||
public class StringUtil {
|
||||
public static String fileName(String path) {
|
||||
if(path.contains(File.separator)) {
|
||||
return path.substring(path.lastIndexOf(File.separatorChar) + 1, path.lastIndexOf('.'));
|
||||
} else if(path.contains("/")) {
|
||||
return path.substring(path.lastIndexOf("/") + 1, path.lastIndexOf('.'));
|
||||
} else if(path.contains(".")) {
|
||||
return path.substring(0, path.lastIndexOf('.'));
|
||||
} else {
|
||||
return path;
|
||||
}
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -15,9 +15,9 @@ import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
import java.util.random.RandomGenerator;
|
||||
|
||||
import com.dfsek.terra.api.noise.NoiseSampler;
|
||||
import com.dfsek.terra.api.util.MathUtil;
|
||||
@@ -43,7 +43,7 @@ public class ProbabilityCollection<E> implements Collection<E> {
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public E get(RandomGenerator r) {
|
||||
public E get(Random r) {
|
||||
if(array.length == 0) return null;
|
||||
return (E) array[r.nextInt(array.length)];
|
||||
}
|
||||
@@ -197,7 +197,7 @@ public class ProbabilityCollection<E> implements Collection<E> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public T get(RandomGenerator r) {
|
||||
public T get(Random r) {
|
||||
return single;
|
||||
}
|
||||
|
||||
|
||||
@@ -51,7 +51,6 @@ import com.dfsek.terra.api.Platform;
|
||||
import com.dfsek.terra.api.addon.BaseAddon;
|
||||
import com.dfsek.terra.api.addon.bootstrap.BootstrapAddonClassLoader;
|
||||
import com.dfsek.terra.api.config.ConfigPack;
|
||||
import com.dfsek.terra.api.config.MetaPack;
|
||||
import com.dfsek.terra.api.config.PluginConfig;
|
||||
import com.dfsek.terra.api.event.EventManager;
|
||||
import com.dfsek.terra.api.event.events.platform.PlatformInitializationEvent;
|
||||
@@ -73,8 +72,6 @@ import com.dfsek.terra.registry.CheckedRegistryImpl;
|
||||
import com.dfsek.terra.registry.LockedRegistryImpl;
|
||||
import com.dfsek.terra.registry.OpenRegistryImpl;
|
||||
import com.dfsek.terra.registry.master.ConfigRegistry;
|
||||
import com.dfsek.terra.registry.master.ConfigRegistry.PackLoadFailuresException;
|
||||
import com.dfsek.terra.registry.master.MetaConfigRegistry;
|
||||
|
||||
|
||||
/**
|
||||
@@ -88,12 +85,9 @@ public abstract class AbstractPlatform implements Platform {
|
||||
private static final MutableBoolean LOADED = new MutableBoolean(false);
|
||||
private final EventManager eventManager = new EventManagerImpl();
|
||||
private final ConfigRegistry configRegistry = new ConfigRegistry();
|
||||
private final MetaConfigRegistry metaConfigRegistry = new MetaConfigRegistry();
|
||||
|
||||
private final CheckedRegistry<ConfigPack> checkedConfigRegistry = new CheckedRegistryImpl<>(configRegistry);
|
||||
|
||||
private final CheckedRegistry<MetaPack> checkedMetaConfigRegistry = new CheckedRegistryImpl<>(metaConfigRegistry);
|
||||
|
||||
private final Profiler profiler = new ProfilerImpl();
|
||||
|
||||
private final GenericLoaders loaders = new GenericLoaders(this);
|
||||
@@ -108,10 +102,6 @@ public abstract class AbstractPlatform implements Platform {
|
||||
return configRegistry;
|
||||
}
|
||||
|
||||
public MetaConfigRegistry getRawMetaConfigRegistry() {
|
||||
return metaConfigRegistry;
|
||||
}
|
||||
|
||||
protected Iterable<BaseAddon> platformAddon() {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
@@ -157,12 +147,11 @@ public abstract class AbstractPlatform implements Platform {
|
||||
|
||||
eventManager.getHandler(FunctionalEventHandler.class)
|
||||
.register(internalAddon, PlatformInitializationEvent.class)
|
||||
.then(event -> loadConfigPacks())
|
||||
.global();
|
||||
|
||||
eventManager.getHandler(FunctionalEventHandler.class)
|
||||
.register(internalAddon, PlatformInitializationEvent.class)
|
||||
.then(event -> loadMetaConfigPacks())
|
||||
.then(event -> {
|
||||
logger.info("Loading config packs...");
|
||||
configRegistry.loadAll(this);
|
||||
logger.info("Loaded packs.");
|
||||
})
|
||||
.global();
|
||||
|
||||
|
||||
@@ -170,38 +159,6 @@ public abstract class AbstractPlatform implements Platform {
|
||||
logger.info("Finished initialization.");
|
||||
}
|
||||
|
||||
protected boolean loadConfigPacks() {
|
||||
logger.info("Loading config packs...");
|
||||
ConfigRegistry configRegistry = getRawConfigRegistry();
|
||||
configRegistry.clear();
|
||||
try {
|
||||
configRegistry.loadAll(this);
|
||||
} catch(IOException e) {
|
||||
logger.error("Failed to load config packs", e);
|
||||
return false;
|
||||
} catch(PackLoadFailuresException e) {
|
||||
e.getExceptions().forEach(ex -> logger.error("Failed to load config pack", ex));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
protected boolean loadMetaConfigPacks() {
|
||||
logger.info("Loading meta config packs...");
|
||||
MetaConfigRegistry metaConfigRegistry = getRawMetaConfigRegistry();
|
||||
metaConfigRegistry.clear();
|
||||
try {
|
||||
metaConfigRegistry.loadAll(this, configRegistry);
|
||||
} catch(IOException e) {
|
||||
logger.error("Failed to load meta config packs", e);
|
||||
return false;
|
||||
} catch(PackLoadFailuresException e) {
|
||||
e.getExceptions().forEach(ex -> logger.error("Failed to meta load config pack", ex));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
protected InternalAddon loadAddons() {
|
||||
List<BaseAddon> addonList = new ArrayList<>();
|
||||
|
||||
@@ -368,12 +325,6 @@ public abstract class AbstractPlatform implements Platform {
|
||||
return checkedConfigRegistry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull CheckedRegistry<MetaPack> getMetaConfigRegistry() {
|
||||
return checkedMetaConfigRegistry;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public @NotNull Registry<BaseAddon> getAddons() {
|
||||
return lockedAddonRegistry;
|
||||
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* This file is part of Terra.
|
||||
*
|
||||
* Terra is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Terra is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.config.fileloaders;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
|
||||
/**
|
||||
* Load all {@code *.yml} files from a {@link java.nio.file.Path}.
|
||||
*/
|
||||
public class FolderLoader extends LoaderImpl {
|
||||
private static final Logger logger = LoggerFactory.getLogger(FolderLoader.class);
|
||||
|
||||
private final Path path;
|
||||
|
||||
public FolderLoader(Path path) {
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream get(String singleFile) throws IOException {
|
||||
return new FileInputStream(new File(path.toFile(), singleFile));
|
||||
}
|
||||
|
||||
protected void load(String directory, String extension) {
|
||||
File newPath = new File(path.toFile(), directory);
|
||||
newPath.mkdirs();
|
||||
try(Stream<Path> paths = Files.walk(newPath.toPath())) {
|
||||
paths.filter(Files::isRegularFile).filter(file -> file.toString().toLowerCase().endsWith(extension)).forEach(file -> {
|
||||
try {
|
||||
String rel = newPath.toPath().relativize(file).toString();
|
||||
streams.put(rel, new FileInputStream(file.toFile()));
|
||||
} catch(FileNotFoundException e) {
|
||||
logger.error("Could not find file to load", e);
|
||||
}
|
||||
});
|
||||
} catch(IOException e) {
|
||||
logger.error("Error while loading files", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
+83
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* This file is part of Terra.
|
||||
*
|
||||
* Terra is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Terra is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.config.fileloaders;
|
||||
|
||||
import com.dfsek.tectonic.api.exception.ConfigException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import com.dfsek.terra.api.config.Loader;
|
||||
|
||||
|
||||
public abstract class LoaderImpl implements Loader {
|
||||
private static final Logger logger = LoggerFactory.getLogger(LoaderImpl.class);
|
||||
|
||||
protected final Map<String, InputStream> streams = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public Loader thenNames(Consumer<List<String>> consumer) throws ConfigException {
|
||||
consumer.accept(new ArrayList<>(streams.keySet()));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Loader thenEntries(Consumer<Set<Map.Entry<String, InputStream>>> consumer) throws ConfigException {
|
||||
consumer.accept(streams.entrySet());
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Open a subdirectory.
|
||||
*
|
||||
* @param directory Directory to open
|
||||
* @param extension File extension
|
||||
*/
|
||||
@Override
|
||||
public LoaderImpl open(String directory, String extension) {
|
||||
if(!streams.isEmpty()) throw new IllegalStateException("Attempted to load new directory before closing existing InputStreams");
|
||||
load(directory, extension);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Close all InputStreams opened.
|
||||
*/
|
||||
@Override
|
||||
public Loader close() {
|
||||
streams.forEach((name, input) -> {
|
||||
try {
|
||||
input.close();
|
||||
} catch(IOException e) {
|
||||
logger.error("Error occurred while loading", e);
|
||||
}
|
||||
});
|
||||
streams.clear();
|
||||
return this;
|
||||
}
|
||||
|
||||
protected abstract void load(String directory, String extension);
|
||||
}
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* This file is part of Terra.
|
||||
*
|
||||
* Terra is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Terra is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.config.fileloaders;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Enumeration;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipFile;
|
||||
|
||||
|
||||
public class ZIPLoader extends LoaderImpl {
|
||||
private static final Logger logger = LoggerFactory.getLogger(ZIPLoader.class);
|
||||
|
||||
private final ZipFile file;
|
||||
|
||||
public ZIPLoader(ZipFile file) {
|
||||
this.file = file;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream get(String singleFile) throws IOException {
|
||||
Enumeration<? extends ZipEntry> entries = file.entries();
|
||||
while(entries.hasMoreElements()) {
|
||||
ZipEntry entry = entries.nextElement();
|
||||
if(!entry.isDirectory() && entry.getName().equals(singleFile)) return file.getInputStream(entry);
|
||||
}
|
||||
throw new IllegalArgumentException("No such file: " + singleFile);
|
||||
}
|
||||
|
||||
protected void load(String directory, String extension) {
|
||||
Enumeration<? extends ZipEntry> entries = file.entries();
|
||||
while(entries.hasMoreElements()) {
|
||||
ZipEntry entry = entries.nextElement();
|
||||
if(!entry.isDirectory() && entry.getName().startsWith(directory) && entry.getName().endsWith(extension)) {
|
||||
try {
|
||||
String rel = entry.getName().substring(directory.length());
|
||||
streams.put(rel, file.getInputStream(entry));
|
||||
} catch(IOException e) {
|
||||
logger.error("Error while loading file from zip", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+5
-3
@@ -27,10 +27,10 @@ import javax.imageio.ImageIO;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.AnnotatedType;
|
||||
import java.nio.file.Files;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import com.dfsek.terra.api.config.ConfigPack;
|
||||
import com.dfsek.terra.api.config.Loader;
|
||||
import com.dfsek.terra.api.properties.Properties;
|
||||
|
||||
|
||||
@@ -39,10 +39,12 @@ import com.dfsek.terra.api.properties.Properties;
|
||||
*/
|
||||
@Deprecated
|
||||
public class BufferedImageLoader implements TypeLoader<BufferedImage> {
|
||||
private final Loader files;
|
||||
|
||||
private final ConfigPack pack;
|
||||
|
||||
public BufferedImageLoader(ConfigPack pack) {
|
||||
public BufferedImageLoader(Loader files, ConfigPack pack) {
|
||||
this.files = files;
|
||||
this.pack = pack;
|
||||
if(!pack.getContext().has(ImageCache.class))
|
||||
pack.getContext().put(new ImageCache(new ConcurrentHashMap<>()));
|
||||
@@ -53,7 +55,7 @@ public class BufferedImageLoader implements TypeLoader<BufferedImage> {
|
||||
throws LoadException {
|
||||
return pack.getContext().get(ImageCache.class).map.computeIfAbsent((String) c, s -> {
|
||||
try {
|
||||
return ImageIO.read(Files.newInputStream(pack.getRootPath().resolve(s)));
|
||||
return ImageIO.read(files.get(s));
|
||||
} catch(IOException e) {
|
||||
throw new LoadException("Unable to load image", e, depthTracker);
|
||||
}
|
||||
|
||||
+51
-31
@@ -33,15 +33,15 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.UncheckedIOException;
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.Type;
|
||||
import java.nio.file.FileSystem;
|
||||
import java.nio.file.FileSystems;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
@@ -51,12 +51,15 @@ import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipFile;
|
||||
|
||||
import com.dfsek.terra.api.Platform;
|
||||
import com.dfsek.terra.api.addon.BaseAddon;
|
||||
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.config.Loader;
|
||||
import com.dfsek.terra.api.config.meta.Meta;
|
||||
import com.dfsek.terra.api.event.events.config.ConfigurationDiscoveryEvent;
|
||||
import com.dfsek.terra.api.event.events.config.ConfigurationLoadEvent;
|
||||
@@ -69,12 +72,15 @@ import com.dfsek.terra.api.registry.OpenRegistry;
|
||||
import com.dfsek.terra.api.registry.Registry;
|
||||
import com.dfsek.terra.api.registry.key.RegistryKey;
|
||||
import com.dfsek.terra.api.tectonic.ShortcutLoader;
|
||||
import com.dfsek.terra.api.util.generic.Construct;
|
||||
import com.dfsek.terra.api.util.generic.pair.Pair;
|
||||
import com.dfsek.terra.api.util.reflection.ReflectionUtil;
|
||||
import com.dfsek.terra.api.util.reflection.TypeKey;
|
||||
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
|
||||
import com.dfsek.terra.api.world.chunk.generation.stage.GenerationStage;
|
||||
import com.dfsek.terra.api.world.chunk.generation.util.provider.ChunkGeneratorProvider;
|
||||
import com.dfsek.terra.config.fileloaders.FolderLoader;
|
||||
import com.dfsek.terra.config.fileloaders.ZIPLoader;
|
||||
import com.dfsek.terra.config.loaders.GenericTemplateSupplierLoader;
|
||||
import com.dfsek.terra.config.loaders.config.BufferedImageLoader;
|
||||
import com.dfsek.terra.config.preprocessor.MetaListLikePreprocessor;
|
||||
@@ -101,7 +107,7 @@ public class ConfigPackImpl implements ConfigPack {
|
||||
private final AbstractConfigLoader abstractConfigLoader = new AbstractConfigLoader();
|
||||
private final ConfigLoader selfLoader = new ConfigLoader();
|
||||
private final Platform platform;
|
||||
private final Path rootPath;
|
||||
private final Loader loader;
|
||||
|
||||
private final Map<BaseAddon, VersionRange> addons;
|
||||
|
||||
@@ -115,29 +121,40 @@ public class ConfigPackImpl implements ConfigPack {
|
||||
|
||||
private final RegistryKey key;
|
||||
|
||||
@SuppressWarnings({ "rawtypes" })
|
||||
public ConfigPackImpl(Path path, Platform platform) throws IOException {
|
||||
public ConfigPackImpl(File folder, Platform platform) {
|
||||
this(new FolderLoader(folder.toPath()), Construct.construct(() -> {
|
||||
try {
|
||||
return new YamlConfiguration(new FileInputStream(new File(folder, "pack.yml")), "pack.yml");
|
||||
} catch(FileNotFoundException e) {
|
||||
throw new UncheckedIOException("No pack.yml file found in " + folder.getAbsolutePath(), e);
|
||||
}
|
||||
}), platform);
|
||||
}
|
||||
|
||||
public ConfigPackImpl(ZipFile file, Platform platform) {
|
||||
this(new ZIPLoader(file), Construct.construct(() -> {
|
||||
ZipEntry pack = null;
|
||||
Enumeration<? extends ZipEntry> entries = file.entries();
|
||||
while(entries.hasMoreElements()) {
|
||||
ZipEntry entry = entries.nextElement();
|
||||
if(entry.getName().equals("pack.yml")) pack = entry;
|
||||
}
|
||||
|
||||
if(pack == null) throw new IllegalArgumentException("No pack.yml file found in " + file.getName());
|
||||
|
||||
try {
|
||||
return new YamlConfiguration(file.getInputStream(pack), "pack.yml");
|
||||
} catch(IOException e) {
|
||||
throw new UncheckedIOException("Unable to load pack.yml from ZIP file", e);
|
||||
}
|
||||
}), platform);
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
private ConfigPackImpl(Loader loader, Configuration packManifest, Platform platform) {
|
||||
long start = System.nanoTime();
|
||||
|
||||
if(Files.notExists(path)) throw new FileNotFoundException("Could not load config pack, " + path + " does not exist");
|
||||
|
||||
if(Files.isDirectory(path)) {
|
||||
this.rootPath = path;
|
||||
} else if(Files.isRegularFile(path)) {
|
||||
if(!path.getFileName().toString().endsWith(".zip")) {
|
||||
throw new IOException("Could not load config pack, file " + path + " is not a zip");
|
||||
}
|
||||
FileSystem zipfs = FileSystems.newFileSystem(path);
|
||||
this.rootPath = zipfs.getPath("/");
|
||||
} else {
|
||||
throw new IOException("Could not load config pack from " + path);
|
||||
}
|
||||
|
||||
Path packManifestPath = rootPath.resolve("pack.yml");
|
||||
if(Files.notExists(packManifestPath)) throw new IOException("No pack.yml found in " + path);
|
||||
Configuration packManifest = new YamlConfiguration(Files.newInputStream(packManifestPath),
|
||||
packManifestPath.getFileName().toString());
|
||||
|
||||
this.loader = loader;
|
||||
this.platform = platform;
|
||||
this.configTypeRegistry = createConfigRegistry();
|
||||
|
||||
@@ -221,7 +238,7 @@ public class ConfigPackImpl implements ConfigPack {
|
||||
|
||||
private Map<String, Configuration> discoverConfigurations() {
|
||||
Map<String, Configuration> configurations = new HashMap<>();
|
||||
platform.getEventManager().callEvent(new ConfigurationDiscoveryEvent(this,
|
||||
platform.getEventManager().callEvent(new ConfigurationDiscoveryEvent(this, loader,
|
||||
(s, c) -> configurations.put(s.replace("\\", "/"),
|
||||
c))); // Create all the configs.
|
||||
return configurations;
|
||||
@@ -266,7 +283,7 @@ public class ConfigPackImpl implements ConfigPack {
|
||||
@Override
|
||||
public void register(TypeRegistry registry) {
|
||||
registry.registerLoader(ConfigType.class, configTypeRegistry)
|
||||
.registerLoader(BufferedImage.class, new BufferedImageLoader(this));
|
||||
.registerLoader(BufferedImage.class, new BufferedImageLoader(loader, this));
|
||||
registryMap.forEach(registry::registerLoader);
|
||||
shortcuts.forEach(registry::registerLoader); // overwrite with delegated shortcuts if present
|
||||
}
|
||||
@@ -292,6 +309,7 @@ public class ConfigPackImpl implements ConfigPack {
|
||||
return seededBiomeProvider;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public <T> CheckedRegistry<T> getOrCreateRegistry(TypeKey<T> typeKey) {
|
||||
return (CheckedRegistry<T>) registryMap.computeIfAbsent(typeKey.getType(), c -> {
|
||||
@@ -330,8 +348,8 @@ public class ConfigPackImpl implements ConfigPack {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Path getRootPath() {
|
||||
return rootPath;
|
||||
public Loader getLoader() {
|
||||
return loader;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -344,7 +362,7 @@ public class ConfigPackImpl implements ConfigPack {
|
||||
return template.getVersion();
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
@SuppressWarnings("unchecked,rawtypes")
|
||||
@Override
|
||||
public <T> ConfigPack registerShortcut(TypeKey<T> clazz, String shortcut, ShortcutLoader<T> loader) {
|
||||
ShortcutHolder<?> holder = shortcuts
|
||||
@@ -388,10 +406,12 @@ public class ConfigPackImpl implements ConfigPack {
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> CheckedRegistry<T> getRegistry(Type type) {
|
||||
return (CheckedRegistry<T>) registryMap.get(type);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public <T> CheckedRegistry<T> getCheckedRegistry(Type type) throws IllegalStateException {
|
||||
return (CheckedRegistry<T>) registryMap.get(type);
|
||||
|
||||
-215
@@ -1,215 +0,0 @@
|
||||
package com.dfsek.terra.config.pack;
|
||||
|
||||
import ca.solostudios.strata.version.Version;
|
||||
import com.dfsek.tectonic.api.TypeRegistry;
|
||||
import com.dfsek.tectonic.api.config.Configuration;
|
||||
import com.dfsek.tectonic.api.config.template.object.ObjectTemplate;
|
||||
import com.dfsek.tectonic.api.loader.AbstractConfigLoader;
|
||||
import com.dfsek.tectonic.api.loader.ConfigLoader;
|
||||
import com.dfsek.tectonic.api.loader.type.TypeLoader;
|
||||
import com.dfsek.tectonic.yaml.YamlConfiguration;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.Type;
|
||||
import java.nio.file.FileSystem;
|
||||
import java.nio.file.FileSystems;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import com.dfsek.terra.api.Platform;
|
||||
import com.dfsek.terra.api.config.ConfigPack;
|
||||
import com.dfsek.terra.api.config.MetaPack;
|
||||
import com.dfsek.terra.api.properties.Context;
|
||||
import com.dfsek.terra.api.registry.CheckedRegistry;
|
||||
import com.dfsek.terra.api.registry.OpenRegistry;
|
||||
import com.dfsek.terra.api.registry.Registry;
|
||||
import com.dfsek.terra.api.registry.key.RegistryKey;
|
||||
import com.dfsek.terra.api.util.reflection.ReflectionUtil;
|
||||
import com.dfsek.terra.api.util.reflection.TypeKey;
|
||||
import com.dfsek.terra.config.loaders.GenericTemplateSupplierLoader;
|
||||
import com.dfsek.terra.registry.CheckedRegistryImpl;
|
||||
import com.dfsek.terra.registry.OpenRegistryImpl;
|
||||
import com.dfsek.terra.registry.master.ConfigRegistry;
|
||||
|
||||
|
||||
public class MetaPackImpl implements MetaPack {
|
||||
|
||||
private static final Pattern PATTERN = Pattern.compile(", ");
|
||||
private static final Logger logger = LoggerFactory.getLogger(MetaPackImpl.class);
|
||||
private final MetaPackTemplate template = new MetaPackTemplate();
|
||||
private final Platform platform;
|
||||
private final Path rootPath;
|
||||
private final Map<String, ConfigPack> packs = new HashMap<>();
|
||||
private final ConfigLoader selfLoader = new ConfigLoader();
|
||||
private final Context context = new Context();
|
||||
private final RegistryKey key;
|
||||
private final Map<Type, CheckedRegistryImpl<?>> registryMap = new HashMap<>();
|
||||
private final AbstractConfigLoader abstractConfigLoader = new AbstractConfigLoader();
|
||||
private final String author;
|
||||
|
||||
public MetaPackImpl(Path path, Platform platform, ConfigRegistry configRegistry) throws IOException {
|
||||
long start = System.nanoTime();
|
||||
|
||||
if(Files.notExists(path)) throw new FileNotFoundException("Could not load metapack, " + path + " does not exist");
|
||||
|
||||
if(Files.isDirectory(path)) {
|
||||
this.rootPath = path;
|
||||
} else if(Files.isRegularFile(path)) {
|
||||
if(!path.getFileName().toString().endsWith(".zip")) {
|
||||
throw new IOException("Could not load metapack, file " + path + " is not a zip");
|
||||
}
|
||||
FileSystem zipfs = FileSystems.newFileSystem(path);
|
||||
this.rootPath = zipfs.getPath("/");
|
||||
} else {
|
||||
throw new IOException("Could not load metapack from " + path);
|
||||
}
|
||||
|
||||
Path packManifestPath = rootPath.resolve("metapack.yml");
|
||||
if(Files.notExists(packManifestPath)) throw new IOException("No metapack.yml found in " + path);
|
||||
Configuration packManifest = new YamlConfiguration(Files.newInputStream(packManifestPath),
|
||||
packManifestPath.getFileName().toString());
|
||||
|
||||
this.platform = platform;
|
||||
|
||||
register(selfLoader);
|
||||
platform.register(selfLoader);
|
||||
|
||||
register(abstractConfigLoader);
|
||||
platform.register(abstractConfigLoader);
|
||||
|
||||
selfLoader.load(template, packManifest);
|
||||
|
||||
String namespace;
|
||||
String id;
|
||||
if(template.getID().contains(":")) {
|
||||
namespace = template.getID().substring(0, template.getID().indexOf(":"));
|
||||
id = template.getID().substring(template.getID().indexOf(":") + 1);
|
||||
} else {
|
||||
id = template.getID();
|
||||
namespace = template.getID();
|
||||
}
|
||||
|
||||
this.key = RegistryKey.of(namespace, id);
|
||||
|
||||
logger.info("Loading metapack \"{}:{}\"", id, namespace);
|
||||
|
||||
template.getPacks().forEach((k, v) -> {
|
||||
RegistryKey registryKey = RegistryKey.parse(v);
|
||||
if(configRegistry.contains(registryKey)) {
|
||||
packs.put(k, configRegistry.get(registryKey).get());
|
||||
logger.info("Linked config pack \"{}\" to metapack \"{}:{}\".", v, namespace, id);
|
||||
} else {
|
||||
logger.warn("Failed to link config pack \"{}\" to metapack \"{}:{}\".", v, namespace, id);
|
||||
}
|
||||
});
|
||||
|
||||
HashSet<String> authors = new HashSet<>();
|
||||
packs.forEach((k, v) -> {
|
||||
authors.addAll(Arrays.asList(PATTERN.split(v.getAuthor())));
|
||||
});
|
||||
authors.addAll(Arrays.asList(PATTERN.split(template.getAuthor())));
|
||||
|
||||
this.author = String.join(", ", authors);
|
||||
|
||||
logger.info("Loaded metapack \"{}:{}\" v{} by {} in {}ms.",
|
||||
namespace, id, getVersion().getFormatted(), author, (System.nanoTime() - start) / 1000000.0D);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getAuthor() {
|
||||
return author;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return template.getVersion();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, ConfigPack> packs() {
|
||||
return packs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Context getContext() {
|
||||
return context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RegistryKey getRegistryKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> CheckedRegistry<T> getRegistry(Type type) {
|
||||
return (CheckedRegistry<T>) registryMap.get(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> CheckedRegistry<T> getCheckedRegistry(Type type) throws IllegalStateException {
|
||||
return (CheckedRegistry<T>) registryMap.get(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> CheckedRegistry<T> getOrCreateRegistry(TypeKey<T> typeKey) {
|
||||
return (CheckedRegistry<T>) registryMap.computeIfAbsent(typeKey.getType(), c -> {
|
||||
OpenRegistry<T> registry = new OpenRegistryImpl<>(typeKey);
|
||||
selfLoader.registerLoader(c, registry);
|
||||
abstractConfigLoader.registerLoader(c, registry);
|
||||
logger.debug("Registered loader for registry of class {}", ReflectionUtil.typeToString(c));
|
||||
|
||||
if(typeKey.getType() instanceof ParameterizedType param) {
|
||||
Type base = param.getRawType();
|
||||
if(base instanceof Class // should always be true but we'll check anyways
|
||||
&& Supplier.class.isAssignableFrom((Class<?>) base)) { // If it's a supplier
|
||||
Type supplied = param.getActualTypeArguments()[0]; // Grab the supplied type
|
||||
if(supplied instanceof ParameterizedType suppliedParam) {
|
||||
Type suppliedBase = suppliedParam.getRawType();
|
||||
if(suppliedBase instanceof Class // should always be true but we'll check anyways
|
||||
&& ObjectTemplate.class.isAssignableFrom((Class<?>) suppliedBase)) {
|
||||
Type templateType = suppliedParam.getActualTypeArguments()[0];
|
||||
GenericTemplateSupplierLoader<?> loader = new GenericTemplateSupplierLoader<>(
|
||||
(Registry<Supplier<ObjectTemplate<Supplier<ObjectTemplate<?>>>>>) registry);
|
||||
selfLoader.registerLoader(templateType, loader);
|
||||
abstractConfigLoader.registerLoader(templateType, loader);
|
||||
logger.debug("Registered template loader for registry of class {}", ReflectionUtil.typeToString(templateType));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new CheckedRegistryImpl<>(registry);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> MetaPackImpl applyLoader(Type type, TypeLoader<T> loader) {
|
||||
abstractConfigLoader.registerLoader(type, loader);
|
||||
selfLoader.registerLoader(type, loader);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> MetaPackImpl applyLoader(Type type, Supplier<ObjectTemplate<T>> loader) {
|
||||
abstractConfigLoader.registerLoader(type, loader);
|
||||
selfLoader.registerLoader(type, loader);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(TypeRegistry registry) {
|
||||
registryMap.forEach(registry::registerLoader);
|
||||
}
|
||||
|
||||
}
|
||||
-41
@@ -1,41 +0,0 @@
|
||||
package com.dfsek.terra.config.pack;
|
||||
|
||||
import ca.solostudios.strata.version.Version;
|
||||
import com.dfsek.tectonic.api.config.template.ConfigTemplate;
|
||||
import com.dfsek.tectonic.api.config.template.annotations.Default;
|
||||
import com.dfsek.tectonic.api.config.template.annotations.Value;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
@SuppressWarnings({ "unused", "FieldMayBeFinal" })
|
||||
public class MetaPackTemplate implements ConfigTemplate {
|
||||
@Value("id")
|
||||
private String id;
|
||||
|
||||
@Value("author")
|
||||
@Default
|
||||
private String author = "Anon Y. Mous";
|
||||
|
||||
@Value("version")
|
||||
private Version version;
|
||||
|
||||
@Value("packs")
|
||||
private Map<String, String> packs;
|
||||
|
||||
public String getID() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getAuthor() {
|
||||
return author;
|
||||
}
|
||||
|
||||
public Version getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public Map<String, String> getPacks() {
|
||||
return packs;
|
||||
}
|
||||
}
|
||||
+37
-34
@@ -17,13 +17,14 @@
|
||||
|
||||
package com.dfsek.terra.registry.master;
|
||||
|
||||
import com.dfsek.tectonic.api.exception.ConfigException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.Serial;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
import java.util.Objects;
|
||||
import java.util.zip.ZipFile;
|
||||
|
||||
import com.dfsek.terra.api.Platform;
|
||||
import com.dfsek.terra.api.config.ConfigPack;
|
||||
@@ -36,42 +37,44 @@ import com.dfsek.terra.registry.OpenRegistryImpl;
|
||||
* Class to hold config packs
|
||||
*/
|
||||
public class ConfigRegistry extends OpenRegistryImpl<ConfigPack> {
|
||||
private static final Logger logger = LoggerFactory.getLogger(ConfigRegistry.class);
|
||||
|
||||
public ConfigRegistry() {
|
||||
super(TypeKey.of(ConfigPack.class));
|
||||
}
|
||||
|
||||
public void loadAll(Platform platform) throws IOException, PackLoadFailuresException {
|
||||
Path packsDirectory = platform.getDataFolder().toPath().resolve("packs");
|
||||
Files.createDirectories(packsDirectory);
|
||||
List<IOException> failedLoads = new ArrayList<>();
|
||||
try(Stream<Path> packs = Files.list(packsDirectory)) {
|
||||
packs.forEach(path -> {
|
||||
try {
|
||||
ConfigPack pack = new ConfigPackImpl(path, platform);
|
||||
registerChecked(pack.getRegistryKey(), pack);
|
||||
} catch(IOException e) {
|
||||
failedLoads.add(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
if(!failedLoads.isEmpty()) {
|
||||
throw new PackLoadFailuresException(failedLoads);
|
||||
}
|
||||
public void load(File folder, Platform platform) throws ConfigException {
|
||||
ConfigPack pack = new ConfigPackImpl(folder, platform);
|
||||
registerChecked(pack.getRegistryKey(), pack);
|
||||
}
|
||||
|
||||
public static class PackLoadFailuresException extends Exception {
|
||||
@Serial
|
||||
private static final long serialVersionUID = 538998844645186306L;
|
||||
|
||||
private final List<Throwable> exceptions;
|
||||
|
||||
public PackLoadFailuresException(List<? extends Throwable> exceptions) {
|
||||
this.exceptions = (List<Throwable>) exceptions;
|
||||
public boolean loadAll(Platform platform) {
|
||||
boolean valid = true;
|
||||
File packsFolder = new File(platform.getDataFolder(), "packs");
|
||||
packsFolder.mkdirs();
|
||||
for(File dir : Objects.requireNonNull(packsFolder.listFiles(File::isDirectory))) {
|
||||
try {
|
||||
load(dir, platform);
|
||||
} catch(ConfigException e) {
|
||||
logger.error("Error loading config pack {}", dir.getName(), e);
|
||||
valid = false;
|
||||
}
|
||||
}
|
||||
|
||||
public List<Throwable> getExceptions() {
|
||||
return exceptions;
|
||||
for(File zip : Objects.requireNonNull(
|
||||
packsFolder.listFiles(file -> file.getName().endsWith(".zip") || file.getName().endsWith(".terra")))) {
|
||||
try {
|
||||
logger.info("Loading ZIP archive: {}", zip.getName());
|
||||
load(new ZipFile(zip), platform);
|
||||
} catch(IOException | ConfigException e) {
|
||||
logger.error("Error loading config pack {}", zip.getName(), e);
|
||||
valid = false;
|
||||
}
|
||||
}
|
||||
return valid;
|
||||
}
|
||||
|
||||
public void load(ZipFile file, Platform platform) throws ConfigException {
|
||||
ConfigPackImpl pack = new ConfigPackImpl(file, platform);
|
||||
registerChecked(pack.getRegistryKey(), pack);
|
||||
}
|
||||
}
|
||||
|
||||
-62
@@ -1,62 +0,0 @@
|
||||
/*
|
||||
* This file is part of Terra.
|
||||
*
|
||||
* Terra is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Terra is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.registry.master;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import com.dfsek.terra.api.Platform;
|
||||
import com.dfsek.terra.api.config.MetaPack;
|
||||
import com.dfsek.terra.api.util.reflection.TypeKey;
|
||||
import com.dfsek.terra.config.pack.MetaPackImpl;
|
||||
import com.dfsek.terra.registry.OpenRegistryImpl;
|
||||
import com.dfsek.terra.registry.master.ConfigRegistry.PackLoadFailuresException;
|
||||
|
||||
|
||||
/**
|
||||
* Class to hold config packs
|
||||
*/
|
||||
public class MetaConfigRegistry extends OpenRegistryImpl<MetaPack> {
|
||||
|
||||
public MetaConfigRegistry() {
|
||||
super(TypeKey.of(MetaPack.class));
|
||||
}
|
||||
|
||||
public void loadAll(Platform platform, ConfigRegistry configRegistry) throws IOException, PackLoadFailuresException {
|
||||
Path packsDirectory = platform.getDataFolder().toPath().resolve("metapacks");
|
||||
Files.createDirectories(packsDirectory);
|
||||
List<IOException> failedLoads = new ArrayList<>();
|
||||
try(Stream<Path> packs = Files.list(packsDirectory)) {
|
||||
packs.forEach(path -> {
|
||||
try {
|
||||
MetaPack pack = new MetaPackImpl(path, platform, configRegistry);
|
||||
registerChecked(pack.getRegistryKey(), pack);
|
||||
} catch(IOException e) {
|
||||
failedLoads.add(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
if(!failedLoads.isEmpty()) {
|
||||
throw new PackLoadFailuresException(failedLoads);
|
||||
}
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionSha256Sum=9d926787066a081739e8200858338b4a69e837c3a821a33aca9db09dd4a41026
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
|
||||
distributionSha256Sum=544c35d6bd849ae8a5ed0bcea39ba677dc40f49df7d1835561582da2009b961d
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
|
||||
networkTimeout=10000
|
||||
validateDistributionUrl=true
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
|
||||
@@ -10,7 +10,7 @@ repositories {
|
||||
|
||||
dependencies {
|
||||
shaded(project(":platforms:bukkit:common"))
|
||||
shaded(project(":platforms:bukkit:nms:v1_20_R3", configuration = "reobf"))
|
||||
shaded(project(":platforms:bukkit:nms:v1_20_R6", configuration = "reobf"))
|
||||
shaded("xyz.jpenilla", "reflection-remapper", Versions.Bukkit.reflectionRemapper)
|
||||
}
|
||||
|
||||
|
||||
@@ -63,7 +63,8 @@ public class PlatformImpl extends AbstractPlatform {
|
||||
@Override
|
||||
public boolean reload() {
|
||||
getTerraConfig().load(this);
|
||||
boolean succeed = loadConfigPacks();
|
||||
getRawConfigRegistry().clear();
|
||||
boolean succeed = getRawConfigRegistry().loadAll(this);
|
||||
|
||||
Bukkit.getWorlds().forEach(world -> {
|
||||
if(world.getGenerator() instanceof BukkitChunkGeneratorWrapper wrapper) {
|
||||
|
||||
@@ -189,6 +189,7 @@ public class TerraBukkitPlugin extends JavaPlugin {
|
||||
@Override
|
||||
public @Nullable
|
||||
ChunkGenerator getDefaultWorldGenerator(@NotNull String worldName, String id) {
|
||||
if (id == null || id.trim().equals("")) { return null; }
|
||||
return new BukkitChunkGeneratorWrapper(generatorMap.computeIfAbsent(worldName, name -> {
|
||||
ConfigPack pack = platform.getConfigRegistry().getByID(id).orElseThrow(
|
||||
() -> new IllegalArgumentException("No such config pack \"" + id + "\""));
|
||||
|
||||
-1
@@ -28,7 +28,6 @@ import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.random.RandomGenerator;
|
||||
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.api.config.ConfigPack;
|
||||
|
||||
+3
-3
@@ -61,8 +61,8 @@ public class BukkitWorldHandle implements WorldHandle {
|
||||
|
||||
@Override
|
||||
public @NotNull EntityType getEntity(@NotNull String id) {
|
||||
if(!id.contains(":")) { //TODO: remove in 7.0
|
||||
String newid = "minecraft:" + id.toLowerCase();
|
||||
if (!id.contains(":")) { //TODO: remove in 7.0
|
||||
String newid = "minecraft:" + id.toLowerCase();;
|
||||
logger.warn(
|
||||
"Translating " + id + " to " + newid + ". In 1.20.3 entity parsing was reworked" +
|
||||
". You are advised to perform this rename in your config backs as this translation will be removed in the next major " +
|
||||
@@ -72,7 +72,7 @@ public class BukkitWorldHandle implements WorldHandle {
|
||||
String entityID = id.toUpperCase(Locale.ROOT).substring(10);
|
||||
|
||||
return new BukkitEntityType(switch(entityID) {
|
||||
case "END_CRYSTAL" -> org.bukkit.entity.EntityType.ENDER_CRYSTAL;
|
||||
case "END_CRYSTAL" -> org.bukkit.entity.EntityType.END_CRYSTAL;
|
||||
case "ENDER_CRYSTAL" -> throw new IllegalArgumentException(
|
||||
"Invalid entity identifier " + id); // make sure this issue can't happen the other way around.
|
||||
default -> org.bukkit.entity.EntityType.valueOf(entityID);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.dfsek.terra.bukkit.nms;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import com.dfsek.terra.bukkit.util.VersionUtil;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -8,7 +9,7 @@ import com.dfsek.terra.bukkit.PlatformImpl;
|
||||
|
||||
|
||||
public interface Initializer {
|
||||
String NMS = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3];
|
||||
String NMS = VersionUtil.getMinecraftVersionInfo().toString().replace(".", "_");
|
||||
String TERRA_PACKAGE = Initializer.class.getPackageName();
|
||||
|
||||
static boolean init(PlatformImpl platform) {
|
||||
|
||||
@@ -77,13 +77,13 @@ public final class VersionUtil {
|
||||
public static final class MinecraftVersionInfo {
|
||||
private static final Logger logger = LoggerFactory.getLogger(MinecraftVersionInfo.class);
|
||||
|
||||
private static final Pattern VERSION_PATTERN = Pattern.compile("v?(\\d+)_(\\d+)_R(\\d+)");
|
||||
private static final Pattern VERSION_PATTERN = Pattern.compile("(\\d+)\\.(\\d+)\\.(\\d+)");
|
||||
private final int major;
|
||||
private final int minor;
|
||||
private final int patch;
|
||||
|
||||
private MinecraftVersionInfo() {
|
||||
this(Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3]);
|
||||
this(Bukkit.getServer().getBukkitVersion().split("-")[0]);
|
||||
}
|
||||
|
||||
private MinecraftVersionInfo(int major, int minor, int patch) {
|
||||
|
||||
+3
-3
@@ -1,10 +1,10 @@
|
||||
package com.dfsek.terra.bukkit.nms.v1_20_R3;
|
||||
package com.dfsek.terra.bukkit.nms.v1_20_6;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.mojang.serialization.Lifecycle;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.Holder.Reference;
|
||||
import net.minecraft.core.MappedRegistry;
|
||||
import net.minecraft.core.RegistrationInfo;
|
||||
import net.minecraft.core.WritableRegistry;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
@@ -49,7 +49,7 @@ public class AwfulBukkitHacks {
|
||||
new ResourceLocation("terra", NMSBiomeInjector.createBiomeID(pack, key))
|
||||
);
|
||||
|
||||
Reference<Biome> holder = biomeRegistry.register(delegateKey, platform, Lifecycle.stable());
|
||||
Reference<Biome> holder = biomeRegistry.register(delegateKey, platform, RegistrationInfo.BUILT_IN);
|
||||
Reflection.REFERENCE.invokeBindValue(holder, platform); // IMPORTANT: bind holder.
|
||||
|
||||
platformBiome.getContext().put(new NMSBiomeInfo(delegateKey));
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.dfsek.terra.bukkit.nms.v1_20_R3;
|
||||
package com.dfsek.terra.bukkit.nms.v1_20_6;
|
||||
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.dfsek.terra.bukkit.nms.v1_20_R3;
|
||||
package com.dfsek.terra.bukkit.nms.v1_20_6;
|
||||
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.Registry;
|
||||
+8
-4
@@ -1,6 +1,6 @@
|
||||
package com.dfsek.terra.bukkit.nms.v1_20_R3;
|
||||
package com.dfsek.terra.bukkit.nms.v1_20_6;
|
||||
|
||||
import com.mojang.serialization.Codec;
|
||||
import com.mojang.serialization.MapCodec;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
@@ -35,8 +35,12 @@ public class NMSBiomeProvider extends BiomeSource {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @NotNull Codec<? extends BiomeSource> codec() {
|
||||
return BiomeSource.CODEC;
|
||||
protected @NotNull MapCodec<? extends BiomeSource> codec() {
|
||||
return MapCodec.assumeMapUnsafe(BiomeSource.CODEC);
|
||||
// return MapCodec.unit(null);
|
||||
// BuiltInRegistries.BIOME_SOURCE.byNameCodec().dispatchMap(this::codec, Function.identity());
|
||||
// BuiltInRegistries.BIOME_SOURCE.byNameCodec().dispatchStable(BiomeSource::codec, Function.identity());
|
||||
// return BiomeSource.CODEC;
|
||||
}
|
||||
|
||||
@Override
|
||||
+5
-5
@@ -1,6 +1,6 @@
|
||||
package com.dfsek.terra.bukkit.nms.v1_20_R3;
|
||||
package com.dfsek.terra.bukkit.nms.v1_20_6;
|
||||
|
||||
import com.mojang.serialization.Codec;
|
||||
import com.mojang.serialization.MapCodec;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.server.level.WorldGenRegion;
|
||||
import net.minecraft.world.level.LevelAccessor;
|
||||
@@ -19,7 +19,7 @@ import net.minecraft.world.level.levelgen.GenerationStep.Carving;
|
||||
import net.minecraft.world.level.levelgen.Heightmap.Types;
|
||||
import net.minecraft.world.level.levelgen.RandomState;
|
||||
import net.minecraft.world.level.levelgen.blending.Blender;
|
||||
import org.bukkit.craftbukkit.v1_20_R3.block.data.CraftBlockData;
|
||||
import org.bukkit.craftbukkit.block.data.CraftBlockData;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -54,8 +54,8 @@ public class NMSChunkGeneratorDelegate extends ChunkGenerator {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @NotNull Codec<? extends ChunkGenerator> codec() {
|
||||
return ChunkGenerator.CODEC;
|
||||
protected @NotNull MapCodec<? extends ChunkGenerator> codec() {
|
||||
return MapCodec.assumeMapUnsafe(ChunkGenerator.CODEC);
|
||||
}
|
||||
|
||||
@Override
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.dfsek.terra.bukkit.nms.v1_20_R3;
|
||||
package com.dfsek.terra.bukkit.nms.v1_20_6;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
+2
-2
@@ -1,9 +1,9 @@
|
||||
package com.dfsek.terra.bukkit.nms.v1_20_R3;
|
||||
package com.dfsek.terra.bukkit.nms.v1_20_6;
|
||||
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.level.chunk.ChunkGenerator;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.craftbukkit.v1_20_R3.CraftWorld;
|
||||
import org.bukkit.craftbukkit.CraftWorld;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.world.WorldInitEvent;
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.dfsek.terra.bukkit.nms.v1_20_R3;
|
||||
package com.dfsek.terra.bukkit.nms.v1_20_6;
|
||||
|
||||
import net.minecraft.world.level.LevelHeightAccessor;
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.dfsek.terra.bukkit.nms.v1_20_R3;
|
||||
package com.dfsek.terra.bukkit.nms.v1_20_6;
|
||||
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.Holder.Reference;
|
||||
+2
-2
@@ -1,4 +1,4 @@
|
||||
package com.dfsek.terra.bukkit.nms.v1_20_R3;
|
||||
package com.dfsek.terra.bukkit.nms.v1_20_6;
|
||||
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
@@ -6,7 +6,7 @@ import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.server.dedicated.DedicatedServer;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.craftbukkit.v1_20_R3.CraftServer;
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
|
||||
|
||||
public class RegistryFetcher {
|
||||
@@ -1,11 +1,11 @@
|
||||
package com.dfsek.terra.cli.handle;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import com.dfsek.terra.api.handle.ItemHandle;
|
||||
import com.dfsek.terra.api.inventory.Item;
|
||||
import com.dfsek.terra.api.inventory.item.Enchantment;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
public class CLIItemHandle implements ItemHandle {
|
||||
@Override
|
||||
|
||||
@@ -20,9 +20,6 @@ package com.dfsek.terra.forge;
|
||||
import ca.solostudios.strata.Versions;
|
||||
import ca.solostudios.strata.parser.tokenizer.ParseException;
|
||||
import ca.solostudios.strata.version.Version;
|
||||
|
||||
import com.dfsek.terra.registry.master.ConfigRegistry.PackLoadFailuresException;
|
||||
|
||||
import net.minecraft.MinecraftVersion;
|
||||
import net.minecraft.registry.Registry;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
@@ -37,7 +34,6 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -66,7 +62,8 @@ public class ForgePlatform extends ModPlatform {
|
||||
@Override
|
||||
public boolean reload() {
|
||||
getTerraConfig().load(this);
|
||||
boolean succeed = loadConfigPacks();
|
||||
getRawConfigRegistry().clear();
|
||||
boolean succeed = getRawConfigRegistry().loadAll(this);
|
||||
|
||||
MinecraftServer server = getServer();
|
||||
|
||||
|
||||
@@ -31,7 +31,6 @@ import com.dfsek.terra.api.world.biome.Biome;
|
||||
import com.dfsek.terra.mod.config.PostLoadCompatibilityOptions;
|
||||
import com.dfsek.terra.mod.config.PreLoadCompatibilityOptions;
|
||||
import com.dfsek.terra.mod.config.VanillaBiomeProperties;
|
||||
import com.dfsek.terra.mod.config.VanillaWorldProperties;
|
||||
|
||||
|
||||
public abstract class MinecraftAddon implements BaseAddon {
|
||||
@@ -45,12 +44,6 @@ public abstract class MinecraftAddon implements BaseAddon {
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
modPlatform.getEventManager()
|
||||
.getHandler(FunctionalEventHandler.class)
|
||||
.register(this, ConfigPackPostLoadEvent.class)
|
||||
.then(event -> event.getPack().getContext().put(event.loadTemplate(new VanillaWorldProperties())))
|
||||
.priority(100)
|
||||
.global();
|
||||
modPlatform.getEventManager()
|
||||
.getHandler(FunctionalEventHandler.class)
|
||||
.register(this, ConfigPackPreLoadEvent.class)
|
||||
|
||||
@@ -5,7 +5,6 @@ import com.dfsek.tectonic.api.depth.DepthTracker;
|
||||
import com.dfsek.tectonic.api.exception.LoadException;
|
||||
import net.minecraft.entity.EntityType;
|
||||
import net.minecraft.entity.SpawnGroup;
|
||||
import net.minecraft.entity.boss.dragon.EnderDragonFight;
|
||||
import net.minecraft.registry.Registry;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.sound.BiomeAdditionsSound;
|
||||
@@ -27,7 +26,6 @@ import net.minecraft.world.gen.WorldPreset;
|
||||
import net.minecraft.world.gen.chunk.ChunkGeneratorSettings;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.function.BiConsumer;
|
||||
@@ -46,7 +44,6 @@ import com.dfsek.terra.mod.config.ProtoPlatformBiome;
|
||||
import com.dfsek.terra.mod.config.SoundEventTemplate;
|
||||
import com.dfsek.terra.mod.config.SpawnCostConfig;
|
||||
import com.dfsek.terra.mod.config.SpawnEntryTemplate;
|
||||
import com.dfsek.terra.mod.config.SpawnGroupTemplate;
|
||||
import com.dfsek.terra.mod.config.SpawnSettingsTemplate;
|
||||
import com.dfsek.terra.mod.config.SpawnTypeConfig;
|
||||
import com.dfsek.terra.mod.config.VillagerTypeTemplate;
|
||||
@@ -62,49 +59,40 @@ public abstract class ModPlatform extends AbstractPlatform {
|
||||
public abstract MinecraftServer getServer();
|
||||
|
||||
public void registerWorldTypes(BiConsumer<Identifier, WorldPreset> registerFunction) {
|
||||
HashSet<String> configPacksInMetaPack = new HashSet<>();
|
||||
getRawMetaConfigRegistry().forEach(pack -> {
|
||||
PresetUtil.createMetaPackPreset(pack, this).apply(registerFunction);
|
||||
pack.packs().forEach((k, v) -> configPacksInMetaPack.add(v.getID()));
|
||||
});
|
||||
getRawConfigRegistry()
|
||||
.forEach(pack -> {
|
||||
if(!configPacksInMetaPack.contains(pack.getID())) {
|
||||
PresetUtil.createDefault(pack, this).apply(registerFunction);
|
||||
}
|
||||
});
|
||||
.forEach(pack -> PresetUtil.createDefault(pack, this).apply(registerFunction));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(TypeRegistry registry) {
|
||||
super.register(registry);
|
||||
registry.registerLoader(PlatformBiome.class, (type, o, loader, depthTracker) -> parseBiome((String) o, depthTracker))
|
||||
.registerLoader(Identifier.class, (type, o, loader, depthTracker) -> {
|
||||
Identifier identifier = Identifier.tryParse((String) o);
|
||||
if(identifier == null)
|
||||
throw new LoadException("Invalid identifier: " + o, depthTracker);
|
||||
return identifier;
|
||||
})
|
||||
.registerLoader(Precipitation.class, (type, o, loader, depthTracker) -> Precipitation.valueOf(((String) o).toUpperCase(
|
||||
Locale.ROOT)))
|
||||
.registerLoader(GrassColorModifier.class,
|
||||
(type, o, loader, depthTracker) -> GrassColorModifier.valueOf(((String) o).toUpperCase(
|
||||
Locale.ROOT)))
|
||||
.registerLoader(GrassColorModifier.class,
|
||||
(type, o, loader, depthTracker) -> TemperatureModifier.valueOf(((String) o).toUpperCase(
|
||||
Locale.ROOT)))
|
||||
.registerLoader(BiomeParticleConfig.class, BiomeParticleConfigTemplate::new)
|
||||
.registerLoader(SoundEvent.class, SoundEventTemplate::new)
|
||||
.registerLoader(BiomeMoodSound.class, BiomeMoodSoundTemplate::new)
|
||||
.registerLoader(BiomeAdditionsSound.class, BiomeAdditionsSoundTemplate::new)
|
||||
.registerLoader(MusicSound.class, MusicSoundTemplate::new)
|
||||
.registerLoader(EntityType.class, EntityTypeTemplate::new)
|
||||
.registerLoader(SpawnCostConfig.class, SpawnCostConfig::new)
|
||||
.registerLoader(SpawnEntry.class, SpawnEntryTemplate::new)
|
||||
.registerLoader(SpawnGroup.class, SpawnGroupTemplate::new)
|
||||
.registerLoader(SpawnTypeConfig.class, SpawnTypeConfig::new)
|
||||
.registerLoader(SpawnSettings.class, SpawnSettingsTemplate::new)
|
||||
.registerLoader(VillagerType.class, VillagerTypeTemplate::new);
|
||||
.registerLoader(Identifier.class, (type, o, loader, depthTracker) -> {
|
||||
Identifier identifier = Identifier.tryParse((String) o);
|
||||
if(identifier == null)
|
||||
throw new LoadException("Invalid identifier: " + o, depthTracker);
|
||||
return identifier;
|
||||
})
|
||||
.registerLoader(Precipitation.class, (type, o, loader, depthTracker) -> Precipitation.valueOf(((String) o).toUpperCase(
|
||||
Locale.ROOT)))
|
||||
.registerLoader(GrassColorModifier.class,
|
||||
(type, o, loader, depthTracker) -> GrassColorModifier.valueOf(((String) o).toUpperCase(
|
||||
Locale.ROOT)))
|
||||
.registerLoader(GrassColorModifier.class,
|
||||
(type, o, loader, depthTracker) -> TemperatureModifier.valueOf(((String) o).toUpperCase(
|
||||
Locale.ROOT)))
|
||||
.registerLoader(SpawnGroup.class,(type, o, loader, depthTracker) -> SpawnGroup.valueOf((String) o))
|
||||
.registerLoader(BiomeParticleConfig.class, BiomeParticleConfigTemplate::new)
|
||||
.registerLoader(SoundEvent.class, SoundEventTemplate::new)
|
||||
.registerLoader(BiomeMoodSound.class, BiomeMoodSoundTemplate::new)
|
||||
.registerLoader(BiomeAdditionsSound.class, BiomeAdditionsSoundTemplate::new)
|
||||
.registerLoader(MusicSound.class, MusicSoundTemplate::new)
|
||||
.registerLoader(EntityType.class, EntityTypeTemplate::new)
|
||||
.registerLoader(SpawnCostConfig.class, SpawnCostConfig::new)
|
||||
.registerLoader(SpawnEntry.class, SpawnEntryTemplate::new)
|
||||
.registerLoader(SpawnTypeConfig.class, SpawnTypeConfig::new)
|
||||
.registerLoader(SpawnSettings.class, SpawnSettingsTemplate::new)
|
||||
.registerLoader(VillagerType.class, VillagerTypeTemplate::new);
|
||||
}
|
||||
|
||||
private ProtoPlatformBiome parseBiome(String id, DepthTracker tracker) throws LoadException {
|
||||
|
||||
+2
-1
@@ -7,6 +7,7 @@ import com.mojang.brigadier.StringReader;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import net.minecraft.command.argument.ParticleEffectArgumentType;
|
||||
import net.minecraft.registry.Registries;
|
||||
import net.minecraft.registry.RegistryWrapper;
|
||||
import net.minecraft.world.biome.BiomeParticleConfig;
|
||||
|
||||
|
||||
@@ -27,7 +28,7 @@ public class BiomeParticleConfigTemplate implements ObjectTemplate<BiomeParticle
|
||||
|
||||
try {
|
||||
return new BiomeParticleConfig(
|
||||
ParticleEffectArgumentType.readParameters(new StringReader(particle), Registries.PARTICLE_TYPE.getReadOnlyWrapper()),
|
||||
ParticleEffectArgumentType.readParameters(new StringReader(particle), (RegistryWrapper.WrapperLookup) Registries.PARTICLE_TYPE.getReadOnlyWrapper()),
|
||||
probability);
|
||||
} catch(CommandSyntaxException e) {
|
||||
throw new RuntimeException(e);
|
||||
|
||||
-48
@@ -1,48 +0,0 @@
|
||||
package com.dfsek.terra.mod.config;
|
||||
|
||||
import com.dfsek.tectonic.api.config.template.annotations.Default;
|
||||
import com.dfsek.tectonic.api.config.template.annotations.Value;
|
||||
import com.dfsek.tectonic.api.config.template.object.ObjectTemplate;
|
||||
|
||||
import com.dfsek.terra.api.util.Range;
|
||||
|
||||
|
||||
public class MonsterSettingsConfig implements ObjectTemplate<MonsterSettingsConfig> {
|
||||
@Value("piglin-safe")
|
||||
@Default
|
||||
private Boolean piglinSafe = null;
|
||||
|
||||
@Value("has-raids")
|
||||
@Default
|
||||
private Boolean hasRaids = null;
|
||||
|
||||
@Value("monster-spawn-light")
|
||||
@Default
|
||||
private Range monsterSpawnLight = null;
|
||||
|
||||
@Value("monster-spawn-block-light-limit")
|
||||
@Default
|
||||
private Integer monsterSpawnBlockLightLimit = null;
|
||||
|
||||
public Boolean getPiglinSafe() {
|
||||
return piglinSafe;
|
||||
}
|
||||
|
||||
public Boolean getHasRaids() {
|
||||
return hasRaids;
|
||||
}
|
||||
|
||||
public Range getMonsterSpawnLight() {
|
||||
return monsterSpawnLight;
|
||||
}
|
||||
|
||||
public Integer getMonsterSpawnBlockLightLimit() {
|
||||
return monsterSpawnBlockLightLimit;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public MonsterSettingsConfig get() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
-18
@@ -1,18 +0,0 @@
|
||||
package com.dfsek.terra.mod.config;
|
||||
|
||||
import com.dfsek.tectonic.api.config.template.annotations.Default;
|
||||
import com.dfsek.tectonic.api.config.template.annotations.Value;
|
||||
import com.dfsek.tectonic.api.config.template.object.ObjectTemplate;
|
||||
import net.minecraft.entity.SpawnGroup;
|
||||
|
||||
|
||||
public class SpawnGroupTemplate implements ObjectTemplate<SpawnGroup> {
|
||||
@Value("group")
|
||||
@Default
|
||||
private String group = null;
|
||||
|
||||
@Override
|
||||
public SpawnGroup get() {
|
||||
return SpawnGroup.valueOf(group);
|
||||
}
|
||||
}
|
||||
+6
-1
@@ -3,7 +3,9 @@ package com.dfsek.terra.mod.config;
|
||||
import com.dfsek.tectonic.api.config.template.annotations.Default;
|
||||
import com.dfsek.tectonic.api.config.template.annotations.Value;
|
||||
import com.dfsek.tectonic.api.config.template.object.ObjectTemplate;
|
||||
import net.minecraft.entity.SpawnGroup;
|
||||
import net.minecraft.world.biome.SpawnSettings;
|
||||
import net.minecraft.world.biome.SpawnSettings.SpawnEntry;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -25,7 +27,10 @@ public class SpawnSettingsTemplate implements ObjectTemplate<SpawnSettings> {
|
||||
public SpawnSettings get() {
|
||||
SpawnSettings.Builder builder = new SpawnSettings.Builder();
|
||||
for(SpawnTypeConfig spawn : spawns) {
|
||||
builder.spawn(spawn.getGroup(), spawn.getEntry());
|
||||
SpawnGroup group = spawn.getGroup();
|
||||
for (SpawnEntry entry : spawn.getEntry()) {
|
||||
builder.spawn(group, entry);
|
||||
}
|
||||
}
|
||||
for(SpawnCostConfig cost : costs) {
|
||||
builder.spawnCost(cost.getType(), cost.getMass(), cost.getGravity());
|
||||
|
||||
+8
-6
@@ -6,21 +6,23 @@ import com.dfsek.tectonic.api.config.template.object.ObjectTemplate;
|
||||
import net.minecraft.entity.SpawnGroup;
|
||||
import net.minecraft.world.biome.SpawnSettings.SpawnEntry;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class SpawnTypeConfig implements ObjectTemplate<SpawnTypeConfig> {
|
||||
@Value("group")
|
||||
@Default
|
||||
private SpawnGroup group = null;
|
||||
|
||||
@Value("entry")
|
||||
|
||||
@Value("entries")
|
||||
@Default
|
||||
private SpawnEntry entry = null;
|
||||
|
||||
private List<SpawnEntry> entry = null;
|
||||
|
||||
public SpawnGroup getGroup() {
|
||||
return group;
|
||||
}
|
||||
|
||||
public SpawnEntry getEntry() {
|
||||
|
||||
public List<SpawnEntry> getEntry() {
|
||||
return entry;
|
||||
}
|
||||
|
||||
|
||||
-171
@@ -1,171 +0,0 @@
|
||||
package com.dfsek.terra.mod.config;
|
||||
|
||||
import com.dfsek.tectonic.api.config.template.ConfigTemplate;
|
||||
import com.dfsek.tectonic.api.config.template.annotations.Default;
|
||||
import com.dfsek.tectonic.api.config.template.annotations.Value;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
import com.dfsek.terra.api.properties.Properties;
|
||||
import com.dfsek.terra.api.util.ConstantRange;
|
||||
import com.dfsek.terra.api.util.Range;
|
||||
|
||||
|
||||
public class VanillaWorldProperties implements ConfigTemplate, Properties {
|
||||
|
||||
@Value("vanilla")
|
||||
@Default
|
||||
private String vanillaDimension = "minecraft:overworld";
|
||||
|
||||
@Value("vanilla-generation")
|
||||
@Default
|
||||
private String vanillaGeneration = vanillaDimension;
|
||||
|
||||
@Value("minecraft.fixed-time")
|
||||
@Default
|
||||
private Long fixedTime = null;
|
||||
|
||||
@Value("minecraft.has-sky-light")
|
||||
@Default
|
||||
private Boolean hasSkyLight = null;
|
||||
|
||||
@Value("minecraft.has-ceiling")
|
||||
@Default
|
||||
private Boolean hasCeiling = null;
|
||||
|
||||
@Value("minecraft.ultra-warm")
|
||||
@Default
|
||||
private Boolean ultraWarm = null;
|
||||
|
||||
@Value("minecraft.natural")
|
||||
@Default
|
||||
private Boolean natural = null;
|
||||
|
||||
@Value("minecraft.coordinate-scale")
|
||||
@Default
|
||||
private Double coordinateScale = null;
|
||||
|
||||
@Value("minecraft.bed-works")
|
||||
@Default
|
||||
private Boolean bedWorks = null;
|
||||
|
||||
@Value("minecraft.respawn-anchor-works")
|
||||
@Default
|
||||
private Boolean respawnAnchorWorks = null;
|
||||
|
||||
@Value("minecraft.height")
|
||||
@Default
|
||||
private Range height = null;
|
||||
|
||||
@Value("minecraft.height.logical")
|
||||
@Default
|
||||
private Integer logicalHeight = null;
|
||||
|
||||
@Value("minecraft.infiniburn")
|
||||
@Default
|
||||
private Identifier infiniburn = null;
|
||||
|
||||
@Value("minecraft.effects")
|
||||
@Default
|
||||
private Identifier effects = null;
|
||||
|
||||
@Value("minecraft.ambient-light")
|
||||
@Default
|
||||
private Float ambientLight = null;
|
||||
|
||||
@Value("minecraft.monster-settings")
|
||||
@Default
|
||||
private MonsterSettingsConfig monsterSettings = null;
|
||||
|
||||
@Value("minecraft.mob-generation")
|
||||
@Default
|
||||
private Boolean mobGeneration = null;
|
||||
|
||||
@Value("minecraft.sealevel")
|
||||
@Default
|
||||
private Integer sealevel = null;
|
||||
|
||||
@Value("minecraft.spawn-height")
|
||||
@Default
|
||||
private Integer spawnHeight = 64;
|
||||
|
||||
public String getVanillaDimension() {
|
||||
return vanillaDimension;
|
||||
}
|
||||
|
||||
public String getVanillaGeneration() {
|
||||
return vanillaGeneration;
|
||||
}
|
||||
|
||||
public Long getFixedTime() {
|
||||
return fixedTime;
|
||||
}
|
||||
|
||||
public Boolean getHasSkyLight() {
|
||||
return hasSkyLight;
|
||||
}
|
||||
|
||||
public Boolean getHasCeiling() {
|
||||
return hasCeiling;
|
||||
}
|
||||
|
||||
public Boolean getUltraWarm() {
|
||||
return ultraWarm;
|
||||
}
|
||||
|
||||
public Boolean getNatural() {
|
||||
return natural;
|
||||
}
|
||||
|
||||
public Double getCoordinateScale() {
|
||||
return coordinateScale;
|
||||
}
|
||||
|
||||
public Boolean getBedWorks() {
|
||||
return bedWorks;
|
||||
}
|
||||
|
||||
public Boolean getRespawnAnchorWorks() {
|
||||
return respawnAnchorWorks;
|
||||
}
|
||||
|
||||
public ConstantRange getHeight() {
|
||||
//TODO THIS IS BAD
|
||||
if(height != null) {
|
||||
return new ConstantRange(height.getMin(), height.getMax());
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Integer getLogicalHeight() {
|
||||
return logicalHeight;
|
||||
}
|
||||
|
||||
public Identifier getInfiniburn() {
|
||||
return infiniburn;
|
||||
}
|
||||
|
||||
public Identifier getEffects() {
|
||||
return effects;
|
||||
}
|
||||
|
||||
public Float getAmbientLight() {
|
||||
return ambientLight;
|
||||
}
|
||||
|
||||
public MonsterSettingsConfig getMonsterSettings() {
|
||||
return monsterSettings;
|
||||
}
|
||||
|
||||
public Boolean getMobGeneration() {
|
||||
return mobGeneration;
|
||||
}
|
||||
|
||||
public Integer getSealevel() {
|
||||
return sealevel;
|
||||
}
|
||||
|
||||
public Integer getSpawnHeight() {
|
||||
return spawnHeight;
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,15 @@
|
||||
package com.dfsek.terra.mod.data;
|
||||
|
||||
import com.mojang.serialization.Codec;
|
||||
import com.mojang.serialization.MapCodec;
|
||||
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||
import net.minecraft.world.gen.chunk.ChunkGeneratorSettings;
|
||||
|
||||
import com.dfsek.terra.api.config.ConfigPack;
|
||||
import com.dfsek.terra.api.registry.key.RegistryKey;
|
||||
import com.dfsek.terra.api.util.ConstantRange;
|
||||
import com.dfsek.terra.mod.CommonPlatform;
|
||||
import com.dfsek.terra.mod.generation.GenerationSettings;
|
||||
import com.dfsek.terra.mod.generation.MinecraftChunkGeneratorWrapper;
|
||||
import com.dfsek.terra.mod.generation.TerraBiomeSource;
|
||||
import com.dfsek.terra.mod.implmentation.TerraIntProvider;
|
||||
|
||||
|
||||
public final class Codecs {
|
||||
@@ -34,28 +33,15 @@ public final class Codecs {
|
||||
"No such config pack " +
|
||||
id)))));
|
||||
|
||||
public static final Codec<TerraBiomeSource> TERRA_BIOME_SOURCE = RecordCodecBuilder
|
||||
.create(instance -> instance.group(
|
||||
public static final MapCodec<TerraBiomeSource> TERRA_BIOME_SOURCE = RecordCodecBuilder
|
||||
.mapCodec(instance -> instance.group(
|
||||
CONFIG_PACK.fieldOf("pack")
|
||||
.stable()
|
||||
.forGetter(TerraBiomeSource::getPack))
|
||||
.apply(instance, instance.stable(TerraBiomeSource::new)));
|
||||
|
||||
public static final Codec<ConstantRange> TERRA_CONSTANT_RANGE = RecordCodecBuilder.create(range -> range.group(
|
||||
Codec.INT.fieldOf("min").stable().forGetter(ConstantRange::getMin),
|
||||
Codec.INT.fieldOf("max").stable().forGetter(ConstantRange::getMax)).apply(range, range.stable(ConstantRange::new)));
|
||||
|
||||
public static final Codec<GenerationSettings> TERRA_GENERATION_SETTINGS = RecordCodecBuilder
|
||||
.create(instance -> instance.group(
|
||||
TERRA_CONSTANT_RANGE.fieldOf("height").stable().forGetter(GenerationSettings::height),
|
||||
Codec.INT.fieldOf("sea_level").forGetter(GenerationSettings::sealevel),
|
||||
Codec.BOOL.fieldOf("mob_generation").forGetter(GenerationSettings::mobGeneration),
|
||||
Codec.INT.fieldOf("spawn_height").forGetter(GenerationSettings::sealevel))
|
||||
.apply(instance, instance.stable(GenerationSettings::new)));
|
||||
|
||||
|
||||
public static final Codec<MinecraftChunkGeneratorWrapper> MINECRAFT_CHUNK_GENERATOR_WRAPPER = RecordCodecBuilder
|
||||
.create(
|
||||
public static final MapCodec<MinecraftChunkGeneratorWrapper> MINECRAFT_CHUNK_GENERATOR_WRAPPER = RecordCodecBuilder
|
||||
.mapCodec(
|
||||
instance -> instance.group(
|
||||
TERRA_BIOME_SOURCE.fieldOf("biome_source")
|
||||
.stable()
|
||||
@@ -63,16 +49,10 @@ public final class Codecs {
|
||||
CONFIG_PACK.fieldOf("pack")
|
||||
.stable()
|
||||
.forGetter(MinecraftChunkGeneratorWrapper::getPack),
|
||||
TERRA_GENERATION_SETTINGS.fieldOf("settings")
|
||||
ChunkGeneratorSettings.REGISTRY_CODEC.fieldOf("settings")
|
||||
.stable()
|
||||
.forGetter(MinecraftChunkGeneratorWrapper::getSettings)
|
||||
).apply(instance, instance.stable(
|
||||
MinecraftChunkGeneratorWrapper::new))
|
||||
);
|
||||
|
||||
public static final Codec<TerraIntProvider> TERRA_CONSTANT_RANGE_INT_PROVIDER_TYPE = RecordCodecBuilder.create(range -> range.group(
|
||||
Codec.INT.fieldOf("min").stable().forGetter(TerraIntProvider::getMin),
|
||||
Codec.INT.fieldOf("max").stable().forGetter(TerraIntProvider::getMax))
|
||||
.apply(range, range.stable((min, max) -> new TerraIntProvider(new ConstantRange(
|
||||
min, max)))));
|
||||
}
|
||||
|
||||
-7
@@ -1,7 +0,0 @@
|
||||
package com.dfsek.terra.mod.generation;
|
||||
|
||||
import com.dfsek.terra.api.util.ConstantRange;
|
||||
|
||||
|
||||
public record GenerationSettings(ConstantRange height, Integer sealevel, Boolean mobGeneration, Integer spawnHeight) {
|
||||
}
|
||||
+16
-19
@@ -18,6 +18,7 @@
|
||||
package com.dfsek.terra.mod.generation;
|
||||
|
||||
import com.mojang.serialization.Codec;
|
||||
import com.mojang.serialization.MapCodec;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.registry.entry.RegistryEntry;
|
||||
@@ -35,11 +36,11 @@ import net.minecraft.world.StructureWorldAccess;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
import net.minecraft.world.biome.source.BiomeAccess;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
import net.minecraft.world.dimension.NetherPortal;
|
||||
import net.minecraft.world.gen.GenerationStep.Carver;
|
||||
import net.minecraft.world.gen.StructureAccessor;
|
||||
import net.minecraft.world.gen.StructureWeightSampler;
|
||||
import net.minecraft.world.gen.chunk.Blender;
|
||||
import net.minecraft.world.gen.chunk.ChunkGeneratorSettings;
|
||||
import net.minecraft.world.gen.chunk.VerticalBlockSample;
|
||||
import net.minecraft.world.gen.densityfunction.DensityFunction.UnblendedNoisePos;
|
||||
import net.minecraft.world.gen.noise.NoiseConfig;
|
||||
@@ -69,13 +70,12 @@ public class MinecraftChunkGeneratorWrapper extends net.minecraft.world.gen.chun
|
||||
private static final Logger logger = LoggerFactory.getLogger(MinecraftChunkGeneratorWrapper.class);
|
||||
|
||||
private final TerraBiomeSource biomeSource;
|
||||
private final GenerationSettings settings;
|
||||
private final RegistryEntry<ChunkGeneratorSettings> settings;
|
||||
private ChunkGenerator delegate;
|
||||
private ConfigPack pack;
|
||||
|
||||
|
||||
public MinecraftChunkGeneratorWrapper(TerraBiomeSource biomeSource, ConfigPack configPack,
|
||||
GenerationSettings settingsSupplier) {
|
||||
RegistryEntry<ChunkGeneratorSettings> settingsSupplier) {
|
||||
super(biomeSource);
|
||||
this.pack = configPack;
|
||||
this.settings = settingsSupplier;
|
||||
@@ -86,7 +86,7 @@ public class MinecraftChunkGeneratorWrapper extends net.minecraft.world.gen.chun
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Codec<? extends net.minecraft.world.gen.chunk.ChunkGenerator> getCodec() {
|
||||
protected MapCodec<? extends net.minecraft.world.gen.chunk.ChunkGenerator> getCodec() {
|
||||
return Codecs.MINECRAFT_CHUNK_GENERATOR_WRAPPER;
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ public class MinecraftChunkGeneratorWrapper extends net.minecraft.world.gen.chun
|
||||
|
||||
@Override
|
||||
public void populateEntities(ChunkRegion region) {
|
||||
if(this.settings.mobGeneration()) {
|
||||
if(!this.settings.value().mobGenerationDisabled()) {
|
||||
ChunkPos chunkPos = region.getCenterPos();
|
||||
RegistryEntry<Biome> registryEntry = region.getBiome(chunkPos.getStartPos().withY(region.getTopY() - 1));
|
||||
ChunkRandom chunkRandom = new ChunkRandom(new CheckedRandom(RandomSeed.getSeed()));
|
||||
@@ -106,6 +106,12 @@ public class MinecraftChunkGeneratorWrapper extends net.minecraft.world.gen.chun
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWorldHeight() {
|
||||
return settings.value().generationShapeConfig().height();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Chunk> populateNoise(Executor executor, Blender blender, NoiseConfig noiseConfig,
|
||||
StructureAccessor structureAccessor, Chunk chunk) {
|
||||
@@ -160,25 +166,16 @@ public class MinecraftChunkGeneratorWrapper extends net.minecraft.world.gen.chun
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWorldHeight() {
|
||||
return settings.height().getRange();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSeaLevel() {
|
||||
return settings.sealevel();
|
||||
return settings.value().seaLevel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinimumY() {
|
||||
return settings.height().getMin();
|
||||
return settings.value().generationShapeConfig().minimumY();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSpawnHeight(HeightLimitView world) {
|
||||
return settings.spawnHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeight(int x, int z, Type heightmap, HeightLimitView height, NoiseConfig noiseConfig) {
|
||||
@@ -206,7 +203,7 @@ public class MinecraftChunkGeneratorWrapper extends net.minecraft.world.gen.chun
|
||||
|
||||
@Override
|
||||
public void getDebugHudText(List<String> text, NoiseConfig noiseConfig, BlockPos pos) {
|
||||
// no op
|
||||
|
||||
}
|
||||
|
||||
public ConfigPack getPack() {
|
||||
@@ -232,7 +229,7 @@ public class MinecraftChunkGeneratorWrapper extends net.minecraft.world.gen.chun
|
||||
return delegate;
|
||||
}
|
||||
|
||||
public GenerationSettings getSettings() {
|
||||
public RegistryEntry<ChunkGeneratorSettings> getSettings() {
|
||||
return settings;
|
||||
}
|
||||
|
||||
|
||||
+2
-1
@@ -18,6 +18,7 @@
|
||||
package com.dfsek.terra.mod.generation;
|
||||
|
||||
import com.mojang.serialization.Codec;
|
||||
import com.mojang.serialization.MapCodec;
|
||||
import net.minecraft.registry.entry.RegistryEntry;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
import net.minecraft.world.biome.source.BiomeSource;
|
||||
@@ -47,7 +48,7 @@ public class TerraBiomeSource extends BiomeSource {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Codec<? extends BiomeSource> getCodec() {
|
||||
protected MapCodec<? extends BiomeSource> getCodec() {
|
||||
return Codecs.TERRA_BIOME_SOURCE;
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -64,8 +64,8 @@ public class MinecraftWorldHandle implements WorldHandle {
|
||||
|
||||
@Override
|
||||
public @NotNull EntityType getEntity(@NotNull String id) {
|
||||
if(!id.contains(":")) { //TODO: remove in 7.0
|
||||
String newid = "minecraft:" + id.toLowerCase();
|
||||
if (!id.contains(":")) { //TODO: remove in 7.0
|
||||
String newid = "minecraft:" + id.toLowerCase();;
|
||||
logger.warn(
|
||||
"Translating " + id + " to " + newid + ". In 1.20.3 entity parsing was reworked" +
|
||||
". You are advised to perform this rename in your config packs as this translation will be removed in the next major " +
|
||||
|
||||
-42
@@ -1,42 +0,0 @@
|
||||
package com.dfsek.terra.mod.implmentation;
|
||||
|
||||
import net.minecraft.util.math.intprovider.IntProvider;
|
||||
import net.minecraft.util.math.intprovider.IntProviderType;
|
||||
import net.minecraft.util.math.random.Random;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.dfsek.terra.api.util.Range;
|
||||
import com.dfsek.terra.mod.util.MinecraftAdapter;
|
||||
|
||||
|
||||
public class TerraIntProvider extends IntProvider {
|
||||
public static final Map<Class, IntProviderType> TERRA_RANGE_TYPE_TO_INT_PROVIDER_TYPE = new HashMap<>();
|
||||
|
||||
public Range delegate;
|
||||
|
||||
public TerraIntProvider(Range delegate) {
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int get(Random random) {
|
||||
return delegate.get(MinecraftAdapter.adapt(random));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMin() {
|
||||
return delegate.getMin();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMax() {
|
||||
return delegate.getMax();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IntProviderType<?> getType() {
|
||||
return TERRA_RANGE_TYPE_TO_INT_PROVIDER_TYPE.get(delegate.getClass());
|
||||
}
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
package com.dfsek.terra.mod.mixin.fix;
|
||||
|
||||
import net.minecraft.world.gen.structure.NetherFossilStructure;
|
||||
import net.minecraft.world.gen.structure.Structure.Context;
|
||||
import net.minecraft.world.gen.structure.Structure.StructurePosition;
|
||||
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.Optional;
|
||||
|
||||
import com.dfsek.terra.mod.generation.MinecraftChunkGeneratorWrapper;
|
||||
|
||||
|
||||
/**
|
||||
* Disable fossil generation in Terra worlds, as they are very expensive due to consistently triggering cache misses.
|
||||
* <p>
|
||||
* Currently, on Fabric, Terra cannot be specified as a Nether generator. TODO: logic to turn fossils back on if chunk generator is in
|
||||
* nether.
|
||||
*/
|
||||
@Mixin(NetherFossilStructure.class)
|
||||
public class NetherFossilOptimization {
|
||||
@Inject(method = "getStructurePosition", at = @At("HEAD"), cancellable = true)
|
||||
public void injectFossilPositions(Context context, CallbackInfoReturnable<Optional<StructurePosition>> cir) {
|
||||
if(context.chunkGenerator() instanceof MinecraftChunkGeneratorWrapper) {
|
||||
cir.setReturnValue(Optional.empty());
|
||||
}
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user