From 6f526134e3f7ea10133dacf89b03fa703905a566 Mon Sep 17 00:00:00 2001 From: "Daniel (aka. rotgruengelb)" Date: Wed, 3 Jul 2024 14:40:37 +0200 Subject: [PATCH] 1. New Datagen System using DataSettings 2. Homes* -> SoH* 3. Recipe Fixes --- build.gradle | 7 +- .../sweetofhomes/SweetOfHomesClient.java | 14 +- .../client/render/RenderLayerHandler.java | 23 +++ .../sweetofhomes/SweetOfHomes.java | 23 ++- .../sweetofhomes/block/HomesBlocks.java | 134 ------------- .../block/SHomesBlocksCollections.java | 75 ------- .../sweetofhomes/block/SoHBlocks.java | 185 ++++++++++++++++++ .../datagen/ModBlockTagProvider.java | 37 ++-- .../datagen/ModItemTagProvider.java | 28 +-- .../datagen/ModLanguageProvider.java | 39 +--- .../datagen/ModLootTableProvider.java | 18 +- .../datagen/ModModelProvider.java | 49 ++--- .../datagen/ModRecipeProvider.java | 47 ++--- ...taGenerator.java => SoHDataGenerator.java} | 9 +- .../datagen/settings/BlockDataSettings.java | 125 ++++++++++++ .../datagen/settings/DataSettings.java | 54 +++++ .../datagen/settings/ItemDataSettings.java | 120 ++++++++++++ .../datagen/settings/TagDataSettings.java | 24 +++ .../sweetofhomes/item/CopperWrenchItem.java | 4 +- .../sweetofhomes/item/HomesItems.java | 52 ----- .../sweetofhomes/item/SoHItems.java | 46 +++++ .../registry/tag/SoHBlockTags.java | 27 +++ .../registry/tag/SoHItemTags.java | 27 +++ .../sweetofhomes/registry/tag/SoHTags.java | 39 ++++ .../rotgruengelb/sweetofhomes/util/Util.java | 25 +++ .../sweetofhomes/util/tag/HomesTags.java | 19 -- ...{HomesGameRules.java => SoHGameRules.java} | 4 +- .../models/block/template_chair.json | 1 + src/main/resources/fabric.mod.json | 2 +- 29 files changed, 823 insertions(+), 434 deletions(-) create mode 100644 src/client/java/net/rotgruengelb/sweetofhomes/client/render/RenderLayerHandler.java delete mode 100644 src/main/java/net/rotgruengelb/sweetofhomes/block/HomesBlocks.java delete mode 100644 src/main/java/net/rotgruengelb/sweetofhomes/block/SHomesBlocksCollections.java create mode 100644 src/main/java/net/rotgruengelb/sweetofhomes/block/SoHBlocks.java rename src/main/java/net/rotgruengelb/sweetofhomes/datagen/{SweetOfHomesDataGenerator.java => SoHDataGenerator.java} (70%) create mode 100644 src/main/java/net/rotgruengelb/sweetofhomes/datagen/settings/BlockDataSettings.java create mode 100644 src/main/java/net/rotgruengelb/sweetofhomes/datagen/settings/DataSettings.java create mode 100644 src/main/java/net/rotgruengelb/sweetofhomes/datagen/settings/ItemDataSettings.java create mode 100644 src/main/java/net/rotgruengelb/sweetofhomes/datagen/settings/TagDataSettings.java delete mode 100644 src/main/java/net/rotgruengelb/sweetofhomes/item/HomesItems.java create mode 100644 src/main/java/net/rotgruengelb/sweetofhomes/item/SoHItems.java create mode 100644 src/main/java/net/rotgruengelb/sweetofhomes/registry/tag/SoHBlockTags.java create mode 100644 src/main/java/net/rotgruengelb/sweetofhomes/registry/tag/SoHItemTags.java create mode 100644 src/main/java/net/rotgruengelb/sweetofhomes/registry/tag/SoHTags.java create mode 100644 src/main/java/net/rotgruengelb/sweetofhomes/util/Util.java delete mode 100644 src/main/java/net/rotgruengelb/sweetofhomes/util/tag/HomesTags.java rename src/main/java/net/rotgruengelb/sweetofhomes/world/{HomesGameRules.java => SoHGameRules.java} (82%) diff --git a/build.gradle b/build.gradle index aed4a03..7887d0c 100644 --- a/build.gradle +++ b/build.gradle @@ -11,9 +11,8 @@ base { } repositories { - maven { - url "https://maven.rotgruengelb.net/releases" - } + maven { url "https://maven.rotgruengelb.net/releases" } + maven { url "https://maven.terraformersmc.com/" } mavenCentral() } @@ -28,6 +27,8 @@ dependencies { modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" modImplementation(annotationProcessor("net.rotgruengelb:nixienaut:${project.nixienaut_version}")) + + modRuntimeOnly "dev.emi:emi-fabric:1.1.8+1.20.4" } processResources { diff --git a/src/client/java/net/rotgruengelb/sweetofhomes/SweetOfHomesClient.java b/src/client/java/net/rotgruengelb/sweetofhomes/SweetOfHomesClient.java index 447d4b0..ea55636 100644 --- a/src/client/java/net/rotgruengelb/sweetofhomes/SweetOfHomesClient.java +++ b/src/client/java/net/rotgruengelb/sweetofhomes/SweetOfHomesClient.java @@ -1,17 +1,15 @@ package net.rotgruengelb.sweetofhomes; import net.fabricmc.api.ClientModInitializer; -import net.fabricmc.fabric.api.blockrenderlayer.v1.BlockRenderLayerMap; import net.fabricmc.fabric.api.client.rendering.v1.EntityRendererRegistry; -import net.minecraft.client.render.RenderLayer; -import net.rotgruengelb.sweetofhomes.block.SHomesBlocksCollections; -import net.rotgruengelb.sweetofhomes.client.render.entity.ChairEntityRenderer; -import net.rotgruengelb.sweetofhomes.entity.HomesEntities; +import net.rotgruengelb.sweetofhomes.client.render.RenderLayerHandler; +import net.rotgruengelb.sweetofhomes.client.render.entity.SeatEntityRenderer; +import net.rotgruengelb.sweetofhomes.entity.SoHEntities; public class SweetOfHomesClient implements ClientModInitializer { @Override public void onInitializeClient() { - - SHomesBlocksCollections.CHAIR_BOCKS.forEach((block) -> BlockRenderLayerMap.INSTANCE.putBlock(block, RenderLayer.getCutout())); - EntityRendererRegistry.register(HomesEntities.CHAIR_ENTITY, ChairEntityRenderer::new); } + EntityRendererRegistry.register(SoHEntities.CHAIR_ENTITY, SeatEntityRenderer::new); + RenderLayerHandler.handelRenderLayers(); + } } \ No newline at end of file diff --git a/src/client/java/net/rotgruengelb/sweetofhomes/client/render/RenderLayerHandler.java b/src/client/java/net/rotgruengelb/sweetofhomes/client/render/RenderLayerHandler.java new file mode 100644 index 0000000..c8604c3 --- /dev/null +++ b/src/client/java/net/rotgruengelb/sweetofhomes/client/render/RenderLayerHandler.java @@ -0,0 +1,23 @@ +package net.rotgruengelb.sweetofhomes.client.render; + +import net.fabricmc.fabric.api.blockrenderlayer.v1.BlockRenderLayerMap; +import net.minecraft.client.render.RenderLayer; +import net.rotgruengelb.sweetofhomes.datagen.SoHDataGenerator; +import net.rotgruengelb.sweetofhomes.datagen.settings.BlockDataSettings; +import net.rotgruengelb.sweetofhomes.datagen.settings.DataSettings; + +public class RenderLayerHandler { + + public static void handelRenderLayers() { + for (DataSettings dataSettings : SoHDataGenerator.dataSettings) { + if (dataSettings instanceof BlockDataSettings blockDataSettings) { + switch (blockDataSettings.getRenderLayer()) { + case CUTOUT -> + BlockRenderLayerMap.INSTANCE.putBlock(blockDataSettings.getBlock(), RenderLayer.getCutout()); + case TRANSLUCENT -> + BlockRenderLayerMap.INSTANCE.putBlock(blockDataSettings.getBlock(), RenderLayer.getTranslucent()); + } + } + } + } +} diff --git a/src/main/java/net/rotgruengelb/sweetofhomes/SweetOfHomes.java b/src/main/java/net/rotgruengelb/sweetofhomes/SweetOfHomes.java index 26bb489..5855fbb 100644 --- a/src/main/java/net/rotgruengelb/sweetofhomes/SweetOfHomes.java +++ b/src/main/java/net/rotgruengelb/sweetofhomes/SweetOfHomes.java @@ -1,10 +1,12 @@ package net.rotgruengelb.sweetofhomes; import net.fabricmc.api.ModInitializer; -import net.rotgruengelb.sweetofhomes.block.HomesBlocks; -import net.rotgruengelb.sweetofhomes.entity.HomesEntities; -import net.rotgruengelb.sweetofhomes.item.HomesItems; -import net.rotgruengelb.sweetofhomes.world.HomesGameRules; +import net.minecraft.util.Identifier; +import net.rotgruengelb.sweetofhomes.block.SoHBlocks; +import net.rotgruengelb.sweetofhomes.entity.SoHEntities; +import net.rotgruengelb.sweetofhomes.item.SoHItems; +import net.rotgruengelb.sweetofhomes.registry.tag.SoHTags; +import net.rotgruengelb.sweetofhomes.world.SoHGameRules; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -15,9 +17,14 @@ public class SweetOfHomes implements ModInitializer { @Override public void onInitialize() { - HomesBlocks.registerModBlocks(); - HomesItems.registerModItems(); - HomesGameRules.registerModGameRules(); - HomesEntities.registerModEntities(); + SoHBlocks.registerModBlocks(); + SoHItems.registerModItems(); + SoHGameRules.registerModGameRules(); + SoHEntities.registerModEntities(); + SoHTags.registerModTags(); + } + + public static Identifier id(String path) { + return new Identifier(MOD_ID, path); } } \ No newline at end of file diff --git a/src/main/java/net/rotgruengelb/sweetofhomes/block/HomesBlocks.java b/src/main/java/net/rotgruengelb/sweetofhomes/block/HomesBlocks.java deleted file mode 100644 index 3c5ffaa..0000000 --- a/src/main/java/net/rotgruengelb/sweetofhomes/block/HomesBlocks.java +++ /dev/null @@ -1,134 +0,0 @@ -package net.rotgruengelb.sweetofhomes.block; - -import net.fabricmc.fabric.api.item.v1.FabricItemSettings; -import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents; -import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; -import net.minecraft.block.*; -import net.minecraft.item.BlockItem; -import net.minecraft.item.Item; -import net.minecraft.item.ItemGroups; -import net.minecraft.item.Items; -import net.minecraft.registry.Registries; -import net.minecraft.registry.Registry; -import net.minecraft.util.Identifier; -import net.minecraft.util.Pair; -import net.rotgruengelb.sweetofhomes.SweetOfHomes; - -@SuppressWarnings("unused") -public class HomesBlocks { - public static final Block AMETHYST_BRICKS = registerBlock("amethyst_bricks", new Block(FabricBlockSettings.copyOf(Blocks.AMETHYST_BLOCK))); - public static final Block CALCITE_BRICKS = registerBlock("calcite_bricks", new Block(FabricBlockSettings.copyOf(Blocks.CALCITE))); - public static final Block PAPER_WALL = registerBlock("paper_wall", new Block(FabricBlockSettings.copyOf(Blocks.BAMBOO_PLANKS))); - public static final Block COPPER_BLITZ = registerCopperBlitz("copper_blitz", new OxidizableBlock(Oxidizable.OxidationLevel.UNAFFECTED, FabricBlockSettings.copyOf(Blocks.COPPER_BLOCK)), Items.COPPER_BLOCK); - public static final Block EXPOSED_COPPER_BLITZ = registerCopperBlitz("exposed_copper_blitz", new OxidizableBlock(Oxidizable.OxidationLevel.EXPOSED, FabricBlockSettings.copyOf(Blocks.COPPER_BLOCK)), Items.EXPOSED_COPPER); - public static final Block WEATHERED_COPPER_BLITZ = registerCopperBlitz("weathered_copper_blitz", new OxidizableBlock(Oxidizable.OxidationLevel.WEATHERED, FabricBlockSettings.copyOf(Blocks.COPPER_BLOCK)), Items.WEATHERED_COPPER); - public static final Block OXIDIZED_COPPER_BLITZ = registerCopperBlitz("oxidized_copper_blitz", new OxidizableBlock(Oxidizable.OxidationLevel.OXIDIZED, FabricBlockSettings.copyOf(Blocks.COPPER_BLOCK)), Items.OXIDIZED_COPPER); - public static final Block WAXED_COPPER_BLITZ = registerCopperBlitz("waxed_copper_blitz", new Block(FabricBlockSettings.copyOf(Blocks.COPPER_BLOCK)), Items.WAXED_COPPER_BLOCK); - public static final Block WAXED_EXPOSED_COPPER_BLITZ = registerCopperBlitz("waxed_exposed_copper_blitz", new Block(FabricBlockSettings.copyOf(Blocks.COPPER_BLOCK)), Items.WAXED_EXPOSED_COPPER); - public static final Block WAXED_WEATHERED_COPPER_BLITZ = registerCopperBlitz("waxed_weathered_copper_blitz", new Block(FabricBlockSettings.copyOf(Blocks.COPPER_BLOCK)), Items.WAXED_WEATHERED_COPPER); - public static final Block WAXED_OXIDIZED_COPPER_BLITZ = registerCopperBlitz("waxed_oxidized_copper_blitz", new Block(FabricBlockSettings.copyOf(Blocks.COPPER_BLOCK)), Items.WAXED_OXIDIZED_COPPER); - public static final Block COPPER_PANELS = registerCopperPanels("copper_panels", new OxidizableBlock(Oxidizable.OxidationLevel.UNAFFECTED, FabricBlockSettings.copyOf(Blocks.COPPER_BLOCK)), Items.CUT_COPPER_SLAB, Items.COPPER_BLOCK); - public static final Block EXPOSED_COPPER_PANELS = registerCopperPanels("exposed_copper_panels", new OxidizableBlock(Oxidizable.OxidationLevel.EXPOSED, FabricBlockSettings.copyOf(Blocks.COPPER_BLOCK)), Items.EXPOSED_CUT_COPPER_SLAB, Items.EXPOSED_COPPER); - public static final Block WEATHERED_COPPER_PANELS = registerCopperPanels("weathered_copper_panels", new OxidizableBlock(Oxidizable.OxidationLevel.WEATHERED, FabricBlockSettings.copyOf(Blocks.COPPER_BLOCK)), Items.WEATHERED_CUT_COPPER_SLAB, Items.WEATHERED_COPPER); - public static final Block OXIDIZED_COPPER_PANELS = registerCopperPanels("oxidized_copper_panels", new OxidizableBlock(Oxidizable.OxidationLevel.OXIDIZED, FabricBlockSettings.copyOf(Blocks.COPPER_BLOCK)), Items.OXIDIZED_CUT_COPPER_SLAB, Items.OXIDIZED_COPPER); - public static final Block WAXED_COPPER_PANELS = registerCopperPanels("waxed_copper_panels", new Block(FabricBlockSettings.copyOf(Blocks.COPPER_BLOCK)), Items.WAXED_CUT_COPPER_SLAB, Items.WAXED_COPPER_BLOCK); - public static final Block WAXED_EXPOSED_COPPER_PANELS = registerCopperPanels("waxed_exposed_copper_panels", new Block(FabricBlockSettings.copyOf(Blocks.COPPER_BLOCK)), Items.WAXED_EXPOSED_CUT_COPPER_SLAB, Items.WAXED_EXPOSED_COPPER); - public static final Block WAXED_WEATHERED_COPPER_PANELS = registerCopperPanels("waxed_weathered_copper_panels", new Block(FabricBlockSettings.copyOf(Blocks.COPPER_BLOCK)), Items.WAXED_WEATHERED_CUT_COPPER_SLAB, Items.WAXED_WEATHERED_COPPER); - public static final Block WAXED_OXIDIZED_COPPER_PANELS = registerCopperPanels("waxed_oxidized_copper_panels", new Block(FabricBlockSettings.copyOf(Blocks.COPPER_BLOCK)), Items.WAXED_OXIDIZED_CUT_COPPER_SLAB, Items.WAXED_OXIDIZED_COPPER); - public static final Block COPPER_PILLAR = registerCopperPillar("copper_pillar", new OxidizablePillarBlock(Oxidizable.OxidationLevel.UNAFFECTED, FabricBlockSettings.copyOf(Blocks.COPPER_BLOCK)), Items.COPPER_BLOCK); - public static final Block EXPOSED_COPPER_PILLAR = registerCopperPillar("exposed_copper_pillar", new OxidizablePillarBlock(Oxidizable.OxidationLevel.EXPOSED, FabricBlockSettings.copyOf(Blocks.COPPER_BLOCK)), Items.EXPOSED_COPPER); - public static final Block WEATHERED_COPPER_PILLAR = registerCopperPillar("weathered_copper_pillar", new OxidizablePillarBlock(Oxidizable.OxidationLevel.WEATHERED, FabricBlockSettings.copyOf(Blocks.COPPER_BLOCK)), Items.WEATHERED_COPPER); - public static final Block OXIDIZED_COPPER_PILLAR = registerCopperPillar("oxidized_copper_pillar", new OxidizablePillarBlock(Oxidizable.OxidationLevel.OXIDIZED, FabricBlockSettings.copyOf(Blocks.COPPER_BLOCK)), Items.OXIDIZED_COPPER); - public static final Block WAXED_COPPER_PILLAR = registerCopperPillar("waxed_copper_pillar", new PillarBlock(FabricBlockSettings.copyOf(Blocks.COPPER_BLOCK)), Items.WAXED_COPPER_BLOCK); - public static final Block WAXED_EXPOSED_COPPER_PILLAR = registerCopperPillar("waxed_exposed_copper_pillar", new PillarBlock(FabricBlockSettings.copyOf(Blocks.COPPER_BLOCK)), Items.WAXED_EXPOSED_COPPER); - public static final Block WAXED_WEATHERED_COPPER_PILLAR = registerCopperPillar("waxed_weathered_copper_pillar", new PillarBlock(FabricBlockSettings.copyOf(Blocks.COPPER_BLOCK)), Items.WAXED_WEATHERED_COPPER); - public static final Block WAXED_OXIDIZED_COPPER_PILLAR = registerCopperPillar("waxed_oxidized_copper_pillar", new PillarBlock(FabricBlockSettings.copyOf(Blocks.COPPER_BLOCK)), Items.WAXED_OXIDIZED_COPPER); - public static final Block ACACIA_PILLAR = registerWoodPillar("acacia_pillar", new PillarBlock(FabricBlockSettings.copyOf(Blocks.ACACIA_PLANKS)), Items.ACACIA_PLANKS); - public static final Block BIRCH_PILLAR = registerWoodPillar("birch_pillar", new PillarBlock(FabricBlockSettings.copyOf(Blocks.BIRCH_PLANKS)), Items.BIRCH_PLANKS); - public static final Block CRIMSON_PILLAR = registerWoodPillar("crimson_pillar", new PillarBlock(FabricBlockSettings.copyOf(Blocks.CRIMSON_PLANKS)), Items.CRIMSON_PLANKS); - public static final Block DARK_OAK_PILLAR = registerWoodPillar("dark_oak_pillar", new PillarBlock(FabricBlockSettings.copyOf(Blocks.DARK_OAK_PLANKS)), Items.DARK_OAK_PLANKS); - public static final Block JUNGLE_PILLAR = registerWoodPillar("jungle_pillar", new PillarBlock(FabricBlockSettings.copyOf(Blocks.JUNGLE_PLANKS)), Items.JUNGLE_PLANKS); - public static final Block OAK_PILLAR = registerWoodPillar("oak_pillar", new PillarBlock(FabricBlockSettings.copyOf(Blocks.OAK_PLANKS)), Items.OAK_PLANKS); - public static final Block SPRUCE_PILLAR = registerWoodPillar("spruce_pillar", new PillarBlock(FabricBlockSettings.copyOf(Blocks.SPRUCE_PLANKS)), Items.SPRUCE_PLANKS); - public static final Block WARPED_PILLAR = registerWoodPillar("warped_pillar", new PillarBlock(FabricBlockSettings.copyOf(Blocks.WARPED_PLANKS)), Items.WARPED_PLANKS); - public static final Block CHERRY_PILLAR = registerWoodPillar("cherry_pillar", new PillarBlock(FabricBlockSettings.copyOf(Blocks.CHERRY_PLANKS)), Items.CHERRY_PLANKS); - public static final Block MANGROVE_PILLAR = registerWoodPillar("mangrove_pillar", new PillarBlock(FabricBlockSettings.copyOf(Blocks.MANGROVE_PLANKS)), Items.MANGROVE_PLANKS); - public static final Block BAMBOO_PILLAR = registerWoodPillar("bamboo_pillar", new PillarBlock(FabricBlockSettings.copyOf(Blocks.BAMBOO_PLANKS)), Items.BAMBOO_PLANKS); - public static final Block ACACIA_CHAIR = registerChair("acacia_chair", new ChairBlock(chairSettings(Blocks.ACACIA_PLANKS))); - public static final Block BIRCH_CHAIR = registerChair("birch_chair", new ChairBlock(chairSettings(Blocks.BIRCH_PLANKS))); - public static final Block CRIMSON_CHAIR = registerChair("crimson_chair", new ChairBlock(chairSettings(Blocks.CRIMSON_PLANKS))); - public static final Block DARK_OAK_CHAIR = registerChair("dark_oak_chair", new ChairBlock(chairSettings(Blocks.DARK_OAK_PLANKS))); - public static final Block JUNGLE_CHAIR = registerChair("jungle_chair", new ChairBlock(chairSettings(Blocks.JUNGLE_PLANKS))); - public static final Block OAK_CHAIR = registerChair("oak_chair", new ChairBlock(chairSettings(Blocks.OAK_PLANKS))); - public static final Block SPRUCE_CHAIR = registerChair("spruce_chair", new ChairBlock(chairSettings(Blocks.SPRUCE_PLANKS))); - public static final Block WARPED_CHAIR = registerChair("warped_chair", new ChairBlock(chairSettings(Blocks.WARPED_PLANKS))); - public static final Block CHERRY_CHAIR = registerChair("cherry_chair", new ChairBlock(chairSettings(Blocks.CHERRY_PLANKS))); - public static final Block MANGROVE_CHAIR = registerChair("mangrove_chair", new ChairBlock(chairSettings(Blocks.MANGROVE_PLANKS))); - public static final Block BAMBOO_CHAIR = registerChair("bamboo_chair", new ChairBlock(chairSettings(Blocks.BAMBOO_PLANKS))); - - private static Block registerBlockNoItem(String name, Block block) { - return registerBlock(name, block, false); - } - - private static Block registerBlock(String name, Block block, boolean withItem) { - SHomesBlocksCollections.BLOCKS.add(block); - if (withItem) { - registerBlockItem(name, new BlockItem(block, new FabricItemSettings())); - } - return Registry.register(Registries.BLOCK, new Identifier(SweetOfHomes.MOD_ID, name), block); - } - - private static Block registerBlock(String name, Block block) { - return registerBlock(name, block, true); - } - - private static Block registerCopperBlitz(String name, Block block, Item base) { - SHomesBlocksCollections.CRAFTING_GEN.COPPER_BLITZ_CRAFTING.put(block, base); - SHomesBlocksCollections.COPPER_BLOCKS.add(block); - return registerBlock(name, block); - } - - private static Block registerChair(String name, Block block) { - SHomesBlocksCollections.WOOD_BLOCKS.add(block); - SHomesBlocksCollections.CHAIR_BOCKS.add((ChairBlock) block); - return registerBlock(name, block); - } - - private static FabricBlockSettings chairSettings(Block block) { - return FabricBlockSettings.copyOf(block) - .nonOpaque() - .allowsSpawning(Blocks::never) - .solidBlock(Blocks::never) - .suffocates(Blocks::never) - .blockVision(Blocks::never); - } - - private static Block registerCopperPillar(String name, Block block, Item base) { - SHomesBlocksCollections.CRAFTING_GEN.COPPER_PILLAR_CRAFTING.put(block, base); - SHomesBlocksCollections.COPPER_BLOCKS.add(block); - return registerBlock(name, block); - } - - private static Block registerWoodPillar(String name, Block block, Item base) { - SHomesBlocksCollections.addWoodPillar(block, base); - return registerBlock(name, block); - } - - private static Block registerCopperPanels(String name, Block block, Item base, Item cuttingBase) { - SHomesBlocksCollections.CRAFTING_GEN.COPPER_PANELS_CRAFTING.put(block, new Pair<>(base, cuttingBase)); - SHomesBlocksCollections.COPPER_BLOCKS.add(block); - return registerBlock(name, block); - } - - private static void registerBlockItem(String name, BlockItem blockItem) { - BlockItem item = Registry.register(Registries.ITEM, new Identifier(SweetOfHomes.MOD_ID, name), blockItem); - ItemGroupEvents.modifyEntriesEvent(ItemGroups.BUILDING_BLOCKS) - .register(content -> content.add(item)); - } - - public static void registerModBlocks() { - SweetOfHomes.LOGGER.debug("Registering HomesBlocks for " + SweetOfHomes.MOD_ID); - - SHomesBlocksCollections.initializeCollections(); - } -} diff --git a/src/main/java/net/rotgruengelb/sweetofhomes/block/SHomesBlocksCollections.java b/src/main/java/net/rotgruengelb/sweetofhomes/block/SHomesBlocksCollections.java deleted file mode 100644 index 999ba05..0000000 --- a/src/main/java/net/rotgruengelb/sweetofhomes/block/SHomesBlocksCollections.java +++ /dev/null @@ -1,75 +0,0 @@ -package net.rotgruengelb.sweetofhomes.block; - -import net.fabricmc.fabric.api.registry.OxidizableBlocksRegistry; -import net.minecraft.block.Block; -import net.minecraft.item.Item; -import net.minecraft.item.ItemConvertible; -import net.minecraft.util.Pair; - -import java.util.*; - -import static net.rotgruengelb.sweetofhomes.block.HomesBlocks.*; - -public class SHomesBlocksCollections { - public static final List BLOCKS = new ArrayList<>(); - public static final List COPPER_BLOCKS = new ArrayList<>(); - public static final List WOOD_BLOCKS = new ArrayList<>(); - public static final List WOODEN_PILLAR_BLOCKS = new ArrayList<>(); - public static final List CHAIR_BOCKS = new ArrayList<>(); - - private static void copperBlocksHelper(Block unaffected, Block exposed, Block weathered, Block oxidized, Block waxedUnaffected, Block waxedExposed, Block waxedWeathered, Block waxedOxidized) { - OxidizableBlocksRegistry.registerOxidizableBlockPair(unaffected, exposed); - OxidizableBlocksRegistry.registerOxidizableBlockPair(exposed, weathered); - OxidizableBlocksRegistry.registerOxidizableBlockPair(weathered, oxidized); - - OxidizableBlocksRegistry.registerWaxableBlockPair(unaffected, waxedUnaffected); - OxidizableBlocksRegistry.registerWaxableBlockPair(exposed, waxedExposed); - OxidizableBlocksRegistry.registerWaxableBlockPair(weathered, waxedWeathered); - OxidizableBlocksRegistry.registerWaxableBlockPair(oxidized, waxedOxidized); - } - - public static void initializeCollections() { - SHomesBlocksCollections.copperBlocksSimpleModelHelper(COPPER_PANELS, EXPOSED_COPPER_PANELS, WEATHERED_COPPER_PANELS, OXIDIZED_COPPER_PANELS, WAXED_COPPER_PANELS, WAXED_EXPOSED_COPPER_PANELS, WAXED_WEATHERED_COPPER_PANELS, WAXED_OXIDIZED_COPPER_PANELS); - SHomesBlocksCollections.copperBlocksSimpleModelHelper(COPPER_BLITZ, EXPOSED_COPPER_BLITZ, WEATHERED_COPPER_BLITZ, OXIDIZED_COPPER_BLITZ, WAXED_COPPER_BLITZ, WAXED_EXPOSED_COPPER_BLITZ, WAXED_WEATHERED_COPPER_BLITZ, WAXED_OXIDIZED_COPPER_BLITZ); - SHomesBlocksCollections.copperBlocksPillarModelHelper(COPPER_PILLAR, EXPOSED_COPPER_PILLAR, WEATHERED_COPPER_PILLAR, OXIDIZED_COPPER_PILLAR, WAXED_COPPER_PILLAR, WAXED_EXPOSED_COPPER_PILLAR, WAXED_WEATHERED_COPPER_PILLAR, WAXED_OXIDIZED_COPPER_PILLAR); - } - - public static void copperBlocksSimpleModelHelper(Block unaffected, Block exposed, Block weathered, Block oxidized, Block waxedUnaffected, Block waxedExposed, Block waxedWeathered, Block waxedOxidized) { - copperBlocksHelper(unaffected, exposed, weathered, oxidized, waxedUnaffected, waxedExposed, waxedWeathered, waxedOxidized); - - MODEL_GEN.UNWAXED_COPPER_BLOCKS_SIMPLE_MODEL.addAll(Arrays.asList(unaffected, exposed, weathered, oxidized)); - MODEL_GEN.WAXED_COPPER_BLOCKS_SIMPLE_MODEL.addAll(Arrays.asList(waxedUnaffected, waxedExposed, waxedWeathered, waxedOxidized)); - } - - public static void copperBlocksPillarModelHelper(Block unaffected, Block exposed, Block weathered, Block oxidized, Block waxedUnaffected, Block waxedExposed, Block waxedWeathered, Block waxedOxidized) { - copperBlocksHelper(unaffected, exposed, weathered, oxidized, waxedUnaffected, waxedExposed, waxedWeathered, waxedOxidized); - - MODEL_GEN.UNWAXED_COPPER_BLOCKS_PILLAR_MODEL.addAll(Arrays.asList(unaffected, exposed, weathered, oxidized)); - MODEL_GEN.WAXED_COPPER_BLOCKS_PILLAR_MODEL.addAll(Arrays.asList(waxedUnaffected, waxedExposed, waxedWeathered, waxedOxidized)); - } - - public static void addWoodPillar(Block block, Item base) { - WOOD_BLOCKS.add(block); - WOODEN_PILLAR_BLOCKS.add(block); - MODEL_GEN.WOOD_BLOCKS_PILLAR_MODEL.add(block); - CRAFTING_GEN.WOOD_PILLAR_CRAFTING.put(block, base); - } - - public static class MODEL_GEN { - public static final List UNWAXED_COPPER_BLOCKS_SIMPLE_MODEL = new ArrayList<>(); - public static final List WAXED_COPPER_BLOCKS_SIMPLE_MODEL = new ArrayList<>(); - - public static final List UNWAXED_COPPER_BLOCKS_PILLAR_MODEL = new ArrayList<>(); - public static final List WAXED_COPPER_BLOCKS_PILLAR_MODEL = new ArrayList<>(); - - public static final List WOOD_BLOCKS_PILLAR_MODEL = new ArrayList<>(); - } - - public static class CRAFTING_GEN { - public static final Map> COPPER_PANELS_CRAFTING = new HashMap<>(); - public static final Map COPPER_BLITZ_CRAFTING = new HashMap<>(); - public static final Map COPPER_PILLAR_CRAFTING = new HashMap<>(); - - public static final Map WOOD_PILLAR_CRAFTING = new HashMap<>(); - } -} diff --git a/src/main/java/net/rotgruengelb/sweetofhomes/block/SoHBlocks.java b/src/main/java/net/rotgruengelb/sweetofhomes/block/SoHBlocks.java new file mode 100644 index 0000000..286d193 --- /dev/null +++ b/src/main/java/net/rotgruengelb/sweetofhomes/block/SoHBlocks.java @@ -0,0 +1,185 @@ +package net.rotgruengelb.sweetofhomes.block; + +import net.fabricmc.fabric.api.item.v1.FabricItemSettings; +import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents; +import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; +import net.minecraft.block.*; +import net.minecraft.data.client.TexturedModel; +import net.minecraft.item.BlockItem; +import net.minecraft.item.Item; +import net.minecraft.item.ItemGroups; +import net.minecraft.item.Items; +import net.minecraft.recipe.book.RecipeCategory; +import net.minecraft.registry.Registries; +import net.minecraft.registry.Registry; +import net.minecraft.registry.tag.BlockTags; +import net.minecraft.registry.tag.ItemTags; +import net.minecraft.util.Identifier; +import net.rotgruengelb.sweetofhomes.SweetOfHomes; +import net.rotgruengelb.sweetofhomes.datagen.settings.BlockDataSettings; +import net.rotgruengelb.sweetofhomes.item.SoHItems; +import net.rotgruengelb.sweetofhomes.registry.tag.SoHItemTags; + +import static net.minecraft.block.Blocks.*; +import static net.rotgruengelb.sweetofhomes.SweetOfHomes.id; +import static net.rotgruengelb.sweetofhomes.datagen.SoHDataGenerator.dataSettings; +import static net.rotgruengelb.sweetofhomes.util.Util.shouldMarkAsNonFlammable; + +@SuppressWarnings("unused") +public class SoHBlocks { + public static final Block AMETHYST_BRICKS = amethystBricks("amethyst_bricks", new Block(copyOf(AMETHYST_BLOCK))); + public static final Block CALCITE_BRICKS = calciteBricks("calcite_bricks", new Block(copyOf(CALCITE))); + public static final Block PAPER_WALL = paperWall("paper_wall", new Block(copyOf(BAMBOO_PLANKS))); + + public static final Block COPPER_BLITZ = copperBlitz("copper_blitz", new OxidizableBlock(Oxidizable.OxidationLevel.UNAFFECTED, copyOf(COPPER_BLOCK)), Items.COPPER_BLOCK); + public static final Block EXPOSED_COPPER_BLITZ = copperBlitz("exposed_copper_blitz", new OxidizableBlock(Oxidizable.OxidationLevel.EXPOSED, copyOf(COPPER_BLOCK)), Items.EXPOSED_COPPER); + public static final Block WEATHERED_COPPER_BLITZ = copperBlitz("weathered_copper_blitz", new OxidizableBlock(Oxidizable.OxidationLevel.WEATHERED, copyOf(COPPER_BLOCK)), Items.WEATHERED_COPPER); + public static final Block OXIDIZED_COPPER_BLITZ = copperBlitz("oxidized_copper_blitz", new OxidizableBlock(Oxidizable.OxidationLevel.OXIDIZED, copyOf(COPPER_BLOCK)), Items.OXIDIZED_COPPER); + public static final Block WAXED_COPPER_BLITZ = copperBlitz("waxed_copper_blitz", new Block(copyOf(COPPER_BLOCK)), Items.WAXED_COPPER_BLOCK); + public static final Block WAXED_EXPOSED_COPPER_BLITZ = copperBlitz("waxed_exposed_copper_blitz", new Block(copyOf(COPPER_BLOCK)), Items.WAXED_EXPOSED_COPPER); + public static final Block WAXED_WEATHERED_COPPER_BLITZ = copperBlitz("waxed_weathered_copper_blitz", new Block(copyOf(COPPER_BLOCK)), Items.WAXED_WEATHERED_COPPER); + public static final Block WAXED_OXIDIZED_COPPER_BLITZ = copperBlitz("waxed_oxidized_copper_blitz", new Block(copyOf(COPPER_BLOCK)), Items.WAXED_OXIDIZED_COPPER); + + public static final Block COPPER_PANELS = copperPanels("copper_panels", new OxidizableBlock(Oxidizable.OxidationLevel.UNAFFECTED, copyOf(COPPER_BLOCK)), Items.CUT_COPPER_SLAB, Items.COPPER_BLOCK); + public static final Block EXPOSED_COPPER_PANELS = copperPanels("exposed_copper_panels", new OxidizableBlock(Oxidizable.OxidationLevel.EXPOSED, copyOf(COPPER_BLOCK)), Items.EXPOSED_CUT_COPPER_SLAB, Items.EXPOSED_COPPER); + public static final Block WEATHERED_COPPER_PANELS = copperPanels("weathered_copper_panels", new OxidizableBlock(Oxidizable.OxidationLevel.WEATHERED, copyOf(COPPER_BLOCK)), Items.WEATHERED_CUT_COPPER_SLAB, Items.WEATHERED_COPPER); + public static final Block OXIDIZED_COPPER_PANELS = copperPanels("oxidized_copper_panels", new OxidizableBlock(Oxidizable.OxidationLevel.OXIDIZED, copyOf(COPPER_BLOCK)), Items.OXIDIZED_CUT_COPPER_SLAB, Items.OXIDIZED_COPPER); + public static final Block WAXED_COPPER_PANELS = copperPanels("waxed_copper_panels", new Block(copyOf(COPPER_BLOCK)), Items.WAXED_CUT_COPPER_SLAB, Items.WAXED_COPPER_BLOCK); + public static final Block WAXED_EXPOSED_COPPER_PANELS = copperPanels("waxed_exposed_copper_panels", new Block(copyOf(COPPER_BLOCK)), Items.WAXED_EXPOSED_CUT_COPPER_SLAB, Items.WAXED_EXPOSED_COPPER); + public static final Block WAXED_WEATHERED_COPPER_PANELS = copperPanels("waxed_weathered_copper_panels", new Block(copyOf(COPPER_BLOCK)), Items.WAXED_WEATHERED_CUT_COPPER_SLAB, Items.WAXED_WEATHERED_COPPER); + public static final Block WAXED_OXIDIZED_COPPER_PANELS = copperPanels("waxed_oxidized_copper_panels", new Block(copyOf(COPPER_BLOCK)), Items.WAXED_OXIDIZED_CUT_COPPER_SLAB, Items.WAXED_OXIDIZED_COPPER); + + public static final Block COPPER_PILLAR = copperPillar("copper_pillar", new OxidizablePillarBlock(Oxidizable.OxidationLevel.UNAFFECTED, copyOf(COPPER_BLOCK)), Items.COPPER_BLOCK); + public static final Block EXPOSED_COPPER_PILLAR = copperPillar("exposed_copper_pillar", new OxidizablePillarBlock(Oxidizable.OxidationLevel.EXPOSED, copyOf(COPPER_BLOCK)), Items.EXPOSED_COPPER); + public static final Block WEATHERED_COPPER_PILLAR = copperPillar("weathered_copper_pillar", new OxidizablePillarBlock(Oxidizable.OxidationLevel.WEATHERED, copyOf(COPPER_BLOCK)), Items.WEATHERED_COPPER); + public static final Block OXIDIZED_COPPER_PILLAR = copperPillar("oxidized_copper_pillar", new OxidizablePillarBlock(Oxidizable.OxidationLevel.OXIDIZED, copyOf(COPPER_BLOCK)), Items.OXIDIZED_COPPER); + public static final Block WAXED_COPPER_PILLAR = copperPillar("waxed_copper_pillar", new PillarBlock(copyOf(COPPER_BLOCK)), Items.WAXED_COPPER_BLOCK); + public static final Block WAXED_EXPOSED_COPPER_PILLAR = copperPillar("waxed_exposed_copper_pillar", new PillarBlock(copyOf(COPPER_BLOCK)), Items.WAXED_EXPOSED_COPPER); + public static final Block WAXED_WEATHERED_COPPER_PILLAR = copperPillar("waxed_weathered_copper_pillar", new PillarBlock(copyOf(COPPER_BLOCK)), Items.WAXED_WEATHERED_COPPER); + public static final Block WAXED_OXIDIZED_COPPER_PILLAR = copperPillar("waxed_oxidized_copper_pillar", new PillarBlock(copyOf(COPPER_BLOCK)), Items.WAXED_OXIDIZED_COPPER); + + public static final Block ACACIA_PILLAR = woodPillar("acacia_pillar", new PillarBlock(copyOf(ACACIA_PLANKS)), Items.ACACIA_PLANKS); + public static final Block BIRCH_PILLAR = woodPillar("birch_pillar", new PillarBlock(copyOf(BIRCH_PLANKS)), Items.BIRCH_PLANKS); + public static final Block CRIMSON_PILLAR = woodPillar("crimson_pillar", new PillarBlock(copyOf(CRIMSON_PLANKS)), Items.CRIMSON_PLANKS); + public static final Block DARK_OAK_PILLAR = woodPillar("dark_oak_pillar", new PillarBlock(copyOf(DARK_OAK_PLANKS)), Items.DARK_OAK_PLANKS); + public static final Block JUNGLE_PILLAR = woodPillar("jungle_pillar", new PillarBlock(copyOf(JUNGLE_PLANKS)), Items.JUNGLE_PLANKS); + public static final Block OAK_PILLAR = woodPillar("oak_pillar", new PillarBlock(copyOf(OAK_PLANKS)), Items.OAK_PLANKS); + public static final Block SPRUCE_PILLAR = woodPillar("spruce_pillar", new PillarBlock(copyOf(SPRUCE_PLANKS)), Items.SPRUCE_PLANKS); + public static final Block WARPED_PILLAR = woodPillar("warped_pillar", new PillarBlock(copyOf(WARPED_PLANKS)), Items.WARPED_PLANKS); + public static final Block CHERRY_PILLAR = woodPillar("cherry_pillar", new PillarBlock(copyOf(CHERRY_PLANKS)), Items.CHERRY_PLANKS); + public static final Block MANGROVE_PILLAR = woodPillar("mangrove_pillar", new PillarBlock(copyOf(MANGROVE_PLANKS)), Items.MANGROVE_PLANKS); + public static final Block BAMBOO_PILLAR = woodPillar("bamboo_pillar", new PillarBlock(copyOf(BAMBOO_PLANKS)), Items.BAMBOO_PLANKS); + + public static final Block ACACIA_CHAIR = chair("acacia_chair", new ChairBlock(chairSettings(ACACIA_PLANKS))); + public static final Block BIRCH_CHAIR = chair("birch_chair", new ChairBlock(chairSettings(BIRCH_PLANKS))); + public static final Block CRIMSON_CHAIR = chair("crimson_chair", new ChairBlock(chairSettings(CRIMSON_PLANKS))); + public static final Block DARK_OAK_CHAIR = chair("dark_oak_chair", new ChairBlock(chairSettings(DARK_OAK_PLANKS))); + public static final Block JUNGLE_CHAIR = chair("jungle_chair", new ChairBlock(chairSettings(JUNGLE_PLANKS))); + public static final Block OAK_CHAIR = chair("oak_chair", new ChairBlock(chairSettings(OAK_PLANKS))); + public static final Block SPRUCE_CHAIR = chair("spruce_chair", new ChairBlock(chairSettings(SPRUCE_PLANKS))); + public static final Block WARPED_CHAIR = chair("warped_chair", new ChairBlock(chairSettings(WARPED_PLANKS))); + public static final Block CHERRY_CHAIR = chair("cherry_chair", new ChairBlock(chairSettings(CHERRY_PLANKS))); + public static final Block MANGROVE_CHAIR = chair("mangrove_chair", new ChairBlock(chairSettings(MANGROVE_PLANKS))); + public static final Block BAMBOO_CHAIR = chair("bamboo_chair", new ChairBlock(chairSettings(BAMBOO_PLANKS))); + + private static Block block(String name, Block block, boolean withItem) { + if (withItem) { + registerBlockItem(name, new BlockItem(block, new FabricItemSettings())); + } + return Registry.register(Registries.BLOCK, new Identifier(SweetOfHomes.MOD_ID, name), block); + } + + private static Block block(String name, Block block) { + block = block(name, block, true); + return dataSettings(new BlockDataSettings<>(id(name), block)); + } + + private static Block copperBlitz(String name, Block block, Item base) { + block = block(name, block, true); + return dataSettings(new BlockDataSettings<>(id(name), block).itemTags() + .blockTags(BlockTags.NEEDS_STONE_TOOL, BlockTags.PICKAXE_MINEABLE) + .recipe2x2ABBA(RecipeCategory.BUILDING_BLOCKS, SoHItems.COPPER_NUGGET, base, 2) + .recipeStonecutting(RecipeCategory.BUILDING_BLOCKS, base, 4) + .copperHelper()); + } + + private static Block chair(String name, Block block) { + block = block(name, block, true); + return dataSettings(new BlockDataSettings<>(id(name), block).blockTags(BlockTags.AXE_MINEABLE) + .itemTags(SoHItemTags.CHAIRS) + .itemTagsIf(shouldMarkAsNonFlammable(name), ItemTags.NON_FLAMMABLE_WOOD) + .blockModelChair() + .renderLayer(BlockDataSettings.RenderLayerEnum.CUTOUT)); + } + + private static FabricBlockSettings chairSettings(Block block) { + return copyOf(block).nonOpaque() + .allowsSpawning(Blocks::never) + .solidBlock(Blocks::never) + .suffocates(Blocks::never) + .blockVision(Blocks::never); + } + + private static FabricBlockSettings copyOf(Block block) { + return FabricBlockSettings.copyOf(block); + } + + private static Block copperPillar(String name, Block block, Item base) { + block = block(name, block, true); + return dataSettings(new BlockDataSettings<>(id(name), block).blockTags(BlockTags.NEEDS_STONE_TOOL, BlockTags.PICKAXE_MINEABLE) + .blockModelAxisRotated(TexturedModel.CUBE_ALL) + .recipe3x3Pillar(RecipeCategory.BUILDING_BLOCKS, base, SoHItems.COPPER_NUGGET, 4) + .copperHelper()); + } + + private static Block woodPillar(String name, Block block, Item base) { + block = block(name, block, true); + return dataSettings(new BlockDataSettings<>(id(name), block).blockTags(BlockTags.AXE_MINEABLE) + .itemTags(SoHItemTags.WOODEN_PILLARS) + .itemTagsIf(shouldMarkAsNonFlammable(name), ItemTags.NON_FLAMMABLE_WOOD) + .blockModelAxisRotated(TexturedModel.CUBE_ALL) + .recipe3x3Pillar(RecipeCategory.BUILDING_BLOCKS, base, Items.STICK, 4)); + } + + private static Block copperPanels(String name, Block block, Item base, Item cuttingBase) { + block = block(name, block, true); + return dataSettings(new BlockDataSettings<>(id(name), block).blockTags(BlockTags.NEEDS_STONE_TOOL, BlockTags.PICKAXE_MINEABLE) + .recipe2x2Compacting(RecipeCategory.BUILDING_BLOCKS, base, 2) + .recipeStonecutting(RecipeCategory.BUILDING_BLOCKS, cuttingBase, 4) + .copperHelper()); + } + + private static Block amethystBricks(String name, Block block) { + block = block(name, block, true); + return dataSettings(new BlockDataSettings<>(id(name), block).blockTags(BlockTags.CRYSTAL_SOUND_BLOCKS, BlockTags.VIBRATION_RESONATORS) + .recipe2x2ABBA(RecipeCategory.BUILDING_BLOCKS, Items.AMETHYST_SHARD, Items.AMETHYST_BLOCK, 2)); + } + + private static Block calciteBricks(String name, Block block) { + block = block(name, block, true); + return dataSettings(new BlockDataSettings<>(id(name), block).blockTags(BlockTags.PICKAXE_MINEABLE) + .recipe2x2Compacting(RecipeCategory.BUILDING_BLOCKS, Items.CALCITE, 4) + .recipeStonecutting(RecipeCategory.BUILDING_BLOCKS, Items.CALCITE, 4)); + } + + private static Block paperWall(String name, Block block) { + block = block(name, block, true); + return dataSettings(new BlockDataSettings<>(id(name), block).blockTags(BlockTags.AXE_MINEABLE) + .recipe2x2ABBA(RecipeCategory.BUILDING_BLOCKS, Items.STICK, Items.PAPER, 4)); + } + + private static void registerBlockItem(String name, BlockItem blockItem) { + BlockItem item = Registry.register(Registries.ITEM, new Identifier(SweetOfHomes.MOD_ID, name), blockItem); + ItemGroupEvents.modifyEntriesEvent(ItemGroups.BUILDING_BLOCKS) + .register(content -> content.add(item)); + } + + public static void registerModBlocks() { + SweetOfHomes.LOGGER.debug("Registering SoHBlocks for " + SweetOfHomes.MOD_ID); + } + + private static Block dataSettings(BlockDataSettings blockDataSettings) { + dataSettings.add(blockDataSettings); + return blockDataSettings.getBlock(); + } +} diff --git a/src/main/java/net/rotgruengelb/sweetofhomes/datagen/ModBlockTagProvider.java b/src/main/java/net/rotgruengelb/sweetofhomes/datagen/ModBlockTagProvider.java index 2de1ad2..37359d7 100644 --- a/src/main/java/net/rotgruengelb/sweetofhomes/datagen/ModBlockTagProvider.java +++ b/src/main/java/net/rotgruengelb/sweetofhomes/datagen/ModBlockTagProvider.java @@ -2,35 +2,28 @@ import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput; import net.fabricmc.fabric.api.datagen.v1.provider.FabricTagProvider; +import net.minecraft.block.Block; import net.minecraft.registry.RegistryWrapper; -import net.minecraft.registry.tag.BlockTags; -import net.rotgruengelb.sweetofhomes.block.HomesBlocks; -import net.rotgruengelb.sweetofhomes.block.SHomesBlocksCollections; -import net.rotgruengelb.sweetofhomes.util.tag.HomesTags; +import net.rotgruengelb.sweetofhomes.datagen.settings.BlockDataSettings; +import net.rotgruengelb.sweetofhomes.datagen.settings.DataSettings; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.util.concurrent.CompletableFuture; public class ModBlockTagProvider extends FabricTagProvider.BlockTagProvider { - public ModBlockTagProvider(FabricDataOutput output, CompletableFuture registriesFuture) { - super(output, registriesFuture); - } + public static final Logger LOGGER = LoggerFactory.getLogger("sweetofhomes/ModBlockTagProvider"); + + public ModBlockTagProvider(FabricDataOutput output, CompletableFuture registriesFuture) { super(output, registriesFuture); } @Override protected void configure(RegistryWrapper.WrapperLookup arg) { - FabricTagBuilder pickaxe_mineable = getOrCreateTagBuilder(BlockTags.PICKAXE_MINEABLE).add(HomesBlocks.AMETHYST_BRICKS) - .add(HomesBlocks.CALCITE_BRICKS); - - FabricTagBuilder needs_stone_tool = getOrCreateTagBuilder(BlockTags.NEEDS_STONE_TOOL); - - SHomesBlocksCollections.COPPER_BLOCKS.forEach(block -> { - pickaxe_mineable.add(block); - needs_stone_tool.add(block); - }); - SHomesBlocksCollections.WOOD_BLOCKS.forEach(block -> getOrCreateTagBuilder(BlockTags.AXE_MINEABLE).add(block)); - SHomesBlocksCollections.WOODEN_PILLAR_BLOCKS.forEach(block -> getOrCreateTagBuilder(HomesTags.BLOCKS.WOODEN_PILLARS).add(block)); - getOrCreateTagBuilder(BlockTags.AXE_MINEABLE).add(HomesBlocks.PAPER_WALL); - getOrCreateTagBuilder(BlockTags.VIBRATION_RESONATORS).add(HomesBlocks.AMETHYST_BRICKS); - getOrCreateTagBuilder(BlockTags.CRYSTAL_SOUND_BLOCKS).add(HomesBlocks.AMETHYST_BRICKS); - + for (DataSettings dataSettings : SoHDataGenerator.dataSettings) { + if (dataSettings instanceof BlockDataSettings blockDataSettings) { + Block block = blockDataSettings.getBlock(); + blockDataSettings.getBlockTags() + .forEach(tag -> getOrCreateTagBuilder(tag).add(block)); + } + } } } diff --git a/src/main/java/net/rotgruengelb/sweetofhomes/datagen/ModItemTagProvider.java b/src/main/java/net/rotgruengelb/sweetofhomes/datagen/ModItemTagProvider.java index 43d6c1d..a4f1ebd 100644 --- a/src/main/java/net/rotgruengelb/sweetofhomes/datagen/ModItemTagProvider.java +++ b/src/main/java/net/rotgruengelb/sweetofhomes/datagen/ModItemTagProvider.java @@ -2,27 +2,29 @@ import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput; import net.fabricmc.fabric.api.datagen.v1.provider.FabricTagProvider; -import net.fabricmc.fabric.api.tag.convention.v1.ConventionalItemTags; +import net.minecraft.item.Item; import net.minecraft.registry.RegistryWrapper; -import net.minecraft.registry.tag.ItemTags; -import net.rotgruengelb.sweetofhomes.block.HomesBlocks; -import net.rotgruengelb.sweetofhomes.block.SHomesBlocksCollections; -import net.rotgruengelb.sweetofhomes.item.HomesItems; -import net.rotgruengelb.sweetofhomes.util.tag.HomesTags; +import net.rotgruengelb.sweetofhomes.datagen.settings.DataSettings; +import net.rotgruengelb.sweetofhomes.datagen.settings.ItemDataSettings; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.util.concurrent.CompletableFuture; public class ModItemTagProvider extends FabricTagProvider.ItemTagProvider { + public static final Logger LOGGER = LoggerFactory.getLogger("sweetofhomes/ModItemTagProvider"); - public ModItemTagProvider(FabricDataOutput output, CompletableFuture completableFuture) { - super(output, completableFuture); - } + public ModItemTagProvider(FabricDataOutput output, CompletableFuture completableFuture) { super(output, completableFuture); } @Override protected void configure(RegistryWrapper.WrapperLookup arg) { - SHomesBlocksCollections.WOODEN_PILLAR_BLOCKS.forEach(block -> getOrCreateTagBuilder(HomesTags.ITEMS.WOODEN_PILLARS).add(block.asItem())); - getOrCreateTagBuilder(ItemTags.NON_FLAMMABLE_WOOD).add(HomesBlocks.WARPED_PILLAR.asItem()) - .add(HomesBlocks.CRIMSON_PILLAR.asItem()); - getOrCreateTagBuilder(ConventionalItemTags.NUGGETS).add(HomesItems.COPPER_NUGGET); + for (DataSettings dataSettings : SoHDataGenerator.dataSettings) { + if (dataSettings instanceof ItemDataSettings itemDataSettings) { + Item item = itemDataSettings.getItem(); + if (item == null) { continue; } + itemDataSettings.getItemTags() + .forEach(tag -> getOrCreateTagBuilder(tag).add(item)); + } + } } } diff --git a/src/main/java/net/rotgruengelb/sweetofhomes/datagen/ModLanguageProvider.java b/src/main/java/net/rotgruengelb/sweetofhomes/datagen/ModLanguageProvider.java index aec71f1..4da74a2 100644 --- a/src/main/java/net/rotgruengelb/sweetofhomes/datagen/ModLanguageProvider.java +++ b/src/main/java/net/rotgruengelb/sweetofhomes/datagen/ModLanguageProvider.java @@ -2,43 +2,20 @@ import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput; import net.fabricmc.fabric.api.datagen.v1.provider.FabricLanguageProvider; -import net.minecraft.block.Block; -import net.minecraft.item.Item; -import net.minecraft.registry.Registries; -import net.rotgruengelb.sweetofhomes.block.SHomesBlocksCollections; -import net.rotgruengelb.sweetofhomes.item.HomesItems; +import net.rotgruengelb.sweetofhomes.datagen.settings.DataSettings; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class ModLanguageProvider extends FabricLanguageProvider { - protected ModLanguageProvider(FabricDataOutput dataOutput) { - super(dataOutput); - } - - public static String convertSnakeCaseToTitleCase(String snakeCaseText) { - String[] words = snakeCaseText.split("_"); - - StringBuilder titleCaseText = new StringBuilder(); + public static final Logger LOGGER = LoggerFactory.getLogger("sweetofhomes/ModLanguageProvider"); - for (String word : words) { - if (!word.isEmpty()) { - titleCaseText.append(Character.toUpperCase(word.charAt(0))) - .append(word.substring(1) - .toLowerCase()) - .append(" "); - } - } - return titleCaseText.toString() - .trim(); - } + protected ModLanguageProvider(FabricDataOutput dataOutput) { super(dataOutput); } @Override public void generateTranslations(TranslationBuilder translationBuilder) { - for (Block block : SHomesBlocksCollections.BLOCKS) { - translationBuilder.add(block, convertSnakeCaseToTitleCase(Registries.BLOCK.getId(block) - .getPath())); - } - for (Item item : HomesItems.ALL.ITEMS) { - translationBuilder.add(item, convertSnakeCaseToTitleCase(Registries.ITEM.getId(item) - .getPath())); + for (DataSettings dataSettings : SoHDataGenerator.dataSettings) { + if (!dataSettings.shouldTranslate()) { continue; } + translationBuilder.add(dataSettings.getTranslationKey(), dataSettings.getTranslation()); } } } diff --git a/src/main/java/net/rotgruengelb/sweetofhomes/datagen/ModLootTableProvider.java b/src/main/java/net/rotgruengelb/sweetofhomes/datagen/ModLootTableProvider.java index e1d2dce..f0b2ae7 100644 --- a/src/main/java/net/rotgruengelb/sweetofhomes/datagen/ModLootTableProvider.java +++ b/src/main/java/net/rotgruengelb/sweetofhomes/datagen/ModLootTableProvider.java @@ -2,18 +2,22 @@ import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput; import net.fabricmc.fabric.api.datagen.v1.provider.FabricBlockLootTableProvider; -import net.minecraft.block.Block; -import net.rotgruengelb.sweetofhomes.block.SHomesBlocksCollections; +import net.rotgruengelb.sweetofhomes.datagen.settings.BlockDataSettings; +import net.rotgruengelb.sweetofhomes.datagen.settings.DataSettings; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class ModLootTableProvider extends FabricBlockLootTableProvider { - protected ModLootTableProvider(FabricDataOutput dataOutput) { - super(dataOutput); - } + public static final Logger LOGGER = LoggerFactory.getLogger("sweetofhomes/ModLootTableProvider"); + + protected ModLootTableProvider(FabricDataOutput dataOutput) { super(dataOutput); } @Override public void generate() { - for (Block block : SHomesBlocksCollections.BLOCKS) { - addDrop(block); + for (DataSettings dataSettings : SoHDataGenerator.dataSettings) { + if (dataSettings instanceof BlockDataSettings blockDataSettings) { + addDrop(blockDataSettings.getBlock()); + } } } } diff --git a/src/main/java/net/rotgruengelb/sweetofhomes/datagen/ModModelProvider.java b/src/main/java/net/rotgruengelb/sweetofhomes/datagen/ModModelProvider.java index 755eb4d..17f5588 100644 --- a/src/main/java/net/rotgruengelb/sweetofhomes/datagen/ModModelProvider.java +++ b/src/main/java/net/rotgruengelb/sweetofhomes/datagen/ModModelProvider.java @@ -5,20 +5,21 @@ import net.minecraft.block.Block; import net.minecraft.data.client.*; import net.minecraft.util.Identifier; -import net.rotgruengelb.sweetofhomes.block.ChairBlock; -import net.rotgruengelb.sweetofhomes.block.HomesBlocks; -import net.rotgruengelb.sweetofhomes.block.SHomesBlocksCollections; -import net.rotgruengelb.sweetofhomes.item.HomesItems; +import net.rotgruengelb.sweetofhomes.datagen.settings.BlockDataSettings; +import net.rotgruengelb.sweetofhomes.datagen.settings.DataSettings; +import net.rotgruengelb.sweetofhomes.datagen.settings.ItemDataSettings; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.util.Optional; public class ModModelProvider extends FabricModelProvider { + public static final Logger LOGGER = LoggerFactory.getLogger("sweetofhomes/ModLootTableProvider"); + public static final TexturedModel.Factory CUBE_ALL_NO_WAXED = TexturedModel.makeFactory(ModModelProvider::allRemoveWaxed, Models.CUBE_ALL); public static final TexturedModel.Factory TEMPLATE_CHAIR = TexturedModel.makeFactory(TextureMap::texture, MODELS.TEMPLATE_CHAIR); - public ModModelProvider(FabricDataOutput output) { - super(output); - } + public ModModelProvider(FabricDataOutput output) { super(output); } public static TextureMap allRemoveWaxed(Block block) { Identifier identifier = TextureMap.getId(block); @@ -29,39 +30,29 @@ public static TextureMap allRemoveWaxed(Block block) { @Override public void generateBlockStateModels(BlockStateModelGenerator gen) { - gen.registerSimpleCubeAll(HomesBlocks.AMETHYST_BRICKS); - gen.registerSimpleCubeAll(HomesBlocks.CALCITE_BRICKS); - gen.registerSimpleCubeAll(HomesBlocks.PAPER_WALL); - for (int i = 0; i < SHomesBlocksCollections.MODEL_GEN.WAXED_COPPER_BLOCKS_SIMPLE_MODEL.size(); i++) { - gen.registerSimpleCubeAll(SHomesBlocksCollections.MODEL_GEN.UNWAXED_COPPER_BLOCKS_SIMPLE_MODEL.get(i)); - gen.registerParented(SHomesBlocksCollections.MODEL_GEN.UNWAXED_COPPER_BLOCKS_SIMPLE_MODEL.get(i), SHomesBlocksCollections.MODEL_GEN.WAXED_COPPER_BLOCKS_SIMPLE_MODEL.get(i)); + for (DataSettings dataSettings : SoHDataGenerator.dataSettings) { + if (dataSettings instanceof BlockDataSettings blockDataSettings) { + blockDataSettings.getBlockModel().accept(gen); + } } - for (int i = 0; i < SHomesBlocksCollections.MODEL_GEN.WAXED_COPPER_BLOCKS_PILLAR_MODEL.size(); i++) { - gen.registerAxisRotated(SHomesBlocksCollections.MODEL_GEN.UNWAXED_COPPER_BLOCKS_PILLAR_MODEL.get(i), TexturedModel.CUBE_ALL); - gen.registerAxisRotated(SHomesBlocksCollections.MODEL_GEN.WAXED_COPPER_BLOCKS_PILLAR_MODEL.get(i), CUBE_ALL_NO_WAXED); - } - SHomesBlocksCollections.CHAIR_BOCKS.forEach(block -> registerChair(block, gen)); - SHomesBlocksCollections.MODEL_GEN.WOOD_BLOCKS_PILLAR_MODEL.forEach(block -> gen.registerAxisRotated(block, TexturedModel.CUBE_ALL)); - } @Override public void generateItemModels(ItemModelGenerator gen) { - gen.register(HomesItems.COPPER_NUGGET, Models.GENERATED); - gen.register(HomesItems.COPPER_WRENCH, Models.HANDHELD); - } - - public final void registerChair(ChairBlock chair, BlockStateModelGenerator generator) { - Identifier identifier = TEMPLATE_CHAIR.upload(chair, generator.modelCollector); - generator.blockStateCollector.accept(BlockStateModelGenerator.createSingletonBlockState(chair, identifier) - .coordinate(BlockStateModelGenerator.createNorthDefaultHorizontalRotationStates())); + for (DataSettings dataSettings : SoHDataGenerator.dataSettings) { + if (dataSettings instanceof BlockDataSettings) { continue; } + if (dataSettings instanceof ItemDataSettings itemDataSettings) { + itemDataSettings.getItemModel().accept(gen); + } + } } private static class MODELS { public static final Model TEMPLATE_CHAIR = block("template_chair", TextureKey.TEXTURE); private static Model block(String parent, TextureKey... requiredTextureKeys) { - return new Model(Optional.of(new Identifier("sweetofhomes", "block/" + parent)), Optional.empty(), requiredTextureKeys); + return new Model(Optional.of(new Identifier("sweetofhomes", "block/" + parent)), + Optional.empty(), requiredTextureKeys); } } } diff --git a/src/main/java/net/rotgruengelb/sweetofhomes/datagen/ModRecipeProvider.java b/src/main/java/net/rotgruengelb/sweetofhomes/datagen/ModRecipeProvider.java index 9937931..5f4395c 100644 --- a/src/main/java/net/rotgruengelb/sweetofhomes/datagen/ModRecipeProvider.java +++ b/src/main/java/net/rotgruengelb/sweetofhomes/datagen/ModRecipeProvider.java @@ -5,20 +5,18 @@ import net.minecraft.data.server.recipe.RecipeExporter; import net.minecraft.data.server.recipe.RecipeProvider; import net.minecraft.data.server.recipe.ShapedRecipeJsonBuilder; +import net.minecraft.data.server.recipe.ShapelessRecipeJsonBuilder; import net.minecraft.item.ItemConvertible; import net.minecraft.item.Items; import net.minecraft.recipe.book.RecipeCategory; -import net.rotgruengelb.sweetofhomes.block.HomesBlocks; -import net.rotgruengelb.sweetofhomes.block.SHomesBlocksCollections; -import net.rotgruengelb.sweetofhomes.item.HomesItems; +import net.rotgruengelb.sweetofhomes.datagen.settings.ItemDataSettings; public class ModRecipeProvider extends FabricRecipeProvider { - public ModRecipeProvider(FabricDataOutput output) { - super(output); - } + public ModRecipeProvider(FabricDataOutput output) { super(output); } public static void offer2x2ABBARecipe(RecipeExporter exporter, RecipeCategory category, ItemConvertible output, ItemConvertible inputA, ItemConvertible inputB, int count) { ShapedRecipeJsonBuilder.create(category, output, count) + .group(getItemPath(output)) .input('A', inputA) .input('B', inputB) .pattern("AB") @@ -30,6 +28,7 @@ public static void offer2x2ABBARecipe(RecipeExporter exporter, RecipeCategory ca public static void offer3x3PillarRecipe(RecipeExporter exporter, RecipeCategory category, ItemConvertible output, ItemConvertible inputCore, ItemConvertible inputSide, int count) { ShapedRecipeJsonBuilder.create(category, output, count) + .group(getItemPath(output)) .input('S', inputSide) .input('C', inputCore) .pattern("SCS") @@ -42,6 +41,7 @@ public static void offer3x3PillarRecipe(RecipeExporter exporter, RecipeCategory public static void offer2x2CompactingRecipe(RecipeExporter exporter, RecipeCategory category, ItemConvertible output, ItemConvertible input, int count) { ShapedRecipeJsonBuilder.create(category, output, count) + .group(getItemPath(output)) .input('#', input) .pattern("##") .pattern("##") @@ -49,30 +49,23 @@ public static void offer2x2CompactingRecipe(RecipeExporter exporter, RecipeCateg .offerTo(exporter); } + public static void offerWaxingRecipe(RecipeExporter exporter, RecipeCategory category, ItemConvertible waxed, ItemConvertible unwaxed) { + ShapelessRecipeJsonBuilder.create(category, waxed, 1) + .group(getItemPath(waxed)) + .input(unwaxed) + .input(Items.HONEYCOMB) + .criterion(hasItem(unwaxed), conditionsFromItem(unwaxed)) + .offerTo(exporter, convertBetween(waxed, Items.HONEYCOMB)); + } + @Override public void generate(RecipeExporter exporter) { - SHomesBlocksCollections.CRAFTING_GEN.COPPER_BLITZ_CRAFTING.forEach((block, base) -> { - offer2x2ABBARecipe(exporter, RecipeCategory.BUILDING_BLOCKS, block, HomesItems.COPPER_NUGGET, base, 2); - offerStonecuttingRecipe(exporter, RecipeCategory.BUILDING_BLOCKS, block, base, 4); - }); - - SHomesBlocksCollections.CRAFTING_GEN.COPPER_PANELS_CRAFTING.forEach((block, basePair) -> { - offer2x2CompactingRecipe(exporter, RecipeCategory.BUILDING_BLOCKS, block, basePair.getLeft(), 2); - offerStonecuttingRecipe(exporter, RecipeCategory.BUILDING_BLOCKS, block, basePair.getRight(), 4); + SoHDataGenerator.dataSettings.forEach(settings -> { + if (settings instanceof ItemDataSettings itemDataSettings) { + itemDataSettings.getRecipes() + .forEach(recipe -> recipe.accept(exporter)); + } }); - - SHomesBlocksCollections.CRAFTING_GEN.COPPER_PILLAR_CRAFTING.forEach((block, core) -> { - offer3x3PillarRecipe(exporter, RecipeCategory.BUILDING_BLOCKS, block, core, HomesItems.COPPER_NUGGET, 4); - offerStonecuttingRecipe(exporter, RecipeCategory.BUILDING_BLOCKS, block, core, 4); - }); - - SHomesBlocksCollections.CRAFTING_GEN.WOOD_PILLAR_CRAFTING.forEach((block, base) -> offer3x3PillarRecipe(exporter, RecipeCategory.BUILDING_BLOCKS, block, base, Items.STICK, 4)); - - offer2x2ABBARecipe(exporter, RecipeCategory.BUILDING_BLOCKS, HomesBlocks.AMETHYST_BRICKS, Items.AMETHYST_SHARD, Items.AMETHYST_BLOCK, 2); - offer2x2ABBARecipe(exporter, RecipeCategory.BUILDING_BLOCKS, HomesBlocks.PAPER_WALL, Items.STICK, Items.PAPER, 4); - offer2x2CompactingRecipe(exporter, RecipeCategory.BUILDING_BLOCKS, HomesBlocks.CALCITE_BRICKS, Items.CALCITE, 4); - offerStonecuttingRecipe(exporter, RecipeCategory.BUILDING_BLOCKS, HomesBlocks.CALCITE_BRICKS, Items.CALCITE, 4); - offerReversibleCompactingRecipes(exporter, RecipeCategory.MISC, HomesItems.COPPER_NUGGET, RecipeCategory.MISC, Items.COPPER_INGOT); } } diff --git a/src/main/java/net/rotgruengelb/sweetofhomes/datagen/SweetOfHomesDataGenerator.java b/src/main/java/net/rotgruengelb/sweetofhomes/datagen/SoHDataGenerator.java similarity index 70% rename from src/main/java/net/rotgruengelb/sweetofhomes/datagen/SweetOfHomesDataGenerator.java rename to src/main/java/net/rotgruengelb/sweetofhomes/datagen/SoHDataGenerator.java index e3a2880..ef95930 100644 --- a/src/main/java/net/rotgruengelb/sweetofhomes/datagen/SweetOfHomesDataGenerator.java +++ b/src/main/java/net/rotgruengelb/sweetofhomes/datagen/SoHDataGenerator.java @@ -2,8 +2,15 @@ import net.fabricmc.fabric.api.datagen.v1.DataGeneratorEntrypoint; import net.fabricmc.fabric.api.datagen.v1.FabricDataGenerator; +import net.rotgruengelb.sweetofhomes.datagen.settings.DataSettings; + +import java.util.ArrayList; +import java.util.List; + +public class SoHDataGenerator implements DataGeneratorEntrypoint { + + public static List> dataSettings = new ArrayList<>(); -public class SweetOfHomesDataGenerator implements DataGeneratorEntrypoint { @Override public void onInitializeDataGenerator(FabricDataGenerator fabricDataGenerator) { FabricDataGenerator.Pack pack = fabricDataGenerator.createPack(); diff --git a/src/main/java/net/rotgruengelb/sweetofhomes/datagen/settings/BlockDataSettings.java b/src/main/java/net/rotgruengelb/sweetofhomes/datagen/settings/BlockDataSettings.java new file mode 100644 index 0000000..3bab286 --- /dev/null +++ b/src/main/java/net/rotgruengelb/sweetofhomes/datagen/settings/BlockDataSettings.java @@ -0,0 +1,125 @@ +package net.rotgruengelb.sweetofhomes.datagen.settings; + +import net.minecraft.block.Block; +import net.minecraft.data.client.*; +import net.minecraft.registry.tag.TagKey; +import net.minecraft.util.Identifier; + +import java.util.ArrayList; +import java.util.List; +import java.util.function.Consumer; + +import static net.rotgruengelb.sweetofhomes.datagen.ModModelProvider.TEMPLATE_CHAIR; + +@SuppressWarnings("unchecked") +public class BlockDataSettings> extends ItemDataSettings { + + protected final Block block; + protected final List> blockTags = new ArrayList<>(); + protected Consumer blockModel = null; + protected RenderLayerEnum renderLayer = RenderLayerEnum.SOLID; + + public BlockDataSettings(Identifier id0, Block block0) { + super(id0, block0.asItem()); + block = block0; + } + + @SafeVarargs + public final T blockTags(TagKey... tags) { + blockTags.addAll(List.of(tags)); + return (T) this; + } + + public Block getBlock() { + return block; + } + + public T renderLayer(RenderLayerEnum renderLayer) { + this.renderLayer = renderLayer; + return (T) this; + } + + public RenderLayerEnum getRenderLayer() { + return renderLayer; + } + + public List> getBlockTags() { + return blockTags; + } + + public Consumer getBlockModel() { + if (blockModel == null) { + return generator -> generator.registerSimpleCubeAll(block); + } + return blockModel; + } + + public T blockModel(Consumer modelGeneratorConsumer) { + blockModel = modelGeneratorConsumer; + return (T) this; + } + + public T blockModelAxisRotated(TexturedModel.Factory modelFactory) { + blockModel = generator -> generator.registerAxisRotated(block, modelFactory); + return (T) this; + } + + public T blockModelParented(Block parent) { + blockModel = generator -> generator.registerParented(block, parent); + return (T) this; + } + + public T blockModelChair() { + blockModel = generator -> { + Identifier identifier = TEMPLATE_CHAIR.upload(block, generator.modelCollector); + generator.blockStateCollector.accept(BlockStateModelGenerator.createSingletonBlockState(block, identifier) + .coordinate(BlockStateModelGenerator.createNorthDefaultHorizontalRotationStates())); + }; + return (T) this; + } + + public T blockModelParented(Identifier parent) { + blockModel = generator -> { + generator.blockStateCollector.accept(VariantsBlockStateSupplier.create(block, BlockStateVariant.create() + .put(VariantSettings.MODEL, parent))); + generator.registerParentedItemModel(block, parent); + }; + return (T) this; + } + + public T blockModelParentedForWaxed() { + if (id.getPath() + .contains("waxed_")) { + return blockModelParented(new Identifier(id.getNamespace(), id.getPath() + .replace("waxed_", "block/"))); + } + + return (T) this; + } + + @Override + public String getTranslationKey() { + return block.getTranslationKey(); + } + + public T copperHelper() { + blockModelParentedForWaxed(); + return recipeWaxing(); + } + + @Override + public T itemModel(Model model) { + throw new UnsupportedOperationException("BlockDataSettings cannot have an item model"); + } + + @Override + public Consumer getItemModel() { + throw new UnsupportedOperationException("BlockDataSettings cannot have an item model"); + } + + public enum RenderLayerEnum { + SOLID, + CUTOUT, + TRANSLUCENT + } +} diff --git a/src/main/java/net/rotgruengelb/sweetofhomes/datagen/settings/DataSettings.java b/src/main/java/net/rotgruengelb/sweetofhomes/datagen/settings/DataSettings.java new file mode 100644 index 0000000..c51d917 --- /dev/null +++ b/src/main/java/net/rotgruengelb/sweetofhomes/datagen/settings/DataSettings.java @@ -0,0 +1,54 @@ +package net.rotgruengelb.sweetofhomes.datagen.settings; + +import net.minecraft.util.Identifier; +import net.rotgruengelb.sweetofhomes.util.Util; + +@SuppressWarnings("unchecked") +public class DataSettings> { + + protected final Identifier id; + protected String translation = null; + protected String translationKey = null; + protected boolean shouldTranslate = true; + + public DataSettings(Identifier id0) { + id = id0; + } + + public S translation(String translation0) { + translation = translation0; + return (S) this; + } + + public S translationKey(String translationKey0) { + translationKey = translationKey0; + return (S) this; + } + + public S shouldTranslate(boolean shouldTranslate0) { + shouldTranslate = shouldTranslate0; + return (S) this; + } + + public boolean shouldTranslate() { + return shouldTranslate; + } + + public String getTranslation() { + if (translation == null) { + return Util.convertSnakeCaseToTitleCase(id.getPath()); + } + return translation; + } + + public String getTranslationKey() { + if (translationKey == null) { + return id.toTranslationKey(); + } + return translationKey; + } + + public Identifier getId() { + return id; + } +} diff --git a/src/main/java/net/rotgruengelb/sweetofhomes/datagen/settings/ItemDataSettings.java b/src/main/java/net/rotgruengelb/sweetofhomes/datagen/settings/ItemDataSettings.java new file mode 100644 index 0000000..eb6ecee --- /dev/null +++ b/src/main/java/net/rotgruengelb/sweetofhomes/datagen/settings/ItemDataSettings.java @@ -0,0 +1,120 @@ +package net.rotgruengelb.sweetofhomes.datagen.settings; + +import net.minecraft.data.client.ItemModelGenerator; +import net.minecraft.data.client.Model; +import net.minecraft.data.client.Models; +import net.minecraft.data.server.recipe.RecipeExporter; +import net.minecraft.data.server.recipe.RecipeProvider; +import net.minecraft.item.Item; +import net.minecraft.recipe.book.RecipeCategory; +import net.minecraft.registry.Registries; +import net.minecraft.registry.tag.TagKey; +import net.minecraft.util.Identifier; +import net.rotgruengelb.sweetofhomes.datagen.ModRecipeProvider; + +import java.util.ArrayList; +import java.util.List; +import java.util.function.Consumer; + +@SuppressWarnings("unchecked") +public class ItemDataSettings> extends DataSettings { + + protected final Item item; + protected final List> itemTags = new ArrayList<>(); + protected final List> recipes = new ArrayList<>(); + protected Consumer itemModel = null; + + public ItemDataSettings(Identifier id0) { + super(id0); + item = null; + } + + public ItemDataSettings(Identifier id0, Item item0) { + super(id0); + item = item0; + } + + public Item getItem() { + return item; + } + + public List> getItemTags() { + return itemTags; + } + + public List> getRecipes() { + return recipes; + } + + public Consumer getItemModel() { + if (itemModel == null) { + return generator -> generator.register(item, Models.GENERATED); + } + return itemModel; + } + + public T itemModel(Model model) { + itemModel = generator -> generator.register(item, model); + return (T) this; + } + + @Override + public String getTranslationKey() { + if (item == null) { + return id.toTranslationKey(); + } + return item.getTranslationKey(); + } + + @SafeVarargs + public final T itemTags(TagKey... tags) { + itemTags.addAll(List.of(tags)); + return (T) this; + } + + @SafeVarargs + public final T itemTagsIf(boolean b, TagKey... tags) { + if (!b) { return (T) this; } + itemTags.addAll(List.of(tags)); + return (T) this; + } + + public T recipe2x2ABBA(RecipeCategory category, Item inputA, Item inputB, int count) { + recipes.add(exporter -> ModRecipeProvider.offer2x2ABBARecipe(exporter, category, item, inputA, inputB, count)); + return (T) this; + } + + public T recipeWaxing() { + if (id.getPath() + .contains("waxed_")) { + recipes.add(exporter -> ModRecipeProvider.offerWaxingRecipe(exporter, RecipeCategory.BUILDING_BLOCKS, item, Registries.ITEM.get(new Identifier(id.getNamespace(), id.getPath() + .replace("waxed_", ""))))); + } + return (T) this; + } + + public T recipe3x3Pillar(RecipeCategory category, Item inputCore, Item inputSide, int count) { + recipes.add(exporter -> ModRecipeProvider.offer3x3PillarRecipe(exporter, category, item, inputCore, inputSide, count)); + return (T) this; + } + + public T recipe2x2Compacting(RecipeCategory category, Item input, int count) { + recipes.add(exporter -> ModRecipeProvider.offer2x2CompactingRecipe(exporter, category, item, input, count)); + return (T) this; + } + + public T recipeReversibleCompacting(RecipeCategory categoryBoth, Item conpactItem) { + recipes.add(exporter -> RecipeProvider.offerReversibleCompactingRecipes(exporter, categoryBoth, item, categoryBoth, conpactItem)); + return (T) this; + } + + public T recipeReversibleCompacting(RecipeCategory reverseCategory, Item conpactItem, RecipeCategory compactingCategory) { + recipes.add(exporter -> RecipeProvider.offerReversibleCompactingRecipes(exporter, reverseCategory, item, compactingCategory, conpactItem)); + return (T) this; + } + + public T recipeStonecutting(RecipeCategory category, Item base, int count) { + recipes.add(exporter -> RecipeProvider.offerStonecuttingRecipe(exporter, category, item, base, count)); + return (T) this; + } +} diff --git a/src/main/java/net/rotgruengelb/sweetofhomes/datagen/settings/TagDataSettings.java b/src/main/java/net/rotgruengelb/sweetofhomes/datagen/settings/TagDataSettings.java new file mode 100644 index 0000000..f45657c --- /dev/null +++ b/src/main/java/net/rotgruengelb/sweetofhomes/datagen/settings/TagDataSettings.java @@ -0,0 +1,24 @@ +package net.rotgruengelb.sweetofhomes.datagen.settings; + +import net.minecraft.util.Identifier; + +public class TagDataSettings> extends DataSettings { + + public final String tagType; + + public TagDataSettings(Identifier id0, String tagType0) { + super(id0); + tagType = tagType0; + } + + public TagDataSettings(Identifier id0) { + super(id0); + tagType = "block"; + } + + @Override + public String getTranslationKey() { + return String.format("tag.%s.%s.%s", tagType, id.getNamespace(), id.getPath() + .replace('/', '.')); + } +} diff --git a/src/main/java/net/rotgruengelb/sweetofhomes/item/CopperWrenchItem.java b/src/main/java/net/rotgruengelb/sweetofhomes/item/CopperWrenchItem.java index 9ca0fd3..1476ce7 100644 --- a/src/main/java/net/rotgruengelb/sweetofhomes/item/CopperWrenchItem.java +++ b/src/main/java/net/rotgruengelb/sweetofhomes/item/CopperWrenchItem.java @@ -20,7 +20,7 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraft.world.WorldAccess; -import net.rotgruengelb.sweetofhomes.world.HomesGameRules; +import net.rotgruengelb.sweetofhomes.world.SoHGameRules; import org.jetbrains.annotations.Nullable; import java.util.Collection; @@ -42,7 +42,7 @@ private static T cycle(Iterable elements, @Nullable T current, boolean in private static void sendMessage(PlayerEntity player, Text message) { if (player.getWorld() .getGameRules() - .getBoolean(HomesGameRules.SHOW_COPPER_WRENCH_MESSAGES)) { + .getBoolean(SoHGameRules.SHOW_COPPER_WRENCH_MESSAGES)) { ((ServerPlayerEntity) player).sendMessageToClient(message, true); } } diff --git a/src/main/java/net/rotgruengelb/sweetofhomes/item/HomesItems.java b/src/main/java/net/rotgruengelb/sweetofhomes/item/HomesItems.java deleted file mode 100644 index bfb45d5..0000000 --- a/src/main/java/net/rotgruengelb/sweetofhomes/item/HomesItems.java +++ /dev/null @@ -1,52 +0,0 @@ -package net.rotgruengelb.sweetofhomes.item; - -import net.fabricmc.fabric.api.item.v1.FabricItemSettings; -import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents; -import net.minecraft.item.Item; -import net.minecraft.item.ItemGroup; -import net.minecraft.item.MusicDiscItem; -import net.minecraft.registry.Registries; -import net.minecraft.registry.Registry; -import net.minecraft.registry.RegistryKey; -import net.minecraft.sound.SoundEvent; -import net.minecraft.util.Identifier; -import net.minecraft.util.Rarity; -import net.rotgruengelb.sweetofhomes.SweetOfHomes; - -import java.util.ArrayList; -import java.util.List; - -public class HomesItems { - - public static final Item COPPER_WRENCH = registerItem("copper_wrench", new CopperWrenchItem(new FabricItemSettings().maxCount(1))); - public static final Item COPPER_NUGGET = registerItem("copper_nugget", new Item(new FabricItemSettings())); - - private static Item registerItem(String name, Item item) { - ALL.ITEMS.add(item); - return Registry.register(Registries.ITEM, new Identifier(SweetOfHomes.MOD_ID, name), item); - } - - private static Item registerMusicDisc(String name, int comparatorOutput, SoundEvent soundEvent, int lengthInSeconds) { - - return registerItem("music_disc_" + name, new MusicDiscItem(comparatorOutput, soundEvent, new FabricItemSettings().maxCount(1) - .rarity(Rarity.RARE), lengthInSeconds)); - } - - public static void addItemsToItemGroup() { - } - - private static void addToItemGroup(RegistryKey group, Item item) { - ItemGroupEvents.modifyEntriesEvent(group) - .register(entries -> entries.add(item)); - } - - public static void registerModItems() { - SweetOfHomes.LOGGER.debug("Registering HomesItems for " + SweetOfHomes.MOD_ID); - - addItemsToItemGroup(); - } - - public static class ALL { - public static final List ITEMS = new ArrayList<>(); - } -} \ No newline at end of file diff --git a/src/main/java/net/rotgruengelb/sweetofhomes/item/SoHItems.java b/src/main/java/net/rotgruengelb/sweetofhomes/item/SoHItems.java new file mode 100644 index 0000000..ad2a906 --- /dev/null +++ b/src/main/java/net/rotgruengelb/sweetofhomes/item/SoHItems.java @@ -0,0 +1,46 @@ +package net.rotgruengelb.sweetofhomes.item; + +import net.fabricmc.fabric.api.item.v1.FabricItemSettings; +import net.fabricmc.fabric.api.tag.convention.v1.ConventionalItemTags; +import net.minecraft.data.client.Model; +import net.minecraft.data.client.Models; +import net.minecraft.item.Item; +import net.minecraft.item.Items; +import net.minecraft.recipe.book.RecipeCategory; +import net.minecraft.registry.Registries; +import net.minecraft.registry.Registry; +import net.minecraft.registry.tag.TagKey; +import net.minecraft.util.Identifier; +import net.rotgruengelb.sweetofhomes.SweetOfHomes; +import net.rotgruengelb.sweetofhomes.datagen.settings.ItemDataSettings; + +import static net.rotgruengelb.sweetofhomes.SweetOfHomes.id; +import static net.rotgruengelb.sweetofhomes.datagen.SoHDataGenerator.dataSettings; + +public class SoHItems { + + public static final Item COPPER_WRENCH = item("copper_wrench", new CopperWrenchItem(new FabricItemSettings().maxCount(1)), Models.HANDHELD); + public static final Item COPPER_NUGGET = copperNugget("copper_nugget", new Item(new FabricItemSettings()), ConventionalItemTags.NUGGETS); + + @SafeVarargs + private static Item item(String name, Item item, Model model, TagKey... tags) { + item = Registry.register(Registries.ITEM, new Identifier(SweetOfHomes.MOD_ID, name), item); + return dataSettings(new ItemDataSettings<>(id(name), item).itemTags(tags).itemModel(model)); + } + + @SafeVarargs + private static Item copperNugget(String name, Item item, TagKey... tags) { + item = Registry.register(Registries.ITEM, new Identifier(SweetOfHomes.MOD_ID, name), item); + return dataSettings(new ItemDataSettings<>(id(name), item).itemTags(tags) + .recipeReversibleCompacting(RecipeCategory.MISC, Items.COPPER_INGOT)); + } + + public static void registerModItems() { + SweetOfHomes.LOGGER.debug("Registering SoHItems for " + SweetOfHomes.MOD_ID); + } + + private static Item dataSettings(ItemDataSettings blockDataSettings) { + dataSettings.add(blockDataSettings); + return blockDataSettings.getItem(); + } +} \ No newline at end of file diff --git a/src/main/java/net/rotgruengelb/sweetofhomes/registry/tag/SoHBlockTags.java b/src/main/java/net/rotgruengelb/sweetofhomes/registry/tag/SoHBlockTags.java new file mode 100644 index 0000000..4076568 --- /dev/null +++ b/src/main/java/net/rotgruengelb/sweetofhomes/registry/tag/SoHBlockTags.java @@ -0,0 +1,27 @@ +package net.rotgruengelb.sweetofhomes.registry.tag; + +import net.minecraft.block.Block; +import net.minecraft.registry.Registry; +import net.minecraft.registry.RegistryKey; +import net.minecraft.registry.RegistryKeys; +import net.minecraft.registry.tag.TagKey; +import net.minecraft.util.Identifier; +import net.rotgruengelb.sweetofhomes.SweetOfHomes; +import net.rotgruengelb.sweetofhomes.datagen.SoHDataGenerator; +import net.rotgruengelb.sweetofhomes.datagen.settings.TagDataSettings; + +public class SoHBlockTags { + public static final TagKey ABOVE_BYPASSES_SEAT_CHECK = createTagKey(RegistryKeys.BLOCK, "above_bypasses_seat_check"); + + private static TagKey createTagKey(RegistryKey> registryKey, String path) { + Identifier id = new Identifier(SweetOfHomes.MOD_ID, path); + TagKey tagKey = TagKey.of(registryKey, id); + + SoHDataGenerator.dataSettings.add(new TagDataSettings<>(id, "block")); + return tagKey; + } + + public static void registerModBlockTags() { + SweetOfHomes.LOGGER.debug("Registering SoHBlockTags for " + SweetOfHomes.MOD_ID); + } +} diff --git a/src/main/java/net/rotgruengelb/sweetofhomes/registry/tag/SoHItemTags.java b/src/main/java/net/rotgruengelb/sweetofhomes/registry/tag/SoHItemTags.java new file mode 100644 index 0000000..9de06fc --- /dev/null +++ b/src/main/java/net/rotgruengelb/sweetofhomes/registry/tag/SoHItemTags.java @@ -0,0 +1,27 @@ +package net.rotgruengelb.sweetofhomes.registry.tag; + +import net.minecraft.item.Item; +import net.minecraft.registry.RegistryKeys; +import net.minecraft.registry.tag.TagKey; +import net.minecraft.util.Identifier; +import net.rotgruengelb.sweetofhomes.SweetOfHomes; +import net.rotgruengelb.sweetofhomes.datagen.SoHDataGenerator; +import net.rotgruengelb.sweetofhomes.datagen.settings.TagDataSettings; + +public class SoHItemTags { + public static final TagKey WOODEN_PILLARS = createTagKey("wooden_pillars"); + public static final TagKey CHAIRS = createTagKey("chairs"); + + private static TagKey createTagKey(String path) { + Identifier id = new Identifier(SweetOfHomes.MOD_ID, path); + TagKey tagKey = TagKey.of(RegistryKeys.ITEM, id); + + SoHDataGenerator.dataSettings.add(new TagDataSettings<>(id, "item")); + return tagKey; + } + + public static void registerModItemTags() { + SweetOfHomes.LOGGER.debug("Registering SoHItemTags for " + SweetOfHomes.MOD_ID); + } + +} diff --git a/src/main/java/net/rotgruengelb/sweetofhomes/registry/tag/SoHTags.java b/src/main/java/net/rotgruengelb/sweetofhomes/registry/tag/SoHTags.java new file mode 100644 index 0000000..3e9ba86 --- /dev/null +++ b/src/main/java/net/rotgruengelb/sweetofhomes/registry/tag/SoHTags.java @@ -0,0 +1,39 @@ +package net.rotgruengelb.sweetofhomes.registry.tag; + +import net.minecraft.entity.EntityType; +import net.minecraft.registry.Registry; +import net.minecraft.registry.RegistryKey; +import net.minecraft.registry.RegistryKeys; +import net.minecraft.registry.tag.TagKey; +import net.minecraft.util.Identifier; +import net.rotgruengelb.sweetofhomes.SweetOfHomes; +import net.rotgruengelb.sweetofhomes.datagen.SoHDataGenerator; +import net.rotgruengelb.sweetofhomes.datagen.settings.TagDataSettings; + +import java.util.Objects; + +public class SoHTags { + + private static TagKey createTagKey(RegistryKey> registryKey, String path, String tagType) { + Identifier id = new Identifier(SweetOfHomes.MOD_ID, path); + TagKey tagKey = TagKey.of(registryKey, id); + + SoHDataGenerator.dataSettings.add(new TagDataSettings<>(id, tagType).shouldTranslate(!Objects.equals(tagType, "entity"))); + return tagKey; + } + + public static void registerModTags() { + SweetOfHomes.LOGGER.debug("Registering SoHTags for " + SweetOfHomes.MOD_ID); + ENTITIES.registerModEntityTags(); + SoHBlockTags.registerModBlockTags(); + SoHItemTags.registerModItemTags(); + } + + public static class ENTITIES { + public static final TagKey> CAN_SIT_IN_SEATS = createTagKey(RegistryKeys.ENTITY_TYPE, "can_sit_in_seats", "entity"); + + public static void registerModEntityTags() { + SweetOfHomes.LOGGER.debug("Registering SoHTags.ENTITIES for " + SweetOfHomes.MOD_ID); + } + } +} diff --git a/src/main/java/net/rotgruengelb/sweetofhomes/util/Util.java b/src/main/java/net/rotgruengelb/sweetofhomes/util/Util.java new file mode 100644 index 0000000..d0b9b1b --- /dev/null +++ b/src/main/java/net/rotgruengelb/sweetofhomes/util/Util.java @@ -0,0 +1,25 @@ +package net.rotgruengelb.sweetofhomes.util; + +public class Util { + + public static String convertSnakeCaseToTitleCase(String snakeCaseText) { + String[] words = snakeCaseText.split("_"); + + StringBuilder titleCaseText = new StringBuilder(); + + for (String word : words) { + if (!word.isEmpty()) { + titleCaseText.append(Character.toUpperCase(word.charAt(0))) + .append(word.substring(1) + .toLowerCase()) + .append(" "); + } + } + return titleCaseText.toString() + .trim(); + } + + public static boolean shouldMarkAsNonFlammable(String string) { + return string.contains("crimson") || string.contains("warped"); + } +} diff --git a/src/main/java/net/rotgruengelb/sweetofhomes/util/tag/HomesTags.java b/src/main/java/net/rotgruengelb/sweetofhomes/util/tag/HomesTags.java deleted file mode 100644 index 61c9677..0000000 --- a/src/main/java/net/rotgruengelb/sweetofhomes/util/tag/HomesTags.java +++ /dev/null @@ -1,19 +0,0 @@ -package net.rotgruengelb.sweetofhomes.util.tag; - -import net.minecraft.block.Block; -import net.minecraft.item.Item; -import net.minecraft.registry.RegistryKeys; -import net.minecraft.registry.tag.TagKey; -import net.minecraft.util.Identifier; -import net.rotgruengelb.sweetofhomes.SweetOfHomes; - -public class HomesTags { - - public static class BLOCKS { - public static final TagKey WOODEN_PILLARS = TagKey.of(RegistryKeys.BLOCK, new Identifier(SweetOfHomes.MOD_ID, "wooden_pillars")); - } - - public static class ITEMS { - public static final TagKey WOODEN_PILLARS = TagKey.of(RegistryKeys.ITEM, new Identifier(SweetOfHomes.MOD_ID, "wooden_pillars")); - } -} diff --git a/src/main/java/net/rotgruengelb/sweetofhomes/world/HomesGameRules.java b/src/main/java/net/rotgruengelb/sweetofhomes/world/SoHGameRules.java similarity index 82% rename from src/main/java/net/rotgruengelb/sweetofhomes/world/HomesGameRules.java rename to src/main/java/net/rotgruengelb/sweetofhomes/world/SoHGameRules.java index 3fd1ccd..8bc2e10 100644 --- a/src/main/java/net/rotgruengelb/sweetofhomes/world/HomesGameRules.java +++ b/src/main/java/net/rotgruengelb/sweetofhomes/world/SoHGameRules.java @@ -5,11 +5,11 @@ import net.minecraft.world.GameRules; import net.rotgruengelb.sweetofhomes.SweetOfHomes; -public class HomesGameRules { +public class SoHGameRules { public static final GameRules.Key SHOW_COPPER_WRENCH_MESSAGES = GameRuleRegistry.register(SweetOfHomes.MOD_ID + ".showCopperWrenchMessages", GameRules.Category.PLAYER, GameRuleFactory.createBooleanRule(false)); public static void registerModGameRules() { - SweetOfHomes.LOGGER.debug("Registering HomesGameRules for " + SweetOfHomes.MOD_ID); + SweetOfHomes.LOGGER.debug("Registering SoHGameRules for " + SweetOfHomes.MOD_ID); } } diff --git a/src/main/resources/assets/sweetofhomes/models/block/template_chair.json b/src/main/resources/assets/sweetofhomes/models/block/template_chair.json index 04a8c40..e3288e0 100644 --- a/src/main/resources/assets/sweetofhomes/models/block/template_chair.json +++ b/src/main/resources/assets/sweetofhomes/models/block/template_chair.json @@ -1,5 +1,6 @@ { "credit": "Made with Blockbench", + "render_type": "minecraft:cutout", "texture_size": [64, 64], "textures": { "particle": "#texture" diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 7bdaad4..a61f64f 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -22,7 +22,7 @@ "net.rotgruengelb.sweetofhomes.SweetOfHomesClient" ], "fabric-datagen": [ - "net.rotgruengelb.sweetofhomes.datagen.SweetOfHomesDataGenerator" + "net.rotgruengelb.sweetofhomes.datagen.SoHDataGenerator" ] }, "mixins": [