mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2025-07-03 16:35:50 +00:00
Compare commits
16 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
853ac3894f | ||
|
6e1cf90ef3 | ||
|
4dc1c96baa | ||
|
de3b9ea7ad | ||
|
d1592422ea | ||
|
028765c91b | ||
|
b3e43321b5 | ||
|
76d3e29d55 | ||
|
a73767ca75 | ||
|
06a13f8757 | ||
|
f8599fd564 | ||
|
ee96e2c9ef | ||
|
cb3bab2293 | ||
|
176e1133f3 | ||
|
ca1531c7ab | ||
|
03c3b666b0 |
39
.github/workflows/build.yml
vendored
Normal file
39
.github/workflows/build.yml
vendored
Normal file
@ -0,0 +1,39 @@
|
||||
# This workflow will build a Java project with Gradle
|
||||
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle
|
||||
|
||||
name: Java CI with Gradle
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- "v*" # Push events to matching v*, i.e. v1.0, v20.15.10
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- name: Set up JDK 1.8
|
||||
uses: actions/setup-java@v1
|
||||
with:
|
||||
java-version: 1.8
|
||||
|
||||
- name: Build Terra
|
||||
run: ./gradlew build -x test && ./gradlew build -x test
|
||||
|
||||
- name: Upload artifacts
|
||||
uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: Package
|
||||
path: build/libs
|
||||
|
||||
- name: Publish release
|
||||
uses: marvinpinto/action-automatic-releases@latest
|
||||
with:
|
||||
repo_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
prerelease: false
|
||||
files: |
|
||||
build/libs/Terra-*-shaded.jar
|
||||
|
10
.idea/jarRepositories.xml
generated
10
.idea/jarRepositories.xml
generated
@ -81,5 +81,15 @@
|
||||
<option name="name" value="MavenLocal" />
|
||||
<option name="url" value="file:$MAVEN_REPOSITORY$/" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="maven5" />
|
||||
<option name="name" value="maven5" />
|
||||
<option name="url" value="https://maven.pkg.github.com/solonovamax/Gaea" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="MavenRepo" />
|
||||
<option name="name" value="MavenRepo" />
|
||||
<option name="url" value="https://repo.maven.apache.org/maven2/" />
|
||||
</remote-repository>
|
||||
</component>
|
||||
</project>
|
5
.idea/vcs.xml
generated
5
.idea/vcs.xml
generated
@ -1,5 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CommitMessageInspectionProfile">
|
||||
<profile version="1.0">
|
||||
<inspection_tool class="GrazieCommit" enabled="true" level="TYPO" enabled_by_default="true" />
|
||||
</profile>
|
||||
</component>
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="Git" />
|
||||
</component>
|
||||
|
@ -96,10 +96,32 @@ tasks.test {
|
||||
maxParallelForks = 12
|
||||
}
|
||||
|
||||
val downloadDefaultPacks = tasks.create("downloadDefaultPacks") {
|
||||
doFirst {
|
||||
file("${buildDir}/resources/main/packs/").deleteRecursively()
|
||||
|
||||
val defaultPackUrl = URL("https://github.com/PolyhedralDev/TerraDefaultConfig/releases/download/latest/default.zip")
|
||||
downloadAndUnzipPack(defaultPackUrl)
|
||||
val netherPackUrl = URL("https://github.com/PolyhedralDev/TerraDefaultConfig/releases/download/latest/nether.zip")
|
||||
downloadAndUnzipPack(netherPackUrl)
|
||||
}
|
||||
|
||||
file("${buildDir}/resources/main/packs/").deleteRecursively()
|
||||
|
||||
val defaultPackUrl = URL("https://github.com/PolyhedralDev/TerraDefaultConfig/releases/download/latest/default.zip")
|
||||
downloadAndUnzipPack(defaultPackUrl)
|
||||
val netherPackUrl = URL("https://github.com/PolyhedralDev/TerraDefaultConfig/releases/download/latest/nether.zip")
|
||||
downloadAndUnzipPack(netherPackUrl)
|
||||
}
|
||||
tasks.compileJava {
|
||||
dependsOn(downloadDefaultPacks)
|
||||
}
|
||||
|
||||
tasks.named<ShadowJar>("shadowJar") {
|
||||
from(tokenizeJavaSources.destinationDir)
|
||||
dependsOn(downloadDefaultPacks)
|
||||
|
||||
archiveClassifier.set("")
|
||||
archiveClassifier.set("shaded")
|
||||
archiveBaseName.set("Terra")
|
||||
setVersion(project.version)
|
||||
relocate("org.apache.commons", "com.dfsek.terra.lib.commons")
|
||||
@ -107,13 +129,9 @@ tasks.named<ShadowJar>("shadowJar") {
|
||||
relocate("parsii", "com.dfsek.terra.lib.parsii")
|
||||
relocate("io.papermc.lib", "com.dfsek.terra.lib.paperlib")
|
||||
relocate("net.jafama", "com.dfsek.terra.lib.jafama")
|
||||
minimize()
|
||||
minimize {
|
||||
exclude(project(":"))
|
||||
}
|
||||
|
||||
tasks.build {
|
||||
dependsOn(tasks.shadowJar)
|
||||
// dependsOn(testWithPaper)
|
||||
// testWithPaper.mustRunAfter(tasks.shadowJar)
|
||||
}
|
||||
|
||||
val testDir = "target/server/"
|
||||
@ -152,21 +170,14 @@ val setupServer = tasks.create("setupServer") {
|
||||
}
|
||||
}
|
||||
|
||||
val downloadDefaultPacks = tasks.create("downloadDefaultPacks") {
|
||||
doFirst {
|
||||
// Downloading latest paper jar.
|
||||
// if (file("${buildDir}/resources/main/packs/default").exists() && file("${buildDir}/resources/main/packs/nether").exists())
|
||||
// return@doFirst
|
||||
// else
|
||||
file("${buildDir}/resources/main/packs/").deleteRecursively()
|
||||
tasks.build {
|
||||
dependsOn(tasks.shadowJar)
|
||||
dependsOn(downloadDefaultPacks)
|
||||
tasks.shadowJar.get().mustRunAfter(downloadDefaultPacks)
|
||||
// dependsOn(testWithPaper)
|
||||
// testWithPaper.mustRunAfter(tasks.shadowJar)
|
||||
}
|
||||
|
||||
val defaultPackUrl = URL("https://github.com/PolyhedralDev/TerraDefaultConfig/releases/download/latest/default.zip")
|
||||
downloadAndUnzipPack(defaultPackUrl)
|
||||
val netherPackUrl = URL("https://github.com/PolyhedralDev/TerraDefaultConfig/releases/download/latest/nether.zip")
|
||||
downloadAndUnzipPack(netherPackUrl)
|
||||
}
|
||||
}
|
||||
tasks.processResources.get().dependsOn(downloadDefaultPacks)
|
||||
|
||||
val testWithPaper = task<JavaExec>(name = "testWithPaper") {
|
||||
standardInput = System.`in`
|
||||
|
@ -5,26 +5,56 @@ import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
public abstract class TerraConfig extends YamlConfiguration {
|
||||
@SuppressWarnings("unused")
|
||||
public abstract class TerraConfig {
|
||||
protected final YamlConfiguration yaml;
|
||||
private final ConfigPack config;
|
||||
protected String id;
|
||||
|
||||
/**
|
||||
* Constructs a new Terra config with a file, config pack and Id.
|
||||
*
|
||||
* @param file The file to use when constructing the config.
|
||||
* @param config The config reference.
|
||||
* @param id The id of the object.
|
||||
* @throws IOException
|
||||
* @throws InvalidConfigurationException
|
||||
* @deprecated Deprecated because you should use {@link #TerraConfig(InputStream, ConfigPack, String)}
|
||||
*/
|
||||
@Deprecated
|
||||
public TerraConfig(File file, ConfigPack config) throws IOException, InvalidConfigurationException {
|
||||
load(file);
|
||||
this(new FileInputStream(file), config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new Terra config with an input stream, config pack and Id.
|
||||
*
|
||||
* @param stream The input stream to use when constructing the config.
|
||||
* @param config The config reference.
|
||||
* @param id The id of the object.
|
||||
* @throws IOException
|
||||
* @throws InvalidConfigurationException
|
||||
*/
|
||||
public TerraConfig(InputStream stream, ConfigPack config) throws IOException, InvalidConfigurationException {
|
||||
yaml = new YamlConfiguration();
|
||||
yaml.load(new InputStreamReader(stream));
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
public TerraConfig(InputStream stream, ConfigPack config) throws IOException, InvalidConfigurationException {
|
||||
load(new InputStreamReader(stream));
|
||||
this.config = config;
|
||||
public YamlConfiguration getYaml() {
|
||||
return yaml;
|
||||
}
|
||||
|
||||
public ConfigPack getConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
public abstract String getID();
|
||||
public String getID() {
|
||||
return id;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,43 @@
|
||||
package com.dfsek.terra.config.deserealized;
|
||||
|
||||
import com.dfsek.terra.carving.UserDefinedCarver;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.polydev.gaea.math.ProbabilityCollection;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
public class Carver implements Generateable {
|
||||
private UserDefinedCarver carver;
|
||||
private String id;
|
||||
private Set<Material> update;
|
||||
private Map<Material, Set<Material>> shift;
|
||||
private Map<Integer, ProbabilityCollection<BlockData>> inner;
|
||||
private Map<Integer, ProbabilityCollection<BlockData>> outer;
|
||||
private Map<Integer, ProbabilityCollection<BlockData>> top;
|
||||
private Map<Integer, ProbabilityCollection<BlockData>> bottom;
|
||||
private boolean updateOcean;
|
||||
private boolean replaceIsBlacklistInner;
|
||||
private boolean replaceIsBlacklistOuter;
|
||||
private boolean replaceIsBlacklistTop;
|
||||
private boolean replaceIsBlacklistBottom;
|
||||
private Set<Material> replaceableInner;
|
||||
private Set<Material> replaceableOuter;
|
||||
private Set<Material> replaceableTop;
|
||||
private Set<Material> replaceableBottom;
|
||||
|
||||
@Override
|
||||
public void generate(Location location, Random random, JavaPlugin plugin) {
|
||||
//TODO
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValidLocation(Location location, JavaPlugin plugin) {
|
||||
return false;
|
||||
//TODO
|
||||
}
|
||||
}
|
97
src/main/java/com/dfsek/terra/config/deserealized/Flora.java
Normal file
97
src/main/java/com/dfsek/terra/config/deserealized/Flora.java
Normal file
@ -0,0 +1,97 @@
|
||||
package com.dfsek.terra.config.deserealized;
|
||||
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.polydev.gaea.math.Range;
|
||||
import org.polydev.gaea.world.palette.Palette;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
public class Flora implements Generateable, org.polydev.gaea.world.Flora {
|
||||
private final Palette<BlockData> floraPalette;
|
||||
private final String id;
|
||||
private final boolean physics;
|
||||
private final boolean ceiling;
|
||||
private final Set<Material> irrigable;
|
||||
private final Set<Material> spawnable;
|
||||
private final Set<Material> replaceable;
|
||||
|
||||
public Flora(Palette<BlockData> floraPalette, String id, boolean physics, boolean ceiling, Set<Material> irrigable, Set<Material> spawnable, Set<Material> replaceable) {
|
||||
this.floraPalette = floraPalette;
|
||||
this.id = id;
|
||||
this.physics = physics;
|
||||
this.ceiling = ceiling;
|
||||
this.irrigable = irrigable;
|
||||
this.spawnable = spawnable;
|
||||
this.replaceable = replaceable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void generate(Location location, Random random, JavaPlugin plugin) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValidLocation(Location location, JavaPlugin plugin) {
|
||||
Block check = location.getBlock();
|
||||
if(ceiling) {
|
||||
Block other = check.getRelative(BlockFace.DOWN);
|
||||
return spawnable.contains(check.getType()) && replaceable.contains(other.getType());
|
||||
} else {
|
||||
Block other = check.getRelative(BlockFace.UP);
|
||||
return spawnable.contains(check.getType()) && replaceable.contains(other.getType()) && isIrrigated(check);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Block> getValidSpawnsAt(Chunk chunk, int x, int z, Range range) {
|
||||
List<Block> blocks = new ArrayList<>();
|
||||
if(ceiling) for(int y : range) {
|
||||
if(y > 255 || y < 1) continue;
|
||||
Block check = chunk.getBlock(x, y, z);
|
||||
if(isValidLocation(check.getLocation(), null)) {
|
||||
blocks.add(check);
|
||||
}
|
||||
}
|
||||
else for(int y : range) {
|
||||
if(y > 254 || y < 0) continue;
|
||||
Block check = chunk.getBlock(x, y, z);
|
||||
if(isValidLocation(check.getLocation(), null)) {
|
||||
blocks.add(check);
|
||||
}
|
||||
}
|
||||
return blocks;
|
||||
}
|
||||
|
||||
private boolean isIrrigated(Block b) {
|
||||
if(irrigable == null) return true;
|
||||
return irrigable.contains(b.getRelative(BlockFace.NORTH).getType())
|
||||
|| irrigable.contains(b.getRelative(BlockFace.SOUTH).getType())
|
||||
|| irrigable.contains(b.getRelative(BlockFace.EAST).getType())
|
||||
|| irrigable.contains(b.getRelative(BlockFace.WEST).getType());
|
||||
}
|
||||
|
||||
@SuppressWarnings("DuplicatedCode")
|
||||
@Override
|
||||
public boolean plant(Location location) {
|
||||
int size = floraPalette.getSize();
|
||||
int c = ceiling ? -1 : 1;
|
||||
for(int i = 0; Math.abs(i) < size; i += c) { // Down if ceiling, up if floor
|
||||
if(i + 1 > 255) return false;
|
||||
if(!replaceable.contains(location.clone().add(0, i + c, 0).getBlock().getType())) return false;
|
||||
}
|
||||
for(int i = 0; Math.abs(i) < size; i += c) { // Down if ceiling, up if floor
|
||||
int lvl = (Math.abs(i));
|
||||
location.clone().add(0, i + c, 0).getBlock().setBlockData(floraPalette.get((ceiling ? lvl : size - lvl - 1), location.getBlockX(), location.getBlockZ()), physics);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package com.dfsek.terra.config.deserealized;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public interface Generateable {
|
||||
void generate(Location location, Random random, JavaPlugin plugin);
|
||||
|
||||
boolean isValidLocation(Location location, JavaPlugin plugin);
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
package com.dfsek.terra.config.deserealized;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.polydev.gaea.math.FastNoiseLite;
|
||||
import org.polydev.gaea.population.ChunkCoordinate;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
@SuppressWarnings("DefaultAnnotationParam")
|
||||
@JsonDeserialize(using = JsonDeserializer.None.class)
|
||||
public class MultiChunkOre extends Ore {
|
||||
protected int min;
|
||||
protected int max;
|
||||
|
||||
@Override
|
||||
public void generate(Location location, Random random, JavaPlugin plugin) {
|
||||
FastNoiseLite noise = new FastNoiseLite(random.nextInt());
|
||||
noise.setNoiseType(FastNoiseLite.NoiseType.OpenSimplex2);
|
||||
noise.setFrequency(deformFrequency);
|
||||
|
||||
Chunk chunk = location.getChunk();
|
||||
|
||||
int rad = randomInRange(random, min, max);
|
||||
Map<ChunkCoordinate, Chunk> chunks = new HashMap<>(); // Cache chunks to prevent re-loading chunks every time one is needed.
|
||||
chunks.put(new ChunkCoordinate(chunk), chunk);
|
||||
for(int x = -rad; x <= rad; x++) {
|
||||
for(int y = -rad; y <= rad; y++) {
|
||||
for(int z = -rad; z <= rad; z++) {
|
||||
Vector origin = location.toVector();
|
||||
Vector source = origin.clone().add(new Vector(x, y, z));
|
||||
|
||||
Vector orig = new Vector(location.getBlockX() + (chunk.getX() << 4), location.getBlockY(), location.getBlockZ() + (chunk.getZ() << 4));
|
||||
Vector oreLocation = orig.clone().add(new Vector(x, y, z));
|
||||
|
||||
if(oreLocation.getBlockY() > 255 || oreLocation.getBlockY() < 0)
|
||||
continue;
|
||||
if(source.distance(origin) < (rad + 0.5) * ((noise.getNoise(x, y, z) + 1) * deform)) {
|
||||
ChunkCoordinate coord = new ChunkCoordinate(Math.floorDiv(oreLocation.getBlockX(), 16), Math.floorDiv(oreLocation.getBlockZ(), 16), chunk.getWorld().getUID());
|
||||
|
||||
Block block = chunks.computeIfAbsent(coord, k -> chunk.getWorld().getChunkAt(oreLocation.toLocation(chunk.getWorld())))
|
||||
.getBlock(Math.floorMod(source.getBlockX(), 16), source.getBlockY(), Math.floorMod(source.getBlockZ(), 16)); // Chunk caching conditional computation
|
||||
if(replaceable.contains(block.getType()) && block.getLocation().getY() >= 0)
|
||||
block.setBlockData(material, update);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
64
src/main/java/com/dfsek/terra/config/deserealized/Ore.java
Normal file
64
src/main/java/com/dfsek/terra/config/deserealized/Ore.java
Normal file
@ -0,0 +1,64 @@
|
||||
package com.dfsek.terra.config.deserealized;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.annotation.JsonSubTypes;
|
||||
import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* This selects which value based on whether the key {@code type} is
|
||||
* {@code multi}, {@code single}, or {@code vanilla}.
|
||||
*/
|
||||
@SuppressWarnings("DefaultAnnotationParam")
|
||||
@JsonTypeInfo(
|
||||
use = JsonTypeInfo.Id.CLASS,
|
||||
include = JsonTypeInfo.As.PROPERTY,
|
||||
property = "type"
|
||||
)
|
||||
@JsonSubTypes({
|
||||
@JsonSubTypes.Type(value = MultiChunkOre.class, name = "multi"),
|
||||
@JsonSubTypes.Type(value = SingleChunkOre.class, name = "single"),
|
||||
@JsonSubTypes.Type(value = VanillaOre.class, name = "vanilla")
|
||||
})
|
||||
public abstract class Ore implements Generateable {
|
||||
protected BlockData material;
|
||||
protected double deform = 0.75;
|
||||
@JsonProperty("deform-frequency")
|
||||
protected double deformFrequency = 0.1;
|
||||
protected String id;
|
||||
protected boolean update = false;
|
||||
@JsonProperty("chunk-edge-offset")
|
||||
protected int chunkEdgeOffset = 0;
|
||||
@JsonProperty("replace")
|
||||
protected Set<Material> replaceable;
|
||||
|
||||
public int getChunkEdgeOffset() {
|
||||
return chunkEdgeOffset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate an ore.
|
||||
*
|
||||
* @param location Location to generate the ore at.
|
||||
* @param random Random used for generation.
|
||||
* @param plugin Plugin reference.
|
||||
*/
|
||||
@Override
|
||||
public abstract void generate(Location location, Random random, JavaPlugin plugin);
|
||||
|
||||
public boolean isValidLocation(Location location, JavaPlugin plugin) {
|
||||
Block block = location.getBlock();
|
||||
return (replaceable.contains(block.getType()) && (block.getLocation().getY() >= 0));
|
||||
}
|
||||
|
||||
protected int randomInRange(Random r, int min, int max) {
|
||||
return r.nextInt(max - min + 1) + min;
|
||||
}
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
package com.dfsek.terra.config.deserealized;
|
||||
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.polydev.gaea.math.FastNoiseLite;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class SingleChunkOre extends Ore {
|
||||
protected int min = 0;
|
||||
protected int max = 255;
|
||||
|
||||
@Override
|
||||
public void generate(Location location, Random random, JavaPlugin plugin) {
|
||||
FastNoiseLite noise = new FastNoiseLite(random.nextInt());
|
||||
noise.setNoiseType(FastNoiseLite.NoiseType.OpenSimplex2);
|
||||
noise.setFrequency(deformFrequency);
|
||||
|
||||
Chunk chunk = location.getChunk();
|
||||
|
||||
int rad = randomInRange(random, min, max);
|
||||
for(int x = -rad; x <= rad; x++) {
|
||||
for(int y = -rad; y <= rad; y++) {
|
||||
for(int z = -rad; z <= rad; z++) {
|
||||
Vector oreLoc = location.toVector().clone().add(new Vector(x, y, z));
|
||||
if(oreLoc.getBlockX() > 15 || oreLoc.getBlockZ() > 15 || oreLoc.getBlockY() > 255 || oreLoc.getBlockX() < 0 || oreLoc.getBlockZ() < 0 || oreLoc.getBlockY() < 0)
|
||||
continue;
|
||||
if(oreLoc.distance(location.toVector()) < (rad + 0.5) * ((noise.getNoise(x, y, z) + 1) * deform)) {
|
||||
Block b = chunk.getBlock(oreLoc.getBlockX(), oreLoc.getBlockY(), oreLoc.getBlockZ());
|
||||
if(replaceable.contains(b.getType()) && b.getLocation().getY() >= 0)
|
||||
b.setBlockData(material, update);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
40
src/main/java/com/dfsek/terra/config/deserealized/Tree.java
Normal file
40
src/main/java/com/dfsek/terra/config/deserealized/Tree.java
Normal file
@ -0,0 +1,40 @@
|
||||
package com.dfsek.terra.config.deserealized;
|
||||
|
||||
import com.dfsek.terra.structure.Rotation;
|
||||
import com.dfsek.terra.structure.Structure;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.polydev.gaea.math.ProbabilityCollection;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
@SuppressWarnings({"unused", "SpellCheckingInspection", "MismatchedQueryAndUpdateOfCollection"})
|
||||
public class Tree implements Generateable {
|
||||
private Set<Material> spawnable;
|
||||
private String id;
|
||||
@JsonProperty("y-offset")
|
||||
private int yOffset;
|
||||
@JsonProperty("files")
|
||||
private ProbabilityCollection<Structure> structure;
|
||||
|
||||
@Override
|
||||
public void generate(Location location, Random random, JavaPlugin plugin) {
|
||||
location.subtract(0, 1, 0);
|
||||
Location mut = location.clone().subtract(0, yOffset, 0);
|
||||
if(!spawnable.contains(location.getBlock().getType()))
|
||||
return;
|
||||
Structure structure = this.structure.get(random);
|
||||
Rotation rotation = Rotation.fromDegrees(random.nextInt(4) * 90);
|
||||
if(!structure.checkSpawns(mut, rotation))
|
||||
return;
|
||||
structure.paste(mut, rotation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValidLocation(Location location, JavaPlugin plugin) {
|
||||
return spawnable.contains(location.getBlock().getType());
|
||||
}
|
||||
}
|
@ -0,0 +1,77 @@
|
||||
package com.dfsek.terra.config.deserealized;
|
||||
|
||||
import net.royawesome.jlibnoise.MathHelper;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.polydev.gaea.world.Ore;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class VanillaOre extends Ore {
|
||||
private int size;
|
||||
|
||||
/**
|
||||
* TODO: what the fuck does half of this do?
|
||||
*
|
||||
* @param location
|
||||
* @param random
|
||||
* @param plugin
|
||||
*/
|
||||
@Override
|
||||
public void generate(Location location, Random random, JavaPlugin plugin) {
|
||||
Chunk chunk = location.getChunk();
|
||||
|
||||
int centerX = location.getBlockX();
|
||||
int centerZ = location.getBlockZ();
|
||||
int centerY = location.getBlockY();
|
||||
|
||||
|
||||
float f = random.nextFloat() * (float) Math.PI;
|
||||
|
||||
double d1 = centerX + 8 + MathHelper.sin(f) * size / 8.0F;
|
||||
double d2 = centerX + 8 - MathHelper.sin(f) * size / 8.0F;
|
||||
double d3 = centerZ + 8 + MathHelper.cos(f) * size / 8.0F;
|
||||
double d4 = centerZ + 8 - MathHelper.cos(f) * size / 8.0F;
|
||||
|
||||
double d5 = centerY + random.nextInt(3) - 2;
|
||||
double d6 = centerY + random.nextInt(3) - 2;
|
||||
|
||||
for(int i = 0; i < size; i++) {
|
||||
float iFactor = (float) i / (float) size;
|
||||
|
||||
double d10 = random.nextDouble() * size / 16.0D;
|
||||
double d11 = (MathHelper.sin((float) Math.PI * iFactor) + 1.0) * d10 + 1.0;
|
||||
double d12 = (MathHelper.sin((float) Math.PI * iFactor) + 1.0) * d10 + 1.0;
|
||||
|
||||
int xStart = MathHelper.floor(d1 + (d2 - d1) * iFactor - d11 / 2.0D);
|
||||
int yStart = MathHelper.floor(d5 + (d6 - d5) * iFactor - d12 / 2.0D);
|
||||
int zStart = MathHelper.floor(d3 + (d4 - d3) * iFactor - d11 / 2.0D);
|
||||
|
||||
int xEnd = MathHelper.floor(d1 + (d2 - d1) * iFactor + d11 / 2.0D);
|
||||
int yEnd = MathHelper.floor(d5 + (d6 - d5) * iFactor + d12 / 2.0D);
|
||||
int zEnd = MathHelper.floor(d3 + (d4 - d3) * iFactor + d11 / 2.0D);
|
||||
|
||||
for(int x = xStart; x <= xEnd; x++) {
|
||||
double d13 = (x + 0.5D - (d1 + (d2 - d1) * iFactor)) / (d11 / 2.0D);
|
||||
|
||||
if(d13 * d13 < 1.0D) {
|
||||
for(int y = yStart; y <= yEnd; y++) {
|
||||
double d14 = (y + 0.5D - (d5 + (d6 - d5) * iFactor)) / (d12 / 2.0D);
|
||||
if(d13 * d13 + d14 * d14 < 1.0D) {
|
||||
for(int z = zStart; z <= zEnd; z++) {
|
||||
double d15 = (z + 0.5D - (d3 + (d4 - d3) * iFactor)) / (d11 / 2.0D);
|
||||
Block block = chunk.getBlock(x, y, z);
|
||||
if((d13 * d13 + d14 * d14 + d15 * d15 < 1.0D) && replaceable.contains(block.getType())) {
|
||||
block.setBlockData(material, update);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -24,20 +24,19 @@ public class BiomeGridConfig extends TerraConfig {
|
||||
@SuppressWarnings("unchecked")
|
||||
public BiomeGridConfig(File file, ConfigPack config) throws IOException, InvalidConfigurationException {
|
||||
super(file, config);
|
||||
load(file);
|
||||
if(!contains("id")) throw new ConfigException("Grid ID unspecified!", "null");
|
||||
this.gridID = getString("id");
|
||||
if(!contains("grid")) throw new ConfigException("Grid key not found!", getID());
|
||||
this.sizeX = Objects.requireNonNull(getList("grid")).size();
|
||||
this.sizeZ = ((List<List<String>>) Objects.requireNonNull(getList("grid"))).get(0).size();
|
||||
if(!yaml.contains("id")) throw new ConfigException("Grid ID unspecified!", "null");
|
||||
this.gridID = yaml.getString("id");
|
||||
if(!yaml.contains("grid")) throw new ConfigException("Grid key not found!", getID());
|
||||
this.sizeX = Objects.requireNonNull(yaml.getList("grid")).size();
|
||||
this.sizeZ = ((List<List<String>>) Objects.requireNonNull(yaml.getList("grid"))).get(0).size();
|
||||
gridRaw = new UserDefinedBiome[sizeX][sizeZ];
|
||||
try {
|
||||
for(int x = 0; x < sizeX; x++) {
|
||||
for(int z = 0; z < sizeZ; z++) {
|
||||
try {
|
||||
gridRaw[x][z] = config.getBiome(((List<List<String>>) Objects.requireNonNull(getList("grid"))).get(x).get(z)).getBiome();
|
||||
gridRaw[x][z] = config.getBiome(((List<List<String>>) Objects.requireNonNull(yaml.getList("grid"))).get(x).get(z)).getBiome();
|
||||
} catch(NullPointerException e) {
|
||||
throw new NotFoundException("Biome", ((List<List<String>>) Objects.requireNonNull(getList("grid"))).get(x).get(z), getID());
|
||||
throw new NotFoundException("Biome", ((List<List<String>>) Objects.requireNonNull(yaml.getList("grid"))).get(x).get(z), getID());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -35,13 +35,13 @@ public class TreeConfig extends TerraConfig implements Tree {
|
||||
|
||||
public TreeConfig(File file, ConfigPack config) throws IOException, InvalidConfigurationException {
|
||||
super(file, config);
|
||||
spawnable = ConfigUtil.toBlockData(getStringList("spawnable"), "spawnable", getID());
|
||||
if(!contains("id")) throw new ConfigException("No ID specified!", "null");
|
||||
id = getString("id");
|
||||
if(!contains("files")) throw new ConfigException("No files specified!", getID());
|
||||
yOffset = getInt("y-offset", 0);
|
||||
spawnable = ConfigUtil.toBlockData(yaml.getStringList("spawnable"), "spawnable", getID());
|
||||
if(!yaml.contains("id")) throw new ConfigException("No ID specified!", "null");
|
||||
id = yaml.getString("id");
|
||||
if(!yaml.contains("files")) throw new ConfigException("No files specified!", getID());
|
||||
yOffset = yaml.getInt("y-offset", 0);
|
||||
try {
|
||||
for(Map.Entry<String, Object> e : Objects.requireNonNull(getConfigurationSection("files")).getValues(false).entrySet()) {
|
||||
for(Map.Entry<String, Object> e : Objects.requireNonNull(yaml.getConfigurationSection("files")).getValues(false).entrySet()) {
|
||||
try {
|
||||
File structureFile = new File(config.getDataFolder() + File.separator + "trees" + File.separator + "data", e.getKey() + ".tstructure");
|
||||
structure.add(Structure.load(structureFile), (Integer) e.getValue());
|
||||
@ -57,7 +57,7 @@ public class TreeConfig extends TerraConfig implements Tree {
|
||||
if(ConfigUtil.debug) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
throw new NotFoundException("Tree Structure", getString("file"), getID());
|
||||
throw new NotFoundException("Tree Structure", yaml.getString("file"), getID());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -25,30 +25,29 @@ public class AbstractBiomeConfig extends TerraConfig {
|
||||
|
||||
public AbstractBiomeConfig(File file, ConfigPack config) throws IOException, InvalidConfigurationException {
|
||||
super(file, config);
|
||||
load(file);
|
||||
if(!contains("id")) throw new ConfigException("Abstract Biome ID unspecified!", "null");
|
||||
this.biomeID = getString("id");
|
||||
if(!yaml.contains("id")) throw new ConfigException("Abstract Biome ID unspecified!", "null");
|
||||
this.biomeID = yaml.getString("id");
|
||||
|
||||
equation = getString("noise-equation");
|
||||
seaLevel = getInt("ocean.level", 62);
|
||||
equation = yaml.getString("noise-equation");
|
||||
seaLevel = yaml.getInt("ocean.level", 62);
|
||||
|
||||
if(contains("carving")) carving = new BiomeCarverConfig(this);
|
||||
if(yaml.contains("carving")) carving = new BiomeCarverConfig(this);
|
||||
|
||||
if(contains("palette")) palette = new BiomePaletteConfig(this, "palette");
|
||||
if(yaml.contains("palette")) palette = new BiomePaletteConfig(this, "palette");
|
||||
|
||||
if(contains("flora")) flora = new BiomeFloraConfig(this);
|
||||
if(yaml.contains("flora")) flora = new BiomeFloraConfig(this);
|
||||
|
||||
if(contains("trees")) trees = new BiomeTreeConfig(this);
|
||||
if(yaml.contains("trees")) trees = new BiomeTreeConfig(this);
|
||||
|
||||
if(contains("ores")) ores = new BiomeOreConfig(this);
|
||||
if(yaml.contains("ores")) ores = new BiomeOreConfig(this);
|
||||
|
||||
if(contains("ocean")) ocean = new BiomeOceanConfig(this);
|
||||
if(yaml.contains("ocean")) ocean = new BiomeOceanConfig(this);
|
||||
|
||||
if(contains("slabs") && getBoolean("slabs.enable", false)) slabs = new BiomeSlabConfig(this);
|
||||
if(yaml.contains("slabs") && yaml.getBoolean("slabs.enable", false)) slabs = new BiomeSlabConfig(this);
|
||||
|
||||
if(contains("structures")) structureConfigs = getStringList("structures");
|
||||
if(yaml.contains("structures")) structureConfigs = yaml.getStringList("structures");
|
||||
|
||||
if(contains("snow")) snow = new BiomeSnowConfig(this);
|
||||
if(yaml.contains("snow")) snow = new BiomeSnowConfig(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -17,7 +17,7 @@ public class BiomeCarverConfig extends TerraConfigSection {
|
||||
|
||||
public BiomeCarverConfig(TerraConfig parent) throws InvalidConfigurationException {
|
||||
super(parent);
|
||||
ConfigurationSection configurationSection = parent.getConfigurationSection("carving");
|
||||
ConfigurationSection configurationSection = parent.getYaml().getConfigurationSection("carving");
|
||||
|
||||
Map<String, Object> cfg;
|
||||
if(configurationSection != null) {
|
||||
|
@ -26,13 +26,13 @@ public class BiomeFloraConfig extends TerraConfigSection {
|
||||
|
||||
public BiomeFloraConfig(TerraConfig parent) throws InvalidConfigurationException {
|
||||
super(parent);
|
||||
ConfigurationSection cfg = parent.getConfigurationSection("flora.items");
|
||||
ConfigurationSection cfg = parent.getYaml().getConfigurationSection("flora.items");
|
||||
if(cfg == null) return;
|
||||
floraSimplex = parent.getBoolean("flora.simplex.enable", false);
|
||||
floraAttempts = parent.getInt("flora.attempts", 1);
|
||||
floraChance = parent.getInt("flora.chance", 0);
|
||||
double floraFreq = parent.getDouble("flora.simplex.frequency", 0.1);
|
||||
int floraSeed = parent.getInt("flora.simplex.seed", 2403);
|
||||
floraSimplex = parent.getYaml().getBoolean("flora.simplex.enable", false);
|
||||
floraAttempts = parent.getYaml().getInt("flora.attempts", 1);
|
||||
floraChance = parent.getYaml().getInt("flora.chance", 0);
|
||||
double floraFreq = parent.getYaml().getDouble("flora.simplex.frequency", 0.1);
|
||||
int floraSeed = parent.getYaml().getInt("flora.simplex.seed", 2403);
|
||||
if(floraSimplex) {
|
||||
floraNoise = new FastNoiseLite(floraSeed);
|
||||
floraNoise.setNoiseType(FastNoiseLite.NoiseType.OpenSimplex2);
|
||||
|
@ -21,8 +21,8 @@ public class BiomeOceanConfig extends TerraConfigSection {
|
||||
|
||||
public BiomeOceanConfig(@NotNull TerraConfig parent) throws InvalidConfigurationException {
|
||||
super(parent);
|
||||
seaLevel = parent.getInt("ocean.level", 62);
|
||||
String oceanN = parent.getString("ocean.palette");
|
||||
seaLevel = parent.getYaml().getInt("ocean.level", 62);
|
||||
String oceanN = parent.getYaml().getString("ocean.palette");
|
||||
if(oceanN != null) {
|
||||
if(oceanN.startsWith("BLOCK:")) {
|
||||
try {
|
||||
|
@ -19,7 +19,7 @@ public class BiomeOreConfig extends TerraConfigSection {
|
||||
|
||||
public BiomeOreConfig(TerraConfig parent) throws InvalidConfigurationException {
|
||||
super(parent);
|
||||
ConfigurationSection c = parent.getConfigurationSection("ores");
|
||||
ConfigurationSection c = parent.getYaml().getConfigurationSection("ores");
|
||||
if(c == null) return;
|
||||
Map<String, Object> cfg = c.getValues(false);
|
||||
try {
|
||||
|
@ -21,7 +21,7 @@ public class BiomePaletteConfig extends TerraConfigSection {
|
||||
|
||||
public BiomePaletteConfig(TerraConfig parent, String key) throws InvalidConfigurationException {
|
||||
super(parent);
|
||||
List<Map<?, ?>> cfg = parent.getMapList(key);
|
||||
List<Map<?, ?>> cfg = parent.getYaml().getMapList(key);
|
||||
if(cfg.size() == 0) return;
|
||||
paletteMap = new TreeMap<>();
|
||||
for(Map<?, ?> e : cfg) {
|
||||
|
@ -27,10 +27,10 @@ public class BiomeSlabConfig extends TerraConfigSection {
|
||||
|
||||
public BiomeSlabConfig(@NotNull TerraConfig parent) throws InvalidConfigurationException {
|
||||
super(parent);
|
||||
slabThreshold = parent.getDouble("slabs.threshold", 0.1D);
|
||||
slabs = getSlabPalettes(parent.getMapList("slabs.palettes"));
|
||||
if(parent.contains("slabs.stair-palettes") && parent.getBoolean("slabs.use-stairs-if-available", false)) {
|
||||
stairs = getSlabPalettes(parent.getMapList("slabs.stair-palettes"));
|
||||
slabThreshold = parent.getYaml().getDouble("slabs.threshold", 0.1D);
|
||||
slabs = getSlabPalettes(parent.getYaml().getMapList("slabs.palettes"));
|
||||
if(parent.getYaml().contains("slabs.stair-palettes") && parent.getYaml().getBoolean("slabs.use-stairs-if-available", false)) {
|
||||
stairs = getSlabPalettes(parent.getYaml().getMapList("slabs.stair-palettes"));
|
||||
} else stairs = new HashMap<>();
|
||||
}
|
||||
|
||||
|
@ -21,11 +21,11 @@ public class BiomeTreeConfig extends TerraConfigSection {
|
||||
|
||||
public BiomeTreeConfig(TerraConfig parent) throws InvalidConfigurationException {
|
||||
super(parent);
|
||||
ConfigurationSection c = parent.getConfigurationSection("trees.items");
|
||||
ConfigurationSection c = parent.getYaml().getConfigurationSection("trees.items");
|
||||
if(c == null) return;
|
||||
Map<String, Object> cfg = c.getValues(false);
|
||||
if(cfg.size() == 0) return;
|
||||
treeDensity = parent.getInt("trees.density", 0);
|
||||
treeDensity = parent.getYaml().getInt("trees.density", 0);
|
||||
|
||||
for(Map.Entry<String, Object> e : cfg.entrySet()) {
|
||||
try {
|
||||
|
@ -38,11 +38,11 @@ public class StructureConfig extends TerraConfig {
|
||||
@SuppressWarnings("unchecked")
|
||||
public StructureConfig(File file, ConfigPack config) throws IOException, InvalidConfigurationException {
|
||||
super(file, config);
|
||||
if(!contains("id")) throw new ConfigException("No ID specified!", "null");
|
||||
id = getString("id");
|
||||
if(!contains("files")) throw new ConfigException("No files specified!", getID());
|
||||
if(!yaml.contains("id")) throw new ConfigException("No ID specified!", "null");
|
||||
id = yaml.getString("id");
|
||||
if(!yaml.contains("files")) throw new ConfigException("No files specified!", getID());
|
||||
try {
|
||||
for(Map.Entry<String, Object> e : Objects.requireNonNull(getConfigurationSection("files")).getValues(false).entrySet()) {
|
||||
for(Map.Entry<String, Object> e : Objects.requireNonNull(yaml.getConfigurationSection("files")).getValues(false).entrySet()) {
|
||||
try {
|
||||
File structureFile = new File(config.getDataFolder() + File.separator + "structures" + File.separator + "data", e.getKey() + ".tstructure");
|
||||
structure.add(Structure.load(structureFile), (Integer) e.getValue());
|
||||
@ -58,10 +58,10 @@ public class StructureConfig extends TerraConfig {
|
||||
if(ConfigUtil.debug) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
throw new NotFoundException("Structure", getString("file"), getID());
|
||||
throw new NotFoundException("Structure", yaml.getString("file"), getID());
|
||||
}
|
||||
if(contains("loot")) {
|
||||
for(Map.Entry<String, Object> e : Objects.requireNonNull(getConfigurationSection("loot")).getValues(false).entrySet()) {
|
||||
if(yaml.contains("loot")) {
|
||||
for(Map.Entry<String, Object> e : Objects.requireNonNull(yaml.getConfigurationSection("loot")).getValues(false).entrySet()) {
|
||||
File lootFile = new File(config.getDataFolder() + File.separator + "structures" + File.separator + "loot", e.getValue().toString() + ".json");
|
||||
try {
|
||||
loot.put(Integer.valueOf(e.getKey()), new LootTable(FileUtils.readFileToString(lootFile)));
|
||||
@ -80,8 +80,8 @@ public class StructureConfig extends TerraConfig {
|
||||
}
|
||||
|
||||
features = new ArrayList<>();
|
||||
if(contains("features")) {
|
||||
for(Map<?, ?> map : getMapList("features")) {
|
||||
if(yaml.contains("features")) {
|
||||
for(Map<?, ?> map : yaml.getMapList("features")) {
|
||||
for(Map.Entry<?, ?> entry : map.entrySet()) {
|
||||
if(entry.getKey().equals("ENTITY_FEATURE"))
|
||||
features.add(new EntityFeatureConfig((Map<String, Object>) entry.getValue()).getFeature());
|
||||
@ -89,9 +89,9 @@ public class StructureConfig extends TerraConfig {
|
||||
}
|
||||
}
|
||||
|
||||
spawn = new GridSpawn(getInt("spawn.width", 500), getInt("spawn.padding", 100));
|
||||
searchStart = new Range(getInt("spawn.start.min", 72), getInt("spawn.start.max", 72));
|
||||
bound = new Range(getInt("spawn.bound.min", 48), getInt("spawn.bound.max", 72));
|
||||
spawn = new GridSpawn(yaml.getInt("spawn.width", 500), yaml.getInt("spawn.padding", 100));
|
||||
searchStart = new Range(yaml.getInt("spawn.start.min", 72), yaml.getInt("spawn.start.max", 72));
|
||||
bound = new Range(yaml.getInt("spawn.bound.min", 48), yaml.getInt("spawn.bound.max", 72));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -0,0 +1,20 @@
|
||||
package com.dfsek.terra.config.jackson;
|
||||
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.deser.std.FromStringDeserializer;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class BlockDataDeserializer extends FromStringDeserializer<BlockData> {
|
||||
protected BlockDataDeserializer() {
|
||||
super(BlockData.class);
|
||||
}
|
||||
|
||||
@SuppressWarnings("RedundantThrows")
|
||||
@Override
|
||||
protected BlockData _deserialize(String value, DeserializationContext ctxt) throws IOException {
|
||||
return Bukkit.createBlockData(value);
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package com.dfsek.terra.config.jackson;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParseException;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.deser.std.FromStringDeserializer;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class MaterialDeserializer extends FromStringDeserializer<Material> {
|
||||
protected MaterialDeserializer() {
|
||||
super(Material.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Material _deserialize(String value, DeserializationContext ctxt) throws IOException {
|
||||
try {
|
||||
return Bukkit.createBlockData(value).getMaterial();
|
||||
} catch(IllegalArgumentException e) {
|
||||
throw new JsonParseException(ctxt.getParser(), "This is not a valid block.", e);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,121 @@
|
||||
package com.dfsek.terra.config.jackson;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonToken;
|
||||
import com.fasterxml.jackson.databind.AnnotationIntrospector;
|
||||
import com.fasterxml.jackson.databind.BeanProperty;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JavaType;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
import com.fasterxml.jackson.databind.JsonMappingException;
|
||||
import com.fasterxml.jackson.databind.KeyDeserializer;
|
||||
import com.fasterxml.jackson.databind.deser.ContextualDeserializer;
|
||||
import com.fasterxml.jackson.databind.deser.ContextualKeyDeserializer;
|
||||
import com.fasterxml.jackson.databind.deser.NullValueProvider;
|
||||
import com.fasterxml.jackson.databind.deser.std.ContainerDeserializerBase;
|
||||
import com.fasterxml.jackson.databind.jsontype.TypeDeserializer;
|
||||
import org.polydev.gaea.math.ProbabilityCollection;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class ProbabilityCollectionDeserializer extends ContainerDeserializerBase<ProbabilityCollection<Object>> implements ContextualDeserializer {
|
||||
|
||||
protected final TypeDeserializer _valueTypeDeserializer;
|
||||
protected KeyDeserializer _keyDeserializer;
|
||||
protected JsonDeserializer<?> _valueDeserializer;
|
||||
|
||||
public ProbabilityCollectionDeserializer(JavaType type, KeyDeserializer keyDeser, JsonDeserializer<?> valueDeser,
|
||||
TypeDeserializer valueTypeDeser, NullValueProvider nuller) {
|
||||
super(type, nuller, null);
|
||||
_keyDeserializer = keyDeser;
|
||||
_valueDeserializer = valueDeser;
|
||||
_valueTypeDeserializer = valueTypeDeser;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonDeserializer<?> createContextual(DeserializationContext ctxt,
|
||||
BeanProperty property) throws JsonMappingException {
|
||||
KeyDeserializer keyDeser = _keyDeserializer;
|
||||
if(keyDeser == null) {
|
||||
keyDeser = ctxt.findKeyDeserializer(_containerType.getKeyType(), property);
|
||||
} else {
|
||||
if(keyDeser instanceof ContextualKeyDeserializer) {
|
||||
keyDeser = ((ContextualKeyDeserializer) keyDeser).createContextual(ctxt, property);
|
||||
}
|
||||
}
|
||||
|
||||
JsonDeserializer<?> valueDeser = _valueDeserializer;
|
||||
// [databind#125]: May have a content converter
|
||||
if(property != null) {
|
||||
valueDeser = findConvertingContentDeserializer(ctxt, property, valueDeser);
|
||||
}
|
||||
final JavaType vt = _containerType.getContentType();
|
||||
if(valueDeser == null) {
|
||||
valueDeser = ctxt.findContextualValueDeserializer(vt, property);
|
||||
} else { // if directly assigned, probably not yet contextual, so:
|
||||
valueDeser = ctxt.handleSecondaryContextualization(valueDeser, property, vt);
|
||||
}
|
||||
TypeDeserializer vtd = _valueTypeDeserializer;
|
||||
if(vtd != null) {
|
||||
vtd = vtd.forProperty(property);
|
||||
}
|
||||
AnnotationIntrospector intr = ctxt.getAnnotationIntrospector();
|
||||
return withResolved(keyDeser, vtd, valueDeser,
|
||||
findContentNullProvider(ctxt, property, valueDeser));
|
||||
}
|
||||
|
||||
protected ProbabilityCollectionDeserializer withResolved(KeyDeserializer keyDeser, TypeDeserializer valueTypeDeser,
|
||||
JsonDeserializer<?> valueDeser, NullValueProvider nuller) {
|
||||
if((_keyDeserializer == keyDeser) && (_valueDeserializer == valueDeser)
|
||||
&& (_valueTypeDeserializer == valueTypeDeser) && (_nullProvider == nuller)) {
|
||||
return this;
|
||||
}
|
||||
return new ProbabilityCollectionDeserializer(_containerType, keyDeser, valueDeser, valueTypeDeser, nuller);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public JsonDeserializer<Object> getContentDeserializer() {
|
||||
return (JsonDeserializer<Object>) _valueDeserializer;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public ProbabilityCollection<Object> deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
|
||||
// Ok: must point to START_OBJECT, FIELD_NAME or END_OBJECT
|
||||
JsonToken t = p.getCurrentToken();
|
||||
if(t != JsonToken.START_OBJECT) {
|
||||
return (ProbabilityCollection<Object>) ctxt.handleUnexpectedToken(getValueType(ctxt), t, p, null);
|
||||
}
|
||||
final ProbabilityCollection<Object> result = new ProbabilityCollection<>();
|
||||
_readAndBind(p, ctxt, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
protected final void _readAndBind(JsonParser p, DeserializationContext ctxt,
|
||||
ProbabilityCollection<Object> result) throws IOException {
|
||||
final KeyDeserializer keyDes = _keyDeserializer;
|
||||
|
||||
String keyStr;
|
||||
if(p.isExpectedStartObjectToken()) {
|
||||
keyStr = p.nextFieldName();
|
||||
} else {
|
||||
JsonToken t = p.getCurrentToken();
|
||||
if(t == JsonToken.END_OBJECT) {
|
||||
return;
|
||||
}
|
||||
ctxt.reportWrongTokenException(this, JsonToken.FIELD_NAME, null);
|
||||
keyStr = p.getCurrentName();
|
||||
}
|
||||
|
||||
while(keyStr != null) {
|
||||
Object key = keyDes.deserializeKey(keyStr, ctxt);
|
||||
int value = _parseIntPrimitive(ctxt, p.nextToken().asString());
|
||||
result.add(key, value);
|
||||
|
||||
|
||||
keyStr = p.nextFieldName();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
package com.dfsek.terra.config.jackson;
|
||||
|
||||
import com.fasterxml.jackson.databind.*;
|
||||
import com.fasterxml.jackson.databind.deser.Deserializers;
|
||||
import com.fasterxml.jackson.databind.jsontype.TypeDeserializer;
|
||||
import com.fasterxml.jackson.databind.type.MapLikeType;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.polydev.gaea.math.ProbabilityCollection;
|
||||
|
||||
|
||||
public class TerraDeserializers extends Deserializers.Base {
|
||||
public TerraDeserializers() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonDeserializer<?> findEnumDeserializer(Class<?> type, DeserializationConfig config,
|
||||
BeanDescription beanDesc) throws JsonMappingException {
|
||||
if (type.isAssignableFrom(Material.class))
|
||||
return new MaterialDeserializer();
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonDeserializer<?> findBeanDeserializer(JavaType type, DeserializationConfig config,
|
||||
BeanDescription beanDesc) throws JsonMappingException {
|
||||
if (type.hasRawClass(BlockData.class))
|
||||
return new BlockDataDeserializer();
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonDeserializer<?> findMapLikeDeserializer(MapLikeType type, DeserializationConfig config,
|
||||
BeanDescription beanDesc, KeyDeserializer keyDeserializer,
|
||||
TypeDeserializer elementTypeDeserializer,
|
||||
JsonDeserializer<?> elementDeserializer) throws JsonMappingException {
|
||||
Class<?> raw = type.getRawClass();
|
||||
if (ProbabilityCollection.class.isAssignableFrom(raw))
|
||||
return new ProbabilityCollectionDeserializer(type, keyDeserializer, elementDeserializer, elementTypeDeserializer, null);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasDeserializerFor(DeserializationConfig config, Class<?> valueType) {
|
||||
return (valueType == ProbabilityCollection.class)
|
||||
|| false;
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
package com.dfsek.terra.config.jackson;
|
||||
|
||||
import com.fasterxml.jackson.core.Version;
|
||||
import com.fasterxml.jackson.databind.Module;
|
||||
|
||||
public class TerraModule extends Module {
|
||||
|
||||
public TerraModule() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getModuleName() {
|
||||
return "TerraModule";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version version() {
|
||||
return new Version(0, 0, 0, null, null, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setupModule(SetupContext context) {
|
||||
context.addDeserializers(new TerraDeserializers());
|
||||
}
|
||||
}
|
@ -48,20 +48,24 @@ public class CavePopulator extends BlockPopulator {
|
||||
Block b = chunk.getBlock(v.getBlockX(), v.getBlockY(), v.getBlockZ());
|
||||
Material m = b.getType();
|
||||
if(e.getValue().equals(CarvingData.CarvingType.CENTER) && c.isReplaceableInner(m)) {
|
||||
if(c.getShiftedBlocks().containsKey(b.getType()))
|
||||
if(c.getShiftedBlocks().containsKey(b.getType())) {
|
||||
shiftCandidate.put(b.getLocation(), b.getType());
|
||||
}
|
||||
b.setBlockData(c.getPaletteInner(v.getBlockY()).get(random), c.shouldUpdateOcean() && borderingOcean(b));
|
||||
} else if(e.getValue().equals(CarvingData.CarvingType.WALL) && c.isReplaceableOuter(m)) {
|
||||
if(c.getShiftedBlocks().containsKey(b.getType()))
|
||||
if(c.getShiftedBlocks().containsKey(b.getType())) {
|
||||
shiftCandidate.put(b.getLocation(), b.getType());
|
||||
}
|
||||
b.setBlockData(c.getPaletteOuter(v.getBlockY()).get(random), c.shouldUpdateOcean() && borderingOcean(b));
|
||||
} else if(e.getValue().equals(CarvingData.CarvingType.TOP) && c.isReplaceableTop(m)) {
|
||||
if(c.getShiftedBlocks().containsKey(b.getType()))
|
||||
if(c.getShiftedBlocks().containsKey(b.getType())) {
|
||||
shiftCandidate.put(b.getLocation(), b.getType());
|
||||
}
|
||||
b.setBlockData(c.getPaletteTop(v.getBlockY()).get(random), c.shouldUpdateOcean() && borderingOcean(b));
|
||||
} else if(e.getValue().equals(CarvingData.CarvingType.BOTTOM) && c.isReplaceableBottom(m)) {
|
||||
if(c.getShiftedBlocks().containsKey(b.getType()))
|
||||
if(c.getShiftedBlocks().containsKey(b.getType())) {
|
||||
shiftCandidate.put(b.getLocation(), b.getType());
|
||||
}
|
||||
b.setBlockData(c.getPaletteBottom(v.getBlockY()).get(random), c.shouldUpdateOcean() && borderingOcean(b));
|
||||
}
|
||||
if(c.getUpdateBlocks().contains(m)) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user