diff --git a/src/generated/resources/.cache/e0d3d0b8d9c807675613821fa865a35f707cd83f b/src/generated/resources/.cache/e0d3d0b8d9c807675613821fa865a35f707cd83f new file mode 100644 index 0000000..fdae234 --- /dev/null +++ b/src/generated/resources/.cache/e0d3d0b8d9c807675613821fa865a35f707cd83f @@ -0,0 +1,2 @@ +// 1.21 2024-08-13T22:21:22.8027373 Data Maps +3136fc55269a4deb6ec159d30383e6941c2ee6a1 data/lingshi/data_maps/item/cooking_food.json diff --git a/src/generated/resources/data/lingshi/data_maps/item/cooking_food.json b/src/generated/resources/data/lingshi/data_maps/item/cooking_food.json new file mode 100644 index 0000000..4ba6700 --- /dev/null +++ b/src/generated/resources/data/lingshi/data_maps/item/cooking_food.json @@ -0,0 +1,10 @@ +{ + "values": { + "lingshi:rice": { + "time": 15.0 + }, + "minecraft:apple": { + "time": 5.0 + } + } +} \ No newline at end of file diff --git a/src/main/java/mczme/lingshi/common/data/CookingFoodDataGen.java b/src/main/java/mczme/lingshi/common/data/CookingFoodDataGen.java new file mode 100644 index 0000000..f9baac7 --- /dev/null +++ b/src/main/java/mczme/lingshi/common/data/CookingFoodDataGen.java @@ -0,0 +1,41 @@ +package mczme.lingshi.common.data; + +import mczme.lingshi.common.datamap.ingredient.CookingFoodData; +import mczme.lingshi.common.registry.ModItems; +import net.minecraft.core.HolderLookup; +import net.minecraft.data.PackOutput; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.tags.TagKey; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.Items; +import net.neoforged.neoforge.common.data.DataMapProvider; + +import java.util.concurrent.CompletableFuture; +import java.util.function.Supplier; + +import static mczme.lingshi.common.datamap.DataMapTypes.COOKING_FOOD; + +public class CookingFoodDataGen extends DataMapProvider { + + protected CookingFoodDataGen(PackOutput packOutput, CompletableFuture lookupProvider) { + super(packOutput, lookupProvider); + } + + @Override + protected void gather() { + addCookingFood(Items.APPLE,5); + addCookingFood(ModItems.RICE,15); + } + + protected void addCookingFood(Item item , float time){ + builder(COOKING_FOOD).add(ResourceLocation.parse(item.toString()),new CookingFoodData(time),false); + } + + protected void addCookingFood(Supplier item , float time){ + builder(COOKING_FOOD).add(ResourceLocation.parse(item.get().toString()),new CookingFoodData(time),false); + } + + protected void addCookingFood(TagKey tag, float time){ + builder(COOKING_FOOD).add(tag,new CookingFoodData(time),false); + } +} diff --git a/src/main/java/mczme/lingshi/common/data/DataGenerators.java b/src/main/java/mczme/lingshi/common/data/DataGenerators.java index 574a15c..bca72f8 100644 --- a/src/main/java/mczme/lingshi/common/data/DataGenerators.java +++ b/src/main/java/mczme/lingshi/common/data/DataGenerators.java @@ -41,7 +41,7 @@ public static void onGatherData(GatherDataEvent event) { // lang datagen event.getGenerator().addProvider( - event.includeServer(), + event.includeClient(), new ChineseLanguageProvider(output) ); @@ -75,5 +75,11 @@ public static void onGatherData(GatherDataEvent event) { event.includeServer(), new ItemTags(output, lookupProvider, pBlockTags.contentsGetter(), existingFileHelper) ); + +// Cooking Food datagen + event.getGenerator().addProvider( + event.includeServer(), + new CookingFoodDataGen(output, lookupProvider) + ); } } diff --git a/src/main/java/mczme/lingshi/common/datamap/DataMapTypes.java b/src/main/java/mczme/lingshi/common/datamap/DataMapTypes.java new file mode 100644 index 0000000..d821c18 --- /dev/null +++ b/src/main/java/mczme/lingshi/common/datamap/DataMapTypes.java @@ -0,0 +1,16 @@ +package mczme.lingshi.common.datamap; + +import mczme.lingshi.common.datamap.ingredient.CookingFoodData; +import mczme.lingshi.lingshi; +import net.minecraft.core.registries.Registries; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.Item; +import net.neoforged.neoforge.registries.datamaps.DataMapType; + +public class DataMapTypes { + public static final DataMapType COOKING_FOOD = DataMapType.builder( + ResourceLocation.fromNamespaceAndPath(lingshi.MODID, "cooking_food"), + Registries.ITEM, CookingFoodData.CODEC + ).build(); + +} diff --git a/src/main/java/mczme/lingshi/common/datamap/ingredient/CookingFoodData.java b/src/main/java/mczme/lingshi/common/datamap/ingredient/CookingFoodData.java new file mode 100644 index 0000000..e58db0d --- /dev/null +++ b/src/main/java/mczme/lingshi/common/datamap/ingredient/CookingFoodData.java @@ -0,0 +1,20 @@ +package mczme.lingshi.common.datamap.ingredient; + +import com.mojang.serialization.Codec; +import com.mojang.serialization.codecs.RecordCodecBuilder; + + +public record CookingFoodData(float time) { + static float MAX_TIME = 30; + + public CookingFoodData(float time){ + if(time > MAX_TIME) this.time = MAX_TIME; + else if(time < 0) this.time = 0; + else this.time = time; + } + + public static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( + Codec.FLOAT.fieldOf("time").forGetter(CookingFoodData::time) + ).apply(instance, CookingFoodData::new)); + +} diff --git a/src/main/java/mczme/lingshi/common/event/Registry.java b/src/main/java/mczme/lingshi/common/event/Registry.java new file mode 100644 index 0000000..369d738 --- /dev/null +++ b/src/main/java/mczme/lingshi/common/event/Registry.java @@ -0,0 +1,16 @@ +package mczme.lingshi.common.event; + +import mczme.lingshi.lingshi; +import net.neoforged.bus.api.SubscribeEvent; +import net.neoforged.fml.common.EventBusSubscriber; +import net.neoforged.neoforge.registries.datamaps.RegisterDataMapTypesEvent; + +import static mczme.lingshi.common.datamap.DataMapTypes.COOKING_FOOD; + +@EventBusSubscriber(modid = lingshi.MODID, bus = EventBusSubscriber.Bus.MOD) +public class Registry { + @SubscribeEvent + private static void registerDataMapTypes(RegisterDataMapTypesEvent event) { + event.register(COOKING_FOOD); + } +}