From a750aaf90a1fa6ed493cc8986ab6b1a61a772dd8 Mon Sep 17 00:00:00 2001 From: tom lee Date: Sun, 23 Jan 2022 19:11:48 +0800 Subject: [PATCH 1/4] Update core + cleanup some junks --- .gitignore | 5 +- .../ExperimentalGenerator.java | 2 +- .../worldGeneration/LodServerWorld.java | 358 ------------------ core | 2 +- fabric/build.gradle | 2 +- 5 files changed, 7 insertions(+), 362 deletions(-) delete mode 100644 common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/LodServerWorld.java diff --git a/.gitignore b/.gitignore index a1a036d4c..953800454 100644 --- a/.gitignore +++ b/.gitignore @@ -47,4 +47,7 @@ classes/ *.launch **/src/generated/ -Merged/ \ No newline at end of file +Merged/ + +# file from notepad++ +*.bak \ No newline at end of file diff --git a/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/ExperimentalGenerator.java b/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/ExperimentalGenerator.java index a1a76e42f..3eaece9bd 100644 --- a/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/ExperimentalGenerator.java +++ b/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/ExperimentalGenerator.java @@ -47,7 +47,7 @@ public class ExperimentalGenerator extends AbstractExperimentalWorldGeneratorWra public LodDimension targetLodDim; public static final int generationGroupSize = 4; public static final int generationGroupSizeFar = 0; - public static int numberOfGenerationPoints = CONFIG.client().advanced().threading().getNumberOfWorldGenerationThreads()*2; + public static int numberOfGenerationPoints = CONFIG.client().advanced().threading().getNumberOfWorldGenerationThreads(); private int estimatedSampleNeeded = 128; diff --git a/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/LodServerWorld.java b/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/LodServerWorld.java deleted file mode 100644 index ed79eb0b3..000000000 --- a/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/LodServerWorld.java +++ /dev/null @@ -1,358 +0,0 @@ -/* - * This file is part of the Distant Horizon mod (formerly the LOD Mod), - * licensed under the GNU GPL v3 License. - * - * Copyright (C) 2020 James Seibel - * - * 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, version 3. - * - * 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.seibel.lod.common.wrappers.worldGeneration; - -import java.util.HashMap; -import java.util.List; -import java.util.Random; -import java.util.function.Predicate; - -import com.seibel.lod.core.util.LodUtil; -import com.seibel.lod.common.wrappers.WrapperUtil; -import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; -import net.minecraft.core.RegistryAccess; -import net.minecraft.core.SectionPos; -import net.minecraft.core.particles.ParticleOptions; -import net.minecraft.server.MinecraftServer; -import net.minecraft.server.level.ServerLevel; -import net.minecraft.sounds.SoundEvent; -import net.minecraft.sounds.SoundSource; -import net.minecraft.world.DifficultyInstance; -import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.level.WorldGenLevel; -import net.minecraft.world.level.biome.Biome; -import net.minecraft.world.level.biome.BiomeManager; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.entity.BlockEntity; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.border.WorldBorder; -import net.minecraft.world.level.chunk.ChunkAccess; -import net.minecraft.world.level.chunk.ChunkSource; -import net.minecraft.world.level.chunk.ChunkStatus; -import net.minecraft.world.level.dimension.DimensionType; -import net.minecraft.world.level.entity.EntityTypeTest; -import net.minecraft.world.level.gameevent.GameEvent; -import net.minecraft.world.level.levelgen.Heightmap; -import net.minecraft.world.level.levelgen.feature.StructureFeature; -import net.minecraft.world.level.levelgen.structure.StructureStart; -import net.minecraft.world.level.lighting.LevelLightEngine; -import net.minecraft.world.level.material.Fluid; -import net.minecraft.world.level.material.FluidState; -import net.minecraft.world.level.storage.LevelData; -import net.minecraft.world.phys.AABB; -import net.minecraft.world.ticks.LevelTickAccess; -import org.jetbrains.annotations.Nullable; - - -/** - * This is a fake ServerWorld used when generating features. - * It allows us to keep each LodChunk generation independent - * of the actual ServerWorld, allowing - * multithread generation. - * - * @author James Seibel - * @version 7-26-2021 - */ -public class LodServerWorld implements WorldGenLevel -{ - - public HashMap heightmaps = new HashMap<>(); - - public final ChunkAccess chunk; - - public final ServerLevel serverWorld; - - public LodServerWorld(ServerLevel newServerWorld, ChunkAccess newChunk) - { - chunk = newChunk; - serverWorld = newServerWorld; - } - - - @Override - public int getHeight(Heightmap.Types heightmapType, int x, int z) - { - // make sure the block position is set relative to the chunk - x = x % LodUtil.CHUNK_WIDTH; - x = (x < 0) ? x + 16 : x; - - z = z % LodUtil.CHUNK_WIDTH; - z = (z < 0) ? z + 16 : z; - - return chunk.getOrCreateHeightmapUnprimed(WrapperUtil.DEFAULT_HEIGHTMAP).getFirstAvailable(x, z); - } - - @Override - public Biome getBiome(BlockPos pos) - { - return chunk.getNoiseBiome(pos.getX() >> 2, pos.getY() >> 2, pos.getZ() >> 2); - } - - @Override - public boolean setBlock(BlockPos pos, BlockState state, int flags, int recursionLeft) - { - return chunk.setBlockState(pos, state, false) == state; - } - - @Override - public BlockState getBlockState(BlockPos pos) - { - return chunk.getBlockState(pos); - } - - @Override - public FluidState getFluidState(BlockPos pos) - { - return chunk.getFluidState(pos); - } - - - @Override - public boolean isStateAtPosition(BlockPos pos, Predicate state) - { - return state.test(chunk.getBlockState(pos)); - } - - @Override - public boolean isFluidAtPosition(BlockPos blockPos, Predicate predicate) { - return predicate.test(chunk.getFluidState(blockPos)); - } - - @Override - public ChunkAccess getChunk(int x, int z, ChunkStatus requiredStatus, boolean nonnull) - { - return chunk; - } - - @Override - public List> startsForFeature(SectionPos p_241827_1_, StructureFeature p_241827_2_) - { - return serverWorld.startsForFeature(p_241827_1_, p_241827_2_); - } - - @Override - public LevelLightEngine getLightEngine() - { - return new LevelLightEngine(null, false, false); - } - - @Override - public long getSeed() - { - return serverWorld.getSeed(); - } - - @Override - public RegistryAccess registryAccess() - { - return serverWorld.registryAccess(); - } - - - /** - * All methods below shouldn't be needed - * and thus have been left unimplemented. - */ - - - @Override - public Random getRandom() - { - throw new UnsupportedOperationException("Not Implemented"); - } - - @Override - public void playSound(Player player, BlockPos pos, SoundEvent soundIn, SoundSource category, float volume, - float pitch) - { - throw new UnsupportedOperationException("Not Implemented"); - } - - @Override - public void addParticle(ParticleOptions particleData, double x, double y, double z, double xSpeed, double ySpeed, - double zSpeed) - { - throw new UnsupportedOperationException("Not Implemented"); - } - - @Override - public BiomeManager getBiomeManager() - { - throw new UnsupportedOperationException("Not Implemented"); - } - - @Override - public int getSeaLevel() - { - throw new UnsupportedOperationException("Not Implemented"); - } - - @Override - public float getShade(Direction p_230487_1_, boolean p_230487_2_) - { - throw new UnsupportedOperationException("Not Implemented"); - } - - @Override - public WorldBorder getWorldBorder() - { - throw new UnsupportedOperationException("Not Implemented"); - } - - @Override - public boolean removeBlock(BlockPos pos, boolean isMoving) - { - throw new UnsupportedOperationException("Not Implemented"); - } - - @Override - public boolean destroyBlock(BlockPos pos, boolean dropBlock, Entity entity, int recursionLeft) - { - throw new UnsupportedOperationException("Not Implemented"); - } - - - @Override - public ServerLevel getLevel() - { - throw new UnsupportedOperationException("Not Implemented"); - } - - - @Override - public ChunkSource getChunkSource() - { - throw new UnsupportedOperationException("Not Implemented"); - } - - - @Override - public DifficultyInstance getCurrentDifficultyAt(BlockPos arg0) - { - throw new UnsupportedOperationException("Not Implemented"); - } - - @Nullable - @Override - public MinecraftServer getServer() { - return serverWorld.getServer(); - } - - - @Override - public long nextSubTickCount() { - return 0; - } - - @Override - public LevelTickAccess getBlockTicks() { - return null; - } - - @Override - public LevelTickAccess getFluidTicks() { - return null; - } - - @Override - public LevelData getLevelData() - { - throw new UnsupportedOperationException("Not Implemented"); - } - - - @Override - public void levelEvent(Player arg0, int arg1, BlockPos arg2, int arg3) - { - throw new UnsupportedOperationException("Not Implemented"); - - } - - // TODO: Check if this causes any issues - @Override - public void gameEvent(@Nullable Entity entity, GameEvent gameEvent, BlockPos blockPos) { - throw new UnsupportedOperationException("Not Implemented"); - } - - - @Override - public List getEntities(Entity arg0, AABB arg1, Predicate arg2) - { - throw new UnsupportedOperationException("Not Implemented"); - } - - @Override - public List getEntities(EntityTypeTest entityTypeTest, AABB aABB, Predicate predicate) { - throw new UnsupportedOperationException("Not Implemented"); - } - - - @Override - public List getEntitiesOfClass(Class arg0, AABB arg1, - Predicate arg2) - { - throw new UnsupportedOperationException("Not Implemented"); - } - - - @Override - public List players() - { - throw new UnsupportedOperationException("Not Implemented"); - } - - - @Override - public int getSkyDarken() - { - throw new UnsupportedOperationException("Not Implemented"); - } - - - @Override - public Biome getUncachedNoiseBiome(int p_225604_1_, int p_225604_2_, int p_225604_3_) - { - throw new UnsupportedOperationException("Not Implemented"); - } - - - @Override - public boolean isClientSide() - { - throw new UnsupportedOperationException("Not Implemented"); - } - - - @Override - public DimensionType dimensionType() - { - throw new UnsupportedOperationException("Not Implemented"); - } - - - @Override - public BlockEntity getBlockEntity(BlockPos p_175625_1_) - { - throw new UnsupportedOperationException("Not Implemented"); - } - -} diff --git a/core b/core index a5a4a3e6e..e9e2af280 160000 --- a/core +++ b/core @@ -1 +1 @@ -Subproject commit a5a4a3e6e25f27b7adb2211936aa16be3cd8349d +Subproject commit e9e2af2807b230ef840b93e78bf4df33daf7fa82 diff --git a/fabric/build.gradle b/fabric/build.gradle index eb86e3880..f081f11b1 100644 --- a/fabric/build.gradle +++ b/fabric/build.gradle @@ -62,7 +62,7 @@ dependencies { implementation "org.joml:joml:1.10.2" // Lithium - modImplementation "maven.modrinth:lithium:${project.lithium_version}" + //modImplementation "maven.modrinth:lithium:${project.lithium_version}" // Iris // modImplementation "maven.modrinth:iris:${project.iris_version}" From e294fc79eb8cffb44ad0337f2cb5d789aa098b50 Mon Sep 17 00:00:00 2001 From: tom lee Date: Sun, 23 Jan 2022 20:28:35 +0800 Subject: [PATCH 2/4] Fixed using wrong func for makeBiome(). --- .../worldGeneration/WorldGenerationStep.java | 15 ++++++++++++--- common/src/main/resources/lod.accesswidener | 1 + 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/WorldGenerationStep.java b/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/WorldGenerationStep.java index 17b5f1987..12a6c19e4 100644 --- a/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/WorldGenerationStep.java +++ b/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/WorldGenerationStep.java @@ -62,6 +62,7 @@ import net.minecraft.world.level.LightLayer; import net.minecraft.world.level.StructureFeatureManager; import net.minecraft.world.level.biome.Biome; import net.minecraft.world.level.biome.BiomeManager; +import net.minecraft.world.level.biome.BiomeResolver; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.EntityBlock; @@ -86,8 +87,11 @@ import net.minecraft.core.Registry; import net.minecraft.core.RegistryAccess; import net.minecraft.core.SectionPos; import net.minecraft.nbt.CompoundTag; +import net.minecraft.world.level.levelgen.Beardifier; +import net.minecraft.world.level.levelgen.BelowZeroRetrogen; import net.minecraft.world.level.levelgen.Heightmap; import net.minecraft.world.level.levelgen.NoiseBasedChunkGenerator; +import net.minecraft.world.level.levelgen.NoiseChunk; import net.minecraft.world.level.levelgen.NoiseSettings; import net.minecraft.world.level.levelgen.WorldGenSettings; import net.minecraft.world.level.levelgen.blending.Blender; @@ -117,7 +121,7 @@ Lod Generation: 0.269023348s */ public final class WorldGenerationStep { - public static final boolean ENABLE_PERF_LOGGING = true; + public static final boolean ENABLE_PERF_LOGGING = false; public static final boolean ENABLE_EVENT_LOGGING = false; //TODO: Make this LightMode a config //TODO: Make actual proper support for StarLight @@ -804,8 +808,13 @@ public final class WorldGenerationStep { public final ChunkStatus STATUS = ChunkStatus.BIOMES; private ChunkAccess createBiomes(ChunkGenerator generator, Registry registry, Blender blender, StructureFeatureManager structureFeatureManager, ChunkAccess chunkAccess) { - chunkAccess.fillBiomesFromNoise(generator.getBiomeSource()::getNoiseBiome, generator.climateSampler()); - return chunkAccess; + if (generator instanceof NoiseBasedChunkGenerator) { + ((NoiseBasedChunkGenerator) generator).doCreateBiomes(registry, blender, structureFeatureManager, chunkAccess); + return chunkAccess; + } else { + chunkAccess.fillBiomesFromNoise(generator.getBiomeSource()::getNoiseBiome, generator.climateSampler()); + return chunkAccess; + } } public void generateGroup(ThreadedParameters tParams, WorldGenRegion worldGenRegion, diff --git a/common/src/main/resources/lod.accesswidener b/common/src/main/resources/lod.accesswidener index 752bd2c30..aa1a0dc5e 100644 --- a/common/src/main/resources/lod.accesswidener +++ b/common/src/main/resources/lod.accesswidener @@ -24,6 +24,7 @@ accessible method net/minecraft/world/level/levelgen/Heightmap setHeight (III)V accessible field net/minecraft/world/level/biome/Biome generationSettings Lnet/minecraft/world/level/biome/BiomeGenerationSettings; accessible field net/minecraft/world/level/levelgen/NoiseBasedChunkGenerator settings Ljava/util/function/Supplier; accessible method net/minecraft/world/level/levelgen/NoiseBasedChunkGenerator doFill (Lnet/minecraft/world/level/levelgen/blending/Blender;Lnet/minecraft/world/level/StructureFeatureManager;Lnet/minecraft/world/level/chunk/ChunkAccess;II)Lnet/minecraft/world/level/chunk/ChunkAccess; +accessible method net/minecraft/world/level/levelgen/NoiseBasedChunkGenerator doCreateBiomes (Lnet/minecraft/core/Registry;Lnet/minecraft/world/level/levelgen/blending/Blender;Lnet/minecraft/world/level/StructureFeatureManager;Lnet/minecraft/world/level/chunk/ChunkAccess;)V # lod generation from save file accessible field net/minecraft/server/level/ChunkMap mainThreadExecutor Lnet/minecraft/util/thread/BlockableEventLoop; From 54f3e9e12d599817c2b2b9ecb095678a0d76a36b Mon Sep 17 00:00:00 2001 From: tom lee Date: Sun, 23 Jan 2022 21:19:53 +0800 Subject: [PATCH 3/4] Update core --- .../common/wrappers/worldGeneration/WorldGenerationStep.java | 3 ++- core | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/WorldGenerationStep.java b/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/WorldGenerationStep.java index 12a6c19e4..73cabd78d 100644 --- a/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/WorldGenerationStep.java +++ b/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/WorldGenerationStep.java @@ -25,6 +25,7 @@ import com.seibel.lod.core.builders.lodBuilding.LodBuilder; import com.seibel.lod.core.builders.lodBuilding.LodBuilderConfig; import com.seibel.lod.core.enums.config.DistanceGenerationMode; import com.seibel.lod.core.objects.lod.LodDimension; +import com.seibel.lod.core.util.LodThreadFactory; import com.seibel.lod.core.wrapperInterfaces.modAccessor.IStarlightAccessor; import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap; @@ -469,7 +470,7 @@ public final class WorldGenerationStep { final StepLight stepLight = new StepLight(); public final ExecutorService executors = Executors - .newCachedThreadPool(new ThreadFactoryBuilder().setNameFormat("Gen-Worker-Thread-%d").build()); + .newCachedThreadPool(new LodThreadFactory("Gen-Worker-Thread", Thread.MIN_PRIORITY)); public boolean tryAddPoint(int px, int pz, int range, Steps target) { int boxSize = range * 2 + 1; diff --git a/core b/core index e9e2af280..f93983994 160000 --- a/core +++ b/core @@ -1 +1 @@ -Subproject commit e9e2af2807b230ef840b93e78bf4df33daf7fa82 +Subproject commit f93983994190c9e32ee57e59b653568d238b7644 From 9d3ce5307ca1a1e4cf49f5437d414a3478dc3487 Mon Sep 17 00:00:00 2001 From: tom lee Date: Sun, 23 Jan 2022 23:17:04 +0800 Subject: [PATCH 4/4] Updated core + cleanup imports in WorldGen --- .../wrappers/worldGeneration/WorldGenerationStep.java | 7 ------- core | 2 +- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/WorldGenerationStep.java b/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/WorldGenerationStep.java index 73cabd78d..4545ddd1b 100644 --- a/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/WorldGenerationStep.java +++ b/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/WorldGenerationStep.java @@ -46,7 +46,6 @@ import java.util.concurrent.TimeUnit; import org.jetbrains.annotations.Nullable; import com.google.common.collect.Sets; -import com.google.common.util.concurrent.ThreadFactoryBuilder; import com.mojang.datafixers.DataFixer; import com.seibel.lod.common.wrappers.chunk.ChunkWrapper; @@ -55,7 +54,6 @@ import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.WorldGenRegion; import net.minecraft.util.Mth; import net.minecraft.world.entity.Entity; -import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.ChunkPos; import net.minecraft.world.level.LevelHeightAccessor; @@ -63,8 +61,6 @@ import net.minecraft.world.level.LightLayer; import net.minecraft.world.level.StructureFeatureManager; import net.minecraft.world.level.biome.Biome; import net.minecraft.world.level.biome.BiomeManager; -import net.minecraft.world.level.biome.BiomeResolver; -import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.EntityBlock; import net.minecraft.world.level.block.entity.BlockEntity; @@ -88,11 +84,8 @@ import net.minecraft.core.Registry; import net.minecraft.core.RegistryAccess; import net.minecraft.core.SectionPos; import net.minecraft.nbt.CompoundTag; -import net.minecraft.world.level.levelgen.Beardifier; -import net.minecraft.world.level.levelgen.BelowZeroRetrogen; import net.minecraft.world.level.levelgen.Heightmap; import net.minecraft.world.level.levelgen.NoiseBasedChunkGenerator; -import net.minecraft.world.level.levelgen.NoiseChunk; import net.minecraft.world.level.levelgen.NoiseSettings; import net.minecraft.world.level.levelgen.WorldGenSettings; import net.minecraft.world.level.levelgen.blending.Blender; diff --git a/core b/core index f93983994..ab3880a5e 160000 --- a/core +++ b/core @@ -1 +1 @@ -Subproject commit f93983994190c9e32ee57e59b653568d238b7644 +Subproject commit ab3880a5e56b7238522fd598696e9fe5ee2f67b6