Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Dev Module #4087

Open
wants to merge 19 commits into
base: 1.21.1
Choose a base branch
from
75 changes: 75 additions & 0 deletions fabric-api-dev/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
`Weight#validate`:
IThundxr marked this conversation as resolved.
Show resolved Hide resolved
- 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#<init>` & `Item#<init>`:
- 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#<init>` & `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

`MinecraftServer#tickWorlds`:
- Argument: `fabric.dev.tickTestManager`
- Default: false
- Ticks TestManager.INSTANCE
IThundxr marked this conversation as resolved.
Show resolved Hide resolved

`CommandManager#<init>`:
- Argument: `fabric.dev.registerDebugCommands`
- Default: true
- Register's Minecraft's debug commands (TestCommand, RaidCommand, DebugPathCommand, DebugMobSpawningCommand, WardenSpawnTrackerCommand, SpawnArmorTrimsCommand, ServerPackCommand) and if on the server DebugConfigCommand
IThundxr marked this conversation as resolved.
Show resolved Hide resolved

`CommandManager#execute`:
- Argument: `fabric.dev.enableCommandExceptionLogging`
- Default: true
- Logs an error if a command threw an exception

`ArgumentTypes#register`:
- Argument: `fabric.dev.registerTestArguments`
- Default: false
- Register's test_argument and test_class command arguments
IThundxr marked this conversation as resolved.
Show resolved Hide resolved

`BlockBox#<init>`
- Argument: `fabric.dev.throwOnInvalidBlockBoxes`
- Default: true
- Throw's an exception if a bounding box is invalid

`Chunk#sampleHeightmap`:
- Argument: `fabric.dev.enable_unprimed_heightmap_logging`
IThundxr marked this conversation as resolved.
Show resolved Hide resolved
- Default: true
- Logs an error if the heightmap is null

`StructureTemplateManager#<init>`:
- Argument: `fabric.dev.enableLoadingStructuresFromGameTests`
- Default: true
- Adds a provider to load structure templates from GameTest files
IThundxr marked this conversation as resolved.
Show resolved Hide resolved

`Util#getChoiceTypeInternal`:
- Argument: `fabric.dev.throwOnMissingDataFixers`
- Default: false
- Throw's an exception if a DataFixer isn't registered
IThundxr marked this conversation as resolved.
Show resolved Hide resolved

