diff --git a/fabric-api-dev/README.md b/fabric-api-dev/README.md deleted file mode 100644 index 6b857575ea..0000000000 --- a/fabric-api-dev/README.md +++ /dev/null @@ -1,55 +0,0 @@ -`Weight#validate`: -- Argument: `fabric.dev.zeroWeightWarning` -- Default: true -- Logs an error when a weight is set to 0 - -`Bootstrap#logMissing`: -- Argument `fabric.dev.logMissingTranslations` -- Default: true -- Logs an error when a translation is missing - -`CommandManager#checkMissing`: -- Argument `fabric.dev.enableCommandArgumentLogging` -- Default: true -- Logs an error regarding argument ambiguity and throws an exception if an argument type is not registered - -`Block#` & `Item#`: -- Argument `fabric.dev.logConventionIssues` -- Default: true -- Logs an error if Block classes don't end with Block and if Item classes don't end with Item - -`EulaReader#` & `EulaReader#createEulaFile`: -- Argument: `fabric.dev.alwaysAgreeToEula` -- Default: false -- Note: By enabling this, you declare that you have agreed to the EULA. -- Skips creating the eula.txt file and always agrees to the EULA - -`CommandManager#`: -- Argument: `fabric.dev.registerDebugCommands` -- Default: true -- Registers Minecraft's debug commands (TestCommand, RaidCommand, DebugPathCommand, DebugMobSpawningCommand, WardenSpawnTrackerCommand, SpawnArmorTrimsCommand, ServerPackCommand) and if on the server DebugConfigCommand - -`CommandManager#execute`: -- Argument: `fabric.dev.enableCommandExceptionLogging` -- Default: true -- Logs an error if a command threw an exception - -`BlockBox#` -- Argument: `fabric.dev.throwOnInvalidBlockBoxes` -- Default: true -- Throw's an exception if a bounding box is invalid - -`Chunk#sampleHeightmap`: -- Argument: `fabric.dev.enableUnprimedHeightmapLogging` -- Default: true -- Logs an error if the heightmap is null - -`Util#debugRunnable` & `Util#debugSupplier`: -- Argument: `fabric.dev.enableSupplierAndRunnableDebugging` -- Default: false -- Set's the current thread's name to the activeThreadName if debugRunnable or debugSupplier is called - -`Util#error` & `Util#throwOrPause`: -- Argument: `fabric.dev.enableExceptionIdePausing` -- Default: true -- Call's a method in which you should have a breakpoint to debug errors thrown with Util#error and exceptions thrown with Util#throwOrPause diff --git a/fabric-api-dev/src/main/java/net/fabricmc/fabric/FabricDev.java b/fabric-api-dev/src/main/java/net/fabricmc/fabric/FabricDev.java deleted file mode 100644 index a18ecf6bae..0000000000 --- a/fabric-api-dev/src/main/java/net/fabricmc/fabric/FabricDev.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2024 FabricMC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.fabricmc.fabric; - -public class FabricDev { - public static final boolean ZERO_WEIGHT_WARNING = getProperty("zeroWeightWarning", true); - public static final boolean LOG_MISSING_TRANSLATIONS = getProperty("logMissingTranslations", true); - public static final boolean LOG_CONVENTION_ISSUES = getProperty("logConventionIssues", true); - public static final boolean ALWAYS_AGREE_TO_EULA = getProperty("alwaysAgreeToEula", false); - public static final boolean REGISTER_DEBUG_COMMANDS = getProperty("registerDebugCommands", true); - public static final boolean ENABLE_COMMAND_EXCEPTION_LOGGING = getProperty("enableCommandExceptionLogging", true); - public static final boolean ENABLE_COMMAND_ARGUMENT_LOGGING = getProperty("enableCommandArgumentLogging", true); - public static final boolean THROW_ON_INVALID_BLOCK_BOXES = getProperty("throwOnInvalidBlockBoxes", true); - public static final boolean ENABLE_UNPRIMED_HEIGHTMAP_LOGGING = getProperty("enableUnprimedHeightmapLogging", true); - public static final boolean ENABLE_SUPPLIER_AND_RUNNABLE_DEBUGGING = getProperty("enableSupplierAndRunnableDebugging", false); - public static final boolean ENABLE_EXCEPTION_IDE_PAUSING = getProperty("enableExceptionIdePausing", true); - - private static boolean getProperty(String name, boolean defaultValue) { - try { - return "true".equalsIgnoreCase(System.getProperty("fabric.dev" + name)); - } catch (Throwable e) { - return defaultValue; - } - } -} diff --git a/fabric-api-dev/src/main/java/net/fabricmc/fabric/FabricDevProperties.java b/fabric-api-dev/src/main/java/net/fabricmc/fabric/FabricDevProperties.java new file mode 100644 index 0000000000..c9667cf10a --- /dev/null +++ b/fabric-api-dev/src/main/java/net/fabricmc/fabric/FabricDevProperties.java @@ -0,0 +1,136 @@ +/* + * Copyright (c) 2024 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.fabricmc.fabric; + +import com.mojang.brigadier.ParseResults; + +import net.fabricmc.loader.api.FabricLoader; + +import net.minecraft.Bootstrap; +import net.minecraft.server.command.CommandManager; +import net.minecraft.server.dedicated.EulaReader; +import net.minecraft.util.collection.Weight; +import net.minecraft.world.Heightmap; + +import java.util.function.Supplier; + +@SuppressWarnings("JavadocReference") +public class FabricDevProperties { + /** + * Logs an error when a weight is set to zero
+ * Property: fabric.dev.zeroWeightWarning
+ * Default value: true
+ * {@link Weight#validate(int)} + */ + public static final boolean ZERO_WEIGHT_WARNING = getProperty("zeroWeightWarning", true); + + /** + * Logs an error when a translation is missing
+ * Property: fabric.dev.logMissingTranslations
+ * Default value: true
+ * {@link Bootstrap#logMissing()} + */ + public static final boolean LOG_MISSING_TRANSLATIONS = getProperty("logMissingTranslations", true); + + /** + * Logs an error if Block classes don't end with Block and if Item classes don't end with Item
+ * Property: fabric.dev.logConventionIssues
+ * Default value: true
+ * {@link net.minecraft.block.Block#Block} and {@link net.minecraft.item.Item#Item} + */ + public static final boolean LOG_CONVENTION_ISSUES = getProperty("logConventionIssues", true); + + /** + * Skips creating the eula.txt file and always agrees to the EULA
+ * Note: By enabling this, you declare that you have agreed to the EULA.
+ * Property: fabric.dev.alwaysAgreeToEula
+ * Default value: false
+ * {@link net.minecraft.server.dedicated.EulaReader#EulaReader} and {@link EulaReader#createEulaFile()} + */ + public static final boolean ALWAYS_AGREE_TO_EULA = getProperty("alwaysAgreeToEula", false); + + /** + * Registers Minecraft's debug commands + * (TestCommand, RaidCommand, DebugPathCommand, DebugMobSpawningCommand, + * WardenSpawnTrackerCommand, SpawnArmorTrimsCommand, ServerPackCommand), + * and if on the server DebugConfigCommand
+ * Property: fabric.dev.registerDebugCommands
+ * Default value: true
+ * {@link CommandManager#CommandManager} + */ + public static final boolean REGISTER_DEBUG_COMMANDS = getProperty("registerDebugCommands", true); + + /** + * Logs an error if a command threw an exception
+ * Property: fabric.dev.enableCommandExceptionLogging
+ * Default value: true
+ * {@link CommandManager#execute(ParseResults, String)} + */ + public static final boolean ENABLE_COMMAND_EXCEPTION_LOGGING = getProperty("enableCommandExceptionLogging", true); + + /** + * Logs an error regarding argument ambiguity and throws an exception if an argument type is not registered
+ * Property: fabric.dev.enableCommandArgumentLogging
+ * Default value: true
+ * {@link CommandManager#checkMissing()} + */ + public static final boolean ENABLE_COMMAND_ARGUMENT_LOGGING = getProperty("enableCommandArgumentLogging", true); + + /** + * Throw's an exception if a bounding box is invalid
+ * Property: fabric.dev.throwOnInvalidBlockBoxes
+ * Default value: true
+ * {@link net.minecraft.util.math.BlockBox#BlockBox(int, int, int, int, int, int)} + */ + public static final boolean THROW_ON_INVALID_BLOCK_BOXES = getProperty("throwOnInvalidBlockBoxes", true); + + /** + * Logs an error if the heightmap is null
+ * Property: fabric.dev.enableUnprimedHeightmapLogging
+ * Default value: true
+ * {@link net.minecraft.world.chunk.Chunk#sampleHeightmap(Heightmap.Type, int, int)} + */ + public static final boolean ENABLE_UNPRIMED_HEIGHTMAP_LOGGING = getProperty("enableUnprimedHeightmapLogging", true); + + /** + * Set's the current thread's name to the activeThreadName if debugRunnable or debugSupplier is called
+ * Property: fabric.dev.enableSupplierAndRunnableDebugging
+ * Default value: false
+ * {@link net.minecraft.util.Util#debugRunnable(String, Runnable)} and {@link net.minecraft.util.Util#debugSupplier(String, Supplier)} + */ + public static final boolean ENABLE_SUPPLIER_AND_RUNNABLE_DEBUGGING = getProperty("enableSupplierAndRunnableDebugging", false); + + /** + * Invokes a method in which you should have a breakpoint to debug errors + * thrown with Util#error and exceptions thrown with Util#throwOrPause
+ * Property: fabric.dev.enableExceptionIdePausing
+ * Default value: true
+ * {@link net.minecraft.util.Util#error(String)}, {@link net.minecraft.util.Util#error(String, Throwable)} + * and {@link net.minecraft.util.Util#throwOrPause(Throwable)} + */ + public static final boolean ENABLE_EXCEPTION_IDE_PAUSING = getProperty("enableExceptionIdePausing", true); + + private static final boolean IS_DEVELOPMENT_ENV = FabricLoader.getInstance().isDevelopmentEnvironment(); + + private static boolean getProperty(String name, boolean defaultValue) { + try { + return "true".equalsIgnoreCase(System.getProperty("fabric.dev" + name)); + } catch (Throwable e) { + return IS_DEVELOPMENT_ENV && defaultValue; + } + } +} diff --git a/fabric-api-dev/src/main/java/net/fabricmc/fabric/mixin/dev/BlockAndItemMixin.java b/fabric-api-dev/src/main/java/net/fabricmc/fabric/mixin/dev/BlockAndItemMixin.java index c15f80d897..e19cdbd9ef 100644 --- a/fabric-api-dev/src/main/java/net/fabricmc/fabric/mixin/dev/BlockAndItemMixin.java +++ b/fabric-api-dev/src/main/java/net/fabricmc/fabric/mixin/dev/BlockAndItemMixin.java @@ -17,14 +17,15 @@ package net.fabricmc.fabric.mixin.dev; import com.llamalad7.mixinextras.injector.ModifyExpressionValue; + +import net.fabricmc.fabric.FabricDevProperties; + import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import net.minecraft.block.Block; import net.minecraft.item.Item; -import net.fabricmc.fabric.FabricDev; - @Mixin({Block.class, Item.class}) public class BlockAndItemMixin { @ModifyExpressionValue(method = { @@ -32,6 +33,6 @@ public class BlockAndItemMixin { "(Lnet/minecraft/item/Item$Settings;)V" }, at = @At(value = "FIELD", target = "Lnet/minecraft/SharedConstants;isDevelopment:Z")) private boolean mevIsDevelopmentForDevModule(boolean original) { - return original || FabricDev.LOG_CONVENTION_ISSUES; + return original || FabricDevProperties.LOG_CONVENTION_ISSUES; } } diff --git a/fabric-api-dev/src/main/java/net/fabricmc/fabric/mixin/dev/BlockBoxMixin.java b/fabric-api-dev/src/main/java/net/fabricmc/fabric/mixin/dev/BlockBoxMixin.java index d6294cd23e..9aff41ea67 100644 --- a/fabric-api-dev/src/main/java/net/fabricmc/fabric/mixin/dev/BlockBoxMixin.java +++ b/fabric-api-dev/src/main/java/net/fabricmc/fabric/mixin/dev/BlockBoxMixin.java @@ -17,17 +17,18 @@ package net.fabricmc.fabric.mixin.dev; import com.llamalad7.mixinextras.injector.ModifyExpressionValue; + +import net.fabricmc.fabric.FabricDevProperties; + import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import net.minecraft.util.math.BlockBox; -import net.fabricmc.fabric.FabricDev; - @Mixin(BlockBox.class) public class BlockBoxMixin { @ModifyExpressionValue(method = "(IIIIII)V", at = @At(value = "FIELD", target = "Lnet/minecraft/SharedConstants;isDevelopment:Z")) private static boolean mevIsDevelopmentForDevModule(boolean original) { - return original || FabricDev.THROW_ON_INVALID_BLOCK_BOXES; + return original || FabricDevProperties.THROW_ON_INVALID_BLOCK_BOXES; } } diff --git a/fabric-api-dev/src/main/java/net/fabricmc/fabric/mixin/dev/BootstrapMixin.java b/fabric-api-dev/src/main/java/net/fabricmc/fabric/mixin/dev/BootstrapMixin.java index 88740e6e00..d3f82cb717 100644 --- a/fabric-api-dev/src/main/java/net/fabricmc/fabric/mixin/dev/BootstrapMixin.java +++ b/fabric-api-dev/src/main/java/net/fabricmc/fabric/mixin/dev/BootstrapMixin.java @@ -21,27 +21,28 @@ import com.llamalad7.mixinextras.injector.ModifyExpressionValue; import com.llamalad7.mixinextras.injector.v2.WrapWithCondition; + +import net.fabricmc.fabric.FabricDevProperties; + import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import net.minecraft.Bootstrap; -import net.fabricmc.fabric.FabricDev; - @Mixin(Bootstrap.class) public class BootstrapMixin { @ModifyExpressionValue(method = "logMissing", at = @At(value = "FIELD", target = "Lnet/minecraft/SharedConstants;isDevelopment:Z")) private static boolean mevIsDevelopmentForDevModule(boolean original) { - return original || FabricDev.LOG_MISSING_TRANSLATIONS || FabricDev.ENABLE_COMMAND_ARGUMENT_LOGGING; + return original || FabricDevProperties.LOG_MISSING_TRANSLATIONS || FabricDevProperties.ENABLE_COMMAND_ARGUMENT_LOGGING; } @WrapWithCondition(method = "logMissing", at = @At(value = "INVOKE", target = "Ljava/util/Set;forEach(Ljava/util/function/Consumer;)V")) private static boolean wrapWithConditionTranslationWarnings(Set instance, Consumer consumer) { - return FabricDev.LOG_MISSING_TRANSLATIONS; + return FabricDevProperties.LOG_MISSING_TRANSLATIONS; } @WrapWithCondition(method = "logMissing", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/command/CommandManager;checkMissing()V")) private static boolean wrapWithConditionCommandArgumentWarnings() { - return FabricDev.ENABLE_COMMAND_ARGUMENT_LOGGING; + return FabricDevProperties.ENABLE_COMMAND_ARGUMENT_LOGGING; } } diff --git a/fabric-api-dev/src/main/java/net/fabricmc/fabric/mixin/dev/ChunkMixin.java b/fabric-api-dev/src/main/java/net/fabricmc/fabric/mixin/dev/ChunkMixin.java index e526d87e66..97c20d4c8e 100644 --- a/fabric-api-dev/src/main/java/net/fabricmc/fabric/mixin/dev/ChunkMixin.java +++ b/fabric-api-dev/src/main/java/net/fabricmc/fabric/mixin/dev/ChunkMixin.java @@ -22,12 +22,12 @@ import net.minecraft.world.chunk.Chunk; -import net.fabricmc.fabric.FabricDev; +import net.fabricmc.fabric.FabricDevProperties; @Mixin(Chunk.class) public class ChunkMixin { @ModifyExpressionValue(method = "sampleHeightmap", at = @At(value = "FIELD", target = "Lnet/minecraft/SharedConstants;isDevelopment:Z")) private static boolean mevIsDevelopmentForDevModule(boolean original) { - return original || FabricDev.ENABLE_UNPRIMED_HEIGHTMAP_LOGGING; + return original || FabricDevProperties.ENABLE_UNPRIMED_HEIGHTMAP_LOGGING; } } diff --git a/fabric-api-dev/src/main/java/net/fabricmc/fabric/mixin/dev/CommandManagerMixin.java b/fabric-api-dev/src/main/java/net/fabricmc/fabric/mixin/dev/CommandManagerMixin.java index 39a8300cec..c69b1ba312 100644 --- a/fabric-api-dev/src/main/java/net/fabricmc/fabric/mixin/dev/CommandManagerMixin.java +++ b/fabric-api-dev/src/main/java/net/fabricmc/fabric/mixin/dev/CommandManagerMixin.java @@ -17,22 +17,23 @@ package net.fabricmc.fabric.mixin.dev; import com.llamalad7.mixinextras.injector.ModifyExpressionValue; + +import net.fabricmc.fabric.FabricDevProperties; + import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import net.minecraft.server.command.CommandManager; -import net.fabricmc.fabric.FabricDev; - @Mixin(CommandManager.class) public class CommandManagerMixin { @ModifyExpressionValue(method = "", at = @At(value = "FIELD", target = "Lnet/minecraft/SharedConstants;isDevelopment:Z")) private static boolean mevIsDevelopmentForDevModule(boolean original) { - return original || FabricDev.REGISTER_DEBUG_COMMANDS; + return original || FabricDevProperties.REGISTER_DEBUG_COMMANDS; } @ModifyExpressionValue(method = "execute", at = @At(value = "FIELD", target = "Lnet/minecraft/SharedConstants;isDevelopment:Z")) private static boolean mevIsDevelopmentForDevModule2(boolean original) { - return original || FabricDev.ENABLE_COMMAND_EXCEPTION_LOGGING; + return original || FabricDevProperties.ENABLE_COMMAND_EXCEPTION_LOGGING; } } diff --git a/fabric-api-dev/src/main/java/net/fabricmc/fabric/mixin/dev/EulaReaderMixin.java b/fabric-api-dev/src/main/java/net/fabricmc/fabric/mixin/dev/EulaReaderMixin.java index a186040386..6011f4af4e 100644 --- a/fabric-api-dev/src/main/java/net/fabricmc/fabric/mixin/dev/EulaReaderMixin.java +++ b/fabric-api-dev/src/main/java/net/fabricmc/fabric/mixin/dev/EulaReaderMixin.java @@ -17,17 +17,18 @@ package net.fabricmc.fabric.mixin.dev; import com.llamalad7.mixinextras.injector.ModifyExpressionValue; + +import net.fabricmc.fabric.FabricDevProperties; + import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import net.minecraft.server.dedicated.EulaReader; -import net.fabricmc.fabric.FabricDev; - @Mixin(EulaReader.class) public class EulaReaderMixin { @ModifyExpressionValue(method = {"", "createEulaFile"}, at = @At(value = "FIELD", target = "Lnet/minecraft/SharedConstants;isDevelopment:Z")) private boolean mevIsDevelopmentForDevModule(boolean original) { - return original || FabricDev.ALWAYS_AGREE_TO_EULA; + return original || FabricDevProperties.ALWAYS_AGREE_TO_EULA; } } diff --git a/fabric-api-dev/src/main/java/net/fabricmc/fabric/mixin/dev/UtilMixin.java b/fabric-api-dev/src/main/java/net/fabricmc/fabric/mixin/dev/UtilMixin.java index 92185eabf6..30cdfcf774 100644 --- a/fabric-api-dev/src/main/java/net/fabricmc/fabric/mixin/dev/UtilMixin.java +++ b/fabric-api-dev/src/main/java/net/fabricmc/fabric/mixin/dev/UtilMixin.java @@ -17,13 +17,14 @@ package net.fabricmc.fabric.mixin.dev; import com.llamalad7.mixinextras.injector.ModifyExpressionValue; + +import net.fabricmc.fabric.FabricDevProperties; + import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import net.minecraft.util.Util; -import net.fabricmc.fabric.FabricDev; - @Mixin(Util.class) public class UtilMixin { @ModifyExpressionValue(method = { @@ -31,11 +32,11 @@ public class UtilMixin { "debugSupplier(Ljava/lang/String;Ljava/util/function/Supplier;)Ljava/util/function/Supplier;" }, at = @At(value = "FIELD", target = "Lnet/minecraft/SharedConstants;isDevelopment:Z")) private static boolean mevIsDevelopmentForDevModule2(boolean original) { - return original || FabricDev.ENABLE_SUPPLIER_AND_RUNNABLE_DEBUGGING; + return original || FabricDevProperties.ENABLE_SUPPLIER_AND_RUNNABLE_DEBUGGING; } @ModifyExpressionValue(method = {"error", "throwOrPause"}, at = @At(value = "FIELD", target = "Lnet/minecraft/SharedConstants;isDevelopment:Z")) private static boolean mevIsDevelopmentForDevModule3(boolean original) { - return original || FabricDev.ENABLE_EXCEPTION_IDE_PAUSING; + return original || FabricDevProperties.ENABLE_EXCEPTION_IDE_PAUSING; } } diff --git a/fabric-api-dev/src/main/java/net/fabricmc/fabric/mixin/dev/WeightMixin.java b/fabric-api-dev/src/main/java/net/fabricmc/fabric/mixin/dev/WeightMixin.java index 3f4e1e4eae..a99e72030f 100644 --- a/fabric-api-dev/src/main/java/net/fabricmc/fabric/mixin/dev/WeightMixin.java +++ b/fabric-api-dev/src/main/java/net/fabricmc/fabric/mixin/dev/WeightMixin.java @@ -22,12 +22,12 @@ import net.minecraft.util.collection.Weight; -import net.fabricmc.fabric.FabricDev; +import net.fabricmc.fabric.FabricDevProperties; @Mixin(Weight.class) public class WeightMixin { @ModifyExpressionValue(method = "validate", at = @At(value = "FIELD", target = "Lnet/minecraft/SharedConstants;isDevelopment:Z")) private static boolean mevIsDevelopmentForDevModule(boolean original) { - return original || FabricDev.ZERO_WEIGHT_WARNING; + return original || FabricDevProperties.ZERO_WEIGHT_WARNING; } } diff --git a/gradle.properties b/gradle.properties index a9182c2b3c..d3920c1cc3 100644 --- a/gradle.properties +++ b/gradle.properties @@ -13,7 +13,7 @@ curseforge_minecraft_version=1.21.1 # Do not manually update, use the bumpversions task: fabric-api-base-version=0.4.42 -fabric-api-dev-version=0.0.1 +fabric-api-dev-version=1.0.0 fabric-api-lookup-api-v1-version=1.6.68 fabric-biome-api-v1-version=13.0.29 fabric-block-api-v1-version=1.0.22