From a5da8b83e88919a1098c8ee678b11f542a8ca87f Mon Sep 17 00:00:00 2001 From: KESSLER Erwan Date: Thu, 26 Dec 2019 23:41:02 +0100 Subject: [PATCH] linked log to in-game chat --- .../kaptainwutax/seedcracker/SeedCracker.java | 24 ++++++------ .../seedcracker/cracker/DecoratorCache.java | 4 +- .../kaptainwutax/seedcracker/util/Log.java | 38 +++++++++++++++++++ 3 files changed, 52 insertions(+), 14 deletions(-) create mode 100644 src/main/java/kaptainwutax/seedcracker/util/Log.java diff --git a/src/main/java/kaptainwutax/seedcracker/SeedCracker.java b/src/main/java/kaptainwutax/seedcracker/SeedCracker.java index e444b15..998477e 100644 --- a/src/main/java/kaptainwutax/seedcracker/SeedCracker.java +++ b/src/main/java/kaptainwutax/seedcracker/SeedCracker.java @@ -5,6 +5,7 @@ import kaptainwutax.seedcracker.cracker.*; import kaptainwutax.seedcracker.cracker.population.PopulationData; import kaptainwutax.seedcracker.finder.FinderQueue; import kaptainwutax.seedcracker.render.RenderQueue; +import kaptainwutax.seedcracker.util.Log; import kaptainwutax.seedcracker.util.Rand; import net.fabricmc.api.ModInitializer; import net.minecraft.util.math.BlockPos; @@ -30,7 +31,6 @@ import java.util.Random; public class SeedCracker implements ModInitializer { - public static final Logger LOG = LogManager.getLogger("Seed Cracker"); private static final SeedCracker INSTANCE = new SeedCracker(); public List worldSeeds = null; @@ -102,19 +102,19 @@ public class SeedCracker implements ModInitializer { this.pillarSeeds = null; this.structureCache.clear(); this.biomeCache.clear(); - this.populationCache.clear(); + this.decoratorCache.clear(); } public synchronized boolean onPillarData(PillarData pillarData) { if(pillarData != null && (this.pillarSeeds == null || this.pillarSeeds.isEmpty())) { - LOG.warn("Looking for pillar seeds..."); + Log.warn("Looking for pillar seeds..."); this.pillarSeeds = pillarData.getPillarSeeds(); if(this.pillarSeeds.size() > 0) { - LOG.warn("Finished search with " + this.pillarSeeds + (this.pillarSeeds.size() == 1 ? " seed." : " seeds.")); + Log.warn("Finished search with " + this.pillarSeeds + (this.pillarSeeds.size() == 1 ? " seed." : " seeds.")); } else { - LOG.error("Finished search with no seeds."); + Log.error("Finished search with no seeds."); } this.onStructureData(null); @@ -138,17 +138,17 @@ public class SeedCracker implements ModInitializer { LOG.warn("Looking for structure seeds with " + this.populationCache.size() + " population features."); this.pillarSeeds.forEach(pillarSeed -> { - timeMachine.buildStructureSeeds(pillarSeed, this.structureCache, this.populationCache, this.structureSeeds); + timeMachine.buildStructureSeeds(pillarSeed, this.structureCache, this.decoratorCache, this.structureSeeds); }); if(this.structureSeeds.size() > 0) { LOG.warn("Finished search with " + this.structureSeeds.size() + (this.structureSeeds.size() == 1 ? " seed." : " seeds.")); } else { - LOG.error("Finished search with no seeds."); + Log.error("Finished search with no seeds."); } this.structureCache.clear(); - this.onPopulationData(null); + this.onDecoratorData(null); this.onBiomeData(null); } else if(this.structureSeeds != null && structureData != null) { this.structureSeeds.removeIf(structureSeed -> { @@ -183,9 +183,9 @@ public class SeedCracker implements ModInitializer { added = true; } - if(this.worldSeeds == null && this.structureSeeds != null && this.biomeCache.size() >= 6) { + if(this.worldSeeds == null && this.structureSeeds != null && this.biomeCache.size() >= 5) { this.worldSeeds = new ArrayList<>(); - LOG.warn("Looking for world seeds with " + this.biomeCache.size() + " biomes."); + Log.warn("Looking for world seeds with " + this.biomeCache.size() + " biomes."); for(int i = 0; i < this.structureSeeds.size(); i++) { SeedCracker.LOG.warn("Progress " + (i * 100.0f) / this.structureSeeds.size() + "%..."); @@ -212,9 +212,9 @@ public class SeedCracker implements ModInitializer { } if(this.worldSeeds.size() > 0) { - LOG.warn("Finished search with " + this.worldSeeds + (this.worldSeeds.size() == 1 ? " seed." : " seeds.")); + Log.warn("Finished search with " + this.worldSeeds + (this.worldSeeds.size() == 1 ? " seed." : " seeds.")); } else { - LOG.error("Finished search with no seeds."); + Log.error("Finished search with no seeds."); } } else if(this.worldSeeds != null && biomeData != null) { this.worldSeeds.removeIf(worldSeed -> { diff --git a/src/main/java/kaptainwutax/seedcracker/cracker/DecoratorCache.java b/src/main/java/kaptainwutax/seedcracker/cracker/DecoratorCache.java index 67bac51..dc05b5e 100644 --- a/src/main/java/kaptainwutax/seedcracker/cracker/DecoratorCache.java +++ b/src/main/java/kaptainwutax/seedcracker/cracker/DecoratorCache.java @@ -1,6 +1,6 @@ package kaptainwutax.seedcracker.cracker; -import kaptainwutax.seedcracker.SeedCracker; +import kaptainwutax.seedcracker.util.Log; import net.minecraft.util.registry.Registry; import net.minecraft.world.biome.Biome; import net.minecraft.world.gen.GenerationStep; @@ -57,7 +57,7 @@ public class DecoratorCache { if(salt == null) { if(debug) { - SeedCracker.LOG.warn(biome.getClass().getSimpleName() + " does not have decorator " + feature + "."); + Log.error(biome.getClass().getSimpleName() + " does not have decorator " + feature + "."); } salt = INVALID; diff --git a/src/main/java/kaptainwutax/seedcracker/util/Log.java b/src/main/java/kaptainwutax/seedcracker/util/Log.java new file mode 100644 index 0000000..5df4c3f --- /dev/null +++ b/src/main/java/kaptainwutax/seedcracker/util/Log.java @@ -0,0 +1,38 @@ +package kaptainwutax.seedcracker.util; + +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.util.TextFormat; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.text.LiteralText; + +public class Log { + + public static void debug(String message) { + PlayerEntity player = getPlayer(); + + if(player != null) { + player.addChatMessage(new LiteralText(message), false); + } + } + + public static void warn(String message) { + PlayerEntity player = getPlayer(); + + if(player != null) { + player.addChatMessage(new LiteralText(TextFormat.YELLOW + message), false); + } + } + + public static void error(String message) { + PlayerEntity player = getPlayer(); + + if(player != null) { + player.addChatMessage(new LiteralText(TextFormat.RED + message), false); + } + } + + private static PlayerEntity getPlayer() { + return MinecraftClient.getInstance().player; + } + +}