`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
1 change: 1 addition & 0 deletions fabric-api-dev/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
version = getSubprojectVersion(project)
43 changes: 43 additions & 0 deletions fabric-api-dev/src/main/java/net/fabricmc/fabric/FabricDev.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* 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;

Check failure on line 17 in fabric-api-dev/src/main/java/net/fabricmc/fabric/FabricDev.java

View workflow job for this annotation

GitHub Actions / build (21-ubuntu)

Name 'net.fabricmc.fabric' must match pattern '^net\.fabricmc\.fabric\.(api(?!\.common\.)(\.client|\.server|)(\.(?!client\.|server\.)[a-z]+([a-rt-z]|ss))+\.v[0-9]+|(impl|mixin|test)(?!\.common\.)(\.client|\.server|)(\.(?!client\.|server\.)[a-z]+([a-rt-z]|ss))+(\.v[0-9]+)?|api\.(event|util|biomes\.v1|registry|client\.screen|container|block|entity|client\.itemgroup|client\.keybinding|tag|tools|client\.model|network|server|client\.render|resource|client\.texture))(|\.[a-z]+(\.[a-z0-9]+)*)$'.

public class FabricDev {
IThundxr marked this conversation as resolved.
Show resolved Hide resolved
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 TICK_TEST_MANAGER = getProperty("tickTestManager", false);
public static final boolean REGISTER_DEBUG_COMMANDS = getProperty("registerDebugCommands", true);
public static final boolean REGISTER_TEST_ARGUMENTS = getProperty("registerTestArguments", false);
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_LOADING_STRUCTURES_FROM_GAMETESTS = getProperty("enableLoadingStructuresFromGameTests", true);
public static final boolean THROW_ON_MISSING_DATA_FIXERS = getProperty("throwOnMissingDataFixers", false);
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(name));
IThundxr marked this conversation as resolved.
Show resolved Hide resolved
} catch (Throwable e) {
return defaultValue;
IThundxr marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* 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.mixin.dev;

import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import org.spongepowered.asm.mixin.Dynamic;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;

import net.minecraft.command.argument.ArgumentTypes;

import net.fabricmc.fabric.FabricDev;

@Mixin(ArgumentTypes.class)
public class ArgumentTypesMixin {
@Dynamic("@ModifyExpressionValue's the FIELD GET of SharedConstants.isDevelopment to add a OR condition for FabricDev.REGISTER_TEST_ARGUMENTS")
IThundxr marked this conversation as resolved.
Show resolved Hide resolved
@ModifyExpressionValue(method = "register(Lnet/minecraft/registry/Registry;)Lnet/minecraft/command/argument/serialize/ArgumentSerializer;", at = @At(value = "FIELD", target = "Lnet/minecraft/SharedConstants;isDevelopment:Z"))
private static boolean fabric$mevIsDevelopmentForDevModule(boolean original) {
IThundxr marked this conversation as resolved.
Show resolved Hide resolved
return original || FabricDev.REGISTER_TEST_ARGUMENTS;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* 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.mixin.dev;

import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import org.spongepowered.asm.mixin.Dynamic;
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 {
@Dynamic("@ModifyExpressionValue's the FIELD GET of SharedConstants.isDevelopment to add a OR condition for FabricDev.LOG_CONVENTION_ISSUES")
@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 fabric$mevIsDevelopmentForDevModule(boolean original) {
return original || FabricDev.LOG_CONVENTION_ISSUES;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* 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.mixin.dev;

import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import org.spongepowered.asm.mixin.Dynamic;
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 {
@Dynamic("@ModifyExpressionValue's the FIELD GET of SharedConstants.isDevelopment to add a OR condition for FabricDev.THROW_ON_INVALID_BLOCK_BOXES")
@ModifyExpressionValue(method = "<init>(IIIIII)V", at = @At(value = "FIELD", target = "Lnet/minecraft/SharedConstants;isDevelopment:Z"))
private static boolean fabric$mevIsDevelopmentForDevModule(boolean original) {
return original || FabricDev.THROW_ON_INVALID_BLOCK_BOXES;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* 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.mixin.dev;

import java.util.Set;
import java.util.function.Consumer;

import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import com.llamalad7.mixinextras.injector.v2.WrapWithCondition;
import org.spongepowered.asm.mixin.Dynamic;
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 {
@Dynamic("@ModifyExpressionValue's the FIELD GET of SharedConstants.isDevelopment to add OR conditions for FabricDev.LOG_MISSING_TRANSLATIONS and FabricDev.ENABLE_COMMAND_ARGUMENT_LOGGING")
@ModifyExpressionValue(method = "logMissing", at = @At(value = "FIELD", target = "Lnet/minecraft/SharedConstants;isDevelopment:Z"))
private static boolean fabric$mevIsDevelopmentForDevModule(boolean original) {
return original || FabricDev.LOG_MISSING_TRANSLATIONS || FabricDev.ENABLE_COMMAND_ARGUMENT_LOGGING;
}

@Dynamic("Only execute the forEach if FabricDev.LOG_MISSING_TRANSLATIONS is true")
@WrapWithCondition(method = "logMissing", at = @At(value = "INVOKE", target = "Ljava/util/Set;forEach(Ljava/util/function/Consumer;)V"))
private static boolean fabric$wrapWithConditionTranslationWarnings(Set<String> instance, Consumer<String> consumer) {
return FabricDev.LOG_MISSING_TRANSLATIONS;
}

@Dynamic("Only log command argument exceptions if FabricDev.ENABLE_COMMAND_ARGUMENT_LOGGING is true")
@WrapWithCondition(method = "logMissing", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/command/CommandManager;checkMissing()V"))
private static boolean fabric$wrapWithConditionCommandArgumentWarnings() {
return FabricDev.ENABLE_COMMAND_ARGUMENT_LOGGING;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* 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.mixin.dev;

import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import org.spongepowered.asm.mixin.Dynamic;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;

import net.minecraft.world.chunk.Chunk;

import net.fabricmc.fabric.FabricDev;

@Mixin(Chunk.class)
public class ChunkMixin {
@Dynamic("@ModifyExpressionValue's the FIELD GET of SharedConstants.isDevelopment to add a OR condition for FabricDev.ENABLE_UNPRIMED_HEIGHTMAP_LOGGING")
@ModifyExpressionValue(method = "sampleHeightmap", at = @At(value = "FIELD", target = "Lnet/minecraft/SharedConstants;isDevelopment:Z"))
private static boolean fabric$mevIsDevelopmentForDevModule(boolean original) {
return original || FabricDev.ENABLE_UNPRIMED_HEIGHTMAP_LOGGING;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* 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.mixin.dev;

import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import org.spongepowered.asm.mixin.Dynamic;
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 {
@Dynamic("@ModifyExpressionValue's the FIELD GET of SharedConstants.isDevelopment to add a OR condition for FabricDev.REGISTER_DEBUG_COMMANDS")
@ModifyExpressionValue(method = "<init>", at = @At(value = "FIELD", target = "Lnet/minecraft/SharedConstants;isDevelopment:Z"))
private static boolean fabric$mevIsDevelopmentForDevModule(boolean original) {
return original || FabricDev.REGISTER_DEBUG_COMMANDS;
}

@Dynamic("@ModifyExpressionValue's the FIELD GET of SharedConstants.isDevelopment to add a OR condition for FabricDev.ENABLE_COMMAND_EXCEPTION_LOGGING")
@ModifyExpressionValue(method = "execute", at = @At(value = "FIELD", target = "Lnet/minecraft/SharedConstants;isDevelopment:Z"))
private static boolean fabric$mevIsDevelopmentForDevModule2(boolean original) {
return original || FabricDev.ENABLE_COMMAND_EXCEPTION_LOGGING;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* 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.mixin.dev;

import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import org.spongepowered.asm.mixin.Dynamic;
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 {
@Dynamic("@ModifyExpressionValue's the FIELD GET of SharedConstants.isDevelopment to add a OR condition for FabricDev.ALWAYS_AGREE_TO_EULA")
@ModifyExpressionValue(method = {"<init>", "createEulaFile"}, at = @At(value = "FIELD", target = "Lnet/minecraft/SharedConstants;isDevelopment:Z"))
private boolean fabric$mevIsDevelopmentForDevModule(boolean original) {
return original || FabricDev.ALWAYS_AGREE_TO_EULA;
}
}
Loading
Loading