mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-12-19 23:19:21 +00:00
Compare commits
59 Commits
old/iris4
...
feat/stati
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3a74164627 | ||
|
|
894de013dd | ||
|
|
e1a7e772cf | ||
|
|
3c6411c322 | ||
|
|
628761affa | ||
|
|
9a81905fdd | ||
|
|
fa7b0f68ff | ||
|
|
487d0ac237 | ||
|
|
e79e3fbe45 | ||
|
|
23a0ab23aa | ||
|
|
c78ffab948 | ||
|
|
d58f497b71 | ||
|
|
3284ab84c5 | ||
|
|
5cf0ac9315 | ||
|
|
4e4e820826 | ||
|
|
cb6e4570f4 | ||
|
|
fb59c7370d | ||
|
|
c16e65f0a8 | ||
|
|
d9681edf62 | ||
|
|
520c156d5f | ||
|
|
5c26ec2521 | ||
|
|
d192e2b6d1 | ||
|
|
5b60b655ed | ||
|
|
97c7ac0528 | ||
|
|
090ff730a7 | ||
|
|
c1f797e7c9 | ||
|
|
4a1a6b80a6 | ||
|
|
e189b2389c | ||
|
|
3265447536 | ||
|
|
8c7c9f89e1 | ||
|
|
d7a991b9b3 | ||
|
|
abf6c93f2e | ||
|
|
1b76a66760 | ||
|
|
c83ac67b47 | ||
|
|
1dca502a90 | ||
|
|
cacef8c8fc | ||
|
|
623fd45ef4 | ||
|
|
007b4b0b53 | ||
|
|
b6bacee095 | ||
|
|
d5251350a1 | ||
|
|
1f9c72d093 | ||
|
|
a1495a10e5 | ||
|
|
11ae48bea1 | ||
|
|
b0f4b29a2d | ||
|
|
c38bb1cd01 | ||
|
|
7faa727bd2 | ||
|
|
9e40259ca2 | ||
|
|
94a7692735 | ||
|
|
8b803a87f0 | ||
|
|
3ae6e92eaf | ||
|
|
0f3c52a5aa | ||
|
|
747be7aa09 | ||
|
|
d651f204f8 | ||
|
|
2bd3ac7a9b | ||
|
|
5e437b34e3 | ||
|
|
a5ef89a128 | ||
|
|
558b8e4eca | ||
|
|
0a001b8a63 | ||
|
|
6c6c9654c1 |
71
build.gradle
71
build.gradle
@@ -32,7 +32,7 @@ plugins {
|
|||||||
id "de.undercouch.download" version "5.0.1"
|
id "de.undercouch.download" version "5.0.1"
|
||||||
}
|
}
|
||||||
|
|
||||||
version '3.4.3-1.19.2-1.21.1'
|
version '3.5.2-1.19.2-1.21.3'
|
||||||
|
|
||||||
// ADD YOURSELF AS A NEW LINE IF YOU WANT YOUR OWN BUILD TASK GENERATED
|
// ADD YOURSELF AS A NEW LINE IF YOU WANT YOUR OWN BUILD TASK GENERATED
|
||||||
// ======================== WINDOWS =============================
|
// ======================== WINDOWS =============================
|
||||||
@@ -43,7 +43,8 @@ registerCustomOutputTask('Coco', 'D://mcsm/plugins')
|
|||||||
registerCustomOutputTask('Strange', 'D://Servers/1.17 Test Server/plugins')
|
registerCustomOutputTask('Strange', 'D://Servers/1.17 Test Server/plugins')
|
||||||
registerCustomOutputTask('Vatuu', 'D://Minecraft/Servers/1.19.4/plugins')
|
registerCustomOutputTask('Vatuu', 'D://Minecraft/Servers/1.19.4/plugins')
|
||||||
registerCustomOutputTask('CrazyDev22', 'C://Users/Julian/Desktop/server/plugins')
|
registerCustomOutputTask('CrazyDev22', 'C://Users/Julian/Desktop/server/plugins')
|
||||||
registerCustomOutputTask('Pixel', 'C://Users/repix/Iris Dimension Engine/1.20.4 - Development/plugins')
|
registerCustomOutputTask('PixelFury', 'C://Users/repix/workplace/Iris/1.21.3 - Development-Public-v3/plugins')
|
||||||
|
registerCustomOutputTask('PixelFuryDev', 'C://Users/repix/workplace/Iris/1.21 - Development-v3/plugins')
|
||||||
// ========================== UNIX ==============================
|
// ========================== UNIX ==============================
|
||||||
registerCustomOutputTaskUnix('CyberpwnLT', '/Users/danielmills/development/server/plugins')
|
registerCustomOutputTaskUnix('CyberpwnLT', '/Users/danielmills/development/server/plugins')
|
||||||
registerCustomOutputTaskUnix('PsychoLT', '/Users/brianfopiano/Developer/RemoteGit/Server/plugins')
|
registerCustomOutputTaskUnix('PsychoLT', '/Users/brianfopiano/Developer/RemoteGit/Server/plugins')
|
||||||
@@ -52,7 +53,8 @@ registerCustomOutputTaskUnix('CrazyDev22LT', '/home/julian/Desktop/server/plugin
|
|||||||
// ==============================================================
|
// ==============================================================
|
||||||
|
|
||||||
def NMS_BINDINGS = Map.of(
|
def NMS_BINDINGS = Map.of(
|
||||||
"v1_21_R1", "1.21-R0.1-SNAPSHOT",
|
"v1_21_R2", "1.21.3-R0.1-SNAPSHOT",
|
||||||
|
"v1_21_R1", "1.21.1-R0.1-SNAPSHOT",
|
||||||
"v1_20_R4", "1.20.6-R0.1-SNAPSHOT",
|
"v1_20_R4", "1.20.6-R0.1-SNAPSHOT",
|
||||||
"v1_20_R3", "1.20.4-R0.1-SNAPSHOT",
|
"v1_20_R3", "1.20.4-R0.1-SNAPSHOT",
|
||||||
"v1_20_R2", "1.20.2-R0.1-SNAPSHOT",
|
"v1_20_R2", "1.20.2-R0.1-SNAPSHOT",
|
||||||
@@ -61,17 +63,14 @@ def NMS_BINDINGS = Map.of(
|
|||||||
"v1_19_R2", "1.19.3-R0.1-SNAPSHOT",
|
"v1_19_R2", "1.19.3-R0.1-SNAPSHOT",
|
||||||
"v1_19_R1", "1.19.2-R0.1-SNAPSHOT"
|
"v1_19_R1", "1.19.2-R0.1-SNAPSHOT"
|
||||||
)
|
)
|
||||||
def JVM_VERSION = Map.of(
|
def JVM_VERSION = Map.of()
|
||||||
"v1_21_R1", 21,
|
|
||||||
"v1_20_R4", 21,
|
|
||||||
)
|
|
||||||
NMS_BINDINGS.each { nms ->
|
NMS_BINDINGS.each { nms ->
|
||||||
project(":nms:${nms.key}") {
|
project(":nms:${nms.key}") {
|
||||||
apply plugin: 'java'
|
apply plugin: 'java'
|
||||||
apply plugin: 'com.volmit.nmstools'
|
apply plugin: 'com.volmit.nmstools'
|
||||||
|
|
||||||
nmsTools {
|
nmsTools {
|
||||||
it.jvm = JVM_VERSION.getOrDefault(nms.key, 17)
|
it.jvm = JVM_VERSION.getOrDefault(nms.key, 21)
|
||||||
it.version = nms.value
|
it.version = nms.value
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,6 +91,7 @@ shadowJar {
|
|||||||
relocate 'com.dfsek.paralithic', 'com.volmit.iris.util.paralithic'
|
relocate 'com.dfsek.paralithic', 'com.volmit.iris.util.paralithic'
|
||||||
relocate 'io.papermc.lib', 'com.volmit.iris.util.paper'
|
relocate 'io.papermc.lib', 'com.volmit.iris.util.paper'
|
||||||
relocate 'net.kyori', 'com.volmit.iris.util.kyori'
|
relocate 'net.kyori', 'com.volmit.iris.util.kyori'
|
||||||
|
relocate 'org.bstats', 'com.volmit.util.metrics'
|
||||||
archiveFileName.set("Iris-${project.version}.jar")
|
archiveFileName.set("Iris-${project.version}.jar")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,23 +109,24 @@ allprojects {
|
|||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
maven { url "https://repo.papermc.io/repository/maven-public/"}
|
maven { url "https://repo.papermc.io/repository/maven-public/" }
|
||||||
maven { url "https://repo.codemc.org/repository/maven-public" }
|
maven { url "https://repo.codemc.org/repository/maven-public" }
|
||||||
maven { url "https://mvn.lumine.io/repository/maven-public/" }
|
maven { url "https://mvn.lumine.io/repository/maven-public/" }
|
||||||
maven { url "https://jitpack.io"}
|
maven { url "https://jitpack.io" }
|
||||||
|
|
||||||
maven { url "https://s01.oss.sonatype.org/content/repositories/snapshots" }
|
maven { url "https://s01.oss.sonatype.org/content/repositories/snapshots" }
|
||||||
maven { url "https://mvn.lumine.io/repository/maven/" }
|
maven { url "https://mvn.lumine.io/repository/maven/" }
|
||||||
maven { url "https://repo.triumphteam.dev/snapshots" }
|
maven { url "https://repo.triumphteam.dev/snapshots" }
|
||||||
maven { url "https://repo.mineinabyss.com/releases" }
|
maven { url "https://repo.mineinabyss.com/releases" }
|
||||||
maven { url 'https://hub.jeff-media.com/nexus/repository/jeff-media-public/' }
|
maven { url 'https://hub.jeff-media.com/nexus/repository/jeff-media-public/' }
|
||||||
maven { url "https://repo.oraxen.com/releases" }
|
maven { url "https://repo.nexomc.com/snapshots/" }
|
||||||
|
maven { url "https://libraries.minecraft.net" }
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
// Provided or Classpath
|
// Provided or Classpath
|
||||||
compileOnly 'org.projectlombok:lombok:1.18.24'
|
compileOnly 'org.projectlombok:lombok:1.18.36'
|
||||||
annotationProcessor 'org.projectlombok:lombok:1.18.24'
|
annotationProcessor 'org.projectlombok:lombok:1.18.36'
|
||||||
|
|
||||||
// Shaded
|
// Shaded
|
||||||
implementation 'com.dfsek:Paralithic:0.4.0'
|
implementation 'com.dfsek:Paralithic:0.4.0'
|
||||||
@@ -133,9 +134,11 @@ allprojects {
|
|||||||
implementation "net.kyori:adventure-text-minimessage:4.17.0"
|
implementation "net.kyori:adventure-text-minimessage:4.17.0"
|
||||||
implementation 'net.kyori:adventure-platform-bukkit:4.3.4'
|
implementation 'net.kyori:adventure-platform-bukkit:4.3.4'
|
||||||
implementation 'net.kyori:adventure-api:4.17.0'
|
implementation 'net.kyori:adventure-api:4.17.0'
|
||||||
|
implementation 'org.bstats:bstats-bukkit:3.1.0'
|
||||||
//implementation 'org.bytedeco:javacpp:1.5.10'
|
//implementation 'org.bytedeco:javacpp:1.5.10'
|
||||||
//implementation 'org.bytedeco:cuda-platform:12.3-8.9-1.5.10'
|
//implementation 'org.bytedeco:cuda-platform:12.3-8.9-1.5.10'
|
||||||
compileOnly 'io.lumine:Mythic-Dist:5.2.1'
|
compileOnly 'io.lumine:Mythic-Dist:5.2.1'
|
||||||
|
compileOnly 'io.lumine:MythicCrucible-Dist:2.0.0'
|
||||||
|
|
||||||
// Dynamically Loaded
|
// Dynamically Loaded
|
||||||
compileOnly 'io.timeandspace:smoothie-map:2.0.2'
|
compileOnly 'io.timeandspace:smoothie-map:2.0.2'
|
||||||
@@ -149,6 +152,7 @@ allprojects {
|
|||||||
compileOnly 'rhino:js:1.7R2'
|
compileOnly 'rhino:js:1.7R2'
|
||||||
compileOnly 'com.github.ben-manes.caffeine:caffeine:3.0.6'
|
compileOnly 'com.github.ben-manes.caffeine:caffeine:3.0.6'
|
||||||
compileOnly 'org.apache.commons:commons-lang3:3.12.0'
|
compileOnly 'org.apache.commons:commons-lang3:3.12.0'
|
||||||
|
compileOnly 'com.github.oshi:oshi-core:6.6.5'
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -158,20 +162,35 @@ allprojects {
|
|||||||
options.compilerArgs << '-parameters'
|
options.compilerArgs << '-parameters'
|
||||||
options.encoding = "UTF-8"
|
options.encoding = "UTF-8"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
javadoc {
|
||||||
|
options.encoding = "UTF-8"
|
||||||
|
options.addStringOption('Xdoclint:none', '-quiet')
|
||||||
|
}
|
||||||
|
|
||||||
|
task sourcesJar(type: Jar, dependsOn: classes) {
|
||||||
|
archiveClassifier.set('sources')
|
||||||
|
from sourceSets.main.allSource
|
||||||
|
}
|
||||||
|
|
||||||
|
task javadocJar(type: Jar, dependsOn: javadoc) {
|
||||||
|
archiveClassifier.set('javadoc')
|
||||||
|
from javadoc.destinationDir
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (JavaVersion.current().toString() != "17") {
|
if (JavaVersion.current().toString() != "21") {
|
||||||
System.err.println()
|
System.err.println()
|
||||||
System.err.println("=========================================================================================================")
|
System.err.println("=========================================================================================================")
|
||||||
System.err.println("You must run gradle on Java 17. You are using " + JavaVersion.current())
|
System.err.println("You must run gradle on Java 21. You are using " + JavaVersion.current())
|
||||||
System.err.println()
|
System.err.println()
|
||||||
System.err.println("=== For IDEs ===")
|
System.err.println("=== For IDEs ===")
|
||||||
System.err.println("1. Configure the project for Java 17")
|
System.err.println("1. Configure the project for Java 21")
|
||||||
System.err.println("2. Configure the bundled gradle to use Java 17 in settings")
|
System.err.println("2. Configure the bundled gradle to use Java 21 in settings")
|
||||||
System.err.println()
|
System.err.println()
|
||||||
System.err.println("=== For Command Line (gradlew) ===")
|
System.err.println("=== For Command Line (gradlew) ===")
|
||||||
System.err.println("1. Install JDK 17 from https://www.oracle.com/java/technologies/javase/jdk17-archive-downloads.html")
|
System.err.println("1. Install JDK 21 from https://www.oracle.com/java/technologies/javase/jdk21-archive-downloads.html")
|
||||||
System.err.println("2. Set JAVA_HOME environment variable to the new jdk installation folder such as C:\\Program Files\\Java\\jdk-17.0.1")
|
System.err.println("2. Set JAVA_HOME environment variable to the new jdk installation folder such as C:\\Program Files\\Java\\jdk-21.0.4")
|
||||||
System.err.println("3. Open a new command prompt window to get the new environment variables if need be.")
|
System.err.println("3. Open a new command prompt window to get the new environment variables if need be.")
|
||||||
System.err.println("=========================================================================================================")
|
System.err.println("=========================================================================================================")
|
||||||
System.err.println()
|
System.err.println()
|
||||||
@@ -185,6 +204,20 @@ task iris(type: Copy) {
|
|||||||
dependsOn(build)
|
dependsOn(build)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// with classifier: 'javadoc' and 'sources'
|
||||||
|
task irisDev(type: Copy) {
|
||||||
|
group "iris"
|
||||||
|
from("core/build/libs/core-javadoc.jar", "core/build/libs/core-sources.jar")
|
||||||
|
rename { String fileName ->
|
||||||
|
fileName.replace("core", "Iris-${version}")
|
||||||
|
}
|
||||||
|
into layout.buildDirectory.asFile.get()
|
||||||
|
dependsOn(iris)
|
||||||
|
dependsOn("core:sourcesJar")
|
||||||
|
dependsOn("core:javadocJar")
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
def registerCustomOutputTask(name, path) {
|
def registerCustomOutputTask(name, path) {
|
||||||
if (!System.properties['os.name'].toLowerCase().contains('windows')) {
|
if (!System.properties['os.name'].toLowerCase().contains('windows')) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ dependencies {
|
|||||||
|
|
||||||
// Third Party Integrations
|
// Third Party Integrations
|
||||||
compileOnly 'com.ticxo.playeranimator:PlayerAnimator:R1.2.7'
|
compileOnly 'com.ticxo.playeranimator:PlayerAnimator:R1.2.7'
|
||||||
compileOnly 'io.th0rgal:oraxen:1.173.0'
|
compileOnly 'com.nexomc:nexo:0.6.0-dev.0'
|
||||||
compileOnly 'com.github.LoneDev6:api-itemsadder:3.4.1-r4'
|
compileOnly 'com.github.LoneDev6:api-itemsadder:3.4.1-r4'
|
||||||
compileOnly 'com.github.PlaceholderAPI:placeholderapi:2.11.3'
|
compileOnly 'com.github.PlaceholderAPI:placeholderapi:2.11.3'
|
||||||
compileOnly 'com.github.Ssomar-Developement:SCore:4.23.10.8'
|
compileOnly 'com.github.Ssomar-Developement:SCore:4.23.10.8'
|
||||||
@@ -71,6 +71,9 @@ dependencies {
|
|||||||
//implementation files('libs/CustomItems.jar')
|
//implementation files('libs/CustomItems.jar')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
java {
|
||||||
|
disableAutoTargetJvm()
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gradle is weird sometimes, we need to delete the plugin yml from the build folder to actually filter properly.
|
* Gradle is weird sometimes, we need to delete the plugin yml from the build folder to actually filter properly.
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ import com.volmit.iris.engine.platform.BukkitChunkGenerator;
|
|||||||
import com.volmit.iris.engine.platform.DummyChunkGenerator;
|
import com.volmit.iris.engine.platform.DummyChunkGenerator;
|
||||||
import com.volmit.iris.core.safeguard.IrisSafeguard;
|
import com.volmit.iris.core.safeguard.IrisSafeguard;
|
||||||
import com.volmit.iris.core.safeguard.UtilsSFG;
|
import com.volmit.iris.core.safeguard.UtilsSFG;
|
||||||
|
import com.volmit.iris.engine.platform.PlatformChunkGenerator;
|
||||||
import com.volmit.iris.util.collection.KList;
|
import com.volmit.iris.util.collection.KList;
|
||||||
import com.volmit.iris.util.collection.KMap;
|
import com.volmit.iris.util.collection.KMap;
|
||||||
import com.volmit.iris.util.exceptions.IrisException;
|
import com.volmit.iris.util.exceptions.IrisException;
|
||||||
@@ -55,7 +56,6 @@ import com.volmit.iris.util.math.RNG;
|
|||||||
import com.volmit.iris.util.misc.getHardware;
|
import com.volmit.iris.util.misc.getHardware;
|
||||||
import com.volmit.iris.util.parallel.MultiBurst;
|
import com.volmit.iris.util.parallel.MultiBurst;
|
||||||
import com.volmit.iris.util.plugin.IrisService;
|
import com.volmit.iris.util.plugin.IrisService;
|
||||||
import com.volmit.iris.util.plugin.Metrics;
|
|
||||||
import com.volmit.iris.util.plugin.VolmitPlugin;
|
import com.volmit.iris.util.plugin.VolmitPlugin;
|
||||||
import com.volmit.iris.util.plugin.VolmitSender;
|
import com.volmit.iris.util.plugin.VolmitSender;
|
||||||
import com.volmit.iris.util.reflect.ShadeFix;
|
import com.volmit.iris.util.reflect.ShadeFix;
|
||||||
@@ -63,13 +63,13 @@ import com.volmit.iris.util.scheduling.J;
|
|||||||
import com.volmit.iris.util.scheduling.Queue;
|
import com.volmit.iris.util.scheduling.Queue;
|
||||||
import com.volmit.iris.util.scheduling.ShurikenQueue;
|
import com.volmit.iris.util.scheduling.ShurikenQueue;
|
||||||
import io.papermc.lib.PaperLib;
|
import io.papermc.lib.PaperLib;
|
||||||
import lombok.Getter;
|
|
||||||
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
||||||
import net.kyori.adventure.text.serializer.ComponentSerializer;
|
import net.kyori.adventure.text.serializer.ComponentSerializer;
|
||||||
import org.bukkit.Bukkit;
|
import org.bstats.bukkit.Metrics;
|
||||||
import org.bukkit.GameMode;
|
import org.bstats.charts.DrilldownPie;
|
||||||
import org.bukkit.Location;
|
import org.bstats.charts.SimplePie;
|
||||||
import org.bukkit.WorldCreator;
|
import org.bstats.charts.SingleLineChart;
|
||||||
|
import org.bukkit.*;
|
||||||
import org.bukkit.block.data.BlockData;
|
import org.bukkit.block.data.BlockData;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
@@ -77,33 +77,31 @@ import org.bukkit.configuration.ConfigurationSection;
|
|||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.*;
|
||||||
import org.bukkit.event.HandlerList;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.generator.BiomeProvider;
|
import org.bukkit.generator.BiomeProvider;
|
||||||
import org.bukkit.generator.ChunkGenerator;
|
import org.bukkit.generator.ChunkGenerator;
|
||||||
import org.bukkit.plugin.IllegalPluginAccessException;
|
import org.bukkit.plugin.IllegalPluginAccessException;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import oshi.SystemInfo;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.lang.annotation.Annotation;
|
import java.lang.annotation.Annotation;
|
||||||
import java.lang.management.ManagementFactory;
|
import java.math.RoundingMode;
|
||||||
import java.lang.management.OperatingSystemMXBean;
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.Date;
|
import java.text.NumberFormat;
|
||||||
import java.util.Map;
|
import java.util.*;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static com.volmit.iris.core.safeguard.IrisSafeguard.*;
|
import static com.volmit.iris.core.safeguard.IrisSafeguard.*;
|
||||||
import static com.volmit.iris.core.safeguard.ServerBootSFG.passedserversoftware;
|
import static com.volmit.iris.core.safeguard.ServerBootSFG.passedserversoftware;
|
||||||
import static com.volmit.iris.util.misc.getHardware.getCPUModel;
|
|
||||||
|
|
||||||
@SuppressWarnings("CanBeFinal")
|
@SuppressWarnings("CanBeFinal")
|
||||||
public class Iris extends VolmitPlugin implements Listener {
|
public class Iris extends VolmitPlugin implements Listener {
|
||||||
public static final String OVERWORLD_TAG = "3800";
|
public static final String OVERWORLD_TAG = "31000";
|
||||||
|
|
||||||
private static final Queue<Runnable> syncJobs = new ShurikenQueue<>();
|
private static final Queue<Runnable> syncJobs = new ShurikenQueue<>();
|
||||||
|
|
||||||
@@ -512,11 +510,10 @@ public class Iris extends VolmitPlugin implements Listener {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
Iris.info("2 World: %s | Generator: %s", s, generator);
|
if (Bukkit.getWorld(s) != null)
|
||||||
|
|
||||||
if (Bukkit.getWorlds().stream().anyMatch(w -> w.getName().equals(s))) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
|
Iris.info("Loading World: %s | Generator: %s", s, generator);
|
||||||
|
|
||||||
Iris.info(C.LIGHT_PURPLE + "Preparing Spawn for " + s + "' using Iris:" + generator + "...");
|
Iris.info(C.LIGHT_PURPLE + "Preparing Spawn for " + s + "' using Iris:" + generator + "...");
|
||||||
new WorldCreator(s)
|
new WorldCreator(s)
|
||||||
@@ -664,7 +661,48 @@ public class Iris extends VolmitPlugin implements Listener {
|
|||||||
|
|
||||||
private void bstats() {
|
private void bstats() {
|
||||||
if (IrisSettings.get().getGeneral().isPluginMetrics()) {
|
if (IrisSettings.get().getGeneral().isPluginMetrics()) {
|
||||||
J.s(() -> new Metrics(Iris.instance, 8757));
|
J.s(() -> {
|
||||||
|
var metrics = new Metrics(Iris.instance, 24220);
|
||||||
|
metrics.addCustomChart(new SingleLineChart("custom_dimensions", () -> Bukkit.getWorlds()
|
||||||
|
.stream()
|
||||||
|
.filter(IrisToolbelt::isIrisWorld)
|
||||||
|
.mapToInt(w -> 1)
|
||||||
|
.sum()));
|
||||||
|
|
||||||
|
metrics.addCustomChart(new DrilldownPie("used_packs", () -> Bukkit.getWorlds().stream()
|
||||||
|
.map(IrisToolbelt::access)
|
||||||
|
.filter(Objects::nonNull)
|
||||||
|
.map(PlatformChunkGenerator::getTarget)
|
||||||
|
.collect(Collectors.toMap(target -> target.getDimension().getLoadKey(), target -> {
|
||||||
|
int version = target.getDimension().getVersion();
|
||||||
|
String checksum = IO.hashRecursive(target.getData().getDataFolder());
|
||||||
|
|
||||||
|
return Map.of("v" + version + " (" + checksum + ")", 1);
|
||||||
|
}, (a, b) -> {
|
||||||
|
Map<String, Integer> merged = new HashMap<>(a);
|
||||||
|
b.forEach((k, v) -> merged.merge(k, v, Integer::sum));
|
||||||
|
return merged;
|
||||||
|
}))));
|
||||||
|
|
||||||
|
|
||||||
|
var info = new SystemInfo().getHardware();
|
||||||
|
var cpu = info.getProcessor().getProcessorIdentifier();
|
||||||
|
var mem = info.getMemory();
|
||||||
|
metrics.addCustomChart(new SimplePie("cpu_model", cpu::getName));
|
||||||
|
|
||||||
|
var nf = NumberFormat.getInstance(Locale.ENGLISH);
|
||||||
|
nf.setMinimumFractionDigits(0);
|
||||||
|
nf.setMaximumFractionDigits(2);
|
||||||
|
nf.setRoundingMode(RoundingMode.HALF_UP);
|
||||||
|
|
||||||
|
metrics.addCustomChart(new DrilldownPie("memory", () -> {
|
||||||
|
double total = mem.getTotal() * 1E-9;
|
||||||
|
double alloc = Math.min(total, Runtime.getRuntime().maxMemory() * 1E-9);
|
||||||
|
return Map.of(nf.format(alloc), Map.of(nf.format(total), 1));
|
||||||
|
}));
|
||||||
|
|
||||||
|
postShutdown.add(metrics::shutdown);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,9 @@ import com.volmit.iris.util.json.JSONException;
|
|||||||
import com.volmit.iris.util.json.JSONObject;
|
import com.volmit.iris.util.json.JSONObject;
|
||||||
import com.volmit.iris.util.plugin.VolmitSender;
|
import com.volmit.iris.util.plugin.VolmitSender;
|
||||||
import com.volmit.iris.util.scheduling.ChronoLatch;
|
import com.volmit.iris.util.scheduling.ChronoLatch;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -42,6 +44,7 @@ public class IrisSettings {
|
|||||||
private IrisSettingsConcurrency concurrency = new IrisSettingsConcurrency();
|
private IrisSettingsConcurrency concurrency = new IrisSettingsConcurrency();
|
||||||
private IrisSettingsStudio studio = new IrisSettingsStudio();
|
private IrisSettingsStudio studio = new IrisSettingsStudio();
|
||||||
private IrisSettingsPerformance performance = new IrisSettingsPerformance();
|
private IrisSettingsPerformance performance = new IrisSettingsPerformance();
|
||||||
|
private IrisSettingsUpdater updater = new IrisSettingsUpdater();
|
||||||
|
|
||||||
public static int getThreadCount(int c) {
|
public static int getThreadCount(int c) {
|
||||||
return switch (c) {
|
return switch (c) {
|
||||||
@@ -144,6 +147,30 @@ public class IrisSettings {
|
|||||||
public int scriptLoaderCacheSize = 512;
|
public int scriptLoaderCacheSize = 512;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public static class IrisSettingsUpdater {
|
||||||
|
public double threadMultiplier = 2;
|
||||||
|
public double chunkLoadSensitivity = 0.7;
|
||||||
|
public MsRange emptyMsRange = new MsRange(80, 100);
|
||||||
|
public MsRange defaultMsRange = new MsRange(20, 40);
|
||||||
|
|
||||||
|
public double getThreadMultiplier() {
|
||||||
|
return Math.min(Math.abs(threadMultiplier), 0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getChunkLoadSensitivity() {
|
||||||
|
return Math.min(chunkLoadSensitivity, 0.9);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public static class MsRange {
|
||||||
|
public int min = 20;
|
||||||
|
public int max = 40;
|
||||||
|
}
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public static class IrisSettingsGeneral {
|
public static class IrisSettingsGeneral {
|
||||||
public boolean DoomsdayAnnihilationSelfDestructMode = false;
|
public boolean DoomsdayAnnihilationSelfDestructMode = false;
|
||||||
|
|||||||
@@ -21,36 +21,25 @@ package com.volmit.iris.core.commands;
|
|||||||
import com.volmit.iris.Iris;
|
import com.volmit.iris.Iris;
|
||||||
import com.volmit.iris.core.ServerConfigurator;
|
import com.volmit.iris.core.ServerConfigurator;
|
||||||
import com.volmit.iris.core.loader.IrisData;
|
import com.volmit.iris.core.loader.IrisData;
|
||||||
import com.volmit.iris.core.nms.INMS;
|
|
||||||
import com.volmit.iris.core.nms.datapack.DataVersion;
|
import com.volmit.iris.core.nms.datapack.DataVersion;
|
||||||
import com.volmit.iris.core.nms.v1X.NMSBinding1X;
|
|
||||||
import com.volmit.iris.core.pregenerator.ChunkUpdater;
|
|
||||||
import com.volmit.iris.core.service.IrisEngineSVC;
|
import com.volmit.iris.core.service.IrisEngineSVC;
|
||||||
import com.volmit.iris.core.tools.IrisConverter;
|
|
||||||
import com.volmit.iris.core.tools.IrisPackBenchmarking;
|
import com.volmit.iris.core.tools.IrisPackBenchmarking;
|
||||||
import com.volmit.iris.core.tools.IrisToolbelt;
|
import com.volmit.iris.core.tools.IrisToolbelt;
|
||||||
import com.volmit.iris.engine.framework.Engine;
|
import com.volmit.iris.engine.framework.Engine;
|
||||||
import com.volmit.iris.engine.mantle.components.MantleObjectComponent;
|
|
||||||
import com.volmit.iris.engine.object.IrisBiome;
|
|
||||||
import com.volmit.iris.engine.object.IrisCave;
|
|
||||||
import com.volmit.iris.engine.object.IrisDimension;
|
import com.volmit.iris.engine.object.IrisDimension;
|
||||||
import com.volmit.iris.engine.object.IrisEntity;
|
|
||||||
import com.volmit.iris.util.data.Dimension;
|
|
||||||
import com.volmit.iris.util.decree.DecreeExecutor;
|
import com.volmit.iris.util.decree.DecreeExecutor;
|
||||||
import com.volmit.iris.util.decree.DecreeOrigin;
|
import com.volmit.iris.util.decree.DecreeOrigin;
|
||||||
import com.volmit.iris.util.decree.annotations.Decree;
|
import com.volmit.iris.util.decree.annotations.Decree;
|
||||||
import com.volmit.iris.util.decree.annotations.Param;
|
import com.volmit.iris.util.decree.annotations.Param;
|
||||||
import com.volmit.iris.util.format.C;
|
import com.volmit.iris.util.format.C;
|
||||||
import com.volmit.iris.util.format.Form;
|
import com.volmit.iris.util.format.Form;
|
||||||
|
import com.volmit.iris.util.io.CountingDataInputStream;
|
||||||
import com.volmit.iris.util.io.IO;
|
import com.volmit.iris.util.io.IO;
|
||||||
import com.volmit.iris.util.mantle.TectonicPlate;
|
import com.volmit.iris.util.mantle.TectonicPlate;
|
||||||
import com.volmit.iris.util.math.Spiraler;
|
|
||||||
import com.volmit.iris.util.math.Vector3d;
|
|
||||||
import com.volmit.iris.util.nbt.mca.MCAFile;
|
import com.volmit.iris.util.nbt.mca.MCAFile;
|
||||||
import com.volmit.iris.util.nbt.mca.MCAUtil;
|
import com.volmit.iris.util.nbt.mca.MCAUtil;
|
||||||
import com.volmit.iris.util.parallel.MultiBurst;
|
import com.volmit.iris.util.parallel.MultiBurst;
|
||||||
import com.volmit.iris.util.plugin.VolmitSender;
|
import com.volmit.iris.util.plugin.VolmitSender;
|
||||||
import io.lumine.mythic.bukkit.adapters.BukkitEntity;
|
|
||||||
import net.jpountz.lz4.LZ4BlockInputStream;
|
import net.jpountz.lz4.LZ4BlockInputStream;
|
||||||
import net.jpountz.lz4.LZ4BlockOutputStream;
|
import net.jpountz.lz4.LZ4BlockOutputStream;
|
||||||
import net.jpountz.lz4.LZ4FrameInputStream;
|
import net.jpountz.lz4.LZ4FrameInputStream;
|
||||||
@@ -58,10 +47,7 @@ import net.jpountz.lz4.LZ4FrameOutputStream;
|
|||||||
import org.apache.commons.lang.RandomStringUtils;
|
import org.apache.commons.lang.RandomStringUtils;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Chunk;
|
import org.bukkit.Chunk;
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.entity.Creeper;
|
|
||||||
import org.bukkit.entity.EntityType;
|
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
@@ -152,12 +138,14 @@ public class CommandDeveloper implements DecreeExecutor {
|
|||||||
|
|
||||||
@Decree(description = "Test")
|
@Decree(description = "Test")
|
||||||
public void packBenchmark(
|
public void packBenchmark(
|
||||||
@Param(description = "The pack to bench", aliases = {"pack"})
|
@Param(description = "The pack to bench", aliases = {"pack"}, defaultValue = "overworld")
|
||||||
IrisDimension dimension
|
IrisDimension dimension,
|
||||||
|
@Param(description = "Radius in regions", defaultValue = "5")
|
||||||
|
int radius,
|
||||||
|
@Param(description = "Open GUI while benchmarking", defaultValue = "false")
|
||||||
|
boolean gui
|
||||||
) {
|
) {
|
||||||
Iris.info("test");
|
new IrisPackBenchmarking(dimension, radius, gui);
|
||||||
IrisPackBenchmarking benchmark = new IrisPackBenchmarking(dimension, 1);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Decree(description = "Upgrade to another Minecraft version")
|
@Decree(description = "Upgrade to another Minecraft version")
|
||||||
@@ -262,7 +250,7 @@ public class CommandDeveloper implements DecreeExecutor {
|
|||||||
VolmitSender sender = sender();
|
VolmitSender sender = sender();
|
||||||
service.submit(() -> {
|
service.submit(() -> {
|
||||||
try {
|
try {
|
||||||
DataInputStream raw = new DataInputStream(new FileInputStream(file));
|
CountingDataInputStream raw = CountingDataInputStream.wrap(new FileInputStream(file));
|
||||||
TectonicPlate plate = new TectonicPlate(height, raw);
|
TectonicPlate plate = new TectonicPlate(height, raw);
|
||||||
raw.close();
|
raw.close();
|
||||||
|
|
||||||
@@ -281,7 +269,7 @@ public class CommandDeveloper implements DecreeExecutor {
|
|||||||
if (size == 0)
|
if (size == 0)
|
||||||
size = tmp.length();
|
size = tmp.length();
|
||||||
start = System.currentTimeMillis();
|
start = System.currentTimeMillis();
|
||||||
DataInputStream din = createInput(tmp, algorithm);
|
CountingDataInputStream din = createInput(tmp, algorithm);
|
||||||
new TectonicPlate(height, din);
|
new TectonicPlate(height, din);
|
||||||
din.close();
|
din.close();
|
||||||
d2 += System.currentTimeMillis() - start;
|
d2 += System.currentTimeMillis() - start;
|
||||||
@@ -301,10 +289,10 @@ public class CommandDeveloper implements DecreeExecutor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private DataInputStream createInput(File file, String algorithm) throws Throwable {
|
private CountingDataInputStream createInput(File file, String algorithm) throws Throwable {
|
||||||
FileInputStream in = new FileInputStream(file);
|
FileInputStream in = new FileInputStream(file);
|
||||||
|
|
||||||
return new DataInputStream(switch (algorithm) {
|
return CountingDataInputStream.wrap(switch (algorithm) {
|
||||||
case "gzip" -> new GZIPInputStream(in);
|
case "gzip" -> new GZIPInputStream(in);
|
||||||
case "lz4f" -> new LZ4FrameInputStream(in);
|
case "lz4f" -> new LZ4FrameInputStream(in);
|
||||||
case "lz4b" -> new LZ4BlockInputStream(in);
|
case "lz4b" -> new LZ4BlockInputStream(in);
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ public class CommandJigsaw implements DecreeExecutor {
|
|||||||
try {
|
try {
|
||||||
var world = world();
|
var world = world();
|
||||||
WorldObjectPlacer placer = new WorldObjectPlacer(world);
|
WorldObjectPlacer placer = new WorldObjectPlacer(world);
|
||||||
PlannedStructure ps = new PlannedStructure(structure, new IrisPosition(player().getLocation().add(0, world.getMinHeight(), 0)), new RNG());
|
PlannedStructure ps = new PlannedStructure(structure, new IrisPosition(player().getLocation().add(0, world.getMinHeight(), 0)), new RNG(), true);
|
||||||
VolmitSender sender = sender();
|
VolmitSender sender = sender();
|
||||||
sender.sendMessage(C.GREEN + "Generated " + ps.getPieces().size() + " pieces in " + Form.duration(p.getMilliseconds(), 2));
|
sender.sendMessage(C.GREEN + "Generated " + ps.getPieces().size() + " pieces in " + Form.duration(p.getMilliseconds(), 2));
|
||||||
ps.place(placer, failed -> sender.sendMessage(failed ? C.GREEN + "Placed the structure!" : C.RED + "Failed to place the structure!"));
|
ps.place(placer, failed -> sender.sendMessage(failed ? C.GREEN + "Placed the structure!" : C.RED + "Failed to place the structure!"));
|
||||||
|
|||||||
@@ -376,9 +376,11 @@ public class CommandObject implements DecreeExecutor {
|
|||||||
@Param(description = "The file to store it in, can use / for subfolders")
|
@Param(description = "The file to store it in, can use / for subfolders")
|
||||||
String name,
|
String name,
|
||||||
@Param(description = "Overwrite existing object files", defaultValue = "false", aliases = "force")
|
@Param(description = "Overwrite existing object files", defaultValue = "false", aliases = "force")
|
||||||
boolean overwrite
|
boolean overwrite,
|
||||||
|
@Param(description = "Use legacy TileState serialization if possible", defaultValue = "true")
|
||||||
|
boolean legacy
|
||||||
) {
|
) {
|
||||||
IrisObject o = WandSVC.createSchematic(player());
|
IrisObject o = WandSVC.createSchematic(player(), legacy);
|
||||||
|
|
||||||
if (o == null) {
|
if (o == null) {
|
||||||
sender().sendMessage(C.YELLOW + "You need to hold your wand!");
|
sender().sendMessage(C.YELLOW + "You need to hold your wand!");
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ import com.volmit.iris.core.loader.IrisData;
|
|||||||
import com.volmit.iris.core.project.IrisProject;
|
import com.volmit.iris.core.project.IrisProject;
|
||||||
import com.volmit.iris.core.service.ConversionSVC;
|
import com.volmit.iris.core.service.ConversionSVC;
|
||||||
import com.volmit.iris.core.service.StudioSVC;
|
import com.volmit.iris.core.service.StudioSVC;
|
||||||
import com.volmit.iris.core.tools.IrisConverter;
|
|
||||||
import com.volmit.iris.core.tools.IrisToolbelt;
|
import com.volmit.iris.core.tools.IrisToolbelt;
|
||||||
import com.volmit.iris.engine.framework.Engine;
|
import com.volmit.iris.engine.framework.Engine;
|
||||||
import com.volmit.iris.engine.object.*;
|
import com.volmit.iris.engine.object.*;
|
||||||
@@ -55,7 +54,6 @@ import com.volmit.iris.util.noise.CNG;
|
|||||||
import com.volmit.iris.util.parallel.BurstExecutor;
|
import com.volmit.iris.util.parallel.BurstExecutor;
|
||||||
import com.volmit.iris.util.parallel.MultiBurst;
|
import com.volmit.iris.util.parallel.MultiBurst;
|
||||||
import com.volmit.iris.util.plugin.VolmitSender;
|
import com.volmit.iris.util.plugin.VolmitSender;
|
||||||
import com.volmit.iris.util.scheduling.ChronoLatch;
|
|
||||||
import com.volmit.iris.util.scheduling.J;
|
import com.volmit.iris.util.scheduling.J;
|
||||||
import com.volmit.iris.util.scheduling.O;
|
import com.volmit.iris.util.scheduling.O;
|
||||||
import com.volmit.iris.util.scheduling.PrecisionStopwatch;
|
import com.volmit.iris.util.scheduling.PrecisionStopwatch;
|
||||||
@@ -64,7 +62,6 @@ import io.papermc.lib.PaperLib;
|
|||||||
import org.bukkit.*;
|
import org.bukkit.*;
|
||||||
import org.bukkit.event.inventory.InventoryType;
|
import org.bukkit.event.inventory.InventoryType;
|
||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
|
||||||
import org.bukkit.util.BlockVector;
|
import org.bukkit.util.BlockVector;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
@@ -79,7 +76,6 @@ import java.time.temporal.ChronoUnit;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.concurrent.CompletableFuture;
|
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Future;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
@@ -176,7 +172,7 @@ public class CommandStudio implements DecreeExecutor {
|
|||||||
KList<Runnable> js = new KList<>();
|
KList<Runnable> js = new KList<>();
|
||||||
BurstExecutor b = MultiBurst.burst.burst();
|
BurstExecutor b = MultiBurst.burst.burst();
|
||||||
b.setMulticore(false);
|
b.setMulticore(false);
|
||||||
int rad = engine.getMantle().getRealRadius();
|
int rad = engine.getMantle().getRadius();
|
||||||
for (int i = -(radius + rad); i <= radius + rad; i++) {
|
for (int i = -(radius + rad); i <= radius + rad; i++) {
|
||||||
for (int j = -(radius + rad); j <= radius + rad; j++) {
|
for (int j = -(radius + rad); j <= radius + rad; j++) {
|
||||||
engine.getMantle().getMantle().deleteChunk(i + cx.getX(), j + cx.getZ());
|
engine.getMantle().getMantle().deleteChunk(i + cx.getX(), j + cx.getZ());
|
||||||
@@ -306,7 +302,7 @@ public class CommandStudio implements DecreeExecutor {
|
|||||||
Inventory inv = Bukkit.createInventory(null, 27 * 2);
|
Inventory inv = Bukkit.createInventory(null, 27 * 2);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
engine().addItems(true, inv, RNG.r, tables, InventorySlotType.STORAGE, player().getLocation().getBlockX(), player().getLocation().getBlockY(), player().getLocation().getBlockZ(), 1);
|
engine().addItems(true, inv, RNG.r, tables, InventorySlotType.STORAGE, player().getWorld(), player().getLocation().getBlockX(), player().getLocation().getBlockY(), player().getLocation().getBlockZ(), 1);
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
Iris.reportError(e);
|
Iris.reportError(e);
|
||||||
sender().sendMessage(C.RED + "Cannot add items to virtual inventory because of: " + e.getMessage());
|
sender().sendMessage(C.RED + "Cannot add items to virtual inventory because of: " + e.getMessage());
|
||||||
@@ -329,7 +325,7 @@ public class CommandStudio implements DecreeExecutor {
|
|||||||
inv.clear();
|
inv.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
engine().addItems(true, inv, new RNG(RNG.r.imax()), tables, InventorySlotType.STORAGE, player().getLocation().getBlockX(), player().getLocation().getBlockY(), player().getLocation().getBlockZ(), 1);
|
engine().addItems(true, inv, new RNG(RNG.r.imax()), tables, InventorySlotType.STORAGE, player().getWorld(), player().getLocation().getBlockX(), player().getLocation().getBlockY(), player().getLocation().getBlockZ(), 1);
|
||||||
}, 0, fast ? 5 : 35));
|
}, 0, fast ? 5 : 35));
|
||||||
|
|
||||||
sender().sendMessage(C.GREEN + "Opening inventory now!");
|
sender().sendMessage(C.GREEN + "Opening inventory now!");
|
||||||
|
|||||||
@@ -43,6 +43,10 @@ public class CommandUpdater implements DecreeExecutor {
|
|||||||
sender().sendMessage(C.GOLD + "This is not an Iris world");
|
sender().sendMessage(C.GOLD + "This is not an Iris world");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (chunkUpdater != null) {
|
||||||
|
chunkUpdater.stop();
|
||||||
|
}
|
||||||
|
|
||||||
chunkUpdater = new ChunkUpdater(world);
|
chunkUpdater = new ChunkUpdater(world);
|
||||||
if (sender().isPlayer()) {
|
if (sender().isPlayer()) {
|
||||||
sender().sendMessage(C.GREEN + "Updating " + world.getName() + C.GRAY + " Total chunks: " + Form.f(chunkUpdater.getChunks()));
|
sender().sendMessage(C.GREEN + "Updating " + world.getName() + C.GRAY + " Total chunks: " + Form.f(chunkUpdater.getChunks()));
|
||||||
@@ -53,14 +57,7 @@ public class CommandUpdater implements DecreeExecutor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Decree(description = "Pause the updater")
|
@Decree(description = "Pause the updater")
|
||||||
public void pause(
|
public void pause( ) {
|
||||||
@Param(description = "World to pause the Updater at")
|
|
||||||
World world
|
|
||||||
) {
|
|
||||||
if (!IrisToolbelt.isIrisWorld(world)) {
|
|
||||||
sender().sendMessage(C.GOLD + "This is not an Iris world");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (chunkUpdater == null) {
|
if (chunkUpdater == null) {
|
||||||
sender().sendMessage(C.GOLD + "You cant pause something that doesnt exist?");
|
sender().sendMessage(C.GOLD + "You cant pause something that doesnt exist?");
|
||||||
return;
|
return;
|
||||||
@@ -68,40 +65,32 @@ public class CommandUpdater implements DecreeExecutor {
|
|||||||
boolean status = chunkUpdater.pause();
|
boolean status = chunkUpdater.pause();
|
||||||
if (sender().isPlayer()) {
|
if (sender().isPlayer()) {
|
||||||
if (status) {
|
if (status) {
|
||||||
sender().sendMessage(C.IRIS + "Paused task for: " + C.GRAY + world.getName());
|
sender().sendMessage(C.IRIS + "Paused task for: " + C.GRAY + chunkUpdater.getName());
|
||||||
} else {
|
} else {
|
||||||
sender().sendMessage(C.IRIS + "Unpause task for: " + C.GRAY + world.getName());
|
sender().sendMessage(C.IRIS + "Unpause task for: " + C.GRAY + chunkUpdater.getName());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (status) {
|
if (status) {
|
||||||
Iris.info(C.IRIS + "Paused task for: " + C.GRAY + world.getName());
|
Iris.info(C.IRIS + "Paused task for: " + C.GRAY + chunkUpdater.getName());
|
||||||
} else {
|
} else {
|
||||||
Iris.info(C.IRIS + "Unpause task for: " + C.GRAY + world.getName());
|
Iris.info(C.IRIS + "Unpause task for: " + C.GRAY + chunkUpdater.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Decree(description = "Stops the updater")
|
@Decree(description = "Stops the updater")
|
||||||
public void stop(
|
public void stop() {
|
||||||
@Param(description = "World to stop the Updater at")
|
|
||||||
World world
|
|
||||||
) {
|
|
||||||
if (!IrisToolbelt.isIrisWorld(world)) {
|
|
||||||
sender().sendMessage(C.GOLD + "This is not an Iris world");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (chunkUpdater == null) {
|
if (chunkUpdater == null) {
|
||||||
sender().sendMessage(C.GOLD + "You cant stop something that doesnt exist?");
|
sender().sendMessage(C.GOLD + "You cant stop something that doesnt exist?");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (sender().isPlayer()) {
|
if (sender().isPlayer()) {
|
||||||
sender().sendMessage("Stopping Updater for: " + C.GRAY + world.getName());
|
sender().sendMessage("Stopping Updater for: " + C.GRAY + chunkUpdater.getName());
|
||||||
} else {
|
} else {
|
||||||
Iris.info("Stopping Updater for: " + C.GRAY + world.getName());
|
Iris.info("Stopping Updater for: " + C.GRAY + chunkUpdater.getName());
|
||||||
}
|
}
|
||||||
chunkUpdater.stop();
|
chunkUpdater.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,113 @@
|
|||||||
|
package com.volmit.iris.core.events;
|
||||||
|
|
||||||
|
import com.volmit.iris.Iris;
|
||||||
|
import com.volmit.iris.engine.framework.Engine;
|
||||||
|
import com.volmit.iris.engine.object.InventorySlotType;
|
||||||
|
import com.volmit.iris.engine.object.IrisLootTable;
|
||||||
|
import com.volmit.iris.util.collection.KList;
|
||||||
|
import com.volmit.iris.util.scheduling.J;
|
||||||
|
import lombok.Getter;
|
||||||
|
import org.bukkit.*;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.event.Event;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
import org.bukkit.event.world.LootGenerateEvent;
|
||||||
|
|
||||||
|
import org.bukkit.inventory.Inventory;
|
||||||
|
import org.bukkit.inventory.InventoryHolder;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.loot.LootContext;
|
||||||
|
import org.bukkit.loot.LootTable;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
public class IrisLootEvent extends Event {
|
||||||
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
private static final LootTable EMPTY = new LootTable() {
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public NamespacedKey getKey() {
|
||||||
|
return new NamespacedKey(Iris.instance, "empty");
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public Collection<ItemStack> populateLoot(@Nullable Random random, @NotNull LootContext context) {
|
||||||
|
return List.of();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void fillInventory(@NotNull Inventory inventory, @Nullable Random random, @NotNull LootContext context) {
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
private final Engine engine;
|
||||||
|
private final Block block;
|
||||||
|
private final InventorySlotType slot;
|
||||||
|
private final KList<IrisLootTable> tables;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for IrisLootEvent with mode selection.
|
||||||
|
*
|
||||||
|
* @param engine The engine instance.
|
||||||
|
* @param block The block associated with the event.
|
||||||
|
* @param slot The inventory slot type.
|
||||||
|
* @param tables The list of IrisLootTables. (mutable*)
|
||||||
|
*/
|
||||||
|
public IrisLootEvent(Engine engine, Block block, InventorySlotType slot, KList<IrisLootTable> tables) {
|
||||||
|
this.engine = engine;
|
||||||
|
this.block = block;
|
||||||
|
this.slot = slot;
|
||||||
|
this.tables = tables;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HandlerList getHandlers() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Required method to get the HandlerList for this event.
|
||||||
|
*
|
||||||
|
* @return The HandlerList.
|
||||||
|
*/
|
||||||
|
public static HandlerList getHandlerList() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Triggers the corresponding Bukkit loot event.
|
||||||
|
* This method integrates your custom IrisLootTables with Bukkit's LootGenerateEvent,
|
||||||
|
* allowing other plugins to modify or cancel the loot generation.
|
||||||
|
*
|
||||||
|
* @return true when the event was canceled
|
||||||
|
*/
|
||||||
|
public static boolean callLootEvent(KList<ItemStack> loot, Inventory inv, World world, int x, int y, int z) {
|
||||||
|
InventoryHolder holder = inv.getHolder();
|
||||||
|
Location loc = new Location(world, x, y, z);
|
||||||
|
if (holder == null) {
|
||||||
|
holder = new InventoryHolder() {
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public Inventory getInventory() {
|
||||||
|
return inv;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
LootContext context = new LootContext.Builder(loc).build();
|
||||||
|
LootGenerateEvent event = new LootGenerateEvent(world, null, holder, EMPTY, context, loot, true);
|
||||||
|
if (!Bukkit.isPrimaryThread()) {
|
||||||
|
Iris.warn("LootGenerateEvent was not called on the main thread, please report this issue.");
|
||||||
|
Thread.dumpStack();
|
||||||
|
J.sfut(() -> Bukkit.getPluginManager().callEvent(event)).join();
|
||||||
|
} else Bukkit.getPluginManager().callEvent(event);
|
||||||
|
|
||||||
|
return event.isCancelled();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -276,9 +276,7 @@ public class NoiseExplorerGUI extends JPanel implements MouseWheelListener, List
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
//Color color = colorMode ? Color.getHSBColor((float) (n), 1f - (float) (n * n * n * n * n * n), 1f - (float) n) : Color.getHSBColor(0f, 0f, (float) n);
|
//Color color = colorMode ? Color.getHSBColor((float) (n), 1f - (float) (n * n * n * n * n * n), 1f - (float) n) : Color.getHSBColor(0f, 0f, (float) n);
|
||||||
//Color color = colorMode ? Color.getHSBColor((float) (n), (float) (n * n * n * n * n * n), (float) n) : Color.getHSBColor(0f, 0f, (float) n);
|
Color color = colorMode ? Color.getHSBColor((float) (0.666f - n * 0.666f), 1f, (float) (1f - n * 0.8f)) : Color.getHSBColor(0f, 0f, (float) n);
|
||||||
Color color = colorMode ? Color.getHSBColor((float) n, (float) (n * n * n * n * n * n), (float) n) : Color.getHSBColor(0f, 0f, (float) n);
|
|
||||||
|
|
||||||
int rgb = color.getRGB();
|
int rgb = color.getRGB();
|
||||||
img.setRGB(xx, z, rgb);
|
img.setRGB(xx, z, rgb);
|
||||||
} catch (Throwable ignored) {
|
} catch (Throwable ignored) {
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import com.willfp.ecoitems.items.EcoItems;
|
|||||||
import org.bukkit.NamespacedKey;
|
import org.bukkit.NamespacedKey;
|
||||||
import org.bukkit.block.data.BlockData;
|
import org.bukkit.block.data.BlockData;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.MissingResourceException;
|
import java.util.MissingResourceException;
|
||||||
|
|
||||||
@@ -33,23 +34,27 @@ public class EcoItemsDataProvider extends ExternalDataProvider {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public BlockData getBlockData(Identifier blockId, KMap<String, String> state) throws MissingResourceException {
|
public BlockData getBlockData(@NotNull Identifier blockId, @NotNull KMap<String, String> state) throws MissingResourceException {
|
||||||
throw new MissingResourceException("Failed to find BlockData!", blockId.namespace(), blockId.key());
|
throw new MissingResourceException("Failed to find BlockData!", blockId.namespace(), blockId.key());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public ItemStack getItemStack(Identifier itemId, KMap<String, Object> customNbt) throws MissingResourceException {
|
public ItemStack getItemStack(@NotNull Identifier itemId, @NotNull KMap<String, Object> customNbt) throws MissingResourceException {
|
||||||
EcoItem item = EcoItems.INSTANCE.getByID(itemId.key());
|
EcoItem item = EcoItems.INSTANCE.getByID(itemId.key());
|
||||||
if (item == null) throw new MissingResourceException("Failed to find Item!", itemId.namespace(), itemId.key());
|
if (item == null) throw new MissingResourceException("Failed to find Item!", itemId.namespace(), itemId.key());
|
||||||
return itemStack.get(item).clone();
|
return itemStack.get(item).clone();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public Identifier[] getBlockTypes() {
|
public Identifier[] getBlockTypes() {
|
||||||
return new Identifier[0];
|
return new Identifier[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public Identifier[] getItemTypes() {
|
public Identifier[] getItemTypes() {
|
||||||
KList<Identifier> names = new KList<>();
|
KList<Identifier> names = new KList<>();
|
||||||
@@ -66,7 +71,7 @@ public class EcoItemsDataProvider extends ExternalDataProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isValidProvider(Identifier id, boolean isItem) {
|
public boolean isValidProvider(@NotNull Identifier id, boolean isItem) {
|
||||||
return id.namespace().equalsIgnoreCase("ecoitems") && isItem;
|
return id.namespace().equalsIgnoreCase("ecoitems") && isItem;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import com.volmit.iris.util.collection.KList;
|
|||||||
import com.volmit.iris.util.collection.KMap;
|
import com.volmit.iris.util.collection.KMap;
|
||||||
import org.bukkit.block.data.BlockData;
|
import org.bukkit.block.data.BlockData;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.MissingResourceException;
|
import java.util.MissingResourceException;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
@@ -20,23 +21,27 @@ public class ExecutableItemsDataProvider extends ExternalDataProvider {
|
|||||||
Iris.info("Setting up ExecutableItems Link...");
|
Iris.info("Setting up ExecutableItems Link...");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public BlockData getBlockData(Identifier blockId, KMap<String, String> state) throws MissingResourceException {
|
public BlockData getBlockData(@NotNull Identifier blockId, @NotNull KMap<String, String> state) throws MissingResourceException {
|
||||||
throw new MissingResourceException("Failed to find BlockData!", blockId.namespace(), blockId.key());
|
throw new MissingResourceException("Failed to find BlockData!", blockId.namespace(), blockId.key());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public ItemStack getItemStack(Identifier itemId, KMap<String, Object> customNbt) throws MissingResourceException {
|
public ItemStack getItemStack(@NotNull Identifier itemId, @NotNull KMap<String, Object> customNbt) throws MissingResourceException {
|
||||||
return ExecutableItemsAPI.getExecutableItemsManager().getExecutableItem(itemId.key())
|
return ExecutableItemsAPI.getExecutableItemsManager().getExecutableItem(itemId.key())
|
||||||
.map(item -> item.buildItem(1, Optional.empty()))
|
.map(item -> item.buildItem(1, Optional.empty()))
|
||||||
.orElseThrow(() -> new MissingResourceException("Failed to find ItemData!", itemId.namespace(), itemId.key()));
|
.orElseThrow(() -> new MissingResourceException("Failed to find ItemData!", itemId.namespace(), itemId.key()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public Identifier[] getBlockTypes() {
|
public Identifier[] getBlockTypes() {
|
||||||
return new Identifier[0];
|
return new Identifier[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public Identifier[] getItemTypes() {
|
public Identifier[] getItemTypes() {
|
||||||
KList<Identifier> names = new KList<>();
|
KList<Identifier> names = new KList<>();
|
||||||
@@ -53,7 +58,7 @@ public class ExecutableItemsDataProvider extends ExternalDataProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isValidProvider(Identifier key, boolean isItem) {
|
public boolean isValidProvider(@NotNull Identifier key, boolean isItem) {
|
||||||
return key.namespace().equalsIgnoreCase("executable_items") && isItem;
|
return key.namespace().equalsIgnoreCase("executable_items") && isItem;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,22 +2,28 @@ package com.volmit.iris.core.link;
|
|||||||
|
|
||||||
import com.volmit.iris.engine.framework.Engine;
|
import com.volmit.iris.engine.framework.Engine;
|
||||||
import com.volmit.iris.util.collection.KMap;
|
import com.volmit.iris.util.collection.KMap;
|
||||||
|
import com.volmit.iris.util.data.IrisBlockData;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
import lombok.NonNull;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.data.BlockData;
|
import org.bukkit.block.data.BlockData;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.MissingResourceException;
|
import java.util.MissingResourceException;
|
||||||
|
|
||||||
|
@Getter
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public abstract class ExternalDataProvider {
|
public abstract class ExternalDataProvider {
|
||||||
|
|
||||||
@Getter
|
@NonNull
|
||||||
private final String pluginId;
|
private final String pluginId;
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public Plugin getPlugin() {
|
public Plugin getPlugin() {
|
||||||
return Bukkit.getPluginManager().getPlugin(pluginId);
|
return Bukkit.getPluginManager().getPlugin(pluginId);
|
||||||
}
|
}
|
||||||
@@ -28,23 +34,60 @@ public abstract class ExternalDataProvider {
|
|||||||
|
|
||||||
public abstract void init();
|
public abstract void init();
|
||||||
|
|
||||||
public BlockData getBlockData(Identifier blockId) throws MissingResourceException {
|
/**
|
||||||
|
* @see ExternalDataProvider#getBlockData(Identifier, KMap)
|
||||||
|
*/
|
||||||
|
@NotNull
|
||||||
|
public BlockData getBlockData(@NotNull Identifier blockId) throws MissingResourceException {
|
||||||
return getBlockData(blockId, new KMap<>());
|
return getBlockData(blockId, new KMap<>());
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract BlockData getBlockData(Identifier blockId, KMap<String, String> state) throws MissingResourceException;
|
/**
|
||||||
|
* This method returns a {@link BlockData} corresponding to the blockID
|
||||||
|
* it is used in any place Iris accepts {@link BlockData}
|
||||||
|
*
|
||||||
|
* @param blockId The id of the block to get
|
||||||
|
* @param state The state of the block to get
|
||||||
|
* @return Corresponding {@link BlockData} to the blockId
|
||||||
|
* may return {@link IrisBlockData} for blocks that need a world for placement
|
||||||
|
* @throws MissingResourceException when the blockId is invalid
|
||||||
|
*/
|
||||||
|
@NotNull
|
||||||
|
public abstract BlockData getBlockData(@NotNull Identifier blockId, @NotNull KMap<String, String> state) throws MissingResourceException;
|
||||||
|
|
||||||
public ItemStack getItemStack(Identifier itemId) throws MissingResourceException {
|
/**
|
||||||
|
* @see ExternalDataProvider#getItemStack(Identifier)
|
||||||
|
*/
|
||||||
|
@NotNull
|
||||||
|
public ItemStack getItemStack(@NotNull Identifier itemId) throws MissingResourceException {
|
||||||
return getItemStack(itemId, new KMap<>());
|
return getItemStack(itemId, new KMap<>());
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract ItemStack getItemStack(Identifier itemId, KMap<String, Object> customNbt) throws MissingResourceException;
|
/**
|
||||||
|
* This method returns a {@link ItemStack} corresponding to the itemID
|
||||||
|
* it is used in loot tables
|
||||||
|
*
|
||||||
|
* @param itemId The id of the item to get
|
||||||
|
* @param customNbt Custom nbt to apply to the item
|
||||||
|
* @return Corresponding {@link ItemStack} to the itemId
|
||||||
|
* @throws MissingResourceException when the itemId is invalid
|
||||||
|
*/
|
||||||
|
@NotNull
|
||||||
|
public abstract ItemStack getItemStack(@NotNull Identifier itemId, @NotNull KMap<String, Object> customNbt) throws MissingResourceException;
|
||||||
|
|
||||||
public void processUpdate(Engine engine, Block block, Identifier blockId) {}
|
/**
|
||||||
|
* This method is used for placing blocks that need to use the plugins api
|
||||||
|
* it will only be called when the {@link ExternalDataProvider#getBlockData(Identifier, KMap)} returned a {@link IrisBlockData}
|
||||||
|
*
|
||||||
|
* @param engine The engine of the world the block is being placed in
|
||||||
|
* @param block The block where the block should be placed
|
||||||
|
* @param blockId The blockId to place
|
||||||
|
*/
|
||||||
|
public void processUpdate(@NotNull Engine engine, @NotNull Block block, @NotNull Identifier blockId) {}
|
||||||
|
|
||||||
public abstract Identifier[] getBlockTypes();
|
public abstract @NotNull Identifier[] getBlockTypes();
|
||||||
|
|
||||||
public abstract Identifier[] getItemTypes();
|
public abstract @NotNull Identifier[] getItemTypes();
|
||||||
|
|
||||||
public abstract boolean isValidProvider(Identifier id, boolean isItem);
|
public abstract boolean isValidProvider(@NotNull Identifier id, boolean isItem);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import org.bukkit.block.Block;
|
|||||||
import org.bukkit.block.data.BlockData;
|
import org.bukkit.block.data.BlockData;
|
||||||
import org.bukkit.block.data.type.Leaves;
|
import org.bukkit.block.data.type.Leaves;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.MissingResourceException;
|
import java.util.MissingResourceException;
|
||||||
@@ -51,8 +52,9 @@ public class HMCLeavesDataProvider extends ExternalDataProvider {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public BlockData getBlockData(Identifier blockId, KMap<String, String> state) throws MissingResourceException {
|
public BlockData getBlockData(@NotNull Identifier blockId, @NotNull KMap<String, String> state) throws MissingResourceException {
|
||||||
Object o = blockDataMap.get(blockId.key());
|
Object o = blockDataMap.get(blockId.key());
|
||||||
if (o == null)
|
if (o == null)
|
||||||
throw new MissingResourceException("Failed to find BlockData!", blockId.namespace(), blockId.key());
|
throw new MissingResourceException("Failed to find BlockData!", blockId.namespace(), blockId.key());
|
||||||
@@ -65,15 +67,16 @@ public class HMCLeavesDataProvider extends ExternalDataProvider {
|
|||||||
return new IrisBlockData(blockData, ExternalDataSVC.buildState(blockId, state));
|
return new IrisBlockData(blockData, ExternalDataSVC.buildState(blockId, state));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public ItemStack getItemStack(Identifier itemId, KMap<String, Object> customNbt) throws MissingResourceException {
|
public ItemStack getItemStack(@NotNull Identifier itemId, @NotNull KMap<String, Object> customNbt) throws MissingResourceException {
|
||||||
if (!itemDataField.containsKey(itemId.key()))
|
if (!itemDataField.containsKey(itemId.key()))
|
||||||
throw new MissingResourceException("Failed to find ItemData!", itemId.namespace(), itemId.key());
|
throw new MissingResourceException("Failed to find ItemData!", itemId.namespace(), itemId.key());
|
||||||
return itemDataField.get(itemId.key()).get();
|
return itemDataField.get(itemId.key()).get();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void processUpdate(Engine engine, Block block, Identifier blockId) {
|
public void processUpdate(@NotNull Engine engine, @NotNull Block block, @NotNull Identifier blockId) {
|
||||||
var pair = ExternalDataSVC.parseState(blockId);
|
var pair = ExternalDataSVC.parseState(blockId);
|
||||||
blockId = pair.getA();
|
blockId = pair.getA();
|
||||||
Boolean result = setCustomBlock.invoke(apiInstance, new Object[]{block.getLocation(), blockId.key(), false});
|
Boolean result = setCustomBlock.invoke(apiInstance, new Object[]{block.getLocation(), blockId.key(), false});
|
||||||
@@ -86,6 +89,7 @@ public class HMCLeavesDataProvider extends ExternalDataProvider {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public Identifier[] getBlockTypes() {
|
public Identifier[] getBlockTypes() {
|
||||||
KList<Identifier> names = new KList<>();
|
KList<Identifier> names = new KList<>();
|
||||||
@@ -101,6 +105,7 @@ public class HMCLeavesDataProvider extends ExternalDataProvider {
|
|||||||
return names.toArray(new Identifier[0]);
|
return names.toArray(new Identifier[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public Identifier[] getItemTypes() {
|
public Identifier[] getItemTypes() {
|
||||||
KList<Identifier> names = new KList<>();
|
KList<Identifier> names = new KList<>();
|
||||||
@@ -117,7 +122,7 @@ public class HMCLeavesDataProvider extends ExternalDataProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isValidProvider(Identifier id, boolean isItem) {
|
public boolean isValidProvider(@NotNull Identifier id, boolean isItem) {
|
||||||
return (isItem ? itemDataField.keySet() : blockDataMap.keySet()).contains(id.key());
|
return (isItem ? itemDataField.keySet() : blockDataMap.keySet()).contains(id.key());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import dev.lone.itemsadder.api.CustomBlock;
|
|||||||
import dev.lone.itemsadder.api.CustomStack;
|
import dev.lone.itemsadder.api.CustomStack;
|
||||||
import org.bukkit.block.data.BlockData;
|
import org.bukkit.block.data.BlockData;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.MissingResourceException;
|
import java.util.MissingResourceException;
|
||||||
|
|
||||||
@@ -32,13 +33,15 @@ public class ItemAdderDataProvider extends ExternalDataProvider {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public BlockData getBlockData(Identifier blockId, KMap<String, String> state) throws MissingResourceException {
|
public BlockData getBlockData(@NotNull Identifier blockId, @NotNull KMap<String, String> state) throws MissingResourceException {
|
||||||
return CustomBlock.getBaseBlockData(blockId.toString());
|
return CustomBlock.getBaseBlockData(blockId.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public ItemStack getItemStack(Identifier itemId, KMap<String, Object> customNbt) throws MissingResourceException {
|
public ItemStack getItemStack(@NotNull Identifier itemId, @NotNull KMap<String, Object> customNbt) throws MissingResourceException {
|
||||||
CustomStack stack = CustomStack.getInstance(itemId.toString());
|
CustomStack stack = CustomStack.getInstance(itemId.toString());
|
||||||
if (stack == null) {
|
if (stack == null) {
|
||||||
throw new MissingResourceException("Failed to find ItemData!", itemId.namespace(), itemId.key());
|
throw new MissingResourceException("Failed to find ItemData!", itemId.namespace(), itemId.key());
|
||||||
@@ -46,6 +49,7 @@ public class ItemAdderDataProvider extends ExternalDataProvider {
|
|||||||
return stack.getItemStack();
|
return stack.getItemStack();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public Identifier[] getBlockTypes() {
|
public Identifier[] getBlockTypes() {
|
||||||
KList<Identifier> keys = new KList<>();
|
KList<Identifier> keys = new KList<>();
|
||||||
@@ -55,6 +59,7 @@ public class ItemAdderDataProvider extends ExternalDataProvider {
|
|||||||
return keys.toArray(new Identifier[0]);
|
return keys.toArray(new Identifier[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public Identifier[] getItemTypes() {
|
public Identifier[] getItemTypes() {
|
||||||
KList<Identifier> keys = new KList<>();
|
KList<Identifier> keys = new KList<>();
|
||||||
@@ -65,7 +70,7 @@ public class ItemAdderDataProvider extends ExternalDataProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isValidProvider(Identifier id, boolean isItem) {
|
public boolean isValidProvider(@NotNull Identifier id, boolean isItem) {
|
||||||
return isItem ? this.itemNamespaces.contains(id.namespace()) : this.blockNamespaces.contains(id.namespace());
|
return isItem ? this.itemNamespaces.contains(id.namespace()) : this.blockNamespaces.contains(id.namespace());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import net.Indyuce.mmoitems.api.block.CustomBlock;
|
|||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.block.data.BlockData;
|
import org.bukkit.block.data.BlockData;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.MissingResourceException;
|
import java.util.MissingResourceException;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
@@ -27,8 +28,9 @@ public class MMOItemsDataProvider extends ExternalDataProvider {
|
|||||||
Iris.info("Setting up MMOItems Link...");
|
Iris.info("Setting up MMOItems Link...");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public BlockData getBlockData(Identifier blockId, KMap<String, String> state) throws MissingResourceException {
|
public BlockData getBlockData(@NotNull Identifier blockId, @NotNull KMap<String, String> state) throws MissingResourceException {
|
||||||
int id = -1;
|
int id = -1;
|
||||||
try {
|
try {
|
||||||
id = Integer.parseInt(blockId.key());
|
id = Integer.parseInt(blockId.key());
|
||||||
@@ -38,8 +40,9 @@ public class MMOItemsDataProvider extends ExternalDataProvider {
|
|||||||
return block.getState().getBlockData();
|
return block.getState().getBlockData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public ItemStack getItemStack(Identifier itemId, KMap<String, Object> customNbt) throws MissingResourceException {
|
public ItemStack getItemStack(@NotNull Identifier itemId, @NotNull KMap<String, Object> customNbt) throws MissingResourceException {
|
||||||
String[] parts = itemId.namespace().split("_", 2);
|
String[] parts = itemId.namespace().split("_", 2);
|
||||||
if (parts.length != 2)
|
if (parts.length != 2)
|
||||||
throw new MissingResourceException("Failed to find ItemData!", itemId.namespace(), itemId.key());
|
throw new MissingResourceException("Failed to find ItemData!", itemId.namespace(), itemId.key());
|
||||||
@@ -82,6 +85,7 @@ public class MMOItemsDataProvider extends ExternalDataProvider {
|
|||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public Identifier[] getBlockTypes() {
|
public Identifier[] getBlockTypes() {
|
||||||
KList<Identifier> names = new KList<>();
|
KList<Identifier> names = new KList<>();
|
||||||
@@ -96,6 +100,7 @@ public class MMOItemsDataProvider extends ExternalDataProvider {
|
|||||||
return names.toArray(new Identifier[0]);
|
return names.toArray(new Identifier[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public Identifier[] getItemTypes() {
|
public Identifier[] getItemTypes() {
|
||||||
KList<Identifier> names = new KList<>();
|
KList<Identifier> names = new KList<>();
|
||||||
@@ -124,7 +129,7 @@ public class MMOItemsDataProvider extends ExternalDataProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isValidProvider(Identifier id, boolean isItem) {
|
public boolean isValidProvider(@NotNull Identifier id, boolean isItem) {
|
||||||
return isItem ? id.namespace().split("_", 2).length == 2 : id.namespace().equals("mmoitems");
|
return isItem ? id.namespace().split("_", 2).length == 2 : id.namespace().equals("mmoitems");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,171 @@
|
|||||||
|
/*
|
||||||
|
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||||
|
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.volmit.iris.core.link;
|
||||||
|
|
||||||
|
import com.volmit.iris.Iris;
|
||||||
|
import com.volmit.iris.core.nms.INMS;
|
||||||
|
import com.volmit.iris.core.nms.container.BiomeColor;
|
||||||
|
import com.volmit.iris.core.service.ExternalDataSVC;
|
||||||
|
import com.volmit.iris.engine.data.cache.Cache;
|
||||||
|
import com.volmit.iris.engine.framework.Engine;
|
||||||
|
import com.volmit.iris.util.collection.KList;
|
||||||
|
import com.volmit.iris.util.collection.KMap;
|
||||||
|
import com.volmit.iris.util.data.B;
|
||||||
|
import com.volmit.iris.util.data.IrisBlockData;
|
||||||
|
import com.volmit.iris.util.math.RNG;
|
||||||
|
import io.lumine.mythic.bukkit.BukkitAdapter;
|
||||||
|
import io.lumine.mythic.bukkit.utils.serialize.Chroma;
|
||||||
|
import io.lumine.mythiccrucible.MythicCrucible;
|
||||||
|
import io.lumine.mythiccrucible.items.CrucibleItem;
|
||||||
|
import io.lumine.mythiccrucible.items.ItemManager;
|
||||||
|
import io.lumine.mythiccrucible.items.blocks.CustomBlockItemContext;
|
||||||
|
import io.lumine.mythiccrucible.items.furniture.FurnitureItemContext;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.block.BlockFace;
|
||||||
|
import org.bukkit.block.data.BlockData;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.MissingResourceException;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public class MythicCrucibleDataProvider extends ExternalDataProvider {
|
||||||
|
|
||||||
|
private ItemManager itemManager;
|
||||||
|
|
||||||
|
public MythicCrucibleDataProvider() {
|
||||||
|
super("MythicCrucible");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void init() {
|
||||||
|
Iris.info("Setting up MythicCrucible Link...");
|
||||||
|
try {
|
||||||
|
this.itemManager = MythicCrucible.inst().getItemManager();
|
||||||
|
} catch (Exception e) {
|
||||||
|
Iris.error("Failed to set up MythicCrucible Link: Unable to fetch MythicCrucible instance!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public BlockData getBlockData(@NotNull Identifier blockId, @NotNull KMap<String, String> state) throws MissingResourceException {
|
||||||
|
CrucibleItem crucibleItem = this.itemManager.getItem(blockId.key())
|
||||||
|
.orElseThrow(() -> new MissingResourceException("Failed to find BlockData!", blockId.namespace(), blockId.key()));
|
||||||
|
CustomBlockItemContext blockItemContext = crucibleItem.getBlockData();
|
||||||
|
FurnitureItemContext furnitureItemContext = crucibleItem.getFurnitureData();
|
||||||
|
if (furnitureItemContext != null) {
|
||||||
|
return new IrisBlockData(B.getAir(), ExternalDataSVC.buildState(blockId, state));
|
||||||
|
} else if (blockItemContext != null) {
|
||||||
|
return blockItemContext.getBlockData();
|
||||||
|
}
|
||||||
|
throw new MissingResourceException("Failed to find BlockData!", blockId.namespace(), blockId.key());
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public ItemStack getItemStack(@NotNull Identifier itemId, @NotNull KMap<String, Object> customNbt) throws MissingResourceException {
|
||||||
|
Optional<CrucibleItem> opt = this.itemManager.getItem(itemId.key());
|
||||||
|
return BukkitAdapter.adapt(opt.orElseThrow(() ->
|
||||||
|
new MissingResourceException("Failed to find ItemData!", itemId.namespace(), itemId.key()))
|
||||||
|
.getMythicItem()
|
||||||
|
.generateItemStack(1));
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public Identifier[] getBlockTypes() {
|
||||||
|
KList<Identifier> names = new KList<>();
|
||||||
|
for (CrucibleItem item : this.itemManager.getItems()) {
|
||||||
|
if (item.getBlockData() == null) continue;
|
||||||
|
try {
|
||||||
|
Identifier key = new Identifier("crucible", item.getInternalName());
|
||||||
|
if (getBlockData(key) != null) {
|
||||||
|
Iris.info("getBlockTypes: Block loaded '" + item.getInternalName() + "'");
|
||||||
|
names.add(key);
|
||||||
|
}
|
||||||
|
} catch (MissingResourceException ignored) {}
|
||||||
|
}
|
||||||
|
return names.toArray(new Identifier[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public Identifier[] getItemTypes() {
|
||||||
|
KList<Identifier> names = new KList<>();
|
||||||
|
for (CrucibleItem item : this.itemManager.getItems()) {
|
||||||
|
try {
|
||||||
|
Identifier key = new Identifier("crucible", item.getInternalName());
|
||||||
|
if (getItemStack(key) != null) {
|
||||||
|
Iris.info("getItemTypes: Item loaded '" + item.getInternalName() + "'");
|
||||||
|
names.add(key);
|
||||||
|
}
|
||||||
|
} catch (MissingResourceException ignored) {}
|
||||||
|
}
|
||||||
|
return names.toArray(new Identifier[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void processUpdate(@NotNull Engine engine, @NotNull Block block, @NotNull Identifier blockId) {
|
||||||
|
var pair = ExternalDataSVC.parseState(blockId);
|
||||||
|
var state = pair.getB();
|
||||||
|
blockId = pair.getA();
|
||||||
|
|
||||||
|
Optional<CrucibleItem> item = itemManager.getItem(blockId.key());
|
||||||
|
if (item.isEmpty()) return;
|
||||||
|
FurnitureItemContext furniture = item.get().getFurnitureData();
|
||||||
|
if (furniture == null) return;
|
||||||
|
|
||||||
|
float yaw = 0;
|
||||||
|
BlockFace face = BlockFace.NORTH;
|
||||||
|
long seed = engine.getSeedManager().getSeed() + Cache.key(block.getX(), block.getZ()) + block.getY();
|
||||||
|
RNG rng = new RNG(seed);
|
||||||
|
if ("true".equals(state.get("randomYaw"))) {
|
||||||
|
yaw = rng.f(0, 360);
|
||||||
|
} else if (state.containsKey("yaw")) {
|
||||||
|
yaw = Float.parseFloat(state.get("yaw"));
|
||||||
|
}
|
||||||
|
if ("true".equals(state.get("randomFace"))) {
|
||||||
|
BlockFace[] faces = BlockFace.values();
|
||||||
|
face = faces[rng.i(0, faces.length - 1)];
|
||||||
|
} else if (state.containsKey("face")) {
|
||||||
|
face = BlockFace.valueOf(state.get("face").toUpperCase());
|
||||||
|
}
|
||||||
|
if (face == BlockFace.SELF) {
|
||||||
|
face = BlockFace.NORTH;
|
||||||
|
}
|
||||||
|
|
||||||
|
BiomeColor type = null;
|
||||||
|
Chroma color = null;
|
||||||
|
try {
|
||||||
|
type = BiomeColor.valueOf(state.get("matchBiome").toUpperCase());
|
||||||
|
} catch (NullPointerException | IllegalArgumentException ignored) {}
|
||||||
|
if (type != null) {
|
||||||
|
var biomeColor = INMS.get().getBiomeColor(block.getLocation(), type);
|
||||||
|
if (biomeColor == null) return;
|
||||||
|
color = Chroma.of(biomeColor.getRGB());
|
||||||
|
}
|
||||||
|
furniture.place(block, face, yaw, color);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isValidProvider(@NotNull Identifier key, boolean isItem) {
|
||||||
|
return key.namespace().equalsIgnoreCase("crucible");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,164 @@
|
|||||||
|
package com.volmit.iris.core.link;
|
||||||
|
|
||||||
|
import com.nexomc.nexo.api.NexoBlocks;
|
||||||
|
import com.nexomc.nexo.api.NexoFurniture;
|
||||||
|
import com.nexomc.nexo.api.NexoItems;
|
||||||
|
import com.nexomc.nexo.items.ItemBuilder;
|
||||||
|
import com.volmit.iris.core.nms.INMS;
|
||||||
|
import com.volmit.iris.core.nms.container.BiomeColor;
|
||||||
|
import com.volmit.iris.core.service.ExternalDataSVC;
|
||||||
|
import com.volmit.iris.engine.data.cache.Cache;
|
||||||
|
import com.volmit.iris.engine.framework.Engine;
|
||||||
|
import com.volmit.iris.util.collection.KMap;
|
||||||
|
import com.volmit.iris.util.data.B;
|
||||||
|
import com.volmit.iris.util.data.IrisBlockData;
|
||||||
|
import com.volmit.iris.util.math.RNG;
|
||||||
|
import org.bukkit.Color;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.block.BlockFace;
|
||||||
|
import org.bukkit.block.data.BlockData;
|
||||||
|
import org.bukkit.entity.ItemDisplay;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.PotionMeta;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.MissingResourceException;
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
|
public class NexoDataProvider extends ExternalDataProvider {
|
||||||
|
private final AtomicBoolean failed = new AtomicBoolean(false);
|
||||||
|
|
||||||
|
public NexoDataProvider() {
|
||||||
|
super("Nexo");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void init() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public BlockData getBlockData(@NotNull Identifier blockId, @NotNull KMap<String, String> state) throws MissingResourceException {
|
||||||
|
if (!NexoItems.exists(blockId.key())) {
|
||||||
|
throw new MissingResourceException("Failed to find BlockData!", blockId.namespace(), blockId.key());
|
||||||
|
}
|
||||||
|
|
||||||
|
Identifier blockState = ExternalDataSVC.buildState(blockId, state);
|
||||||
|
if (NexoBlocks.isCustomBlock(blockId.key())) {
|
||||||
|
BlockData data = NexoBlocks.blockData(blockId.key());
|
||||||
|
if (data == null)
|
||||||
|
throw new MissingResourceException("Failed to find BlockData!", blockId.namespace(), blockId.key());
|
||||||
|
return new IrisBlockData(data, blockState);
|
||||||
|
} else if (NexoFurniture.isFurniture(blockId.key())) {
|
||||||
|
return new IrisBlockData(B.getAir(), blockState);
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new MissingResourceException("Failed to find BlockData!", blockId.namespace(), blockId.key());
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public ItemStack getItemStack(@NotNull Identifier itemId, @NotNull KMap<String, Object> customNbt) throws MissingResourceException {
|
||||||
|
ItemBuilder builder = NexoItems.itemFromId(itemId.key());
|
||||||
|
if (builder == null) {
|
||||||
|
throw new MissingResourceException("Failed to find ItemData!", itemId.namespace(), itemId.key());
|
||||||
|
}
|
||||||
|
return builder.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void processUpdate(@NotNull Engine engine, @NotNull Block block, @NotNull Identifier blockId) {
|
||||||
|
var pair = ExternalDataSVC.parseState(blockId);
|
||||||
|
var state = pair.getB();
|
||||||
|
blockId = pair.getA();
|
||||||
|
|
||||||
|
if (NexoBlocks.isCustomBlock(blockId.key())) {
|
||||||
|
NexoBlocks.place(blockId.key(), block.getLocation());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!NexoFurniture.isFurniture(blockId.key()))
|
||||||
|
return;
|
||||||
|
|
||||||
|
float yaw = 0;
|
||||||
|
BlockFace face = BlockFace.NORTH;
|
||||||
|
|
||||||
|
long seed = engine.getSeedManager().getSeed() + Cache.key(block.getX(), block.getZ()) + block.getY();
|
||||||
|
RNG rng = new RNG(seed);
|
||||||
|
if ("true".equals(state.get("randomYaw"))) {
|
||||||
|
yaw = rng.f(0, 360);
|
||||||
|
} else if (state.containsKey("yaw")) {
|
||||||
|
yaw = Float.parseFloat(state.get("yaw"));
|
||||||
|
}
|
||||||
|
if ("true".equals(state.get("randomFace"))) {
|
||||||
|
BlockFace[] faces = BlockFace.values();
|
||||||
|
face = faces[rng.i(0, faces.length - 1)];
|
||||||
|
} else if (state.containsKey("face")) {
|
||||||
|
face = BlockFace.valueOf(state.get("face").toUpperCase());
|
||||||
|
}
|
||||||
|
if (face == BlockFace.SELF) {
|
||||||
|
face = BlockFace.NORTH;
|
||||||
|
}
|
||||||
|
ItemDisplay display = NexoFurniture.place(blockId.key(), block.getLocation(), yaw, face);
|
||||||
|
if (display == null) return;
|
||||||
|
ItemStack itemStack = display.getItemStack();
|
||||||
|
if (itemStack == null) return;
|
||||||
|
|
||||||
|
BiomeColor type = null;
|
||||||
|
try {
|
||||||
|
type = BiomeColor.valueOf(state.get("matchBiome").toUpperCase());
|
||||||
|
} catch (NullPointerException | IllegalArgumentException ignored) {}
|
||||||
|
|
||||||
|
if (type != null) {
|
||||||
|
var biomeColor = INMS.get().getBiomeColor(block.getLocation(), type);
|
||||||
|
if (biomeColor == null) return;
|
||||||
|
var potionColor = Color.fromARGB(biomeColor.getAlpha(), biomeColor.getRed(), biomeColor.getGreen(), biomeColor.getBlue());
|
||||||
|
if (itemStack.getItemMeta() instanceof PotionMeta meta) {
|
||||||
|
meta.setColor(potionColor);
|
||||||
|
itemStack.setItemMeta(meta);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
display.setItemStack(itemStack);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public Identifier[] getBlockTypes() {
|
||||||
|
return Arrays.stream(NexoItems.itemNames())
|
||||||
|
.map(i -> new Identifier("nexo", i))
|
||||||
|
.filter(i -> {
|
||||||
|
try {
|
||||||
|
return getBlockData(i) != null;
|
||||||
|
} catch (MissingResourceException e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.toArray(Identifier[]::new);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public Identifier[] getItemTypes() {
|
||||||
|
return Arrays.stream(NexoItems.itemNames())
|
||||||
|
.map(i -> new Identifier("nexo", i))
|
||||||
|
.filter(i -> {
|
||||||
|
try {
|
||||||
|
return getItemStack(i) != null;
|
||||||
|
} catch (MissingResourceException e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.toArray(Identifier[]::new);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isValidProvider(@NotNull Identifier id, boolean isItem) {
|
||||||
|
return "nexo".equalsIgnoreCase(id.namespace());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isReady() {
|
||||||
|
return super.isReady() && !failed.get();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,213 +0,0 @@
|
|||||||
/*
|
|
||||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
|
||||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.volmit.iris.core.link;
|
|
||||||
|
|
||||||
import com.volmit.iris.Iris;
|
|
||||||
import com.volmit.iris.core.nms.INMS;
|
|
||||||
import com.volmit.iris.core.nms.container.BiomeColor;
|
|
||||||
import com.volmit.iris.core.service.ExternalDataSVC;
|
|
||||||
import com.volmit.iris.engine.data.cache.Cache;
|
|
||||||
import com.volmit.iris.engine.framework.Engine;
|
|
||||||
import com.volmit.iris.util.collection.KList;
|
|
||||||
import com.volmit.iris.util.collection.KMap;
|
|
||||||
import com.volmit.iris.util.data.B;
|
|
||||||
import com.volmit.iris.util.data.IrisBlockData;
|
|
||||||
import com.volmit.iris.util.math.RNG;
|
|
||||||
import com.volmit.iris.util.reflect.WrappedField;
|
|
||||||
import io.th0rgal.oraxen.api.OraxenItems;
|
|
||||||
import io.th0rgal.oraxen.items.ItemBuilder;
|
|
||||||
import io.th0rgal.oraxen.mechanics.Mechanic;
|
|
||||||
import io.th0rgal.oraxen.mechanics.MechanicFactory;
|
|
||||||
import io.th0rgal.oraxen.mechanics.MechanicsManager;
|
|
||||||
import io.th0rgal.oraxen.mechanics.provided.gameplay.block.BlockMechanic;
|
|
||||||
import io.th0rgal.oraxen.mechanics.provided.gameplay.block.BlockMechanicFactory;
|
|
||||||
import io.th0rgal.oraxen.mechanics.provided.gameplay.furniture.FurnitureFactory;
|
|
||||||
import io.th0rgal.oraxen.mechanics.provided.gameplay.furniture.FurnitureMechanic;
|
|
||||||
import io.th0rgal.oraxen.mechanics.provided.gameplay.noteblock.NoteBlockMechanicFactory;
|
|
||||||
import io.th0rgal.oraxen.mechanics.provided.gameplay.stringblock.StringBlockMechanicFactory;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.Color;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.block.Block;
|
|
||||||
import org.bukkit.block.BlockFace;
|
|
||||||
import org.bukkit.block.data.BlockData;
|
|
||||||
import org.bukkit.block.data.MultipleFacing;
|
|
||||||
import org.bukkit.entity.Entity;
|
|
||||||
import org.bukkit.entity.ItemDisplay;
|
|
||||||
import org.bukkit.entity.ItemFrame;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
import org.bukkit.inventory.meta.PotionMeta;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.MissingResourceException;
|
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.function.Consumer;
|
|
||||||
|
|
||||||
public class OraxenDataProvider extends ExternalDataProvider {
|
|
||||||
|
|
||||||
private static final String FIELD_FACTORIES_MAP = "FACTORIES_BY_MECHANIC_ID";
|
|
||||||
|
|
||||||
private WrappedField<MechanicsManager, Map<String, MechanicFactory>> factories;
|
|
||||||
|
|
||||||
public OraxenDataProvider() {
|
|
||||||
super("Oraxen");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void init() {
|
|
||||||
Iris.info("Setting up Oraxen Link...");
|
|
||||||
this.factories = new WrappedField<>(MechanicsManager.class, FIELD_FACTORIES_MAP);
|
|
||||||
if (this.factories.hasFailed()) {
|
|
||||||
Iris.error("Failed to set up Oraxen Link: Unable to fetch MechanicFactoriesMap!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public BlockData getBlockData(Identifier blockId, KMap<String, String> state) throws MissingResourceException {
|
|
||||||
MechanicFactory factory = getFactory(blockId);
|
|
||||||
if (factory instanceof NoteBlockMechanicFactory f)
|
|
||||||
return f.createNoteBlockData(blockId.key());
|
|
||||||
else if (factory instanceof BlockMechanicFactory f) {
|
|
||||||
MultipleFacing newBlockData = (MultipleFacing) Bukkit.createBlockData(Material.MUSHROOM_STEM);
|
|
||||||
BlockMechanic.setBlockFacing(newBlockData, ((BlockMechanic) f.getMechanic(blockId.key())).getCustomVariation());
|
|
||||||
return newBlockData;
|
|
||||||
} else if (factory instanceof StringBlockMechanicFactory f) {
|
|
||||||
return f.createTripwireData(blockId.key());
|
|
||||||
} else if (factory instanceof FurnitureFactory) {
|
|
||||||
return new IrisBlockData(B.getAir(), ExternalDataSVC.buildState(blockId, state));
|
|
||||||
} else
|
|
||||||
throw new MissingResourceException("Failed to find BlockData!", blockId.namespace(), blockId.key());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ItemStack getItemStack(Identifier itemId, KMap<String, Object> customNbt) throws MissingResourceException {
|
|
||||||
Optional<ItemBuilder> opt = OraxenItems.getOptionalItemById(itemId.key());
|
|
||||||
return opt.orElseThrow(() -> new MissingResourceException("Failed to find ItemData!", itemId.namespace(), itemId.key())).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void processUpdate(Engine engine, Block block, Identifier blockId) {
|
|
||||||
var pair = ExternalDataSVC.parseState(blockId);
|
|
||||||
var state = pair.getB();
|
|
||||||
blockId = pair.getA();
|
|
||||||
Mechanic mechanic = getFactory(blockId).getMechanic(blockId.key());
|
|
||||||
if (mechanic instanceof FurnitureMechanic f) {
|
|
||||||
float yaw = 0;
|
|
||||||
BlockFace face = BlockFace.NORTH;
|
|
||||||
|
|
||||||
long seed = engine.getSeedManager().getSeed() + Cache.key(block.getX(), block.getZ()) + block.getY();
|
|
||||||
RNG rng = new RNG(seed);
|
|
||||||
if ("true".equals(state.get("randomYaw"))) {
|
|
||||||
yaw = rng.f(0, 360);
|
|
||||||
} else if (state.containsKey("yaw")) {
|
|
||||||
yaw = Float.parseFloat(state.get("yaw"));
|
|
||||||
}
|
|
||||||
if ("true".equals(state.get("randomFace"))) {
|
|
||||||
BlockFace[] faces = BlockFace.values();
|
|
||||||
face = faces[rng.i(0, faces.length - 1)];
|
|
||||||
} else if (state.containsKey("face")) {
|
|
||||||
face = BlockFace.valueOf(state.get("face").toUpperCase());
|
|
||||||
}
|
|
||||||
if (face == BlockFace.SELF) {
|
|
||||||
face = BlockFace.NORTH;
|
|
||||||
}
|
|
||||||
ItemStack itemStack = OraxenItems.getItemById(f.getItemID()).build();
|
|
||||||
Entity entity = f.place(block.getLocation(), itemStack, yaw, face, false);
|
|
||||||
|
|
||||||
Consumer<ItemStack> setter = null;
|
|
||||||
if (entity instanceof ItemFrame frame) {
|
|
||||||
itemStack = frame.getItem();
|
|
||||||
setter = frame::setItem;
|
|
||||||
} else if (entity instanceof ItemDisplay display) {
|
|
||||||
itemStack = display.getItemStack();
|
|
||||||
setter = display::setItemStack;
|
|
||||||
}
|
|
||||||
if (setter == null || itemStack == null) return;
|
|
||||||
|
|
||||||
BiomeColor type = null;
|
|
||||||
try {
|
|
||||||
type = BiomeColor.valueOf(state.get("matchBiome").toUpperCase());
|
|
||||||
} catch (NullPointerException | IllegalArgumentException ignored) {}
|
|
||||||
|
|
||||||
if (type != null) {
|
|
||||||
var biomeColor = INMS.get().getBiomeColor(block.getLocation(), type);
|
|
||||||
if (biomeColor == null) return;
|
|
||||||
var potionColor = Color.fromARGB(biomeColor.getAlpha(), biomeColor.getRed(), biomeColor.getGreen(), biomeColor.getBlue());
|
|
||||||
if (itemStack.getItemMeta() instanceof PotionMeta meta) {
|
|
||||||
meta.setColor(potionColor);
|
|
||||||
itemStack.setItemMeta(meta);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
setter.accept(itemStack);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Identifier[] getBlockTypes() {
|
|
||||||
KList<Identifier> names = new KList<>();
|
|
||||||
for (String name : OraxenItems.getItemNames()) {
|
|
||||||
try {
|
|
||||||
Identifier key = new Identifier("oraxen", name);
|
|
||||||
if (getBlockData(key) != null)
|
|
||||||
names.add(key);
|
|
||||||
} catch (MissingResourceException ignored) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return names.toArray(new Identifier[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Identifier[] getItemTypes() {
|
|
||||||
KList<Identifier> names = new KList<>();
|
|
||||||
for (String name : OraxenItems.getItemNames()) {
|
|
||||||
try {
|
|
||||||
Identifier key = new Identifier("oraxen", name);
|
|
||||||
if (getItemStack(key) != null)
|
|
||||||
names.add(key);
|
|
||||||
} catch (MissingResourceException ignored) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return names.toArray(new Identifier[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isReady() {
|
|
||||||
if (super.isReady()) {
|
|
||||||
if (factories == null) {
|
|
||||||
this.factories = new WrappedField<>(MechanicsManager.class, FIELD_FACTORIES_MAP);
|
|
||||||
}
|
|
||||||
return super.isReady() && !factories.hasFailed();
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isValidProvider(Identifier key, boolean isItem) {
|
|
||||||
return key.namespace().equalsIgnoreCase("oraxen");
|
|
||||||
}
|
|
||||||
|
|
||||||
private MechanicFactory getFactory(Identifier key) throws MissingResourceException {
|
|
||||||
return factories.get().values().stream()
|
|
||||||
.filter(i -> i.getItems().contains(key.key()))
|
|
||||||
.findFirst()
|
|
||||||
.orElseThrow(() -> new MissingResourceException("Failed to find BlockData!", key.namespace(), key.key()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -36,6 +36,7 @@ import com.volmit.iris.util.format.C;
|
|||||||
import com.volmit.iris.util.math.RNG;
|
import com.volmit.iris.util.math.RNG;
|
||||||
import com.volmit.iris.util.parallel.BurstExecutor;
|
import com.volmit.iris.util.parallel.BurstExecutor;
|
||||||
import com.volmit.iris.util.parallel.MultiBurst;
|
import com.volmit.iris.util.parallel.MultiBurst;
|
||||||
|
import com.volmit.iris.util.reflect.OldEnum;
|
||||||
import com.volmit.iris.util.scheduling.ChronoLatch;
|
import com.volmit.iris.util.scheduling.ChronoLatch;
|
||||||
import com.volmit.iris.util.scheduling.J;
|
import com.volmit.iris.util.scheduling.J;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
@@ -337,6 +338,15 @@ public class IrisData implements ExclusionStrategy, TypeAdapterFactory {
|
|||||||
this.imageLoader = registerLoader(IrisImage.class);
|
this.imageLoader = registerLoader(IrisImage.class);
|
||||||
this.scriptLoader = registerLoader(IrisScript.class);
|
this.scriptLoader = registerLoader(IrisScript.class);
|
||||||
this.matterObjectLoader = registerLoader(IrisMatterObject.class);
|
this.matterObjectLoader = registerLoader(IrisMatterObject.class);
|
||||||
|
if (OldEnum.exists()) {
|
||||||
|
builder.registerTypeAdapterFactory(new TypeAdapterFactory() {
|
||||||
|
@Override
|
||||||
|
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
|
||||||
|
return (TypeAdapter<T>) OldEnum.create(type.getRawType());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
gson = builder.create();
|
gson = builder.create();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -434,6 +444,7 @@ public class IrisData implements ExclusionStrategy, TypeAdapterFactory {
|
|||||||
return adapter.read(reader);
|
return adapter.read(reader);
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
Iris.error("Failed to read " + typeToken.getRawType().getCanonicalName() + "... faking objects a little to load the file at least.");
|
Iris.error("Failed to read " + typeToken.getRawType().getCanonicalName() + "... faking objects a little to load the file at least.");
|
||||||
|
Iris.reportError(e);
|
||||||
try {
|
try {
|
||||||
return (T) typeToken.getRawType().getConstructor().newInstance();
|
return (T) typeToken.getRawType().getConstructor().newInstance();
|
||||||
} catch (Throwable ignored) {
|
} catch (Throwable ignored) {
|
||||||
|
|||||||
@@ -30,7 +30,9 @@ public class INMS {
|
|||||||
"1.20.5", "v1_20_R4",
|
"1.20.5", "v1_20_R4",
|
||||||
"1.20.6", "v1_20_R4",
|
"1.20.6", "v1_20_R4",
|
||||||
"1.21", "v1_21_R1",
|
"1.21", "v1_21_R1",
|
||||||
"1.21.1", "v1_21_R1"
|
"1.21.1", "v1_21_R1",
|
||||||
|
"1.21.2", "v1_21_R2",
|
||||||
|
"1.21.3", "v1_21_R2"
|
||||||
);
|
);
|
||||||
//@done
|
//@done
|
||||||
private static final INMSBinding binding = bind();
|
private static final INMSBinding binding = bind();
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package com.volmit.iris.core.nms.datapack;
|
|||||||
import com.volmit.iris.core.nms.INMS;
|
import com.volmit.iris.core.nms.INMS;
|
||||||
import com.volmit.iris.core.nms.datapack.v1192.DataFixerV1192;
|
import com.volmit.iris.core.nms.datapack.v1192.DataFixerV1192;
|
||||||
import com.volmit.iris.core.nms.datapack.v1206.DataFixerV1206;
|
import com.volmit.iris.core.nms.datapack.v1206.DataFixerV1206;
|
||||||
|
import com.volmit.iris.core.nms.datapack.v1213.DataFixerV1213;
|
||||||
import com.volmit.iris.util.collection.KMap;
|
import com.volmit.iris.util.collection.KMap;
|
||||||
import lombok.AccessLevel;
|
import lombok.AccessLevel;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
@@ -13,7 +14,8 @@ import java.util.function.Supplier;
|
|||||||
@Getter
|
@Getter
|
||||||
public enum DataVersion {
|
public enum DataVersion {
|
||||||
V1192("1.19.2", 10, DataFixerV1192::new),
|
V1192("1.19.2", 10, DataFixerV1192::new),
|
||||||
V1205("1.20.6", 41, DataFixerV1206::new);
|
V1205("1.20.6", 41, DataFixerV1206::new),
|
||||||
|
V1213("1.21.3", 57, DataFixerV1213::new);
|
||||||
private static final KMap<DataVersion, IDataFixer> cache = new KMap<>();
|
private static final KMap<DataVersion, IDataFixer> cache = new KMap<>();
|
||||||
@Getter(AccessLevel.NONE)
|
@Getter(AccessLevel.NONE)
|
||||||
private final Supplier<IDataFixer> constructor;
|
private final Supplier<IDataFixer> constructor;
|
||||||
|
|||||||
@@ -16,6 +16,8 @@ public class DataFixerV1206 implements IDataFixer {
|
|||||||
int spawnRarity = biome.getSpawnRarity();
|
int spawnRarity = biome.getSpawnRarity();
|
||||||
if (spawnRarity > 0) {
|
if (spawnRarity > 0) {
|
||||||
json.put("creature_spawn_probability", Math.min(spawnRarity/20d, 0.9999999));
|
json.put("creature_spawn_probability", Math.min(spawnRarity/20d, 0.9999999));
|
||||||
|
} else {
|
||||||
|
json.remove("creature_spawn_probability");
|
||||||
}
|
}
|
||||||
|
|
||||||
var spawns = biome.getSpawns();
|
var spawns = biome.getSpawns();
|
||||||
@@ -26,10 +28,10 @@ public class DataFixerV1206 implements IDataFixer {
|
|||||||
for (IrisBiomeCustomSpawn i : spawns) {
|
for (IrisBiomeCustomSpawn i : spawns) {
|
||||||
JSONArray g = groups.computeIfAbsent(i.getGroup(), (k) -> new JSONArray());
|
JSONArray g = groups.computeIfAbsent(i.getGroup(), (k) -> new JSONArray());
|
||||||
JSONObject o = new JSONObject();
|
JSONObject o = new JSONObject();
|
||||||
o.put("type", "minecraft:" + i.getType().name().toLowerCase());
|
o.put("type", i.getType().getKey());
|
||||||
o.put("weight", i.getWeight());
|
o.put("weight", i.getWeight());
|
||||||
o.put("minCount", Math.min(i.getMinCount()/20d, 0));
|
o.put("minCount", i.getMinCount());
|
||||||
o.put("maxCount", Math.min(i.getMaxCount()/20d, 0.9999999));
|
o.put("maxCount", i.getMaxCount());
|
||||||
g.put(o);
|
g.put(o);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package com.volmit.iris.core.nms.datapack.v1213;
|
||||||
|
|
||||||
|
import com.volmit.iris.core.nms.datapack.v1206.DataFixerV1206;
|
||||||
|
import com.volmit.iris.engine.object.IrisBiomeCustom;
|
||||||
|
import com.volmit.iris.util.json.JSONArray;
|
||||||
|
import com.volmit.iris.util.json.JSONObject;
|
||||||
|
|
||||||
|
public class DataFixerV1213 extends DataFixerV1206 {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JSONObject fixCustomBiome(IrisBiomeCustom biome, JSONObject json) {
|
||||||
|
json = super.fixCustomBiome(biome, json);
|
||||||
|
json.put("carvers", new JSONArray());
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -21,7 +21,6 @@ package com.volmit.iris.core.nms.v1X;
|
|||||||
import com.volmit.iris.Iris;
|
import com.volmit.iris.Iris;
|
||||||
import com.volmit.iris.core.nms.INMSBinding;
|
import com.volmit.iris.core.nms.INMSBinding;
|
||||||
import com.volmit.iris.core.nms.container.BiomeColor;
|
import com.volmit.iris.core.nms.container.BiomeColor;
|
||||||
import com.volmit.iris.core.nms.container.BlockPos;
|
|
||||||
import com.volmit.iris.engine.framework.Engine;
|
import com.volmit.iris.engine.framework.Engine;
|
||||||
import com.volmit.iris.util.collection.KList;
|
import com.volmit.iris.util.collection.KList;
|
||||||
import com.volmit.iris.util.collection.KMap;
|
import com.volmit.iris.util.collection.KMap;
|
||||||
@@ -32,7 +31,6 @@ import com.volmit.iris.util.nbt.mca.palette.MCAPaletteAccess;
|
|||||||
import com.volmit.iris.util.nbt.tag.CompoundTag;
|
import com.volmit.iris.util.nbt.tag.CompoundTag;
|
||||||
import org.bukkit.*;
|
import org.bukkit.*;
|
||||||
import org.bukkit.block.Biome;
|
import org.bukkit.block.Biome;
|
||||||
import org.bukkit.entity.Dolphin;
|
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||||
@@ -40,8 +38,8 @@ import org.bukkit.generator.ChunkGenerator;
|
|||||||
import org.bukkit.generator.structure.Structure;
|
import org.bukkit.generator.structure.Structure;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
import java.awt.*;
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
|
import java.util.stream.StreamSupport;
|
||||||
|
|
||||||
public class NMSBinding1X implements INMSBinding {
|
public class NMSBinding1X implements INMSBinding {
|
||||||
private static final boolean supportsCustomHeight = testCustomHeight();
|
private static final boolean supportsCustomHeight = testCustomHeight();
|
||||||
@@ -113,7 +111,7 @@ public class NMSBinding1X implements INMSBinding {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KList<String> getStructureKeys() {
|
public KList<String> getStructureKeys() {
|
||||||
var list = Registry.STRUCTURE.stream()
|
var list = StreamSupport.stream(Registry.STRUCTURE.spliterator(), false)
|
||||||
.map(Structure::getKey)
|
.map(Structure::getKey)
|
||||||
.map(NamespacedKey::toString)
|
.map(NamespacedKey::toString)
|
||||||
.toList();
|
.toList();
|
||||||
|
|||||||
@@ -1,16 +1,21 @@
|
|||||||
package com.volmit.iris.core.pregenerator;
|
package com.volmit.iris.core.pregenerator;
|
||||||
|
|
||||||
import com.volmit.iris.Iris;
|
import com.volmit.iris.Iris;
|
||||||
|
import com.volmit.iris.core.IrisSettings;
|
||||||
|
import com.volmit.iris.core.nms.container.Pair;
|
||||||
import com.volmit.iris.core.tools.IrisToolbelt;
|
import com.volmit.iris.core.tools.IrisToolbelt;
|
||||||
|
import com.volmit.iris.engine.data.cache.Cache;
|
||||||
import com.volmit.iris.engine.framework.Engine;
|
import com.volmit.iris.engine.framework.Engine;
|
||||||
import com.volmit.iris.util.collection.KList;
|
|
||||||
import com.volmit.iris.util.collection.KMap;
|
import com.volmit.iris.util.collection.KMap;
|
||||||
import com.volmit.iris.util.format.Form;
|
import com.volmit.iris.util.format.Form;
|
||||||
|
import com.volmit.iris.util.mantle.MantleFlag;
|
||||||
import com.volmit.iris.util.math.M;
|
import com.volmit.iris.util.math.M;
|
||||||
|
import com.volmit.iris.util.math.Position2;
|
||||||
import com.volmit.iris.util.math.RollingSequence;
|
import com.volmit.iris.util.math.RollingSequence;
|
||||||
import com.volmit.iris.util.math.Spiraler;
|
import com.volmit.iris.util.profile.LoadBalancer;
|
||||||
import com.volmit.iris.util.scheduling.J;
|
import com.volmit.iris.util.scheduling.J;
|
||||||
import io.papermc.lib.PaperLib;
|
import io.papermc.lib.PaperLib;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Chunk;
|
import org.bukkit.Chunk;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
|
|
||||||
@@ -23,53 +28,40 @@ import java.util.concurrent.atomic.AtomicInteger;
|
|||||||
import java.util.concurrent.atomic.AtomicLong;
|
import java.util.concurrent.atomic.AtomicLong;
|
||||||
|
|
||||||
public class ChunkUpdater {
|
public class ChunkUpdater {
|
||||||
private AtomicBoolean paused;
|
private final AtomicBoolean paused = new AtomicBoolean();
|
||||||
private AtomicBoolean cancelled;
|
private final AtomicBoolean cancelled = new AtomicBoolean();
|
||||||
private KMap<Chunk, Long> lastUse;
|
private final KMap<Long, Pair<Long, AtomicInteger>> lastUse = new KMap<>();
|
||||||
private final RollingSequence chunksPerSecond;
|
private final RollingSequence chunksPerSecond = new RollingSequence(5);
|
||||||
private final AtomicInteger worldheightsize;
|
private final AtomicInteger totalMaxChunks = new AtomicInteger();
|
||||||
private final AtomicInteger worldwidthsize;
|
private final AtomicInteger chunksProcessed = new AtomicInteger();
|
||||||
private final AtomicInteger totalChunks;
|
private final AtomicInteger chunksProcessedLast = new AtomicInteger();
|
||||||
private final AtomicInteger totalMaxChunks;
|
private final AtomicInteger chunksUpdated = new AtomicInteger();
|
||||||
private final AtomicInteger totalMcaregions;
|
private final AtomicBoolean serverEmpty = new AtomicBoolean(true);
|
||||||
private final AtomicInteger position;
|
private final AtomicLong lastCpsTime = new AtomicLong(M.ms());
|
||||||
private AtomicInteger chunksProcessed;
|
private final int coreLimit = (int) Math.max(Runtime.getRuntime().availableProcessors() * IrisSettings.get().getUpdater().getThreadMultiplier(), 1);
|
||||||
private AtomicInteger chunksUpdated;
|
private final Semaphore semaphore = new Semaphore(256);
|
||||||
private AtomicLong startTime;
|
private final LoadBalancer loadBalancer = new LoadBalancer(semaphore, 256, IrisSettings.get().getUpdater().emptyMsRange);
|
||||||
private ExecutorService executor;
|
private final AtomicLong startTime = new AtomicLong();
|
||||||
private ExecutorService chunkExecutor;
|
private final Dimensions dimensions;
|
||||||
private ScheduledExecutorService scheduler;
|
private final PregenTask task;
|
||||||
private CompletableFuture future;
|
private final ExecutorService executor = Executors.newFixedThreadPool(coreLimit);
|
||||||
private CountDownLatch latch;
|
private final ExecutorService chunkExecutor = Executors.newFixedThreadPool(coreLimit);
|
||||||
private final Object pauseLock;
|
private final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
|
||||||
|
private final CountDownLatch latch;
|
||||||
private final Engine engine;
|
private final Engine engine;
|
||||||
private final World world;
|
private final World world;
|
||||||
|
|
||||||
public ChunkUpdater(World world) {
|
public ChunkUpdater(World world) {
|
||||||
this.engine = IrisToolbelt.access(world).getEngine();
|
this.engine = IrisToolbelt.access(world).getEngine();
|
||||||
this.chunksPerSecond = new RollingSequence(5);
|
|
||||||
this.world = world;
|
this.world = world;
|
||||||
this.lastUse = new KMap();
|
this.dimensions = calculateWorldDimensions(new File(world.getWorldFolder(), "region"));
|
||||||
this.worldheightsize = new AtomicInteger(calculateWorldDimensions(new File(world.getWorldFolder(), "region"), 1));
|
this.task = dimensions.task();
|
||||||
this.worldwidthsize = new AtomicInteger(calculateWorldDimensions(new File(world.getWorldFolder(), "region"), 0));
|
this.totalMaxChunks.set(dimensions.count * 1024);
|
||||||
int m = Math.max(worldheightsize.get(), worldwidthsize.get());
|
|
||||||
this.executor = Executors.newFixedThreadPool(Math.max(Runtime.getRuntime().availableProcessors() / 3, 1));
|
|
||||||
this.chunkExecutor = Executors.newFixedThreadPool(Math.max(Runtime.getRuntime().availableProcessors() / 3, 1));
|
|
||||||
this.scheduler = Executors.newScheduledThreadPool(1);
|
|
||||||
this.future = new CompletableFuture<>();
|
|
||||||
this.startTime = new AtomicLong();
|
|
||||||
this.worldheightsize.set(m);
|
|
||||||
this.worldwidthsize.set(m);
|
|
||||||
this.totalMaxChunks = new AtomicInteger((worldheightsize.get() / 16) * (worldwidthsize.get() / 16));
|
|
||||||
this.chunksProcessed = new AtomicInteger();
|
|
||||||
this.chunksUpdated = new AtomicInteger();
|
|
||||||
this.position = new AtomicInteger(0);
|
|
||||||
this.latch = new CountDownLatch(totalMaxChunks.get());
|
this.latch = new CountDownLatch(totalMaxChunks.get());
|
||||||
this.paused = new AtomicBoolean(false);
|
}
|
||||||
this.pauseLock = new Object();
|
|
||||||
this.cancelled = new AtomicBoolean(false);
|
public String getName() {
|
||||||
this.totalChunks = new AtomicInteger(0);
|
return world.getName();
|
||||||
this.totalMcaregions = new AtomicInteger(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getChunks() {
|
public int getChunks() {
|
||||||
@@ -97,7 +89,6 @@ public class ChunkUpdater {
|
|||||||
cancelled.set(true);
|
cancelled.set(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void update() {
|
private void update() {
|
||||||
Iris.info("Updating..");
|
Iris.info("Updating..");
|
||||||
try {
|
try {
|
||||||
@@ -106,11 +97,11 @@ public class ChunkUpdater {
|
|||||||
try {
|
try {
|
||||||
if (!paused.get()) {
|
if (!paused.get()) {
|
||||||
long eta = computeETA();
|
long eta = computeETA();
|
||||||
long elapsedSeconds = (System.currentTimeMillis() - startTime.get()) / 1000;
|
|
||||||
int processed = chunksProcessed.get();
|
int processed = chunksProcessed.get();
|
||||||
double cps = elapsedSeconds > 0 ? processed / (double) elapsedSeconds : 0;
|
double last = processed - chunksProcessedLast.getAndSet(processed);
|
||||||
|
double cps = last / ((M.ms() - lastCpsTime.getAndSet(M.ms())) / 1000d);
|
||||||
chunksPerSecond.put(cps);
|
chunksPerSecond.put(cps);
|
||||||
double percentage = ((double) chunksProcessed.get() / (double) totalMaxChunks.get()) * 100;
|
double percentage = ((double) processed / (double) totalMaxChunks.get()) * 100;
|
||||||
if (!cancelled.get()) {
|
if (!cancelled.get()) {
|
||||||
Iris.info("Updated: " + Form.f(processed) + " of " + Form.f(totalMaxChunks.get()) + " (%.0f%%) " + Form.f(chunksPerSecond.getAverage()) + "/s, ETA: " + Form.duration(eta,
|
Iris.info("Updated: " + Form.f(processed) + " of " + Form.f(totalMaxChunks.get()) + " (%.0f%%) " + Form.f(chunksPerSecond.getAverage()) + "/s, ETA: " + Form.duration(eta,
|
||||||
2), percentage);
|
2), percentage);
|
||||||
@@ -120,35 +111,20 @@ public class ChunkUpdater {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}, 0, 3, TimeUnit.SECONDS);
|
}, 0, 3, TimeUnit.SECONDS);
|
||||||
|
scheduler.scheduleAtFixedRate(this::unloadChunks, 0, 1, TimeUnit.SECONDS);
|
||||||
|
scheduler.scheduleAtFixedRate(() -> {
|
||||||
|
boolean empty = Bukkit.getOnlinePlayers().isEmpty();
|
||||||
|
if (serverEmpty.getAndSet(empty) == empty)
|
||||||
|
return;
|
||||||
|
loadBalancer.setRange(empty ? IrisSettings.get().getUpdater().emptyMsRange : IrisSettings.get().getUpdater().defaultMsRange);
|
||||||
|
}, 0, 10, TimeUnit.SECONDS);
|
||||||
|
|
||||||
CompletableFuture.runAsync(() -> {
|
var t = new Thread(() -> {
|
||||||
for (int i = 0; i < totalMaxChunks.get(); i++) {
|
run();
|
||||||
if (paused.get()) {
|
|
||||||
synchronized (pauseLock) {
|
|
||||||
try {
|
|
||||||
pauseLock.wait();
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
Iris.error("Interrupted while waiting for executor: ");
|
|
||||||
e.printStackTrace();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
executor.submit(() -> {
|
|
||||||
if (!cancelled.get()) {
|
|
||||||
processNextChunk();
|
|
||||||
}
|
|
||||||
latch.countDown();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}).thenRun(() -> {
|
|
||||||
try {
|
|
||||||
latch.await();
|
|
||||||
close();
|
close();
|
||||||
} catch (Exception e) {
|
}, "Iris Chunk Updater - " + world.getName());
|
||||||
Thread.currentThread().interrupt();
|
t.setPriority(Thread.MAX_PRIORITY);
|
||||||
}
|
t.start();
|
||||||
});
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@@ -157,14 +133,16 @@ public class ChunkUpdater {
|
|||||||
|
|
||||||
public void close() {
|
public void close() {
|
||||||
try {
|
try {
|
||||||
unloadAndSaveAllChunks();
|
loadBalancer.close();
|
||||||
|
semaphore.acquire(256);
|
||||||
|
|
||||||
executor.shutdown();
|
executor.shutdown();
|
||||||
executor.awaitTermination(5, TimeUnit.SECONDS);
|
executor.awaitTermination(5, TimeUnit.SECONDS);
|
||||||
chunkExecutor.shutdown();
|
chunkExecutor.shutdown();
|
||||||
chunkExecutor.awaitTermination(5, TimeUnit.SECONDS);
|
chunkExecutor.awaitTermination(5, TimeUnit.SECONDS);
|
||||||
scheduler.shutdownNow();
|
scheduler.shutdownNow();
|
||||||
} catch (Exception ignored) {
|
unloadAndSaveAllChunks();
|
||||||
}
|
} catch (Exception ignored) {}
|
||||||
if (cancelled.get()) {
|
if (cancelled.get()) {
|
||||||
Iris.info("Updated: " + Form.f(chunksUpdated.get()) + " Chunks");
|
Iris.info("Updated: " + Form.f(chunksUpdated.get()) + " Chunks");
|
||||||
Iris.info("Irritated: " + Form.f(chunksProcessed.get()) + " of " + Form.f(totalMaxChunks.get()));
|
Iris.info("Irritated: " + Form.f(chunksProcessed.get()) + " of " + Form.f(totalMaxChunks.get()));
|
||||||
@@ -175,18 +153,69 @@ public class ChunkUpdater {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processNextChunk() {
|
private void run() {
|
||||||
int pos = position.getAndIncrement();
|
task.iterateRegions((rX, rZ) -> {
|
||||||
int[] coords = getChunk(pos);
|
if (cancelled.get())
|
||||||
if (loadChunksIfGenerated(coords[0], coords[1])) {
|
return;
|
||||||
Chunk c = world.getChunkAt(coords[0], coords[1]);
|
|
||||||
engine.updateChunk(c);
|
while (paused.get()) {
|
||||||
chunksUpdated.incrementAndGet();
|
J.sleep(50);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (rX < dimensions.min.getX() || rX > dimensions.max.getX() || rZ < dimensions.min.getZ() || rZ > dimensions.max.getZ()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
PregenTask.iterateRegion(rX, rZ, (x, z) -> {
|
||||||
|
while (paused.get() && !cancelled.get()) {
|
||||||
|
J.sleep(50);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
semaphore.acquire();
|
||||||
|
} catch (InterruptedException ignored) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
chunkExecutor.submit(() -> {
|
||||||
|
try {
|
||||||
|
if (!cancelled.get())
|
||||||
|
processChunk(x, z);
|
||||||
|
} finally {
|
||||||
|
latch.countDown();
|
||||||
|
semaphore.release();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void processChunk(int x, int z) {
|
||||||
|
if (!loadChunksIfGenerated(x, z)) {
|
||||||
chunksProcessed.getAndIncrement();
|
chunksProcessed.getAndIncrement();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
Chunk c = world.getChunkAt(x, z);
|
||||||
|
engine.getMantle().getMantle().getChunk(c);
|
||||||
|
engine.updateChunk(c);
|
||||||
|
|
||||||
|
for (int xx = -1; xx <= 1; xx++) {
|
||||||
|
for (int zz = -1; zz <= 1; zz++) {
|
||||||
|
var counter = lastUse.get(Cache.key(x + xx, z + zz));
|
||||||
|
if (counter != null) counter.getB().decrementAndGet();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
chunksUpdated.incrementAndGet();
|
||||||
|
chunksProcessed.getAndIncrement();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean loadChunksIfGenerated(int x, int z) {
|
private boolean loadChunksIfGenerated(int x, int z) {
|
||||||
|
if (engine.getMantle().getMantle().hasFlag(x, z, MantleFlag.ETCHED))
|
||||||
|
return false;
|
||||||
|
|
||||||
for (int dx = -1; dx <= 1; dx++) {
|
for (int dx = -1; dx <= 1; dx++) {
|
||||||
for (int dz = -1; dz <= 1; dz++) {
|
for (int dz = -1; dz <= 1; dz++) {
|
||||||
if (!PaperLib.isChunkGenerated(world, x + dx, z + dz)) {
|
if (!PaperLib.isChunkGenerated(world, x + dx, z + dz)) {
|
||||||
@@ -196,45 +225,79 @@ public class ChunkUpdater {
|
|||||||
}
|
}
|
||||||
|
|
||||||
AtomicBoolean generated = new AtomicBoolean(true);
|
AtomicBoolean generated = new AtomicBoolean(true);
|
||||||
KList<Future<?>> futures = new KList<>(9);
|
CountDownLatch latch = new CountDownLatch(9);
|
||||||
for (int dx = -1; dx <= 1; dx++) {
|
for (int dx = -1; dx <= 1; dx++) {
|
||||||
for (int dz = -1; dz <= 1; dz++) {
|
for (int dz = -1; dz <= 1; dz++) {
|
||||||
int xx = x + dx;
|
int xx = x + dx;
|
||||||
int zz = z + dz;
|
int zz = z + dz;
|
||||||
futures.add(chunkExecutor.submit(() -> {
|
executor.submit(() -> {
|
||||||
|
try {
|
||||||
Chunk c;
|
Chunk c;
|
||||||
try {
|
try {
|
||||||
c = PaperLib.getChunkAtAsync(world, xx, zz, false).get();
|
c = PaperLib.getChunkAtAsync(world, xx, zz, false, true)
|
||||||
|
.thenApply(chunk -> {
|
||||||
|
if (chunk != null)
|
||||||
|
chunk.addPluginChunkTicket(Iris.instance);
|
||||||
|
return chunk;
|
||||||
|
}).get();
|
||||||
} catch (InterruptedException | ExecutionException e) {
|
} catch (InterruptedException | ExecutionException e) {
|
||||||
generated.set(false);
|
generated.set(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (c == null) {
|
||||||
|
generated.set(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!c.isLoaded()) {
|
if (!c.isLoaded()) {
|
||||||
CountDownLatch latch = new CountDownLatch(1);
|
var future = J.sfut(() -> c.load(false));
|
||||||
J.s(() -> {
|
if (future != null) future.join();
|
||||||
c.load(false);
|
}
|
||||||
|
|
||||||
|
if (!PaperLib.isChunkGenerated(c.getWorld(), xx, zz))
|
||||||
|
generated.set(false);
|
||||||
|
|
||||||
|
var pair = lastUse.computeIfAbsent(Cache.key(c), k -> new Pair<>(0L, new AtomicInteger(-1)));
|
||||||
|
pair.setA(M.ms());
|
||||||
|
pair.getB().updateAndGet(i -> i == -1 ? 1 : ++i);
|
||||||
|
} finally {
|
||||||
latch.countDown();
|
latch.countDown();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
latch.await();
|
latch.await();
|
||||||
} catch (InterruptedException ignored) {}
|
} catch (InterruptedException e) {
|
||||||
}
|
Iris.info("Interrupted while waiting for chunks to load");
|
||||||
if (!c.isGenerated()) {
|
|
||||||
generated.set(false);
|
|
||||||
}
|
|
||||||
lastUse.put(c, M.ms());
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
while (!futures.isEmpty()) {
|
|
||||||
futures.removeIf(Future::isDone);
|
|
||||||
try {
|
|
||||||
Thread.sleep(50);
|
|
||||||
} catch (InterruptedException ignored) {}
|
|
||||||
}
|
}
|
||||||
return generated.get();
|
return generated.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private synchronized void unloadChunks() {
|
||||||
|
for (var key : new ArrayList<>(lastUse.keySet())) {
|
||||||
|
if (key == null) continue;
|
||||||
|
var pair = lastUse.get(key);
|
||||||
|
if (pair == null) continue;
|
||||||
|
var lastUseTime = pair.getA();
|
||||||
|
var counter = pair.getB();
|
||||||
|
if (lastUseTime == null || counter == null)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (M.ms() - lastUseTime >= 5000 && counter.get() == 0) {
|
||||||
|
int x = Cache.keyX(key);
|
||||||
|
int z = Cache.keyZ(key);
|
||||||
|
J.s(() -> {
|
||||||
|
world.removePluginChunkTicket(x, z, Iris.instance);
|
||||||
|
world.unloadChunk(x, z);
|
||||||
|
lastUse.remove(key);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void unloadAndSaveAllChunks() {
|
private void unloadAndSaveAllChunks() {
|
||||||
try {
|
try {
|
||||||
J.sfut(() -> {
|
J.sfut(() -> {
|
||||||
@@ -243,13 +306,7 @@ public class ChunkUpdater {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Chunk i : new ArrayList<>(lastUse.keySet())) {
|
unloadChunks();
|
||||||
Long lastUseTime = lastUse.get(i);
|
|
||||||
if (lastUseTime != null && M.ms() - lastUseTime >= 5000) {
|
|
||||||
i.unload();
|
|
||||||
lastUse.remove(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
world.save();
|
world.save();
|
||||||
}).get();
|
}).get();
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
@@ -266,7 +323,7 @@ public class ChunkUpdater {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int calculateWorldDimensions(File regionDir, Integer o) {
|
private Dimensions calculateWorldDimensions(File regionDir) {
|
||||||
File[] files = regionDir.listFiles((dir, name) -> name.endsWith(".mca"));
|
File[] files = regionDir.listFiles((dir, name) -> name.endsWith(".mca"));
|
||||||
|
|
||||||
int minX = Integer.MAX_VALUE;
|
int minX = Integer.MAX_VALUE;
|
||||||
@@ -279,40 +336,23 @@ public class ChunkUpdater {
|
|||||||
int x = Integer.parseInt(parts[1]);
|
int x = Integer.parseInt(parts[1]);
|
||||||
int z = Integer.parseInt(parts[2]);
|
int z = Integer.parseInt(parts[2]);
|
||||||
|
|
||||||
if (x < minX) minX = x;
|
minX = Math.min(minX, x);
|
||||||
if (x > maxX) maxX = x;
|
maxX = Math.max(maxX, x);
|
||||||
if (z < minZ) minZ = z;
|
minZ = Math.min(minZ, z);
|
||||||
if (z > maxZ) maxZ = z;
|
maxZ = Math.max(maxZ, z);
|
||||||
|
}
|
||||||
|
int oX = minX + ((maxX - minX) / 2);
|
||||||
|
int oZ = minZ + ((maxZ - minZ) / 2);
|
||||||
|
|
||||||
|
int height = maxX - minX + 1;
|
||||||
|
int width = maxZ - minZ + 1;
|
||||||
|
|
||||||
|
return new Dimensions(new Position2(minX, minZ), new Position2(maxX, maxZ), height * width, PregenTask.builder()
|
||||||
|
.width((int) Math.ceil(width / 2d))
|
||||||
|
.height((int) Math.ceil(height / 2d))
|
||||||
|
.center(new Position2(oX, oZ))
|
||||||
|
.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
int height = (maxX - minX + 1) * 32 * 16;
|
private record Dimensions(Position2 min, Position2 max, int count, PregenTask task) { }
|
||||||
int width = (maxZ - minZ + 1) * 32 * 16;
|
|
||||||
|
|
||||||
if (o == 1) {
|
|
||||||
return height;
|
|
||||||
}
|
|
||||||
if (o == 0) {
|
|
||||||
return width;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int[] getChunk(int position) {
|
|
||||||
int p = -1;
|
|
||||||
AtomicInteger xx = new AtomicInteger();
|
|
||||||
AtomicInteger zz = new AtomicInteger();
|
|
||||||
Spiraler s = new Spiraler(worldheightsize.get() * 2, worldwidthsize.get() * 2, (x, z) -> {
|
|
||||||
xx.set(x);
|
|
||||||
zz.set(z);
|
|
||||||
});
|
|
||||||
|
|
||||||
while (s.hasNext() && p++ < position) {
|
|
||||||
s.next();
|
|
||||||
}
|
|
||||||
int[] coords = new int[2];
|
|
||||||
coords[0] = xx.get();
|
|
||||||
coords[1] = zz.get();
|
|
||||||
|
|
||||||
return coords;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ import com.volmit.iris.util.math.RollingSequence;
|
|||||||
import com.volmit.iris.util.math.Spiraler;
|
import com.volmit.iris.util.math.Spiraler;
|
||||||
import com.volmit.iris.util.scheduling.ChronoLatch;
|
import com.volmit.iris.util.scheduling.ChronoLatch;
|
||||||
import com.volmit.iris.util.scheduling.J;
|
import com.volmit.iris.util.scheduling.J;
|
||||||
import lombok.Builder;
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@@ -261,14 +260,14 @@ public class DeepSearchPregenerator extends Thread implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@Builder
|
@lombok.Builder
|
||||||
public static class DeepSearchJob {
|
public static class DeepSearchJob {
|
||||||
private World world;
|
private World world;
|
||||||
@Builder.Default
|
@lombok.Builder.Default
|
||||||
private int radiusBlocks = 5000;
|
private int radiusBlocks = 5000;
|
||||||
@Builder.Default
|
@lombok.Builder.Default
|
||||||
private int position = 0;
|
private int position = 0;
|
||||||
@Builder.Default
|
@lombok.Builder.Default
|
||||||
boolean paused = false;
|
boolean paused = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ import com.volmit.iris.util.math.Spiraler;
|
|||||||
import com.volmit.iris.util.scheduling.ChronoLatch;
|
import com.volmit.iris.util.scheduling.ChronoLatch;
|
||||||
import com.volmit.iris.util.scheduling.J;
|
import com.volmit.iris.util.scheduling.J;
|
||||||
import io.papermc.lib.PaperLib;
|
import io.papermc.lib.PaperLib;
|
||||||
import lombok.Builder;
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@@ -264,22 +263,22 @@ public class LazyPregenerator extends Thread implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@Builder
|
@lombok.Builder
|
||||||
public static class LazyPregenJob {
|
public static class LazyPregenJob {
|
||||||
private String world;
|
private String world;
|
||||||
@Builder.Default
|
@lombok.Builder.Default
|
||||||
private int healingPosition = 0;
|
private int healingPosition = 0;
|
||||||
@Builder.Default
|
@lombok.Builder.Default
|
||||||
private boolean healing = false;
|
private boolean healing = false;
|
||||||
@Builder.Default
|
@lombok.Builder.Default
|
||||||
private int chunksPerMinute = 32;
|
private int chunksPerMinute = 32;
|
||||||
@Builder.Default
|
@lombok.Builder.Default
|
||||||
private int radiusBlocks = 5000;
|
private int radiusBlocks = 5000;
|
||||||
@Builder.Default
|
@lombok.Builder.Default
|
||||||
private int position = 0;
|
private int position = 0;
|
||||||
@Builder.Default
|
@lombok.Builder.Default
|
||||||
boolean silent = false;
|
boolean silent = false;
|
||||||
@Builder.Default
|
@lombok.Builder.Default
|
||||||
boolean paused = false;
|
boolean paused = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ import com.volmit.iris.util.scheduling.ChronoLatch;
|
|||||||
import com.volmit.iris.util.scheduling.J;
|
import com.volmit.iris.util.scheduling.J;
|
||||||
import com.volmit.iris.util.scheduling.PrecisionStopwatch;
|
import com.volmit.iris.util.scheduling.PrecisionStopwatch;
|
||||||
import io.papermc.lib.PaperLib;
|
import io.papermc.lib.PaperLib;
|
||||||
import lombok.Builder;
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import org.apache.logging.log4j.core.util.ExecutorServices;
|
import org.apache.logging.log4j.core.util.ExecutorServices;
|
||||||
@@ -328,14 +327,14 @@ public class TurboPregenerator extends Thread implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@Builder
|
@lombok.Builder
|
||||||
public static class TurboPregenJob {
|
public static class TurboPregenJob {
|
||||||
private String world;
|
private String world;
|
||||||
@Builder.Default
|
@lombok.Builder.Default
|
||||||
private int radiusBlocks = 5000;
|
private int radiusBlocks = 5000;
|
||||||
@Builder.Default
|
@lombok.Builder.Default
|
||||||
private int position = 0;
|
private int position = 0;
|
||||||
@Builder.Default
|
@lombok.Builder.Default
|
||||||
boolean paused = false;
|
boolean paused = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ import com.volmit.iris.Iris;
|
|||||||
import com.volmit.iris.core.pregenerator.PregenListener;
|
import com.volmit.iris.core.pregenerator.PregenListener;
|
||||||
import com.volmit.iris.core.pregenerator.PregeneratorMethod;
|
import com.volmit.iris.core.pregenerator.PregeneratorMethod;
|
||||||
import com.volmit.iris.core.tools.IrisToolbelt;
|
import com.volmit.iris.core.tools.IrisToolbelt;
|
||||||
import com.volmit.iris.util.collection.KList;
|
|
||||||
import com.volmit.iris.util.collection.KMap;
|
import com.volmit.iris.util.collection.KMap;
|
||||||
import com.volmit.iris.util.mantle.Mantle;
|
import com.volmit.iris.util.mantle.Mantle;
|
||||||
import com.volmit.iris.util.math.M;
|
import com.volmit.iris.util.math.M;
|
||||||
@@ -34,12 +33,12 @@ import org.bukkit.World;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Semaphore;
|
||||||
|
|
||||||
public class AsyncPregenMethod implements PregeneratorMethod {
|
public class AsyncPregenMethod implements PregeneratorMethod {
|
||||||
private final World world;
|
private final World world;
|
||||||
private final MultiBurst burst;
|
private final MultiBurst burst;
|
||||||
private final KList<Future<?>> future;
|
private final Semaphore semaphore;
|
||||||
private final Map<Chunk, Long> lastUse;
|
private final Map<Chunk, Long> lastUse;
|
||||||
|
|
||||||
public AsyncPregenMethod(World world, int threads) {
|
public AsyncPregenMethod(World world, int threads) {
|
||||||
@@ -49,7 +48,7 @@ public class AsyncPregenMethod implements PregeneratorMethod {
|
|||||||
|
|
||||||
this.world = world;
|
this.world = world;
|
||||||
burst = new MultiBurst("Iris Async Pregen", Thread.MIN_PRIORITY);
|
burst = new MultiBurst("Iris Async Pregen", Thread.MIN_PRIORITY);
|
||||||
future = new KList<>(256);
|
semaphore = new Semaphore(256);
|
||||||
this.lastUse = new KMap<>();
|
this.lastUse = new KMap<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,7 +62,7 @@ public class AsyncPregenMethod implements PregeneratorMethod {
|
|||||||
|
|
||||||
for (Chunk i : new ArrayList<>(lastUse.keySet())) {
|
for (Chunk i : new ArrayList<>(lastUse.keySet())) {
|
||||||
Long lastUseTime = lastUse.get(i);
|
Long lastUseTime = lastUse.get(i);
|
||||||
if (lastUseTime != null && M.ms() - lastUseTime >= 10000) {
|
if (!i.isLoaded() || (lastUseTime != null && M.ms() - lastUseTime >= 10000)) {
|
||||||
i.unload();
|
i.unload();
|
||||||
lastUse.remove(i);
|
lastUse.remove(i);
|
||||||
}
|
}
|
||||||
@@ -85,37 +84,8 @@ public class AsyncPregenMethod implements PregeneratorMethod {
|
|||||||
} catch (InterruptedException ignored) {
|
} catch (InterruptedException ignored) {
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
} finally {
|
||||||
}
|
semaphore.release();
|
||||||
|
|
||||||
private void waitForChunksPartial(int maxWaiting) {
|
|
||||||
while (future.size() > maxWaiting) {
|
|
||||||
try {
|
|
||||||
Future<?> i = future.remove(0);
|
|
||||||
|
|
||||||
if (i == null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
i.get();
|
|
||||||
} catch (Throwable e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void waitForChunks() {
|
|
||||||
for (Future<?> i : future.copy()) {
|
|
||||||
if (i == null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
i.get();
|
|
||||||
future.remove(i);
|
|
||||||
} catch (Throwable e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -131,14 +101,13 @@ public class AsyncPregenMethod implements PregeneratorMethod {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() {
|
public void close() {
|
||||||
waitForChunks();
|
semaphore.acquireUninterruptibly(256);
|
||||||
unloadAndSaveAllChunks();
|
unloadAndSaveAllChunks();
|
||||||
burst.close();
|
burst.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void save() {
|
public void save() {
|
||||||
waitForChunksPartial(256);
|
|
||||||
unloadAndSaveAllChunks();
|
unloadAndSaveAllChunks();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -155,10 +124,12 @@ public class AsyncPregenMethod implements PregeneratorMethod {
|
|||||||
@Override
|
@Override
|
||||||
public void generateChunk(int x, int z, PregenListener listener) {
|
public void generateChunk(int x, int z, PregenListener listener) {
|
||||||
listener.onChunkGenerating(x, z);
|
listener.onChunkGenerating(x, z);
|
||||||
if (future.size() > 256) {
|
try {
|
||||||
waitForChunksPartial(256);
|
semaphore.acquire();
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
future.add(burst.complete(() -> completeChunk(x, z, listener)));
|
burst.complete(() -> completeChunk(x, z, listener));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -22,21 +22,23 @@ import com.volmit.iris.Iris;
|
|||||||
import com.volmit.iris.core.loader.IrisData;
|
import com.volmit.iris.core.loader.IrisData;
|
||||||
import com.volmit.iris.core.loader.IrisRegistrant;
|
import com.volmit.iris.core.loader.IrisRegistrant;
|
||||||
import com.volmit.iris.core.loader.ResourceLoader;
|
import com.volmit.iris.core.loader.ResourceLoader;
|
||||||
import com.volmit.iris.engine.framework.ListFunction;
|
|
||||||
import com.volmit.iris.engine.object.annotations.*;
|
import com.volmit.iris.engine.object.annotations.*;
|
||||||
import com.volmit.iris.util.collection.KList;
|
import com.volmit.iris.util.collection.KList;
|
||||||
import com.volmit.iris.util.collection.KMap;
|
import com.volmit.iris.util.collection.KMap;
|
||||||
import com.volmit.iris.util.data.B;
|
import com.volmit.iris.util.data.B;
|
||||||
import com.volmit.iris.util.json.JSONArray;
|
import com.volmit.iris.util.json.JSONArray;
|
||||||
import com.volmit.iris.util.json.JSONObject;
|
import com.volmit.iris.util.json.JSONObject;
|
||||||
|
import com.volmit.iris.util.reflect.OldEnum;
|
||||||
import org.bukkit.enchantments.Enchantment;
|
import org.bukkit.enchantments.Enchantment;
|
||||||
import org.bukkit.potion.PotionEffectType;
|
import org.bukkit.potion.PotionEffectType;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.function.Function;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class SchemaBuilder {
|
public class SchemaBuilder {
|
||||||
@@ -44,7 +46,6 @@ public class SchemaBuilder {
|
|||||||
private static final String SYMBOL_TYPE__N = "";
|
private static final String SYMBOL_TYPE__N = "";
|
||||||
private static final JSONArray POTION_TYPES = getPotionTypes();
|
private static final JSONArray POTION_TYPES = getPotionTypes();
|
||||||
private static final JSONArray ENCHANT_TYPES = getEnchantTypes();
|
private static final JSONArray ENCHANT_TYPES = getEnchantTypes();
|
||||||
private static final JSONArray ITEM_TYPES = new JSONArray(B.getItemTypes());
|
|
||||||
private static final JSONArray FONT_TYPES = new JSONArray(GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames());
|
private static final JSONArray FONT_TYPES = new JSONArray(GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames());
|
||||||
private final KMap<String, JSONObject> definitions;
|
private final KMap<String, JSONObject> definitions;
|
||||||
private final Class<?> root;
|
private final Class<?> root;
|
||||||
@@ -262,7 +263,7 @@ public class SchemaBuilder {
|
|||||||
|
|
||||||
if (!definitions.containsKey(key)) {
|
if (!definitions.containsKey(key)) {
|
||||||
JSONObject j = new JSONObject();
|
JSONObject j = new JSONObject();
|
||||||
j.put("enum", ITEM_TYPES);
|
j.put("enum", B.getItemTypes());
|
||||||
definitions.put(key, j);
|
definitions.put(key, j);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -342,38 +343,9 @@ public class SchemaBuilder {
|
|||||||
description.add(SYMBOL_TYPE__N + " Must be a valid Potion Effect Type (use ctrl+space for auto complete!)");
|
description.add(SYMBOL_TYPE__N + " Must be a valid Potion Effect Type (use ctrl+space for auto complete!)");
|
||||||
|
|
||||||
} else if (k.getType().isEnum()) {
|
} else if (k.getType().isEnum()) {
|
||||||
fancyType = k.getType().getSimpleName().replaceAll("\\QIris\\E", "");
|
fancyType = addEnum(k.getType(), prop, description, k.getType().getEnumConstants(), o -> ((Enum<?>) o).name());
|
||||||
JSONArray a = new JSONArray();
|
} else if (OldEnum.isOldEnum(k.getType())) {
|
||||||
boolean advanced = k.getType().isAnnotationPresent(Desc.class);
|
fancyType = addEnum(k.getType(), prop, description, OldEnum.values(k.getType()), OldEnum::name);
|
||||||
for (Object gg : k.getType().getEnumConstants()) {
|
|
||||||
if (advanced) {
|
|
||||||
try {
|
|
||||||
JSONObject j = new JSONObject();
|
|
||||||
String name = ((Enum<?>) gg).name();
|
|
||||||
j.put("const", name);
|
|
||||||
Desc dd = k.getType().getField(name).getAnnotation(Desc.class);
|
|
||||||
j.put("description", dd == null ? ("No Description for " + name) : dd.value());
|
|
||||||
a.put(j);
|
|
||||||
} catch (Throwable e) {
|
|
||||||
Iris.reportError(e);
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
a.put(((Enum<?>) gg).name());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
String key = (advanced ? "oneof-" : "") + "enum-" + k.getType().getCanonicalName().replaceAll("\\Q.\\E", "-").toLowerCase();
|
|
||||||
|
|
||||||
if (!definitions.containsKey(key)) {
|
|
||||||
JSONObject j = new JSONObject();
|
|
||||||
j.put(advanced ? "oneOf" : "enum", a);
|
|
||||||
definitions.put(key, j);
|
|
||||||
}
|
|
||||||
|
|
||||||
prop.put("$ref", "#/definitions/" + key);
|
|
||||||
description.add(SYMBOL_TYPE__N + " Must be a valid " + k.getType().getSimpleName().replaceAll("\\QIris\\E", "") + " (use ctrl+space for auto complete!)");
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case "object" -> {
|
case "object" -> {
|
||||||
@@ -468,7 +440,7 @@ public class SchemaBuilder {
|
|||||||
|
|
||||||
if (!definitions.containsKey(key)) {
|
if (!definitions.containsKey(key)) {
|
||||||
JSONObject j = new JSONObject();
|
JSONObject j = new JSONObject();
|
||||||
j.put("enum", ITEM_TYPES);
|
j.put("enum", B.getItemTypes());
|
||||||
definitions.put(key, j);
|
definitions.put(key, j);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -519,39 +491,9 @@ public class SchemaBuilder {
|
|||||||
prop.put("items", items);
|
prop.put("items", items);
|
||||||
description.add(SYMBOL_TYPE__N + " Must be a valid Potion Effect Type (use ctrl+space for auto complete!)");
|
description.add(SYMBOL_TYPE__N + " Must be a valid Potion Effect Type (use ctrl+space for auto complete!)");
|
||||||
} else if (t.type().isEnum()) {
|
} else if (t.type().isEnum()) {
|
||||||
fancyType = "List of " + t.type().getSimpleName().replaceAll("\\QIris\\E", "") + "s";
|
fancyType = addEnumList(prop, description, t, t.type().getEnumConstants(), o -> ((Enum<?>) o).name());
|
||||||
JSONArray a = new JSONArray();
|
} else if (OldEnum.isOldEnum(t.type())) {
|
||||||
boolean advanced = t.type().isAnnotationPresent(Desc.class);
|
fancyType = addEnumList(prop, description, t, OldEnum.values(t.type()), OldEnum::name);
|
||||||
for (Object gg : t.type().getEnumConstants()) {
|
|
||||||
if (advanced) {
|
|
||||||
try {
|
|
||||||
JSONObject j = new JSONObject();
|
|
||||||
String name = ((Enum<?>) gg).name();
|
|
||||||
j.put("const", name);
|
|
||||||
Desc dd = t.type().getField(name).getAnnotation(Desc.class);
|
|
||||||
j.put("description", dd == null ? ("No Description for " + name) : dd.value());
|
|
||||||
a.put(j);
|
|
||||||
} catch (Throwable e) {
|
|
||||||
Iris.reportError(e);
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
a.put(((Enum<?>) gg).name());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
String key = (advanced ? "oneof-" : "") + "enum-" + t.type().getCanonicalName().replaceAll("\\Q.\\E", "-").toLowerCase();
|
|
||||||
|
|
||||||
if (!definitions.containsKey(key)) {
|
|
||||||
JSONObject j = new JSONObject();
|
|
||||||
j.put(advanced ? "oneOf" : "enum", a);
|
|
||||||
definitions.put(key, j);
|
|
||||||
}
|
|
||||||
|
|
||||||
JSONObject items = new JSONObject();
|
|
||||||
items.put("$ref", "#/definitions/" + key);
|
|
||||||
prop.put("items", items);
|
|
||||||
description.add(SYMBOL_TYPE__N + " Must be a valid " + t.type().getSimpleName().replaceAll("\\QIris\\E", "") + " (use ctrl+space for auto complete!)");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -584,7 +526,7 @@ public class SchemaBuilder {
|
|||||||
if (value instanceof List) {
|
if (value instanceof List) {
|
||||||
d.add(" ");
|
d.add(" ");
|
||||||
d.add("* Default Value is an empty list");
|
d.add("* Default Value is an empty list");
|
||||||
} else if (!cl.isPrimitive() && !(value instanceof Number) && !(value instanceof String) && !(cl.isEnum())) {
|
} else if (!cl.isPrimitive() && !(value instanceof Number) && !(value instanceof String) && !(cl.isEnum()) && !OldEnum.isOldEnum(cl)) {
|
||||||
d.add(" ");
|
d.add(" ");
|
||||||
d.add("* Default Value is a default object (create this object to see default properties)");
|
d.add("* Default Value is a default object (create this object to see default properties)");
|
||||||
} else {
|
} else {
|
||||||
@@ -630,6 +572,50 @@ public class SchemaBuilder {
|
|||||||
return prop;
|
return prop;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private String addEnumList(JSONObject prop, KList<String> description, ArrayType t, Object[] values, Function<Object, String> function) {
|
||||||
|
JSONObject items = new JSONObject();
|
||||||
|
var s = addEnum(t.type(), items, description, values, function);
|
||||||
|
prop.put("items", items);
|
||||||
|
|
||||||
|
return "List of " + s + "s";
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private String addEnum(Class<?> type, JSONObject prop, KList<String> description, Object[] values, Function<Object, String> function) {
|
||||||
|
JSONArray a = new JSONArray();
|
||||||
|
boolean advanced = type.isAnnotationPresent(Desc.class);
|
||||||
|
for (Object gg : values) {
|
||||||
|
if (advanced) {
|
||||||
|
try {
|
||||||
|
JSONObject j = new JSONObject();
|
||||||
|
String name = function.apply(gg);
|
||||||
|
j.put("const", name);
|
||||||
|
Desc dd = type.getField(name).getAnnotation(Desc.class);
|
||||||
|
j.put("description", dd == null ? ("No Description for " + name) : dd.value());
|
||||||
|
a.put(j);
|
||||||
|
} catch (Throwable e) {
|
||||||
|
Iris.reportError(e);
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
a.put(function.apply(gg));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
String key = (advanced ? "oneof-" : "") + "enum-" + type.getCanonicalName().replaceAll("\\Q.\\E", "-").toLowerCase();
|
||||||
|
|
||||||
|
if (!definitions.containsKey(key)) {
|
||||||
|
JSONObject j = new JSONObject();
|
||||||
|
j.put(advanced ? "oneOf" : "enum", a);
|
||||||
|
definitions.put(key, j);
|
||||||
|
}
|
||||||
|
|
||||||
|
prop.put("$ref", "#/definitions/" + key);
|
||||||
|
description.add(SYMBOL_TYPE__N + " Must be a valid " + type.getSimpleName().replaceAll("\\QIris\\E", "") + " (use ctrl+space for auto complete!)");
|
||||||
|
return type.getSimpleName().replaceAll("\\QIris\\E", "");
|
||||||
|
}
|
||||||
|
|
||||||
private String getType(Class<?> c) {
|
private String getType(Class<?> c) {
|
||||||
if (c.equals(int.class) || c.equals(Integer.class) || c.equals(long.class) || c.equals(Long.class)) {
|
if (c.equals(int.class) || c.equals(Integer.class) || c.equals(long.class) || c.equals(Long.class)) {
|
||||||
return "integer";
|
return "integer";
|
||||||
@@ -643,7 +629,7 @@ public class SchemaBuilder {
|
|||||||
return "boolean";
|
return "boolean";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (c.equals(String.class) || c.isEnum() || c.equals(Enchantment.class) || c.equals(PotionEffectType.class)) {
|
if (c.equals(String.class) || c.isEnum() || OldEnum.isOldEnum(c) || c.equals(Enchantment.class) || c.equals(PotionEffectType.class)) {
|
||||||
return "string";
|
return "string";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,12 +20,11 @@ import java.util.Map;
|
|||||||
import java.util.StringJoiner;
|
import java.util.StringJoiner;
|
||||||
|
|
||||||
import static com.volmit.iris.Iris.getJavaVersion;
|
import static com.volmit.iris.Iris.getJavaVersion;
|
||||||
import static com.volmit.iris.Iris.instance;
|
|
||||||
import static com.volmit.iris.core.safeguard.IrisSafeguard.*;
|
import static com.volmit.iris.core.safeguard.IrisSafeguard.*;
|
||||||
|
|
||||||
public class ServerBootSFG {
|
public class ServerBootSFG {
|
||||||
public static final Map<String, Boolean> incompatibilities = new HashMap<>();
|
public static final Map<String, Boolean> incompatibilities = new HashMap<>();
|
||||||
public static boolean isJDK17 = true;
|
public static boolean isCorrectJDK = true;
|
||||||
public static boolean hasEnoughDiskSpace = true;
|
public static boolean hasEnoughDiskSpace = true;
|
||||||
public static boolean isJRE = false;
|
public static boolean isJRE = false;
|
||||||
public static boolean hasPrivileges = true;
|
public static boolean hasPrivileges = true;
|
||||||
@@ -87,8 +86,8 @@ public class ServerBootSFG {
|
|||||||
severityHigh++;
|
severityHigh++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!List.of(17, 21).contains(getJavaVersion())) {
|
if (!List.of(21).contains(getJavaVersion())) {
|
||||||
isJDK17 = false;
|
isCorrectJDK = false;
|
||||||
joiner.add("Unsupported Java version");
|
joiner.add("Unsupported Java version");
|
||||||
severityMedium++;
|
severityMedium++;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ public class UtilsSFG {
|
|||||||
}
|
}
|
||||||
if (ServerBootSFG.unsuportedversion) {
|
if (ServerBootSFG.unsuportedversion) {
|
||||||
Iris.safeguard(C.RED + "Server Version");
|
Iris.safeguard(C.RED + "Server Version");
|
||||||
Iris.safeguard(C.RED + "- Iris only supports 1.19.2 > 1.21.1");
|
Iris.safeguard(C.RED + "- Iris only supports 1.19.2 > 1.21.3");
|
||||||
}
|
}
|
||||||
if (!ServerBootSFG.passedserversoftware) {
|
if (!ServerBootSFG.passedserversoftware) {
|
||||||
Iris.safeguard(C.YELLOW + "Unsupported Server Software");
|
Iris.safeguard(C.YELLOW + "Unsupported Server Software");
|
||||||
@@ -51,13 +51,13 @@ public class UtilsSFG {
|
|||||||
Iris.safeguard(C.YELLOW + "Insufficient Disk Space");
|
Iris.safeguard(C.YELLOW + "Insufficient Disk Space");
|
||||||
Iris.safeguard(C.YELLOW + "- The server has insufficient Free DiskSpace to run iris required 3GB+.");
|
Iris.safeguard(C.YELLOW + "- The server has insufficient Free DiskSpace to run iris required 3GB+.");
|
||||||
}
|
}
|
||||||
if (!ServerBootSFG.isJDK17) {
|
if (!ServerBootSFG.isCorrectJDK) {
|
||||||
Iris.safeguard(C.YELLOW + "Unsupported java version");
|
Iris.safeguard(C.YELLOW + "Unsupported java version");
|
||||||
Iris.safeguard(C.YELLOW + "- Please consider using JDK 17 (or 21 for 1.20.6) Instead of JDK " + Iris.getJavaVersion());
|
Iris.safeguard(C.YELLOW + "- Please consider using JDK 21 Instead of JDK " + Iris.getJavaVersion());
|
||||||
}
|
}
|
||||||
if (ServerBootSFG.isJRE) {
|
if (ServerBootSFG.isJRE) {
|
||||||
Iris.safeguard(C.YELLOW + "Unsupported Server JDK");
|
Iris.safeguard(C.YELLOW + "Unsupported Server JDK");
|
||||||
Iris.safeguard(C.YELLOW + "- Please consider using JDK 17 (or 21 for 1.20.6) Instead of JRE " + Iris.getJavaVersion());
|
Iris.safeguard(C.YELLOW + "- Please consider using JDK 21 Instead of JRE " + Iris.getJavaVersion());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ import org.bukkit.event.player.PlayerChangedWorldEvent;
|
|||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.CopyOnWriteArrayList;
|
||||||
|
|
||||||
public class BoardSVC implements IrisService, BoardProvider {
|
public class BoardSVC implements IrisService, BoardProvider {
|
||||||
private final KMap<Player, PlayerBoard> boards = new KMap<>();
|
private final KMap<Player, PlayerBoard> boards = new KMap<>();
|
||||||
@@ -104,11 +105,11 @@ public class BoardSVC implements IrisService, BoardProvider {
|
|||||||
@Data
|
@Data
|
||||||
public static class PlayerBoard {
|
public static class PlayerBoard {
|
||||||
private final Player player;
|
private final Player player;
|
||||||
private final KList<String> lines;
|
private final CopyOnWriteArrayList<String> lines;
|
||||||
|
|
||||||
public PlayerBoard(Player player) {
|
public PlayerBoard(Player player) {
|
||||||
this.player = player;
|
this.player = player;
|
||||||
this.lines = new KList<>();
|
this.lines = new CopyOnWriteArrayList<>();
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import com.volmit.iris.util.collection.KList;
|
|||||||
import com.volmit.iris.util.collection.KMap;
|
import com.volmit.iris.util.collection.KMap;
|
||||||
import com.volmit.iris.util.plugin.IrisService;
|
import com.volmit.iris.util.plugin.IrisService;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import lombok.NonNull;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.data.BlockData;
|
import org.bukkit.block.data.BlockData;
|
||||||
@@ -46,9 +47,13 @@ public class ExternalDataSVC implements IrisService {
|
|||||||
Iris.info("Loading ExternalDataProvider...");
|
Iris.info("Loading ExternalDataProvider...");
|
||||||
Bukkit.getPluginManager().registerEvents(this, Iris.instance);
|
Bukkit.getPluginManager().registerEvents(this, Iris.instance);
|
||||||
|
|
||||||
providers.add(new OraxenDataProvider());
|
providers.add(new NexoDataProvider());
|
||||||
if (Bukkit.getPluginManager().getPlugin("Oraxen") != null) {
|
if (Bukkit.getPluginManager().getPlugin("Nexo") != null) {
|
||||||
Iris.info("Oraxen found, loading OraxenDataProvider...");
|
Iris.info("Nexo found, loading NexoDataProvider...");
|
||||||
|
}
|
||||||
|
providers.add(new MythicCrucibleDataProvider());
|
||||||
|
if (Bukkit.getPluginManager().getPlugin("MythicCrucible") != null) {
|
||||||
|
Iris.info("MythicCrucible found, loading MythicCrucibleDataProvider...");
|
||||||
}
|
}
|
||||||
providers.add(new ItemAdderDataProvider());
|
providers.add(new ItemAdderDataProvider());
|
||||||
if (Bukkit.getPluginManager().getPlugin("ItemAdder") != null) {
|
if (Bukkit.getPluginManager().getPlugin("ItemAdder") != null) {
|
||||||
@@ -95,6 +100,18 @@ public class ExternalDataSVC implements IrisService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void registerProvider(@NonNull ExternalDataProvider provider) {
|
||||||
|
String plugin = provider.getPluginId();
|
||||||
|
if (providers.stream().map(ExternalDataProvider::getPluginId).anyMatch(plugin::equals))
|
||||||
|
throw new IllegalArgumentException("A provider with the same plugin id already exists.");
|
||||||
|
|
||||||
|
providers.add(provider);
|
||||||
|
if (provider.isReady()) {
|
||||||
|
activeProviders.add(provider);
|
||||||
|
provider.init();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public Optional<BlockData> getBlockData(final Identifier key) {
|
public Optional<BlockData> getBlockData(final Identifier key) {
|
||||||
var pair = parseState(key);
|
var pair = parseState(key);
|
||||||
Identifier mod = pair.getA();
|
Identifier mod = pair.getA();
|
||||||
|
|||||||
@@ -63,8 +63,13 @@ public class StudioSVC implements IrisService {
|
|||||||
|
|
||||||
if (!f.exists()) {
|
if (!f.exists()) {
|
||||||
Iris.info("Downloading Default Pack " + pack);
|
Iris.info("Downloading Default Pack " + pack);
|
||||||
|
if (pack.equals("overworld")) {
|
||||||
|
String url = "https://github.com/IrisDimensions/overworld/releases/download/" + Iris.OVERWORLD_TAG + "/overworld.zip";
|
||||||
|
Iris.service(StudioSVC.class).downloadRelease(Iris.getSender(), url, false, false);
|
||||||
|
} else {
|
||||||
downloadSearch(Iris.getSender(), pack, false);
|
downloadSearch(Iris.getSender(), pack, false);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ public class WandSVC implements IrisService {
|
|||||||
* @param p The wand player
|
* @param p The wand player
|
||||||
* @return The new object
|
* @return The new object
|
||||||
*/
|
*/
|
||||||
public static IrisObject createSchematic(Player p) {
|
public static IrisObject createSchematic(Player p, boolean legacy) {
|
||||||
if (!isHoldingWand(p)) {
|
if (!isHoldingWand(p)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -132,7 +132,7 @@ public class WandSVC implements IrisService {
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
BlockVector bv = b.getLocation().subtract(c.getLowerNE().toVector()).toVector().toBlockVector();
|
BlockVector bv = b.getLocation().subtract(c.getLowerNE().toVector()).toVector().toBlockVector();
|
||||||
s.setUnsigned(bv.getBlockX(), bv.getBlockY(), bv.getBlockZ(), b);
|
s.setUnsigned(bv.getBlockX(), bv.getBlockY(), bv.getBlockZ(), b, legacy);
|
||||||
} finally {
|
} finally {
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,10 +24,8 @@ import com.volmit.iris.core.IrisSettings;
|
|||||||
import com.volmit.iris.core.ServerConfigurator;
|
import com.volmit.iris.core.ServerConfigurator;
|
||||||
import com.volmit.iris.core.pregenerator.PregenTask;
|
import com.volmit.iris.core.pregenerator.PregenTask;
|
||||||
import com.volmit.iris.core.service.StudioSVC;
|
import com.volmit.iris.core.service.StudioSVC;
|
||||||
import com.volmit.iris.engine.framework.Engine;
|
|
||||||
import com.volmit.iris.engine.object.IrisDimension;
|
import com.volmit.iris.engine.object.IrisDimension;
|
||||||
import com.volmit.iris.engine.platform.PlatformChunkGenerator;
|
import com.volmit.iris.engine.platform.PlatformChunkGenerator;
|
||||||
import com.volmit.iris.core.safeguard.UtilsSFG;
|
|
||||||
import com.volmit.iris.util.exceptions.IrisException;
|
import com.volmit.iris.util.exceptions.IrisException;
|
||||||
import com.volmit.iris.util.format.C;
|
import com.volmit.iris.util.format.C;
|
||||||
import com.volmit.iris.util.format.Form;
|
import com.volmit.iris.util.format.Form;
|
||||||
@@ -46,7 +44,6 @@ import java.util.concurrent.CompletableFuture;
|
|||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
import static com.volmit.iris.core.safeguard.IrisSafeguard.unstablemode;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Makes it a lot easier to setup an engine, world, studio or whatever
|
* Makes it a lot easier to setup an engine, world, studio or whatever
|
||||||
@@ -126,14 +123,11 @@ public class IrisCreator {
|
|||||||
if (sender == null)
|
if (sender == null)
|
||||||
sender = Iris.getSender();
|
sender = Iris.getSender();
|
||||||
|
|
||||||
if (!studio()) {
|
if (!studio() || benchmark) {
|
||||||
Iris.service(StudioSVC.class).installIntoWorld(sender, d.getLoadKey(), new File(Bukkit.getWorldContainer(), name()));
|
|
||||||
}
|
|
||||||
if (benchmark) {
|
|
||||||
Iris.service(StudioSVC.class).installIntoWorld(sender, d.getLoadKey(), new File(Bukkit.getWorldContainer(), name()));
|
Iris.service(StudioSVC.class).installIntoWorld(sender, d.getLoadKey(), new File(Bukkit.getWorldContainer(), name()));
|
||||||
}
|
}
|
||||||
|
|
||||||
PlatformChunkGenerator access = null;
|
PlatformChunkGenerator access;
|
||||||
AtomicReference<World> world = new AtomicReference<>();
|
AtomicReference<World> world = new AtomicReference<>();
|
||||||
AtomicDouble pp = new AtomicDouble(0);
|
AtomicDouble pp = new AtomicDouble(0);
|
||||||
O<Boolean> done = new O<>();
|
O<Boolean> done = new O<>();
|
||||||
|
|||||||
@@ -9,8 +9,6 @@ import com.volmit.iris.util.collection.KList;
|
|||||||
import com.volmit.iris.util.collection.KMap;
|
import com.volmit.iris.util.collection.KMap;
|
||||||
import com.volmit.iris.util.exceptions.IrisException;
|
import com.volmit.iris.util.exceptions.IrisException;
|
||||||
import com.volmit.iris.util.format.Form;
|
import com.volmit.iris.util.format.Form;
|
||||||
import com.volmit.iris.util.math.Position2;
|
|
||||||
|
|
||||||
import com.volmit.iris.util.scheduling.J;
|
import com.volmit.iris.util.scheduling.J;
|
||||||
import com.volmit.iris.util.scheduling.PrecisionStopwatch;
|
import com.volmit.iris.util.scheduling.PrecisionStopwatch;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
@@ -27,29 +25,29 @@ import java.nio.file.attribute.BasicFileAttributes;
|
|||||||
import java.time.Clock;
|
import java.time.Clock;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.concurrent.*;
|
|
||||||
|
|
||||||
|
|
||||||
public class IrisPackBenchmarking {
|
public class IrisPackBenchmarking {
|
||||||
@Getter
|
@Getter
|
||||||
public static IrisPackBenchmarking instance;
|
public static IrisPackBenchmarking instance;
|
||||||
public static boolean benchmarkInProgress = false;
|
public static boolean benchmarkInProgress = false;
|
||||||
private IrisDimension IrisDimension;
|
private final PrecisionStopwatch stopwatch = new PrecisionStopwatch();
|
||||||
private int radius;
|
private final IrisDimension dimension;
|
||||||
private boolean finished = false;
|
private final int radius;
|
||||||
PrecisionStopwatch stopwatch;
|
private final boolean gui;
|
||||||
|
|
||||||
public IrisPackBenchmarking(IrisDimension dimension, int r) {
|
public IrisPackBenchmarking(IrisDimension dimension, int radius, boolean gui) {
|
||||||
instance = this;
|
instance = this;
|
||||||
this.IrisDimension = dimension;
|
this.dimension = dimension;
|
||||||
this.radius = r;
|
this.radius = radius;
|
||||||
|
this.gui = gui;
|
||||||
runBenchmark();
|
runBenchmark();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void runBenchmark() {
|
private void runBenchmark() {
|
||||||
this.stopwatch = new PrecisionStopwatch();
|
Thread.ofVirtual()
|
||||||
ExecutorService service = Executors.newSingleThreadExecutor();
|
.name("PackBenchmarking")
|
||||||
service.submit(() -> {
|
.start(() -> {
|
||||||
Iris.info("Setting up benchmark environment ");
|
Iris.info("Setting up benchmark environment ");
|
||||||
benchmarkInProgress = true;
|
benchmarkInProgress = true;
|
||||||
File file = new File("benchmark");
|
File file = new File("benchmark");
|
||||||
@@ -88,13 +86,13 @@ public class IrisPackBenchmarking {
|
|||||||
File profilers = new File("plugins" + File.separator + "Iris" + File.separator + "packbenchmarks");
|
File profilers = new File("plugins" + File.separator + "Iris" + File.separator + "packbenchmarks");
|
||||||
profilers.mkdir();
|
profilers.mkdir();
|
||||||
|
|
||||||
File results = new File("plugins " + File.separator + "Iris", IrisDimension.getName() + LocalDateTime.now(Clock.systemDefaultZone()) + ".txt");
|
File results = new File(profilers, dimension.getName() + " " + LocalDateTime.now(Clock.systemDefaultZone()).toString().replace(':', '-') + ".txt");
|
||||||
results.createNewFile();
|
results.getParentFile().mkdirs();
|
||||||
KMap<String, Double> metrics = engine.getMetrics().pull();
|
KMap<String, Double> metrics = engine.getMetrics().pull();
|
||||||
try (FileWriter writer = new FileWriter(results)) {
|
try (FileWriter writer = new FileWriter(results)) {
|
||||||
writer.write("-----------------\n");
|
writer.write("-----------------\n");
|
||||||
writer.write("Results:\n");
|
writer.write("Results:\n");
|
||||||
writer.write("Dimension: " + IrisDimension.getName() + "\n");
|
writer.write("Dimension: " + dimension.getName() + "\n");
|
||||||
writer.write("- Date of Benchmark: " + LocalDateTime.now(Clock.systemDefaultZone()) + "\n");
|
writer.write("- Date of Benchmark: " + LocalDateTime.now(Clock.systemDefaultZone()) + "\n");
|
||||||
writer.write("\n");
|
writer.write("\n");
|
||||||
writer.write("Metrics");
|
writer.write("Metrics");
|
||||||
@@ -116,17 +114,24 @@ public class IrisPackBenchmarking {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
Bukkit.getServer().unloadWorld("benchmark", true);
|
J.s(() -> {
|
||||||
|
var world = Bukkit.getWorld("benchmark");
|
||||||
|
if (world == null) return;
|
||||||
|
IrisToolbelt.evacuate(world);
|
||||||
|
Bukkit.unloadWorld(world, true);
|
||||||
|
});
|
||||||
|
|
||||||
stopwatch.end();
|
stopwatch.end();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Iris.error("Something has gone wrong!");
|
Iris.error("Something has gone wrong!");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private void createBenchmark(){
|
|
||||||
|
private void createBenchmark() {
|
||||||
try {
|
try {
|
||||||
IrisToolbelt.createWorld()
|
IrisToolbelt.createWorld()
|
||||||
.dimension(IrisDimension.getName())
|
.dimension(dimension.getLoadKey())
|
||||||
.name("benchmark")
|
.name("benchmark")
|
||||||
.seed(1337)
|
.seed(1337)
|
||||||
.studio(false)
|
.studio(false)
|
||||||
@@ -137,15 +142,12 @@ public class IrisPackBenchmarking {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void startBenchmark(){
|
private void startBenchmark() {
|
||||||
int x = 0;
|
|
||||||
int z = 0;
|
|
||||||
IrisToolbelt.pregenerate(PregenTask
|
IrisToolbelt.pregenerate(PregenTask
|
||||||
.builder()
|
.builder()
|
||||||
.gui(false)
|
.gui(gui)
|
||||||
.center(new Position2(x, z))
|
.width(radius)
|
||||||
.width(5)
|
.height(radius)
|
||||||
.height(5)
|
|
||||||
.build(), Bukkit.getWorld("benchmark")
|
.build(), Bukkit.getWorld("benchmark")
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -179,7 +181,7 @@ public class IrisPackBenchmarking {
|
|||||||
|
|
||||||
private boolean deleteDirectory(Path dir) {
|
private boolean deleteDirectory(Path dir) {
|
||||||
try {
|
try {
|
||||||
Files.walkFileTree(dir, new SimpleFileVisitor<Path>() {
|
Files.walkFileTree(dir, new SimpleFileVisitor<>() {
|
||||||
@Override
|
@Override
|
||||||
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
|
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
|
||||||
Files.delete(file);
|
Files.delete(file);
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ import com.volmit.iris.util.collection.KMap;
|
|||||||
import com.volmit.iris.util.collection.KSet;
|
import com.volmit.iris.util.collection.KSet;
|
||||||
import com.volmit.iris.util.context.IrisContext;
|
import com.volmit.iris.util.context.IrisContext;
|
||||||
import com.volmit.iris.util.data.DataProvider;
|
import com.volmit.iris.util.data.DataProvider;
|
||||||
|
import com.volmit.iris.util.interpolation.IrisInterpolation.NoiseKey;
|
||||||
import com.volmit.iris.util.math.M;
|
import com.volmit.iris.util.math.M;
|
||||||
import com.volmit.iris.util.math.RNG;
|
import com.volmit.iris.util.math.RNG;
|
||||||
import com.volmit.iris.util.noise.CNG;
|
import com.volmit.iris.util.noise.CNG;
|
||||||
@@ -292,9 +293,11 @@ public class IrisComplex implements DataProvider {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
KMap<NoiseKey, IrisBiome> cache = new KMap<>();
|
||||||
double hi = interpolator.interpolate(x, z, (xx, zz) -> {
|
double hi = interpolator.interpolate(x, z, (xx, zz) -> {
|
||||||
try {
|
try {
|
||||||
IrisBiome bx = baseBiomeStream.get(xx, zz);
|
IrisBiome bx = baseBiomeStream.get(xx, zz);
|
||||||
|
cache.put(new NoiseKey(xx, zz), bx);
|
||||||
double b = 0;
|
double b = 0;
|
||||||
|
|
||||||
for (IrisGenerator gen : generators) {
|
for (IrisGenerator gen : generators) {
|
||||||
@@ -313,7 +316,11 @@ public class IrisComplex implements DataProvider {
|
|||||||
|
|
||||||
double lo = interpolator.interpolate(x, z, (xx, zz) -> {
|
double lo = interpolator.interpolate(x, z, (xx, zz) -> {
|
||||||
try {
|
try {
|
||||||
IrisBiome bx = baseBiomeStream.get(xx, zz);
|
IrisBiome bx = cache.get(new NoiseKey(xx, zz));
|
||||||
|
if (bx == null) {
|
||||||
|
bx = baseBiomeStream.get(xx, zz);
|
||||||
|
cache.put(new NoiseKey(xx, zz), bx);
|
||||||
|
}
|
||||||
double b = 0;
|
double b = 0;
|
||||||
|
|
||||||
for (IrisGenerator gen : generators) {
|
for (IrisGenerator gen : generators) {
|
||||||
|
|||||||
@@ -18,32 +18,21 @@
|
|||||||
|
|
||||||
package com.volmit.iris.engine;
|
package com.volmit.iris.engine;
|
||||||
|
|
||||||
import com.volmit.iris.Iris;
|
import com.volmit.iris.core.nms.container.Pair;
|
||||||
import com.volmit.iris.engine.data.cache.AtomicCache;
|
import com.volmit.iris.engine.data.cache.AtomicCache;
|
||||||
import com.volmit.iris.engine.framework.Engine;
|
import com.volmit.iris.engine.framework.Engine;
|
||||||
import com.volmit.iris.engine.mantle.EngineMantle;
|
import com.volmit.iris.engine.mantle.EngineMantle;
|
||||||
import com.volmit.iris.engine.mantle.MantleComponent;
|
import com.volmit.iris.engine.mantle.MantleComponent;
|
||||||
import com.volmit.iris.engine.mantle.components.MantleCarvingComponent;
|
import com.volmit.iris.engine.mantle.components.*;
|
||||||
import com.volmit.iris.engine.mantle.components.MantleFluidBodyComponent;
|
|
||||||
import com.volmit.iris.engine.mantle.components.MantleJigsawComponent;
|
|
||||||
import com.volmit.iris.engine.mantle.components.MantleObjectComponent;
|
|
||||||
import com.volmit.iris.engine.object.*;
|
|
||||||
import com.volmit.iris.util.collection.KList;
|
import com.volmit.iris.util.collection.KList;
|
||||||
import com.volmit.iris.util.collection.KMap;
|
import com.volmit.iris.util.collection.KMap;
|
||||||
import com.volmit.iris.util.collection.KSet;
|
import com.volmit.iris.util.collection.KSet;
|
||||||
import com.volmit.iris.util.format.C;
|
|
||||||
import com.volmit.iris.util.format.Form;
|
import com.volmit.iris.util.format.Form;
|
||||||
import com.volmit.iris.util.mantle.Mantle;
|
import com.volmit.iris.util.mantle.Mantle;
|
||||||
import com.volmit.iris.util.parallel.BurstExecutor;
|
import lombok.*;
|
||||||
import lombok.Data;
|
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
import lombok.ToString;
|
|
||||||
import org.bukkit.util.BlockVector;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.util.stream.Collectors;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@EqualsAndHashCode(exclude = "engine")
|
@EqualsAndHashCode(exclude = "engine")
|
||||||
@@ -51,8 +40,9 @@ import java.util.concurrent.atomic.AtomicInteger;
|
|||||||
public class IrisEngineMantle implements EngineMantle {
|
public class IrisEngineMantle implements EngineMantle {
|
||||||
private final Engine engine;
|
private final Engine engine;
|
||||||
private final Mantle mantle;
|
private final Mantle mantle;
|
||||||
private final KList<MantleComponent> components;
|
@Getter(AccessLevel.NONE)
|
||||||
private final int radius;
|
private final KMap<Integer, KList<MantleComponent>> components;
|
||||||
|
private final AtomicCache<KList<Pair<KList<MantleComponent>, Integer>>> componentsCache = new AtomicCache<>();
|
||||||
private final AtomicCache<Integer> radCache = new AtomicCache<>();
|
private final AtomicCache<Integer> radCache = new AtomicCache<>();
|
||||||
private final MantleObjectComponent object;
|
private final MantleObjectComponent object;
|
||||||
private final MantleJigsawComponent jigsaw;
|
private final MantleJigsawComponent jigsaw;
|
||||||
@@ -60,19 +50,59 @@ public class IrisEngineMantle implements EngineMantle {
|
|||||||
public IrisEngineMantle(Engine engine) {
|
public IrisEngineMantle(Engine engine) {
|
||||||
this.engine = engine;
|
this.engine = engine;
|
||||||
this.mantle = new Mantle(new File(engine.getWorld().worldFolder(), "mantle"), engine.getTarget().getHeight());
|
this.mantle = new Mantle(new File(engine.getWorld().worldFolder(), "mantle"), engine.getTarget().getHeight());
|
||||||
radius = radCache.aquire(this::computeParallaxSize);
|
components = new KMap<>();
|
||||||
components = new KList<>();
|
|
||||||
registerComponent(new MantleCarvingComponent(this));
|
registerComponent(new MantleCarvingComponent(this));
|
||||||
registerComponent(new MantleFluidBodyComponent(this));
|
registerComponent(new MantleFluidBodyComponent(this));
|
||||||
jigsaw = new MantleJigsawComponent(this);
|
jigsaw = new MantleJigsawComponent(this);
|
||||||
registerComponent(jigsaw);
|
registerComponent(jigsaw);
|
||||||
object = new MantleObjectComponent(this);
|
object = new MantleObjectComponent(this);
|
||||||
registerComponent(object);
|
registerComponent(object);
|
||||||
|
registerComponent(new MantleStaticComponent(this));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getRadius() {
|
||||||
|
if (components.isEmpty()) return 0;
|
||||||
|
return getComponents().getFirst().getB();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getRealRadius() {
|
||||||
|
if (components.isEmpty()) return 0;
|
||||||
|
return getComponents().getLast().getB();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public KList<Pair<KList<MantleComponent>, Integer>> getComponents() {
|
||||||
|
return componentsCache.aquire(() -> {
|
||||||
|
var list = components.keySet()
|
||||||
|
.stream()
|
||||||
|
.sorted()
|
||||||
|
.map(components::get)
|
||||||
|
.map(components -> {
|
||||||
|
int radius = components.stream()
|
||||||
|
.mapToInt(MantleComponent::getRadius)
|
||||||
|
.max()
|
||||||
|
.orElse(0);
|
||||||
|
return new Pair<>(components, radius);
|
||||||
|
})
|
||||||
|
.collect(Collectors.toCollection(KList::new));
|
||||||
|
|
||||||
|
|
||||||
|
int radius = 0;
|
||||||
|
for (var pair : list.reversed()) {
|
||||||
|
radius += pair.getB();
|
||||||
|
pair.setB(Math.ceilDiv(radius, 16));
|
||||||
|
}
|
||||||
|
|
||||||
|
return list;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void registerComponent(MantleComponent c) {
|
public void registerComponent(MantleComponent c) {
|
||||||
components.add(c);
|
components.computeIfAbsent(c.getPriority(), k -> new KList<>()).add(c);
|
||||||
|
componentsCache.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -84,243 +114,4 @@ public class IrisEngineMantle implements EngineMantle {
|
|||||||
public MantleObjectComponent getObjectComponent() {
|
public MantleObjectComponent getObjectComponent() {
|
||||||
return object;
|
return object;
|
||||||
}
|
}
|
||||||
|
|
||||||
private KList<IrisRegion> getAllRegions() {
|
|
||||||
KList<IrisRegion> r = new KList<>();
|
|
||||||
|
|
||||||
for (String i : getEngine().getDimension().getRegions()) {
|
|
||||||
r.add(getEngine().getData().getRegionLoader().load(i));
|
|
||||||
}
|
|
||||||
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
private KList<IrisBiome> getAllBiomes() {
|
|
||||||
KList<IrisBiome> r = new KList<>();
|
|
||||||
|
|
||||||
for (IrisRegion i : getAllRegions()) {
|
|
||||||
r.addAll(i.getAllBiomes(getEngine()));
|
|
||||||
}
|
|
||||||
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void warn(String ob, BlockVector bv) {
|
|
||||||
if (Math.max(bv.getBlockX(), bv.getBlockZ()) > 128) {
|
|
||||||
Iris.warn("Object " + ob + " has a large size (" + bv + ") and may increase memory usage!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void warnScaled(String ob, BlockVector bv, double ms) {
|
|
||||||
if (Math.max(bv.getBlockX(), bv.getBlockZ()) > 128) {
|
|
||||||
Iris.warn("Object " + ob + " has a large size (" + bv + ") and may increase memory usage! (Object scaled up to " + Form.pc(ms, 2) + ")");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private int computeParallaxSize() {
|
|
||||||
Iris.verbose("Calculating the Parallax Size in Parallel");
|
|
||||||
AtomicInteger xg = new AtomicInteger(0);
|
|
||||||
AtomicInteger zg = new AtomicInteger();
|
|
||||||
xg.set(0);
|
|
||||||
zg.set(0);
|
|
||||||
int jig = 0;
|
|
||||||
KSet<String> objects = new KSet<>();
|
|
||||||
KMap<IrisObjectScale, KList<String>> scalars = new KMap<>();
|
|
||||||
int x = xg.get();
|
|
||||||
int z = zg.get();
|
|
||||||
|
|
||||||
if (getEngine().getDimension().isUseMantle()) {
|
|
||||||
KList<IrisRegion> r = getAllRegions();
|
|
||||||
KList<IrisBiome> b = getAllBiomes();
|
|
||||||
|
|
||||||
for (IrisBiome i : b) {
|
|
||||||
for (IrisObjectPlacement j : i.getObjects()) {
|
|
||||||
if (j.getScale().canScaleBeyond()) {
|
|
||||||
scalars.put(j.getScale(), j.getPlace());
|
|
||||||
} else {
|
|
||||||
objects.addAll(j.getPlace());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (IrisJigsawStructurePlacement j : i.getJigsawStructures()) {
|
|
||||||
jig = Math.max(jig, getData().getJigsawStructureLoader().load(j.getStructure()).getMaxDimension());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (IrisRegion i : r) {
|
|
||||||
for (IrisObjectPlacement j : i.getObjects()) {
|
|
||||||
if (j.getScale().canScaleBeyond()) {
|
|
||||||
scalars.put(j.getScale(), j.getPlace());
|
|
||||||
} else {
|
|
||||||
objects.addAll(j.getPlace());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (IrisJigsawStructurePlacement j : i.getJigsawStructures()) {
|
|
||||||
jig = Math.max(jig, getData().getJigsawStructureLoader().load(j.getStructure()).getMaxDimension());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (IrisJigsawStructurePlacement j : getEngine().getDimension().getJigsawStructures()) {
|
|
||||||
jig = Math.max(jig, getData().getJigsawStructureLoader().load(j.getStructure()).getMaxDimension());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (getEngine().getDimension().getStronghold() != null) {
|
|
||||||
try {
|
|
||||||
jig = Math.max(jig, getData().getJigsawStructureLoader().load(getEngine().getDimension().getStronghold()).getMaxDimension());
|
|
||||||
} catch (Throwable e) {
|
|
||||||
Iris.reportError(e);
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Iris.verbose("Checking sizes for " + Form.f(objects.size()) + " referenced objects.");
|
|
||||||
BurstExecutor e = getEngine().getTarget().getBurster().burst(objects.size());
|
|
||||||
KMap<String, BlockVector> sizeCache = new KMap<>();
|
|
||||||
for (String i : objects) {
|
|
||||||
e.queue(() -> {
|
|
||||||
try {
|
|
||||||
BlockVector bv = sizeCache.computeIfAbsent(i, (k) -> {
|
|
||||||
try {
|
|
||||||
return IrisObject.sampleSize(getData().getObjectLoader().findFile(i));
|
|
||||||
} catch (IOException ex) {
|
|
||||||
Iris.reportError(ex);
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (bv == null) {
|
|
||||||
throw new RuntimeException();
|
|
||||||
}
|
|
||||||
|
|
||||||
warn(i, bv);
|
|
||||||
|
|
||||||
synchronized (xg) {
|
|
||||||
xg.getAndSet(Math.max(bv.getBlockX(), xg.get()));
|
|
||||||
}
|
|
||||||
|
|
||||||
synchronized (zg) {
|
|
||||||
zg.getAndSet(Math.max(bv.getBlockZ(), zg.get()));
|
|
||||||
}
|
|
||||||
} catch (Throwable ed) {
|
|
||||||
Iris.reportError(ed);
|
|
||||||
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
for (Map.Entry<IrisObjectScale, KList<String>> entry : scalars.entrySet()) {
|
|
||||||
double ms = entry.getKey().getMaximumScale();
|
|
||||||
for (String j : entry.getValue()) {
|
|
||||||
e.queue(() -> {
|
|
||||||
try {
|
|
||||||
BlockVector bv = sizeCache.computeIfAbsent(j, (k) -> {
|
|
||||||
try {
|
|
||||||
return IrisObject.sampleSize(getData().getObjectLoader().findFile(j));
|
|
||||||
} catch (IOException ioException) {
|
|
||||||
Iris.reportError(ioException);
|
|
||||||
ioException.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (bv == null) {
|
|
||||||
throw new RuntimeException();
|
|
||||||
}
|
|
||||||
|
|
||||||
warnScaled(j, bv, ms);
|
|
||||||
|
|
||||||
synchronized (xg) {
|
|
||||||
xg.getAndSet((int) Math.max(Math.ceil(bv.getBlockX() * ms), xg.get()));
|
|
||||||
}
|
|
||||||
|
|
||||||
synchronized (zg) {
|
|
||||||
zg.getAndSet((int) Math.max(Math.ceil(bv.getBlockZ() * ms), zg.get()));
|
|
||||||
}
|
|
||||||
} catch (Throwable ee) {
|
|
||||||
Iris.reportError(ee);
|
|
||||||
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
e.complete();
|
|
||||||
|
|
||||||
x = xg.get();
|
|
||||||
z = zg.get();
|
|
||||||
|
|
||||||
for (IrisDepositGenerator i : getEngine().getDimension().getDeposits()) {
|
|
||||||
int max = i.getMaxDimension();
|
|
||||||
x = Math.max(max, x);
|
|
||||||
z = Math.max(max, z);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (IrisRegion v : r) {
|
|
||||||
for (IrisDepositGenerator i : v.getDeposits()) {
|
|
||||||
int max = i.getMaxDimension();
|
|
||||||
x = Math.max(max, x);
|
|
||||||
z = Math.max(max, z);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (IrisBiome v : b) {
|
|
||||||
for (IrisDepositGenerator i : v.getDeposits()) {
|
|
||||||
int max = i.getMaxDimension();
|
|
||||||
x = Math.max(max, x);
|
|
||||||
z = Math.max(max, z);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
x = Math.max(z, x);
|
|
||||||
int u = x;
|
|
||||||
int c = Math.max(computeCarvingRange(), computeBodyRange());
|
|
||||||
x = Math.max(jig, x);
|
|
||||||
x = Math.max(x, c);
|
|
||||||
x = (Math.max(x, 16) + 16) >> 4;
|
|
||||||
x = x % 2 == 0 ? x + 1 : x;
|
|
||||||
Iris.info("Mantle Size: " + x + " Chunks");
|
|
||||||
Iris.info(" Object Mantle Size: " + u + " (" + ((Math.max(u, 16) + 16) >> 4) + ")");
|
|
||||||
Iris.info(" Jigsaw Mantle Size: " + jig + " (" + ((Math.max(jig, 16) + 16) >> 4) + ")");
|
|
||||||
Iris.info(" Carving Mantle Size: " + c + " (" + ((Math.max(c, 16) + 16) >> 4) + ")");
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
private int computeBodyRange() {
|
|
||||||
int m = 0;
|
|
||||||
|
|
||||||
m = Math.max(m, getDimension().getFluidBodies().getMaxRange(getData()));
|
|
||||||
|
|
||||||
for (IrisRegion i : getDimension().getAllRegions(getEngine())) {
|
|
||||||
m = Math.max(m, i.getFluidBodies().getMaxRange(getData()));
|
|
||||||
}
|
|
||||||
|
|
||||||
for (IrisBiome i : getDimension().getAllBiomes(getEngine())) {
|
|
||||||
m = Math.max(m, i.getFluidBodies().getMaxRange(getData()));
|
|
||||||
}
|
|
||||||
|
|
||||||
return m;
|
|
||||||
}
|
|
||||||
|
|
||||||
private int computeCarvingRange() {
|
|
||||||
int m = 0;
|
|
||||||
|
|
||||||
m = Math.max(m, getDimension().getCarving().getMaxRange(getData()));
|
|
||||||
|
|
||||||
for (IrisRegion i : getDimension().getAllRegions(getEngine())) {
|
|
||||||
m = Math.max(m, i.getCarving().getMaxRange(getData()));
|
|
||||||
}
|
|
||||||
|
|
||||||
for (IrisBiome i : getDimension().getAllBiomes(getEngine())) {
|
|
||||||
m = Math.max(m, i.getCarving().getMaxRange(getData()));
|
|
||||||
}
|
|
||||||
|
|
||||||
return m;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -459,7 +459,7 @@ public class IrisWorldManager extends EngineAssignedWorldManager {
|
|||||||
IrisEngineData ed = getEngine().getEngineData();
|
IrisEngineData ed = getEngine().getEngineData();
|
||||||
IrisEngineSpawnerCooldown cd = null;
|
IrisEngineSpawnerCooldown cd = null;
|
||||||
|
|
||||||
for (IrisEngineSpawnerCooldown j : ed.getSpawnerCooldowns()) {
|
for (IrisEngineSpawnerCooldown j : ed.getSpawnerCooldowns().copy()) {
|
||||||
if (j.getSpawner().equals(i.getLoadKey())) {
|
if (j.getSpawner().equals(i.getLoadKey())) {
|
||||||
cd = j;
|
cd = j;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,15 +43,7 @@ public class IrisCeilingDecorator extends IrisEngineDecorator {
|
|||||||
IrisDecorator decorator = getDecorator(biome, realX, realZ);
|
IrisDecorator decorator = getDecorator(biome, realX, realZ);
|
||||||
if (decorator != null) {
|
if (decorator != null) {
|
||||||
if (!decorator.isStacking()) {
|
if (!decorator.isStacking()) {
|
||||||
if (height >= 0 || height < getEngine().getHeight()) {
|
data.set(x, height, z, fixFaces(decorator.getBlockData100(biome, getRng(), realX, height, realZ, getData()), realX, height, realZ));
|
||||||
if (null != decorator.getBlockDataForTop(biome, getRng(), realX, height, realZ, getData())) {
|
|
||||||
data.set(x, height, z, decorator.getBlockData100(biome, getRng(), realX, height, realZ, getData()));
|
|
||||||
height--;
|
|
||||||
data.set(x, height, z, decorator.getBlockDataForTop(biome, getRng(), realX, height, realZ, getData()));
|
|
||||||
} else {
|
|
||||||
data.set(x, height, z, decorator.getBlockData100(biome, getRng(), realX, height, realZ, getData()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
int stack = decorator.getHeight(getRng().nextParallelRNG(Cache.key(realX, realZ)), realX, realZ, getData());
|
int stack = decorator.getHeight(getRng().nextParallelRNG(Cache.key(realX, realZ)), realX, realZ, getData());
|
||||||
if (decorator.isScaleStack()) {
|
if (decorator.isScaleStack()) {
|
||||||
|
|||||||
@@ -44,15 +44,7 @@ public class IrisSeaFloorDecorator extends IrisEngineDecorator {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (height >= 0 || height < getEngine().getHeight()) {
|
if (height >= 0 || height < getEngine().getHeight()) {
|
||||||
if (null != decorator.getBlockDataForTop(biome, getRng(), realX, height, realZ, getData())) {
|
|
||||||
if (height == getDimension().getFluidHeight() - 1) {
|
|
||||||
data.set(x, height, z, decorator.getBlockData100(biome, getRng(), realX, height, realZ, getData()));
|
data.set(x, height, z, decorator.getBlockData100(biome, getRng(), realX, height, realZ, getData()));
|
||||||
height++;
|
|
||||||
data.set(x, height, z, decorator.getBlockDataForTop(biome, getRng(), realX, height, realZ, getData()));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
data.set(x, height, z, decorator.getBlockData100(biome, getRng(), realX, height, realZ, getData()));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
int stack = decorator.getHeight(getRng().nextParallelRNG(Cache.key(realX, realZ)), realX, realZ, getData());
|
int stack = decorator.getHeight(getRng().nextParallelRNG(Cache.key(realX, realZ)), realX, realZ, getData());
|
||||||
|
|||||||
@@ -40,13 +40,7 @@ public class IrisSeaSurfaceDecorator extends IrisEngineDecorator {
|
|||||||
if (decorator != null) {
|
if (decorator != null) {
|
||||||
if (!decorator.isStacking()) {
|
if (!decorator.isStacking()) {
|
||||||
if (height >= 0 || height < getEngine().getHeight()) {
|
if (height >= 0 || height < getEngine().getHeight()) {
|
||||||
if (null != decorator.getBlockDataForTop(biome, getRng(), realX, height, realZ, getData())) {
|
data.set(x, height + 1, z, decorator.getBlockData100(biome, getRng(), realX, height, realZ, getData()));
|
||||||
data.set(x, height, z, decorator.getBlockData100(biome, getRng(), realX, height, realZ, getData()));
|
|
||||||
height++;
|
|
||||||
data.set(x, height, z, decorator.getBlockDataForTop(biome, getRng(), realX, height, realZ, getData()));
|
|
||||||
} else {
|
|
||||||
data.set(x, height, z, decorator.getBlockData100(biome, getRng(), realX, height, realZ, getData()));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
int stack = decorator.getHeight(getRng().nextParallelRNG(Cache.key(realX, realZ)), realX, realZ, getData());
|
int stack = decorator.getHeight(getRng().nextParallelRNG(Cache.key(realX, realZ)), realX, realZ, getData());
|
||||||
|
|||||||
@@ -51,13 +51,7 @@ public class IrisShoreLineDecorator extends IrisEngineDecorator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!decorator.isStacking()) {
|
if (!decorator.isStacking()) {
|
||||||
if (null != decorator.getBlockDataForTop(biome, getRng(), realX, height, realZ, getData())) {
|
data.set(x, height + 1, z, decorator.getBlockData100(biome, getRng(), realX, height, realZ, getData()));
|
||||||
data.set(x, height, z, decorator.getBlockData100(biome, getRng(), realX, height, realZ, getData()));
|
|
||||||
height++;
|
|
||||||
data.set(x, height, z, decorator.getBlockDataForTop(biome, getRng(), realX, height, realZ, getData()));
|
|
||||||
} else {
|
|
||||||
data.set(x, height, z, decorator.getBlockData100(biome, getRng(), realX, height, realZ, getData()));
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
int stack = decorator.getHeight(getRng().nextParallelRNG(Cache.key(realX, realZ)), realX, realZ, getData());
|
int stack = decorator.getHeight(getRng().nextParallelRNG(Cache.key(realX, realZ)), realX, realZ, getData());
|
||||||
if (decorator.isScaleStack()) {
|
if (decorator.isScaleStack()) {
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ package com.volmit.iris.engine.framework;
|
|||||||
|
|
||||||
import com.volmit.iris.Iris;
|
import com.volmit.iris.Iris;
|
||||||
import com.volmit.iris.core.IrisSettings;
|
import com.volmit.iris.core.IrisSettings;
|
||||||
|
import com.volmit.iris.core.events.IrisLootEvent;
|
||||||
import com.volmit.iris.core.gui.components.RenderType;
|
import com.volmit.iris.core.gui.components.RenderType;
|
||||||
import com.volmit.iris.core.gui.components.Renderer;
|
import com.volmit.iris.core.gui.components.Renderer;
|
||||||
import com.volmit.iris.core.link.Identifier;
|
import com.volmit.iris.core.link.Identifier;
|
||||||
@@ -27,6 +28,7 @@ import com.volmit.iris.core.loader.IrisData;
|
|||||||
import com.volmit.iris.core.loader.IrisRegistrant;
|
import com.volmit.iris.core.loader.IrisRegistrant;
|
||||||
import com.volmit.iris.core.nms.container.BlockPos;
|
import com.volmit.iris.core.nms.container.BlockPos;
|
||||||
import com.volmit.iris.core.nms.container.Pair;
|
import com.volmit.iris.core.nms.container.Pair;
|
||||||
|
import com.volmit.iris.core.pregenerator.ChunkUpdater;
|
||||||
import com.volmit.iris.core.service.ExternalDataSVC;
|
import com.volmit.iris.core.service.ExternalDataSVC;
|
||||||
import com.volmit.iris.engine.IrisComplex;
|
import com.volmit.iris.engine.IrisComplex;
|
||||||
import com.volmit.iris.engine.data.cache.Cache;
|
import com.volmit.iris.engine.data.cache.Cache;
|
||||||
@@ -57,15 +59,13 @@ import com.volmit.iris.util.matter.TileWrapper;
|
|||||||
import com.volmit.iris.util.matter.slices.container.JigsawPieceContainer;
|
import com.volmit.iris.util.matter.slices.container.JigsawPieceContainer;
|
||||||
import com.volmit.iris.util.parallel.BurstExecutor;
|
import com.volmit.iris.util.parallel.BurstExecutor;
|
||||||
import com.volmit.iris.util.parallel.MultiBurst;
|
import com.volmit.iris.util.parallel.MultiBurst;
|
||||||
|
import com.volmit.iris.util.reflect.W;
|
||||||
import com.volmit.iris.util.scheduling.ChronoLatch;
|
import com.volmit.iris.util.scheduling.ChronoLatch;
|
||||||
import com.volmit.iris.util.scheduling.J;
|
import com.volmit.iris.util.scheduling.J;
|
||||||
import com.volmit.iris.util.scheduling.PrecisionStopwatch;
|
import com.volmit.iris.util.scheduling.PrecisionStopwatch;
|
||||||
import com.volmit.iris.util.stream.ProceduralStream;
|
import com.volmit.iris.util.stream.ProceduralStream;
|
||||||
import io.papermc.lib.PaperLib;
|
import io.papermc.lib.PaperLib;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.*;
|
||||||
import org.bukkit.Chunk;
|
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.block.Biome;
|
import org.bukkit.block.Biome;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.BlockFace;
|
import org.bukkit.block.BlockFace;
|
||||||
@@ -76,10 +76,11 @@ import org.bukkit.inventory.Inventory;
|
|||||||
import org.bukkit.inventory.InventoryHolder;
|
import org.bukkit.inventory.InventoryHolder;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.Color;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.Semaphore;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import java.util.concurrent.atomic.AtomicLong;
|
import java.util.concurrent.atomic.AtomicLong;
|
||||||
@@ -273,33 +274,43 @@ public interface Engine extends DataProvider, Fallible, LootProvider, BlockUpdat
|
|||||||
for (int z = -1; z <= 1; z++) {
|
for (int z = -1; z <= 1; z++) {
|
||||||
if (c.getWorld().isChunkLoaded(c.getX() + x, c.getZ() + z))
|
if (c.getWorld().isChunkLoaded(c.getX() + x, c.getZ() + z))
|
||||||
continue;
|
continue;
|
||||||
Iris.debug("Chunk %s, %s [%s, %s] is not loaded".formatted(c.getX() + x, c.getZ() + z, x, z));
|
var msg = "Chunk %s, %s [%s, %s] is not loaded".formatted(c.getX() + x, c.getZ() + z, x, z);
|
||||||
|
if (W.getStack().getCallerClass().equals(ChunkUpdater.class)) Iris.warn(msg);
|
||||||
|
else Iris.debug(msg);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!getMantle().getMantle().isLoaded(c)) {
|
var mantle = getMantle().getMantle();
|
||||||
Iris.debug("Mantle Chunk " + c.getX() + c.getX() + " is not loaded");
|
if (!mantle.isLoaded(c)) {
|
||||||
|
var msg = "Mantle Chunk " + c.getX() + c.getX() + " is not loaded";
|
||||||
|
if (W.getStack().getCallerClass().equals(ChunkUpdater.class)) Iris.warn(msg);
|
||||||
|
else Iris.debug(msg);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
getMantle().getMantle().raiseFlag(c.getX(), c.getZ(), MantleFlag.TILE, () -> J.s(() -> {
|
var chunk = mantle.getChunk(c);
|
||||||
getMantle().getMantle().iterateChunk(c.getX(), c.getZ(), TileWrapper.class, (x, y, z, v) -> {
|
if (chunk.isFlagged(MantleFlag.ETCHED)) return;
|
||||||
|
chunk.flag(MantleFlag.ETCHED, true);
|
||||||
|
|
||||||
|
Semaphore semaphore = new Semaphore(3);
|
||||||
|
chunk.raiseFlag(MantleFlag.TILE, run(semaphore, () -> J.s(() -> {
|
||||||
|
mantle.iterateChunk(c.getX(), c.getZ(), TileWrapper.class, (x, y, z, v) -> {
|
||||||
int betterY = y + getWorld().minHeight();
|
int betterY = y + getWorld().minHeight();
|
||||||
if (!TileData.setTileState(c.getBlock(x, betterY, z), v.getData()))
|
if (!TileData.setTileState(c.getBlock(x, betterY, z), v.getData()))
|
||||||
Iris.warn("Failed to set tile entity data at [%d %d %d | %s] for tile %s!", x, betterY, z, c.getBlock(x, betterY, z).getBlockData().getMaterial().getKey(), v.getData().getMaterial().name());
|
Iris.warn("Failed to set tile entity data at [%d %d %d | %s] for tile %s!", x, betterY, z, c.getBlock(x, betterY, z).getBlockData().getMaterial().getKey(), v.getData().getMaterial().name());
|
||||||
});
|
});
|
||||||
}));
|
})));
|
||||||
getMantle().getMantle().raiseFlag(c.getX(), c.getZ(), MantleFlag.CUSTOM, () -> J.s(() -> {
|
chunk.raiseFlag(MantleFlag.CUSTOM, run(semaphore, () -> J.s(() -> {
|
||||||
getMantle().getMantle().iterateChunk(c.getX(), c.getZ(), Identifier.class, (x, y, z, v) -> {
|
mantle.iterateChunk(c.getX(), c.getZ(), Identifier.class, (x, y, z, v) -> {
|
||||||
Iris.service(ExternalDataSVC.class).processUpdate(this, c.getBlock(x & 15, y + getWorld().minHeight(), z & 15), v);
|
Iris.service(ExternalDataSVC.class).processUpdate(this, c.getBlock(x & 15, y + getWorld().minHeight(), z & 15), v);
|
||||||
});
|
});
|
||||||
}));
|
})));
|
||||||
|
|
||||||
getMantle().getMantle().raiseFlag(c.getX(), c.getZ(), MantleFlag.UPDATE, () -> J.s(() -> {
|
chunk.raiseFlag(MantleFlag.UPDATE, run(semaphore, () -> J.s(() -> {
|
||||||
PrecisionStopwatch p = PrecisionStopwatch.start();
|
PrecisionStopwatch p = PrecisionStopwatch.start();
|
||||||
KMap<Long, Integer> updates = new KMap<>();
|
KMap<Long, Integer> updates = new KMap<>();
|
||||||
RNG r = new RNG(Cache.key(c.getX(), c.getZ()));
|
RNG r = new RNG(Cache.key(c.getX(), c.getZ()));
|
||||||
getMantle().getMantle().iterateChunk(c.getX(), c.getZ(), MatterCavern.class, (x, yf, z, v) -> {
|
mantle.iterateChunk(c.getX(), c.getZ(), MatterCavern.class, (x, yf, z, v) -> {
|
||||||
int y = yf + getWorld().minHeight();
|
int y = yf + getWorld().minHeight();
|
||||||
if (!B.isFluid(c.getBlock(x & 15, y, z & 15).getBlockData())) {
|
if (!B.isFluid(c.getBlock(x & 15, y, z & 15).getBlockData())) {
|
||||||
return;
|
return;
|
||||||
@@ -329,7 +340,7 @@ public interface Engine extends DataProvider, Fallible, LootProvider, BlockUpdat
|
|||||||
});
|
});
|
||||||
|
|
||||||
updates.forEach((k, v) -> update(Cache.keyX(k), v, Cache.keyZ(k), c, r));
|
updates.forEach((k, v) -> update(Cache.keyX(k), v, Cache.keyZ(k), c, r));
|
||||||
getMantle().getMantle().iterateChunk(c.getX(), c.getZ(), MatterUpdate.class, (x, yf, z, v) -> {
|
mantle.iterateChunk(c.getX(), c.getZ(), MatterUpdate.class, (x, yf, z, v) -> {
|
||||||
int y = yf + getWorld().minHeight();
|
int y = yf + getWorld().minHeight();
|
||||||
if (v != null && v.isUpdate()) {
|
if (v != null && v.isUpdate()) {
|
||||||
int vx = x & 15;
|
int vx = x & 15;
|
||||||
@@ -340,9 +351,25 @@ public interface Engine extends DataProvider, Fallible, LootProvider, BlockUpdat
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
getMantle().getMantle().deleteChunkSlice(c.getX(), c.getZ(), MatterUpdate.class);
|
mantle.deleteChunkSlice(c.getX(), c.getZ(), MatterUpdate.class);
|
||||||
getMetrics().getUpdates().put(p.getMilliseconds());
|
getMetrics().getUpdates().put(p.getMilliseconds());
|
||||||
}, RNG.r.i(0, 20)));
|
}, RNG.r.i(0, 20))));
|
||||||
|
|
||||||
|
try {
|
||||||
|
semaphore.acquire(3);
|
||||||
|
} catch (InterruptedException ignored) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Runnable run(Semaphore semaphore, Runnable runnable) {
|
||||||
|
return () -> {
|
||||||
|
if (!semaphore.tryAcquire())
|
||||||
|
return;
|
||||||
|
try {
|
||||||
|
runnable.run();
|
||||||
|
} finally {
|
||||||
|
semaphore.release();
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@BlockCoordinates
|
@BlockCoordinates
|
||||||
@@ -388,7 +415,7 @@ public interface Engine extends DataProvider, Fallible, LootProvider, BlockUpdat
|
|||||||
if (tables.isEmpty())
|
if (tables.isEmpty())
|
||||||
return;
|
return;
|
||||||
InventoryHolder m = (InventoryHolder) block.getState();
|
InventoryHolder m = (InventoryHolder) block.getState();
|
||||||
addItems(false, m.getInventory(), rx, tables, slot, x, y, z, 15);
|
addItems(false, m.getInventory(), rx, tables, slot, c.getWorld(), x, y, z, 15);
|
||||||
|
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
Iris.reportError(e);
|
Iris.reportError(e);
|
||||||
@@ -441,7 +468,10 @@ public interface Engine extends DataProvider, Fallible, LootProvider, BlockUpdat
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
default void injectTables(KList<IrisLootTable> list, IrisLootReference r) {
|
default void injectTables(KList<IrisLootTable> list, IrisLootReference r, boolean fallback) {
|
||||||
|
if (r.getMode().equals(IrisLootMode.FALLBACK) && !fallback)
|
||||||
|
return;
|
||||||
|
|
||||||
if (r.getMode().equals(IrisLootMode.CLEAR) || r.getMode().equals(IrisLootMode.REPLACE)) {
|
if (r.getMode().equals(IrisLootMode.CLEAR) || r.getMode().equals(IrisLootMode.REPLACE)) {
|
||||||
list.clear();
|
list.clear();
|
||||||
}
|
}
|
||||||
@@ -476,10 +506,11 @@ public interface Engine extends DataProvider, Fallible, LootProvider, BlockUpdat
|
|||||||
IrisBiome biomeUnder = ry < he ? getComplex().getCaveBiomeStream().get(rx, rz) : biomeSurface;
|
IrisBiome biomeUnder = ry < he ? getComplex().getCaveBiomeStream().get(rx, rz) : biomeSurface;
|
||||||
|
|
||||||
double multiplier = 1D * getDimension().getLoot().getMultiplier() * region.getLoot().getMultiplier() * biomeSurface.getLoot().getMultiplier() * biomeUnder.getLoot().getMultiplier();
|
double multiplier = 1D * getDimension().getLoot().getMultiplier() * region.getLoot().getMultiplier() * biomeSurface.getLoot().getMultiplier() * biomeUnder.getLoot().getMultiplier();
|
||||||
injectTables(tables, getDimension().getLoot());
|
boolean fallback = tables.isEmpty();
|
||||||
injectTables(tables, region.getLoot());
|
injectTables(tables, getDimension().getLoot(), fallback);
|
||||||
injectTables(tables, biomeSurface.getLoot());
|
injectTables(tables, region.getLoot(), fallback);
|
||||||
injectTables(tables, biomeUnder.getLoot());
|
injectTables(tables, biomeSurface.getLoot(), fallback);
|
||||||
|
injectTables(tables, biomeUnder.getLoot(), fallback);
|
||||||
|
|
||||||
if (tables.isNotEmpty()) {
|
if (tables.isNotEmpty()) {
|
||||||
int target = (int) Math.round(tables.size() * multiplier);
|
int target = (int) Math.round(tables.size() * multiplier);
|
||||||
@@ -497,16 +528,16 @@ public interface Engine extends DataProvider, Fallible, LootProvider, BlockUpdat
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
default void addItems(boolean debug, Inventory inv, RNG rng, KList<IrisLootTable> tables, InventorySlotType slot, int x, int y, int z, int mgf) {
|
default void addItems(boolean debug, Inventory inv, RNG rng, KList<IrisLootTable> tables, InventorySlotType slot, World world, int x, int y, int z, int mgf) {
|
||||||
KList<ItemStack> items = new KList<>();
|
KList<ItemStack> items = new KList<>();
|
||||||
|
|
||||||
int b = 4;
|
|
||||||
for (IrisLootTable i : tables) {
|
for (IrisLootTable i : tables) {
|
||||||
if (i == null)
|
if (i == null)
|
||||||
continue;
|
continue;
|
||||||
b++;
|
items.addAll(i.getLoot(debug, rng, slot, world, x, y, z));
|
||||||
items.addAll(i.getLoot(debug, rng, slot, x, y, z));
|
|
||||||
}
|
}
|
||||||
|
if (IrisLootEvent.callLootEvent(items, inv, world, x, y, z))
|
||||||
|
return;
|
||||||
|
|
||||||
if (PaperLib.isPaper() && getWorld().hasRealWorld()) {
|
if (PaperLib.isPaper() && getWorld().hasRealWorld()) {
|
||||||
PaperLib.getChunkAtAsync(getWorld().realWorld(), x >> 4, z >> 4).thenAccept((c) -> {
|
PaperLib.getChunkAtAsync(getWorld().realWorld(), x >> 4, z >> 4).thenAccept((c) -> {
|
||||||
@@ -795,6 +826,13 @@ public interface Engine extends DataProvider, Fallible, LootProvider, BlockUpdat
|
|||||||
return new PlacedObject(piece.getPlacementOptions(), getData().getObjectLoader().load(object), id, x, z);
|
return new PlacedObject(piece.getPlacementOptions(), getData().getObjectLoader().load(object), id, x, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (var staticPlacement : getDimension().getStaticPlacements().getObjects()) {
|
||||||
|
IrisObjectPlacement i = staticPlacement.placement();
|
||||||
|
if (i.getPlace().contains(object)) {
|
||||||
|
return new PlacedObject(i, getData().getObjectLoader().load(object), id, x, z);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
IrisRegion region = getRegion(x, z);
|
IrisRegion region = getRegion(x, z);
|
||||||
|
|
||||||
for (IrisObjectPlacement i : region.getObjects()) {
|
for (IrisObjectPlacement i : region.getObjects()) {
|
||||||
|
|||||||
@@ -1,32 +0,0 @@
|
|||||||
package com.volmit.iris.engine.framework;
|
|
||||||
|
|
||||||
import com.volmit.iris.engine.object.InventorySlotType;
|
|
||||||
import com.volmit.iris.engine.object.IrisLootTable;
|
|
||||||
import com.volmit.iris.util.collection.KList;
|
|
||||||
import lombok.Getter;
|
|
||||||
import org.bukkit.block.Block;
|
|
||||||
import org.bukkit.event.Event;
|
|
||||||
import org.bukkit.event.HandlerList;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
public class IrisLootEvent extends Event {
|
|
||||||
private static final HandlerList handlers = new HandlerList();
|
|
||||||
private final Engine engine;
|
|
||||||
private final Block block;
|
|
||||||
private final InventorySlotType slot;
|
|
||||||
private final KList<IrisLootTable> tables;
|
|
||||||
|
|
||||||
public IrisLootEvent(Engine engine, Block block, InventorySlotType slot, KList<IrisLootTable> tables) {
|
|
||||||
this.engine = engine;
|
|
||||||
this.block = block;
|
|
||||||
this.slot = slot;
|
|
||||||
this.tables = tables;
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public HandlerList getHandlers() {
|
|
||||||
return handlers;
|
|
||||||
}
|
|
||||||
public static HandlerList getHandlerList() {
|
|
||||||
return handlers;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,8 +1,10 @@
|
|||||||
package com.volmit.iris.engine.framework;
|
package com.volmit.iris.engine.framework;
|
||||||
|
|
||||||
|
import com.volmit.iris.core.loader.IrisData;
|
||||||
|
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
public interface ListFunction<T, R> extends Function<T, R> {
|
public interface ListFunction<R> extends Function<IrisData, R> {
|
||||||
String key();
|
String key();
|
||||||
String fancyName();
|
String fancyName();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,15 +23,16 @@ import com.volmit.iris.engine.object.IrisLootReference;
|
|||||||
import com.volmit.iris.engine.object.IrisLootTable;
|
import com.volmit.iris.engine.object.IrisLootTable;
|
||||||
import com.volmit.iris.util.collection.KList;
|
import com.volmit.iris.util.collection.KList;
|
||||||
import com.volmit.iris.util.math.RNG;
|
import com.volmit.iris.util.math.RNG;
|
||||||
|
import org.bukkit.World;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
|
|
||||||
public interface LootProvider {
|
public interface LootProvider {
|
||||||
void scramble(Inventory inventory, RNG rng);
|
void scramble(Inventory inventory, RNG rng);
|
||||||
|
|
||||||
void injectTables(KList<IrisLootTable> list, IrisLootReference r);
|
void injectTables(KList<IrisLootTable> list, IrisLootReference r, boolean fallback);
|
||||||
|
|
||||||
KList<IrisLootTable> getLootTables(RNG rng, Block b);
|
KList<IrisLootTable> getLootTables(RNG rng, Block b);
|
||||||
|
|
||||||
void addItems(boolean debug, Inventory inv, RNG rng, KList<IrisLootTable> tables, InventorySlotType slot, int x, int y, int z, int mgf);
|
void addItems(boolean debug, Inventory inv, RNG rng, KList<IrisLootTable> tables, InventorySlotType slot, World world, int x, int y, int z, int mgf);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import com.volmit.iris.core.loader.IrisData;
|
|||||||
import com.volmit.iris.core.tools.IrisToolbelt;
|
import com.volmit.iris.core.tools.IrisToolbelt;
|
||||||
import com.volmit.iris.engine.data.cache.Cache;
|
import com.volmit.iris.engine.data.cache.Cache;
|
||||||
import com.volmit.iris.engine.framework.Engine;
|
import com.volmit.iris.engine.framework.Engine;
|
||||||
import com.volmit.iris.engine.framework.IrisLootEvent;
|
import com.volmit.iris.core.events.IrisLootEvent;
|
||||||
import com.volmit.iris.engine.mantle.EngineMantle;
|
import com.volmit.iris.engine.mantle.EngineMantle;
|
||||||
import com.volmit.iris.engine.object.IObjectPlacer;
|
import com.volmit.iris.engine.object.IObjectPlacer;
|
||||||
import com.volmit.iris.engine.object.InventorySlotType;
|
import com.volmit.iris.engine.object.InventorySlotType;
|
||||||
@@ -20,8 +20,6 @@ import org.bukkit.Bukkit;
|
|||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.BlockState;
|
|
||||||
import org.bukkit.block.TileState;
|
|
||||||
import org.bukkit.block.data.BlockData;
|
import org.bukkit.block.data.BlockData;
|
||||||
import org.bukkit.inventory.InventoryHolder;
|
import org.bukkit.inventory.InventoryHolder;
|
||||||
|
|
||||||
@@ -74,7 +72,7 @@ public class WorldObjectPlacer implements IObjectPlacer {
|
|||||||
if (tables.isEmpty())
|
if (tables.isEmpty())
|
||||||
return;
|
return;
|
||||||
InventoryHolder m = (InventoryHolder) block.getState();
|
InventoryHolder m = (InventoryHolder) block.getState();
|
||||||
engine.addItems(false, m.getInventory(), rx, tables, slot, x, y, z, 15);
|
engine.addItems(false, m.getInventory(), rx, tables, slot, world, x, y, z, 15);
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
Iris.reportError(e);
|
Iris.reportError(e);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,16 +50,18 @@ public class PlannedStructure {
|
|||||||
private IrisPosition position;
|
private IrisPosition position;
|
||||||
private IrisData data;
|
private IrisData data;
|
||||||
private RNG rng;
|
private RNG rng;
|
||||||
|
private boolean forcePlace;
|
||||||
private boolean verbose;
|
private boolean verbose;
|
||||||
private boolean terminating;
|
private boolean terminating;
|
||||||
|
|
||||||
public PlannedStructure(IrisJigsawStructure structure, IrisPosition position, RNG rng) {
|
public PlannedStructure(IrisJigsawStructure structure, IrisPosition position, RNG rng, boolean forcePlace) {
|
||||||
terminating = false;
|
terminating = false;
|
||||||
verbose = true;
|
verbose = true;
|
||||||
this.pieces = new KList<>();
|
this.pieces = new KList<>();
|
||||||
this.structure = structure;
|
this.structure = structure;
|
||||||
this.position = position;
|
this.position = position;
|
||||||
this.rng = rng;
|
this.rng = rng;
|
||||||
|
this.forcePlace = forcePlace || structure.isForcePlace();
|
||||||
this.data = structure.getLoader();
|
this.data = structure.getLoader();
|
||||||
generateStartPiece();
|
generateStartPiece();
|
||||||
|
|
||||||
@@ -108,6 +110,9 @@ public class PlannedStructure {
|
|||||||
} else {
|
} else {
|
||||||
options.setMode(i.getPiece().getPlaceMode());
|
options.setMode(i.getPiece().getPlaceMode());
|
||||||
}
|
}
|
||||||
|
if (forcePlace) {
|
||||||
|
options.setForcePlace(true);
|
||||||
|
}
|
||||||
|
|
||||||
IrisObject v = i.getObject();
|
IrisObject v = i.getObject();
|
||||||
int sx = (v.getW() / 2);
|
int sx = (v.getW() / 2);
|
||||||
|
|||||||
@@ -20,10 +20,10 @@ package com.volmit.iris.engine.mantle;
|
|||||||
|
|
||||||
import com.volmit.iris.core.IrisSettings;
|
import com.volmit.iris.core.IrisSettings;
|
||||||
import com.volmit.iris.core.loader.IrisData;
|
import com.volmit.iris.core.loader.IrisData;
|
||||||
|
import com.volmit.iris.core.nms.container.Pair;
|
||||||
import com.volmit.iris.engine.IrisComplex;
|
import com.volmit.iris.engine.IrisComplex;
|
||||||
import com.volmit.iris.engine.framework.Engine;
|
import com.volmit.iris.engine.framework.Engine;
|
||||||
import com.volmit.iris.engine.framework.EngineTarget;
|
import com.volmit.iris.engine.framework.EngineTarget;
|
||||||
import com.volmit.iris.engine.framework.SeedManager;
|
|
||||||
import com.volmit.iris.engine.mantle.components.MantleJigsawComponent;
|
import com.volmit.iris.engine.mantle.components.MantleJigsawComponent;
|
||||||
import com.volmit.iris.engine.mantle.components.MantleObjectComponent;
|
import com.volmit.iris.engine.mantle.components.MantleObjectComponent;
|
||||||
import com.volmit.iris.engine.object.IObjectPlacer;
|
import com.volmit.iris.engine.object.IObjectPlacer;
|
||||||
@@ -44,7 +44,6 @@ import com.volmit.iris.util.matter.*;
|
|||||||
import com.volmit.iris.util.matter.slices.UpdateMatter;
|
import com.volmit.iris.util.matter.slices.UpdateMatter;
|
||||||
import com.volmit.iris.util.parallel.BurstExecutor;
|
import com.volmit.iris.util.parallel.BurstExecutor;
|
||||||
import com.volmit.iris.util.parallel.MultiBurst;
|
import com.volmit.iris.util.parallel.MultiBurst;
|
||||||
import org.bukkit.block.TileState;
|
|
||||||
import org.bukkit.block.data.BlockData;
|
import org.bukkit.block.data.BlockData;
|
||||||
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
@@ -59,7 +58,9 @@ public interface EngineMantle extends IObjectPlacer {
|
|||||||
|
|
||||||
int getRadius();
|
int getRadius();
|
||||||
|
|
||||||
KList<MantleComponent> getComponents();
|
int getRealRadius();
|
||||||
|
|
||||||
|
KList<Pair<KList<MantleComponent>, Integer>> getComponents();
|
||||||
|
|
||||||
void registerComponent(MantleComponent c);
|
void registerComponent(MantleComponent c);
|
||||||
|
|
||||||
@@ -187,34 +188,31 @@ public interface EngineMantle extends IObjectPlacer {
|
|||||||
return getEngine().burst();
|
return getEngine().burst();
|
||||||
}
|
}
|
||||||
|
|
||||||
default int getRealRadius() {
|
|
||||||
return (int) Math.ceil(getRadius() / 2D);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@ChunkCoordinates
|
@ChunkCoordinates
|
||||||
default void generateMatter(int x, int z, boolean multicore, ChunkContext context) {
|
default void generateMatter(int x, int z, boolean multicore, ChunkContext context) {
|
||||||
synchronized (this) {
|
|
||||||
if (!getEngine().getDimension().isUseMantle()) {
|
if (!getEngine().getDimension().isUseMantle()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int s = getRealRadius();
|
try (MantleWriter writer = getMantle().write(this, x, z, getRadius() * 2)) {
|
||||||
BurstExecutor burst = burst().burst(multicore);
|
var iterator = getComponents().iterator();
|
||||||
MantleWriter writer = getMantle().write(this, x, z, s * 2);
|
while (iterator.hasNext()) {
|
||||||
for (int i = -s; i <= s; i++) {
|
var pair = iterator.next();
|
||||||
for (int j = -s; j <= s; j++) {
|
int radius = pair.getB();
|
||||||
int xx = i + x;
|
boolean last = !iterator.hasNext();
|
||||||
int zz = j + z;
|
BurstExecutor burst = burst().burst(radius * 2 + 1);
|
||||||
burst.queue(() -> {
|
burst.setMulticore(multicore);
|
||||||
IrisContext.touch(getEngine().getContext());
|
|
||||||
getMantle().raiseFlag(xx, zz, MantleFlag.PLANNED, () -> {
|
for (int i = -radius; i <= radius; i++) {
|
||||||
|
for (int j = -radius; j <= radius; j++) {
|
||||||
|
int xx = x + i;
|
||||||
|
int zz = z + j;
|
||||||
MantleChunk mc = getMantle().getChunk(xx, zz);
|
MantleChunk mc = getMantle().getChunk(xx, zz);
|
||||||
|
|
||||||
for (MantleComponent k : getComponents()) {
|
burst.queue(() -> {
|
||||||
generateMantleComponent(writer, xx, zz, k, mc, context);
|
IrisContext.touch(getEngine().getContext());
|
||||||
}
|
pair.getA().forEach(k -> generateMantleComponent(writer, xx, zz, k, mc, context));
|
||||||
});
|
if (last) mc.flag(MantleFlag.PLANNED, true);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -222,6 +220,7 @@ public interface EngineMantle extends IObjectPlacer {
|
|||||||
burst.complete();
|
burst.complete();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
default void generateMantleComponent(MantleWriter writer, int x, int z, MantleComponent c, MantleChunk mc, ChunkContext context) {
|
default void generateMantleComponent(MantleWriter writer, int x, int z, MantleComponent c, MantleChunk mc, ChunkContext context) {
|
||||||
mc.raiseFlag(c.getFlag(), () -> c.generateLayer(writer, x, z, context));
|
mc.raiseFlag(c.getFlag(), () -> c.generateLayer(writer, x, z, context));
|
||||||
|
|||||||
@@ -29,4 +29,5 @@ import lombok.ToString;
|
|||||||
public abstract class IrisMantleComponent implements MantleComponent {
|
public abstract class IrisMantleComponent implements MantleComponent {
|
||||||
private final EngineMantle engineMantle;
|
private final EngineMantle engineMantle;
|
||||||
private final MantleFlag flag;
|
private final MantleFlag flag;
|
||||||
|
private final int priority;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,11 +26,12 @@ import com.volmit.iris.util.documentation.ChunkCoordinates;
|
|||||||
import com.volmit.iris.util.mantle.Mantle;
|
import com.volmit.iris.util.mantle.Mantle;
|
||||||
import com.volmit.iris.util.mantle.MantleFlag;
|
import com.volmit.iris.util.mantle.MantleFlag;
|
||||||
import com.volmit.iris.util.parallel.BurstExecutor;
|
import com.volmit.iris.util.parallel.BurstExecutor;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public interface MantleComponent {
|
public interface MantleComponent extends Comparable<MantleComponent> {
|
||||||
default int getRadius() {
|
int getPriority();
|
||||||
return getEngineMantle().getRealRadius();
|
|
||||||
}
|
int getRadius();
|
||||||
|
|
||||||
default IrisData getData() {
|
default IrisData getData() {
|
||||||
return getEngineMantle().getData();
|
return getEngineMantle().getData();
|
||||||
@@ -62,4 +63,9 @@ public interface MantleComponent {
|
|||||||
|
|
||||||
@ChunkCoordinates
|
@ChunkCoordinates
|
||||||
void generateLayer(MantleWriter writer, int x, int z, ChunkContext context);
|
void generateLayer(MantleWriter writer, int x, int z, ChunkContext context);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
default int compareTo(@NotNull MantleComponent o) {
|
||||||
|
return Integer.compare(getPriority(), o.getPriority());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,7 +35,6 @@ import com.volmit.iris.util.mantle.MantleChunk;
|
|||||||
import com.volmit.iris.util.math.RNG;
|
import com.volmit.iris.util.math.RNG;
|
||||||
import com.volmit.iris.util.matter.Matter;
|
import com.volmit.iris.util.matter.Matter;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import org.bukkit.block.TileState;
|
|
||||||
import org.bukkit.block.data.BlockData;
|
import org.bukkit.block.data.BlockData;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
@@ -44,7 +43,7 @@ import java.util.List;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public class MantleWriter implements IObjectPlacer {
|
public class MantleWriter implements IObjectPlacer, AutoCloseable {
|
||||||
private final EngineMantle engineMantle;
|
private final EngineMantle engineMantle;
|
||||||
private final Mantle mantle;
|
private final Mantle mantle;
|
||||||
private final KMap<Long, MantleChunk> cachedChunks;
|
private final KMap<Long, MantleChunk> cachedChunks;
|
||||||
@@ -62,7 +61,7 @@ public class MantleWriter implements IObjectPlacer {
|
|||||||
|
|
||||||
for (int i = -radius; i <= radius; i++) {
|
for (int i = -radius; i <= radius; i++) {
|
||||||
for (int j = -radius; j <= radius; j++) {
|
for (int j = -radius; j <= radius; j++) {
|
||||||
cachedChunks.put(Cache.key(i + x, j + z), mantle.getChunk(i + x, j + z));
|
cachedChunks.put(Cache.key(i + x, j + z), mantle.getChunk(i + x, j + z).use());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -633,4 +632,12 @@ public class MantleWriter implements IObjectPlacer {
|
|||||||
return cx >= this.x - radius && cx <= this.x + radius
|
return cx >= this.x - radius && cx <= this.x + radius
|
||||||
&& cz >= this.z - radius && cz <= this.z + radius;
|
&& cz >= this.z - radius && cz <= this.z + radius;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() {
|
||||||
|
cachedChunks.values().removeIf(c -> {
|
||||||
|
c.release();
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,10 +29,14 @@ import com.volmit.iris.util.context.ChunkContext;
|
|||||||
import com.volmit.iris.util.documentation.ChunkCoordinates;
|
import com.volmit.iris.util.documentation.ChunkCoordinates;
|
||||||
import com.volmit.iris.util.mantle.MantleFlag;
|
import com.volmit.iris.util.mantle.MantleFlag;
|
||||||
import com.volmit.iris.util.math.RNG;
|
import com.volmit.iris.util.math.RNG;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
public class MantleCarvingComponent extends IrisMantleComponent {
|
public class MantleCarvingComponent extends IrisMantleComponent {
|
||||||
|
private final int radius = computeRadius();
|
||||||
|
|
||||||
public MantleCarvingComponent(EngineMantle engineMantle) {
|
public MantleCarvingComponent(EngineMantle engineMantle) {
|
||||||
super(engineMantle, MantleFlag.CARVED);
|
super(engineMantle, MantleFlag.CARVED, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -56,4 +60,21 @@ public class MantleCarvingComponent extends IrisMantleComponent {
|
|||||||
private void carve(IrisCarving carving, MantleWriter writer, RNG rng, int cx, int cz) {
|
private void carve(IrisCarving carving, MantleWriter writer, RNG rng, int cx, int cz) {
|
||||||
carving.doCarving(writer, rng, getEngineMantle().getEngine(), cx << 4, -1, cz << 4);
|
carving.doCarving(writer, rng, getEngineMantle().getEngine(), cx << 4, -1, cz << 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int computeRadius() {
|
||||||
|
var dimension = getDimension();
|
||||||
|
int max = 0;
|
||||||
|
|
||||||
|
max = Math.max(max, dimension.getCarving().getMaxRange(getData()));
|
||||||
|
|
||||||
|
for (var i : dimension.getAllRegions(this::getData)) {
|
||||||
|
max = Math.max(max, i.getCarving().getMaxRange(getData()));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (var i : dimension.getAllBiomes(this::getData)) {
|
||||||
|
max = Math.max(max, i.getCarving().getMaxRange(getData()));
|
||||||
|
}
|
||||||
|
|
||||||
|
return max;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,10 +29,14 @@ import com.volmit.iris.util.context.ChunkContext;
|
|||||||
import com.volmit.iris.util.documentation.ChunkCoordinates;
|
import com.volmit.iris.util.documentation.ChunkCoordinates;
|
||||||
import com.volmit.iris.util.mantle.MantleFlag;
|
import com.volmit.iris.util.mantle.MantleFlag;
|
||||||
import com.volmit.iris.util.math.RNG;
|
import com.volmit.iris.util.math.RNG;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
public class MantleFluidBodyComponent extends IrisMantleComponent {
|
public class MantleFluidBodyComponent extends IrisMantleComponent {
|
||||||
|
private final int radius = computeRadius();
|
||||||
|
|
||||||
public MantleFluidBodyComponent(EngineMantle engineMantle) {
|
public MantleFluidBodyComponent(EngineMantle engineMantle) {
|
||||||
super(engineMantle, MantleFlag.FLUID_BODIES);
|
super(engineMantle, MantleFlag.FLUID_BODIES, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -56,4 +60,20 @@ public class MantleFluidBodyComponent extends IrisMantleComponent {
|
|||||||
private void generate(IrisFluidBodies bodies, MantleWriter writer, RNG rng, int cx, int cz) {
|
private void generate(IrisFluidBodies bodies, MantleWriter writer, RNG rng, int cx, int cz) {
|
||||||
bodies.generate(writer, rng, getEngineMantle().getEngine(), cx << 4, -1, cz << 4);
|
bodies.generate(writer, rng, getEngineMantle().getEngine(), cx << 4, -1, cz << 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int computeRadius() {
|
||||||
|
int max = 0;
|
||||||
|
|
||||||
|
max = Math.max(max, getDimension().getFluidBodies().getMaxRange(getData()));
|
||||||
|
|
||||||
|
for (IrisRegion i : getDimension().getAllRegions(this::getData)) {
|
||||||
|
max = Math.max(max, i.getFluidBodies().getMaxRange(getData()));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (IrisBiome i : getDimension().getAllBiomes(this::getData)) {
|
||||||
|
max = Math.max(max, i.getFluidBodies().getMaxRange(getData()));
|
||||||
|
}
|
||||||
|
|
||||||
|
return max;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,15 +34,18 @@ import com.volmit.iris.util.math.Position2;
|
|||||||
import com.volmit.iris.util.math.RNG;
|
import com.volmit.iris.util.math.RNG;
|
||||||
import com.volmit.iris.util.matter.slices.container.JigsawStructuresContainer;
|
import com.volmit.iris.util.matter.slices.container.JigsawStructuresContainer;
|
||||||
import com.volmit.iris.util.noise.CNG;
|
import com.volmit.iris.util.noise.CNG;
|
||||||
|
import lombok.Getter;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class MantleJigsawComponent extends IrisMantleComponent {
|
public class MantleJigsawComponent extends IrisMantleComponent {
|
||||||
|
@Getter
|
||||||
|
private final int radius = computeRadius();
|
||||||
private final CNG cng;
|
private final CNG cng;
|
||||||
|
|
||||||
public MantleJigsawComponent(EngineMantle engineMantle) {
|
public MantleJigsawComponent(EngineMantle engineMantle) {
|
||||||
super(engineMantle, MantleFlag.JIGSAW);
|
super(engineMantle, MantleFlag.JIGSAW, 1);
|
||||||
cng = NoiseStyle.STATIC.create(new RNG(jigsaw()));
|
cng = NoiseStyle.STATIC.create(new RNG(jigsaw()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,7 +69,7 @@ public class MantleJigsawComponent extends IrisMantleComponent {
|
|||||||
for (Position2 pos : poss) {
|
for (Position2 pos : poss) {
|
||||||
if (x == pos.getX() >> 4 && z == pos.getZ() >> 4) {
|
if (x == pos.getX() >> 4 && z == pos.getZ() >> 4) {
|
||||||
IrisJigsawStructure structure = getData().getJigsawStructureLoader().load(getDimension().getStronghold());
|
IrisJigsawStructure structure = getData().getJigsawStructureLoader().load(getDimension().getStronghold());
|
||||||
place(writer, pos.toIris(), structure, new RNG(seed));
|
place(writer, pos.toIris(), structure, new RNG(seed), true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -92,7 +95,7 @@ public class MantleJigsawComponent extends IrisMantleComponent {
|
|||||||
RNG rng = new RNG(seed);
|
RNG rng = new RNG(seed);
|
||||||
IrisPosition position = new IrisPosition((x << 4) + rng.nextInt(15), 0, (z << 4) + rng.nextInt(15));
|
IrisPosition position = new IrisPosition((x << 4) + rng.nextInt(15), 0, (z << 4) + rng.nextInt(15));
|
||||||
IrisJigsawStructure structure = getData().getJigsawStructureLoader().load(i.getStructure());
|
IrisJigsawStructure structure = getData().getJigsawStructureLoader().load(i.getStructure());
|
||||||
return place(writer, position, structure, rng);
|
return place(writer, position, structure, rng, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ChunkCoordinates
|
@ChunkCoordinates
|
||||||
@@ -161,11 +164,36 @@ public class MantleJigsawComponent extends IrisMantleComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@BlockCoordinates
|
@BlockCoordinates
|
||||||
private boolean place(MantleWriter writer, IrisPosition position, IrisJigsawStructure structure, RNG rng) {
|
private boolean place(MantleWriter writer, IrisPosition position, IrisJigsawStructure structure, RNG rng, boolean forcePlace) {
|
||||||
return new PlannedStructure(structure, position, rng).place(writer, getMantle(), writer.getEngine());
|
return new PlannedStructure(structure, position, rng, forcePlace).place(writer, getMantle(), writer.getEngine());
|
||||||
}
|
}
|
||||||
|
|
||||||
private long jigsaw() {
|
private long jigsaw() {
|
||||||
return getEngineMantle().getEngine().getSeedManager().getJigsaw();
|
return getEngineMantle().getEngine().getSeedManager().getJigsaw();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int computeRadius() {
|
||||||
|
var dimension = getDimension();
|
||||||
|
|
||||||
|
KSet<String> structures = new KSet<>();
|
||||||
|
for (var placement : dimension.getJigsawStructures()) {
|
||||||
|
structures.add(placement.getStructure());
|
||||||
|
}
|
||||||
|
for (var region : dimension.getAllRegions(this::getData)) {
|
||||||
|
for (var placement : region.getJigsawStructures()) {
|
||||||
|
structures.add(placement.getStructure());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (var biome : dimension.getAllBiomes(this::getData)) {
|
||||||
|
for (var placement : biome.getJigsawStructures()) {
|
||||||
|
structures.add(placement.getStructure());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int max = 0;
|
||||||
|
for (var structure : structures) {
|
||||||
|
max = Math.max(max, getData().getJigsawStructureLoader().load(structure).getMaxDimension());
|
||||||
|
}
|
||||||
|
return max;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,28 +19,43 @@
|
|||||||
package com.volmit.iris.engine.mantle.components;
|
package com.volmit.iris.engine.mantle.components;
|
||||||
|
|
||||||
import com.volmit.iris.Iris;
|
import com.volmit.iris.Iris;
|
||||||
|
import com.volmit.iris.core.loader.IrisData;
|
||||||
import com.volmit.iris.engine.data.cache.Cache;
|
import com.volmit.iris.engine.data.cache.Cache;
|
||||||
import com.volmit.iris.engine.mantle.EngineMantle;
|
import com.volmit.iris.engine.mantle.EngineMantle;
|
||||||
import com.volmit.iris.engine.mantle.IrisMantleComponent;
|
import com.volmit.iris.engine.mantle.IrisMantleComponent;
|
||||||
import com.volmit.iris.engine.mantle.MantleWriter;
|
import com.volmit.iris.engine.mantle.MantleWriter;
|
||||||
import com.volmit.iris.engine.object.*;
|
import com.volmit.iris.engine.object.*;
|
||||||
|
import com.volmit.iris.util.collection.KList;
|
||||||
|
import com.volmit.iris.util.collection.KMap;
|
||||||
import com.volmit.iris.util.collection.KSet;
|
import com.volmit.iris.util.collection.KSet;
|
||||||
import com.volmit.iris.util.context.ChunkContext;
|
import com.volmit.iris.util.context.ChunkContext;
|
||||||
import com.volmit.iris.util.data.B;
|
import com.volmit.iris.util.data.B;
|
||||||
import com.volmit.iris.util.data.IrisBlockData;
|
import com.volmit.iris.util.data.IrisBlockData;
|
||||||
import com.volmit.iris.util.documentation.BlockCoordinates;
|
import com.volmit.iris.util.documentation.BlockCoordinates;
|
||||||
import com.volmit.iris.util.documentation.ChunkCoordinates;
|
import com.volmit.iris.util.documentation.ChunkCoordinates;
|
||||||
|
import com.volmit.iris.util.format.Form;
|
||||||
import com.volmit.iris.util.mantle.MantleFlag;
|
import com.volmit.iris.util.mantle.MantleFlag;
|
||||||
import com.volmit.iris.util.math.RNG;
|
import com.volmit.iris.util.math.RNG;
|
||||||
import com.volmit.iris.util.matter.MatterStructurePOI;
|
import com.volmit.iris.util.matter.MatterStructurePOI;
|
||||||
import com.volmit.iris.util.noise.CNG;
|
import com.volmit.iris.util.noise.CNG;
|
||||||
import com.volmit.iris.util.noise.NoiseType;
|
import com.volmit.iris.util.noise.NoiseType;
|
||||||
|
import com.volmit.iris.util.parallel.BurstExecutor;
|
||||||
|
import com.volmit.iris.util.parallel.MultiBurst;
|
||||||
|
import lombok.Getter;
|
||||||
|
import org.bukkit.util.BlockVector;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
|
@Getter
|
||||||
public class MantleObjectComponent extends IrisMantleComponent {
|
public class MantleObjectComponent extends IrisMantleComponent {
|
||||||
|
private final int radius = computeRadius();
|
||||||
|
|
||||||
public MantleObjectComponent(EngineMantle engineMantle) {
|
public MantleObjectComponent(EngineMantle engineMantle) {
|
||||||
super(engineMantle, MantleFlag.OBJECT);
|
super(engineMantle, MantleFlag.OBJECT, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -146,4 +161,94 @@ public class MantleObjectComponent extends IrisMantleComponent {
|
|||||||
|
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int computeRadius() {
|
||||||
|
var dimension = getDimension();
|
||||||
|
|
||||||
|
KSet<String> objects = new KSet<>();
|
||||||
|
KMap<IrisObjectScale, KList<String>> scalars = new KMap<>();
|
||||||
|
for (var region : dimension.getAllRegions(this::getData)) {
|
||||||
|
for (var placement : region.getObjects()) {
|
||||||
|
if (placement.getScale().canScaleBeyond()) {
|
||||||
|
scalars.put(placement.getScale(), placement.getPlace());
|
||||||
|
} else {
|
||||||
|
objects.addAll(placement.getPlace());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (var biome : region.getAllBiomes(this::getData)) {
|
||||||
|
for (var placement : biome.getObjects()) {
|
||||||
|
if (placement.getScale().canScaleBeyond()) {
|
||||||
|
scalars.put(placement.getScale(), placement.getPlace());
|
||||||
|
} else {
|
||||||
|
objects.addAll(placement.getPlace());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return computeObjectRadius(objects, scalars, getEngineMantle().getTarget().getBurster(), getData());
|
||||||
|
}
|
||||||
|
|
||||||
|
static int computeObjectRadius(KSet<String> objects, KMap<IrisObjectScale, KList<String>> scalars, MultiBurst burst, IrisData data) {
|
||||||
|
AtomicInteger x = new AtomicInteger();
|
||||||
|
AtomicInteger z = new AtomicInteger();
|
||||||
|
|
||||||
|
BurstExecutor e = burst.burst(objects.size());
|
||||||
|
KMap<String, BlockVector> sizeCache = new KMap<>();
|
||||||
|
for (String loadKey : objects) {
|
||||||
|
e.queue(() -> {
|
||||||
|
try {
|
||||||
|
BlockVector bv = sampleSize(sizeCache, data, loadKey);
|
||||||
|
|
||||||
|
if (Math.max(bv.getBlockX(), bv.getBlockZ()) > 128) {
|
||||||
|
Iris.warn("Object " + loadKey + " has a large size (" + bv + ") and may increase memory usage!");
|
||||||
|
}
|
||||||
|
|
||||||
|
x.getAndUpdate(i -> Math.max(bv.getBlockX(), i));
|
||||||
|
z.getAndUpdate(i -> Math.max(bv.getBlockZ(), i));
|
||||||
|
} catch (Throwable ed) {
|
||||||
|
Iris.reportError(ed);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Map.Entry<IrisObjectScale, KList<String>> entry : scalars.entrySet()) {
|
||||||
|
double ms = entry.getKey().getMaximumScale();
|
||||||
|
for (String loadKey : entry.getValue()) {
|
||||||
|
e.queue(() -> {
|
||||||
|
try {
|
||||||
|
BlockVector bv = sampleSize(sizeCache, data, loadKey);
|
||||||
|
|
||||||
|
if (Math.max(bv.getBlockX(), bv.getBlockZ()) > 128) {
|
||||||
|
Iris.warn("Object " + loadKey + " has a large size (" + bv + ") and may increase memory usage! (Object scaled up to " + Form.pc(ms, 2) + ")");
|
||||||
|
}
|
||||||
|
|
||||||
|
x.getAndUpdate(i -> (int) Math.max(Math.ceil(bv.getBlockX() * ms), i));
|
||||||
|
x.getAndUpdate(i -> (int) Math.max(Math.ceil(bv.getBlockZ() * ms), i));
|
||||||
|
} catch (Throwable ee) {
|
||||||
|
Iris.reportError(ee);
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
e.complete();
|
||||||
|
return Math.max(x.get(), z.get());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static BlockVector sampleSize(KMap<String, BlockVector> sizeCache, IrisData data, String loadKey) {
|
||||||
|
BlockVector bv = sizeCache.computeIfAbsent(loadKey, (k) -> {
|
||||||
|
try {
|
||||||
|
return IrisObject.sampleSize(data.getObjectLoader().findFile(loadKey));
|
||||||
|
} catch (IOException ioException) {
|
||||||
|
Iris.reportError(ioException);
|
||||||
|
ioException.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
return Objects.requireNonNull(bv, "sampleSize returned a null block vector");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,59 @@
|
|||||||
|
package com.volmit.iris.engine.mantle.components;
|
||||||
|
|
||||||
|
import com.volmit.iris.engine.mantle.EngineMantle;
|
||||||
|
import com.volmit.iris.engine.mantle.IrisMantleComponent;
|
||||||
|
import com.volmit.iris.engine.mantle.MantleWriter;
|
||||||
|
import com.volmit.iris.engine.object.IrisObjectScale;
|
||||||
|
import com.volmit.iris.engine.object.IrisStaticPlacement;
|
||||||
|
import com.volmit.iris.engine.object.NoiseStyle;
|
||||||
|
import com.volmit.iris.util.collection.KList;
|
||||||
|
import com.volmit.iris.util.collection.KMap;
|
||||||
|
import com.volmit.iris.util.collection.KSet;
|
||||||
|
import com.volmit.iris.util.context.ChunkContext;
|
||||||
|
import com.volmit.iris.util.mantle.MantleFlag;
|
||||||
|
import com.volmit.iris.util.math.RNG;
|
||||||
|
import com.volmit.iris.util.noise.CNG;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
public class MantleStaticComponent extends IrisMantleComponent {
|
||||||
|
private final CNG cng;
|
||||||
|
@Getter
|
||||||
|
private final int radius = computeRadius();
|
||||||
|
|
||||||
|
public MantleStaticComponent(EngineMantle engineMantle) {
|
||||||
|
super(engineMantle, MantleFlag.STATIC, 1);
|
||||||
|
cng = NoiseStyle.STATIC.create(new RNG(seed()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void generateLayer(MantleWriter writer, int x, int z, ChunkContext context) {
|
||||||
|
RNG rng = new RNG(cng.fit(Integer.MIN_VALUE, Integer.MAX_VALUE, x, z));
|
||||||
|
for (IrisStaticPlacement placement : getDimension().getStaticPlacements().getAll(x, z)) {
|
||||||
|
placement.place(writer, rng, getData());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private int computeRadius() {
|
||||||
|
var placements = getDimension().getStaticPlacements();
|
||||||
|
|
||||||
|
KSet<String> objects = new KSet<>();
|
||||||
|
KMap<IrisObjectScale, KList<String>> scalars = new KMap<>();
|
||||||
|
for (var staticPlacement : placements.getObjects()) {
|
||||||
|
var placement = staticPlacement.placement();
|
||||||
|
if (placement.getScale().canScaleBeyond()) {
|
||||||
|
scalars.put(placement.getScale(), placement.getPlace());
|
||||||
|
} else {
|
||||||
|
objects.addAll(placement.getPlace());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int jigsaw = placements.getStructures()
|
||||||
|
.stream()
|
||||||
|
.mapToInt(staticPlacement -> staticPlacement.maxDimension(getData()))
|
||||||
|
.max()
|
||||||
|
.orElse(0);
|
||||||
|
int object = MantleObjectComponent.computeObjectRadius(objects, scalars, getEngineMantle().getTarget().getBurster(), getData());
|
||||||
|
|
||||||
|
return Math.max(jigsaw, object);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -20,10 +20,7 @@ package com.volmit.iris.engine.modifier;
|
|||||||
|
|
||||||
import com.volmit.iris.engine.framework.Engine;
|
import com.volmit.iris.engine.framework.Engine;
|
||||||
import com.volmit.iris.engine.framework.EngineAssignedModifier;
|
import com.volmit.iris.engine.framework.EngineAssignedModifier;
|
||||||
import com.volmit.iris.engine.object.IrisBiome;
|
import com.volmit.iris.engine.object.*;
|
||||||
import com.volmit.iris.engine.object.IrisDepositGenerator;
|
|
||||||
import com.volmit.iris.engine.object.IrisObject;
|
|
||||||
import com.volmit.iris.engine.object.IrisRegion;
|
|
||||||
import com.volmit.iris.util.context.ChunkContext;
|
import com.volmit.iris.util.context.ChunkContext;
|
||||||
import com.volmit.iris.util.data.B;
|
import com.volmit.iris.util.data.B;
|
||||||
import com.volmit.iris.util.data.HeightMap;
|
import com.volmit.iris.util.data.HeightMap;
|
||||||
@@ -45,30 +42,26 @@ public class IrisDepositModifier extends EngineAssignedModifier<BlockData> {
|
|||||||
@Override
|
@Override
|
||||||
public void onModify(int x, int z, Hunk<BlockData> output, boolean multicore, ChunkContext context) {
|
public void onModify(int x, int z, Hunk<BlockData> output, boolean multicore, ChunkContext context) {
|
||||||
PrecisionStopwatch p = PrecisionStopwatch.start();
|
PrecisionStopwatch p = PrecisionStopwatch.start();
|
||||||
generateDeposits(rng, output, Math.floorDiv(x, 16), Math.floorDiv(z, 16), multicore, context);
|
generateDeposits(output, Math.floorDiv(x, 16), Math.floorDiv(z, 16), multicore, context);
|
||||||
getEngine().getMetrics().getDeposit().put(p.getMilliseconds());
|
getEngine().getMetrics().getDeposit().put(p.getMilliseconds());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void generateDeposits(RNG rx, Hunk<BlockData> terrain, int x, int z, boolean multicore, ChunkContext context) {
|
public void generateDeposits(Hunk<BlockData> terrain, int x, int z, boolean multicore, ChunkContext context) {
|
||||||
RNG ro = rx.nextParallelRNG(x * x).nextParallelRNG(z * z);
|
|
||||||
IrisRegion region = context.getRegion().get(7, 7);
|
IrisRegion region = context.getRegion().get(7, 7);
|
||||||
IrisBiome biome = context.getBiome().get(7, 7);
|
IrisBiome biome = context.getBiome().get(7, 7);
|
||||||
BurstExecutor burst = burst().burst(multicore);
|
BurstExecutor burst = burst().burst(multicore);
|
||||||
|
|
||||||
|
long seed = x * 341873128712L + z * 132897987541L;
|
||||||
for (IrisDepositGenerator k : getDimension().getDeposits()) {
|
for (IrisDepositGenerator k : getDimension().getDeposits()) {
|
||||||
burst.queue(() -> generate(k, terrain, ro, x, z, false, context));
|
burst.queue(() -> generate(k, terrain, rng.nextParallelRNG(seed), x, z, false, context));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (IrisDepositGenerator k : region.getDeposits()) {
|
for (IrisDepositGenerator k : region.getDeposits()) {
|
||||||
for (int l = 0; l < ro.i(k.getMinPerChunk(), k.getMaxPerChunk()); l++) {
|
burst.queue(() -> generate(k, terrain, rng.nextParallelRNG(seed), x, z, false, context));
|
||||||
burst.queue(() -> generate(k, terrain, ro, x, z, false, context));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (IrisDepositGenerator k : biome.getDeposits()) {
|
for (IrisDepositGenerator k : biome.getDeposits()) {
|
||||||
for (int l = 0; l < ro.i(k.getMinPerChunk(), k.getMaxPerChunk()); l++) {
|
burst.queue(() -> generate(k, terrain, rng.nextParallelRNG(seed), x, z, false, context));
|
||||||
burst.queue(() -> generate(k, terrain, ro, x, z, false, context));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
burst.complete();
|
burst.complete();
|
||||||
}
|
}
|
||||||
@@ -78,45 +71,48 @@ public class IrisDepositModifier extends EngineAssignedModifier<BlockData> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void generate(IrisDepositGenerator k, Hunk<BlockData> data, RNG rng, int cx, int cz, boolean safe, HeightMap he, ChunkContext context) {
|
public void generate(IrisDepositGenerator k, Hunk<BlockData> data, RNG rng, int cx, int cz, boolean safe, HeightMap he, ChunkContext context) {
|
||||||
for (int l = 0; l < rng.i(k.getMinPerChunk(), k.getMaxPerChunk()); l++) {
|
if (k.getSpawnChance() < rng.d())
|
||||||
|
return;
|
||||||
|
|
||||||
|
for (int l = 0; l < rng.i(k.getMinPerChunk(), k.getMaxPerChunk() + 1); l++) {
|
||||||
|
if (k.getPerClumpSpawnChance() < rng.d())
|
||||||
|
continue;
|
||||||
|
|
||||||
IrisObject clump = k.getClump(rng, getData());
|
IrisObject clump = k.getClump(rng, getData());
|
||||||
|
|
||||||
int af = (int) Math.floor(clump.getW() / 2D);
|
int dim = clump.getW();
|
||||||
int bf = (int) Math.floor(16D - (clump.getW() / 2D));
|
int min = dim / 2;
|
||||||
|
int max = (int) (16D - dim / 2D);
|
||||||
|
|
||||||
if (af > bf || af < 0 || bf > 15) {
|
if (min > max || min < 0 || max > 15) {
|
||||||
af = 6;
|
min = 6;
|
||||||
bf = 9;
|
max = 9;
|
||||||
}
|
}
|
||||||
|
|
||||||
af = Math.max(af - 1, 0);
|
int x = rng.i(min, max + 1);
|
||||||
int x = rng.i(af, bf);
|
int z = rng.i(min, max + 1);
|
||||||
int z = rng.i(af, bf);
|
|
||||||
int height = (he != null ? he.getHeight((cx << 4) + x, (cz << 4) + z) : (int) (Math.round(
|
int height = (he != null ? he.getHeight((cx << 4) + x, (cz << 4) + z) : (int) (Math.round(
|
||||||
context.getHeight().get(x, z)
|
context.getHeight().get(x, z)
|
||||||
))) - 7;
|
))) - 7;
|
||||||
|
|
||||||
if (height <= 0) {
|
if (height <= 0)
|
||||||
return;
|
continue;
|
||||||
}
|
|
||||||
|
|
||||||
int i = Math.max(0, k.getMinHeight());
|
int minY = Math.max(0, k.getMinHeight());
|
||||||
// TODO: WARNING HEIGHT
|
// TODO: WARNING HEIGHT
|
||||||
int a = Math.min(height, Math.min(getEngine().getHeight(), k.getMaxHeight()));
|
int maxY = Math.min(height, Math.min(getEngine().getHeight(), k.getMaxHeight()));
|
||||||
|
|
||||||
if (i >= a) {
|
if (minY >= maxY)
|
||||||
return;
|
continue;
|
||||||
}
|
|
||||||
|
|
||||||
int h = rng.i(i, a);
|
int y = rng.i(minY, maxY + 1);
|
||||||
|
|
||||||
if (h > k.getMaxHeight() || h < k.getMinHeight() || h > height - 2) {
|
if (y > k.getMaxHeight() || y < k.getMinHeight() || y > height - 2)
|
||||||
return;
|
continue;
|
||||||
}
|
|
||||||
|
|
||||||
for (BlockVector j : clump.getBlocks().keySet()) {
|
for (BlockVector j : clump.getBlocks().keySet()) {
|
||||||
int nx = j.getBlockX() + x;
|
int nx = j.getBlockX() + x;
|
||||||
int ny = j.getBlockY() + h;
|
int ny = j.getBlockY() + y;
|
||||||
int nz = j.getBlockZ() + z;
|
int nz = j.getBlockZ() + z;
|
||||||
|
|
||||||
if (ny > height || nx > 15 || nx < 0 || ny > getEngine().getHeight() || ny < 0 || nz < 0 || nz > 15) {
|
if (ny > height || nx > 15 || nx < 0 || ny > getEngine().getHeight() || ny < 0 || nz < 0 || nz > 15) {
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package com.volmit.iris.engine.object;
|
||||||
|
|
||||||
|
import com.volmit.iris.core.loader.IrisData;
|
||||||
|
import com.volmit.iris.util.collection.KList;
|
||||||
|
import org.bukkit.block.data.BlockData;
|
||||||
|
|
||||||
|
public interface IObjectLoot {
|
||||||
|
KList<IrisBlockData> getFilter();
|
||||||
|
KList<BlockData> getFilter(IrisData manager);
|
||||||
|
boolean isExact();
|
||||||
|
String getName();
|
||||||
|
int getWeight();
|
||||||
|
}
|
||||||
@@ -37,12 +37,10 @@ public class IrisBiomeCustomSpawn {
|
|||||||
private EntityType type = EntityType.COW;
|
private EntityType type = EntityType.COW;
|
||||||
|
|
||||||
@MinNumber(1)
|
@MinNumber(1)
|
||||||
@MaxNumber(20)
|
|
||||||
@Desc("The min to spawn")
|
@Desc("The min to spawn")
|
||||||
private int minCount = 2;
|
private int minCount = 2;
|
||||||
|
|
||||||
@MinNumber(1)
|
@MinNumber(1)
|
||||||
@MaxNumber(20)
|
|
||||||
@Desc("The max to spawn")
|
@Desc("The max to spawn")
|
||||||
private int maxCount = 5;
|
private int maxCount = 5;
|
||||||
|
|
||||||
|
|||||||
@@ -22,13 +22,14 @@ import com.volmit.iris.core.loader.IrisData;
|
|||||||
import com.volmit.iris.engine.data.cache.AtomicCache;
|
import com.volmit.iris.engine.data.cache.AtomicCache;
|
||||||
import com.volmit.iris.engine.object.annotations.*;
|
import com.volmit.iris.engine.object.annotations.*;
|
||||||
import com.volmit.iris.util.collection.KList;
|
import com.volmit.iris.util.collection.KList;
|
||||||
|
import com.volmit.iris.util.collection.KSet;
|
||||||
|
import com.volmit.iris.util.math.BlockPosition;
|
||||||
import com.volmit.iris.util.math.RNG;
|
import com.volmit.iris.util.math.RNG;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
import lombok.experimental.Accessors;
|
import lombok.experimental.Accessors;
|
||||||
import org.bukkit.block.data.BlockData;
|
import org.bukkit.block.data.BlockData;
|
||||||
import org.bukkit.util.BlockVector;
|
|
||||||
|
|
||||||
@Snippet("deposit")
|
@Snippet("deposit")
|
||||||
@Accessors(chain = true)
|
@Accessors(chain = true)
|
||||||
@@ -69,6 +70,14 @@ public class IrisDepositGenerator {
|
|||||||
@MaxNumber(2048)
|
@MaxNumber(2048)
|
||||||
@Desc("The minimum amount of clumps per chunk")
|
@Desc("The minimum amount of clumps per chunk")
|
||||||
private int minPerChunk = 0;
|
private int minPerChunk = 0;
|
||||||
|
@MinNumber(0)
|
||||||
|
@MaxNumber(1)
|
||||||
|
@Desc("The change of the deposit spawning in a chunk")
|
||||||
|
private double spawnChance = 1;
|
||||||
|
@MinNumber(0)
|
||||||
|
@MaxNumber(1)
|
||||||
|
@Desc("The change of the a clump spawning in a chunk")
|
||||||
|
private double perClumpSpawnChance = 1;
|
||||||
@Required
|
@Required
|
||||||
@ArrayType(min = 1, type = IrisBlockData.class)
|
@ArrayType(min = 1, type = IrisBlockData.class)
|
||||||
@Desc("The palette of blocks to be used in this deposit generator")
|
@Desc("The palette of blocks to be used in this deposit generator")
|
||||||
@@ -90,35 +99,62 @@ public class IrisDepositGenerator {
|
|||||||
|
|
||||||
return objectsf;
|
return objectsf;
|
||||||
});
|
});
|
||||||
return objects.get(rng.i(0, objects.size() - 1));
|
return objects.get(rng.i(0, objects.size()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getMaxDimension() {
|
public int getMaxDimension() {
|
||||||
return Math.min(11, (int) Math.round(Math.pow(maxSize, 1D / 3D)));
|
return Math.min(11, (int) Math.ceil(Math.cbrt(maxSize)));
|
||||||
}
|
}
|
||||||
|
|
||||||
private IrisObject generateClumpObject(RNG rngv, IrisData rdata) {
|
private IrisObject generateClumpObject(RNG rngv, IrisData rdata) {
|
||||||
int s = rngv.i(minSize, maxSize);
|
int s = rngv.i(minSize, maxSize + 1);
|
||||||
int dim = Math.min(11, (int) Math.round(Math.pow(maxSize, 1D / 3D)));
|
if (s == 1) {
|
||||||
int w = dim / 2;
|
IrisObject o = new IrisObject(1, 1, 1);
|
||||||
|
o.getBlocks().put(o.getCenter(), nextBlock(rngv, rdata));
|
||||||
|
return o;
|
||||||
|
}
|
||||||
|
|
||||||
|
int dim = Math.min(11, (int) Math.ceil(Math.cbrt(s)));
|
||||||
IrisObject o = new IrisObject(dim, dim, dim);
|
IrisObject o = new IrisObject(dim, dim, dim);
|
||||||
|
|
||||||
if (s == 1) {
|
int volume = dim * dim * dim;
|
||||||
o.getBlocks().put(o.getCenter(), nextBlock(rngv, rdata));
|
if (s >= volume) {
|
||||||
} else {
|
int x = 0, y = 0, z = 0;
|
||||||
while (s > 0) {
|
|
||||||
s--;
|
while (z < dim) {
|
||||||
BlockVector ang = new BlockVector(rngv.i(-w, w), rngv.i(-w, w), rngv.i(-w, w));
|
o.setUnsigned(x++, y, z, nextBlock(rngv, rdata));
|
||||||
BlockVector pos = o.getCenter().clone().add(ang).toBlockVector();
|
|
||||||
o.getBlocks().put(pos, nextBlock(rngv, rdata));
|
if (x == dim) {
|
||||||
|
x = 0;
|
||||||
|
y++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (y == dim) {
|
||||||
|
y = 0;
|
||||||
|
z++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return o;
|
||||||
|
}
|
||||||
|
|
||||||
|
KSet<BlockPosition> set = new KSet<>();
|
||||||
|
while (s > 0) {
|
||||||
|
BlockPosition ang = new BlockPosition(
|
||||||
|
rngv.i(0, dim),
|
||||||
|
rngv.i(0, dim),
|
||||||
|
rngv.i(0, dim)
|
||||||
|
);
|
||||||
|
if (!set.add(ang)) continue;
|
||||||
|
|
||||||
|
s--;
|
||||||
|
o.setUnsigned(ang.getX(), ang.getY(), ang.getZ(), nextBlock(rngv, rdata));
|
||||||
}
|
}
|
||||||
|
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
|
|
||||||
private BlockData nextBlock(RNG rngv, IrisData rdata) {
|
private BlockData nextBlock(RNG rngv, IrisData rdata) {
|
||||||
return getBlockData(rdata).get(rngv.i(0, getBlockData(rdata).size() - 1));
|
return getBlockData(rdata).get(rngv.i(0, getBlockData(rdata).size()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public KList<BlockData> getBlockData(IrisData rdata) {
|
public KList<BlockData> getBlockData(IrisData rdata) {
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ package com.volmit.iris.engine.object;
|
|||||||
import com.volmit.iris.Iris;
|
import com.volmit.iris.Iris;
|
||||||
import com.volmit.iris.core.loader.IrisData;
|
import com.volmit.iris.core.loader.IrisData;
|
||||||
import com.volmit.iris.core.loader.IrisRegistrant;
|
import com.volmit.iris.core.loader.IrisRegistrant;
|
||||||
|
import com.volmit.iris.core.nms.INMS;
|
||||||
import com.volmit.iris.core.nms.datapack.IDataFixer;
|
import com.volmit.iris.core.nms.datapack.IDataFixer;
|
||||||
import com.volmit.iris.engine.data.cache.AtomicCache;
|
import com.volmit.iris.engine.data.cache.AtomicCache;
|
||||||
import com.volmit.iris.engine.object.annotations.*;
|
import com.volmit.iris.engine.object.annotations.*;
|
||||||
@@ -309,6 +310,8 @@ public class IrisDimension extends IrisRegistrant {
|
|||||||
@MaxNumber(318)
|
@MaxNumber(318)
|
||||||
@Desc("The Subterrain Fluid Layer Height")
|
@Desc("The Subterrain Fluid Layer Height")
|
||||||
private int caveLavaHeight = 8;
|
private int caveLavaHeight = 8;
|
||||||
|
@Desc("Static Placements for objects and structures")
|
||||||
|
private IrisStaticPlacements staticPlacements = new IrisStaticPlacements();
|
||||||
|
|
||||||
public int getMaxHeight() {
|
public int getMaxHeight() {
|
||||||
return (int) getDimensionHeight().getMax();
|
return (int) getDimensionHeight().getMax();
|
||||||
@@ -487,10 +490,10 @@ public class IrisDimension extends IrisRegistrant {
|
|||||||
{
|
{
|
||||||
"pack": {
|
"pack": {
|
||||||
"description": "Iris Data Pack. This pack contains all installed Iris Packs' resources.",
|
"description": "Iris Data Pack. This pack contains all installed Iris Packs' resources.",
|
||||||
"pack_format": 10
|
"pack_format": {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
""");
|
""".replace("{}", INMS.get().getDataVersion().getPackFormat() + ""));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Iris.reportError(e);
|
Iris.reportError(e);
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|||||||
@@ -271,7 +271,7 @@ public class IrisEntity extends IrisRegistrant {
|
|||||||
|
|
||||||
for (String fi : getLoot().getTables()) {
|
for (String fi : getLoot().getTables()) {
|
||||||
IrisLootTable i = gen.getData().getLootLoader().load(fi);
|
IrisLootTable i = gen.getData().getLootLoader().load(fi);
|
||||||
items.addAll(i.getLoot(gen.isStudio(), rng.nextParallelRNG(345911), InventorySlotType.STORAGE, finalAt.getBlockX(), finalAt.getBlockY(), finalAt.getBlockZ()));
|
items.addAll(i.getLoot(gen.isStudio(), rng.nextParallelRNG(345911), InventorySlotType.STORAGE, finalAt.getWorld(), finalAt.getBlockX(), finalAt.getBlockY(), finalAt.getBlockZ()));
|
||||||
}
|
}
|
||||||
|
|
||||||
return items;
|
return items;
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import com.volmit.iris.Iris;
|
|||||||
import com.volmit.iris.core.loader.IrisRegistrant;
|
import com.volmit.iris.core.loader.IrisRegistrant;
|
||||||
import com.volmit.iris.engine.data.cache.AtomicCache;
|
import com.volmit.iris.engine.data.cache.AtomicCache;
|
||||||
import com.volmit.iris.engine.object.annotations.*;
|
import com.volmit.iris.engine.object.annotations.*;
|
||||||
|
import com.volmit.iris.engine.object.annotations.functions.StructureKeyFunction;
|
||||||
import com.volmit.iris.util.collection.KList;
|
import com.volmit.iris.util.collection.KList;
|
||||||
import com.volmit.iris.util.json.JSONObject;
|
import com.volmit.iris.util.json.JSONObject;
|
||||||
import com.volmit.iris.util.plugin.VolmitSender;
|
import com.volmit.iris.util.plugin.VolmitSender;
|
||||||
@@ -73,6 +74,9 @@ public class IrisJigsawStructure extends IrisRegistrant {
|
|||||||
@Desc("The minecraft key to use when creating treasure maps")
|
@Desc("The minecraft key to use when creating treasure maps")
|
||||||
private String structureKey = null;
|
private String structureKey = null;
|
||||||
|
|
||||||
|
@Desc("Force Place the whole structure")
|
||||||
|
private boolean forcePlace = false;
|
||||||
|
|
||||||
private transient AtomicCache<Integer> maxDimension = new AtomicCache<>();
|
private transient AtomicCache<Integer> maxDimension = new AtomicCache<>();
|
||||||
|
|
||||||
private void loadPool(String p, KList<String> pools, KList<String> pieces) {
|
private void loadPool(String p, KList<String> pools, KList<String> pieces) {
|
||||||
@@ -141,7 +145,7 @@ public class IrisJigsawStructure extends IrisRegistrant {
|
|||||||
avg += getLoader().getJigsawPieceLoader().load(i).getMax2dDimension();
|
avg += getLoader().getJigsawPieceLoader().load(i).getMax2dDimension();
|
||||||
}
|
}
|
||||||
|
|
||||||
return (avg / (pieces.size() > 0 ? pieces.size() : 1)) * (((getMaxDepth() + 1) * 2) + 1);
|
return (avg / (!pieces.isEmpty() ? pieces.size() : 1)) * (((getMaxDepth() + 1) * 2) + 1);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,5 +27,7 @@ public enum IrisLootMode {
|
|||||||
@Desc("Clear all loot tables then add this table")
|
@Desc("Clear all loot tables then add this table")
|
||||||
CLEAR,
|
CLEAR,
|
||||||
@Desc("Replace all loot tables with this table (same as clear)")
|
@Desc("Replace all loot tables with this table (same as clear)")
|
||||||
REPLACE
|
REPLACE,
|
||||||
|
@Desc("Only use when there was no loot table defined by an object")
|
||||||
|
FALLBACK
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ import lombok.EqualsAndHashCode;
|
|||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
import lombok.experimental.Accessors;
|
import lombok.experimental.Accessors;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.World;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
@Accessors(chain = true)
|
@Accessors(chain = true)
|
||||||
@@ -67,7 +68,7 @@ public class IrisLootTable extends IrisRegistrant {
|
|||||||
@ArrayType(min = 1, type = IrisLoot.class)
|
@ArrayType(min = 1, type = IrisLoot.class)
|
||||||
private KList<IrisLoot> loot = new KList<>();
|
private KList<IrisLoot> loot = new KList<>();
|
||||||
|
|
||||||
public KList<ItemStack> getLoot(boolean debug, RNG rng, InventorySlotType slot, int x, int y, int z) {
|
public KList<ItemStack> getLoot(boolean debug, RNG rng, InventorySlotType slot, World world, int x, int y, int z) {
|
||||||
KList<ItemStack> lootf = new KList<>();
|
KList<ItemStack> lootf = new KList<>();
|
||||||
|
|
||||||
int m = 0;
|
int m = 0;
|
||||||
|
|||||||
@@ -562,7 +562,7 @@ public class IrisObject extends IrisRegistrant {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUnsigned(int x, int y, int z, Block block) {
|
public void setUnsigned(int x, int y, int z, Block block, boolean legacy) {
|
||||||
BlockVector v = getSigned(x, y, z);
|
BlockVector v = getSigned(x, y, z);
|
||||||
|
|
||||||
if (block == null) {
|
if (block == null) {
|
||||||
@@ -571,7 +571,7 @@ public class IrisObject extends IrisRegistrant {
|
|||||||
} else {
|
} else {
|
||||||
BlockData data = block.getBlockData();
|
BlockData data = block.getBlockData();
|
||||||
getBlocks().put(v, data);
|
getBlocks().put(v, data);
|
||||||
TileData state = TileData.getTileState(block);
|
TileData state = TileData.getTileState(block, legacy);
|
||||||
if (state != null) {
|
if (state != null) {
|
||||||
Iris.debug("Saved State " + v);
|
Iris.debug("Saved State " + v);
|
||||||
getStates().put(v, state);
|
getStates().put(v, state);
|
||||||
@@ -663,7 +663,18 @@ public class IrisObject extends IrisRegistrant {
|
|||||||
yrand = yrand > 0 ? rng.i(0, yrand) : yrand < 0 ? rng.i(yrand, 0) : yrand;
|
yrand = yrand > 0 ? rng.i(0, yrand) : yrand < 0 ? rng.i(yrand, 0) : yrand;
|
||||||
boolean bail = false;
|
boolean bail = false;
|
||||||
|
|
||||||
if (yv < 0) {
|
if (config.isFromBottom()) {
|
||||||
|
// todo Convert this to a mode and make it compatible with jigsaw
|
||||||
|
y = (getH() + 1) + rty;
|
||||||
|
if (!config.isForcePlace()) {
|
||||||
|
if (placer.isCarved(x, y, z) ||
|
||||||
|
placer.isCarved(x, y - 1, z) ||
|
||||||
|
placer.isCarved(x, y - 2, z) ||
|
||||||
|
placer.isCarved(x, y - 3, z)) {
|
||||||
|
bail = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (yv < 0) {
|
||||||
if (config.getMode().equals(ObjectPlaceMode.CENTER_HEIGHT) || config.getMode() == ObjectPlaceMode.CENTER_STILT) {
|
if (config.getMode().equals(ObjectPlaceMode.CENTER_HEIGHT) || config.getMode() == ObjectPlaceMode.CENTER_STILT) {
|
||||||
y = (c != null ? c.getSurface() : placer.getHighest(x, z, getLoader(), config.isUnderwater())) + rty;
|
y = (c != null ? c.getSurface() : placer.getHighest(x, z, getLoader(), config.isUnderwater())) + rty;
|
||||||
if (!config.isForcePlace()) {
|
if (!config.isForcePlace()) {
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ import org.bukkit.block.data.BlockData;
|
|||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@Desc("Represents loot within this object or jigsaw piece")
|
@Desc("Represents loot within this object or jigsaw piece")
|
||||||
@Data
|
@Data
|
||||||
public class IrisObjectLoot {
|
public class IrisObjectLoot implements IObjectLoot {
|
||||||
private final transient AtomicCache<KList<BlockData>> filterCache = new AtomicCache<>();
|
private final transient AtomicCache<KList<BlockData>> filterCache = new AtomicCache<>();
|
||||||
@ArrayType(min = 1, type = IrisBlockData.class)
|
@ArrayType(min = 1, type = IrisBlockData.class)
|
||||||
@Desc("The list of blocks this loot table should apply to")
|
@Desc("The list of blocks this loot table should apply to")
|
||||||
|
|||||||
@@ -34,9 +34,15 @@ import lombok.Data;
|
|||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
import lombok.experimental.Accessors;
|
import lombok.experimental.Accessors;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.NamespacedKey;
|
||||||
import org.bukkit.TreeType;
|
import org.bukkit.TreeType;
|
||||||
import org.bukkit.block.data.BlockData;
|
import org.bukkit.block.data.BlockData;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
@Snippet("object-placer")
|
@Snippet("object-placer")
|
||||||
@EqualsAndHashCode()
|
@EqualsAndHashCode()
|
||||||
@@ -103,6 +109,8 @@ public class IrisObjectPlacement {
|
|||||||
private boolean onwater = false;
|
private boolean onwater = false;
|
||||||
@Desc("If set to true, this object will only place parts of itself where blocks already exist. Warning: Melding is very performance intensive!")
|
@Desc("If set to true, this object will only place parts of itself where blocks already exist. Warning: Melding is very performance intensive!")
|
||||||
private boolean meld = false;
|
private boolean meld = false;
|
||||||
|
@Desc("If set to true, this object will get placed from the bottom of the world up")
|
||||||
|
private boolean fromBottom;
|
||||||
@Desc("If set to true, this object will place from the ground up instead of height checks when not y locked to the surface. This is not compatable with X and Z axis rotations (it may look off)")
|
@Desc("If set to true, this object will place from the ground up instead of height checks when not y locked to the surface. This is not compatable with X and Z axis rotations (it may look off)")
|
||||||
private boolean bottom = false;
|
private boolean bottom = false;
|
||||||
@Desc("If set to true, air will be placed before the schematic places.")
|
@Desc("If set to true, air will be placed before the schematic places.")
|
||||||
@@ -123,6 +131,9 @@ public class IrisObjectPlacement {
|
|||||||
@ArrayType(min = 1, type = IrisObjectLoot.class)
|
@ArrayType(min = 1, type = IrisObjectLoot.class)
|
||||||
@Desc("The loot tables to apply to these objects")
|
@Desc("The loot tables to apply to these objects")
|
||||||
private KList<IrisObjectLoot> loot = new KList<>();
|
private KList<IrisObjectLoot> loot = new KList<>();
|
||||||
|
@ArrayType(min = 1, type = IrisObjectVanillaLoot.class)
|
||||||
|
@Desc("The vanilla loot tables to apply to these objects")
|
||||||
|
private KList<IrisObjectVanillaLoot> vanillaLoot = new KList<>();
|
||||||
@Desc("Whether the given loot tables override any and all other loot tables available in the dimension, region or biome.")
|
@Desc("Whether the given loot tables override any and all other loot tables available in the dimension, region or biome.")
|
||||||
private boolean overrideGlobalLoot = false;
|
private boolean overrideGlobalLoot = false;
|
||||||
@Desc("This object / these objects override the following trees when they grow...")
|
@Desc("This object / these objects override the following trees when they grow...")
|
||||||
@@ -211,12 +222,22 @@ public class IrisObjectPlacement {
|
|||||||
|
|
||||||
private TableCache getCache(IrisData manager) {
|
private TableCache getCache(IrisData manager) {
|
||||||
return cache.aquire(() -> {
|
return cache.aquire(() -> {
|
||||||
|
TableCache cache = new TableCache();
|
||||||
|
|
||||||
|
cache.merge(getCache(manager, getVanillaLoot(), IrisObjectPlacement::getVanillaTable));
|
||||||
|
cache.merge(getCache(manager, getLoot(), manager.getLootLoader()::load));
|
||||||
|
|
||||||
|
return cache;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private TableCache getCache(IrisData manager, KList<? extends IObjectLoot> list, Function<String, IrisLootTable> loader) {
|
||||||
TableCache tc = new TableCache();
|
TableCache tc = new TableCache();
|
||||||
|
|
||||||
for (IrisObjectLoot loot : getLoot()) {
|
for (IObjectLoot loot : list) {
|
||||||
if (loot == null)
|
if (loot == null)
|
||||||
continue;
|
continue;
|
||||||
IrisLootTable table = manager.getLootLoader().load(loot.getName());
|
IrisLootTable table = loader.apply(loot.getName());
|
||||||
if (table == null) {
|
if (table == null) {
|
||||||
Iris.warn("Couldn't find loot table " + loot.getName());
|
Iris.warn("Couldn't find loot table " + loot.getName());
|
||||||
continue;
|
continue;
|
||||||
@@ -250,7 +271,14 @@ public class IrisObjectPlacement {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return tc;
|
return tc;
|
||||||
});
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
private static IrisVanillaLootTable getVanillaTable(String name) {
|
||||||
|
return Optional.ofNullable(NamespacedKey.fromString(name))
|
||||||
|
.map(Bukkit::getLootTable)
|
||||||
|
.map(IrisVanillaLootTable::new)
|
||||||
|
.orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -262,7 +290,6 @@ public class IrisObjectPlacement {
|
|||||||
*/
|
*/
|
||||||
public IrisLootTable getTable(BlockData data, IrisData dataManager) {
|
public IrisLootTable getTable(BlockData data, IrisData dataManager) {
|
||||||
TableCache cache = getCache(dataManager);
|
TableCache cache = getCache(dataManager);
|
||||||
|
|
||||||
if (B.isStorageChest(data)) {
|
if (B.isStorageChest(data)) {
|
||||||
IrisLootTable picked = null;
|
IrisLootTable picked = null;
|
||||||
if (cache.exact.containsKey(data.getMaterial()) && cache.exact.get(data.getMaterial()).containsKey(data)) {
|
if (cache.exact.containsKey(data.getMaterial()) && cache.exact.get(data.getMaterial()).containsKey(data)) {
|
||||||
@@ -283,5 +310,11 @@ public class IrisObjectPlacement {
|
|||||||
final transient WeightedRandom<IrisLootTable> global = new WeightedRandom<>();
|
final transient WeightedRandom<IrisLootTable> global = new WeightedRandom<>();
|
||||||
final transient KMap<Material, WeightedRandom<IrisLootTable>> basic = new KMap<>();
|
final transient KMap<Material, WeightedRandom<IrisLootTable>> basic = new KMap<>();
|
||||||
final transient KMap<Material, KMap<BlockData, WeightedRandom<IrisLootTable>>> exact = new KMap<>();
|
final transient KMap<Material, KMap<BlockData, WeightedRandom<IrisLootTable>>> exact = new KMap<>();
|
||||||
|
|
||||||
|
private void merge(TableCache other) {
|
||||||
|
global.merge(other.global);
|
||||||
|
basic.merge(other.basic, WeightedRandom::merge);
|
||||||
|
exact.merge(other.exact, (a, b) -> a.merge(b, WeightedRandom::merge));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,50 @@
|
|||||||
|
package com.volmit.iris.engine.object;
|
||||||
|
|
||||||
|
import com.volmit.iris.core.loader.IrisData;
|
||||||
|
import com.volmit.iris.engine.data.cache.AtomicCache;
|
||||||
|
import com.volmit.iris.engine.object.annotations.*;
|
||||||
|
import com.volmit.iris.engine.object.annotations.functions.LootTableKeyFunction;
|
||||||
|
import com.volmit.iris.util.collection.KList;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
import org.bukkit.block.data.BlockData;
|
||||||
|
|
||||||
|
@Snippet("object-vanilla-loot")
|
||||||
|
@Accessors(chain = true)
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Desc("Represents vanilla loot within this object or jigsaw piece")
|
||||||
|
@Data
|
||||||
|
public class IrisObjectVanillaLoot implements IObjectLoot {
|
||||||
|
private final transient AtomicCache<KList<BlockData>> filterCache = new AtomicCache<>();
|
||||||
|
@ArrayType(min = 1, type = IrisBlockData.class)
|
||||||
|
@Desc("The list of blocks this loot table should apply to")
|
||||||
|
private KList<IrisBlockData> filter = new KList<>();
|
||||||
|
@Desc("Exactly match the block data or not")
|
||||||
|
private boolean exact = false;
|
||||||
|
@Desc("The vanilla loot table key")
|
||||||
|
@Required
|
||||||
|
@RegistryListFunction(LootTableKeyFunction.class)
|
||||||
|
private String name;
|
||||||
|
@Desc("The weight of this loot table being chosen")
|
||||||
|
private int weight = 1;
|
||||||
|
|
||||||
|
public KList<BlockData> getFilter(IrisData rdata) {
|
||||||
|
return filterCache.aquire(() ->
|
||||||
|
{
|
||||||
|
KList<BlockData> b = new KList<>();
|
||||||
|
|
||||||
|
for (IrisBlockData i : filter) {
|
||||||
|
BlockData bx = i.getBlockData(rdata);
|
||||||
|
|
||||||
|
if (bx != null) {
|
||||||
|
b.add(bx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return b;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
package com.volmit.iris.engine.object;
|
||||||
|
|
||||||
|
import com.volmit.iris.core.loader.IrisData;
|
||||||
|
import com.volmit.iris.engine.mantle.MantleWriter;
|
||||||
|
import com.volmit.iris.engine.object.annotations.Desc;
|
||||||
|
import com.volmit.iris.engine.object.annotations.Required;
|
||||||
|
import com.volmit.iris.util.data.B;
|
||||||
|
import com.volmit.iris.util.data.IrisBlockData;
|
||||||
|
import com.volmit.iris.util.math.RNG;
|
||||||
|
import com.volmit.iris.util.matter.MatterStructurePOI;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Desc("Static Object Placement")
|
||||||
|
@Accessors(chain = true, fluent = true)
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class IrisStaticObjectPlacement implements IrisStaticPlacement {
|
||||||
|
@Required
|
||||||
|
@Desc("The X coordinate to spawn the object at")
|
||||||
|
private int x = 0;
|
||||||
|
@Required
|
||||||
|
@Desc("The Y coordinate to spawn the object at\nuse a value <0 to allow the placement modes to function")
|
||||||
|
private int y = 0;
|
||||||
|
@Required
|
||||||
|
@Desc("The Z coordinate to spawn the object at")
|
||||||
|
private int z = 0;
|
||||||
|
@Required
|
||||||
|
@Desc("The object placement to use")
|
||||||
|
private IrisObjectPlacement placement;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void place(MantleWriter writer, RNG rng, IrisData irisData) {
|
||||||
|
IrisObject v = placement.getScale().get(rng, placement.getObject(() -> irisData, rng));
|
||||||
|
if (v == null) return;
|
||||||
|
|
||||||
|
v.place(x, y, z, writer, placement, rng, irisData);
|
||||||
|
int id = rng.i(0, Integer.MAX_VALUE);
|
||||||
|
v.place(x, y, z, writer, placement, rng, (b, data) -> {
|
||||||
|
writer.setData(b.getX(), b.getY(), b.getZ(), v.getLoadKey() + "@" + id);
|
||||||
|
if (placement.isDolphinTarget() && placement.isUnderwater() && B.isStorageChest(data)) {
|
||||||
|
writer.setData(b.getX(), b.getY(), b.getZ(), MatterStructurePOI.BURIED_TREASURE);
|
||||||
|
}
|
||||||
|
if (data instanceof IrisBlockData d) {
|
||||||
|
writer.setData(b.getX(), b.getY(), b.getZ(), d.getCustom());
|
||||||
|
}
|
||||||
|
}, null, irisData);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package com.volmit.iris.engine.object;
|
||||||
|
|
||||||
|
import com.volmit.iris.core.loader.IrisData;
|
||||||
|
import com.volmit.iris.engine.mantle.MantleWriter;
|
||||||
|
import com.volmit.iris.util.documentation.ChunkCoordinates;
|
||||||
|
import com.volmit.iris.util.math.RNG;
|
||||||
|
|
||||||
|
public interface IrisStaticPlacement {
|
||||||
|
int x();
|
||||||
|
int y();
|
||||||
|
int z();
|
||||||
|
|
||||||
|
@ChunkCoordinates
|
||||||
|
default boolean shouldPlace(int chunkX, int chunkZ) {
|
||||||
|
return x() >> 4 == chunkX && z() >> 4 == chunkZ;
|
||||||
|
}
|
||||||
|
|
||||||
|
void place(MantleWriter writer, RNG rng, IrisData data);
|
||||||
|
}
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
package com.volmit.iris.engine.object;
|
||||||
|
|
||||||
|
|
||||||
|
import com.volmit.iris.engine.object.annotations.ArrayType;
|
||||||
|
import com.volmit.iris.engine.object.annotations.Desc;
|
||||||
|
import com.volmit.iris.util.collection.KList;
|
||||||
|
import com.volmit.iris.util.documentation.ChunkCoordinates;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
@Accessors(chain = true)
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Desc("Static Placements")
|
||||||
|
@Data
|
||||||
|
public class IrisStaticPlacements {
|
||||||
|
@Desc("List of static jigsaw structures")
|
||||||
|
@ArrayType(type = IrisStaticStructurePlacement.class)
|
||||||
|
private KList<IrisStaticStructurePlacement> structures = new KList<>();
|
||||||
|
|
||||||
|
@Desc("List of static objects")
|
||||||
|
@ArrayType(type = IrisStaticObjectPlacement.class)
|
||||||
|
private KList<IrisStaticObjectPlacement> objects = new KList<>();
|
||||||
|
|
||||||
|
@ChunkCoordinates
|
||||||
|
public KList<IrisStaticStructurePlacement> getStructures(int chunkX, int chunkZ) {
|
||||||
|
return filter(structures.stream(), chunkX, chunkZ);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ChunkCoordinates
|
||||||
|
public KList<IrisStaticObjectPlacement> getObjects(int chunkX, int chunkZ) {
|
||||||
|
return filter(objects.stream(), chunkX, chunkZ);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ChunkCoordinates
|
||||||
|
public KList<IrisStaticPlacement> getAll(int chunkX, int chunkZ) {
|
||||||
|
return filter(Stream.concat(structures.stream(), objects.stream()), chunkX, chunkZ);
|
||||||
|
}
|
||||||
|
|
||||||
|
private <T extends IrisStaticPlacement> KList<T> filter(Stream<T> stream, int chunkX, int chunkZ) {
|
||||||
|
return stream.filter(p -> p.shouldPlace(chunkX, chunkZ))
|
||||||
|
.collect(Collectors.toCollection(KList::new));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
package com.volmit.iris.engine.object;
|
||||||
|
|
||||||
|
import com.volmit.iris.Iris;
|
||||||
|
import com.volmit.iris.core.loader.IrisData;
|
||||||
|
import com.volmit.iris.engine.jigsaw.PlannedStructure;
|
||||||
|
import com.volmit.iris.engine.mantle.MantleWriter;
|
||||||
|
import com.volmit.iris.engine.object.annotations.ArrayType;
|
||||||
|
import com.volmit.iris.engine.object.annotations.Desc;
|
||||||
|
import com.volmit.iris.engine.object.annotations.RegistryListResource;
|
||||||
|
import com.volmit.iris.engine.object.annotations.Required;
|
||||||
|
import com.volmit.iris.util.collection.KList;
|
||||||
|
import com.volmit.iris.util.math.RNG;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Desc("Static Jigsaw Structure Placement")
|
||||||
|
@Accessors(chain = true, fluent = true)
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class IrisStaticStructurePlacement implements IrisStaticPlacement {
|
||||||
|
@Required
|
||||||
|
@Desc("The X coordinate to spawn the structure at")
|
||||||
|
private int x = 0;
|
||||||
|
@Required
|
||||||
|
@Desc("The Y coordinate to spawn the structure at")
|
||||||
|
private int y = 0;
|
||||||
|
@Required
|
||||||
|
@Desc("The Z coordinate to spawn the structure at")
|
||||||
|
private int z = 0;
|
||||||
|
@Required
|
||||||
|
@ArrayType(min = 1, type = String.class)
|
||||||
|
@RegistryListResource(IrisJigsawStructure.class)
|
||||||
|
@Desc("The structures to place")
|
||||||
|
private KList<String> structures;
|
||||||
|
|
||||||
|
public int maxDimension(IrisData data) {
|
||||||
|
return data.getJigsawStructureLoader().loadAll(structures)
|
||||||
|
.stream()
|
||||||
|
.mapToInt(IrisJigsawStructure::getMaxDimension)
|
||||||
|
.max()
|
||||||
|
.orElse(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void place(MantleWriter writer, RNG rng, IrisData data) {
|
||||||
|
IrisJigsawStructure jigsaw = null;
|
||||||
|
while (jigsaw == null && !structures.isEmpty()) {
|
||||||
|
String loadKey = structures.popRandom(rng);
|
||||||
|
jigsaw = data.getJigsawStructureLoader().load(loadKey);
|
||||||
|
|
||||||
|
if (jigsaw == null)
|
||||||
|
Iris.error("Jigsaw structure not found " + loadKey);
|
||||||
|
}
|
||||||
|
if (jigsaw == null) {
|
||||||
|
Iris.error("No jigsaw structure found for " + structures);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
new PlannedStructure(jigsaw, new IrisPosition(x, y, z), rng, false)
|
||||||
|
.place(writer, writer.getMantle(), writer.getEngine());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,80 @@
|
|||||||
|
package com.volmit.iris.engine.object;
|
||||||
|
|
||||||
|
import com.volmit.iris.core.loader.IrisData;
|
||||||
|
import com.volmit.iris.util.collection.KList;
|
||||||
|
import com.volmit.iris.util.math.RNG;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.loot.LootContext;
|
||||||
|
import org.bukkit.loot.LootTable;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
public class IrisVanillaLootTable extends IrisLootTable {
|
||||||
|
private final LootTable lootTable;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "Vanilla " + lootTable.getKey();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getRarity() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMaxPicked() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMinPicked() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMaxTries() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public KList<IrisLoot> getLoot() {
|
||||||
|
return new KList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public KList<ItemStack> getLoot(boolean debug, RNG rng, InventorySlotType slot, World world, int x, int y, int z) {
|
||||||
|
return new KList<>(lootTable.populateLoot(rng, new LootContext.Builder(new Location(world, x, y, z)).build()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getFolderName() {
|
||||||
|
throw new UnsupportedOperationException("VanillaLootTables do not have a folder name");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getTypeName() {
|
||||||
|
throw new UnsupportedOperationException("VanillaLootTables do not have a type name");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public File getLoadFile() {
|
||||||
|
throw new UnsupportedOperationException("VanillaLootTables do not have a load file");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IrisData getLoader() {
|
||||||
|
throw new UnsupportedOperationException("VanillaLootTables do not have a loader");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public KList<String> getPreprocessors() {
|
||||||
|
return new KList<>();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,28 +1,40 @@
|
|||||||
package com.volmit.iris.engine.object;
|
package com.volmit.iris.engine.object;
|
||||||
|
|
||||||
|
import com.volmit.iris.core.nms.container.Pair;
|
||||||
|
import com.volmit.iris.engine.data.cache.AtomicCache;
|
||||||
import com.volmit.iris.util.collection.KList;
|
import com.volmit.iris.util.collection.KList;
|
||||||
|
import com.volmit.iris.util.collection.KMap;
|
||||||
import com.volmit.iris.util.scheduling.J;
|
import com.volmit.iris.util.scheduling.J;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.NonNull;
|
||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
import org.apache.commons.io.function.IOFunction;
|
import org.apache.commons.io.function.IOFunction;
|
||||||
import org.bukkit.DyeColor;
|
import org.bukkit.*;
|
||||||
import org.bukkit.block.*;
|
import org.bukkit.block.*;
|
||||||
import org.bukkit.block.banner.Pattern;
|
import org.bukkit.block.banner.Pattern;
|
||||||
import org.bukkit.block.banner.PatternType;
|
import org.bukkit.block.banner.PatternType;
|
||||||
|
import org.bukkit.block.data.BlockData;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.io.DataInputStream;
|
import java.io.DataInputStream;
|
||||||
import java.io.DataOutputStream;
|
import java.io.DataOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.StreamSupport;
|
||||||
|
|
||||||
@ToString
|
@ToString
|
||||||
@EqualsAndHashCode(callSuper = false)
|
@EqualsAndHashCode(callSuper = false)
|
||||||
public class LegacyTileData extends TileData {
|
public class LegacyTileData extends TileData {
|
||||||
private static final Map<Integer, IOFunction<DataInputStream, Handler>> legacy = Map.of(
|
private static final Map<Integer, Pair<Builder, IOFunction<DataInputStream, Handler>>> legacy = Map.of(
|
||||||
0, SignHandler::new,
|
0, new Pair<>(SignHandler::fromBukkit, SignHandler::new),
|
||||||
1, SpawnerHandler::new,
|
1, new Pair<>(SpawnerHandler::fromBukkit, SpawnerHandler::new),
|
||||||
2, BannerHandler::new);
|
2, new Pair<>(BannerHandler::fromBukkit, BannerHandler::new));
|
||||||
|
private static final AtomicCache<Tag<Material>> SIGNS = new AtomicCache<>();
|
||||||
private final int id;
|
private final int id;
|
||||||
private final Handler handler;
|
private final Handler handler;
|
||||||
|
|
||||||
@@ -31,7 +43,39 @@ public class LegacyTileData extends TileData {
|
|||||||
var factory = legacy.get(id);
|
var factory = legacy.get(id);
|
||||||
if (factory == null)
|
if (factory == null)
|
||||||
throw new IOException("Unknown tile type: " + id);
|
throw new IOException("Unknown tile type: " + id);
|
||||||
handler = factory.apply(in);
|
handler = factory.getB().apply(in);
|
||||||
|
}
|
||||||
|
|
||||||
|
private LegacyTileData(int id, Handler handler) {
|
||||||
|
this.id = id;
|
||||||
|
this.handler = handler;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public static LegacyTileData fromBukkit(@NonNull BlockState tileState) {
|
||||||
|
var type = tileState.getType();
|
||||||
|
for (var id : legacy.keySet()) {
|
||||||
|
var factory = legacy.get(id);
|
||||||
|
var handler = factory.getA().apply(tileState, type);
|
||||||
|
if (handler != null)
|
||||||
|
return new LegacyTileData(id, handler);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NonNull KMap<String, Object> getProperties() {
|
||||||
|
return new KMap<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NonNull Material getMaterial() {
|
||||||
|
return handler.getMaterial();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isApplicable(BlockData data) {
|
||||||
|
return handler.isApplicable(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -51,12 +95,20 @@ public class LegacyTileData extends TileData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private interface Handler {
|
private interface Handler {
|
||||||
|
Material getMaterial();
|
||||||
|
boolean isApplicable(BlockData data);
|
||||||
void toBinary(DataOutputStream out) throws IOException;
|
void toBinary(DataOutputStream out) throws IOException;
|
||||||
void toBukkit(Block block);
|
void toBukkit(Block block);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@FunctionalInterface
|
||||||
|
private interface Builder {
|
||||||
|
@Nullable Handler apply(@NonNull BlockState blockState, @NonNull Material type);
|
||||||
|
}
|
||||||
|
|
||||||
@ToString
|
@ToString
|
||||||
@EqualsAndHashCode
|
@EqualsAndHashCode
|
||||||
|
@AllArgsConstructor
|
||||||
private static class SignHandler implements Handler {
|
private static class SignHandler implements Handler {
|
||||||
private final String line1;
|
private final String line1;
|
||||||
private final String line2;
|
private final String line2;
|
||||||
@@ -72,6 +124,23 @@ public class LegacyTileData extends TileData {
|
|||||||
dyeColor = DyeColor.values()[in.readByte()];
|
dyeColor = DyeColor.values()[in.readByte()];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
private static SignHandler fromBukkit(BlockState blockState, Material type) {
|
||||||
|
if (!signsTag().isTagged(type) || !(blockState instanceof Sign sign))
|
||||||
|
return null;
|
||||||
|
return new SignHandler(sign.getLine(0), sign.getLine(1), sign.getLine(2), sign.getLine(3), sign.getColor());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Material getMaterial() {
|
||||||
|
return Material.OAK_SIGN;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isApplicable(BlockData data) {
|
||||||
|
return signsTag().isTagged(data.getMaterial());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void toBinary(DataOutputStream out) throws IOException {
|
public void toBinary(DataOutputStream out) throws IOException {
|
||||||
out.writeUTF(line1);
|
out.writeUTF(line1);
|
||||||
@@ -94,6 +163,7 @@ public class LegacyTileData extends TileData {
|
|||||||
}
|
}
|
||||||
@ToString
|
@ToString
|
||||||
@EqualsAndHashCode
|
@EqualsAndHashCode
|
||||||
|
@AllArgsConstructor
|
||||||
private static class SpawnerHandler implements Handler {
|
private static class SpawnerHandler implements Handler {
|
||||||
private final EntityType type;
|
private final EntityType type;
|
||||||
|
|
||||||
@@ -101,6 +171,22 @@ public class LegacyTileData extends TileData {
|
|||||||
type = EntityType.values()[in.readShort()];
|
type = EntityType.values()[in.readShort()];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static SpawnerHandler fromBukkit(BlockState blockState, Material material) {
|
||||||
|
if (material != Material.SPAWNER || !(blockState instanceof CreatureSpawner spawner))
|
||||||
|
return null;
|
||||||
|
return new SpawnerHandler(spawner.getSpawnedType());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Material getMaterial() {
|
||||||
|
return Material.SPAWNER;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isApplicable(BlockData data) {
|
||||||
|
return data.getMaterial() == Material.SPAWNER;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void toBinary(DataOutputStream out) throws IOException {
|
public void toBinary(DataOutputStream out) throws IOException {
|
||||||
out.writeShort(type.ordinal());
|
out.writeShort(type.ordinal());
|
||||||
@@ -115,6 +201,7 @@ public class LegacyTileData extends TileData {
|
|||||||
}
|
}
|
||||||
@ToString
|
@ToString
|
||||||
@EqualsAndHashCode
|
@EqualsAndHashCode
|
||||||
|
@AllArgsConstructor
|
||||||
private static class BannerHandler implements Handler {
|
private static class BannerHandler implements Handler {
|
||||||
private final KList<Pattern> patterns;
|
private final KList<Pattern> patterns;
|
||||||
private final DyeColor baseColor;
|
private final DyeColor baseColor;
|
||||||
@@ -130,6 +217,22 @@ public class LegacyTileData extends TileData {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static BannerHandler fromBukkit(BlockState blockState, Material type) {
|
||||||
|
if (!Tag.BANNERS.isTagged(type) || !(blockState instanceof Banner banner))
|
||||||
|
return null;
|
||||||
|
return new BannerHandler(new KList<>(banner.getPatterns()), banner.getBaseColor());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Material getMaterial() {
|
||||||
|
return Material.WHITE_BANNER;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isApplicable(BlockData data) {
|
||||||
|
return Tag.BANNERS.isTagged(data.getMaterial());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void toBinary(DataOutputStream out) throws IOException {
|
public void toBinary(DataOutputStream out) throws IOException {
|
||||||
out.writeByte(baseColor.ordinal());
|
out.writeByte(baseColor.ordinal());
|
||||||
@@ -148,4 +251,32 @@ public class LegacyTileData extends TileData {
|
|||||||
banner.update();
|
banner.update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static Tag<Material> signsTag() {
|
||||||
|
return SIGNS.aquire(() -> {
|
||||||
|
var signs = Bukkit.getTag("blocks", NamespacedKey.minecraft("all_signs"), Material.class);
|
||||||
|
if (signs != null)
|
||||||
|
return signs;
|
||||||
|
return new Tag<>() {
|
||||||
|
@Override
|
||||||
|
public boolean isTagged(@NotNull Material item) {
|
||||||
|
return item.getKey().getKey().endsWith("_sign");
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public Set<Material> getValues() {
|
||||||
|
return StreamSupport.stream(Registry.MATERIAL.spliterator(), false)
|
||||||
|
.filter(this::isTagged)
|
||||||
|
.collect(Collectors.toUnmodifiableSet());
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public NamespacedKey getKey() {
|
||||||
|
return NamespacedKey.minecraft("all_signs");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,9 +53,15 @@ public class TileData implements Cloneable {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TileData getTileState(Block block) {
|
public static TileData getTileState(Block block, boolean useLegacy) {
|
||||||
if (!INMS.get().hasTile(block.getType()))
|
if (!INMS.get().hasTile(block.getType()))
|
||||||
return null;
|
return null;
|
||||||
|
if (useLegacy) {
|
||||||
|
var legacy = LegacyTileData.fromBukkit(block.getState());
|
||||||
|
if (legacy != null)
|
||||||
|
return legacy;
|
||||||
|
}
|
||||||
|
|
||||||
return new TileData().fromBukkit(block);
|
return new TileData().fromBukkit(block);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package com.volmit.iris.engine.object.annotations;
|
package com.volmit.iris.engine.object.annotations;
|
||||||
|
|
||||||
import com.volmit.iris.core.loader.IrisData;
|
|
||||||
import com.volmit.iris.engine.framework.ListFunction;
|
import com.volmit.iris.engine.framework.ListFunction;
|
||||||
import com.volmit.iris.util.collection.KList;
|
import com.volmit.iris.util.collection.KList;
|
||||||
|
|
||||||
@@ -13,5 +12,5 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
|||||||
@Retention(RUNTIME)
|
@Retention(RUNTIME)
|
||||||
@Target({PARAMETER, TYPE, FIELD})
|
@Target({PARAMETER, TYPE, FIELD})
|
||||||
public @interface RegistryListFunction {
|
public @interface RegistryListFunction {
|
||||||
Class<? extends ListFunction<IrisData, KList<String>>> value();
|
Class<? extends ListFunction<KList<String>>> value();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package com.volmit.iris.engine.object.annotations.functions;
|
||||||
|
|
||||||
|
import com.volmit.iris.core.loader.IrisData;
|
||||||
|
import com.volmit.iris.engine.framework.ListFunction;
|
||||||
|
import com.volmit.iris.util.collection.KList;
|
||||||
|
import org.bukkit.NamespacedKey;
|
||||||
|
import org.bukkit.Registry;
|
||||||
|
import org.bukkit.loot.LootTable;
|
||||||
|
import org.bukkit.loot.LootTables;
|
||||||
|
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.StreamSupport;
|
||||||
|
|
||||||
|
public class LootTableKeyFunction implements ListFunction<KList<String>> {
|
||||||
|
@Override
|
||||||
|
public String key() {
|
||||||
|
return "loot-table-key";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String fancyName() {
|
||||||
|
return "LootTable Key";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public KList<String> apply(IrisData data) {
|
||||||
|
return StreamSupport.stream(Registry.LOOT_TABLES.spliterator(), false)
|
||||||
|
.map(LootTables::getLootTable)
|
||||||
|
.map(LootTable::getKey)
|
||||||
|
.map(NamespacedKey::toString)
|
||||||
|
.collect(Collectors.toCollection(KList::new));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
package com.volmit.iris.engine.object.annotations;
|
package com.volmit.iris.engine.object.annotations.functions;
|
||||||
|
|
||||||
import com.volmit.iris.core.loader.IrisData;
|
import com.volmit.iris.core.loader.IrisData;
|
||||||
import com.volmit.iris.core.nms.INMS;
|
import com.volmit.iris.core.nms.INMS;
|
||||||
import com.volmit.iris.engine.framework.ListFunction;
|
import com.volmit.iris.engine.framework.ListFunction;
|
||||||
import com.volmit.iris.util.collection.KList;
|
import com.volmit.iris.util.collection.KList;
|
||||||
|
|
||||||
public class StructureKeyFunction implements ListFunction<IrisData, KList<String>> {
|
public class StructureKeyFunction implements ListFunction<KList<String>> {
|
||||||
@Override
|
@Override
|
||||||
public String key() {
|
public String key() {
|
||||||
return "structure-key";
|
return "structure-key";
|
||||||
@@ -80,15 +80,6 @@ public class KList<T> extends ArrayList<T> implements List<T> {
|
|||||||
return indexOf(v);
|
return indexOf(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Remove the last element
|
|
||||||
*/
|
|
||||||
public KList<T> removeLast() {
|
|
||||||
remove(last());
|
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addMultiple(T t, int c) {
|
public void addMultiple(T t, int c) {
|
||||||
for (int i = 0; i < c; i++) {
|
for (int i = 0; i < c; i++) {
|
||||||
add(t);
|
add(t);
|
||||||
@@ -496,7 +487,7 @@ public class KList<T> extends ArrayList<T> implements List<T> {
|
|||||||
return pop();
|
return pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
return remove(rng.i(0, last()));
|
return remove(rng.i(0, size()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public KList<T> sub(int f, int t) {
|
public KList<T> sub(int f, int t) {
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ import java.util.Comparator;
|
|||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import java.util.function.BiFunction;
|
||||||
|
|
||||||
@SuppressWarnings("ALL")
|
@SuppressWarnings("ALL")
|
||||||
public class KMap<K, V> extends ConcurrentHashMap<K, V> {
|
public class KMap<K, V> extends ConcurrentHashMap<K, V> {
|
||||||
@@ -151,6 +152,17 @@ public class KMap<K, V> extends ConcurrentHashMap<K, V> {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Merge with another map
|
||||||
|
*
|
||||||
|
* @param m the map to merge
|
||||||
|
* @return this map (builder)
|
||||||
|
*/
|
||||||
|
public KMap<K, V> merge(KMap<K, V> m, BiFunction<V, V, V> merger) {
|
||||||
|
m.forEach((k, v) -> merge(k, v, merger));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a copy of this map
|
* Return a copy of this map
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -810,7 +810,7 @@ public class Cuboid implements Iterable<Block>, Cloneable, ConfigurationSerializ
|
|||||||
}
|
}
|
||||||
|
|
||||||
var b = w.getBlockAt((chunk.getX() << 4) + rX, y, (chunk.getZ() << 4) + rZ);
|
var b = w.getBlockAt((chunk.getX() << 4) + rX, y, (chunk.getZ() << 4) + rZ);
|
||||||
if (++y >= maxY) {
|
if (++y > maxY) {
|
||||||
y = minY;
|
y = minY;
|
||||||
if (++rX > mX) {
|
if (++rX > mX) {
|
||||||
if (++rZ > mZ) {
|
if (++rZ > mZ) {
|
||||||
|
|||||||
@@ -42,11 +42,18 @@ public class WeightedRandom<T> {
|
|||||||
totalWeight += weight;
|
totalWeight += weight;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public WeightedRandom<T> merge(WeightedRandom<T> other) {
|
||||||
|
weightedObjects.addAll(other.weightedObjects);
|
||||||
|
totalWeight += other.totalWeight;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public T pullRandom() {
|
public T pullRandom() {
|
||||||
int pull = random.nextInt(totalWeight);
|
int pull = random.nextInt(totalWeight);
|
||||||
int index = 0;
|
int index = 0;
|
||||||
while (pull > 0) {
|
while (pull > 0) {
|
||||||
pull -= weightedObjects.get(index).getV();
|
pull -= weightedObjects.get(index).getV();
|
||||||
|
if (pull <= 0) break;
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
return weightedObjects.get(index).getK();
|
return weightedObjects.get(index).getK();
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package com.volmit.iris.util.documentation;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This Argument is exclusive
|
||||||
|
*/
|
||||||
|
public @interface Exclusive {
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package com.volmit.iris.util.documentation;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This Argument is inclusive
|
||||||
|
*/
|
||||||
|
public @interface Inclusive {
|
||||||
|
}
|
||||||
@@ -997,7 +997,10 @@ public class IrisInterpolation {
|
|||||||
return getNoise3D(method, x, y, z, rad, rad, rad, n);
|
return getNoise3D(method, x, y, z, rad, rad, rad, n);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static double getNoise(InterpolationMethod method, int x, int z, double h, NoiseProvider n) {
|
public static double getNoise(InterpolationMethod method, int x, int z, double h, NoiseProvider noise) {
|
||||||
|
HashMap<NoiseKey, Double> cache = new HashMap<>(64);
|
||||||
|
NoiseProvider n = (x1, z1) -> cache.computeIfAbsent(new NoiseKey(x1, z1), k -> noise.noise(k.x, k.z));
|
||||||
|
|
||||||
if (method.equals(InterpolationMethod.BILINEAR)) {
|
if (method.equals(InterpolationMethod.BILINEAR)) {
|
||||||
return getBilinearNoise(x, z, h, n);
|
return getBilinearNoise(x, z, h, n);
|
||||||
} else if (method.equals(InterpolationMethod.STARCAST_3)) {
|
} else if (method.equals(InterpolationMethod.STARCAST_3)) {
|
||||||
@@ -1058,4 +1061,7 @@ public class IrisInterpolation {
|
|||||||
public static double rangeScale(double amin, double amax, double bmin, double bmax, double b) {
|
public static double rangeScale(double amin, double amax, double bmin, double bmax, double b) {
|
||||||
return amin + ((amax - amin) * ((b - bmin) / (bmax - bmin)));
|
return amin + ((amax - amin) * ((b - bmin) / (bmax - bmin)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public record NoiseKey(double x, double z) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,87 @@
|
|||||||
|
package com.volmit.iris.util.io;
|
||||||
|
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.io.DataInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
|
public class CountingDataInputStream extends DataInputStream {
|
||||||
|
private final Counter counter;
|
||||||
|
|
||||||
|
private CountingDataInputStream(@NotNull InputStream in) {
|
||||||
|
super(in);
|
||||||
|
if (!(in instanceof Counter c))
|
||||||
|
throw new IllegalArgumentException("Underlying stream must be a Counter");
|
||||||
|
this.counter = c;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CountingDataInputStream wrap(@NotNull InputStream in) {
|
||||||
|
return new CountingDataInputStream(new Counter(in));
|
||||||
|
}
|
||||||
|
|
||||||
|
public long count() {
|
||||||
|
return counter.count;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void skipTo(long target) throws IOException {
|
||||||
|
skipNBytes(Math.max(target - counter.count, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
private static class Counter extends InputStream {
|
||||||
|
private final InputStream in;
|
||||||
|
private long count;
|
||||||
|
private long mark = -1;
|
||||||
|
private int markLimit = 0;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int read() throws IOException {
|
||||||
|
int i = in.read();
|
||||||
|
if (i != -1) count(1);
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int read(@NotNull byte[] b, int off, int len) throws IOException {
|
||||||
|
int i = in.read(b, off, len);
|
||||||
|
count(i);
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void count(int i) {
|
||||||
|
count += i;
|
||||||
|
if (mark == -1)
|
||||||
|
return;
|
||||||
|
|
||||||
|
markLimit -= i;
|
||||||
|
if (markLimit <= 0)
|
||||||
|
mark = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean markSupported() {
|
||||||
|
return in.markSupported();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public synchronized void mark(int readlimit) {
|
||||||
|
if (!in.markSupported()) return;
|
||||||
|
in.mark(readlimit);
|
||||||
|
mark = count;
|
||||||
|
markLimit = readlimit;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public synchronized void reset() throws IOException {
|
||||||
|
in.reset();
|
||||||
|
count = mark;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() throws IOException {
|
||||||
|
in.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -28,9 +28,7 @@ import java.security.MessageDigest;
|
|||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.zip.GZIPInputStream;
|
import java.util.zip.*;
|
||||||
import java.util.zip.ZipEntry;
|
|
||||||
import java.util.zip.ZipFile;
|
|
||||||
|
|
||||||
@SuppressWarnings("ALL")
|
@SuppressWarnings("ALL")
|
||||||
public class IO {
|
public class IO {
|
||||||
@@ -113,6 +111,45 @@ public class IO {
|
|||||||
return "¯\\_(ツ)_/¯";
|
return "¯\\_(ツ)_/¯";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String hashRecursive(File base) {
|
||||||
|
LinkedList<File> files = new LinkedList<>();
|
||||||
|
Set<File> processed = new HashSet<>();
|
||||||
|
files.add(base);
|
||||||
|
try {
|
||||||
|
CRC32 crc = new CRC32();
|
||||||
|
while (!files.isEmpty()) {
|
||||||
|
File file = files.removeFirst();
|
||||||
|
if (!processed.add(file))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (file.isDirectory()) {
|
||||||
|
File[] arr = file.listFiles();
|
||||||
|
if (arr == null)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
Arrays.parallelSort(arr, Comparator.comparing(File::getName));
|
||||||
|
files.addAll(Arrays.asList(arr));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
try (var fin = new FileInputStream(file)) {
|
||||||
|
var din = new CheckedInputStream(fin, crc);
|
||||||
|
fullTransfer(din, new VoidOutputStream(), 8192);
|
||||||
|
} catch (IOException e) {
|
||||||
|
Iris.reportError(e);
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Long.toHexString(crc.getValue());
|
||||||
|
} catch (Throwable e) {
|
||||||
|
Iris.reportError(e);
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
public static String hash(File b) {
|
public static String hash(File b) {
|
||||||
try {
|
try {
|
||||||
MessageDigest d = MessageDigest.getInstance("SHA-256");
|
MessageDigest d = MessageDigest.getInstance("SHA-256");
|
||||||
|
|||||||
@@ -471,6 +471,12 @@ public class Mantle {
|
|||||||
hyperLock.withLong(id, () -> {
|
hyperLock.withLong(id, () -> {
|
||||||
TectonicPlate m = loadedRegions.get(id);
|
TectonicPlate m = loadedRegions.get(id);
|
||||||
if (m != null) {
|
if (m != null) {
|
||||||
|
if (m.inUse()) {
|
||||||
|
Iris.debug("Tectonic Plate was added to unload while in use " + C.DARK_GREEN + m.getX() + " " + m.getZ());
|
||||||
|
if (disableClear) toUnload.remove(id);
|
||||||
|
lastUse.put(id, M.ms());
|
||||||
|
return;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
m.write(fileForRegion(dataFolder, id));
|
m.write(fileForRegion(dataFolder, id));
|
||||||
loadedRegions.remove(id);
|
loadedRegions.remove(id);
|
||||||
@@ -567,9 +573,6 @@ public class Mantle {
|
|||||||
}
|
}
|
||||||
|
|
||||||
File file = fileForRegion(dataFolder, x, z);
|
File file = fileForRegion(dataFolder, x, z);
|
||||||
if (!file.exists())
|
|
||||||
file = new File(dataFolder, file.getName().substring(".lz4b".length()));
|
|
||||||
|
|
||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
try {
|
try {
|
||||||
Iris.addPanic("reading.tectonic-plate", file.getAbsolutePath());
|
Iris.addPanic("reading.tectonic-plate", file.getAbsolutePath());
|
||||||
|
|||||||
@@ -21,14 +21,17 @@ package com.volmit.iris.util.mantle;
|
|||||||
import com.volmit.iris.Iris;
|
import com.volmit.iris.Iris;
|
||||||
import com.volmit.iris.util.documentation.ChunkCoordinates;
|
import com.volmit.iris.util.documentation.ChunkCoordinates;
|
||||||
import com.volmit.iris.util.function.Consumer4;
|
import com.volmit.iris.util.function.Consumer4;
|
||||||
|
import com.volmit.iris.util.io.CountingDataInputStream;
|
||||||
import com.volmit.iris.util.matter.IrisMatter;
|
import com.volmit.iris.util.matter.IrisMatter;
|
||||||
import com.volmit.iris.util.matter.Matter;
|
import com.volmit.iris.util.matter.Matter;
|
||||||
import com.volmit.iris.util.matter.MatterSlice;
|
import com.volmit.iris.util.matter.MatterSlice;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
import lombok.Synchronized;
|
||||||
|
|
||||||
import java.io.DataInputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.DataOutputStream;
|
import java.io.DataOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import java.util.concurrent.atomic.AtomicIntegerArray;
|
import java.util.concurrent.atomic.AtomicIntegerArray;
|
||||||
import java.util.concurrent.atomic.AtomicReferenceArray;
|
import java.util.concurrent.atomic.AtomicReferenceArray;
|
||||||
|
|
||||||
@@ -43,6 +46,7 @@ public class MantleChunk {
|
|||||||
private final int z;
|
private final int z;
|
||||||
private final AtomicIntegerArray flags;
|
private final AtomicIntegerArray flags;
|
||||||
private final AtomicReferenceArray<Matter> sections;
|
private final AtomicReferenceArray<Matter> sections;
|
||||||
|
private final AtomicInteger ref = new AtomicInteger();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a mantle chunk
|
* Create a mantle chunk
|
||||||
@@ -69,7 +73,7 @@ public class MantleChunk {
|
|||||||
* @throws IOException shit happens
|
* @throws IOException shit happens
|
||||||
* @throws ClassNotFoundException shit happens
|
* @throws ClassNotFoundException shit happens
|
||||||
*/
|
*/
|
||||||
public MantleChunk(int sectionHeight, DataInputStream din) throws IOException, ClassNotFoundException {
|
public MantleChunk(int sectionHeight, CountingDataInputStream din) throws IOException {
|
||||||
this(sectionHeight, din.readByte(), din.readByte());
|
this(sectionHeight, din.readByte(), din.readByte());
|
||||||
int s = din.readByte();
|
int s = din.readByte();
|
||||||
|
|
||||||
@@ -79,16 +83,46 @@ public class MantleChunk {
|
|||||||
|
|
||||||
for (int i = 0; i < s; i++) {
|
for (int i = 0; i < s; i++) {
|
||||||
Iris.addPanic("read.section", "Section[" + i + "]");
|
Iris.addPanic("read.section", "Section[" + i + "]");
|
||||||
if (din.readBoolean()) {
|
long size = din.readInt();
|
||||||
|
if (size == 0) continue;
|
||||||
|
long start = din.count();
|
||||||
|
|
||||||
|
try {
|
||||||
sections.set(i, Matter.readDin(din));
|
sections.set(i, Matter.readDin(din));
|
||||||
|
} catch (IOException e) {
|
||||||
|
long end = start + size;
|
||||||
|
Iris.error("Failed to read chunk section, skipping it.");
|
||||||
|
Iris.addPanic("read.byte.range", start + " " + end);
|
||||||
|
Iris.addPanic("read.byte.current", din.count() + "");
|
||||||
|
Iris.reportError(e);
|
||||||
|
e.printStackTrace();
|
||||||
|
Iris.panic();
|
||||||
|
|
||||||
|
din.skipTo(end);
|
||||||
|
TectonicPlate.addError();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean inUse() {
|
||||||
|
return ref.get() > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MantleChunk use() {
|
||||||
|
ref.incrementAndGet();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void release() {
|
||||||
|
ref.decrementAndGet();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Synchronized
|
||||||
public void flag(MantleFlag flag, boolean f) {
|
public void flag(MantleFlag flag, boolean f) {
|
||||||
flags.set(flag.ordinal(), f ? 1 : 0);
|
flags.set(flag.ordinal(), f ? 1 : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Synchronized
|
||||||
public void raiseFlag(MantleFlag flag, Runnable r) {
|
public void raiseFlag(MantleFlag flag, Runnable r) {
|
||||||
if (!isFlagged(flag)) {
|
if (!isFlagged(flag)) {
|
||||||
flag(flag, true);
|
flag(flag, true);
|
||||||
@@ -174,15 +208,22 @@ public class MantleChunk {
|
|||||||
dos.writeBoolean(flags.get(i) == 1);
|
dos.writeBoolean(flags.get(i) == 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var bytes = new ByteArrayOutputStream(8192);
|
||||||
|
var sub = new DataOutputStream(bytes);
|
||||||
for (int i = 0; i < sections.length(); i++) {
|
for (int i = 0; i < sections.length(); i++) {
|
||||||
trimSlice(i);
|
trimSlice(i);
|
||||||
|
|
||||||
if (exists(i)) {
|
if (exists(i)) {
|
||||||
dos.writeBoolean(true);
|
try {
|
||||||
Matter matter = get(i);
|
Matter matter = get(i);
|
||||||
matter.writeDos(dos);
|
matter.writeDos(sub);
|
||||||
|
dos.writeInt(bytes.size());
|
||||||
|
bytes.writeTo(dos);
|
||||||
|
} finally {
|
||||||
|
bytes.reset();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
dos.writeBoolean(false);
|
dos.writeInt(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,7 +35,8 @@ public enum MantleFlag {
|
|||||||
ETCHED,
|
ETCHED,
|
||||||
TILE,
|
TILE,
|
||||||
CUSTOM,
|
CUSTOM,
|
||||||
DISCOVERED;
|
DISCOVERED,
|
||||||
|
STATIC;
|
||||||
|
|
||||||
static StateList getStateList() {
|
static StateList getStateList() {
|
||||||
return new StateList(MantleFlag.values());
|
return new StateList(MantleFlag.values());
|
||||||
|
|||||||
@@ -21,26 +21,31 @@ package com.volmit.iris.util.mantle;
|
|||||||
import com.volmit.iris.Iris;
|
import com.volmit.iris.Iris;
|
||||||
import com.volmit.iris.engine.EnginePanic;
|
import com.volmit.iris.engine.EnginePanic;
|
||||||
import com.volmit.iris.engine.data.cache.Cache;
|
import com.volmit.iris.engine.data.cache.Cache;
|
||||||
|
import com.volmit.iris.util.collection.KSet;
|
||||||
import com.volmit.iris.util.documentation.ChunkCoordinates;
|
import com.volmit.iris.util.documentation.ChunkCoordinates;
|
||||||
import com.volmit.iris.util.format.C;
|
import com.volmit.iris.util.format.C;
|
||||||
import com.volmit.iris.util.format.Form;
|
import com.volmit.iris.util.format.Form;
|
||||||
|
import com.volmit.iris.util.io.CountingDataInputStream;
|
||||||
import com.volmit.iris.util.scheduling.PrecisionStopwatch;
|
import com.volmit.iris.util.scheduling.PrecisionStopwatch;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import net.jpountz.lz4.LZ4BlockInputStream;
|
import net.jpountz.lz4.LZ4BlockInputStream;
|
||||||
import net.jpountz.lz4.LZ4BlockOutputStream;
|
import net.jpountz.lz4.LZ4BlockOutputStream;
|
||||||
import net.jpountz.lz4.LZ4FrameInputStream;
|
|
||||||
import net.jpountz.lz4.LZ4FrameOutputStream;
|
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
import java.nio.channels.Channels;
|
||||||
|
import java.nio.channels.FileChannel;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.StandardCopyOption;
|
||||||
|
import java.nio.file.StandardOpenOption;
|
||||||
import java.util.concurrent.atomic.AtomicReferenceArray;
|
import java.util.concurrent.atomic.AtomicReferenceArray;
|
||||||
import java.util.zip.GZIPInputStream;
|
|
||||||
import java.util.zip.GZIPOutputStream;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tectonic Plates are essentially representations of regions in minecraft.
|
* Tectonic Plates are essentially representations of regions in minecraft.
|
||||||
* Tectonic Plates are fully atomic & thread safe
|
* Tectonic Plates are fully atomic & thread safe
|
||||||
*/
|
*/
|
||||||
public class TectonicPlate {
|
public class TectonicPlate {
|
||||||
|
private static final KSet<Thread> errors = new KSet<>();
|
||||||
|
|
||||||
private final int sectionHeight;
|
private final int sectionHeight;
|
||||||
private final AtomicReferenceArray<MantleChunk> chunks;
|
private final AtomicReferenceArray<MantleChunk> chunks;
|
||||||
|
|
||||||
@@ -68,33 +73,67 @@ public class TectonicPlate {
|
|||||||
* @param worldHeight the height of the world
|
* @param worldHeight the height of the world
|
||||||
* @param din the data input
|
* @param din the data input
|
||||||
* @throws IOException shit happens yo
|
* @throws IOException shit happens yo
|
||||||
* @throws ClassNotFoundException real shit bro
|
|
||||||
*/
|
*/
|
||||||
public TectonicPlate(int worldHeight, DataInputStream din) throws IOException, ClassNotFoundException {
|
public TectonicPlate(int worldHeight, CountingDataInputStream din) throws IOException {
|
||||||
this(worldHeight, din.readInt(), din.readInt());
|
this(worldHeight, din.readInt(), din.readInt());
|
||||||
|
if (!din.markSupported())
|
||||||
|
throw new IOException("Mark not supported!");
|
||||||
|
|
||||||
for (int i = 0; i < chunks.length(); i++) {
|
for (int i = 0; i < chunks.length(); i++) {
|
||||||
if (din.readBoolean()) {
|
long size = din.readInt();
|
||||||
|
if (size == 0) continue;
|
||||||
|
long start = din.count();
|
||||||
|
|
||||||
|
try {
|
||||||
Iris.addPanic("read-chunk", "Chunk[" + i + "]");
|
Iris.addPanic("read-chunk", "Chunk[" + i + "]");
|
||||||
chunks.set(i, new MantleChunk(sectionHeight, din));
|
chunks.set(i, new MantleChunk(sectionHeight, din));
|
||||||
EnginePanic.saveLast();
|
EnginePanic.saveLast();
|
||||||
|
} catch (Throwable e) {
|
||||||
|
long end = start + size;
|
||||||
|
Iris.error("Failed to read chunk, creating a new chunk instead.");
|
||||||
|
Iris.addPanic("read.byte.range", start + " " + end);
|
||||||
|
Iris.addPanic("read.byte.current", din.count() + "");
|
||||||
|
Iris.reportError(e);
|
||||||
|
e.printStackTrace();
|
||||||
|
Iris.panic();
|
||||||
|
|
||||||
|
din.skipTo(end);
|
||||||
|
TectonicPlate.addError();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TectonicPlate read(int worldHeight, File file) throws IOException, ClassNotFoundException {
|
public static TectonicPlate read(int worldHeight, File file) throws IOException {
|
||||||
FileInputStream fin = new FileInputStream(file);
|
try (FileChannel fc = FileChannel.open(file.toPath(), StandardOpenOption.READ, StandardOpenOption.WRITE, StandardOpenOption.SYNC)) {
|
||||||
DataInputStream din;
|
fc.lock();
|
||||||
if (file.getName().endsWith("ttp.lz4b")) {
|
|
||||||
|
InputStream fin = Channels.newInputStream(fc);
|
||||||
LZ4BlockInputStream lz4 = new LZ4BlockInputStream(fin);
|
LZ4BlockInputStream lz4 = new LZ4BlockInputStream(fin);
|
||||||
din = new DataInputStream(new BufferedInputStream(lz4));
|
BufferedInputStream bis = new BufferedInputStream(lz4);
|
||||||
} else {
|
try (CountingDataInputStream din = CountingDataInputStream.wrap(bis)) {
|
||||||
GZIPInputStream gzi = new GZIPInputStream(fin);
|
return new TectonicPlate(worldHeight, din);
|
||||||
din = new DataInputStream(new BufferedInputStream(gzi));
|
|
||||||
}
|
}
|
||||||
TectonicPlate p = new TectonicPlate(worldHeight, din);
|
} finally {
|
||||||
din.close();
|
if (errors.remove(Thread.currentThread())) {
|
||||||
|
File dump = Iris.instance.getDataFolder("dump", file.getName() + ".bin");
|
||||||
|
try (FileChannel fc = FileChannel.open(file.toPath(), StandardOpenOption.READ, StandardOpenOption.WRITE, StandardOpenOption.SYNC)) {
|
||||||
|
fc.lock();
|
||||||
|
|
||||||
return p;
|
InputStream fin = Channels.newInputStream(fc);
|
||||||
|
LZ4BlockInputStream lz4 = new LZ4BlockInputStream(fin);
|
||||||
|
Files.copy(lz4, dump.toPath(), StandardCopyOption.REPLACE_EXISTING);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean inUse() {
|
||||||
|
for (int i = 0; i < chunks.length(); i++) {
|
||||||
|
MantleChunk chunk = chunks.get(i);
|
||||||
|
if (chunk != null && chunk.inUse())
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -150,14 +189,10 @@ public class TectonicPlate {
|
|||||||
*/
|
*/
|
||||||
@ChunkCoordinates
|
@ChunkCoordinates
|
||||||
public MantleChunk getOrCreate(int x, int z) {
|
public MantleChunk getOrCreate(int x, int z) {
|
||||||
MantleChunk chunk = get(x, z);
|
return chunks.updateAndGet(index(x, z), chunk -> {
|
||||||
|
if (chunk != null) return chunk;
|
||||||
if (chunk == null) {
|
return new MantleChunk(sectionHeight, x & 31, z & 31);
|
||||||
chunk = new MantleChunk(sectionHeight, x & 31, z & 31);
|
});
|
||||||
chunks.set(index(x, z), chunk);
|
|
||||||
}
|
|
||||||
|
|
||||||
return chunk;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ChunkCoordinates
|
@ChunkCoordinates
|
||||||
@@ -173,19 +208,16 @@ public class TectonicPlate {
|
|||||||
*/
|
*/
|
||||||
public void write(File file) throws IOException {
|
public void write(File file) throws IOException {
|
||||||
PrecisionStopwatch p = PrecisionStopwatch.start();
|
PrecisionStopwatch p = PrecisionStopwatch.start();
|
||||||
FileOutputStream fos = new FileOutputStream(file);
|
try (FileChannel fc = FileChannel.open(file.toPath(), StandardOpenOption.READ, StandardOpenOption.WRITE, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.SYNC)) {
|
||||||
DataOutputStream dos;
|
fc.lock();
|
||||||
if (file.getName().endsWith("ttp.lz4b")) {
|
|
||||||
LZ4BlockOutputStream lz4 = new LZ4BlockOutputStream(fos);
|
OutputStream fos = Channels.newOutputStream(fc);
|
||||||
dos = new DataOutputStream(lz4);
|
try (DataOutputStream dos = new DataOutputStream(new LZ4BlockOutputStream(fos))) {
|
||||||
} else {
|
|
||||||
GZIPOutputStream gzo = new GZIPOutputStream(fos);
|
|
||||||
dos = new DataOutputStream(gzo);
|
|
||||||
}
|
|
||||||
write(dos);
|
write(dos);
|
||||||
dos.close();
|
|
||||||
Iris.debug("Saved Tectonic Plate " + C.DARK_GREEN + file.getName().split("\\Q.\\E")[0] + C.RED + " in " + Form.duration(p.getMilliseconds(), 2));
|
Iris.debug("Saved Tectonic Plate " + C.DARK_GREEN + file.getName().split("\\Q.\\E")[0] + C.RED + " in " + Form.duration(p.getMilliseconds(), 2));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write this tectonic plate to a data stream
|
* Write this tectonic plate to a data stream
|
||||||
@@ -197,15 +229,26 @@ public class TectonicPlate {
|
|||||||
dos.writeInt(x);
|
dos.writeInt(x);
|
||||||
dos.writeInt(z);
|
dos.writeInt(z);
|
||||||
|
|
||||||
|
var bytes = new ByteArrayOutputStream(8192);
|
||||||
|
var sub = new DataOutputStream(bytes);
|
||||||
for (int i = 0; i < chunks.length(); i++) {
|
for (int i = 0; i < chunks.length(); i++) {
|
||||||
MantleChunk chunk = chunks.get(i);
|
MantleChunk chunk = chunks.get(i);
|
||||||
|
|
||||||
if (chunk != null) {
|
if (chunk != null) {
|
||||||
dos.writeBoolean(true);
|
try {
|
||||||
chunk.write(dos);
|
chunk.write(sub);
|
||||||
|
dos.writeInt(bytes.size());
|
||||||
|
bytes.writeTo(dos);
|
||||||
|
} finally {
|
||||||
|
bytes.reset();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
dos.writeBoolean(false);
|
dos.writeInt(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void addError() {
|
||||||
|
errors.add(Thread.currentThread());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,9 @@
|
|||||||
|
|
||||||
package com.volmit.iris.util.math;
|
package com.volmit.iris.util.math;
|
||||||
|
|
||||||
|
import com.volmit.iris.util.documentation.Exclusive;
|
||||||
|
import com.volmit.iris.util.documentation.Inclusive;
|
||||||
|
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
@@ -89,11 +92,11 @@ public class RNG extends Random {
|
|||||||
return d() > percent;
|
return d() > percent;
|
||||||
}
|
}
|
||||||
|
|
||||||
public short si(int lowerBound, int upperBound) {
|
public short si(@Inclusive int lowerBound, @Inclusive int upperBound) {
|
||||||
return (short) (lowerBound + (nextFloat() * ((upperBound - lowerBound) + 1)));
|
return (short) (lowerBound + (nextFloat() * ((upperBound - lowerBound) + 1)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public short si(int upperBound) {
|
public short si(@Inclusive int upperBound) {
|
||||||
return si(0, upperBound);
|
return si(0, upperBound);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,11 +104,11 @@ public class RNG extends Random {
|
|||||||
return si(1);
|
return si(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public float f(float lowerBound, float upperBound) {
|
public float f(@Inclusive float lowerBound, @Exclusive float upperBound) {
|
||||||
return lowerBound + (nextFloat() * ((upperBound - lowerBound)));
|
return lowerBound + (nextFloat() * ((upperBound - lowerBound)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public float f(float upperBound) {
|
public float f(@Exclusive float upperBound) {
|
||||||
return f(0, upperBound);
|
return f(0, upperBound);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -113,7 +116,7 @@ public class RNG extends Random {
|
|||||||
return f(1);
|
return f(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public double d(double lowerBound, double upperBound) {
|
public double d(@Inclusive double lowerBound, @Exclusive double upperBound) {
|
||||||
if (lowerBound > upperBound) {
|
if (lowerBound > upperBound) {
|
||||||
return M.lerp(upperBound, lowerBound, nextDouble());
|
return M.lerp(upperBound, lowerBound, nextDouble());
|
||||||
}
|
}
|
||||||
@@ -121,7 +124,7 @@ public class RNG extends Random {
|
|||||||
return M.lerp(lowerBound, upperBound, nextDouble());
|
return M.lerp(lowerBound, upperBound, nextDouble());
|
||||||
}
|
}
|
||||||
|
|
||||||
public double d(double upperBound) {
|
public double d(@Exclusive double upperBound) {
|
||||||
return d(0, upperBound);
|
return d(0, upperBound);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -129,19 +132,19 @@ public class RNG extends Random {
|
|||||||
return d(1);
|
return d(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int i(int lowerBound, int upperBound) {
|
public int i(@Inclusive int lowerBound, @Exclusive int upperBound) {
|
||||||
return (int) Math.floor(d(lowerBound, upperBound));
|
return (int) Math.floor(d(lowerBound, upperBound));
|
||||||
}
|
}
|
||||||
|
|
||||||
public int i(int upperBound) {
|
public int i(@Exclusive int upperBound) {
|
||||||
return i(Math.min(upperBound, 0), Math.max(0, upperBound));
|
return i(Math.min(upperBound, 0), Math.max(0, upperBound));
|
||||||
}
|
}
|
||||||
|
|
||||||
public long l(long lowerBound, long upperBound) {
|
public long l(@Inclusive long lowerBound, @Exclusive long upperBound) {
|
||||||
return Math.round(d(lowerBound, upperBound));
|
return Math.round(d(lowerBound, upperBound));
|
||||||
}
|
}
|
||||||
|
|
||||||
public long l(long upperBound) {
|
public long l(@Exclusive long upperBound) {
|
||||||
return l(0, upperBound);
|
return l(0, upperBound);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,6 +23,8 @@ import com.volmit.iris.engine.object.IrisObject;
|
|||||||
import com.volmit.iris.engine.object.IrisPosition;
|
import com.volmit.iris.engine.object.IrisPosition;
|
||||||
import com.volmit.iris.util.collection.KSet;
|
import com.volmit.iris.util.collection.KSet;
|
||||||
import com.volmit.iris.util.hunk.Hunk;
|
import com.volmit.iris.util.hunk.Hunk;
|
||||||
|
import com.volmit.iris.util.io.CountingDataInputStream;
|
||||||
|
import com.volmit.iris.util.mantle.TectonicPlate;
|
||||||
import com.volmit.iris.util.math.BlockPosition;
|
import com.volmit.iris.util.math.BlockPosition;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.block.data.BlockData;
|
import org.bukkit.block.data.BlockData;
|
||||||
@@ -96,18 +98,18 @@ public interface Matter {
|
|||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Matter read(File f) throws IOException, ClassNotFoundException {
|
static Matter read(File f) throws IOException {
|
||||||
FileInputStream in = new FileInputStream(f);
|
FileInputStream in = new FileInputStream(f);
|
||||||
Matter m = read(in);
|
Matter m = read(in);
|
||||||
in.close();
|
in.close();
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Matter read(InputStream in) throws IOException, ClassNotFoundException {
|
static Matter read(InputStream in) throws IOException {
|
||||||
return read(in, (b) -> new IrisMatter(b.getX(), b.getY(), b.getZ()));
|
return read(in, (b) -> new IrisMatter(b.getX(), b.getY(), b.getZ()));
|
||||||
}
|
}
|
||||||
|
|
||||||
static Matter readDin(DataInputStream in) throws IOException, ClassNotFoundException {
|
static Matter readDin(CountingDataInputStream in) throws IOException {
|
||||||
return readDin(in, (b) -> new IrisMatter(b.getX(), b.getY(), b.getZ()));
|
return readDin(in, (b) -> new IrisMatter(b.getX(), b.getY(), b.getZ()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -120,11 +122,11 @@ public interface Matter {
|
|||||||
* @return the matter object
|
* @return the matter object
|
||||||
* @throws IOException shit happens yo
|
* @throws IOException shit happens yo
|
||||||
*/
|
*/
|
||||||
static Matter read(InputStream in, Function<BlockPosition, Matter> matterFactory) throws IOException, ClassNotFoundException {
|
static Matter read(InputStream in, Function<BlockPosition, Matter> matterFactory) throws IOException {
|
||||||
return readDin(new DataInputStream(in), matterFactory);
|
return readDin(CountingDataInputStream.wrap(in), matterFactory);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Matter readDin(DataInputStream din, Function<BlockPosition, Matter> matterFactory) throws IOException, ClassNotFoundException {
|
static Matter readDin(CountingDataInputStream din, Function<BlockPosition, Matter> matterFactory) throws IOException {
|
||||||
Matter matter = matterFactory.apply(new BlockPosition(
|
Matter matter = matterFactory.apply(new BlockPosition(
|
||||||
din.readInt(),
|
din.readInt(),
|
||||||
din.readInt(),
|
din.readInt(),
|
||||||
@@ -137,17 +139,30 @@ public interface Matter {
|
|||||||
Iris.addPanic("read.matter.header", matter.getHeader().toString());
|
Iris.addPanic("read.matter.header", matter.getHeader().toString());
|
||||||
|
|
||||||
for (int i = 0; i < sliceCount; i++) {
|
for (int i = 0; i < sliceCount; i++) {
|
||||||
|
long size = din.readInt();
|
||||||
|
if (size == 0) continue;
|
||||||
|
long start = din.count();
|
||||||
|
|
||||||
Iris.addPanic("read.matter.slice", i + "");
|
Iris.addPanic("read.matter.slice", i + "");
|
||||||
|
try {
|
||||||
String cn = din.readUTF();
|
String cn = din.readUTF();
|
||||||
Iris.addPanic("read.matter.slice.class", cn);
|
Iris.addPanic("read.matter.slice.class", cn);
|
||||||
try {
|
|
||||||
Class<?> type = Class.forName(cn);
|
Class<?> type = Class.forName(cn);
|
||||||
MatterSlice<?> slice = matter.createSlice(type, matter);
|
MatterSlice<?> slice = matter.createSlice(type, matter);
|
||||||
slice.read(din);
|
slice.read(din);
|
||||||
matter.putSlice(type, slice);
|
matter.putSlice(type, slice);
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
|
long end = start + size;
|
||||||
|
Iris.error("Failed to read matter slice, skipping it.");
|
||||||
|
Iris.addPanic("read.byte.range", start + " " + end);
|
||||||
|
Iris.addPanic("read.byte.current", din.count() + "");
|
||||||
|
Iris.reportError(e);
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
throw new IOException("Can't read class '" + cn + "' (slice count reverse at " + sliceCount + ")");
|
Iris.panic();
|
||||||
|
|
||||||
|
din.skipTo(end);
|
||||||
|
TectonicPlate.addError();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -414,8 +429,16 @@ public interface Matter {
|
|||||||
dos.writeByte(getSliceTypes().size());
|
dos.writeByte(getSliceTypes().size());
|
||||||
getHeader().write(dos);
|
getHeader().write(dos);
|
||||||
|
|
||||||
|
var bytes = new ByteArrayOutputStream(1024);
|
||||||
|
var sub = new DataOutputStream(bytes);
|
||||||
for (Class<?> i : getSliceTypes()) {
|
for (Class<?> i : getSliceTypes()) {
|
||||||
getSlice(i).write(dos);
|
try {
|
||||||
|
getSlice(i).write(sub);
|
||||||
|
dos.writeInt(bytes.size());
|
||||||
|
bytes.writeTo(dos);
|
||||||
|
} finally {
|
||||||
|
bytes.reset();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user