mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-12-27 19:19:07 +00:00
Biome holder injection post gen
This commit is contained in:
@@ -18,9 +18,11 @@
|
||||
|
||||
package com.volmit.iris.core.nms;
|
||||
|
||||
import com.volmit.iris.util.mantle.Mantle;
|
||||
import com.volmit.iris.util.nbt.mca.palette.MCABiomeContainer;
|
||||
import com.volmit.iris.util.nbt.mca.palette.MCAPaletteAccess;
|
||||
import com.volmit.iris.util.nbt.tag.CompoundTag;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.WorldCreator;
|
||||
@@ -83,4 +85,6 @@ public interface INMSBinding {
|
||||
}
|
||||
|
||||
MCAPaletteAccess createPalette();
|
||||
|
||||
void injectBiomesFromMantle(Chunk e, Mantle mantle);
|
||||
}
|
||||
|
||||
@@ -25,6 +25,8 @@ import com.volmit.iris.engine.data.cache.AtomicCache;
|
||||
import com.volmit.iris.engine.object.IrisBiome;
|
||||
import com.volmit.iris.util.collection.KMap;
|
||||
import com.volmit.iris.util.hunk.Hunk;
|
||||
import com.volmit.iris.util.mantle.Mantle;
|
||||
import com.volmit.iris.util.matter.MatterBiomeInject;
|
||||
import com.volmit.iris.util.nbt.io.NBTUtil;
|
||||
import com.volmit.iris.util.nbt.mca.NBTWorld;
|
||||
import com.volmit.iris.util.nbt.mca.palette.MCABiomeContainer;
|
||||
@@ -399,6 +401,24 @@ public class NMSBinding19_2 implements INMSBinding {
|
||||
i -> ((CraftBlockData) NBTWorld.getBlockData(i)).getState());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void injectBiomesFromMantle(Chunk e, Mantle mantle) {
|
||||
LevelChunk chunk = ((CraftChunk)e).getHandle();
|
||||
mantle.iterateChunk(e.getX(), e.getZ(), MatterBiomeInject.class, (x,y,z,b) -> {
|
||||
if(b != null) {
|
||||
if(b.isCustom()) {
|
||||
chunk.setBiome(x, y, z, (Holder<net.minecraft.world.level.biome.Biome>) getBiomeBaseFromId(b.getBiomeId()));
|
||||
}
|
||||
|
||||
else {
|
||||
chunk.setBiome(x, y, z, (Holder<net.minecraft.world.level.biome.Biome>) getBiomeBase(e.getWorld(), b.getBiome()));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
chunk.setUnsaved(true);
|
||||
}
|
||||
|
||||
private static Object getFor(Class<?> type, Object source) {
|
||||
Object o = fieldFor(type, source);
|
||||
|
||||
|
||||
@@ -20,9 +20,11 @@ package com.volmit.iris.core.nms.v1X;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.core.nms.INMSBinding;
|
||||
import com.volmit.iris.util.mantle.Mantle;
|
||||
import com.volmit.iris.util.nbt.mca.palette.MCABiomeContainer;
|
||||
import com.volmit.iris.util.nbt.mca.palette.MCAPaletteAccess;
|
||||
import com.volmit.iris.util.nbt.tag.CompoundTag;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Biome;
|
||||
@@ -57,6 +59,11 @@ public class NMSBinding1X implements INMSBinding {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void injectBiomesFromMantle(Chunk e, Mantle mantle) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deserializeTile(CompoundTag s, Location newPosition) {
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ package com.volmit.iris.engine;
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.core.IrisSettings;
|
||||
import com.volmit.iris.core.loader.IrisData;
|
||||
import com.volmit.iris.core.nms.INMS;
|
||||
import com.volmit.iris.engine.framework.Engine;
|
||||
import com.volmit.iris.engine.framework.EngineAssignedWorldManager;
|
||||
import com.volmit.iris.engine.object.*;
|
||||
@@ -31,14 +32,14 @@ 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.math.M;
|
||||
import com.volmit.iris.util.math.Position2;
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
import com.volmit.iris.util.matter.MatterBiomeInject;
|
||||
import com.volmit.iris.util.matter.MatterMarker;
|
||||
import com.volmit.iris.util.parallel.MultiBurst;
|
||||
import com.volmit.iris.util.plugin.Chunks;
|
||||
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.Looper;
|
||||
import com.volmit.iris.util.scheduling.*;
|
||||
import com.volmit.iris.util.scheduling.jobs.QueueJob;
|
||||
import io.papermc.lib.PaperLib;
|
||||
import lombok.Data;
|
||||
@@ -81,6 +82,7 @@ public class IrisWorldManager extends EngineAssignedWorldManager {
|
||||
private int actuallySpawned = 0;
|
||||
private int cooldown = 0;
|
||||
private List<Entity> precount = new KList<>();
|
||||
private KSet<Position2> injectBiomes = new KSet<>();
|
||||
|
||||
public IrisWorldManager() {
|
||||
super(null);
|
||||
@@ -463,6 +465,10 @@ public class IrisWorldManager extends EngineAssignedWorldManager {
|
||||
getEngine().getMantle().save();
|
||||
}
|
||||
|
||||
public void requestBiomeInject(Position2 p) {
|
||||
injectBiomes.add(p);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChunkLoad(Chunk e, boolean generated) {
|
||||
if(getEngine().isClosed()) {
|
||||
@@ -472,6 +478,14 @@ public class IrisWorldManager extends EngineAssignedWorldManager {
|
||||
energy += 0.3;
|
||||
fixEnergy();
|
||||
getEngine().cleanupMantleChunk(e.getX(), e.getZ());
|
||||
|
||||
if(generated && !injectBiomes.isEmpty()) {
|
||||
Position2 p = new Position2(e.getX(), e.getZ());
|
||||
|
||||
if(injectBiomes.remove(p)) {
|
||||
INMS.get().injectBiomesFromMantle(e, getMantle());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void spawn(IrisPosition block, IrisSpawner spawner, boolean initial) {
|
||||
|
||||
@@ -31,6 +31,8 @@ import com.volmit.iris.util.hunk.Hunk;
|
||||
import com.volmit.iris.util.hunk.view.BiomeGridHunkHolder;
|
||||
import com.volmit.iris.util.hunk.view.BiomeGridHunkView;
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
import com.volmit.iris.util.matter.MatterBiomeInject;
|
||||
import com.volmit.iris.util.matter.slices.BiomeInjectMatter;
|
||||
import com.volmit.iris.util.parallel.BurstExecutor;
|
||||
import com.volmit.iris.util.scheduling.ChronoLatch;
|
||||
import com.volmit.iris.util.scheduling.PrecisionStopwatch;
|
||||
@@ -47,33 +49,6 @@ public class IrisBiomeActuator extends EngineAssignedActuator<Biome> {
|
||||
rng = new RNG(engine.getSeedManager().getBiome());
|
||||
}
|
||||
|
||||
@BlockCoordinates
|
||||
private boolean injectBiome(Hunk<Biome> h, int x, int y, int z, Object bb) {
|
||||
try {
|
||||
if(h instanceof BiomeGridHunkView hh) {
|
||||
ChunkGenerator.BiomeGrid g = hh.getChunk();
|
||||
if(g instanceof TerrainChunk) {
|
||||
((TerrainChunk) g).getBiomeBaseInjector().setBiome(x, y, z, bb);
|
||||
} else {
|
||||
hh.forceBiomeBaseInto(x, y, z, bb);
|
||||
}
|
||||
return true;
|
||||
} else if(h instanceof BiomeGridHunkHolder hh) {
|
||||
ChunkGenerator.BiomeGrid g = hh.getChunk();
|
||||
if(g instanceof TerrainChunk) {
|
||||
((TerrainChunk) g).getBiomeBaseInjector().setBiome(x, y, z, bb);
|
||||
} else {
|
||||
hh.forceBiomeBaseInto(x, y, z, bb);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
} catch(Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@BlockCoordinates
|
||||
@Override
|
||||
public void onActuate(int x, int z, Hunk<Biome> h, boolean multicore, ChunkContext context) {
|
||||
@@ -84,35 +59,19 @@ public class IrisBiomeActuator extends EngineAssignedActuator<Biome> {
|
||||
for(int zf = 0; zf < h.getDepth(); zf++) {
|
||||
ib = context.getBiome().get(xf, zf);
|
||||
int maxHeight = (int) (getComplex().getFluidHeight() + ib.getMaxWithObjectHeight(getData()));
|
||||
MatterBiomeInject matter = null;
|
||||
|
||||
if(ib.isCustom()) {
|
||||
try {
|
||||
IrisBiomeCustom custom = ib.getCustomBiome(rng, x, 0, z);
|
||||
Object biomeBase = INMS.get().getCustomBiomeBaseHolderFor(getDimension().getLoadKey() + ":" + custom.getId());
|
||||
|
||||
if(biomeBase == null || !injectBiome(h, x, 0, z, biomeBase)) {
|
||||
throw new RuntimeException("Cant inject biome!");
|
||||
}
|
||||
|
||||
for(int i = 0; i < maxHeight; i++) {
|
||||
injectBiome(h, xf, i, zf, biomeBase);
|
||||
}
|
||||
} catch(Throwable e) {
|
||||
Iris.reportError(e);
|
||||
Biome v = ib.getSkyBiome(rng, x, 0, z);
|
||||
for(int i = 0; i < maxHeight; i++) {
|
||||
h.set(xf, i, zf, v);
|
||||
}
|
||||
}
|
||||
IrisBiomeCustom custom = ib.getCustomBiome(rng, x, 0, z);
|
||||
Object biomeBase = INMS.get().getCustomBiomeBaseHolderFor(getDimension().getLoadKey() + ":" + custom.getId());
|
||||
matter = BiomeInjectMatter.get(INMS.get().getTrueBiomeBaseId(biomeBase));
|
||||
} else {
|
||||
Biome v = ib.getSkyBiome(rng, x, 0, z);
|
||||
matter = BiomeInjectMatter.get(v);
|
||||
}
|
||||
|
||||
if(v != null) {
|
||||
for(int i = 0; i < maxHeight; i++) {
|
||||
h.set(xf, i, zf, v);
|
||||
}
|
||||
} else if(cl.flip()) {
|
||||
Iris.error("No biome provided for " + ib.getLoadKey());
|
||||
}
|
||||
for(int i = 0; i < maxHeight; i++) {
|
||||
getEngine().getMantle().getMantle().set(x, i, z, matter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.volmit.iris.util.matter;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import org.bukkit.block.Biome;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class MatterBiomeInject {
|
||||
private final boolean custom;
|
||||
private final Integer biomeId;
|
||||
private final Biome biome;
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.volmit.iris.util.matter.slices;
|
||||
|
||||
import com.volmit.iris.util.data.palette.Palette;
|
||||
import com.volmit.iris.util.matter.MatterBiomeInject;
|
||||
import com.volmit.iris.util.matter.MatterCavern;
|
||||
import com.volmit.iris.util.matter.Sliced;
|
||||
import org.bukkit.block.Biome;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
@Sliced
|
||||
public class BiomeInjectMatter extends RawMatter<MatterBiomeInject> {
|
||||
public BiomeInjectMatter() {
|
||||
this(1, 1, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Palette<MatterBiomeInject> getGlobalPalette() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public BiomeInjectMatter(int width, int height, int depth) {
|
||||
super(width, height, depth, MatterBiomeInject.class);
|
||||
}
|
||||
|
||||
public static MatterBiomeInject get(Biome biome)
|
||||
{
|
||||
return get(false, 0, biome);
|
||||
}
|
||||
|
||||
public static MatterBiomeInject get(int customBiome) {
|
||||
return get(true, customBiome, null);
|
||||
}
|
||||
|
||||
public static MatterBiomeInject get(boolean custom, int customBiome, Biome biome) {
|
||||
return new MatterBiomeInject(custom, customBiome, biome);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeNode(MatterBiomeInject b, DataOutputStream dos) throws IOException {
|
||||
dos.writeBoolean(b.isCustom());
|
||||
|
||||
if(b.isCustom()) {
|
||||
dos.writeShort(b.getBiomeId());
|
||||
}
|
||||
|
||||
else {
|
||||
dos.writeByte(b.getBiome().ordinal());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public MatterBiomeInject readNode(DataInputStream din) throws IOException {
|
||||
boolean b = din.readBoolean();
|
||||
int id = b ? din.readShort() : 0;
|
||||
Biome biome = !b ? Biome.values()[din.readByte()] : Biome.PLAINS;
|
||||
|
||||
return new MatterBiomeInject(b, id, biome);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user