diff --git a/src/main/java/org/hiedacamellia/whispergrove/core/data/provider/StateProvider.java b/src/main/java/org/hiedacamellia/whispergrove/core/data/provider/StateProvider.java index f7d5049..47e0423 100644 --- a/src/main/java/org/hiedacamellia/whispergrove/core/data/provider/StateProvider.java +++ b/src/main/java/org/hiedacamellia/whispergrove/core/data/provider/StateProvider.java @@ -2,7 +2,10 @@ import net.minecraft.data.PackOutput; import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.CropBlock; import net.neoforged.neoforge.client.model.generators.BlockStateProvider; +import net.neoforged.neoforge.client.model.generators.ConfiguredModel; import net.neoforged.neoforge.common.data.ExistingFileHelper; import org.hiedacamellia.whispergrove.WhisperGrove; import org.hiedacamellia.whispergrove.registers.WGBlock; @@ -15,23 +18,49 @@ public StateProvider(PackOutput gen, ExistingFileHelper helper) { @Override protected void registerStatesAndModels() { - axisBlock(WGBlock.RouGuiLog.get(),modLoc("block/rou_gui_log"),modLoc("block/rou_gui_log_top")); - simpleBlockItem(WGBlock.RouGuiLog.get(),models().cubeTop("rou_gui_log",modLoc("block/rou_gui_log"),modLoc("block/rou_gui_log_top"))); + axisBlock(WGBlock.RouGuiLog.get(), modLoc("block/rou_gui_log"), modLoc("block/rou_gui_log_top")); + simpleBlockItem(WGBlock.RouGuiLog.get(), models().cubeTop("rou_gui_log", modLoc("block/rou_gui_log"), modLoc("block/rou_gui_log_top"))); - axisBlock(WGBlock.RouGuiStrippedLog.get(),modLoc("block/rou_gui_stripped_log"),modLoc("block/rou_gui_log_top")); - simpleBlockItem(WGBlock.RouGuiStrippedLog.get(),models().cubeTop("rou_gui_stripped_log",modLoc("block/rou_gui_stripped_log"),modLoc("block/rou_gui_log_top"))); + axisBlock(WGBlock.RouGuiStrippedLog.get(), modLoc("block/rou_gui_stripped_log"), modLoc("block/rou_gui_log_top")); + simpleBlockItem(WGBlock.RouGuiStrippedLog.get(), models().cubeTop("rou_gui_stripped_log", modLoc("block/rou_gui_stripped_log"), modLoc("block/rou_gui_log_top"))); simpleBlockWithItem(WGBlock.RouGuiLeaves.get(), models().leaves("rou_gui_leaves", modLoc("block/rou_gui_leaves"))); simpleBlockWithItem(WGBlock.RouGuiPlanks.get(), cubeAll(WGBlock.RouGuiPlanks.get())); - slabBlock(WGBlock.RouGuiSlab.get(),modLoc("block/rou_gui_planks"),modLoc("block/rou_gui_planks")); - simpleBlockItem(WGBlock.RouGuiSlab.get(),models().slab("rou_gui_slab",modLoc("block/rou_gui_planks"),modLoc("block/rou_gui_planks"),modLoc("block/rou_gui_planks"))); + slabBlock(WGBlock.RouGuiSlab.get(), modLoc("block/rou_gui_planks"), modLoc("block/rou_gui_planks")); + simpleBlockItem(WGBlock.RouGuiSlab.get(), models().slab("rou_gui_slab", modLoc("block/rou_gui_planks"), modLoc("block/rou_gui_planks"), modLoc("block/rou_gui_planks"))); - stairsBlock(WGBlock.RouGuiStair.get(),modLoc("block/rou_gui_planks")); - simpleBlockItem(WGBlock.RouGuiStair.get(),models().stairs("rou_gui_stair",modLoc("block/rou_gui_planks"),modLoc("block/rou_gui_planks"),modLoc("block/rou_gui_planks"))); + stairsBlock(WGBlock.RouGuiStair.get(), modLoc("block/rou_gui_planks")); + simpleBlockItem(WGBlock.RouGuiStair.get(), models().stairs("rou_gui_stair", modLoc("block/rou_gui_planks"), modLoc("block/rou_gui_planks"), modLoc("block/rou_gui_planks"))); - simpleBlock(WGBlock.Roller.get(),this.models().getExistingFile(ResourceLocation.fromNamespaceAndPath(WhisperGrove.MODID, "roller"))); + simpleBlock(WGBlock.Roller.get(), this.models().getExistingFile(ResourceLocation.fromNamespaceAndPath(WhisperGrove.MODID, "roller"))); simpleBlockItem(WGBlock.Roller.get(), this.models().getExistingFile(ResourceLocation.fromNamespaceAndPath(WhisperGrove.MODID, "roller"))); + + WGBlock.CROP_BLOCKS.forEach((s, baseCropBlockDeferredBlock) -> registerCropBlockModels(baseCropBlockDeferredBlock.get(), s)); + } + + private void registerCropBlockModels(Block block, String name) { + getVariantBuilder(block).forAllStates(state -> { + int age = state.getValue(CropBlock.AGE); + return ConfiguredModel.builder() + .modelFile(models().crop(getCropBlockModelName(name, age), getCropBlockModelLocation(name, age))) + .build(); + }); + + } + + private ResourceLocation getCropBlockModelLocation(String name, int age) { + return ResourceLocation.fromNamespaceAndPath(WhisperGrove.MODID, getCropBlockModelName(name, age)); + } + + private String getCropBlockModelName(String name, int age) { + return "block/" + name + "_stage" + switch (age) { + case 0, 1 -> 0; + case 2, 3 -> 1; + case 4, 5, 6 -> 2; + case 7 -> 3; + default -> throw new IllegalArgumentException("Invalid age: " + age); + }; } } diff --git a/src/main/java/org/hiedacamellia/whispergrove/registers/WGBlock.java b/src/main/java/org/hiedacamellia/whispergrove/registers/WGBlock.java index e935800..883583b 100644 --- a/src/main/java/org/hiedacamellia/whispergrove/registers/WGBlock.java +++ b/src/main/java/org/hiedacamellia/whispergrove/registers/WGBlock.java @@ -1,29 +1,44 @@ package org.hiedacamellia.whispergrove.registers; -import net.minecraft.world.level.block.ButtonBlock; -import net.minecraft.world.level.block.LeavesBlock; -import net.minecraft.world.level.block.SlabBlock; -import net.minecraft.world.level.block.StairBlock; +import net.minecraft.world.level.block.*; +import net.minecraft.world.level.block.state.BlockBehaviour; import net.neoforged.neoforge.registries.DeferredBlock; import net.neoforged.neoforge.registries.DeferredRegister; import org.hiedacamellia.whispergrove.WhisperGrove; import org.hiedacamellia.whispergrove.content.common.blocks.*; import org.hiedacamellia.whispergrove.core.entry.BaseBlock; +import org.hiedacamellia.whispergrove.core.entry.BaseCropBlock; import org.hiedacamellia.whispergrove.core.entry.BaseLogBlock; +import java.util.Dictionary; +import java.util.Hashtable; +import java.util.Map; +import java.util.stream.Collectors; +import java.util.stream.Stream; + public class WGBlock { public static final DeferredRegister.Blocks BLOCKS = DeferredRegister.createBlocks(WhisperGrove.MODID); //public static final DeferredBlock TEST_BLOCK = BLOCKS.register("test_block",() -> new TestBlock("test_block")); - public static final DeferredBlock RouGuiLog = BLOCKS.register("rou_gui_log",() -> new RouGuiLogBlock("rou_gui_log")); - public static final DeferredBlock RouGuiStrippedLog = BLOCKS.register("rou_gui_stripped_log",() -> new RouGuiStrippedLogBlock("rou_gui_stripped_log")); - public static final DeferredBlock RouGuiPlanks = BLOCKS.register("rou_gui_planks",() -> new RouGuiPlanksBlock("rou_gui_planks")); - public static final DeferredBlock RouGuiSlab = BLOCKS.register("rou_gui_slab",() -> new RouGuiSlabBlock("rou_gui_slab")); - public static final DeferredBlock RouGuiLeaves = BLOCKS.register("rou_gui_leaves",() -> new RouGuiLeavesBlock("rou_gui_leaves")); - public static final DeferredBlock RouGuiStair = BLOCKS.register("rou_gui_stair",() -> new RouGuiStairsBlock("rou_gui_stair")); - - public static final DeferredBlock Roller = BLOCKS.register("roller",() -> new RollerBlock("roller")); + public static final DeferredBlock RouGuiLog = BLOCKS.register("rou_gui_log", () -> new RouGuiLogBlock("rou_gui_log")); + public static final DeferredBlock RouGuiStrippedLog = BLOCKS.register("rou_gui_stripped_log", () -> new RouGuiStrippedLogBlock("rou_gui_stripped_log")); + public static final DeferredBlock RouGuiPlanks = BLOCKS.register("rou_gui_planks", () -> new RouGuiPlanksBlock("rou_gui_planks")); + public static final DeferredBlock RouGuiSlab = BLOCKS.register("rou_gui_slab", () -> new RouGuiSlabBlock("rou_gui_slab")); + public static final DeferredBlock RouGuiLeaves = BLOCKS.register("rou_gui_leaves", () -> new RouGuiLeavesBlock("rou_gui_leaves")); + public static final DeferredBlock RouGuiStair = BLOCKS.register("rou_gui_stair", () -> new RouGuiStairsBlock("rou_gui_stair")); + public static final DeferredBlock Roller = BLOCKS.register("roller", () -> new RollerBlock("roller")); + public static final Map> CROP_BLOCKS = Stream.of( + "di_huang", + "gan_cao", + "huang_qi", + "long_dan_cao", + "ren_shen" + ) + .collect(Collectors.toMap( + s -> s, + s -> BLOCKS.register(s, () -> new BaseCropBlock(BlockBehaviour.Properties.ofFullCopy(Blocks.POTATOES), s)) + )); }