From c97bdc9941badd7fcabfcff2d5eaa3bc8d18639d Mon Sep 17 00:00:00 2001 From: manmaed Date: Tue, 1 Oct 2024 22:24:16 +0100 Subject: [PATCH] closes and fixes #7 --- .../e0d3d0b8d9c807675613821fa865a35f707cd83f | 2 ++ .../neoforge/data_maps/item/compostables.json | 11 +++++++ .../java/net/manmaed/cottonly/Cottonly.java | 12 ------- .../datagenerators/CottonDataMaps.java | 33 +++++++++++++++++++ .../CottonlyDataGeneration.java | 1 + 5 files changed, 47 insertions(+), 12 deletions(-) create mode 100644 src/generated/resources/.cache/e0d3d0b8d9c807675613821fa865a35f707cd83f create mode 100644 src/generated/resources/data/neoforge/data_maps/item/compostables.json create mode 100644 src/main/java/net/manmaed/cottonly/datagenerators/CottonDataMaps.java diff --git a/src/generated/resources/.cache/e0d3d0b8d9c807675613821fa865a35f707cd83f b/src/generated/resources/.cache/e0d3d0b8d9c807675613821fa865a35f707cd83f new file mode 100644 index 0000000..f96dd38 --- /dev/null +++ b/src/generated/resources/.cache/e0d3d0b8d9c807675613821fa865a35f707cd83f @@ -0,0 +1,2 @@ +// 1.21 2024-10-01T22:03:29.4033395 Data Maps +cd167d458df01c70b8fdf741124c5cb6ad903930 data/neoforge/data_maps/item/compostables.json diff --git a/src/generated/resources/data/neoforge/data_maps/item/compostables.json b/src/generated/resources/data/neoforge/data_maps/item/compostables.json new file mode 100644 index 0000000..6b4fa60 --- /dev/null +++ b/src/generated/resources/data/neoforge/data_maps/item/compostables.json @@ -0,0 +1,11 @@ +{ + "values": { + "cottonly:cotton_ball": { + "chance": 0.65 + }, + "cottonly:cotton_seeds": { + "can_villager_compost": true, + "chance": 0.3 + } + } +} \ No newline at end of file diff --git a/src/main/java/net/manmaed/cottonly/Cottonly.java b/src/main/java/net/manmaed/cottonly/Cottonly.java index 396838e..1f4525b 100644 --- a/src/main/java/net/manmaed/cottonly/Cottonly.java +++ b/src/main/java/net/manmaed/cottonly/Cottonly.java @@ -9,10 +9,8 @@ import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; -import net.minecraft.world.level.block.ComposterBlock; import net.neoforged.bus.api.IEventBus; import net.neoforged.fml.common.Mod; -import net.neoforged.fml.event.lifecycle.FMLCommonSetupEvent; import net.neoforged.neoforge.registries.DeferredHolder; import net.neoforged.neoforge.registries.DeferredRegister; @@ -49,19 +47,9 @@ public class Cottonly { public Cottonly(IEventBus eventBus) { CItems.ITEMS.register(eventBus); CBlocks.BLOCKS.register(eventBus); - eventBus.addListener(this::init); CLoots.LOOT_MODIFIERS.register(eventBus); CREATIVE_MODE_TABS.register(eventBus); eventBus.addListener(CottonlyClient::doClientStuff); } - - private void init(FMLCommonSetupEvent event) { - registerCompostable(0.65F, CItems.COTTON_SEED.get()); - } - - private static void registerCompostable(float chance, Item itemIn) { - ComposterBlock.COMPOSTABLES.put(itemIn, chance); - } - } diff --git a/src/main/java/net/manmaed/cottonly/datagenerators/CottonDataMaps.java b/src/main/java/net/manmaed/cottonly/datagenerators/CottonDataMaps.java new file mode 100644 index 0000000..a34ab4e --- /dev/null +++ b/src/main/java/net/manmaed/cottonly/datagenerators/CottonDataMaps.java @@ -0,0 +1,33 @@ +package net.manmaed.cottonly.datagenerators; + +import net.manmaed.cottonly.items.CItems; +import net.minecraft.core.HolderLookup; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.data.PackOutput; +import net.neoforged.neoforge.common.data.DataMapProvider; +import net.neoforged.neoforge.registries.datamaps.builtin.Compostable; +import net.neoforged.neoforge.registries.datamaps.builtin.NeoForgeDataMaps; + +import java.util.concurrent.CompletableFuture; + +public class CottonDataMaps extends DataMapProvider { + + public CottonDataMaps(PackOutput packOutput, CompletableFuture lookupProvider) { + super(packOutput, lookupProvider); + } + + @Override + protected void gather() { + builder(NeoForgeDataMaps.COMPOSTABLES) + .add(BuiltInRegistries.ITEM.wrapAsHolder(CItems.COTTON_SEED.get()), new Compostable(0.3F, true), false) + .add(BuiltInRegistries.ITEM.wrapAsHolder(CItems.COTTON_BALL.get()), new Compostable(0.65F), false); + ; + } + + /* how it should look like + "minecraft:wheat_seeds": { + "can_villager_compost": true, + "chance": 0.3 + } + */ +} diff --git a/src/main/java/net/manmaed/cottonly/datagenerators/CottonlyDataGeneration.java b/src/main/java/net/manmaed/cottonly/datagenerators/CottonlyDataGeneration.java index 8094cec..2fa2b6a 100644 --- a/src/main/java/net/manmaed/cottonly/datagenerators/CottonlyDataGeneration.java +++ b/src/main/java/net/manmaed/cottonly/datagenerators/CottonlyDataGeneration.java @@ -29,5 +29,6 @@ public static void gatherData(GatherDataEvent event) { generator.addProvider(true, new CottonLootTables(packOutput, lookupProvider)); generator.addProvider(true, new CottonBlockStateProvider(packOutput, fileHelper)); CottonLanguageProvider.addTranslations(generator); + generator.addProvider(true, new CottonDataMaps(packOutput, lookupProvider)); } }