Skip to content

Commit

Permalink
Address the last few reviews
Browse files Browse the repository at this point in the history
  • Loading branch information
IThundxr committed Sep 13, 2024
1 parent e5226ed commit a5bd1d0
Show file tree
Hide file tree
Showing 12 changed files with 169 additions and 121 deletions.
55 changes: 0 additions & 55 deletions fabric-api-dev/README.md

This file was deleted.

39 changes: 0 additions & 39 deletions fabric-api-dev/src/main/java/net/fabricmc/fabric/FabricDev.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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</br>
* Property: <code>fabric.dev.zeroWeightWarning</code></br>
* Default value: true</br>
* {@link Weight#validate(int)}
*/
public static final boolean ZERO_WEIGHT_WARNING = getProperty("zeroWeightWarning", true);

/**
* Logs an error when a translation is missing</br>
* Property: <code>fabric.dev.logMissingTranslations</code></br>
* Default value: true</br>
* {@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</br>
* Property: <code>fabric.dev.logConventionIssues</code></br>
* Default value: true</br>
* {@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</br>
* <strong>Note: By enabling this, you declare that you have agreed to the EULA.</strong></br>
* Property: <code>fabric.dev.alwaysAgreeToEula</code></br>
* Default value: false</br>
* {@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</br>
* Property: <code>fabric.dev.registerDebugCommands</code></br>
* Default value: true</br>
* {@link CommandManager#CommandManager}
*/
public static final boolean REGISTER_DEBUG_COMMANDS = getProperty("registerDebugCommands", true);

/**
* Logs an error if a command threw an exception</br>
* Property: <code>fabric.dev.enableCommandExceptionLogging</code></br>
* Default value: true</br>
* {@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</br>
* Property: <code>fabric.dev.enableCommandArgumentLogging</code></br>
* Default value: true</br>
* {@link CommandManager#checkMissing()}
*/
public static final boolean ENABLE_COMMAND_ARGUMENT_LOGGING = getProperty("enableCommandArgumentLogging", true);

/**
* Throw's an exception if a bounding box is invalid</br>
* Property: <code>fabric.dev.throwOnInvalidBlockBoxes</code></br>
* Default value: true</br>
* {@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</br>
* Property: <code>fabric.dev.enableUnprimedHeightmapLogging</code></br>
* Default value: true</br>
* {@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</br>
* Property: <code>fabric.dev.enableSupplierAndRunnableDebugging</code></br>
* Default value: false</br>
* {@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</br>
* Property: <code>fabric.dev.enableExceptionIdePausing</code></br>
* Default value: true</br>
* {@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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,22 @@
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 = {
"<init>(Lnet/minecraft/block/AbstractBlock$Settings;)V",
"<init>(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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "<init>(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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> instance, Consumer<String> 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "<init>", 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {"<init>", "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;
}
}
Loading

0 comments on commit a5bd1d0

Please sign in to comment.