mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-19 02:36:59 +00:00
Merge remote-tracking branch 'upstream/master' into DecreeCommands
This commit is contained in:
commit
8547ea4c6a
20
.github/workflows/gradlebuild.yml
vendored
20
.github/workflows/gradlebuild.yml
vendored
@ -12,14 +12,14 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: set up JDK 16
|
||||
uses: actions/setup-java@v2
|
||||
with:
|
||||
java-version: '16'
|
||||
distribution: 'adopt'
|
||||
- uses: actions/checkout@v2
|
||||
- name: set up JDK 16
|
||||
uses: actions/setup-java@v2
|
||||
with:
|
||||
java-version: '16'
|
||||
distribution: 'adopt'
|
||||
|
||||
- name: Grant execute permission for gradlew
|
||||
run: chmod +x gradlew
|
||||
- name: Build with Gradle
|
||||
run: ./gradlew build
|
||||
- name: Grant execute permission for gradlew
|
||||
run: chmod +x gradlew
|
||||
- name: Build with Gradle
|
||||
run: ./gradlew build
|
||||
|
31
build.gradle
31
build.gradle
@ -91,10 +91,10 @@ file(jar.archiveFile.get().getAsFile().getParentFile().getParentFile().getParent
|
||||
processResources {
|
||||
filesMatching('**/plugin.yml') {
|
||||
expand(
|
||||
'name': name.toString(),
|
||||
'version': version.toString(),
|
||||
'main': main.toString(),
|
||||
'apiversion': apiVersion.toString()
|
||||
'name': name.toString(),
|
||||
'version': version.toString(),
|
||||
'main': main.toString(),
|
||||
'apiversion': apiVersion.toString()
|
||||
)
|
||||
}
|
||||
}
|
||||
@ -158,17 +158,17 @@ compileJava {
|
||||
}
|
||||
|
||||
shadowJar
|
||||
{
|
||||
minimize()
|
||||
append("plugin.yml")
|
||||
relocate 'com.dfsek.paralithic', 'com.volmit.iris.util.paralithic'
|
||||
relocate 'io.papermc.lib', 'com.volmit.iris.util.paper'
|
||||
dependencies {
|
||||
include(dependency('io.papermc:paperlib'))
|
||||
include(dependency('com.dfsek:Paralithic'))
|
||||
include(dependency('net.kyori:'))
|
||||
}
|
||||
}
|
||||
{
|
||||
minimize()
|
||||
append("plugin.yml")
|
||||
relocate 'com.dfsek.paralithic', 'com.volmit.iris.util.paralithic'
|
||||
relocate 'io.papermc.lib', 'com.volmit.iris.util.paper'
|
||||
dependencies {
|
||||
include(dependency('io.papermc:paperlib'))
|
||||
include(dependency('com.dfsek:Paralithic'))
|
||||
include(dependency('net.kyori:'))
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
// Provided or Classpath
|
||||
@ -197,4 +197,5 @@ dependencies {
|
||||
implementation 'bsf:bsf:2.4.0'
|
||||
implementation 'rhino:js:1.7R2'
|
||||
implementation 'com.github.ben-manes.caffeine:caffeine:3.0.3'
|
||||
implementation 'org.apache.commons:commons-lang3:3.12.0'
|
||||
}
|
||||
|
@ -31,7 +31,6 @@ import com.volmit.iris.core.project.loader.IrisData;
|
||||
import com.volmit.iris.core.service.StudioSVC;
|
||||
import com.volmit.iris.engine.object.biome.IrisBiome;
|
||||
import com.volmit.iris.engine.object.biome.IrisBiomeCustom;
|
||||
import com.volmit.iris.engine.object.block.IrisBlockData;
|
||||
import com.volmit.iris.engine.object.common.IrisWorld;
|
||||
import com.volmit.iris.engine.object.compat.IrisCompat;
|
||||
import com.volmit.iris.engine.object.dimensional.IrisDimension;
|
||||
@ -49,28 +48,38 @@ import com.volmit.iris.util.io.InstanceState;
|
||||
import com.volmit.iris.util.io.JarScanner;
|
||||
import com.volmit.iris.util.math.M;
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
import com.volmit.iris.util.nbt.mca.*;
|
||||
import com.volmit.iris.util.parallel.MultiBurst;
|
||||
import com.volmit.iris.util.plugin.*;
|
||||
import com.volmit.iris.util.reflect.ShadeFix;
|
||||
import com.volmit.iris.util.scheduling.*;
|
||||
import com.volmit.iris.util.scheduling.J;
|
||||
import com.volmit.iris.util.scheduling.Looper;
|
||||
import com.volmit.iris.util.scheduling.Queue;
|
||||
import com.volmit.iris.util.scheduling.ShurikenQueue;
|
||||
import io.papermc.lib.PaperLib;
|
||||
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
||||
import net.kyori.adventure.text.serializer.ComponentSerializer;
|
||||
import net.minecraft.world.level.chunk.storage.RegionFile;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockDamageEvent;
|
||||
import org.bukkit.generator.ChunkGenerator;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.checkerframework.checker.units.qual.K;
|
||||
|
||||
import java.io.*;
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.net.URL;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@SuppressWarnings("CanBeFinal")
|
||||
public class Iris extends VolmitPlugin implements Listener {
|
||||
@ -117,6 +126,128 @@ public class Iris extends VolmitPlugin implements Listener {
|
||||
}).start();
|
||||
}
|
||||
|
||||
private void testmca() {
|
||||
try
|
||||
{
|
||||
int forceBits = 6;
|
||||
int possibilities = (int) (Math.pow(2, forceBits) - 1);
|
||||
KList<BlockData> bp = new KList<>();
|
||||
Set<BlockData> bf = new KSet<>();
|
||||
|
||||
while(bp.size() < possibilities)
|
||||
{
|
||||
BlockData b = null;
|
||||
|
||||
while(b == null)
|
||||
{
|
||||
try
|
||||
{
|
||||
b = Material.values()[RNG.r.i(Material.values().length-1)].createBlockData();
|
||||
}
|
||||
|
||||
catch(Throwable e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
bp.addIfMissing(b);
|
||||
}
|
||||
|
||||
MCAFile file = new MCAFile(0, 0);
|
||||
for(int cx = 0; cx < 32; cx++)
|
||||
{
|
||||
for(int cz = 0; cz < 32; cz++)
|
||||
{
|
||||
Chunk c = Chunk.newChunk();
|
||||
|
||||
for(int i = 0; i < 16; i++)
|
||||
{
|
||||
for(int j = 0; j < 16; j++)
|
||||
{
|
||||
for(int k = 0; k < 16; k++)
|
||||
{
|
||||
BlockData b = bp.getRandom();
|
||||
c.setBlockStateAt(i,j,k, NBTWorld.getCompound(b), false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
file.setChunk(cx, cz, c);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
File f = new File("r.0.0.mca");
|
||||
Iris.info("Write " + MCAUtil.write(file, f) + " chunks");
|
||||
file = MCAUtil.read(f);
|
||||
|
||||
for(int i = 0; i < 1024; i++) {
|
||||
Chunk c = file.getChunks().get(i);
|
||||
|
||||
if (c == null) {
|
||||
Iris.error("Missing Chunk: " + i);
|
||||
continue;
|
||||
}
|
||||
|
||||
Section s = c.getSection(0);
|
||||
|
||||
if (s == null)
|
||||
{
|
||||
Iris.error("Missing section 0 in chunk: " + i);
|
||||
continue;
|
||||
}
|
||||
|
||||
for(int a = 0; a < 16; a++)
|
||||
{
|
||||
for(int b = 0; b < 16; b++)
|
||||
{
|
||||
for(int ca = 0; ca < 16; ca++)
|
||||
{
|
||||
BlockData data = NBTWorld.getBlockData(s.getBlockStateAt(a, b, ca));
|
||||
bf.add(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Iris.info("Read .. OK?");
|
||||
|
||||
Iris.info("Possibilities: " + bp.size());
|
||||
Iris.info("Read Possibss: " + bf.size());
|
||||
int match = 0;
|
||||
for(BlockData i : bp)
|
||||
{
|
||||
if(bf.contains(i))
|
||||
{
|
||||
match++;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
Iris.warn("Couldn't find preset " + i.getAsString(true) + " in any section");
|
||||
}
|
||||
}
|
||||
|
||||
for(BlockData i : bf)
|
||||
{
|
||||
if(!bp.contains(i))
|
||||
{
|
||||
Iris.warn("Forign block data " + i.getAsString(true) + "! (ignore leaves, they are modded by us)");
|
||||
}
|
||||
}
|
||||
Iris.info("Matched: " + match);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
catch(Throwable ee)
|
||||
{
|
||||
ee.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private void enable() {
|
||||
audiences = BukkitAudiences.create(this);
|
||||
@ -130,10 +261,10 @@ public class Iris extends VolmitPlugin implements Listener {
|
||||
configWatcher = new FileWatcher(getDataFile("settings.json"));
|
||||
services.values().forEach(IrisService::onEnable);
|
||||
services.values().forEach(this::registerListener);
|
||||
J.s(this::testmca, 20);
|
||||
}
|
||||
|
||||
public void postShutdown(Runnable r)
|
||||
{
|
||||
public void postShutdown(Runnable r) {
|
||||
postShutdown.add(r);
|
||||
}
|
||||
|
||||
@ -437,18 +568,12 @@ public class Iris extends VolmitPlugin implements Listener {
|
||||
|
||||
@Override
|
||||
public ChunkGenerator getDefaultWorldGenerator(String worldName, String id) {
|
||||
if(worldName.equals("test"))
|
||||
{
|
||||
try
|
||||
{
|
||||
if (worldName.equals("test")) {
|
||||
try {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
|
||||
catch(Throwable e)
|
||||
{
|
||||
} catch (Throwable e) {
|
||||
Iris.info(e.getStackTrace()[1].getClassName());
|
||||
if(e.getStackTrace()[1].getClassName().contains("com.onarandombox.MultiverseCore"))
|
||||
{
|
||||
if (e.getStackTrace()[1].getClassName().contains("com.onarandombox.MultiverseCore")) {
|
||||
Iris.debug("MVC Test detected, Quick! Send them the dummy!");
|
||||
return new DummyChunkGenerator();
|
||||
}
|
||||
@ -490,8 +615,7 @@ public class Iris extends VolmitPlugin implements Listener {
|
||||
Iris.debug("Generator Config: " + w.toString());
|
||||
|
||||
File ff = new File(w.worldFolder(), "iris/pack");
|
||||
if(!ff.exists() || ff.listFiles().length == 0)
|
||||
{
|
||||
if (!ff.exists() || ff.listFiles().length == 0) {
|
||||
ff.mkdirs();
|
||||
service(StudioSVC.class).installIntoWorld(sender, dim.getLoadKey(), ff.getParentFile());
|
||||
}
|
||||
@ -736,21 +860,17 @@ public class Iris extends VolmitPlugin implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
public static void dump()
|
||||
{
|
||||
try
|
||||
{
|
||||
public static void dump() {
|
||||
try {
|
||||
File fi = Iris.instance.getDataFile("dump", "td-" + new java.sql.Date(M.ms()) + ".txt");
|
||||
FileOutputStream fos = new FileOutputStream(fi );
|
||||
FileOutputStream fos = new FileOutputStream(fi);
|
||||
Map<Thread, StackTraceElement[]> f = Thread.getAllStackTraces();
|
||||
PrintWriter pw = new PrintWriter(fos);
|
||||
for(Thread i : f.keySet())
|
||||
{
|
||||
for (Thread i : f.keySet()) {
|
||||
pw.println("========================================");
|
||||
pw.println("Thread: '" + i.getName() + "' ID: " + i.getId() + " STATUS: " + i.getState().name());
|
||||
|
||||
for(StackTraceElement j : f.get(i))
|
||||
{
|
||||
for (StackTraceElement j : f.get(i)) {
|
||||
pw.println(" @ " + j.toString());
|
||||
}
|
||||
|
||||
@ -761,10 +881,7 @@ public class Iris extends VolmitPlugin implements Listener {
|
||||
|
||||
pw.close();
|
||||
System.out.println("DUMPED! See " + fi.getAbsolutePath());
|
||||
}
|
||||
|
||||
catch(Throwable e)
|
||||
{
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
@ -20,12 +20,9 @@ package com.volmit.iris.core;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.engine.object.basic.IrisRange;
|
||||
import com.volmit.iris.util.collection.KSet;
|
||||
import com.volmit.iris.util.io.IO;
|
||||
import com.volmit.iris.util.json.JSONException;
|
||||
import com.volmit.iris.util.json.JSONObject;
|
||||
import com.volmit.iris.util.scheduling.J;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.File;
|
||||
@ -57,8 +54,7 @@ public class IrisSettings {
|
||||
return getParallax().getParallaxRegionEvictionMS();
|
||||
}
|
||||
|
||||
public static int getPriority(int c)
|
||||
{
|
||||
public static int getPriority(int c) {
|
||||
return Math.max(Math.min(c, Thread.MAX_PRIORITY), Thread.MIN_PRIORITY);
|
||||
}
|
||||
|
||||
|
@ -21,23 +21,13 @@ package com.volmit.iris.core.command.object;
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.core.IrisSettings;
|
||||
import com.volmit.iris.core.project.loader.IrisData;
|
||||
import com.volmit.iris.core.service.StudioSVC;
|
||||
import com.volmit.iris.core.tools.IrisToolbelt;
|
||||
import com.volmit.iris.engine.object.objects.IrisObject;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.plugin.MortarCommand;
|
||||
import com.volmit.iris.util.plugin.VolmitSender;
|
||||
import com.volmit.iris.util.scheduling.J;
|
||||
import com.volmit.iris.util.scheduling.Queue;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.text.NumberFormat;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class CommandIrisObjectAnalyze extends MortarCommand {
|
||||
|
||||
public CommandIrisObjectAnalyze() {
|
||||
|
@ -21,13 +21,10 @@ package com.volmit.iris.core.command.studio;
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.core.IrisSettings;
|
||||
import com.volmit.iris.core.project.IrisProject;
|
||||
import com.volmit.iris.core.service.ConversionSVC;
|
||||
import com.volmit.iris.core.service.StudioSVC;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.plugin.MortarCommand;
|
||||
import com.volmit.iris.util.plugin.VolmitSender;
|
||||
import com.volmit.iris.util.scheduling.jobs.Job;
|
||||
import com.volmit.iris.util.scheduling.jobs.JobCollection;
|
||||
|
||||
public class CommandIrisStudioCompile extends MortarCommand {
|
||||
public CommandIrisStudioCompile() {
|
||||
@ -49,8 +46,7 @@ public class CommandIrisStudioCompile extends MortarCommand {
|
||||
return true;
|
||||
}
|
||||
|
||||
if(args.length == 0)
|
||||
{
|
||||
if (args.length == 0) {
|
||||
sender.sendMessage(getArgsUsage());
|
||||
return true;
|
||||
}
|
||||
|
@ -31,14 +31,8 @@ import com.volmit.iris.util.decree.annotations.Param;
|
||||
import com.volmit.iris.util.decree.exceptions.DecreeParsingException;
|
||||
import com.volmit.iris.util.decree.exceptions.DecreeWhichException;
|
||||
import com.volmit.iris.util.format.C;
|
||||
import com.volmit.iris.util.math.M;
|
||||
import lombok.val;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.PrintWriter;
|
||||
import java.sql.Date;
|
||||
import java.util.Map;
|
||||
|
||||
@Decree(name = "irisd", aliases = {"ird"}, description = "Basic Command")
|
||||
public class DecIris implements DecreeExecutor {
|
||||
@ -126,7 +120,8 @@ public class DecIris implements DecreeExecutor {
|
||||
case "%" -> v = value1 % value2;
|
||||
case ">>" -> v = value1 >> value2;
|
||||
case "<<" -> v = value1 << value2;
|
||||
};
|
||||
}
|
||||
;
|
||||
if (v == null) {
|
||||
sender().sendMessage(C.RED + "The operator you entered: (" + operator + ") is invalid!");
|
||||
return;
|
||||
|
@ -115,8 +115,8 @@ public class DecObject implements DecreeExecutor {
|
||||
@Decree(description = "Contract a selection based on your looking direction", aliases = "-")
|
||||
public void contract(
|
||||
@Param(description = "The amount to inset by", defaultValue = "1")
|
||||
int amount
|
||||
){
|
||||
int amount
|
||||
) {
|
||||
if (!WandSVC.isHoldingWand(player())) {
|
||||
sender().sendMessage("Hold your wand.");
|
||||
return;
|
||||
@ -140,8 +140,8 @@ public class DecObject implements DecreeExecutor {
|
||||
@Decree(description = "Set point 1 to look", aliases = "p1")
|
||||
public void position1(
|
||||
@Param(description = "Whether to use your current position, or where you look", defaultValue = "true")
|
||||
boolean here
|
||||
){
|
||||
boolean here
|
||||
) {
|
||||
if (!WandSVC.isHoldingWand(player())) {
|
||||
sender().sendMessage("Ready your Wand.");
|
||||
return;
|
||||
@ -166,7 +166,7 @@ public class DecObject implements DecreeExecutor {
|
||||
public void position2(
|
||||
@Param(description = "Whether to use your current position, or where you look", defaultValue = "true")
|
||||
boolean here
|
||||
){
|
||||
) {
|
||||
if (!WandSVC.isHoldingWand(player())) {
|
||||
sender().sendMessage("Ready your Wand.");
|
||||
return;
|
||||
@ -186,16 +186,18 @@ public class DecObject implements DecreeExecutor {
|
||||
player().setItemInHand(WandSVC.createWand(g[0], g[1]));
|
||||
}
|
||||
}
|
||||
|
||||
private static final Set<Material> skipBlocks = Set.of(Material.GRASS, Material.SNOW, Material.VINE, Material.TORCH, Material.DEAD_BUSH,
|
||||
Material.POPPY, Material.DANDELION);
|
||||
|
||||
@Decree(description = "Paste an object")
|
||||
public void paste(
|
||||
@Param(description = "The object to paste", customHandler = ObjectHandler.class)
|
||||
String object,
|
||||
@Param(description = "Whether or not to edit the object (need to hold wand)", defaultValue = "false")
|
||||
boolean edit,
|
||||
boolean edit,
|
||||
@Param(description = "The amount of degrees to rotate by", defaultValue = "0")
|
||||
int rotate,
|
||||
int rotate,
|
||||
@Param(description = "The factor by which to scale the object placement", defaultValue = "1")
|
||||
double scale
|
||||
// ,
|
||||
|
@ -76,7 +76,6 @@ import org.bukkit.util.Vector;
|
||||
import java.awt.*;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.function.Supplier;
|
||||
|
@ -18,6 +18,7 @@
|
||||
|
||||
package com.volmit.iris.core.nms;
|
||||
|
||||
import com.volmit.iris.util.nbt.mca.palettes.RegistryBlockID;
|
||||
import com.volmit.iris.util.nbt.tag.CompoundTag;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
@ -74,4 +75,6 @@ public interface INMSBinding {
|
||||
default boolean supportsDataPacks() {
|
||||
return false;
|
||||
}
|
||||
|
||||
RegistryBlockID computeBlockIDRegistry() throws NoSuchFieldException, IllegalAccessException;
|
||||
}
|
||||
|
@ -22,6 +22,8 @@ import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.core.nms.INMSBinding;
|
||||
import com.volmit.iris.util.collection.KMap;
|
||||
import com.volmit.iris.util.nbt.io.NBTUtil;
|
||||
import com.volmit.iris.util.nbt.mca.NBTWorld;
|
||||
import com.volmit.iris.util.nbt.mca.palettes.RegistryBlockID;
|
||||
import com.volmit.iris.util.nbt.tag.CompoundTag;
|
||||
import net.minecraft.core.BlockPosition;
|
||||
import net.minecraft.core.IRegistry;
|
||||
@ -35,6 +37,8 @@ import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.server.level.WorldServer;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.level.biome.BiomeBase;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.entity.TileEntity;
|
||||
import net.minecraft.world.level.block.state.IBlockData;
|
||||
import net.minecraft.world.level.chunk.BiomeStorage;
|
||||
@ -44,8 +48,10 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.craftbukkit.v1_17_R1.CraftServer;
|
||||
import org.bukkit.craftbukkit.v1_17_R1.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_17_R1.block.data.CraftBlockData;
|
||||
import org.bukkit.craftbukkit.v1_17_R1.entity.CraftEntity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.generator.ChunkGenerator;
|
||||
@ -53,6 +59,10 @@ import org.bukkit.generator.ChunkGenerator;
|
||||
import java.io.*;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.IdentityHashMap;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public class NMSBinding17_1 implements INMSBinding {
|
||||
@ -63,6 +73,24 @@ public class NMSBinding17_1 implements INMSBinding {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RegistryBlockID computeBlockIDRegistry() throws NoSuchFieldException, IllegalAccessException {
|
||||
Field cf = net.minecraft.core.RegistryBlockID.class.getDeclaredField("c");
|
||||
Field df = net.minecraft.core.RegistryBlockID.class.getDeclaredField("d");
|
||||
cf.setAccessible(true);
|
||||
df.setAccessible(true);
|
||||
net.minecraft.core.RegistryBlockID<IBlockData> blockData = Block.p;
|
||||
IdentityHashMap<IBlockData, Integer> c = (IdentityHashMap<IBlockData, Integer>) cf.get(blockData);
|
||||
List<IBlockData> d = (List<IBlockData>) df.get(blockData);
|
||||
List<CompoundTag> realTags = new ArrayList<>();
|
||||
HashMap<CompoundTag, Integer> realMap = new HashMap<>(512);
|
||||
d.forEach((i) -> realTags.add(NBTWorld.getCompound(CraftBlockData.fromData(i))));
|
||||
c.forEach((k,v) -> realMap.put(NBTWorld.getCompound(CraftBlockData.fromData(k)), v));
|
||||
RegistryBlockID registry = new RegistryBlockID(realMap, realTags);
|
||||
Iris.info("INMS: Stole Global Palette: " + realTags.size() + " Tags, " + realMap.size() + " Mapped");
|
||||
return registry;
|
||||
}
|
||||
|
||||
private Object getBiomeStorage(ChunkGenerator.BiomeGrid g) {
|
||||
try {
|
||||
return getFieldForBiomeStorage(g).get(g);
|
||||
|
@ -18,7 +18,9 @@
|
||||
|
||||
package com.volmit.iris.core.nms.v1X;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.core.nms.INMSBinding;
|
||||
import com.volmit.iris.util.nbt.mca.palettes.RegistryBlockID;
|
||||
import com.volmit.iris.util.nbt.tag.CompoundTag;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
@ -142,4 +144,10 @@ public class NMSBinding1X implements INMSBinding {
|
||||
public void forceBiomeInto(int x, int y, int z, Object somethingVeryDirty, ChunkGenerator.BiomeGrid chunk) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public RegistryBlockID computeBlockIDRegistry() throws NoSuchFieldException, IllegalAccessException {
|
||||
Iris.error("Cannot use the global data palette! Iris is incapable of using MCA generation on this version of minecraft!");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -28,7 +28,6 @@ import io.papermc.lib.PaperLib;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.World;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
public class AsyncPregenMethod implements PregeneratorMethod {
|
||||
|
@ -32,13 +32,11 @@ import java.net.MalformedURLException;
|
||||
public class IrisPack {
|
||||
private final File folder;
|
||||
|
||||
public IrisPack(File folder)
|
||||
{
|
||||
public IrisPack(File folder) {
|
||||
this.folder = folder;
|
||||
}
|
||||
|
||||
public void delete()
|
||||
{
|
||||
public void delete() {
|
||||
IO.delete(folder);
|
||||
folder.delete();
|
||||
}
|
||||
|
@ -39,9 +39,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.collection.KSet;
|
||||
import com.volmit.iris.util.data.B;
|
||||
import com.volmit.iris.util.exceptions.IrisException;
|
||||
import com.volmit.iris.util.format.C;
|
||||
import com.volmit.iris.util.format.Form;
|
||||
import com.volmit.iris.util.io.IO;
|
||||
import com.volmit.iris.util.json.JSONArray;
|
||||
@ -55,7 +53,6 @@ import com.volmit.iris.util.scheduling.PrecisionStopwatch;
|
||||
import com.volmit.iris.util.scheduling.jobs.Job;
|
||||
import com.volmit.iris.util.scheduling.jobs.JobCollection;
|
||||
import com.volmit.iris.util.scheduling.jobs.ParallelQueueJob;
|
||||
import com.volmit.iris.util.scheduling.jobs.QueueJob;
|
||||
import lombok.Data;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
@ -519,18 +516,16 @@ public class IrisProject {
|
||||
@Override
|
||||
public void execute(File f) {
|
||||
try {
|
||||
IrisObject o = new IrisObject(0,0,0);
|
||||
IrisObject o = new IrisObject(0, 0, 0);
|
||||
o.read(f);
|
||||
|
||||
if(o.getBlocks().isEmpty())
|
||||
{
|
||||
if (o.getBlocks().isEmpty()) {
|
||||
sender.sendMessageRaw("<hover:show_text:'Error:\n" +
|
||||
"<yellow>" + f.getPath() +
|
||||
"'><red>- IOB " + f.getName() + " has 0 blocks!");
|
||||
}
|
||||
|
||||
if(o.getW() == 0 || o.getH() == 0 || o.getD() == 0)
|
||||
{
|
||||
if (o.getW() == 0 || o.getH() == 0 || o.getD() == 0) {
|
||||
sender.sendMessageRaw("<hover:show_text:'Error:\n" +
|
||||
"<yellow>" + f.getPath() + "\n<red>The width height or depth has a zero in it (bad format)" +
|
||||
"'><red>- IOB " + f.getName() + " is not 3D!");
|
||||
@ -558,7 +553,7 @@ public class IrisProject {
|
||||
} catch (Throwable e) {
|
||||
sender.sendMessageRaw("<hover:show_text:'Error:\n" +
|
||||
"<yellow>" + f.getPath() +
|
||||
"\n<red>" +e.getMessage() +
|
||||
"\n<red>" + e.getMessage() +
|
||||
"'><red>- JSON Error " + f.getName());
|
||||
}
|
||||
}
|
||||
@ -576,8 +571,7 @@ public class IrisProject {
|
||||
String key = data.toLoadKey(f);
|
||||
ResourceLoader<?> loader = data.getTypedLoaderFor(f);
|
||||
|
||||
if(loader == null)
|
||||
{
|
||||
if (loader == null) {
|
||||
sender.sendMessageBasic("Can't find loader for " + f.getPath());
|
||||
return;
|
||||
}
|
||||
@ -587,15 +581,10 @@ public class IrisProject {
|
||||
load.scanForErrors(p, sender);
|
||||
}
|
||||
|
||||
public void compare(Class<?> c, JSONObject j, VolmitSender sender, KList<String> path)
|
||||
{
|
||||
try
|
||||
{
|
||||
public void compare(Class<?> c, JSONObject j, VolmitSender sender, KList<String> path) {
|
||||
try {
|
||||
Object o = c.getClass().getConstructor().newInstance();
|
||||
}
|
||||
|
||||
catch(Throwable e)
|
||||
{
|
||||
} catch (Throwable e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -32,7 +32,6 @@ import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
import java.awt.*;
|
||||
import java.lang.reflect.AccessibleObject;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.List;
|
||||
|
@ -19,7 +19,6 @@
|
||||
package com.volmit.iris.core.project.loader;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.core.service.StudioSVC;
|
||||
import com.volmit.iris.engine.framework.Engine;
|
||||
import com.volmit.iris.engine.object.biome.IrisBiome;
|
||||
import com.volmit.iris.engine.object.block.IrisBlockData;
|
||||
@ -44,9 +43,8 @@ import com.volmit.iris.util.math.RNG;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Data
|
||||
public class IrisData {
|
||||
@ -73,9 +71,8 @@ public class IrisData {
|
||||
private Engine engine;
|
||||
private final int id;
|
||||
|
||||
public static IrisData get(File dataFolder)
|
||||
{
|
||||
return dataLoaders.compute(dataFolder, (k,v) -> v == null ? new IrisData(dataFolder) : v);
|
||||
public static IrisData get(File dataFolder) {
|
||||
return dataLoaders.compute(dataFolder, (k, v) -> v == null ? new IrisData(dataFolder) : v);
|
||||
}
|
||||
|
||||
private IrisData(File dataFolder) {
|
||||
@ -86,20 +83,16 @@ public class IrisData {
|
||||
hotloaded();
|
||||
}
|
||||
|
||||
public static void dereference()
|
||||
{
|
||||
public static void dereference() {
|
||||
dataLoaders.v().forEach(IrisData::cleanupEngine);
|
||||
}
|
||||
|
||||
public ResourceLoader<?> getTypedLoaderFor(File f) {
|
||||
String[] k = f.getPath().split("\\Q"+File.separator+"\\E");
|
||||
String[] k = f.getPath().split("\\Q" + File.separator + "\\E");
|
||||
|
||||
for(String i : k)
|
||||
{
|
||||
for(ResourceLoader<?> j : loaders.values())
|
||||
{
|
||||
if(j.getFolderName().equals(i))
|
||||
{
|
||||
for (String i : k) {
|
||||
for (ResourceLoader<?> j : loaders.values()) {
|
||||
if (j.getFolderName().equals(i)) {
|
||||
return j;
|
||||
}
|
||||
}
|
||||
@ -108,10 +101,8 @@ public class IrisData {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void cleanupEngine()
|
||||
{
|
||||
if(engine != null && engine.isClosed())
|
||||
{
|
||||
public void cleanupEngine() {
|
||||
if (engine != null && engine.isClosed()) {
|
||||
engine = null;
|
||||
Iris.debug("Dereferenced Data<Engine> " + getId() + " " + getDataFolder());
|
||||
}
|
||||
@ -119,11 +110,9 @@ public class IrisData {
|
||||
|
||||
public static int cacheSize() {
|
||||
int m = 0;
|
||||
for(IrisData i : dataLoaders.values())
|
||||
{
|
||||
for(ResourceLoader<?> j : i.getLoaders().values())
|
||||
{
|
||||
m+=j.getLoadCache().size();
|
||||
for (IrisData i : dataLoaders.values()) {
|
||||
for (ResourceLoader<?> j : i.getLoaders().values()) {
|
||||
m += j.getLoadCache().size();
|
||||
}
|
||||
}
|
||||
|
||||
@ -332,18 +321,14 @@ public class IrisData {
|
||||
}
|
||||
|
||||
public String toLoadKey(File f) {
|
||||
if(f.getPath().startsWith(getDataFolder().getPath()))
|
||||
{
|
||||
if (f.getPath().startsWith(getDataFolder().getPath())) {
|
||||
String[] full = f.getPath().split("\\Q" + File.separator + "\\E");
|
||||
String[] df = getDataFolder().getPath().split("\\Q" + File.separator + "\\E");
|
||||
String g = "";
|
||||
boolean m = true;
|
||||
for(int i = 0; i < full.length; i++)
|
||||
{
|
||||
if(i >= df.length)
|
||||
{
|
||||
if(m)
|
||||
{
|
||||
for (int i = 0; i < full.length; i++) {
|
||||
if (i >= df.length) {
|
||||
if (m) {
|
||||
m = false;
|
||||
continue;
|
||||
}
|
||||
@ -354,10 +339,7 @@ public class IrisData {
|
||||
|
||||
String ff = g.toString().substring(1).split("\\Q.\\E")[0];
|
||||
return ff;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
} else {
|
||||
Iris.error("Forign file from loader " + f.getPath() + " (loader realm: " + getDataFolder().getPath() + ")");
|
||||
}
|
||||
|
||||
|
@ -18,7 +18,6 @@
|
||||
|
||||
package com.volmit.iris.core.service;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.core.decrees.DecIris;
|
||||
import com.volmit.iris.engine.data.cache.AtomicCache;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
|
@ -28,29 +28,24 @@ import com.volmit.iris.util.scheduling.Looper;
|
||||
|
||||
import java.util.concurrent.ExecutorService;
|
||||
|
||||
public class PreservationSVC implements IrisService
|
||||
{
|
||||
public class PreservationSVC implements IrisService {
|
||||
private KList<Thread> threads = new KList<>();
|
||||
private KList<ExecutorService> services = new KList<>();
|
||||
private Looper dereferencer;
|
||||
|
||||
public void register(Thread t)
|
||||
{
|
||||
public void register(Thread t) {
|
||||
threads.add(t);
|
||||
}
|
||||
|
||||
public void register(MultiBurst burst)
|
||||
{
|
||||
public void register(MultiBurst burst) {
|
||||
|
||||
}
|
||||
|
||||
public void register(ExecutorService service)
|
||||
{
|
||||
public void register(ExecutorService service) {
|
||||
services.add(service);
|
||||
}
|
||||
|
||||
public void dereference()
|
||||
{
|
||||
public void dereference() {
|
||||
IrisContext.dereference();
|
||||
IrisData.dereference();
|
||||
}
|
||||
@ -76,33 +71,22 @@ public class PreservationSVC implements IrisService
|
||||
dereference();
|
||||
|
||||
postShutdown(() -> {
|
||||
for(Thread i : threads)
|
||||
{
|
||||
if(i.isAlive())
|
||||
{
|
||||
try
|
||||
{
|
||||
for (Thread i : threads) {
|
||||
if (i.isAlive()) {
|
||||
try {
|
||||
i.interrupt();
|
||||
Iris.info("Shutdown Thread " + i.getName());
|
||||
}
|
||||
|
||||
catch(Throwable e)
|
||||
{
|
||||
} catch (Throwable e) {
|
||||
Iris.reportError(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(ExecutorService i : services)
|
||||
{
|
||||
try
|
||||
{
|
||||
for (ExecutorService i : services) {
|
||||
try {
|
||||
i.shutdownNow();
|
||||
Iris.info("Shutdown Executor Service " + i);
|
||||
}
|
||||
|
||||
catch(Throwable e)
|
||||
{
|
||||
} catch (Throwable e) {
|
||||
Iris.reportError(e);
|
||||
}
|
||||
}
|
||||
|
@ -21,7 +21,6 @@ package com.volmit.iris.core.service;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.core.IrisSettings;
|
||||
import com.volmit.iris.core.project.IrisProject;
|
||||
import com.volmit.iris.core.project.loader.IrisData;
|
||||
import com.volmit.iris.core.tools.IrisToolbelt;
|
||||
@ -77,8 +76,7 @@ public class StudioSVC implements IrisService {
|
||||
|
||||
for (World i : Bukkit.getWorlds()) {
|
||||
if (IrisToolbelt.isIrisWorld(i)) {
|
||||
if(IrisToolbelt.isStudio(i))
|
||||
{
|
||||
if (IrisToolbelt.isStudio(i)) {
|
||||
IrisToolbelt.evacuate(i);
|
||||
IrisToolbelt.access(i).close();
|
||||
}
|
||||
@ -165,8 +163,7 @@ public class StudioSVC implements IrisService {
|
||||
try {
|
||||
url = getListing(false).get(key);
|
||||
|
||||
if(url == null)
|
||||
{
|
||||
if (url == null) {
|
||||
Iris.warn("ITS ULL for " + key);
|
||||
}
|
||||
|
||||
|
@ -128,7 +128,8 @@ public class IrisToolbelt {
|
||||
return pregenerate(task, new HeadlessPregenMethod(((HeadlessGenerator) gen).getWorld(), (HeadlessGenerator) gen));
|
||||
}
|
||||
|
||||
return pregenerate(task, new HybridPregenMethod(gen.getEngine().getWorld().realWorld(), IrisSettings.getThreadCount((int) IrisSettings.get().getConcurrency().getParallelism())));
|
||||
return pregenerate(task, new HybridPregenMethod(gen.getEngine().getWorld().realWorld(),
|
||||
IrisSettings.getThreadCount((int) IrisSettings.get().getConcurrency().getParallelism())));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -19,7 +19,6 @@
|
||||
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.project.loader.IrisData;
|
||||
import com.volmit.iris.engine.actuator.IrisTerrainNormalActuator;
|
||||
@ -32,13 +31,10 @@ import com.volmit.iris.engine.object.decoration.IrisDecorationPart;
|
||||
import com.volmit.iris.engine.object.decoration.IrisDecorator;
|
||||
import com.volmit.iris.engine.object.feature.IrisFeaturePositional;
|
||||
import com.volmit.iris.engine.object.noise.IrisGenerator;
|
||||
import com.volmit.iris.engine.object.noise.IrisInterpolator;
|
||||
import com.volmit.iris.engine.object.noise.IrisShapedGeneratorStyle;
|
||||
import com.volmit.iris.engine.object.regional.IrisRegion;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.collection.KMap;
|
||||
import com.volmit.iris.util.data.DataProvider;
|
||||
import com.volmit.iris.util.function.NoiseProvider;
|
||||
import com.volmit.iris.util.math.M;
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
import com.volmit.iris.util.noise.CNG;
|
||||
@ -49,7 +45,6 @@ import org.bukkit.Material;
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
|
@ -30,7 +30,10 @@ import com.volmit.iris.engine.actuator.IrisTerrainNormalActuator;
|
||||
import com.volmit.iris.engine.data.cache.AtomicCache;
|
||||
import com.volmit.iris.engine.framework.*;
|
||||
import com.volmit.iris.engine.mantle.EngineMantle;
|
||||
import com.volmit.iris.engine.modifier.*;
|
||||
import com.volmit.iris.engine.modifier.IrisCaveModifier;
|
||||
import com.volmit.iris.engine.modifier.IrisDepositModifier;
|
||||
import com.volmit.iris.engine.modifier.IrisPostModifier;
|
||||
import com.volmit.iris.engine.modifier.IrisRavineModifier;
|
||||
import com.volmit.iris.engine.object.biome.IrisBiome;
|
||||
import com.volmit.iris.engine.object.biome.IrisBiomePaletteLayer;
|
||||
import com.volmit.iris.engine.object.decoration.IrisDecorator;
|
||||
@ -41,20 +44,17 @@ import com.volmit.iris.util.atomics.AtomicRollingSequence;
|
||||
import com.volmit.iris.util.collection.KMap;
|
||||
import com.volmit.iris.util.context.IrisContext;
|
||||
import com.volmit.iris.util.documentation.BlockCoordinates;
|
||||
import com.volmit.iris.util.documentation.ChunkCoordinates;
|
||||
import com.volmit.iris.util.format.C;
|
||||
import com.volmit.iris.util.format.Form;
|
||||
import com.volmit.iris.util.hunk.Hunk;
|
||||
import com.volmit.iris.util.io.IO;
|
||||
import com.volmit.iris.util.math.M;
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
import com.volmit.iris.util.math.RollingSequence;
|
||||
import com.volmit.iris.util.scheduling.ChronoLatch;
|
||||
import com.volmit.iris.util.scheduling.J;
|
||||
import com.volmit.iris.util.scheduling.PrecisionStopwatch;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
@ -62,7 +62,6 @@ import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
@ -133,13 +132,12 @@ public class IrisEngine implements Engine {
|
||||
}
|
||||
|
||||
private void tickRandomPlayer() {
|
||||
if(effects != null) {
|
||||
if (effects != null) {
|
||||
effects.tickRandomPlayer();
|
||||
}
|
||||
}
|
||||
|
||||
private void prehotload()
|
||||
{
|
||||
private void prehotload() {
|
||||
worldManager.close();
|
||||
complex.close();
|
||||
execution.close();
|
||||
@ -153,10 +151,8 @@ public class IrisEngine implements Engine {
|
||||
effects.close();
|
||||
}
|
||||
|
||||
private void setupEngine()
|
||||
{
|
||||
try
|
||||
{
|
||||
private void setupEngine() {
|
||||
try {
|
||||
Iris.debug("Setup Engine " + getCacheID());
|
||||
cacheId = RNG.r.nextInt();
|
||||
worldManager = new IrisWorldManager(this);
|
||||
@ -171,10 +167,7 @@ public class IrisEngine implements Engine {
|
||||
postModifier = new IrisPostModifier(this);
|
||||
effects = new IrisEngineEffects(this);
|
||||
J.a(this::computeBiomeMaxes);
|
||||
}
|
||||
|
||||
catch(Throwable e)
|
||||
{
|
||||
} catch (Throwable e) {
|
||||
Iris.error("FAILED TO SETUP ENGINE!");
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -397,34 +390,44 @@ public class IrisEngine implements Engine {
|
||||
@BlockCoordinates
|
||||
@Override
|
||||
public void generate(int x, int z, Hunk<BlockData> vblocks, Hunk<Biome> vbiomes, boolean multicore) throws WrongEngineBroException {
|
||||
if(closed)
|
||||
{
|
||||
if (closed) {
|
||||
throw new WrongEngineBroException();
|
||||
}
|
||||
|
||||
context.touch();
|
||||
getEngineData().getStatistics().generatedChunk();
|
||||
try {
|
||||
|
||||
PrecisionStopwatch p = PrecisionStopwatch.start();
|
||||
Hunk<BlockData> blocks = vblocks.listen((xx, y, zz, t) -> catchBlockUpdates(x + xx, y + getMinHeight(), z + zz, t));
|
||||
getMantle().generateMatter(x >> 4, z >> 4, multicore);
|
||||
|
||||
burst().burst(multicore,
|
||||
() -> getTerrainActuator().actuate(x, z, vblocks, multicore),
|
||||
() -> getBiomeActuator().actuate(x, z, vbiomes, multicore)
|
||||
);
|
||||
burst().burst(multicore,
|
||||
() -> getCaveModifier().modify(x, z, vblocks, multicore),
|
||||
() -> getDecorantActuator().actuate(x, z, blocks, multicore),
|
||||
() -> getRavineModifier().modify(x, z, vblocks, multicore)
|
||||
);
|
||||
if (multicore) {
|
||||
for (int i = 0; i < 16; i++) {
|
||||
for (int j = 0; j < 16; j++) {
|
||||
blocks.set(i, 0, j, Material.RED_GLAZED_TERRACOTTA.createBlockData());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
getMantle().generateMatter(x >> 4, z >> 4, multicore);
|
||||
|
||||
getPostModifier().modify(x, z, vblocks, multicore);
|
||||
burst().burst(multicore,
|
||||
() -> getTerrainActuator().actuate(x, z, vblocks, multicore),
|
||||
() -> getBiomeActuator().actuate(x, z, vbiomes, multicore)
|
||||
);
|
||||
burst().burst(multicore,
|
||||
() -> getCaveModifier().modify(x, z, vblocks, multicore),
|
||||
() -> getDecorantActuator().actuate(x, z, blocks, multicore),
|
||||
() -> getRavineModifier().modify(x, z, vblocks, multicore)
|
||||
);
|
||||
|
||||
getPostModifier().modify(x, z, vblocks, multicore);
|
||||
|
||||
burst().burst(multicore,
|
||||
() -> getMantle().insertMatter(x >> 4, z >> 4, BlockData.class, blocks, multicore),
|
||||
() -> getDepositModifier().modify(x, z, vblocks, multicore)
|
||||
);
|
||||
}
|
||||
|
||||
burst().burst(multicore,
|
||||
() -> getMantle().insertMatter(x >> 4, z >> 4, BlockData.class, blocks, multicore),
|
||||
() -> getDepositModifier().modify(x, z, vblocks, multicore)
|
||||
);
|
||||
|
||||
getMetrics().getTotal().put(p.getMilliseconds());
|
||||
generated.incrementAndGet();
|
||||
|
@ -18,7 +18,6 @@
|
||||
|
||||
package com.volmit.iris.engine;
|
||||
|
||||
import com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap;
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.engine.data.cache.AtomicCache;
|
||||
import com.volmit.iris.engine.framework.Engine;
|
||||
@ -29,7 +28,6 @@ import com.volmit.iris.engine.mantle.components.MantleJigsawComponent;
|
||||
import com.volmit.iris.engine.mantle.components.MantleObjectComponent;
|
||||
import com.volmit.iris.engine.object.biome.IrisBiome;
|
||||
import com.volmit.iris.engine.object.deposits.IrisDepositGenerator;
|
||||
import com.volmit.iris.engine.object.feature.IrisFeaturePositional;
|
||||
import com.volmit.iris.engine.object.feature.IrisFeaturePotential;
|
||||
import com.volmit.iris.engine.object.jigsaw.IrisJigsawStructurePlacement;
|
||||
import com.volmit.iris.engine.object.objects.IrisObject;
|
||||
@ -39,21 +37,14 @@ import com.volmit.iris.engine.object.regional.IrisRegion;
|
||||
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.documentation.BlockCoordinates;
|
||||
import com.volmit.iris.util.documentation.ChunkCoordinates;
|
||||
import com.volmit.iris.util.format.Form;
|
||||
import com.volmit.iris.util.mantle.Mantle;
|
||||
import com.volmit.iris.util.mantle.MantleFlag;
|
||||
import com.volmit.iris.util.parallel.BurstExecutor;
|
||||
import com.volmit.iris.util.stream.ProceduralStream;
|
||||
import com.volmit.iris.util.stream.interpolation.Interpolated;
|
||||
import com.volmit.iris.util.stream.utility.CachedStream2D;
|
||||
import lombok.Data;
|
||||
import org.bukkit.util.BlockVector;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
|
@ -39,7 +39,6 @@ import com.volmit.iris.util.math.RNG;
|
||||
import com.volmit.iris.util.scheduling.ChronoLatch;
|
||||
import com.volmit.iris.util.scheduling.J;
|
||||
import com.volmit.iris.util.scheduling.Looper;
|
||||
import io.papermc.lib.PaperLib;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.bukkit.Chunk;
|
||||
@ -99,10 +98,8 @@ public class IrisWorldManager extends EngineAssignedWorldManager {
|
||||
interrupt();
|
||||
}
|
||||
|
||||
if(getEngine().getWorld().hasRealWorld())
|
||||
{
|
||||
if(chunkUpdater.flip())
|
||||
{
|
||||
if (getEngine().getWorld().hasRealWorld()) {
|
||||
if (chunkUpdater.flip()) {
|
||||
updateChunks();
|
||||
}
|
||||
|
||||
@ -152,8 +149,7 @@ public class IrisWorldManager extends EngineAssignedWorldManager {
|
||||
}
|
||||
|
||||
private void updateChunks() {
|
||||
for(Player i : getEngine().getWorld().realWorld().getPlayers())
|
||||
{
|
||||
for (Player i : getEngine().getWorld().realWorld().getPlayers()) {
|
||||
J.s(() -> {
|
||||
Chunk c = i.getLocation().getChunk();
|
||||
J.a(() -> getEngine().updateChunk(c));
|
||||
|
@ -26,12 +26,10 @@ import com.volmit.iris.engine.framework.EngineAssignedActuator;
|
||||
import com.volmit.iris.engine.object.biome.IrisBiome;
|
||||
import com.volmit.iris.engine.object.biome.IrisBiomeCustom;
|
||||
import com.volmit.iris.util.documentation.BlockCoordinates;
|
||||
import com.volmit.iris.util.format.Form;
|
||||
import com.volmit.iris.util.hunk.Hunk;
|
||||
import com.volmit.iris.util.hunk.view.BiomeGridHunkView;
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
import com.volmit.iris.util.parallel.BurstExecutor;
|
||||
import com.volmit.iris.util.parallel.MultiBurst;
|
||||
import com.volmit.iris.util.scheduling.PrecisionStopwatch;
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.generator.ChunkGenerator;
|
||||
|
@ -18,7 +18,6 @@
|
||||
|
||||
package com.volmit.iris.engine.actuator;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.engine.decorator.*;
|
||||
import com.volmit.iris.engine.framework.Engine;
|
||||
import com.volmit.iris.engine.framework.EngineAssignedActuator;
|
||||
@ -26,7 +25,6 @@ import com.volmit.iris.engine.framework.EngineDecorator;
|
||||
import com.volmit.iris.engine.object.biome.IrisBiome;
|
||||
import com.volmit.iris.engine.object.carve.IrisCaveLayer;
|
||||
import com.volmit.iris.util.documentation.BlockCoordinates;
|
||||
import com.volmit.iris.util.format.Form;
|
||||
import com.volmit.iris.util.hunk.Hunk;
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
import com.volmit.iris.util.parallel.BurstExecutor;
|
||||
@ -35,7 +33,6 @@ import lombok.Getter;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.BiPredicate;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
@ -99,7 +96,7 @@ public class IrisDecorantActuator extends EngineAssignedActuator<BlockData> {
|
||||
int realX = (int) Math.round(modX(x + finalI));
|
||||
int realZ;
|
||||
IrisBiome biome, cave;
|
||||
for (int j=0; j < output.getDepth(); j++) {
|
||||
for (int j = 0; j < output.getDepth(); j++) {
|
||||
boolean solid, liquid;
|
||||
int emptyFor = 0;
|
||||
int liquidFor = 0;
|
||||
@ -113,8 +110,7 @@ public class IrisDecorantActuator extends EngineAssignedActuator<BlockData> {
|
||||
continue;
|
||||
}
|
||||
|
||||
if(height < getDimension().getFluidHeight())
|
||||
{
|
||||
if (height < getDimension().getFluidHeight()) {
|
||||
getSeaSurfaceDecorator().decorate(finalI, j,
|
||||
realX, (int) Math.round(modX(x + finalI + 1)), (int) Math.round(modX(x + finalI - 1)),
|
||||
realZ, (int) Math.round(modZ(z + j + 1)), (int) Math.round(modZ(z + j - 1)),
|
||||
|
@ -18,11 +18,9 @@
|
||||
|
||||
package com.volmit.iris.engine.actuator;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.engine.framework.Engine;
|
||||
import com.volmit.iris.engine.framework.EngineAssignedActuator;
|
||||
import com.volmit.iris.engine.object.biome.IrisBiome;
|
||||
import com.volmit.iris.engine.object.noise.IrisShapedGeneratorStyle;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.documentation.BlockCoordinates;
|
||||
import com.volmit.iris.util.hunk.Hunk;
|
||||
@ -66,8 +64,7 @@ public class IrisTerrainNormalActuator extends EngineAssignedActuator<BlockData>
|
||||
getEngine().getMetrics().getTerrain().put(p.getMilliseconds());
|
||||
}
|
||||
|
||||
private int fluidOrHeight(int height)
|
||||
{
|
||||
private int fluidOrHeight(int height) {
|
||||
return Math.max(getDimension().getFluidHeight(), height);
|
||||
}
|
||||
|
||||
@ -97,7 +94,7 @@ public class IrisTerrainNormalActuator extends EngineAssignedActuator<BlockData>
|
||||
|
||||
KList<BlockData> blocks = null;
|
||||
KList<BlockData> fblocks = null;
|
||||
int depth,fdepth;
|
||||
int depth, fdepth;
|
||||
|
||||
for (int i = hf; i >= 0; i--) {
|
||||
if (i >= h.getHeight()) {
|
||||
|
@ -18,107 +18,68 @@
|
||||
|
||||
package com.volmit.iris.engine.data.cache;
|
||||
|
||||
import com.volmit.iris.util.math.M;
|
||||
import com.volmit.iris.util.scheduling.IrisLock;
|
||||
import com.volmit.iris.Iris;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class AtomicCache<T> {
|
||||
private transient volatile T t;
|
||||
private transient volatile long a;
|
||||
private transient volatile int validations;
|
||||
private final IrisLock check;
|
||||
private final IrisLock time;
|
||||
private final IrisLock write;
|
||||
private final boolean nullSupport;
|
||||
private transient final AtomicReference<T> t;
|
||||
private transient final AtomicBoolean set;
|
||||
private transient final ReentrantLock lock;
|
||||
private transient final boolean nullSupport;
|
||||
|
||||
public AtomicCache() {
|
||||
this(false);
|
||||
}
|
||||
|
||||
public AtomicCache(boolean nullSupport) {
|
||||
set = nullSupport ? new AtomicBoolean() : null;
|
||||
t = new AtomicReference<>();
|
||||
lock = new ReentrantLock();
|
||||
this.nullSupport = nullSupport;
|
||||
check = new IrisLock("Check");
|
||||
write = new IrisLock("Write");
|
||||
time = new IrisLock("Time");
|
||||
validations = 0;
|
||||
a = -1;
|
||||
t = null;
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
check.lock();
|
||||
write.lock();
|
||||
time.lock();
|
||||
a = -1;
|
||||
t = null;
|
||||
time.unlock();
|
||||
write.unlock();
|
||||
check.unlock();
|
||||
t.set(null);
|
||||
|
||||
if (nullSupport) {
|
||||
set.set(false);
|
||||
}
|
||||
}
|
||||
|
||||
public T aquire(Supplier<T> t) {
|
||||
if (nullSupport) {
|
||||
return aquireNull(t);
|
||||
if (this.t.get() != null) {
|
||||
return this.t.get();
|
||||
} else if (nullSupport && set.get()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (this.t != null && validations > 1000) {
|
||||
return this.t;
|
||||
lock.lock();
|
||||
|
||||
if (this.t.get() != null) {
|
||||
lock.unlock();
|
||||
return this.t.get();
|
||||
} else if (nullSupport && set.get()) {
|
||||
lock.unlock();
|
||||
return null;
|
||||
}
|
||||
|
||||
if (this.t != null && M.ms() - a > 1000) {
|
||||
if (this.t != null) {
|
||||
//noinspection NonAtomicOperationOnVolatileField
|
||||
validations++;
|
||||
try {
|
||||
this.t.set(t.get());
|
||||
|
||||
if (nullSupport) {
|
||||
set.set(true);
|
||||
}
|
||||
|
||||
return this.t;
|
||||
} catch (Throwable e) {
|
||||
Iris.error("Atomic cache failure!");
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
check.lock();
|
||||
lock.unlock();
|
||||
|
||||
if (this.t == null) {
|
||||
write.lock();
|
||||
this.t = t.get();
|
||||
|
||||
time.lock();
|
||||
|
||||
if (a == -1) {
|
||||
a = M.ms();
|
||||
}
|
||||
|
||||
time.unlock();
|
||||
write.unlock();
|
||||
}
|
||||
|
||||
check.unlock();
|
||||
return this.t;
|
||||
}
|
||||
|
||||
public T aquireNull(Supplier<T> t) {
|
||||
if (validations > 1000) {
|
||||
return this.t;
|
||||
}
|
||||
|
||||
if (M.ms() - a > 1000) {
|
||||
//noinspection NonAtomicOperationOnVolatileField
|
||||
validations++;
|
||||
return this.t;
|
||||
}
|
||||
|
||||
check.lock();
|
||||
write.lock();
|
||||
this.t = t.get();
|
||||
|
||||
time.lock();
|
||||
|
||||
if (a == -1) {
|
||||
a = M.ms();
|
||||
}
|
||||
|
||||
time.unlock();
|
||||
write.unlock();
|
||||
check.unlock();
|
||||
return this.t;
|
||||
return this.t.get();
|
||||
}
|
||||
}
|
||||
|
@ -92,8 +92,7 @@ public class MCATerrainChunk implements TerrainChunk {
|
||||
return;
|
||||
}
|
||||
|
||||
if(blockData == null)
|
||||
{
|
||||
if (blockData == null) {
|
||||
Iris.error("NULL BD");
|
||||
}
|
||||
|
||||
|
@ -18,7 +18,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.biome.IrisBiome;
|
||||
|
@ -21,8 +21,6 @@ package com.volmit.iris.engine.framework;
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.generator.LimitedRegion;
|
||||
import org.bukkit.generator.WorldInfo;
|
||||
|
||||
public interface BlockUpdater {
|
||||
|
||||
|
@ -45,10 +45,8 @@ import com.volmit.iris.util.data.B;
|
||||
import com.volmit.iris.util.data.DataProvider;
|
||||
import com.volmit.iris.util.documentation.BlockCoordinates;
|
||||
import com.volmit.iris.util.documentation.ChunkCoordinates;
|
||||
import com.volmit.iris.util.format.Form;
|
||||
import com.volmit.iris.util.function.Function2;
|
||||
import com.volmit.iris.util.hunk.Hunk;
|
||||
import com.volmit.iris.util.mantle.Mantle;
|
||||
import com.volmit.iris.util.mantle.MantleFlag;
|
||||
import com.volmit.iris.util.math.BlockPosition;
|
||||
import com.volmit.iris.util.math.M;
|
||||
@ -60,7 +58,10 @@ import com.volmit.iris.util.scheduling.J;
|
||||
import com.volmit.iris.util.scheduling.PrecisionStopwatch;
|
||||
import com.volmit.iris.util.stream.ProceduralStream;
|
||||
import io.papermc.lib.PaperLib;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
@ -70,7 +71,6 @@ import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.Color;
|
||||
import java.util.Arrays;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
@ -393,8 +393,7 @@ public interface Engine extends DataProvider, Fallible, LootProvider, BlockUpdat
|
||||
items.addAll(i.getLoot(debug, items.isEmpty(), rng, slot, x, y, z, b + b, mgf + b));
|
||||
}
|
||||
|
||||
if(PaperLib.isPaper() && getWorld().hasRealWorld())
|
||||
{
|
||||
if (PaperLib.isPaper() && getWorld().hasRealWorld()) {
|
||||
PaperLib.getChunkAtAsync(getWorld().realWorld(), x >> 4, z >> 4).thenAccept((c) -> {
|
||||
Runnable r = () -> {
|
||||
for (ItemStack i : items) {
|
||||
@ -404,20 +403,13 @@ public interface Engine extends DataProvider, Fallible, LootProvider, BlockUpdat
|
||||
scramble(inv, rng);
|
||||
};
|
||||
|
||||
if(Bukkit.isPrimaryThread())
|
||||
{
|
||||
if (Bukkit.isPrimaryThread()) {
|
||||
r.run();
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
} else {
|
||||
J.s(r);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
} else {
|
||||
for (ItemStack i : items) {
|
||||
inv.addItem(i);
|
||||
}
|
||||
|
@ -18,7 +18,6 @@
|
||||
|
||||
package com.volmit.iris.engine.framework;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.util.documentation.BlockCoordinates;
|
||||
import com.volmit.iris.util.hunk.Hunk;
|
||||
|
||||
|
@ -18,7 +18,6 @@
|
||||
|
||||
package com.volmit.iris.engine.framework;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.util.documentation.BlockCoordinates;
|
||||
import com.volmit.iris.util.hunk.Hunk;
|
||||
|
||||
|
@ -80,8 +80,7 @@ public abstract class EngineAssignedWorldManager extends EngineAssignedComponent
|
||||
|
||||
Iris.debug("Ps: " + p.size());
|
||||
|
||||
for(Position2 i : p)
|
||||
{
|
||||
for (Position2 i : p) {
|
||||
Iris.debug("- " + i.getX() + " " + i.getZ());
|
||||
}
|
||||
|
||||
|
@ -33,8 +33,7 @@ public interface EngineComponent {
|
||||
|
||||
String getName();
|
||||
|
||||
default MultiBurst burst()
|
||||
{
|
||||
default MultiBurst burst() {
|
||||
return getEngine().burst();
|
||||
}
|
||||
|
||||
|
@ -18,7 +18,6 @@
|
||||
|
||||
package com.volmit.iris.engine.framework;
|
||||
|
||||
import com.volmit.iris.core.IrisSettings;
|
||||
import com.volmit.iris.core.project.loader.IrisData;
|
||||
import com.volmit.iris.engine.object.common.IrisWorld;
|
||||
import com.volmit.iris.engine.object.dimensional.IrisDimension;
|
||||
|
@ -21,11 +21,8 @@ package com.volmit.iris.engine.jigsaw;
|
||||
import com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap;
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.core.project.loader.IrisData;
|
||||
import com.volmit.iris.core.tools.IrisToolbelt;
|
||||
import com.volmit.iris.engine.framework.Engine;
|
||||
import com.volmit.iris.engine.object.basic.IrisPosition;
|
||||
import com.volmit.iris.engine.object.common.IObjectPlacer;
|
||||
import com.volmit.iris.engine.object.entity.IrisEntity;
|
||||
import com.volmit.iris.engine.object.feature.IrisFeature;
|
||||
import com.volmit.iris.engine.object.feature.IrisFeaturePositional;
|
||||
import com.volmit.iris.engine.object.jigsaw.IrisJigsawPiece;
|
||||
@ -38,9 +35,7 @@ import com.volmit.iris.util.mantle.Mantle;
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
import lombok.Data;
|
||||
import org.bukkit.Axis;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Entity;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@ -116,20 +111,13 @@ public class PlannedStructure {
|
||||
int offset = i.getPosition().getY() - startHeight;
|
||||
int height = 0;
|
||||
|
||||
if(i.getStructure().getStructure().getLockY() == -1)
|
||||
{
|
||||
if(i.getStructure().getStructure().getOverrideYRange() != null)
|
||||
{
|
||||
height = (int)i.getStructure().getStructure().getOverrideYRange().get(rng, xx, zz, getData());
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
if (i.getStructure().getStructure().getLockY() == -1) {
|
||||
if (i.getStructure().getStructure().getOverrideYRange() != null) {
|
||||
height = (int) i.getStructure().getStructure().getOverrideYRange().get(rng, xx, zz, getData());
|
||||
} else {
|
||||
height = placer.getHighest(xx, zz, getData());
|
||||
}
|
||||
}
|
||||
|
||||
else{
|
||||
} else {
|
||||
height = i.getStructure().getStructure().getLockY();
|
||||
}
|
||||
|
||||
@ -244,8 +232,7 @@ public class PlannedStructure {
|
||||
}
|
||||
|
||||
private boolean generateRotatedPiece(PlannedPiece piece, IrisJigsawPieceConnector pieceConnector, IrisJigsawPiece idea, IrisObjectRotation rotation) {
|
||||
if (!idea.getPlacementOptions().getRotation().isEnabled())
|
||||
{
|
||||
if (!idea.getPlacementOptions().getRotation().isEnabled()) {
|
||||
rotation = piece.getRotation();
|
||||
}
|
||||
|
||||
|
@ -33,17 +33,13 @@ import com.volmit.iris.util.documentation.BlockCoordinates;
|
||||
import com.volmit.iris.util.documentation.ChunkCoordinates;
|
||||
import com.volmit.iris.util.hunk.Hunk;
|
||||
import com.volmit.iris.util.mantle.Mantle;
|
||||
import com.volmit.iris.util.mantle.MantleFlag;
|
||||
import com.volmit.iris.util.noise.CNG;
|
||||
import com.volmit.iris.util.parallel.BurstExecutor;
|
||||
import com.volmit.iris.util.parallel.MultiBurst;
|
||||
import com.volmit.iris.util.scheduling.PrecisionStopwatch;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.block.TileState;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
// TODO: MOVE PLACER OUT OF MATTER INTO ITS OWN THING
|
||||
@ -181,8 +177,7 @@ public interface EngineMantle extends IObjectPlacer {
|
||||
|
||||
KList<Runnable> post = new KList<>();
|
||||
Consumer<Runnable> c = (i) -> {
|
||||
synchronized (post)
|
||||
{
|
||||
synchronized (post) {
|
||||
post.add(i);
|
||||
}
|
||||
};
|
||||
@ -201,8 +196,7 @@ public interface EngineMantle extends IObjectPlacer {
|
||||
|
||||
burst.complete();
|
||||
|
||||
while(!post.isEmpty())
|
||||
{
|
||||
while (!post.isEmpty()) {
|
||||
KList<Runnable> px = post.copy();
|
||||
post.clear();
|
||||
burst().burst(multicore, px);
|
||||
|
@ -20,7 +20,6 @@ package com.volmit.iris.engine.mantle;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.core.project.loader.IrisData;
|
||||
import com.volmit.iris.engine.IrisEngineMantle;
|
||||
import com.volmit.iris.engine.data.cache.Cache;
|
||||
import com.volmit.iris.engine.object.common.IObjectPlacer;
|
||||
import com.volmit.iris.engine.object.feature.IrisFeaturePositional;
|
||||
@ -34,8 +33,7 @@ import org.bukkit.block.TileState;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
|
||||
@Data
|
||||
public class MantleWriter implements IObjectPlacer
|
||||
{
|
||||
public class MantleWriter implements IObjectPlacer {
|
||||
private final EngineMantle engineMantle;
|
||||
private final Mantle mantle;
|
||||
private final KMap<Long, MantleChunk> cachedChunks;
|
||||
@ -43,8 +41,7 @@ public class MantleWriter implements IObjectPlacer
|
||||
private final int x;
|
||||
private final int z;
|
||||
|
||||
public MantleWriter(EngineMantle engineMantle, Mantle mantle, int x, int z, int radius)
|
||||
{
|
||||
public MantleWriter(EngineMantle engineMantle, Mantle mantle, int x, int z, int radius) {
|
||||
this.engineMantle = engineMantle;
|
||||
this.mantle = mantle;
|
||||
this.cachedChunks = new KMap<>();
|
||||
@ -59,8 +56,7 @@ public class MantleWriter implements IObjectPlacer
|
||||
}
|
||||
}
|
||||
|
||||
public <T> void setData(int x, int y, int z, T t)
|
||||
{
|
||||
public <T> void setData(int x, int y, int z, T t) {
|
||||
int cx = x >> 4;
|
||||
int cz = z >> 4;
|
||||
|
||||
@ -68,31 +64,22 @@ public class MantleWriter implements IObjectPlacer
|
||||
return;
|
||||
}
|
||||
|
||||
if(cx >= this.x - radius && cx <= this.x + radius
|
||||
&& cz >= this.z - radius && cz <= this.z + radius)
|
||||
{
|
||||
if (cx >= this.x - radius && cx <= this.x + radius
|
||||
&& cz >= this.z - radius && cz <= this.z + radius) {
|
||||
MantleChunk chunk = cachedChunks.get(Cache.key(cx, cz));
|
||||
|
||||
if(chunk == null)
|
||||
{
|
||||
if (chunk == null) {
|
||||
Iris.error("Mantle Writer Accessed " + cx + "," + cz + " and came up null (and yet within bounds!)");
|
||||
return;
|
||||
}
|
||||
|
||||
if(t instanceof IrisFeaturePositional)
|
||||
{
|
||||
if (t instanceof IrisFeaturePositional) {
|
||||
chunk.addFeature((IrisFeaturePositional) t);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
} else {
|
||||
Matter matter = chunk.getOrCreate(y >> 4);
|
||||
matter.slice(matter.getClass(t)).set(x & 15, y & 15, z & 15, t);
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
} else {
|
||||
Iris.error("Mantle Writer[" + this.x + "," + this.z + ",R" + this.radius + "] Tried to access " + x + "," + y + "," + z + " (Chunk " + cx + "," + cz + ") which is OUT OF BOUNDS!");
|
||||
}
|
||||
}
|
||||
@ -144,6 +131,6 @@ public class MantleWriter implements IObjectPlacer
|
||||
|
||||
@Override
|
||||
public void setTile(int xx, int yy, int zz, TileData<? extends TileState> tile) {
|
||||
getEngineMantle().setTile(xx,yy,zz,tile);
|
||||
getEngineMantle().setTile(xx, yy, zz, tile);
|
||||
}
|
||||
}
|
||||
|
@ -18,7 +18,6 @@
|
||||
|
||||
package com.volmit.iris.engine.modifier;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.engine.framework.Engine;
|
||||
import com.volmit.iris.engine.framework.EngineAssignedModifier;
|
||||
import com.volmit.iris.engine.object.biome.IrisBiome;
|
||||
@ -26,11 +25,9 @@ import com.volmit.iris.engine.object.deposits.IrisDepositGenerator;
|
||||
import com.volmit.iris.engine.object.objects.IrisObject;
|
||||
import com.volmit.iris.engine.object.regional.IrisRegion;
|
||||
import com.volmit.iris.util.data.HeightMap;
|
||||
import com.volmit.iris.util.format.Form;
|
||||
import com.volmit.iris.util.hunk.Hunk;
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
import com.volmit.iris.util.parallel.BurstExecutor;
|
||||
import com.volmit.iris.util.parallel.MultiBurst;
|
||||
import com.volmit.iris.util.scheduling.PrecisionStopwatch;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.util.BlockVector;
|
||||
|
@ -19,26 +19,14 @@
|
||||
package com.volmit.iris.engine.modifier;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.engine.data.cache.AtomicCache;
|
||||
import com.volmit.iris.engine.data.cache.Cache;
|
||||
import com.volmit.iris.engine.framework.Engine;
|
||||
import com.volmit.iris.engine.framework.EngineAssignedModifier;
|
||||
import com.volmit.iris.engine.object.biome.IrisBiome;
|
||||
import com.volmit.iris.engine.object.common.CaveResult;
|
||||
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.format.Form;
|
||||
import com.volmit.iris.util.function.*;
|
||||
import com.volmit.iris.util.hunk.Hunk;
|
||||
import com.volmit.iris.util.hunk.storage.ArrayHunk;
|
||||
import com.volmit.iris.util.math.Average;
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
import com.volmit.iris.util.math.RollingSequence;
|
||||
import com.volmit.iris.util.parallel.BurstExecutor;
|
||||
import com.volmit.iris.util.scheduling.PrecisionStopwatch;
|
||||
import com.volmit.iris.util.stream.ProceduralStream;
|
||||
import com.volmit.iris.util.stream.interpolation.Interpolated;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.block.data.Levelled;
|
||||
@ -46,8 +34,6 @@ import org.bukkit.block.data.Waterlogged;
|
||||
import org.bukkit.block.data.type.Slab;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class IrisPostModifier extends EngineAssignedModifier<BlockData> {
|
||||
private static final BlockData AIR = B.get("AIR");
|
||||
|
@ -54,8 +54,9 @@ public class IrisPosition {
|
||||
public IrisPosition(Vector v) {
|
||||
this(v.getBlockX(), v.getBlockY(), v.getBlockZ());
|
||||
}
|
||||
|
||||
public IrisPosition(double x, double y, double z) {
|
||||
this((int)x,(int)y,(int)z);
|
||||
this((int) x, (int) y, (int) z);
|
||||
}
|
||||
|
||||
|
||||
|
@ -35,7 +35,6 @@ import com.volmit.iris.engine.object.jigsaw.IrisJigsawStructurePlacement;
|
||||
import com.volmit.iris.engine.object.loot.IrisLootReference;
|
||||
import com.volmit.iris.engine.object.meta.IrisEffect;
|
||||
import com.volmit.iris.engine.object.noise.IrisGeneratorStyle;
|
||||
import com.volmit.iris.engine.object.noise.IrisShapedGeneratorStyle;
|
||||
import com.volmit.iris.engine.object.noise.IrisSlopeClip;
|
||||
import com.volmit.iris.engine.object.noise.NoiseStyle;
|
||||
import com.volmit.iris.engine.object.objects.IrisObject;
|
||||
@ -198,8 +197,8 @@ public class IrisBiome extends IrisRegistrant implements IRare {
|
||||
private final transient AtomicCache<KMap<String, IrisBiomeGeneratorLink>> genCache = new AtomicCache<>();
|
||||
private final transient AtomicCache<KMap<String, Integer>> genCacheMax = new AtomicCache<>();
|
||||
private final transient AtomicCache<KMap<String, Integer>> genCacheMin = new AtomicCache<>();
|
||||
private final transient AtomicCache<KList<IrisObjectPlacement>> surfaceObjectsCache = new AtomicCache<>(false);
|
||||
private final transient AtomicCache<KList<IrisObjectPlacement>> carveObjectsCache = new AtomicCache<>(false);
|
||||
private final transient AtomicCache<KList<IrisObjectPlacement>> surfaceObjectsCache = new AtomicCache<>();
|
||||
private final transient AtomicCache<KList<IrisObjectPlacement>> carveObjectsCache = new AtomicCache<>();
|
||||
private final transient AtomicCache<Color> cacheColor = new AtomicCache<>();
|
||||
private final transient AtomicCache<Color> cacheColorObjectDensity = new AtomicCache<>();
|
||||
private final transient AtomicCache<Color> cacheColorDecoratorLoad = new AtomicCache<>();
|
||||
|
@ -18,26 +18,16 @@
|
||||
|
||||
package com.volmit.iris.engine.object.cave;
|
||||
|
||||
import com.volmit.iris.core.project.loader.IrisData;
|
||||
import com.volmit.iris.core.project.loader.IrisRegistrant;
|
||||
import com.volmit.iris.engine.object.annotations.Desc;
|
||||
import com.volmit.iris.engine.object.noise.IrisWorm;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.data.B;
|
||||
import com.volmit.iris.util.json.JSONObject;
|
||||
import com.volmit.iris.util.mantle.Mantle;
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
import com.volmit.iris.util.noise.Worm;
|
||||
import com.volmit.iris.util.noise.Worm3;
|
||||
import com.volmit.iris.util.noise.WormIterator3;
|
||||
import com.volmit.iris.util.plugin.VolmitSender;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Accessors(chain = true)
|
||||
|
@ -33,13 +33,11 @@ import com.volmit.iris.util.mantle.Mantle;
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
import com.volmit.iris.util.noise.Worm3;
|
||||
import com.volmit.iris.util.noise.WormIterator3;
|
||||
import com.volmit.iris.util.plugin.VolmitSender;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.util.BlockVector;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
@ -66,22 +64,18 @@ public class IrisCavePlacer implements IRare {
|
||||
private transient final AtomicCache<IrisCave> caveCache = new AtomicCache<>();
|
||||
private transient final AtomicBoolean fail = new AtomicBoolean(false);
|
||||
|
||||
public IrisCave getRealCave(IrisData data)
|
||||
{
|
||||
public IrisCave getRealCave(IrisData data) {
|
||||
return caveCache.aquire(() -> data.getCaveLoader().load(getCave()));
|
||||
}
|
||||
|
||||
public void generateCave(Mantle mantle, RNG rng, IrisData data, int x, int y, int z)
|
||||
{
|
||||
if(fail.get())
|
||||
{
|
||||
public void generateCave(Mantle mantle, RNG rng, IrisData data, int x, int y, int z) {
|
||||
if (fail.get()) {
|
||||
return;
|
||||
}
|
||||
|
||||
IrisCave cave = getRealCave(data);
|
||||
|
||||
if(cave == null)
|
||||
{
|
||||
if (cave == null) {
|
||||
Iris.warn("Unable to locate cave for generation!");
|
||||
fail.set(true);
|
||||
return;
|
||||
@ -90,8 +84,7 @@ public class IrisCavePlacer implements IRare {
|
||||
WormIterator3 w = cave.getWorm().iterate3D(rng, data, x, y, z);
|
||||
KList<Vector> points = new KList<>();
|
||||
int itr = 0;
|
||||
while(w.hasNext())
|
||||
{
|
||||
while (w.hasNext()) {
|
||||
itr++;
|
||||
Worm3 wx = w.next();
|
||||
points.add(new Vector(wx.getX().getPosition(), wx.getY().getPosition(), wx.getZ().getPosition()));
|
||||
|
@ -22,6 +22,7 @@ import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.core.project.loader.IrisData;
|
||||
import com.volmit.iris.core.service.StudioSVC;
|
||||
import com.volmit.iris.core.tools.IrisToolbelt;
|
||||
import com.volmit.iris.engine.framework.Engine;
|
||||
import com.volmit.iris.engine.object.dimensional.IrisDimension;
|
||||
import com.volmit.iris.engine.platform.BukkitChunkGenerator;
|
||||
import com.volmit.iris.engine.platform.HeadlessGenerator;
|
||||
@ -65,8 +66,21 @@ public class HeadlessWorld {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
public HeadlessGenerator generate() {
|
||||
return new HeadlessGenerator(this);
|
||||
Engine e = null;
|
||||
|
||||
if (getWorld().tryGetRealWorld()) {
|
||||
if (IrisToolbelt.isIrisWorld(getWorld().realWorld())) {
|
||||
e = IrisToolbelt.access(getWorld().realWorld()).getEngine();
|
||||
}
|
||||
}
|
||||
|
||||
if (e != null) {
|
||||
Iris.info("Using Existing Engine " + getWorld().name() + " for Headless Pregeneration.");
|
||||
}
|
||||
|
||||
return e != null ? new HeadlessGenerator(this, e) : new HeadlessGenerator(this);
|
||||
}
|
||||
|
||||
public World load() {
|
||||
@ -81,7 +95,8 @@ public class HeadlessWorld {
|
||||
}
|
||||
|
||||
public static HeadlessWorld from(World world) {
|
||||
return new HeadlessWorld(world.getName(), IrisToolbelt.access(world).getEngine().getTarget().getDimension(), world.getSeed());
|
||||
return new HeadlessWorld(world.getName(), IrisToolbelt.access(world)
|
||||
.getEngine().getTarget().getDimension(), world.getSeed());
|
||||
}
|
||||
|
||||
public static HeadlessWorld from(String name, String dimension, long seed) {
|
||||
|
@ -24,6 +24,7 @@ import com.volmit.iris.util.collection.KList;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Entity;
|
||||
@ -61,6 +62,21 @@ public class IrisWorld {
|
||||
.environment(world.getEnvironment());
|
||||
}
|
||||
|
||||
public boolean tryGetRealWorld() {
|
||||
if (hasRealWorld()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
World w = Bukkit.getWorld(name);
|
||||
|
||||
if (w != null) {
|
||||
realWorld = w;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean hasRealWorld() {
|
||||
return realWorld != null;
|
||||
}
|
||||
|
@ -22,7 +22,6 @@ import com.volmit.iris.core.project.loader.IrisData;
|
||||
import com.volmit.iris.engine.data.cache.AtomicCache;
|
||||
import com.volmit.iris.engine.object.annotations.*;
|
||||
import com.volmit.iris.engine.object.block.IrisBlockData;
|
||||
import com.volmit.iris.engine.object.noise.IrisGenerator;
|
||||
import com.volmit.iris.engine.object.objects.IrisObject;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
|
@ -39,7 +39,6 @@ import com.volmit.iris.engine.object.jigsaw.IrisJigsawStructure;
|
||||
import com.volmit.iris.engine.object.jigsaw.IrisJigsawStructurePlacement;
|
||||
import com.volmit.iris.engine.object.loot.IrisLootReference;
|
||||
import com.volmit.iris.engine.object.noise.IrisGeneratorStyle;
|
||||
import com.volmit.iris.engine.object.noise.IrisInterpolator;
|
||||
import com.volmit.iris.engine.object.noise.IrisShapedGeneratorStyle;
|
||||
import com.volmit.iris.engine.object.noise.NoiseStyle;
|
||||
import com.volmit.iris.engine.object.objects.IrisObjectPlacement;
|
||||
|
@ -105,21 +105,14 @@ public class IrisEntitySpawn implements IRare {
|
||||
};
|
||||
|
||||
if (l != null) {
|
||||
if(referenceSpawner.getAllowedLightLevels().getMin() > 0 || referenceSpawner.getAllowedLightLevels().getMax() < 15)
|
||||
{
|
||||
if(referenceSpawner.getAllowedLightLevels().contains(l.getBlock().getLightLevel()))
|
||||
{
|
||||
if (spawn100(gen, l) != null)
|
||||
{
|
||||
if (referenceSpawner.getAllowedLightLevels().getMin() > 0 || referenceSpawner.getAllowedLightLevels().getMax() < 15) {
|
||||
if (referenceSpawner.getAllowedLightLevels().contains(l.getBlock().getLightLevel())) {
|
||||
if (spawn100(gen, l) != null) {
|
||||
s++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
if (spawn100(gen, l) != null)
|
||||
{
|
||||
} else {
|
||||
if (spawn100(gen, l) != null) {
|
||||
s++;
|
||||
}
|
||||
}
|
||||
|
@ -65,13 +65,9 @@ public class IrisFeaturePositional {
|
||||
|
||||
public static IrisFeaturePositional read(DataInputStream s) throws IOException {
|
||||
String sx = s.readUTF();
|
||||
try
|
||||
{
|
||||
try {
|
||||
return new Gson().fromJson(sx, IrisFeaturePositional.class);
|
||||
}
|
||||
|
||||
catch(Throwable e)
|
||||
{
|
||||
} catch (Throwable e) {
|
||||
Iris.error(sx);
|
||||
e.printStackTrace();
|
||||
throw new IOException(e);
|
||||
|
@ -24,7 +24,6 @@ import com.volmit.iris.engine.data.cache.AtomicCache;
|
||||
import com.volmit.iris.engine.object.annotations.*;
|
||||
import com.volmit.iris.engine.object.common.IRare;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.context.IrisContext;
|
||||
import com.volmit.iris.util.interpolation.IrisInterpolation;
|
||||
import com.volmit.iris.util.json.JSONObject;
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
|
@ -18,7 +18,6 @@
|
||||
|
||||
package com.volmit.iris.engine.object.noise;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.core.project.loader.IrisData;
|
||||
import com.volmit.iris.engine.data.cache.AtomicCache;
|
||||
import com.volmit.iris.engine.object.annotations.Desc;
|
||||
|
@ -21,17 +21,8 @@ package com.volmit.iris.engine.object.noise;
|
||||
import com.volmit.iris.core.project.loader.IrisData;
|
||||
import com.volmit.iris.engine.data.cache.AtomicCache;
|
||||
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.basic.IrisRange;
|
||||
import com.volmit.iris.engine.object.common.IRare;
|
||||
import com.volmit.iris.engine.object.noise.IrisGeneratorStyle;
|
||||
import com.volmit.iris.engine.object.noise.IrisNoiseGenerator;
|
||||
import com.volmit.iris.engine.object.noise.IrisStyledRange;
|
||||
import com.volmit.iris.engine.object.noise.NoiseStyle;
|
||||
import com.volmit.iris.util.function.NoiseProvider;
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
import com.volmit.iris.util.noise.Worm;
|
||||
import com.volmit.iris.util.noise.WormIterator2;
|
||||
import com.volmit.iris.util.noise.WormIterator3;
|
||||
import lombok.AllArgsConstructor;
|
||||
@ -64,13 +55,11 @@ public class IrisWorm {
|
||||
|
||||
private transient final AtomicCache<NoiseProvider> angleProviderCache = new AtomicCache<>();
|
||||
|
||||
public NoiseProvider getAngleProvider(RNG rng, IrisData data)
|
||||
{
|
||||
public NoiseProvider getAngleProvider(RNG rng, IrisData data) {
|
||||
return angleProviderCache.aquire(() -> (xx, zz) -> angleStyle.create(rng, data).fitDouble(-0.5, 0.5, xx, zz) * segmentDistance.get(rng, xx, zz, data));
|
||||
}
|
||||
|
||||
public WormIterator2 iterate2D(RNG rng, IrisData data, int x, int z)
|
||||
{
|
||||
public WormIterator2 iterate2D(RNG rng, IrisData data, int x, int z) {
|
||||
return WormIterator2.builder()
|
||||
.maxDistance(maxDistance)
|
||||
.maxIterations(maxSegments == -1 ? maxDistance : maxSegments)
|
||||
@ -78,8 +67,7 @@ public class IrisWorm {
|
||||
.build();
|
||||
}
|
||||
|
||||
public WormIterator3 iterate3D(RNG rng, IrisData data, int x, int y, int z)
|
||||
{
|
||||
public WormIterator3 iterate3D(RNG rng, IrisData data, int x, int y, int z) {
|
||||
return WormIterator3.builder()
|
||||
.maxDistance(maxDistance)
|
||||
.maxIterations(maxSegments == -1 ? maxDistance : maxSegments)
|
||||
|
@ -34,7 +34,6 @@ import com.volmit.iris.engine.object.jigsaw.IrisJigsawStructurePlacement;
|
||||
import com.volmit.iris.engine.object.loot.IrisLootReference;
|
||||
import com.volmit.iris.engine.object.meta.IrisEffect;
|
||||
import com.volmit.iris.engine.object.noise.IrisGeneratorStyle;
|
||||
import com.volmit.iris.engine.object.noise.IrisShapedGeneratorStyle;
|
||||
import com.volmit.iris.engine.object.noise.NoiseStyle;
|
||||
import com.volmit.iris.engine.object.objects.IrisObjectPlacement;
|
||||
import com.volmit.iris.engine.object.spawners.IrisSpawner;
|
||||
|
@ -35,7 +35,6 @@ import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
|
@ -29,13 +29,11 @@ import com.volmit.iris.engine.framework.WrongEngineBroException;
|
||||
import com.volmit.iris.engine.object.common.IrisWorld;
|
||||
import com.volmit.iris.engine.object.dimensional.IrisDimension;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.format.C;
|
||||
import com.volmit.iris.util.hunk.Hunk;
|
||||
import com.volmit.iris.util.io.ReactiveFolder;
|
||||
import com.volmit.iris.util.scheduling.ChronoLatch;
|
||||
import com.volmit.iris.util.scheduling.J;
|
||||
import com.volmit.iris.util.scheduling.Looper;
|
||||
import com.volmit.iris.util.scheduling.PrecisionStopwatch;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.bukkit.Bukkit;
|
||||
@ -47,8 +45,6 @@ import org.bukkit.generator.BlockPopulator;
|
||||
import org.bukkit.generator.ChunkGenerator;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.management.RuntimeErrorException;
|
||||
import javax.swing.text.TableView;
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
@ -100,13 +96,11 @@ public class BukkitChunkGenerator extends ChunkGenerator implements PlatformChun
|
||||
IrisData data = IrisData.get(dataLocation);
|
||||
IrisDimension dimension = data.getDimensionLoader().load(dimensionKey);
|
||||
|
||||
if(dimension == null)
|
||||
{
|
||||
if (dimension == null) {
|
||||
Iris.error("Oh No! There's no pack in " + data.getDataFolder().getPath() + " or... there's no dimension for the key " + dimensionKey);
|
||||
IrisDimension test = IrisData.loadAnyDimension(dimensionKey);
|
||||
|
||||
if(test != null)
|
||||
{
|
||||
if (test != null) {
|
||||
Iris.warn("Looks like " + dimensionKey + " exists in " + test.getLoadFile().getPath());
|
||||
Iris.service(StudioSVC.class).installIntoWorld(Iris.getSender(), dimensionKey, dataLocation.getParentFile().getParentFile());
|
||||
Iris.warn("Attempted to install into " + data.getDataFolder().getPath());
|
||||
@ -114,21 +108,14 @@ public class BukkitChunkGenerator extends ChunkGenerator implements PlatformChun
|
||||
data.clearLists();
|
||||
test = data.getDimensionLoader().load(dimensionKey);
|
||||
|
||||
if(test != null)
|
||||
{
|
||||
if (test != null) {
|
||||
Iris.success("Woo! Patched the Engine!");
|
||||
dimension = test;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
} else {
|
||||
Iris.error("Failed to patch dimension!");
|
||||
throw new RuntimeException("Missing Dimension: " + dimensionKey);
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
} else {
|
||||
Iris.error("Nope, you don't have an installation containing " + dimensionKey + " try downloading it?");
|
||||
throw new RuntimeException("Missing Dimension: " + dimensionKey);
|
||||
}
|
||||
@ -161,8 +148,7 @@ public class BukkitChunkGenerator extends ChunkGenerator implements PlatformChun
|
||||
withExclusiveControl(() -> getEngine().hotload());
|
||||
}
|
||||
|
||||
public void withExclusiveControl(Runnable r)
|
||||
{
|
||||
public void withExclusiveControl(Runnable r) {
|
||||
J.a(() -> {
|
||||
try {
|
||||
loadLock.acquire(LOAD_LOCKS);
|
||||
@ -176,9 +162,10 @@ public class BukkitChunkGenerator extends ChunkGenerator implements PlatformChun
|
||||
|
||||
@Override
|
||||
public @NotNull ChunkData generateChunkData(@NotNull World world, @NotNull Random ignored, int x, int z, @NotNull BiomeGrid biome) {
|
||||
|
||||
|
||||
try {
|
||||
if(lastSeed != world.getSeed())
|
||||
{
|
||||
if (lastSeed != world.getSeed()) {
|
||||
Iris.warn("Seed for engine " + lastSeed + " does not match world seed if " + world.getSeed());
|
||||
lastSeed = world.getSeed();
|
||||
engine.getTarget().getWorld().seed(lastSeed);
|
||||
@ -196,29 +183,20 @@ public class BukkitChunkGenerator extends ChunkGenerator implements PlatformChun
|
||||
Iris.debug("Generated " + x + " " + z);
|
||||
loadLock.release();
|
||||
return c;
|
||||
}
|
||||
|
||||
catch (WrongEngineBroException e)
|
||||
{
|
||||
} catch (WrongEngineBroException e) {
|
||||
Iris.warn("Trying to generate with a shut-down engine! Did you reload? Attempting to resolve this...");
|
||||
|
||||
try
|
||||
{
|
||||
try {
|
||||
setupEngine();
|
||||
Iris.success("Resolved! Should generate now!");
|
||||
}
|
||||
|
||||
catch(Throwable fe)
|
||||
{
|
||||
} catch (Throwable fe) {
|
||||
Iris.error("FATAL! Iris cannot generate in this world since it was reloaded! This will cause a crash, with missing chunks, so we're crashing right now!");
|
||||
Bukkit.shutdown();
|
||||
throw new RuntimeException();
|
||||
}
|
||||
|
||||
return generateChunkData(world, ignored, x, z, biome);
|
||||
}
|
||||
|
||||
catch (Throwable e) {
|
||||
} catch (Throwable e) {
|
||||
loadLock.release();
|
||||
Iris.error("======================================");
|
||||
e.printStackTrace();
|
||||
|
@ -19,7 +19,6 @@
|
||||
package com.volmit.iris.engine.platform;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.core.IrisSettings;
|
||||
import com.volmit.iris.core.nms.INMS;
|
||||
import com.volmit.iris.core.pregenerator.PregenListener;
|
||||
import com.volmit.iris.core.pregenerator.PregenTask;
|
||||
@ -34,6 +33,7 @@ import com.volmit.iris.util.documentation.ChunkCoordinates;
|
||||
import com.volmit.iris.util.documentation.RegionCoordinates;
|
||||
import com.volmit.iris.util.hunk.Hunk;
|
||||
import com.volmit.iris.util.math.Position2;
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
import com.volmit.iris.util.nbt.mca.MCAFile;
|
||||
import com.volmit.iris.util.nbt.mca.MCAUtil;
|
||||
import com.volmit.iris.util.nbt.mca.NBTWorld;
|
||||
@ -56,12 +56,17 @@ public class HeadlessGenerator implements PlatformChunkGenerator {
|
||||
private final NBTWorld writer;
|
||||
private final MultiBurst burst;
|
||||
private final Engine engine;
|
||||
private final long rkey = RNG.r.lmax();
|
||||
|
||||
public HeadlessGenerator(HeadlessWorld world) {
|
||||
this(world, new IrisEngine(new EngineTarget(world.getWorld(), world.getDimension(), world.getDimension().getLoader()), world.isStudio()));
|
||||
}
|
||||
|
||||
public HeadlessGenerator(HeadlessWorld world, Engine engine) {
|
||||
this.engine = engine;
|
||||
this.world = world;
|
||||
burst = MultiBurst.burst;
|
||||
writer = new NBTWorld(world.getWorld().worldFolder());
|
||||
engine = new IrisEngine(new EngineTarget(world.getWorld(), world.getDimension(), world.getDimension().getLoader()), isStudio());
|
||||
}
|
||||
|
||||
@ChunkCoordinates
|
||||
@ -79,6 +84,7 @@ public class HeadlessGenerator implements PlatformChunkGenerator {
|
||||
getEngine().generate(x * 16, z * 16,
|
||||
Hunk.view((ChunkGenerator.ChunkData) tc), Hunk.view((ChunkGenerator.BiomeGrid) tc),
|
||||
false);
|
||||
chunk.cleanupPalettesAndBlockStates();
|
||||
} catch (Throwable e) {
|
||||
Iris.error("======================================");
|
||||
e.printStackTrace();
|
||||
@ -102,7 +108,7 @@ public class HeadlessGenerator implements PlatformChunkGenerator {
|
||||
@RegionCoordinates
|
||||
public void generateRegion(int x, int z, PregenListener listener) {
|
||||
BurstExecutor e = burst.burst(1024);
|
||||
MCAFile f = writer.getMCA(x, x);
|
||||
MCAFile f = writer.getMCA(x, z);
|
||||
PregenTask.iterateRegion(x, z, (ii, jj) -> e.queue(() -> {
|
||||
if (listener != null) {
|
||||
listener.onChunkGenerating(ii, jj);
|
||||
@ -132,7 +138,6 @@ public class HeadlessGenerator implements PlatformChunkGenerator {
|
||||
}
|
||||
|
||||
public void close() {
|
||||
getEngine().close();
|
||||
writer.close();
|
||||
}
|
||||
|
||||
|
@ -49,12 +49,10 @@ public class IrisContext {
|
||||
}
|
||||
|
||||
public static void dereference() {
|
||||
synchronized (context)
|
||||
{
|
||||
synchronized (context) {
|
||||
for (Thread i : context.k()) {
|
||||
if (!i.isAlive() || context.get(i).engine.isClosed()) {
|
||||
if(context.get(i).engine.isClosed())
|
||||
{
|
||||
if (context.get(i).engine.isClosed()) {
|
||||
Iris.debug("Dereferenced Context<Engine> " + i.getName() + " " + i.getId());
|
||||
}
|
||||
|
||||
|
@ -21,7 +21,6 @@ package com.volmit.iris.util.data;
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.core.IrisSettings;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.collection.KMap;
|
||||
import com.volmit.iris.util.scheduling.ChronoLatch;
|
||||
import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
|
||||
import it.unimi.dsi.fastutil.ints.IntSet;
|
||||
@ -284,8 +283,7 @@ public class B {
|
||||
return Material.valueOf(bdx.trim().toUpperCase());
|
||||
} catch (Throwable e) {
|
||||
Iris.reportError(e);
|
||||
if(clw.flip())
|
||||
{
|
||||
if (clw.flip()) {
|
||||
Iris.warn("Unknown Material: " + bdx);
|
||||
}
|
||||
return null;
|
||||
@ -295,8 +293,7 @@ public class B {
|
||||
public static Material getMaterial(String bdx) {
|
||||
Material m = getMaterialOrNull(bdx);
|
||||
|
||||
if(m == null)
|
||||
{
|
||||
if (m == null) {
|
||||
return AIR_MATERIAL;
|
||||
}
|
||||
|
||||
@ -313,8 +310,7 @@ public class B {
|
||||
BlockData bdx = parseBlockData(bd);
|
||||
|
||||
if (bdx == null) {
|
||||
if(clw.flip())
|
||||
{
|
||||
if (clw.flip()) {
|
||||
Iris.warn("Unknown Block Data '" + bd + "'");
|
||||
}
|
||||
return AIR;
|
||||
@ -324,8 +320,7 @@ public class B {
|
||||
} catch (Throwable e) {
|
||||
Iris.reportError(e);
|
||||
|
||||
if(clw.flip())
|
||||
{
|
||||
if (clw.flip()) {
|
||||
Iris.warn("Unknown Block Data '" + bdxf + "'");
|
||||
}
|
||||
}
|
||||
@ -363,8 +358,7 @@ public class B {
|
||||
|
||||
return bx;
|
||||
} catch (Throwable e) {
|
||||
if(clw.flip())
|
||||
{
|
||||
if (clw.flip()) {
|
||||
Iris.warn("Unknown Block Data: " + ix);
|
||||
}
|
||||
|
||||
|
@ -20,11 +20,9 @@ package com.volmit.iris.util.data;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.core.service.StudioSVC;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.format.Form;
|
||||
import com.volmit.iris.util.plugin.VolmitSender;
|
||||
import com.volmit.iris.util.scheduling.jobs.DownloadJob;
|
||||
import com.volmit.iris.util.scheduling.jobs.Job;
|
||||
import com.volmit.iris.util.scheduling.jobs.JobCollection;
|
||||
import com.volmit.iris.util.scheduling.jobs.SingleJob;
|
||||
import lombok.Builder;
|
||||
@ -111,8 +109,7 @@ public class IrisPackRepository {
|
||||
public void install(VolmitSender sender) throws MalformedURLException {
|
||||
File pack = Iris.instance.getDataFolder(StudioSVC.WORKSPACE_NAME, getRepo());
|
||||
|
||||
if(!pack.exists())
|
||||
{
|
||||
if (!pack.exists()) {
|
||||
File dl = new File(Iris.getTemp(), "dltk-" + UUID.randomUUID() + ".zip");
|
||||
File work = new File(Iris.getTemp(), "extk-" + UUID.randomUUID());
|
||||
new JobCollection(Form.capitalize(getRepo()),
|
||||
|
@ -44,18 +44,13 @@ public class DecreeParameter {
|
||||
|
||||
public DecreeParameterHandler<?> getHandler() {
|
||||
return handlerCache.aquire(() -> {
|
||||
try
|
||||
{
|
||||
if(param.customHandler().equals(DummyHandler.class))
|
||||
{
|
||||
try {
|
||||
if (param.customHandler().equals(DummyHandler.class)) {
|
||||
return DecreeSystem.getHandler(getType());
|
||||
}
|
||||
|
||||
return param.customHandler().getConstructor().newInstance();
|
||||
}
|
||||
|
||||
catch(Throwable e)
|
||||
{
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
@ -32,8 +32,7 @@ public interface DecreeParameterHandler<T> {
|
||||
*/
|
||||
KList<T> getPossibilities();
|
||||
|
||||
default boolean isDummy()
|
||||
{
|
||||
default boolean isDummy() {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -25,7 +25,6 @@ import com.volmit.iris.util.decree.DecreeSystem;
|
||||
import com.volmit.iris.util.decree.exceptions.DecreeParsingException;
|
||||
import com.volmit.iris.util.decree.exceptions.DecreeWhichException;
|
||||
import com.volmit.iris.util.format.Form;
|
||||
import com.volmit.iris.util.math.M;
|
||||
import com.volmit.iris.util.plugin.VolmitSender;
|
||||
import org.bukkit.FluidCollisionMode;
|
||||
import org.bukkit.entity.Player;
|
||||
|
@ -29,8 +29,7 @@ public class DummyHandler implements DecreeParameterHandler<Object> {
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isDummy()
|
||||
{
|
||||
public boolean isDummy() {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -16,21 +16,8 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.volmit.iris.util.hunk.io;
|
||||
package com.volmit.iris.util.function;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class BooleanHunkIOAdapter extends PaletteHunkIOAdapter<Boolean> {
|
||||
|
||||
@Override
|
||||
public void write(Boolean data, DataOutputStream dos) throws IOException {
|
||||
dos.writeBoolean(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean read(DataInputStream din) throws IOException {
|
||||
return din.readBoolean();
|
||||
}
|
||||
public interface NastySupplier<T> {
|
||||
T get() throws Throwable;
|
||||
}
|
@ -21,14 +21,12 @@ package com.volmit.iris.util.hunk;
|
||||
import com.volmit.iris.engine.object.basic.IrisPosition;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.function.*;
|
||||
import com.volmit.iris.util.hunk.io.HunkIOAdapter;
|
||||
import com.volmit.iris.util.hunk.storage.*;
|
||||
import com.volmit.iris.util.hunk.view.*;
|
||||
import com.volmit.iris.util.interpolation.InterpolationMethod;
|
||||
import com.volmit.iris.util.interpolation.InterpolationMethod3D;
|
||||
import com.volmit.iris.util.interpolation.IrisInterpolation;
|
||||
import com.volmit.iris.util.math.BlockPosition;
|
||||
import com.volmit.iris.util.oldnbt.ByteArrayTag;
|
||||
import com.volmit.iris.util.parallel.BurstExecutor;
|
||||
import com.volmit.iris.util.parallel.MultiBurst;
|
||||
import com.volmit.iris.util.stream.interpolation.Interpolated;
|
||||
@ -38,9 +36,7 @@ import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.generator.ChunkGenerator.BiomeGrid;
|
||||
import org.bukkit.generator.ChunkGenerator.ChunkData;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.Consumer;
|
||||
@ -229,18 +225,6 @@ public interface Hunk<T> {
|
||||
return count.get();
|
||||
}
|
||||
|
||||
default void write(OutputStream s, HunkIOAdapter<T> h) throws IOException {
|
||||
h.write(this, s);
|
||||
}
|
||||
|
||||
default ByteArrayTag writeByteArrayTag(HunkIOAdapter<T> h, String name) throws IOException {
|
||||
return h.writeByteArrayTag(this, name);
|
||||
}
|
||||
|
||||
default void write(File s, HunkIOAdapter<T> h) throws IOException {
|
||||
h.write(this, s);
|
||||
}
|
||||
|
||||
default boolean isAtomic() {
|
||||
return false;
|
||||
}
|
||||
@ -1450,8 +1434,7 @@ public interface Hunk<T> {
|
||||
return false;
|
||||
}
|
||||
|
||||
default boolean contains(int x, int y, int z)
|
||||
{
|
||||
default boolean contains(int x, int y, int z) {
|
||||
return x < getWidth() && x >= 0 && y < getHeight() && y >= 0 && z < getDepth() && z >= 0;
|
||||
}
|
||||
}
|
||||
|
@ -1,81 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2021 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.util.hunk.io;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.util.function.Function3;
|
||||
import com.volmit.iris.util.hunk.Hunk;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
public abstract class BasicHunkIOAdapter<T> implements HunkIOAdapter<T> {
|
||||
@Override
|
||||
public void write(Hunk<T> t, OutputStream out) throws IOException {
|
||||
DataOutputStream dos = new DataOutputStream(out);
|
||||
dos.writeShort(t.getWidth() + Short.MIN_VALUE);
|
||||
dos.writeShort(t.getHeight() + Short.MIN_VALUE);
|
||||
dos.writeShort(t.getDepth() + Short.MIN_VALUE);
|
||||
dos.writeInt(t.getNonNullEntries() + Integer.MIN_VALUE);
|
||||
|
||||
AtomicBoolean failure = new AtomicBoolean(false);
|
||||
t.iterate(0, (x, y, z, w) -> {
|
||||
if (w != null) {
|
||||
try {
|
||||
dos.writeShort(x + Short.MIN_VALUE);
|
||||
dos.writeShort(y + Short.MIN_VALUE);
|
||||
dos.writeShort(z + Short.MIN_VALUE);
|
||||
write(w, dos);
|
||||
} catch (Throwable e) {
|
||||
Iris.reportError(e);
|
||||
e.printStackTrace();
|
||||
failure.set(true);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
dos.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Hunk<T> read(Function3<Integer, Integer, Integer, Hunk<T>> factory, InputStream in) throws IOException {
|
||||
DataInputStream din = new DataInputStream(in);
|
||||
int w = din.readShort() - Short.MIN_VALUE;
|
||||
int h = din.readShort() - Short.MIN_VALUE;
|
||||
int d = din.readShort() - Short.MIN_VALUE;
|
||||
int e = din.readInt() - Integer.MIN_VALUE;
|
||||
Hunk<T> t = factory.apply(w, h, d);
|
||||
|
||||
for (int i = 0; i < e; i++) {
|
||||
int x = din.readShort() - Short.MIN_VALUE;
|
||||
int y = din.readShort() - Short.MIN_VALUE;
|
||||
int z = din.readShort() - Short.MIN_VALUE;
|
||||
T v = read(din);
|
||||
|
||||
if (v == null) {
|
||||
throw new IOException("NULL VALUE AT " + x + " " + y + " " + z);
|
||||
}
|
||||
|
||||
t.setRaw(x, y, z, v);
|
||||
}
|
||||
|
||||
in.close();
|
||||
return t;
|
||||
}
|
||||
}
|
@ -1,56 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2021 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.util.hunk.io;
|
||||
|
||||
import com.volmit.iris.util.data.IOAdapter;
|
||||
import com.volmit.iris.util.function.Function3;
|
||||
import com.volmit.iris.util.hunk.Hunk;
|
||||
import com.volmit.iris.util.io.CustomOutputStream;
|
||||
import com.volmit.iris.util.oldnbt.ByteArrayTag;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
|
||||
public interface HunkIOAdapter<T> extends IOAdapter<T> {
|
||||
void write(Hunk<T> t, OutputStream out) throws IOException;
|
||||
|
||||
Hunk<T> read(Function3<Integer, Integer, Integer, Hunk<T>> factory, InputStream in) throws IOException;
|
||||
|
||||
default void write(Hunk<T> t, File f) throws IOException {
|
||||
f.getParentFile().mkdirs();
|
||||
FileOutputStream fos = new FileOutputStream(f);
|
||||
GZIPOutputStream gzo = new CustomOutputStream(fos, 6);
|
||||
write(t, gzo);
|
||||
}
|
||||
|
||||
default Hunk<T> read(Function3<Integer, Integer, Integer, Hunk<T>> factory, File f) throws IOException {
|
||||
return read(factory, new GZIPInputStream(new FileInputStream(f)));
|
||||
}
|
||||
|
||||
default Hunk<T> read(Function3<Integer, Integer, Integer, Hunk<T>> factory, ByteArrayTag f) throws IOException {
|
||||
return read(factory, new ByteArrayInputStream(f.getValue()));
|
||||
}
|
||||
|
||||
default ByteArrayTag writeByteArrayTag(Hunk<T> tHunk, String name) throws IOException {
|
||||
ByteArrayOutputStream boas = new ByteArrayOutputStream();
|
||||
write(tHunk, boas);
|
||||
return new ByteArrayTag(name, boas.toByteArray());
|
||||
}
|
||||
}
|
@ -1,101 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2021 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.util.hunk.io;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.util.collection.KMap;
|
||||
import com.volmit.iris.util.oldnbt.CompoundTag;
|
||||
import com.volmit.iris.util.oldnbt.NBTInputStream;
|
||||
import com.volmit.iris.util.oldnbt.NBTOutputStream;
|
||||
import com.volmit.iris.util.oldnbt.Tag;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
@SuppressWarnings("SynchronizeOnNonFinalField")
|
||||
public class HunkRegion {
|
||||
private final File folder;
|
||||
private CompoundTag compound;
|
||||
private final int x;
|
||||
private final int z;
|
||||
|
||||
public HunkRegion(File folder, int x, int z, CompoundTag compound) {
|
||||
this.compound = fix(compound);
|
||||
this.folder = folder;
|
||||
this.x = x;
|
||||
this.z = z;
|
||||
folder.mkdirs();
|
||||
}
|
||||
|
||||
public HunkRegion(File folder, int x, int z) {
|
||||
this(folder, x, z, new CompoundTag(x + "." + z, new KMap<>()));
|
||||
File f = getFile();
|
||||
|
||||
if (f.exists()) {
|
||||
try {
|
||||
NBTInputStream in = new NBTInputStream(new FileInputStream(f));
|
||||
compound = fix((CompoundTag) in.readTag());
|
||||
in.close();
|
||||
} catch (Throwable e) {
|
||||
Iris.reportError(e);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public CompoundTag getCompound() {
|
||||
return compound;
|
||||
}
|
||||
|
||||
private CompoundTag fix(CompoundTag readTag) {
|
||||
Map<String, Tag> v = readTag.getValue();
|
||||
|
||||
if (!(v instanceof KMap)) {
|
||||
return new CompoundTag(readTag.getName(), new KMap<>(v));
|
||||
}
|
||||
|
||||
return readTag;
|
||||
}
|
||||
|
||||
public File getFile() {
|
||||
return new File(folder, x + "." + z + ".dat");
|
||||
}
|
||||
|
||||
public void save() throws IOException {
|
||||
synchronized (compound) {
|
||||
File f = getFile();
|
||||
FileOutputStream fos = new FileOutputStream(f);
|
||||
NBTOutputStream out = new NBTOutputStream(fos);
|
||||
out.writeTag(compound);
|
||||
out.close();
|
||||
}
|
||||
}
|
||||
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public int getZ() {
|
||||
return z;
|
||||
}
|
||||
|
||||
}
|
@ -1,262 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2021 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.util.hunk.io;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.engine.object.tile.TileData;
|
||||
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.function.Function2;
|
||||
import com.volmit.iris.util.function.Function3;
|
||||
import com.volmit.iris.util.hunk.Hunk;
|
||||
import com.volmit.iris.util.math.M;
|
||||
import com.volmit.iris.util.math.Position2;
|
||||
import com.volmit.iris.util.oldnbt.ByteArrayTag;
|
||||
import com.volmit.iris.util.oldnbt.CompoundTag;
|
||||
import com.volmit.iris.util.oldnbt.Tag;
|
||||
import com.volmit.iris.util.parallel.MultiBurst;
|
||||
import org.bukkit.block.TileState;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
public class HunkRegionSlice<T> {
|
||||
public static final Function2<Integer, CompoundTag, HunkRegionSlice<BlockData>> BLOCKDATA = (h, c) -> new HunkRegionSlice<>(h, Hunk::newMappedHunk, new BlockDataHunkIOAdapter(), c, "blockdata");
|
||||
public static final Function2<Integer, CompoundTag, HunkRegionSlice<TileData<? extends TileState>>> TILE = (h, c) -> new HunkRegionSlice<>(h, Hunk::newMappedHunk, new TileDataHunkIOAdapter(), c, "tile");
|
||||
public static final Function3<Integer, CompoundTag, String, HunkRegionSlice<String>> STRING = (h, c, t) -> new HunkRegionSlice<>(h, Hunk::newMappedHunk, new StringHunkIOAdapter(), c, t);
|
||||
public static final Function3<Integer, CompoundTag, String, HunkRegionSlice<Boolean>> BOOLEAN = (h, c, t) -> new HunkRegionSlice<>(h, Hunk::newMappedHunk, new BooleanHunkIOAdapter(), c, t);
|
||||
private final Function3<Integer, Integer, Integer, Hunk<T>> factory;
|
||||
private final HunkIOAdapter<T> adapter;
|
||||
private final CompoundTag compound;
|
||||
private final String key;
|
||||
private final KMap<Position2, Hunk<T>> loadedChunks;
|
||||
private final KMap<Position2, Long> lastUse;
|
||||
private final KSet<Position2> save;
|
||||
private final int height;
|
||||
|
||||
public HunkRegionSlice(int height, Function3<Integer, Integer, Integer, Hunk<T>> factory, HunkIOAdapter<T> adapter, CompoundTag compound, String key) {
|
||||
this.height = height;
|
||||
this.loadedChunks = new KMap<>();
|
||||
this.factory = factory;
|
||||
this.adapter = adapter;
|
||||
this.compound = compound;
|
||||
this.save = new KSet<>();
|
||||
this.key = key;
|
||||
this.lastUse = new KMap<>();
|
||||
}
|
||||
|
||||
public synchronized int cleanup(long t) {
|
||||
int v = 0;
|
||||
if (loadedChunks.size() != lastUse.size()) {
|
||||
Iris.warn("Incorrect chunk use counts in " + key + " region slice.");
|
||||
|
||||
for (Position2 i : lastUse.k()) {
|
||||
if (!loadedChunks.containsKey(i)) {
|
||||
Iris.warn(" Missing LoadChunkKey " + i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (Position2 i : lastUse.k()) {
|
||||
Long l = lastUse.get(i);
|
||||
if (l == null || M.ms() - l > t) {
|
||||
v++;
|
||||
MultiBurst.burst.lazy(() -> {
|
||||
unload(i.getX(), i.getZ());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
public synchronized void clear() {
|
||||
for (String i : new KList<>(compound.getValue().keySet())) {
|
||||
if (i.startsWith(key + ".")) {
|
||||
compound.getValue().remove(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void save(MultiBurst burst) {
|
||||
|
||||
try {
|
||||
for (Position2 i : save.copy()) {
|
||||
if (i == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
save(i.getX(), i.getZ());
|
||||
|
||||
try {
|
||||
save.remove(i);
|
||||
} catch (Throwable eer) {
|
||||
Iris.reportError(eer);
|
||||
}
|
||||
}
|
||||
} catch (Throwable ee) {
|
||||
Iris.reportError(ee);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean contains(int x, int z) {
|
||||
return compound.getValue().containsKey(key(x, z));
|
||||
}
|
||||
|
||||
public void delete(int x, int z) {
|
||||
compound.getValue().remove(key(x, z));
|
||||
}
|
||||
|
||||
public Hunk<T> read(int x, int z) throws IOException {
|
||||
AtomicReference<IOException> e = new AtomicReference<>();
|
||||
Hunk<T> xt = null;
|
||||
|
||||
Tag t = compound.getValue().get(key(x, z));
|
||||
|
||||
if ((t instanceof ByteArrayTag)) {
|
||||
try {
|
||||
xt = adapter.read(factory, (ByteArrayTag) t);
|
||||
} catch (IOException xe) {
|
||||
Iris.reportError(xe);
|
||||
e.set(xe);
|
||||
}
|
||||
}
|
||||
|
||||
if (xt != null) {
|
||||
return xt;
|
||||
}
|
||||
|
||||
if (e.get() != null) {
|
||||
throw e.get();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void write(Hunk<T> hunk, int x, int z) throws IOException {
|
||||
compound.getValue().put(key(x, z), hunk.writeByteArrayTag(adapter, key(x, z)));
|
||||
}
|
||||
|
||||
public synchronized int unloadAll() {
|
||||
int v = 0;
|
||||
for (Position2 i : loadedChunks.k()) {
|
||||
unload(i.getX(), i.getZ());
|
||||
v++;
|
||||
}
|
||||
|
||||
save.clear();
|
||||
loadedChunks.clear();
|
||||
lastUse.clear();
|
||||
return v;
|
||||
}
|
||||
|
||||
public void save(Hunk<T> region, int x, int z) {
|
||||
try {
|
||||
write(region, x, z);
|
||||
} catch (IOException e) {
|
||||
Iris.reportError(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isLoaded(int x, int z) {
|
||||
return loadedChunks.containsKey(new Position2(x, z));
|
||||
}
|
||||
|
||||
public void save(int x, int z) {
|
||||
if (isLoaded(x, z)) {
|
||||
save(get(x, z), x, z);
|
||||
}
|
||||
}
|
||||
|
||||
public void unload(int x, int z) {
|
||||
Position2 key = new Position2(x, z);
|
||||
if (isLoaded(x, z)) {
|
||||
if (save.contains(key)) {
|
||||
save(x, z);
|
||||
save.remove(key);
|
||||
}
|
||||
|
||||
lastUse.remove(key);
|
||||
loadedChunks.remove(key);
|
||||
}
|
||||
}
|
||||
|
||||
public Hunk<T> load(int x, int z) {
|
||||
if (isLoaded(x, z)) {
|
||||
return loadedChunks.get(new Position2(x, z));
|
||||
}
|
||||
|
||||
Hunk<T> v = null;
|
||||
|
||||
if (contains(x, z)) {
|
||||
try {
|
||||
v = read(x, z);
|
||||
} catch (IOException e) {
|
||||
Iris.reportError(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
if (v == null) {
|
||||
v = factory.apply(16, height, 16);
|
||||
}
|
||||
|
||||
loadedChunks.put(new Position2(x, z), v);
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
public Hunk<T> get(int x, int z) {
|
||||
Position2 key = new Position2(x, z);
|
||||
|
||||
Hunk<T> c = loadedChunks.get(key);
|
||||
|
||||
if (c == null) {
|
||||
c = load(x, z);
|
||||
}
|
||||
|
||||
lastUse.put(new Position2(x, z), M.ms());
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
public Hunk<T> getR(int x, int z) {
|
||||
return get(x, z).readOnly();
|
||||
}
|
||||
|
||||
public Hunk<T> getRW(int x, int z) {
|
||||
save.add(new Position2(x, z));
|
||||
return get(x, z);
|
||||
}
|
||||
|
||||
private String key(int x, int z) {
|
||||
if (x < 0 || x >= 32 || z < 0 || z >= 32) {
|
||||
throw new IndexOutOfBoundsException("The chunk " + x + " " + z + " is out of bounds max is 31x31");
|
||||
}
|
||||
|
||||
return key + "." + x + "." + z;
|
||||
}
|
||||
|
||||
public int getLoadCount() {
|
||||
return loadedChunks.size();
|
||||
}
|
||||
}
|
@ -1,97 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2021 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.util.hunk.io;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.util.data.DataPalette;
|
||||
import com.volmit.iris.util.function.Function3;
|
||||
import com.volmit.iris.util.hunk.Hunk;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public abstract class PaletteHunkIOAdapter<T> implements HunkIOAdapter<T> {
|
||||
@Override
|
||||
public void write(Hunk<T> t, OutputStream out) throws IOException {
|
||||
DataOutputStream dos = new DataOutputStream(out);
|
||||
dos.writeShort(t.getWidth() + Short.MIN_VALUE);
|
||||
dos.writeShort(t.getHeight() + Short.MIN_VALUE);
|
||||
dos.writeShort(t.getDepth() + Short.MIN_VALUE);
|
||||
AtomicInteger nonNull = new AtomicInteger(0);
|
||||
DataPalette<T> palette = new DataPalette<>();
|
||||
|
||||
t.iterateSync((x, y, z, w) -> {
|
||||
if (w != null) {
|
||||
palette.getIndex(w);
|
||||
nonNull.getAndAdd(1);
|
||||
}
|
||||
});
|
||||
|
||||
palette.write(this, dos);
|
||||
dos.writeInt(nonNull.get() + Integer.MIN_VALUE);
|
||||
AtomicBoolean failure = new AtomicBoolean(false);
|
||||
t.iterateSync((x, y, z, w) -> {
|
||||
if (w != null) {
|
||||
try {
|
||||
dos.writeShort(x + Short.MIN_VALUE);
|
||||
dos.writeShort(y + Short.MIN_VALUE);
|
||||
dos.writeShort(z + Short.MIN_VALUE);
|
||||
dos.writeShort(palette.getIndex(w) + Short.MIN_VALUE);
|
||||
} catch (Throwable e) {
|
||||
Iris.reportError(e);
|
||||
e.printStackTrace();
|
||||
failure.set(true);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
dos.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Hunk<T> read(Function3<Integer, Integer, Integer, Hunk<T>> factory, InputStream in) throws IOException {
|
||||
DataInputStream din = new DataInputStream(in);
|
||||
int w = din.readShort() - Short.MIN_VALUE;
|
||||
int h = din.readShort() - Short.MIN_VALUE;
|
||||
int d = din.readShort() - Short.MIN_VALUE;
|
||||
DataPalette<T> palette = DataPalette.getPalette(this, din);
|
||||
int e = din.readInt() - Integer.MIN_VALUE;
|
||||
Hunk<T> t = factory.apply(w, h, d);
|
||||
|
||||
for (int i = 0; i < e; i++) {
|
||||
int x = din.readShort() - Short.MIN_VALUE;
|
||||
int y = din.readShort() - Short.MIN_VALUE;
|
||||
int z = din.readShort() - Short.MIN_VALUE;
|
||||
int vf = din.readShort() - Short.MIN_VALUE;
|
||||
|
||||
T v = null;
|
||||
if (palette.getPalette().hasIndex(vf)) {
|
||||
v = palette.getPalette().get(vf);
|
||||
}
|
||||
|
||||
if (v != null) {
|
||||
t.setRaw(x, y, z, v);
|
||||
}
|
||||
}
|
||||
|
||||
in.close();
|
||||
return t;
|
||||
}
|
||||
}
|
@ -1,45 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2021 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.util.hunk.io;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.engine.object.tile.TileData;
|
||||
import org.bukkit.block.TileState;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class TileDataHunkIOAdapter extends PaletteHunkIOAdapter<TileData<? extends TileState>> {
|
||||
@Override
|
||||
public void write(TileData<? extends TileState> data, DataOutputStream dos) throws IOException {
|
||||
data.toBinary(dos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileData<? extends TileState> read(DataInputStream din) throws IOException {
|
||||
try {
|
||||
return TileData.read(din);
|
||||
} catch (Throwable e) {
|
||||
Iris.reportError(e);
|
||||
e.printStackTrace();
|
||||
throw new IOException();
|
||||
}
|
||||
}
|
||||
}
|
@ -18,7 +18,6 @@
|
||||
|
||||
package com.volmit.iris.util.hunk.storage;
|
||||
|
||||
import com.volmit.iris.util.collection.KMap;
|
||||
import com.volmit.iris.util.function.Consumer4;
|
||||
import com.volmit.iris.util.function.Consumer4IO;
|
||||
import com.volmit.iris.util.hunk.Hunk;
|
||||
@ -49,15 +48,14 @@ public class MappedSyncHunk<T> extends StorageHunk<T> implements Hunk<T> {
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
synchronized(data)
|
||||
{
|
||||
synchronized (data) {
|
||||
return data.isEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRaw(int x, int y, int z, T t) {
|
||||
synchronized(data) {
|
||||
synchronized (data) {
|
||||
if (t == null) {
|
||||
data.remove(index(x, y, z));
|
||||
return;
|
||||
@ -73,8 +71,7 @@ public class MappedSyncHunk<T> extends StorageHunk<T> implements Hunk<T> {
|
||||
|
||||
@Override
|
||||
public synchronized Hunk<T> iterateSync(Consumer4<Integer, Integer, Integer, T> c) {
|
||||
synchronized(data)
|
||||
{
|
||||
synchronized (data) {
|
||||
int idx, z;
|
||||
|
||||
for (Map.Entry<Integer, T> g : data.entrySet()) {
|
||||
@ -90,8 +87,7 @@ public class MappedSyncHunk<T> extends StorageHunk<T> implements Hunk<T> {
|
||||
|
||||
@Override
|
||||
public synchronized Hunk<T> iterateSyncIO(Consumer4IO<Integer, Integer, Integer, T> c) throws IOException {
|
||||
synchronized(data)
|
||||
{
|
||||
synchronized (data) {
|
||||
int idx, z;
|
||||
|
||||
for (Map.Entry<Integer, T> g : data.entrySet()) {
|
||||
@ -107,16 +103,14 @@ public class MappedSyncHunk<T> extends StorageHunk<T> implements Hunk<T> {
|
||||
|
||||
@Override
|
||||
public void empty(T b) {
|
||||
synchronized(data)
|
||||
{
|
||||
synchronized (data) {
|
||||
data.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getRaw(int x, int y, int z) {
|
||||
synchronized(data)
|
||||
{
|
||||
synchronized (data) {
|
||||
return data.get(index(x, y, z));
|
||||
}
|
||||
}
|
||||
|
@ -45,7 +45,6 @@ import org.bukkit.util.Vector;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
@ -90,10 +89,11 @@ public class Mantle {
|
||||
|
||||
/**
|
||||
* Raise a flag if it is lowered currently, If the flag was raised, execute the runnable
|
||||
* @param x the chunk x
|
||||
* @param z the chunk z
|
||||
*
|
||||
* @param x the chunk x
|
||||
* @param z the chunk z
|
||||
* @param flag the flag to raise
|
||||
* @param r the runnable to fire if the flag is now raised (and was previously lowered)
|
||||
* @param r the runnable to fire if the flag is now raised (and was previously lowered)
|
||||
*/
|
||||
@ChunkCoordinates
|
||||
public void raiseFlag(int x, int z, MantleFlag flag, Runnable r) {
|
||||
@ -106,23 +106,24 @@ public class Mantle {
|
||||
/**
|
||||
* Obtain a cached writer which only contains cached chunks.
|
||||
* This avoids locking on regions when writing to lots of chunks
|
||||
* @param x the x chunk
|
||||
* @param z the z chunk
|
||||
*
|
||||
* @param x the x chunk
|
||||
* @param z the z chunk
|
||||
* @param radius the radius chunks
|
||||
* @return the writer
|
||||
*/
|
||||
@ChunkCoordinates
|
||||
public MantleWriter write(EngineMantle engineMantle, int x, int z, int radius)
|
||||
{
|
||||
public MantleWriter write(EngineMantle engineMantle, int x, int z, int radius) {
|
||||
return new MantleWriter(engineMantle, this, x, z, radius);
|
||||
}
|
||||
|
||||
/**
|
||||
* Lower a flag if it is raised. If the flag was lowered (meaning it was previously raised), execute the runnable
|
||||
* @param x the chunk x
|
||||
* @param z the chunk z
|
||||
*
|
||||
* @param x the chunk x
|
||||
* @param z the chunk z
|
||||
* @param flag the flag to lower
|
||||
* @param r the runnable that is fired if the flag was raised but is now lowered
|
||||
* @param r the runnable that is fired if the flag was raised but is now lowered
|
||||
*/
|
||||
@ChunkCoordinates
|
||||
public void lowerFlag(int x, int z, MantleFlag flag, Runnable r) {
|
||||
@ -133,16 +134,16 @@ public class Mantle {
|
||||
}
|
||||
|
||||
@ChunkCoordinates
|
||||
public MantleChunk getChunk(int x, int z)
|
||||
{
|
||||
return get(x>>5, z>>5).getOrCreate(x & 31, z & 31);
|
||||
public MantleChunk getChunk(int x, int z) {
|
||||
return get(x >> 5, z >> 5).getOrCreate(x & 31, z & 31);
|
||||
}
|
||||
|
||||
/**
|
||||
* Flag or unflag a chunk
|
||||
* @param x the chunk x
|
||||
* @param z the chunk z
|
||||
* @param flag the flag
|
||||
*
|
||||
* @param x the chunk x
|
||||
* @param z the chunk z
|
||||
* @param flag the flag
|
||||
* @param flagged should it be set to flagged or not
|
||||
*/
|
||||
@ChunkCoordinates
|
||||
@ -152,29 +153,29 @@ public class Mantle {
|
||||
|
||||
/**
|
||||
* Check very quickly if a tectonic plate exists via cached or the file system
|
||||
*
|
||||
* @param x the x region coordinate
|
||||
* @param z the z region coordinate
|
||||
* @return true if it exists
|
||||
*/
|
||||
@RegionCoordinates
|
||||
public boolean hasTectonicPlate(int x, int z)
|
||||
{
|
||||
public boolean hasTectonicPlate(int x, int z) {
|
||||
Long k = key(x, z);
|
||||
return loadedRegions.containsKey(k) || fileForRegion(dataFolder, k).exists();
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterate data in a chunk
|
||||
* @param x the chunk x
|
||||
* @param z the chunk z
|
||||
* @param type the type of data to iterate
|
||||
*
|
||||
* @param x the chunk x
|
||||
* @param z the chunk z
|
||||
* @param type the type of data to iterate
|
||||
* @param iterator the iterator (x,y,z,data) -> do stuff
|
||||
* @param <T> the type of data to iterate
|
||||
* @param <T> the type of data to iterate
|
||||
*/
|
||||
@ChunkCoordinates
|
||||
public <T> void iterateChunk(int x, int z, Class<T> type, Consumer4<Integer, Integer, Integer, T> iterator) {
|
||||
if(!hasTectonicPlate(x >> 5, z >> 5))
|
||||
{
|
||||
if (!hasTectonicPlate(x >> 5, z >> 5)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -183,15 +184,15 @@ public class Mantle {
|
||||
|
||||
/**
|
||||
* Does this chunk have a flag on it?
|
||||
* @param x the x
|
||||
* @param z the z
|
||||
*
|
||||
* @param x the x
|
||||
* @param z the z
|
||||
* @param flag the flag to test
|
||||
* @return true if it's flagged
|
||||
*/
|
||||
@ChunkCoordinates
|
||||
public boolean hasFlag(int x, int z, MantleFlag flag) {
|
||||
if(!hasTectonicPlate(x >> 5, z >> 5))
|
||||
{
|
||||
if (!hasTectonicPlate(x >> 5, z >> 5)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -222,14 +223,10 @@ public class Mantle {
|
||||
return;
|
||||
}
|
||||
|
||||
if(t instanceof IrisFeaturePositional)
|
||||
{
|
||||
if (t instanceof IrisFeaturePositional) {
|
||||
get((x >> 4) >> 5, (z >> 4) >> 5)
|
||||
.getOrCreate((x >> 4) & 31, (z >> 4) & 31).addFeature((IrisFeaturePositional) t);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
} else {
|
||||
Matter matter = get((x >> 4) >> 5, (z >> 4) >> 5)
|
||||
.getOrCreate((x >> 4) & 31, (z >> 4) & 31)
|
||||
.getOrCreate(y >> 4);
|
||||
@ -260,8 +257,7 @@ public class Mantle {
|
||||
throw new RuntimeException("The Mantle is closed");
|
||||
}
|
||||
|
||||
if(!hasTectonicPlate((x >> 4) >> 5, (z >> 4) >> 5))
|
||||
{
|
||||
if (!hasTectonicPlate((x >> 4) >> 5, (z >> 4) >> 5)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -277,10 +273,10 @@ public class Mantle {
|
||||
|
||||
/**
|
||||
* Is this mantle closed
|
||||
*
|
||||
* @return true if it is
|
||||
*/
|
||||
public boolean isClosed()
|
||||
{
|
||||
public boolean isClosed() {
|
||||
return closed.get();
|
||||
}
|
||||
|
||||
@ -307,13 +303,9 @@ public class Mantle {
|
||||
});
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
try {
|
||||
b.complete();
|
||||
}
|
||||
|
||||
catch(Throwable e)
|
||||
{
|
||||
} catch (Throwable e) {
|
||||
Iris.reportError(e);
|
||||
}
|
||||
|
||||
@ -457,9 +449,10 @@ public class Mantle {
|
||||
|
||||
/**
|
||||
* Get the file for a region
|
||||
*
|
||||
* @param folder the folder
|
||||
* @param x the x coord
|
||||
* @param z the z coord
|
||||
* @param x the x coord
|
||||
* @param z the z coord
|
||||
* @return the file
|
||||
*/
|
||||
public static File fileForRegion(File folder, int x, int z) {
|
||||
@ -468,14 +461,14 @@ public class Mantle {
|
||||
|
||||
/**
|
||||
* Get the file for the given region
|
||||
*
|
||||
* @param folder the data folder
|
||||
* @param key the region key
|
||||
* @param key the region key
|
||||
* @return the file
|
||||
*/
|
||||
public static File fileForRegion(File folder, Long key) {
|
||||
File f = new File(folder, "p." + key + ".ttp");
|
||||
if(!f.getParentFile().exists())
|
||||
{
|
||||
if (!f.getParentFile().exists()) {
|
||||
f.getParentFile().mkdirs();
|
||||
}
|
||||
return f;
|
||||
@ -483,6 +476,7 @@ public class Mantle {
|
||||
|
||||
/**
|
||||
* Get the long value representing a chunk or region coordinate
|
||||
*
|
||||
* @param x the x
|
||||
* @param z the z
|
||||
* @return the value
|
||||
@ -497,33 +491,33 @@ public class Mantle {
|
||||
|
||||
/**
|
||||
* Set a sphere into the mantle
|
||||
* @param cx the center x
|
||||
* @param cy the center y
|
||||
* @param cz the center z
|
||||
*
|
||||
* @param cx the center x
|
||||
* @param cy the center y
|
||||
* @param cz the center z
|
||||
* @param radius the radius of this sphere
|
||||
* @param fill should it be filled? or just the outer shell?
|
||||
* @param data the data to set
|
||||
* @param <T> the type of data to apply to the mantle
|
||||
* @param fill should it be filled? or just the outer shell?
|
||||
* @param data the data to set
|
||||
* @param <T> the type of data to apply to the mantle
|
||||
*/
|
||||
public <T> void setSphere(int cx, int cy, int cz, double radius, boolean fill, T data)
|
||||
{
|
||||
public <T> void setSphere(int cx, int cy, int cz, double radius, boolean fill, T data) {
|
||||
setElipsoid(cx, cy, cz, radius, radius, radius, fill, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set an elipsoid into the mantle
|
||||
* @param cx the center x
|
||||
* @param cy the center y
|
||||
* @param cz the center z
|
||||
* @param rx the x radius
|
||||
* @param ry the y radius
|
||||
* @param rz the z radius
|
||||
*
|
||||
* @param cx the center x
|
||||
* @param cy the center y
|
||||
* @param cz the center z
|
||||
* @param rx the x radius
|
||||
* @param ry the y radius
|
||||
* @param rz the z radius
|
||||
* @param fill should it be filled or just the outer shell?
|
||||
* @param data the data to set
|
||||
* @param <T> the type of data to apply to the mantle
|
||||
* @param <T> the type of data to apply to the mantle
|
||||
*/
|
||||
public <T> void setElipsoid(int cx, int cy, int cz, double rx, double ry, double rz, boolean fill, T data)
|
||||
{
|
||||
public <T> void setElipsoid(int cx, int cy, int cz, double rx, double ry, double rz, boolean fill, T data) {
|
||||
rx += 0.5;
|
||||
ry += 0.5;
|
||||
rz += 0.5;
|
||||
@ -535,11 +529,13 @@ public class Mantle {
|
||||
final int ceilRadiusZ = (int) Math.ceil(rz);
|
||||
double nextXn = 0;
|
||||
|
||||
forX: for (int x = 0; x <= ceilRadiusX; ++x) {
|
||||
forX:
|
||||
for (int x = 0; x <= ceilRadiusX; ++x) {
|
||||
final double xn = nextXn;
|
||||
nextXn = (x + 1) * invRadiusX;
|
||||
double nextYn = 0;
|
||||
forY: for (int y = 0; y <= ceilRadiusY; ++y) {
|
||||
forY:
|
||||
for (int y = 0; y <= ceilRadiusY; ++y) {
|
||||
final double yn = nextYn;
|
||||
nextYn = (y + 1) * invRadiusY;
|
||||
double nextZn = 0;
|
||||
@ -564,15 +560,15 @@ public class Mantle {
|
||||
}
|
||||
}
|
||||
|
||||
set(x + cx,y + cy,z + cz, data);
|
||||
set(-x + cx,y + cy,z + cz, data);
|
||||
set(x + cx,-y + cy,z + cz, data);
|
||||
set(x + cx,y + cy,-z + cz, data);
|
||||
set(-x + cx,y + cy,-z + cz, data);
|
||||
set(-x + cx,-y + cy,z + cz, data);
|
||||
set(x + cx,-y + cy,-z + cz, data);
|
||||
set(-x + cx,y + cy,-z + cz, data);
|
||||
set(-x + cx,-y + cy,-z + cz, data);
|
||||
set(x + cx, y + cy, z + cz, data);
|
||||
set(-x + cx, y + cy, z + cz, data);
|
||||
set(x + cx, -y + cy, z + cz, data);
|
||||
set(x + cx, y + cy, -z + cz, data);
|
||||
set(-x + cx, y + cy, -z + cz, data);
|
||||
set(-x + cx, -y + cy, z + cz, data);
|
||||
set(x + cx, -y + cy, -z + cz, data);
|
||||
set(-x + cx, y + cy, -z + cz, data);
|
||||
set(-x + cx, -y + cy, -z + cz, data);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -580,26 +576,23 @@ public class Mantle {
|
||||
|
||||
/**
|
||||
* Set a cuboid of data in the mantle
|
||||
* @param x1 the min x
|
||||
* @param y1 the min y
|
||||
* @param z1 the min z
|
||||
* @param x2 the max x
|
||||
* @param y2 the max y
|
||||
* @param z2 the max z
|
||||
*
|
||||
* @param x1 the min x
|
||||
* @param y1 the min y
|
||||
* @param z1 the min z
|
||||
* @param x2 the max x
|
||||
* @param y2 the max y
|
||||
* @param z2 the max z
|
||||
* @param data the data to set
|
||||
* @param <T> the type of data to apply to the mantle
|
||||
* @param <T> the type of data to apply to the mantle
|
||||
*/
|
||||
public <T> void setCuboid(int x1, int y1, int z1, int x2, int y2, int z2, T data)
|
||||
{
|
||||
int j,k;
|
||||
public <T> void setCuboid(int x1, int y1, int z1, int x2, int y2, int z2, T data) {
|
||||
int j, k;
|
||||
|
||||
for(int i = x1; i <= x2; i++)
|
||||
{
|
||||
for(j = x1; j <= x2; j++)
|
||||
{
|
||||
for(k = x1; k <= x2; k++)
|
||||
{
|
||||
set(i,j,k,data);
|
||||
for (int i = x1; i <= x2; i++) {
|
||||
for (j = x1; j <= x2; j++) {
|
||||
for (k = x1; k <= x2; k++) {
|
||||
set(i, j, k, data);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -607,13 +600,14 @@ public class Mantle {
|
||||
|
||||
/**
|
||||
* Set a pyramid of data in the mantle
|
||||
* @param cx the center x
|
||||
* @param cy the base y
|
||||
* @param cz the center z
|
||||
* @param data the data to set
|
||||
* @param size the size of the pyramid (width of base & height)
|
||||
*
|
||||
* @param cx the center x
|
||||
* @param cy the base y
|
||||
* @param cz the center z
|
||||
* @param data the data to set
|
||||
* @param size the size of the pyramid (width of base & height)
|
||||
* @param filled should it be filled or hollow
|
||||
* @param <T> the type of data to apply to the mantle
|
||||
* @param <T> the type of data to apply to the mantle
|
||||
*/
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
public <T> void setPyramid(int cx, int cy, int cz, T data, int size, boolean filled) {
|
||||
@ -636,10 +630,11 @@ public class Mantle {
|
||||
|
||||
/**
|
||||
* Set a 3d tube spline interpolated with Kochanek Bartels
|
||||
*
|
||||
* @param nodevectors the vector points
|
||||
* @param radius the radius
|
||||
* @param filled if it should be filled or hollow
|
||||
* @param data the data to set
|
||||
* @param radius the radius
|
||||
* @param filled if it should be filled or hollow
|
||||
* @param data the data to set
|
||||
*/
|
||||
public <T> void setSpline(List<Vector> nodevectors, double radius, boolean filled, T data) {
|
||||
setSpline(nodevectors, 0, 0, 0, 10, radius, filled, data);
|
||||
@ -647,15 +642,16 @@ public class Mantle {
|
||||
|
||||
/**
|
||||
* Set a 3d tube spline interpolated with Kochanek Bartels
|
||||
*
|
||||
* @param nodevectors the spline points
|
||||
* @param tension the tension 0
|
||||
* @param bias the bias 0
|
||||
* @param continuity the continuity 0
|
||||
* @param quality the quality 10
|
||||
* @param radius the radius
|
||||
* @param filled filled or hollow
|
||||
* @param data the data to set
|
||||
* @param <T> the type of data to apply to the mantle
|
||||
* @param tension the tension 0
|
||||
* @param bias the bias 0
|
||||
* @param continuity the continuity 0
|
||||
* @param quality the quality 10
|
||||
* @param radius the radius
|
||||
* @param filled filled or hollow
|
||||
* @param data the data to set
|
||||
* @param <T> the type of data to apply to the mantle
|
||||
*/
|
||||
public <T> void setSpline(List<Vector> nodevectors, double tension, double bias, double continuity, double quality, double radius, boolean filled, T data) {
|
||||
Set<IrisPosition> vset = new KSet<>();
|
||||
@ -687,25 +683,26 @@ public class Mantle {
|
||||
|
||||
/**
|
||||
* Set a 3d line
|
||||
* @param a the first point
|
||||
* @param b the second point
|
||||
*
|
||||
* @param a the first point
|
||||
* @param b the second point
|
||||
* @param radius the radius
|
||||
* @param filled hollow or filled?
|
||||
* @param data the data
|
||||
* @param <T> the type of data to apply to the mantle
|
||||
* @param data the data
|
||||
* @param <T> the type of data to apply to the mantle
|
||||
*/
|
||||
public <T> void setLine(IrisPosition a, IrisPosition b, double radius, boolean filled, T data)
|
||||
{
|
||||
public <T> void setLine(IrisPosition a, IrisPosition b, double radius, boolean filled, T data) {
|
||||
setLine(ImmutableList.of(a, b), radius, filled, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set lines for points
|
||||
*
|
||||
* @param vectors the points
|
||||
* @param radius the radius
|
||||
* @param filled hollow or filled?
|
||||
* @param data the data to set
|
||||
* @param <T> the type of data to apply to the mantle
|
||||
* @param radius the radius
|
||||
* @param filled hollow or filled?
|
||||
* @param data the data to set
|
||||
* @param <T> the type of data to apply to the mantle
|
||||
*/
|
||||
public <T> void setLine(List<IrisPosition> vectors, double radius, boolean filled, T data) {
|
||||
Set<IrisPosition> vset = new KSet<>();
|
||||
@ -770,28 +767,30 @@ public class Mantle {
|
||||
|
||||
/**
|
||||
* Set a cylinder in the mantle
|
||||
* @param cx the center x
|
||||
* @param cy the base y
|
||||
* @param cz the center z
|
||||
* @param data the data to set
|
||||
*
|
||||
* @param cx the center x
|
||||
* @param cy the base y
|
||||
* @param cz the center z
|
||||
* @param data the data to set
|
||||
* @param radius the radius
|
||||
* @param height the height of the cyl
|
||||
* @param filled filled or not
|
||||
*/
|
||||
public <T> void setCylinder(int cx, int cy, int cz, T data, double radius, int height, boolean filled){
|
||||
public <T> void setCylinder(int cx, int cy, int cz, T data, double radius, int height, boolean filled) {
|
||||
setCylinder(cx, cy, cz, data, radius, radius, height, filled);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a cylinder in the mantle
|
||||
* @param cx the center x
|
||||
* @param cy the base y
|
||||
* @param cz the center z
|
||||
* @param data the data to set
|
||||
*
|
||||
* @param cx the center x
|
||||
* @param cy the base y
|
||||
* @param cz the center z
|
||||
* @param data the data to set
|
||||
* @param radiusX the x radius
|
||||
* @param radiusZ the z radius
|
||||
* @param height the height of this cyl
|
||||
* @param filled filled or hollow?
|
||||
* @param height the height of this cyl
|
||||
* @param filled filled or hollow?
|
||||
*/
|
||||
public <T> void setCylinder(int cx, int cy, int cz, T data, double radiusX, double radiusZ, int height, boolean filled) {
|
||||
int affected = 0;
|
||||
@ -817,7 +816,8 @@ public class Mantle {
|
||||
final int ceilRadiusZ = (int) Math.ceil(radiusZ);
|
||||
double nextXn = 0;
|
||||
|
||||
forX: for (int x = 0; x <= ceilRadiusX; ++x) {
|
||||
forX:
|
||||
for (int x = 0; x <= ceilRadiusX; ++x) {
|
||||
final double xn = nextXn;
|
||||
nextXn = (x + 1) * invRadiusX;
|
||||
double nextZn = 0;
|
||||
@ -850,23 +850,18 @@ public class Mantle {
|
||||
}
|
||||
}
|
||||
|
||||
public <T> void set(IrisPosition pos, T data)
|
||||
{
|
||||
public <T> void set(IrisPosition pos, T data) {
|
||||
set(pos.getX(), pos.getY(), pos.getZ(), data);
|
||||
}
|
||||
|
||||
public <T> void set(List<IrisPosition> positions, T data)
|
||||
{
|
||||
for(IrisPosition i : positions)
|
||||
{
|
||||
public <T> void set(List<IrisPosition> positions, T data) {
|
||||
for (IrisPosition i : positions) {
|
||||
set(i, data);
|
||||
}
|
||||
}
|
||||
|
||||
public <T> void set(Set<IrisPosition> positions, T data)
|
||||
{
|
||||
for(IrisPosition i : positions)
|
||||
{
|
||||
public <T> void set(Set<IrisPosition> positions, T data) {
|
||||
for (IrisPosition i : positions) {
|
||||
set(i, data);
|
||||
}
|
||||
}
|
||||
|
@ -19,15 +19,12 @@
|
||||
package com.volmit.iris.util.mantle;
|
||||
|
||||
import com.volmit.iris.engine.object.feature.IrisFeaturePositional;
|
||||
import com.volmit.iris.util.data.Varint;
|
||||
import com.volmit.iris.util.documentation.ChunkCoordinates;
|
||||
import com.volmit.iris.util.function.Consumer4;
|
||||
import com.volmit.iris.util.matter.IrisMatter;
|
||||
import com.volmit.iris.util.matter.Matter;
|
||||
import com.volmit.iris.util.matter.MatterSlice;
|
||||
import com.volmit.iris.util.matter.slices.ZoneMatter;
|
||||
import com.volmit.iris.util.parallel.BurstExecutor;
|
||||
import com.volmit.iris.util.parallel.MultiBurst;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
@ -87,8 +84,7 @@ public class MantleChunk {
|
||||
|
||||
short v = din.readShort();
|
||||
|
||||
for(int i = 0; i < v; i++)
|
||||
{
|
||||
for (int i = 0; i < v; i++) {
|
||||
features.add(zm.readNode(din));
|
||||
}
|
||||
}
|
||||
@ -187,8 +183,7 @@ public class MantleChunk {
|
||||
|
||||
dos.writeShort(features.size());
|
||||
|
||||
for(IrisFeaturePositional i : features)
|
||||
{
|
||||
for (IrisFeaturePositional i : features) {
|
||||
zm.writeNode(i, dos);
|
||||
}
|
||||
}
|
||||
|
@ -23,7 +23,6 @@ import com.volmit.iris.engine.data.cache.Cache;
|
||||
import com.volmit.iris.util.documentation.ChunkCoordinates;
|
||||
import com.volmit.iris.util.format.C;
|
||||
import com.volmit.iris.util.format.Form;
|
||||
import com.volmit.iris.util.hunk.storage.ArrayHunk;
|
||||
import com.volmit.iris.util.scheduling.PrecisionStopwatch;
|
||||
|
||||
import java.io.*;
|
||||
|
@ -30,7 +30,7 @@ public class INode {
|
||||
private double continuity;
|
||||
|
||||
public INode() {
|
||||
this(new Vector(0,0,0));
|
||||
this(new Vector(0, 0, 0));
|
||||
}
|
||||
|
||||
public INode(INode other) {
|
||||
|
@ -89,15 +89,15 @@ public class KochanekBartelsInterpolation implements PathInterpolation {
|
||||
* Returns the linear combination of the given coefficients with the nodes adjacent to baseIndex.
|
||||
*
|
||||
* @param baseIndex node index
|
||||
* @param f1 coefficient for baseIndex-1
|
||||
* @param f2 coefficient for baseIndex
|
||||
* @param f3 coefficient for baseIndex+1
|
||||
* @param f4 coefficient for baseIndex+2
|
||||
* @param f1 coefficient for baseIndex-1
|
||||
* @param f2 coefficient for baseIndex
|
||||
* @param f3 coefficient for baseIndex+1
|
||||
* @param f4 coefficient for baseIndex+2
|
||||
* @return linear combination of nodes[n-1..n+2] with f1..4
|
||||
*/
|
||||
private Vector linearCombination(int baseIndex, double f1, double f2, double f3, double f4) {
|
||||
final Vector r1 = retrieve(baseIndex - 1).multiply(f1);
|
||||
final Vector r2 = retrieve(baseIndex ).multiply(f2);
|
||||
final Vector r2 = retrieve(baseIndex).multiply(f2);
|
||||
final Vector r3 = retrieve(baseIndex + 1).multiply(f3);
|
||||
final Vector r4 = retrieve(baseIndex + 2).multiply(f4);
|
||||
|
||||
@ -108,7 +108,7 @@ public class KochanekBartelsInterpolation implements PathInterpolation {
|
||||
* Retrieves a node. Indexes are clamped to the valid range.
|
||||
*
|
||||
* @param index node index to retrieve
|
||||
* @return nodes[clamp(0, nodes.length-1)]
|
||||
* @return nodes[clamp(0, nodes.length - 1)]
|
||||
*/
|
||||
private Vector retrieve(int index) {
|
||||
if (index < 0) {
|
||||
@ -204,11 +204,11 @@ public class KochanekBartelsInterpolation implements PathInterpolation {
|
||||
case 1:
|
||||
// This case is merely a speed-up for a very common case
|
||||
return arcLengthRecursive(indexLeft, remainderLeft, 1.0)
|
||||
+ arcLengthRecursive(indexRight, 0.0, remainderRight);
|
||||
+ arcLengthRecursive(indexRight, 0.0, remainderRight);
|
||||
|
||||
default:
|
||||
return arcLengthRecursive(indexLeft, remainderLeft, indexRight - 1, 1.0)
|
||||
+ arcLengthRecursive(indexRight, 0.0, remainderRight);
|
||||
+ arcLengthRecursive(indexRight, 0.0, remainderRight);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -18,45 +18,60 @@
|
||||
|
||||
package com.volmit.iris.util.math;
|
||||
|
||||
import net.minecraft.SystemUtils;
|
||||
import net.minecraft.core.BaseBlockPosition;
|
||||
import net.minecraft.world.phys.AxisAlignedBB;
|
||||
import net.minecraft.world.phys.Vec3D;
|
||||
import org.bukkit.craftbukkit.libs.org.apache.commons.lang3.math.NumberUtils;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.IntPredicate;
|
||||
|
||||
public class MathHelper {
|
||||
public static final float a = MathHelper.c(2.0f);
|
||||
private static final float[] b = (float[]) a((Object) new float[65536], var0 ->
|
||||
{
|
||||
for (int var1 = 0; var1 < ((float[]) var0).length; ++var1) {
|
||||
((float[]) var0)[var1] = (float) Math.sin((double) var1 * 3.141592653589793 * 2.0 / 65536.0);
|
||||
private static final int h = 1024;
|
||||
private static final float i = 1024.0F;
|
||||
private static final long j = 61440L;
|
||||
private static final long k = 16384L;
|
||||
private static final long l = -4611686018427387904L;
|
||||
private static final long m = -9223372036854775808L;
|
||||
public static final float a = 3.1415927F;
|
||||
public static final float b = 1.5707964F;
|
||||
public static final float c = 6.2831855F;
|
||||
public static final float d = 0.017453292F;
|
||||
public static final float e = 57.295776F;
|
||||
public static final float f = 1.0E-5F;
|
||||
public static final float g = c(2.0F);
|
||||
private static final float n = 10430.378F;
|
||||
private static final float[] o = (float[]) SystemUtils.a(new float[65536], (var0x) -> {
|
||||
for (int var1 = 0; var1 < var0x.length; ++var1) {
|
||||
var0x[var1] = (float) Math.sin((double) var1 * 3.141592653589793D * 2.0D / 65536.0D);
|
||||
}
|
||||
});
|
||||
|
||||
public static <T> T a(T var0, Consumer<T> var1) {
|
||||
var1.accept(var0);
|
||||
return var0;
|
||||
});
|
||||
private static final Random p = new Random();
|
||||
private static final int[] q = new int[]{0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8, 31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9};
|
||||
private static final double r = 0.16666666666666666D;
|
||||
private static final int s = 8;
|
||||
private static final int t = 257;
|
||||
private static final double u = Double.longBitsToDouble(4805340802404319232L);
|
||||
private static final double[] v = new double[257];
|
||||
private static final double[] w = new double[257];
|
||||
|
||||
public MathHelper() {
|
||||
}
|
||||
|
||||
private static final Random c = new Random();
|
||||
private static final int[] d = new int[]{0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8, 31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9};
|
||||
private static final double e = Double.longBitsToDouble(4805340802404319232L);
|
||||
private static final double[] f = new double[257];
|
||||
private static final double[] g = new double[257];
|
||||
|
||||
public static float sin(float var0) {
|
||||
return b[(int) (var0 * 10430.378f) & 65535];
|
||||
return o[(int) (var0 * 10430.378F) & '\uffff'];
|
||||
}
|
||||
|
||||
public static float cos(float var0) {
|
||||
return b[(int) (var0 * 10430.378f + 16384.0f) & 65535];
|
||||
return o[(int) (var0 * 10430.378F + 16384.0F) & '\uffff'];
|
||||
}
|
||||
|
||||
public static float c(float var0) {
|
||||
return (float) Math.sqrt(var0);
|
||||
}
|
||||
|
||||
public static float sqrt(double var0) {
|
||||
return (float) Math.sqrt(var0);
|
||||
return (float) Math.sqrt((double) var0);
|
||||
}
|
||||
|
||||
public static int d(float var0) {
|
||||
@ -64,16 +79,24 @@ public class MathHelper {
|
||||
return var0 < (float) var1 ? var1 - 1 : var1;
|
||||
}
|
||||
|
||||
public static int a(double var0) {
|
||||
return (int) (var0 + 1024.0D) - 1024;
|
||||
}
|
||||
|
||||
public static int floor(double var0) {
|
||||
int var2 = (int) var0;
|
||||
return var0 < (double) var2 ? var2 - 1 : var2;
|
||||
}
|
||||
|
||||
public static long d(double var0) {
|
||||
public static long c(double var0) {
|
||||
long var2 = (long) var0;
|
||||
return var0 < (double) var2 ? var2 - 1L : var2;
|
||||
}
|
||||
|
||||
public static int d(double var0) {
|
||||
return (int) (var0 >= 0.0D ? var0 : -var0 + 1.0D);
|
||||
}
|
||||
|
||||
public static float e(float var0) {
|
||||
return Math.abs(var0);
|
||||
}
|
||||
@ -87,50 +110,77 @@ public class MathHelper {
|
||||
return var0 > (float) var1 ? var1 + 1 : var1;
|
||||
}
|
||||
|
||||
public static int f(double var0) {
|
||||
public static int e(double var0) {
|
||||
int var2 = (int) var0;
|
||||
return var0 > (double) var2 ? var2 + 1 : var2;
|
||||
}
|
||||
|
||||
public static byte a(byte var0, byte var1, byte var2) {
|
||||
if (var0 < var1) {
|
||||
return var1;
|
||||
} else {
|
||||
return var0 > var2 ? var2 : var0;
|
||||
}
|
||||
}
|
||||
|
||||
public static int clamp(int var0, int var1, int var2) {
|
||||
if (var0 < var1) {
|
||||
return var1;
|
||||
} else {
|
||||
return var0 > var2 ? var2 : var0;
|
||||
}
|
||||
}
|
||||
|
||||
public static long a(long var0, long var2, long var4) {
|
||||
if (var0 < var2) {
|
||||
return var2;
|
||||
} else {
|
||||
return var0 > var4 ? var4 : var0;
|
||||
}
|
||||
return Math.min(var0, var2);
|
||||
}
|
||||
|
||||
public static float a(float var0, float var1, float var2) {
|
||||
if (var0 < var1) {
|
||||
return var1;
|
||||
} else {
|
||||
return var0 > var2 ? var2 : var0;
|
||||
}
|
||||
return Math.min(var0, var2);
|
||||
}
|
||||
|
||||
public static double a(double var0, double var2, double var4) {
|
||||
if (var0 < var2) {
|
||||
return var2;
|
||||
} else {
|
||||
return var0 > var4 ? var4 : var0;
|
||||
}
|
||||
return Math.min(var0, var4);
|
||||
}
|
||||
|
||||
public static double b(double var0, double var2, double var4) {
|
||||
if (var4 < 0.0) {
|
||||
if (var4 < 0.0D) {
|
||||
return var0;
|
||||
} else {
|
||||
return var4 > 1.0D ? var2 : d(var4, var0, var2);
|
||||
}
|
||||
if (var4 > 1.0) {
|
||||
return var2;
|
||||
}
|
||||
|
||||
public static float b(float var0, float var1, float var2) {
|
||||
if (var2 < 0.0F) {
|
||||
return var0;
|
||||
} else {
|
||||
return var2 > 1.0F ? var1 : h(var2, var0, var1);
|
||||
}
|
||||
return MathHelper.d(var4, var0, var2);
|
||||
}
|
||||
|
||||
public static double a(double var0, double var2) {
|
||||
if (var0 < 0.0) {
|
||||
if (var0 < 0.0D) {
|
||||
var0 = -var0;
|
||||
}
|
||||
if (var2 < 0.0) {
|
||||
|
||||
if (var2 < 0.0D) {
|
||||
var2 = -var2;
|
||||
}
|
||||
return Math.max(var0, var2);
|
||||
|
||||
return var0 > var2 ? var0 : var2;
|
||||
}
|
||||
|
||||
public static int a(int var0, int var1) {
|
||||
@ -138,89 +188,131 @@ public class MathHelper {
|
||||
}
|
||||
|
||||
public static int nextInt(Random var0, int var1, int var2) {
|
||||
if (var1 >= var2) {
|
||||
return var1;
|
||||
}
|
||||
return var0.nextInt(var2 - var1 + 1) + var1;
|
||||
return var1 >= var2 ? var1 : var0.nextInt(var2 - var1 + 1) + var1;
|
||||
}
|
||||
|
||||
public static float a(Random var0, float var1, float var2) {
|
||||
if (var1 >= var2) {
|
||||
return var1;
|
||||
}
|
||||
return var0.nextFloat() * (var2 - var1) + var1;
|
||||
return var1 >= var2 ? var1 : var0.nextFloat() * (var2 - var1) + var1;
|
||||
}
|
||||
|
||||
public static double a(Random var0, double var1, double var3) {
|
||||
if (var1 >= var3) {
|
||||
return var1;
|
||||
}
|
||||
return var0.nextDouble() * (var3 - var1) + var1;
|
||||
return var1 >= var3 ? var1 : var0.nextDouble() * (var3 - var1) + var1;
|
||||
}
|
||||
|
||||
public static double a(long[] var0) {
|
||||
long var1 = 0L;
|
||||
for (long var6 : var0) {
|
||||
long[] var3 = var0;
|
||||
int var4 = var0.length;
|
||||
|
||||
for (int var5 = 0; var5 < var4; ++var5) {
|
||||
long var6 = var3[var5];
|
||||
var1 += var6;
|
||||
}
|
||||
|
||||
return (double) var1 / (double) var0.length;
|
||||
}
|
||||
|
||||
public static boolean a(float var0, float var1) {
|
||||
return Math.abs(var1 - var0) < 1.0E-5F;
|
||||
}
|
||||
|
||||
public static boolean b(double var0, double var2) {
|
||||
return Math.abs(var2 - var0) < 9.999999747378752E-6;
|
||||
return Math.abs(var2 - var0) < 9.999999747378752E-6D;
|
||||
}
|
||||
|
||||
public static int b(int var0, int var1) {
|
||||
return Math.floorMod(var0, var1);
|
||||
}
|
||||
|
||||
public static float g(float var0) {
|
||||
float var1 = var0 % 360.0f;
|
||||
if (var1 >= 180.0f) {
|
||||
var1 -= 360.0f;
|
||||
public static float b(float var0, float var1) {
|
||||
return (var0 % var1 + var1) % var1;
|
||||
}
|
||||
|
||||
public static double c(double var0, double var2) {
|
||||
return (var0 % var2 + var2) % var2;
|
||||
}
|
||||
|
||||
public static int b(int var0) {
|
||||
int var1 = var0 % 360;
|
||||
if (var1 >= 180) {
|
||||
var1 -= 360;
|
||||
}
|
||||
if (var1 < -180.0f) {
|
||||
var1 += 360.0f;
|
||||
|
||||
if (var1 < -180) {
|
||||
var1 += 360;
|
||||
}
|
||||
|
||||
return var1;
|
||||
}
|
||||
|
||||
public static double g(double var0) {
|
||||
double var2 = var0 % 360.0;
|
||||
if (var2 >= 180.0) {
|
||||
var2 -= 360.0;
|
||||
public static float g(float var0) {
|
||||
float var1 = var0 % 360.0F;
|
||||
if (var1 >= 180.0F) {
|
||||
var1 -= 360.0F;
|
||||
}
|
||||
if (var2 < -180.0) {
|
||||
var2 += 360.0;
|
||||
|
||||
if (var1 < -180.0F) {
|
||||
var1 += 360.0F;
|
||||
}
|
||||
|
||||
return var1;
|
||||
}
|
||||
|
||||
public static double f(double var0) {
|
||||
double var2 = var0 % 360.0D;
|
||||
if (var2 >= 180.0D) {
|
||||
var2 -= 360.0D;
|
||||
}
|
||||
|
||||
if (var2 < -180.0D) {
|
||||
var2 += 360.0D;
|
||||
}
|
||||
|
||||
return var2;
|
||||
}
|
||||
|
||||
public static float c(float var0, float var1) {
|
||||
return MathHelper.g(var1 - var0);
|
||||
return g(var1 - var0);
|
||||
}
|
||||
|
||||
public static float d(float var0, float var1) {
|
||||
return MathHelper.e(MathHelper.c(var0, var1));
|
||||
}
|
||||
|
||||
public static float b(float var0, float var1, float var2) {
|
||||
float var3 = MathHelper.c(var0, var1);
|
||||
float var4 = MathHelper.a(var3, -var2, var2);
|
||||
return var1 - var4;
|
||||
return e(c(var0, var1));
|
||||
}
|
||||
|
||||
public static float c(float var0, float var1, float var2) {
|
||||
var2 = MathHelper.e(var2);
|
||||
if (var0 < var1) {
|
||||
return MathHelper.a(var0 + var2, var0, var1);
|
||||
}
|
||||
return MathHelper.a(var0 - var2, var1, var0);
|
||||
float var3 = c(var0, var1);
|
||||
float var4 = a(var3, -var2, var2);
|
||||
return var1 - var4;
|
||||
}
|
||||
|
||||
public static float d(float var0, float var1, float var2) {
|
||||
float var3 = MathHelper.c(var0, var1);
|
||||
return MathHelper.c(var0, var0 + var3, var2);
|
||||
var2 = e(var2);
|
||||
return var0 < var1 ? a(var0 + var2, var0, var1) : a(var0 - var2, var1, var0);
|
||||
}
|
||||
|
||||
public static float e(float var0, float var1, float var2) {
|
||||
float var3 = c(var0, var1);
|
||||
return d(var0, var0 + var3, var2);
|
||||
}
|
||||
|
||||
public static int a(String var0, int var1) {
|
||||
return NumberUtils.toInt(var0, var1);
|
||||
}
|
||||
|
||||
public static int a(String var0, int var1, int var2) {
|
||||
return Math.max(var2, a(var0, var1));
|
||||
}
|
||||
|
||||
public static double a(String var0, double var1) {
|
||||
try {
|
||||
return Double.parseDouble(var0);
|
||||
} catch (Throwable var4) {
|
||||
return var1;
|
||||
}
|
||||
}
|
||||
|
||||
public static double a(String var0, double var1, double var3) {
|
||||
return Math.max(var3, a(var0, var1));
|
||||
}
|
||||
|
||||
public static int c(int var0) {
|
||||
@ -238,166 +330,250 @@ public class MathHelper {
|
||||
}
|
||||
|
||||
public static int e(int var0) {
|
||||
var0 = MathHelper.d(var0) ? var0 : MathHelper.c(var0);
|
||||
return d[(int) ((long) var0 * 125613361L >> 27) & 31];
|
||||
var0 = d(var0) ? var0 : c(var0);
|
||||
return q[(int) ((long) var0 * 125613361L >> 27) & 31];
|
||||
}
|
||||
|
||||
public static int f(int var0) {
|
||||
return MathHelper.e(var0) - (MathHelper.d(var0) ? 0 : 1);
|
||||
return e(var0) - (d(var0) ? 0 : 1);
|
||||
}
|
||||
|
||||
public static int f(float var0, float var1, float var2) {
|
||||
return b(d(var0 * 255.0F), d(var1 * 255.0F), d(var2 * 255.0F));
|
||||
}
|
||||
|
||||
public static int b(int var0, int var1, int var2) {
|
||||
int var3 = (var0 << 8) + var1;
|
||||
var3 = (var3 << 8) + var2;
|
||||
return var3;
|
||||
}
|
||||
|
||||
public static int c(int var0, int var1) {
|
||||
int var2;
|
||||
if (var1 == 0) {
|
||||
return 0;
|
||||
}
|
||||
if (var0 == 0) {
|
||||
return var1;
|
||||
}
|
||||
if (var0 < 0) {
|
||||
var1 *= -1;
|
||||
}
|
||||
if ((var2 = var0 % var1) == 0) {
|
||||
return var0;
|
||||
}
|
||||
return var0 + var1 - var2;
|
||||
int var2 = (var0 & 16711680) >> 16;
|
||||
int var3 = (var1 & 16711680) >> 16;
|
||||
int var4 = (var0 & '\uff00') >> 8;
|
||||
int var5 = (var1 & '\uff00') >> 8;
|
||||
int var6 = (var0 & 255) >> 0;
|
||||
int var7 = (var1 & 255) >> 0;
|
||||
int var8 = (int) ((float) var2 * (float) var3 / 255.0F);
|
||||
int var9 = (int) ((float) var4 * (float) var5 / 255.0F);
|
||||
int var10 = (int) ((float) var6 * (float) var7 / 255.0F);
|
||||
return var0 & -16777216 | var8 << 16 | var9 << 8 | var10;
|
||||
}
|
||||
|
||||
public static int a(int var0, float var1, float var2, float var3) {
|
||||
int var4 = (var0 & 16711680) >> 16;
|
||||
int var5 = (var0 & '\uff00') >> 8;
|
||||
int var6 = (var0 & 255) >> 0;
|
||||
int var7 = (int) ((float) var4 * var1);
|
||||
int var8 = (int) ((float) var5 * var2);
|
||||
int var9 = (int) ((float) var6 * var3);
|
||||
return var0 & -16777216 | var7 << 16 | var8 << 8 | var9;
|
||||
}
|
||||
|
||||
public static float h(float var0) {
|
||||
return var0 - (float) MathHelper.d(var0);
|
||||
return var0 - (float) d(var0);
|
||||
}
|
||||
|
||||
public static double h(double var0) {
|
||||
return var0 - (double) MathHelper.d(var0);
|
||||
public static double g(double var0) {
|
||||
return var0 - (double) c(var0);
|
||||
}
|
||||
|
||||
public static long a(BlockPosition var0) {
|
||||
public static Vec3D a(Vec3D var0, Vec3D var1, Vec3D var2, Vec3D var3, double var4) {
|
||||
double var6 = ((-var4 + 2.0D) * var4 - 1.0D) * var4 * 0.5D;
|
||||
double var8 = ((3.0D * var4 - 5.0D) * var4 * var4 + 2.0D) * 0.5D;
|
||||
double var10 = ((-3.0D * var4 + 4.0D) * var4 + 1.0D) * var4 * 0.5D;
|
||||
double var12 = (var4 - 1.0D) * var4 * var4 * 0.5D;
|
||||
return new Vec3D(var0.b * var6 + var1.b * var8 + var2.b * var10 + var3.b * var12, var0.c * var6 + var1.c * var8 + var2.c * var10 + var3.c * var12, var0.d * var6 + var1.d * var8 + var2.d * var10 + var3.d * var12);
|
||||
}
|
||||
|
||||
public static long a(BaseBlockPosition var0) {
|
||||
return c(var0.getX(), var0.getY(), var0.getZ());
|
||||
}
|
||||
|
||||
public static long c(int var0, int var1, int var2) {
|
||||
long var3 = (var0 * 3129871L) ^ (long) var2 * 116129781L ^ (long) var1;
|
||||
long var3 = (long) (var0 * 3129871) ^ (long) var2 * 116129781L ^ (long) var1;
|
||||
var3 = var3 * var3 * 42317861L + var3 * 11L;
|
||||
return var3 >> 16;
|
||||
}
|
||||
|
||||
public static UUID a(Random var0) {
|
||||
long var1 = var0.nextLong() & -61441L | 16384L;
|
||||
long var3 = var0.nextLong() & 0x3FFFFFFFFFFFFFFFL | Long.MIN_VALUE;
|
||||
long var3 = var0.nextLong() & 4611686018427387903L | -9223372036854775808L;
|
||||
return new UUID(var1, var3);
|
||||
}
|
||||
|
||||
public static UUID a() {
|
||||
return MathHelper.a(c);
|
||||
return a(p);
|
||||
}
|
||||
|
||||
public static double c(double var0, double var2, double var4) {
|
||||
return (var0 - var2) / (var4 - var2);
|
||||
}
|
||||
|
||||
public static double d(double var0, double var2) {
|
||||
double var9;
|
||||
boolean var6;
|
||||
boolean var7;
|
||||
boolean var8;
|
||||
double var4 = var2 * var2 + var0 * var0;
|
||||
if (Double.isNaN(var4)) {
|
||||
return Double.NaN;
|
||||
public static boolean a(Vec3D var0, Vec3D var1, AxisAlignedBB var2) {
|
||||
double var3 = (var2.a + var2.d) * 0.5D;
|
||||
double var5 = (var2.d - var2.a) * 0.5D;
|
||||
double var7 = var0.b - var3;
|
||||
if (Math.abs(var7) > var5 && var7 * var1.b >= 0.0D) {
|
||||
return false;
|
||||
} else {
|
||||
double var9 = (var2.b + var2.e) * 0.5D;
|
||||
double var11 = (var2.e - var2.b) * 0.5D;
|
||||
double var13 = var0.c - var9;
|
||||
if (Math.abs(var13) > var11 && var13 * var1.c >= 0.0D) {
|
||||
return false;
|
||||
} else {
|
||||
double var15 = (var2.c + var2.f) * 0.5D;
|
||||
double var17 = (var2.f - var2.c) * 0.5D;
|
||||
double var19 = var0.d - var15;
|
||||
if (Math.abs(var19) > var17 && var19 * var1.d >= 0.0D) {
|
||||
return false;
|
||||
} else {
|
||||
double var21 = Math.abs(var1.b);
|
||||
double var23 = Math.abs(var1.c);
|
||||
double var25 = Math.abs(var1.d);
|
||||
double var27 = var1.c * var19 - var1.d * var13;
|
||||
if (Math.abs(var27) > var11 * var25 + var17 * var23) {
|
||||
return false;
|
||||
} else {
|
||||
var27 = var1.d * var7 - var1.b * var19;
|
||||
if (Math.abs(var27) > var5 * var25 + var17 * var21) {
|
||||
return false;
|
||||
} else {
|
||||
var27 = var1.b * var13 - var1.c * var7;
|
||||
return Math.abs(var27) < var5 * var23 + var11 * var21;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@SuppressWarnings("unused")
|
||||
boolean bl = var6 = var0 < 0.0;
|
||||
if (var6) {
|
||||
var0 = -var0;
|
||||
}
|
||||
@SuppressWarnings("unused")
|
||||
boolean bl2 = var7 = var2 < 0.0;
|
||||
if (var7) {
|
||||
var2 = -var2;
|
||||
}
|
||||
@SuppressWarnings("unused")
|
||||
boolean bl3 = var8 = var0 > var2;
|
||||
if (var8) {
|
||||
var9 = var2;
|
||||
var2 = var0;
|
||||
var0 = var9;
|
||||
}
|
||||
var9 = MathHelper.i(var4);
|
||||
double var11 = e + (var0 *= var9);
|
||||
int var13 = (int) Double.doubleToRawLongBits(var11);
|
||||
double var14 = f[var13];
|
||||
double var16 = g[var13];
|
||||
double var18 = var11 - e;
|
||||
double var20 = var0 * var16 - (var2 *= var9) * var18;
|
||||
double var22 = (6.0 + var20 * var20) * var20 * 0.16666666666666666;
|
||||
double var24 = var14 + var22;
|
||||
if (var8) {
|
||||
var24 = 1.5707963267948966 - var24;
|
||||
}
|
||||
if (var7) {
|
||||
var24 = 3.141592653589793 - var24;
|
||||
}
|
||||
if (var6) {
|
||||
var24 = -var24;
|
||||
}
|
||||
return var24;
|
||||
}
|
||||
|
||||
public static double i(double var0) {
|
||||
double var2 = 0.5 * var0;
|
||||
long var4 = Double.doubleToRawLongBits(var0);
|
||||
var4 = 6910469410427058090L - (var4 >> 1);
|
||||
var0 = Double.longBitsToDouble(var4);
|
||||
var0 *= 1.5 - var2 * var0 * var0;
|
||||
public static double d(double var0, double var2) {
|
||||
double var4 = var2 * var2 + var0 * var0;
|
||||
if (Double.isNaN(var4)) {
|
||||
return 0.0D / 0.0;
|
||||
} else {
|
||||
boolean var6 = var0 < 0.0D;
|
||||
if (var6) {
|
||||
var0 = -var0;
|
||||
}
|
||||
|
||||
boolean var7 = var2 < 0.0D;
|
||||
if (var7) {
|
||||
var2 = -var2;
|
||||
}
|
||||
|
||||
boolean var8 = var0 > var2;
|
||||
double var9;
|
||||
if (var8) {
|
||||
var9 = var2;
|
||||
var2 = var0;
|
||||
var0 = var9;
|
||||
}
|
||||
|
||||
var9 = h(var4);
|
||||
var2 *= var9;
|
||||
var0 *= var9;
|
||||
double var11 = u + var0;
|
||||
int var13 = (int) Double.doubleToRawLongBits(var11);
|
||||
double var14 = v[var13];
|
||||
double var16 = w[var13];
|
||||
double var18 = var11 - u;
|
||||
double var20 = var0 * var16 - var2 * var18;
|
||||
double var22 = (6.0D + var20 * var20) * var20 * 0.16666666666666666D;
|
||||
double var24 = var14 + var22;
|
||||
if (var8) {
|
||||
var24 = 1.5707963267948966D - var24;
|
||||
}
|
||||
|
||||
if (var7) {
|
||||
var24 = 3.141592653589793D - var24;
|
||||
}
|
||||
|
||||
if (var6) {
|
||||
var24 = -var24;
|
||||
}
|
||||
|
||||
return var24;
|
||||
}
|
||||
}
|
||||
|
||||
public static float i(float var0) {
|
||||
float var1 = 0.5F * var0;
|
||||
int var2 = Float.floatToIntBits(var0);
|
||||
var2 = 1597463007 - (var2 >> 1);
|
||||
var0 = Float.intBitsToFloat(var2);
|
||||
var0 *= 1.5F - var1 * var0 * var0;
|
||||
return var0;
|
||||
}
|
||||
|
||||
public static int f(float var0, float var1, float var2) {
|
||||
float var9;
|
||||
public static double h(double var0) {
|
||||
double var2 = 0.5D * var0;
|
||||
long var4 = Double.doubleToRawLongBits(var0);
|
||||
var4 = 6910469410427058090L - (var4 >> 1);
|
||||
var0 = Double.longBitsToDouble(var4);
|
||||
var0 *= 1.5D - var2 * var0 * var0;
|
||||
return var0;
|
||||
}
|
||||
|
||||
public static float j(float var0) {
|
||||
int var1 = Float.floatToIntBits(var0);
|
||||
var1 = 1419967116 - var1 / 3;
|
||||
float var2 = Float.intBitsToFloat(var1);
|
||||
var2 = 0.6666667F * var2 + 1.0F / (3.0F * var2 * var2 * var0);
|
||||
var2 = 0.6666667F * var2 + 1.0F / (3.0F * var2 * var2 * var0);
|
||||
return var2;
|
||||
}
|
||||
|
||||
public static int g(float var0, float var1, float var2) {
|
||||
int var3 = (int) (var0 * 6.0F) % 6;
|
||||
float var4 = var0 * 6.0F - (float) var3;
|
||||
float var5 = var2 * (1.0F - var1);
|
||||
float var6 = var2 * (1.0F - var4 * var1);
|
||||
float var7 = var2 * (1.0F - (1.0F - var4) * var1);
|
||||
float var8;
|
||||
float var9;
|
||||
float var10;
|
||||
int var3 = (int) (var0 * 6.0f) % 6;
|
||||
float var4 = var0 * 6.0f - (float) var3;
|
||||
float var5 = var2 * (1.0f - var1);
|
||||
float var6 = var2 * (1.0f - var4 * var1);
|
||||
float var7 = var2 * (1.0f - (1.0f - var4) * var1);
|
||||
switch (var3) {
|
||||
case 0 -> {
|
||||
case 0:
|
||||
var8 = var2;
|
||||
var9 = var7;
|
||||
var10 = var5;
|
||||
}
|
||||
case 1 -> {
|
||||
break;
|
||||
case 1:
|
||||
var8 = var6;
|
||||
var9 = var2;
|
||||
var10 = var5;
|
||||
}
|
||||
case 2 -> {
|
||||
break;
|
||||
case 2:
|
||||
var8 = var5;
|
||||
var9 = var2;
|
||||
var10 = var7;
|
||||
}
|
||||
case 3 -> {
|
||||
break;
|
||||
case 3:
|
||||
var8 = var5;
|
||||
var9 = var6;
|
||||
var10 = var2;
|
||||
}
|
||||
case 4 -> {
|
||||
break;
|
||||
case 4:
|
||||
var8 = var7;
|
||||
var9 = var5;
|
||||
var10 = var2;
|
||||
}
|
||||
case 5 -> {
|
||||
break;
|
||||
case 5:
|
||||
var8 = var2;
|
||||
var9 = var5;
|
||||
var10 = var6;
|
||||
}
|
||||
default -> {
|
||||
break;
|
||||
default:
|
||||
throw new RuntimeException("Something went wrong when converting from HSV to RGB. Input was " + var0 + ", " + var1 + ", " + var2);
|
||||
}
|
||||
}
|
||||
int var11 = MathHelper.clamp((int) (var8 * 255.0f), 0, 255);
|
||||
int var12 = MathHelper.clamp((int) (var9 * 255.0f), 0, 255);
|
||||
int var13 = MathHelper.clamp((int) (var10 * 255.0f), 0, 255);
|
||||
|
||||
int var11 = clamp((int) (var8 * 255.0F), 0, 255);
|
||||
int var12 = clamp((int) (var9 * 255.0F), 0, 255);
|
||||
int var13 = clamp((int) (var10 * 255.0F), 0, 255);
|
||||
return var11 << 16 | var12 << 8 | var13;
|
||||
}
|
||||
|
||||
@ -410,22 +586,103 @@ public class MathHelper {
|
||||
return var0;
|
||||
}
|
||||
|
||||
public static long a(long var0) {
|
||||
var0 ^= var0 >>> 33;
|
||||
var0 *= -49064778989728563L;
|
||||
var0 ^= var0 >>> 33;
|
||||
var0 *= -4265267296055464877L;
|
||||
var0 ^= var0 >>> 33;
|
||||
return var0;
|
||||
}
|
||||
|
||||
public static double[] a(double... var0) {
|
||||
float var1 = 0.0F;
|
||||
double[] var2f = var0;
|
||||
int var3 = var0.length;
|
||||
|
||||
for (int var4 = 0; var4 < var3; ++var4) {
|
||||
double var5 = var2f[var4];
|
||||
var1 = (float) ((double) var1 + var5);
|
||||
}
|
||||
|
||||
int var2;
|
||||
for (var2 = 0; var2 < var0.length; ++var2) {
|
||||
var0[var2] /= (double) var1;
|
||||
}
|
||||
|
||||
for (var2 = 0; var2 < var0.length; ++var2) {
|
||||
var0[var2] += var2 == 0 ? 0.0D : var0[var2 - 1];
|
||||
}
|
||||
|
||||
return var0;
|
||||
}
|
||||
|
||||
public static int a(Random var0, double[] var1) {
|
||||
double var2 = var0.nextDouble();
|
||||
|
||||
for (int var4 = 0; var4 < var1.length; ++var4) {
|
||||
if (var2 < var1[var4]) {
|
||||
return var4;
|
||||
}
|
||||
}
|
||||
|
||||
return var1.length;
|
||||
}
|
||||
|
||||
public static double[] a(double var0, double var2, double var4, int var6, int var7) {
|
||||
double[] var8 = new double[var7 - var6 + 1];
|
||||
int var9 = 0;
|
||||
|
||||
for (int var10 = var6; var10 <= var7; ++var10) {
|
||||
var8[var9] = Math.max(0.0D, var0 * StrictMath.exp(-((double) var10 - var4) * ((double) var10 - var4) / (2.0D * var2 * var2)));
|
||||
++var9;
|
||||
}
|
||||
|
||||
return var8;
|
||||
}
|
||||
|
||||
public static double[] a(double var0, double var2, double var4, double var6, double var8, double var10, int var12, int var13) {
|
||||
double[] var14 = new double[var13 - var12 + 1];
|
||||
int var15 = 0;
|
||||
|
||||
for (int var16 = var12; var16 <= var13; ++var16) {
|
||||
var14[var15] = Math.max(0.0D, var0 * StrictMath.exp(-((double) var16 - var4) * ((double) var16 - var4) / (2.0D * var2 * var2)) + var6 * StrictMath.exp(-((double) var16 - var10) * ((double) var16 - var10) / (2.0D * var8 * var8)));
|
||||
++var15;
|
||||
}
|
||||
|
||||
return var14;
|
||||
}
|
||||
|
||||
public static double[] a(double var0, double var2, int var4, int var5) {
|
||||
double[] var6 = new double[var5 - var4 + 1];
|
||||
int var7 = 0;
|
||||
|
||||
for (int var8 = var4; var8 <= var5; ++var8) {
|
||||
var6[var7] = Math.max(var0 * StrictMath.log((double) var8) + var2, 0.0D);
|
||||
++var7;
|
||||
}
|
||||
|
||||
return var6;
|
||||
}
|
||||
|
||||
public static int a(int var0, int var1, IntPredicate var2) {
|
||||
int var3 = var1 - var0;
|
||||
|
||||
while (var3 > 0) {
|
||||
int var4 = var3 / 2;
|
||||
int var5 = var0 + var4;
|
||||
if (var2.test(var5)) {
|
||||
var3 = var4;
|
||||
continue;
|
||||
} else {
|
||||
var0 = var5 + 1;
|
||||
var3 -= var4 + 1;
|
||||
}
|
||||
var0 = var5 + 1;
|
||||
var3 -= var4 + 1;
|
||||
}
|
||||
|
||||
return var0;
|
||||
}
|
||||
|
||||
public static float g(float var0, float var1, float var2) {
|
||||
public static float h(float var0, float var1, float var2) {
|
||||
return var1 + var0 * (var2 - var1);
|
||||
}
|
||||
|
||||
@ -434,46 +691,118 @@ public class MathHelper {
|
||||
}
|
||||
|
||||
public static double a(double var0, double var2, double var4, double var6, double var8, double var10) {
|
||||
return MathHelper.d(var2, MathHelper.d(var0, var4, var6), MathHelper.d(var0, var8, var10));
|
||||
return d(var2, d(var0, var4, var6), d(var0, var8, var10));
|
||||
}
|
||||
|
||||
public static double a(double var0, double var2, double var4, double var6, double var8, double var10, double var12, double var14, double var16, double var18, double var20) {
|
||||
return MathHelper.d(var4, MathHelper.a(var0, var2, var6, var8, var10, var12), MathHelper.a(var0, var2, var14, var16, var18, var20));
|
||||
return d(var4, a(var0, var2, var6, var8, var10, var12), a(var0, var2, var14, var16, var18, var20));
|
||||
}
|
||||
|
||||
public static double i(double var0) {
|
||||
return var0 * var0 * var0 * (var0 * (var0 * 6.0D - 15.0D) + 10.0D);
|
||||
}
|
||||
|
||||
public static double j(double var0) {
|
||||
return var0 * var0 * var0 * (var0 * (var0 * 6.0 - 15.0) + 10.0);
|
||||
return 30.0D * var0 * var0 * (var0 - 1.0D) * (var0 - 1.0D);
|
||||
}
|
||||
|
||||
public static int k(double var0) {
|
||||
if (var0 == 0.0) {
|
||||
if (var0 == 0.0D) {
|
||||
return 0;
|
||||
} else {
|
||||
return var0 > 0.0D ? 1 : -1;
|
||||
}
|
||||
return var0 > 0.0 ? 1 : -1;
|
||||
}
|
||||
|
||||
public static float i(float var0, float var1, float var2) {
|
||||
return var1 + var0 * g(var2 - var1);
|
||||
}
|
||||
|
||||
public static float j(float var0, float var1, float var2) {
|
||||
return Math.min(var0 * var0 * 0.6F + var1 * var1 * ((3.0F + var1) / 4.0F) + var2 * var2 * 0.8F, 1.0F);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static float j(float var0, float var1, float var2) {
|
||||
public static float k(float var0, float var1, float var2) {
|
||||
float var3;
|
||||
for (var3 = var1 - var0; var3 < -180.0f; var3 += 360.0f) {
|
||||
for (var3 = var1 - var0; var3 < -180.0F; var3 += 360.0F) {
|
||||
}
|
||||
while (var3 >= 180.0f) {
|
||||
var3 -= 360.0f;
|
||||
|
||||
while (var3 >= 180.0F) {
|
||||
var3 -= 360.0F;
|
||||
}
|
||||
|
||||
return var0 + var2 * var3;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static float l(double var0) {
|
||||
while (var0 >= 180.0D) {
|
||||
var0 -= 360.0D;
|
||||
}
|
||||
|
||||
while (var0 < -180.0D) {
|
||||
var0 += 360.0D;
|
||||
}
|
||||
|
||||
return (float) var0;
|
||||
}
|
||||
|
||||
public static float e(float var0, float var1) {
|
||||
return (Math.abs(var0 % var1 - var1 * 0.5F) - var1 * 0.25F) / (var1 * 0.25F);
|
||||
}
|
||||
|
||||
public static float k(float var0) {
|
||||
return var0 * var0;
|
||||
}
|
||||
|
||||
public static double m(double var0) {
|
||||
return var0 * var0;
|
||||
}
|
||||
|
||||
public static int h(int var0) {
|
||||
return var0 * var0;
|
||||
}
|
||||
|
||||
public static double a(double var0, double var2, double var4, double var6, double var8) {
|
||||
return b(var6, var8, c(var0, var2, var4));
|
||||
}
|
||||
|
||||
public static double b(double var0, double var2, double var4, double var6, double var8) {
|
||||
return d(c(var0, var2, var4), var6, var8);
|
||||
}
|
||||
|
||||
public static double n(double var0) {
|
||||
return var0 + (2.0D * (new Random((long) floor(var0 * 3000.0D))).nextDouble() - 1.0D) * 1.0E-7D / 2.0D;
|
||||
}
|
||||
|
||||
public static int d(int var0, int var1) {
|
||||
return (var0 + var1 - 1) / var1 * var1;
|
||||
}
|
||||
|
||||
public static int b(Random var0, int var1, int var2) {
|
||||
return var0.nextInt(var2 - var1 + 1) + var1;
|
||||
}
|
||||
|
||||
public static float b(Random var0, float var1, float var2) {
|
||||
return var0.nextFloat() * (var2 - var1) + var1;
|
||||
}
|
||||
|
||||
public static float c(Random var0, float var1, float var2) {
|
||||
return var1 + (float) var0.nextGaussian() * var2;
|
||||
}
|
||||
|
||||
public static double a(int var0, double var1, int var3) {
|
||||
return Math.sqrt((double) (var0 * var0) + var1 * var1 + (double) (var3 * var3));
|
||||
}
|
||||
|
||||
static {
|
||||
for (int var02 = 0; var02 < 257; ++var02) {
|
||||
// TODO: WARNING HEIGHT
|
||||
double var1 = (double) var02 / 256.0;
|
||||
for (int var0 = 0; var0 < 257; ++var0) {
|
||||
double var1 = (double) var0 / 256.0D;
|
||||
double var3 = Math.asin(var1);
|
||||
MathHelper.g[var02] = Math.cos(var3);
|
||||
MathHelper.f[var02] = var3;
|
||||
w[var0] = Math.cos(var3);
|
||||
v[var0] = var3;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -18,16 +18,13 @@
|
||||
|
||||
package com.volmit.iris.util.matter;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.engine.object.basic.IrisPosition;
|
||||
import com.volmit.iris.util.collection.KSet;
|
||||
import com.volmit.iris.util.data.Varint;
|
||||
import com.volmit.iris.util.format.C;
|
||||
import com.volmit.iris.util.hunk.Hunk;
|
||||
import com.volmit.iris.util.math.BlockPosition;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.craftbukkit.v1_17_R1.block.data.type.CraftLeaves;
|
||||
import org.bukkit.entity.Entity;
|
||||
|
||||
import java.io.*;
|
||||
@ -190,13 +187,9 @@ public interface Matter {
|
||||
slice = (MatterSlice<T>) createSlice(c, this);
|
||||
|
||||
if (slice == null) {
|
||||
try
|
||||
{
|
||||
try {
|
||||
throw new RuntimeException("Bad slice " + c.getCanonicalName());
|
||||
}
|
||||
|
||||
catch(Throwable e)
|
||||
{
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
@ -18,7 +18,6 @@
|
||||
|
||||
package com.volmit.iris.util.matter.slices;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.engine.object.feature.IrisFeaturePositional;
|
||||
import com.volmit.iris.util.matter.Sliced;
|
||||
|
||||
|
@ -18,6 +18,8 @@
|
||||
|
||||
package com.volmit.iris.util.nbt.mca;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.util.io.IO;
|
||||
import com.volmit.iris.util.nbt.io.NBTDeserializer;
|
||||
import com.volmit.iris.util.nbt.io.NBTSerializer;
|
||||
import com.volmit.iris.util.nbt.io.NamedTag;
|
||||
@ -658,11 +660,7 @@ public class Chunk {
|
||||
level.putInt("zPos", zPos);
|
||||
level.putLong("LastUpdate", lastUpdate);
|
||||
level.putLong("InhabitedTime", inhabitedTime);
|
||||
if (dataVersion < 2202) {
|
||||
if (biomes != null && biomes.length == 256) level.putIntArray("Biomes", biomes);
|
||||
} else {
|
||||
if (biomes != null && biomes.length == 1024) level.putIntArray("Biomes", biomes);
|
||||
}
|
||||
if (biomes != null && biomes.length == 1024) level.putIntArray("Biomes", biomes);
|
||||
if (heightMaps != null) level.put("Heightmaps", heightMaps);
|
||||
if (carvingMasks != null) level.put("CarvingMasks", carvingMasks);
|
||||
if (entities != null) level.put("Entities", entities);
|
||||
@ -688,14 +686,4 @@ public class Chunk {
|
||||
public int sectionCount() {
|
||||
return sections.length();
|
||||
}
|
||||
|
||||
public void runLighting() {
|
||||
for (int s = 15; s >= 0; s--) {
|
||||
Section section = getSection(s);
|
||||
|
||||
if (section != null) {
|
||||
section.runLighting();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,7 @@
|
||||
|
||||
package com.volmit.iris.util.nbt.mca;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.math.Position2;
|
||||
import com.volmit.iris.util.nbt.tag.CompoundTag;
|
||||
|
@ -28,7 +28,6 @@ import com.volmit.iris.util.math.M;
|
||||
import com.volmit.iris.util.nbt.tag.CompoundTag;
|
||||
import com.volmit.iris.util.nbt.tag.StringTag;
|
||||
import com.volmit.iris.util.parallel.HyperLock;
|
||||
import com.volmit.iris.util.scheduling.IrisLock;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
@ -39,10 +38,38 @@ import java.util.Map;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class NBTWorld {
|
||||
private static final BlockData AIR = B.get("AIR");
|
||||
private static final Map<String, CompoundTag> blockDataCache = new KMap<>();
|
||||
private static final Map<BlockData, CompoundTag> blockDataCache = new KMap<>();
|
||||
private static final Function<BlockData, CompoundTag> BLOCK_DATA_COMPUTE = (blockData) -> {
|
||||
CompoundTag s = new CompoundTag();
|
||||
String data = blockData.getAsString(true);
|
||||
NamespacedKey key = blockData.getMaterial().getKey();
|
||||
s.putString("Name", key.getNamespace() + ":" + key.getKey());
|
||||
|
||||
if (data.contains("[")) {
|
||||
String raw = data.split("\\Q[\\E")[1].replaceAll("\\Q]\\E", "");
|
||||
CompoundTag props = new CompoundTag();
|
||||
if (raw.contains(",")) {
|
||||
for (String i : raw.split("\\Q,\\E")) {
|
||||
String[] m = i.split("\\Q=\\E");
|
||||
String k = m[0];
|
||||
String v = m[1];
|
||||
props.put(k, new StringTag(v));
|
||||
}
|
||||
} else {
|
||||
String[] m = raw.split("\\Q=\\E");
|
||||
String k = m[0];
|
||||
String v = m[1];
|
||||
props.put(k, new StringTag(v));
|
||||
}
|
||||
s.put("Properties", props);
|
||||
}
|
||||
|
||||
return s;
|
||||
};
|
||||
private static final Map<Biome, Integer> biomeIds = computeBiomeIDs();
|
||||
private final KMap<Long, MCAFile> loadedRegions;
|
||||
private final HyperLock hyperLock = new HyperLock();
|
||||
@ -184,38 +211,8 @@ public class NBTWorld {
|
||||
return b;
|
||||
}
|
||||
|
||||
public static CompoundTag getCompound(BlockData blockData) {
|
||||
String data = blockData.getAsString(true);
|
||||
|
||||
if (blockDataCache.containsKey(data)) {
|
||||
return blockDataCache.get(data).clone();
|
||||
}
|
||||
|
||||
CompoundTag s = new CompoundTag();
|
||||
NamespacedKey key = blockData.getMaterial().getKey();
|
||||
s.putString("Name", key.getNamespace() + ":" + key.getKey());
|
||||
|
||||
if (data.contains("[")) {
|
||||
String raw = data.split("\\Q[\\E")[1].replaceAll("\\Q]\\E", "");
|
||||
CompoundTag props = new CompoundTag();
|
||||
if (raw.contains(",")) {
|
||||
for (String i : raw.split("\\Q,\\E")) {
|
||||
String[] m = i.split("\\Q=\\E");
|
||||
String k = m[0];
|
||||
String v = m[1];
|
||||
props.put(k, new StringTag(v));
|
||||
}
|
||||
} else {
|
||||
String[] m = raw.split("\\Q=\\E");
|
||||
String k = m[0];
|
||||
String v = m[1];
|
||||
props.put(k, new StringTag(v));
|
||||
}
|
||||
s.put("Properties", props);
|
||||
}
|
||||
|
||||
blockDataCache.put(data, s.clone());
|
||||
return s;
|
||||
public static CompoundTag getCompound(BlockData bd) {
|
||||
return blockDataCache.computeIfAbsent(bd, BLOCK_DATA_COMPUTE).clone();
|
||||
}
|
||||
|
||||
public BlockData getBlockData(int x, int y, int z) {
|
||||
@ -238,8 +235,7 @@ public class NBTWorld {
|
||||
getChunkSection(x >> 4, y >> 4, z >> 4).setBlockStateAt(x & 15, y & 15, z & 15, getCompound(data), false);
|
||||
}
|
||||
|
||||
public int getBiomeId(Biome b)
|
||||
{
|
||||
public int getBiomeId(Biome b) {
|
||||
return biomeIds.get(b);
|
||||
}
|
||||
|
||||
@ -259,8 +255,7 @@ public class NBTWorld {
|
||||
return s;
|
||||
}
|
||||
|
||||
public Chunk getChunk(int x, int z)
|
||||
{
|
||||
public Chunk getChunk(int x, int z) {
|
||||
return getChunk(getMCA(x >> 5, z >> 5), x, z);
|
||||
}
|
||||
|
||||
@ -275,11 +270,18 @@ public class NBTWorld {
|
||||
return c;
|
||||
}
|
||||
|
||||
public Chunk getNewChunk(MCAFile mca, int x, int z) {
|
||||
Chunk c = Chunk.newChunk();
|
||||
mca.setChunk(x & 31, z & 31, c);
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
public long getIdleDuration(int x, int z) {
|
||||
return hyperLock.withResult(x, z, () -> {
|
||||
Long l = lastUse.get(Cache.key(x, z));
|
||||
return l == null ? 0 : (M.ms() - l);
|
||||
});
|
||||
return hyperLock.withResult(x, z, () -> {
|
||||
Long l = lastUse.get(Cache.key(x, z));
|
||||
return l == null ? 0 : (M.ms() - l);
|
||||
});
|
||||
}
|
||||
|
||||
public MCAFile getMCA(int x, int z) {
|
||||
|
@ -18,26 +18,17 @@
|
||||
|
||||
package com.volmit.iris.util.nbt.mca;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.util.collection.KMap;
|
||||
import com.volmit.iris.util.nbt.mca.palettes.DataPaletteBlock;
|
||||
import com.volmit.iris.util.nbt.tag.ByteArrayTag;
|
||||
import com.volmit.iris.util.nbt.tag.CompoundTag;
|
||||
import com.volmit.iris.util.nbt.tag.ListTag;
|
||||
import com.volmit.iris.util.nbt.tag.LongArrayTag;
|
||||
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicLongArray;
|
||||
|
||||
public class Section {
|
||||
private CompoundTag data;
|
||||
private Map<String, List<PaletteIndex>> valueIndexedPalette = new KMap<>();
|
||||
private ListTag<CompoundTag> palette;
|
||||
private DataPaletteBlock palette;
|
||||
private byte[] blockLight;
|
||||
private AtomicLongArray blockStates;
|
||||
private byte[] skyLight;
|
||||
private int dataVersion;
|
||||
|
||||
@ -52,83 +43,18 @@ public class Section {
|
||||
if (rawPalette == null) {
|
||||
return;
|
||||
}
|
||||
palette = rawPalette.asCompoundTagList();
|
||||
for (int i = 0; i < palette.size(); i++) {
|
||||
CompoundTag data = palette.get(i);
|
||||
putValueIndexedPalette(data, i);
|
||||
}
|
||||
|
||||
ByteArrayTag blockLight = sectionRoot.getByteArrayTag("BlockLight");
|
||||
palette = new DataPaletteBlock();
|
||||
LongArrayTag blockStates = sectionRoot.getLongArrayTag("BlockStates");
|
||||
palette.load((ListTag<CompoundTag>) rawPalette, blockStates.getValue());
|
||||
ByteArrayTag blockLight = sectionRoot.getByteArrayTag("BlockLight");
|
||||
ByteArrayTag skyLight = sectionRoot.getByteArrayTag("SkyLight");
|
||||
|
||||
if ((loadFlags & LoadFlags.BLOCK_LIGHTS) != 0) {
|
||||
this.blockLight = blockLight != null ? blockLight.getValue() : null;
|
||||
}
|
||||
if ((loadFlags & LoadFlags.BLOCK_STATES) != 0) {
|
||||
this.blockStates = blockStates != null ? new AtomicLongArray(blockStates.getValue()) : null;
|
||||
}
|
||||
if ((loadFlags & LoadFlags.SKY_LIGHT) != 0) {
|
||||
this.skyLight = skyLight != null ? skyLight.getValue() : null;
|
||||
}
|
||||
this.blockLight = blockLight != null ? blockLight.getValue() : null;
|
||||
this.skyLight = skyLight != null ? skyLight.getValue() : null;
|
||||
}
|
||||
|
||||
Section() {
|
||||
}
|
||||
|
||||
void putValueIndexedPalette(CompoundTag data, int index) {
|
||||
PaletteIndex leaf = new PaletteIndex(data, index);
|
||||
String name = data.getString("Name");
|
||||
List<PaletteIndex> leaves = valueIndexedPalette.get(name);
|
||||
if (leaves == null) {
|
||||
leaves = new ArrayList<>(1);
|
||||
leaves.add(leaf);
|
||||
valueIndexedPalette.put(name, leaves);
|
||||
} else {
|
||||
for (PaletteIndex pal : leaves) {
|
||||
if (pal.data.equals(data)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
leaves.add(leaf);
|
||||
}
|
||||
}
|
||||
|
||||
PaletteIndex getValueIndexedPalette(CompoundTag data) {
|
||||
List<PaletteIndex> leaves = valueIndexedPalette.get(data.getString("Name"));
|
||||
if (leaves == null) {
|
||||
return null;
|
||||
}
|
||||
for (PaletteIndex leaf : leaves) {
|
||||
if (leaf.data.equals(data)) {
|
||||
return leaf;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void runLighting() {
|
||||
for (int x = 1; x < 14; x++) {
|
||||
for (int z = 1; z < 14; z++) {
|
||||
for (int y = 0; y < 16; y++) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("ClassCanBeRecord")
|
||||
private static class PaletteIndex {
|
||||
|
||||
final CompoundTag data;
|
||||
final int index;
|
||||
|
||||
PaletteIndex(CompoundTag data, int index) {
|
||||
this.data = data;
|
||||
this.index = index;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the data of this Section is empty.
|
||||
*
|
||||
@ -147,17 +73,11 @@ public class Section {
|
||||
* @param blockZ The z-coordinate of the block in this Section
|
||||
* @return The block state data of this block.
|
||||
*/
|
||||
public CompoundTag getBlockStateAt(int blockX, int blockY, int blockZ) {
|
||||
try {
|
||||
int index = getBlockIndex(blockX, blockY, blockZ);
|
||||
int paletteIndex = getPaletteIndex(index);
|
||||
return palette.get(paletteIndex);
|
||||
} catch (Throwable ignored) {
|
||||
Iris.reportError(ignored);
|
||||
|
||||
public synchronized CompoundTag getBlockStateAt(int blockX, int blockY, int blockZ) {
|
||||
synchronized (palette)
|
||||
{
|
||||
return palette.getBlock(blockX&15, blockY&15, blockZ&15);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -167,116 +87,12 @@ public class Section {
|
||||
* @param blockY The y-coordinate of the block in this Section
|
||||
* @param blockZ The z-coordinate of the block in this Section
|
||||
* @param state The block state to be set
|
||||
* @param cleanup When <code>true</code>, it will cleanup the palette of this section.
|
||||
* This option should only be used moderately to avoid unnecessary recalculation of the palette indices.
|
||||
* Recalculating the Palette should only be executed once right before saving the Section to file.
|
||||
*/
|
||||
public synchronized void setBlockStateAt(int blockX, int blockY, int blockZ, CompoundTag state, boolean cleanup) {
|
||||
int paletteSizeBefore = palette.size();
|
||||
int paletteIndex = addToPalette(state);
|
||||
//power of 2 --> bits must increase, but only if the palette size changed
|
||||
//otherwise we would attempt to update all blockstates and the entire palette
|
||||
//every time an existing blockstate was added while having 2^x blockstates in the palette
|
||||
if (paletteSizeBefore != palette.size() && (paletteIndex & (paletteIndex - 1)) == 0) {
|
||||
adjustBlockStateBits(null, blockStates);
|
||||
cleanup = true;
|
||||
synchronized (palette)
|
||||
{
|
||||
palette.setBlock(blockX&15, blockY&15, blockZ&15, state);
|
||||
}
|
||||
|
||||
setPaletteIndex(getBlockIndex(blockX, blockY, blockZ), paletteIndex, blockStates);
|
||||
|
||||
if (cleanup) {
|
||||
cleanupPaletteAndBlockStates();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the index of the block data in the palette.
|
||||
*
|
||||
* @param blockStateIndex The index of the block in this section, ranging from 0-4095.
|
||||
* @return The index of the block data in the palette.
|
||||
*/
|
||||
public int getPaletteIndex(int blockStateIndex) {
|
||||
int bits = blockStates.length() >> 6;
|
||||
|
||||
if (dataVersion < 2527) {
|
||||
double blockStatesIndex = blockStateIndex / (4096D / blockStates.length());
|
||||
int longIndex = (int) blockStatesIndex;
|
||||
int startBit = (int) ((blockStatesIndex - Math.floor(blockStatesIndex)) * 64D);
|
||||
if (startBit + bits > 64) {
|
||||
long prev = bitRange(blockStates.get(longIndex), startBit, 64);
|
||||
long next = bitRange(blockStates.get(longIndex + 1), 0, startBit + bits - 64);
|
||||
return (int) ((next << 64 - startBit) + prev);
|
||||
} else {
|
||||
return (int) bitRange(blockStates.get(longIndex), startBit, startBit + bits);
|
||||
}
|
||||
} else {
|
||||
int indicesPerLong = (int) (64D / bits);
|
||||
int blockStatesIndex = blockStateIndex / indicesPerLong;
|
||||
int startBit = (blockStateIndex % indicesPerLong) * bits;
|
||||
return (int) bitRange(blockStates.get(blockStatesIndex), startBit, startBit + bits);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the index of the block data in the BlockStates. Does not adjust the size of the BlockStates array.
|
||||
*
|
||||
* @param blockIndex The index of the block in this section, ranging from 0-4095.
|
||||
* @param paletteIndex The block state to be set (index of block data in the palette).
|
||||
* @param blockStates The block states to be updated.
|
||||
*/
|
||||
public synchronized void setPaletteIndex(int blockIndex, int paletteIndex, AtomicLongArray blockStates) {
|
||||
int bits = blockStates.length() >> 6;
|
||||
|
||||
if (dataVersion < 2527) {
|
||||
double blockStatesIndex = blockIndex / (4096D / blockStates.length());
|
||||
int longIndex = (int) blockStatesIndex;
|
||||
int startBit = (int) ((blockStatesIndex - Math.floor(longIndex)) * 64D);
|
||||
if (startBit + bits > 64) {
|
||||
blockStates.set(longIndex, updateBits(blockStates.get(longIndex), paletteIndex, startBit, 64));
|
||||
blockStates.set(longIndex + 1, updateBits(blockStates.get(longIndex + 1), paletteIndex, startBit - 64, startBit + bits - 64));
|
||||
} else {
|
||||
blockStates.set(longIndex, updateBits(blockStates.get(longIndex), paletteIndex, startBit, startBit + bits));
|
||||
}
|
||||
} else {
|
||||
int indicesPerLong = (int) (64D / bits);
|
||||
int blockStatesIndex = blockIndex / indicesPerLong;
|
||||
int startBit = (blockIndex % indicesPerLong) * bits;
|
||||
blockStates.set(blockStatesIndex, updateBits(blockStates.get(blockStatesIndex), paletteIndex, startBit, startBit + bits));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches the palette of this Section.
|
||||
*
|
||||
* @return The palette of this Section.
|
||||
*/
|
||||
public ListTag<CompoundTag> getPalette() {
|
||||
return palette;
|
||||
}
|
||||
|
||||
synchronized int addToPalette(CompoundTag data) {
|
||||
PaletteIndex index;
|
||||
if ((index = getValueIndexedPalette(data)) != null) {
|
||||
return index.index;
|
||||
}
|
||||
palette.add(data);
|
||||
putValueIndexedPalette(data, palette.size() - 1);
|
||||
return palette.size() - 1;
|
||||
}
|
||||
|
||||
int getBlockIndex(int blockX, int blockY, int blockZ) {
|
||||
return (blockY & 0xF) * 256 + (blockZ & 0xF) * 16 + (blockX & 0xF);
|
||||
}
|
||||
|
||||
static long updateBits(long n, long m, int i, int j) {
|
||||
//replace i to j in n with j - i bits of m
|
||||
long mShifted = i > 0 ? (m & ((1L << j - i) - 1)) << i : (m & ((1L << j - i) - 1)) >>> -i;
|
||||
return ((n & ((j > 63 ? 0 : (~0L << j)) | (i < 0 ? 0 : ((1L << i) - 1L)))) | mShifted);
|
||||
}
|
||||
|
||||
static long bitRange(long value, int from, int to) {
|
||||
int waste = 64 - to;
|
||||
return (value << waste) >>> (waste + from);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -284,69 +100,14 @@ public class Section {
|
||||
* This should only be used moderately to avoid unnecessary recalculation of the palette indices.
|
||||
* Recalculating the Palette should only be executed once right before saving the Section to file.
|
||||
*/
|
||||
public synchronized void cleanupPaletteAndBlockStates() {
|
||||
Map<Integer, Integer> oldToNewMapping = cleanupPalette();
|
||||
adjustBlockStateBits(oldToNewMapping, blockStates);
|
||||
}
|
||||
public void cleanupPaletteAndBlockStates() {
|
||||
|
||||
private synchronized Map<Integer, Integer> cleanupPalette() {
|
||||
//create index - palette mapping
|
||||
Map<Integer, Integer> allIndices = new Int2IntOpenHashMap();
|
||||
for (int i = 0; i < 4096; i++) {
|
||||
int paletteIndex = getPaletteIndex(i);
|
||||
allIndices.put(paletteIndex, paletteIndex);
|
||||
}
|
||||
//delete unused blocks from palette
|
||||
//start at index 1 because we need to keep minecraft:air
|
||||
int index = 1;
|
||||
valueIndexedPalette = new HashMap<>(valueIndexedPalette.size());
|
||||
putValueIndexedPalette(palette.get(0), 0);
|
||||
for (int i = 1; i < palette.size(); i++) {
|
||||
if (!allIndices.containsKey(index)) {
|
||||
palette.remove(i);
|
||||
i--;
|
||||
} else {
|
||||
putValueIndexedPalette(palette.get(i), i);
|
||||
allIndices.put(index, i);
|
||||
}
|
||||
index++;
|
||||
}
|
||||
|
||||
return allIndices;
|
||||
}
|
||||
|
||||
synchronized void adjustBlockStateBits(Map<Integer, Integer> oldToNewMapping, AtomicLongArray blockStates) {
|
||||
//increases or decreases the amount of bits used per BlockState
|
||||
//based on the size of the palette. oldToNewMapping can be used to update indices
|
||||
//if the palette had been cleaned up before using MCAFile#cleanupPalette().
|
||||
|
||||
int newBits = 32 - Integer.numberOfLeadingZeros(palette.size() - 1);
|
||||
newBits = Math.max(newBits, 4);
|
||||
|
||||
AtomicLongArray newBlockStates;
|
||||
|
||||
if (dataVersion < 2527) {
|
||||
newBlockStates = newBits == blockStates.length() / 64 ? blockStates : new AtomicLongArray(newBits * 64);
|
||||
} else {
|
||||
int newLength = (int) Math.ceil(4096D / (64D / newBits));
|
||||
newBlockStates = newBits == blockStates.length() / 64 ? blockStates : new AtomicLongArray(newLength);
|
||||
}
|
||||
if (oldToNewMapping != null) {
|
||||
for (int i = 0; i < 4096; i++) {
|
||||
setPaletteIndex(i, oldToNewMapping.get(getPaletteIndex(i)), newBlockStates);
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < 4096; i++) {
|
||||
setPaletteIndex(i, getPaletteIndex(i), newBlockStates);
|
||||
}
|
||||
}
|
||||
this.blockStates = newBlockStates;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The block light array of this Section
|
||||
*/
|
||||
public byte[] getBlockLight() {
|
||||
public synchronized byte[] getBlockLight() {
|
||||
return blockLight;
|
||||
}
|
||||
|
||||
@ -356,40 +117,17 @@ public class Section {
|
||||
* @param blockLight The block light array
|
||||
* @throws IllegalArgumentException When the length of the array is not 2048
|
||||
*/
|
||||
public void setBlockLight(byte[] blockLight) {
|
||||
public synchronized void setBlockLight(byte[] blockLight) {
|
||||
if (blockLight != null && blockLight.length != 2048) {
|
||||
throw new IllegalArgumentException("BlockLight array must have a length of 2048");
|
||||
}
|
||||
this.blockLight = blockLight;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The indices of the block states of this Section.
|
||||
*/
|
||||
public AtomicLongArray getBlockStates() {
|
||||
return blockStates;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the block state indices to a custom value.
|
||||
*
|
||||
* @param blockStates The block state indices.
|
||||
* @throws NullPointerException If <code>blockStates</code> is <code>null</code>
|
||||
* @throws IllegalArgumentException When <code>blockStates</code>' length is < 256 or > 4096 and is not a multiple of 64
|
||||
*/
|
||||
public synchronized void setBlockStates(AtomicLongArray blockStates) {
|
||||
if (blockStates == null) {
|
||||
throw new NullPointerException("BlockStates cannot be null");
|
||||
} else if (blockStates.length() % 64 != 0 || blockStates.length() < 256 || blockStates.length() > 4096) {
|
||||
throw new IllegalArgumentException("BlockStates must have a length > 255 and < 4097 and must be divisible by 64");
|
||||
}
|
||||
this.blockStates = blockStates;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The sky light values of this Section
|
||||
*/
|
||||
public byte[] getSkyLight() {
|
||||
public synchronized byte[] getSkyLight() {
|
||||
return skyLight;
|
||||
}
|
||||
|
||||
@ -399,7 +137,7 @@ public class Section {
|
||||
* @param skyLight The custom sky light values
|
||||
* @throws IllegalArgumentException If the length of the array is not 2048
|
||||
*/
|
||||
public void setSkyLight(byte[] skyLight) {
|
||||
public synchronized void setSkyLight(byte[] skyLight) {
|
||||
if (skyLight != null && skyLight.length != 2048) {
|
||||
throw new IllegalArgumentException("SkyLight array must have a length of 2048");
|
||||
}
|
||||
@ -413,11 +151,7 @@ public class Section {
|
||||
*/
|
||||
public static Section newSection() {
|
||||
Section s = new Section();
|
||||
s.blockStates = new AtomicLongArray(256);
|
||||
s.palette = new ListTag<>(CompoundTag.class);
|
||||
CompoundTag air = new CompoundTag();
|
||||
air.putString("Name", "minecraft:air");
|
||||
s.palette.add(air);
|
||||
s.palette = new DataPaletteBlock();
|
||||
s.data = new CompoundTag();
|
||||
return s;
|
||||
}
|
||||
@ -430,23 +164,18 @@ public class Section {
|
||||
* @param y The Y-value of this Section
|
||||
* @return A reference to the raw CompoundTag this Section is based on
|
||||
*/
|
||||
public CompoundTag updateHandle(int y) {
|
||||
public synchronized CompoundTag updateHandle(int y) {
|
||||
data.putByte("Y", (byte) y);
|
||||
|
||||
if (palette != null) {
|
||||
data.put("Palette", palette);
|
||||
synchronized (palette)
|
||||
{
|
||||
palette.save(data, "Palette", "BlockStates");
|
||||
}
|
||||
}
|
||||
if (blockLight != null) {
|
||||
data.putByteArray("BlockLight", blockLight);
|
||||
}
|
||||
if (blockStates != null) {
|
||||
long[] c = new long[blockStates.length()];
|
||||
|
||||
for (int i = 0; i < c.length; i++) {
|
||||
c[i] = blockStates.get(i);
|
||||
}
|
||||
|
||||
data.putLongArray("BlockStates", c);
|
||||
}
|
||||
if (skyLight != null) {
|
||||
data.putByteArray("SkyLight", skyLight);
|
||||
}
|
||||
|
@ -0,0 +1,125 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2021 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.util.nbt.mca.palettes;
|
||||
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import java.util.function.IntConsumer;
|
||||
|
||||
public class DataBits {
|
||||
private static final int[] a = new int[]{-1, -1, 0, -2147483648, 0, 0, 1431655765, 1431655765, 0, -2147483648, 0, 1, 858993459, 858993459, 0, 715827882, 715827882, 0, 613566756, 613566756, 0, -2147483648, 0, 2, 477218588, 477218588, 0, 429496729, 429496729, 0, 390451572, 390451572, 0, 357913941, 357913941, 0, 330382099, 330382099, 0, 306783378, 306783378, 0, 286331153, 286331153, 0, -2147483648, 0, 3, 252645135, 252645135, 0, 238609294, 238609294, 0, 226050910, 226050910, 0, 214748364, 214748364, 0, 204522252, 204522252, 0, 195225786, 195225786, 0, 186737708, 186737708, 0, 178956970, 178956970, 0, 171798691, 171798691, 0, 165191049, 165191049, 0, 159072862, 159072862, 0, 153391689, 153391689, 0, 148102320, 148102320, 0, 143165576, 143165576, 0, 138547332, 138547332, 0, -2147483648, 0, 4, 130150524, 130150524, 0, 126322567, 126322567, 0, 122713351, 122713351, 0, 119304647, 119304647, 0, 116080197, 116080197, 0, 113025455, 113025455, 0, 110127366, 110127366, 0, 107374182, 107374182, 0, 104755299, 104755299, 0, 102261126, 102261126, 0, 99882960, 99882960, 0, 97612893, 97612893, 0, 95443717, 95443717, 0, 93368854, 93368854, 0, 91382282, 91382282, 0, 89478485, 89478485, 0, 87652393, 87652393, 0, 85899345, 85899345, 0, 84215045, 84215045, 0, 82595524, 82595524, 0, 81037118, 81037118, 0, 79536431, 79536431, 0, 78090314, 78090314, 0, 76695844, 76695844, 0, 75350303, 75350303, 0, 74051160, 74051160, 0, 72796055, 72796055, 0, 71582788, 71582788, 0, 70409299, 70409299, 0, 69273666, 69273666, 0, 68174084, 68174084, 0, -2147483648, 0, 5};
|
||||
private final long[] data;
|
||||
private final int c;
|
||||
private final long paletteSize;
|
||||
private final int blockSize;
|
||||
private final int f;
|
||||
private final int g;
|
||||
private final int h;
|
||||
private final int i;
|
||||
|
||||
public DataBits(int var0, int var1) {
|
||||
this(var0, var1, (long[]) null);
|
||||
}
|
||||
|
||||
public DataBits(int bitsPerBlock, int var1, long[] data) {
|
||||
Validate.inclusiveBetween(1L, 32L, (long) bitsPerBlock);
|
||||
this.blockSize = var1;
|
||||
this.c = bitsPerBlock;
|
||||
this.paletteSize = (1L << bitsPerBlock) - 1L;
|
||||
this.f = (char) (64 / bitsPerBlock);
|
||||
int var3 = 3 * (this.f - 1);
|
||||
this.g = a[var3 + 0];
|
||||
this.h = a[var3 + 1];
|
||||
this.i = a[var3 + 2];
|
||||
int var4 = (var1 + this.f - 1) / this.f;
|
||||
if (data != null) {
|
||||
if (data.length != var4) {
|
||||
throw new RuntimeException("Invalid length given for storage, got: " + data.length + " but expected: " + var4);
|
||||
}
|
||||
|
||||
this.data = data;
|
||||
} else {
|
||||
this.data = new long[var4];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private int b(int var0) {
|
||||
long var1 = Integer.toUnsignedLong(this.g);
|
||||
long var3 = Integer.toUnsignedLong(this.h);
|
||||
return (int) ((long) var0 * var1 + var3 >> 32 >> this.i);
|
||||
}
|
||||
|
||||
public int setBlockResulting(int blockIndex, int paletteIndex) {
|
||||
Validate.inclusiveBetween(0L, (long) (this.blockSize - 1), (long) blockIndex);
|
||||
Validate.inclusiveBetween(0L, this.paletteSize, (long) paletteIndex);
|
||||
int var2 = this.b(blockIndex);
|
||||
long var3 = this.data[var2];
|
||||
int var5 = (blockIndex - var2 * this.f) * this.c;
|
||||
int var6 = (int) (var3 >> var5 & this.paletteSize);
|
||||
this.data[var2] = var3 & ~(this.paletteSize << var5) | ((long) paletteIndex & this.paletteSize) << var5;
|
||||
return var6;
|
||||
}
|
||||
|
||||
public void setBlock(int blockIndex, int paletteIndex) {
|
||||
Validate.inclusiveBetween(0L, (long) (this.blockSize - 1), (long) blockIndex);
|
||||
Validate.inclusiveBetween(0L, this.paletteSize, (long) paletteIndex);
|
||||
int var2 = this.b(blockIndex);
|
||||
long var3 = this.data[var2];
|
||||
int var5 = (blockIndex - var2 * this.f) * this.c;
|
||||
this.data[var2] = var3 & ~(this.paletteSize << var5) | ((long) paletteIndex & this.paletteSize) << var5;
|
||||
}
|
||||
|
||||
public int getIndexFromPos(int var0) {
|
||||
Validate.inclusiveBetween(0L, (long) (this.blockSize - 1), (long) var0);
|
||||
int var1 = this.b(var0);
|
||||
long var2 = this.data[var1];
|
||||
int var4 = (var0 - var1 * this.f) * this.c;
|
||||
return (int) (var2 >> var4 & this.paletteSize);
|
||||
}
|
||||
|
||||
public long[] getData() {
|
||||
return this.data;
|
||||
}
|
||||
|
||||
public int b() {
|
||||
return this.blockSize;
|
||||
}
|
||||
|
||||
public int getBitsPerBlock() {
|
||||
return this.c;
|
||||
}
|
||||
|
||||
public void a(IntConsumer var0) {
|
||||
int var1 = 0;
|
||||
long[] var3 = this.data;
|
||||
int var4 = var3.length;
|
||||
for (long l : var3) {
|
||||
long var5 = l;
|
||||
for (int j = 0; j < this.f; ++j) {
|
||||
var0.accept((int) (var5 & this.paletteSize));
|
||||
var5 >>= this.c;
|
||||
++var1;
|
||||
if (var1 >= this.blockSize) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -16,21 +16,21 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.volmit.iris.util.hunk.io;
|
||||
package com.volmit.iris.util.nbt.mca.palettes;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import com.volmit.iris.util.nbt.tag.CompoundTag;
|
||||
import com.volmit.iris.util.nbt.tag.ListTag;
|
||||
|
||||
public class StringHunkIOAdapter extends PaletteHunkIOAdapter<String> {
|
||||
import java.util.function.Predicate;
|
||||
|
||||
@Override
|
||||
public void write(String data, DataOutputStream dos) throws IOException {
|
||||
dos.writeUTF(data);
|
||||
}
|
||||
public interface DataPalette {
|
||||
int getIndex(CompoundTag block);
|
||||
|
||||
@Override
|
||||
public String read(DataInputStream din) throws IOException {
|
||||
return din.readUTF();
|
||||
}
|
||||
boolean contains(Predicate<CompoundTag> predicate);
|
||||
|
||||
CompoundTag getByIndex(int index);
|
||||
|
||||
int size();
|
||||
|
||||
void replace(ListTag<CompoundTag> palette);
|
||||
}
|
@ -0,0 +1,225 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2021 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.util.nbt.mca.palettes;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.core.nms.INMS;
|
||||
import com.volmit.iris.engine.data.cache.AtomicCache;
|
||||
import com.volmit.iris.util.math.MathHelper;
|
||||
import com.volmit.iris.util.nbt.io.SNBTSerializer;
|
||||
import com.volmit.iris.util.nbt.mca.NBTWorld;
|
||||
import com.volmit.iris.util.nbt.tag.CompoundTag;
|
||||
import com.volmit.iris.util.nbt.tag.ListTag;
|
||||
import com.volmit.iris.util.scheduling.J;
|
||||
import it.unimi.dsi.fastutil.ints.Int2IntMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
|
||||
import lombok.Getter;
|
||||
import net.minecraft.world.level.chunk.ChunkSection;
|
||||
import org.bukkit.Material;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Getter
|
||||
public class DataPaletteBlock implements DataPaletteExpandable {
|
||||
private static final int d = 4096;
|
||||
public static final int HASH_BITS = 9;
|
||||
public static final int LINEAR_BITS = 4;
|
||||
private final DataPalette globalPalette;
|
||||
private final DataPaletteExpandable f = (var0x, var1x) -> 0;
|
||||
private final RegistryBlockID stolenRegistry;
|
||||
private final CompoundTag defAir;
|
||||
private static final AtomicCache<RegistryBlockID> reg = new AtomicCache<>();
|
||||
private static final AtomicCache<DataPaletteGlobal> global = new AtomicCache<>();
|
||||
private static final CompoundTag air = NBTWorld.getCompound(Material.AIR.createBlockData());
|
||||
protected DataBits dataBits;
|
||||
private DataPalette currentPalette;
|
||||
private int bits = 0;
|
||||
|
||||
public DataPaletteBlock() {
|
||||
this(global(), registry(), air);
|
||||
}
|
||||
|
||||
public DataPaletteBlock(DataPalette var0,
|
||||
RegistryBlockID var1,
|
||||
CompoundTag airType) {
|
||||
this.globalPalette = var0;
|
||||
this.stolenRegistry = var1;
|
||||
this.defAir = airType;
|
||||
this.changeBitsTo(4);
|
||||
}
|
||||
|
||||
private static RegistryBlockID registry()
|
||||
{
|
||||
return ((DataPaletteGlobal) global()).getRegistry();
|
||||
}
|
||||
|
||||
private static DataPalette global() {
|
||||
return global.aquire(() -> new DataPaletteGlobal(J.attemptResult(() -> INMS.get().computeBlockIDRegistry()), air));
|
||||
}
|
||||
|
||||
|
||||
private static int blockIndex(int x, int y, int z) {
|
||||
return y << 8 | z << 4 | x;
|
||||
}
|
||||
|
||||
private void changeBitsTo(int newbits) {
|
||||
if (newbits != bits) {
|
||||
bits = newbits;
|
||||
if (bits <= LINEAR_BITS) {
|
||||
bits = LINEAR_BITS;
|
||||
currentPalette = new DataPaletteLinear(bits, this);
|
||||
} else if (bits < HASH_BITS) {
|
||||
currentPalette = new DataPaletteHash(bits, this);
|
||||
} else {
|
||||
currentPalette = globalPalette;
|
||||
bits = MathHelper.e(stolenRegistry.size());
|
||||
}
|
||||
|
||||
currentPalette.getIndex(defAir);
|
||||
dataBits = new DataBits(bits, 4096);
|
||||
}
|
||||
}
|
||||
|
||||
public int onResize(int newBits, CompoundTag newData) {
|
||||
DataBits oldBits = dataBits;
|
||||
DataPalette oldPalette = currentPalette;
|
||||
changeBitsTo(newBits);
|
||||
|
||||
for (int i = 0; i < oldBits.b(); ++i) {
|
||||
CompoundTag block = oldPalette.getByIndex(oldBits.getIndexFromPos(i));
|
||||
if (block != null) {
|
||||
setBlockIndex(i, block);
|
||||
}
|
||||
}
|
||||
|
||||
return currentPalette.getIndex(newData);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public CompoundTag setBlockAndReturn(int x, int y, int z, CompoundTag block) {
|
||||
return setBlockIndexAndReturn(blockIndex(x, y, z), block);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
private CompoundTag setBlockIndexAndReturn(int index, CompoundTag block) {
|
||||
int paletteIndex = currentPalette.getIndex(block);
|
||||
int res = dataBits.setBlockResulting(index, paletteIndex);
|
||||
CompoundTag testBlock = currentPalette.getByIndex(res);
|
||||
return testBlock == null ? defAir : testBlock;
|
||||
}
|
||||
|
||||
public void setBlock(int x, int y, int z, CompoundTag block) {
|
||||
setBlockIndex(blockIndex(x, y, z), block);
|
||||
}
|
||||
|
||||
private void setBlockIndex(int blockIndex, CompoundTag block) {
|
||||
int paletteIndex = currentPalette.getIndex(block);
|
||||
dataBits.setBlock(blockIndex, paletteIndex);
|
||||
}
|
||||
|
||||
public CompoundTag getBlock(int x, int y, int z) {
|
||||
return getByIndex(blockIndex(x, y, z));
|
||||
}
|
||||
|
||||
protected CompoundTag getByIndex(int index) {
|
||||
if(currentPalette == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
CompoundTag data = currentPalette.getByIndex(dataBits.getIndexFromPos(index));
|
||||
return data == null ? defAir : data;
|
||||
}
|
||||
|
||||
public void load(ListTag<CompoundTag> palettedata, long[] databits) {
|
||||
int readBits = Math.max(4, MathHelper.e(palettedata.size()));
|
||||
if (readBits != bits) {
|
||||
changeBitsTo(readBits);
|
||||
}
|
||||
|
||||
currentPalette.replace(palettedata);
|
||||
int dblen = databits.length * 64 / 4096;
|
||||
if (currentPalette == globalPalette) {
|
||||
DataPalette hashPalette = new DataPaletteHash(readBits, f);
|
||||
hashPalette.replace(palettedata);
|
||||
DataBits var5 = new DataBits(readBits, 4096, databits);
|
||||
|
||||
for (int i = 0; i < 4096; ++i) {
|
||||
dataBits.setBlock(i, globalPalette.getIndex(hashPalette.getByIndex(var5.getIndexFromPos(i))));
|
||||
}
|
||||
} else if (dblen == bits) {
|
||||
System.arraycopy(databits, 0, dataBits.getData(), 0, databits.length);
|
||||
} else {
|
||||
DataBits var4 = new DataBits(dblen, 4096, databits);
|
||||
|
||||
for (int i = 0; i < 4096; ++i) {
|
||||
dataBits.setBlock(i, var4.getIndexFromPos(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void save(CompoundTag to, String paletteName, String blockStatesName) {
|
||||
DataPaletteHash hashpal = new DataPaletteHash(bits, f);
|
||||
CompoundTag cursor = defAir;
|
||||
int palIndex = hashpal.getIndex(defAir);
|
||||
int[] paletteIndex = new int[4096];
|
||||
int i;
|
||||
for (i = 0; i < 4096; ++i) {
|
||||
CompoundTag entry = getByIndex(i);
|
||||
if (!entry.equals(cursor)) {
|
||||
cursor = entry;
|
||||
palIndex = hashpal.getIndex(entry);
|
||||
}
|
||||
|
||||
paletteIndex[i] = palIndex;
|
||||
}
|
||||
|
||||
ListTag<CompoundTag> npalette = (ListTag<CompoundTag>) ListTag.createUnchecked(CompoundTag.class);
|
||||
hashpal.writePalette(npalette);
|
||||
to.put(paletteName, npalette);
|
||||
int bits = Math.max(4, MathHelper.e(npalette.size()));
|
||||
DataBits writeBits = new DataBits(bits, 4096);
|
||||
|
||||
for (i = 0; i < paletteIndex.length; ++i) {
|
||||
writeBits.setBlock(i, paletteIndex[i]);
|
||||
}
|
||||
|
||||
to.putLongArray(blockStatesName, writeBits.getData());
|
||||
to.putString("DEBUG_PALETTE_MODE", currentPalette.getClass().getSimpleName());
|
||||
}
|
||||
|
||||
public boolean contains(Predicate<CompoundTag> var0) {
|
||||
return currentPalette.contains(var0);
|
||||
}
|
||||
|
||||
public void a(PaletteConsumer<CompoundTag> var0) {
|
||||
Int2IntMap var1 = new Int2IntOpenHashMap();
|
||||
dataBits.a((var1x) -> var1.put(var1x, var1.get(var1x) + 1));
|
||||
var1.int2IntEntrySet().forEach((var1x) -> var0.accept(currentPalette.getByIndex(var1x.getIntKey()), var1x.getIntValue()));
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface PaletteConsumer<T> {
|
||||
void accept(T var1, int var2);
|
||||
}
|
||||
}
|
@ -16,30 +16,10 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.volmit.iris.util.oldnbt;
|
||||
package com.volmit.iris.util.nbt.mca.palettes;
|
||||
|
||||
/**
|
||||
* The <code>TAG_End</code> tag.
|
||||
*
|
||||
* @author Graham Edgecombe
|
||||
*/
|
||||
public final class EndTag extends Tag {
|
||||
|
||||
/**
|
||||
* Creates the tag.
|
||||
*/
|
||||
public EndTag() {
|
||||
super("");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getValue() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "TAG_End";
|
||||
}
|
||||
import com.volmit.iris.util.nbt.tag.CompoundTag;
|
||||
|
||||
interface DataPaletteExpandable {
|
||||
int onResize(int newBits, CompoundTag newData);
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2021 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.util.nbt.mca.palettes;
|
||||
|
||||
import com.volmit.iris.util.nbt.tag.CompoundTag;
|
||||
import com.volmit.iris.util.nbt.tag.ListTag;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import java.util.function.Predicate;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class DataPaletteGlobal implements DataPalette {
|
||||
@Getter
|
||||
private final RegistryBlockID registry;
|
||||
private final CompoundTag air;
|
||||
|
||||
public int getIndex(CompoundTag block) {
|
||||
int id = this.registry.getId(block);
|
||||
return id == -1 ? 0 : id;
|
||||
}
|
||||
|
||||
public boolean contains(Predicate<CompoundTag> predicate) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public CompoundTag getByIndex(int index) {
|
||||
CompoundTag block = registry.fromId(index);
|
||||
return block == null ? air : block;
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return registry.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void replace(ListTag<CompoundTag> palette) {
|
||||
throw new UnsupportedOperationException("Cannot replace the global palette!");
|
||||
}
|
||||
}
|
@ -0,0 +1,80 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2021 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.util.nbt.mca.palettes;
|
||||
|
||||
import com.volmit.iris.util.nbt.tag.CompoundTag;
|
||||
import com.volmit.iris.util.nbt.tag.ListTag;
|
||||
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class DataPaletteHash implements DataPalette {
|
||||
private final RegistryID registryId;
|
||||
private final DataPaletteExpandable expander;
|
||||
private final int bits;
|
||||
|
||||
public DataPaletteHash(int bits, DataPaletteExpandable expander) {
|
||||
this.bits = bits;
|
||||
this.expander = expander;
|
||||
this.registryId = new RegistryID(1 << bits);
|
||||
}
|
||||
|
||||
public int getIndex(CompoundTag block) {
|
||||
int id = registryId.getId(block);
|
||||
if (id == -1) {
|
||||
id = registryId.c(block);
|
||||
if (id >= 1 << bits) {
|
||||
id = expander.onResize(bits + 1, block);
|
||||
}
|
||||
}
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
public boolean contains(Predicate<CompoundTag> predicate) {
|
||||
for (int i = 0; i < size(); ++i) {
|
||||
if (predicate.test(registryId.fromId(i))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public CompoundTag getByIndex(int index) {
|
||||
return registryId.fromId(index);
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return registryId.size();
|
||||
}
|
||||
|
||||
public void replace(ListTag<CompoundTag> palette) {
|
||||
registryId.clear();
|
||||
|
||||
for (int i = 0; i < palette.size(); ++i) {
|
||||
registryId.c(palette.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
public void writePalette(ListTag<CompoundTag> list) {
|
||||
for (int i = 0; i < size(); ++i) {
|
||||
list.add(registryId.fromId(i));
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,82 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2021 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.util.nbt.mca.palettes;
|
||||
|
||||
import com.volmit.iris.util.nbt.tag.CompoundTag;
|
||||
import com.volmit.iris.util.nbt.tag.ListTag;
|
||||
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class DataPaletteLinear implements DataPalette {
|
||||
private final CompoundTag[] palette;
|
||||
private final DataPaletteExpandable expander;
|
||||
private final int e;
|
||||
private int size;
|
||||
|
||||
public DataPaletteLinear(int bits, DataPaletteExpandable expander) {
|
||||
this.palette = new CompoundTag[1 << bits];
|
||||
this.e = bits;
|
||||
this.expander = expander;
|
||||
this.size = 0;
|
||||
}
|
||||
|
||||
public int getIndex(CompoundTag block) {
|
||||
int i;
|
||||
for (i = 0; i < size; ++i) {
|
||||
if (palette[i].equals(block)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
i = size;
|
||||
if (i < palette.length) {
|
||||
palette[i] = block;
|
||||
++size;
|
||||
return i;
|
||||
} else {
|
||||
return expander.onResize(e + 1, block);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean contains(Predicate<CompoundTag> predicate) {
|
||||
for (int i = 0; i < this.size; ++i) {
|
||||
if (predicate.test(palette[i])) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public CompoundTag getByIndex(int index) {
|
||||
return index >= 0 && index < size ? palette[index] : null;
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return size;
|
||||
}
|
||||
|
||||
public void replace(ListTag<CompoundTag> palette) {
|
||||
for (int i = 0; i < palette.size(); ++i) {
|
||||
this.palette[i] = palette.get(i);
|
||||
}
|
||||
|
||||
this.size = palette.size();
|
||||
}
|
||||
}
|
@ -16,24 +16,12 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.volmit.iris.util.hunk.io;
|
||||
package com.volmit.iris.util.nbt.mca.palettes;
|
||||
|
||||
import com.volmit.iris.util.data.B;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import com.volmit.iris.util.nbt.tag.CompoundTag;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
public interface Registry extends Iterable<CompoundTag> {
|
||||
int getId(CompoundTag block);
|
||||
|
||||
public class BlockDataHunkIOAdapter extends PaletteHunkIOAdapter<BlockData> {
|
||||
|
||||
@Override
|
||||
public void write(BlockData blockData, DataOutputStream dos) throws IOException {
|
||||
dos.writeUTF(blockData.getAsString(true));
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockData read(DataInputStream din) throws IOException {
|
||||
return B.get(din.readUTF());
|
||||
}
|
||||
CompoundTag fromId(int id);
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2021 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.util.nbt.mca.palettes;
|
||||
|
||||
import com.google.common.collect.Iterators;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.volmit.iris.util.nbt.tag.CompoundTag;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class RegistryBlockID implements Registry {
|
||||
private final Map<CompoundTag, Integer> indexMap;
|
||||
private final List<CompoundTag> indexes;
|
||||
|
||||
public RegistryBlockID(Map<CompoundTag, Integer> c, List<CompoundTag> d) {
|
||||
this.indexMap = c;
|
||||
this.indexes = d;
|
||||
}
|
||||
|
||||
public RegistryBlockID() {
|
||||
this(512);
|
||||
}
|
||||
|
||||
public RegistryBlockID(int var0) {
|
||||
this.indexes = Lists.newArrayListWithExpectedSize(var0);
|
||||
this.indexMap = new HashMap<>(var0);
|
||||
}
|
||||
|
||||
public int getId(CompoundTag block) {
|
||||
Integer var1 = this.indexMap.get(block);
|
||||
return var1 == null ? -1 : var1;
|
||||
}
|
||||
|
||||
public final CompoundTag fromId(int id) {
|
||||
return id >= 0 && id < this.indexes.size() ? this.indexes.get(id) : null;
|
||||
}
|
||||
|
||||
public Iterator<CompoundTag> iterator() {
|
||||
return Iterators.filter(this.indexes.iterator(), Objects::nonNull);
|
||||
}
|
||||
|
||||
public boolean hasIndex(int var0) {
|
||||
return this.fromId(var0) != null;
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return this.indexMap.size();
|
||||
}
|
||||
}
|
@ -0,0 +1,176 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2021 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.util.nbt.mca.palettes;
|
||||
|
||||
import com.google.common.collect.Iterators;
|
||||
import com.volmit.iris.util.math.MathHelper;
|
||||
import com.volmit.iris.util.nbt.tag.CompoundTag;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.Objects;
|
||||
|
||||
public class RegistryID implements Registry {
|
||||
public static final int a = -1;
|
||||
private static final CompoundTag b = null;
|
||||
private static final float c = 0.8F;
|
||||
private CompoundTag[] d;
|
||||
private int[] e;
|
||||
private CompoundTag[] f;
|
||||
private int g;
|
||||
private int size;
|
||||
|
||||
public RegistryID(int var0) {
|
||||
var0 = (int) ((float) var0 / 0.8F);
|
||||
this.d = new CompoundTag[var0];
|
||||
this.f = new CompoundTag[var0];
|
||||
this.e = new int[var0];
|
||||
}
|
||||
|
||||
public int getId(CompoundTag block) {
|
||||
return this.c(this.b(block, this.d(block)));
|
||||
}
|
||||
|
||||
public CompoundTag fromId(int id) {
|
||||
return id >= 0 && id < this.f.length ? this.f[id] : null;
|
||||
}
|
||||
|
||||
private int c(int var0) {
|
||||
return var0 == -1 ? -1 : this.e[var0];
|
||||
}
|
||||
|
||||
public boolean b(CompoundTag var0) {
|
||||
return this.getId(var0) != -1;
|
||||
}
|
||||
|
||||
public boolean b(int var0) {
|
||||
return this.fromId(var0) != null;
|
||||
}
|
||||
|
||||
public int c(CompoundTag var0) {
|
||||
int var1 = this.c();
|
||||
this.a(var0, var1);
|
||||
return var1;
|
||||
}
|
||||
|
||||
private int c() {
|
||||
while (this.g < this.f.length && this.f[this.g] != null) {
|
||||
++this.g;
|
||||
}
|
||||
|
||||
return this.g;
|
||||
}
|
||||
|
||||
private void d(int var0) {
|
||||
CompoundTag[] var1 = this.d;
|
||||
int[] var2 = this.e;
|
||||
this.d = new CompoundTag[var0];
|
||||
this.e = new int[var0];
|
||||
this.f = new CompoundTag[var0];
|
||||
this.g = 0;
|
||||
this.size = 0;
|
||||
|
||||
for (int var3 = 0; var3 < var1.length; ++var3) {
|
||||
if (var1[var3] != null) {
|
||||
this.a(var1[var3], var2[var3]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void a(CompoundTag var0, int var1) {
|
||||
int var2 = Math.max(var1, this.size + 1);
|
||||
int var3;
|
||||
if ((float) var2 >= (float) this.d.length * 0.8F) {
|
||||
for (var3 = this.d.length << 1; var3 < var1; var3 <<= 1) {
|
||||
}
|
||||
|
||||
this.d(var3);
|
||||
}
|
||||
|
||||
var3 = this.e(this.d(var0));
|
||||
this.d[var3] = var0;
|
||||
this.e[var3] = var1;
|
||||
this.f[var1] = var0;
|
||||
++this.size;
|
||||
if (var1 == this.g) {
|
||||
++this.g;
|
||||
}
|
||||
}
|
||||
|
||||
private int d(CompoundTag block) {
|
||||
return (MathHelper.g(System.identityHashCode(block)) & 2147483647) % this.d.length;
|
||||
}
|
||||
|
||||
private int b(CompoundTag block, int var1) {
|
||||
int var2;
|
||||
for (var2 = var1; var2 < this.d.length; ++var2) {
|
||||
if (this.d[var2] == null) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (this.d[var2].equals(block)) {
|
||||
return var2;
|
||||
}
|
||||
}
|
||||
|
||||
for (var2 = 0; var2 < var1; ++var2) {
|
||||
if (this.d[var2] == null) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (this.d[var2].equals(block)) {
|
||||
return var2;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
private int e(int var0) {
|
||||
int var1;
|
||||
for (var1 = var0; var1 < this.d.length; ++var1) {
|
||||
if (this.d[var1] == null) {
|
||||
return var1;
|
||||
}
|
||||
}
|
||||
|
||||
for (var1 = 0; var1 < var0; ++var1) {
|
||||
if (this.d[var1] == null) {
|
||||
return var1;
|
||||
}
|
||||
}
|
||||
|
||||
throw new RuntimeException("Overflowed :(");
|
||||
}
|
||||
|
||||
public Iterator<CompoundTag> iterator() {
|
||||
return Iterators.filter(Iterators.forArray(this.f), Objects::nonNull);
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
Arrays.fill(this.d, null);
|
||||
Arrays.fill(this.f, null);
|
||||
this.g = 0;
|
||||
this.size = 0;
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return this.size;
|
||||
}
|
||||
}
|
@ -22,6 +22,7 @@ import com.volmit.iris.engine.data.io.MaxDepthIO;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
@ -42,6 +43,11 @@ public class ListTag<T extends Tag<?>> extends Tag<List<T>> implements Iterable<
|
||||
super(createEmptyValue(3));
|
||||
}
|
||||
|
||||
public ListTag<T> makeAtomic() {
|
||||
setValue(new CopyOnWriteArrayList<>(getValue()));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte getID() {
|
||||
return ID;
|
||||
@ -302,7 +308,7 @@ public class ListTag<T extends Tag<?>> extends Tag<List<T>> implements Iterable<
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(getTypeClass().hashCode(), getValue().hashCode());
|
||||
return Objects.hash(getValue().hashCode());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -94,7 +94,7 @@ public abstract class Tag<T> implements Cloneable {
|
||||
/**
|
||||
* @return The value of this Tag.
|
||||
*/
|
||||
protected T getValue() {
|
||||
public T getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user