first commit
This commit is contained in:
29
src/main/java/com/learning/Learning.java
Normal file
29
src/main/java/com/learning/Learning.java
Normal file
@@ -0,0 +1,29 @@
|
||||
package com.learning;
|
||||
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.learning.item.CustomItem;
|
||||
import com.learning.itemgroup.CustomItemGroup;
|
||||
|
||||
public class Learning implements ModInitializer {
|
||||
public static final String MOD_ID = "learning";
|
||||
|
||||
// This logger is used to write text to the console and the log file.
|
||||
// It is considered best practice to use your mod id as the logger's name.
|
||||
// That way, it's clear which mod wrote info, warnings, and errors.
|
||||
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);
|
||||
|
||||
@Override
|
||||
public void onInitialize() {
|
||||
// This code runs as soon as Minecraft is in a mod-load-ready state.
|
||||
// However, some things (like resources) may still be uninitialized.
|
||||
// Proceed with mild caution.
|
||||
|
||||
LOGGER.info("Hello Fabric world!");
|
||||
CustomItem.registerItems();
|
||||
CustomItemGroup.registerItemGroup();
|
||||
}
|
||||
}
|
11
src/main/java/com/learning/LearningDataGenerator.java
Normal file
11
src/main/java/com/learning/LearningDataGenerator.java
Normal file
@@ -0,0 +1,11 @@
|
||||
package com.learning;
|
||||
|
||||
import net.fabricmc.fabric.api.datagen.v1.DataGeneratorEntrypoint;
|
||||
import net.fabricmc.fabric.api.datagen.v1.FabricDataGenerator;
|
||||
|
||||
public class LearningDataGenerator implements DataGeneratorEntrypoint {
|
||||
@Override
|
||||
public void onInitializeDataGenerator(FabricDataGenerator fabricDataGenerator) {
|
||||
|
||||
}
|
||||
}
|
7
src/main/java/com/learning/component/Foods.java
Normal file
7
src/main/java/com/learning/component/Foods.java
Normal file
@@ -0,0 +1,7 @@
|
||||
package com.learning.component;
|
||||
|
||||
import net.minecraft.component.type.FoodComponent;
|
||||
|
||||
public class Foods {
|
||||
public static FoodComponent toastFood = new FoodComponent.Builder().nutrition(4).build();
|
||||
}
|
40
src/main/java/com/learning/item/CustomItem.java
Normal file
40
src/main/java/com/learning/item/CustomItem.java
Normal file
@@ -0,0 +1,40 @@
|
||||
package com.learning.item;
|
||||
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
import com.learning.Learning;
|
||||
import com.learning.component.Foods;
|
||||
import com.learning.item.Toast;
|
||||
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.registry.Registries;
|
||||
import net.minecraft.registry.Registry;
|
||||
import net.minecraft.registry.RegistryKey;
|
||||
import net.minecraft.registry.RegistryKeys;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.component.type.ConsumableComponents;
|
||||
|
||||
public class CustomItem {
|
||||
public static void registerItems() {
|
||||
Learning.LOGGER.info("Registering Items...");
|
||||
}
|
||||
|
||||
public static Item toast = register("toast", Toast::new, new Item.Settings().food(Foods.toastFood, ConsumableComponents.food().consumeSeconds(0.5f).build()));
|
||||
|
||||
private static Item register(String itemId) {
|
||||
return register(itemId, new Item.Settings());
|
||||
}
|
||||
|
||||
private static Item register(String itemId, Item.Settings settings) {
|
||||
return register(itemId, Item::new, settings);
|
||||
}
|
||||
|
||||
private static Item register(String itemId, Function<Item.Settings, Item> factory, Item.Settings settings) {
|
||||
RegistryKey<Item> key = keyOf(itemId);
|
||||
return Registry.register(Registries.ITEM, key, factory.apply(settings.registryKey(key)));
|
||||
}
|
||||
private static RegistryKey<Item> keyOf(String itemId) {
|
||||
return RegistryKey.of(RegistryKeys.ITEM, Identifier.of(Learning.MOD_ID, itemId));
|
||||
}
|
||||
}
|
28
src/main/java/com/learning/item/Toast.java
Normal file
28
src/main/java/com/learning/item/Toast.java
Normal file
@@ -0,0 +1,28 @@
|
||||
package com.learning.item;
|
||||
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.tooltip.TooltipType;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Formatting;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class Toast extends Item {
|
||||
public Toast(Item.Settings settings) {
|
||||
super(settings);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appendTooltip(ItemStack stack, TooltipContext context, List<Text> tooltip, TooltipType type) {
|
||||
super.appendTooltip(stack, context, tooltip, type);
|
||||
tooltip.add(Text.translatable("toolTip.learning.toast0").formatted(Formatting.GRAY));
|
||||
if (Screen.hasControlDown()) {
|
||||
tooltip.add(Text.translatable("toolTip.learning.toast1"));
|
||||
} else {
|
||||
tooltip.add(Text.translatable("toolTip.learning.hold_control"));
|
||||
}
|
||||
}
|
||||
}
|
39
src/main/java/com/learning/itemgroup/CustomItemGroup.java
Normal file
39
src/main/java/com/learning/itemgroup/CustomItemGroup.java
Normal file
@@ -0,0 +1,39 @@
|
||||
package com.learning.itemgroup;
|
||||
|
||||
|
||||
import com.learning.Learning;
|
||||
import com.learning.item.CustomItem;
|
||||
|
||||
import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents;
|
||||
import net.minecraft.item.ItemGroup;
|
||||
import net.minecraft.item.ItemGroups;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.registry.Registries;
|
||||
import net.minecraft.registry.Registry;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
public class CustomItemGroup {
|
||||
public static void registerItemGroup() {
|
||||
Learning.LOGGER.info("Registering ItemGroup...");
|
||||
Learning.LOGGER.info("Registering item into ItemGroups...");
|
||||
ItemGroupEvents.modifyEntriesEvent(ItemGroups.FOOD_AND_DRINK).register(
|
||||
register -> register.add(CustomItem.toast)
|
||||
);
|
||||
}
|
||||
|
||||
public static ItemGroup customItemGroup = register("custom_itemgroup", ItemGroup.create(null, -1)
|
||||
.icon(() -> new ItemStack(CustomItem.toast))
|
||||
.displayName(Text.translatable("itemGroup.learning.custom_itemgroup"))
|
||||
.entries((displayContext, entries) -> {
|
||||
entries.add(CustomItem.toast);
|
||||
})
|
||||
.build());
|
||||
|
||||
private static ItemGroup register(String groupId, ItemGroup itemGroup) {
|
||||
return Registry.register(
|
||||
Registries.ITEM_GROUP,
|
||||
Identifier.of(Learning.MOD_ID, groupId),
|
||||
itemGroup);
|
||||
}
|
||||
}
|
15
src/main/java/com/learning/mixin/ExampleMixin.java
Normal file
15
src/main/java/com/learning/mixin/ExampleMixin.java
Normal file
@@ -0,0 +1,15 @@
|
||||
package com.learning.mixin;
|
||||
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
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(MinecraftServer.class)
|
||||
public class ExampleMixin {
|
||||
@Inject(at = @At("HEAD"), method = "loadWorld")
|
||||
private void init(CallbackInfo info) {
|
||||
// This code is injected into the start of MinecraftServer.loadWorld()V
|
||||
}
|
||||
}
|
BIN
src/main/resources/assets/learning/icon.png
Normal file
BIN
src/main/resources/assets/learning/icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.4 KiB |
6
src/main/resources/assets/learning/items/toast.json
Normal file
6
src/main/resources/assets/learning/items/toast.json
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"model": {
|
||||
"type": "minecraft:model",
|
||||
"model": "learning:item/toast"
|
||||
}
|
||||
}
|
9
src/main/resources/assets/learning/lang/en_us.json
Normal file
9
src/main/resources/assets/learning/lang/en_us.json
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"item.learning.toast": "Toast",
|
||||
|
||||
"itemGroup.learning.custom_itemgroup": "My Dear...",
|
||||
|
||||
"toolTip.learning.toast0": "A simple fastfood.",
|
||||
"toolTip.learning.toast1": "Will be tastier after baking in the furnace!",
|
||||
"toolTip.learning.hold_control": "Hold §6Control §rto show more information."
|
||||
}
|
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"parent": "item/generated",
|
||||
"textures": {
|
||||
"layer0": "learning:item/toast"
|
||||
}
|
||||
}
|
BIN
src/main/resources/assets/learning/textures/item/toast.png
Normal file
BIN
src/main/resources/assets/learning/textures/item/toast.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 149 B |
37
src/main/resources/fabric.mod.json
Normal file
37
src/main/resources/fabric.mod.json
Normal file
@@ -0,0 +1,37 @@
|
||||
{
|
||||
"schemaVersion": 1,
|
||||
"id": "learning",
|
||||
"version": "${version}",
|
||||
"name": "Learning",
|
||||
"description": "This is an example description! Tell everyone what your mod is about!",
|
||||
"authors": [
|
||||
"Me!"
|
||||
],
|
||||
"contact": {
|
||||
"homepage": "https://fabricmc.net/",
|
||||
"sources": "https://github.com/FabricMC/fabric-example-mod"
|
||||
},
|
||||
"license": "CC0-1.0",
|
||||
"icon": "assets/learning/icon.png",
|
||||
"environment": "*",
|
||||
"entrypoints": {
|
||||
"main": [
|
||||
"com.learning.Learning"
|
||||
],
|
||||
"fabric-datagen": [
|
||||
"com.learning.LearningDataGenerator"
|
||||
]
|
||||
},
|
||||
"mixins": [
|
||||
"learning.mixins.json"
|
||||
],
|
||||
"depends": {
|
||||
"fabricloader": ">=0.16.10",
|
||||
"minecraft": "~1.21.4",
|
||||
"java": ">=21",
|
||||
"fabric-api": "*"
|
||||
},
|
||||
"suggests": {
|
||||
"another-mod": "*"
|
||||
}
|
||||
}
|
11
src/main/resources/learning.mixins.json
Normal file
11
src/main/resources/learning.mixins.json
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"required": true,
|
||||
"package": "com.learning.mixin",
|
||||
"compatibilityLevel": "JAVA_21",
|
||||
"mixins": [
|
||||
"ExampleMixin"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user