From 9b4a3e4b7a5d75c870f0b547cfcd8b6c0c68a1ef Mon Sep 17 00:00:00 2001 From: Jenny Date: Thu, 9 Jan 2025 11:21:41 +0100 Subject: [PATCH] implement DataGen correctly --- .../compressedblocks/CompressedBlocks.java | 18 +---- .../com/jenny/compressedblocks/Tools.java | 4 +- .../datagen/DataGenerators.java | 28 +++++++ .../datagen/ModBlockTagGenerator.java | 76 +++++++++++++++++++ .../{ => datagen}/ModItemModelProvider.java | 4 +- .../datagen/ModItemTagGenerator.java | 24 ++++++ .../models/item/ultra_pickaxe.json | 6 -- .../minecraft/tags/blocks/mineable/axe.json | 5 -- .../minecraft/tags/blocks/mineable/hoe.json | 5 -- .../tags/blocks/mineable/pickaxe.json | 21 ----- .../tags/blocks/mineable/shovel.json | 5 -- .../tags/blocks/needs_diamond_tool.json | 9 --- .../tags/blocks/needs_iron_tool.json | 12 --- .../tags/blocks/needs_stone_tool.json | 8 -- 14 files changed, 133 insertions(+), 92 deletions(-) create mode 100644 src/main/java/com/jenny/compressedblocks/datagen/DataGenerators.java create mode 100644 src/main/java/com/jenny/compressedblocks/datagen/ModBlockTagGenerator.java rename src/main/java/com/jenny/compressedblocks/{ => datagen}/ModItemModelProvider.java (96%) create mode 100644 src/main/java/com/jenny/compressedblocks/datagen/ModItemTagGenerator.java delete mode 100644 src/main/resources/assets/compressedblocks/models/item/ultra_pickaxe.json delete mode 100755 src/main/resources/data/minecraft/tags/blocks/mineable/axe.json delete mode 100755 src/main/resources/data/minecraft/tags/blocks/mineable/hoe.json delete mode 100755 src/main/resources/data/minecraft/tags/blocks/mineable/pickaxe.json delete mode 100755 src/main/resources/data/minecraft/tags/blocks/mineable/shovel.json delete mode 100755 src/main/resources/data/minecraft/tags/blocks/needs_diamond_tool.json delete mode 100755 src/main/resources/data/minecraft/tags/blocks/needs_iron_tool.json delete mode 100755 src/main/resources/data/minecraft/tags/blocks/needs_stone_tool.json diff --git a/src/main/java/com/jenny/compressedblocks/CompressedBlocks.java b/src/main/java/com/jenny/compressedblocks/CompressedBlocks.java index a3363f5..88bb72e 100755 --- a/src/main/java/com/jenny/compressedblocks/CompressedBlocks.java +++ b/src/main/java/com/jenny/compressedblocks/CompressedBlocks.java @@ -1,21 +1,13 @@ package com.jenny.compressedblocks; - -import com.jenny.compressedblocks.Tools; import com.mojang.logging.LogUtils; import net.minecraft.client.Minecraft; -import net.minecraft.client.resources.model.Material; import net.minecraft.core.registries.Registries; import net.minecraft.network.chat.Component; -import net.minecraft.world.flag.FeatureFlag; -import net.minecraft.world.flag.FeatureFlagSet; -import net.minecraft.world.flag.FeatureFlags; import net.minecraft.world.item.*; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.block.IronBarsBlock; import net.minecraft.world.level.block.state.BlockBehaviour; -import net.minecraft.world.level.block.state.properties.NoteBlockInstrument; import net.minecraft.world.level.material.MapColor; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.common.MinecraftForge; @@ -140,21 +132,13 @@ public class CompressedBlocks { IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus(); - // Register the commonSetup method for modloading modEventBus.addListener(this::commonSetup); - - // Register the Deferred Register to the mod event bus so blocks get registered BLOCKS.register(modEventBus); - // Register the Deferred Register to the mod event bus so items get registered ITEMS.register(modEventBus); Tools.register(modEventBus); - // Register the Deferred Register to the mod event bus so tabs get registered + CREATIVE_MODE_TABS.register(modEventBus); - - // Register ourselves for server and other game events we are interested in MinecraftForge.EVENT_BUS.register(this); - - // Register our mod's ForgeConfigSpec so that Forge can create and load the config file for us ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, Config.SPEC); } diff --git a/src/main/java/com/jenny/compressedblocks/Tools.java b/src/main/java/com/jenny/compressedblocks/Tools.java index 406667c..e4c7f99 100644 --- a/src/main/java/com/jenny/compressedblocks/Tools.java +++ b/src/main/java/com/jenny/compressedblocks/Tools.java @@ -1,8 +1,6 @@ package com.jenny.compressedblocks; -import com.jenny.compressedblocks.ToolTiers; import net.minecraft.world.item.*; -import net.minecraftforge.common.ForgeSpawnEggItem; import net.minecraftforge.eventbus.api.IEventBus; import net.minecraftforge.registries.DeferredRegister; import net.minecraftforge.registries.ForgeRegistries; @@ -16,5 +14,5 @@ public class Tools { - public static void register(IEventBus eventBus) {TOOLS.register(eventBus);}; + public static void register(IEventBus eventBus) {TOOLS.register(eventBus);} } diff --git a/src/main/java/com/jenny/compressedblocks/datagen/DataGenerators.java b/src/main/java/com/jenny/compressedblocks/datagen/DataGenerators.java new file mode 100644 index 0000000..fbba382 --- /dev/null +++ b/src/main/java/com/jenny/compressedblocks/datagen/DataGenerators.java @@ -0,0 +1,28 @@ +package com.jenny.compressedblocks.datagen; + +import com.jenny.compressedblocks.CompressedBlocks; +import net.minecraft.core.HolderLookup; +import net.minecraft.data.DataGenerator; +import net.minecraft.data.PackOutput; +import net.minecraftforge.common.data.ExistingFileHelper; +import net.minecraftforge.data.event.GatherDataEvent; +import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.minecraftforge.fml.common.Mod; +import org.jetbrains.annotations.NotNull; +import java.util.concurrent.CompletableFuture; + +@Mod.EventBusSubscriber(modid = CompressedBlocks.MODID, bus = Mod.EventBusSubscriber.Bus.MOD) +public class DataGenerators { + @SubscribeEvent + public static void gatherData(@NotNull GatherDataEvent event) { + DataGenerator generator = event.getGenerator(); + PackOutput packOutput = generator.getPackOutput(); + ExistingFileHelper existingFileHelper = event.getExistingFileHelper(); + CompletableFuture lookupProvider = event.getLookupProvider(); + + generator.addProvider(event.includeClient(), new ModItemModelProvider(packOutput, existingFileHelper)); + ModBlockTagGenerator blockTagGenerator = generator.addProvider(event.includeServer(), + new ModBlockTagGenerator(packOutput, lookupProvider, existingFileHelper)); + generator.addProvider(event.includeServer(), new ModItemTagGenerator(packOutput, lookupProvider, blockTagGenerator.contentsGetter(), existingFileHelper)); + } +} \ No newline at end of file diff --git a/src/main/java/com/jenny/compressedblocks/datagen/ModBlockTagGenerator.java b/src/main/java/com/jenny/compressedblocks/datagen/ModBlockTagGenerator.java new file mode 100644 index 0000000..def7360 --- /dev/null +++ b/src/main/java/com/jenny/compressedblocks/datagen/ModBlockTagGenerator.java @@ -0,0 +1,76 @@ +package com.jenny.compressedblocks.datagen; + +import com.jenny.compressedblocks.CompressedBlocks; +import net.minecraft.core.HolderLookup; +import net.minecraft.data.PackOutput; +import net.minecraft.tags.BlockTags; +import net.minecraftforge.common.data.BlockTagsProvider; +import net.minecraftforge.common.data.ExistingFileHelper; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.concurrent.CompletableFuture; + +public class ModBlockTagGenerator extends BlockTagsProvider { + public ModBlockTagGenerator(PackOutput output, CompletableFuture lookupProvider, @Nullable ExistingFileHelper existingFileHelper) { + super(output, lookupProvider, CompressedBlocks.MODID, existingFileHelper); + } + + @Override + protected void addTags(@NotNull HolderLookup.Provider pProvider) { + this.tag(BlockTags.MINEABLE_WITH_PICKAXE) + .add( + CompressedBlocks.COBBLESTONE_1X.get(), + CompressedBlocks.COBBLESTONE_2X.get(), + CompressedBlocks.COBBLESTONE_3X.get(), + CompressedBlocks.COBBLESTONE_4X.get(), + + CompressedBlocks.ANDESITE_1X.get(), + CompressedBlocks.ANDESITE_2X.get(), + CompressedBlocks.ANDESITE_3X.get(), + CompressedBlocks.ANDESITE_4X.get(), + + CompressedBlocks.DIORITE_1X.get(), + CompressedBlocks.DIORITE_2X.get(), + CompressedBlocks.DIORITE_3X.get(), + CompressedBlocks.DIORITE_4X.get(), + + CompressedBlocks.GRANITE_1X.get(), + CompressedBlocks.GRANITE_2X.get(), + CompressedBlocks.GRANITE_3X.get(), + CompressedBlocks.GRANITE_4X.get(), + + CompressedBlocks.CBLOCK_MINING.get() + ); + + this.tag(BlockTags.NEEDS_STONE_TOOL) + .add( + CompressedBlocks.COBBLESTONE_1X.get(), + CompressedBlocks.ANDESITE_1X.get(), + CompressedBlocks.DIORITE_1X.get(), + CompressedBlocks.GRANITE_1X.get() + ); + + this.tag(BlockTags.NEEDS_IRON_TOOL) + .add( + CompressedBlocks.COBBLESTONE_2X.get(), + CompressedBlocks.ANDESITE_2X.get(), + CompressedBlocks.DIORITE_2X.get(), + CompressedBlocks.GRANITE_2X.get(), + + CompressedBlocks.COBBLESTONE_3X.get(), + CompressedBlocks.ANDESITE_3X.get(), + CompressedBlocks.DIORITE_3X.get(), + CompressedBlocks.GRANITE_3X.get() + ); + + this.tag(BlockTags.NEEDS_DIAMOND_TOOL) + .add( + CompressedBlocks.COBBLESTONE_4X.get(), + CompressedBlocks.ANDESITE_4X.get(), + CompressedBlocks.DIORITE_4X.get(), + CompressedBlocks.GRANITE_4X.get(), + CompressedBlocks.CBLOCK_MINING.get() + ); + } +} \ No newline at end of file diff --git a/src/main/java/com/jenny/compressedblocks/ModItemModelProvider.java b/src/main/java/com/jenny/compressedblocks/datagen/ModItemModelProvider.java similarity index 96% rename from src/main/java/com/jenny/compressedblocks/ModItemModelProvider.java rename to src/main/java/com/jenny/compressedblocks/datagen/ModItemModelProvider.java index 5d926f3..faadef1 100644 --- a/src/main/java/com/jenny/compressedblocks/ModItemModelProvider.java +++ b/src/main/java/com/jenny/compressedblocks/datagen/ModItemModelProvider.java @@ -1,5 +1,7 @@ -package com.jenny.compressedblocks; +package com.jenny.compressedblocks.datagen; +import com.jenny.compressedblocks.CompressedBlocks; +import com.jenny.compressedblocks.Tools; import net.minecraft.data.PackOutput; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.Item; diff --git a/src/main/java/com/jenny/compressedblocks/datagen/ModItemTagGenerator.java b/src/main/java/com/jenny/compressedblocks/datagen/ModItemTagGenerator.java new file mode 100644 index 0000000..b381900 --- /dev/null +++ b/src/main/java/com/jenny/compressedblocks/datagen/ModItemTagGenerator.java @@ -0,0 +1,24 @@ +package com.jenny.compressedblocks.datagen; + +import com.jenny.compressedblocks.CompressedBlocks; +import net.minecraft.core.HolderLookup; +import net.minecraft.data.PackOutput; +import net.minecraft.data.tags.ItemTagsProvider; +import net.minecraft.world.level.block.Block; +import net.minecraftforge.common.data.ExistingFileHelper; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.concurrent.CompletableFuture; + +public class ModItemTagGenerator extends ItemTagsProvider { + public ModItemTagGenerator(PackOutput p_275343_, CompletableFuture p_275729_, + CompletableFuture> p_275322_, @Nullable ExistingFileHelper existingFileHelper) { + super(p_275343_, p_275729_, p_275322_, CompressedBlocks.MODID, existingFileHelper); + } + + @Override + protected void addTags(@NotNull HolderLookup.Provider pProvider) { + + } +} \ No newline at end of file diff --git a/src/main/resources/assets/compressedblocks/models/item/ultra_pickaxe.json b/src/main/resources/assets/compressedblocks/models/item/ultra_pickaxe.json deleted file mode 100644 index 6474693..0000000 --- a/src/main/resources/assets/compressedblocks/models/item/ultra_pickaxe.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "parent": "minecraft:item/handheld", - "textures": { - "layer0": "compressedblocks:item/ultra_pickaxe" - } -} \ No newline at end of file diff --git a/src/main/resources/data/minecraft/tags/blocks/mineable/axe.json b/src/main/resources/data/minecraft/tags/blocks/mineable/axe.json deleted file mode 100755 index 34ca73b..0000000 --- a/src/main/resources/data/minecraft/tags/blocks/mineable/axe.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "values": [ - - ] -} \ No newline at end of file diff --git a/src/main/resources/data/minecraft/tags/blocks/mineable/hoe.json b/src/main/resources/data/minecraft/tags/blocks/mineable/hoe.json deleted file mode 100755 index 34ca73b..0000000 --- a/src/main/resources/data/minecraft/tags/blocks/mineable/hoe.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "values": [ - - ] -} \ No newline at end of file diff --git a/src/main/resources/data/minecraft/tags/blocks/mineable/pickaxe.json b/src/main/resources/data/minecraft/tags/blocks/mineable/pickaxe.json deleted file mode 100755 index 8824062..0000000 --- a/src/main/resources/data/minecraft/tags/blocks/mineable/pickaxe.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "values": [ - "compressedblocks:cobblestone_1x", - "compressedblocks:cobblestone_2x", - "compressedblocks:cobblestone_3x", - "compressedblocks:cobblestone_4x", - "compressedblocks:andesite_1x", - "compressedblocks:andesite_2x", - "compressedblocks:andesite_3x", - "compressedblocks:andesite_4x", - "compressedblocks:diorite_1x", - "compressedblocks:diorite_2x", - "compressedblocks:diorite_3x", - "compressedblocks:diorite_4x", - "compressedblocks:granite_1x", - "compressedblocks:granite_2x", - "compressedblocks:granite_3x", - "compressedblocks:granite_4x", - "compressedblocks:cblock_mining" - ] -} \ No newline at end of file diff --git a/src/main/resources/data/minecraft/tags/blocks/mineable/shovel.json b/src/main/resources/data/minecraft/tags/blocks/mineable/shovel.json deleted file mode 100755 index 34ca73b..0000000 --- a/src/main/resources/data/minecraft/tags/blocks/mineable/shovel.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "values": [ - - ] -} \ No newline at end of file diff --git a/src/main/resources/data/minecraft/tags/blocks/needs_diamond_tool.json b/src/main/resources/data/minecraft/tags/blocks/needs_diamond_tool.json deleted file mode 100755 index 37c73e0..0000000 --- a/src/main/resources/data/minecraft/tags/blocks/needs_diamond_tool.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "values": [ - "compressedblocks:cobblestone_4x", - "compressedblocks:andesite_4x", - "compressedblocks:diorite_4x", - "compressedblocks:granite_4x", - "compressedblocks:cblock_mining" - ] -} \ No newline at end of file diff --git a/src/main/resources/data/minecraft/tags/blocks/needs_iron_tool.json b/src/main/resources/data/minecraft/tags/blocks/needs_iron_tool.json deleted file mode 100755 index 3bf0075..0000000 --- a/src/main/resources/data/minecraft/tags/blocks/needs_iron_tool.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "values": [ - "compressedblocks:cobblestone_2x", - "compressedblocks:cobblestone_3x", - "compressedblocks:andesite_2x", - "compressedblocks:andesite_3x", - "compressedblocks:diorite_2x", - "compressedblocks:diorite_3x", - "compressedblocks:granite_2x", - "compressedblocks:granite_3x" - ] -} \ No newline at end of file diff --git a/src/main/resources/data/minecraft/tags/blocks/needs_stone_tool.json b/src/main/resources/data/minecraft/tags/blocks/needs_stone_tool.json deleted file mode 100755 index 94a9a8c..0000000 --- a/src/main/resources/data/minecraft/tags/blocks/needs_stone_tool.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "values": [ - "compressedblocks:cobblestone_1x", - "compressedblocks:andesite_1x", - "compressedblocks:diorite_1x", - "compressedblocks:granite_1x" - ] -} \ No newline at end of file