Skip to content

Commit 5313ad6

Browse files
added custom Recipe Providers for datagen and support for local publishing
1 parent 24eb612 commit 5313ad6

File tree

5 files changed

+177
-15
lines changed

5 files changed

+177
-15
lines changed

build.gradle

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,17 @@ nexusPublishing {
9494
connectTimeout = Duration.ofMinutes(3)
9595
clientTimeout = Duration.ofMinutes(3)
9696
}
97+
publishing {
98+
repositories {
99+
maven {
100+
name = "local"
101+
// change URLs to point to your repos, e.g. http://my.org/repo
102+
def releasesRepoUrl = "$buildDir/repos/releases"
103+
def snapshotsRepoUrl = "$buildDir/repos/snapshots"
104+
url = version.endsWith("SNAPSHOT") ? snapshotsRepoUrl : releasesRepoUrl
105+
}
106+
}
107+
}
97108
project.plugins.withType(MavenPublishPlugin).all {
98109
PublishingExtension publishing = project.extensions.getByType(PublishingExtension)
99110
publishing.publications.withType(MavenPublication).all { mavenPublication ->
@@ -122,6 +133,6 @@ project.plugins.withType(MavenPublishPlugin).all {
122133
}
123134
}
124135

125-
exec {
126-
commandLine "echo", "##[set-output name=version;]${project.version}";
127-
}
136+
exec {
137+
commandLine "echo", "##[set-output name=version;]${project.version}";
138+
}

gradle.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ loader_version=0.14.21
1212
#Fabric api
1313
fabric_version=0.82.0+1.19.4
1414
# Mod Properties
15-
mod_version=1.19.4-1.0.1
15+
mod_version=1.19.4-1.3.0
1616
maven_group=io.github.codecraftplugin
1717
archives_base_name=registry-lib
18+

src/main/java/io/github/codecraftplugin/registrylib/RegisteryLib.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
import io.github.codecraftplugin.registrylib.utils.Registry;
44
import net.fabricmc.api.ModInitializer;
55
import net.fabricmc.fabric.api.item.v1.FabricItemSettings;
6-
import net.minecraft.item.Item;
7-
import net.minecraft.item.ItemGroup;
8-
import net.minecraft.item.ItemGroups;
6+
import net.minecraft.item.*;
97
import org.slf4j.Logger;
108
import org.slf4j.LoggerFactory;
119

@@ -15,6 +13,8 @@ public class RegisteryLib implements ModInitializer {
1513
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);
1614
@Override
1715
public void onInitialize() {
18-
Item registeritem = Registry.registerItems("registeritem",MOD_ID,new Item(new FabricItemSettings()), ItemGroups.TOOLS);
16+
Item itemgroupicon = Registry.registerItems("itemgroupicon",MOD_ID,new Item(new FabricItemSettings()), ItemGroups.TOOLS);
17+
ItemGroup testitemgroup = Registry.registerItemGroup("testitemgroup",MOD_ID,()->new ItemStack(itemgroupicon));
18+
Item registeritem = Registry.registerItems("registeritem",MOD_ID,new Item(new FabricItemSettings()), testitemgroup);
1919
}
2020
}

src/main/java/io/github/codecraftplugin/registrylib/utils/Registry.java

Lines changed: 66 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.github.codecraftplugin.registrylib.utils;
22

33
import net.fabricmc.fabric.api.item.v1.FabricItemSettings;
4+
import net.fabricmc.fabric.api.itemgroup.v1.FabricItemGroup;
45
import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents;
56
import net.fabricmc.loader.api.FabricLoader;
67
import net.minecraft.block.Block;
@@ -11,35 +12,76 @@
1112
import net.minecraft.entity.SpawnGroup;
1213
import net.minecraft.entity.effect.StatusEffect;
1314
import net.minecraft.fluid.FlowableFluid;
14-
import net.minecraft.item.BlockItem;
15-
import net.minecraft.item.Item;
16-
import net.minecraft.item.ItemGroup;
17-
import net.minecraft.item.ItemGroups;
15+
import net.minecraft.item.*;
1816
import net.minecraft.registry.Registries;
17+
import net.minecraft.text.Text;
1918
import net.minecraft.util.Identifier;
2019
import org.slf4j.Logger;
2120

