Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/crop #3

Merged
merged 3 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
};
}
}
39 changes: 27 additions & 12 deletions src/main/java/org/hiedacamellia/whispergrove/registers/WGBlock.java
Original file line number Diff line number Diff line change
@@ -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<Block> TEST_BLOCK = BLOCKS.register("test_block",() -> new TestBlock("test_block"));

public static final DeferredBlock<BaseLogBlock> RouGuiLog = BLOCKS.register("rou_gui_log",() -> new RouGuiLogBlock("rou_gui_log"));
public static final DeferredBlock<BaseLogBlock> RouGuiStrippedLog = BLOCKS.register("rou_gui_stripped_log",() -> new RouGuiStrippedLogBlock("rou_gui_stripped_log"));
public static final DeferredBlock<BaseBlock> RouGuiPlanks = BLOCKS.register("rou_gui_planks",() -> new RouGuiPlanksBlock("rou_gui_planks"));
public static final DeferredBlock<SlabBlock> RouGuiSlab = BLOCKS.register("rou_gui_slab",() -> new RouGuiSlabBlock("rou_gui_slab"));
public static final DeferredBlock<LeavesBlock> RouGuiLeaves = BLOCKS.register("rou_gui_leaves",() -> new RouGuiLeavesBlock("rou_gui_leaves"));
public static final DeferredBlock<StairBlock> RouGuiStair = BLOCKS.register("rou_gui_stair",() -> new RouGuiStairsBlock("rou_gui_stair"));

public static final DeferredBlock<RollerBlock> Roller = BLOCKS.register("roller",() -> new RollerBlock("roller"));
public static final DeferredBlock<BaseLogBlock> RouGuiLog = BLOCKS.register("rou_gui_log", () -> new RouGuiLogBlock("rou_gui_log"));
public static final DeferredBlock<BaseLogBlock> RouGuiStrippedLog = BLOCKS.register("rou_gui_stripped_log", () -> new RouGuiStrippedLogBlock("rou_gui_stripped_log"));
public static final DeferredBlock<BaseBlock> RouGuiPlanks = BLOCKS.register("rou_gui_planks", () -> new RouGuiPlanksBlock("rou_gui_planks"));
public static final DeferredBlock<SlabBlock> RouGuiSlab = BLOCKS.register("rou_gui_slab", () -> new RouGuiSlabBlock("rou_gui_slab"));
public static final DeferredBlock<LeavesBlock> RouGuiLeaves = BLOCKS.register("rou_gui_leaves", () -> new RouGuiLeavesBlock("rou_gui_leaves"));
public static final DeferredBlock<StairBlock> RouGuiStair = BLOCKS.register("rou_gui_stair", () -> new RouGuiStairsBlock("rou_gui_stair"));

public static final DeferredBlock<RollerBlock> Roller = BLOCKS.register("roller", () -> new RollerBlock("roller"));

public static final Map<String, DeferredBlock<BaseCropBlock>> 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))
));
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading