From 3118f743a0536e3868d7a30d11c88f61d7f193cb Mon Sep 17 00:00:00 2001 From: cyberpwn Date: Fri, 27 Aug 2021 11:29:18 -0400 Subject: [PATCH] Fixes --- .../com/volmit/iris/engine/IrisEngine.java | 9 +- .../volmit/iris/engine/framework/Engine.java | 19 ++-- .../engine/modifier/IrisCarveModifier.java | 89 +++++++++++++++++++ .../volmit/iris/util/matter/MatterCavern.java | 28 ++++++ .../volmit/iris/util/matter/MatterUpdate.java | 28 ++++++ .../iris/util/matter/slices/CavernMatter.java | 12 +-- .../iris/util/matter/slices/UpdateMatter.java | 11 +-- 7 files changed, 166 insertions(+), 30 deletions(-) create mode 100644 src/main/java/com/volmit/iris/engine/modifier/IrisCarveModifier.java create mode 100644 src/main/java/com/volmit/iris/util/matter/MatterCavern.java create mode 100644 src/main/java/com/volmit/iris/util/matter/MatterUpdate.java diff --git a/src/main/java/com/volmit/iris/engine/IrisEngine.java b/src/main/java/com/volmit/iris/engine/IrisEngine.java index 7c3bb3c63..89522e5c5 100644 --- a/src/main/java/com/volmit/iris/engine/IrisEngine.java +++ b/src/main/java/com/volmit/iris/engine/IrisEngine.java @@ -30,6 +30,7 @@ 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.IrisCarveModifier; import com.volmit.iris.engine.modifier.IrisDepositModifier; import com.volmit.iris.engine.modifier.IrisPostModifier; import com.volmit.iris.engine.object.biome.IrisBiome; @@ -66,7 +67,6 @@ import java.util.concurrent.atomic.AtomicLong; @Data public class IrisEngine implements Engine { - // TODO: Remove block population, stop using bukkit private final AtomicInteger generated; private final AtomicInteger generatedLast; private final AtomicDouble perSecond; @@ -95,6 +95,7 @@ public class IrisEngine implements Engine { private EngineActuator decorantActuator; private EngineActuator biomeActuator; private EngineModifier depositModifier; + private EngineModifier caveModifier; private EngineModifier postModifier; private final AtomicCache engineData = new AtomicCache<>(); private final AtomicBoolean cleaning; @@ -141,6 +142,7 @@ public class IrisEngine implements Engine { decorantActuator.close(); biomeActuator.close(); depositModifier.close(); + caveModifier.close(); postModifier.close(); effects.close(); } @@ -157,6 +159,7 @@ public class IrisEngine implements Engine { biomeActuator = new IrisBiomeActuator(this); depositModifier = new IrisDepositModifier(this); postModifier = new IrisPostModifier(this); + caveModifier = new IrisCarveModifier(this); effects = new IrisEngineEffects(this); J.a(this::computeBiomeMaxes); } catch (Throwable e) { @@ -334,6 +337,7 @@ public class IrisEngine implements Engine { getBiomeActuator().close(); getDepositModifier().close(); getPostModifier().close(); + getCaveModifier().close(); getMantle().close(); getComplex().close(); getData().dump(); @@ -411,8 +415,9 @@ public class IrisEngine implements Engine { getBiomeActuator().actuate(x, z, vbiomes, multicore); getDecorantActuator().actuate(x, z, blocks, multicore); getPostModifier().modify(x, z, vblocks, multicore); - getMantle().insertMatter(x >> 4, z >> 4, BlockData.class, blocks, multicore); getDepositModifier().modify(x, z, vblocks, multicore); + getCaveModifier().modify(x >> 4,z >> 4, vblocks, multicore); + getMantle().insertMatter(x >> 4, z >> 4, BlockData.class, blocks, multicore); } getMetrics().getTotal().put(p.getMilliseconds()); generated.incrementAndGet(); diff --git a/src/main/java/com/volmit/iris/engine/framework/Engine.java b/src/main/java/com/volmit/iris/engine/framework/Engine.java index 8abeaa8f1..77711d6de 100644 --- a/src/main/java/com/volmit/iris/engine/framework/Engine.java +++ b/src/main/java/com/volmit/iris/engine/framework/Engine.java @@ -52,6 +52,7 @@ import com.volmit.iris.util.mantle.MantleFlag; import com.volmit.iris.util.math.BlockPosition; import com.volmit.iris.util.math.M; import com.volmit.iris.util.math.RNG; +import com.volmit.iris.util.matter.MatterUpdate; import com.volmit.iris.util.matter.slices.UpdateMatter; import com.volmit.iris.util.parallel.BurstExecutor; import com.volmit.iris.util.parallel.MultiBurst; @@ -95,16 +96,6 @@ public interface Engine extends DataProvider, Fallible, LootProvider, BlockUpdat void recycle(); - EngineActuator getTerrainActuator(); - - EngineActuator getDecorantActuator(); - - EngineActuator getBiomeActuator(); - - EngineModifier getDepositModifier(); - - EngineModifier getPostModifier(); - void close(); IrisContext getContext(); @@ -244,7 +235,7 @@ public interface Engine extends DataProvider, Fallible, LootProvider, BlockUpdat default void updateChunk(Chunk c) { getMantle().getMantle().raiseFlag(c.getX(), c.getZ(), MantleFlag.UPDATE, () -> J.s(() -> { PrecisionStopwatch p = PrecisionStopwatch.start(); - getMantle().getMantle().iterateChunk(c.getX(), c.getZ(), UpdateMatter.MatterUpdate.class, (x, y, z, v) -> { + getMantle().getMantle().iterateChunk(c.getX(), c.getZ(), MatterUpdate.class, (x, y, z, v) -> { if (v != null && v.isUpdate()) { int vx = x & 15; int vz = z & 15; @@ -299,6 +290,12 @@ public interface Engine extends DataProvider, Fallible, LootProvider, BlockUpdat } } } + + else + { + block.setType(Material.AIR, false); + block.setBlockData(data, true); + } } @Override diff --git a/src/main/java/com/volmit/iris/engine/modifier/IrisCarveModifier.java b/src/main/java/com/volmit/iris/engine/modifier/IrisCarveModifier.java new file mode 100644 index 000000000..ba35da86c --- /dev/null +++ b/src/main/java/com/volmit/iris/engine/modifier/IrisCarveModifier.java @@ -0,0 +1,89 @@ +/* + * 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 . + */ + +package com.volmit.iris.engine.modifier; + +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.deposits.IrisDepositGenerator; +import com.volmit.iris.engine.object.objects.IrisObject; +import com.volmit.iris.engine.object.regional.IrisRegion; +import com.volmit.iris.util.data.B; +import com.volmit.iris.util.data.HeightMap; +import com.volmit.iris.util.hunk.Hunk; +import com.volmit.iris.util.mantle.Mantle; +import com.volmit.iris.util.mantle.MantleChunk; +import com.volmit.iris.util.math.RNG; +import com.volmit.iris.util.matter.MatterCavern; +import com.volmit.iris.util.matter.slices.CavernMatter; +import com.volmit.iris.util.parallel.BurstExecutor; +import com.volmit.iris.util.scheduling.PrecisionStopwatch; +import org.bukkit.Material; +import org.bukkit.block.data.BlockData; +import org.bukkit.util.BlockVector; + +public class IrisCarveModifier extends EngineAssignedModifier { + private final RNG rng; + private final BlockData AIR = Material.CAVE_AIR.createBlockData(); + + public IrisCarveModifier(Engine engine) { + super(engine, "Carve"); + rng = new RNG(getEngine().getWorld().seed() + 3297778).nextParallelRNG(67648777); + } + + @Override + public void onModify(int x, int z, Hunk output, boolean multicore) { + PrecisionStopwatch p = PrecisionStopwatch.start(); + Mantle mantle = getEngine().getMantle().getMantle(); + MantleChunk mc = getEngine().getMantle().getMantle().getChunk(x, z); + mc.iterate(MatterCavern.class, (xx, yy, zz, c) -> { + int rx = xx & 15; + int rz = zz & 15; + boolean caveAbove = mantle.get(xx, yy+1, zz, MatterCavern.class) != null; + BlockData currentAbove = output.get(rx, yy+1, rz); + BlockData current = output.get(rx, yy, rz); + + if(current.getMaterial().isAir()) + { + return; + } + + if(B.isFluid(currentAbove) && !caveAbove) + { + getEngine().getMantle().updateBlock(xx, yy+1, zz); + } + + if(B.isFluid(current)) + { + getEngine().getMantle().updateBlock(xx, yy, zz); + return; + } + + if(B.isFoliage(currentAbove) && !caveAbove) + { + output.set(rx, yy+1, rz, AIR); + getEngine().getMantle().updateBlock(xx, yy+2, zz); + } + + output.set(rx, yy, rz, AIR); + }); + getEngine().getMetrics().getDeposit().put(p.getMilliseconds()); + } +} diff --git a/src/main/java/com/volmit/iris/util/matter/MatterCavern.java b/src/main/java/com/volmit/iris/util/matter/MatterCavern.java new file mode 100644 index 000000000..a06df01ef --- /dev/null +++ b/src/main/java/com/volmit/iris/util/matter/MatterCavern.java @@ -0,0 +1,28 @@ +/* + * 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 . + */ + +package com.volmit.iris.util.matter; + +import lombok.AllArgsConstructor; +import lombok.Data; + +@Data +@AllArgsConstructor +public class MatterCavern { + private final boolean cavern; +} diff --git a/src/main/java/com/volmit/iris/util/matter/MatterUpdate.java b/src/main/java/com/volmit/iris/util/matter/MatterUpdate.java new file mode 100644 index 000000000..e675741d1 --- /dev/null +++ b/src/main/java/com/volmit/iris/util/matter/MatterUpdate.java @@ -0,0 +1,28 @@ +/* + * 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 . + */ + +package com.volmit.iris.util.matter; + +import lombok.AllArgsConstructor; +import lombok.Data; + +@Data +@AllArgsConstructor +public class MatterUpdate { + private final boolean update; +} \ No newline at end of file diff --git a/src/main/java/com/volmit/iris/util/matter/slices/CavernMatter.java b/src/main/java/com/volmit/iris/util/matter/slices/CavernMatter.java index 6729d1b2d..636cd5605 100644 --- a/src/main/java/com/volmit/iris/util/matter/slices/CavernMatter.java +++ b/src/main/java/com/volmit/iris/util/matter/slices/CavernMatter.java @@ -18,6 +18,7 @@ package com.volmit.iris.util.matter.slices; +import com.volmit.iris.util.matter.MatterCavern; import com.volmit.iris.util.matter.Sliced; import lombok.AllArgsConstructor; import lombok.Data; @@ -27,7 +28,7 @@ import java.io.DataOutputStream; import java.io.IOException; @Sliced -public class CavernMatter extends RawMatter { +public class CavernMatter extends RawMatter { public static final MatterCavern ON = new MatterCavern(true); public static final MatterCavern OFF = new MatterCavern(false); @@ -41,18 +42,11 @@ public class CavernMatter extends RawMatter { @Override public void writeNode(MatterCavern b, DataOutputStream dos) throws IOException { - dos.writeBoolean(b.cavern); + dos.writeBoolean(b.isCavern()); } @Override public MatterCavern readNode(DataInputStream din) throws IOException { return din.readBoolean() ? ON : OFF; } - - @Data - @AllArgsConstructor - public static class MatterCavern { - private final boolean cavern; - } - } diff --git a/src/main/java/com/volmit/iris/util/matter/slices/UpdateMatter.java b/src/main/java/com/volmit/iris/util/matter/slices/UpdateMatter.java index 585f1641d..65f487210 100644 --- a/src/main/java/com/volmit/iris/util/matter/slices/UpdateMatter.java +++ b/src/main/java/com/volmit/iris/util/matter/slices/UpdateMatter.java @@ -18,6 +18,7 @@ package com.volmit.iris.util.matter.slices; +import com.volmit.iris.util.matter.MatterUpdate; import com.volmit.iris.util.matter.Sliced; import lombok.AllArgsConstructor; import lombok.Data; @@ -27,7 +28,7 @@ import java.io.DataOutputStream; import java.io.IOException; @Sliced -public class UpdateMatter extends RawMatter { +public class UpdateMatter extends RawMatter { public static final MatterUpdate ON = new MatterUpdate(true); public static final MatterUpdate OFF = new MatterUpdate(false); @@ -41,17 +42,11 @@ public class UpdateMatter extends RawMatter { @Override public void writeNode(MatterUpdate b, DataOutputStream dos) throws IOException { - dos.writeBoolean(b.update); + dos.writeBoolean(b.isUpdate()); } @Override public MatterUpdate readNode(DataInputStream din) throws IOException { return din.readBoolean() ? ON : OFF; } - - @Data - @AllArgsConstructor - public static class MatterUpdate { - private final boolean update; - } }