Better logging

This commit is contained in:
Frank 2022-07-10 00:26:07 +02:00
parent a988083417
commit 8f9c33e378
9 changed files with 99 additions and 23 deletions

View file

@ -1,8 +1,10 @@
package org.betterx.bclib.api.v2.generator;
import org.betterx.bclib.BCLib;
import org.betterx.bclib.api.v2.levelgen.biomes.BiomeAPI;
import org.betterx.bclib.api.v2.levelgen.biomes.InternalBiomeAPI;
import org.betterx.worlds.together.biomesource.BiomeSourceFromRegistry;
import org.betterx.worlds.together.biomesource.BiomeSourceHelper;
import org.betterx.worlds.together.biomesource.MergeableBiomeSource;
import org.betterx.worlds.together.world.BiomeSourceWithNoiseRelatedSettings;
import org.betterx.worlds.together.world.BiomeSourceWithSeed;
@ -19,6 +21,7 @@ import com.google.common.collect.Sets;
import java.util.Comparator;
import java.util.List;
import java.util.Set;
import org.jetbrains.annotations.NotNull;
public abstract class BCLBiomeSource extends BiomeSource implements BiomeSourceWithSeed, MergeableBiomeSource<BCLBiomeSource>, BiomeSourceWithNoiseRelatedSettings, BiomeSourceFromRegistry<BCLBiomeSource> {
protected final Registry<Biome> biomeRegistry;
@ -54,7 +57,7 @@ public abstract class BCLBiomeSource extends BiomeSource implements BiomeSourceW
final public void setSeed(long seed) {
if (seed != currentSeed) {
System.out.println(this + " set Seed: " + seed);
BCLib.LOGGER.debug(this + "\n --> new seed = " + seed);
this.currentSeed = seed;
initMap(seed);
}
@ -67,14 +70,14 @@ public abstract class BCLBiomeSource extends BiomeSource implements BiomeSourceW
*/
final public void setMaxHeight(int maxHeight) {
if (this.maxHeight != maxHeight) {
System.out.println(this + " set Max Height: " + maxHeight);
BCLib.LOGGER.debug(this + "\n --> new height = " + maxHeight);
this.maxHeight = maxHeight;
onHeightChange(maxHeight);
}
}
protected final void initMap(long seed) {
System.out.println(this + " updates Map");
BCLib.LOGGER.debug(this + "\n --> Map Update");
onInitMap(seed);
}
@ -89,6 +92,11 @@ public abstract class BCLBiomeSource extends BiomeSource implements BiomeSourceW
protected abstract BCLBiomeSource cloneForDatapack(Set<Holder<Biome>> datapackBiomes);
@NotNull
protected String getNamespaces() {
return BiomeSourceHelper.getNamespaces(possibleBiomes());
}
public interface ValidBiomePredicate {
boolean isValid(Holder<Biome> biome, ResourceLocation location);
}

View file

@ -78,13 +78,12 @@ public class BCLChunkGenerator extends NoiseBasedChunkGenerator implements Resto
}
if (WorldsTogether.RUNS_TERRABLENDER) {
BCLib.LOGGER.info("Make sure features are loaded from terrablender for " + biomeSource);
BCLib.LOGGER.info("Make sure features are loaded from terrablender" + biomeSource);
//terrablender is invalidating the feature initialization
//we redo it at this point, otherwise we will get blank biomes
rebuildFeaturesPerStep(biomeSource);
}
System.out.println("Chunk Generator: " + this + " (biomeSource: " + biomeSource + ")");
}
private void rebuildFeaturesPerStep(BiomeSource biomeSource) {

View file

@ -31,7 +31,6 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.BiFunction;
import org.jetbrains.annotations.NotNull;
public class BCLibEndBiomeSource extends BCLBiomeSource implements BiomeSourceWithConfig<BCLibEndBiomeSource, BCLEndBiomeSourceConfig>, ReloadableBiomeSource {
@ -57,7 +56,6 @@ public class BCLibEndBiomeSource extends BCLBiomeSource implements BiomeSourceWi
)
);
private final Point pos;
private final BiFunction<Point, Integer, Boolean> endLandFunction;
private BiomeMap mapLand;
private BiomeMap mapVoid;
private BiomeMap mapCenter;
@ -99,7 +97,6 @@ public class BCLibEndBiomeSource extends BCLBiomeSource implements BiomeSourceWi
this.config = config;
rebuildBiomePickers();
this.endLandFunction = GeneratorOptions.getEndLandFunction();
this.pos = new Point();
if (initMaps) {
@ -434,7 +431,13 @@ public class BCLibEndBiomeSource extends BCLBiomeSource implements BiomeSourceWi
@Override
public String toString() {
return "BCLib - The End BiomeSource (" + Integer.toHexString(hashCode()) + ", config=" + config + ", seed=" + currentSeed + ", height=" + maxHeight + ", customLand=" + (endLandFunction != null) + ", biomes=" + possibleBiomes().size() + ")";
return "\nBCLib - The End BiomeSource (" + Integer.toHexString(hashCode()) + ")" +
"\n biomes = " + possibleBiomes().size() +
"\n namespaces = " + getNamespaces() +
"\n seed = " + currentSeed +
"\n height = " + maxHeight +
"\n deciders = " + deciders.size() +
"\n config = " + config;
}
@Override

View file

@ -96,8 +96,8 @@ public class BCLibNetherBiomeSource extends BCLBiomeSource implements BiomeSourc
return;
}
if (!BiomeAPI.hasBiome(biomeID)) {
BCLBiome bclBiome = new BCLBiome(biomeID, biome.value());
BCLBiome bclBiome = new BCLBiome(biomeID, biome.value(), BiomeAPI.BiomeType.NETHER);
BiomeAPI.registerBiome(bclBiome);
biomePicker.addBiome(bclBiome);
} else {
BCLBiome bclBiome = BiomeAPI.getBiome(biomeID);
@ -114,17 +114,27 @@ public class BCLibNetherBiomeSource extends BCLBiomeSource implements BiomeSourc
}
protected BCLBiomeSource cloneForDatapack(Set<Holder<Biome>> datapackBiomes) {
datapackBiomes.addAll(getBclBiomes(this.biomeRegistry));
datapackBiomes.addAll(getNonVanillaBiomes(this.biomeRegistry));
datapackBiomes.addAll(possibleBiomes().stream()
.filter(h -> !h.unwrapKey()
.orElseThrow()
.location()
.getNamespace()
.equals("minecraft"))
.toList());
return new BCLibNetherBiomeSource(
this.biomeRegistry,
datapackBiomes.stream().toList(),
datapackBiomes.stream()
.filter(b -> b.isValidInRegistry(biomeRegistry) && b.unwrapKey()
.orElse(null) != BCLBiomeRegistry.EMPTY_BIOME.getBiomeKey())
.toList(),
this.currentSeed,
config,
true
);
}
private static List<Holder<Biome>> getBclBiomes(Registry<Biome> biomeRegistry) {
private static List<Holder<Biome>> getNonVanillaBiomes(Registry<Biome> biomeRegistry) {
List<String> include = Configs.BIOMES_CONFIG.getIncludeMatching(BiomeAPI.BiomeType.NETHER);
List<String> exclude = Configs.BIOMES_CONFIG.getExcludeMatching(BiomeAPI.BiomeType.NETHER);
@ -147,14 +157,15 @@ public class BCLibNetherBiomeSource extends BCLBiomeSource implements BiomeSourc
}
private static boolean isValidNonVanillaNetherBiome(Holder<Biome> biome, ResourceLocation location) {
return (
!"minecraft".equals(location.getNamespace()) &&
NetherBiomes.canGenerateInNether(biome.unwrapKey().get())) ||
BiomeAPI.wasRegisteredAs(location, BiomeAPI.BiomeType.BCL_NETHER);
}
if (BiomeAPI.wasRegisteredAs(location, BiomeAPI.BiomeType.END_IGNORE) || biome.unwrapKey()
.orElseThrow()
.location()
.getNamespace()
.equals("minecraft"))
return false;
public static <T> void debug(Object el, Registry<T> reg) {
System.out.println("Unknown " + el + " in " + reg);
return NetherBiomes.canGenerateInNether(biome.unwrapKey().get()) ||
BiomeAPI.wasRegisteredAsNetherBiome(location);
}
public static void register() {
@ -207,7 +218,12 @@ public class BCLibNetherBiomeSource extends BCLBiomeSource implements BiomeSourc
@Override
public String toString() {
return "BCLib - Nether BiomeSource (" + Integer.toHexString(hashCode()) + ", config=" + config + ", seed=" + currentSeed + ", height=" + maxHeight + ", biomes=" + possibleBiomes().size() + ")";
return "\nBCLib - Nether BiomeSource (" + Integer.toHexString(hashCode()) + ")" +
"\n biomes = " + possibleBiomes().size() +
"\n namespaces = " + getNamespaces() +
"\n seed = " + currentSeed +
"\n height = " + maxHeight +
"\n config = " + config;
}
@Override

View file

@ -236,7 +236,8 @@ public class InternalBiomeAPI {
}
public static void applyModifications(BiomeSource source, ResourceKey<LevelStem> dimension) {
BCLib.LOGGER.info("Apply Modifications for " + dimension.location() + " BiomeSource " + source);
BCLib.LOGGER.info("\nApply Modifications for " + dimension.location() + source.toString()
.replace("\n", "\n "));
/*if (dimension.location().equals(LevelStem.NETHER)){
if (source instanceof BCLBiomeSource s) {
NetherBiomes.useLegacyGeneration = s.biomeSourceVersion==BCLBiomeSource.BIOME_SOURCE_VERSION_SQUARE;

View file

@ -0,0 +1,19 @@
package org.betterx.worlds.together.biomesource;
import net.minecraft.core.Holder;
import net.minecraft.world.level.biome.Biome;
import java.util.Collection;
import java.util.stream.Collectors;
public class BiomeSourceHelper {
public static String getNamespaces(Collection<Holder<Biome>> biomes) {
String namespaces = biomes
.stream()
.filter(h -> h.unwrapKey().isPresent())
.map(h -> h.unwrapKey().get().location().getNamespace())
.distinct()
.collect(Collectors.joining(", "));
return namespaces;
}
}

View file

@ -0,0 +1,18 @@
package org.betterx.worlds.together.mixin.common;
import org.betterx.worlds.together.biomesource.BiomeSourceHelper;
import net.minecraft.world.level.biome.BiomeSource;
import org.spongepowered.asm.mixin.Mixin;
@Mixin(BiomeSource.class)
public class BiomeSourceMixin {
@Override
public String toString() {
BiomeSource self = (BiomeSource) (Object) this;
return "\n" + getClass().getSimpleName() + " (" + Integer.toHexString(hashCode()) + ")" +
"\n biomes = " + self.possibleBiomes().size() +
"\n namespaces = " + BiomeSourceHelper.getNamespaces(self.possibleBiomes());
}
}

View file

@ -1,5 +1,6 @@
package org.betterx.worlds.together.world.event;
import org.betterx.bclib.BCLib;
import org.betterx.worlds.together.WorldsTogether;
import org.betterx.worlds.together.levelgen.WorldGenUtil;
import org.betterx.worlds.together.mixin.common.RegistryOpsAccessor;
@ -294,13 +295,23 @@ public class WorldBootstrap {
}
public static void finalizeWorldGenSettings(WorldGenSettings worldGenSettings) {
String output = "World Dimensions: ";
for (var entry : worldGenSettings.dimensions().entrySet()) {
WorldEventsImpl.ON_FINALIZE_LEVEL_STEM.emit(e -> e.now(
worldGenSettings,
entry.getKey(),
entry.getValue()
));
output += "\n - " + entry.getKey().location().toString() + ": " +
"\n " + entry.getValue().generator().toString() + " " +
entry.getValue()
.generator()
.getBiomeSource()
.toString()
.replace("\n", "\n ");
}
BCLib.LOGGER.info(output);
SurfaceRuleUtil.injectSurfaceRulesToAllDimensions(worldGenSettings);
}

View file

@ -4,6 +4,7 @@
"package": "org.betterx.worlds.together.mixin.common",
"compatibilityLevel": "JAVA_17",
"mixins": [
"BiomeSourceMixin",
"BuiltinRegistriesMixin",
"DedicatedServerPropertiesMixin",
"DiggerItemAccessor",