Look ma, no Bukkit API in the core package

This commit is contained in:
dfsek 2020-12-11 17:30:17 -07:00
parent 7ee1d2c391
commit 5bf699cba9
345 changed files with 1352 additions and 2642 deletions

View File

@ -14,12 +14,19 @@ plugins {
id("com.github.johnrengelman.shadow").version("6.1.0") id("com.github.johnrengelman.shadow").version("6.1.0")
} }
val versionObj = Version("2", "2", "0", true)
allprojects {
version = versionObj
group = "com.dfsek.terra"
}
repositories { repositories {
maven { url = uri("https://hub.spigotmc.org/nexus/content/repositories/snapshots/") } maven { url = uri("https://hub.spigotmc.org/nexus/content/repositories/snapshots/") }
maven { url = uri("http://maven.enginehub.org/repo/") } maven { url = uri("http://maven.enginehub.org/repo/") }
maven { url = uri("https://repo.codemc.org/repository/maven-public") } maven { url = uri("https://repo.codemc.org/repository/maven-public") }
maven { url = uri("https://papermc.io/repo/repository/maven-public/") } maven { url = uri("https://papermc.io/repo/repository/maven-public/") }
maven { url = uri("https://repo.aikar.co/content/groups/aikar/") }
} }
java { java {
@ -27,15 +34,10 @@ java {
targetCompatibility = JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_1_8
} }
val versionObj = Version("2", "2", "0", true)
version = versionObj
dependencies { dependencies {
implementation("org.apache.commons:commons-rng-core:1.3") implementation("org.apache.commons:commons-rng-core:1.3")
implementation("net.jafama:jafama:2.3.2") implementation("net.jafama:jafama:2.3.2")
compileOnly("org.jetbrains:annotations:20.1.0")
implementation("commons-io:commons-io:2.4") implementation("commons-io:commons-io:2.4")
implementation("org.apache.commons:commons-imaging:1.0-alpha2") implementation("org.apache.commons:commons-imaging:1.0-alpha2")
@ -47,19 +49,20 @@ dependencies {
implementation("com.scireum:parsii:1.2.1") implementation("com.scireum:parsii:1.2.1")
compileOnly("org.spigotmc:spigot-api:1.16.2-R0.1-SNAPSHOT")
implementation("io.papermc:paperlib:1.0.5")
implementation("net.jafama:jafama:2.3.2") implementation("net.jafama:jafama:2.3.2")
implementation("com.dfsek:Tectonic:1.0.3") implementation("com.dfsek:Tectonic:1.0.3")
// JUnit. // JUnit.
testImplementation("org.junit.jupiter:junit-jupiter-api:5.7.0") testImplementation("org.junit.jupiter:junit-jupiter-api:5.7.0")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.7.0") testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.7.0")
} }
val compileJava: JavaCompile by tasks val compileJava: JavaCompile by tasks
val mainSourceSet: SourceSet = sourceSets["main"] val mainSourceSet: SourceSet = sourceSets["main"]
@ -168,7 +171,7 @@ val testWithPaper = task<JavaExec>(name = "testWithPaper") {
// Copy Terra into dir // Copy Terra into dir
doFirst { doFirst {
copy { copy {
from("${buildDir}/libs/Terra-${versionObj}.jar") from("${project("platforms:bukkit").buildDir}/libs/Terra-${versionObj}.jar")
into("${testDir}/plugins/") into("${testDir}/plugins/")
} }
} }

47
common/build.gradle.kts Normal file
View File

@ -0,0 +1,47 @@
plugins {
java
maven
idea
id("com.github.johnrengelman.shadow")
}
group = "com.dfsek.terra.common"
repositories {
mavenCentral()
maven { url = uri("https://hub.spigotmc.org/nexus/content/repositories/snapshots/") }
maven { url = uri("http://maven.enginehub.org/repo/") }
maven { url = uri("https://repo.codemc.org/repository/maven-public") }
maven { url = uri("https://papermc.io/repo/repository/maven-public/") }
}
dependencies {
compileOnly("org.jetbrains:annotations:20.1.0")
testImplementation("org.junit.jupiter:junit-jupiter-api:5.7.0")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.7.0")
implementation("org.apache.commons:commons-rng-core:1.3")
implementation("commons-io:commons-io:2.4")
implementation("com.scireum:parsii:1.2.1")
implementation("com.dfsek:Tectonic:1.0.3")
implementation("net.jafama:jafama:2.3.2")
compileOnly("com.googlecode.json-simple:json-simple:1.1")
implementation("com.google.guava:guava:30.0-jre")
}
tasks.named<com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar>("shadowJar") {
archiveClassifier.set("")
archiveBaseName.set("Terra")
setVersion(project.version)
relocate("org.apache.commons", "com.dfsek.terra.lib.commons")
relocate("org.bstats.bukkit", "com.dfsek.terra.lib.bstats")
relocate("parsii", "com.dfsek.terra.lib.parsii")
relocate("io.papermc.lib", "com.dfsek.terra.lib.paperlib")
relocate("net.jafama", "com.dfsek.terra.lib.jafama")
relocate("com.dfsek.tectonic", "com.dfsek.terra.lib.tectonic")
relocate("net.jafama", "com.dfsek.terra.lib.jafama")
minimize()
}

View File

@ -3,7 +3,6 @@ package com.dfsek.terra;
import com.dfsek.terra.api.gaea.biome.BiomeGrid; import com.dfsek.terra.api.gaea.biome.BiomeGrid;
import com.dfsek.terra.api.generic.TerraPlugin; import com.dfsek.terra.api.generic.TerraPlugin;
import com.dfsek.terra.api.generic.world.World; import com.dfsek.terra.api.generic.world.World;
import com.dfsek.terra.api.implementations.bukkit.generator.BukkitChunkGenerator;
import com.dfsek.terra.biome.BiomeZone; import com.dfsek.terra.biome.BiomeZone;
import com.dfsek.terra.biome.grid.master.TerraBiomeGrid; import com.dfsek.terra.biome.grid.master.TerraBiomeGrid;
import com.dfsek.terra.biome.grid.master.TerraRadialBiomeGrid; import com.dfsek.terra.biome.grid.master.TerraRadialBiomeGrid;
@ -12,6 +11,7 @@ import com.dfsek.terra.config.base.ConfigPack;
import com.dfsek.terra.config.base.ConfigPackTemplate; import com.dfsek.terra.config.base.ConfigPackTemplate;
import com.dfsek.terra.config.builder.biomegrid.BiomeGridBuilder; import com.dfsek.terra.config.builder.biomegrid.BiomeGridBuilder;
import com.dfsek.terra.debug.Debug; import com.dfsek.terra.debug.Debug;
import com.dfsek.terra.generation.TerraChunkGenerator;
public class TerraWorld { public class TerraWorld {
private final TerraBiomeGrid grid; private final TerraBiomeGrid grid;
@ -55,7 +55,7 @@ public class TerraWorld {
} }
public static boolean isTerraWorld(World w) { public static boolean isTerraWorld(World w) {
return w.getGenerator() instanceof BukkitChunkGenerator; return w.getGenerator() instanceof TerraChunkGenerator;
} }
public TerraBiomeGrid getGrid() { public TerraBiomeGrid getGrid() {

View File

@ -0,0 +1,8 @@
package com.dfsek.terra.api;
import com.dfsek.terra.api.generic.Handle;
import com.dfsek.terra.api.generic.world.vector.Location;
public interface Entity extends Handle {
Location getLocation();
}

View File

@ -17,7 +17,6 @@ import com.dfsek.terra.config.loaders.config.GridSpawnLoader;
import com.dfsek.terra.config.loaders.config.NoiseBuilderLoader; import com.dfsek.terra.config.loaders.config.NoiseBuilderLoader;
import com.dfsek.terra.config.loaders.config.OreConfigLoader; import com.dfsek.terra.config.loaders.config.OreConfigLoader;
import com.dfsek.terra.config.loaders.config.OreHolderLoader; import com.dfsek.terra.config.loaders.config.OreHolderLoader;
import com.dfsek.terra.config.loaders.config.StructureFeatureLoader;
import com.dfsek.terra.config.loaders.config.TreeLayerLoader; import com.dfsek.terra.config.loaders.config.TreeLayerLoader;
import com.dfsek.terra.config.loaders.palette.CarverPaletteLoader; import com.dfsek.terra.config.loaders.palette.CarverPaletteLoader;
import com.dfsek.terra.config.loaders.palette.PaletteHolderLoader; import com.dfsek.terra.config.loaders.palette.PaletteHolderLoader;
@ -31,9 +30,7 @@ import com.dfsek.terra.generation.items.ores.OreHolder;
import com.dfsek.terra.generation.items.tree.TreeLayer; import com.dfsek.terra.generation.items.tree.TreeLayer;
import com.dfsek.terra.image.ImageLoader; import com.dfsek.terra.image.ImageLoader;
import com.dfsek.terra.procgen.GridSpawn; import com.dfsek.terra.procgen.GridSpawn;
import com.dfsek.terra.structure.features.Feature;
import com.dfsek.terra.util.MaterialSet; import com.dfsek.terra.util.MaterialSet;
import com.dfsek.terra.util.StructureTypeEnum;
public class GenericLoaders implements LoaderRegistrar { public class GenericLoaders implements LoaderRegistrar {
private final TerraPlugin main; private final TerraPlugin main;
@ -57,10 +54,8 @@ public class GenericLoaders implements LoaderRegistrar {
.registerLoader(TreeLayer.class, new TreeLayerLoader(main)) .registerLoader(TreeLayer.class, new TreeLayerLoader(main))
.registerLoader(MaterialSet.class, new MaterialSetLoader()) .registerLoader(MaterialSet.class, new MaterialSetLoader())
.registerLoader(OreHolder.class, new OreHolderLoader()) .registerLoader(OreHolder.class, new OreHolderLoader())
.registerLoader(Feature.class, new StructureFeatureLoader())
.registerLoader(ImageLoader.class, new ImageLoaderLoader()) .registerLoader(ImageLoader.class, new ImageLoaderLoader())
.registerLoader(TerraBiomeGrid.Type.class, (t, o, l) -> TerraBiomeGrid.Type.valueOf((String) o)) .registerLoader(TerraBiomeGrid.Type.class, (t, o, l) -> TerraBiomeGrid.Type.valueOf((String) o))
.registerLoader(StructureTypeEnum.class, (t, o, l) -> StructureTypeEnum.valueOf((String) o))
.registerLoader(ImageLoader.Channel.class, (t, o, l) -> ImageLoader.Channel.valueOf((String) o)) .registerLoader(ImageLoader.Channel.class, (t, o, l) -> ImageLoader.Channel.valueOf((String) o))
.registerLoader(ImageLoader.Align.class, (t, o, l) -> ImageLoader.Align.valueOf((String) o)) .registerLoader(ImageLoader.Align.class, (t, o, l) -> ImageLoader.Align.valueOf((String) o))
.registerLoader(TerraFlora.Search.class, (t, o, l) -> TerraFlora.Search.valueOf((String) o)); .registerLoader(TerraFlora.Search.class, (t, o, l) -> TerraFlora.Search.valueOf((String) o));

View File

@ -0,0 +1,4 @@
package com.dfsek.terra.api;
public interface Player extends Entity {
}

View File

@ -1,11 +1,11 @@
package com.dfsek.terra.api.gaea; package com.dfsek.terra.api.gaea;
import org.bukkit.plugin.java.JavaPlugin; import com.dfsek.terra.api.generic.TerraPlugin;
public class Debug { public class Debug {
public static JavaPlugin main; public static TerraPlugin main;
public static void setMain(JavaPlugin main) { public static void setMain(TerraPlugin main) {
Debug.main = main; Debug.main = main;
} }

View File

@ -1,6 +1,7 @@
package com.dfsek.terra.api.gaea.biome; package com.dfsek.terra.api.gaea.biome;
import org.bukkit.World;
import com.dfsek.terra.api.generic.world.World;
/** /**
* Interface to be implemented by a custom generator's Biome enum.<br> * Interface to be implemented by a custom generator's Biome enum.<br>

View File

@ -13,8 +13,6 @@ public abstract class Decorator {
public abstract boolean overrideStructureChance(); public abstract boolean overrideStructureChance();
public abstract org.bukkit.block.Biome getVanillaBiome();
public abstract ProbabilityCollection<Flora> getFlora(); public abstract ProbabilityCollection<Flora> getFlora();
public abstract int getFloraChance(); public abstract int getFloraChance();

View File

@ -1,8 +1,7 @@
package com.dfsek.terra.api.gaea.lang; package com.dfsek.terra.api.gaea.lang;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.InvalidConfigurationException; import com.dfsek.terra.api.generic.CommandSender;
import org.bukkit.configuration.file.YamlConfiguration;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.io.File; import java.io.File;
@ -11,17 +10,15 @@ import java.util.List;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
public class Language extends YamlConfiguration { public class Language {
public Language(File file) throws IOException, InvalidConfigurationException { public Language(File file) throws IOException {
load(file); load(file);
} }
@Override public void load(@NotNull File file) throws IOException {
public void load(@NotNull File file) throws IOException, InvalidConfigurationException {
super.load(file);
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public Message getMessage(String id) { public Message getMessage(String id) {
Object m = get(id); Object m = null;
Message temp; Message temp;
if(m instanceof List) { if(m instanceof List) {
temp = new MultiLineMessage((List<String>) m); temp = new MultiLineMessage((List<String>) m);

View File

@ -1,6 +1,7 @@
package com.dfsek.terra.api.gaea.lang; package com.dfsek.terra.api.gaea.lang;
import org.bukkit.command.CommandSender;
import com.dfsek.terra.api.generic.CommandSender;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;

View File

@ -1,7 +1,6 @@
package com.dfsek.terra.api.gaea.lang; package com.dfsek.terra.api.gaea.lang;
import org.bukkit.ChatColor; import com.dfsek.terra.api.generic.CommandSender;
import org.bukkit.command.CommandSender;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
@ -16,14 +15,14 @@ public class MultiLineMessage implements Message {
@Override @Override
public void log(Logger logger, Level level, String... args) { public void log(Logger logger, Level level, String... args) {
for(String line: message) { for(String line: message) {
logger.log(level, ChatColor.translateAlternateColorCodes('&', String.format(line, Arrays.asList(args).toArray()))); logger.log(level, String.format(line, Arrays.asList(args).toArray()));
} }
} }
@Override @Override
public void send(CommandSender sender, String... args) { public void send(CommandSender sender, String... args) {
for(String line: message) { for(String line: message) {
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', String.format(line, Arrays.asList(args).toArray()))); sender.sendMessage(String.format(line, Arrays.asList(args).toArray()));
} }
} }

View File

@ -1,7 +1,7 @@
package com.dfsek.terra.api.gaea.lang; package com.dfsek.terra.api.gaea.lang;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender; import com.dfsek.terra.api.generic.CommandSender;
import java.util.Arrays; import java.util.Arrays;
import java.util.logging.Level; import java.util.logging.Level;
@ -14,12 +14,12 @@ public class SingleLineMessage implements Message {
} }
@Override @Override
public void log(Logger logger, Level level, String... args) { public void log(Logger logger, Level level, String... args) {
logger.log(level, ChatColor.translateAlternateColorCodes('&', String.format(message, Arrays.asList(args).toArray()))); logger.log(level, String.format(message, Arrays.asList(args).toArray()));
} }
@Override @Override
public void send(CommandSender sender, String... args) { public void send(CommandSender sender, String... args) {
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', String.format(message, Arrays.asList(args).toArray()))); sender.sendMessage(String.format(message, Arrays.asList(args).toArray()));
} }
@Override @Override

View File

@ -1,8 +1,5 @@
package com.dfsek.terra.api.gaea.profiler; package com.dfsek.terra.api.gaea.profiler;
import net.jafama.FastMath;
import net.md_5.bungee.api.ChatColor;
/** /**
* Class to hold a profiler data value. Contains formatting method to highlight value based on desired range. * Class to hold a profiler data value. Contains formatting method to highlight value based on desired range.
*/ */
@ -34,12 +31,6 @@ public class DataHolder {
* @return String - The formatted data. * @return String - The formatted data.
*/ */
public String getFormattedData(long data) { public String getFormattedData(long data) {
double range = desiredRangePercent * desired; return type.getFormatted(data);
ChatColor color = ChatColor.YELLOW;
if(FastMath.abs(data - desired) > range) {
if(data > desired) color = type.getDesire().getHighColor();
else color = type.getDesire().getLowColor();
}
return color + type.getFormatted(data) + ChatColor.RESET;
} }
} }

View File

@ -0,0 +1,10 @@
package com.dfsek.terra.api.gaea.profiler;
/**
* Enum to represent the "goal" of a value, whether it is desirable for the value to be high (e.g. Frequency), or low (e.g. Period)
*/
public enum Desire {
LOW, HIGH
}

View File

@ -3,7 +3,6 @@ package com.dfsek.terra.api.gaea.profiler;
import com.dfsek.terra.api.gaea.math.MathUtil; import com.dfsek.terra.api.gaea.math.MathUtil;
import com.dfsek.terra.api.gaea.util.GlueList; import com.dfsek.terra.api.gaea.util.GlueList;
import net.jafama.FastMath; import net.jafama.FastMath;
import org.bukkit.Bukkit;
import java.math.BigInteger; import java.math.BigInteger;
import java.util.List; import java.util.List;
@ -33,7 +32,6 @@ public class Measurement {
public void record(long value) { public void record(long value) {
max = FastMath.max(value, max); max = FastMath.max(value, max);
min = FastMath.min(value, min); min = FastMath.min(value, min);
if(value / 1000000 > 5000) Bukkit.getLogger().warning("Measurement took " + type.getFormatted(value));
measurements.add(value); measurements.add(value);
} }

View File

@ -1,12 +1,9 @@
package com.dfsek.terra.api.gaea.profiler; package com.dfsek.terra.api.gaea.profiler;
import com.dfsek.terra.api.generic.world.World; import com.dfsek.terra.api.generic.world.World;
import com.dfsek.terra.api.implementations.bukkit.generator.BukkitChunkGenerator;
import com.dfsek.terra.api.implementations.bukkit.generator.BukkitChunkGeneratorWrapper;
import com.google.common.collect.BiMap; import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap; import com.google.common.collect.HashBiMap;
import net.jafama.FastMath; import net.jafama.FastMath;
import org.bukkit.ChatColor;
import java.util.Map; import java.util.Map;
@ -16,7 +13,7 @@ public class WorldProfiler {
private boolean isProfiling; private boolean isProfiling;
public WorldProfiler(World w) { public WorldProfiler(World w) {
if(!(w.getGenerator() instanceof BukkitChunkGenerator)) if(w.getGenerator().getTerraGenerator() == null)
throw new IllegalArgumentException("Attempted to instantiate profiler on non-Gaea managed world!"); throw new IllegalArgumentException("Attempted to instantiate profiler on non-Gaea managed world!");
this.addMeasurement(new Measurement(2500000, DataType.PERIOD_MILLISECONDS), "TotalChunkGenTime") this.addMeasurement(new Measurement(2500000, DataType.PERIOD_MILLISECONDS), "TotalChunkGenTime")
.addMeasurement(new Measurement(2500000, DataType.PERIOD_MILLISECONDS), "ChunkBaseGenTime") .addMeasurement(new Measurement(2500000, DataType.PERIOD_MILLISECONDS), "ChunkBaseGenTime")
@ -24,29 +21,25 @@ public class WorldProfiler {
.addMeasurement(new Measurement(2000000, DataType.PERIOD_MILLISECONDS), "PopulationManagerTime"); .addMeasurement(new Measurement(2000000, DataType.PERIOD_MILLISECONDS), "PopulationManagerTime");
isProfiling = false; isProfiling = false;
this.world = w; this.world = w;
((BukkitChunkGeneratorWrapper) ((BukkitChunkGenerator) w.getGenerator()).getHandle()).getDelegate().attachProfiler(this); w.getGenerator().getTerraGenerator().attachProfiler(this);
} }
public String getResultsFormatted() { public String getResultsFormatted() {
if(! isProfiling) return "Profiler is not currently running."; if(! isProfiling) return "Profiler is not currently running.";
StringBuilder result = new StringBuilder(ChatColor.GOLD + "Gaea World Profiler Results (Min / Avg / Max / Std Dev): \n"); StringBuilder result = new StringBuilder("Gaea World Profiler Results (Min / Avg / Max / Std Dev): \n");
for(Map.Entry<String, Measurement> e : measures.entrySet()) { for(Map.Entry<String, Measurement> e : measures.entrySet()) {
result.append(ChatColor.GOLD) result
.append(e.getKey()) .append(e.getKey())
.append(": ") .append(": ")
.append(e.getValue().getDataHolder().getFormattedData(e.getValue().getMin())) .append(e.getValue().getDataHolder().getFormattedData(e.getValue().getMin()))
.append(ChatColor.GOLD)
.append(" / ") .append(" / ")
.append(e.getValue().getDataHolder().getFormattedData(e.getValue().average())) .append(e.getValue().getDataHolder().getFormattedData(e.getValue().average()))
.append(ChatColor.GOLD)
.append(" / ") .append(" / ")
.append(e.getValue().getDataHolder().getFormattedData(e.getValue().getMax())) .append(e.getValue().getDataHolder().getFormattedData(e.getValue().getMax()))
.append(ChatColor.GOLD)
.append(" / ") .append(" / ")
.append(ChatColor.GREEN)
.append((double) FastMath.round((e.getValue().getStdDev() / 1000000) * 100D) / 100D) .append((double) FastMath.round((e.getValue().getStdDev() / 1000000) * 100D) / 100D)
.append("ms") .append("ms")
.append(ChatColor.GOLD).append(" (x").append(e.getValue().size()).append(")\n"); .append(" (x").append(e.getValue().size()).append(")\n");
} }
return result.toString(); return result.toString();
} }

View File

@ -2,12 +2,12 @@ package com.dfsek.terra.api.gaea.structures.loot;
import com.dfsek.terra.api.gaea.structures.loot.functions.AmountFunction; import com.dfsek.terra.api.gaea.structures.loot.functions.AmountFunction;
import com.dfsek.terra.api.gaea.structures.loot.functions.DamageFunction; import com.dfsek.terra.api.gaea.structures.loot.functions.DamageFunction;
import com.dfsek.terra.api.gaea.structures.loot.functions.EnchantWithLevelsFunction;
import com.dfsek.terra.api.gaea.structures.loot.functions.Function; import com.dfsek.terra.api.gaea.structures.loot.functions.Function;
import com.dfsek.terra.api.gaea.util.GlueList; import com.dfsek.terra.api.gaea.util.GlueList;
import com.dfsek.terra.api.generic.TerraPlugin;
import com.dfsek.terra.api.generic.inventory.ItemStack;
import com.dfsek.terra.api.generic.world.block.MaterialData;
import net.jafama.FastMath; import net.jafama.FastMath;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.json.simple.JSONArray; import org.json.simple.JSONArray;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
@ -18,19 +18,20 @@ import java.util.Random;
* Representation of a single item entry within a Loot Table pool. * Representation of a single item entry within a Loot Table pool.
*/ */
public class Entry { public class Entry {
private final Material item; private final MaterialData item;
private final long weight; private final long weight;
private final List<Function> functions = new GlueList<>(); private final List<Function> functions = new GlueList<>();
private final TerraPlugin main;
/** /**
* Instantiates an Entry from a JSON representation. * Instantiates an Entry from a JSON representation.
* *
* @param entry The JSON Object to instantiate from. * @param entry The JSON Object to instantiate from.
*/ */
public Entry(JSONObject entry) { public Entry(JSONObject entry, TerraPlugin main) {
this.main = main;
String id = entry.get("name").toString(); String id = entry.get("name").toString();
this.item = Material.matchMaterial(id); this.item = main.getWorldHandle().createMaterialData(id);
long weight1; long weight1;
try { try {
@ -62,15 +63,6 @@ public class Entry {
long minDamage = (long) ((JSONObject) ((JSONObject) function).get("damage")).get("min"); long minDamage = (long) ((JSONObject) ((JSONObject) function).get("damage")).get("min");
functions.add(new DamageFunction(FastMath.toIntExact(minDamage), FastMath.toIntExact(maxDamage))); functions.add(new DamageFunction(FastMath.toIntExact(minDamage), FastMath.toIntExact(maxDamage)));
break; break;
case "minecraft:enchant_with_levels":
case "enchant_with_levels":
long maxEnchant = (long) ((JSONObject) ((JSONObject) function).get("levels")).get("max");
long minEnchant = (long) ((JSONObject) ((JSONObject) function).get("levels")).get("min");
JSONArray disabled = null;
if(((JSONObject) function).containsKey("disabled_enchants"))
disabled = (JSONArray) ((JSONObject) function).get("disabled_enchants");
functions.add(new EnchantWithLevelsFunction(FastMath.toIntExact(minEnchant), FastMath.toIntExact(maxEnchant), disabled));
break;
} }
} }
} }
@ -83,7 +75,7 @@ public class Entry {
* @return ItemStack - The ItemStack with all functions applied. * @return ItemStack - The ItemStack with all functions applied.
*/ */
public ItemStack getItem(Random r) { public ItemStack getItem(Random r) {
ItemStack item = new ItemStack(this.item, 1); ItemStack item = main.getItemHandle().newItemStack(this.item, 1);
for(Function f : functions) { for(Function f : functions) {
item = f.apply(item, r); item = f.apply(item, r);
} }

View File

@ -1,8 +1,9 @@
package com.dfsek.terra.api.gaea.structures.loot; package com.dfsek.terra.api.gaea.structures.loot;
import com.dfsek.terra.api.gaea.util.GlueList; import com.dfsek.terra.api.gaea.util.GlueList;
import org.bukkit.inventory.Inventory; import com.dfsek.terra.api.generic.TerraPlugin;
import org.bukkit.inventory.ItemStack; import com.dfsek.terra.api.generic.inventory.Inventory;
import com.dfsek.terra.api.generic.inventory.ItemStack;
import org.json.simple.JSONArray; import org.json.simple.JSONArray;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser; import org.json.simple.parser.JSONParser;
@ -23,12 +24,12 @@ public class LootTable {
* @param json The JSON String representing the loot table. * @param json The JSON String representing the loot table.
* @throws ParseException if malformed JSON is passed. * @throws ParseException if malformed JSON is passed.
*/ */
public LootTable(String json) throws ParseException { public LootTable(String json, TerraPlugin main) throws ParseException {
JSONParser jsonParser = new JSONParser(); JSONParser jsonParser = new JSONParser();
Object tableJSON = jsonParser.parse(json); Object tableJSON = jsonParser.parse(json);
JSONArray poolArray = (JSONArray) ((JSONObject) tableJSON).get("pools"); JSONArray poolArray = (JSONArray) ((JSONObject) tableJSON).get("pools");
for(Object pool : poolArray) { for(Object pool : poolArray) {
pools.add(new Pool((JSONObject) pool)); pools.add(new Pool((JSONObject) pool, main));
} }
} }
@ -64,7 +65,7 @@ public class LootTable {
if(slotItem == null) { if(slotItem == null) {
i.setItem(slot, newStack); i.setItem(slot, newStack);
stack.setAmount(stack.getAmount() - 1); stack.setAmount(stack.getAmount() - 1);
} else if(slotItem.getType() == newStack.getType()) { } else if(slotItem.getType().equals(newStack.getType())) {
ItemStack dep = newStack.clone(); ItemStack dep = newStack.clone();
dep.setAmount(newStack.getAmount() + slotItem.getAmount()); dep.setAmount(newStack.getAmount() + slotItem.getAmount());
i.setItem(slot, dep); i.setItem(slot, dep);

View File

@ -2,8 +2,9 @@ package com.dfsek.terra.api.gaea.structures.loot;
import com.dfsek.terra.api.gaea.math.ProbabilityCollection; import com.dfsek.terra.api.gaea.math.ProbabilityCollection;
import com.dfsek.terra.api.gaea.util.GlueList; import com.dfsek.terra.api.gaea.util.GlueList;
import com.dfsek.terra.api.generic.TerraPlugin;
import com.dfsek.terra.api.generic.inventory.ItemStack;
import net.jafama.FastMath; import net.jafama.FastMath;
import org.bukkit.inventory.ItemStack;
import org.json.simple.JSONArray; import org.json.simple.JSONArray;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
@ -16,14 +17,15 @@ import java.util.Random;
public class Pool { public class Pool {
private final int max; private final int max;
private final int min; private final int min;
private final ProbabilityCollection<Entry> entries = new ProbabilityCollection<>(); private final ProbabilityCollection<Entry> entries;
/** /**
* Instantiates a Pool from a JSON representation. * Instantiates a Pool from a JSON representation.
* *
* @param pool The JSON Object to instantiate from. * @param pool The JSON Object to instantiate from.
*/ */
public Pool(JSONObject pool) { public Pool(JSONObject pool, TerraPlugin main) {
entries = new ProbabilityCollection<>();
Object amount = pool.get("rolls"); Object amount = pool.get("rolls");
if(amount instanceof Long) { if(amount instanceof Long) {
max = FastMath.toIntExact((Long) amount); max = FastMath.toIntExact((Long) amount);
@ -34,7 +36,7 @@ public class Pool {
} }
for(Object entryJSON : (JSONArray) pool.get("entries")) { for(Object entryJSON : (JSONArray) pool.get("entries")) {
Entry entry = new Entry((JSONObject) entryJSON); Entry entry = new Entry((JSONObject) entryJSON, main);
entries.add(entry, FastMath.toIntExact(entry.getWeight())); entries.add(entry, FastMath.toIntExact(entry.getWeight()));
} }
} }

View File

@ -1,6 +1,7 @@
package com.dfsek.terra.api.gaea.structures.loot.functions; package com.dfsek.terra.api.gaea.structures.loot.functions;
import org.bukkit.inventory.ItemStack;
import com.dfsek.terra.api.generic.inventory.ItemStack;
import java.util.Random; import java.util.Random;

View File

@ -1,8 +1,8 @@
package com.dfsek.terra.api.gaea.structures.loot.functions; package com.dfsek.terra.api.gaea.structures.loot.functions;
import org.bukkit.inventory.ItemStack; import com.dfsek.terra.api.generic.inventory.ItemStack;
import org.bukkit.inventory.meta.Damageable; import com.dfsek.terra.api.generic.inventory.item.Damageable;
import org.bukkit.inventory.meta.ItemMeta; import com.dfsek.terra.api.generic.inventory.item.ItemMeta;
import java.util.Random; import java.util.Random;

View File

@ -1,6 +1,7 @@
package com.dfsek.terra.api.gaea.structures.loot.functions; package com.dfsek.terra.api.gaea.structures.loot.functions;
import org.bukkit.inventory.ItemStack;
import com.dfsek.terra.api.generic.inventory.ItemStack;
import java.util.Random; import java.util.Random;

View File

@ -1,8 +1,9 @@
package com.dfsek.terra.api.gaea.tree.fractal; package com.dfsek.terra.api.gaea.tree.fractal;
import com.dfsek.terra.api.generic.Entity;
import com.dfsek.terra.api.generic.world.vector.Location; import com.dfsek.terra.api.generic.world.vector.Location;
import org.bukkit.entity.Entity;
import org.bukkit.util.Consumer; import java.util.function.Consumer;
public class EntitySpawnHolder { public class EntitySpawnHolder {

View File

@ -1,20 +1,18 @@
package com.dfsek.terra.api.gaea.tree.fractal; package com.dfsek.terra.api.gaea.tree.fractal;
import com.dfsek.terra.api.gaea.util.GlueList; import com.dfsek.terra.api.gaea.util.GlueList;
import com.dfsek.terra.api.generic.Entity;
import com.dfsek.terra.api.generic.TerraPlugin;
import com.dfsek.terra.api.generic.world.block.BlockData; import com.dfsek.terra.api.generic.world.block.BlockData;
import com.dfsek.terra.api.generic.world.block.MaterialData; import com.dfsek.terra.api.generic.world.block.MaterialData;
import com.dfsek.terra.api.generic.world.vector.Location; import com.dfsek.terra.api.generic.world.vector.Location;
import com.dfsek.terra.api.implementations.bukkit.world.block.BukkitBlockData;
import org.bukkit.Material;
import org.bukkit.entity.Entity;
import org.bukkit.util.Consumer;
import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.Random; import java.util.Random;
import java.util.function.Consumer;
public abstract class FractalTree { public abstract class FractalTree {
@ -22,9 +20,7 @@ public abstract class FractalTree {
private final List<EntitySpawnHolder> entities = new GlueList<>(); private final List<EntitySpawnHolder> entities = new GlueList<>();
private final Location origin; private final Location origin;
private final Random random; private final Random random;
private final List<Material> replaceable = Arrays.asList(Material.AIR, Material.GRASS_BLOCK, Material.DIRT, Material.STONE, Material.COARSE_DIRT, Material.GRAVEL, Material.PODZOL, private final TerraPlugin main;
Material.GRASS, Material.TALL_GRASS, Material.FERN, Material.POPPY, Material.LARGE_FERN, Material.BLUE_ORCHID, Material.AZURE_BLUET, Material.END_STONE, Material.SNOW, Material.SAND, Material.STONE_BUTTON, Material.DEAD_BUSH);
/** /**
* Instantiates a TreeGrower at an origin location. * Instantiates a TreeGrower at an origin location.
@ -32,9 +28,10 @@ public abstract class FractalTree {
* @param origin - The origin location. * @param origin - The origin location.
* @param random - The random object to use whilst generating the tree. * @param random - The random object to use whilst generating the tree.
*/ */
public FractalTree(Location origin, Random random) { public FractalTree(Location origin, Random random, TerraPlugin plugin) {
this.origin = origin.add(0, 1, 0); this.origin = origin.add(0, 1, 0);
this.random = random; this.random = random;
this.main = plugin;
} }
/** /**
@ -71,8 +68,12 @@ public abstract class FractalTree {
* @param l - The location to set. * @param l - The location to set.
* @param m - The material to which it will be set. * @param m - The material to which it will be set.
*/ */
public void setBlock(Location l, Material m) { public void setBlock(Location l, BlockData m) {
treeAssembler.put(l, new BukkitBlockData(m.createBlockData())); treeAssembler.put(l, m);
}
public TerraPlugin getMain() {
return main;
} }
/** /**
@ -86,7 +87,6 @@ public abstract class FractalTree {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void plant() { public void plant() {
for(Map.Entry<Location, BlockData> entry : treeAssembler.entrySet()) { for(Map.Entry<Location, BlockData> entry : treeAssembler.entrySet()) {
if(replaceable.contains(entry.getKey().getBlock().getType()))
entry.getKey().getBlock().setBlockData(entry.getValue(), false); entry.getKey().getBlock().setBlockData(entry.getValue(), false);
} }
for(EntitySpawnHolder e : entities) { for(EntitySpawnHolder e : entities) {
@ -107,7 +107,7 @@ public abstract class FractalTree {
* @return Material - The material at the specified block. * @return Material - The material at the specified block.
*/ */
public MaterialData getMaterial(Location l) { public MaterialData getMaterial(Location l) {
return treeAssembler.getOrDefault(l, new BukkitBlockData(Material.AIR.createBlockData())).getMaterial(); return treeAssembler.getOrDefault(l, main.getWorldHandle().createBlockData("minecraft:air")).getMaterial();
} }

View File

@ -1,9 +1,9 @@
package com.dfsek.terra.api.gaea.tree.fractal; package com.dfsek.terra.api.gaea.tree.fractal;
import com.dfsek.terra.api.gaea.math.ProbabilityCollection; import com.dfsek.terra.api.gaea.math.ProbabilityCollection;
import com.dfsek.terra.api.generic.world.block.BlockData;
import com.dfsek.terra.api.generic.world.vector.Location; import com.dfsek.terra.api.generic.world.vector.Location;
import com.dfsek.terra.api.generic.world.vector.Vector3; import com.dfsek.terra.api.generic.world.vector.Vector3;
import org.bukkit.Material;
public class TreeGeometry { public class TreeGeometry {
private final FractalTree tree; private final FractalTree tree;
@ -20,15 +20,15 @@ public class TreeGeometry {
return tree; return tree;
} }
public void generateSphere(Location l, Material m, int radius, boolean overwrite) { public void generateSphere(Location l, BlockData m, int radius, boolean overwrite) {
generateSphere(l, new ProbabilityCollection<Material>().add(m, 1), radius, overwrite); generateSphere(l, new ProbabilityCollection<BlockData>().add(m, 1), radius, overwrite);
} }
public void generateCylinder(Location l, Material m, int radius, int height, boolean overwrite) { public void generateCylinder(Location l, BlockData m, int radius, int height, boolean overwrite) {
generateCylinder(l, new ProbabilityCollection<Material>().add(m, 1), radius, height, overwrite); generateCylinder(l, new ProbabilityCollection<BlockData>().add(m, 1), radius, height, overwrite);
} }
public void generateSphere(Location l, ProbabilityCollection<Material> m, int radius, boolean overwrite) { public void generateSphere(Location l, ProbabilityCollection<BlockData> m, int radius, boolean overwrite) {
for(int x = - radius; x <= radius; x++) { for(int x = - radius; x <= radius; x++) {
for(int y = - radius; y <= radius; y++) { for(int y = - radius; y <= radius; y++) {
for(int z = - radius; z <= radius; z++) { for(int z = - radius; z <= radius; z++) {
@ -40,7 +40,7 @@ public class TreeGeometry {
} }
} }
public void generateSponge(Location l, ProbabilityCollection<Material> m, int radius, boolean overwrite, int sponginess) { public void generateSponge(Location l, ProbabilityCollection<BlockData> m, int radius, boolean overwrite, int sponginess) {
for(int x = - radius; x <= radius; x++) { for(int x = - radius; x <= radius; x++) {
for(int y = - radius; y <= radius; y++) { for(int y = - radius; y <= radius; y++) {
for(int z = - radius; z <= radius; z++) { for(int z = - radius; z <= radius; z++) {
@ -52,7 +52,7 @@ public class TreeGeometry {
} }
} }
public void generateCylinder(Location l, ProbabilityCollection<Material> m, int radius, int height, boolean overwrite) { public void generateCylinder(Location l, ProbabilityCollection<BlockData> m, int radius, int height, boolean overwrite) {
for(int x = - radius; x <= radius; x++) { for(int x = - radius; x <= radius; x++) {
for(int y = 0; y <= height; y++) { for(int y = 0; y <= height; y++) {
for(int z = - radius; z <= radius; z++) { for(int z = - radius; z <= radius; z++) {

View File

@ -1,8 +1,9 @@
package com.dfsek.terra.api.gaea.tree.fractal.trees; package com.dfsek.terra.api.gaea.tree.fractal.trees;
import com.dfsek.terra.api.gaea.tree.fractal.FractalTree; import com.dfsek.terra.api.gaea.tree.fractal.FractalTree;
import com.dfsek.terra.api.generic.TerraPlugin;
import com.dfsek.terra.api.generic.world.block.BlockData;
import com.dfsek.terra.api.generic.world.vector.Location; import com.dfsek.terra.api.generic.world.vector.Location;
import org.bukkit.Material;
import java.util.Random; import java.util.Random;
@ -13,8 +14,8 @@ public class Cactus extends FractalTree {
* @param origin - The origin location. * @param origin - The origin location.
* @param random - The random object to use whilst generating the tree. * @param random - The random object to use whilst generating the tree.
*/ */
public Cactus(Location origin, Random random) { public Cactus(Location origin, Random random, TerraPlugin main) {
super(origin, random); super(origin, random, main);
} }
/** /**
@ -22,7 +23,8 @@ public class Cactus extends FractalTree {
*/ */
@Override @Override
public void grow() { public void grow() {
BlockData cactus = getMain().getWorldHandle().createBlockData("minecraft:cactus");
int h = super.getRandom().nextInt(4) + 1; int h = super.getRandom().nextInt(4) + 1;
for(int i = 0; i < h; i++) setBlock(super.getOrigin().clone().add(0, i, 0), Material.CACTUS); for(int i = 0; i < h; i++) setBlock(super.getOrigin().clone().add(0, i, 0), cactus);
} }
} }

View File

@ -3,16 +3,18 @@ package com.dfsek.terra.api.gaea.tree.fractal.trees;
import com.dfsek.terra.api.gaea.math.ProbabilityCollection; import com.dfsek.terra.api.gaea.math.ProbabilityCollection;
import com.dfsek.terra.api.gaea.tree.fractal.FractalTree; import com.dfsek.terra.api.gaea.tree.fractal.FractalTree;
import com.dfsek.terra.api.gaea.tree.fractal.TreeGeometry; import com.dfsek.terra.api.gaea.tree.fractal.TreeGeometry;
import com.dfsek.terra.api.generic.TerraPlugin;
import com.dfsek.terra.api.generic.world.WorldHandle;
import com.dfsek.terra.api.generic.world.block.BlockData;
import com.dfsek.terra.api.generic.world.vector.Location; import com.dfsek.terra.api.generic.world.vector.Location;
import com.dfsek.terra.api.generic.world.vector.Vector3; import com.dfsek.terra.api.generic.world.vector.Vector3;
import org.bukkit.Material;
import java.util.Random; import java.util.Random;
public class IceSpike extends FractalTree { public class IceSpike extends FractalTree {
private final TreeGeometry geo; private final TreeGeometry geo;
private static final ProbabilityCollection<Material> ice = new ProbabilityCollection<Material>().add(Material.PACKED_ICE, 95).add(Material.BLUE_ICE, 5); private final ProbabilityCollection<BlockData> ice;
/** /**
* Instantiates a TreeGrower at an origin location. * Instantiates a TreeGrower at an origin location.
@ -20,9 +22,11 @@ public class IceSpike extends FractalTree {
* @param origin - The origin location. * @param origin - The origin location.
* @param random - The random object to use whilst generating the tree. * @param random - The random object to use whilst generating the tree.
*/ */
public IceSpike(Location origin, Random random) { public IceSpike(Location origin, Random random, TerraPlugin main) {
super(origin, random); super(origin, random, main);
geo = new TreeGeometry(this); geo = new TreeGeometry(this);
WorldHandle handle = main.getWorldHandle();
ice = new ProbabilityCollection<BlockData>().add(handle.createBlockData("minecraft:packed_ice"), 95).add(handle.createBlockData("minecraft:blue_ice"), 5);
} }
private double getOffset() { private double getOffset() {

View File

@ -2,10 +2,11 @@ package com.dfsek.terra.api.gaea.tree.fractal.trees;
import com.dfsek.terra.api.gaea.tree.fractal.FractalTree; import com.dfsek.terra.api.gaea.tree.fractal.FractalTree;
import com.dfsek.terra.api.gaea.tree.fractal.TreeGeometry; import com.dfsek.terra.api.gaea.tree.fractal.TreeGeometry;
import com.dfsek.terra.api.generic.TerraPlugin;
import com.dfsek.terra.api.generic.world.block.BlockData;
import com.dfsek.terra.api.generic.world.vector.Location; import com.dfsek.terra.api.generic.world.vector.Location;
import com.dfsek.terra.api.generic.world.vector.Vector3; import com.dfsek.terra.api.generic.world.vector.Vector3;
import net.jafama.FastMath; import net.jafama.FastMath;
import org.bukkit.Material;
import java.util.Random; import java.util.Random;
@ -19,8 +20,8 @@ public class OakTree extends FractalTree {
* @param origin - The origin location. * @param origin - The origin location.
* @param random - The random object to use whilst generating the tree. * @param random - The random object to use whilst generating the tree.
*/ */
public OakTree(Location origin, Random random) { public OakTree(Location origin, Random random, TerraPlugin main) {
super(origin, random); super(origin, random, main);
geo = new TreeGeometry(this); geo = new TreeGeometry(this);
} }
@ -33,14 +34,16 @@ public class OakTree extends FractalTree {
} }
private void growBranch(Location l1, Vector3 diff, double d1, int recursions) { private void growBranch(Location l1, Vector3 diff, double d1, int recursions) {
BlockData wood = getMain().getWorldHandle().createBlockData("minecraft:oak_wood");
BlockData leaves = getMain().getWorldHandle().createBlockData("minecraft:oak_leave");
if(recursions > 1) { if(recursions > 1) {
geo.generateSphere(l1, Material.OAK_LEAVES, 1 + super.getRandom().nextInt(2) + (3 - recursions), false); geo.generateSphere(l1, leaves, 1 + super.getRandom().nextInt(2) + (3 - recursions), false);
if(recursions > 2) return; if(recursions > 2) return;
} }
if(diff.getY() < 0) diff.rotateAroundAxis(TreeGeometry.getPerpendicular(diff.clone()).normalize(), FastMath.PI); if(diff.getY() < 0) diff.rotateAroundAxis(TreeGeometry.getPerpendicular(diff.clone()).normalize(), FastMath.PI);
int d = (int) diff.length(); int d = (int) diff.length();
for(int i = 0; i < d; i++) { for(int i = 0; i < d; i++) {
geo.generateSphere(l1.clone().add(diff.clone().multiply((double) i / d)), Material.OAK_WOOD, FastMath.max((int) d1, 0), true); geo.generateSphere(l1.clone().add(diff.clone().multiply((double) i / d)), wood, FastMath.max((int) d1, 0), true);
} }
double runningAngle = (double) 45 / (recursions + 1); double runningAngle = (double) 45 / (recursions + 1);
growBranch(l1.clone().add(diff), diff.clone().multiply(0.75).rotateAroundX(FastMath.toRadians(runningAngle + getNoise())).rotateAroundZ(FastMath.toRadians(getNoise())), growBranch(l1.clone().add(diff), diff.clone().multiply(0.75).rotateAroundX(FastMath.toRadians(runningAngle + getNoise())).rotateAroundZ(FastMath.toRadians(getNoise())),

View File

@ -1,9 +1,9 @@
package com.dfsek.terra.api.gaea.tree.fractal.trees; package com.dfsek.terra.api.gaea.tree.fractal.trees;
import com.dfsek.terra.api.gaea.tree.fractal.FractalTree; import com.dfsek.terra.api.gaea.tree.fractal.FractalTree;
import com.dfsek.terra.api.generic.TerraPlugin;
import com.dfsek.terra.api.generic.world.block.BlockData;
import com.dfsek.terra.api.generic.world.vector.Location; import com.dfsek.terra.api.generic.world.vector.Location;
import org.bukkit.Material;
import org.bukkit.entity.EnderCrystal;
import java.util.Random; import java.util.Random;
@ -14,8 +14,8 @@ public class ShatteredPillar extends FractalTree {
* @param origin - The origin location. * @param origin - The origin location.
* @param random - The random object to use whilst generating the tree. * @param random - The random object to use whilst generating the tree.
*/ */
public ShatteredPillar(Location origin, Random random) { public ShatteredPillar(Location origin, Random random, TerraPlugin main) {
super(origin, random); super(origin, random, main);
} }
/** /**
@ -23,30 +23,28 @@ public class ShatteredPillar extends FractalTree {
*/ */
@Override @Override
public void grow() { public void grow() {
BlockData obsidian = getMain().getWorldHandle().createBlockData("minecraft:obsidian");
int h = super.getRandom().nextInt(5) + 8; int h = super.getRandom().nextInt(5) + 8;
int max = h; int max = h;
for(int i = - h; i < h; i++) setBlock(super.getOrigin().clone().add(0, i, 0), Material.OBSIDIAN); for(int i = - h; i < h; i++) setBlock(super.getOrigin().clone().add(0, i, 0), obsidian);
h = h + (getRandom().nextBoolean() ? getRandom().nextInt(3) + 1 : - (getRandom().nextInt(3) + 1)); h = h + (getRandom().nextBoolean() ? getRandom().nextInt(3) + 1 : - (getRandom().nextInt(3) + 1));
int[] crystalLoc = new int[] {0, 0}; int[] crystalLoc = new int[] {0, 0};
if(h > max) { if(h > max) {
max = h; max = h;
crystalLoc = new int[] {1, 0}; crystalLoc = new int[] {1, 0};
} }
for(int i = - h; i < h; i++) setBlock(super.getOrigin().clone().add(1, i, 0), Material.OBSIDIAN); for(int i = - h; i < h; i++) setBlock(super.getOrigin().clone().add(1, i, 0), obsidian);
h = h + (getRandom().nextBoolean() ? getRandom().nextInt(3) + 1 : - (getRandom().nextInt(3) + 1)); h = h + (getRandom().nextBoolean() ? getRandom().nextInt(3) + 1 : - (getRandom().nextInt(3) + 1));
if(h > max) { if(h > max) {
max = h; max = h;
crystalLoc = new int[] {0, 1}; crystalLoc = new int[] {0, 1};
} }
for(int i = - h; i < h; i++) setBlock(super.getOrigin().clone().add(0, i, 1), Material.OBSIDIAN); for(int i = - h; i < h; i++) setBlock(super.getOrigin().clone().add(0, i, 1), obsidian);
h = h + (getRandom().nextBoolean() ? getRandom().nextInt(3) + 1 : - (getRandom().nextInt(3) + 1)); h = h + (getRandom().nextBoolean() ? getRandom().nextInt(3) + 1 : - (getRandom().nextInt(3) + 1));
if(h > max) { if(h > max) {
max = h; max = h;
crystalLoc = new int[] {1, 1}; crystalLoc = new int[] {1, 1};
} }
for(int i = - h; i < h; i++) setBlock(super.getOrigin().clone().add(1, i, 1), Material.OBSIDIAN); for(int i = - h; i < h; i++) setBlock(super.getOrigin().clone().add(1, i, 1), obsidian);
if(getRandom().nextInt(100) < 25)
spawnEntity(getOrigin().add(crystalLoc[0] + 0.5, max, crystalLoc[1] + 0.5), EnderCrystal.class,
enderCrystal -> ((EnderCrystal) enderCrystal).setShowingBottom(false));
} }
} }

View File

@ -3,21 +3,19 @@ package com.dfsek.terra.api.gaea.tree.fractal.trees;
import com.dfsek.terra.api.gaea.math.ProbabilityCollection; import com.dfsek.terra.api.gaea.math.ProbabilityCollection;
import com.dfsek.terra.api.gaea.tree.fractal.FractalTree; import com.dfsek.terra.api.gaea.tree.fractal.FractalTree;
import com.dfsek.terra.api.gaea.tree.fractal.TreeGeometry; import com.dfsek.terra.api.gaea.tree.fractal.TreeGeometry;
import com.dfsek.terra.api.generic.TerraPlugin;
import com.dfsek.terra.api.generic.world.WorldHandle;
import com.dfsek.terra.api.generic.world.block.BlockData;
import com.dfsek.terra.api.generic.world.vector.Location; import com.dfsek.terra.api.generic.world.vector.Location;
import com.dfsek.terra.api.generic.world.vector.Vector3; import com.dfsek.terra.api.generic.world.vector.Vector3;
import net.jafama.FastMath; import net.jafama.FastMath;
import org.bukkit.Material;
import java.util.Random; import java.util.Random;
public class ShatteredTree extends FractalTree { public class ShatteredTree extends FractalTree {
private final TreeGeometry geo; private final TreeGeometry geo;
private final ProbabilityCollection<Material> bark = new ProbabilityCollection<Material>() private final ProbabilityCollection<BlockData> bark;
.add(Material.OBSIDIAN, 1) private final ProbabilityCollection<BlockData> leaves;
.add(Material.BLACK_CONCRETE, 1);
private final ProbabilityCollection<Material> leaves = new ProbabilityCollection<Material>()
.add(Material.PURPLE_STAINED_GLASS, 1)
.add(Material.MAGENTA_STAINED_GLASS, 1);
/** /**
* Instantiates a TreeGrower at an origin location. * Instantiates a TreeGrower at an origin location.
@ -25,9 +23,17 @@ public class ShatteredTree extends FractalTree {
* @param origin - The origin location. * @param origin - The origin location.
* @param random - The random object to use whilst generating the tree. * @param random - The random object to use whilst generating the tree.
*/ */
public ShatteredTree(Location origin, Random random) { public ShatteredTree(Location origin, Random random, TerraPlugin main) {
super(origin, random); super(origin, random, main);
geo = new TreeGeometry(this); geo = new TreeGeometry(this);
WorldHandle handle = main.getWorldHandle();
bark = new ProbabilityCollection<BlockData>()
.add(handle.createBlockData("minecraft:obsidian"), 1)
.add(handle.createBlockData("minecraft:black_concrete"), 1);
leaves = new ProbabilityCollection<BlockData>()
.add(handle.createBlockData("minecraft:purple_stained_glass"), 1)
.add(handle.createBlockData("minecraft:magenta_stained_glass"), 1);
} }
/** /**

View File

@ -1,8 +1,9 @@
package com.dfsek.terra.api.gaea.tree.fractal.trees; package com.dfsek.terra.api.gaea.tree.fractal.trees;
import com.dfsek.terra.api.gaea.tree.fractal.FractalTree; import com.dfsek.terra.api.gaea.tree.fractal.FractalTree;
import com.dfsek.terra.api.generic.TerraPlugin;
import com.dfsek.terra.api.generic.world.block.BlockData;
import com.dfsek.terra.api.generic.world.vector.Location; import com.dfsek.terra.api.generic.world.vector.Location;
import org.bukkit.Material;
import java.util.Random; import java.util.Random;
@ -13,8 +14,8 @@ public class SmallShatteredPillar extends FractalTree {
* @param origin - The origin location. * @param origin - The origin location.
* @param random - The random object to use whilst generating the tree. * @param random - The random object to use whilst generating the tree.
*/ */
public SmallShatteredPillar(Location origin, Random random) { public SmallShatteredPillar(Location origin, Random random, TerraPlugin main) {
super(origin, random); super(origin, random, main);
} }
/** /**
@ -23,6 +24,7 @@ public class SmallShatteredPillar extends FractalTree {
@Override @Override
public void grow() { public void grow() {
int h = super.getRandom().nextInt(5) + 5; int h = super.getRandom().nextInt(5) + 5;
for(int i = - h; i < h; i++) setBlock(super.getOrigin().clone().add(0, i, 0), Material.OBSIDIAN); BlockData obsidian = getMain().getWorldHandle().createBlockData("minecraft:obsidian");
for(int i = - h; i < h; i++) setBlock(super.getOrigin().clone().add(0, i, 0), obsidian);
} }
} }

View File

@ -3,21 +3,19 @@ package com.dfsek.terra.api.gaea.tree.fractal.trees;
import com.dfsek.terra.api.gaea.math.ProbabilityCollection; import com.dfsek.terra.api.gaea.math.ProbabilityCollection;
import com.dfsek.terra.api.gaea.tree.fractal.FractalTree; import com.dfsek.terra.api.gaea.tree.fractal.FractalTree;
import com.dfsek.terra.api.gaea.tree.fractal.TreeGeometry; import com.dfsek.terra.api.gaea.tree.fractal.TreeGeometry;
import com.dfsek.terra.api.generic.TerraPlugin;
import com.dfsek.terra.api.generic.world.WorldHandle;
import com.dfsek.terra.api.generic.world.block.BlockData;
import com.dfsek.terra.api.generic.world.vector.Location; import com.dfsek.terra.api.generic.world.vector.Location;
import com.dfsek.terra.api.generic.world.vector.Vector3; import com.dfsek.terra.api.generic.world.vector.Vector3;
import net.jafama.FastMath; import net.jafama.FastMath;
import org.bukkit.Material;
import java.util.Random; import java.util.Random;
public class SmallShatteredTree extends FractalTree { public class SmallShatteredTree extends FractalTree {
private final TreeGeometry geo; private final TreeGeometry geo;
private final ProbabilityCollection<Material> bark = new ProbabilityCollection<Material>() private final ProbabilityCollection<BlockData> bark;
.add(Material.OBSIDIAN, 1) private final ProbabilityCollection<BlockData> leaves;
.add(Material.BLACK_CONCRETE, 1);
private final ProbabilityCollection<Material> leaves = new ProbabilityCollection<Material>()
.add(Material.PURPLE_STAINED_GLASS, 1)
.add(Material.MAGENTA_STAINED_GLASS, 1);
/** /**
* Instantiates a TreeGrower at an origin location. * Instantiates a TreeGrower at an origin location.
@ -25,9 +23,17 @@ public class SmallShatteredTree extends FractalTree {
* @param origin - The origin location. * @param origin - The origin location.
* @param random - The random object to use whilst generating the tree. * @param random - The random object to use whilst generating the tree.
*/ */
public SmallShatteredTree(Location origin, Random random) { public SmallShatteredTree(Location origin, Random random, TerraPlugin main) {
super(origin, random); super(origin, random, main);
geo = new TreeGeometry(this); geo = new TreeGeometry(this);
WorldHandle handle = main.getWorldHandle();
bark = new ProbabilityCollection<BlockData>()
.add(handle.createBlockData("minecraft:obsidian"), 1)
.add(handle.createBlockData("minecraft:black_concrete"), 1);
leaves = new ProbabilityCollection<BlockData>()
.add(handle.createBlockData("minecraft:purple_stained_glass"), 1)
.add(handle.createBlockData("minecraft:magenta_stained_glass"), 1);
} }
/** /**

View File

@ -2,10 +2,11 @@ package com.dfsek.terra.api.gaea.tree.fractal.trees;
import com.dfsek.terra.api.gaea.tree.fractal.FractalTree; import com.dfsek.terra.api.gaea.tree.fractal.FractalTree;
import com.dfsek.terra.api.gaea.tree.fractal.TreeGeometry; import com.dfsek.terra.api.gaea.tree.fractal.TreeGeometry;
import com.dfsek.terra.api.generic.TerraPlugin;
import com.dfsek.terra.api.generic.world.block.BlockData;
import com.dfsek.terra.api.generic.world.vector.Location; import com.dfsek.terra.api.generic.world.vector.Location;
import com.dfsek.terra.api.generic.world.vector.Vector3; import com.dfsek.terra.api.generic.world.vector.Vector3;
import net.jafama.FastMath; import net.jafama.FastMath;
import org.bukkit.Material;
import java.util.Random; import java.util.Random;
@ -18,8 +19,8 @@ public class SpruceTree extends FractalTree {
* @param origin - The origin location. * @param origin - The origin location.
* @param random - The random object to use whilst generating the tree. * @param random - The random object to use whilst generating the tree.
*/ */
public SpruceTree(Location origin, Random random) { public SpruceTree(Location origin, Random random, TerraPlugin main) {
super(origin, random); super(origin, random, main);
geo = new TreeGeometry(this); geo = new TreeGeometry(this);
} }
@ -35,12 +36,14 @@ public class SpruceTree extends FractalTree {
if(diff.getY() < 0) diff.rotateAroundAxis(TreeGeometry.getPerpendicular(diff.clone()).normalize(), FastMath.PI); if(diff.getY() < 0) diff.rotateAroundAxis(TreeGeometry.getPerpendicular(diff.clone()).normalize(), FastMath.PI);
int d = (int) diff.length(); int d = (int) diff.length();
int rad = 7; int rad = 7;
BlockData wood = getMain().getWorldHandle().createBlockData("minecraft:spruce_wood");
BlockData leaves = getMain().getWorldHandle().createBlockData("minecraft:spruce_leave");
for(int i = 0; i < d; i++) { for(int i = 0; i < d; i++) {
geo.generateSphere(l1.clone().add(diff.clone().multiply((double) i / d)), Material.SPRUCE_WOOD, (int) ((i > d * 0.65) ? 0.5 : 1.5), true); geo.generateSphere(l1.clone().add(diff.clone().multiply((double) i / d)), wood, (int) ((i > d * 0.65) ? 0.5 : 1.5), true);
if(i > 3) if(i > 3)
geo.generateCylinder(l1.clone().add(diff.clone().multiply((double) i / d)), Material.SPRUCE_LEAVES, (int) (((6 - (i % 4))) * (1.25 - ((double) i / d))), 1, false); geo.generateCylinder(l1.clone().add(diff.clone().multiply((double) i / d)), leaves, (int) (((6 - (i % 4))) * (1.25 - ((double) i / d))), 1, false);
} }
setBlock(l1.clone().add(diff), Material.SPRUCE_LEAVES); setBlock(l1.clone().add(diff), leaves);
setBlock(l1.clone().add(diff).add(0, 1, 0), Material.SPRUCE_LEAVES); setBlock(l1.clone().add(diff).add(0, 1, 0), leaves);
} }
} }

View File

@ -1,5 +1,6 @@
package com.dfsek.terra.api.gaea.util; package com.dfsek.terra.api.gaea.util;
import org.apache.commons.rng.core.source64.XoRoShiRo128PlusPlus; import org.apache.commons.rng.core.source64.XoRoShiRo128PlusPlus;
import java.util.Random; import java.util.Random;

View File

@ -0,0 +1,5 @@
package com.dfsek.terra.api.generic;
public interface CommandSender extends Handle {
void sendMessage(String message);
}

View File

@ -0,0 +1,4 @@
package com.dfsek.terra.api.generic;
public interface Entity extends Handle {
}

View File

@ -2,14 +2,18 @@ package com.dfsek.terra.api.generic;
import com.dfsek.terra.TerraWorld; import com.dfsek.terra.TerraWorld;
import com.dfsek.terra.api.LoaderRegistrar; import com.dfsek.terra.api.LoaderRegistrar;
import com.dfsek.terra.api.gaea.lang.Language;
import com.dfsek.terra.api.generic.inventory.ItemHandle;
import com.dfsek.terra.api.generic.world.World; import com.dfsek.terra.api.generic.world.World;
import com.dfsek.terra.api.generic.world.WorldHandle; import com.dfsek.terra.api.generic.world.WorldHandle;
import com.dfsek.terra.config.base.PluginConfig; import com.dfsek.terra.config.base.PluginConfig;
import com.dfsek.terra.registry.ConfigRegistry;
import java.io.File;
import java.util.logging.Logger; import java.util.logging.Logger;
public interface TerraPlugin extends LoaderRegistrar { public interface TerraPlugin extends LoaderRegistrar {
WorldHandle getHandle(); WorldHandle getWorldHandle();
boolean isEnabled(); boolean isEnabled();
@ -18,4 +22,16 @@ public interface TerraPlugin extends LoaderRegistrar {
Logger getLogger(); Logger getLogger();
PluginConfig getTerraConfig(); PluginConfig getTerraConfig();
File getDataFolder();
boolean isDebug();
Language getLanguage();
ConfigRegistry getRegistry();
void reload();
ItemHandle getItemHandle();
} }

View File

@ -0,0 +1,4 @@
package com.dfsek.terra.api.generic;
public interface Tree extends Handle {
}

View File

@ -0,0 +1,11 @@
package com.dfsek.terra.api.generic.inventory;
import com.dfsek.terra.api.generic.Handle;
public interface Inventory extends Handle {
int getSize();
ItemStack getItem(int slot);
void setItem(int slot, ItemStack newStack);
}

View File

@ -0,0 +1,7 @@
package com.dfsek.terra.api.generic.inventory;
import com.dfsek.terra.api.generic.world.block.MaterialData;
public interface ItemHandle {
ItemStack newItemStack(MaterialData material, int amount);
}

View File

@ -0,0 +1,19 @@
package com.dfsek.terra.api.generic.inventory;
import com.dfsek.terra.api.generic.Handle;
import com.dfsek.terra.api.generic.inventory.item.ItemMeta;
import com.dfsek.terra.api.generic.world.block.MaterialData;
public interface ItemStack extends Handle, Cloneable {
int getAmount();
void setAmount(int i);
MaterialData getType();
ItemStack clone();
ItemMeta getItemMeta();
void setItemMeta(ItemMeta meta);
}

View File

@ -0,0 +1,10 @@
package com.dfsek.terra.api.generic.inventory.item;
import com.dfsek.terra.api.generic.Handle;
public interface Damageable extends Handle, Cloneable {
Damageable clone();
int getDamage();
void setDamage(int damage);
boolean hasDamage();
}

View File

@ -0,0 +1,6 @@
package com.dfsek.terra.api.generic.inventory.item;
import com.dfsek.terra.api.generic.Handle;
public interface ItemMeta extends Handle {
}

View File

@ -1,15 +1,15 @@
package com.dfsek.terra.api.generic.world; package com.dfsek.terra.api.generic.world;
import com.dfsek.terra.api.generic.Entity;
import com.dfsek.terra.api.generic.Handle; import com.dfsek.terra.api.generic.Handle;
import com.dfsek.terra.api.generic.Tree;
import com.dfsek.terra.api.generic.generator.ChunkGenerator; import com.dfsek.terra.api.generic.generator.ChunkGenerator;
import com.dfsek.terra.api.generic.world.block.Block; import com.dfsek.terra.api.generic.world.block.Block;
import com.dfsek.terra.api.generic.world.vector.Location; import com.dfsek.terra.api.generic.world.vector.Location;
import org.bukkit.TreeType;
import org.bukkit.entity.Entity;
import org.bukkit.util.Consumer;
import java.io.File; import java.io.File;
import java.util.UUID; import java.util.UUID;
import java.util.function.Consumer;
public interface World extends Handle { public interface World extends Handle {
long getSeed(); long getSeed();
@ -32,7 +32,7 @@ public interface World extends Handle {
Block getBlockAt(Location l); Block getBlockAt(Location l);
boolean generateTree(Location l, TreeType vanillaTreeType); // TODO: Bukkit treetype is bad boolean generateTree(Location l, Tree vanillaTreeType); // TODO: Bukkit treetype is bad
void spawn(Location location, Class<Entity> entity, Consumer<Entity> consumer); // TODO: Bukkit Entity is bad void spawn(Location location, Class<Entity> entity, Consumer<Entity> consumer); // TODO: Bukkit Entity is bad
} }

View File

@ -0,0 +1,5 @@
package com.dfsek.terra.api.generic.world.block;
public enum Axis {
X, Y, Z
}

View File

@ -82,67 +82,67 @@ public enum BlockFace {
} }
@NotNull @NotNull
public org.bukkit.block.BlockFace getOppositeFace() { public BlockFace getOppositeFace() {
switch(this) { switch(this) {
case NORTH: case NORTH:
return org.bukkit.block.BlockFace.SOUTH; return BlockFace.SOUTH;
case SOUTH: case SOUTH:
return org.bukkit.block.BlockFace.NORTH; return BlockFace.NORTH;
case EAST: case EAST:
return org.bukkit.block.BlockFace.WEST; return BlockFace.WEST;
case WEST: case WEST:
return org.bukkit.block.BlockFace.EAST; return BlockFace.EAST;
case UP: case UP:
return org.bukkit.block.BlockFace.DOWN; return BlockFace.DOWN;
case DOWN: case DOWN:
return org.bukkit.block.BlockFace.UP; return BlockFace.UP;
case NORTH_EAST: case NORTH_EAST:
return org.bukkit.block.BlockFace.SOUTH_WEST; return BlockFace.SOUTH_WEST;
case NORTH_WEST: case NORTH_WEST:
return org.bukkit.block.BlockFace.SOUTH_EAST; return BlockFace.SOUTH_EAST;
case SOUTH_EAST: case SOUTH_EAST:
return org.bukkit.block.BlockFace.NORTH_WEST; return BlockFace.NORTH_WEST;
case SOUTH_WEST: case SOUTH_WEST:
return org.bukkit.block.BlockFace.NORTH_EAST; return BlockFace.NORTH_EAST;
case WEST_NORTH_WEST: case WEST_NORTH_WEST:
return org.bukkit.block.BlockFace.EAST_SOUTH_EAST; return BlockFace.EAST_SOUTH_EAST;
case NORTH_NORTH_WEST: case NORTH_NORTH_WEST:
return org.bukkit.block.BlockFace.SOUTH_SOUTH_EAST; return BlockFace.SOUTH_SOUTH_EAST;
case NORTH_NORTH_EAST: case NORTH_NORTH_EAST:
return org.bukkit.block.BlockFace.SOUTH_SOUTH_WEST; return BlockFace.SOUTH_SOUTH_WEST;
case EAST_NORTH_EAST: case EAST_NORTH_EAST:
return org.bukkit.block.BlockFace.WEST_SOUTH_WEST; return BlockFace.WEST_SOUTH_WEST;
case EAST_SOUTH_EAST: case EAST_SOUTH_EAST:
return org.bukkit.block.BlockFace.WEST_NORTH_WEST; return BlockFace.WEST_NORTH_WEST;
case SOUTH_SOUTH_EAST: case SOUTH_SOUTH_EAST:
return org.bukkit.block.BlockFace.NORTH_NORTH_WEST; return BlockFace.NORTH_NORTH_WEST;
case SOUTH_SOUTH_WEST: case SOUTH_SOUTH_WEST:
return org.bukkit.block.BlockFace.NORTH_NORTH_EAST; return BlockFace.NORTH_NORTH_EAST;
case WEST_SOUTH_WEST: case WEST_SOUTH_WEST:
return org.bukkit.block.BlockFace.EAST_NORTH_EAST; return BlockFace.EAST_NORTH_EAST;
case SELF: case SELF:
return org.bukkit.block.BlockFace.SELF; return BlockFace.SELF;
} }
return org.bukkit.block.BlockFace.SELF; return BlockFace.SELF;
} }
} }

View File

@ -10,4 +10,6 @@ public interface MaterialData extends Handle {
boolean isSolid(); boolean isSolid();
boolean isAir(); boolean isAir();
double getMaxDurability();
} }

View File

@ -0,0 +1,9 @@
package com.dfsek.terra.api.generic.world.block.data;
import com.dfsek.terra.api.generic.world.block.BlockData;
public interface AnaloguePowerable extends BlockData {
int getMaximumPower();
int getPower();
void setPower(int power);
}

View File

@ -9,4 +9,8 @@ public interface MultipleFacing extends BlockData {
Set<BlockFace> getFaces(); Set<BlockFace> getFaces();
void setFace(BlockFace face, boolean facing); void setFace(BlockFace face, boolean facing);
Set<BlockFace> getAllowedFaces();
boolean hasFace(BlockFace f);
} }

View File

@ -0,0 +1,12 @@
package com.dfsek.terra.api.generic.world.block.data;
import com.dfsek.terra.api.generic.world.block.Axis;
import com.dfsek.terra.api.generic.world.block.BlockData;
import java.util.Set;
public interface Orientable extends BlockData {
Set<Axis> getAxes();
void setAxis(Axis axis);
Axis getAxis();
}

View File

@ -0,0 +1,22 @@
package com.dfsek.terra.api.generic.world.block.data;
import com.dfsek.terra.api.generic.world.block.BlockData;
public interface Rail extends BlockData {
Shape getShape();
void setShape(Shape newShape);
enum Shape {
ASCENDING_EAST,
ASCENDING_NORTH,
ASCENDING_SOUTH,
ASCENDING_WEST,
EAST_WEST,
NORTH_EAST,
NORTH_SOUTH,
NORTH_WEST,
SOUTH_EAST,
SOUTH_WEST
}
}

View File

@ -0,0 +1,15 @@
package com.dfsek.terra.api.generic.world.block.data;
import com.dfsek.terra.api.generic.world.block.BlockData;
import com.dfsek.terra.api.generic.world.block.BlockFace;
import java.util.Set;
public interface RedstoneWire extends BlockData, AnaloguePowerable {
Set<BlockFace> getAllowedFaces();
Connection getFace(BlockFace face);
void setFace(BlockFace face, Connection connection);
enum Connection {
NONE, SIDE, UP
}
}

View File

@ -0,0 +1,15 @@
package com.dfsek.terra.api.generic.world.block.data;
import com.dfsek.terra.api.generic.world.block.BlockData;
import com.dfsek.terra.api.generic.world.block.BlockFace;
public interface Wall extends BlockData, Waterlogged {
boolean isUp();
void setHeight(BlockFace face, Height height);
Height getHeight(BlockFace face);
void setUp(boolean up);
enum Height {
LOW, NONE, TALL
}
}

View File

@ -0,0 +1,4 @@
package com.dfsek.terra.api.generic.world.block.state;
public interface BlockState {
}

Some files were not shown because too many files have changed in this diff Show More