From 0467d0a5ee28518f0131556b25e53dc67ffdc075 Mon Sep 17 00:00:00 2001 From: Herobane Date: Tue, 10 Oct 2023 21:05:02 +0200 Subject: [PATCH] + Added ruby item --- .../java/net/herobane/learning/Config.java | 63 ------------------ .../java/net/herobane/learning/Learning.java | 38 +++++------ .../net/herobane/learning/item/ModItems.java | 19 ++++++ .../resources/assets/learning/lang/en_us.json | 3 + .../resources/assets/learning/lang/fr_fr.json | 3 + .../assets/learning/models/item/ruby.json | 6 ++ .../assets/learning/textures/item/ruby.png | Bin 0 -> 729 bytes 7 files changed, 48 insertions(+), 84 deletions(-) delete mode 100644 src/main/java/net/herobane/learning/Config.java create mode 100644 src/main/java/net/herobane/learning/item/ModItems.java create mode 100644 src/main/resources/assets/learning/lang/en_us.json create mode 100644 src/main/resources/assets/learning/lang/fr_fr.json create mode 100644 src/main/resources/assets/learning/models/item/ruby.json create mode 100644 src/main/resources/assets/learning/textures/item/ruby.png diff --git a/src/main/java/net/herobane/learning/Config.java b/src/main/java/net/herobane/learning/Config.java deleted file mode 100644 index 7209c6d..0000000 --- a/src/main/java/net/herobane/learning/Config.java +++ /dev/null @@ -1,63 +0,0 @@ -package net.herobane.learning; - -import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.item.Item; -import net.minecraftforge.common.ForgeConfigSpec; -import net.minecraftforge.eventbus.api.SubscribeEvent; -import net.minecraftforge.fml.common.Mod; -import net.minecraftforge.fml.event.config.ModConfigEvent; -import net.minecraftforge.registries.ForgeRegistries; - -import java.util.List; -import java.util.Set; -import java.util.stream.Collectors; - -// 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 -@Mod.EventBusSubscriber(modid = Learning.MODID, bus = Mod.EventBusSubscriber.Bus.MOD) -public class Config -{ - private static final ForgeConfigSpec.Builder BUILDER = new ForgeConfigSpec.Builder(); - - private static final ForgeConfigSpec.BooleanValue LOG_DIRT_BLOCK = BUILDER - .comment("Whether to log the dirt block on common setup") - .define("logDirtBlock", true); - - private static final ForgeConfigSpec.IntValue MAGIC_NUMBER = BUILDER - .comment("A magic number") - .defineInRange("magicNumber", 42, 0, Integer.MAX_VALUE); - - public static final ForgeConfigSpec.ConfigValue MAGIC_NUMBER_INTRODUCTION = BUILDER - .comment("What you want the introduction message to be for the magic number") - .define("magicNumberIntroduction", "The magic number is... "); - - // a list of strings that are treated as resource locations for items - private static final ForgeConfigSpec.ConfigValue> ITEM_STRINGS = BUILDER - .comment("A list of items to log on common setup.") - .defineListAllowEmpty("items", List.of("minecraft:iron_ingot"), Config::validateItemName); - - static final ForgeConfigSpec SPEC = BUILDER.build(); - - public static boolean logDirtBlock; - public static int magicNumber; - public static String magicNumberIntroduction; - public static Set items; - - private static boolean validateItemName(final Object obj) - { - return obj instanceof final String itemName && ForgeRegistries.ITEMS.containsKey(new ResourceLocation(itemName)); - } - - @SubscribeEvent - static void onLoad(final ModConfigEvent event) - { - logDirtBlock = LOG_DIRT_BLOCK.get(); - magicNumber = MAGIC_NUMBER.get(); - magicNumberIntroduction = MAGIC_NUMBER_INTRODUCTION.get(); - - // convert the list of strings into a set of items - items = ITEM_STRINGS.get().stream() - .map(itemName -> ForgeRegistries.ITEMS.getValue(new ResourceLocation(itemName))) - .collect(Collectors.toSet()); - } -} diff --git a/src/main/java/net/herobane/learning/Learning.java b/src/main/java/net/herobane/learning/Learning.java index 6dd66b9..99f20ba 100644 --- a/src/main/java/net/herobane/learning/Learning.java +++ b/src/main/java/net/herobane/learning/Learning.java @@ -1,68 +1,64 @@ package net.herobane.learning; import com.mojang.logging.LogUtils; + +import net.herobane.learning.item.ModItems; +import net.minecraft.world.item.CreativeModeTabs; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.BuildCreativeModeTabContentsEvent; import net.minecraftforge.event.server.ServerStartingEvent; import net.minecraftforge.eventbus.api.IEventBus; import net.minecraftforge.eventbus.api.SubscribeEvent; -import net.minecraftforge.fml.ModLoadingContext; import net.minecraftforge.fml.common.Mod; -import net.minecraftforge.fml.config.ModConfig; import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent; import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; + import org.slf4j.Logger; // The value here should match an entry in the META-INF/mods.toml file @Mod(Learning.MODID) -public class Learning -{ +public class Learning { // Define mod id in a common place for everything to reference public static final String MODID = "learning"; // Directly reference a slf4j logger private static final Logger LOGGER = LogUtils.getLogger(); - public Learning() - { + public Learning() { IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus(); + ModItems.register(modEventBus); modEventBus.addListener(this::commonSetup); MinecraftForge.EVENT_BUS.register(this); modEventBus.addListener(this::addCreative); - ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, Config.SPEC); } - private void commonSetup(final FMLCommonSetupEvent event) - { - + private void commonSetup(final FMLCommonSetupEvent event) { + } - private void addCreative(BuildCreativeModeTabContentsEvent event) - { - + private void addCreative(BuildCreativeModeTabContentsEvent event) { + if (event.getTabKey() == CreativeModeTabs.INGREDIENTS) + event.accept(ModItems.RUBY); } @SubscribeEvent - public void onServerStarting(ServerStartingEvent event) - { + public void onServerStarting(ServerStartingEvent event) { // Do something when the server starts LOGGER.info("Hello from serverside"); } - // You can use EventBusSubscriber to automatically register all static methods in the class annotated with @SubscribeEvent + // You can use EventBusSubscriber to automatically register all static methods + // in the class annotated with @SubscribeEvent @Mod.EventBusSubscriber(modid = MODID, bus = Mod.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 clientside"); } } } - diff --git a/src/main/java/net/herobane/learning/item/ModItems.java b/src/main/java/net/herobane/learning/item/ModItems.java new file mode 100644 index 0000000..4c2490c --- /dev/null +++ b/src/main/java/net/herobane/learning/item/ModItems.java @@ -0,0 +1,19 @@ +package net.herobane.learning.item; + +import net.herobane.learning.Learning; +import net.minecraft.world.item.Item; +import net.minecraftforge.eventbus.api.IEventBus; +import net.minecraftforge.registries.DeferredRegister; +import net.minecraftforge.registries.ForgeRegistries; +import net.minecraftforge.registries.RegistryObject; + +public class ModItems { + + public static final DeferredRegister ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, Learning.MODID); + public static final RegistryObject RUBY = ITEMS.register("ruby", () -> new Item(new Item.Properties())); + + public static void register(IEventBus eventBus) { + ITEMS.register(eventBus); + } + +} diff --git a/src/main/resources/assets/learning/lang/en_us.json b/src/main/resources/assets/learning/lang/en_us.json new file mode 100644 index 0000000..6a68cf5 --- /dev/null +++ b/src/main/resources/assets/learning/lang/en_us.json @@ -0,0 +1,3 @@ +{ + "item.learning.ruby": "Ruby" +} \ No newline at end of file diff --git a/src/main/resources/assets/learning/lang/fr_fr.json b/src/main/resources/assets/learning/lang/fr_fr.json new file mode 100644 index 0000000..30c94b4 --- /dev/null +++ b/src/main/resources/assets/learning/lang/fr_fr.json @@ -0,0 +1,3 @@ +{ + "item.learning.ruby": "Rubis" +} \ No newline at end of file diff --git a/src/main/resources/assets/learning/models/item/ruby.json b/src/main/resources/assets/learning/models/item/ruby.json new file mode 100644 index 0000000..d9a4fa3 --- /dev/null +++ b/src/main/resources/assets/learning/models/item/ruby.json @@ -0,0 +1,6 @@ +{ + "parent": "item/generated", + "textures": { + "layer0": "learning:item/ruby" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/learning/textures/item/ruby.png b/src/main/resources/assets/learning/textures/item/ruby.png new file mode 100644 index 0000000000000000000000000000000000000000..dcbe0c5c32778da551e19f38e46a16628c171c64 GIT binary patch literal 729 zcmV;~0w(>5P)EX>4Tx04R}tkv&MmKpe$iQ>9uef_4yb$WWc^q9Tr^ibb$c+6t{Ym|Xe=O&XFE z7e~Rh;NZt%)xpJCR|i)?5c~jfb#YR3krMxx6k5c1aNLh~_a1le0HIlBs@W3*RLwHd ziMW`{uZn?J1ksNngbK2d-P^xs+Wq|iPU>=)v88u}00006VoOIv0RI600RN!9r;`8x010qNS#tmY zE+YT{E+YYWr9XB6000McNliru=L!iD9UKJWk^BGv02y>eSad^gZEa<4bO1wgWnpw> zWFU8GbZ8()Nlj2!fese{006N`L_t(I%VS`m5HMmBbmfxzk4=2{w`Yt54RGa>`oB!v z9?ln0k!N6FU|@K2=OIJX%Yzt(u;6kUOd}z{gjchk5(E=#fGd~O|6SH`2+aYOD2kVf z+hc?eRu^E?%)r3FaOu~33^ANxz_8&sQDK1HfJ^s?P6rrXcys3=12!>i&d2EjbVG1y z#+i^R1oas7*aT5DKmGHSVe#j?#3v+VTc7^f00000 LNkvXXu0mjfgjPVa literal 0 HcmV?d00001