From 7993c82065f55502bbbcf1ac95322231552e47a8 Mon Sep 17 00:00:00 2001 From: CodeCraft <86466022+CodeCraftPlugin@users.noreply.github.com> Date: Mon, 19 Jun 2023 22:16:18 +0530 Subject: [PATCH] successfully updated it to 1.20.1 --- .github/workflows/build.yml | 2 +- gradle.properties | 16 ++++----- .../registrylib/RegisteryLib.java | 7 ++++ .../registrylib/utils/Registry.java | 36 ++++++++++++++----- src/main/resources/fabric.mod.json | 2 +- 5 files changed, 44 insertions(+), 19 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4a0ade0..aeef9b1 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -40,5 +40,5 @@ jobs: game_endpoint: "minecraft" relations: "fabric-api:requiredDependency,modmenu:optionalDependency" token: ${{ secrets.CF_API_TOKEN }} - game_version: "Minecraft 1.19:1.19.4,Java 17,Fabric,Client,Server" + game_versions: "Minecraft 1.20:1.20.1,Java 17,Fabric,Client,Server" project_id: "776484" diff --git a/gradle.properties b/gradle.properties index 4d7a243..b73c4a7 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,16 +3,14 @@ org.gradle.jvmargs=-Xmx1G org.gradle.daemon=false # Fabric Properties # check these on https://fabricmc.net/develop/ - - -minecraft_version=1.19.4 -yarn_mappings=1.19.4+build.2 -loader_version=0.14.21 - -#Fabric api -fabric_version=0.82.0+1.19.4 # Mod Properties -mod_version=1.19.4-1.3.2 +mod_version=1.20.1-1.0.0 maven_group=io.github.codecraftplugin archives_base_name=registry-lib +#Minecraft +minecraft_version=1.20.1 +yarn_mappings=1.20.1+build.2 +loader_version=0.14.21 +#Fabric api +fabric_version=0.83.1+1.20.1 diff --git a/src/main/java/io/github/codecraftplugin/registrylib/RegisteryLib.java b/src/main/java/io/github/codecraftplugin/registrylib/RegisteryLib.java index 50849ea..c627655 100644 --- a/src/main/java/io/github/codecraftplugin/registrylib/RegisteryLib.java +++ b/src/main/java/io/github/codecraftplugin/registrylib/RegisteryLib.java @@ -4,6 +4,9 @@ import net.fabricmc.api.ModInitializer; import net.fabricmc.fabric.api.item.v1.FabricItemSettings; import net.minecraft.item.*; +import net.minecraft.registry.RegistryKey; +import net.minecraft.registry.RegistryKeys; +import net.minecraft.util.Identifier; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -11,7 +14,11 @@ public class RegisteryLib implements ModInitializer { public static final String MOD_ID = "registry"; public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID); + public static final RegistryKey ITEM_GROUP = Registry.registerItemGroup("registry_item_group",MOD_ID,()-> new ItemStack(Items.CANDLE)); + @Override public void onInitialize() { + Item x = Registry.registerItems("test",MOD_ID,new Item(new FabricItemSettings()),ITEM_GROUP); + } } diff --git a/src/main/java/io/github/codecraftplugin/registrylib/utils/Registry.java b/src/main/java/io/github/codecraftplugin/registrylib/utils/Registry.java index fb9b8b6..8c44675 100644 --- a/src/main/java/io/github/codecraftplugin/registrylib/utils/Registry.java +++ b/src/main/java/io/github/codecraftplugin/registrylib/utils/Registry.java @@ -14,6 +14,8 @@ import net.minecraft.fluid.FlowableFluid; import net.minecraft.item.*; import net.minecraft.registry.Registries; +import net.minecraft.registry.RegistryKey; +import net.minecraft.registry.RegistryKeys; import net.minecraft.text.Text; import net.minecraft.util.Identifier; import org.slf4j.Logger; @@ -31,7 +33,7 @@ public class Registry { * @param itemGroup the item group * @return the item will be created and returned */ - public static Item registerItems(String name, String MOD_ID, Item item, ItemGroup itemGroup){ + public static Item registerItems(String name, String MOD_ID, Item item, RegistryKey itemGroup){ Item createditem = net.minecraft.registry.Registry.register(Registries.ITEM,new Identifier(MOD_ID,name),item); addToItemGroup(itemGroup,createditem); return createditem; @@ -44,7 +46,7 @@ public static Item registerItems(String name, String MOD_ID, Item item, ItemGrou * @param block the block settings * @return the block and the block item will be created and returned */ - public static Block registerBlocks(String name, String MOD_ID, Block block, ItemGroup itemGroup){ + public static Block registerBlocks(String name, String MOD_ID, Block block, RegistryKey itemGroup){ registerBlockItem(name,MOD_ID,block,itemGroup); return net.minecraft.registry.Registry.register(Registries.BLOCK,new Identifier(MOD_ID,name),block); } @@ -57,7 +59,7 @@ public static Block registerBlocks(String name, String MOD_ID, Block block, Item * @param itemGroup the item group that the block item will be shown * @return the block item without creating the block (for crops) */ - public static Item registerBlockItem(String name, String MOD_ID, Block block, ItemGroup itemGroup) { + public static Item registerBlockItem(String name, String MOD_ID, Block block, RegistryKey itemGroup) { Item blockItem = net.minecraft.registry.Registry.register(Registries.ITEM,new Identifier(MOD_ID,name), new BlockItem(block,new FabricItemSettings())); addToItemGroup(itemGroup,blockItem); @@ -71,9 +73,13 @@ public static Item registerBlockItem(String name, String MOD_ID, Block block, It * @param itemStack the item that you want to use as the icon as an item stack e.g. new ItemStack(Items.APPLE); * @return the item group */ - public static ItemGroup registerItemGroup(String name, String MOD_ID, Supplier itemStack){ - String formattedName = name.substring(0, 1).toUpperCase() + name.substring(1).toLowerCase(); - return FabricItemGroup.builder(new Identifier(MOD_ID,name)).displayName(Text.literal(formattedName)).icon(itemStack).build(); + public static RegistryKey registerItemGroup(String name, String MOD_ID, Supplier itemStack){ + String displayName = formatString(name); + RegistryKey customItemGroup = RegistryKey.of(RegistryKeys.ITEM_GROUP,new Identifier(MOD_ID,name)); + net.minecraft.registry.Registry.register(Registries.ITEM_GROUP, customItemGroup, FabricItemGroup.builder() + .icon(itemStack).displayName(Text.literal(displayName)).build()); + + return customItemGroup; } //Adds Group to the items created @@ -82,7 +88,7 @@ public static ItemGroup registerItemGroup(String name, String MOD_ID, Supplier group, Item item) { ItemGroupEvents.modifyEntriesEvent(group).register(entries -> entries.add(item)); } /** @@ -175,5 +181,19 @@ public static I registerEgg(I item, Identifier name) { } return null; } - + + private static String formatString(String input) { + String[] words = input.split("_"); + StringBuilder result = new StringBuilder(); + + for (String word : words) { + if (!word.isEmpty()) { + String formattedWord = word.substring(0, 1).toUpperCase() + word.substring(1).toLowerCase(); + result.append(formattedWord).append(" "); + } + } + + return result.toString().trim(); + } + } \ No newline at end of file diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 80ec721..3a31810 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -24,6 +24,6 @@ "depends": { "fabricloader": ">=0.14.8", "fabric": "*", - "minecraft": "1.19.x" + "minecraft": "1.20.x" } }