From 9144606688ad58e826eccbb4d92a46eec55f9d9b Mon Sep 17 00:00:00 2001 From: repixelatedmc Date: Mon, 19 Aug 2024 19:36:35 +0200 Subject: [PATCH 01/18] Biggest 1 line fix ever --- core/src/main/java/com/volmit/iris/core/ServerConfigurator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/com/volmit/iris/core/ServerConfigurator.java b/core/src/main/java/com/volmit/iris/core/ServerConfigurator.java index 1a760d9d7..a1e273d65 100644 --- a/core/src/main/java/com/volmit/iris/core/ServerConfigurator.java +++ b/core/src/main/java/com/volmit/iris/core/ServerConfigurator.java @@ -58,7 +58,7 @@ public class ServerConfigurator { } private static void increaseKeepAliveSpigot() throws IOException, InvalidConfigurationException { - File spigotConfig = new File("config/spigot.yml"); + File spigotConfig = new File("spigot.yml"); FileConfiguration f = new YamlConfiguration(); f.load(spigotConfig); long tt = f.getLong("settings.timeout-time"); From 38ad345f851b9d17001aad982606c3439c1e469e Mon Sep 17 00:00:00 2001 From: Julian Krings Date: Sun, 25 Aug 2024 19:35:49 +0200 Subject: [PATCH 02/18] potential fix for pregen deadlock --- .../volmit/iris/core/gui/PregeneratorJob.java | 7 ++++- .../methods/AsyncPregenMethod.java | 26 +++++-------------- 2 files changed, 13 insertions(+), 20 deletions(-) diff --git a/core/src/main/java/com/volmit/iris/core/gui/PregeneratorJob.java b/core/src/main/java/com/volmit/iris/core/gui/PregeneratorJob.java index 6d3534971..35569f6f6 100644 --- a/core/src/main/java/com/volmit/iris/core/gui/PregeneratorJob.java +++ b/core/src/main/java/com/volmit/iris/core/gui/PregeneratorJob.java @@ -93,7 +93,12 @@ public class PregeneratorJob implements PregenListener { open(); } - J.a(this.pregenerator::start, 20); + var t = new Thread(() -> { + J.sleep(1000); + this.pregenerator.start(); + }, "Iris Pregenerator"); + t.setPriority(Thread.MIN_PRIORITY); + t.start(); } public static boolean shutdownInstance() { diff --git a/core/src/main/java/com/volmit/iris/core/pregenerator/methods/AsyncPregenMethod.java b/core/src/main/java/com/volmit/iris/core/pregenerator/methods/AsyncPregenMethod.java index 80b0a3dfd..5d9048fd3 100644 --- a/core/src/main/java/com/volmit/iris/core/pregenerator/methods/AsyncPregenMethod.java +++ b/core/src/main/java/com/volmit/iris/core/pregenerator/methods/AsyncPregenMethod.java @@ -29,15 +29,11 @@ import com.volmit.iris.util.math.M; import com.volmit.iris.util.parallel.MultiBurst; import com.volmit.iris.util.scheduling.J; import io.papermc.lib.PaperLib; -import org.bukkit.Bukkit; import org.bukkit.Chunk; import org.bukkit.World; import java.util.ArrayList; -import java.util.HashMap; import java.util.Map; -import java.util.Objects; -import java.util.concurrent.ForkJoinPool; import java.util.concurrent.Future; public class AsyncPregenMethod implements PregeneratorMethod { @@ -52,8 +48,8 @@ public class AsyncPregenMethod implements PregeneratorMethod { } this.world = world; - burst = MultiBurst.burst; - future = new KList<>(1024); + burst = new MultiBurst("Iris Async Pregen", Thread.NORM_PRIORITY); + future = new KList<>(256); this.lastUse = new KMap<>(); } @@ -81,24 +77,17 @@ public class AsyncPregenMethod implements PregeneratorMethod { private void completeChunk(int x, int z, PregenListener listener) { try { - future.add(PaperLib.getChunkAtAsync(world, x, z, true).thenApply((i) -> { - if (i == null) { - - } - Chunk c = Bukkit.getWorld(world.getUID()).getChunkAt(x, z); - lastUse.put(c, M.ms()); + PaperLib.getChunkAtAsync(world, x, z, true).thenAccept((i) -> { + lastUse.put(i, M.ms()); listener.onChunkGenerated(x, z); listener.onChunkCleaned(x, z); - return 0; - })); + }).join(); } catch (Throwable e) { e.printStackTrace(); } } private void waitForChunksPartial(int maxWaiting) { - future.removeWhere(Objects::isNull); - while (future.size() > maxWaiting) { try { Future i = future.remove(0); @@ -127,8 +116,6 @@ public class AsyncPregenMethod implements PregeneratorMethod { e.printStackTrace(); } } - - future.removeWhere(Objects::isNull); } @Override @@ -145,6 +132,7 @@ public class AsyncPregenMethod implements PregeneratorMethod { public void close() { waitForChunks(); unloadAndSaveAllChunks(); + burst.close(); } @Override @@ -169,7 +157,7 @@ public class AsyncPregenMethod implements PregeneratorMethod { if (future.size() > 256) { waitForChunksPartial(256); } - future.add(burst.complete(() -> completeChunk(x, z, listener))); + burst.complete(() -> completeChunk(x, z, listener)); } @Override From be3e8ebd516f1f948f3ded865e9f8221a35cafb2 Mon Sep 17 00:00:00 2001 From: Julian Krings Date: Sun, 25 Aug 2024 19:41:35 +0200 Subject: [PATCH 03/18] fix MMOItems support --- .../volmit/iris/core/link/MMOItemsDataProvider.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/com/volmit/iris/core/link/MMOItemsDataProvider.java b/core/src/main/java/com/volmit/iris/core/link/MMOItemsDataProvider.java index b402f32ab..f5a940590 100644 --- a/core/src/main/java/com/volmit/iris/core/link/MMOItemsDataProvider.java +++ b/core/src/main/java/com/volmit/iris/core/link/MMOItemsDataProvider.java @@ -5,6 +5,7 @@ import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.collection.KMap; import com.volmit.iris.util.scheduling.J; import net.Indyuce.mmoitems.MMOItems; +import net.Indyuce.mmoitems.api.ItemTier; import net.Indyuce.mmoitems.api.Type; import net.Indyuce.mmoitems.api.block.CustomBlock; import org.bukkit.Bukkit; @@ -46,8 +47,13 @@ public class MMOItemsDataProvider extends ExternalDataProvider { Runnable run = () -> { try { var type = api().getTypes().get(parts[1]); - int level = customNbt.containsKey("level") ? (int) customNbt.get("level") : -1; - var tier = api().getTiers().get(String.valueOf(customNbt.get("tier"))); + int level = -1; + ItemTier tier = null; + + if (customNbt != null) { + level = (int) customNbt.getOrDefault("level", -1); + tier = api().getTiers().get(String.valueOf(customNbt.get("tier"))); + } ItemStack itemStack; if (type == null) { From 29007fdbfab7a75aadf0429689e0ccab8c30a721 Mon Sep 17 00:00:00 2001 From: Julian Krings Date: Sun, 25 Aug 2024 21:48:10 +0200 Subject: [PATCH 04/18] fix walls not being rotated --- .../engine/object/IrisObjectRotation.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/core/src/main/java/com/volmit/iris/engine/object/IrisObjectRotation.java b/core/src/main/java/com/volmit/iris/engine/object/IrisObjectRotation.java index 6e8eb2a11..9ae2c3c32 100644 --- a/core/src/main/java/com/volmit/iris/engine/object/IrisObjectRotation.java +++ b/core/src/main/java/com/volmit/iris/engine/object/IrisObjectRotation.java @@ -22,6 +22,7 @@ import com.volmit.iris.Iris; import com.volmit.iris.engine.object.annotations.Desc; import com.volmit.iris.engine.object.annotations.Snippet; import com.volmit.iris.util.collection.KList; +import com.volmit.iris.util.collection.KMap; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; @@ -30,9 +31,12 @@ import org.bukkit.Axis; import org.bukkit.Material; import org.bukkit.block.BlockFace; import org.bukkit.block.data.*; +import org.bukkit.block.data.type.Wall; +import org.bukkit.block.structure.StructureRotation; import org.bukkit.util.BlockVector; import java.util.List; +import java.util.Map; @Snippet("object-rotator") @Accessors(chain = true) @@ -41,6 +45,8 @@ import java.util.List; @Desc("Configures rotation for iris") @Data public class IrisObjectRotation { + private static final List WALL_FACES = List.of(BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST, BlockFace.WEST); + @Desc("If this rotator is enabled or not") private boolean enabled = true; @@ -282,6 +288,22 @@ public class IrisObjectRotation { for (BlockFace i : faces) { g.setFace(i, true); } + } else if (d instanceof Wall wall) { + KMap faces = new KMap<>(); + + for (BlockFace i : WALL_FACES) { + Wall.Height h = wall.getHeight(i); + BlockVector bv = new BlockVector(i.getModX(), i.getModY(), i.getModZ()); + bv = rotate(bv.clone(), spinx, spiny, spinz); + BlockFace r = getFace(bv); + if (WALL_FACES.contains(r)) { + faces.put(r, h); + } + } + + for (BlockFace i : WALL_FACES) { + wall.setHeight(i, faces.getOrDefault(i, Wall.Height.NONE)); + } } else if (d.getMaterial().equals(Material.NETHER_PORTAL) && d instanceof Orientable g) { //TODO: Fucks up logs BlockFace f = faceForAxis(g.getAxis()); From 66a17396662b44ba72cf7b4963ef36a2bfb85616 Mon Sep 17 00:00:00 2001 From: Julian Krings Date: Sun, 25 Aug 2024 22:16:40 +0200 Subject: [PATCH 05/18] v+ --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 62e4c9025..711dcff67 100644 --- a/build.gradle +++ b/build.gradle @@ -32,7 +32,7 @@ plugins { id "de.undercouch.download" version "5.0.1" } -version '3.4.1-1.19.2-1.21.1' +version '3.4.3-1.19.2-1.21.1' // ADD YOURSELF AS A NEW LINE IF YOU WANT YOUR OWN BUILD TASK GENERATED // ======================== WINDOWS ============================= From 3f24d5c8e1c40988015c39a5cae1b73e37f732f4 Mon Sep 17 00:00:00 2001 From: Julian Krings Date: Tue, 27 Aug 2024 15:55:02 +0200 Subject: [PATCH 06/18] fix seed for structure placement --- .../iris/engine/mantle/components/MantleJigsawComponent.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/com/volmit/iris/engine/mantle/components/MantleJigsawComponent.java b/core/src/main/java/com/volmit/iris/engine/mantle/components/MantleJigsawComponent.java index 4f48245bf..17e192c19 100644 --- a/core/src/main/java/com/volmit/iris/engine/mantle/components/MantleJigsawComponent.java +++ b/core/src/main/java/com/volmit/iris/engine/mantle/components/MantleJigsawComponent.java @@ -57,7 +57,7 @@ public class MantleJigsawComponent extends IrisMantleComponent { @ChunkCoordinates private void generateJigsaw(MantleWriter writer, int x, int z, IrisBiome biome, IrisRegion region) { - long seed = cng.fit(Integer.MIN_VALUE, Integer.MIN_VALUE, x, z); + long seed = cng.fit(Integer.MIN_VALUE, Integer.MAX_VALUE, x, z); if (getDimension().getStronghold() != null) { List poss = getDimension().getStrongholds(seed()); @@ -130,7 +130,7 @@ public class MantleJigsawComponent extends IrisMantleComponent { public IrisJigsawStructure guess(int x, int z) { // todo The guess doesnt bring into account that the placer may return -1 // todo doesnt bring skipped placements into account - long seed = cng.fit(Integer.MIN_VALUE, Integer.MIN_VALUE, x, z); + long seed = cng.fit(Integer.MIN_VALUE, Integer.MAX_VALUE, x, z); IrisBiome biome = getEngineMantle().getEngine().getSurfaceBiome((x << 4) + 8, (z << 4) + 8); IrisRegion region = getEngineMantle().getEngine().getRegion((x << 4) + 8, (z << 4) + 8); From 79341bf56287e3253a4bdcb947c90aa9bdfab452 Mon Sep 17 00:00:00 2001 From: Julian Krings Date: Wed, 28 Aug 2024 14:17:54 +0200 Subject: [PATCH 07/18] update adventure api --- build.gradle | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/build.gradle b/build.gradle index 711dcff67..81d90ce2e 100644 --- a/build.gradle +++ b/build.gradle @@ -130,9 +130,9 @@ allprojects { // Shaded implementation 'com.dfsek:Paralithic:0.4.0' implementation 'io.papermc:paperlib:1.0.5' - implementation "net.kyori:adventure-text-minimessage:4.13.1" - implementation 'net.kyori:adventure-platform-bukkit:4.3.2' - implementation 'net.kyori:adventure-api:4.13.1' + implementation "net.kyori:adventure-text-minimessage:4.17.0" + implementation 'net.kyori:adventure-platform-bukkit:4.3.4' + implementation 'net.kyori:adventure-api:4.17.0' //implementation 'org.bytedeco:javacpp:1.5.10' //implementation 'org.bytedeco:cuda-platform:12.3-8.9-1.5.10' compileOnly 'io.lumine:Mythic-Dist:5.2.1' From ec8af56f0d83b774ac4596b379d34c4c6994448b Mon Sep 17 00:00:00 2001 From: Julian Krings Date: Wed, 28 Aug 2024 20:30:43 +0200 Subject: [PATCH 08/18] woops --- .../iris/core/pregenerator/methods/AsyncPregenMethod.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/com/volmit/iris/core/pregenerator/methods/AsyncPregenMethod.java b/core/src/main/java/com/volmit/iris/core/pregenerator/methods/AsyncPregenMethod.java index 5d9048fd3..8bb12df0b 100644 --- a/core/src/main/java/com/volmit/iris/core/pregenerator/methods/AsyncPregenMethod.java +++ b/core/src/main/java/com/volmit/iris/core/pregenerator/methods/AsyncPregenMethod.java @@ -48,7 +48,7 @@ public class AsyncPregenMethod implements PregeneratorMethod { } this.world = world; - burst = new MultiBurst("Iris Async Pregen", Thread.NORM_PRIORITY); + burst = new MultiBurst("Iris Async Pregen", Thread.MIN_PRIORITY); future = new KList<>(256); this.lastUse = new KMap<>(); } @@ -81,7 +81,8 @@ public class AsyncPregenMethod implements PregeneratorMethod { lastUse.put(i, M.ms()); listener.onChunkGenerated(x, z); listener.onChunkCleaned(x, z); - }).join(); + }).get(); + } catch (InterruptedException ignored) { } catch (Throwable e) { e.printStackTrace(); } @@ -157,7 +158,7 @@ public class AsyncPregenMethod implements PregeneratorMethod { if (future.size() > 256) { waitForChunksPartial(256); } - burst.complete(() -> completeChunk(x, z, listener)); + future.add(burst.complete(() -> completeChunk(x, z, listener))); } @Override From 0c92c20c658fba6dee4751f4f8634b7dad201651 Mon Sep 17 00:00:00 2001 From: Julian Krings Date: Sat, 31 Aug 2024 14:13:50 +0200 Subject: [PATCH 09/18] ehm --- .../main/java/com/volmit/iris/engine/framework/Engine.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/com/volmit/iris/engine/framework/Engine.java b/core/src/main/java/com/volmit/iris/engine/framework/Engine.java index a7083fff7..7547126e4 100644 --- a/core/src/main/java/com/volmit/iris/engine/framework/Engine.java +++ b/core/src/main/java/com/volmit/iris/engine/framework/Engine.java @@ -53,6 +53,7 @@ import com.volmit.iris.util.math.Position2; import com.volmit.iris.util.math.RNG; import com.volmit.iris.util.matter.MatterCavern; import com.volmit.iris.util.matter.MatterUpdate; +import com.volmit.iris.util.matter.TileWrapper; import com.volmit.iris.util.matter.slices.container.JigsawPieceContainer; import com.volmit.iris.util.parallel.BurstExecutor; import com.volmit.iris.util.parallel.MultiBurst; @@ -282,10 +283,10 @@ public interface Engine extends DataProvider, Fallible, LootProvider, BlockUpdat } getMantle().getMantle().raiseFlag(c.getX(), c.getZ(), MantleFlag.TILE, () -> J.s(() -> { - getMantle().getMantle().iterateChunk(c.getX(), c.getZ(), TileData.class, (x, y, z, tile) -> { + getMantle().getMantle().iterateChunk(c.getX(), c.getZ(), TileWrapper.class, (x, y, z, v) -> { int betterY = y + getWorld().minHeight(); - if (!TileData.setTileState(c.getBlock(x, betterY, z), tile)) - Iris.warn("Failed to set tile entity data at [%d %d %d | %s] for tile %s!", x, betterY, z, c.getBlock(x, betterY, z).getBlockData().getMaterial().getKey(), tile.getMaterial().name()); + if (!TileData.setTileState(c.getBlock(x, betterY, z), v.getData())) + Iris.warn("Failed to set tile entity data at [%d %d %d | %s] for tile %s!", x, betterY, z, c.getBlock(x, betterY, z).getBlockData().getMaterial().getKey(), v.getData().getMaterial().name()); }); })); getMantle().getMantle().raiseFlag(c.getX(), c.getZ(), MantleFlag.CUSTOM, () -> J.s(() -> { From cc584ba377965067ea12f19b0d1f57e6622f4904 Mon Sep 17 00:00:00 2001 From: Julian Krings Date: Sat, 31 Aug 2024 16:01:25 +0200 Subject: [PATCH 10/18] add progressbar to object saving --- .../com/volmit/iris/core/service/WandSVC.java | 76 ++++++++++++++----- 1 file changed, 57 insertions(+), 19 deletions(-) diff --git a/core/src/main/java/com/volmit/iris/core/service/WandSVC.java b/core/src/main/java/com/volmit/iris/core/service/WandSVC.java index d5a57d77d..8cf63af47 100644 --- a/core/src/main/java/com/volmit/iris/core/service/WandSVC.java +++ b/core/src/main/java/com/volmit/iris/core/service/WandSVC.java @@ -36,6 +36,7 @@ import com.volmit.iris.util.plugin.VolmitSender; import com.volmit.iris.util.scheduling.J; import com.volmit.iris.util.scheduling.S; import com.volmit.iris.util.scheduling.SR; +import com.volmit.iris.util.scheduling.jobs.Job; import org.bukkit.*; import org.bukkit.block.Block; import org.bukkit.enchantments.Enchantment; @@ -55,11 +56,12 @@ import java.awt.Color; import java.util.ArrayList; import java.util.Objects; import java.util.concurrent.CountDownLatch; +import java.util.concurrent.atomic.AtomicInteger; public class WandSVC implements IrisService { private static final Particle CRIT_MAGIC = E.getOrDefault(Particle.class, "CRIT_MAGIC", "CRIT"); private static final Particle REDSTONE = E.getOrDefault(Particle.class, "REDSTONE", "DUST"); - private static final int BLOCKS_PER_TICK = Integer.parseInt(System.getProperty("iris.blocks_per_tick", "1000")); + private static final int MS_PER_TICK = Integer.parseInt(System.getProperty("iris.ms_per_tick", "30")); private static ItemStack dust; private static ItemStack wand; @@ -85,27 +87,63 @@ public class WandSVC implements IrisService { IrisObject s = new IrisObject(c.getSizeX(), c.getSizeY(), c.getSizeZ()); var it = c.iterator(); + + int total = c.getSizeX() * c.getSizeY() * c.getSizeZ(); + AtomicInteger i = new AtomicInteger(0); var latch = new CountDownLatch(1); - new SR() { + new Job() { @Override - public void run() { - for (int i = 0; i < BLOCKS_PER_TICK; i++) { - if (!it.hasNext()) { - cancel(); - latch.countDown(); - return; - } - - var b = it.next(); - if (b.getType().equals(Material.AIR)) - continue; - - BlockVector bv = b.getLocation().subtract(c.getLowerNE().toVector()).toVector().toBlockVector(); - s.setUnsigned(bv.getBlockX(), bv.getBlockY(), bv.getBlockZ(), b); - } + public String getName() { + return "Scanning Selection"; } - }; - latch.await(); + + @Override + public void execute() { + new SR() { + @Override + public void run() { + var time = M.ms() + MS_PER_TICK; + while (time > M.ms()) { + if (!it.hasNext()) { + cancel(); + latch.countDown(); + return; + } + + try { + var b = it.next(); + if (b.getType().equals(Material.AIR)) + continue; + + BlockVector bv = b.getLocation().subtract(c.getLowerNE().toVector()).toVector().toBlockVector(); + s.setUnsigned(bv.getBlockX(), bv.getBlockY(), bv.getBlockZ(), b); + } finally { + i.incrementAndGet(); + } + } + } + }; + try { + latch.await(); + } catch (InterruptedException ignored) {} + } + + @Override + public void completeWork() {} + + @Override + public int getTotalWork() { + return total; + } + + @Override + public int getWorkCompleted() { + return i.get(); + } + }.execute(new VolmitSender(p), true, () -> {}); + try { + latch.await(); + } catch (InterruptedException ignored) {} return s; } catch (Throwable e) { From 18e57e40970fadb3273823dd08c3e9f87e3a119c Mon Sep 17 00:00:00 2001 From: Julian Krings Date: Sat, 31 Aug 2024 16:28:52 +0200 Subject: [PATCH 11/18] add progressbar to object writing --- .../iris/core/commands/CommandObject.java | 2 +- .../volmit/iris/engine/object/IrisObject.java | 95 +++++++++++++++++++ 2 files changed, 96 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/com/volmit/iris/core/commands/CommandObject.java b/core/src/main/java/com/volmit/iris/core/commands/CommandObject.java index c5cdd74b6..fd2d8f214 100644 --- a/core/src/main/java/com/volmit/iris/core/commands/CommandObject.java +++ b/core/src/main/java/com/volmit/iris/core/commands/CommandObject.java @@ -381,7 +381,7 @@ public class CommandObject implements DecreeExecutor { return; } try { - o.write(file); + o.write(file, sender()); } catch (IOException e) { sender().sendMessage(C.RED + "Failed to save object because of an IOException: " + e.getMessage()); Iris.reportError(e); diff --git a/core/src/main/java/com/volmit/iris/engine/object/IrisObject.java b/core/src/main/java/com/volmit/iris/engine/object/IrisObject.java index 0866ee63f..472dad80c 100644 --- a/core/src/main/java/com/volmit/iris/engine/object/IrisObject.java +++ b/core/src/main/java/com/volmit/iris/engine/object/IrisObject.java @@ -43,6 +43,7 @@ import com.volmit.iris.util.parallel.MultiBurst; import com.volmit.iris.util.plugin.VolmitSender; import com.volmit.iris.util.scheduling.IrisLock; import com.volmit.iris.util.scheduling.PrecisionStopwatch; +import com.volmit.iris.util.scheduling.jobs.Job; import com.volmit.iris.util.stream.ProceduralStream; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -63,7 +64,9 @@ import org.bukkit.util.Vector; import java.io.*; import java.util.*; +import java.util.concurrent.CountDownLatch; import java.util.concurrent.atomic.AtomicInteger; +import java.util.concurrent.atomic.AtomicReference; import java.util.function.BiConsumer; @Accessors(chain = true) @@ -384,6 +387,88 @@ public class IrisObject extends IrisRegistrant { } } + public void write(OutputStream o, VolmitSender sender) throws IOException { + AtomicReference ref = new AtomicReference<>(); + CountDownLatch latch = new CountDownLatch(1); + new Job() { + private int total = getBlocks().size() * 3 + getStates().size(); + private int c = 0; + + @Override + public String getName() { + return "Saving Object"; + } + + @Override + public void execute() { + try { + DataOutputStream dos = new DataOutputStream(o); + dos.writeInt(w); + dos.writeInt(h); + dos.writeInt(d); + dos.writeUTF("Iris V2 IOB;"); + + KList palette = new KList<>(); + + for (BlockData i : getBlocks().values()) { + palette.addIfMissing(i.getAsString()); + ++c; + } + total -= getBlocks().size() - palette.size(); + + dos.writeShort(palette.size()); + + for (String i : palette) { + dos.writeUTF(i); + ++c; + } + + dos.writeInt(getBlocks().size()); + + for (BlockVector i : getBlocks().keySet()) { + dos.writeShort(i.getBlockX()); + dos.writeShort(i.getBlockY()); + dos.writeShort(i.getBlockZ()); + dos.writeShort(palette.indexOf(getBlocks().get(i).getAsString())); + ++c; + } + + dos.writeInt(getStates().size()); + for (BlockVector i : getStates().keySet()) { + dos.writeShort(i.getBlockX()); + dos.writeShort(i.getBlockY()); + dos.writeShort(i.getBlockZ()); + getStates().get(i).toBinary(dos); + ++c; + } + } catch (IOException e) { + ref.set(e); + } finally { + latch.countDown(); + } + } + + @Override + public void completeWork() {} + + @Override + public int getTotalWork() { + return total; + } + + @Override + public int getWorkCompleted() { + return c; + } + }.execute(sender, true, () -> {}); + + try { + latch.await(); + } catch (InterruptedException ignored) {} + if (ref.get() != null) + throw ref.get(); + } + public void read(File file) throws IOException { var fin = new BufferedInputStream(new FileInputStream(file)); try { @@ -408,6 +493,16 @@ public class IrisObject extends IrisRegistrant { out.close(); } + public void write(File file, VolmitSender sender) throws IOException { + if (file == null) { + return; + } + + FileOutputStream out = new FileOutputStream(file); + write(out, sender); + out.close(); + } + public void shrinkwrap() { BlockVector min = new BlockVector(); BlockVector max = new BlockVector(); From 8041db4f40fc91410a89efb876a0b5072c93bbee Mon Sep 17 00:00:00 2001 From: RePixelatedMC <107539181+RePixelatedMC@users.noreply.github.com> Date: Sat, 31 Aug 2024 17:17:20 +0200 Subject: [PATCH 12/18] - New draw system - Crazy performance compared to the old system --- .../volmit/iris/core/wand/WandSelection.java | 119 ++++++++---------- 1 file changed, 53 insertions(+), 66 deletions(-) diff --git a/core/src/main/java/com/volmit/iris/core/wand/WandSelection.java b/core/src/main/java/com/volmit/iris/core/wand/WandSelection.java index e2b99633b..30ecd3771 100644 --- a/core/src/main/java/com/volmit/iris/core/wand/WandSelection.java +++ b/core/src/main/java/com/volmit/iris/core/wand/WandSelection.java @@ -30,9 +30,11 @@ import org.bukkit.util.Vector; import java.awt.*; public class WandSelection { - private static final Particle REDSTONE = E.getOrDefault(Particle.class, "REDSTONE", "DUST"); + private static final Particle REDSTONE = E.getOrDefault(Particle.class, "REDSTONE", "DUST"); private final Cuboid c; private final Player p; + private static final double STEP = 0.25; + private static final int MAX_PARTICLES = 10000; public WandSelection(Cuboid c, Player p) { this.c = c; @@ -40,77 +42,62 @@ public class WandSelection { } public void draw() { - double accuracy; - double dist; + Location playerLoc = p.getLocation(); + double maxDistanceSquared = 256 * 256; + int particleCount = 0; - for (double i = c.getLowerX() - 1; i < c.getUpperX() + 1; i += 0.25) { - for (double j = c.getLowerY() - 1; j < c.getUpperY() + 1; j += 0.25) { - for (double k = c.getLowerZ() - 1; k < c.getUpperZ() + 1; k += 0.25) { - boolean ii = i == c.getLowerX() || i == c.getUpperX(); - boolean jj = j == c.getLowerY() || j == c.getUpperY(); - boolean kk = k == c.getLowerZ() || k == c.getUpperZ(); + // cube! + Location[][] edges = { + {c.getLowerNE(), new Location(c.getWorld(), c.getUpperX() + 1, c.getLowerY(), c.getLowerZ())}, + {c.getLowerNE(), new Location(c.getWorld(), c.getLowerX(), c.getUpperY() + 1, c.getLowerZ())}, + {c.getLowerNE(), new Location(c.getWorld(), c.getLowerX(), c.getLowerY(), c.getUpperZ() + 1)}, + {new Location(c.getWorld(), c.getUpperX() + 1, c.getLowerY(), c.getLowerZ()), new Location(c.getWorld(), c.getUpperX() + 1, c.getUpperY() + 1, c.getLowerZ())}, + {new Location(c.getWorld(), c.getUpperX() + 1, c.getLowerY(), c.getLowerZ()), new Location(c.getWorld(), c.getUpperX() + 1, c.getLowerY(), c.getUpperZ() + 1)}, + {new Location(c.getWorld(), c.getLowerX(), c.getUpperY() + 1, c.getLowerZ()), new Location(c.getWorld(), c.getUpperX() + 1, c.getUpperY() + 1, c.getLowerZ())}, + {new Location(c.getWorld(), c.getLowerX(), c.getUpperY() + 1, c.getLowerZ()), new Location(c.getWorld(), c.getLowerX(), c.getUpperY() + 1, c.getUpperZ() + 1)}, + {new Location(c.getWorld(), c.getLowerX(), c.getLowerY(), c.getUpperZ() + 1), new Location(c.getWorld(), c.getUpperX() + 1, c.getLowerY(), c.getUpperZ() + 1)}, + {new Location(c.getWorld(), c.getLowerX(), c.getLowerY(), c.getUpperZ() + 1), new Location(c.getWorld(), c.getLowerX(), c.getUpperY() + 1, c.getUpperZ() + 1)}, + {new Location(c.getWorld(), c.getUpperX() + 1, c.getUpperY() + 1, c.getLowerZ()), new Location(c.getWorld(), c.getUpperX() + 1, c.getUpperY() + 1, c.getUpperZ() + 1)}, + {new Location(c.getWorld(), c.getLowerX(), c.getUpperY() + 1, c.getUpperZ() + 1), new Location(c.getWorld(), c.getUpperX() + 1, c.getUpperY() + 1, c.getUpperZ() + 1)}, + {new Location(c.getWorld(), c.getUpperX() + 1, c.getLowerY(), c.getUpperZ() + 1), new Location(c.getWorld(), c.getUpperX() + 1, c.getUpperY() + 1, c.getUpperZ() + 1)} + }; - if ((ii && jj) || (ii && kk) || (kk && jj)) { - Vector push = new Vector(0, 0, 0); + for (Location[] edge : edges) { + Vector direction = edge[1].toVector().subtract(edge[0].toVector()); + double length = direction.length(); + direction.normalize(); - if (i == c.getLowerX()) { - push.add(new Vector(-0.55, 0, 0)); - } + for (double d = 0; d <= length; d += STEP) { + Location particleLoc = edge[0].clone().add(direction.clone().multiply(d)); - if (j == c.getLowerY()) { - push.add(new Vector(0, -0.55, 0)); - } - - if (k == c.getLowerZ()) { - push.add(new Vector(0, 0, -0.55)); - } - - if (i == c.getUpperX()) { - push.add(new Vector(0.55, 0, 0)); - } - - if (j == c.getUpperY()) { - push.add(new Vector(0, 0.55, 0)); - } - - if (k == c.getUpperZ()) { - push.add(new Vector(0, 0, 0.55)); - } - - Location a = new Location(c.getWorld(), i, j, k).add(0.5, 0.5, 0.5).add(push); - accuracy = M.lerpInverse(0, 64 * 64, p.getLocation().distanceSquared(a)); - dist = M.lerp(0.125, 3.5, accuracy); - - if (M.r(M.min(dist * 5, 0.9D) * 0.995)) { - continue; - } - - if (ii && jj) { - a.add(0, 0, RNG.r.d(-0.3, 0.3)); - } - - if (kk && jj) { - a.add(RNG.r.d(-0.3, 0.3), 0, 0); - } - - if (ii && kk) { - a.add(0, RNG.r.d(-0.3, 0.3), 0); - } - - if (p.getLocation().distanceSquared(a) < 256 * 256) { - Color color = Color.getHSBColor((float) (0.5f + (Math.sin((i + j + k + (p.getTicksLived() / 2f)) / (20f)) / 2)), 1, 1); - int r = color.getRed(); - int g = color.getGreen(); - int b = color.getBlue(); - - p.spawnParticle(REDSTONE, a.getX(), a.getY(), a.getZ(), - 1, 0, 0, 0, 0, - new Particle.DustOptions(org.bukkit.Color.fromRGB(r, g, b), - (float) dist * 3f)); - } - } + if (playerLoc.distanceSquared(particleLoc) > maxDistanceSquared) { + continue; } + + if (particleCount >= MAX_PARTICLES) { + return; + } + + spawnParticle(particleLoc, playerLoc); + particleCount++; } } } + + private void spawnParticle(Location particleLoc, Location playerLoc) { + double accuracy = M.lerpInverse(0, 64 * 64, playerLoc.distanceSquared(particleLoc)); + double dist = M.lerp(0.125, 3.5, accuracy); + + if (M.r(Math.min(dist * 5, 0.9D) * 0.995)) { + return; + } + + float hue = (float) (0.5f + (Math.sin((particleLoc.getX() + particleLoc.getY() + particleLoc.getZ() + (p.getTicksLived() / 2f)) / 20f) / 2)); + Color color = Color.getHSBColor(hue, 1, 1); + + p.spawnParticle(REDSTONE, particleLoc, + 0, 0, 0, 0, 1, + new Particle.DustOptions(org.bukkit.Color.fromRGB(color.getRed(), color.getGreen(), color.getBlue()), + (float) dist * 3f)); + } } From 08fa436885a7237bf517578251ed88603551d94f Mon Sep 17 00:00:00 2001 From: RePixelatedMC <107539181+RePixelatedMC@users.noreply.github.com> Date: Sat, 31 Aug 2024 17:45:09 +0200 Subject: [PATCH 13/18] better --- .../main/java/com/volmit/iris/core/wand/WandSelection.java | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/core/src/main/java/com/volmit/iris/core/wand/WandSelection.java b/core/src/main/java/com/volmit/iris/core/wand/WandSelection.java index 30ecd3771..d6f3d4aac 100644 --- a/core/src/main/java/com/volmit/iris/core/wand/WandSelection.java +++ b/core/src/main/java/com/volmit/iris/core/wand/WandSelection.java @@ -33,8 +33,7 @@ public class WandSelection { private static final Particle REDSTONE = E.getOrDefault(Particle.class, "REDSTONE", "DUST"); private final Cuboid c; private final Player p; - private static final double STEP = 0.25; - private static final int MAX_PARTICLES = 10000; + private static final double STEP = 0.10; public WandSelection(Cuboid c, Player p) { this.c = c; @@ -74,10 +73,6 @@ public class WandSelection { continue; } - if (particleCount >= MAX_PARTICLES) { - return; - } - spawnParticle(particleLoc, playerLoc); particleCount++; } From 67638440309a69df06977ca3ae0e093a9f373903 Mon Sep 17 00:00:00 2001 From: RePixelatedMC <107539181+RePixelatedMC@users.noreply.github.com> Date: Sat, 31 Aug 2024 18:29:43 +0200 Subject: [PATCH 14/18] back to debug --- .../src/main/java/com/volmit/iris/engine/object/IrisObject.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/com/volmit/iris/engine/object/IrisObject.java b/core/src/main/java/com/volmit/iris/engine/object/IrisObject.java index 472dad80c..aabae1998 100644 --- a/core/src/main/java/com/volmit/iris/engine/object/IrisObject.java +++ b/core/src/main/java/com/volmit/iris/engine/object/IrisObject.java @@ -573,7 +573,7 @@ public class IrisObject extends IrisRegistrant { getBlocks().put(v, data); TileData state = TileData.getTileState(block); if (state != null) { - Iris.info("Saved State " + v); + Iris.debug("Saved State " + v); getStates().put(v, state); } } From 3c9bcc9bb07f55aaa2570437deb0c8148995f6e9 Mon Sep 17 00:00:00 2001 From: Julian Krings Date: Sun, 1 Sep 2024 15:24:49 +0200 Subject: [PATCH 15/18] add chunked cuboid iterator --- .../com/volmit/iris/core/service/WandSVC.java | 24 +++++- .../com/volmit/iris/util/data/Cuboid.java | 83 +++++++++++++++++++ 2 files changed, 103 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/com/volmit/iris/core/service/WandSVC.java b/core/src/main/java/com/volmit/iris/core/service/WandSVC.java index 8cf63af47..1899941bc 100644 --- a/core/src/main/java/com/volmit/iris/core/service/WandSVC.java +++ b/core/src/main/java/com/volmit/iris/core/service/WandSVC.java @@ -86,12 +86,14 @@ public class WandSVC implements IrisService { Cuboid c = new Cuboid(f[0], f[1]); IrisObject s = new IrisObject(c.getSizeX(), c.getSizeY(), c.getSizeZ()); - var it = c.iterator(); + var it = c.chunkedIterator(); int total = c.getSizeX() * c.getSizeY() * c.getSizeZ(); - AtomicInteger i = new AtomicInteger(0); var latch = new CountDownLatch(1); new Job() { + private int i; + private Chunk chunk; + @Override public String getName() { return "Scanning Selection"; @@ -105,6 +107,11 @@ public class WandSVC implements IrisService { var time = M.ms() + MS_PER_TICK; while (time > M.ms()) { if (!it.hasNext()) { + if (chunk != null) { + chunk.removePluginChunkTicket(Iris.instance); + chunk = null; + } + cancel(); latch.countDown(); return; @@ -112,13 +119,22 @@ public class WandSVC implements IrisService { try { var b = it.next(); + var bChunk = b.getChunk(); + if (chunk == null) { + chunk = bChunk; + chunk.addPluginChunkTicket(Iris.instance); + } else if (chunk != bChunk) { + chunk.removePluginChunkTicket(Iris.instance); + chunk = bChunk; + } + if (b.getType().equals(Material.AIR)) continue; BlockVector bv = b.getLocation().subtract(c.getLowerNE().toVector()).toVector().toBlockVector(); s.setUnsigned(bv.getBlockX(), bv.getBlockY(), bv.getBlockZ(), b); } finally { - i.incrementAndGet(); + i++; } } } @@ -138,7 +154,7 @@ public class WandSVC implements IrisService { @Override public int getWorkCompleted() { - return i.get(); + return i; } }.execute(new VolmitSender(p), true, () -> {}); try { diff --git a/core/src/main/java/com/volmit/iris/util/data/Cuboid.java b/core/src/main/java/com/volmit/iris/util/data/Cuboid.java index 437f65298..c2ea5b51a 100644 --- a/core/src/main/java/com/volmit/iris/util/data/Cuboid.java +++ b/core/src/main/java/com/volmit/iris/util/data/Cuboid.java @@ -20,6 +20,7 @@ package com.volmit.iris.util.data; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.math.Direction; +import com.volmit.iris.util.math.Position2; import org.bukkit.*; import org.bukkit.block.Block; import org.bukkit.configuration.serialization.ConfigurationSerializable; @@ -651,6 +652,10 @@ public class Cuboid implements Iterable, Cloneable, ConfigurationSerializ return new CuboidIterator(getWorld(), x1, y1, z1, x2, y2, z2); } + public Iterator chunkedIterator() { + return new ChunkedCuboidIterator(getWorld(), x1, y1, z1, x2, y2, z2); + } + /* * (non-Javadoc) * @@ -746,4 +751,82 @@ public class Cuboid implements Iterable, Cloneable, ConfigurationSerializ } } + public static class ChunkedCuboidIterator implements Iterator { + private final World w; + private final int minRX, minY, minRZ, maxRX, maxY, maxRZ; + private final int minCX, minCZ, maxCX, maxCZ; + private int mX, mZ, bX, rX, rZ, y; + + private Position2 chunk; + private int cX, cZ; + + public ChunkedCuboidIterator(World w, int x1, int y1, int z1, int x2, int y2, int z2) { + this.w = w; + minY = Math.min(y1, y2); + maxY = Math.max(y1, y2); + int minX = Math.min(x1, x2); + int minZ = Math.min(z1, z2); + int maxX = Math.max(x1, x2); + int maxZ = Math.max(z1, z2); + minRX = minX & 15; + minRZ = minZ & 15; + maxRX = maxX & 15; + maxRZ = maxZ & 15; + + minCX = minX >> 4; + minCZ = minZ >> 4; + maxCX = maxX >> 4; + maxCZ = maxZ >> 4; + cX = minCX; + cZ = minCZ; + + rX = minX & 15; + rZ = minZ & 15; + y = minY; + } + + @Override + public boolean hasNext() { + return chunk != null || hasNextChunk(); + } + + public boolean hasNextChunk() { + return cX <= maxCX && cZ <= maxCZ; + } + + @Override + public Block next() { + if (chunk == null) { + chunk = new Position2(cX, cZ); + if (++cX > maxCX) { + cX = minCX; + cZ++; + } + + mX = chunk.getX() == maxCX ? maxRX : 15; + mZ = chunk.getZ() == maxCZ ? maxRZ : 15; + rX = bX = chunk.getX() == minCX ? minRX : 0; + rZ = chunk.getZ() == minCZ ? minRZ : 0; + } + + var b = w.getBlockAt((chunk.getX() << 4) + rX, y, (chunk.getZ() << 4) + rZ); + if (++y >= maxY) { + y = minY; + if (++rX > mX) { + if (++rZ > mZ) { + chunk = null; + return b; + } + rX = bX; + } + } + + return b; + } + + @Override + public void remove() { + // nop + } + } } \ No newline at end of file From e101155a4c34a3cb4d224d7558686615d8a33c4d Mon Sep 17 00:00:00 2001 From: Julian Krings Date: Sun, 1 Sep 2024 18:51:23 +0200 Subject: [PATCH 16/18] fix datapack particle rarity --- .../java/com/volmit/iris/engine/object/IrisBiomeCustom.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/com/volmit/iris/engine/object/IrisBiomeCustom.java b/core/src/main/java/com/volmit/iris/engine/object/IrisBiomeCustom.java index dd3e16af6..aa3859c83 100644 --- a/core/src/main/java/com/volmit/iris/engine/object/IrisBiomeCustom.java +++ b/core/src/main/java/com/volmit/iris/engine/object/IrisBiomeCustom.java @@ -104,7 +104,7 @@ public class IrisBiomeCustom { JSONObject po = new JSONObject(); po.put("type", ambientParticle.getParticle().name().toLowerCase()); particle.put("options", po); - particle.put("probability", ambientParticle.getRarity()); + particle.put("probability", 1f/ambientParticle.getRarity()); effects.put("particle", particle); } From b0eedee519a5bd71587e9bba913f1bf60391b366 Mon Sep 17 00:00:00 2001 From: RePixelatedMC <107539181+RePixelatedMC@users.noreply.github.com> Date: Wed, 4 Sep 2024 15:07:30 +0200 Subject: [PATCH 17/18] - Progress bar for /iris std dist - Noted out that its in chunks for radius in /iris std dist --- .../iris/core/commands/CommandStudio.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/com/volmit/iris/core/commands/CommandStudio.java b/core/src/main/java/com/volmit/iris/core/commands/CommandStudio.java index 774e760b8..7227b431d 100644 --- a/core/src/main/java/com/volmit/iris/core/commands/CommandStudio.java +++ b/core/src/main/java/com/volmit/iris/core/commands/CommandStudio.java @@ -55,6 +55,7 @@ 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.plugin.VolmitSender; +import com.volmit.iris.util.scheduling.ChronoLatch; import com.volmit.iris.util.scheduling.J; import com.volmit.iris.util.scheduling.O; import com.volmit.iris.util.scheduling.PrecisionStopwatch; @@ -63,6 +64,7 @@ import io.papermc.lib.PaperLib; import org.bukkit.*; import org.bukkit.event.inventory.InventoryType; import org.bukkit.inventory.Inventory; +import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.util.BlockVector; import org.bukkit.util.Vector; @@ -77,6 +79,7 @@ import java.time.temporal.ChronoUnit; import java.util.Arrays; import java.util.Date; import java.util.Objects; +import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; import java.util.concurrent.atomic.AtomicInteger; @@ -335,29 +338,38 @@ public class CommandStudio implements DecreeExecutor { @Decree(description = "Get all structures in a radius of chunks", aliases = "dist", origin = DecreeOrigin.PLAYER) - public void distances(@Param(description = "The radius") int radius) { + public void distances(@Param(description = "The radius in chunks") int radius) { var engine = engine(); if (engine == null) { sender().sendMessage(C.RED + "Only works in an Iris world!"); return; } var sender = sender(); - int d = radius*2; + int d = radius * 2; KMap> data = new KMap<>(); var multiBurst = new MultiBurst("Distance Sampler", Thread.MIN_PRIORITY); var executor = multiBurst.burst(radius * radius); sender.sendMessage(C.GRAY + "Generating data..."); var loc = player().getLocation(); + int totalTasks = d * d; + AtomicInteger completedTasks = new AtomicInteger(0); + int c = J.ar(() -> { + sender.sendProgress((double) completedTasks.get() / totalTasks, "Finding structures"); + }, 0); + new Spiraler(d, d, (x, z) -> executor.queue(() -> { var struct = engine.getStructureAt(x, z); if (struct != null) { data.computeIfAbsent(struct.getLoadKey(), (k) -> new KList<>()).add(new Position2(x, z)); } + completedTasks.incrementAndGet(); })).setOffset(loc.getBlockX(), loc.getBlockZ()).drain(); executor.complete(); multiBurst.close(); + J.car(c); + for (var key : data.keySet()) { var list = data.get(key); KList distances = new KList<>(list.size() - 1); @@ -390,6 +402,7 @@ public class CommandStudio implements DecreeExecutor { } } + @Decree(description = "Render a world map (External GUI)", aliases = "render") public void map( @Param(name = "world", description = "The world to open the generator for", contextual = true) From e21fdf46e0dede099a58398483ab78caee7c5964 Mon Sep 17 00:00:00 2001 From: RePixelatedMC <107539181+RePixelatedMC@users.noreply.github.com> Date: Thu, 5 Sep 2024 21:57:40 +0200 Subject: [PATCH 18/18] - New Noise color < need further testing > - Iris schem converter --- .../com/volmit/iris/core/IrisSettings.java | 1 + .../iris/core/commands/CommandDeveloper.java | 1 + .../iris/core/commands/CommandObject.java | 11 + .../iris/core/gui/NoiseExplorerGUI.java | 8 +- .../volmit/iris/core/tools/IrisConverter.java | 287 +----------------- 5 files changed, 34 insertions(+), 274 deletions(-) diff --git a/core/src/main/java/com/volmit/iris/core/IrisSettings.java b/core/src/main/java/com/volmit/iris/core/IrisSettings.java index 9eccc80e1..19c16e6ba 100644 --- a/core/src/main/java/com/volmit/iris/core/IrisSettings.java +++ b/core/src/main/java/com/volmit/iris/core/IrisSettings.java @@ -171,6 +171,7 @@ public class IrisSettings { public static class IrisSettingsGUI { public boolean useServerLaunchedGuis = true; public boolean maximumPregenGuiFPS = false; + public boolean colorMode = true; } @Data diff --git a/core/src/main/java/com/volmit/iris/core/commands/CommandDeveloper.java b/core/src/main/java/com/volmit/iris/core/commands/CommandDeveloper.java index 81473b45f..cb43a29d2 100644 --- a/core/src/main/java/com/volmit/iris/core/commands/CommandDeveloper.java +++ b/core/src/main/java/com/volmit/iris/core/commands/CommandDeveloper.java @@ -26,6 +26,7 @@ import com.volmit.iris.core.nms.datapack.DataVersion; import com.volmit.iris.core.nms.v1X.NMSBinding1X; import com.volmit.iris.core.pregenerator.ChunkUpdater; import com.volmit.iris.core.service.IrisEngineSVC; +import com.volmit.iris.core.tools.IrisConverter; import com.volmit.iris.core.tools.IrisPackBenchmarking; import com.volmit.iris.core.tools.IrisToolbelt; import com.volmit.iris.engine.framework.Engine; diff --git a/core/src/main/java/com/volmit/iris/core/commands/CommandObject.java b/core/src/main/java/com/volmit/iris/core/commands/CommandObject.java index fd2d8f214..6c7270db8 100644 --- a/core/src/main/java/com/volmit/iris/core/commands/CommandObject.java +++ b/core/src/main/java/com/volmit/iris/core/commands/CommandObject.java @@ -24,6 +24,7 @@ import com.volmit.iris.core.loader.IrisData; import com.volmit.iris.core.service.ObjectSVC; import com.volmit.iris.core.service.StudioSVC; import com.volmit.iris.core.service.WandSVC; +import com.volmit.iris.core.tools.IrisConverter; import com.volmit.iris.engine.framework.Engine; import com.volmit.iris.engine.object.*; import com.volmit.iris.util.data.Cuboid; @@ -210,6 +211,16 @@ public class CommandObject implements DecreeExecutor { } } + @Decree(description = "Convert .schem files in the 'convert' folder to .iob files.") + public void convert () { + try { + IrisConverter.convertSchematics(sender()); + } catch (Exception e) { + e.printStackTrace(); + } + + } + @Decree(description = "Get a powder that reveals objects", studio = true, aliases = "d") public void dust() { player().getInventory().addItem(WandSVC.createDust()); diff --git a/core/src/main/java/com/volmit/iris/core/gui/NoiseExplorerGUI.java b/core/src/main/java/com/volmit/iris/core/gui/NoiseExplorerGUI.java index 6f816f6f3..e4be6dea9 100644 --- a/core/src/main/java/com/volmit/iris/core/gui/NoiseExplorerGUI.java +++ b/core/src/main/java/com/volmit/iris/core/gui/NoiseExplorerGUI.java @@ -19,6 +19,7 @@ package com.volmit.iris.core.gui; import com.volmit.iris.Iris; +import com.volmit.iris.core.IrisSettings; import com.volmit.iris.core.events.IrisEngineHotloadEvent; import com.volmit.iris.engine.object.NoiseStyle; import com.volmit.iris.util.collection.KList; @@ -61,7 +62,7 @@ public class NoiseExplorerGUI extends JPanel implements MouseWheelListener, List @SuppressWarnings("CanBeFinal") RollingSequence r = new RollingSequence(20); @SuppressWarnings("CanBeFinal") - boolean colorMode = true; + boolean colorMode = IrisSettings.get().getGui().colorMode; double scale = 1; CNG cng = NoiseStyle.STATIC.create(new RNG(RNG.r.nextLong())); @SuppressWarnings("CanBeFinal") @@ -274,7 +275,10 @@ public class NoiseExplorerGUI extends JPanel implements MouseWheelListener, List n = n > 1 ? 1 : n < 0 ? 0 : n; try { - Color color = colorMode ? Color.getHSBColor((float) (n), 1f - (float) (n * n * n * n * n * n), 1f - (float) n) : Color.getHSBColor(0f, 0f, (float) n); + //Color color = colorMode ? Color.getHSBColor((float) (n), 1f - (float) (n * n * n * n * n * n), 1f - (float) n) : Color.getHSBColor(0f, 0f, (float) n); + //Color color = colorMode ? Color.getHSBColor((float) (n), (float) (n * n * n * n * n * n), (float) n) : Color.getHSBColor(0f, 0f, (float) n); + Color color = colorMode ? Color.getHSBColor((float) n, (float) (n * n * n * n * n * n), (float) n) : Color.getHSBColor(0f, 0f, (float) n); + int rgb = color.getRGB(); img.setRGB(xx, z, rgb); } catch (Throwable ignored) { diff --git a/core/src/main/java/com/volmit/iris/core/tools/IrisConverter.java b/core/src/main/java/com/volmit/iris/core/tools/IrisConverter.java index fb4d344eb..f58cc5c69 100644 --- a/core/src/main/java/com/volmit/iris/core/tools/IrisConverter.java +++ b/core/src/main/java/com/volmit/iris/core/tools/IrisConverter.java @@ -12,9 +12,11 @@ import com.volmit.iris.util.reflect.V; import com.volmit.iris.util.scheduling.J; import com.volmit.iris.util.scheduling.PrecisionStopwatch; import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap; +import org.apache.commons.io.FileUtils; import org.bukkit.Bukkit; import org.bukkit.block.Block; import org.bukkit.block.data.BlockData; +import org.bukkit.util.FileUtil; import org.bukkit.util.Vector; import java.io.File; @@ -33,11 +35,15 @@ public class IrisConverter { FilenameFilter filter = (dir, name) -> name.endsWith(".schem"); File[] fileList = folder.listFiles(filter); + if (fileList == null) { + sender.sendMessage("No schematic files to convert found in " + folder.getAbsolutePath()); + return; + } ExecutorService executorService = Executors.newFixedThreadPool(1); executorService.submit(() -> { for (File schem : fileList) { try { - PrecisionStopwatch p = new PrecisionStopwatch(); + PrecisionStopwatch p = PrecisionStopwatch.start(); boolean largeObject = false; NamedTag tag = null; try { @@ -52,21 +58,17 @@ public class IrisConverter { int objW = ((ShortTag) compound.get("Width")).getValue(); int objH = ((ShortTag) compound.get("Height")).getValue(); int objD = ((ShortTag) compound.get("Length")).getValue(); + int i = -1; int mv = objW * objH * objD; AtomicInteger v = new AtomicInteger(0); - AtomicInteger fv = new AtomicInteger(0); if (mv > 500_000) { largeObject = true; Iris.info(C.GRAY + "Converting.. "+ schem.getName() + " -> " + schem.getName().replace(".schem", ".iob")); Iris.info(C.GRAY + "- It may take a while"); if (sender.isPlayer()) { - J.a(() -> { -// while (v.get() != mv) { -// double pr = ((double) v.get() / (double ) mv); -// sender.sendProgress(pr, "Converting"); -// J.sleep(16); -// } - }); + i = J.ar(() -> { + sender.sendProgress((double) v.get() / mv, "Converting"); + }, 0); } } @@ -82,165 +84,8 @@ public class IrisConverter { ByteArrayTag byteArray = (ByteArrayTag) compound.get("BlockData"); byte[] originalBlockArray = byteArray.getValue(); - int b = 0; - int a = 0; - Map y = new HashMap<>(); - Map x = new HashMap<>(); - Map z = new HashMap<>(); - // Height adjustments - for (int h = 0; h < objH; h++) { - if (b == 0) { - y.put(h, (byte) 0); - } - if (b > 0) { - y.put(h, (byte) 1); - } - a = 0; - b = 0; - for (int d = 0; d < objD; d++) { - for (int w = 0; w < objW; w++) { - BlockData db = blockmap.get((int) originalBlockArray[fv.get()]); - if(db.getAsString().contains("minecraft:air")) { - a++; - } else { - b++; - } - fv.getAndAdd(1); - } - } - } - fv.set(0); - - // Width adjustments - for (int w = 0; w < objW; w++) { - if (b == 0) { - x.put(w, (byte) 0); - } - if (b > 0) { - x.put(w, (byte) 1); - } - a = 0; - b = 0; - for (int h = 0; h < objH; h++) { - for (int d = 0; d < objD; d++) { - BlockData db = blockmap.get((int) originalBlockArray[fv.get()]); - if(db.getAsString().contains("minecraft:air")) { - a++; - } else { - b++; - } - fv.getAndAdd(1); - } - } - } - fv.set(0); - - // Depth adjustments - for (int d = 0; d < objD; d++) { - if (b == 0) { - z.put(d, (byte) 0); - } - if (b > 0) { - z.put(d, (byte) 1); - } - a = 0; - b = 0; - for (int h = 0; h < objH; h++) { - for (int w = 0; w < objW; w++) { - BlockData db = blockmap.get((int) originalBlockArray[fv.get()]); - if(db.getAsString().contains("minecraft:air")) { - a++; - } else { - b++; - } - fv.getAndAdd(1); - } - } - } - fv.set(0); - int CorrectObjH = getCorrectY(y, objH); - int CorrectObjW = getCorrectX(x, objW); - int CorrectObjD = getCorrectZ(z, objD); - - //IrisObject object = new IrisObject(CorrectObjW, CorrectObjH, CorrectObjH); IrisObject object = new IrisObject(objW, objH, objD); - Vector originalVector = new Vector(objW,objH,objD); - - - int[] yc = null; - int[] xc = null; - int[] zc = null; - - - int fo = 0; - int so = 0; - int o = 0; - int c = 0; - for (Integer i : y.keySet()) { - if (y.get(i) == 0) { - o++; - } - if (y.get(i) == 1) { - c++; - if (c == 1) { - fo = o; - } - o = 0; - } - } - so = o; - yc = new int[]{fo, so}; - - fo = 0; - so = 0; - o = 0; - c = 0; - for (Integer i : x.keySet()) { - if (x.get(i) == 0) { - o++; - } - if (x.get(i) == 1) { - c++; - if (c == 1) { - fo = o; - } - o = 0; - } - } - so = o; - xc = new int[]{fo, so}; - - fo = 0; - so = 0; - o = 0; - c = 0; - for (Integer i : z.keySet()) { - if (z.get(i) == 0) { - o++; - } - if (z.get(i) == 1) { - c++; - if (c == 1) { - fo = o; - } - o = 0; - } - } - so = o; - zc = new int[]{fo, so}; - - int h1, h2, w1, w2, v1 = 0, volume = objW * objH * objD; - Map blockLocationMap = new LinkedHashMap<>(); - boolean hasAir = false; - int pos = 0; - for (int i : originalBlockArray) { - blockLocationMap.put(pos, i); - pos++; - } - - - for (int h = 0; h < objH; h++) { for (int d = 0; d < objD; d++) { for (int w = 0; w < objW; w++) { @@ -252,9 +97,9 @@ public class IrisConverter { } } } - - + if (i != -1) J.car(i); try { + object.shrinkwrap(); object.write(new File(folder, schem.getName().replace(".schem", ".iob"))); } catch (IOException e) { Iris.info(C.RED + "Failed to save: " + schem.getName()); @@ -272,7 +117,7 @@ public class IrisConverter { } else { Iris.info(C.GRAY + "Converted " + schem.getName() + " -> " + schem.getName().replace(".schem", ".iob")); } - // schem.delete(); + FileUtils.delete(schem); } } catch (Exception e) { Iris.info(C.RED + "Failed to convert: " + schem.getName()); @@ -283,112 +128,10 @@ public class IrisConverter { Iris.reportError(e); } } + sender.sendMessage(C.GRAY + "converted: " + fileList.length); }); } - public static boolean isNewPointFurther(int[] originalPoint, int[] oldPoint, int[] newPoint) { - int oX = oldPoint[1]; - int oY = oldPoint[2]; - int oZ = oldPoint[3]; - - int nX = newPoint[1]; - int nY = newPoint[2]; - int nZ = newPoint[3]; - - int orX = originalPoint[1]; - int orY = originalPoint[2]; - int orZ = originalPoint[3]; - - double oldDistance = Math.sqrt(Math.pow(oX - orX, 2) + Math.pow(oY - orY, 2) + Math.pow(oZ - orZ, 2)); - double newDistance = Math.sqrt(Math.pow(nX - orX, 2) + Math.pow(nY - orY, 2) + Math.pow(nZ - orZ, 2)); - - if (newDistance > oldDistance) { - return true; - } - return false; - } - - public static int[] getCoordinates(int pos, int obX, int obY, int obZ) { - int z = 0; - int[] coords = new int[4]; - for (int h = 0; h < obY; h++) { - for (int d = 0; d < obZ; d++) { - for (int w = 0; w < obX; w++) { - if (z == pos) { - coords[1] = w; - coords[2] = h; - coords[3] = d; - return coords; - } - z++; - } - } - } - return null; - } - - public static int getCorrectY(Map y, int H) { - int fo = 0; - int so = 0; - int o = 0; - int c = 0; - for (Integer i : y.keySet()) { - if (y.get(i) == 0) { - o++; - } - if (y.get(i) == 1) { - c++; - if(c == 1){ - fo = o; - } - o = 0; - } - } - so = o; - return H = H - (fo + so); - } - - public static int getCorrectX(Map x, int W) { - int fo = 0; - int so = 0; - int o = 0; - int c = 0; - for (Integer i : x.keySet()) { - if (x.get(i) == 0) { - o++; - } - if (x.get(i) == 1) { - c++; - if(c == 1){ - fo = o; - } - o = 0; - } - } - so = o; - return W = W - (fo + so); - } - - public static int getCorrectZ(Map z, int D) { - int fo = 0; - int so = 0; - int o = 0; - int c = 0; - for (Integer i : z.keySet()) { - if (z.get(i) == 0) { - o++; - } - if (z.get(i) == 1) { - c++; - if(c == 1){ - fo = o; - } - o = 0; - } - } - so = o; - return D = D - (fo + so); - } }