22-
23-
public class Registry {
21+
import java.util.function.Supplier;
2422

2523

24+
public class Registry {
25+
/**
26+
* Register items item.
27+
*
28+
* @param name the name of the item
29+
* @param MOD_ID the mod id of your mod
30+
* @param item the item settings
31+
* @param itemGroup the item group
32+
* @return the item will be created and returned
33+
*/
2634
public static Item registerItems(String name, String MOD_ID, Item item, ItemGroup itemGroup){
2735
Item createditem = net.minecraft.registry.Registry.register(Registries.ITEM,new Identifier(MOD_ID,name),item);
2836
addToItemGroup(itemGroup,createditem);
2937
return createditem;
3038
}
39+
/**
40+
* Register items item.
41+
*
42+
* @param name the name of the item
43+
* @param MOD_ID the mod id of your mod
44+
* @param block the block settings
45+
* @return the block and the block item will be created and returned
46+
*/
3147
public static Block registerBlocks(String name, String MOD_ID, Block block, ItemGroup itemGroup){
3248
registerBlockItem(name,MOD_ID,block,itemGroup);
3349
return net.minecraft.registry.Registry.register(Registries.BLOCK,new Identifier(MOD_ID,name),block);
3450
}
51+
52+
/**
53+
*
54+
* @param name the name of the item
55+
* @param MOD_ID the Mod id of your mod
56+
* @param block the reference of the block this item is for
57+
* @param itemGroup the item group that the block item will be shown
58+
* @return the block item without creating the block (for crops)
59+
*/
3560
public static Item registerBlockItem(String name, String MOD_ID, Block block, ItemGroup itemGroup) {
3661
Item blockItem = net.minecraft.registry.Registry.register(Registries.ITEM,new Identifier(MOD_ID,name),
3762
new BlockItem(block,new FabricItemSettings()));
3863
addToItemGroup(itemGroup,blockItem);
3964
return blockItem;
4065
}
66+
67+
/**
68+
*
69+
* @param name the name of the group make sure the name is same the name you want to be displayed in the game
70+
* @param MOD_ID the mod id of your mod
71+
* @param itemStack the item that you want to use as the icon as an item stack e.g. new ItemStack(Items.APPLE);
72+
* @return the item group
73+
*/
74+
public static ItemGroup registerItemGroup(String name, String MOD_ID, Supplier<ItemStack> itemStack){
75+
String formattedName = name.substring(0, 1).toUpperCase() + name.substring(1).toLowerCase();
76+
return FabricItemGroup.builder(new Identifier(MOD_ID,name)).displayName(Text.literal(formattedName)).icon(itemStack).build();
77+
}
4178
//Adds Group to the items created
4279

80+
/**
81+
* Add an item to an item group
82+
* @param group reference of the item Group
83+
* @param item reference of the item
84+
*/
4385
public static void addToItemGroup(ItemGroup group, Item item) {
4486
ItemGroupEvents.modifyEntriesEvent(group).register(entries -> entries.add(item));
4587
}
@@ -56,7 +98,14 @@ public static Block registerBlocksWithoutBlockItem(String name, String MOD_ID, B
5698
return net.minecraft.registry.Registry.register(Registries.BLOCK,new Identifier(MOD_ID,name),block);
5799
}
58100

59-
//register enchantments
101+
/**
102+
* Register enchantments enchantment.
103+
*
104+
* @param name the name of the enchantment
105+
* @param enchantment the enchantment settings
106+
* @param MOD_ID the mod id of your mod
107+
* @return the enchantment
108+
*/
60109
public static Enchantment registerEnchantments(String name, Enchantment enchantment, String MOD_ID){
61110
return net.minecraft.registry.Registry.register(Registries.ENCHANTMENT, new Identifier(MOD_ID, name),enchantment);
62111

@@ -88,10 +137,20 @@ public static EntityType registerEntity(String name,String MOD_ID, EntityType en
88137
return net.minecraft.registry.Registry.register(Registries.ENTITY_TYPE, new Identifier(MOD_ID,name),entity);
89138
}
90139
//register status effects
140+
141+
/**
142+
* Register status effects status effect.
143+
*
144+
* @param name the name of the status effect / potion effect
145+
* @param MOD_ID the mod id of your mod
146+
* @param statusEffect the status effect settings
147+
* @return the status effect
148+
*/
91149
public static StatusEffect registerStatusEffects(String name,String MOD_ID, StatusEffect statusEffect){
92150
return net.minecraft.registry.Registry.register(Registries.STATUS_EFFECT, new Identifier(MOD_ID, name), statusEffect);
93151
}
94152
//register entities with spawn egg
153+
95154
public static <T extends Entity> EntityType<T> buildEntity(EntityType.EntityFactory<T> entity, Class<T> entityClass,
96155
float width, float height, SpawnGroup group, String MOD_ID) {
97156
if (FabricLoader.getInstance().isDevelopmentEnvironment()) {
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
package io.github.codecraftplugin.registrylib.utils;
2+
3+
import net.fabricmc.fabric.api.datagen.v1.provider.FabricRecipeProvider;
4+
import net.minecraft.data.server.recipe.RecipeJsonProvider;
5+
import net.minecraft.data.server.recipe.ShapedRecipeJsonBuilder;
6+
import net.minecraft.item.ItemConvertible;
7+
import net.minecraft.item.Items;
8+
import net.minecraft.recipe.book.RecipeCategory;
9+
10+
import java.util.function.Consumer;
11+
12+
public class RegistryRecipeProvider {
13+
14+
/**
15+
* for making an Axe recipe
16+
* @param exporter the exporter
17+
* @param output the output that is the axe
18+
* @param input the material the axe is made up of (wood, stone, iron, gold, diamond, any modded material)
19+
*/
20+
21+
public static void offerAxeRecipe(Consumer<RecipeJsonProvider> exporter, ItemConvertible output, ItemConvertible input) {
22+
ShapedRecipeJsonBuilder.create(RecipeCategory.TOOLS, output).input(Character.valueOf('#'), input).input('S', Items.STICK)
23+
.pattern("## ")
24+
.pattern("#S ")
25+
.pattern(" S ")
26+
.group("axe")
27+
.criterion(FabricRecipeProvider.hasItem(input),
28+
FabricRecipeProvider.conditionsFromItem(input)).offerTo(exporter);
29+
}
30+
/**
31+
* for making a Pickaxe recipe
32+
* @param exporter the exporter
33+
* @param output the output that is the pickaxe
34+
* @param input the material the pickaxe is made up of (wood, stone, iron, gold, diamond, any modded material)
35+
*/
36+
public static void offerPickaxeRecipe(Consumer<RecipeJsonProvider> exporter, ItemConvertible output, ItemConvertible input) {
37+
ShapedRecipeJsonBuilder.create(RecipeCategory.TOOLS, output).input(Character.valueOf('#'), input).input('S', Items.STICK)
38+
.pattern("###")
39+
.pattern(" S ").pattern(" S ")
40+
.group("pickaxe")
41+
.criterion(FabricRecipeProvider.hasItem(input),
42+
FabricRecipeProvider.conditionsFromItem(input)).offerTo(exporter);
43+
}
44+
/**
45+
* for making a Hoe recipe
46+
* @param exporter the exporter
47+
* @param output the output that is the Hoe
48+
* @param input the material the Hoe is made up of (wood, stone, iron, gold, diamond, any modded material)
49+
*/
50+
51+
public static void offerHoeRecipe(Consumer<RecipeJsonProvider> exporter, ItemConvertible output, ItemConvertible input) {
52+
ShapedRecipeJsonBuilder.create(RecipeCategory.TOOLS, output).input(Character.valueOf('#'), input).input('S', Items.STICK)
53+
.pattern("## ")
54+
.pattern(" S ")
55+
.pattern(" S ")
56+
.group("hoe").criterion(FabricRecipeProvider.hasItem(input),
57+
FabricRecipeProvider.conditionsFromItem(input))
58+
.offerTo(exporter);
59+
}/**
60+
* for making an Shovel recipe
61+
* @param exporter the exporter
62+
* @param output the output that is the Shovel
63+
* @param input the material the Shovel is made up of (wood, stone, iron, gold, diamond, any modded material)
64+
*/
65+
66+
public static void offerShovelRecipe(Consumer<RecipeJsonProvider> exporter, ItemConvertible output, ItemConvertible input) {
67+
ShapedRecipeJsonBuilder.create(RecipeCategory.TOOLS, output).input(Character.valueOf('#'), input).input('S', Items.STICK)
68+
.pattern(" # ")
69+
.pattern(" S ")
70+
.pattern(" S ")
71+
.group("shovel")
72+
.criterion(FabricRecipeProvider.hasItem(input),
73+
FabricRecipeProvider.conditionsFromItem(input))
74+
.offerTo(exporter);
75+
}
76+
/**
77+
* for making a Sword recipe
78+
* @param exporter the exporter
79+
* @param output the output that is the Sword
80+
* @param input the material the Sword is made up of (wood, stone, iron, gold, diamond, any modded material)
81+
*/
82+
public static void offerSwordRecipe(Consumer<RecipeJsonProvider> exporter, ItemConvertible output, ItemConvertible input) {
83+
ShapedRecipeJsonBuilder.create(RecipeCategory.TOOLS, output).input(Character.valueOf('#'), input).input('S', Items.STICK)
84+
.pattern(" # ")
85+
.pattern(" # ")
86+
.pattern(" S ")
87+
.criterion(FabricRecipeProvider.hasItem(input),
88+
FabricRecipeProvider.conditionsFromItem(input))
89+
.group("sword").offerTo(exporter);
90+
}
91+
}

0 commit comments

Comments
 (0)