Initial Commit
This commit is contained in:
27
Common/build.gradle
Normal file
27
Common/build.gradle
Normal file
@@ -0,0 +1,27 @@
|
||||
archivesBaseName = "ExampleMod-Common-${minecraft_version}"
|
||||
|
||||
dependencies {
|
||||
// Add your dependencies here
|
||||
}
|
||||
|
||||
/**
|
||||
* ===============================================================================
|
||||
* = DO NOT EDIT BELOW THIS LINE UNLESS YOU KNOW WHAT YOU ARE DOING =
|
||||
* ===============================================================================
|
||||
*/
|
||||
|
||||
unimined.minecraft {
|
||||
fabric {
|
||||
loader fabric_loader
|
||||
}
|
||||
|
||||
defaultRemapJar = false
|
||||
}
|
||||
|
||||
processResources {
|
||||
def buildProps = project.properties.clone()
|
||||
|
||||
filesMatching(['pack.mcmeta']) {
|
||||
expand buildProps
|
||||
}
|
||||
}
|
@@ -0,0 +1,34 @@
|
||||
package com.author.examplemod;
|
||||
|
||||
import com.author.examplemod.platform.IPlatformHelper;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.world.food.FoodProperties;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Items;
|
||||
import net.minecraft.world.item.TooltipFlag;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ExampleModCommon {
|
||||
|
||||
public static void initialize() {
|
||||
ModConstants.LOGGER.info("Hello from Common init on {}! we are currently in a {} environment!", IPlatformHelper.INSTANCE.getPlatformName(), IPlatformHelper.INSTANCE.isDevelopmentEnvironment() ? "development" : "production");
|
||||
ModConstants.LOGGER.info("Diamond Item >> {}", BuiltInRegistries.ITEM.getKey(Items.DIAMOND));
|
||||
}
|
||||
|
||||
// This method serves as a hook to modify item tooltips. The vanilla game
|
||||
// has no mechanism to load tooltip listeners so this must be registered
|
||||
// by a mod loader like Forge or Fabric.
|
||||
public static void onItemTooltip(ItemStack stack, TooltipFlag context, List<Component> tooltip) {
|
||||
if (!stack.isEmpty()) {
|
||||
final FoodProperties food = stack.getItem().getFoodProperties();
|
||||
|
||||
if (food != null) {
|
||||
tooltip.add(Component.literal("Nutrition: " + food.getNutrition()));
|
||||
tooltip.add(Component.literal("Saturation: " + food.getSaturationModifier()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
11
Common/src/main/java/com/author/examplemod/ModConstants.java
Normal file
11
Common/src/main/java/com/author/examplemod/ModConstants.java
Normal file
@@ -0,0 +1,11 @@
|
||||
package com.author.examplemod;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
public class ModConstants {
|
||||
|
||||
public static final String MOD_ID = "examplemod";
|
||||
public static final Logger LOGGER = LogManager.getLogger(MOD_ID);
|
||||
|
||||
}
|
@@ -0,0 +1,18 @@
|
||||
package com.author.examplemod.mixin.client;
|
||||
|
||||
import com.author.examplemod.ModConstants;
|
||||
import net.minecraft.client.gui.screens.TitleScreen;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(TitleScreen.class)
|
||||
public class ExampleMixin {
|
||||
|
||||
@Inject(at = @At("HEAD"), method = "init()V")
|
||||
private void init(CallbackInfo ci) {
|
||||
ModConstants.LOGGER.info("This line is printed by a mixin from Common!");
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,27 @@
|
||||
package com.author.examplemod.platform;
|
||||
|
||||
public interface IPlatformHelper {
|
||||
IPlatformHelper INSTANCE = ImplLoader.load(IPlatformHelper.class);
|
||||
|
||||
/**
|
||||
* Gets the name of the current platform
|
||||
*
|
||||
* @return The name of the current platform.
|
||||
*/
|
||||
String getPlatformName();
|
||||
|
||||
/**
|
||||
* Checks if a mod with the given id is loaded.
|
||||
*
|
||||
* @param modId The mod to check if it is loaded.
|
||||
* @return True if the mod is loaded, false otherwise.
|
||||
*/
|
||||
boolean isModLoaded(String modId);
|
||||
|
||||
/**
|
||||
* Check if the game is currently in a development environment.
|
||||
*
|
||||
* @return True if in a development environment, false otherwise.
|
||||
*/
|
||||
boolean isDevelopmentEnvironment();
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
package com.author.examplemod.platform;
|
||||
|
||||
import java.util.ServiceLoader;
|
||||
|
||||
public class ImplLoader {
|
||||
public static <T> T load(Class<T> clazz) {
|
||||
return ServiceLoader.load(clazz)
|
||||
.findFirst()
|
||||
.orElseThrow(() -> new NullPointerException("Failed to load service for " + clazz.getName()));
|
||||
}
|
||||
}
|
16
Common/src/main/resources/examplemod.mixins.json
Normal file
16
Common/src/main/resources/examplemod.mixins.json
Normal file
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"required": true,
|
||||
"minVersion": "0.8",
|
||||
"package": "com.author.examplemod.mixin",
|
||||
"compatibilityLevel": "JAVA_17",
|
||||
"mixins": [
|
||||
],
|
||||
"client": [
|
||||
"client.ExampleMixin"
|
||||
],
|
||||
"server": [
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
}
|
||||
}
|
6
Common/src/main/resources/pack.mcmeta
Normal file
6
Common/src/main/resources/pack.mcmeta
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"pack": {
|
||||
"description": "${mod_id}",
|
||||
"pack_format": 12
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user