mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-08-16 00:05:59 +00:00
overwrite heightmaps for structure placement
This commit is contained in:
parent
5a5a01a7c7
commit
f4756a46d3
@ -15,6 +15,7 @@ import com.volmit.iris.util.collection.KSet;
|
|||||||
import com.volmit.iris.util.mantle.MantleFlag;
|
import com.volmit.iris.util.mantle.MantleFlag;
|
||||||
import com.volmit.iris.util.math.Position2;
|
import com.volmit.iris.util.math.Position2;
|
||||||
import com.volmit.iris.util.reflect.WrappedField;
|
import com.volmit.iris.util.reflect.WrappedField;
|
||||||
|
import com.volmit.iris.util.reflect.WrappedReturningMethod;
|
||||||
import net.minecraft.CrashReport;
|
import net.minecraft.CrashReport;
|
||||||
import net.minecraft.CrashReportCategory;
|
import net.minecraft.CrashReportCategory;
|
||||||
import net.minecraft.ReportedException;
|
import net.minecraft.ReportedException;
|
||||||
@ -35,6 +36,7 @@ import net.minecraft.world.level.block.state.BlockState;
|
|||||||
import net.minecraft.world.level.chunk.ChunkAccess;
|
import net.minecraft.world.level.chunk.ChunkAccess;
|
||||||
import net.minecraft.world.level.chunk.ChunkGenerator;
|
import net.minecraft.world.level.chunk.ChunkGenerator;
|
||||||
import net.minecraft.world.level.chunk.ChunkGeneratorStructureState;
|
import net.minecraft.world.level.chunk.ChunkGeneratorStructureState;
|
||||||
|
import net.minecraft.world.level.chunk.status.ChunkStatus;
|
||||||
import net.minecraft.world.level.levelgen.*;
|
import net.minecraft.world.level.levelgen.*;
|
||||||
import net.minecraft.world.level.levelgen.blending.Blender;
|
import net.minecraft.world.level.levelgen.blending.Blender;
|
||||||
import net.minecraft.world.level.levelgen.structure.BoundingBox;
|
import net.minecraft.world.level.levelgen.structure.BoundingBox;
|
||||||
@ -52,16 +54,15 @@ import org.spigotmc.SpigotWorldConfig;
|
|||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.util.Comparator;
|
import java.lang.reflect.Method;
|
||||||
import java.util.List;
|
import java.util.*;
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
public class IrisChunkGenerator extends CustomChunkGenerator {
|
public class IrisChunkGenerator extends CustomChunkGenerator {
|
||||||
private static final WrappedField<ChunkGenerator, BiomeSource> BIOME_SOURCE;
|
private static final WrappedField<ChunkGenerator, BiomeSource> BIOME_SOURCE;
|
||||||
|
private static final WrappedReturningMethod<Heightmap, Object> SET_HEIGHT;
|
||||||
private final ChunkGenerator delegate;
|
private final ChunkGenerator delegate;
|
||||||
private final Engine engine;
|
private final Engine engine;
|
||||||
private final KMap<ResourceKey<Structure>, KSet<String>> structures = new KMap<>();
|
private final KMap<ResourceKey<Structure>, KSet<String>> structures = new KMap<>();
|
||||||
@ -310,6 +311,25 @@ public class IrisChunkGenerator extends CustomChunkGenerator {
|
|||||||
.sorted(Comparator.comparingInt(s -> s.step().ordinal()))
|
.sorted(Comparator.comparingInt(s -> s.step().ordinal()))
|
||||||
.toList();
|
.toList();
|
||||||
|
|
||||||
|
var surface = chunkAccess.getOrCreateHeightmapUnprimed(Heightmap.Types.WORLD_SURFACE_WG);
|
||||||
|
var ocean = chunkAccess.getOrCreateHeightmapUnprimed(Heightmap.Types.OCEAN_FLOOR_WG);
|
||||||
|
var motion = chunkAccess.getOrCreateHeightmapUnprimed(Heightmap.Types.MOTION_BLOCKING);
|
||||||
|
var motionNoLeaves = chunkAccess.getOrCreateHeightmapUnprimed(Heightmap.Types.MOTION_BLOCKING_NO_LEAVES);
|
||||||
|
|
||||||
|
for (int x = 0; x < 16; x++) {
|
||||||
|
for (int z = 0; z < 16; z++) {
|
||||||
|
int wX = x + blockPos.getX();
|
||||||
|
int wZ = z + blockPos.getZ();
|
||||||
|
|
||||||
|
int noAir = engine.getHeight(wX, wZ, false) + engine.getMinHeight() + 1;
|
||||||
|
int noFluid = engine.getHeight(wX, wZ, true) + engine.getMinHeight() + 1;
|
||||||
|
SET_HEIGHT.invoke(ocean, x, z, noFluid);
|
||||||
|
SET_HEIGHT.invoke(surface, x, z, noAir);
|
||||||
|
SET_HEIGHT.invoke(motion, x, z, noAir);
|
||||||
|
SET_HEIGHT.invoke(motionNoLeaves, x, z, noAir);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (int j = 0; j < list.size(); j++) {
|
for (int j = 0; j < list.size(); j++) {
|
||||||
Structure structure = list.get(j);
|
Structure structure = list.get(j);
|
||||||
random.setFeatureSeed(i, j, structure.step().ordinal());
|
random.setFeatureSeed(i, j, structure.step().ordinal());
|
||||||
@ -325,6 +345,8 @@ public class IrisChunkGenerator extends CustomChunkGenerator {
|
|||||||
throw new ReportedException(crashReport);
|
throw new ReportedException(crashReport);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Heightmap.primeHeightmaps(chunkAccess, ChunkStatus.FINAL_HEIGHTMAPS);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static BoundingBox getWritableArea(ChunkAccess ichunkaccess) {
|
private static BoundingBox getWritableArea(ChunkAccess ichunkaccess) {
|
||||||
@ -396,7 +418,21 @@ public class IrisChunkGenerator extends CustomChunkGenerator {
|
|||||||
}
|
}
|
||||||
if (biomeSource == null)
|
if (biomeSource == null)
|
||||||
throw new RuntimeException("Could not find biomeSource field in ChunkGenerator!");
|
throw new RuntimeException("Could not find biomeSource field in ChunkGenerator!");
|
||||||
|
|
||||||
|
Method setHeight = null;
|
||||||
|
for (Method method : Heightmap.class.getDeclaredMethods()) {
|
||||||
|
var types = method.getParameterTypes();
|
||||||
|
if (types.length != 3 || !Arrays.equals(types, new Class<?>[]{int.class, int.class, int.class})
|
||||||
|
|| !method.getReturnType().equals(void.class))
|
||||||
|
continue;
|
||||||
|
setHeight = method;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (setHeight == null)
|
||||||
|
throw new RuntimeException("Could not find setHeight method in Heightmap!");
|
||||||
|
|
||||||
BIOME_SOURCE = new WrappedField<>(ChunkGenerator.class, biomeSource.getName());
|
BIOME_SOURCE = new WrappedField<>(ChunkGenerator.class, biomeSource.getName());
|
||||||
|
SET_HEIGHT = new WrappedReturningMethod<>(Heightmap.class, setHeight.getName(), setHeight.getParameterTypes());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ChunkGenerator edit(ChunkGenerator generator, BiomeSource source) {
|
private static ChunkGenerator edit(ChunkGenerator generator, BiomeSource source) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user