diff --git a/build.gradle b/build.gradle
index c25acb4..f39a688 100644
--- a/build.gradle
+++ b/build.gradle
@@ -4,6 +4,7 @@ plugins {
id 'idea'
id 'maven-publish'
id 'net.neoforged.gradle.userdev' version '7.0.109'
+ id 'com.diffplug.spotless' version '6.22.0'
}
version = mod_version
@@ -162,3 +163,26 @@ idea {
downloadJavadoc = true
}
}
+
+// Spotless Java is an automated code formatter https://github.com/diffplug/spotless
+// It can be used to enforce a consistent style across the entire project by running the spotlessApply task
+spotless {
+ java {
+ // Format all java files in the src/ directory
+ target rootProject.fileTree("src", {
+ include "**/*.java"
+ })
+ // Force files to end with a newline (prevents diff changes on the last line when new content is added)
+ endWithNewline()
+ // Forces indentation to be done with spaces due to inconsistent tab sizes
+ indentWithSpaces()
+ // Removes unused imports
+ removeUnusedImports()
+ // Enables "skip-formatting" blocks - https://github.com/diffplug/spotless/blob/main/plugin-gradle/README.md#spotlessoff-and-spotlesson
+ toggleOffOn()
+ // Read the eclipse formatter XML at formatter-config.xml
+ eclipse().configFile rootProject.file('formatter-config.xml')
+ // Use the default import order provided by spotless. https://github.com/diffplug/spotless/blob/main/plugin-gradle/README.md#java
+ importOrder()
+ }
+}
diff --git a/formatter-config.xml b/formatter-config.xml
new file mode 100644
index 0000000..8632531
--- /dev/null
+++ b/formatter-config.xml
@@ -0,0 +1,401 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/main/java/com/example/examplemod/Config.java b/src/main/java/com/example/examplemod/Config.java
index b96d525..39dcc2a 100644
--- a/src/main/java/com/example/examplemod/Config.java
+++ b/src/main/java/com/example/examplemod/Config.java
@@ -3,7 +3,6 @@
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
-
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.Item;
@@ -15,8 +14,7 @@
// An example config class. This is not required, but it's a good idea to have one to keep your config organized.
// Demonstrates how to use Forge's config APIs
@EventBusSubscriber(modid = ExampleMod.MODID, bus = EventBusSubscriber.Bus.MOD)
-public class Config
-{
+public class Config {
private static final ModConfigSpec.Builder BUILDER = new ModConfigSpec.Builder();
private static final ModConfigSpec.BooleanValue LOG_DIRT_BLOCK = BUILDER
@@ -43,14 +41,12 @@ public class Config
public static String magicNumberIntroduction;
public static Set- items;
- private static boolean validateItemName(final Object obj)
- {
+ private static boolean validateItemName(final Object obj) {
return obj instanceof String itemName && BuiltInRegistries.ITEM.containsKey(new ResourceLocation(itemName));
}
@SubscribeEvent
- static void onLoad(final ModConfigEvent event)
- {
+ static void onLoad(final ModConfigEvent event) {
logDirtBlock = LOG_DIRT_BLOCK.get();
magicNumber = MAGIC_NUMBER.get();
magicNumberIntroduction = MAGIC_NUMBER_INTRODUCTION.get();
diff --git a/src/main/java/com/example/examplemod/ExampleMod.java b/src/main/java/com/example/examplemod/ExampleMod.java
index 259b3da..c04bfaa 100644
--- a/src/main/java/com/example/examplemod/ExampleMod.java
+++ b/src/main/java/com/example/examplemod/ExampleMod.java
@@ -1,9 +1,6 @@
package com.example.examplemod;
-import org.slf4j.Logger;
-
import com.mojang.logging.LogUtils;
-
import net.minecraft.client.Minecraft;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.registries.Registries;
@@ -33,11 +30,11 @@
import net.neoforged.neoforge.registries.DeferredHolder;
import net.neoforged.neoforge.registries.DeferredItem;
import net.neoforged.neoforge.registries.DeferredRegister;
+import org.slf4j.Logger;
// The value here should match an entry in the META-INF/mods.toml file
@Mod(ExampleMod.MODID)
-public class ExampleMod
-{
+public class ExampleMod {
// Define mod id in a common place for everything to reference
public static final String MODID = "examplemod";
// Directly reference a slf4j logger
@@ -69,8 +66,7 @@ public class ExampleMod
// The constructor for the mod class is the first code that is run when your mod is loaded.
// FML will recognize some parameter types like IEventBus or ModContainer and pass them in automatically.
- public ExampleMod(IEventBus modEventBus, ModContainer modContainer)
- {
+ public ExampleMod(IEventBus modEventBus, ModContainer modContainer) {
// Register the commonSetup method for modloading
modEventBus.addListener(this::commonSetup);
@@ -93,8 +89,7 @@ public ExampleMod(IEventBus modEventBus, ModContainer modContainer)
modContainer.registerConfig(ModConfig.Type.COMMON, Config.SPEC);
}
- private void commonSetup(final FMLCommonSetupEvent event)
- {
+ private void commonSetup(final FMLCommonSetupEvent event) {
// Some common setup code
LOGGER.info("HELLO FROM COMMON SETUP");
@@ -107,27 +102,23 @@ private void commonSetup(final FMLCommonSetupEvent event)
}
// Add the example block item to the building blocks tab
- private void addCreative(BuildCreativeModeTabContentsEvent event)
- {
+ private void addCreative(BuildCreativeModeTabContentsEvent event) {
if (event.getTabKey() == CreativeModeTabs.BUILDING_BLOCKS)
event.accept(EXAMPLE_BLOCK_ITEM);
}
// You can use SubscribeEvent and let the Event Bus discover methods to call
@SubscribeEvent
- public void onServerStarting(ServerStartingEvent event)
- {
+ public void onServerStarting(ServerStartingEvent event) {
// Do something when the server starts
LOGGER.info("HELLO from server starting");
}
// You can use EventBusSubscriber to automatically register all static methods in the class annotated with @SubscribeEvent
@EventBusSubscriber(modid = MODID, bus = EventBusSubscriber.Bus.MOD, value = Dist.CLIENT)
- public static class ClientModEvents
- {
+ public static class ClientModEvents {
@SubscribeEvent
- public static void onClientSetup(FMLClientSetupEvent event)
- {
+ public static void onClientSetup(FMLClientSetupEvent event) {
// Some client setup code
LOGGER.info("HELLO FROM CLIENT SETUP");
LOGGER.info("MINECRAFT NAME >> {}", Minecraft.getInstance().getUser().getName());