mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-12-26 10:39:07 +00:00
Compare commits
54 Commits
feat/stati
...
3.6.4-1.20
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8eb2287ec0 | ||
|
|
c4f0722614 | ||
|
|
7fa1484b21 | ||
|
|
1c5eb8b910 | ||
|
|
94bf530d93 | ||
|
|
686ae57b5b | ||
|
|
a911685aaf | ||
|
|
6899761ca9 | ||
|
|
a58958fd62 | ||
|
|
307f3c9158 | ||
|
|
4f275c2e06 | ||
|
|
7e4e3f3cd8 | ||
|
|
84e5add564 | ||
|
|
4d4adbb76f | ||
|
|
ff2f285784 | ||
|
|
8b1636e78a | ||
|
|
3bdad10562 | ||
|
|
ac03a977aa | ||
|
|
d7270f66e1 | ||
|
|
b220b1bffa | ||
|
|
4796fe98cb | ||
|
|
ece905ec6e | ||
|
|
53c9e7c04c | ||
|
|
29f6f52443 | ||
|
|
a778cc51a6 | ||
|
|
c6963d0cd3 | ||
|
|
489844f61b | ||
|
|
4d1b0246ca | ||
|
|
13f3511fa8 | ||
|
|
f6f2766315 | ||
|
|
56530a1245 | ||
|
|
210a1f29a7 | ||
|
|
847bf972ae | ||
|
|
e5d21fdf7e | ||
|
|
0b2fd3b358 | ||
|
|
10484d1226 | ||
|
|
ce0092c52a | ||
|
|
474e033c2b | ||
|
|
62aad1f497 | ||
|
|
32b5157682 | ||
|
|
70717ea282 | ||
|
|
15975f108c | ||
|
|
66c66e82c1 | ||
|
|
4f6da95d8e | ||
|
|
b37ccbdf01 | ||
|
|
30dbe0881a | ||
|
|
20ad4657a9 | ||
|
|
d4986f42a6 | ||
|
|
8df15c0c2d | ||
|
|
24e1c578c8 | ||
|
|
1c3bff7559 | ||
|
|
a09657b4d0 | ||
|
|
910220d3ca | ||
|
|
fc05c24e3a |
@@ -15,17 +15,17 @@ Consider supporting our development by buying Iris on spigot! We work hard to ma
|
||||
|
||||
### Command Line Builds
|
||||
|
||||
1. Install [Java JDK 17](https://www.oracle.com/java/technologies/javase/jdk17-archive-downloads.html)
|
||||
1. Install [Java JDK 21](https://www.oracle.com/java/technologies/javase/jdk21-archive-downloads.html)
|
||||
2. Set the JDK installation path to `JAVA_HOME` as an environment variable.
|
||||
* Windows
|
||||
1. Start > Type `env` and press Enter
|
||||
2. Advanced > Environment Variables
|
||||
3. Under System Variables, click `New...`
|
||||
4. Variable Name: `JAVA_HOME`
|
||||
5. Variable Value: `C:\Program Files\Java\jdk-17.0.1` (verify this exists after installing java don't just copy
|
||||
5. Variable Value: `C:\Program Files\Java\jdk-21.0.1` (verify this exists after installing java don't just copy
|
||||
the example text)
|
||||
* MacOS
|
||||
1. Run `/usr/libexec/java_home -V` and look for Java 17
|
||||
1. Run `/usr/libexec/java_home -V` and look for Java 21
|
||||
2. Run `sudo nano ~/.zshenv`
|
||||
3. Add `export JAVA_HOME=$(/usr/libexec/java_home)` as a new line
|
||||
4. Use `CTRL + X`, then Press `Y`, Then `ENTER`
|
||||
@@ -35,7 +35,7 @@ Consider supporting our development by buying Iris on spigot! We work hard to ma
|
||||
|
||||
### IDE Builds (for development)
|
||||
|
||||
* Configure ITJ Gradle to use JDK 17 (in settings, search for gradle)
|
||||
* Configure ITJ Gradle to use JDK 21 (in settings, search for gradle)
|
||||
* Add a build line in the build.gradle for your own build task to directly compile Iris into your plugins folder if you
|
||||
prefer.
|
||||
* Resync the project & run your newly created task (under the development folder in gradle tasks!)
|
||||
|
||||
@@ -32,7 +32,8 @@ plugins {
|
||||
id "de.undercouch.download" version "5.0.1"
|
||||
}
|
||||
|
||||
version '3.5.2-1.19.2-1.21.3'
|
||||
|
||||
version '3.6.3-1.20.1-1.21.4'
|
||||
|
||||
// ADD YOURSELF AS A NEW LINE IF YOU WANT YOUR OWN BUILD TASK GENERATED
|
||||
// ======================== WINDOWS =============================
|
||||
@@ -53,15 +54,13 @@ registerCustomOutputTaskUnix('CrazyDev22LT', '/home/julian/Desktop/server/plugin
|
||||
// ==============================================================
|
||||
|
||||
def NMS_BINDINGS = Map.of(
|
||||
"v1_21_R3", "1.21.4-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_R3", "1.20.4-R0.1-SNAPSHOT",
|
||||
"v1_20_R2", "1.20.2-R0.1-SNAPSHOT",
|
||||
"v1_20_R1", "1.20.1-R0.1-SNAPSHOT",
|
||||
"v1_19_R3", "1.19.4-R0.1-SNAPSHOT",
|
||||
"v1_19_R2", "1.19.3-R0.1-SNAPSHOT",
|
||||
"v1_19_R1", "1.19.2-R0.1-SNAPSHOT"
|
||||
)
|
||||
def JVM_VERSION = Map.of()
|
||||
NMS_BINDINGS.each { nms ->
|
||||
@@ -129,7 +128,7 @@ allprojects {
|
||||
annotationProcessor 'org.projectlombok:lombok:1.18.36'
|
||||
|
||||
// Shaded
|
||||
implementation 'com.dfsek:Paralithic:0.4.0'
|
||||
implementation 'com.dfsek:paralithic:0.8.1'
|
||||
implementation 'io.papermc:paperlib:1.0.5'
|
||||
implementation "net.kyori:adventure-text-minimessage:4.17.0"
|
||||
implementation 'net.kyori:adventure-platform-bukkit:4.3.4'
|
||||
|
||||
@@ -62,7 +62,7 @@ dependencies {
|
||||
|
||||
// Third Party Integrations
|
||||
compileOnly 'com.ticxo.playeranimator:PlayerAnimator:R1.2.7'
|
||||
compileOnly 'com.nexomc:nexo:0.6.0-dev.0'
|
||||
compileOnly 'com.nexomc:nexo:1.0.0-dev.38'
|
||||
compileOnly 'com.github.LoneDev6:api-itemsadder:3.4.1-r4'
|
||||
compileOnly 'com.github.PlaceholderAPI:placeholderapi:2.11.3'
|
||||
compileOnly 'com.github.Ssomar-Developement:SCore:4.23.10.8'
|
||||
|
||||
@@ -32,8 +32,10 @@ import com.volmit.iris.core.nms.v1X.NMSBinding1X;
|
||||
import com.volmit.iris.core.pregenerator.LazyPregenerator;
|
||||
import com.volmit.iris.core.service.StudioSVC;
|
||||
import com.volmit.iris.core.tools.IrisToolbelt;
|
||||
import com.volmit.iris.core.tools.IrisWorldCreator;
|
||||
import com.volmit.iris.engine.EnginePanic;
|
||||
import com.volmit.iris.engine.object.IrisCompat;
|
||||
import com.volmit.iris.engine.object.IrisContextInjector;
|
||||
import com.volmit.iris.engine.object.IrisDimension;
|
||||
import com.volmit.iris.engine.object.IrisWorld;
|
||||
import com.volmit.iris.engine.platform.BukkitChunkGenerator;
|
||||
@@ -101,8 +103,6 @@ import static com.volmit.iris.core.safeguard.ServerBootSFG.passedserversoftware;
|
||||
|
||||
@SuppressWarnings("CanBeFinal")
|
||||
public class Iris extends VolmitPlugin implements Listener {
|
||||
public static final String OVERWORLD_TAG = "31000";
|
||||
|
||||
private static final Queue<Runnable> syncJobs = new ShurikenQueue<>();
|
||||
|
||||
public static Iris instance;
|
||||
@@ -467,6 +467,7 @@ public class Iris extends VolmitPlugin implements Listener {
|
||||
configWatcher = new FileWatcher(getDataFile("settings.json"));
|
||||
services.values().forEach(IrisService::onEnable);
|
||||
services.values().forEach(this::registerListener);
|
||||
registerListener(new IrisContextInjector());
|
||||
J.s(() -> {
|
||||
J.a(() -> PaperLib.suggestPaper(this));
|
||||
J.a(() -> IO.delete(getTemp()));
|
||||
@@ -516,10 +517,10 @@ public class Iris extends VolmitPlugin implements Listener {
|
||||
Iris.info("Loading World: %s | Generator: %s", s, generator);
|
||||
|
||||
Iris.info(C.LIGHT_PURPLE + "Preparing Spawn for " + s + "' using Iris:" + generator + "...");
|
||||
new WorldCreator(s)
|
||||
WorldCreator c = new WorldCreator(s)
|
||||
.generator(getDefaultWorldGenerator(s, generator))
|
||||
.environment(IrisData.loadAnyDimension(generator).getEnvironment())
|
||||
.createWorld();
|
||||
.environment(IrisData.loadAnyDimension(generator).getEnvironment());
|
||||
INMS.get().createWorld(c);
|
||||
Iris.info(C.LIGHT_PURPLE + "Loaded " + s + "!");
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
@@ -672,10 +673,12 @@ public class Iris extends VolmitPlugin implements Listener {
|
||||
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());
|
||||
.map(PlatformChunkGenerator::getEngine)
|
||||
.collect(Collectors.toMap(engine -> engine.getDimension().getLoadKey(), engine -> {
|
||||
var hash32 = engine.getHash32().getNow(null);
|
||||
if (hash32 == null) return Map.of();
|
||||
int version = engine.getDimension().getVersion();
|
||||
String checksum = Long.toHexString(hash32);
|
||||
|
||||
return Map.of("v" + version + " (" + checksum + ")", 1);
|
||||
}, (a, b) -> {
|
||||
@@ -777,7 +780,7 @@ public class Iris extends VolmitPlugin implements Listener {
|
||||
service(StudioSVC.class).installIntoWorld(getSender(), dim.getLoadKey(), w.worldFolder());
|
||||
}
|
||||
|
||||
return new BukkitChunkGenerator(w, false, ff, dim.getLoadKey(), false);
|
||||
return new BukkitChunkGenerator(w, false, ff, dim.getLoadKey());
|
||||
}
|
||||
|
||||
public void splash() {
|
||||
|
||||
@@ -181,6 +181,7 @@ public class IrisSettings {
|
||||
public boolean splashLogoStartup = true;
|
||||
public boolean useConsoleCustomColors = true;
|
||||
public boolean useCustomColorsIngame = true;
|
||||
public boolean adjustVanillaHeight = false;
|
||||
public String forceMainWorld = "";
|
||||
public int spinh = -20;
|
||||
public int spins = 7;
|
||||
|
||||
@@ -28,20 +28,27 @@ import com.volmit.iris.engine.object.IrisBiomeCustom;
|
||||
import com.volmit.iris.engine.object.IrisDimension;
|
||||
import com.volmit.iris.engine.object.IrisRange;
|
||||
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.format.C;
|
||||
import com.volmit.iris.util.plugin.VolmitSender;
|
||||
import com.volmit.iris.util.scheduling.J;
|
||||
import lombok.Data;
|
||||
import lombok.NonNull;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static com.volmit.iris.core.nms.datapack.IDataFixer.Dimension.*;
|
||||
|
||||
public class ServerConfigurator {
|
||||
public static void configure() {
|
||||
@@ -84,7 +91,7 @@ public class ServerConfigurator {
|
||||
}
|
||||
}
|
||||
|
||||
private static List<File> getDatapacksFolder() {
|
||||
private static KList<File> getDatapacksFolder() {
|
||||
if (!IrisSettings.get().getGeneral().forceMainWorld.isEmpty()) {
|
||||
return new KList<File>().qadd(new File(Bukkit.getWorldContainer(), IrisSettings.get().getGeneral().forceMainWorld + "/datapacks"));
|
||||
}
|
||||
@@ -99,57 +106,17 @@ public class ServerConfigurator {
|
||||
|
||||
public static void installDataPacks(IDataFixer fixer, boolean fullInstall) {
|
||||
Iris.info("Checking Data Packs...");
|
||||
File packs = new File("plugins/Iris/packs");
|
||||
double ultimateMaxHeight = 0;
|
||||
double ultimateMinHeight = 0;
|
||||
if (packs.exists() && packs.isDirectory()) {
|
||||
for (File pack : packs.listFiles()) {
|
||||
IrisData data = IrisData.get(pack);
|
||||
if (pack.isDirectory()) {
|
||||
File dimensionsFolder = new File(pack, "dimensions");
|
||||
if (dimensionsFolder.exists() && dimensionsFolder.isDirectory()) {
|
||||
for (File file : dimensionsFolder.listFiles()) {
|
||||
if (file.isFile() && file.getName().endsWith(".json")) {
|
||||
IrisDimension dim = data.getDimensionLoader().load(file.getName().split("\\Q.\\E")[0]);
|
||||
if (ultimateMaxHeight < dim.getDimensionHeight().getMax()) {
|
||||
ultimateMaxHeight = dim.getDimensionHeight().getMax();
|
||||
}
|
||||
if (ultimateMinHeight > dim.getDimensionHeight().getMin()) {
|
||||
ultimateMinHeight = dim.getDimensionHeight().getMin();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
DimensionHeight height = new DimensionHeight(fixer);
|
||||
KList<File> folders = getDatapacksFolder();
|
||||
KMap<String, KSet<String>> biomes = new KMap<>();
|
||||
|
||||
if (packs.exists()) {
|
||||
for (File i : packs.listFiles()) {
|
||||
if (i.isDirectory()) {
|
||||
Iris.verbose("Checking Pack: " + i.getPath());
|
||||
IrisData data = IrisData.get(i);
|
||||
File dims = new File(i, "dimensions");
|
||||
|
||||
if (dims.exists()) {
|
||||
for (File j : dims.listFiles()) {
|
||||
if (j.getName().endsWith(".json")) {
|
||||
IrisDimension dim = data.getDimensionLoader().load(j.getName().split("\\Q.\\E")[0]);
|
||||
|
||||
if (dim == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Iris.verbose(" Checking Dimension " + dim.getLoadFile().getPath());
|
||||
for (File dpack : getDatapacksFolder()) {
|
||||
dim.installDataPack(fixer, () -> data, dpack, ultimateMaxHeight, ultimateMinHeight);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
allPacks().flatMap(height::merge)
|
||||
.parallel()
|
||||
.forEach(dim -> {
|
||||
Iris.verbose(" Checking Dimension " + dim.getLoadFile().getPath());
|
||||
dim.installBiomes(fixer, dim::getLoader, folders, biomes.computeIfAbsent(dim.getLoadKey(), k -> new KSet<>()));
|
||||
});
|
||||
IrisDimension.writeShared(folders, height);
|
||||
|
||||
Iris.info("Data Packs Setup!");
|
||||
|
||||
@@ -158,57 +125,40 @@ public class ServerConfigurator {
|
||||
}
|
||||
|
||||
private static void verifyDataPacksPost(boolean allowRestarting) {
|
||||
File packs = new File("plugins/Iris/packs");
|
||||
boolean bad = allPacks()
|
||||
.map(data -> {
|
||||
Iris.verbose("Checking Pack: " + data.getDataFolder().getPath());
|
||||
var loader = data.getDimensionLoader();
|
||||
return loader.loadAll(loader.getPossibleKeys())
|
||||
.stream()
|
||||
.map(ServerConfigurator::verifyDataPackInstalled)
|
||||
.toList()
|
||||
.contains(false);
|
||||
})
|
||||
.toList()
|
||||
.contains(true);
|
||||
if (!bad) return;
|
||||
|
||||
boolean bad = false;
|
||||
if (packs.exists()) {
|
||||
for (File i : packs.listFiles()) {
|
||||
if (i.isDirectory()) {
|
||||
Iris.verbose("Checking Pack: " + i.getPath());
|
||||
IrisData data = IrisData.get(i);
|
||||
File dims = new File(i, "dimensions");
|
||||
|
||||
if (dims.exists()) {
|
||||
for (File j : dims.listFiles()) {
|
||||
if (j.getName().endsWith(".json")) {
|
||||
IrisDimension dim = data.getDimensionLoader().load(j.getName().split("\\Q.\\E")[0]);
|
||||
if (allowRestarting) {
|
||||
restart();
|
||||
} else if (INMS.get().supportsDataPacks()) {
|
||||
Iris.error("============================================================================");
|
||||
Iris.error(C.ITALIC + "You need to restart your server to properly generate custom biomes.");
|
||||
Iris.error(C.ITALIC + "By continuing, Iris will use backup biomes in place of the custom biomes.");
|
||||
Iris.error("----------------------------------------------------------------------------");
|
||||
Iris.error(C.UNDERLINE + "IT IS HIGHLY RECOMMENDED YOU RESTART THE SERVER BEFORE GENERATING!");
|
||||
Iris.error("============================================================================");
|
||||
|
||||
if (dim == null) {
|
||||
Iris.error("Failed to load " + j.getPath() + " ");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!verifyDataPackInstalled(dim)) {
|
||||
bad = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (Player i : Bukkit.getOnlinePlayers()) {
|
||||
if (i.isOp() || i.hasPermission("iris.all")) {
|
||||
VolmitSender sender = new VolmitSender(i, Iris.instance.getTag("WARNING"));
|
||||
sender.sendMessage("There are some Iris Packs that have custom biomes in them");
|
||||
sender.sendMessage("You need to restart your server to use these packs.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (bad) {
|
||||
if (allowRestarting) {
|
||||
restart();
|
||||
} else if (INMS.get().supportsDataPacks()) {
|
||||
Iris.error("============================================================================");
|
||||
Iris.error(C.ITALIC + "You need to restart your server to properly generate custom biomes.");
|
||||
Iris.error(C.ITALIC + "By continuing, Iris will use backup biomes in place of the custom biomes.");
|
||||
Iris.error("----------------------------------------------------------------------------");
|
||||
Iris.error(C.UNDERLINE + "IT IS HIGHLY RECOMMENDED YOU RESTART THE SERVER BEFORE GENERATING!");
|
||||
Iris.error("============================================================================");
|
||||
|
||||
for (Player i : Bukkit.getOnlinePlayers()) {
|
||||
if (i.isOp() || i.hasPermission("iris.all")) {
|
||||
VolmitSender sender = new VolmitSender(i, Iris.instance.getTag("WARNING"));
|
||||
sender.sendMessage("There are some Iris Packs that have custom biomes in them");
|
||||
sender.sendMessage("You need to restart your server to use these packs.");
|
||||
}
|
||||
}
|
||||
|
||||
J.sleep(3000);
|
||||
}
|
||||
J.sleep(3000);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -218,7 +168,7 @@ public class ServerConfigurator {
|
||||
Iris.warn("This will only happen when your pack changes (updates/first time setup)");
|
||||
Iris.warn("(You can disable this auto restart in iris settings)");
|
||||
J.s(() -> {
|
||||
Iris.warn("Looks like the restart command diddn't work. Stopping the server instead!");
|
||||
Iris.warn("Looks like the restart command didn't work. Stopping the server instead!");
|
||||
Bukkit.shutdown();
|
||||
}, 100);
|
||||
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "restart");
|
||||
@@ -226,22 +176,24 @@ public class ServerConfigurator {
|
||||
}
|
||||
|
||||
public static boolean verifyDataPackInstalled(IrisDimension dimension) {
|
||||
IrisData idm = IrisData.get(Iris.instance.getDataFolder("packs", dimension.getLoadKey()));
|
||||
KSet<String> keys = new KSet<>();
|
||||
boolean warn = false;
|
||||
|
||||
for (IrisBiome i : dimension.getAllBiomes(() -> idm)) {
|
||||
for (IrisBiome i : dimension.getAllBiomes(dimension::getLoader)) {
|
||||
if (i.isCustom()) {
|
||||
for (IrisBiomeCustom j : i.getCustomDerivitives()) {
|
||||
keys.add(dimension.getLoadKey() + ":" + j.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
String key = getWorld(dimension.getLoader());
|
||||
if (key == null) key = dimension.getLoadKey();
|
||||
else key += "/" + dimension.getLoadKey();
|
||||
|
||||
if (!INMS.get().supportsDataPacks()) {
|
||||
if (!keys.isEmpty()) {
|
||||
Iris.warn("===================================================================================");
|
||||
Iris.warn("Pack " + dimension.getLoadKey() + " has " + keys.size() + " custom biome(s). ");
|
||||
Iris.warn("Pack " + key + " has " + keys.size() + " custom biome(s). ");
|
||||
Iris.warn("Your server version does not yet support datapacks for iris.");
|
||||
Iris.warn("The world will generate these biomes as backup biomes.");
|
||||
Iris.warn("====================================================================================");
|
||||
@@ -260,10 +212,74 @@ public class ServerConfigurator {
|
||||
}
|
||||
|
||||
if (warn) {
|
||||
Iris.error("The Pack " + dimension.getLoadKey() + " is INCAPABLE of generating custom biomes");
|
||||
Iris.error("The Pack " + key + " is INCAPABLE of generating custom biomes");
|
||||
Iris.error("If not done automatically, restart your server before generating with this pack!");
|
||||
}
|
||||
|
||||
return !warn;
|
||||
}
|
||||
|
||||
public static Stream<IrisData> allPacks() {
|
||||
return Stream.concat(listFiles(new File("plugins/Iris/packs")),
|
||||
listFiles(Bukkit.getWorldContainer()).map(w -> new File(w, "iris/pack")))
|
||||
.filter(File::isDirectory)
|
||||
.map(IrisData::get);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static String getWorld(@NonNull IrisData data) {
|
||||
String worldContainer = Bukkit.getWorldContainer().getAbsolutePath();
|
||||
if (!worldContainer.endsWith(File.separator)) worldContainer += File.separator;
|
||||
|
||||
String path = data.getDataFolder().getAbsolutePath();
|
||||
if (!path.startsWith(worldContainer)) return null;
|
||||
int l = path.endsWith(File.separator) ? 11 : 10;
|
||||
return path.substring(worldContainer.length(), path.length() - l);
|
||||
}
|
||||
|
||||
private static Stream<File> listFiles(File parent) {
|
||||
var files = parent.listFiles();
|
||||
return files == null ? Stream.empty() : Arrays.stream(files);
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class DimensionHeight {
|
||||
private final IDataFixer fixer;
|
||||
private IrisRange overworld = new IrisRange();
|
||||
private IrisRange nether = new IrisRange();
|
||||
private IrisRange end = new IrisRange();
|
||||
private int logicalOverworld = 0;
|
||||
private int logicalNether = 0;
|
||||
private int logicalEnd = 0;
|
||||
|
||||
public Stream<IrisDimension> merge(IrisData data) {
|
||||
Iris.verbose("Checking Pack: " + data.getDataFolder().getPath());
|
||||
var loader = data.getDimensionLoader();
|
||||
return loader.loadAll(loader.getPossibleKeys())
|
||||
.stream()
|
||||
.peek(this::merge);
|
||||
}
|
||||
|
||||
public void merge(IrisDimension dimension) {
|
||||
overworld.merge(dimension.getDimensionHeight());
|
||||
nether.merge(dimension.getDimensionHeight());
|
||||
end.merge(dimension.getDimensionHeight());
|
||||
|
||||
logicalOverworld = Math.max(logicalOverworld, dimension.getLogicalHeight());
|
||||
logicalNether = Math.max(logicalNether, dimension.getLogicalHeightNether());
|
||||
logicalEnd = Math.max(logicalEnd, dimension.getLogicalHeightEnd());
|
||||
}
|
||||
|
||||
public String overworldType() {
|
||||
return fixer.createDimension(OVERRWORLD, overworld, logicalOverworld).toString(4);
|
||||
}
|
||||
|
||||
public String netherType() {
|
||||
return fixer.createDimension(NETHER, nether, logicalNether).toString(4);
|
||||
}
|
||||
|
||||
public String endType() {
|
||||
return fixer.createDimension(THE_END, end, logicalEnd).toString(4);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,9 +20,8 @@ package com.volmit.iris.core.commands;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.core.IrisSettings;
|
||||
import com.volmit.iris.core.ServerConfigurator;
|
||||
import com.volmit.iris.core.loader.IrisData;
|
||||
import com.volmit.iris.core.nms.datapack.DataVersion;
|
||||
import com.volmit.iris.core.nms.INMS;
|
||||
import com.volmit.iris.core.pregenerator.ChunkUpdater;
|
||||
import com.volmit.iris.core.service.StudioSVC;
|
||||
import com.volmit.iris.core.tools.IrisBenchmarking;
|
||||
@@ -43,9 +42,7 @@ import com.volmit.iris.util.format.C;
|
||||
import com.volmit.iris.util.format.Form;
|
||||
import com.volmit.iris.util.plugin.VolmitSender;
|
||||
import com.volmit.iris.util.scheduling.J;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Difficulty;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.WorldCreator;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
@@ -55,10 +52,8 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.generator.ChunkGenerator;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.io.Console;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@@ -94,9 +89,7 @@ public class CommandIris implements DecreeExecutor {
|
||||
@Param(aliases = "dimension", description = "The dimension type to create the world with", defaultValue = "default")
|
||||
IrisDimension type,
|
||||
@Param(description = "The seed to generate the world with", defaultValue = "1337")
|
||||
long seed,
|
||||
@Param(description = "If it should convert the dimension to match the vanilla height system.", defaultValue = "false")
|
||||
boolean vanillaheight
|
||||
long seed
|
||||
) {
|
||||
if(sender() instanceof Player) {
|
||||
if (incompatibilities.get("Multiverse-Core")) {
|
||||
@@ -140,7 +133,6 @@ public class CommandIris implements DecreeExecutor {
|
||||
.seed(seed)
|
||||
.sender(sender())
|
||||
.studio(false)
|
||||
.smartVanillaHeight(vanillaheight)
|
||||
.create();
|
||||
} catch (Throwable e) {
|
||||
sender().sendMessage(C.RED + "Exception raised during creation. See the console for more details.");
|
||||
@@ -274,6 +266,17 @@ public class CommandIris implements DecreeExecutor {
|
||||
return;
|
||||
}
|
||||
sender().sendMessage(C.GREEN + "Removing world: " + world.getName());
|
||||
|
||||
if (!IrisToolbelt.evacuate(world)) {
|
||||
sender().sendMessage(C.RED + "Failed to evacuate world: " + world.getName());
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Bukkit.unloadWorld(world, false)) {
|
||||
sender().sendMessage(C.RED + "Failed to unload world: " + world.getName());
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
if (IrisToolbelt.removeWorld(world)) {
|
||||
sender().sendMessage(C.GREEN + "Successfully removed " + world.getName() + " from bukkit.yml");
|
||||
@@ -286,27 +289,32 @@ public class CommandIris implements DecreeExecutor {
|
||||
}
|
||||
IrisToolbelt.evacuate(world, "Deleting world");
|
||||
deletingWorld = true;
|
||||
Bukkit.unloadWorld(world, false);
|
||||
int retries = 12;
|
||||
if (delete) {
|
||||
if (!delete) {
|
||||
deletingWorld = false;
|
||||
return;
|
||||
}
|
||||
VolmitSender sender = sender();
|
||||
J.a(() -> {
|
||||
int retries = 12;
|
||||
|
||||
if (deleteDirectory(world.getWorldFolder())) {
|
||||
sender().sendMessage(C.GREEN + "Successfully removed world folder");
|
||||
sender.sendMessage(C.GREEN + "Successfully removed world folder");
|
||||
} else {
|
||||
while(true){
|
||||
if (deleteDirectory(world.getWorldFolder())){
|
||||
sender().sendMessage(C.GREEN + "Successfully removed world folder");
|
||||
sender.sendMessage(C.GREEN + "Successfully removed world folder");
|
||||
break;
|
||||
}
|
||||
retries--;
|
||||
if (retries == 0){
|
||||
sender().sendMessage(C.RED + "Failed to remove world folder");
|
||||
sender.sendMessage(C.RED + "Failed to remove world folder");
|
||||
break;
|
||||
}
|
||||
J.sleep(3000);
|
||||
}
|
||||
}
|
||||
}
|
||||
deletingWorld = false;
|
||||
deletingWorld = false;
|
||||
});
|
||||
}
|
||||
|
||||
public static boolean deleteDirectory(File dir) {
|
||||
@@ -405,7 +413,7 @@ public class CommandIris implements DecreeExecutor {
|
||||
) {
|
||||
sender().sendMessage(C.GREEN + "Downloading pack: " + pack + "/" + branch + (trim ? " trimmed" : "") + (overwrite ? " overwriting" : ""));
|
||||
if (pack.equals("overworld")) {
|
||||
String url = "https://github.com/IrisDimensions/overworld/releases/download/" + Iris.OVERWORLD_TAG + "/overworld.zip";
|
||||
String url = "https://github.com/IrisDimensions/overworld/releases/download/" + INMS.OVERWORLD_TAG + "/overworld.zip";
|
||||
Iris.service(StudioSVC.class).downloadRelease(sender(), url, trim, overwrite);
|
||||
} else {
|
||||
Iris.service(StudioSVC.class).downloadSearch(sender(), "IrisDimensions/" + pack + "/" + branch, trim, overwrite);
|
||||
@@ -591,10 +599,10 @@ public class CommandIris implements DecreeExecutor {
|
||||
continue;
|
||||
}
|
||||
Iris.info(C.LIGHT_PURPLE + "Preparing Spawn for " + s + "' using Iris:" + generator + "...");
|
||||
new WorldCreator(s)
|
||||
WorldCreator c = new WorldCreator(s)
|
||||
.generator(getDefaultWorldGenerator(s, generator))
|
||||
.environment(IrisData.loadAnyDimension(generator).getEnvironment())
|
||||
.createWorld();
|
||||
.environment(IrisData.loadAnyDimension(generator).getEnvironment());
|
||||
INMS.get().createWorld(c);
|
||||
Iris.info(C.LIGHT_PURPLE + "Loaded " + s + "!");
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
@@ -649,6 +657,6 @@ public class CommandIris implements DecreeExecutor {
|
||||
ff.mkdirs();
|
||||
service(StudioSVC.class).installIntoWorld(sender, dim.getLoadKey(), ff.getParentFile());
|
||||
}
|
||||
return new BukkitChunkGenerator(w, false, ff, dim.getLoadKey(), false);
|
||||
return new BukkitChunkGenerator(w, false, ff, dim.getLoadKey());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,6 +28,8 @@ import com.volmit.iris.core.tools.IrisConverter;
|
||||
import com.volmit.iris.engine.framework.Engine;
|
||||
import com.volmit.iris.engine.object.*;
|
||||
import com.volmit.iris.util.data.Cuboid;
|
||||
import com.volmit.iris.util.data.IrisCustomData;
|
||||
import com.volmit.iris.util.data.registry.Materials;
|
||||
import com.volmit.iris.util.decree.DecreeExecutor;
|
||||
import com.volmit.iris.util.decree.DecreeOrigin;
|
||||
import com.volmit.iris.util.decree.annotations.Decree;
|
||||
@@ -36,12 +38,9 @@ import com.volmit.iris.util.decree.specialhandlers.ObjectHandler;
|
||||
import com.volmit.iris.util.format.C;
|
||||
import com.volmit.iris.util.math.Direction;
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
import com.volmit.iris.util.misc.E;
|
||||
import com.volmit.iris.util.scheduling.Queue;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.TileState;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.util.Vector;
|
||||
@@ -54,7 +53,7 @@ import java.util.*;
|
||||
@Decree(name = "object", aliases = "o", origin = DecreeOrigin.PLAYER, studio = true, description = "Iris object manipulation")
|
||||
public class CommandObject implements DecreeExecutor {
|
||||
|
||||
private static final Set<Material> skipBlocks = Set.of(E.getOrDefault(Material.class, "GRASS", "SHORT_GRASS"), Material.SNOW, Material.VINE, Material.TORCH, Material.DEAD_BUSH,
|
||||
private static final Set<Material> skipBlocks = Set.of(Materials.GRASS, Material.SNOW, Material.VINE, Material.TORCH, Material.DEAD_BUSH,
|
||||
Material.POPPY, Material.DANDELION);
|
||||
|
||||
public static IObjectPlacer createPlacer(World world, Map<Block, BlockData> futureBlockChanges) {
|
||||
@@ -79,7 +78,10 @@ public class CommandObject implements DecreeExecutor {
|
||||
|
||||
futureBlockChanges.put(block, block.getBlockData());
|
||||
|
||||
block.setBlockData(d);
|
||||
if (d instanceof IrisCustomData data) {
|
||||
block.setBlockData(data.getBase());
|
||||
Iris.warn("Tried to place custom block at " + x + ", " + y + ", " + z + " which is not supported!");
|
||||
} else block.setBlockData(d);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -30,6 +30,7 @@ import com.volmit.iris.engine.object.IrisWorld;
|
||||
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.data.registry.Attributes;
|
||||
import com.volmit.iris.util.format.Form;
|
||||
import com.volmit.iris.util.math.BlockPosition;
|
||||
import com.volmit.iris.util.math.M;
|
||||
@@ -56,6 +57,8 @@ import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
import static com.volmit.iris.util.data.registry.Attributes.MAX_HEALTH;
|
||||
|
||||
public class VisionGUI extends JPanel implements MouseWheelListener, KeyListener, MouseMotionListener, MouseInputListener {
|
||||
private static final long serialVersionUID = 2094606939770332040L;
|
||||
private final KList<LivingEntity> lastEntities = new KList<>();
|
||||
@@ -636,7 +639,7 @@ public class VisionGUI extends JPanel implements MouseWheelListener, KeyListener
|
||||
|
||||
k.add("Pos: " + h.getLocation().getBlockX() + ", " + h.getLocation().getBlockY() + ", " + h.getLocation().getBlockZ());
|
||||
k.add("UUID: " + h.getUniqueId());
|
||||
k.add("HP: " + h.getHealth() + " / " + h.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue());
|
||||
k.add("HP: " + h.getHealth() + " / " + h.getAttribute(MAX_HEALTH).getValue());
|
||||
|
||||
drawCardTR(g, k);
|
||||
}
|
||||
|
||||
@@ -55,10 +55,10 @@ public class IrisRenderer {
|
||||
IrisBiome b = renderer.getBiome((int) Math.round(x), renderer.getMaxHeight() - 1, (int) Math.round(z));
|
||||
IrisBiomeGeneratorLink g = b.getGenerators().get(0);
|
||||
Color c;
|
||||
if (g.getMax(renderer) <= 0) {
|
||||
if (g.getMax() <= 0) {
|
||||
// Max is below water level, so it is most likely an ocean biome
|
||||
c = Color.BLUE;
|
||||
} else if (g.getMin(renderer) < 0) {
|
||||
} else if (g.getMin() < 0) {
|
||||
// Min is below water level, but max is not, so it is most likely a shore biome
|
||||
c = Color.YELLOW;
|
||||
} else {
|
||||
|
||||
@@ -2,7 +2,7 @@ package com.volmit.iris.core.link;
|
||||
|
||||
import com.volmit.iris.engine.framework.Engine;
|
||||
import com.volmit.iris.util.collection.KMap;
|
||||
import com.volmit.iris.util.data.IrisBlockData;
|
||||
import com.volmit.iris.util.data.IrisCustomData;
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@@ -49,7 +49,7 @@ public abstract class ExternalDataProvider {
|
||||
* @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
|
||||
* may return {@link IrisCustomData} for blocks that need a world for placement
|
||||
* @throws MissingResourceException when the blockId is invalid
|
||||
*/
|
||||
@NotNull
|
||||
@@ -77,7 +77,7 @@ public abstract class ExternalDataProvider {
|
||||
|
||||
/**
|
||||
* 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}
|
||||
* it will only be called when the {@link ExternalDataProvider#getBlockData(Identifier, KMap)} returned a {@link IrisCustomData}
|
||||
*
|
||||
* @param engine The engine of the world the block is being placed in
|
||||
* @param block The block where the block should be placed
|
||||
|
||||
@@ -6,7 +6,7 @@ import com.volmit.iris.core.service.ExternalDataSVC;
|
||||
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.IrisBlockData;
|
||||
import com.volmit.iris.util.data.IrisCustomData;
|
||||
import com.volmit.iris.util.reflect.WrappedField;
|
||||
import com.volmit.iris.util.reflect.WrappedReturningMethod;
|
||||
import org.bukkit.Bukkit;
|
||||
@@ -64,7 +64,7 @@ public class HMCLeavesDataProvider extends ExternalDataProvider {
|
||||
BlockData blockData = Bukkit.createBlockData(material);
|
||||
if (IrisSettings.get().getGenerator().preventLeafDecay && blockData instanceof Leaves leaves)
|
||||
leaves.setPersistent(true);
|
||||
return new IrisBlockData(blockData, ExternalDataSVC.buildState(blockId, state));
|
||||
return new IrisCustomData(blockData, ExternalDataSVC.buildState(blockId, state));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -27,7 +27,7 @@ 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.data.IrisCustomData;
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
import io.lumine.mythic.bukkit.BukkitAdapter;
|
||||
import io.lumine.mythic.bukkit.utils.serialize.Chroma;
|
||||
@@ -71,7 +71,7 @@ public class MythicCrucibleDataProvider extends ExternalDataProvider {
|
||||
CustomBlockItemContext blockItemContext = crucibleItem.getBlockData();
|
||||
FurnitureItemContext furnitureItemContext = crucibleItem.getFurnitureData();
|
||||
if (furnitureItemContext != null) {
|
||||
return new IrisBlockData(B.getAir(), ExternalDataSVC.buildState(blockId, state));
|
||||
return new IrisCustomData(B.getAir(), ExternalDataSVC.buildState(blockId, state));
|
||||
} else if (blockItemContext != null) {
|
||||
return blockItemContext.getBlockData();
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ import org.bukkit.plugin.Plugin;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public class MythicMobsLink {
|
||||
|
||||
@@ -54,6 +55,6 @@ public class MythicMobsLink {
|
||||
}
|
||||
|
||||
public Collection<String> getMythicMobTypes() {
|
||||
return isEnabled() ? MythicBukkit.inst().getMobManager().getMobNames() : null;
|
||||
return isEnabled() ? MythicBukkit.inst().getMobManager().getMobNames() : List.of();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ 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.data.IrisCustomData;
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.block.Block;
|
||||
@@ -49,9 +49,9 @@ public class NexoDataProvider extends ExternalDataProvider {
|
||||
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);
|
||||
return new IrisCustomData(data, blockState);
|
||||
} else if (NexoFurniture.isFurniture(blockId.key())) {
|
||||
return new IrisBlockData(B.getAir(), blockState);
|
||||
return new IrisCustomData(B.getAir(), blockState);
|
||||
}
|
||||
|
||||
throw new MissingResourceException("Failed to find BlockData!", blockId.namespace(), blockId.key());
|
||||
@@ -125,7 +125,7 @@ public class NexoDataProvider extends ExternalDataProvider {
|
||||
@NotNull
|
||||
@Override
|
||||
public Identifier[] getBlockTypes() {
|
||||
return Arrays.stream(NexoItems.itemNames())
|
||||
return NexoItems.itemNames().stream()
|
||||
.map(i -> new Identifier("nexo", i))
|
||||
.filter(i -> {
|
||||
try {
|
||||
@@ -140,7 +140,7 @@ public class NexoDataProvider extends ExternalDataProvider {
|
||||
@NotNull
|
||||
@Override
|
||||
public Identifier[] getItemTypes() {
|
||||
return Arrays.stream(NexoItems.itemNames())
|
||||
return NexoItems.itemNames().stream()
|
||||
.map(i -> new Identifier("nexo", i))
|
||||
.filter(i -> {
|
||||
try {
|
||||
|
||||
@@ -23,19 +23,28 @@ import com.volmit.iris.core.IrisSettings;
|
||||
import com.volmit.iris.core.nms.v1X.NMSBinding1X;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class INMS {
|
||||
private static final Map<String, String> REVISION = Map.of(
|
||||
"1.20.5", "v1_20_R4",
|
||||
"1.20.6", "v1_20_R4",
|
||||
"1.21", "v1_21_R1",
|
||||
"1.21.1", "v1_21_R1",
|
||||
"1.21.2", "v1_21_R2",
|
||||
"1.21.3", "v1_21_R2"
|
||||
"1.20.5", "v1_20_R4",
|
||||
"1.20.6", "v1_20_R4",
|
||||
"1.21", "v1_21_R1",
|
||||
"1.21.1", "v1_21_R1",
|
||||
"1.21.2", "v1_21_R2",
|
||||
"1.21.3", "v1_21_R2",
|
||||
"1.21.4", "v1_21_R3"
|
||||
);
|
||||
private static final List<Version> PACKS = List.of(
|
||||
new Version(21, 4, "31010"),
|
||||
new Version(21, 2, "31000"),
|
||||
new Version(20, 1, "3910")
|
||||
);
|
||||
|
||||
//@done
|
||||
private static final INMSBinding binding = bind();
|
||||
public static final String OVERWORLD_TAG = getOverworldTag();
|
||||
|
||||
public static INMSBinding get() {
|
||||
return binding;
|
||||
@@ -86,4 +95,26 @@ public class INMS {
|
||||
|
||||
return new NMSBinding1X();
|
||||
}
|
||||
|
||||
private static String getOverworldTag() {
|
||||
var version = Bukkit.getServer().getBukkitVersion().split("-")[0].split("\\.", 3);
|
||||
int major = 0;
|
||||
int minor = 0;
|
||||
|
||||
if (version.length > 2) {
|
||||
major = Integer.parseInt(version[1]);
|
||||
minor = Integer.parseInt(version[2]);
|
||||
} else if (version.length == 2) {
|
||||
major = Integer.parseInt(version[1]);
|
||||
}
|
||||
|
||||
for (var p : PACKS) {
|
||||
if (p.major > major || p.minor > minor)
|
||||
continue;
|
||||
return p.tag;
|
||||
}
|
||||
return "3910";
|
||||
}
|
||||
|
||||
private record Version(int major, int minor, String tag) {}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,9 @@
|
||||
|
||||
package com.volmit.iris.core.nms;
|
||||
|
||||
import com.volmit.iris.core.nms.container.AutoClosing;
|
||||
import com.volmit.iris.core.nms.container.BiomeColor;
|
||||
import com.volmit.iris.core.nms.container.Pair;
|
||||
import com.volmit.iris.core.nms.datapack.DataVersion;
|
||||
import com.volmit.iris.engine.framework.Engine;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
@@ -91,7 +93,9 @@ public interface INMSBinding {
|
||||
MCABiomeContainer newBiomeContainer(int min, int max);
|
||||
|
||||
default World createWorld(WorldCreator c) {
|
||||
return c.createWorld();
|
||||
try (var ignored = injectLevelStems()) {
|
||||
return c.createWorld();
|
||||
}
|
||||
}
|
||||
|
||||
int countCustomBiomes();
|
||||
@@ -125,4 +129,12 @@ public interface INMSBinding {
|
||||
}
|
||||
|
||||
KList<String> getStructureKeys();
|
||||
|
||||
default AutoClosing injectLevelStems() {
|
||||
return new AutoClosing(() -> {});
|
||||
}
|
||||
|
||||
default Pair<Integer, AutoClosing> injectUncached(boolean overworld, boolean nether, boolean end) {
|
||||
return new Pair<>(0, injectLevelStems());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.volmit.iris.core.nms.container;
|
||||
|
||||
import com.volmit.iris.util.function.NastyRunnable;
|
||||
import lombok.AllArgsConstructor;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
@AllArgsConstructor
|
||||
public class AutoClosing implements AutoCloseable {
|
||||
private final AtomicBoolean closed = new AtomicBoolean();
|
||||
private final NastyRunnable action;
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
if (closed.getAndSet(true)) return;
|
||||
try {
|
||||
action.run();
|
||||
} catch (Throwable e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,28 @@
|
||||
package com.volmit.iris.core.nms.datapack;
|
||||
|
||||
import com.volmit.iris.engine.object.IrisBiomeCustom;
|
||||
import com.volmit.iris.engine.object.IrisRange;
|
||||
import com.volmit.iris.util.json.JSONObject;
|
||||
|
||||
public interface IDataFixer {
|
||||
|
||||
JSONObject fixCustomBiome(IrisBiomeCustom biome, JSONObject json);
|
||||
default JSONObject fixCustomBiome(IrisBiomeCustom biome, JSONObject json) {
|
||||
return json;
|
||||
}
|
||||
|
||||
JSONObject fixDimension(JSONObject json);
|
||||
JSONObject rawDimension(Dimension dimension);
|
||||
|
||||
default JSONObject createDimension(Dimension dimension, IrisRange height, int logicalHeight) {
|
||||
JSONObject obj = rawDimension(dimension);
|
||||
obj.put("min_y", height.getMin());
|
||||
obj.put("height", height.getMax() - height.getMin());
|
||||
obj.put("logical_height", logicalHeight);
|
||||
return obj;
|
||||
}
|
||||
|
||||
enum Dimension {
|
||||
OVERRWORLD,
|
||||
NETHER,
|
||||
THE_END
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,18 +1,81 @@
|
||||
package com.volmit.iris.core.nms.datapack.v1192;
|
||||
|
||||
import com.volmit.iris.core.nms.datapack.IDataFixer;
|
||||
import com.volmit.iris.engine.object.IrisBiomeCustom;
|
||||
import com.volmit.iris.util.json.JSONObject;
|
||||
import java.util.Map;
|
||||
|
||||
public class DataFixerV1192 implements IDataFixer {
|
||||
|
||||
@Override
|
||||
public JSONObject fixCustomBiome(IrisBiomeCustom biome, JSONObject json) {
|
||||
return json;
|
||||
}
|
||||
private static final Map<Dimension, String> DIMENSIONS = Map.of(
|
||||
Dimension.OVERRWORLD, """
|
||||
{
|
||||
"ambient_light": 0.0,
|
||||
"bed_works": true,
|
||||
"coordinate_scale": 1.0,
|
||||
"effects": "minecraft:overworld",
|
||||
"has_ceiling": false,
|
||||
"has_raids": true,
|
||||
"has_skylight": true,
|
||||
"infiniburn": "#minecraft:infiniburn_overworld",
|
||||
"monster_spawn_block_light_limit": 0,
|
||||
"monster_spawn_light_level": {
|
||||
"type": "minecraft:uniform",
|
||||
"value": {
|
||||
"max_inclusive": 7,
|
||||
"min_inclusive": 0
|
||||
}
|
||||
},
|
||||
"natural": true,
|
||||
"piglin_safe": false,
|
||||
"respawn_anchor_works": false,
|
||||
"ultrawarm": false
|
||||
}""",
|
||||
Dimension.NETHER, """
|
||||
{
|
||||
"ambient_light": 0.1,
|
||||
"bed_works": false,
|
||||
"coordinate_scale": 8.0,
|
||||
"effects": "minecraft:the_nether",
|
||||
"fixed_time": 18000,
|
||||
"has_ceiling": true,
|
||||
"has_raids": false,
|
||||
"has_skylight": false,
|
||||
"infiniburn": "#minecraft:infiniburn_nether",
|
||||
"monster_spawn_block_light_limit": 15,
|
||||
"monster_spawn_light_level": 7,
|
||||
"natural": false,
|
||||
"piglin_safe": true,
|
||||
"respawn_anchor_works": true,
|
||||
"ultrawarm": true
|
||||
}""",
|
||||
Dimension.THE_END, """
|
||||
{
|
||||
"ambient_light": 0.0,
|
||||
"bed_works": false,
|
||||
"coordinate_scale": 1.0,
|
||||
"effects": "minecraft:the_end",
|
||||
"fixed_time": 6000,
|
||||
"has_ceiling": false,
|
||||
"has_raids": true,
|
||||
"has_skylight": false,
|
||||
"infiniburn": "#minecraft:infiniburn_end",
|
||||
"monster_spawn_block_light_limit": 0,
|
||||
"monster_spawn_light_level": {
|
||||
"type": "minecraft:uniform",
|
||||
"value": {
|
||||
"max_inclusive": 7,
|
||||
"min_inclusive": 0
|
||||
}
|
||||
},
|
||||
"natural": false,
|
||||
"piglin_safe": false,
|
||||
"respawn_anchor_works": false,
|
||||
"ultrawarm": false
|
||||
}"""
|
||||
);
|
||||
|
||||
@Override
|
||||
public JSONObject fixDimension(JSONObject json) {
|
||||
return json;
|
||||
public JSONObject rawDimension(Dimension dimension) {
|
||||
return new JSONObject(DIMENSIONS.get(dimension));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.volmit.iris.core.nms.datapack.v1206;
|
||||
|
||||
import com.volmit.iris.core.nms.datapack.IDataFixer;
|
||||
import com.volmit.iris.core.nms.datapack.v1192.DataFixerV1192;
|
||||
import com.volmit.iris.engine.object.IrisBiomeCustom;
|
||||
import com.volmit.iris.engine.object.IrisBiomeCustomSpawn;
|
||||
import com.volmit.iris.engine.object.IrisBiomeCustomSpawnType;
|
||||
@@ -10,7 +10,7 @@ import com.volmit.iris.util.json.JSONObject;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public class DataFixerV1206 implements IDataFixer {
|
||||
public class DataFixerV1206 extends DataFixerV1192 {
|
||||
@Override
|
||||
public JSONObject fixCustomBiome(IrisBiomeCustom biome, JSONObject json) {
|
||||
int spawnRarity = biome.getSpawnRarity();
|
||||
@@ -45,7 +45,8 @@ public class DataFixerV1206 implements IDataFixer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject fixDimension(JSONObject json) {
|
||||
public JSONObject rawDimension(Dimension dimension) {
|
||||
JSONObject json = super.rawDimension(dimension);
|
||||
if (!(json.get("monster_spawn_light_level") instanceof JSONObject lightLevel))
|
||||
return json;
|
||||
var value = (JSONObject) lightLevel.remove("value");
|
||||
|
||||
@@ -37,7 +37,7 @@ public class UtilsSFG {
|
||||
}
|
||||
if (ServerBootSFG.unsuportedversion) {
|
||||
Iris.safeguard(C.RED + "Server Version");
|
||||
Iris.safeguard(C.RED + "- Iris only supports 1.19.2 > 1.21.3");
|
||||
Iris.safeguard(C.RED + "- Iris only supports 1.20.1 > 1.21.4");
|
||||
}
|
||||
if (!ServerBootSFG.passedserversoftware) {
|
||||
Iris.safeguard(C.YELLOW + "Unsupported Server Software");
|
||||
|
||||
@@ -24,6 +24,7 @@ import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.core.IrisSettings;
|
||||
import com.volmit.iris.core.ServerConfigurator;
|
||||
import com.volmit.iris.core.loader.IrisData;
|
||||
import com.volmit.iris.core.nms.INMS;
|
||||
import com.volmit.iris.core.pack.IrisPack;
|
||||
import com.volmit.iris.core.project.IrisProject;
|
||||
import com.volmit.iris.core.tools.IrisToolbelt;
|
||||
@@ -64,7 +65,7 @@ public class StudioSVC implements IrisService {
|
||||
if (!f.exists()) {
|
||||
Iris.info("Downloading Default Pack " + pack);
|
||||
if (pack.equals("overworld")) {
|
||||
String url = "https://github.com/IrisDimensions/overworld/releases/download/" + Iris.OVERWORLD_TAG + "/overworld.zip";
|
||||
String url = "https://github.com/IrisDimensions/overworld/releases/download/" + INMS.OVERWORLD_TAG + "/overworld.zip";
|
||||
Iris.service(StudioSVC.class).downloadRelease(Iris.getSender(), url, false, false);
|
||||
} else {
|
||||
downloadSearch(Iris.getSender(), pack, false);
|
||||
|
||||
@@ -27,6 +27,7 @@ import com.volmit.iris.engine.platform.PlatformChunkGenerator;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.collection.KMap;
|
||||
import com.volmit.iris.util.data.Cuboid;
|
||||
import com.volmit.iris.util.data.IrisCustomData;
|
||||
import com.volmit.iris.util.math.BlockPosition;
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
import com.volmit.iris.util.plugin.IrisService;
|
||||
@@ -34,7 +35,6 @@ import com.volmit.iris.util.scheduling.J;
|
||||
import org.bukkit.*;
|
||||
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.type.Sapling;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@@ -142,7 +142,9 @@ public class TreeSVC implements IrisService {
|
||||
public void set(int x, int y, int z, BlockData d) {
|
||||
Block b = event.getWorld().getBlockAt(x, y, z);
|
||||
BlockState state = b.getState();
|
||||
state.setBlockData(d);
|
||||
if (d instanceof IrisCustomData data)
|
||||
state.setBlockData(data.getBase());
|
||||
else state.setBlockData(d);
|
||||
blockStateList.add(b.getState());
|
||||
dataCache.put(new Location(event.getWorld(), x, y, z), d);
|
||||
}
|
||||
@@ -213,12 +215,17 @@ public class TreeSVC implements IrisService {
|
||||
block = false;
|
||||
|
||||
if (!iGrow.isCancelled()) {
|
||||
for (BlockState block : iGrow.getBlocks()) {
|
||||
Location l = block.getLocation();
|
||||
for (BlockState state : iGrow.getBlocks()) {
|
||||
Location l = state.getLocation();
|
||||
|
||||
if (dataCache.containsKey(l)) {
|
||||
l.getBlock().setBlockData(dataCache.get(l), false);
|
||||
}
|
||||
BlockData d = dataCache.get(l);
|
||||
if (d == null) continue;
|
||||
Block block = l.getBlock();
|
||||
|
||||
if (d instanceof IrisCustomData data) {
|
||||
block.setBlockData(data.getBase(), false);
|
||||
Iris.service(ExternalDataSVC.class).processUpdate(engine, block, data.getCustom());
|
||||
} else block.setBlockData(d);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -30,15 +30,12 @@ import com.volmit.iris.util.format.C;
|
||||
import com.volmit.iris.util.math.M;
|
||||
import com.volmit.iris.util.matter.Matter;
|
||||
import com.volmit.iris.util.matter.WorldMatter;
|
||||
import com.volmit.iris.util.misc.E;
|
||||
import com.volmit.iris.util.plugin.IrisService;
|
||||
import com.volmit.iris.util.plugin.VolmitSender;
|
||||
import com.volmit.iris.util.scheduling.J;
|
||||
import com.volmit.iris.util.scheduling.S;
|
||||
import com.volmit.iris.util.scheduling.SR;
|
||||
import com.volmit.iris.util.scheduling.jobs.Job;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@@ -56,11 +53,11 @@ import java.awt.Color;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import static com.volmit.iris.util.data.registry.Particles.CRIT_MAGIC;
|
||||
import static com.volmit.iris.util.data.registry.Particles.REDSTONE;
|
||||
|
||||
public class WandSVC implements IrisService {
|
||||
private static final Particle CRIT_MAGIC = E.getOrDefault(Particle.class, "CRIT_MAGIC", "CRIT");
|
||||
private static final Particle REDSTONE = E.getOrDefault(Particle.class, "REDSTONE", "DUST");
|
||||
private static final int MS_PER_TICK = Integer.parseInt(System.getProperty("iris.ms_per_tick", "30"));
|
||||
|
||||
private static ItemStack dust;
|
||||
|
||||
@@ -22,6 +22,7 @@ import com.google.common.util.concurrent.AtomicDouble;
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.core.IrisSettings;
|
||||
import com.volmit.iris.core.ServerConfigurator;
|
||||
import com.volmit.iris.core.nms.INMS;
|
||||
import com.volmit.iris.core.pregenerator.PregenTask;
|
||||
import com.volmit.iris.core.service.StudioSVC;
|
||||
import com.volmit.iris.engine.object.IrisDimension;
|
||||
@@ -83,7 +84,6 @@ public class IrisCreator {
|
||||
* Benchmark mode
|
||||
*/
|
||||
private boolean benchmark = false;
|
||||
private boolean smartVanillaHeight = false;
|
||||
|
||||
public static boolean removeFromBukkitYml(String name) throws IOException {
|
||||
YamlConfiguration yml = YamlConfiguration.loadConfiguration(BUKKIT_YML);
|
||||
@@ -137,7 +137,6 @@ public class IrisCreator {
|
||||
.name(name)
|
||||
.seed(seed)
|
||||
.studio(studio)
|
||||
.smartVanillaHeight(smartVanillaHeight)
|
||||
.create();
|
||||
ServerConfigurator.installDataPacks(false);
|
||||
|
||||
@@ -172,7 +171,7 @@ public class IrisCreator {
|
||||
|
||||
try {
|
||||
J.sfut(() -> {
|
||||
world.set(wc.createWorld());
|
||||
world.set(INMS.get().createWorld(wc));
|
||||
}).get();
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
|
||||
@@ -21,10 +21,13 @@ package com.volmit.iris.core.tools;
|
||||
import com.volmit.iris.core.loader.IrisData;
|
||||
import com.volmit.iris.engine.object.*;
|
||||
import com.volmit.iris.engine.platform.BukkitChunkGenerator;
|
||||
import com.volmit.iris.util.reflect.WrappedField;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.WorldCreator;
|
||||
import org.bukkit.WorldType;
|
||||
import org.bukkit.generator.ChunkGenerator;
|
||||
import sun.misc.Unsafe;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
@@ -32,7 +35,6 @@ public class IrisWorldCreator {
|
||||
private String name;
|
||||
private boolean studio = false;
|
||||
private String dimensionName = null;
|
||||
private boolean smartVanillaHeight = false;
|
||||
private long seed = 1337;
|
||||
|
||||
public IrisWorldCreator() {
|
||||
@@ -64,11 +66,6 @@ public class IrisWorldCreator {
|
||||
return this;
|
||||
}
|
||||
|
||||
public IrisWorldCreator smartVanillaHeight(boolean smartVanillaHeight) {
|
||||
this.smartVanillaHeight = smartVanillaHeight;
|
||||
return this;
|
||||
}
|
||||
|
||||
public WorldCreator create() {
|
||||
IrisDimension dim = IrisData.loadAnyDimension(dimensionName);
|
||||
|
||||
@@ -82,7 +79,7 @@ public class IrisWorldCreator {
|
||||
.build();
|
||||
ChunkGenerator g = new BukkitChunkGenerator(w, studio, studio
|
||||
? dim.getLoader().getDataFolder() :
|
||||
new File(w.worldFolder(), "iris/pack"), dimensionName, smartVanillaHeight);
|
||||
new File(w.worldFolder(), "iris/pack"), dimensionName);
|
||||
|
||||
|
||||
return new WorldCreator(name)
|
||||
|
||||
@@ -20,8 +20,6 @@ package com.volmit.iris.core.wand;
|
||||
|
||||
import com.volmit.iris.util.data.Cuboid;
|
||||
import com.volmit.iris.util.math.M;
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
import com.volmit.iris.util.misc.E;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -29,8 +27,9 @@ import org.bukkit.util.Vector;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
import static com.volmit.iris.util.data.registry.Particles.REDSTONE;
|
||||
|
||||
public class WandSelection {
|
||||
private static final Particle REDSTONE = E.getOrDefault(Particle.class, "REDSTONE", "DUST");
|
||||
private final Cuboid c;
|
||||
private final Player p;
|
||||
private static final double STEP = 0.10;
|
||||
|
||||
@@ -21,10 +21,10 @@ package com.volmit.iris.engine;
|
||||
import com.google.common.util.concurrent.AtomicDouble;
|
||||
import com.google.gson.Gson;
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.core.IrisSettings;
|
||||
import com.volmit.iris.core.ServerConfigurator;
|
||||
import com.volmit.iris.core.events.IrisEngineHotloadEvent;
|
||||
import com.volmit.iris.core.gui.PregeneratorJob;
|
||||
import com.volmit.iris.core.loader.ResourceLoader;
|
||||
import com.volmit.iris.core.nms.container.BlockPos;
|
||||
import com.volmit.iris.core.nms.container.Pair;
|
||||
import com.volmit.iris.core.project.IrisProject;
|
||||
@@ -53,7 +53,6 @@ import com.volmit.iris.util.scheduling.PrecisionStopwatch;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
@@ -63,11 +62,10 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(exclude = "context")
|
||||
@@ -92,6 +90,7 @@ public class IrisEngine implements Engine {
|
||||
private final AtomicBoolean cleaning;
|
||||
private final ChronoLatch cleanLatch;
|
||||
private final SeedManager seedManager;
|
||||
private CompletableFuture<Long> hash32;
|
||||
private EngineMode mode;
|
||||
private EngineEffects effects;
|
||||
private EngineExecutionEnvironment execution;
|
||||
@@ -174,8 +173,17 @@ public class IrisEngine implements Engine {
|
||||
complex = new IrisComplex(this);
|
||||
execution = new IrisExecutionEnvironment(this);
|
||||
effects = new IrisEngineEffects(this);
|
||||
hash32 = new CompletableFuture<>();
|
||||
setupMode();
|
||||
J.a(this::computeBiomeMaxes);
|
||||
J.a(() -> {
|
||||
File[] roots = getData().getLoaders()
|
||||
.values()
|
||||
.stream()
|
||||
.map(ResourceLoader::getRoot)
|
||||
.toArray(File[]::new);
|
||||
hash32.complete(IO.hashRecursive(roots));
|
||||
});
|
||||
} catch (Throwable e) {
|
||||
Iris.error("FAILED TO SETUP ENGINE!");
|
||||
e.printStackTrace();
|
||||
|
||||
@@ -23,11 +23,12 @@ import com.volmit.iris.engine.data.cache.AtomicCache;
|
||||
import com.volmit.iris.engine.framework.Engine;
|
||||
import com.volmit.iris.engine.mantle.EngineMantle;
|
||||
import com.volmit.iris.engine.mantle.MantleComponent;
|
||||
import com.volmit.iris.engine.mantle.components.*;
|
||||
import com.volmit.iris.engine.mantle.components.MantleCarvingComponent;
|
||||
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.util.collection.KList;
|
||||
import com.volmit.iris.util.collection.KMap;
|
||||
import com.volmit.iris.util.collection.KSet;
|
||||
import com.volmit.iris.util.format.Form;
|
||||
import com.volmit.iris.util.mantle.Mantle;
|
||||
import lombok.*;
|
||||
|
||||
@@ -57,7 +58,6 @@ public class IrisEngineMantle implements EngineMantle {
|
||||
registerComponent(jigsaw);
|
||||
object = new MantleObjectComponent(this);
|
||||
registerComponent(object);
|
||||
registerComponent(new MantleStaticComponent(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -62,6 +62,7 @@ import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@@ -299,28 +300,6 @@ public class IrisWorldManager extends EngineAssignedWorldManager {
|
||||
energy += 1.2;
|
||||
}
|
||||
|
||||
//@builder
|
||||
IrisBiome biome = IrisSettings.get().getWorld().isAnbientEntitySpawningSystem()
|
||||
? getEngine().getSurfaceBiome(c) : null;
|
||||
IrisEntitySpawn v = IrisSettings.get().getWorld().isAnbientEntitySpawningSystem()
|
||||
? spawnRandomly(Stream.concat(getData().getSpawnerLoader()
|
||||
.loadAll(getDimension().getEntitySpawners())
|
||||
.shuffleCopy(RNG.r).stream()
|
||||
.filter(this::canSpawn)
|
||||
.filter((i) -> i.isValid(biome))
|
||||
.flatMap((i) -> stream(i, initial)),
|
||||
Stream.concat(getData().getSpawnerLoader()
|
||||
.loadAll(getEngine().getRegion(c.getX() << 4, c.getZ() << 4).getEntitySpawners())
|
||||
.shuffleCopy(RNG.r).stream().filter(this::canSpawn)
|
||||
.flatMap((i) -> stream(i, initial)),
|
||||
getData().getSpawnerLoader()
|
||||
.loadAll(getEngine().getSurfaceBiome(c.getX() << 4, c.getZ() << 4).getEntitySpawners())
|
||||
.shuffleCopy(RNG.r).stream().filter(this::canSpawn)
|
||||
.flatMap((i) -> stream(i, initial))))
|
||||
.collect(Collectors.toList()))
|
||||
.popRandom(RNG.r) : null;
|
||||
//@done
|
||||
|
||||
if (IrisSettings.get().getWorld().isMarkerEntitySpawningSystem()) {
|
||||
getSpawnersFromMarkers(c).forEach((blockf, spawners) -> {
|
||||
if (spawners.isEmpty()) {
|
||||
@@ -335,94 +314,67 @@ public class IrisWorldManager extends EngineAssignedWorldManager {
|
||||
});
|
||||
}
|
||||
|
||||
if (v != null && v.getReferenceSpawner() != null) {
|
||||
int maxEntCount = v.getReferenceSpawner().getMaxEntitiesPerChunk();
|
||||
if (!IrisSettings.get().getWorld().isAnbientEntitySpawningSystem()) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (Entity i : c.getEntities()) {
|
||||
if (i instanceof LivingEntity) {
|
||||
if (-maxEntCount <= 0) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
//@builder
|
||||
Predicate<IrisSpawner> filter = i -> i.canSpawn(getEngine(), c.getX(), c.getZ());
|
||||
ChunkCounter counter = new ChunkCounter(c.getEntities());
|
||||
|
||||
try {
|
||||
spawn(c, v);
|
||||
} catch (Throwable e) {
|
||||
J.s(() -> spawn(c, v));
|
||||
}
|
||||
IrisBiome biome = getEngine().getSurfaceBiome(c);
|
||||
IrisEntitySpawn v = spawnRandomly(Stream.concat(getData().getSpawnerLoader()
|
||||
.loadAll(getDimension().getEntitySpawners())
|
||||
.shuffleCopy(RNG.r)
|
||||
.stream()
|
||||
.filter(filter)
|
||||
.filter((i) -> i.isValid(biome)),
|
||||
Stream.concat(getData()
|
||||
.getSpawnerLoader()
|
||||
.loadAll(getEngine().getRegion(c.getX() << 4, c.getZ() << 4).getEntitySpawners())
|
||||
.shuffleCopy(RNG.r)
|
||||
.stream()
|
||||
.filter(filter),
|
||||
getData().getSpawnerLoader()
|
||||
.loadAll(getEngine().getSurfaceBiome(c.getX() << 4, c.getZ() << 4).getEntitySpawners())
|
||||
.shuffleCopy(RNG.r)
|
||||
.stream()
|
||||
.filter(filter)))
|
||||
.filter(counter)
|
||||
.flatMap((i) -> stream(i, initial))
|
||||
.collect(Collectors.toList()))
|
||||
.getRandom();
|
||||
//@done
|
||||
if (v == null || v.getReferenceSpawner() == null)
|
||||
return;
|
||||
|
||||
try {
|
||||
spawn(c, v);
|
||||
} catch (Throwable e) {
|
||||
J.s(() -> spawn(c, v));
|
||||
}
|
||||
}
|
||||
|
||||
private void spawn(Chunk c, IrisEntitySpawn i) {
|
||||
boolean allow = true;
|
||||
|
||||
if (!i.getReferenceSpawner().getMaximumRatePerChunk().isInfinite()) {
|
||||
allow = false;
|
||||
IrisEngineChunkData cd = getEngine().getEngineData().getChunk(c.getX(), c.getZ());
|
||||
IrisEngineSpawnerCooldown sc = null;
|
||||
for (IrisEngineSpawnerCooldown j : cd.getCooldowns()) {
|
||||
if (j.getSpawner().equals(i.getReferenceSpawner().getLoadKey())) {
|
||||
sc = j;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (sc == null) {
|
||||
sc = new IrisEngineSpawnerCooldown();
|
||||
sc.setSpawner(i.getReferenceSpawner().getLoadKey());
|
||||
cd.getCooldowns().add(sc);
|
||||
}
|
||||
|
||||
if (sc.canSpawn(i.getReferenceSpawner().getMaximumRatePerChunk())) {
|
||||
sc.spawn(getEngine());
|
||||
allow = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (allow) {
|
||||
int s = i.spawn(getEngine(), c, RNG.r);
|
||||
actuallySpawned += s;
|
||||
if (s > 0) {
|
||||
getCooldown(i.getReferenceSpawner()).spawn(getEngine());
|
||||
energy -= s * ((i.getEnergyMultiplier() * i.getReferenceSpawner().getEnergyMultiplier() * 1));
|
||||
}
|
||||
IrisSpawner ref = i.getReferenceSpawner();
|
||||
int s = i.spawn(getEngine(), c, RNG.r);
|
||||
actuallySpawned += s;
|
||||
if (s > 0) {
|
||||
ref.spawn(getEngine(), c.getX(), c.getZ());
|
||||
energy -= s * ((i.getEnergyMultiplier() * ref.getEnergyMultiplier() * 1));
|
||||
}
|
||||
}
|
||||
|
||||
private void spawn(IrisPosition c, IrisEntitySpawn i) {
|
||||
boolean allow = true;
|
||||
private void spawn(IrisPosition pos, IrisEntitySpawn i) {
|
||||
IrisSpawner ref = i.getReferenceSpawner();
|
||||
if (!ref.canSpawn(getEngine(), pos.getX() >> 4, pos.getZ()))
|
||||
return;
|
||||
|
||||
if (!i.getReferenceSpawner().getMaximumRatePerChunk().isInfinite()) {
|
||||
allow = false;
|
||||
IrisEngineChunkData cd = getEngine().getEngineData().getChunk(c.getX() >> 4, c.getZ() >> 4);
|
||||
IrisEngineSpawnerCooldown sc = null;
|
||||
for (IrisEngineSpawnerCooldown j : cd.getCooldowns()) {
|
||||
if (j.getSpawner().equals(i.getReferenceSpawner().getLoadKey())) {
|
||||
sc = j;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (sc == null) {
|
||||
sc = new IrisEngineSpawnerCooldown();
|
||||
sc.setSpawner(i.getReferenceSpawner().getLoadKey());
|
||||
cd.getCooldowns().add(sc);
|
||||
}
|
||||
|
||||
if (sc.canSpawn(i.getReferenceSpawner().getMaximumRatePerChunk())) {
|
||||
sc.spawn(getEngine());
|
||||
allow = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (allow) {
|
||||
int s = i.spawn(getEngine(), c, RNG.r);
|
||||
actuallySpawned += s;
|
||||
if (s > 0) {
|
||||
getCooldown(i.getReferenceSpawner()).spawn(getEngine());
|
||||
energy -= s * ((i.getEnergyMultiplier() * i.getReferenceSpawner().getEnergyMultiplier() * 1));
|
||||
}
|
||||
int s = i.spawn(getEngine(), pos, RNG.r);
|
||||
actuallySpawned += s;
|
||||
if (s > 0) {
|
||||
ref.spawn(getEngine(), pos.getX() >> 4, pos.getZ() >> 4);
|
||||
energy -= s * ((i.getEnergyMultiplier() * ref.getEnergyMultiplier() * 1));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -450,31 +402,6 @@ public class IrisWorldManager extends EngineAssignedWorldManager {
|
||||
return rarityTypes;
|
||||
}
|
||||
|
||||
public boolean canSpawn(IrisSpawner i) {
|
||||
return i.isValid(getEngine().getWorld().realWorld())
|
||||
&& getCooldown(i).canSpawn(i.getMaximumRate());
|
||||
}
|
||||
|
||||
private IrisEngineSpawnerCooldown getCooldown(IrisSpawner i) {
|
||||
IrisEngineData ed = getEngine().getEngineData();
|
||||
IrisEngineSpawnerCooldown cd = null;
|
||||
|
||||
for (IrisEngineSpawnerCooldown j : ed.getSpawnerCooldowns().copy()) {
|
||||
if (j.getSpawner().equals(i.getLoadKey())) {
|
||||
cd = j;
|
||||
}
|
||||
}
|
||||
|
||||
if (cd == null) {
|
||||
cd = new IrisEngineSpawnerCooldown();
|
||||
cd.setSpawner(i.getLoadKey());
|
||||
cd.setLastSpawn(M.ms() - i.getMaximumRate().getInterval());
|
||||
ed.getSpawnerCooldowns().add(cd);
|
||||
}
|
||||
|
||||
return cd;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTick() {
|
||||
|
||||
@@ -708,4 +635,27 @@ public class IrisWorldManager extends EngineAssignedWorldManager {
|
||||
|
||||
return (double) entityCount / (getEngine().getWorld().realWorld().getLoadedChunks().length + 1) * 1.28;
|
||||
}
|
||||
|
||||
@Data
|
||||
private static class ChunkCounter implements Predicate<IrisSpawner> {
|
||||
private final Entity[] entities;
|
||||
private transient int index = 0;
|
||||
private transient int count = 0;
|
||||
|
||||
@Override
|
||||
public boolean test(IrisSpawner spawner) {
|
||||
int max = spawner.getMaxEntitiesPerChunk();
|
||||
if (max <= count)
|
||||
return false;
|
||||
|
||||
while (index < entities.length) {
|
||||
if (entities[index++] instanceof LivingEntity) {
|
||||
if (++count >= max)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ package com.volmit.iris.engine.data.chunk;
|
||||
import com.volmit.iris.core.nms.BiomeBaseInjector;
|
||||
import com.volmit.iris.core.nms.INMS;
|
||||
import com.volmit.iris.util.data.IrisBiomeStorage;
|
||||
import com.volmit.iris.util.data.IrisBlockData;
|
||||
import com.volmit.iris.util.data.IrisCustomData;
|
||||
import lombok.Setter;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
@@ -121,7 +121,7 @@ public class LinkedTerrainChunk implements TerrainChunk {
|
||||
|
||||
@Override
|
||||
public synchronized void setBlock(int x, int y, int z, BlockData blockData) {
|
||||
if (blockData instanceof IrisBlockData d)
|
||||
if (blockData instanceof IrisCustomData d)
|
||||
blockData = d.getBase();
|
||||
rawChunkData.setBlock(x, y, z, blockData);
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ package com.volmit.iris.engine.data.chunk;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.core.nms.BiomeBaseInjector;
|
||||
import com.volmit.iris.util.data.IrisBlockData;
|
||||
import com.volmit.iris.util.data.IrisCustomData;
|
||||
import com.volmit.iris.util.nbt.mca.Chunk;
|
||||
import com.volmit.iris.util.nbt.mca.NBTWorld;
|
||||
import lombok.AllArgsConstructor;
|
||||
@@ -89,7 +89,7 @@ public class MCATerrainChunk implements TerrainChunk {
|
||||
if (blockData == null) {
|
||||
Iris.error("NULL BD");
|
||||
}
|
||||
if (blockData instanceof IrisBlockData data)
|
||||
if (blockData instanceof IrisCustomData data)
|
||||
blockData = data.getBase();
|
||||
|
||||
mcaChunk.setBlockStateAt(xx, y, zz, NBTWorld.getCompound(blockData), false);
|
||||
|
||||
@@ -18,18 +18,16 @@
|
||||
|
||||
package com.volmit.iris.engine.decorator;
|
||||
|
||||
import com.volmit.iris.engine.data.cache.Cache;
|
||||
import com.volmit.iris.engine.framework.Engine;
|
||||
import com.volmit.iris.engine.object.IrisBiome;
|
||||
import com.volmit.iris.engine.object.IrisDecorationPart;
|
||||
import com.volmit.iris.engine.object.IrisDecorator;
|
||||
import com.volmit.iris.util.data.B;
|
||||
import com.volmit.iris.util.documentation.BlockCoordinates;
|
||||
import com.volmit.iris.util.hunk.Hunk;
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.block.data.MultipleFacing;
|
||||
import org.bukkit.block.data.type.PointedDripstone;
|
||||
|
||||
public class IrisCeilingDecorator extends IrisEngineDecorator {
|
||||
@@ -40,12 +38,14 @@ public class IrisCeilingDecorator extends IrisEngineDecorator {
|
||||
@BlockCoordinates
|
||||
@Override
|
||||
public void decorate(int x, int z, int realX, int realX1, int realX_1, int realZ, int realZ1, int realZ_1, Hunk<BlockData> data, IrisBiome biome, int height, int max) {
|
||||
IrisDecorator decorator = getDecorator(biome, realX, realZ);
|
||||
RNG rng = getRNG(realX, realZ);
|
||||
IrisDecorator decorator = getDecorator(rng, biome, realX, realZ);
|
||||
|
||||
if (decorator != null) {
|
||||
if (!decorator.isStacking()) {
|
||||
data.set(x, height, z, fixFaces(decorator.getBlockData100(biome, getRng(), realX, height, realZ, getData()), realX, height, realZ));
|
||||
data.set(x, height, z, fixFaces(decorator.getBlockData100(biome, rng, realX, height, realZ, getData()), data, x, z, realX, height, realZ));
|
||||
} else {
|
||||
int stack = decorator.getHeight(getRng().nextParallelRNG(Cache.key(realX, realZ)), realX, realZ, getData());
|
||||
int stack = decorator.getHeight(rng, realX, realZ, getData());
|
||||
if (decorator.isScaleStack()) {
|
||||
stack = Math.min((int) Math.ceil((double) max * ((double) stack / 100)), decorator.getAbsoluteMaxStack());
|
||||
} else {
|
||||
@@ -53,7 +53,7 @@ public class IrisCeilingDecorator extends IrisEngineDecorator {
|
||||
}
|
||||
|
||||
if (stack == 1) {
|
||||
data.set(x, height, z, decorator.getBlockDataForTop(biome, getRng(), realX, height, realZ, getData()));
|
||||
data.set(x, height, z, decorator.getBlockDataForTop(biome, rng, realX, height, realZ, getData()));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -66,8 +66,8 @@ public class IrisCeilingDecorator extends IrisEngineDecorator {
|
||||
double threshold = (((double) i) / (double) (stack - 1));
|
||||
|
||||
BlockData bd = threshold >= decorator.getTopThreshold() ?
|
||||
decorator.getBlockDataForTop(biome, getRng(), realX, h, realZ, getData()) :
|
||||
decorator.getBlockData100(biome, getRng(), realX, h, realZ, getData());
|
||||
decorator.getBlockDataForTop(biome, rng, realX, h, realZ, getData()) :
|
||||
decorator.getBlockData100(biome, rng, realX, h, realZ, getData());
|
||||
|
||||
if (bd instanceof PointedDripstone) {
|
||||
PointedDripstone.Thickness th = PointedDripstone.Thickness.BASE;
|
||||
@@ -97,24 +97,4 @@ public class IrisCeilingDecorator extends IrisEngineDecorator {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private BlockData fixFaces(BlockData b, int x, int y, int z) {
|
||||
if (B.isVineBlock(b)) {
|
||||
MultipleFacing data = (MultipleFacing) b.clone();
|
||||
boolean found = false;
|
||||
for (BlockFace f : BlockFace.values()) {
|
||||
if (!f.isCartesian())
|
||||
continue;
|
||||
Material m = getEngine().getMantle().get(x + f.getModX(), y + f.getModY(), z + f.getModZ()).getMaterial();
|
||||
if (m.isSolid()) {
|
||||
found = true;
|
||||
data.setFace(f, m.isSolid());
|
||||
}
|
||||
}
|
||||
if (!found)
|
||||
data.setFace(BlockFace.UP, true);
|
||||
return data;
|
||||
}
|
||||
return b;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
package com.volmit.iris.engine.decorator;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.engine.data.cache.Cache;
|
||||
import com.volmit.iris.engine.framework.Engine;
|
||||
import com.volmit.iris.engine.framework.EngineAssignedComponent;
|
||||
import com.volmit.iris.engine.framework.EngineDecorator;
|
||||
@@ -27,30 +26,42 @@ import com.volmit.iris.engine.object.IrisBiome;
|
||||
import com.volmit.iris.engine.object.IrisDecorationPart;
|
||||
import com.volmit.iris.engine.object.IrisDecorator;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.data.B;
|
||||
import com.volmit.iris.util.hunk.Hunk;
|
||||
import com.volmit.iris.util.documentation.BlockCoordinates;
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.BlockSupport;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.block.data.MultipleFacing;
|
||||
|
||||
public abstract class IrisEngineDecorator extends EngineAssignedComponent implements EngineDecorator {
|
||||
|
||||
@Getter
|
||||
private final RNG rng;
|
||||
|
||||
@Getter
|
||||
private final IrisDecorationPart part;
|
||||
private final long seed;
|
||||
private final long modX, modZ;
|
||||
|
||||
public IrisEngineDecorator(Engine engine, String name, IrisDecorationPart part) {
|
||||
super(engine, name + " Decorator");
|
||||
this.part = part;
|
||||
this.rng = new RNG(getSeed() + 29356788 - (part.ordinal() * 10439677L));
|
||||
this.seed = getSeed() + 29356788 - (part.ordinal() * 10439677L);
|
||||
this.modX = 29356788 ^ (part.ordinal() + 6);
|
||||
this.modZ = 10439677 ^ (part.ordinal() + 1);
|
||||
}
|
||||
|
||||
protected IrisDecorator getDecorator(IrisBiome biome, double realX, double realZ) {
|
||||
KList<IrisDecorator> v = new KList<>();
|
||||
RNG rng = new RNG(Cache.key((int) realX, (int) realZ));
|
||||
@BlockCoordinates
|
||||
protected RNG getRNG(int x, int z) {
|
||||
return new RNG(x * modX + z * modZ + seed);
|
||||
}
|
||||
|
||||
protected IrisDecorator getDecorator(RNG rng, IrisBiome biome, double realX, double realZ) {
|
||||
KList<IrisDecorator> v = new KList<>();
|
||||
|
||||
RNG gRNG = new RNG(seed);
|
||||
for (IrisDecorator i : biome.getDecorators()) {
|
||||
try {
|
||||
if (i.getPartOf().equals(part) && i.getBlockData(biome, this.rng, realX, realZ, getData()) != null) {
|
||||
if (i.getPartOf().equals(part) && i.getBlockData(biome, gRNG, realX, realZ, getData()) != null) {
|
||||
v.add(i);
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
@@ -65,4 +76,40 @@ public abstract class IrisEngineDecorator extends EngineAssignedComponent implem
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
protected BlockData fixFaces(BlockData b, Hunk<BlockData> hunk, int rX, int rZ, int x, int y, int z) {
|
||||
if (B.isVineBlock(b)) {
|
||||
MultipleFacing data = (MultipleFacing) b.clone();
|
||||
data.getFaces().forEach(f -> data.setFace(f, false));
|
||||
|
||||
boolean found = false;
|
||||
for (BlockFace f : BlockFace.values()) {
|
||||
if (!f.isCartesian())
|
||||
continue;
|
||||
int yy = y + f.getModY();
|
||||
|
||||
BlockData r = getEngine().getMantle().get(x + f.getModX(), yy, z + f.getModZ());
|
||||
if (r.isFaceSturdy(f.getOppositeFace(), BlockSupport.FULL)) {
|
||||
found = true;
|
||||
data.setFace(f, true);
|
||||
continue;
|
||||
}
|
||||
|
||||
int xx = rX + f.getModX();
|
||||
int zz = rZ + f.getModZ();
|
||||
if (xx < 0 || xx > 15 || zz < 0 || zz > 15 || yy < 0 || yy > hunk.getHeight())
|
||||
continue;
|
||||
|
||||
r = hunk.get(xx, yy, zz);
|
||||
if (r.isFaceSturdy(f.getOppositeFace(), BlockSupport.FULL)) {
|
||||
found = true;
|
||||
data.setFace(f, true);
|
||||
}
|
||||
}
|
||||
if (!found)
|
||||
data.setFace(BlockFace.DOWN, true);
|
||||
return data;
|
||||
}
|
||||
return b;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,13 +18,13 @@
|
||||
|
||||
package com.volmit.iris.engine.decorator;
|
||||
|
||||
import com.volmit.iris.engine.data.cache.Cache;
|
||||
import com.volmit.iris.engine.framework.Engine;
|
||||
import com.volmit.iris.engine.object.IrisBiome;
|
||||
import com.volmit.iris.engine.object.IrisDecorationPart;
|
||||
import com.volmit.iris.engine.object.IrisDecorator;
|
||||
import com.volmit.iris.util.documentation.BlockCoordinates;
|
||||
import com.volmit.iris.util.hunk.Hunk;
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
|
||||
public class IrisSeaFloorDecorator extends IrisEngineDecorator {
|
||||
@@ -35,7 +35,8 @@ public class IrisSeaFloorDecorator extends IrisEngineDecorator {
|
||||
@BlockCoordinates
|
||||
@Override
|
||||
public void decorate(int x, int z, int realX, int realX1, int realX_1, int realZ, int realZ1, int realZ_1, Hunk<BlockData> data, IrisBiome biome, int height, int max) {
|
||||
IrisDecorator decorator = getDecorator(biome, realX, realZ);
|
||||
RNG rng = getRNG(realX, realZ);
|
||||
IrisDecorator decorator = getDecorator(rng, biome, realX, realZ);
|
||||
|
||||
if (decorator != null) {
|
||||
if (!decorator.isStacking()) {
|
||||
@@ -44,17 +45,17 @@ public class IrisSeaFloorDecorator extends IrisEngineDecorator {
|
||||
return;
|
||||
}
|
||||
if (height >= 0 || height < getEngine().getHeight()) {
|
||||
data.set(x, height, z, decorator.getBlockData100(biome, getRng(), realX, height, realZ, getData()));
|
||||
data.set(x, height, z, decorator.getBlockData100(biome, rng, realX, height, realZ, getData()));
|
||||
}
|
||||
} else {
|
||||
int stack = decorator.getHeight(getRng().nextParallelRNG(Cache.key(realX, realZ)), realX, realZ, getData());
|
||||
int stack = decorator.getHeight(rng, realX, realZ, getData());
|
||||
if (decorator.isScaleStack()) {
|
||||
int maxStack = max - height;
|
||||
stack = (int) Math.ceil((double) maxStack * ((double) stack / 100));
|
||||
} else stack = Math.min(stack, max - height);
|
||||
|
||||
if (stack == 1) {
|
||||
data.set(x, height, z, decorator.getBlockDataForTop(biome, getRng(), realX, height, realZ, getData()));
|
||||
data.set(x, height, z, decorator.getBlockDataForTop(biome, rng, realX, height, realZ, getData()));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -66,8 +67,8 @@ public class IrisSeaFloorDecorator extends IrisEngineDecorator {
|
||||
|
||||
double threshold = ((double) i) / (stack - 1);
|
||||
data.set(x, h, z, threshold >= decorator.getTopThreshold() ?
|
||||
decorator.getBlockDataForTop(biome, getRng(), realX, h, realZ, getData()) :
|
||||
decorator.getBlockData100(biome, getRng(), realX, h, realZ, getData()));
|
||||
decorator.getBlockDataForTop(biome, rng, realX, h, realZ, getData()) :
|
||||
decorator.getBlockData100(biome, rng, realX, h, realZ, getData()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,13 +18,13 @@
|
||||
|
||||
package com.volmit.iris.engine.decorator;
|
||||
|
||||
import com.volmit.iris.engine.data.cache.Cache;
|
||||
import com.volmit.iris.engine.framework.Engine;
|
||||
import com.volmit.iris.engine.object.IrisBiome;
|
||||
import com.volmit.iris.engine.object.IrisDecorationPart;
|
||||
import com.volmit.iris.engine.object.IrisDecorator;
|
||||
import com.volmit.iris.util.documentation.BlockCoordinates;
|
||||
import com.volmit.iris.util.hunk.Hunk;
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
|
||||
public class IrisSeaSurfaceDecorator extends IrisEngineDecorator {
|
||||
@@ -35,22 +35,23 @@ public class IrisSeaSurfaceDecorator extends IrisEngineDecorator {
|
||||
@BlockCoordinates
|
||||
@Override
|
||||
public void decorate(int x, int z, int realX, int realX1, int realX_1, int realZ, int realZ1, int realZ_1, Hunk<BlockData> data, IrisBiome biome, int height, int max) {
|
||||
IrisDecorator decorator = getDecorator(biome, realX, realZ);
|
||||
RNG rng = getRNG(realX, realZ);
|
||||
IrisDecorator decorator = getDecorator(rng, biome, realX, realZ);
|
||||
|
||||
if (decorator != null) {
|
||||
if (!decorator.isStacking()) {
|
||||
if (height >= 0 || height < getEngine().getHeight()) {
|
||||
data.set(x, height + 1, z, decorator.getBlockData100(biome, getRng(), realX, height, realZ, getData()));
|
||||
data.set(x, height + 1, z, decorator.getBlockData100(biome, rng, realX, height, realZ, getData()));
|
||||
}
|
||||
} else {
|
||||
int stack = decorator.getHeight(getRng().nextParallelRNG(Cache.key(realX, realZ)), realX, realZ, getData());
|
||||
int stack = decorator.getHeight(rng, realX, realZ, getData());
|
||||
if (decorator.isScaleStack()) {
|
||||
int maxStack = max - height;
|
||||
stack = (int) Math.ceil((double) maxStack * ((double) stack / 100));
|
||||
}
|
||||
|
||||
if (stack == 1) {
|
||||
data.set(x, height, z, decorator.getBlockDataForTop(biome, getRng(), realX, height, realZ, getData()));
|
||||
data.set(x, height, z, decorator.getBlockDataForTop(biome, rng, realX, height, realZ, getData()));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -62,8 +63,8 @@ public class IrisSeaSurfaceDecorator extends IrisEngineDecorator {
|
||||
|
||||
double threshold = ((double) i) / (stack - 1);
|
||||
data.set(x, h + 1, z, threshold >= decorator.getTopThreshold() ?
|
||||
decorator.getBlockDataForTop(biome, getRng().nextParallelRNG(i), realX, h, realZ, getData()) :
|
||||
decorator.getBlockData100(biome, getRng().nextParallelRNG(i), realX, h, realZ, getData()));
|
||||
decorator.getBlockDataForTop(biome, rng, realX, h, realZ, getData()) :
|
||||
decorator.getBlockData100(biome, rng, realX, h, realZ, getData()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,13 +18,13 @@
|
||||
|
||||
package com.volmit.iris.engine.decorator;
|
||||
|
||||
import com.volmit.iris.engine.data.cache.Cache;
|
||||
import com.volmit.iris.engine.framework.Engine;
|
||||
import com.volmit.iris.engine.object.IrisBiome;
|
||||
import com.volmit.iris.engine.object.IrisDecorationPart;
|
||||
import com.volmit.iris.engine.object.IrisDecorator;
|
||||
import com.volmit.iris.util.documentation.BlockCoordinates;
|
||||
import com.volmit.iris.util.hunk.Hunk;
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
|
||||
public class IrisShoreLineDecorator extends IrisEngineDecorator {
|
||||
@@ -42,7 +42,8 @@ public class IrisShoreLineDecorator extends IrisEngineDecorator {
|
||||
Math.round(getComplex().getHeightStream().get(realX, realZ1)) < getComplex().getFluidHeight() ||
|
||||
Math.round(getComplex().getHeightStream().get(realX, realZ_1)) < getComplex().getFluidHeight()
|
||||
) {
|
||||
IrisDecorator decorator = getDecorator(biome, realX, realZ);
|
||||
RNG rng = getRNG(realX, realZ);
|
||||
IrisDecorator decorator = getDecorator(rng, biome, realX, realZ);
|
||||
|
||||
if (decorator != null) {
|
||||
if (!decorator.isForcePlace() && !decorator.getSlopeCondition().isDefault()
|
||||
@@ -51,16 +52,16 @@ public class IrisShoreLineDecorator extends IrisEngineDecorator {
|
||||
}
|
||||
|
||||
if (!decorator.isStacking()) {
|
||||
data.set(x, height + 1, z, decorator.getBlockData100(biome, getRng(), realX, height, realZ, getData()));
|
||||
data.set(x, height + 1, z, decorator.getBlockData100(biome, rng, realX, height, realZ, getData()));
|
||||
} else {
|
||||
int stack = decorator.getHeight(getRng().nextParallelRNG(Cache.key(realX, realZ)), realX, realZ, getData());
|
||||
int stack = decorator.getHeight(rng, realX, realZ, getData());
|
||||
if (decorator.isScaleStack()) {
|
||||
int maxStack = max - height;
|
||||
stack = (int) Math.ceil((double) maxStack * ((double) stack / 100));
|
||||
} else stack = Math.min(max - height, stack);
|
||||
|
||||
if (stack == 1) {
|
||||
data.set(x, height, z, decorator.getBlockDataForTop(biome, getRng(), realX, height, realZ, getData()));
|
||||
data.set(x, height, z, decorator.getBlockDataForTop(biome, rng, realX, height, realZ, getData()));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -68,8 +69,8 @@ public class IrisShoreLineDecorator extends IrisEngineDecorator {
|
||||
int h = height + i;
|
||||
double threshold = ((double) i) / (stack - 1);
|
||||
data.set(x, h + 1, z, threshold >= decorator.getTopThreshold() ?
|
||||
decorator.getBlockDataForTop(biome, getRng(), realX, h, realZ, getData()) :
|
||||
decorator.getBlockData100(biome, getRng(), realX, h, realZ, getData()));
|
||||
decorator.getBlockDataForTop(biome, rng, realX, h, realZ, getData()) :
|
||||
decorator.getBlockData100(biome, rng, realX, h, realZ, getData()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
package com.volmit.iris.engine.decorator;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.engine.data.cache.Cache;
|
||||
import com.volmit.iris.engine.framework.Engine;
|
||||
import com.volmit.iris.engine.object.InferredType;
|
||||
import com.volmit.iris.engine.object.IrisBiome;
|
||||
@@ -28,11 +27,11 @@ import com.volmit.iris.engine.object.IrisDecorator;
|
||||
import com.volmit.iris.util.data.B;
|
||||
import com.volmit.iris.util.documentation.BlockCoordinates;
|
||||
import com.volmit.iris.util.hunk.Hunk;
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.data.Bisected;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.block.data.MultipleFacing;
|
||||
import org.bukkit.block.data.type.PointedDripstone;
|
||||
|
||||
public class IrisSurfaceDecorator extends IrisEngineDecorator {
|
||||
@@ -48,7 +47,8 @@ public class IrisSurfaceDecorator extends IrisEngineDecorator {
|
||||
}
|
||||
|
||||
BlockData bd, bdx;
|
||||
IrisDecorator decorator = getDecorator(biome, realX, realZ);
|
||||
RNG rng = getRNG(realX, realZ);
|
||||
IrisDecorator decorator = getDecorator(rng, biome, realX, realZ);
|
||||
bdx = data.get(x, height, z);
|
||||
boolean underwater = height < getDimension().getFluidHeight();
|
||||
|
||||
@@ -59,7 +59,7 @@ public class IrisSurfaceDecorator extends IrisEngineDecorator {
|
||||
}
|
||||
|
||||
if (!decorator.isStacking()) {
|
||||
bd = decorator.getBlockData100(biome, getRng(), realX, height, realZ, getData());
|
||||
bd = decorator.getBlockData100(biome, rng, realX, height, realZ, getData());
|
||||
|
||||
if (!underwater) {
|
||||
if (!canGoOn(bd, bdx) && (!decorator.isForcePlace() && decorator.getForceBlock() == null)) {
|
||||
@@ -68,12 +68,12 @@ public class IrisSurfaceDecorator extends IrisEngineDecorator {
|
||||
}
|
||||
|
||||
if (decorator.getForceBlock() != null) {
|
||||
data.set(x, height, z, fixFaces(decorator.getForceBlock().getBlockData(getData()), x, height, z));
|
||||
data.set(x, height, z, fixFaces(decorator.getForceBlock().getBlockData(getData()), data, x, z, realX, height, realZ));
|
||||
} else if (!decorator.isForcePlace()) {
|
||||
if (decorator.getWhitelist() != null && decorator.getWhitelist().stream().noneMatch(d -> d.getBlockData(getData()).equals(bdx))) {
|
||||
return;
|
||||
}
|
||||
if (decorator.getBlacklist() != null && decorator.getWhitelist().stream().anyMatch(d -> d.getBlockData(getData()).equals(bdx))) {
|
||||
if (decorator.getBlacklist() != null && decorator.getBlacklist().stream().anyMatch(d -> d.getBlockData(getData()).equals(bdx))) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -91,14 +91,14 @@ public class IrisSurfaceDecorator extends IrisEngineDecorator {
|
||||
}
|
||||
|
||||
if (B.isAir(data.get(x, height + 1, z))) {
|
||||
data.set(x, height + 1, z, fixFaces(bd, x, height + 1, z));
|
||||
data.set(x, height + 1, z, fixFaces(bd, data, x, z, realX, height + 1, realZ));
|
||||
}
|
||||
} else {
|
||||
if (height < getDimension().getFluidHeight()) {
|
||||
max = getDimension().getFluidHeight();
|
||||
}
|
||||
|
||||
int stack = decorator.getHeight(getRng().nextParallelRNG(Cache.key(realX, realZ)), realX, realZ, getData());
|
||||
int stack = decorator.getHeight(rng, realX, realZ, getData());
|
||||
|
||||
if (decorator.isScaleStack()) {
|
||||
stack = Math.min((int) Math.ceil((double) max * ((double) stack / 100)), decorator.getAbsoluteMaxStack());
|
||||
@@ -107,7 +107,7 @@ public class IrisSurfaceDecorator extends IrisEngineDecorator {
|
||||
}
|
||||
|
||||
if (stack == 1) {
|
||||
data.set(x, height, z, decorator.getBlockDataForTop(biome, getRng(), realX, height, realZ, getData()));
|
||||
data.set(x, height, z, decorator.getBlockDataForTop(biome, rng, realX, height, realZ, getData()));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -115,8 +115,8 @@ public class IrisSurfaceDecorator extends IrisEngineDecorator {
|
||||
int h = height + i;
|
||||
double threshold = ((double) i) / (stack - 1);
|
||||
bd = threshold >= decorator.getTopThreshold() ?
|
||||
decorator.getBlockDataForTop(biome, getRng(), realX, h, realZ, getData()) :
|
||||
decorator.getBlockData100(biome, getRng(), realX, h, realZ, getData());
|
||||
decorator.getBlockDataForTop(biome, rng, realX, h, realZ, getData()) :
|
||||
decorator.getBlockData100(biome, rng, realX, h, realZ, getData());
|
||||
|
||||
if (bd == null) {
|
||||
break;
|
||||
@@ -158,24 +158,4 @@ public class IrisSurfaceDecorator extends IrisEngineDecorator {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private BlockData fixFaces(BlockData b, int x, int y, int z) {
|
||||
if (B.isVineBlock(b)) {
|
||||
MultipleFacing data = (MultipleFacing) b.clone();
|
||||
boolean found = false;
|
||||
for (BlockFace f : BlockFace.values()) {
|
||||
if (!f.isCartesian())
|
||||
continue;
|
||||
Material m = getEngine().getMantle().get(x + f.getModX(), y + f.getModY(), z + f.getModZ()).getMaterial();
|
||||
if (m.isSolid()) {
|
||||
found = true;
|
||||
data.setFace(f, m.isSolid());
|
||||
}
|
||||
}
|
||||
if (!found)
|
||||
data.setFace(BlockFace.UP, true);
|
||||
return data;
|
||||
}
|
||||
return b;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ import com.volmit.iris.util.context.ChunkContext;
|
||||
import com.volmit.iris.util.context.IrisContext;
|
||||
import com.volmit.iris.util.data.B;
|
||||
import com.volmit.iris.util.data.DataProvider;
|
||||
import com.volmit.iris.util.data.IrisBlockData;
|
||||
import com.volmit.iris.util.data.IrisCustomData;
|
||||
import com.volmit.iris.util.documentation.BlockCoordinates;
|
||||
import com.volmit.iris.util.documentation.ChunkCoordinates;
|
||||
import com.volmit.iris.util.format.C;
|
||||
@@ -80,6 +80,7 @@ import java.awt.Color;
|
||||
import java.util.Arrays;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.Semaphore;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
@@ -258,10 +259,8 @@ public interface Engine extends DataProvider, Fallible, LootProvider, BlockUpdat
|
||||
if (B.isUpdatable(data)) {
|
||||
getMantle().updateBlock(x, y, z);
|
||||
}
|
||||
if (data instanceof IrisBlockData d) {
|
||||
getMantle().getMantle().set(x, y, z, d.getCustom());
|
||||
} else {
|
||||
getMantle().getMantle().remove(x, y, z, Identifier.class);
|
||||
if (data instanceof IrisCustomData) {
|
||||
getMantle().getMantle().flag(x >> 4, z >> 4, MantleFlag.CUSTOM, true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -611,6 +610,8 @@ public interface Engine extends DataProvider, Fallible, LootProvider, BlockUpdat
|
||||
|
||||
int getGenerated();
|
||||
|
||||
CompletableFuture<Long> getHash32();
|
||||
|
||||
default <T> IrisPosition lookForStreamResult(T find, ProceduralStream<T> stream, Function2<T, T, Boolean> matcher, long timeout) {
|
||||
AtomicInteger checked = new AtomicInteger();
|
||||
AtomicLong time = new AtomicLong(M.ms());
|
||||
@@ -826,13 +827,6 @@ public interface Engine extends DataProvider, Fallible, LootProvider, BlockUpdat
|
||||
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);
|
||||
|
||||
for (IrisObjectPlacement i : region.getObjects()) {
|
||||
|
||||
@@ -13,6 +13,7 @@ import com.volmit.iris.engine.object.IrisLootTable;
|
||||
import com.volmit.iris.engine.object.TileData;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.data.B;
|
||||
import com.volmit.iris.util.data.IrisCustomData;
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
@@ -78,7 +79,11 @@ public class WorldObjectPlacer implements IObjectPlacer {
|
||||
}
|
||||
}
|
||||
|
||||
block.setBlockData(d);
|
||||
|
||||
if (d instanceof IrisCustomData data) {
|
||||
block.setBlockData(data.getBase());
|
||||
Iris.warn("Tried to place custom block at " + x + ", " + y + ", " + z + " which is not supported!");
|
||||
} else block.setBlockData(d);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -25,7 +25,6 @@ import com.volmit.iris.engine.framework.Engine;
|
||||
import com.volmit.iris.engine.framework.placer.WorldObjectPlacer;
|
||||
import com.volmit.iris.engine.object.*;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.data.IrisBlockData;
|
||||
import com.volmit.iris.util.mantle.Mantle;
|
||||
import com.volmit.iris.util.math.Position2;
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
@@ -155,9 +154,6 @@ public class PlannedStructure {
|
||||
return v.place(xx, height, zz, placer, options, rng, (b, data) -> {
|
||||
e.set(b.getX(), b.getY(), b.getZ(), v.getLoadKey() + "@" + id);
|
||||
e.set(b.getX(), b.getY(), b.getZ(), container);
|
||||
if (data instanceof IrisBlockData d) {
|
||||
e.set(b.getX(), b.getY(), b.getZ(), d.getCustom());
|
||||
}
|
||||
}, null, getData().getEngine() != null ? getData() : eng.getData()) != -1;
|
||||
}
|
||||
|
||||
|
||||
@@ -34,6 +34,7 @@ import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.context.ChunkContext;
|
||||
import com.volmit.iris.util.context.IrisContext;
|
||||
import com.volmit.iris.util.data.B;
|
||||
import com.volmit.iris.util.data.IrisCustomData;
|
||||
import com.volmit.iris.util.documentation.BlockCoordinates;
|
||||
import com.volmit.iris.util.documentation.ChunkCoordinates;
|
||||
import com.volmit.iris.util.hunk.Hunk;
|
||||
@@ -104,7 +105,10 @@ public interface EngineMantle extends IObjectPlacer {
|
||||
|
||||
@Override
|
||||
default void set(int x, int y, int z, BlockData d) {
|
||||
getMantle().set(x, y, z, d == null ? AIR : d);
|
||||
if (d instanceof IrisCustomData data) {
|
||||
getMantle().set(x, y, z, data.getBase());
|
||||
getMantle().set(x, y, z, data.getCustom());
|
||||
} else getMantle().set(x, y, z, d == null ? AIR : d);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -29,6 +29,7 @@ import com.volmit.iris.engine.object.IrisPosition;
|
||||
import com.volmit.iris.engine.object.TileData;
|
||||
import com.volmit.iris.util.collection.KMap;
|
||||
import com.volmit.iris.util.collection.KSet;
|
||||
import com.volmit.iris.util.data.IrisCustomData;
|
||||
import com.volmit.iris.util.function.Function3;
|
||||
import com.volmit.iris.util.mantle.Mantle;
|
||||
import com.volmit.iris.util.mantle.MantleChunk;
|
||||
@@ -166,7 +167,10 @@ public class MantleWriter implements IObjectPlacer, AutoCloseable {
|
||||
|
||||
@Override
|
||||
public void set(int x, int y, int z, BlockData d) {
|
||||
setData(x, y, z, d);
|
||||
if (d instanceof IrisCustomData data) {
|
||||
setData(x, y, z, data.getBase());
|
||||
setData(x, y, z, data.getCustom());
|
||||
} else setData(x, y, z, d);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -90,8 +90,10 @@ public class MantleJigsawComponent extends IrisMantleComponent {
|
||||
private boolean placeStructures(MantleWriter writer, long seed, int x, int z, KList<IrisJigsawStructurePlacement> structures,
|
||||
KSet<Position2> cachedRegions, KMap<String, KSet<Position2>> cache, KMap<Position2, Double> distanceCache) {
|
||||
IrisJigsawStructurePlacement i = pick(structures, seed, x, z);
|
||||
if (i == null || checkMinDistances(i.collectMinDistances(), x, z, cachedRegions, cache, distanceCache))
|
||||
return false;
|
||||
try {
|
||||
if (i == null || checkMinDistances(i.collectMinDistances(), x, z, cachedRegions, cache, distanceCache))
|
||||
return false;
|
||||
} catch (Throwable ignored) {}
|
||||
RNG rng = new RNG(seed);
|
||||
IrisPosition position = new IrisPosition((x << 4) + rng.nextInt(15), 0, (z << 4) + rng.nextInt(15));
|
||||
IrisJigsawStructure structure = getData().getJigsawStructureLoader().load(i.getStructure());
|
||||
@@ -159,7 +161,7 @@ public class MantleJigsawComponent extends IrisMantleComponent {
|
||||
@ChunkCoordinates
|
||||
private IrisJigsawStructurePlacement pick(List<IrisJigsawStructurePlacement> structures, long seed, int x, int z) {
|
||||
return IRare.pick(structures.stream()
|
||||
.filter(p -> p.shouldPlace(getDimension().getJigsawStructureDivisor(), jigsaw(), x, z))
|
||||
.filter(p -> p.shouldPlace(getData(), getDimension().getJigsawStructureDivisor(), jigsaw(), x, z))
|
||||
.toList(), new RNG(seed).nextDouble());
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
package com.volmit.iris.engine.mantle.components;
|
||||
|
||||
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.mantle.EngineMantle;
|
||||
import com.volmit.iris.engine.mantle.IrisMantleComponent;
|
||||
@@ -30,7 +29,6 @@ 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.data.B;
|
||||
import com.volmit.iris.util.data.IrisBlockData;
|
||||
import com.volmit.iris.util.documentation.BlockCoordinates;
|
||||
import com.volmit.iris.util.documentation.ChunkCoordinates;
|
||||
import com.volmit.iris.util.format.Form;
|
||||
@@ -40,13 +38,11 @@ import com.volmit.iris.util.matter.MatterStructurePOI;
|
||||
import com.volmit.iris.util.noise.CNG;
|
||||
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.concurrent.atomic.AtomicInteger;
|
||||
|
||||
@@ -119,9 +115,6 @@ public class MantleObjectComponent extends IrisMantleComponent {
|
||||
if (objectPlacement.isDolphinTarget() && objectPlacement.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, getData());
|
||||
}
|
||||
}
|
||||
@@ -165,67 +158,99 @@ public class MantleObjectComponent extends IrisMantleComponent {
|
||||
private int computeRadius() {
|
||||
var dimension = getDimension();
|
||||
|
||||
AtomicInteger xg = new AtomicInteger();
|
||||
AtomicInteger zg = new AtomicInteger();
|
||||
|
||||
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());
|
||||
for (var j : region.getObjects()) {
|
||||
if (j.getScale().canScaleBeyond()) {
|
||||
scalars.put(j.getScale(), j.getPlace());
|
||||
} else {
|
||||
objects.addAll(placement.getPlace());
|
||||
objects.addAll(j.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());
|
||||
}
|
||||
}
|
||||
for (var biome : dimension.getAllBiomes(this::getData)) {
|
||||
for (var j : biome.getObjects()) {
|
||||
if (j.getScale().canScaleBeyond()) {
|
||||
scalars.put(j.getScale(), j.getPlace());
|
||||
} else {
|
||||
objects.addAll(j.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());
|
||||
BurstExecutor e = getEngineMantle().getTarget().getBurster().burst(objects.size());
|
||||
KMap<String, BlockVector> sizeCache = new KMap<>();
|
||||
for (String loadKey : objects) {
|
||||
for (String i : objects) {
|
||||
e.queue(() -> {
|
||||
try {
|
||||
BlockVector bv = sampleSize(sizeCache, data, loadKey);
|
||||
BlockVector bv = sizeCache.computeIfAbsent(i, (k) -> {
|
||||
try {
|
||||
return IrisObject.sampleSize(getData().getObjectLoader().findFile(i));
|
||||
} catch (IOException ex) {
|
||||
Iris.reportError(ex);
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
if (Math.max(bv.getBlockX(), bv.getBlockZ()) > 128) {
|
||||
Iris.warn("Object " + loadKey + " has a large size (" + bv + ") and may increase memory usage!");
|
||||
return null;
|
||||
});
|
||||
|
||||
if (bv == null) {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
|
||||
x.getAndUpdate(i -> Math.max(bv.getBlockX(), i));
|
||||
z.getAndUpdate(i -> Math.max(bv.getBlockZ(), i));
|
||||
if (Math.max(bv.getBlockX(), bv.getBlockZ()) > 128) {
|
||||
Iris.warn("Object " + i + " has a large size (" + bv + ") and may increase memory usage!");
|
||||
}
|
||||
|
||||
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 loadKey : entry.getValue()) {
|
||||
for (String j : entry.getValue()) {
|
||||
e.queue(() -> {
|
||||
try {
|
||||
BlockVector bv = sampleSize(sizeCache, data, loadKey);
|
||||
BlockVector bv = sizeCache.computeIfAbsent(j, (k) -> {
|
||||
try {
|
||||
return IrisObject.sampleSize(getData().getObjectLoader().findFile(j));
|
||||
} catch (IOException ioException) {
|
||||
Iris.reportError(ioException);
|
||||
ioException.printStackTrace();
|
||||
}
|
||||
|
||||
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) + ")");
|
||||
return null;
|
||||
});
|
||||
|
||||
if (bv == null) {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
|
||||
x.getAndUpdate(i -> (int) Math.max(Math.ceil(bv.getBlockX() * ms), i));
|
||||
x.getAndUpdate(i -> (int) Math.max(Math.ceil(bv.getBlockZ() * ms), i));
|
||||
if (Math.max(bv.getBlockX(), bv.getBlockZ()) > 128) {
|
||||
Iris.warn("Object " + j + " has a large size (" + bv + ") and may increase memory usage! (Object scaled up to " + Form.pc(ms, 2) + ")");
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
@@ -235,20 +260,6 @@ public class MantleObjectComponent extends IrisMantleComponent {
|
||||
}
|
||||
|
||||
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");
|
||||
return Math.max(xg.get(), zg.get());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,59 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -25,10 +25,7 @@ import com.volmit.iris.engine.framework.Engine;
|
||||
import com.volmit.iris.engine.framework.EngineMode;
|
||||
import com.volmit.iris.engine.framework.EngineStage;
|
||||
import com.volmit.iris.engine.framework.IrisEngineMode;
|
||||
import com.volmit.iris.engine.modifier.IrisCarveModifier;
|
||||
import com.volmit.iris.engine.modifier.IrisDepositModifier;
|
||||
import com.volmit.iris.engine.modifier.IrisPerfectionModifier;
|
||||
import com.volmit.iris.engine.modifier.IrisPostModifier;
|
||||
import com.volmit.iris.engine.modifier.*;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
|
||||
public class ModeOverworld extends IrisEngineMode implements EngineMode {
|
||||
@@ -41,6 +38,7 @@ public class ModeOverworld extends IrisEngineMode implements EngineMode {
|
||||
var post = new IrisPostModifier(getEngine());
|
||||
var deposit = new IrisDepositModifier(getEngine());
|
||||
var perfection = new IrisPerfectionModifier(getEngine());
|
||||
var custom = new IrisCustomModifier(getEngine());
|
||||
EngineStage sBiome = (x, z, k, p, m, c) -> biome.actuate(x, z, p, m, c);
|
||||
EngineStage sGenMatter = (x, z, k, p, m, c) -> generateMatter(x >> 4, z >> 4, m, c);
|
||||
EngineStage sTerrain = (x, z, k, p, m, c) -> terrain.actuate(x, z, k, m, c);
|
||||
@@ -50,6 +48,7 @@ public class ModeOverworld extends IrisEngineMode implements EngineMode {
|
||||
EngineStage sPost = (x, z, k, p, m, c) -> post.modify(x, z, k, m, c);
|
||||
EngineStage sInsertMatter = (x, z, K, p, m, c) -> getMantle().insertMatter(x >> 4, z >> 4, BlockData.class, K, m);
|
||||
EngineStage sPerfection = (x, z, k, p, m, c) -> perfection.modify(x, z, k, m, c);
|
||||
EngineStage sCustom = (x, z, k, p, m, c) -> custom.modify(x, z, k, m, c);
|
||||
|
||||
registerStage(burst(
|
||||
sGenMatter,
|
||||
@@ -65,6 +64,6 @@ public class ModeOverworld extends IrisEngineMode implements EngineMode {
|
||||
sDecorant
|
||||
));
|
||||
registerStage(sPerfection);
|
||||
|
||||
registerStage(sCustom);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ public class IrisCarveModifier extends EngineAssignedModifier<BlockData> {
|
||||
public void onModify(int x, int z, Hunk<BlockData> output, boolean multicore, ChunkContext context) {
|
||||
PrecisionStopwatch p = PrecisionStopwatch.start();
|
||||
Mantle mantle = getEngine().getMantle().getMantle();
|
||||
MantleChunk mc = getEngine().getMantle().getMantle().getChunk(x, z);
|
||||
MantleChunk mc = getEngine().getMantle().getMantle().getChunk(x, z).use();
|
||||
KMap<Long, KList<Integer>> positions = new KMap<>();
|
||||
KMap<IrisPosition, MatterCavern> walls = new KMap<>();
|
||||
Consumer4<Integer, Integer, Integer, MatterCavern> iterator = (xx, yy, zz, c) -> {
|
||||
@@ -166,6 +166,7 @@ public class IrisCarveModifier extends EngineAssignedModifier<BlockData> {
|
||||
});
|
||||
|
||||
getEngine().getMetrics().getDeposit().put(p.getMilliseconds());
|
||||
mc.release();
|
||||
}
|
||||
|
||||
private void processZone(Hunk<BlockData> output, MantleChunk mc, Mantle mantle, CaveZone zone, int rx, int rz, int xx, int zz) {
|
||||
@@ -211,14 +212,6 @@ public class IrisCarveModifier extends EngineAssignedModifier<BlockData> {
|
||||
|
||||
biome.setInferredType(InferredType.CAVE);
|
||||
|
||||
for (IrisDecorator i : biome.getDecorators()) {
|
||||
if (i.getPartOf().equals(IrisDecorationPart.NONE) && B.isSolid(output.get(rx, zone.getFloor() - 1, rz))) {
|
||||
decorant.getSurfaceDecorator().decorate(rx, rz, xx, xx, xx, zz, zz, zz, output, biome, zone.getFloor() - 1, zone.airThickness());
|
||||
} else if (i.getPartOf().equals(IrisDecorationPart.CEILING) && B.isSolid(output.get(rx, zone.getCeiling() + 1, rz))) {
|
||||
decorant.getCeilingDecorator().decorate(rx, rz, xx, xx, xx, zz, zz, zz, output, biome, zone.getCeiling(), zone.airThickness());
|
||||
}
|
||||
}
|
||||
|
||||
KList<BlockData> blocks = biome.generateLayers(getDimension(), xx, zz, rng, 3, zone.floor, getData(), getComplex());
|
||||
|
||||
for (int i = 0; i < zone.floor - 1; i++) {
|
||||
@@ -260,6 +253,14 @@ public class IrisCarveModifier extends EngineAssignedModifier<BlockData> {
|
||||
output.set(rx, zone.ceiling + i + 1, rz, b);
|
||||
}
|
||||
}
|
||||
|
||||
for (IrisDecorator i : biome.getDecorators()) {
|
||||
if (i.getPartOf().equals(IrisDecorationPart.NONE) && B.isSolid(output.get(rx, zone.getFloor() - 1, rz))) {
|
||||
decorant.getSurfaceDecorator().decorate(rx, rz, xx, xx, xx, zz, zz, zz, output, biome, zone.getFloor() - 1, zone.airThickness());
|
||||
} else if (i.getPartOf().equals(IrisDecorationPart.CEILING) && B.isSolid(output.get(rx, zone.getCeiling() + 1, rz))) {
|
||||
decorant.getCeilingDecorator().decorate(rx, rz, xx, xx, xx, zz, zz, zz, output, biome, zone.getCeiling(), zone.airThickness());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Data
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.volmit.iris.engine.modifier;
|
||||
import com.volmit.iris.core.link.Identifier;
|
||||
import com.volmit.iris.engine.framework.Engine;
|
||||
import com.volmit.iris.engine.framework.EngineAssignedModifier;
|
||||
import com.volmit.iris.util.context.ChunkContext;
|
||||
import com.volmit.iris.util.data.IrisCustomData;
|
||||
import com.volmit.iris.util.hunk.Hunk;
|
||||
import com.volmit.iris.util.mantle.MantleFlag;
|
||||
import com.volmit.iris.util.parallel.BurstExecutor;
|
||||
import com.volmit.iris.util.parallel.MultiBurst;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
public class IrisCustomModifier extends EngineAssignedModifier<BlockData> {
|
||||
public IrisCustomModifier(Engine engine) {
|
||||
super(engine, "Custom");
|
||||
}
|
||||
@Override
|
||||
public void onModify(int x, int z, Hunk<BlockData> output, boolean multicore, ChunkContext context) {
|
||||
var mc = getEngine().getMantle().getMantle().getChunk(x >> 4, z >> 4);
|
||||
if (!mc.isFlagged(MantleFlag.CUSTOM_ACTIVE)) return;
|
||||
mc.use();
|
||||
|
||||
BurstExecutor burst = MultiBurst.burst.burst(output.getHeight());
|
||||
burst.setMulticore(multicore);
|
||||
for (int y = 0; y < output.getHeight(); y++) {
|
||||
int finalY = y;
|
||||
burst.queue(() -> {
|
||||
for (int rX = 0; rX < output.getWidth(); rX++) {
|
||||
for (int rZ = 0; rZ < output.getDepth(); rZ++) {
|
||||
BlockData b = output.get(rX, finalY, rZ);
|
||||
if (!(b instanceof IrisCustomData d)) continue;
|
||||
|
||||
mc.getOrCreate(finalY >> 4)
|
||||
.slice(Identifier.class)
|
||||
.set(rX, finalY & 15, rZ, d.getCustom());
|
||||
output.set(rX, finalY, rZ, d.getBase());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
burst.complete();
|
||||
mc.release();
|
||||
}
|
||||
}
|
||||
@@ -200,7 +200,7 @@ public class IrisBiome extends IrisRegistrant implements IRare {
|
||||
KMap<String, Integer> l = new KMap<>();
|
||||
|
||||
for (IrisBiomeGeneratorLink i : getGenerators()) {
|
||||
l.put(i.getGenerator(), i.getMax(engine));
|
||||
l.put(i.getGenerator(), i.getMax());
|
||||
|
||||
}
|
||||
|
||||
@@ -216,7 +216,7 @@ public class IrisBiome extends IrisRegistrant implements IRare {
|
||||
KMap<String, Integer> l = new KMap<>();
|
||||
|
||||
for (IrisBiomeGeneratorLink i : getGenerators()) {
|
||||
l.put(i.getGenerator(), i.getMin(engine));
|
||||
l.put(i.getGenerator(), i.getMin());
|
||||
}
|
||||
|
||||
return l;
|
||||
@@ -457,7 +457,7 @@ public class IrisBiome extends IrisRegistrant implements IRare {
|
||||
int maxHeight = 0;
|
||||
|
||||
for (IrisBiomeGeneratorLink i : getGenerators()) {
|
||||
maxHeight += i.getMax(engine);
|
||||
maxHeight += i.getMax();
|
||||
}
|
||||
|
||||
return maxHeight;
|
||||
@@ -470,7 +470,7 @@ public class IrisBiome extends IrisRegistrant implements IRare {
|
||||
int maxHeight = 0;
|
||||
|
||||
for (IrisBiomeGeneratorLink i : getGenerators()) {
|
||||
maxHeight += i.getMax(engine);
|
||||
maxHeight += i.getMax();
|
||||
}
|
||||
|
||||
int gg = 0;
|
||||
|
||||
@@ -18,9 +18,7 @@
|
||||
|
||||
package com.volmit.iris.engine.object;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.engine.data.cache.AtomicCache;
|
||||
import com.volmit.iris.engine.framework.Engine;
|
||||
import com.volmit.iris.engine.object.annotations.*;
|
||||
import com.volmit.iris.util.data.DataProvider;
|
||||
import com.volmit.iris.util.interpolation.IrisInterpolation;
|
||||
@@ -39,18 +37,16 @@ public class IrisBiomeGeneratorLink {
|
||||
@RegistryListResource(IrisGenerator.class)
|
||||
@Desc("The generator id")
|
||||
private String generator = "default";
|
||||
@DependsOn({ "min", "max" })
|
||||
@DependsOn({"min", "max"})
|
||||
@Required
|
||||
@MinNumber(-2032) // TODO: WARNING HEIGHT
|
||||
@MaxNumber(2032) // TODO: WARNING HEIGHT
|
||||
@Desc("The min block value (value + fluidHeight)")
|
||||
@Getter(AccessLevel.NONE)
|
||||
private int min = 0;
|
||||
@DependsOn({ "min", "max" })
|
||||
@DependsOn({"min", "max"})
|
||||
@Required
|
||||
@MinNumber(-2032) // TODO: WARNING HEIGHT
|
||||
@MaxNumber(2032) // TODO: WARNING HEIGHT
|
||||
@Getter(AccessLevel.NONE)
|
||||
@Desc("The max block value (value + fluidHeight)")
|
||||
private int max = 0;
|
||||
|
||||
@@ -66,70 +62,6 @@ public class IrisBiomeGeneratorLink {
|
||||
});
|
||||
}
|
||||
|
||||
private int[] getBiomeGeneratorsRaw(Engine engine) {
|
||||
int max = engine.getDimension().getMinHeight();
|
||||
int min = engine.getDimension().getMaxHeight();
|
||||
for (IrisBiome biome : engine.getAllBiomes()) {
|
||||
for (IrisBiomeGeneratorLink i : biome.getGenerators()) {
|
||||
int biomeRawMax = i.getMaxRaw();
|
||||
int biomeRawMin = i.getMinRaw();
|
||||
if (max < biomeRawMax)
|
||||
max = biomeRawMax;
|
||||
if (min > biomeRawMin)
|
||||
min = biomeRawMin;
|
||||
}
|
||||
}
|
||||
|
||||
return new int[] { min, max };
|
||||
}
|
||||
|
||||
private int calculateHeight(Engine engine, int option) {
|
||||
int dmx = engine.getDimension().getMaxHeight();
|
||||
int dmn = engine.getDimension().getMinHeight();
|
||||
int[] heights = getBiomeGeneratorsRaw(engine);
|
||||
int gmx = heights[1];
|
||||
int gmn = heights[0];
|
||||
|
||||
int mx = getMaxRaw();
|
||||
int mn = getMinRaw();
|
||||
if (engine.getDimension().isSmartVanillaHeight()) {
|
||||
if (mx > 0)
|
||||
mx = Math.min((int) (((float) mx / (float) gmx) * 300.0f), 300);
|
||||
if (mx < 0)
|
||||
mx = Math.min((int) (((float) mx / (float) gmn) * 300.0f), 56);
|
||||
|
||||
if (mn > 0)
|
||||
mn = Math.min((int) (((float) mn / (float) gmx) * 300.0f), 300);
|
||||
if (mn < 0)
|
||||
mn = Math.min((int) (((float) mn / (float) gmn) * 300.0f), 56);
|
||||
}
|
||||
|
||||
if (option == 1) {
|
||||
return mx;
|
||||
}
|
||||
if (option == 0) {
|
||||
return mn;
|
||||
}
|
||||
Iris.error("Fatal Generator error!");
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int getMax(Engine engine) {
|
||||
return calculateHeight(engine, 1);
|
||||
}
|
||||
|
||||
public int getMin(Engine engine) {
|
||||
return calculateHeight(engine, 0);
|
||||
}
|
||||
|
||||
private int getMaxRaw() {
|
||||
return max;
|
||||
}
|
||||
|
||||
private int getMinRaw() {
|
||||
return min;
|
||||
}
|
||||
|
||||
public double getHeight(DataProvider xg, double x, double z, long seed) {
|
||||
double g = getCachedGenerator(xg).getHeight(x, z, seed);
|
||||
g = g < 0 ? 0 : g;
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
package com.volmit.iris.engine.object;
|
||||
|
||||
import com.volmit.iris.core.nms.INMS;
|
||||
import com.volmit.iris.core.nms.container.AutoClosing;
|
||||
import com.volmit.iris.util.misc.ServerProperties;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.world.WorldInitEvent;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static com.volmit.iris.Iris.instance;
|
||||
|
||||
public class IrisContextInjector implements Listener {
|
||||
private AutoClosing autoClosing = null;
|
||||
private final int totalWorlds;
|
||||
private int worldCounter = 0;
|
||||
|
||||
public IrisContextInjector() {
|
||||
if (!Bukkit.getWorlds().isEmpty()) {
|
||||
totalWorlds = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
String levelName = ServerProperties.LEVEL_NAME;
|
||||
List<String> irisWorlds = irisWorlds();
|
||||
boolean overworld = irisWorlds.contains(levelName);
|
||||
boolean nether = irisWorlds.contains(levelName + "_nether");
|
||||
boolean end = irisWorlds.contains(levelName + "_end");
|
||||
|
||||
int i = 1;
|
||||
if (Bukkit.getAllowNether()) i++;
|
||||
if (Bukkit.getAllowEnd()) i++;
|
||||
|
||||
if (overworld || nether || end) {
|
||||
var pair = INMS.get().injectUncached(overworld, nether, end);
|
||||
i += pair.getA() - 3;
|
||||
autoClosing = pair.getB();
|
||||
}
|
||||
|
||||
totalWorlds = i;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void on(WorldInitEvent event) {
|
||||
if (++worldCounter < totalWorlds) return;
|
||||
if (autoClosing != null) {
|
||||
autoClosing.close();
|
||||
autoClosing = null;
|
||||
}
|
||||
instance.unregisterListener(this);
|
||||
}
|
||||
|
||||
private List<String> irisWorlds() {
|
||||
var config = YamlConfiguration.loadConfiguration(ServerProperties.BUKKIT_YML);
|
||||
ConfigurationSection section = config.getConfigurationSection("worlds");
|
||||
if (section == null) return List.of();
|
||||
|
||||
return section.getKeys(false)
|
||||
.stream()
|
||||
.filter(k -> section.getString(k + ".generator", "").startsWith("Iris"))
|
||||
.toList();
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,8 @@
|
||||
package com.volmit.iris.engine.object;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.core.IrisSettings;
|
||||
import com.volmit.iris.core.ServerConfigurator.DimensionHeight;
|
||||
import com.volmit.iris.core.loader.IrisData;
|
||||
import com.volmit.iris.core.loader.IrisRegistrant;
|
||||
import com.volmit.iris.core.nms.INMS;
|
||||
@@ -26,6 +28,7 @@ import com.volmit.iris.core.nms.datapack.IDataFixer;
|
||||
import com.volmit.iris.engine.data.cache.AtomicCache;
|
||||
import com.volmit.iris.engine.object.annotations.*;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.collection.KSet;
|
||||
import com.volmit.iris.util.data.DataProvider;
|
||||
import com.volmit.iris.util.io.IO;
|
||||
import com.volmit.iris.util.json.JSONObject;
|
||||
@@ -54,73 +57,6 @@ import java.io.IOException;
|
||||
public class IrisDimension extends IrisRegistrant {
|
||||
public static final BlockData STONE = Material.STONE.createBlockData();
|
||||
public static final BlockData WATER = Material.WATER.createBlockData();
|
||||
private static final String DP_OVERWORLD_DEFAULT = """
|
||||
{
|
||||
"ambient_light": 0.0,
|
||||
"bed_works": true,
|
||||
"coordinate_scale": 1.0,
|
||||
"effects": "minecraft:overworld",
|
||||
"has_ceiling": false,
|
||||
"has_raids": true,
|
||||
"has_skylight": true,
|
||||
"infiniburn": "#minecraft:infiniburn_overworld",
|
||||
"monster_spawn_block_light_limit": 0,
|
||||
"monster_spawn_light_level": {
|
||||
"type": "minecraft:uniform",
|
||||
"value": {
|
||||
"max_inclusive": 7,
|
||||
"min_inclusive": 0
|
||||
}
|
||||
},
|
||||
"natural": true,
|
||||
"piglin_safe": false,
|
||||
"respawn_anchor_works": false,
|
||||
"ultrawarm": false
|
||||
}""";
|
||||
|
||||
private static final String DP_NETHER_DEFAULT = """
|
||||
{
|
||||
"ambient_light": 0.1,
|
||||
"bed_works": false,
|
||||
"coordinate_scale": 8.0,
|
||||
"effects": "minecraft:the_nether",
|
||||
"fixed_time": 18000,
|
||||
"has_ceiling": true,
|
||||
"has_raids": false,
|
||||
"has_skylight": false,
|
||||
"infiniburn": "#minecraft:infiniburn_nether",
|
||||
"monster_spawn_block_light_limit": 15,
|
||||
"monster_spawn_light_level": 7,
|
||||
"natural": false,
|
||||
"piglin_safe": true,
|
||||
"respawn_anchor_works": true,
|
||||
"ultrawarm": true
|
||||
}""";
|
||||
|
||||
private static final String DP_END_DEFAULT = """
|
||||
{
|
||||
"ambient_light": 0.0,
|
||||
"bed_works": false,
|
||||
"coordinate_scale": 1.0,
|
||||
"effects": "minecraft:the_end",
|
||||
"fixed_time": 6000,
|
||||
"has_ceiling": false,
|
||||
"has_raids": true,
|
||||
"has_skylight": false,
|
||||
"infiniburn": "#minecraft:infiniburn_end",
|
||||
"monster_spawn_block_light_limit": 0,
|
||||
"monster_spawn_light_level": {
|
||||
"type": "minecraft:uniform",
|
||||
"value": {
|
||||
"max_inclusive": 7,
|
||||
"min_inclusive": 0
|
||||
}
|
||||
},
|
||||
"natural": false,
|
||||
"piglin_safe": false,
|
||||
"respawn_anchor_works": false,
|
||||
"ultrawarm": false
|
||||
}""";
|
||||
private final transient AtomicCache<Position2> parallaxSize = new AtomicCache<>();
|
||||
private final transient AtomicCache<CNG> rockLayerGenerator = new AtomicCache<>();
|
||||
private final transient AtomicCache<CNG> fluidLayerGenerator = new AtomicCache<>();
|
||||
@@ -234,8 +170,6 @@ public class IrisDimension extends IrisRegistrant {
|
||||
private IrisRange dimensionHeightEnd = new IrisRange(-64, 320);
|
||||
@Desc("Define the min and max Y bounds of this dimension. Please keep in mind that Iris internally generates from 0 to (max - min). \n\nFor example at -64 to 320, Iris is internally generating to 0 to 384, then on outputting chunks, it shifts it down by the min height (64 blocks). The default is -64 to 320. \n\nThe fluid height is placed at (fluid height + min height). So a fluid height of 63 would actually show up in the world at 1.")
|
||||
private IrisRange dimensionHeightNether = new IrisRange(-64, 320);
|
||||
@Desc("Enable smart vanilla height")
|
||||
private boolean smartVanillaHeight = false;
|
||||
@RegistryListResource(IrisBiome.class)
|
||||
@Desc("Keep this either undefined or empty. Setting any biome name into this will force iris to only generate the specified biome. Great for testing.")
|
||||
private String focus = "";
|
||||
@@ -310,8 +244,6 @@ public class IrisDimension extends IrisRegistrant {
|
||||
@MaxNumber(318)
|
||||
@Desc("The Subterrain Fluid Layer Height")
|
||||
private int caveLavaHeight = 8;
|
||||
@Desc("Static Placements for objects and structures")
|
||||
private IrisStaticPlacements staticPlacements = new IrisStaticPlacements();
|
||||
|
||||
public int getMaxHeight() {
|
||||
return (int) getDimensionHeight().getMax();
|
||||
@@ -447,61 +379,35 @@ public class IrisDimension extends IrisRegistrant {
|
||||
return landBiomeStyle;
|
||||
}
|
||||
|
||||
public boolean installDataPack(IDataFixer fixer, DataProvider data, File datapacks, double ultimateMaxHeight, double ultimateMinHeight) {
|
||||
boolean write = false;
|
||||
boolean changed = false;
|
||||
|
||||
IO.delete(new File(datapacks, "iris/data/" + getLoadKey().toLowerCase()));
|
||||
|
||||
for (IrisBiome i : getAllBiomes(data)) {
|
||||
if (i.isCustom()) {
|
||||
write = true;
|
||||
|
||||
for (IrisBiomeCustom j : i.getCustomDerivitives()) {
|
||||
File output = new File(datapacks, "iris/data/" + getLoadKey().toLowerCase() + "/worldgen/biome/" + j.getId() + ".json");
|
||||
|
||||
if (!output.exists()) {
|
||||
changed = true;
|
||||
}
|
||||
|
||||
Iris.verbose(" Installing Data Pack Biome: " + output.getPath());
|
||||
output.getParentFile().mkdirs();
|
||||
try {
|
||||
IO.writeAll(output, j.generateJson(fixer));
|
||||
} catch (IOException e) {
|
||||
Iris.reportError(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!dimensionHeight.equals(new IrisRange(-64, 320)) && this.name.equalsIgnoreCase("overworld")) {
|
||||
Iris.verbose(" Installing Data Pack Dimension Types: \"minecraft:overworld\", \"minecraft:the_nether\", \"minecraft:the_end\"");
|
||||
dimensionHeight.setMax(ultimateMaxHeight);
|
||||
dimensionHeight.setMin(ultimateMinHeight);
|
||||
changed = writeDimensionType(fixer, changed, datapacks);
|
||||
}
|
||||
|
||||
if (write) {
|
||||
File mcm = new File(datapacks, "iris/pack.mcmeta");
|
||||
try {
|
||||
IO.writeAll(mcm, """
|
||||
{
|
||||
"pack": {
|
||||
"description": "Iris Data Pack. This pack contains all installed Iris Packs' resources.",
|
||||
"pack_format": {}
|
||||
}
|
||||
public void installBiomes(IDataFixer fixer, DataProvider data, KList<File> folders, KSet<String> biomes) {
|
||||
getAllBiomes(data)
|
||||
.stream()
|
||||
.filter(IrisBiome::isCustom)
|
||||
.map(IrisBiome::getCustomDerivitives)
|
||||
.flatMap(KList::stream)
|
||||
.parallel()
|
||||
.forEach(j -> {
|
||||
String json = j.generateJson(fixer);
|
||||
synchronized (biomes) {
|
||||
if (!biomes.add(j.getId())) {
|
||||
Iris.verbose("Duplicate Data Pack Biome: " + getLoadKey() + "/" + j.getId());
|
||||
return;
|
||||
}
|
||||
""".replace("{}", INMS.get().getDataVersion().getPackFormat() + ""));
|
||||
} catch (IOException e) {
|
||||
Iris.reportError(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
Iris.verbose(" Installing Data Pack MCMeta: " + mcm.getPath());
|
||||
}
|
||||
}
|
||||
|
||||
return changed;
|
||||
for (File datapacks : folders) {
|
||||
File output = new File(datapacks, "iris/data/" + getLoadKey().toLowerCase() + "/worldgen/biome/" + j.getId() + ".json");
|
||||
|
||||
Iris.verbose(" Installing Data Pack Biome: " + output.getPath());
|
||||
output.getParentFile().mkdirs();
|
||||
try {
|
||||
IO.writeAll(output, json);
|
||||
} catch (IOException e) {
|
||||
Iris.reportError(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -519,66 +425,55 @@ public class IrisDimension extends IrisRegistrant {
|
||||
|
||||
}
|
||||
|
||||
public boolean writeDimensionType(IDataFixer fixer, boolean changed, File datapacks) {
|
||||
File dimTypeOverworld = new File(datapacks, "iris/data/minecraft/dimension_type/overworld.json");
|
||||
if (!dimTypeOverworld.exists())
|
||||
changed = true;
|
||||
dimTypeOverworld.getParentFile().mkdirs();
|
||||
public static void writeShared(KList<File> folders, DimensionHeight height) {
|
||||
Iris.verbose(" Installing Data Pack Dimension Types: \"iris:overworld\", \"iris:the_nether\", \"iris:the_end\"");
|
||||
for (File datapacks : folders) {
|
||||
write(datapacks, "overworld", height.overworldType());
|
||||
write(datapacks, "the_nether", height.netherType());
|
||||
write(datapacks, "the_end", height.endType());
|
||||
}
|
||||
|
||||
String raw = """
|
||||
{
|
||||
"pack": {
|
||||
"description": "Iris Data Pack. This pack contains all installed Iris Packs' resources.",
|
||||
"pack_format": {}
|
||||
}
|
||||
}
|
||||
""".replace("{}", INMS.get().getDataVersion().getPackFormat() + "");
|
||||
|
||||
for (File datapacks : folders) {
|
||||
File mcm = new File(datapacks, "iris/pack.mcmeta");
|
||||
try {
|
||||
IO.writeAll(mcm, raw);
|
||||
} catch (IOException e) {
|
||||
Iris.reportError(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
Iris.verbose(" Installing Data Pack MCMeta: " + mcm.getPath());
|
||||
}
|
||||
}
|
||||
|
||||
private static void write(File datapacks, String type, String json) {
|
||||
File dimType = new File(datapacks, "iris/data/iris/dimension_type/" + type + ".json");
|
||||
File dimTypeVanilla = new File(datapacks, "iris/data/minecraft/dimension_type/" + type + ".json");
|
||||
|
||||
dimType.getParentFile().mkdirs();
|
||||
try {
|
||||
IO.writeAll(dimTypeOverworld, generateDatapackJsonOverworld(fixer));
|
||||
IO.writeAll(dimType, json);
|
||||
} catch (IOException e) {
|
||||
Iris.reportError(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
File dimTypeNether = new File(datapacks, "iris/data/minecraft/dimension_type/the_nether.json");
|
||||
if (!dimTypeNether.exists())
|
||||
changed = true;
|
||||
dimTypeNether.getParentFile().mkdirs();
|
||||
try {
|
||||
IO.writeAll(dimTypeNether, generateDatapackJsonNether(fixer));
|
||||
} catch (IOException e) {
|
||||
Iris.reportError(e);
|
||||
e.printStackTrace();
|
||||
if (IrisSettings.get().getGeneral().adjustVanillaHeight || dimTypeVanilla.exists()) {
|
||||
dimTypeVanilla.getParentFile().mkdirs();
|
||||
try {
|
||||
IO.writeAll(dimTypeVanilla, json);
|
||||
} catch (IOException e) {
|
||||
Iris.reportError(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
File dimTypeEnd = new File(datapacks, "iris/data/minecraft/dimension_type/the_end.json");
|
||||
if (!dimTypeEnd.exists())
|
||||
changed = true;
|
||||
dimTypeEnd.getParentFile().mkdirs();
|
||||
try {
|
||||
IO.writeAll(dimTypeEnd, generateDatapackJsonEnd(fixer));
|
||||
} catch (IOException e) {
|
||||
Iris.reportError(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return changed;
|
||||
}
|
||||
|
||||
private String generateDatapackJsonOverworld(IDataFixer fixer) {
|
||||
JSONObject obj = new JSONObject(DP_OVERWORLD_DEFAULT);
|
||||
obj.put("min_y", dimensionHeight.getMin());
|
||||
obj.put("height", dimensionHeight.getMax() - dimensionHeight.getMin());
|
||||
obj.put("logical_height", logicalHeight);
|
||||
return fixer.fixDimension(obj).toString(4);
|
||||
}
|
||||
|
||||
private String generateDatapackJsonNether(IDataFixer fixer) {
|
||||
JSONObject obj = new JSONObject(DP_NETHER_DEFAULT);
|
||||
obj.put("min_y", dimensionHeightNether.getMin());
|
||||
obj.put("height", dimensionHeightNether.getMax() - dimensionHeightNether.getMin());
|
||||
obj.put("logical_height", logicalHeightNether);
|
||||
return fixer.fixDimension(obj).toString(4);
|
||||
}
|
||||
|
||||
private String generateDatapackJsonEnd(IDataFixer fixer) {
|
||||
JSONObject obj = new JSONObject(DP_END_DEFAULT);
|
||||
obj.put("min_y", dimensionHeightEnd.getMin());
|
||||
obj.put("height", dimensionHeightEnd.getMax() - dimensionHeightEnd.getMin());
|
||||
obj.put("logical_height", logicalHeightEnd);
|
||||
return fixer.fixDimension(obj).toString(4);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,43 +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.engine.object;
|
||||
|
||||
import com.volmit.iris.engine.framework.Engine;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class IrisEngineChunkData {
|
||||
private long chunk;
|
||||
private KList<IrisEngineSpawnerCooldown> cooldowns = new KList<>();
|
||||
|
||||
public void cleanup(Engine engine) {
|
||||
for (IrisEngineSpawnerCooldown i : getCooldowns().copy()) {
|
||||
IrisSpawner sp = engine.getData().getSpawnerLoader().load(i.getSpawner());
|
||||
|
||||
if (sp == null || i.canSpawn(sp.getMaximumRate())) {
|
||||
getCooldowns().remove(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return cooldowns.isEmpty();
|
||||
}
|
||||
}
|
||||
@@ -20,51 +20,31 @@ package com.volmit.iris.engine.object;
|
||||
|
||||
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 lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
@Data
|
||||
public class IrisEngineData {
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class IrisEngineData extends IrisSpawnerCooldowns {
|
||||
private IrisEngineStatistics statistics = new IrisEngineStatistics();
|
||||
private KList<IrisEngineSpawnerCooldown> spawnerCooldowns = new KList<>();
|
||||
private KList<IrisEngineChunkData> chunks = new KList<>();
|
||||
private KMap<Long, IrisSpawnerCooldowns> chunks = new KMap<>();
|
||||
private Long seed = null;
|
||||
|
||||
public void removeChunk(int x, int z) {
|
||||
long k = Cache.key(x, z);
|
||||
chunks.removeWhere((i) -> i.getChunk() == k);
|
||||
chunks.remove(Cache.key(x, z));
|
||||
}
|
||||
|
||||
public IrisEngineChunkData getChunk(int x, int z) {
|
||||
long k = Cache.key(x, z);
|
||||
|
||||
for (IrisEngineChunkData i : chunks) {
|
||||
if (i.getChunk() == k) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
IrisEngineChunkData c = new IrisEngineChunkData();
|
||||
c.setChunk(k);
|
||||
chunks.add(c);
|
||||
return c;
|
||||
public IrisSpawnerCooldowns getChunk(int x, int z) {
|
||||
return chunks.computeIfAbsent(Cache.key(x, z), k -> new IrisSpawnerCooldowns());
|
||||
}
|
||||
|
||||
public void cleanup(Engine engine) {
|
||||
for (IrisEngineSpawnerCooldown i : getSpawnerCooldowns().copy()) {
|
||||
IrisSpawner sp = engine.getData().getSpawnerLoader().load(i.getSpawner());
|
||||
super.cleanup(engine);
|
||||
|
||||
if (sp == null || i.canSpawn(sp.getMaximumRate())) {
|
||||
getSpawnerCooldowns().remove(i);
|
||||
}
|
||||
}
|
||||
|
||||
for (IrisEngineChunkData i : chunks.copy()) {
|
||||
i.cleanup(engine);
|
||||
|
||||
if (i.isEmpty()) {
|
||||
getChunks().remove(i);
|
||||
}
|
||||
}
|
||||
chunks.values().removeIf(chunk -> {
|
||||
chunk.cleanup(engine);
|
||||
return chunk.isEmpty();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,6 @@ import com.volmit.iris.util.format.C;
|
||||
import com.volmit.iris.util.json.JSONObject;
|
||||
import com.volmit.iris.util.math.M;
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
import com.volmit.iris.util.misc.E;
|
||||
import com.volmit.iris.util.plugin.Chunks;
|
||||
import com.volmit.iris.util.plugin.VolmitSender;
|
||||
import com.volmit.iris.util.scheduling.J;
|
||||
@@ -57,6 +56,8 @@ import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import static com.volmit.iris.util.data.registry.Particles.ITEM;
|
||||
|
||||
@SuppressWarnings("ALL")
|
||||
@Accessors(chain = true)
|
||||
@NoArgsConstructor
|
||||
@@ -66,7 +67,6 @@ import java.util.concurrent.atomic.AtomicReference;
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class IrisEntity extends IrisRegistrant {
|
||||
private static final Particle ITEM = E.getOrDefault(Particle.class, "ITEM_CRACK", "ITEM");
|
||||
@Required
|
||||
@Desc("The type of entity to spawn. To spawn a mythic mob, set this type to unknown and define mythic type.")
|
||||
private EntityType type = EntityType.UNKNOWN;
|
||||
|
||||
@@ -24,6 +24,7 @@ import com.dfsek.paralithic.eval.parser.Scope;
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.core.loader.IrisRegistrant;
|
||||
import com.volmit.iris.engine.data.cache.AtomicCache;
|
||||
import com.volmit.iris.engine.object.IrisExpressionFunction.FunctionContext;
|
||||
import com.volmit.iris.engine.object.annotations.ArrayType;
|
||||
import com.volmit.iris.engine.object.annotations.Desc;
|
||||
import com.volmit.iris.engine.object.annotations.Required;
|
||||
@@ -46,12 +47,14 @@ import lombok.experimental.Accessors;
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class IrisExpression extends IrisRegistrant {
|
||||
private static final Parser parser = new Parser();
|
||||
|
||||
@ArrayType(type = IrisExpressionLoad.class, min = 1)
|
||||
@Desc("Variables to use in this expression")
|
||||
private KList<IrisExpressionLoad> variables = new KList<>();
|
||||
|
||||
@ArrayType(type = IrisExpressionFunction.class, min = 1)
|
||||
@Desc("Functions to use in this expression")
|
||||
private KList<IrisExpressionFunction> functions = new KList<>();
|
||||
|
||||
@Required
|
||||
@Desc("The expression. Inherited variables are x, y and z. Avoid using those variable names.")
|
||||
private String expression;
|
||||
@@ -62,6 +65,7 @@ public class IrisExpression extends IrisRegistrant {
|
||||
private Expression expression() {
|
||||
return expressionCache.aquire(() -> {
|
||||
Scope scope = new Scope(); // Create variable scope. This scope can hold both constants and invocation variables.
|
||||
Parser parser = new Parser();
|
||||
|
||||
try {
|
||||
for (IrisExpressionLoad i : variables) {
|
||||
@@ -76,6 +80,12 @@ public class IrisExpression extends IrisRegistrant {
|
||||
Iris.error("Script Variable load error in " + getLoadFile().getPath());
|
||||
}
|
||||
|
||||
for (IrisExpressionFunction f : functions) {
|
||||
if (!f.isValid()) continue;
|
||||
f.setData(getLoader());
|
||||
parser.registerFunction(f.getName(), f);
|
||||
}
|
||||
|
||||
try {
|
||||
return parser.parse(getExpression(), scope);
|
||||
} catch (Throwable e) {
|
||||
@@ -103,7 +113,7 @@ public class IrisExpression extends IrisRegistrant {
|
||||
g[m++] = z;
|
||||
g[m] = -1;
|
||||
|
||||
return expression().evaluate(g);
|
||||
return expression().evaluate(new FunctionContext(rng), g);
|
||||
}
|
||||
|
||||
public double evaluate(RNG rng, double x, double y, double z) {
|
||||
@@ -117,7 +127,7 @@ public class IrisExpression extends IrisRegistrant {
|
||||
g[m++] = y;
|
||||
g[m] = z;
|
||||
|
||||
return expression().evaluate(g);
|
||||
return expression().evaluate(new FunctionContext(rng), g);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
package com.volmit.iris.engine.object;
|
||||
|
||||
import com.dfsek.paralithic.functions.dynamic.Context;
|
||||
import com.dfsek.paralithic.functions.dynamic.DynamicFunction;
|
||||
import com.dfsek.paralithic.node.Statefulness;
|
||||
import com.volmit.iris.core.loader.IrisData;
|
||||
import com.volmit.iris.engine.object.annotations.Desc;
|
||||
import com.volmit.iris.engine.object.annotations.MinNumber;
|
||||
import com.volmit.iris.engine.object.annotations.Required;
|
||||
import com.volmit.iris.engine.object.annotations.Snippet;
|
||||
import com.volmit.iris.util.collection.KMap;
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
import lombok.*;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@Snippet("expression-function")
|
||||
@Accessors(chain = true)
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Desc("Represents a function to use in your expression. Do not set the name to x, y, or z, also don't duplicate names.")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class IrisExpressionFunction implements DynamicFunction {
|
||||
@Required
|
||||
@Desc("The function to assign this value to. Do not set the name to x, y, or z")
|
||||
private String name;
|
||||
|
||||
@Desc("If defined, this variable will use a generator style as it's value")
|
||||
private IrisGeneratorStyle styleValue = null;
|
||||
|
||||
@Desc("If defined, iris will use an internal stream from the engine as it's value")
|
||||
private IrisEngineStreamType engineStreamValue = null;
|
||||
|
||||
@MinNumber(2)
|
||||
@Desc("Number of arguments for the function")
|
||||
private int args = 2;
|
||||
|
||||
@Getter(AccessLevel.NONE)
|
||||
@Setter(AccessLevel.NONE)
|
||||
private transient final KMap<FunctionContext, Provider> cache = new KMap<>();
|
||||
private transient IrisData data;
|
||||
|
||||
public boolean isValid() {
|
||||
return styleValue != null || engineStreamValue != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getArgNumber() {
|
||||
if (engineStreamValue != null) return 2;
|
||||
return Math.max(args, 2);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Statefulness statefulness() {
|
||||
return Statefulness.STATEFUL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double eval(double... doubles) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double eval(@Nullable Context raw, double... args) {
|
||||
return cache.computeIfAbsent((FunctionContext) raw, context -> {
|
||||
assert context != null;
|
||||
if (engineStreamValue != null) {
|
||||
var stream = engineStreamValue.get(data.getEngine());
|
||||
return d -> stream.get(d[0], d[1]);
|
||||
}
|
||||
|
||||
if (styleValue != null) {
|
||||
return styleValue.createNoCache(context.rng, data)::noise;
|
||||
}
|
||||
|
||||
return d -> Double.NaN;
|
||||
}).eval(args);
|
||||
}
|
||||
|
||||
public record FunctionContext(@NonNull RNG rng) implements Context {
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
FunctionContext that = (FunctionContext) o;
|
||||
return rng.getSeed() == that.rng.getSeed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Long.hashCode(rng.getSeed());
|
||||
}
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
private interface Provider {
|
||||
double eval(double... args);
|
||||
}
|
||||
}
|
||||
@@ -23,12 +23,11 @@ import com.volmit.iris.engine.data.cache.AtomicCache;
|
||||
import com.volmit.iris.engine.object.annotations.Desc;
|
||||
import com.volmit.iris.engine.object.annotations.Required;
|
||||
import com.volmit.iris.engine.object.annotations.Snippet;
|
||||
import com.volmit.iris.util.collection.KMap;
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
import com.volmit.iris.util.noise.CNG;
|
||||
import com.volmit.iris.util.stream.ProceduralStream;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.*;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@Snippet("expression-load")
|
||||
@@ -57,6 +56,9 @@ public class IrisExpressionLoad {
|
||||
|
||||
private transient AtomicCache<ProceduralStream<Double>> streamCache = new AtomicCache<>();
|
||||
private transient AtomicCache<Double> valueCache = new AtomicCache<>();
|
||||
@Getter(AccessLevel.NONE)
|
||||
@Setter(AccessLevel.NONE)
|
||||
private transient final KMap<Long, CNG> styleCache = new KMap<>();
|
||||
|
||||
public double getValue(RNG rng, IrisData data, double x, double z) {
|
||||
if (engineValue != null) {
|
||||
@@ -68,7 +70,8 @@ public class IrisExpressionLoad {
|
||||
}
|
||||
|
||||
if (styleValue != null) {
|
||||
return styleValue.create(rng, data).noise(x, z);
|
||||
return styleCache.computeIfAbsent(rng.getSeed(), k -> styleValue.createNoCache(new RNG(k), data))
|
||||
.noise(x, z);
|
||||
}
|
||||
|
||||
return staticValue;
|
||||
@@ -84,7 +87,8 @@ public class IrisExpressionLoad {
|
||||
}
|
||||
|
||||
if (styleValue != null) {
|
||||
return styleValue.create(rng, data).noise(x, y, z);
|
||||
return styleCache.computeIfAbsent(rng.getSeed(), k -> styleValue.createNoCache(new RNG(k), data))
|
||||
.noise(x, y, z);
|
||||
}
|
||||
|
||||
return staticValue;
|
||||
|
||||
@@ -139,6 +139,14 @@ public class IrisJigsawStructure extends IrisRegistrant {
|
||||
loadPiece(i, pools, pieces);
|
||||
}
|
||||
|
||||
if (pieces.isEmpty()) {
|
||||
int max = 0;
|
||||
for (String i : getPieces()) {
|
||||
max = Math.max(max, getLoader().getJigsawPieceLoader().load(i).getMax2dDimension());
|
||||
}
|
||||
return max;
|
||||
}
|
||||
|
||||
int avg = 0;
|
||||
|
||||
for (String i : pieces) {
|
||||
|
||||
@@ -19,13 +19,8 @@
|
||||
package com.volmit.iris.engine.object;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.engine.object.annotations.ArrayType;
|
||||
import com.volmit.iris.engine.object.annotations.Desc;
|
||||
import com.volmit.iris.engine.object.annotations.MaxNumber;
|
||||
import com.volmit.iris.engine.object.annotations.MinNumber;
|
||||
import com.volmit.iris.engine.object.annotations.RegistryListResource;
|
||||
import com.volmit.iris.engine.object.annotations.Required;
|
||||
import com.volmit.iris.engine.object.annotations.Snippet;
|
||||
import com.volmit.iris.core.loader.IrisData;
|
||||
import com.volmit.iris.engine.object.annotations.*;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.collection.KMap;
|
||||
import com.volmit.iris.util.documentation.ChunkCoordinates;
|
||||
@@ -54,6 +49,7 @@ public class IrisJigsawStructurePlacement implements IRare {
|
||||
private int rarity = 100;
|
||||
|
||||
@Required
|
||||
@DependsOn({"spacing", "separation"})
|
||||
@Desc("The salt to use when generating the structure (to differentiate structures)")
|
||||
@MinNumber(Long.MIN_VALUE)
|
||||
@MaxNumber(Long.MAX_VALUE)
|
||||
@@ -61,16 +57,26 @@ public class IrisJigsawStructurePlacement implements IRare {
|
||||
|
||||
@Required
|
||||
@MinNumber(0)
|
||||
@DependsOn({"salt", "separation"})
|
||||
@Desc("Average distance in chunks between two neighboring generation attempts")
|
||||
private int spacing = -1;
|
||||
|
||||
@Required
|
||||
@MinNumber(0)
|
||||
@DependsOn({"salt", "spacing"})
|
||||
@Desc("Minimum distance in chunks between two neighboring generation attempts\nThe maximum distance of two neighboring generation attempts is 2*spacing - separation")
|
||||
private int separation = -1;
|
||||
|
||||
@Desc("The method used to spread the structure")
|
||||
private SpreadType spreadType = SpreadType.TRIANGULAR;
|
||||
private SpreadType spreadType = SpreadType.LINEAR;
|
||||
|
||||
@DependsOn({"spreadType"})
|
||||
@Desc("The noise style to use when spreadType is set to 'NOISE'\nThis ignores the spacing and separation parameters")
|
||||
private IrisGeneratorStyle style = new IrisGeneratorStyle();
|
||||
|
||||
@DependsOn({"spreadType", "style"})
|
||||
@Desc("Threshold for noise style")
|
||||
private double threshold = 0.5;
|
||||
|
||||
@ArrayType(type = IrisJigsawMinDistance.class)
|
||||
@Desc("List of minimum distances to check for")
|
||||
@@ -89,20 +95,29 @@ public class IrisJigsawStructurePlacement implements IRare {
|
||||
}
|
||||
|
||||
private void calculateMissing(double divisor, long seed) {
|
||||
seed = seed + hashCode();
|
||||
if (salt != 0 && separation > 0 && spacing > 0)
|
||||
return;
|
||||
seed *= (long) structure.hashCode() * rarity;
|
||||
if (salt == 0) {
|
||||
salt = new RNG(seed).nextLong(Integer.MIN_VALUE, Integer.MAX_VALUE);
|
||||
salt = new RNG(seed).l(Integer.MIN_VALUE, Integer.MAX_VALUE);
|
||||
}
|
||||
|
||||
if (separation == -1 || spacing == -1) {
|
||||
separation = (int) Math.round(rarity / divisor);
|
||||
spacing = new RNG(seed).nextInt(separation, separation * 2);
|
||||
spacing = new RNG(seed).i(separation, separation * 2);
|
||||
}
|
||||
}
|
||||
|
||||
@ChunkCoordinates
|
||||
public boolean shouldPlace(double divisor, long seed, int x, int z) {
|
||||
public boolean shouldPlace(IrisData data, double divisor, long seed, int x, int z) {
|
||||
calculateMissing(divisor, seed);
|
||||
if (spreadType != SpreadType.NOISE)
|
||||
return shouldPlaceSpread(seed, x, z);
|
||||
|
||||
return style.create(new RNG(seed + salt), data).noise(x, z) > threshold;
|
||||
}
|
||||
|
||||
private boolean shouldPlaceSpread(long seed, int x, int z) {
|
||||
if (separation > spacing) {
|
||||
separation = spacing;
|
||||
Iris.warn("JigsawStructurePlacement: separation must be less than or equal to spacing");
|
||||
@@ -123,7 +138,9 @@ public class IrisJigsawStructurePlacement implements IRare {
|
||||
@Desc("Linear spread")
|
||||
LINEAR(RNG::i),
|
||||
@Desc("Triangular spread")
|
||||
TRIANGULAR((rng, bound) -> (rng.i(bound) + rng.i(bound)) / 2);
|
||||
TRIANGULAR((rng, bound) -> (rng.i(bound) + rng.i(bound)) / 2),
|
||||
@Desc("Noise based spread\nThis ignores the spacing and separation parameters")
|
||||
NOISE((rng, bound) -> 0);
|
||||
private final SpreadMethod method;
|
||||
|
||||
SpreadType(SpreadMethod method) {
|
||||
|
||||
@@ -29,7 +29,7 @@ import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.collection.KMap;
|
||||
import com.volmit.iris.util.context.IrisContext;
|
||||
import com.volmit.iris.util.data.B;
|
||||
import com.volmit.iris.util.data.IrisBlockData;
|
||||
import com.volmit.iris.util.data.IrisCustomData;
|
||||
import com.volmit.iris.util.format.Form;
|
||||
import com.volmit.iris.util.interpolation.IrisInterpolation;
|
||||
import com.volmit.iris.util.json.JSONObject;
|
||||
@@ -53,8 +53,6 @@ import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.TileState;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.block.data.MultipleFacing;
|
||||
import org.bukkit.block.data.Waterlogged;
|
||||
@@ -943,7 +941,7 @@ public class IrisObject extends IrisRegistrant {
|
||||
if (j.isExact() ? k.matches(data) : k.getMaterial().equals(data.getMaterial())) {
|
||||
BlockData newData = j.getReplace(rng, i.getX() + x, i.getY() + y, i.getZ() + z, rdata).clone();
|
||||
|
||||
if (newData.getMaterial() == data.getMaterial() && !(newData instanceof IrisBlockData || data instanceof IrisBlockData))
|
||||
if (newData.getMaterial() == data.getMaterial() && !(newData instanceof IrisCustomData || data instanceof IrisCustomData))
|
||||
data = data.merge(newData);
|
||||
else
|
||||
data = newData;
|
||||
@@ -1012,8 +1010,9 @@ public class IrisObject extends IrisRegistrant {
|
||||
}
|
||||
|
||||
boolean wouldReplace = B.isSolid(placer.get(xx, yy, zz)) && B.isVineBlock(data);
|
||||
boolean place = !data.getMaterial().equals(Material.AIR) && !data.getMaterial().equals(Material.CAVE_AIR) && !wouldReplace;
|
||||
|
||||
if (!data.getMaterial().equals(Material.AIR) && !data.getMaterial().equals(Material.CAVE_AIR) && !wouldReplace) {
|
||||
if (data instanceof IrisCustomData || place) {
|
||||
placer.set(xx, yy, zz, data);
|
||||
if (tile != null) {
|
||||
placer.setTile(xx, yy, zz, tile);
|
||||
|
||||
@@ -50,4 +50,10 @@ public class IrisRange {
|
||||
public boolean contains(int v) {
|
||||
return v >= min && v <= max;
|
||||
}
|
||||
|
||||
public IrisRange merge(IrisRange other) {
|
||||
min = Math.min(min, other.min);
|
||||
max = Math.max(max, other.max);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ public class IrisRate {
|
||||
}
|
||||
|
||||
public long getInterval() {
|
||||
long t = per.getMilliseconds() / (amount == 0 ? 1 : amount);
|
||||
long t = per.toMilliseconds() / (amount == 0 ? 1 : amount);
|
||||
return Math.abs(t <= 0 ? 1 : t);
|
||||
}
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
package com.volmit.iris.engine.object;
|
||||
|
||||
import com.volmit.iris.core.loader.IrisRegistrant;
|
||||
import com.volmit.iris.engine.framework.Engine;
|
||||
import com.volmit.iris.engine.object.annotations.ArrayType;
|
||||
import com.volmit.iris.engine.object.annotations.Desc;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
@@ -95,6 +96,37 @@ public class IrisSpawner extends IrisRegistrant {
|
||||
return timeBlock.isWithin(world) && weather.is(world);
|
||||
}
|
||||
|
||||
public boolean canSpawn(Engine engine) {
|
||||
if (!isValid(engine.getWorld().realWorld()))
|
||||
return false;
|
||||
|
||||
var rate = getMaximumRate();
|
||||
return rate.isInfinite() || engine.getEngineData().getCooldown(this).canSpawn(rate);
|
||||
}
|
||||
|
||||
public boolean canSpawn(Engine engine, int x, int z) {
|
||||
if (!canSpawn(engine))
|
||||
return false;
|
||||
|
||||
var rate = getMaximumRatePerChunk();
|
||||
return rate.isInfinite() || engine.getEngineData().getChunk(x, z).getCooldown(this).canSpawn(rate);
|
||||
}
|
||||
|
||||
public void spawn(Engine engine) {
|
||||
if (getMaximumRate().isInfinite())
|
||||
return;
|
||||
|
||||
engine.getEngineData().getCooldown(this).spawn(engine);
|
||||
}
|
||||
|
||||
public void spawn(Engine engine, int x, int z) {
|
||||
spawn(engine);
|
||||
if (getMaximumRatePerChunk().isInfinite())
|
||||
return;
|
||||
|
||||
engine.getEngineData().getChunk(x, z).getCooldown(this).spawn(engine);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFolderName() {
|
||||
return "spawners";
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.volmit.iris.engine.object;
|
||||
|
||||
import com.volmit.iris.engine.framework.Engine;
|
||||
import com.volmit.iris.util.collection.KMap;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NonNull;
|
||||
|
||||
@EqualsAndHashCode
|
||||
public class IrisSpawnerCooldowns {
|
||||
private final KMap<String, IrisEngineSpawnerCooldown> cooldowns = new KMap<>();
|
||||
|
||||
public IrisEngineSpawnerCooldown getCooldown(@NonNull IrisSpawner spawner) {
|
||||
return getCooldown(spawner.getLoadKey());
|
||||
}
|
||||
|
||||
public IrisEngineSpawnerCooldown getCooldown(@NonNull String loadKey) {
|
||||
return cooldowns.computeIfAbsent(loadKey, k -> {
|
||||
IrisEngineSpawnerCooldown cd = new IrisEngineSpawnerCooldown();
|
||||
cd.setSpawner(loadKey);
|
||||
return cd;
|
||||
});
|
||||
}
|
||||
|
||||
public void cleanup(Engine engine) {
|
||||
cooldowns.values().removeIf(cd -> {
|
||||
IrisSpawner sp = engine.getData().getSpawnerLoader().load(cd.getSpawner());
|
||||
return sp == null || cd.canSpawn(sp.getMaximumRate());
|
||||
});
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return cooldowns.isEmpty();
|
||||
}
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
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);
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
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));
|
||||
}
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
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());
|
||||
}
|
||||
}
|
||||
@@ -35,7 +35,6 @@ import java.io.IOException;
|
||||
|
||||
@SuppressWarnings("ALL")
|
||||
@Getter
|
||||
@ToString
|
||||
@EqualsAndHashCode
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor(access = AccessLevel.PROTECTED)
|
||||
@@ -137,4 +136,9 @@ public class TileData implements Cloneable {
|
||||
clone.properties = properties.copy(); //TODO make a deep copy
|
||||
return clone;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return material.getKey() + gson.toJson(properties);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,8 +58,6 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
@@ -86,7 +84,6 @@ public class BukkitChunkGenerator extends ChunkGenerator implements PlatformChun
|
||||
private final boolean studio;
|
||||
private final AtomicInteger a = new AtomicInteger(0);
|
||||
private final CompletableFuture<Integer> spawnChunks = new CompletableFuture<>();
|
||||
private final boolean smartVanillaHeight;
|
||||
private Engine engine;
|
||||
private Looper hotloader;
|
||||
private StudioMode lastMode;
|
||||
@@ -96,7 +93,7 @@ public class BukkitChunkGenerator extends ChunkGenerator implements PlatformChun
|
||||
|
||||
private boolean initialized = false;
|
||||
|
||||
public BukkitChunkGenerator(IrisWorld world, boolean studio, File dataLocation, String dimensionKey, boolean smartVanillaHeight) {
|
||||
public BukkitChunkGenerator(IrisWorld world, boolean studio, File dataLocation, String dimensionKey) {
|
||||
setup = new AtomicBoolean(false);
|
||||
studioGenerator = null;
|
||||
dummyBiomeProvider = new DummyBiomeProvider();
|
||||
@@ -108,7 +105,6 @@ public class BukkitChunkGenerator extends ChunkGenerator implements PlatformChun
|
||||
this.dataLocation = dataLocation;
|
||||
this.dimensionKey = dimensionKey;
|
||||
this.folder = new ReactiveFolder(dataLocation, (_a, _b, _c) -> hotload());
|
||||
this.smartVanillaHeight = smartVanillaHeight;
|
||||
Bukkit.getServer().getPluginManager().registerEvents(this, Iris.instance);
|
||||
}
|
||||
|
||||
@@ -186,14 +182,6 @@ public class BukkitChunkGenerator extends ChunkGenerator implements PlatformChun
|
||||
throw new RuntimeException("Missing Dimension: " + dimensionKey);
|
||||
}
|
||||
}
|
||||
if (smartVanillaHeight) {
|
||||
dimension.setSmartVanillaHeight(true);
|
||||
try (FileWriter writer = new FileWriter(data.getDimensionLoader().fileFor(dimension))) {
|
||||
writer.write(data.getGson().toJson(dimension));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
lastMode = StudioMode.NORMAL;
|
||||
engine = new IrisEngine(new EngineTarget(world, dimension, data), studio);
|
||||
|
||||
@@ -487,7 +487,7 @@ public class KList<T> extends ArrayList<T> implements List<T> {
|
||||
return pop();
|
||||
}
|
||||
|
||||
return remove(rng.i(0, size()));
|
||||
return remove(rng.i(0, last()));
|
||||
}
|
||||
|
||||
public KList<T> sub(int f, int t) {
|
||||
|
||||
@@ -22,10 +22,9 @@ import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.core.IrisSettings;
|
||||
import com.volmit.iris.core.link.Identifier;
|
||||
import com.volmit.iris.core.service.ExternalDataSVC;
|
||||
import com.volmit.iris.engine.object.IrisCompat;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.collection.KMap;
|
||||
import com.volmit.iris.util.misc.E;
|
||||
import com.volmit.iris.util.data.registry.Materials;
|
||||
import com.volmit.iris.util.scheduling.ChronoLatch;
|
||||
import it.unimi.dsi.fastutil.ints.*;
|
||||
import org.bukkit.Bukkit;
|
||||
@@ -47,7 +46,7 @@ public class B {
|
||||
private static final KMap<String, BlockData> custom = new KMap<>();
|
||||
|
||||
private static final Material AIR_MATERIAL = Material.AIR;
|
||||
private static final Material SHORT_GRASS = E.getOrDefault(Material.class, "GRASS", "SHORT_GRASS");
|
||||
private static final Material SHORT_GRASS = Materials.GRASS;
|
||||
private static final BlockData AIR = AIR_MATERIAL.createBlockData();
|
||||
private static final IntSet foliageCache = buildFoliageCache();
|
||||
private static final IntSet deepslateCache = buildDeepslateCache();
|
||||
|
||||
@@ -15,7 +15,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@Data
|
||||
public class IrisBlockData implements BlockData {
|
||||
public class IrisCustomData implements BlockData {
|
||||
private final @NonNull BlockData base;
|
||||
private final @NotNull Identifier custom;
|
||||
|
||||
@@ -40,12 +40,12 @@ public class IrisBlockData implements BlockData {
|
||||
@NotNull
|
||||
@Override
|
||||
public BlockData merge(@NotNull BlockData blockData) {
|
||||
return new IrisBlockData(base.merge(blockData), custom);
|
||||
return new IrisCustomData(base.merge(blockData), custom);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(@Nullable BlockData blockData) {
|
||||
if (blockData instanceof IrisBlockData b)
|
||||
if (blockData instanceof IrisCustomData b)
|
||||
return custom.equals(b.custom) && base.matches(b.base);
|
||||
return base.matches(blockData);
|
||||
}
|
||||
@@ -53,7 +53,7 @@ public class IrisBlockData implements BlockData {
|
||||
@NotNull
|
||||
@Override
|
||||
public BlockData clone() {
|
||||
return new IrisBlockData(base.clone(), custom);
|
||||
return new IrisCustomData(base.clone(), custom);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.volmit.iris.util.data.registry;
|
||||
|
||||
import org.bukkit.attribute.Attribute;
|
||||
|
||||
public class Attributes {
|
||||
public static final Attribute MAX_HEALTH = RegistryUtil.find(Attribute.class, "generic_max_health", "max_health");
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.volmit.iris.util.data.registry;
|
||||
|
||||
import org.bukkit.Material;
|
||||
|
||||
import static com.volmit.iris.util.data.registry.RegistryUtil.find;
|
||||
|
||||
public class Materials {
|
||||
public static final Material GRASS = find(Material.class, "grass", "short_grass");
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.volmit.iris.util.data.registry;
|
||||
|
||||
import org.bukkit.Particle;
|
||||
|
||||
import static com.volmit.iris.util.data.registry.RegistryUtil.find;
|
||||
|
||||
public class Particles {
|
||||
public static final Particle CRIT_MAGIC = find(Particle.class, "crit_magic", "crit");
|
||||
public static final Particle REDSTONE = find(Particle.class, "redstone", "dust");
|
||||
public static final Particle ITEM = find(Particle.class, "item_crack", "item");
|
||||
}
|
||||
@@ -0,0 +1,209 @@
|
||||
package com.volmit.iris.util.data.registry;
|
||||
|
||||
import com.volmit.iris.core.nms.container.Pair;
|
||||
import com.volmit.iris.engine.data.cache.AtomicCache;
|
||||
import lombok.NonNull;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Keyed;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.Registry;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public class RegistryUtil {
|
||||
private static final AtomicCache<RegistryLookup> registryLookup = new AtomicCache<>();
|
||||
private static final Map<Class<?>, Map<NamespacedKey, Keyed>> KEYED_REGISTRY = new HashMap<>();
|
||||
private static final Map<Class<?>, Map<NamespacedKey, Object>> ENUM_REGISTRY = new HashMap<>();
|
||||
private static final Map<Class<?>, Registry<Keyed>> REGISTRY = new HashMap<>();
|
||||
|
||||
@NonNull
|
||||
public static <T> T find(@NonNull Class<T> typeClass, @NonNull String... keys) {
|
||||
return find(typeClass, defaultLookup(), keys);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static <T> T find(@NonNull Class<T> typeClass, @Nullable Lookup<T> lookup, @NonNull String... keys) {
|
||||
return find(typeClass, lookup, Arrays.stream(keys).map(NamespacedKey::minecraft).toArray(NamespacedKey[]::new));
|
||||
}
|
||||
|
||||
public static <T> T find(@NonNull Class<T> typeClass, @NonNull NamespacedKey... keys) {
|
||||
return find(typeClass, defaultLookup(), keys);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static <T> T find(@NonNull Class<T> typeClass, @Nullable Lookup<T> lookup, @NonNull NamespacedKey... keys) {
|
||||
if (keys.length == 0) throw new IllegalArgumentException("Need at least one key");
|
||||
Registry<Keyed> registry = null;
|
||||
if (Keyed.class.isAssignableFrom(typeClass)) {
|
||||
registry = getRegistry(typeClass.asSubclass(Keyed.class));
|
||||
}
|
||||
if (registry == null) {
|
||||
registry = REGISTRY.computeIfAbsent(typeClass, t -> Arrays.stream(Registry.class.getDeclaredFields())
|
||||
.filter(field -> Modifier.isStatic(field.getModifiers()) && Modifier.isPublic(field.getModifiers()))
|
||||
.filter(field -> Registry.class.isAssignableFrom(field.getType()))
|
||||
.filter(field -> ((ParameterizedType) field.getGenericType()).getActualTypeArguments()[0].equals(t))
|
||||
.map(field -> {
|
||||
try {
|
||||
return (Registry<Keyed>) field.get(null);
|
||||
} catch (IllegalAccessException e) {
|
||||
return null;
|
||||
}
|
||||
})
|
||||
.filter(Objects::nonNull)
|
||||
.findFirst()
|
||||
.orElse(null));
|
||||
}
|
||||
|
||||
if (registry != null) {
|
||||
for (NamespacedKey key : keys) {
|
||||
Keyed value = registry.get(key);
|
||||
if (value != null)
|
||||
return (T) value;
|
||||
}
|
||||
}
|
||||
|
||||
if (lookup != null)
|
||||
return lookup.find(typeClass, keys);
|
||||
throw new IllegalArgumentException("No element found for keys: " + Arrays.toString(keys));
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static <T> T findByField(@NonNull Class<T> typeClass, @NonNull NamespacedKey... keys) {
|
||||
var values = KEYED_REGISTRY.computeIfAbsent(typeClass, RegistryUtil::getKeyedValues);
|
||||
for (NamespacedKey key : keys) {
|
||||
var value = values.get(key);
|
||||
if (value != null)
|
||||
return (T) value;
|
||||
}
|
||||
throw new IllegalArgumentException("No element found for keys: " + Arrays.toString(keys));
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static <T> T findByEnum(@NonNull Class<T> typeClass, @NonNull NamespacedKey... keys) {
|
||||
var values = ENUM_REGISTRY.computeIfAbsent(typeClass, RegistryUtil::getEnumValues);
|
||||
for (NamespacedKey key : keys) {
|
||||
var value = values.get(key);
|
||||
if (value != null)
|
||||
return (T) value;
|
||||
}
|
||||
throw new IllegalArgumentException("No element found for keys: " + Arrays.toString(keys));
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static <T> Lookup<T> defaultLookup() {
|
||||
return Lookup.combine(RegistryUtil::findByField, RegistryUtil::findByEnum);
|
||||
}
|
||||
|
||||
private static Map<NamespacedKey, Keyed> getKeyedValues(@NonNull Class<?> typeClass) {
|
||||
return Arrays.stream(typeClass.getDeclaredFields())
|
||||
.filter(field -> Modifier.isPublic(field.getModifiers()) && Modifier.isStatic(field.getModifiers()))
|
||||
.filter(field -> Keyed.class.isAssignableFrom(field.getType()))
|
||||
.map(field -> {
|
||||
try {
|
||||
return (Keyed) field.get(null);
|
||||
} catch (Throwable e) {
|
||||
return null;
|
||||
}
|
||||
})
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toMap(Keyed::getKey, Function.identity()));
|
||||
}
|
||||
|
||||
private static Map<NamespacedKey, Object> getEnumValues(@NonNull Class<?> typeClass) {
|
||||
return Arrays.stream(typeClass.getDeclaredFields())
|
||||
.filter(field -> Modifier.isPublic(field.getModifiers()) && Modifier.isStatic(field.getModifiers()))
|
||||
.filter(field -> typeClass.isAssignableFrom(field.getType()))
|
||||
.map(field -> {
|
||||
try {
|
||||
return new Pair<>(NamespacedKey.minecraft(field.getName().toLowerCase()), field.get(null));
|
||||
} catch (Throwable e) {
|
||||
return null;
|
||||
}
|
||||
})
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toMap(Pair::getA, Pair::getB));
|
||||
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface Lookup<T> {
|
||||
@NonNull
|
||||
T find(@NonNull Class<T> typeClass, @NonNull NamespacedKey... keys);
|
||||
|
||||
static <T> Lookup<T> combine(@NonNull Lookup<T>... lookups) {
|
||||
if (lookups.length == 0) throw new IllegalArgumentException("Need at least one lookup");
|
||||
return (typeClass, keys) -> {
|
||||
for (Lookup<T> lookup : lookups) {
|
||||
try {
|
||||
return lookup.find(typeClass, keys);
|
||||
} catch (IllegalArgumentException ignored) {}
|
||||
}
|
||||
throw new IllegalArgumentException("No element found for keys: " + Arrays.toString(keys));
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static <T extends Keyed> Registry<T> getRegistry(@NotNull Class<T> type) {
|
||||
RegistryLookup lookup = registryLookup.aquire(() -> {
|
||||
RegistryLookup bukkit;
|
||||
try {
|
||||
bukkit = Bukkit::getRegistry;
|
||||
} catch (Throwable ignored) {
|
||||
bukkit = null;
|
||||
}
|
||||
return new DefaultRegistryLookup(bukkit);
|
||||
});
|
||||
return lookup.find(type);
|
||||
}
|
||||
|
||||
private interface RegistryLookup {
|
||||
@Nullable
|
||||
<T extends Keyed> Registry<T> find(@NonNull Class<T> type);
|
||||
}
|
||||
|
||||
private static class DefaultRegistryLookup implements RegistryLookup {
|
||||
private final RegistryLookup bukkit;
|
||||
private final Map<Type, Object> registries;
|
||||
|
||||
private DefaultRegistryLookup(RegistryLookup bukkit) {
|
||||
this.bukkit = bukkit;
|
||||
registries = Arrays.stream(Registry.class.getDeclaredFields())
|
||||
.filter(field -> Modifier.isPublic(field.getModifiers()) && Modifier.isStatic(field.getModifiers()))
|
||||
.filter(field -> Registry.class.isAssignableFrom(field.getType()))
|
||||
.map(field -> {
|
||||
var type = ((ParameterizedType) field.getGenericType()).getActualTypeArguments()[0];
|
||||
try {
|
||||
return new Pair<>(type, field.get(null));
|
||||
} catch (Throwable e) {
|
||||
return null;
|
||||
}
|
||||
})
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toMap(Pair::getA, Pair::getB, (a, b) -> a));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public <T extends Keyed> Registry<T> find(@NonNull Class<T> type) {
|
||||
if (bukkit == null) return (Registry<T>) registries.get(type);
|
||||
try {
|
||||
return bukkit.find(type);
|
||||
} catch (Throwable e) {
|
||||
return (Registry<T>) registries.get(type);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,7 @@
|
||||
package com.volmit.iris.util.hunk.view;
|
||||
|
||||
import com.volmit.iris.util.data.B;
|
||||
import com.volmit.iris.util.data.IrisBlockData;
|
||||
import com.volmit.iris.util.data.IrisCustomData;
|
||||
import com.volmit.iris.util.hunk.Hunk;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.generator.ChunkGenerator.ChunkData;
|
||||
@@ -73,7 +73,7 @@ public class ChunkDataHunkView implements Hunk<BlockData> {
|
||||
}
|
||||
|
||||
try {
|
||||
if (t instanceof IrisBlockData d)
|
||||
if (t instanceof IrisCustomData d)
|
||||
t = d.getBase();
|
||||
chunk.setBlock(x, y + chunk.getMinHeight(), z, t);
|
||||
} catch (Throwable ignored) {
|
||||
|
||||
@@ -111,10 +111,12 @@ public class IO {
|
||||
return "¯\\_(ツ)_/¯";
|
||||
}
|
||||
|
||||
public static String hashRecursive(File base) {
|
||||
public static long hashRecursive(File... bases) {
|
||||
LinkedList<File> files = new LinkedList<>();
|
||||
Set<File> processed = new HashSet<>();
|
||||
files.add(base);
|
||||
Arrays.parallelSort(bases, Comparator.comparing(File::getName));
|
||||
files.addAll(Arrays.asList(bases));
|
||||
|
||||
try {
|
||||
CRC32 crc = new CRC32();
|
||||
while (!files.isEmpty()) {
|
||||
@@ -141,13 +143,13 @@ public class IO {
|
||||
}
|
||||
}
|
||||
|
||||
return Long.toHexString(crc.getValue());
|
||||
return crc.getValue();
|
||||
} catch (Throwable e) {
|
||||
Iris.reportError(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return "";
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static String hash(File b) {
|
||||
|
||||
@@ -26,7 +26,6 @@ import com.volmit.iris.util.matter.IrisMatter;
|
||||
import com.volmit.iris.util.matter.Matter;
|
||||
import com.volmit.iris.util.matter.MatterSlice;
|
||||
import lombok.Getter;
|
||||
import lombok.Synchronized;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataOutputStream;
|
||||
@@ -117,17 +116,16 @@ public class MantleChunk {
|
||||
ref.decrementAndGet();
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
public void flag(MantleFlag flag, boolean f) {
|
||||
flags.set(flag.ordinal(), f ? 1 : 0);
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
public void raiseFlag(MantleFlag flag, Runnable r) {
|
||||
if (!isFlagged(flag)) {
|
||||
flag(flag, true);
|
||||
r.run();
|
||||
synchronized (this) {
|
||||
if (!isFlagged(flag)) flag(flag, true);
|
||||
else return;
|
||||
}
|
||||
r.run();
|
||||
}
|
||||
|
||||
public boolean isFlagged(MantleFlag flag) {
|
||||
|
||||
@@ -36,7 +36,7 @@ public enum MantleFlag {
|
||||
TILE,
|
||||
CUSTOM,
|
||||
DISCOVERED,
|
||||
STATIC;
|
||||
CUSTOM_ACTIVE;
|
||||
|
||||
static StateList getStateList() {
|
||||
return new StateList(MantleFlag.values());
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
|
||||
package com.volmit.iris.util.matter.slices;
|
||||
|
||||
import com.volmit.iris.util.data.IrisBlockData;
|
||||
import com.volmit.iris.util.data.IrisCustomData;
|
||||
import com.volmit.iris.util.data.palette.Palette;
|
||||
import com.volmit.iris.util.matter.Sliced;
|
||||
import org.bukkit.Bukkit;
|
||||
@@ -41,7 +41,7 @@ public class BlockMatter extends RawMatter<BlockData> {
|
||||
public BlockMatter(int width, int height, int depth) {
|
||||
super(width, height, depth, BlockData.class);
|
||||
registerWriter(World.class, ((w, d, x, y, z) -> {
|
||||
if (d instanceof IrisBlockData c)
|
||||
if (d instanceof IrisCustomData c)
|
||||
w.getBlockAt(x, y, z).setBlockData(c.getBase());
|
||||
else w.getBlockAt(x, y, z).setBlockData(d);
|
||||
}));
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
package com.volmit.iris.util.misc;
|
||||
|
||||
public class E {
|
||||
|
||||
public static <T extends Enum<T>> T getOrDefault(Class<T> enumClass, String name, String fallback) {
|
||||
try {
|
||||
return Enum.valueOf(enumClass, name);
|
||||
} catch (Throwable e) {
|
||||
return Enum.valueOf(enumClass, fallback);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.volmit.iris.util.misc;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Properties;
|
||||
|
||||
public class ServerProperties {
|
||||
public static final Properties DATA = new Properties();
|
||||
public static final File SERVER_PROPERTIES;
|
||||
public static final File BUKKIT_YML;
|
||||
|
||||
public static final String LEVEL_NAME = DATA.getProperty("level-name", "world");
|
||||
|
||||
static {
|
||||
String[] args = ProcessHandle.current()
|
||||
.info()
|
||||
.arguments()
|
||||
.orElse(new String[0]);
|
||||
|
||||
String propertiesPath = "server.properties";
|
||||
String bukkitYml = "bukkit.yml";
|
||||
|
||||
for (int i = 0; i < args.length - 1; i++) {
|
||||
switch (args[i]) {
|
||||
case "-c", "--config" -> propertiesPath = args[i + 1];
|
||||
case "-b", "--bukkit-settings" -> bukkitYml = args[i + 1];
|
||||
}
|
||||
}
|
||||
|
||||
SERVER_PROPERTIES = new File(propertiesPath);
|
||||
BUKKIT_YML = new File(bukkitYml);
|
||||
try (FileInputStream in = new FileInputStream(SERVER_PROPERTIES)){
|
||||
DATA.load(in);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,150 +0,0 @@
|
||||
package com.volmit.iris.core.nms.v1_19_R1;
|
||||
|
||||
import com.mojang.serialization.Codec;
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.engine.data.cache.AtomicCache;
|
||||
import com.volmit.iris.engine.framework.Engine;
|
||||
import com.volmit.iris.engine.object.IrisBiome;
|
||||
import com.volmit.iris.engine.object.IrisBiomeCustom;
|
||||
import com.volmit.iris.util.collection.KMap;
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.core.RegistryAccess;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
import net.minecraft.world.level.biome.BiomeSource;
|
||||
import net.minecraft.world.level.biome.Climate;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.craftbukkit.v1_19_R1.CraftServer;
|
||||
import org.bukkit.craftbukkit.v1_19_R1.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_19_R1.block.CraftBlock;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class CustomBiomeSource extends BiomeSource {
|
||||
private final long seed;
|
||||
private final Engine engine;
|
||||
private final Registry<Biome> biomeCustomRegistry;
|
||||
private final Registry<Biome> biomeRegistry;
|
||||
private final AtomicCache<RegistryAccess> registryAccess = new AtomicCache<>();
|
||||
private final RNG rng;
|
||||
private final KMap<String, Holder<Biome>> customBiomes;
|
||||
|
||||
public CustomBiomeSource(long seed, Engine engine, World world) {
|
||||
super(getAllBiomes(
|
||||
((RegistryAccess) getFor(RegistryAccess.Frozen.class, ((CraftServer) Bukkit.getServer()).getHandle().getServer()))
|
||||
.registry(Registry.BIOME_REGISTRY).orElse(null),
|
||||
((CraftWorld) world).getHandle().registryAccess().registry(Registry.BIOME_REGISTRY).orElse(null),
|
||||
engine));
|
||||
this.engine = engine;
|
||||
this.seed = seed;
|
||||
this.biomeCustomRegistry = registry().registry(Registry.BIOME_REGISTRY).orElse(null);
|
||||
this.biomeRegistry = ((CraftWorld) world).getHandle().registryAccess().registry(Registry.BIOME_REGISTRY).orElse(null);
|
||||
this.rng = new RNG(engine.getSeedManager().getBiome());
|
||||
this.customBiomes = fillCustomBiomes(biomeCustomRegistry, engine);
|
||||
}
|
||||
|
||||
private static List<Holder<Biome>> getAllBiomes(Registry<Biome> customRegistry, Registry<Biome> registry, Engine engine) {
|
||||
List<Holder<Biome>> b = new ArrayList<>();
|
||||
|
||||
for (IrisBiome i : engine.getAllBiomes()) {
|
||||
if (i.isCustom()) {
|
||||
for (IrisBiomeCustom j : i.getCustomDerivitives()) {
|
||||
b.add(customRegistry.getHolder(customRegistry.getResourceKey(customRegistry
|
||||
.get(new ResourceLocation(engine.getDimension().getLoadKey() + ":" + j.getId()))).get()).get());
|
||||
}
|
||||
} else {
|
||||
b.add(CraftBlock.biomeToBiomeBase(registry, i.getVanillaDerivative()));
|
||||
}
|
||||
}
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
private static Object getFor(Class<?> type, Object source) {
|
||||
Object o = fieldFor(type, source);
|
||||
|
||||
if (o != null) {
|
||||
return o;
|
||||
}
|
||||
|
||||
return invokeFor(type, source);
|
||||
}
|
||||
|
||||
private static Object fieldFor(Class<?> returns, Object in) {
|
||||
return fieldForClass(returns, in.getClass(), in);
|
||||
}
|
||||
|
||||
private static Object invokeFor(Class<?> returns, Object in) {
|
||||
for (Method i : in.getClass().getMethods()) {
|
||||
if (i.getReturnType().equals(returns)) {
|
||||
i.setAccessible(true);
|
||||
try {
|
||||
Iris.debug("[NMS] Found " + returns.getSimpleName() + " in " + in.getClass().getSimpleName() + "." + i.getName() + "()");
|
||||
return i.invoke(in);
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static <T> T fieldForClass(Class<T> returnType, Class<?> sourceType, Object in) {
|
||||
for (Field i : sourceType.getDeclaredFields()) {
|
||||
if (i.getType().equals(returnType)) {
|
||||
i.setAccessible(true);
|
||||
try {
|
||||
Iris.debug("[NMS] Found " + returnType.getSimpleName() + " in " + sourceType.getSimpleName() + "." + i.getName());
|
||||
return (T) i.get(in);
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private KMap<String, Holder<Biome>> fillCustomBiomes(Registry<Biome> customRegistry, Engine engine) {
|
||||
KMap<String, Holder<Biome>> m = new KMap<>();
|
||||
|
||||
for (IrisBiome i : engine.getAllBiomes()) {
|
||||
if (i.isCustom()) {
|
||||
for (IrisBiomeCustom j : i.getCustomDerivitives()) {
|
||||
m.put(j.getId(), customRegistry.getHolder(customRegistry.getResourceKey(customRegistry
|
||||
.get(new ResourceLocation(engine.getDimension().getLoadKey() + ":" + j.getId()))).get()).get());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
private RegistryAccess registry() {
|
||||
return registryAccess.aquire(() -> (RegistryAccess) getFor(RegistryAccess.Frozen.class, ((CraftServer) Bukkit.getServer()).getHandle().getServer()));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Codec<? extends BiomeSource> codec() {
|
||||
throw new UnsupportedOperationException("Not supported");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Holder<Biome> getNoiseBiome(int x, int y, int z, Climate.Sampler sampler) {
|
||||
int m = (y - engine.getMinHeight()) << 2;
|
||||
IrisBiome ib = engine.getComplex().getTrueBiomeStream().get(x << 2, z << 2);
|
||||
if (ib.isCustom()) {
|
||||
return customBiomes.get(ib.getCustomBiome(rng, x << 2, m, z << 2).getId());
|
||||
} else {
|
||||
org.bukkit.block.Biome v = ib.getSkyBiome(rng, x << 2, m, z << 2);
|
||||
return CraftBlock.biomeToBiomeBase(biomeRegistry, v);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,257 +0,0 @@
|
||||
package com.volmit.iris.core.nms.v1_19_R1;
|
||||
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
import com.mojang.serialization.Codec;
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.engine.framework.Engine;
|
||||
import com.volmit.iris.engine.framework.ResultLocator;
|
||||
import com.volmit.iris.engine.framework.WrongEngineBroException;
|
||||
import com.volmit.iris.engine.object.IrisJigsawStructure;
|
||||
import com.volmit.iris.engine.object.IrisJigsawStructurePlacement;
|
||||
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.mantle.MantleFlag;
|
||||
import com.volmit.iris.util.math.Position2;
|
||||
import com.volmit.iris.util.reflect.WrappedField;
|
||||
import net.minecraft.core.*;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.WorldGenRegion;
|
||||
import net.minecraft.tags.TagKey;
|
||||
import net.minecraft.util.random.WeightedRandomList;
|
||||
import net.minecraft.world.entity.MobCategory;
|
||||
import net.minecraft.world.level.LevelHeightAccessor;
|
||||
import net.minecraft.world.level.NoiseColumn;
|
||||
import net.minecraft.world.level.StructureManager;
|
||||
import net.minecraft.world.level.WorldGenLevel;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
import net.minecraft.world.level.biome.BiomeManager;
|
||||
import net.minecraft.world.level.biome.BiomeSource;
|
||||
import net.minecraft.world.level.biome.MobSpawnSettings;
|
||||
import net.minecraft.world.level.chunk.ChunkAccess;
|
||||
import net.minecraft.world.level.chunk.ChunkGenerator;
|
||||
import net.minecraft.world.level.levelgen.GenerationStep;
|
||||
import net.minecraft.world.level.levelgen.Heightmap;
|
||||
import net.minecraft.world.level.levelgen.RandomState;
|
||||
import net.minecraft.world.level.levelgen.blending.Blender;
|
||||
import net.minecraft.world.level.levelgen.structure.Structure;
|
||||
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplateManager;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.craftbukkit.v1_19_R1.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_19_R1.generator.CustomChunkGenerator;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
public class IrisChunkGenerator extends CustomChunkGenerator {
|
||||
private static final WrappedField<ChunkGenerator, BiomeSource> BIOME_SOURCE;
|
||||
private final ChunkGenerator delegate;
|
||||
private final Engine engine;
|
||||
private final KMap<ResourceKey<Structure>, KSet<String>> structures = new KMap<>();
|
||||
|
||||
public IrisChunkGenerator(ChunkGenerator delegate, long seed, Engine engine, World world) {
|
||||
super(((CraftWorld) world).getHandle(), edit(delegate, new CustomBiomeSource(seed, engine, world)), null);
|
||||
this.delegate = delegate;
|
||||
this.engine = engine;
|
||||
var dimension = engine.getDimension();
|
||||
|
||||
KSet<IrisJigsawStructure> placements = new KSet<>();
|
||||
addAll(dimension.getJigsawStructures(), placements);
|
||||
for (var region : dimension.getAllRegions(engine)) {
|
||||
addAll(region.getJigsawStructures(), placements);
|
||||
for (var biome : region.getAllBiomes(engine))
|
||||
addAll(biome.getJigsawStructures(), placements);
|
||||
}
|
||||
var stronghold = dimension.getStronghold();
|
||||
if (stronghold != null)
|
||||
placements.add(engine.getData().getJigsawStructureLoader().load(stronghold));
|
||||
placements.removeIf(Objects::isNull);
|
||||
|
||||
var registry = ((CraftWorld) world).getHandle().registryAccess().registry(Registry.STRUCTURE_REGISTRY).orElseThrow();
|
||||
for (var s : placements) {
|
||||
try {
|
||||
String raw = s.getStructureKey();
|
||||
if (raw == null) continue;
|
||||
boolean tag = raw.startsWith("#");
|
||||
if (tag) raw = raw.substring(1);
|
||||
|
||||
var location = new ResourceLocation(raw);
|
||||
if (!tag) {
|
||||
structures.computeIfAbsent(ResourceKey.create(Registry.STRUCTURE_REGISTRY, location), k -> new KSet<>()).add(s.getLoadKey());
|
||||
continue;
|
||||
}
|
||||
|
||||
var key = TagKey.create(Registry.STRUCTURE_REGISTRY, location);
|
||||
var set = registry.getTag(key).orElse(null);
|
||||
if (set == null) {
|
||||
Iris.error("Could not find structure tag: " + raw);
|
||||
continue;
|
||||
}
|
||||
for (var holder : set) {
|
||||
var resourceKey = holder.unwrapKey().orElse(null);
|
||||
if (resourceKey == null) continue;
|
||||
structures.computeIfAbsent(resourceKey, k -> new KSet<>()).add(s.getLoadKey());
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
Iris.error("Failed to load structure: " + s.getLoadKey());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void addAll(KList<IrisJigsawStructurePlacement> placements, KSet<IrisJigsawStructure> structures) {
|
||||
if (placements == null) return;
|
||||
placements.stream()
|
||||
.map(IrisJigsawStructurePlacement::getStructure)
|
||||
.map(engine.getData().getJigsawStructureLoader()::load)
|
||||
.filter(Objects::nonNull)
|
||||
.forEach(structures::add);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Pair<BlockPos, Holder<Structure>> findNearestMapStructure(ServerLevel level, HolderSet<Structure> holders, BlockPos pos, int radius, boolean findUnexplored) {
|
||||
if (engine.getDimension().isDisableExplorerMaps())
|
||||
return null;
|
||||
|
||||
KMap<String, Holder<Structure>> structures = new KMap<>();
|
||||
for (var holder : holders) {
|
||||
if (holder == null) continue;
|
||||
var key = holder.unwrapKey().orElse(null);
|
||||
var set = this.structures.get(key);
|
||||
if (set == null) continue;
|
||||
for (var structure : set) {
|
||||
structures.put(structure, holder);
|
||||
}
|
||||
}
|
||||
if (structures.isEmpty())
|
||||
return null;
|
||||
|
||||
var locator = ResultLocator.locateStructure(structures.keySet())
|
||||
.then((e, p , s) -> structures.get(s.getLoadKey()));
|
||||
if (findUnexplored)
|
||||
locator = locator.then((e, p, s) -> e.getMantle().getMantle().getChunk(p.getX(), p.getZ()).isFlagged(MantleFlag.DISCOVERED) ? null : s);
|
||||
|
||||
try {
|
||||
var result = locator.find(engine, new Position2(pos.getX() >> 4, pos.getZ() >> 4), radius * 10L, i -> {}, false).get();
|
||||
if (result == null) return null;
|
||||
var blockPos = new BlockPos(result.getBlockX(), 0, result.getBlockZ());
|
||||
return Pair.of(blockPos, result.obj());
|
||||
} catch (WrongEngineBroException | ExecutionException | InterruptedException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Codec<? extends ChunkGenerator> codec() {
|
||||
return Codec.unit(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChunkGenerator getDelegate() {
|
||||
if (delegate instanceof CustomChunkGenerator chunkGenerator)
|
||||
return chunkGenerator.getDelegate();
|
||||
return delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinY() {
|
||||
return delegate.getMinY();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSeaLevel() {
|
||||
return delegate.getSeaLevel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createStructures(RegistryAccess iregistrycustom, RandomState randomstate, StructureManager structuremanager, ChunkAccess ichunkaccess, StructureTemplateManager structuretemplatemanager, long i) {
|
||||
delegate.createStructures(iregistrycustom, randomstate, structuremanager, ichunkaccess, structuretemplatemanager, i);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buildSurface(WorldGenRegion regionlimitedworldaccess, StructureManager structuremanager, RandomState randomstate, ChunkAccess ichunkaccess) {
|
||||
delegate.buildSurface(regionlimitedworldaccess, structuremanager, randomstate, ichunkaccess);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyCarvers(WorldGenRegion regionlimitedworldaccess, long seed, RandomState randomstate, BiomeManager biomemanager, StructureManager structuremanager, ChunkAccess ichunkaccess, GenerationStep.Carving worldgenstage_features) {
|
||||
delegate.applyCarvers(regionlimitedworldaccess, seed, randomstate, biomemanager, structuremanager, ichunkaccess, worldgenstage_features);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<ChunkAccess> fillFromNoise(Executor executor, Blender blender, RandomState randomstate, StructureManager structuremanager, ChunkAccess ichunkaccess) {
|
||||
return delegate.fillFromNoise(executor, blender, randomstate, structuremanager, ichunkaccess);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBaseHeight(int i, int j, Heightmap.Types heightmap_type, LevelHeightAccessor levelheightaccessor, RandomState randomstate) {
|
||||
return delegate.getBaseHeight(i, j, heightmap_type, levelheightaccessor, randomstate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public WeightedRandomList<MobSpawnSettings.SpawnerData> getMobsAt(Holder<Biome> holder, StructureManager structuremanager, MobCategory enumcreaturetype, BlockPos blockposition) {
|
||||
return delegate.getMobsAt(holder, structuremanager, enumcreaturetype, blockposition);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyBiomeDecoration(WorldGenLevel generatoraccessseed, ChunkAccess ichunkaccess, StructureManager structuremanager) {
|
||||
delegate.applyBiomeDecoration(generatoraccessseed, ichunkaccess, structuremanager);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addDebugScreenInfo(List<String> list, RandomState randomstate, BlockPos blockposition) {
|
||||
delegate.addDebugScreenInfo(list, randomstate, blockposition);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void spawnOriginalMobs(WorldGenRegion regionlimitedworldaccess) {
|
||||
delegate.spawnOriginalMobs(regionlimitedworldaccess);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSpawnHeight(LevelHeightAccessor levelheightaccessor) {
|
||||
return delegate.getSpawnHeight(levelheightaccessor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getGenDepth() {
|
||||
return delegate.getGenDepth();
|
||||
}
|
||||
|
||||
@Override
|
||||
public NoiseColumn getBaseColumn(int i, int j, LevelHeightAccessor levelheightaccessor, RandomState randomstate) {
|
||||
return delegate.getBaseColumn(i, j, levelheightaccessor, randomstate);
|
||||
}
|
||||
|
||||
static {
|
||||
Field biomeSource = null;
|
||||
for (Field field : ChunkGenerator.class.getDeclaredFields()) {
|
||||
if (!field.getType().equals(BiomeSource.class))
|
||||
continue;
|
||||
biomeSource = field;
|
||||
break;
|
||||
}
|
||||
if (biomeSource == null)
|
||||
throw new RuntimeException("Could not find biomeSource field in ChunkGenerator!");
|
||||
BIOME_SOURCE = new WrappedField<>(ChunkGenerator.class, biomeSource.getName());
|
||||
}
|
||||
|
||||
private static ChunkGenerator edit(ChunkGenerator generator, BiomeSource source) {
|
||||
try {
|
||||
BIOME_SOURCE.set(generator, source);
|
||||
if (generator instanceof CustomChunkGenerator custom)
|
||||
BIOME_SOURCE.set(custom.getDelegate(), source);
|
||||
|
||||
return generator;
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,626 +0,0 @@
|
||||
package com.volmit.iris.core.nms.v1_19_R1;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Vector;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
import com.volmit.iris.core.nms.container.BiomeColor;
|
||||
import com.volmit.iris.util.scheduling.J;
|
||||
import net.minecraft.nbt.*;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.server.commands.data.BlockDataAccessor;
|
||||
import net.minecraft.tags.TagKey;
|
||||
import net.minecraft.world.level.LevelReader;
|
||||
import net.minecraft.world.level.block.EntityBlock;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.craftbukkit.v1_19_R1.CraftChunk;
|
||||
import org.bukkit.craftbukkit.v1_19_R1.CraftServer;
|
||||
import org.bukkit.craftbukkit.v1_19_R1.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_19_R1.block.CraftBlock;
|
||||
import org.bukkit.craftbukkit.v1_19_R1.block.CraftBlockState;
|
||||
import org.bukkit.craftbukkit.v1_19_R1.block.CraftBlockStates;
|
||||
import org.bukkit.craftbukkit.v1_19_R1.block.data.CraftBlockData;
|
||||
import org.bukkit.craftbukkit.v1_19_R1.entity.CraftDolphin;
|
||||
import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftItemStack;
|
||||
import org.bukkit.entity.Dolphin;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||
import org.bukkit.generator.ChunkGenerator;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.core.nms.INMSBinding;
|
||||
import com.volmit.iris.engine.data.cache.AtomicCache;
|
||||
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.hunk.Hunk;
|
||||
import com.volmit.iris.util.json.JSONObject;
|
||||
import com.volmit.iris.util.mantle.Mantle;
|
||||
import com.volmit.iris.util.math.Vector3d;
|
||||
import com.volmit.iris.util.matter.MatterBiomeInject;
|
||||
import com.volmit.iris.util.nbt.io.NBTUtil;
|
||||
import com.volmit.iris.util.nbt.mca.NBTWorld;
|
||||
import com.volmit.iris.util.nbt.mca.palette.*;
|
||||
import com.volmit.iris.util.nbt.tag.CompoundTag;
|
||||
|
||||
import it.unimi.dsi.fastutil.objects.Object2IntMap;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.core.RegistryAccess;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.level.biome.BiomeSource;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.chunk.ChunkAccess;
|
||||
import net.minecraft.world.level.chunk.LevelChunk;
|
||||
import sun.misc.Unsafe;
|
||||
|
||||
public class NMSBinding implements INMSBinding {
|
||||
private final KMap<Biome, Object> baseBiomeCache = new KMap<>();
|
||||
private final BlockData AIR = Material.AIR.createBlockData();
|
||||
private final AtomicCache<MCAIdMap<net.minecraft.world.level.biome.Biome>> biomeMapCache = new AtomicCache<>();
|
||||
private final AtomicCache<MCAIdMapper<BlockState>> registryCache = new AtomicCache<>();
|
||||
private final AtomicCache<MCAPalette<BlockState>> globalCache = new AtomicCache<>();
|
||||
private final AtomicCache<RegistryAccess> registryAccess = new AtomicCache<>();
|
||||
private final AtomicCache<Method> byIdRef = new AtomicCache<>();
|
||||
private Field biomeStorageCache = null;
|
||||
|
||||
private static Object getFor(Class<?> type, Object source) {
|
||||
Object o = fieldFor(type, source);
|
||||
|
||||
if (o != null) {
|
||||
return o;
|
||||
}
|
||||
|
||||
return invokeFor(type, source);
|
||||
}
|
||||
|
||||
private static Object invokeFor(Class<?> returns, Object in) {
|
||||
for (Method i : in.getClass().getMethods()) {
|
||||
if (i.getReturnType().equals(returns)) {
|
||||
i.setAccessible(true);
|
||||
try {
|
||||
Iris.debug("[NMS] Found " + returns.getSimpleName() + " in " + in.getClass().getSimpleName() + "." + i.getName() + "()");
|
||||
return i.invoke(in);
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static Object fieldFor(Class<?> returns, Object in) {
|
||||
return fieldForClass(returns, in.getClass(), in);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static <T> T fieldForClass(Class<T> returnType, Class<?> sourceType, Object in) {
|
||||
for (Field i : sourceType.getDeclaredFields()) {
|
||||
if (i.getType().equals(returnType)) {
|
||||
i.setAccessible(true);
|
||||
try {
|
||||
Iris.debug("[NMS] Found " + returnType.getSimpleName() + " in " + sourceType.getSimpleName() + "." + i.getName());
|
||||
return (T) i.get(in);
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static Class<?> getClassType(Class<?> type, int ordinal) {
|
||||
return type.getDeclaredClasses()[ordinal];
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasTile(Material material) {
|
||||
return !CraftBlockState.class.equals(CraftBlockStates.getBlockStateType(material));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasTile(Location l) {
|
||||
return ((CraftWorld) l.getWorld()).getHandle().getBlockEntity(new BlockPos(l.getBlockX(), l.getBlockY(), l.getBlockZ()), false) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public KMap<String, Object> serializeTile(Location location) {
|
||||
BlockEntity e = ((CraftWorld) location.getWorld()).getHandle().getBlockEntity(new BlockPos(location.getBlockX(), location.getBlockY(), location.getBlockZ()), false);
|
||||
|
||||
if (e == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
net.minecraft.nbt.CompoundTag tag = e.saveWithoutMetadata();
|
||||
return (KMap<String, Object>) convertFromTag(tag, 0, 64);
|
||||
}
|
||||
|
||||
@Contract(value = "null, _, _ -> null", pure = true)
|
||||
private Object convertFromTag(net.minecraft.nbt.Tag tag, int depth, int maxDepth) {
|
||||
if (tag == null || depth > maxDepth) return null;
|
||||
if (tag instanceof CollectionTag<?> collection) {
|
||||
KList<Object> list = new KList<>();
|
||||
|
||||
for (Object i : collection) {
|
||||
if (i instanceof net.minecraft.nbt.Tag t)
|
||||
list.add(convertFromTag(t, depth + 1, maxDepth));
|
||||
else list.add(i);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
if (tag instanceof net.minecraft.nbt.CompoundTag compound) {
|
||||
KMap<String, Object> map = new KMap<>();
|
||||
|
||||
for (String key : compound.getAllKeys()) {
|
||||
var child = compound.get(key);
|
||||
if (child == null) continue;
|
||||
var value = convertFromTag(child, depth + 1, maxDepth);
|
||||
if (value == null) continue;
|
||||
map.put(key, value);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
if (tag instanceof NumericTag numeric)
|
||||
return numeric.getAsNumber();
|
||||
return tag.getAsString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deserializeTile(KMap<String, Object> map, Location pos) {
|
||||
net.minecraft.nbt.CompoundTag tag = (net.minecraft.nbt.CompoundTag) convertToTag(map, 0, 64);
|
||||
var level = ((CraftWorld) pos.getWorld()).getHandle();
|
||||
var blockPos = new BlockPos(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ());
|
||||
J.s(() -> merge(level, blockPos, tag));
|
||||
}
|
||||
|
||||
private void merge(ServerLevel level, BlockPos blockPos, net.minecraft.nbt.CompoundTag tag) {
|
||||
var blockEntity = level.getBlockEntity(blockPos);
|
||||
if (blockEntity == null) {
|
||||
Iris.warn("[NMS] BlockEntity not found at " + blockPos);
|
||||
var state = level.getBlockState(blockPos);
|
||||
if (!state.hasBlockEntity())
|
||||
return;
|
||||
|
||||
blockEntity = ((EntityBlock) state.getBlock())
|
||||
.newBlockEntity(blockPos, state);
|
||||
}
|
||||
var accessor = new BlockDataAccessor(blockEntity, blockPos);
|
||||
accessor.setData(tag.merge(accessor.getData()));
|
||||
}
|
||||
|
||||
private Tag convertToTag(Object object, int depth, int maxDepth) {
|
||||
if (object == null || depth > maxDepth) return EndTag.INSTANCE;
|
||||
if (object instanceof Map<?,?> map) {
|
||||
var tag = new net.minecraft.nbt.CompoundTag();
|
||||
for (var i : map.entrySet()) {
|
||||
tag.put(i.getKey().toString(), convertToTag(i.getValue(), depth + 1, maxDepth));
|
||||
}
|
||||
return tag;
|
||||
}
|
||||
if (object instanceof List<?> list) {
|
||||
var tag = new net.minecraft.nbt.ListTag();
|
||||
for (var i : list) {
|
||||
tag.add(convertToTag(i, depth + 1, maxDepth));
|
||||
}
|
||||
return tag;
|
||||
}
|
||||
if (object instanceof Byte number) return ByteTag.valueOf(number);
|
||||
if (object instanceof Short number) return ShortTag.valueOf(number);
|
||||
if (object instanceof Integer number) return IntTag.valueOf(number);
|
||||
if (object instanceof Long number) return LongTag.valueOf(number);
|
||||
if (object instanceof Float number) return FloatTag.valueOf(number);
|
||||
if (object instanceof Double number) return DoubleTag.valueOf(number);
|
||||
if (object instanceof String string) return StringTag.valueOf(string);
|
||||
return EndTag.INSTANCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundTag serializeEntity(Entity location) {
|
||||
return null;// TODO:
|
||||
}
|
||||
|
||||
@Override
|
||||
public Entity deserializeEntity(CompoundTag s, Location newPosition) {
|
||||
return null;// TODO:
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsCustomHeight() {
|
||||
return true;
|
||||
}
|
||||
|
||||
private RegistryAccess registry() {
|
||||
return registryAccess.aquire(() -> (RegistryAccess) getFor(RegistryAccess.Frozen.class, ((CraftServer) Bukkit.getServer()).getHandle().getServer()));
|
||||
}
|
||||
|
||||
private Registry<net.minecraft.world.level.biome.Biome> getCustomBiomeRegistry() {
|
||||
return registry().registry(Registry.BIOME_REGISTRY).orElse(null);
|
||||
}
|
||||
|
||||
private Registry<Block> getBlockRegistry() {
|
||||
return registry().registry(Registry.BLOCK_REGISTRY).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getBiomeBaseFromId(int id) {
|
||||
return getCustomBiomeRegistry().getHolder(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinHeight(World world) {
|
||||
return world.getMinHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsCustomBiomes() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTrueBiomeBaseId(Object biomeBase) {
|
||||
return getCustomBiomeRegistry().getId(((Holder<net.minecraft.world.level.biome.Biome>) biomeBase).value());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getTrueBiomeBase(Location location) {
|
||||
return ((CraftWorld) location.getWorld()).getHandle().getBiome(new BlockPos(location.getBlockX(), location.getBlockY(), location.getBlockZ()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTrueBiomeBaseKey(Location location) {
|
||||
return getKeyForBiomeBase(getTrueBiomeBase(location));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getCustomBiomeBaseFor(String mckey) {
|
||||
return getCustomBiomeRegistry().get(new ResourceLocation(mckey));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getCustomBiomeBaseHolderFor(String mckey) {
|
||||
return getCustomBiomeRegistry().getHolder(getTrueBiomeBaseId(getCustomBiomeRegistry().get(new ResourceLocation(mckey)))).get();
|
||||
}
|
||||
|
||||
public int getBiomeBaseIdForKey(String key) {
|
||||
return getCustomBiomeRegistry().getId(getCustomBiomeRegistry().get(new ResourceLocation(key)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getKeyForBiomeBase(Object biomeBase) {
|
||||
return getCustomBiomeRegistry().getKey((net.minecraft.world.level.biome.Biome) biomeBase).getPath(); // something, not something:something
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getBiomeBase(World world, Biome biome) {
|
||||
return CraftBlock.biomeToBiomeBase(((CraftWorld) world).getHandle()
|
||||
.registryAccess().registry(Registry.BIOME_REGISTRY).orElse(null), biome);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getBiomeBase(Object registry, Biome biome) {
|
||||
Object v = baseBiomeCache.get(biome);
|
||||
|
||||
if (v != null) {
|
||||
return v;
|
||||
}
|
||||
//noinspection unchecked
|
||||
v = CraftBlock.biomeToBiomeBase((Registry<net.minecraft.world.level.biome.Biome>) registry, biome);
|
||||
if (v == null) {
|
||||
// Ok so there is this new biome name called "CUSTOM" in Paper's new releases.
|
||||
// But, this does NOT exist within CraftBukkit which makes it return an error.
|
||||
// So, we will just return the ID that the plains biome returns instead.
|
||||
//noinspection unchecked
|
||||
return CraftBlock.biomeToBiomeBase((Registry<net.minecraft.world.level.biome.Biome>) registry, Biome.PLAINS);
|
||||
}
|
||||
baseBiomeCache.put(biome, v);
|
||||
return v;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KList<Biome> getBiomes() {
|
||||
return new KList<>(Biome.values()).qdel(Biome.CUSTOM);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBukkit() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBiomeId(Biome biome) {
|
||||
for (World i : Bukkit.getWorlds()) {
|
||||
if (i.getEnvironment().equals(World.Environment.NORMAL)) {
|
||||
Registry<net.minecraft.world.level.biome.Biome> registry = ((CraftWorld) i).getHandle().registryAccess().registry(Registry.BIOME_REGISTRY).orElse(null);
|
||||
return registry.getId((net.minecraft.world.level.biome.Biome) getBiomeBase(registry, biome));
|
||||
}
|
||||
}
|
||||
|
||||
return biome.ordinal();
|
||||
}
|
||||
|
||||
private MCAIdMap<net.minecraft.world.level.biome.Biome> getBiomeMapping() {
|
||||
return biomeMapCache.aquire(() -> new MCAIdMap<>() {
|
||||
@NotNull
|
||||
@Override
|
||||
public Iterator<net.minecraft.world.level.biome.Biome> iterator() {
|
||||
return getCustomBiomeRegistry().iterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getId(net.minecraft.world.level.biome.Biome paramT) {
|
||||
return getCustomBiomeRegistry().getId(paramT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public net.minecraft.world.level.biome.Biome byId(int paramInt) {
|
||||
return (net.minecraft.world.level.biome.Biome) getBiomeBaseFromId(paramInt);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private MCABiomeContainer getBiomeContainerInterface(MCAIdMap<net.minecraft.world.level.biome.Biome> biomeMapping, MCAChunkBiomeContainer<net.minecraft.world.level.biome.Biome> base) {
|
||||
return new MCABiomeContainer() {
|
||||
@Override
|
||||
public int[] getData() {
|
||||
return base.writeBiomes();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBiome(int x, int y, int z, int id) {
|
||||
base.setBiome(x, y, z, biomeMapping.byId(id));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBiome(int x, int y, int z) {
|
||||
return biomeMapping.getId(base.getBiome(x, y, z));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public MCABiomeContainer newBiomeContainer(int min, int max) {
|
||||
MCAChunkBiomeContainer<net.minecraft.world.level.biome.Biome> base = new MCAChunkBiomeContainer<>(getBiomeMapping(), min, max);
|
||||
return getBiomeContainerInterface(getBiomeMapping(), base);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MCABiomeContainer newBiomeContainer(int min, int max, int[] data) {
|
||||
MCAChunkBiomeContainer<net.minecraft.world.level.biome.Biome> base = new MCAChunkBiomeContainer<>(getBiomeMapping(), min, max, data);
|
||||
return getBiomeContainerInterface(getBiomeMapping(), base);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int countCustomBiomes() {
|
||||
AtomicInteger a = new AtomicInteger(0);
|
||||
|
||||
getCustomBiomeRegistry().keySet().forEach((i) -> {
|
||||
if (i.getNamespace().equals("minecraft")) {
|
||||
return;
|
||||
}
|
||||
|
||||
a.incrementAndGet();
|
||||
Iris.debug("Custom Biome: " + i);
|
||||
});
|
||||
|
||||
return a.get();
|
||||
}
|
||||
|
||||
public boolean supportsDataPacks() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void setBiomes(int cx, int cz, World world, Hunk<Object> biomes) {
|
||||
LevelChunk c = ((CraftWorld) world).getHandle().getChunk(cx, cz);
|
||||
biomes.iterateSync((x, y, z, b) -> c.setBiome(x, y, z, (Holder<net.minecraft.world.level.biome.Biome>) b));
|
||||
c.setUnsaved(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forceBiomeInto(int x, int y, int z, Object somethingVeryDirty, ChunkGenerator.BiomeGrid chunk) {
|
||||
try {
|
||||
ChunkAccess s = (ChunkAccess) getFieldForBiomeStorage(chunk).get(chunk);
|
||||
Holder<net.minecraft.world.level.biome.Biome> biome = (Holder<net.minecraft.world.level.biome.Biome>) somethingVeryDirty;
|
||||
s.setBiome(x, y, z, biome);
|
||||
} catch (IllegalAccessException e) {
|
||||
Iris.reportError(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private Field getFieldForBiomeStorage(Object storage) {
|
||||
Field f = biomeStorageCache;
|
||||
|
||||
if (f != null) {
|
||||
return f;
|
||||
}
|
||||
try {
|
||||
f = storage.getClass().getDeclaredField("biome");
|
||||
f.setAccessible(true);
|
||||
return f;
|
||||
} catch (Throwable e) {
|
||||
Iris.reportError(e);
|
||||
e.printStackTrace();
|
||||
Iris.error(storage.getClass().getCanonicalName());
|
||||
}
|
||||
|
||||
biomeStorageCache = f;
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MCAPaletteAccess createPalette() {
|
||||
MCAIdMapper<BlockState> registry = registryCache.aquireNasty(() -> {
|
||||
Field cf = net.minecraft.core.IdMapper.class.getDeclaredField("tToId");
|
||||
Field df = net.minecraft.core.IdMapper.class.getDeclaredField("idToT");
|
||||
Field bf = net.minecraft.core.IdMapper.class.getDeclaredField("nextId");
|
||||
cf.setAccessible(true);
|
||||
df.setAccessible(true);
|
||||
bf.setAccessible(true);
|
||||
net.minecraft.core.IdMapper<BlockState> blockData = Block.BLOCK_STATE_REGISTRY;
|
||||
int b = bf.getInt(blockData);
|
||||
Object2IntMap<BlockState> c = (Object2IntMap<BlockState>) cf.get(blockData);
|
||||
List<BlockState> d = (List<BlockState>) df.get(blockData);
|
||||
return new MCAIdMapper<BlockState>(c, d, b);
|
||||
});
|
||||
MCAPalette<BlockState> global = globalCache.aquireNasty(() -> new MCAGlobalPalette<>(registry, ((CraftBlockData) AIR).getState()));
|
||||
MCAPalettedContainer<BlockState> container = new MCAPalettedContainer<>(global, registry,
|
||||
i -> ((CraftBlockData) NBTWorld.getBlockData(i)).getState(),
|
||||
i -> NBTWorld.getCompound(CraftBlockData.fromData(i)),
|
||||
((CraftBlockData) AIR).getState());
|
||||
return new MCAWrappedPalettedContainer<>(container,
|
||||
i -> NBTWorld.getCompound(CraftBlockData.fromData(i)),
|
||||
i -> ((CraftBlockData) NBTWorld.getBlockData(i)).getState());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void injectBiomesFromMantle(Chunk e, Mantle mantle) {
|
||||
ChunkAccess chunk = ((CraftChunk) e).getHandle();
|
||||
AtomicInteger c = new AtomicInteger();
|
||||
AtomicInteger r = new AtomicInteger();
|
||||
mantle.iterateChunk(e.getX(), e.getZ(), MatterBiomeInject.class, (x, y, z, b) -> {
|
||||
if (b != null) {
|
||||
if (b.isCustom()) {
|
||||
chunk.setBiome(x, y, z, getCustomBiomeRegistry().getHolder(b.getBiomeId()).get());
|
||||
c.getAndIncrement();
|
||||
} else {
|
||||
chunk.setBiome(x, y, z, (Holder<net.minecraft.world.level.biome.Biome>) getBiomeBase(e.getWorld(), b.getBiome()));
|
||||
r.getAndIncrement();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public ItemStack applyCustomNbt(ItemStack itemStack, KMap<String, Object> customNbt) throws IllegalArgumentException {
|
||||
if (customNbt != null && !customNbt.isEmpty()) {
|
||||
net.minecraft.world.item.ItemStack s = CraftItemStack.asNMSCopy(itemStack);
|
||||
|
||||
try {
|
||||
net.minecraft.nbt.CompoundTag tag = TagParser.parseTag((new JSONObject(customNbt)).toString());
|
||||
tag.merge(s.getOrCreateTag());
|
||||
s.setTag(tag);
|
||||
} catch (CommandSyntaxException var5) {
|
||||
throw new IllegalArgumentException(var5);
|
||||
}
|
||||
|
||||
return CraftItemStack.asBukkitCopy(s);
|
||||
} else {
|
||||
return itemStack;
|
||||
}
|
||||
}
|
||||
|
||||
public void inject(long seed, Engine engine, World world) {
|
||||
var chunkMap = ((CraftWorld)world).getHandle().getChunkSource().chunkMap;
|
||||
chunkMap.generator = new IrisChunkGenerator(chunkMap.generator, seed, engine, world);
|
||||
}
|
||||
|
||||
public Vector3d getBoundingbox(org.bukkit.entity.EntityType entity) {
|
||||
Field[] fields = EntityType.class.getDeclaredFields();
|
||||
for (Field field : fields) {
|
||||
if (Modifier.isStatic(field.getModifiers()) && field.getType().equals(EntityType.class)) {
|
||||
try {
|
||||
EntityType entityType = (EntityType) field.get(null);
|
||||
if (entityType.getDescriptionId().equals("entity.minecraft." + entity.name().toLowerCase())) {
|
||||
Vector<Float> v1 = new Vector<>();
|
||||
v1.add(entityType.getHeight());
|
||||
entityType.getDimensions();
|
||||
Vector3d box = new Vector3d( entityType.getWidth(), entityType.getHeight(), entityType.getWidth());
|
||||
//System.out.println("Entity Type: " + entityType.getDescriptionId() + ", " + "Height: " + height + ", Width: " + width);
|
||||
return box;
|
||||
}
|
||||
} catch (IllegalAccessException e) {
|
||||
Iris.error("Unable to get entity dimensions!");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Entity spawnEntity(Location location, org.bukkit.entity.EntityType type, CreatureSpawnEvent.SpawnReason reason) {
|
||||
return ((CraftWorld) location.getWorld()).spawn(location, type.getEntityClass(), null, reason);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Color getBiomeColor(Location location, BiomeColor type) {
|
||||
LevelReader reader = ((CraftWorld) location.getWorld()).getHandle();
|
||||
var holder = reader.getBiome(new BlockPos(location.getBlockX(), location.getBlockY(), location.getBlockZ()));
|
||||
var biome = holder.value();
|
||||
if (biome == null) throw new IllegalArgumentException("Invalid biome: " + holder.unwrapKey().orElse(null));
|
||||
|
||||
int rgba = switch (type) {
|
||||
case FOG -> biome.getFogColor();
|
||||
case WATER -> biome.getWaterColor();
|
||||
case WATER_FOG -> biome.getWaterFogColor();
|
||||
case SKY -> biome.getSkyColor();
|
||||
case FOLIAGE -> biome.getFoliageColor();
|
||||
case GRASS -> biome.getGrassColor(location.getBlockX(), location.getBlockZ());
|
||||
};
|
||||
if (rgba == 0) {
|
||||
if (BiomeColor.FOLIAGE == type && biome.getSpecialEffects().getFoliageColorOverride().isEmpty())
|
||||
return null;
|
||||
if (BiomeColor.GRASS == type && biome.getSpecialEffects().getGrassColorOverride().isEmpty())
|
||||
return null;
|
||||
}
|
||||
return new Color(rgba, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public KList<String> getStructureKeys() {
|
||||
KList<String> keys = new KList<>();
|
||||
|
||||
var registry = registry().registry(Registry.STRUCTURE_REGISTRY).orElse(null);
|
||||
if (registry == null) return keys;
|
||||
registry.keySet().stream().map(ResourceLocation::toString).forEach(keys::add);
|
||||
registry.getTags()
|
||||
.map(Pair::getFirst)
|
||||
.map(TagKey::location)
|
||||
.map(ResourceLocation::toString)
|
||||
.map(s -> "#" + s)
|
||||
.forEach(keys::add);
|
||||
|
||||
return keys;
|
||||
}
|
||||
|
||||
private static Field getField(Class<?> clazz, Class<?> fieldType) throws NoSuchFieldException {
|
||||
try {
|
||||
for (Field f : clazz.getDeclaredFields()) {
|
||||
if (f.getType().equals(fieldType))
|
||||
return f;
|
||||
}
|
||||
throw new NoSuchFieldException(fieldType.getName());
|
||||
} catch (NoSuchFieldException var4) {
|
||||
Class<?> superClass = clazz.getSuperclass();
|
||||
if (superClass == null) {
|
||||
throw var4;
|
||||
} else {
|
||||
return getField(superClass, fieldType);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,152 +0,0 @@
|
||||
package com.volmit.iris.core.nms.v1_19_R2;
|
||||
|
||||
import com.mojang.serialization.Codec;
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.engine.data.cache.AtomicCache;
|
||||
import com.volmit.iris.engine.framework.Engine;
|
||||
import com.volmit.iris.engine.object.IrisBiome;
|
||||
import com.volmit.iris.engine.object.IrisBiomeCustom;
|
||||
import com.volmit.iris.util.collection.KMap;
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.core.RegistryAccess;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
import net.minecraft.world.level.biome.BiomeSource;
|
||||
import net.minecraft.world.level.biome.Climate;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.craftbukkit.v1_19_R2.CraftServer;
|
||||
import org.bukkit.craftbukkit.v1_19_R2.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_19_R2.block.CraftBlock;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class CustomBiomeSource extends BiomeSource {
|
||||
|
||||
private final long seed;
|
||||
private final Engine engine;
|
||||
private final Registry<Biome> biomeCustomRegistry;
|
||||
private final Registry<Biome> biomeRegistry;
|
||||
private final AtomicCache<RegistryAccess> registryAccess = new AtomicCache<>();
|
||||
private final RNG rng;
|
||||
private final KMap<String, Holder<Biome>> customBiomes;
|
||||
|
||||
public CustomBiomeSource(long seed, Engine engine, World world) {
|
||||
super(getAllBiomes(
|
||||
((RegistryAccess) getFor(RegistryAccess.Frozen.class, ((CraftServer) Bukkit.getServer()).getHandle().getServer()))
|
||||
.registry(Registries.BIOME).orElse(null),
|
||||
((CraftWorld) world).getHandle().registryAccess().registry(Registries.BIOME).orElse(null),
|
||||
engine));
|
||||
this.engine = engine;
|
||||
this.seed = seed;
|
||||
this.biomeCustomRegistry = registry().registry(Registries.BIOME).orElse(null);
|
||||
this.biomeRegistry = ((CraftWorld) world).getHandle().registryAccess().registry(Registries.BIOME).orElse(null);
|
||||
this.rng = new RNG(engine.getSeedManager().getBiome());
|
||||
this.customBiomes = fillCustomBiomes(biomeCustomRegistry, engine);
|
||||
}
|
||||
|
||||
private static List<Holder<Biome>> getAllBiomes(Registry<Biome> customRegistry, Registry<Biome> registry, Engine engine) {
|
||||
List<Holder<Biome>> b = new ArrayList<>();
|
||||
|
||||
for (IrisBiome i : engine.getAllBiomes()) {
|
||||
if (i.isCustom()) {
|
||||
for (IrisBiomeCustom j : i.getCustomDerivitives()) {
|
||||
b.add(customRegistry.getHolder(customRegistry.getResourceKey(customRegistry
|
||||
.get(new ResourceLocation(engine.getDimension().getLoadKey() + ":" + j.getId()))).get()).get());
|
||||
}
|
||||
} else {
|
||||
b.add(CraftBlock.biomeToBiomeBase(registry, i.getVanillaDerivative()));
|
||||
}
|
||||
}
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
private static Object getFor(Class<?> type, Object source) {
|
||||
Object o = fieldFor(type, source);
|
||||
|
||||
if (o != null) {
|
||||
return o;
|
||||
}
|
||||
|
||||
return invokeFor(type, source);
|
||||
}
|
||||
|
||||
private static Object fieldFor(Class<?> returns, Object in) {
|
||||
return fieldForClass(returns, in.getClass(), in);
|
||||
}
|
||||
|
||||
private static Object invokeFor(Class<?> returns, Object in) {
|
||||
for (Method i : in.getClass().getMethods()) {
|
||||
if (i.getReturnType().equals(returns)) {
|
||||
i.setAccessible(true);
|
||||
try {
|
||||
Iris.debug("[NMS] Found " + returns.getSimpleName() + " in " + in.getClass().getSimpleName() + "." + i.getName() + "()");
|
||||
return i.invoke(in);
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static <T> T fieldForClass(Class<T> returnType, Class<?> sourceType, Object in) {
|
||||
for (Field i : sourceType.getDeclaredFields()) {
|
||||
if (i.getType().equals(returnType)) {
|
||||
i.setAccessible(true);
|
||||
try {
|
||||
Iris.debug("[NMS] Found " + returnType.getSimpleName() + " in " + sourceType.getSimpleName() + "." + i.getName());
|
||||
return (T) i.get(in);
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private KMap<String, Holder<Biome>> fillCustomBiomes(Registry<Biome> customRegistry, Engine engine) {
|
||||
KMap<String, Holder<Biome>> m = new KMap<>();
|
||||
|
||||
for (IrisBiome i : engine.getAllBiomes()) {
|
||||
if (i.isCustom()) {
|
||||
for (IrisBiomeCustom j : i.getCustomDerivitives()) {
|
||||
m.put(j.getId(), customRegistry.getHolder(customRegistry.getResourceKey(customRegistry
|
||||
.get(new ResourceLocation(engine.getDimension().getLoadKey() + ":" + j.getId()))).get()).get());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
private RegistryAccess registry() {
|
||||
return registryAccess.aquire(() -> (RegistryAccess) getFor(RegistryAccess.Frozen.class, ((CraftServer) Bukkit.getServer()).getHandle().getServer()));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Codec<? extends BiomeSource> codec() {
|
||||
throw new UnsupportedOperationException("Not supported");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Holder<Biome> getNoiseBiome(int x, int y, int z, Climate.Sampler sampler) {
|
||||
int m = (y - engine.getMinHeight()) << 2;
|
||||
IrisBiome ib = engine.getComplex().getTrueBiomeStream().get(x << 2, z << 2);
|
||||
if (ib.isCustom()) {
|
||||
return customBiomes.get(ib.getCustomBiome(rng, x << 2, m, z << 2).getId());
|
||||
} else {
|
||||
org.bukkit.block.Biome v = ib.getSkyBiome(rng, x << 2, m, z << 2);
|
||||
return CraftBlock.biomeToBiomeBase(biomeRegistry, v);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,260 +0,0 @@
|
||||
package com.volmit.iris.core.nms.v1_19_R2;
|
||||
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
import com.mojang.serialization.Codec;
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.engine.framework.Engine;
|
||||
import com.volmit.iris.engine.framework.ResultLocator;
|
||||
import com.volmit.iris.engine.framework.WrongEngineBroException;
|
||||
import com.volmit.iris.engine.object.IrisJigsawStructure;
|
||||
import com.volmit.iris.engine.object.IrisJigsawStructurePlacement;
|
||||
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.mantle.MantleFlag;
|
||||
import com.volmit.iris.util.math.Position2;
|
||||
import com.volmit.iris.util.reflect.WrappedField;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.HolderSet;
|
||||
import net.minecraft.core.RegistryAccess;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.WorldGenRegion;
|
||||
import net.minecraft.tags.TagKey;
|
||||
import net.minecraft.util.random.WeightedRandomList;
|
||||
import net.minecraft.world.entity.MobCategory;
|
||||
import net.minecraft.world.level.LevelHeightAccessor;
|
||||
import net.minecraft.world.level.NoiseColumn;
|
||||
import net.minecraft.world.level.StructureManager;
|
||||
import net.minecraft.world.level.WorldGenLevel;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
import net.minecraft.world.level.biome.BiomeManager;
|
||||
import net.minecraft.world.level.biome.BiomeSource;
|
||||
import net.minecraft.world.level.biome.MobSpawnSettings;
|
||||
import net.minecraft.world.level.chunk.ChunkAccess;
|
||||
import net.minecraft.world.level.chunk.ChunkGenerator;
|
||||
import net.minecraft.world.level.chunk.ChunkGeneratorStructureState;
|
||||
import net.minecraft.world.level.levelgen.GenerationStep;
|
||||
import net.minecraft.world.level.levelgen.Heightmap;
|
||||
import net.minecraft.world.level.levelgen.RandomState;
|
||||
import net.minecraft.world.level.levelgen.blending.Blender;
|
||||
import net.minecraft.world.level.levelgen.structure.Structure;
|
||||
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplateManager;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.craftbukkit.v1_19_R2.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_19_R2.generator.CustomChunkGenerator;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.*;
|
||||
|
||||
public class IrisChunkGenerator extends CustomChunkGenerator {
|
||||
private static final WrappedField<ChunkGenerator, BiomeSource> BIOME_SOURCE;
|
||||
private final ChunkGenerator delegate;
|
||||
private final Engine engine;
|
||||
private final KMap<ResourceKey<Structure>, KSet<String>> structures = new KMap<>();
|
||||
|
||||
public IrisChunkGenerator(ChunkGenerator delegate, long seed, Engine engine, World world) {
|
||||
super(((CraftWorld) world).getHandle(), edit(delegate, new CustomBiomeSource(seed, engine, world)), null);
|
||||
this.delegate = delegate;
|
||||
this.engine = engine;
|
||||
var dimension = engine.getDimension();
|
||||
|
||||
KSet<IrisJigsawStructure> placements = new KSet<>();
|
||||
addAll(dimension.getJigsawStructures(), placements);
|
||||
for (var region : dimension.getAllRegions(engine)) {
|
||||
addAll(region.getJigsawStructures(), placements);
|
||||
for (var biome : region.getAllBiomes(engine))
|
||||
addAll(biome.getJigsawStructures(), placements);
|
||||
}
|
||||
var stronghold = dimension.getStronghold();
|
||||
if (stronghold != null)
|
||||
placements.add(engine.getData().getJigsawStructureLoader().load(stronghold));
|
||||
placements.removeIf(Objects::isNull);
|
||||
|
||||
var registry = ((CraftWorld) world).getHandle().registryAccess().registry(Registries.STRUCTURE).orElseThrow();
|
||||
for (var s : placements) {
|
||||
try {
|
||||
String raw = s.getStructureKey();
|
||||
if (raw == null) continue;
|
||||
boolean tag = raw.startsWith("#");
|
||||
if (tag) raw = raw.substring(1);
|
||||
|
||||
var location = new ResourceLocation(raw);
|
||||
if (!tag) {
|
||||
structures.computeIfAbsent(ResourceKey.create(Registries.STRUCTURE, location), k -> new KSet<>()).add(s.getLoadKey());
|
||||
continue;
|
||||
}
|
||||
|
||||
var key = TagKey.create(Registries.STRUCTURE, location);
|
||||
var set = registry.getTag(key).orElse(null);
|
||||
if (set == null) {
|
||||
Iris.error("Could not find structure tag: " + raw);
|
||||
continue;
|
||||
}
|
||||
for (var holder : set) {
|
||||
var resourceKey = holder.unwrapKey().orElse(null);
|
||||
if (resourceKey == null) continue;
|
||||
structures.computeIfAbsent(resourceKey, k -> new KSet<>()).add(s.getLoadKey());
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
Iris.error("Failed to load structure: " + s.getLoadKey());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void addAll(KList<IrisJigsawStructurePlacement> placements, KSet<IrisJigsawStructure> structures) {
|
||||
if (placements == null) return;
|
||||
placements.stream()
|
||||
.map(IrisJigsawStructurePlacement::getStructure)
|
||||
.map(engine.getData().getJigsawStructureLoader()::load)
|
||||
.filter(Objects::nonNull)
|
||||
.forEach(structures::add);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Pair<BlockPos, Holder<Structure>> findNearestMapStructure(ServerLevel level, HolderSet<Structure> holders, BlockPos pos, int radius, boolean findUnexplored) {
|
||||
if (engine.getDimension().isDisableExplorerMaps())
|
||||
return null;
|
||||
|
||||
KMap<String, Holder<Structure>> structures = new KMap<>();
|
||||
for (var holder : holders) {
|
||||
if (holder == null) continue;
|
||||
var key = holder.unwrapKey().orElse(null);
|
||||
var set = this.structures.get(key);
|
||||
if (set == null) continue;
|
||||
for (var structure : set) {
|
||||
structures.put(structure, holder);
|
||||
}
|
||||
}
|
||||
if (structures.isEmpty())
|
||||
return null;
|
||||
|
||||
var locator = ResultLocator.locateStructure(structures.keySet())
|
||||
.then((e, p , s) -> structures.get(s.getLoadKey()));
|
||||
if (findUnexplored)
|
||||
locator = locator.then((e, p, s) -> e.getMantle().getMantle().getChunk(p.getX(), p.getZ()).isFlagged(MantleFlag.DISCOVERED) ? null : s);
|
||||
|
||||
try {
|
||||
var result = locator.find(engine, new Position2(pos.getX() >> 4, pos.getZ() >> 4), radius * 10L, i -> {}, false).get();
|
||||
if (result == null) return null;
|
||||
var blockPos = new BlockPos(result.getBlockX(), 0, result.getBlockZ());
|
||||
return Pair.of(blockPos, result.obj());
|
||||
} catch (WrongEngineBroException | ExecutionException | InterruptedException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Codec<? extends ChunkGenerator> codec() {
|
||||
return Codec.unit(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChunkGenerator getDelegate() {
|
||||
if (delegate instanceof CustomChunkGenerator chunkGenerator)
|
||||
return chunkGenerator.getDelegate();
|
||||
return delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinY() {
|
||||
return delegate.getMinY();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSeaLevel() {
|
||||
return delegate.getSeaLevel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createStructures(RegistryAccess iregistrycustom, ChunkGeneratorStructureState chunkgeneratorstructurestate, StructureManager structuremanager, ChunkAccess ichunkaccess, StructureTemplateManager structuretemplatemanager) {
|
||||
delegate.createStructures(iregistrycustom, chunkgeneratorstructurestate, structuremanager, ichunkaccess, structuretemplatemanager);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buildSurface(WorldGenRegion regionlimitedworldaccess, StructureManager structuremanager, RandomState randomstate, ChunkAccess ichunkaccess) {
|
||||
delegate.buildSurface(regionlimitedworldaccess, structuremanager, randomstate, ichunkaccess);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyCarvers(WorldGenRegion regionlimitedworldaccess, long seed, RandomState randomstate, BiomeManager biomemanager, StructureManager structuremanager, ChunkAccess ichunkaccess, GenerationStep.Carving worldgenstage_features) {
|
||||
delegate.applyCarvers(regionlimitedworldaccess, seed, randomstate, biomemanager, structuremanager, ichunkaccess, worldgenstage_features);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<ChunkAccess> fillFromNoise(Executor executor, Blender blender, RandomState randomstate, StructureManager structuremanager, ChunkAccess ichunkaccess) {
|
||||
return delegate.fillFromNoise(executor, blender, randomstate, structuremanager, ichunkaccess);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBaseHeight(int i, int j, Heightmap.Types heightmap_type, LevelHeightAccessor levelheightaccessor, RandomState randomstate) {
|
||||
return delegate.getBaseHeight(i, j, heightmap_type, levelheightaccessor, randomstate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public WeightedRandomList<MobSpawnSettings.SpawnerData> getMobsAt(Holder<Biome> holder, StructureManager structuremanager, MobCategory enumcreaturetype, BlockPos blockposition) {
|
||||
return delegate.getMobsAt(holder, structuremanager, enumcreaturetype, blockposition);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyBiomeDecoration(WorldGenLevel generatoraccessseed, ChunkAccess ichunkaccess, StructureManager structuremanager) {
|
||||
delegate.applyBiomeDecoration(generatoraccessseed, ichunkaccess, structuremanager);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addDebugScreenInfo(List<String> list, RandomState randomstate, BlockPos blockposition) {
|
||||
delegate.addDebugScreenInfo(list, randomstate, blockposition);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void spawnOriginalMobs(WorldGenRegion regionlimitedworldaccess) {
|
||||
delegate.spawnOriginalMobs(regionlimitedworldaccess);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSpawnHeight(LevelHeightAccessor levelheightaccessor) {
|
||||
return delegate.getSpawnHeight(levelheightaccessor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getGenDepth() {
|
||||
return delegate.getGenDepth();
|
||||
}
|
||||
|
||||
@Override
|
||||
public NoiseColumn getBaseColumn(int i, int j, LevelHeightAccessor levelheightaccessor, RandomState randomstate) {
|
||||
return delegate.getBaseColumn(i, j, levelheightaccessor, randomstate);
|
||||
}
|
||||
|
||||
static {
|
||||
Field biomeSource = null;
|
||||
for (Field field : ChunkGenerator.class.getDeclaredFields()) {
|
||||
if (!field.getType().equals(BiomeSource.class))
|
||||
continue;
|
||||
biomeSource = field;
|
||||
break;
|
||||
}
|
||||
if (biomeSource == null)
|
||||
throw new RuntimeException("Could not find biomeSource field in ChunkGenerator!");
|
||||
BIOME_SOURCE = new WrappedField<>(ChunkGenerator.class, biomeSource.getName());
|
||||
}
|
||||
|
||||
private static ChunkGenerator edit(ChunkGenerator generator, BiomeSource source) {
|
||||
try {
|
||||
BIOME_SOURCE.set(generator, source);
|
||||
if (generator instanceof CustomChunkGenerator custom)
|
||||
BIOME_SOURCE.set(custom.getDelegate(), source);
|
||||
|
||||
return generator;
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,638 +0,0 @@
|
||||
package com.volmit.iris.core.nms.v1_19_R3;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Vector;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
import com.volmit.iris.core.nms.container.BiomeColor;
|
||||
import com.volmit.iris.util.scheduling.J;
|
||||
import net.minecraft.nbt.*;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.server.commands.data.BlockDataAccessor;
|
||||
import net.minecraft.tags.TagKey;
|
||||
import net.minecraft.world.level.LevelReader;
|
||||
import net.minecraft.world.level.block.EntityBlock;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.craftbukkit.v1_19_R3.CraftChunk;
|
||||
import org.bukkit.craftbukkit.v1_19_R3.CraftServer;
|
||||
import org.bukkit.craftbukkit.v1_19_R3.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_19_R3.block.CraftBlock;
|
||||
import org.bukkit.craftbukkit.v1_19_R3.block.CraftBlockState;
|
||||
import org.bukkit.craftbukkit.v1_19_R3.block.CraftBlockStates;
|
||||
import org.bukkit.craftbukkit.v1_19_R3.block.data.CraftBlockData;
|
||||
import org.bukkit.craftbukkit.v1_19_R3.entity.CraftDolphin;
|
||||
import org.bukkit.craftbukkit.v1_19_R3.inventory.CraftItemStack;
|
||||
import org.bukkit.entity.Dolphin;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||
import org.bukkit.generator.ChunkGenerator;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.core.nms.INMSBinding;
|
||||
import com.volmit.iris.engine.data.cache.AtomicCache;
|
||||
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.hunk.Hunk;
|
||||
import com.volmit.iris.util.json.JSONObject;
|
||||
import com.volmit.iris.util.mantle.Mantle;
|
||||
import com.volmit.iris.util.math.Vector3d;
|
||||
import com.volmit.iris.util.matter.MatterBiomeInject;
|
||||
import com.volmit.iris.util.nbt.io.NBTUtil;
|
||||
import com.volmit.iris.util.nbt.mca.NBTWorld;
|
||||
import com.volmit.iris.util.nbt.mca.palette.*;
|
||||
import com.volmit.iris.util.nbt.tag.CompoundTag;
|
||||
|
||||
import it.unimi.dsi.fastutil.objects.Object2IntMap;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.core.RegistryAccess;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.level.biome.BiomeSource;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.chunk.ChunkAccess;
|
||||
import net.minecraft.world.level.chunk.ChunkStatus;
|
||||
import net.minecraft.world.level.chunk.LevelChunk;
|
||||
import sun.misc.Unsafe;
|
||||
|
||||
public class NMSBinding implements INMSBinding {
|
||||
private final KMap<Biome, Object> baseBiomeCache = new KMap<>();
|
||||
private final BlockData AIR = Material.AIR.createBlockData();
|
||||
private final AtomicCache<MCAIdMap<net.minecraft.world.level.biome.Biome>> biomeMapCache = new AtomicCache<>();
|
||||
private final AtomicCache<MCAIdMapper<BlockState>> registryCache = new AtomicCache<>();
|
||||
private final AtomicCache<MCAPalette<BlockState>> globalCache = new AtomicCache<>();
|
||||
private final AtomicCache<RegistryAccess> registryAccess = new AtomicCache<>();
|
||||
private final AtomicCache<Method> byIdRef = new AtomicCache<>();
|
||||
private Field biomeStorageCache = null;
|
||||
|
||||
private static Object getFor(Class<?> type, Object source) {
|
||||
Object o = fieldFor(type, source);
|
||||
|
||||
if (o != null) {
|
||||
return o;
|
||||
}
|
||||
|
||||
return invokeFor(type, source);
|
||||
}
|
||||
|
||||
private static Object invokeFor(Class<?> returns, Object in) {
|
||||
for (Method i : in.getClass().getMethods()) {
|
||||
if (i.getReturnType().equals(returns)) {
|
||||
i.setAccessible(true);
|
||||
try {
|
||||
Iris.debug("[NMS] Found " + returns.getSimpleName() + " in " + in.getClass().getSimpleName() + "." + i.getName() + "()");
|
||||
return i.invoke(in);
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static Object fieldFor(Class<?> returns, Object in) {
|
||||
return fieldForClass(returns, in.getClass(), in);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static <T> T fieldForClass(Class<T> returnType, Class<?> sourceType, Object in) {
|
||||
for (Field i : sourceType.getDeclaredFields()) {
|
||||
if (i.getType().equals(returnType)) {
|
||||
i.setAccessible(true);
|
||||
try {
|
||||
Iris.debug("[NMS] Found " + returnType.getSimpleName() + " in " + sourceType.getSimpleName() + "." + i.getName());
|
||||
return (T) i.get(in);
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static Class<?> getClassType(Class<?> type, int ordinal) {
|
||||
return type.getDeclaredClasses()[ordinal];
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasTile(Material material) {
|
||||
return !CraftBlockState.class.equals(CraftBlockStates.getBlockStateType(material));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasTile(Location l) {
|
||||
return ((CraftWorld) l.getWorld()).getHandle().getBlockEntity(new BlockPos(l.getBlockX(), l.getBlockY(), l.getBlockZ()), false) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public KMap<String, Object> serializeTile(Location location) {
|
||||
BlockEntity e = ((CraftWorld) location.getWorld()).getHandle().getBlockEntity(new BlockPos(location.getBlockX(), location.getBlockY(), location.getBlockZ()), false);
|
||||
|
||||
if (e == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
net.minecraft.nbt.CompoundTag tag = e.saveWithoutMetadata();
|
||||
return (KMap<String, Object>) convertFromTag(tag, 0, 64);
|
||||
}
|
||||
|
||||
@Contract(value = "null, _, _ -> null", pure = true)
|
||||
private Object convertFromTag(net.minecraft.nbt.Tag tag, int depth, int maxDepth) {
|
||||
if (tag == null || depth > maxDepth) return null;
|
||||
if (tag instanceof CollectionTag<?> collection) {
|
||||
KList<Object> list = new KList<>();
|
||||
|
||||
for (Object i : collection) {
|
||||
if (i instanceof net.minecraft.nbt.Tag t)
|
||||
list.add(convertFromTag(t, depth + 1, maxDepth));
|
||||
else list.add(i);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
if (tag instanceof net.minecraft.nbt.CompoundTag compound) {
|
||||
KMap<String, Object> map = new KMap<>();
|
||||
|
||||
for (String key : compound.getAllKeys()) {
|
||||
var child = compound.get(key);
|
||||
if (child == null) continue;
|
||||
var value = convertFromTag(child, depth + 1, maxDepth);
|
||||
if (value == null) continue;
|
||||
map.put(key, value);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
if (tag instanceof NumericTag numeric)
|
||||
return numeric.getAsNumber();
|
||||
return tag.getAsString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deserializeTile(KMap<String, Object> map, Location pos) {
|
||||
net.minecraft.nbt.CompoundTag tag = (net.minecraft.nbt.CompoundTag) convertToTag(map, 0, 64);
|
||||
var level = ((CraftWorld) pos.getWorld()).getHandle();
|
||||
var blockPos = new BlockPos(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ());
|
||||
J.s(() -> merge(level, blockPos, tag));
|
||||
}
|
||||
|
||||
private void merge(ServerLevel level, BlockPos blockPos, net.minecraft.nbt.CompoundTag tag) {
|
||||
var blockEntity = level.getBlockEntity(blockPos);
|
||||
if (blockEntity == null) {
|
||||
Iris.warn("[NMS] BlockEntity not found at " + blockPos);
|
||||
var state = level.getBlockState(blockPos);
|
||||
if (!state.hasBlockEntity())
|
||||
return;
|
||||
|
||||
blockEntity = ((EntityBlock) state.getBlock())
|
||||
.newBlockEntity(blockPos, state);
|
||||
}
|
||||
var accessor = new BlockDataAccessor(blockEntity, blockPos);
|
||||
accessor.setData(tag.merge(accessor.getData()));
|
||||
}
|
||||
|
||||
private Tag convertToTag(Object object, int depth, int maxDepth) {
|
||||
if (object == null || depth > maxDepth) return EndTag.INSTANCE;
|
||||
if (object instanceof Map<?,?> map) {
|
||||
var tag = new net.minecraft.nbt.CompoundTag();
|
||||
for (var i : map.entrySet()) {
|
||||
tag.put(i.getKey().toString(), convertToTag(i.getValue(), depth + 1, maxDepth));
|
||||
}
|
||||
return tag;
|
||||
}
|
||||
if (object instanceof List<?> list) {
|
||||
var tag = new net.minecraft.nbt.ListTag();
|
||||
for (var i : list) {
|
||||
tag.add(convertToTag(i, depth + 1, maxDepth));
|
||||
}
|
||||
return tag;
|
||||
}
|
||||
if (object instanceof Byte number) return ByteTag.valueOf(number);
|
||||
if (object instanceof Short number) return ShortTag.valueOf(number);
|
||||
if (object instanceof Integer number) return IntTag.valueOf(number);
|
||||
if (object instanceof Long number) return LongTag.valueOf(number);
|
||||
if (object instanceof Float number) return FloatTag.valueOf(number);
|
||||
if (object instanceof Double number) return DoubleTag.valueOf(number);
|
||||
if (object instanceof String string) return StringTag.valueOf(string);
|
||||
return EndTag.INSTANCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundTag serializeEntity(Entity location) {
|
||||
return null;// TODO:
|
||||
}
|
||||
|
||||
@Override
|
||||
public Entity deserializeEntity(CompoundTag s, Location newPosition) {
|
||||
return null;// TODO:
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsCustomHeight() {
|
||||
return true;
|
||||
}
|
||||
|
||||
private RegistryAccess registry() {
|
||||
return registryAccess.aquire(() -> (RegistryAccess) getFor(RegistryAccess.Frozen.class, ((CraftServer) Bukkit.getServer()).getHandle().getServer()));
|
||||
}
|
||||
|
||||
private Registry<net.minecraft.world.level.biome.Biome> getCustomBiomeRegistry() {
|
||||
return registry().registry(Registries.BIOME).orElse(null);
|
||||
}
|
||||
|
||||
private Registry<Block> getBlockRegistry() {
|
||||
return registry().registry(Registries.BLOCK).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getBiomeBaseFromId(int id) {
|
||||
return getCustomBiomeRegistry().getHolder(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinHeight(World world) {
|
||||
return world.getMinHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsCustomBiomes() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTrueBiomeBaseId(Object biomeBase) {
|
||||
return getCustomBiomeRegistry().getId(((Holder<net.minecraft.world.level.biome.Biome>) biomeBase).value());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getTrueBiomeBase(Location location) {
|
||||
return ((CraftWorld) location.getWorld()).getHandle().getBiome(new BlockPos(location.getBlockX(), location.getBlockY(), location.getBlockZ()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTrueBiomeBaseKey(Location location) {
|
||||
return getKeyForBiomeBase(getTrueBiomeBase(location));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getCustomBiomeBaseFor(String mckey) {
|
||||
return getCustomBiomeRegistry().get(new ResourceLocation(mckey));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getCustomBiomeBaseHolderFor(String mckey) {
|
||||
return getCustomBiomeRegistry().getHolder(getTrueBiomeBaseId(getCustomBiomeRegistry().get(new ResourceLocation(mckey)))).get();
|
||||
}
|
||||
|
||||
public int getBiomeBaseIdForKey(String key) {
|
||||
return getCustomBiomeRegistry().getId(getCustomBiomeRegistry().get(new ResourceLocation(key)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getKeyForBiomeBase(Object biomeBase) {
|
||||
return getCustomBiomeRegistry().getKey((net.minecraft.world.level.biome.Biome) biomeBase).getPath(); // something, not something:something
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getBiomeBase(World world, Biome biome) {
|
||||
return CraftBlock.biomeToBiomeBase(((CraftWorld) world).getHandle()
|
||||
.registryAccess().registry(Registries.BIOME).orElse(null), biome);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getBiomeBase(Object registry, Biome biome) {
|
||||
Object v = baseBiomeCache.get(biome);
|
||||
|
||||
if (v != null) {
|
||||
return v;
|
||||
}
|
||||
//noinspection unchecked
|
||||
v = CraftBlock.biomeToBiomeBase((Registry<net.minecraft.world.level.biome.Biome>) registry, biome);
|
||||
if (v == null) {
|
||||
// Ok so there is this new biome name called "CUSTOM" in Paper's new releases.
|
||||
// But, this does NOT exist within CraftBukkit which makes it return an error.
|
||||
// So, we will just return the ID that the plains biome returns instead.
|
||||
//noinspection unchecked
|
||||
return CraftBlock.biomeToBiomeBase((Registry<net.minecraft.world.level.biome.Biome>) registry, Biome.PLAINS);
|
||||
}
|
||||
baseBiomeCache.put(biome, v);
|
||||
return v;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public KList<Biome> getBiomes() {
|
||||
return new KList<>(Biome.values()).qdel(Biome.CHERRY_GROVE).qdel(Biome.CUSTOM);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBukkit() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBiomeId(Biome biome) {
|
||||
for (World i : Bukkit.getWorlds()) {
|
||||
if (i.getEnvironment().equals(World.Environment.NORMAL)) {
|
||||
Registry<net.minecraft.world.level.biome.Biome> registry = ((CraftWorld) i).getHandle().registryAccess().registry(Registries.BIOME).orElse(null);
|
||||
return registry.getId((net.minecraft.world.level.biome.Biome) getBiomeBase(registry, biome));
|
||||
}
|
||||
}
|
||||
|
||||
return biome.ordinal();
|
||||
}
|
||||
|
||||
private MCAIdMap<net.minecraft.world.level.biome.Biome> getBiomeMapping() {
|
||||
return biomeMapCache.aquire(() -> new MCAIdMap<>() {
|
||||
@NotNull
|
||||
@Override
|
||||
public Iterator<net.minecraft.world.level.biome.Biome> iterator() {
|
||||
return getCustomBiomeRegistry().iterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getId(net.minecraft.world.level.biome.Biome paramT) {
|
||||
return getCustomBiomeRegistry().getId(paramT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public net.minecraft.world.level.biome.Biome byId(int paramInt) {
|
||||
return (net.minecraft.world.level.biome.Biome) getBiomeBaseFromId(paramInt);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private MCABiomeContainer getBiomeContainerInterface(MCAIdMap<net.minecraft.world.level.biome.Biome> biomeMapping, MCAChunkBiomeContainer<net.minecraft.world.level.biome.Biome> base) {
|
||||
return new MCABiomeContainer() {
|
||||
@Override
|
||||
public int[] getData() {
|
||||
return base.writeBiomes();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBiome(int x, int y, int z, int id) {
|
||||
base.setBiome(x, y, z, biomeMapping.byId(id));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBiome(int x, int y, int z) {
|
||||
return biomeMapping.getId(base.getBiome(x, y, z));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public MCABiomeContainer newBiomeContainer(int min, int max) {
|
||||
MCAChunkBiomeContainer<net.minecraft.world.level.biome.Biome> base = new MCAChunkBiomeContainer<>(getBiomeMapping(), min, max);
|
||||
return getBiomeContainerInterface(getBiomeMapping(), base);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MCABiomeContainer newBiomeContainer(int min, int max, int[] data) {
|
||||
MCAChunkBiomeContainer<net.minecraft.world.level.biome.Biome> base = new MCAChunkBiomeContainer<>(getBiomeMapping(), min, max, data);
|
||||
return getBiomeContainerInterface(getBiomeMapping(), base);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int countCustomBiomes() {
|
||||
AtomicInteger a = new AtomicInteger(0);
|
||||
|
||||
getCustomBiomeRegistry().keySet().forEach((i) -> {
|
||||
if (i.getNamespace().equals("minecraft")) {
|
||||
return;
|
||||
}
|
||||
|
||||
a.incrementAndGet();
|
||||
Iris.debug("Custom Biome: " + i);
|
||||
});
|
||||
|
||||
return a.get();
|
||||
}
|
||||
|
||||
public boolean supportsDataPacks() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void setBiomes(int cx, int cz, World world, Hunk<Object> biomes) {
|
||||
LevelChunk c = ((CraftWorld) world).getHandle().getChunk(cx, cz);
|
||||
biomes.iterateSync((x, y, z, b) -> c.setBiome(x, y, z, (Holder<net.minecraft.world.level.biome.Biome>) b));
|
||||
c.setUnsaved(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forceBiomeInto(int x, int y, int z, Object somethingVeryDirty, ChunkGenerator.BiomeGrid chunk) {
|
||||
try {
|
||||
ChunkAccess s = (ChunkAccess) getFieldForBiomeStorage(chunk).get(chunk);
|
||||
Holder<net.minecraft.world.level.biome.Biome> biome = (Holder<net.minecraft.world.level.biome.Biome>) somethingVeryDirty;
|
||||
s.setBiome(x, y, z, biome);
|
||||
} catch (IllegalAccessException e) {
|
||||
Iris.reportError(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private Field getFieldForBiomeStorage(Object storage) {
|
||||
Field f = biomeStorageCache;
|
||||
|
||||
if (f != null) {
|
||||
return f;
|
||||
}
|
||||
try {
|
||||
f = storage.getClass().getDeclaredField("biome");
|
||||
f.setAccessible(true);
|
||||
return f;
|
||||
} catch (Throwable e) {
|
||||
Iris.reportError(e);
|
||||
e.printStackTrace();
|
||||
Iris.error(storage.getClass().getCanonicalName());
|
||||
}
|
||||
|
||||
biomeStorageCache = f;
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MCAPaletteAccess createPalette() {
|
||||
MCAIdMapper<BlockState> registry = registryCache.aquireNasty(() -> {
|
||||
Field cf = net.minecraft.core.IdMapper.class.getDeclaredField("tToId");
|
||||
Field df = net.minecraft.core.IdMapper.class.getDeclaredField("idToT");
|
||||
Field bf = net.minecraft.core.IdMapper.class.getDeclaredField("nextId");
|
||||
cf.setAccessible(true);
|
||||
df.setAccessible(true);
|
||||
bf.setAccessible(true);
|
||||
net.minecraft.core.IdMapper<BlockState> blockData = Block.BLOCK_STATE_REGISTRY;
|
||||
int b = bf.getInt(blockData);
|
||||
Object2IntMap<BlockState> c = (Object2IntMap<BlockState>) cf.get(blockData);
|
||||
List<BlockState> d = (List<BlockState>) df.get(blockData);
|
||||
return new MCAIdMapper<BlockState>(c, d, b);
|
||||
});
|
||||
MCAPalette<BlockState> global = globalCache.aquireNasty(() -> new MCAGlobalPalette<>(registry, ((CraftBlockData) AIR).getState()));
|
||||
MCAPalettedContainer<BlockState> container = new MCAPalettedContainer<>(global, registry,
|
||||
i -> ((CraftBlockData) NBTWorld.getBlockData(i)).getState(),
|
||||
i -> NBTWorld.getCompound(CraftBlockData.fromData(i)),
|
||||
((CraftBlockData) AIR).getState());
|
||||
return new MCAWrappedPalettedContainer<>(container,
|
||||
i -> NBTWorld.getCompound(CraftBlockData.fromData(i)),
|
||||
i -> ((CraftBlockData) NBTWorld.getBlockData(i)).getState());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void injectBiomesFromMantle(Chunk e, Mantle mantle) {
|
||||
ChunkAccess chunk = ((CraftChunk) e).getHandle(ChunkStatus.FULL);
|
||||
AtomicInteger c = new AtomicInteger();
|
||||
AtomicInteger r = new AtomicInteger();
|
||||
mantle.iterateChunk(e.getX(), e.getZ(), MatterBiomeInject.class, (x, y, z, b) -> {
|
||||
if (b != null) {
|
||||
if (b.isCustom()) {
|
||||
chunk.setBiome(x, y, z, getCustomBiomeRegistry().getHolder(b.getBiomeId()).get());
|
||||
c.getAndIncrement();
|
||||
} else {
|
||||
chunk.setBiome(x, y, z, (Holder<net.minecraft.world.level.biome.Biome>) getBiomeBase(e.getWorld(), b.getBiome()));
|
||||
r.getAndIncrement();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public ItemStack applyCustomNbt(ItemStack itemStack, KMap<String, Object> customNbt) throws IllegalArgumentException {
|
||||
if (customNbt != null && !customNbt.isEmpty()) {
|
||||
net.minecraft.world.item.ItemStack s = CraftItemStack.asNMSCopy(itemStack);
|
||||
|
||||
try {
|
||||
net.minecraft.nbt.CompoundTag tag = TagParser.parseTag((new JSONObject(customNbt)).toString());
|
||||
tag.merge(s.getOrCreateTag());
|
||||
s.setTag(tag);
|
||||
} catch (CommandSyntaxException var5) {
|
||||
throw new IllegalArgumentException(var5);
|
||||
}
|
||||
|
||||
return CraftItemStack.asBukkitCopy(s);
|
||||
} else {
|
||||
return itemStack;
|
||||
}
|
||||
}
|
||||
|
||||
public void setTreasurePos(Dolphin dolphin, com.volmit.iris.core.nms.container.BlockPos pos) {
|
||||
CraftDolphin cd = (CraftDolphin)dolphin;
|
||||
cd.getHandle().setTreasurePos(new BlockPos(pos.getX(), pos.getY(), pos.getZ()));
|
||||
cd.getHandle().setGotFish(true);
|
||||
}
|
||||
|
||||
public void inject(long seed, Engine engine, World world) {
|
||||
var chunkMap = ((CraftWorld)world).getHandle().getChunkSource().chunkMap;
|
||||
chunkMap.generator = new IrisChunkGenerator(chunkMap.generator, seed, engine, world);
|
||||
}
|
||||
|
||||
public Vector3d getBoundingbox(org.bukkit.entity.EntityType entity) {
|
||||
Field[] fields = EntityType.class.getDeclaredFields();
|
||||
for (Field field : fields) {
|
||||
if (Modifier.isStatic(field.getModifiers()) && field.getType().equals(EntityType.class)) {
|
||||
try {
|
||||
EntityType entityType = (EntityType) field.get(null);
|
||||
if (entityType.getDescriptionId().equals("entity.minecraft." + entity.name().toLowerCase())) {
|
||||
Vector<Float> v1 = new Vector<>();
|
||||
v1.add(entityType.getHeight());
|
||||
entityType.getDimensions();
|
||||
Vector3d box = new Vector3d( entityType.getWidth(), entityType.getHeight(), entityType.getWidth());
|
||||
//System.out.println("Entity Type: " + entityType.getDescriptionId() + ", " + "Height: " + height + ", Width: " + width);
|
||||
return box;
|
||||
}
|
||||
} catch (IllegalAccessException e) {
|
||||
Iris.error("Unable to get entity dimensions!");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Entity spawnEntity(Location location, org.bukkit.entity.EntityType type, CreatureSpawnEvent.SpawnReason reason) {
|
||||
if (type == org.bukkit.entity.EntityType.CAMEL) {
|
||||
return null;
|
||||
}
|
||||
return ((CraftWorld) location.getWorld()).spawn(location, type.getEntityClass(), null, reason);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Color getBiomeColor(Location location, BiomeColor type) {
|
||||
LevelReader reader = ((CraftWorld) location.getWorld()).getHandle();
|
||||
var holder = reader.getBiome(new BlockPos(location.getBlockX(), location.getBlockY(), location.getBlockZ()));
|
||||
var biome = holder.value();
|
||||
if (biome == null) throw new IllegalArgumentException("Invalid biome: " + holder.unwrapKey().orElse(null));
|
||||
|
||||
int rgba = switch (type) {
|
||||
case FOG -> biome.getFogColor();
|
||||
case WATER -> biome.getWaterColor();
|
||||
case WATER_FOG -> biome.getWaterFogColor();
|
||||
case SKY -> biome.getSkyColor();
|
||||
case FOLIAGE -> biome.getFoliageColor();
|
||||
case GRASS -> biome.getGrassColor(location.getBlockX(), location.getBlockZ());
|
||||
};
|
||||
if (rgba == 0) {
|
||||
if (BiomeColor.FOLIAGE == type && biome.getSpecialEffects().getFoliageColorOverride().isEmpty())
|
||||
return null;
|
||||
if (BiomeColor.GRASS == type && biome.getSpecialEffects().getGrassColorOverride().isEmpty())
|
||||
return null;
|
||||
}
|
||||
return new Color(rgba, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public KList<String> getStructureKeys() {
|
||||
KList<String> keys = new KList<>();
|
||||
|
||||
var registry = registry().registry(Registries.STRUCTURE).orElse(null);
|
||||
if (registry == null) return keys;
|
||||
registry.keySet().stream().map(ResourceLocation::toString).forEach(keys::add);
|
||||
registry.getTags()
|
||||
.map(Pair::getFirst)
|
||||
.map(TagKey::location)
|
||||
.map(ResourceLocation::toString)
|
||||
.map(s -> "#" + s)
|
||||
.forEach(keys::add);
|
||||
|
||||
return keys;
|
||||
}
|
||||
|
||||
private static Field getField(Class<?> clazz, Class<?> fieldType) throws NoSuchFieldException {
|
||||
try {
|
||||
for (Field f : clazz.getDeclaredFields()) {
|
||||
if (f.getType().equals(fieldType))
|
||||
return f;
|
||||
}
|
||||
throw new NoSuchFieldException(fieldType.getName());
|
||||
} catch (NoSuchFieldException var4) {
|
||||
Class<?> superClass = clazz.getSuperclass();
|
||||
if (superClass == null) {
|
||||
throw var4;
|
||||
} else {
|
||||
return getField(superClass, fieldType);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,8 +2,10 @@ package com.volmit.iris.core.nms.v1_20_R1;
|
||||
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
import com.mojang.serialization.Lifecycle;
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.core.nms.INMSBinding;
|
||||
import com.volmit.iris.core.nms.container.AutoClosing;
|
||||
import com.volmit.iris.core.nms.container.BiomeColor;
|
||||
import com.volmit.iris.engine.data.cache.AtomicCache;
|
||||
import com.volmit.iris.engine.framework.Engine;
|
||||
@@ -20,14 +22,16 @@ import com.volmit.iris.util.nbt.mca.palette.*;
|
||||
import com.volmit.iris.util.nbt.tag.CompoundTag;
|
||||
import com.volmit.iris.util.scheduling.J;
|
||||
import it.unimi.dsi.fastutil.objects.Object2IntMap;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Holder;
|
||||
import lombok.SneakyThrows;
|
||||
import net.minecraft.core.*;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.core.RegistryAccess;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.nbt.*;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.WorldLoader;
|
||||
import net.minecraft.server.commands.data.BlockDataAccessor;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.tags.TagKey;
|
||||
@@ -41,6 +45,8 @@ import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.chunk.ChunkAccess;
|
||||
import net.minecraft.world.level.chunk.ChunkStatus;
|
||||
import net.minecraft.world.level.chunk.LevelChunk;
|
||||
import net.minecraft.world.level.dimension.DimensionType;
|
||||
import net.minecraft.world.level.dimension.LevelStem;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
@@ -73,11 +79,10 @@ import java.io.DataOutputStream;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Vector;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class NMSBinding implements INMSBinding {
|
||||
|
||||
@@ -85,9 +90,11 @@ public class NMSBinding implements INMSBinding {
|
||||
private final KMap<Biome, Object> baseBiomeCache = new KMap<>();
|
||||
private final BlockData AIR = Material.AIR.createBlockData();
|
||||
private final AtomicCache<MCAIdMap<net.minecraft.world.level.biome.Biome>> biomeMapCache = new AtomicCache<>();
|
||||
private final AtomicCache<WorldLoader.DataLoadContext> dataLoadContext = new AtomicCache<>();
|
||||
private final AtomicCache<MCAIdMapper<BlockState>> registryCache = new AtomicCache<>();
|
||||
private final AtomicCache<MCAPalette<BlockState>> globalCache = new AtomicCache<>();
|
||||
private final AtomicCache<RegistryAccess> registryAccess = new AtomicCache<>();
|
||||
private final ReentrantLock dataContextLock = new ReentrantLock(true);
|
||||
private final AtomicCache<Method> byIdRef = new AtomicCache<>();
|
||||
private Field biomeStorageCache = null;
|
||||
|
||||
@@ -214,7 +221,7 @@ public class NMSBinding implements INMSBinding {
|
||||
.newBlockEntity(blockPos, state);
|
||||
}
|
||||
var accessor = new BlockDataAccessor(blockEntity, blockPos);
|
||||
accessor.setData(tag.merge(accessor.getData()));
|
||||
accessor.setData(accessor.getData().merge(tag));
|
||||
}
|
||||
|
||||
private Tag convertToTag(Object object, int depth, int maxDepth) {
|
||||
@@ -568,6 +575,9 @@ public class NMSBinding implements INMSBinding {
|
||||
|
||||
public void inject(long seed, Engine engine, World world) {
|
||||
var chunkMap = ((CraftWorld)world).getHandle().getChunkSource().chunkMap;
|
||||
var dimensionType = chunkMap.level.dimensionTypeRegistration().unwrapKey().orElse(null);
|
||||
if (dimensionType != null && !dimensionType.location().getNamespace().equals("iris"))
|
||||
Iris.error("Loaded world %s with invalid dimension type! (%s)", world.getName(), dimensionType.location().toString());
|
||||
chunkMap.generator = new IrisChunkGenerator(chunkMap.generator, seed, engine, world);
|
||||
}
|
||||
|
||||
@@ -628,4 +638,98 @@ public class NMSBinding implements INMSBinding {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public AutoClosing injectLevelStems() {
|
||||
return inject(this::supplier);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SneakyThrows
|
||||
public com.volmit.iris.core.nms.container.Pair<Integer, AutoClosing> injectUncached(boolean overworld, boolean nether, boolean end) {
|
||||
var reg = registry();
|
||||
var field = getField(RegistryAccess.ImmutableRegistryAccess.class, Map.class);
|
||||
field.setAccessible(true);
|
||||
|
||||
AutoClosing closing = inject(old -> new WorldLoader.DataLoadContext(
|
||||
old.resources(),
|
||||
old.dataConfiguration(),
|
||||
old.datapackWorldgen(),
|
||||
createRegistryAccess(old.datapackDimensions(), true, overworld, nether, end)
|
||||
)
|
||||
);
|
||||
|
||||
var injected = ((CraftServer) Bukkit.getServer()).getServer().worldLoader.datapackDimensions().registryOrThrow(Registries.LEVEL_STEM);
|
||||
var old = (Map<ResourceKey<? extends Registry<?>>, Registry<?>>) field.get(reg);
|
||||
var fake = new HashMap<>(old);
|
||||
fake.put(Registries.LEVEL_STEM, injected);
|
||||
field.set(reg, fake);
|
||||
|
||||
return new com.volmit.iris.core.nms.container.Pair<>(
|
||||
injected.size(),
|
||||
new AutoClosing(() -> {
|
||||
closing.close();
|
||||
field.set(reg, old);
|
||||
}));
|
||||
}
|
||||
|
||||
private WorldLoader.DataLoadContext supplier(WorldLoader.DataLoadContext old) {
|
||||
return dataLoadContext.aquire(() -> new WorldLoader.DataLoadContext(
|
||||
old.resources(),
|
||||
old.dataConfiguration(),
|
||||
old.datapackWorldgen(),
|
||||
createRegistryAccess(old.datapackDimensions(), false, true, true, true)
|
||||
));
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
private AutoClosing inject(Function<WorldLoader.DataLoadContext, WorldLoader.DataLoadContext> transformer) {
|
||||
if (!dataContextLock.tryLock()) throw new IllegalStateException("Failed to inject data context!");
|
||||
|
||||
var server = ((CraftServer) Bukkit.getServer());
|
||||
var field = getField(MinecraftServer.class, WorldLoader.DataLoadContext.class);
|
||||
var nmsServer = server.getServer();
|
||||
var old = nmsServer.worldLoader;
|
||||
|
||||
field.setAccessible(true);
|
||||
field.set(nmsServer, transformer.apply(old));
|
||||
|
||||
return new AutoClosing(() -> {
|
||||
field.set(nmsServer, old);
|
||||
dataContextLock.unlock();
|
||||
});
|
||||
}
|
||||
|
||||
private RegistryAccess.Frozen createRegistryAccess(RegistryAccess.Frozen datapack, boolean copy, boolean overworld, boolean nether, boolean end) {
|
||||
var access = registry();
|
||||
var dimensions = access.registryOrThrow(Registries.DIMENSION_TYPE);
|
||||
var levelStems = access.registryOrThrow(Registries.LEVEL_STEM);
|
||||
|
||||
var fake = new MappedRegistry<>(Registries.LEVEL_STEM, Lifecycle.experimental());
|
||||
if (overworld) register(fake, levelStems, dimensions, LevelStem.OVERWORLD);
|
||||
if (nether) register(fake, levelStems, dimensions, LevelStem.NETHER);
|
||||
if (end) register(fake, levelStems, dimensions, LevelStem.END);
|
||||
copy(fake, datapack.registry(Registries.LEVEL_STEM).orElse(null));
|
||||
|
||||
if (copy) copy(fake, levelStems);
|
||||
|
||||
return new RegistryAccess.Frozen.ImmutableRegistryAccess(List.of(fake.freeze())).freeze();
|
||||
}
|
||||
|
||||
private void register(MappedRegistry<LevelStem> target, Registry<LevelStem> levelStems, Registry<DimensionType> dimensions, ResourceKey<LevelStem> key) {
|
||||
target.register(key, new LevelStem(
|
||||
dimensions.getHolderOrThrow(ResourceKey.create(Registries.DIMENSION_TYPE, new ResourceLocation("iris", key.location().getPath()))),
|
||||
levelStems.getOrThrow(key).generator()
|
||||
), Lifecycle.stable());
|
||||
}
|
||||
|
||||
private void copy(MappedRegistry<LevelStem> target, Registry<LevelStem> source) {
|
||||
if (source == null) return;
|
||||
source.registryKeySet().forEach(key -> {
|
||||
var value = source.get(key);
|
||||
var info = source.lifecycle(value);
|
||||
if (value != null && info != null && !target.containsKey(key))
|
||||
target.register(key, value, info);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,21 +8,29 @@ import java.io.DataOutputStream;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Vector;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
import java.util.function.Function;
|
||||
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
import com.mojang.serialization.Lifecycle;
|
||||
import com.volmit.iris.core.nms.container.AutoClosing;
|
||||
import com.volmit.iris.core.nms.container.BiomeColor;
|
||||
import com.volmit.iris.util.scheduling.J;
|
||||
import lombok.SneakyThrows;
|
||||
import net.minecraft.core.*;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.nbt.*;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.WorldLoader;
|
||||
import net.minecraft.server.commands.data.BlockDataAccessor;
|
||||
import net.minecraft.tags.TagKey;
|
||||
import net.minecraft.world.level.LevelReader;
|
||||
import net.minecraft.world.level.block.EntityBlock;
|
||||
import net.minecraft.world.level.dimension.DimensionType;
|
||||
import net.minecraft.world.level.dimension.LevelStem;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
@@ -61,10 +69,6 @@ import com.volmit.iris.util.nbt.mca.palette.*;
|
||||
import com.volmit.iris.util.nbt.tag.CompoundTag;
|
||||
|
||||
import it.unimi.dsi.fastutil.objects.Object2IntMap;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.core.RegistryAccess;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
@@ -83,9 +87,11 @@ public class NMSBinding implements INMSBinding {
|
||||
private final KMap<Biome, Object> baseBiomeCache = new KMap<>();
|
||||
private final BlockData AIR = Material.AIR.createBlockData();
|
||||
private final AtomicCache<MCAIdMap<net.minecraft.world.level.biome.Biome>> biomeMapCache = new AtomicCache<>();
|
||||
private final AtomicCache<WorldLoader.DataLoadContext> dataLoadContext = new AtomicCache<>();
|
||||
private final AtomicCache<MCAIdMapper<BlockState>> registryCache = new AtomicCache<>();
|
||||
private final AtomicCache<MCAPalette<BlockState>> globalCache = new AtomicCache<>();
|
||||
private final AtomicCache<RegistryAccess> registryAccess = new AtomicCache<>();
|
||||
private final ReentrantLock dataContextLock = new ReentrantLock(true);
|
||||
private final AtomicCache<Method> byIdRef = new AtomicCache<>();
|
||||
private Field biomeStorageCache = null;
|
||||
|
||||
@@ -212,7 +218,7 @@ public class NMSBinding implements INMSBinding {
|
||||
.newBlockEntity(blockPos, state);
|
||||
}
|
||||
var accessor = new BlockDataAccessor(blockEntity, blockPos);
|
||||
accessor.setData(tag.merge(accessor.getData()));
|
||||
accessor.setData(accessor.getData().merge(tag));
|
||||
}
|
||||
|
||||
private Tag convertToTag(Object object, int depth, int maxDepth) {
|
||||
@@ -538,6 +544,9 @@ public class NMSBinding implements INMSBinding {
|
||||
|
||||
public void inject(long seed, Engine engine, World world) {
|
||||
var chunkMap = ((CraftWorld)world).getHandle().getChunkSource().chunkMap;
|
||||
var dimensionType = chunkMap.level.dimensionTypeRegistration().unwrapKey().orElse(null);
|
||||
if (dimensionType != null && !dimensionType.location().getNamespace().equals("iris"))
|
||||
Iris.error("Loaded world %s with invalid dimension type! (%s)", world.getName(), dimensionType.location().toString());
|
||||
chunkMap.generator = new IrisChunkGenerator(chunkMap.generator, seed, engine, world);
|
||||
}
|
||||
|
||||
@@ -630,4 +639,98 @@ public class NMSBinding implements INMSBinding {
|
||||
public static Holder<net.minecraft.world.level.biome.Biome> biomeToBiomeBase(Registry<net.minecraft.world.level.biome.Biome> registry, Biome biome) {
|
||||
return registry.getHolderOrThrow(ResourceKey.create(Registries.BIOME, CraftNamespacedKey.toMinecraft(biome.getKey())));
|
||||
}
|
||||
|
||||
@Override
|
||||
public AutoClosing injectLevelStems() {
|
||||
return inject(this::supplier);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SneakyThrows
|
||||
public com.volmit.iris.core.nms.container.Pair<Integer, AutoClosing> injectUncached(boolean overworld, boolean nether, boolean end) {
|
||||
var reg = registry();
|
||||
var field = getField(RegistryAccess.ImmutableRegistryAccess.class, Map.class);
|
||||
field.setAccessible(true);
|
||||
|
||||
AutoClosing closing = inject(old -> new WorldLoader.DataLoadContext(
|
||||
old.resources(),
|
||||
old.dataConfiguration(),
|
||||
old.datapackWorldgen(),
|
||||
createRegistryAccess(old.datapackDimensions(), true, overworld, nether, end)
|
||||
)
|
||||
);
|
||||
|
||||
var injected = ((CraftServer) Bukkit.getServer()).getServer().worldLoader.datapackDimensions().registryOrThrow(Registries.LEVEL_STEM);
|
||||
var old = (Map<ResourceKey<? extends Registry<?>>, Registry<?>>) field.get(reg);
|
||||
var fake = new HashMap<>(old);
|
||||
fake.put(Registries.LEVEL_STEM, injected);
|
||||
field.set(reg, fake);
|
||||
|
||||
return new com.volmit.iris.core.nms.container.Pair<>(
|
||||
injected.size(),
|
||||
new AutoClosing(() -> {
|
||||
closing.close();
|
||||
field.set(reg, old);
|
||||
}));
|
||||
}
|
||||
|
||||
private WorldLoader.DataLoadContext supplier(WorldLoader.DataLoadContext old) {
|
||||
return dataLoadContext.aquire(() -> new WorldLoader.DataLoadContext(
|
||||
old.resources(),
|
||||
old.dataConfiguration(),
|
||||
old.datapackWorldgen(),
|
||||
createRegistryAccess(old.datapackDimensions(), false, true, true, true)
|
||||
));
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
private AutoClosing inject(Function<WorldLoader.DataLoadContext, WorldLoader.DataLoadContext> transformer) {
|
||||
if (!dataContextLock.tryLock()) throw new IllegalStateException("Failed to inject data context!");
|
||||
|
||||
var server = ((CraftServer) Bukkit.getServer());
|
||||
var field = getField(MinecraftServer.class, WorldLoader.DataLoadContext.class);
|
||||
var nmsServer = server.getServer();
|
||||
var old = nmsServer.worldLoader;
|
||||
|
||||
field.setAccessible(true);
|
||||
field.set(nmsServer, transformer.apply(old));
|
||||
|
||||
return new AutoClosing(() -> {
|
||||
field.set(nmsServer, old);
|
||||
dataContextLock.unlock();
|
||||
});
|
||||
}
|
||||
|
||||
private RegistryAccess.Frozen createRegistryAccess(RegistryAccess.Frozen datapack, boolean copy, boolean overworld, boolean nether, boolean end) {
|
||||
var access = registry();
|
||||
var dimensions = access.registryOrThrow(Registries.DIMENSION_TYPE);
|
||||
var levelStems = access.registryOrThrow(Registries.LEVEL_STEM);
|
||||
|
||||
var fake = new MappedRegistry<>(Registries.LEVEL_STEM, Lifecycle.experimental());
|
||||
if (overworld) register(fake, levelStems, dimensions, LevelStem.OVERWORLD);
|
||||
if (nether) register(fake, levelStems, dimensions, LevelStem.NETHER);
|
||||
if (end) register(fake, levelStems, dimensions, LevelStem.END);
|
||||
copy(fake, datapack.registry(Registries.LEVEL_STEM).orElse(null));
|
||||
|
||||
if (copy) copy(fake, levelStems);
|
||||
|
||||
return new RegistryAccess.Frozen.ImmutableRegistryAccess(List.of(fake.freeze())).freeze();
|
||||
}
|
||||
|
||||
private void register(MappedRegistry<LevelStem> target, Registry<LevelStem> levelStems, Registry<DimensionType> dimensions, ResourceKey<LevelStem> key) {
|
||||
target.register(key, new LevelStem(
|
||||
dimensions.getHolderOrThrow(ResourceKey.create(Registries.DIMENSION_TYPE, new ResourceLocation("iris", key.location().getPath()))),
|
||||
levelStems.getOrThrow(key).generator()
|
||||
), Lifecycle.stable());
|
||||
}
|
||||
|
||||
private void copy(MappedRegistry<LevelStem> target, Registry<LevelStem> source) {
|
||||
if (source == null) return;
|
||||
source.registryKeySet().forEach(key -> {
|
||||
var value = source.get(key);
|
||||
var info = source.lifecycle(value);
|
||||
if (value != null && info != null && !target.containsKey(key))
|
||||
target.register(key, value, info);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,21 +8,29 @@ import java.io.DataOutputStream;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Vector;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
import java.util.function.Function;
|
||||
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
import com.mojang.serialization.Lifecycle;
|
||||
import com.volmit.iris.core.nms.container.AutoClosing;
|
||||
import com.volmit.iris.core.nms.container.BiomeColor;
|
||||
import com.volmit.iris.util.scheduling.J;
|
||||
import lombok.SneakyThrows;
|
||||
import net.minecraft.core.*;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.nbt.*;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.WorldLoader;
|
||||
import net.minecraft.server.commands.data.BlockDataAccessor;
|
||||
import net.minecraft.tags.TagKey;
|
||||
import net.minecraft.world.level.LevelReader;
|
||||
import net.minecraft.world.level.block.EntityBlock;
|
||||
import net.minecraft.world.level.dimension.DimensionType;
|
||||
import net.minecraft.world.level.dimension.LevelStem;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
@@ -61,10 +69,6 @@ import com.volmit.iris.util.nbt.mca.palette.*;
|
||||
import com.volmit.iris.util.nbt.tag.CompoundTag;
|
||||
|
||||
import it.unimi.dsi.fastutil.objects.Object2IntMap;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.core.RegistryAccess;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
@@ -83,9 +87,11 @@ public class NMSBinding implements INMSBinding {
|
||||
private final KMap<Biome, Object> baseBiomeCache = new KMap<>();
|
||||
private final BlockData AIR = Material.AIR.createBlockData();
|
||||
private final AtomicCache<MCAIdMap<net.minecraft.world.level.biome.Biome>> biomeMapCache = new AtomicCache<>();
|
||||
private final AtomicCache<WorldLoader.DataLoadContext> dataLoadContext = new AtomicCache<>();
|
||||
private final AtomicCache<MCAIdMapper<BlockState>> registryCache = new AtomicCache<>();
|
||||
private final AtomicCache<MCAPalette<BlockState>> globalCache = new AtomicCache<>();
|
||||
private final AtomicCache<RegistryAccess> registryAccess = new AtomicCache<>();
|
||||
private final ReentrantLock dataContextLock = new ReentrantLock(true);
|
||||
private final AtomicCache<Method> byIdRef = new AtomicCache<>();
|
||||
private Field biomeStorageCache = null;
|
||||
|
||||
@@ -212,7 +218,7 @@ public class NMSBinding implements INMSBinding {
|
||||
.newBlockEntity(blockPos, state);
|
||||
}
|
||||
var accessor = new BlockDataAccessor(blockEntity, blockPos);
|
||||
accessor.setData(tag.merge(accessor.getData()));
|
||||
accessor.setData(accessor.getData().merge(tag));
|
||||
}
|
||||
|
||||
private Tag convertToTag(Object object, int depth, int maxDepth) {
|
||||
@@ -538,6 +544,9 @@ public class NMSBinding implements INMSBinding {
|
||||
|
||||
public void inject(long seed, Engine engine, World world) {
|
||||
var chunkMap = ((CraftWorld)world).getHandle().getChunkSource().chunkMap;
|
||||
var dimensionType = chunkMap.level.dimensionTypeRegistration().unwrapKey().orElse(null);
|
||||
if (dimensionType != null && !dimensionType.location().getNamespace().equals("iris"))
|
||||
Iris.error("Loaded world %s with invalid dimension type! (%s)", world.getName(), dimensionType.location().toString());
|
||||
chunkMap.generator = new IrisChunkGenerator(chunkMap.generator, seed, engine, world);
|
||||
}
|
||||
|
||||
@@ -631,4 +640,98 @@ public class NMSBinding implements INMSBinding {
|
||||
public static Holder<net.minecraft.world.level.biome.Biome> biomeToBiomeBase(Registry<net.minecraft.world.level.biome.Biome> registry, Biome biome) {
|
||||
return registry.getHolderOrThrow(ResourceKey.create(Registries.BIOME, CraftNamespacedKey.toMinecraft(biome.getKey())));
|
||||
}
|
||||
|
||||
@Override
|
||||
public AutoClosing injectLevelStems() {
|
||||
return inject(this::supplier);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SneakyThrows
|
||||
public com.volmit.iris.core.nms.container.Pair<Integer, AutoClosing> injectUncached(boolean overworld, boolean nether, boolean end) {
|
||||
var reg = registry();
|
||||
var field = getField(RegistryAccess.ImmutableRegistryAccess.class, Map.class);
|
||||
field.setAccessible(true);
|
||||
|
||||
AutoClosing closing = inject(old -> new WorldLoader.DataLoadContext(
|
||||
old.resources(),
|
||||
old.dataConfiguration(),
|
||||
old.datapackWorldgen(),
|
||||
createRegistryAccess(old.datapackDimensions(), true, overworld, nether, end)
|
||||
)
|
||||
);
|
||||
|
||||
var injected = ((CraftServer) Bukkit.getServer()).getServer().worldLoader.datapackDimensions().registryOrThrow(Registries.LEVEL_STEM);
|
||||
var old = (Map<ResourceKey<? extends Registry<?>>, Registry<?>>) field.get(reg);
|
||||
var fake = new HashMap<>(old);
|
||||
fake.put(Registries.LEVEL_STEM, injected);
|
||||
field.set(reg, fake);
|
||||
|
||||
return new com.volmit.iris.core.nms.container.Pair<>(
|
||||
injected.size(),
|
||||
new AutoClosing(() -> {
|
||||
closing.close();
|
||||
field.set(reg, old);
|
||||
}));
|
||||
}
|
||||
|
||||
private WorldLoader.DataLoadContext supplier(WorldLoader.DataLoadContext old) {
|
||||
return dataLoadContext.aquire(() -> new WorldLoader.DataLoadContext(
|
||||
old.resources(),
|
||||
old.dataConfiguration(),
|
||||
old.datapackWorldgen(),
|
||||
createRegistryAccess(old.datapackDimensions(), false, true, true, true)
|
||||
));
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
private AutoClosing inject(Function<WorldLoader.DataLoadContext, WorldLoader.DataLoadContext> transformer) {
|
||||
if (!dataContextLock.tryLock()) throw new IllegalStateException("Failed to inject data context!");
|
||||
|
||||
var server = ((CraftServer) Bukkit.getServer());
|
||||
var field = getField(MinecraftServer.class, WorldLoader.DataLoadContext.class);
|
||||
var nmsServer = server.getServer();
|
||||
var old = nmsServer.worldLoader;
|
||||
|
||||
field.setAccessible(true);
|
||||
field.set(nmsServer, transformer.apply(old));
|
||||
|
||||
return new AutoClosing(() -> {
|
||||
field.set(nmsServer, old);
|
||||
dataContextLock.unlock();
|
||||
});
|
||||
}
|
||||
|
||||
private RegistryAccess.Frozen createRegistryAccess(RegistryAccess.Frozen datapack, boolean copy, boolean overworld, boolean nether, boolean end) {
|
||||
var access = registry();
|
||||
var dimensions = access.registryOrThrow(Registries.DIMENSION_TYPE);
|
||||
var levelStems = access.registryOrThrow(Registries.LEVEL_STEM);
|
||||
|
||||
var fake = new MappedRegistry<>(Registries.LEVEL_STEM, Lifecycle.experimental());
|
||||
if (overworld) register(fake, levelStems, dimensions, LevelStem.OVERWORLD);
|
||||
if (nether) register(fake, levelStems, dimensions, LevelStem.NETHER);
|
||||
if (end) register(fake, levelStems, dimensions, LevelStem.END);
|
||||
copy(fake, datapack.registry(Registries.LEVEL_STEM).orElse(null));
|
||||
|
||||
if (copy) copy(fake, levelStems);
|
||||
|
||||
return new RegistryAccess.Frozen.ImmutableRegistryAccess(List.of(fake.freeze())).freeze();
|
||||
}
|
||||
|
||||
private void register(MappedRegistry<LevelStem> target, Registry<LevelStem> levelStems, Registry<DimensionType> dimensions, ResourceKey<LevelStem> key) {
|
||||
target.register(key, new LevelStem(
|
||||
dimensions.getHolderOrThrow(ResourceKey.create(Registries.DIMENSION_TYPE, new ResourceLocation("iris", key.location().getPath()))),
|
||||
levelStems.getOrThrow(key).generator()
|
||||
), Lifecycle.stable());
|
||||
}
|
||||
|
||||
private void copy(MappedRegistry<LevelStem> target, Registry<LevelStem> source) {
|
||||
if (source == null) return;
|
||||
source.registryKeySet().forEach(key -> {
|
||||
var value = source.get(key);
|
||||
var info = source.lifecycle(value);
|
||||
if (value != null && info != null && !target.containsKey(key))
|
||||
target.register(key, value, info);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,12 +6,17 @@ import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
import java.util.function.Function;
|
||||
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
import com.mojang.serialization.Lifecycle;
|
||||
import com.volmit.iris.core.nms.container.AutoClosing;
|
||||
import com.volmit.iris.core.nms.container.BiomeColor;
|
||||
import com.volmit.iris.core.nms.datapack.DataVersion;
|
||||
import com.volmit.iris.util.nbt.tag.CompoundTag;
|
||||
import com.volmit.iris.util.scheduling.J;
|
||||
import lombok.SneakyThrows;
|
||||
import net.minecraft.core.*;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.core.component.DataComponents;
|
||||
@@ -25,6 +30,8 @@ import net.minecraft.nbt.LongTag;
|
||||
import net.minecraft.nbt.ShortTag;
|
||||
import net.minecraft.nbt.StringTag;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.WorldLoader;
|
||||
import net.minecraft.server.commands.data.BlockDataAccessor;
|
||||
import net.minecraft.server.commands.data.DataCommands;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
@@ -34,6 +41,8 @@ import net.minecraft.world.level.LevelReader;
|
||||
import net.minecraft.world.level.block.EntityBlock;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraft.world.level.chunk.status.ChunkStatus;
|
||||
import net.minecraft.world.level.dimension.DimensionType;
|
||||
import net.minecraft.world.level.dimension.LevelStem;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
@@ -86,9 +95,11 @@ public class NMSBinding implements INMSBinding {
|
||||
private final KMap<Biome, Object> baseBiomeCache = new KMap<>();
|
||||
private final BlockData AIR = Material.AIR.createBlockData();
|
||||
private final AtomicCache<MCAIdMap<net.minecraft.world.level.biome.Biome>> biomeMapCache = new AtomicCache<>();
|
||||
private final AtomicCache<WorldLoader.DataLoadContext> dataLoadContext = new AtomicCache<>();
|
||||
private final AtomicCache<MCAIdMapper<BlockState>> registryCache = new AtomicCache<>();
|
||||
private final AtomicCache<MCAPalette<BlockState>> globalCache = new AtomicCache<>();
|
||||
private final AtomicCache<RegistryAccess> registryAccess = new AtomicCache<>();
|
||||
private final ReentrantLock dataContextLock = new ReentrantLock(true);
|
||||
private final AtomicCache<Method> byIdRef = new AtomicCache<>();
|
||||
private Field biomeStorageCache = null;
|
||||
|
||||
@@ -216,7 +227,7 @@ public class NMSBinding implements INMSBinding {
|
||||
.newBlockEntity(blockPos, state);
|
||||
}
|
||||
var accessor = new BlockDataAccessor(blockEntity, blockPos);
|
||||
accessor.setData(tag.merge(accessor.getData()));
|
||||
accessor.setData(accessor.getData().merge(tag));
|
||||
}
|
||||
|
||||
private Tag convertToTag(Object object, int depth, int maxDepth) {
|
||||
@@ -544,6 +555,10 @@ public class NMSBinding implements INMSBinding {
|
||||
|
||||
public void inject(long seed, Engine engine, World world) {
|
||||
var chunkMap = ((CraftWorld)world).getHandle().getChunkSource().chunkMap;
|
||||
var dimensionType = chunkMap.level.dimensionTypeRegistration().unwrapKey().orElse(null);
|
||||
if (dimensionType != null && !dimensionType.location().getNamespace().equals("iris"))
|
||||
Iris.error("Loaded world %s with invalid dimension type! (%s)", world.getName(), dimensionType.location().toString());
|
||||
|
||||
chunkMap.generator = new IrisChunkGenerator(chunkMap.generator, seed, engine, world);
|
||||
}
|
||||
|
||||
@@ -650,4 +665,98 @@ public class NMSBinding implements INMSBinding {
|
||||
|
||||
return keys;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AutoClosing injectLevelStems() {
|
||||
return inject(this::supplier);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SneakyThrows
|
||||
public com.volmit.iris.core.nms.container.Pair<Integer, AutoClosing> injectUncached(boolean overworld, boolean nether, boolean end) {
|
||||
var reg = registry();
|
||||
var field = getField(RegistryAccess.ImmutableRegistryAccess.class, Map.class);
|
||||
field.setAccessible(true);
|
||||
|
||||
AutoClosing closing = inject(old -> new WorldLoader.DataLoadContext(
|
||||
old.resources(),
|
||||
old.dataConfiguration(),
|
||||
old.datapackWorldgen(),
|
||||
createRegistryAccess(old.datapackDimensions(), true, overworld, nether, end)
|
||||
)
|
||||
);
|
||||
|
||||
var injected = ((CraftServer) Bukkit.getServer()).getServer().worldLoader.datapackDimensions().registryOrThrow(Registries.LEVEL_STEM);
|
||||
var old = (Map<ResourceKey<? extends Registry<?>>, Registry<?>>) field.get(reg);
|
||||
var fake = new HashMap<>(old);
|
||||
fake.put(Registries.LEVEL_STEM, injected);
|
||||
field.set(reg, fake);
|
||||
|
||||
return new com.volmit.iris.core.nms.container.Pair<>(
|
||||
injected.size(),
|
||||
new AutoClosing(() -> {
|
||||
closing.close();
|
||||
field.set(reg, old);
|
||||
}));
|
||||
}
|
||||
|
||||
private WorldLoader.DataLoadContext supplier(WorldLoader.DataLoadContext old) {
|
||||
return dataLoadContext.aquire(() -> new WorldLoader.DataLoadContext(
|
||||
old.resources(),
|
||||
old.dataConfiguration(),
|
||||
old.datapackWorldgen(),
|
||||
createRegistryAccess(old.datapackDimensions(), false, true, true, true)
|
||||
));
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
private AutoClosing inject(Function<WorldLoader.DataLoadContext, WorldLoader.DataLoadContext> transformer) {
|
||||
if (!dataContextLock.tryLock()) throw new IllegalStateException("Failed to inject data context!");
|
||||
|
||||
var server = ((CraftServer) Bukkit.getServer());
|
||||
var field = getField(MinecraftServer.class, WorldLoader.DataLoadContext.class);
|
||||
var nmsServer = server.getServer();
|
||||
var old = nmsServer.worldLoader;
|
||||
|
||||
field.setAccessible(true);
|
||||
field.set(nmsServer, transformer.apply(old));
|
||||
|
||||
return new AutoClosing(() -> {
|
||||
field.set(nmsServer, old);
|
||||
dataContextLock.unlock();
|
||||
});
|
||||
}
|
||||
|
||||
private RegistryAccess.Frozen createRegistryAccess(RegistryAccess.Frozen datapack, boolean copy, boolean overworld, boolean nether, boolean end) {
|
||||
var access = registry();
|
||||
var dimensions = access.registryOrThrow(Registries.DIMENSION_TYPE);
|
||||
var levelStems = access.registryOrThrow(Registries.LEVEL_STEM);
|
||||
|
||||
var fake = new MappedRegistry<>(Registries.LEVEL_STEM, Lifecycle.experimental());
|
||||
if (overworld) register(fake, levelStems, dimensions, LevelStem.OVERWORLD);
|
||||
if (nether) register(fake, levelStems, dimensions, LevelStem.NETHER);
|
||||
if (end) register(fake, levelStems, dimensions, LevelStem.END);
|
||||
copy(fake, datapack.registry(Registries.LEVEL_STEM).orElse(null));
|
||||
|
||||
if (copy) copy(fake, levelStems);
|
||||
|
||||
return new RegistryAccess.Frozen.ImmutableRegistryAccess(List.of(fake.freeze())).freeze();
|
||||
}
|
||||
|
||||
private void register(MappedRegistry<LevelStem> target, Registry<LevelStem> levelStems, Registry<DimensionType> dimensions, ResourceKey<LevelStem> key) {
|
||||
target.register(key, new LevelStem(
|
||||
dimensions.getHolder(new ResourceLocation("iris", key.location().getPath())).orElseThrow(),
|
||||
levelStems.getOrThrow(key).generator()
|
||||
), RegistrationInfo.BUILT_IN);
|
||||
}
|
||||
|
||||
private void copy(MappedRegistry<LevelStem> target, Registry<LevelStem> source) {
|
||||
if (source == null) return;
|
||||
source.registryKeySet().forEach(key -> {
|
||||
var value = source.get(key);
|
||||
var info = source.registrationInfo(key).orElse(null);
|
||||
if (value != null && info != null && !target.containsKey(key))
|
||||
target.register(key, value, info);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,14 +10,23 @@ import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
import java.util.function.Function;
|
||||
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
import com.mojang.serialization.Lifecycle;
|
||||
import com.volmit.iris.core.nms.container.AutoClosing;
|
||||
import com.volmit.iris.core.nms.container.BiomeColor;
|
||||
import com.volmit.iris.core.nms.datapack.DataVersion;
|
||||
import com.volmit.iris.util.scheduling.J;
|
||||
import lombok.SneakyThrows;
|
||||
import net.minecraft.core.*;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.core.component.DataComponents;
|
||||
import net.minecraft.nbt.*;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.WorldLoader;
|
||||
import net.minecraft.server.commands.data.BlockDataAccessor;
|
||||
import net.minecraft.server.level.ChunkMap;
|
||||
import net.minecraft.tags.TagKey;
|
||||
@@ -26,6 +35,8 @@ import net.minecraft.world.level.LevelReader;
|
||||
import net.minecraft.world.level.block.EntityBlock;
|
||||
import net.minecraft.world.level.chunk.status.ChunkStatus;
|
||||
import net.minecraft.world.level.chunk.status.WorldGenContext;
|
||||
import net.minecraft.world.level.dimension.DimensionType;
|
||||
import net.minecraft.world.level.dimension.LevelStem;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
@@ -64,10 +75,6 @@ import com.volmit.iris.util.nbt.mca.palette.*;
|
||||
import com.volmit.iris.util.nbt.tag.CompoundTag;
|
||||
|
||||
import it.unimi.dsi.fastutil.objects.Object2IntMap;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.core.RegistryAccess;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
@@ -85,9 +92,11 @@ public class NMSBinding implements INMSBinding {
|
||||
private final KMap<Biome, Object> baseBiomeCache = new KMap<>();
|
||||
private final BlockData AIR = Material.AIR.createBlockData();
|
||||
private final AtomicCache<MCAIdMap<net.minecraft.world.level.biome.Biome>> biomeMapCache = new AtomicCache<>();
|
||||
private final AtomicCache<WorldLoader.DataLoadContext> dataLoadContext = new AtomicCache<>();
|
||||
private final AtomicCache<MCAIdMapper<BlockState>> registryCache = new AtomicCache<>();
|
||||
private final AtomicCache<MCAPalette<BlockState>> globalCache = new AtomicCache<>();
|
||||
private final AtomicCache<RegistryAccess> registryAccess = new AtomicCache<>();
|
||||
private final ReentrantLock dataContextLock = new ReentrantLock(true);
|
||||
private final AtomicCache<Method> byIdRef = new AtomicCache<>();
|
||||
private Field biomeStorageCache = null;
|
||||
|
||||
@@ -215,7 +224,7 @@ public class NMSBinding implements INMSBinding {
|
||||
.newBlockEntity(blockPos, state);
|
||||
}
|
||||
var accessor = new BlockDataAccessor(blockEntity, blockPos);
|
||||
accessor.setData(tag.merge(accessor.getData()));
|
||||
accessor.setData(accessor.getData().merge(tag));
|
||||
}
|
||||
|
||||
private Tag convertToTag(Object object, int depth, int maxDepth) {
|
||||
@@ -546,6 +555,9 @@ public class NMSBinding implements INMSBinding {
|
||||
var worldGenContextField = getField(chunkMap.getClass(), WorldGenContext.class);
|
||||
worldGenContextField.setAccessible(true);
|
||||
var worldGenContext = (WorldGenContext) worldGenContextField.get(chunkMap);
|
||||
var dimensionType = chunkMap.level.dimensionTypeRegistration().unwrapKey().orElse(null);
|
||||
if (dimensionType != null && !dimensionType.location().getNamespace().equals("iris"))
|
||||
Iris.error("Loaded world %s with invalid dimension type! (%s)", world.getName(), dimensionType.location().toString());
|
||||
|
||||
var newContext = new WorldGenContext(
|
||||
worldGenContext.level(), new IrisChunkGenerator(worldGenContext.generator(), seed, engine, world),
|
||||
@@ -657,4 +669,98 @@ public class NMSBinding implements INMSBinding {
|
||||
|
||||
return keys;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AutoClosing injectLevelStems() {
|
||||
return inject(this::supplier);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SneakyThrows
|
||||
public com.volmit.iris.core.nms.container.Pair<Integer, AutoClosing> injectUncached(boolean overworld, boolean nether, boolean end) {
|
||||
var reg = registry();
|
||||
var field = getField(RegistryAccess.ImmutableRegistryAccess.class, Map.class);
|
||||
field.setAccessible(true);
|
||||
|
||||
AutoClosing closing = inject(old -> new WorldLoader.DataLoadContext(
|
||||
old.resources(),
|
||||
old.dataConfiguration(),
|
||||
old.datapackWorldgen(),
|
||||
createRegistryAccess(old.datapackDimensions(), true, overworld, nether, end)
|
||||
)
|
||||
);
|
||||
|
||||
var injected = ((CraftServer) Bukkit.getServer()).getServer().worldLoader.datapackDimensions().registryOrThrow(Registries.LEVEL_STEM);
|
||||
var old = (Map<ResourceKey<? extends Registry<?>>, Registry<?>>) field.get(reg);
|
||||
var fake = new HashMap<>(old);
|
||||
fake.put(Registries.LEVEL_STEM, injected);
|
||||
field.set(reg, fake);
|
||||
|
||||
return new com.volmit.iris.core.nms.container.Pair<>(
|
||||
injected.size(),
|
||||
new AutoClosing(() -> {
|
||||
closing.close();
|
||||
field.set(reg, old);
|
||||
}));
|
||||
}
|
||||
|
||||
private WorldLoader.DataLoadContext supplier(WorldLoader.DataLoadContext old) {
|
||||
return dataLoadContext.aquire(() -> new WorldLoader.DataLoadContext(
|
||||
old.resources(),
|
||||
old.dataConfiguration(),
|
||||
old.datapackWorldgen(),
|
||||
createRegistryAccess(old.datapackDimensions(), false, true, true, true)
|
||||
));
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
private AutoClosing inject(Function<WorldLoader.DataLoadContext, WorldLoader.DataLoadContext> transformer) {
|
||||
if (!dataContextLock.tryLock()) throw new IllegalStateException("Failed to inject data context!");
|
||||
|
||||
var server = ((CraftServer) Bukkit.getServer());
|
||||
var field = getField(MinecraftServer.class, WorldLoader.DataLoadContext.class);
|
||||
var nmsServer = server.getServer();
|
||||
var old = nmsServer.worldLoader;
|
||||
|
||||
field.setAccessible(true);
|
||||
field.set(nmsServer, transformer.apply(old));
|
||||
|
||||
return new AutoClosing(() -> {
|
||||
field.set(nmsServer, old);
|
||||
dataContextLock.unlock();
|
||||
});
|
||||
}
|
||||
|
||||
private RegistryAccess.Frozen createRegistryAccess(RegistryAccess.Frozen datapack, boolean copy, boolean overworld, boolean nether, boolean end) {
|
||||
var access = registry();
|
||||
var dimensions = access.registryOrThrow(Registries.DIMENSION_TYPE);
|
||||
var levelStems = access.registryOrThrow(Registries.LEVEL_STEM);
|
||||
|
||||
var fake = new MappedRegistry<>(Registries.LEVEL_STEM, Lifecycle.experimental());
|
||||
if (overworld) register(fake, levelStems, dimensions, LevelStem.OVERWORLD);
|
||||
if (nether) register(fake, levelStems, dimensions, LevelStem.NETHER);
|
||||
if (end) register(fake, levelStems, dimensions, LevelStem.END);
|
||||
copy(fake, datapack.registry(Registries.LEVEL_STEM).orElse(null));
|
||||
|
||||
if (copy) copy(fake, levelStems);
|
||||
|
||||
return new RegistryAccess.Frozen.ImmutableRegistryAccess(List.of(fake.freeze())).freeze();
|
||||
}
|
||||
|
||||
private void register(MappedRegistry<LevelStem> target, Registry<LevelStem> levelStems, Registry<DimensionType> dimensions, ResourceKey<LevelStem> key) {
|
||||
target.register(key, new LevelStem(
|
||||
dimensions.getHolder(ResourceLocation.fromNamespaceAndPath("iris", key.location().getPath())).orElseThrow(),
|
||||
levelStems.getOrThrow(key).generator()
|
||||
), RegistrationInfo.BUILT_IN);
|
||||
}
|
||||
|
||||
private void copy(MappedRegistry<LevelStem> target, Registry<LevelStem> source) {
|
||||
if (source == null) return;
|
||||
source.registryKeySet().forEach(key -> {
|
||||
var value = source.get(key);
|
||||
var info = source.registrationInfo(key).orElse(null);
|
||||
if (value != null && info != null && !target.containsKey(key))
|
||||
target.register(key, value, info);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,15 +6,23 @@ import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
import java.util.function.Function;
|
||||
|
||||
import com.mojang.serialization.Lifecycle;
|
||||
import com.volmit.iris.core.nms.container.AutoClosing;
|
||||
import com.volmit.iris.core.nms.container.BiomeColor;
|
||||
import com.volmit.iris.core.nms.container.Pair;
|
||||
import com.volmit.iris.core.nms.datapack.DataVersion;
|
||||
import com.volmit.iris.util.scheduling.J;
|
||||
import lombok.SneakyThrows;
|
||||
import net.minecraft.core.*;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.core.component.DataComponents;
|
||||
import net.minecraft.nbt.*;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.WorldLoader;
|
||||
import net.minecraft.server.commands.data.BlockDataAccessor;
|
||||
import net.minecraft.tags.TagKey;
|
||||
import net.minecraft.world.item.component.CustomData;
|
||||
@@ -22,6 +30,8 @@ import net.minecraft.world.level.LevelReader;
|
||||
import net.minecraft.world.level.block.EntityBlock;
|
||||
import net.minecraft.world.level.chunk.status.ChunkStatus;
|
||||
import net.minecraft.world.level.chunk.status.WorldGenContext;
|
||||
import net.minecraft.world.level.dimension.DimensionType;
|
||||
import net.minecraft.world.level.dimension.LevelStem;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
@@ -72,9 +82,11 @@ public class NMSBinding implements INMSBinding {
|
||||
private final KMap<Biome, Object> baseBiomeCache = new KMap<>();
|
||||
private final BlockData AIR = Material.AIR.createBlockData();
|
||||
private final AtomicCache<MCAIdMap<net.minecraft.world.level.biome.Biome>> biomeMapCache = new AtomicCache<>();
|
||||
private final AtomicCache<WorldLoader.DataLoadContext> dataLoadContext = new AtomicCache<>();
|
||||
private final AtomicCache<MCAIdMapper<BlockState>> registryCache = new AtomicCache<>();
|
||||
private final AtomicCache<MCAPalette<BlockState>> globalCache = new AtomicCache<>();
|
||||
private final AtomicCache<RegistryAccess> registryAccess = new AtomicCache<>();
|
||||
private final ReentrantLock dataContextLock = new ReentrantLock(true);
|
||||
private final AtomicCache<Method> byIdRef = new AtomicCache<>();
|
||||
private Field biomeStorageCache = null;
|
||||
|
||||
@@ -202,7 +214,7 @@ public class NMSBinding implements INMSBinding {
|
||||
.newBlockEntity(blockPos, state);
|
||||
}
|
||||
var accessor = new BlockDataAccessor(blockEntity, blockPos);
|
||||
accessor.setData(tag.merge(accessor.getData()));
|
||||
accessor.setData(accessor.getData().merge(tag));
|
||||
}
|
||||
|
||||
private Tag convertToTag(Object object, int depth, int maxDepth) {
|
||||
@@ -533,6 +545,9 @@ public class NMSBinding implements INMSBinding {
|
||||
var worldGenContextField = getField(chunkMap.getClass(), WorldGenContext.class);
|
||||
worldGenContextField.setAccessible(true);
|
||||
var worldGenContext = (WorldGenContext) worldGenContextField.get(chunkMap);
|
||||
var dimensionType = chunkMap.level.dimensionTypeRegistration().unwrapKey().orElse(null);
|
||||
if (dimensionType != null && !dimensionType.location().getNamespace().equals("iris"))
|
||||
Iris.error("Loaded world %s with invalid dimension type! (%s)", world.getName(), dimensionType.location().toString());
|
||||
|
||||
var newContext = new WorldGenContext(
|
||||
worldGenContext.level(), new IrisChunkGenerator(worldGenContext.generator(), seed, engine, world),
|
||||
@@ -644,4 +659,98 @@ public class NMSBinding implements INMSBinding {
|
||||
|
||||
return keys;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AutoClosing injectLevelStems() {
|
||||
return inject(this::supplier);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SneakyThrows
|
||||
public Pair<Integer, AutoClosing> injectUncached(boolean overworld, boolean nether, boolean end) {
|
||||
var reg = registry();
|
||||
var field = getField(RegistryAccess.ImmutableRegistryAccess.class, Map.class);
|
||||
field.setAccessible(true);
|
||||
|
||||
AutoClosing closing = inject(old -> new WorldLoader.DataLoadContext(
|
||||
old.resources(),
|
||||
old.dataConfiguration(),
|
||||
old.datapackWorldgen(),
|
||||
createRegistryAccess(old.datapackDimensions(), true, overworld, nether, end)
|
||||
)
|
||||
);
|
||||
|
||||
var injected = ((CraftServer) Bukkit.getServer()).getServer().worldLoader.datapackDimensions().lookupOrThrow(Registries.LEVEL_STEM);
|
||||
var old = (Map<ResourceKey<? extends Registry<?>>, Registry<?>>) field.get(reg);
|
||||
var fake = new HashMap<>(old);
|
||||
fake.put(Registries.LEVEL_STEM, injected);
|
||||
field.set(reg, fake);
|
||||
|
||||
return new Pair<>(
|
||||
injected.size(),
|
||||
new AutoClosing(() -> {
|
||||
closing.close();
|
||||
field.set(reg, old);
|
||||
}));
|
||||
}
|
||||
|
||||
private WorldLoader.DataLoadContext supplier(WorldLoader.DataLoadContext old) {
|
||||
return dataLoadContext.aquire(() -> new WorldLoader.DataLoadContext(
|
||||
old.resources(),
|
||||
old.dataConfiguration(),
|
||||
old.datapackWorldgen(),
|
||||
createRegistryAccess(old.datapackDimensions(), false, true, true, true)
|
||||
));
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
private AutoClosing inject(Function<WorldLoader.DataLoadContext, WorldLoader.DataLoadContext> transformer) {
|
||||
if (!dataContextLock.tryLock()) throw new IllegalStateException("Failed to inject data context!");
|
||||
|
||||
var server = ((CraftServer) Bukkit.getServer());
|
||||
var field = getField(MinecraftServer.class, WorldLoader.DataLoadContext.class);
|
||||
var nmsServer = server.getServer();
|
||||
var old = nmsServer.worldLoader;
|
||||
|
||||
field.setAccessible(true);
|
||||
field.set(nmsServer, transformer.apply(old));
|
||||
|
||||
return new AutoClosing(() -> {
|
||||
field.set(nmsServer, old);
|
||||
dataContextLock.unlock();
|
||||
});
|
||||
}
|
||||
|
||||
private RegistryAccess.Frozen createRegistryAccess(RegistryAccess.Frozen datapack, boolean copy, boolean overworld, boolean nether, boolean end) {
|
||||
var access = registry();
|
||||
var dimensions = access.lookupOrThrow(Registries.DIMENSION_TYPE);
|
||||
var levelStems = access.lookupOrThrow(Registries.LEVEL_STEM);
|
||||
|
||||
var fake = new MappedRegistry<>(Registries.LEVEL_STEM, Lifecycle.experimental());
|
||||
if (overworld) register(fake, levelStems, dimensions, LevelStem.OVERWORLD);
|
||||
if (nether) register(fake, levelStems, dimensions, LevelStem.NETHER);
|
||||
if (end) register(fake, levelStems, dimensions, LevelStem.END);
|
||||
copy(fake, datapack.lookup(Registries.LEVEL_STEM).orElse(null));
|
||||
|
||||
if (copy) copy(fake, levelStems);
|
||||
|
||||
return new RegistryAccess.Frozen.ImmutableRegistryAccess(List.of(fake.freeze())).freeze();
|
||||
}
|
||||
|
||||
private void register(MappedRegistry<LevelStem> target, Registry<LevelStem> levelStems, Registry<DimensionType> dimensions, ResourceKey<LevelStem> key) {
|
||||
target.register(key, new LevelStem(
|
||||
dimensions.get(ResourceLocation.fromNamespaceAndPath("iris", key.location().getPath())).orElseThrow(),
|
||||
levelStems.getValueOrThrow(key).generator()
|
||||
), RegistrationInfo.BUILT_IN);
|
||||
}
|
||||
|
||||
private void copy(MappedRegistry<LevelStem> target, Registry<LevelStem> source) {
|
||||
if (source == null) return;
|
||||
source.listElementIds().forEach(key -> {
|
||||
var value = source.getValue(key);
|
||||
var info = source.registrationInfo(key).orElse(null);
|
||||
if (value != null && info != null && !target.containsKey(key))
|
||||
target.register(key, value, info);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.volmit.iris.core.nms.v1_19_R3;
|
||||
package com.volmit.iris.core.nms.v1_21_R3;
|
||||
|
||||
import com.mojang.serialization.Codec;
|
||||
import com.mojang.serialization.MapCodec;
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.engine.data.cache.AtomicCache;
|
||||
import com.volmit.iris.engine.framework.Engine;
|
||||
@@ -19,9 +19,9 @@ import net.minecraft.world.level.biome.BiomeSource;
|
||||
import net.minecraft.world.level.biome.Climate;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.craftbukkit.v1_19_R3.CraftServer;
|
||||
import org.bukkit.craftbukkit.v1_19_R3.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_19_R3.block.CraftBlock;
|
||||
import org.bukkit.craftbukkit.v1_21_R3.CraftServer;
|
||||
import org.bukkit.craftbukkit.v1_21_R3.CraftWorld;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
@@ -42,8 +42,8 @@ public class CustomBiomeSource extends BiomeSource {
|
||||
public CustomBiomeSource(long seed, Engine engine, World world) {
|
||||
this.engine = engine;
|
||||
this.seed = seed;
|
||||
this.biomeCustomRegistry = registry().registry(Registries.BIOME).orElse(null);
|
||||
this.biomeRegistry = ((RegistryAccess) getFor(RegistryAccess.Frozen.class, ((CraftServer) Bukkit.getServer()).getHandle().getServer())).registry(Registries.BIOME).orElse(null);
|
||||
this.biomeCustomRegistry = registry().lookup(Registries.BIOME).orElse(null);
|
||||
this.biomeRegistry = ((RegistryAccess) getFor(RegistryAccess.Frozen.class, ((CraftServer) Bukkit.getServer()).getHandle().getServer())).lookup(Registries.BIOME).orElse(null);
|
||||
this.rng = new RNG(engine.getSeedManager().getBiome());
|
||||
this.customBiomes = fillCustomBiomes(biomeCustomRegistry, engine);
|
||||
}
|
||||
@@ -54,11 +54,11 @@ public class CustomBiomeSource extends BiomeSource {
|
||||
for (IrisBiome i : engine.getAllBiomes()) {
|
||||
if (i.isCustom()) {
|
||||
for (IrisBiomeCustom j : i.getCustomDerivitives()) {
|
||||
b.add(customRegistry.getHolder(customRegistry.getResourceKey(customRegistry
|
||||
.get(new ResourceLocation(engine.getDimension().getLoadKey() + ":" + j.getId()))).get()).get());
|
||||
b.add(customRegistry.get(customRegistry.getResourceKey(customRegistry
|
||||
.getValue(ResourceLocation.fromNamespaceAndPath(engine.getDimension().getLoadKey(), j.getId()))).get()).get());
|
||||
}
|
||||
} else {
|
||||
b.add(CraftBlock.biomeToBiomeBase(registry, i.getVanillaDerivative()));
|
||||
b.add(NMSBinding.biomeToBiomeBase(registry, i.getVanillaDerivative()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,8 +115,8 @@ public class CustomBiomeSource extends BiomeSource {
|
||||
protected Stream<Holder<Biome>> collectPossibleBiomes() {
|
||||
return getAllBiomes(
|
||||
((RegistryAccess) getFor(RegistryAccess.Frozen.class, ((CraftServer) Bukkit.getServer()).getHandle().getServer()))
|
||||
.registry(Registries.BIOME).orElse(null),
|
||||
((CraftWorld) engine.getWorld().realWorld()).getHandle().registryAccess().registry(Registries.BIOME).orElse(null),
|
||||
.lookup(Registries.BIOME).orElse(null),
|
||||
((CraftWorld) engine.getWorld().realWorld()).getHandle().registryAccess().lookup(Registries.BIOME).orElse(null),
|
||||
engine).stream();
|
||||
}
|
||||
private KMap<String, Holder<Biome>> fillCustomBiomes(Registry<Biome> customRegistry, Engine engine) {
|
||||
@@ -125,15 +125,15 @@ public class CustomBiomeSource extends BiomeSource {
|
||||
for (IrisBiome i : engine.getAllBiomes()) {
|
||||
if (i.isCustom()) {
|
||||
for (IrisBiomeCustom j : i.getCustomDerivitives()) {
|
||||
ResourceLocation resourceLocation = new ResourceLocation(engine.getDimension().getLoadKey() + ":" + j.getId());
|
||||
Biome biome = customRegistry.get(resourceLocation);
|
||||
ResourceLocation resourceLocation = ResourceLocation.fromNamespaceAndPath(engine.getDimension().getLoadKey(), j.getId());
|
||||
Biome biome = customRegistry.getValue(resourceLocation);
|
||||
Optional<ResourceKey<Biome>> optionalBiomeKey = customRegistry.getResourceKey(biome);
|
||||
if (optionalBiomeKey.isEmpty()) {
|
||||
Iris.error("Cannot find biome for IrisBiomeCustom " + j.getId() + " from engine " + engine.getName());
|
||||
continue;
|
||||
}
|
||||
ResourceKey<Biome> biomeKey = optionalBiomeKey.get();
|
||||
Optional<Holder.Reference<Biome>> optionalReferenceHolder = customRegistry.getHolder(biomeKey);
|
||||
Optional<Holder.Reference<Biome>> optionalReferenceHolder = customRegistry.get(biomeKey);
|
||||
if (optionalReferenceHolder.isEmpty()) {
|
||||
Iris.error("Cannot find reference to biome " + biomeKey + " for engine " + engine.getName());
|
||||
continue;
|
||||
@@ -151,7 +151,7 @@ public class CustomBiomeSource extends BiomeSource {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Codec<? extends BiomeSource> codec() {
|
||||
protected MapCodec<? extends BiomeSource> codec() {
|
||||
throw new UnsupportedOperationException("Not supported");
|
||||
}
|
||||
|
||||
@@ -163,7 +163,7 @@ public class CustomBiomeSource extends BiomeSource {
|
||||
return customBiomes.get(ib.getCustomBiome(rng, x << 2, m, z << 2).getId());
|
||||
} else {
|
||||
org.bukkit.block.Biome v = ib.getSkyBiome(rng, x << 2, m, z << 2);
|
||||
return CraftBlock.biomeToBiomeBase(biomeRegistry, v);
|
||||
return NMSBinding.biomeToBiomeBase(biomeRegistry, v);
|
||||
}
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user