Skip to content

Commit

Permalink
successfully updated it to 1.20.1
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeCraftPlugin committed Jun 19, 2023
1 parent 6bb19eb commit 7993c82
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
16 changes: 7 additions & 9 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,21 @@
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;


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<ItemGroup> 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);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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> itemGroup){
Item createditem = net.minecraft.registry.Registry.register(Registries.ITEM,new Identifier(MOD_ID,name),item);
addToItemGroup(itemGroup,createditem);
return createditem;
Expand All @@ -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> itemGroup){
registerBlockItem(name,MOD_ID,block,itemGroup);
return net.minecraft.registry.Registry.register(Registries.BLOCK,new Identifier(MOD_ID,name),block);
}
Expand All @@ -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> itemGroup) {
Item blockItem = net.minecraft.registry.Registry.register(Registries.ITEM,new Identifier(MOD_ID,name),
new BlockItem(block,new FabricItemSettings()));
addToItemGroup(itemGroup,blockItem);
Expand All @@ -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> 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<ItemGroup> registerItemGroup(String name, String MOD_ID, Supplier<ItemStack> itemStack){
String displayName = formatString(name);
RegistryKey<ItemGroup> 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

Expand All @@ -82,7 +88,7 @@ public static ItemGroup registerItemGroup(String name, String MOD_ID, Supplier<I
* @param group reference of the item Group
* @param item reference of the item
*/
public static void addToItemGroup(ItemGroup group, Item item) {
public static void addToItemGroup(RegistryKey<ItemGroup> group, Item item) {
ItemGroupEvents.modifyEntriesEvent(group).register(entries -> entries.add(item));
}
/**
Expand Down Expand Up @@ -175,5 +181,19 @@ public static <I extends Item> 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();
}

}
2 changes: 1 addition & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@
"depends": {
"fabricloader": ">=0.14.8",
"fabric": "*",
"minecraft": "1.19.x"
"minecraft": "1.20.x"
}
}

0 comments on commit 7993c82

Please sign in to comment.