Skip to content

Commit

Permalink
custom crops
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaupenjoe committed Nov 18, 2024
1 parent 2c048cd commit 364d5c9
Show file tree
Hide file tree
Showing 26 changed files with 247 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// 1.21.1 2024-10-08T15:10:08.6925406 Item Models: tutorialmod
// 1.21.1 2024-11-18T21:41:02.6803398 Item Models: tutorialmod
f746b64540daf2ab6302b3ec01a78490c48fc10b assets/tutorialmod/models/item/bar_brawl_music_disc.json
85c4092ee8a88b79898e775ffd1ddd7a535d2b66 assets/tutorialmod/models/item/bismuth.json
02b77817941627a9a89f06fa5972e0a4ddb84b4c assets/tutorialmod/models/item/bismuth_axe.json
Expand Down Expand Up @@ -59,5 +59,6 @@ a54afda44eb7250175edad834ef386f45087b341 assets/tutorialmod/models/item/bismuth_
91ec90598690688b7129cd5976415ae5158e72d3 assets/tutorialmod/models/item/frostfire_ice.json
449182fb0ac0479cfb756ef062a8c183fc5a3c2a assets/tutorialmod/models/item/kaupen_armor_trim_smithing_template.json
f4c84ba8717deb3f252eef0b2e0833f60e735029 assets/tutorialmod/models/item/radish.json
31a67c391f1ba73a4df4fca94eeb64f7c376bc2e assets/tutorialmod/models/item/radish_seeds.json
4632490c178511af06a636377c35e6caf64df3f1 assets/tutorialmod/models/item/raw_bismuth.json
fa9080666ba4e3910d0814ec35a3e300f861fb1c assets/tutorialmod/models/item/starlight_ashes.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// 1.21.1 2024-09-06T17:33:35.0863894 Block States: tutorialmod
// 1.21.1 2024-11-18T21:41:02.6783381 Block States: tutorialmod
fc4b73d7d5429cd1c496b45459a243216fd5ce35 assets/tutorialmod/blockstates/bismuth_block.json
12833e7b89e5c0f2e9106085dcf9d9e11cf75b57 assets/tutorialmod/blockstates/bismuth_button.json
b4895c3f5396f7c4c029762f48f46f1369cf5748 assets/tutorialmod/blockstates/bismuth_deepslate_ore.json
Expand All @@ -13,6 +13,7 @@ a5684b332541303f689be2ab2e93be8d036d413e assets/tutorialmod/blockstates/bismuth_
9d8278772738444ac0eba6ec9893d81fca8e1d9a assets/tutorialmod/blockstates/bismuth_trapdoor.json
4665b9ff850bc1d6542ed2f5aaedfb1a035a83c2 assets/tutorialmod/blockstates/bismuth_wall.json
2d316979b5247b802b0590d94b40bac75fde6974 assets/tutorialmod/blockstates/magic_block.json
369ff19f0ddd34b3501a422ca9ba6eee50c28c09 assets/tutorialmod/blockstates/radish_crop.json
0097fc802455bf29f1de139c677fb7693e30bd10 assets/tutorialmod/models/block/bismuth_block.json
b430d1d87061bca0196d877adbdf71173f9deaf4 assets/tutorialmod/models/block/bismuth_button.json
57614ad44a43d12f36bdeec43b7b072f4d943f7f assets/tutorialmod/models/block/bismuth_button_pressed.json
Expand Down Expand Up @@ -48,6 +49,10 @@ bf629be687860a4a95a789e357fda47617961e8a assets/tutorialmod/models/block/bismuth
78aa4dc97e2c8f0af42d1b0593c3634241e449ef assets/tutorialmod/models/block/bismuth_wall_side.json
aaab7fc2523e163f34142343d458459ae7208fe9 assets/tutorialmod/models/block/bismuth_wall_side_tall.json
ed27aaa00c275028e1495bb6d6bfdcea1851067b assets/tutorialmod/models/block/magic_block.json
31185a07fc2dc6f1371a066ffe41a03981a51692 assets/tutorialmod/models/block/radish_crop_stage0.json
130f25109def058713c7d74bf283b7c097ae5425 assets/tutorialmod/models/block/radish_crop_stage1.json
0238d5cbef661310169a033429e97d1485072fe7 assets/tutorialmod/models/block/radish_crop_stage2.json
7e4b2f1a22ca8f24a1760fa3ecefaa513861b41a assets/tutorialmod/models/block/radish_crop_stage3.json
a118ac7349d7896719a282e634bc3604295f34bd assets/tutorialmod/models/item/bismuth_block.json
41ec25eced74c31f69d29965c8aef70bd0501eef assets/tutorialmod/models/item/bismuth_deepslate_ore.json
89a73a57845e0490c3904533720baeedf7e46a57 assets/tutorialmod/models/item/bismuth_fence_gate.json
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// 1.21.1 2024-09-06T17:33:35.0853897 Loot Tables
// 1.21.1 2024-11-18T21:41:02.6773369 Loot Tables
ea33c2a1e420da7916da2626364d946e161c2f6c data/tutorialmod/loot_table/blocks/bismuth_block.json
63b39624969e53a57f98de95c0d38077aa71266c data/tutorialmod/loot_table/blocks/bismuth_button.json
fd34a70d43389eb067a721582f8a89c3b58d29ab data/tutorialmod/loot_table/blocks/bismuth_deepslate_ore.json
Expand All @@ -12,3 +12,4 @@ edb6bac3a5e85ec91ead9c525ddd13c5bbe7a2cb data/tutorialmod/loot_table/blocks/bism
bf986659c2331d19b05cf2597b400a5e0d4c73c3 data/tutorialmod/loot_table/blocks/bismuth_stairs.json
5d7db77384b7e1a5ee2fe5c42e7aea41ff597ef5 data/tutorialmod/loot_table/blocks/bismuth_trapdoor.json
af8e04bde28dac9e526252e8e8eb41e72357aa78 data/tutorialmod/loot_table/blocks/bismuth_wall.json
36b9bcd239fc7b8ab4aeafcbd04a4e2528293936 data/tutorialmod/loot_table/blocks/radish_crop.json
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
// 1.21.1 2024-09-06T14:19:09.142399 Data Maps
// 1.21.1 2024-11-18T21:41:02.6763367 Data Maps
08cbba1cee30ccded1912b69e8daba63f0bce421 data/neoforge/data_maps/item/compostables.json
89ae608dc3591441aa01b7bcad52e4309e9de471 data/neoforge/data_maps/item/furnace_fuels.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"variants": {
"age=0": {
"model": "tutorialmod:block/radish_crop_stage0"
},
"age=1": {
"model": "tutorialmod:block/radish_crop_stage1"
},
"age=2": {
"model": "tutorialmod:block/radish_crop_stage2"
},
"age=3": {
"model": "tutorialmod:block/radish_crop_stage3"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"parent": "minecraft:block/crop",
"render_type": "minecraft:cutout",
"textures": {
"crop": "tutorialmod:block/radish_crop_stage0"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"parent": "minecraft:block/crop",
"render_type": "minecraft:cutout",
"textures": {
"crop": "tutorialmod:block/radish_crop_stage1"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"parent": "minecraft:block/crop",
"render_type": "minecraft:cutout",
"textures": {
"crop": "tutorialmod:block/radish_crop_stage2"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"parent": "minecraft:block/crop",
"render_type": "minecraft:cutout",
"textures": {
"crop": "tutorialmod:block/radish_crop_stage3"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parent": "minecraft:item/generated",
"textures": {
"layer0": "tutorialmod:item/radish_seeds"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"values": {
"tutorialmod:radish": {
"chance": 0.45
},
"tutorialmod:radish_seeds": {
"chance": 0.25
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{
"type": "minecraft:block",
"functions": [
{
"function": "minecraft:explosion_decay"
}
],
"pools": [
{
"bonus_rolls": 0.0,
"entries": [
{
"type": "minecraft:alternatives",
"children": [
{
"type": "minecraft:item",
"conditions": [
{
"block": "tutorialmod:radish_crop",
"condition": "minecraft:block_state_property",
"properties": {
"age": "3"
}
}
],
"name": "tutorialmod:radish"
},
{
"type": "minecraft:item",
"name": "tutorialmod:radish_seeds"
}
]
}
],
"rolls": 1.0
},
{
"bonus_rolls": 0.0,
"conditions": [
{
"block": "tutorialmod:radish_crop",
"condition": "minecraft:block_state_property",
"properties": {
"age": "3"
}
}
],
"entries": [
{
"type": "minecraft:item",
"functions": [
{
"enchantment": "minecraft:fortune",
"formula": "minecraft:binomial_with_bonus_count",
"function": "minecraft:apply_bonus",
"parameters": {
"extra": 3,
"probability": 0.5714286
}
}
],
"name": "tutorialmod:radish_seeds"
}
],
"rolls": 1.0
}
],
"random_sequence": "tutorialmod:blocks/radish_crop"
}
4 changes: 4 additions & 0 deletions src/main/java/net/kaupenjoe/tutorialmod/block/ModBlocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import net.kaupenjoe.tutorialmod.TutorialMod;
import net.kaupenjoe.tutorialmod.block.custom.BismuthLampBlock;
import net.kaupenjoe.tutorialmod.block.custom.MagicBlock;
import net.kaupenjoe.tutorialmod.block.custom.RadishCropBlock;
import net.kaupenjoe.tutorialmod.item.ModItems;
import net.kaupenjoe.tutorialmod.sound.ModSounds;
import net.minecraft.util.valueproviders.UniformInt;
Expand Down Expand Up @@ -63,6 +64,9 @@ public class ModBlocks {
() -> new BismuthLampBlock(BlockBehaviour.Properties.of().strength(2f)
.requiresCorrectToolForDrops().lightLevel(state -> state.getValue(BismuthLampBlock.CLICKED) ? 15 : 0)));

public static final DeferredBlock<Block> RADISH_CROP = BLOCKS.register("radish_crop",
() -> new RadishCropBlock(BlockBehaviour.Properties.ofFullCopy(Blocks.BEETROOTS)));


private static <T extends Block> DeferredBlock<T> registerBlock(String name, Supplier<T> block) {
DeferredBlock<T> toReturn = BLOCKS.register(name, block);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package net.kaupenjoe.tutorialmod.block.custom;

import net.kaupenjoe.tutorialmod.item.ModItems;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.ItemLike;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.CropBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.IntegerProperty;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;

public class RadishCropBlock extends CropBlock {
public static final int MAX_AGE = 3;
public static final IntegerProperty AGE = IntegerProperty.create("age", 0, 3);
private static final VoxelShape[] SHAPE_BY_AGE =
new VoxelShape[]{
Block.box(0.0, 0.0, 0.0, 16.0, 2.0, 16.0),
Block.box(0.0, 0.0, 0.0, 16.0, 4.0, 16.0),
Block.box(0.0, 0.0, 0.0, 16.0, 6.0, 16.0),
Block.box(0.0, 0.0, 0.0, 16.0, 8.0, 16.0)};


public RadishCropBlock(Properties properties) {
super(properties);
}

@Override
protected VoxelShape getShape(BlockState state, BlockGetter level, BlockPos pos, CollisionContext context) {
return SHAPE_BY_AGE[state.getValue(AGE)];
}

@Override
protected ItemLike getBaseSeedId() {
return ModItems.RADISH_SEEDS;
}

@Override
public IntegerProperty getAgeProperty() {
return AGE;
}

@Override
public int getMaxAge() {
return MAX_AGE;
}

@Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
builder.add(AGE);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package net.kaupenjoe.tutorialmod.datagen;

import net.kaupenjoe.tutorialmod.block.ModBlocks;
import net.kaupenjoe.tutorialmod.block.custom.RadishCropBlock;
import net.kaupenjoe.tutorialmod.item.ModItems;
import net.minecraft.advancements.critereon.StatePropertiesPredicate;
import net.minecraft.core.Holder;
import net.minecraft.core.HolderLookup;
import net.minecraft.core.registries.Registries;
Expand All @@ -15,6 +17,8 @@
import net.minecraft.world.level.storage.loot.entries.LootItem;
import net.minecraft.world.level.storage.loot.functions.ApplyBonusCount;
import net.minecraft.world.level.storage.loot.functions.SetItemCountFunction;
import net.minecraft.world.level.storage.loot.predicates.LootItemBlockStatePropertyCondition;
import net.minecraft.world.level.storage.loot.predicates.LootItemCondition;
import net.minecraft.world.level.storage.loot.providers.number.UniformGenerator;

import java.util.Set;
Expand Down Expand Up @@ -51,6 +55,12 @@ protected void generate() {

dropSelf(ModBlocks.BISMUTH_LAMP.get());

LootItemCondition.Builder lootItemConditionBuilder = LootItemBlockStatePropertyCondition.hasBlockStateProperties(ModBlocks.RADISH_CROP.get())
.setProperties(StatePropertiesPredicate.Builder.properties().hasProperty(RadishCropBlock.AGE, 3));

this.add(ModBlocks.RADISH_CROP.get(), this.createCropDrops(ModBlocks.RADISH_CROP.get(),
ModItems.RADISH.get(), ModItems.RADISH_SEEDS.get(), lootItemConditionBuilder));

}

protected LootTable.Builder createMultipleOreDrops(Block pBlock, Item item, float minDrops, float maxDrops) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,19 @@
import net.kaupenjoe.tutorialmod.TutorialMod;
import net.kaupenjoe.tutorialmod.block.ModBlocks;
import net.kaupenjoe.tutorialmod.block.custom.BismuthLampBlock;
import net.kaupenjoe.tutorialmod.block.custom.RadishCropBlock;
import net.minecraft.data.PackOutput;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.CropBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.neoforged.neoforge.client.model.generators.BlockStateProvider;
import net.neoforged.neoforge.client.model.generators.ConfiguredModel;
import net.neoforged.neoforge.client.model.generators.ModelFile;
import net.neoforged.neoforge.common.data.ExistingFileHelper;
import net.neoforged.neoforge.registries.DeferredBlock;

import java.util.function.Function;

public class ModBlockStateProvider extends BlockStateProvider {
public ModBlockStateProvider(PackOutput output, ExistingFileHelper exFileHelper) {
super(output, TutorialMod.MOD_ID, exFileHelper);
Expand Down Expand Up @@ -45,6 +50,22 @@ protected void registerStatesAndModels() {
blockItem(ModBlocks.BISMUTH_TRAPDOOR, "_bottom");

customLamp();

makeCrop(((CropBlock) ModBlocks.RADISH_CROP.get()), "radish_crop_stage", "radish_crop_stage");
}

public void makeCrop(CropBlock block, String modelName, String textureName) {
Function<BlockState, ConfiguredModel[]> function = state -> states(state, block, modelName, textureName);

getVariantBuilder(block).forAllStates(function);
}

private ConfiguredModel[] states(BlockState state, CropBlock block, String modelName, String textureName) {
ConfiguredModel[] models = new ConfiguredModel[1];
models[0] = new ConfiguredModel(models().crop(modelName + state.getValue(((RadishCropBlock) block).getAgeProperty()),
ResourceLocation.fromNamespaceAndPath(TutorialMod.MOD_ID, "block/" + textureName + state.getValue(((RadishCropBlock) block).getAgeProperty()))).renderType("cutout"));

return models;
}

private void customLamp() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import net.minecraft.core.HolderLookup;
import net.minecraft.data.PackOutput;
import net.neoforged.neoforge.common.data.DataMapProvider;
import net.neoforged.neoforge.registries.datamaps.builtin.Compostable;
import net.neoforged.neoforge.registries.datamaps.builtin.FurnaceFuel;
import net.neoforged.neoforge.registries.datamaps.builtin.NeoForgeDataMaps;

Expand All @@ -19,5 +20,9 @@ protected void gather() {
this.builder(NeoForgeDataMaps.FURNACE_FUELS)
.add(ModItems.STARLIGHT_ASHES.getId(), new FurnaceFuel(1200), false)
.add(ModItems.FROSTFIRE_ICE.getId(), new FurnaceFuel(2400), false);

this.builder(NeoForgeDataMaps.COMPOSTABLES)
.add(ModItems.RADISH_SEEDS.getId(), new Compostable(0.25f), false)
.add(ModItems.RADISH.getId(), new Compostable(0.45f), false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ protected void registerModels() {
basicItem(ModItems.BISMUTH_HORSE_ARMOR.get());
basicItem(ModItems.KAUPEN_SMITHING_TEMPLATE.get());
basicItem(ModItems.BAR_BRAWL_MUSIC_DISC.get());

basicItem(ModItems.RADISH_SEEDS.get());
}

// Shoutout to El_Redstoniano for making this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public class ModCreativeModeTabs {
output.accept(ModItems.KAUPEN_BOW);

output.accept(ModItems.BAR_BRAWL_MUSIC_DISC);
output.accept(ModItems.RADISH_SEEDS);

}).build());

Expand Down
4 changes: 4 additions & 0 deletions src/main/java/net/kaupenjoe/tutorialmod/item/ModItems.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.kaupenjoe.tutorialmod.item;

import net.kaupenjoe.tutorialmod.TutorialMod;
import net.kaupenjoe.tutorialmod.block.ModBlocks;
import net.kaupenjoe.tutorialmod.item.custom.ChiselItem;
import net.kaupenjoe.tutorialmod.item.custom.FuelItem;
import net.kaupenjoe.tutorialmod.item.custom.HammerItem;
Expand Down Expand Up @@ -86,6 +87,9 @@ public void appendHoverText(ItemStack stack, TooltipContext context, List<Compon
public static final DeferredItem<Item> BAR_BRAWL_MUSIC_DISC = ITEMS.register("bar_brawl_music_disc",
() -> new Item(new Item.Properties().jukeboxPlayable(ModSounds.BAR_BRAWL_KEY).stacksTo(1)));

public static final DeferredItem<Item> RADISH_SEEDS = ITEMS.register("radish_seeds",
() -> new ItemNameBlockItem(ModBlocks.RADISH_CROP.get(), new Item.Properties()));


public static void register(IEventBus eventBus) {
ITEMS.register(eventBus);
Expand Down
Loading

0 comments on commit 364d5c9

Please sign in to comment.