From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Martijn Muijsers Date: Fri, 25 Nov 2022 16:26:04 +0100 Subject: [PATCH] Softly log invalid pool element errors License: MIT (https://opensource.org/licenses/MIT) Gale - https://galemc.org This patch is based on the following patch: "Change vanilla structure error to info log level" By: chickeneer As part of: EmpireCraft (https://github.com/starlis/empirecraft) Licensed under: MIT (https://opensource.org/licenses/MIT) diff --git a/src/main/java/net/minecraft/world/level/levelgen/structure/PoolElementStructurePiece.java b/src/main/java/net/minecraft/world/level/levelgen/structure/PoolElementStructurePiece.java index d2b4654a9095a678bbc9e004af969cf54da0fcab..d797bac97ec1adec7a25a26c8e052e70e8db1c28 100644 --- a/src/main/java/net/minecraft/world/level/levelgen/structure/PoolElementStructurePiece.java +++ b/src/main/java/net/minecraft/world/level/levelgen/structure/PoolElementStructurePiece.java @@ -23,10 +23,11 @@ import net.minecraft.world.level.levelgen.structure.pieces.StructurePieceType; import net.minecraft.world.level.levelgen.structure.pools.JigsawJunction; import net.minecraft.world.level.levelgen.structure.pools.StructurePoolElement; import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplateManager; +import org.galemc.gale.configuration.GaleGlobalConfiguration; import org.slf4j.Logger; public class PoolElementStructurePiece extends StructurePiece { - private static final Logger LOGGER = LogUtils.getLogger(); + public static final Logger LOGGER = LogUtils.getLogger(); // Gale - EMC - softly log invalid pool element errors - private -> public protected final StructurePoolElement element; protected BlockPos position; private final int groundLevelDelta; @@ -49,7 +50,7 @@ public class PoolElementStructurePiece extends StructurePiece { this.position = new BlockPos(nbt.getInt("PosX"), nbt.getInt("PosY"), nbt.getInt("PosZ")); this.groundLevelDelta = nbt.getInt("ground_level_delta"); DynamicOps dynamicOps = RegistryOps.create(NbtOps.INSTANCE, context.registryAccess()); - this.element = StructurePoolElement.CODEC.parse(dynamicOps, nbt.getCompound("pool_element")).resultOrPartial(LOGGER::error).orElseThrow(() -> { + this.element = StructurePoolElement.CODEC.parse(dynamicOps, nbt.getCompound("pool_element")).resultOrPartial(GaleGlobalConfiguration.get().logToConsole.invalidPoolElementErrorStringConsumer).orElseThrow(() -> { // Gale - EMC - softly log invalid pool element errors return new IllegalStateException("Invalid pool element found"); }); this.rotation = Rotation.valueOf(nbt.getString("rotation")); diff --git a/src/main/java/org/galemc/gale/configuration/GaleGlobalConfiguration.java b/src/main/java/org/galemc/gale/configuration/GaleGlobalConfiguration.java index 72786c52906aa327ad49577390265f326693a975..882830dd0bddb81e1a592cdd089d4340beb946a7 100644 --- a/src/main/java/org/galemc/gale/configuration/GaleGlobalConfiguration.java +++ b/src/main/java/org/galemc/gale/configuration/GaleGlobalConfiguration.java @@ -4,8 +4,12 @@ package org.galemc.gale.configuration; import io.papermc.paper.configuration.Configuration; import io.papermc.paper.configuration.ConfigurationPart; +import net.minecraft.world.level.levelgen.structure.PoolElementStructurePiece; import org.spongepowered.configurate.objectmapping.meta.Setting; +import java.util.Locale; +import java.util.function.Consumer; + @SuppressWarnings({"CanBeFinal", "FieldCanBeLocal", "FieldMayBeFinal", "NotNullFieldNotInitialized", "InnerClassMayBeStatic"}) public class GaleGlobalConfiguration extends ConfigurationPart { static final int CURRENT_VERSION = 1; @@ -108,7 +112,7 @@ public class GaleGlobalConfiguration extends ConfigurationPart { } public LogToConsole logToConsole; - public class LogToConsole extends ConfigurationPart { + public class LogToConsole extends ConfigurationPart.Post { // Gale - EMC - softly log invalid pool element errors public boolean invalidStatistics = true; // Gale - EMC - do not log invalid statistics public boolean ignoredAdvancements = true; // Gale - Purpur - do not log ignored advancements @@ -124,6 +128,21 @@ public class GaleGlobalConfiguration extends ConfigurationPart { public boolean notSecureMarker = true; // Gale - do not log Not Secure marker } + // Gale start - EMC - softly log invalid pool element errors + public String invalidPoolElementErrorLogLevel = "info"; + public transient Consumer invalidPoolElementErrorStringConsumer; + + @Override + public void postProcess() { + this.invalidPoolElementErrorStringConsumer = switch (this.invalidPoolElementErrorLogLevel.toLowerCase(Locale.ROOT)) { + case "none" -> $ -> {}; + case "info", "log" -> PoolElementStructurePiece.LOGGER::info; + case "warn", "warning" -> PoolElementStructurePiece.LOGGER::warn; + default -> PoolElementStructurePiece.LOGGER::error; + }; + } + // Gale end - EMC - softly log invalid pool element errors + } }