2 block high crops

This commit is contained in:
Kaupenjoe
2023-08-25 19:04:01 +02:00
parent 9df4951e7f
commit f14aa69ed7
35 changed files with 381 additions and 3 deletions

View File

@@ -1,4 +1,6 @@
// 1.20.1 2023-08-23T16:37:35.3734389 Item Models: tutorialmod
// 1.20.1 2023-08-25T18:43:33.7676698 Item Models: tutorialmod
6126e26da373f9113d9e9be875b14a0d13857444 assets/tutorialmod/models/item/corn.json
4c5c277fa6360b149d6c3ab20584fcc4450cda27 assets/tutorialmod/models/item/corn_seeds.json
93719e53df04c62d91023fe733206eb93b7aac86 assets/tutorialmod/models/item/metal_detector.json
d56de8e6898d1c12a15eca045badafe1947aa387 assets/tutorialmod/models/item/pine_cone.json
d24305376f58c1ef118279a5c8f5b087a07b1d47 assets/tutorialmod/models/item/raw_sapphire.json

View File

@@ -1,4 +1,5 @@
// 1.20.1 2023-08-23T16:37:35.3724177 Block States: tutorialmod
// 1.20.1 2023-08-25T18:43:33.7666559 Block States: tutorialmod
d537bf85846bd7eeffa314408c867cc1a7d531d5 assets/tutorialmod/blockstates/corn_crop.json
a3ad172be3e203ff6840db063558f809a86ca15a assets/tutorialmod/blockstates/deepslate_sapphire_ore.json
890efea75d7398469e0d7d5704472303c35fae62 assets/tutorialmod/blockstates/end_stone_sapphire_ore.json
0198f629d0db6eb40ebd91067bbe631626116b54 assets/tutorialmod/blockstates/nether_sapphire_ore.json
@@ -16,6 +17,15 @@ f0189f740d5f66bdbf03bf833b7f89a0439615f8 assets/tutorialmod/blockstates/sapphire
2af36ae7d141d045a91f520bcc8da0c216bf2ccb assets/tutorialmod/blockstates/sapphire_wall.json
7e439f9c39ea91be588ddc78cf4cd903b5b9cb70 assets/tutorialmod/blockstates/sound_block.json
e7f53e64f659401806aad6003e5356aac69c0a08 assets/tutorialmod/blockstates/strawberry_crop.json
1052548f03dcd89a42fba5f0b6255dbb94ccc937 assets/tutorialmod/models/block/corn_stage_0.json
2c3b6838a486dcc1685dc9909d0bd7dbcdadd587 assets/tutorialmod/models/block/corn_stage_1.json
823aa05ad0633dc6fa1f8eb719f161a3d6ade1a1 assets/tutorialmod/models/block/corn_stage_2.json
22ff96e0e02068129316cc59bd124d3aeea7d740 assets/tutorialmod/models/block/corn_stage_3.json
291d7e80fcb45f37492431d833079488c62285ce assets/tutorialmod/models/block/corn_stage_4.json
c959ba97653c4e01203e09e175194b10797d4054 assets/tutorialmod/models/block/corn_stage_5.json
cf760df02741eab6d508ac36d3ffecdef636ce0a assets/tutorialmod/models/block/corn_stage_6.json
3eda0733674b5c29414cb9b19924b13f9e7b4ffb assets/tutorialmod/models/block/corn_stage_7.json
55ed2caa3126b780e9a064f6a73f009a802e85fb assets/tutorialmod/models/block/corn_stage_8.json
f98cb6175399c28ce46a77b4e68664303bc2c3d3 assets/tutorialmod/models/block/deepslate_sapphire_ore.json
0c40efccb23d85e5bdf98a041a64a110359aed7c assets/tutorialmod/models/block/end_stone_sapphire_ore.json
5df59719eaf8bf42bcfeee7e2154e96a044c2703 assets/tutorialmod/models/block/nether_sapphire_ore.json

View File

@@ -1,4 +1,5 @@
// 1.20.1 2023-08-23T16:37:35.3709099 Loot Tables
// 1.20.1 2023-08-25T18:43:33.7656337 Loot Tables
6c9ebf0160580ee21535fe3b1a2a5cd808cacb89 data/tutorialmod/loot_tables/blocks/corn_crop.json
3655045aeb4e2ae62e9069b0db07927965a12389 data/tutorialmod/loot_tables/blocks/deepslate_sapphire_ore.json
629bc7af98fd6a08d902f9c3e46896fc09101f43 data/tutorialmod/loot_tables/blocks/end_stone_sapphire_ore.json
c615daffa6bb4a20fd0f4d36534331bdbeff2746 data/tutorialmod/loot_tables/blocks/nether_sapphire_ore.json

View File

@@ -0,0 +1,31 @@
{
"variants": {
"age=0": {
"model": "tutorialmod:block/corn_stage_0"
},
"age=1": {
"model": "tutorialmod:block/corn_stage_1"
},
"age=2": {
"model": "tutorialmod:block/corn_stage_2"
},
"age=3": {
"model": "tutorialmod:block/corn_stage_3"
},
"age=4": {
"model": "tutorialmod:block/corn_stage_4"
},
"age=5": {
"model": "tutorialmod:block/corn_stage_5"
},
"age=6": {
"model": "tutorialmod:block/corn_stage_6"
},
"age=7": {
"model": "tutorialmod:block/corn_stage_7"
},
"age=8": {
"model": "tutorialmod:block/corn_stage_8"
}
}
}

View File

@@ -0,0 +1,7 @@
{
"parent": "minecraft:block/crop",
"render_type": "minecraft:cutout",
"textures": {
"crop": "tutorialmod:block/corn_stage_0"
}
}

View File

@@ -0,0 +1,7 @@
{
"parent": "minecraft:block/crop",
"render_type": "minecraft:cutout",
"textures": {
"crop": "tutorialmod:block/corn_stage_1"
}
}

View File

@@ -0,0 +1,7 @@
{
"parent": "minecraft:block/crop",
"render_type": "minecraft:cutout",
"textures": {
"crop": "tutorialmod:block/corn_stage_2"
}
}

View File

@@ -0,0 +1,7 @@
{
"parent": "minecraft:block/crop",
"render_type": "minecraft:cutout",
"textures": {
"crop": "tutorialmod:block/corn_stage_3"
}
}

View File

@@ -0,0 +1,7 @@
{
"parent": "minecraft:block/crop",
"render_type": "minecraft:cutout",
"textures": {
"crop": "tutorialmod:block/corn_stage_4"
}
}

View File

@@ -0,0 +1,7 @@
{
"parent": "minecraft:block/crop",
"render_type": "minecraft:cutout",
"textures": {
"crop": "tutorialmod:block/corn_stage_5"
}
}

View File

@@ -0,0 +1,7 @@
{
"parent": "minecraft:block/crop",
"render_type": "minecraft:cutout",
"textures": {
"crop": "tutorialmod:block/corn_stage_6"
}
}

View File

@@ -0,0 +1,7 @@
{
"parent": "minecraft:block/crop",
"render_type": "minecraft:cutout",
"textures": {
"crop": "tutorialmod:block/corn_stage_7"
}
}

View File

@@ -0,0 +1,7 @@
{
"parent": "minecraft:block/crop",
"render_type": "minecraft:cutout",
"textures": {
"crop": "tutorialmod:block/corn_stage_8"
}
}

View File

@@ -0,0 +1,6 @@
{
"parent": "minecraft:item/generated",
"textures": {
"layer0": "tutorialmod:item/corn"
}
}

View File

@@ -0,0 +1,6 @@
{
"parent": "minecraft:item/generated",
"textures": {
"layer0": "tutorialmod:item/corn_seeds"
}
}

View File

@@ -0,0 +1,93 @@
{
"type": "minecraft:block",
"functions": [
{
"function": "minecraft:explosion_decay"
}
],
"pools": [
{
"bonus_rolls": 0.0,
"entries": [
{
"type": "minecraft:alternatives",
"children": [
{
"type": "minecraft:item",
"conditions": [
{
"condition": "minecraft:any_of",
"terms": [
{
"block": "tutorialmod:corn_crop",
"condition": "minecraft:block_state_property",
"properties": {
"age": "7"
}
},
{
"block": "tutorialmod:corn_crop",
"condition": "minecraft:block_state_property",
"properties": {
"age": "8"
}
}
]
}
],
"name": "tutorialmod:corn"
},
{
"type": "minecraft:item",
"name": "tutorialmod:corn_seeds"
}
]
}
],
"rolls": 1.0
},
{
"bonus_rolls": 0.0,
"conditions": [
{
"condition": "minecraft:any_of",
"terms": [
{
"block": "tutorialmod:corn_crop",
"condition": "minecraft:block_state_property",
"properties": {
"age": "7"
}
},
{
"block": "tutorialmod:corn_crop",
"condition": "minecraft:block_state_property",
"properties": {
"age": "8"
}
}
]
}
],
"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:corn_seeds"
}
],
"rolls": 1.0
}
],
"random_sequence": "tutorialmod:blocks/corn_crop"
}

View File

@@ -1,6 +1,7 @@
package net.kaupenjoe.tutorialmod.block;
import net.kaupenjoe.tutorialmod.TutorialMod;
import net.kaupenjoe.tutorialmod.block.custom.CornCropBlock;
import net.kaupenjoe.tutorialmod.block.custom.SoundBlock;
import net.kaupenjoe.tutorialmod.block.custom.StrawberryCropBlock;
import net.kaupenjoe.tutorialmod.item.ModItems;
@@ -72,6 +73,9 @@ public class ModBlocks {
public static final RegistryObject<Block> STRAWBERRY_CROP = BLOCKS.register("strawberry_crop",
() -> new StrawberryCropBlock(BlockBehaviour.Properties.copy(Blocks.WHEAT).noOcclusion().noCollission()));
public static final RegistryObject<Block> CORN_CROP = BLOCKS.register("corn_crop",
() -> new CornCropBlock(BlockBehaviour.Properties.copy(Blocks.WHEAT).noOcclusion().noCollission()));

View File

@@ -0,0 +1,116 @@
package net.kaupenjoe.tutorialmod.block.custom;
import net.kaupenjoe.tutorialmod.item.ModItems;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.ItemLike;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
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;
import net.minecraftforge.common.IPlantable;
public class CornCropBlock extends CropBlock {
public static final int FIRST_STAGE_MAX_AGE = 7;
public static final int SECOND_STAGE_MAX_AGE = 1;
private static final VoxelShape[] SHAPE_BY_AGE = new VoxelShape[]{
Block.box(0.0D, 0.0D, 0.0D, 16.0D, 2.0D, 16.0D),
Block.box(0.0D, 0.0D, 0.0D, 16.0D, 4.0D, 16.0D),
Block.box(0.0D, 0.0D, 0.0D, 16.0D, 6.0D, 16.0D),
Block.box(0.0D, 0.0D, 0.0D, 16.0D, 8.0D, 16.0D),
Block.box(0.0D, 0.0D, 0.0D, 16.0D, 10.0D, 16.0D),
Block.box(0.0D, 0.0D, 0.0D, 16.0D, 12.0D, 16.0D),
Block.box(0.0D, 0.0D, 0.0D, 16.0D, 14.0D, 16.0D),
Block.box(0.0D, 0.0D, 0.0D, 16.0D, 16.0D, 16.0D),
Block.box(0.0D, 0.0D, 0.0D, 16.0D, 16.0D, 16.0D)};
public static final IntegerProperty AGE = IntegerProperty.create("age", 0, 8);
public CornCropBlock(Properties pProperties) {
super(pProperties);
}
@Override
public VoxelShape getShape(BlockState pState, BlockGetter pLevel, BlockPos pPos, CollisionContext pContext) {
return SHAPE_BY_AGE[this.getAge(pState)];
}
public void randomTick(BlockState pState, ServerLevel pLevel, BlockPos pPos, RandomSource pRandom) {
if (!pLevel.isAreaLoaded(pPos, 1)) return;
if (pLevel.getRawBrightness(pPos, 0) >= 9) {
int currentAge = this.getAge(pState);
if (currentAge < this.getMaxAge()) {
float growthSpeed = getGrowthSpeed(this, pLevel, pPos);
if (net.minecraftforge.common.ForgeHooks.onCropsGrowPre(pLevel, pPos, pState, pRandom.nextInt((int)(25.0F / growthSpeed) + 1) == 0)) {
if(currentAge == FIRST_STAGE_MAX_AGE) {
if(pLevel.getBlockState(pPos.above(1)).is(Blocks.AIR)) {
pLevel.setBlock(pPos.above(1), this.getStateForAge(currentAge + 1), 2);
}
} else {
pLevel.setBlock(pPos, this.getStateForAge(currentAge + 1), 2);
}
net.minecraftforge.common.ForgeHooks.onCropsGrowPost(pLevel, pPos, pState);
}
}
}
}
@Override
public boolean canSustainPlant(BlockState state, BlockGetter world, BlockPos pos, Direction facing, IPlantable plantable) {
return super.mayPlaceOn(state, world, pos);
}
@Override
public boolean canSurvive(BlockState pState, LevelReader pLevel, BlockPos pPos) {
return super.canSurvive(pState, pLevel, pPos) || (pLevel.getBlockState(pPos.below(1)).is(this) &&
pLevel.getBlockState(pPos.below(1)).getValue(AGE) == 7);
}
@Override
public void growCrops(Level pLevel, BlockPos pPos, BlockState pState) {
int nextAge = this.getAge(pState) + this.getBonemealAgeIncrease(pLevel);
int maxAge = this.getMaxAge();
if(nextAge > maxAge) {
nextAge = maxAge;
}
if(this.getAge(pState) == FIRST_STAGE_MAX_AGE && pLevel.getBlockState(pPos.above(1)).is(Blocks.AIR)) {
pLevel.setBlock(pPos.above(1), this.getStateForAge(nextAge), 2);
} else {
pLevel.setBlock(pPos, this.getStateForAge(nextAge - SECOND_STAGE_MAX_AGE), 2);
}
}
@Override
public int getMaxAge() {
return FIRST_STAGE_MAX_AGE + SECOND_STAGE_MAX_AGE;
}
@Override
protected ItemLike getBaseSeedId() {
return ModItems.CORN_SEEDS.get();
}
@Override
public IntegerProperty getAgeProperty() {
return AGE;
}
@Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> pBuilder) {
pBuilder.add(AGE);
}
}

View File

@@ -2,6 +2,7 @@ package net.kaupenjoe.tutorialmod.datagen;
import net.kaupenjoe.tutorialmod.TutorialMod;
import net.kaupenjoe.tutorialmod.block.ModBlocks;
import net.kaupenjoe.tutorialmod.block.custom.CornCropBlock;
import net.kaupenjoe.tutorialmod.block.custom.StrawberryCropBlock;
import net.minecraft.data.PackOutput;
import net.minecraft.resources.ResourceLocation;
@@ -45,6 +46,7 @@ public class ModBlockStateProvider extends BlockStateProvider {
trapdoorBlockWithRenderType(((TrapDoorBlock) ModBlocks.SAPPHIRE_TRAPDOOR.get()), modLoc("block/sapphire_trapdoor"), true, "cutout");
makeStrawberryCrop((CropBlock) ModBlocks.STRAWBERRY_CROP.get(), "strawberry_stage", "strawberry_stage");
makeCornCrop(((CropBlock) ModBlocks.CORN_CROP.get()), "corn_stage_", "corn_stage_");
}
@@ -62,6 +64,20 @@ public class ModBlockStateProvider extends BlockStateProvider {
return models;
}
public void makeCornCrop(CropBlock block, String modelName, String textureName) {
Function<BlockState, ConfiguredModel[]> function = state -> cornStates(state, block, modelName, textureName);
getVariantBuilder(block).forAllStates(function);
}
private ConfiguredModel[] cornStates(BlockState state, CropBlock block, String modelName, String textureName) {
ConfiguredModel[] models = new ConfiguredModel[1];
models[0] = new ConfiguredModel(models().crop(modelName + state.getValue(((CornCropBlock) block).getAgeProperty()),
new ResourceLocation(TutorialMod.MOD_ID, "block/" + textureName + state.getValue(((CornCropBlock) block).getAgeProperty()))).renderType("cutout"));
return models;
}
private void blockWithItem(RegistryObject<Block> blockRegistryObject) {
simpleBlockWithItem(blockRegistryObject.get(), cubeAll(blockRegistryObject.get()));
}

View File

@@ -50,6 +50,9 @@ public class ModItemModelProvider extends ItemModelProvider {
simpleItem(ModItems.STRAWBERRY);
simpleItem(ModItems.STRAWBERRY_SEEDS);
simpleItem(ModItems.CORN);
simpleItem(ModItems.CORN_SEEDS);
simpleBlockItem(ModBlocks.SAPPHIRE_DOOR);
fenceItem(ModBlocks.SAPPHIRE_FENCE, ModBlocks.SAPPHIRE_BLOCK);

View File

@@ -1,6 +1,7 @@
package net.kaupenjoe.tutorialmod.datagen.loot;
import net.kaupenjoe.tutorialmod.block.ModBlocks;
import net.kaupenjoe.tutorialmod.block.custom.CornCropBlock;
import net.kaupenjoe.tutorialmod.block.custom.StrawberryCropBlock;
import net.kaupenjoe.tutorialmod.item.ModItems;
import net.minecraft.advancements.critereon.StatePropertiesPredicate;
@@ -62,6 +63,21 @@ public class ModBlockLootTables extends BlockLootSubProvider {
this.add(ModBlocks.STRAWBERRY_CROP.get(), createCropDrops(ModBlocks.STRAWBERRY_CROP.get(), ModItems.STRAWBERRY.get(),
ModItems.STRAWBERRY_SEEDS.get(), lootitemcondition$builder));
LootItemCondition.Builder lootitemcondition$builder2 = LootItemBlockStatePropertyCondition
.hasBlockStateProperties(ModBlocks.CORN_CROP.get())
.setProperties(StatePropertiesPredicate.Builder.properties().hasProperty(CornCropBlock.AGE, 7))
.or(LootItemBlockStatePropertyCondition
.hasBlockStateProperties(ModBlocks.CORN_CROP.get())
.setProperties(StatePropertiesPredicate.Builder.properties().hasProperty(CornCropBlock.AGE, 8)));
// LootItemCondition.Builder lootitemcondition$builder2 = LootItemBlockStatePropertyCondition
// .hasBlockStateProperties(ModBlocks.CORN_CROP.get())
// .setProperties(StatePropertiesPredicate.Builder.properties().hasProperty(CornCropBlock.AGE, 8));
this.add(ModBlocks.CORN_CROP.get(), createCropDrops(ModBlocks.CORN_CROP.get(), ModItems.CORN.get(),
ModItems.CORN_SEEDS.get(), lootitemcondition$builder2));
}
protected LootTable.Builder createCopperLikeOreDrops(Block pBlock, Item item) {

View File

@@ -43,6 +43,9 @@ public class ModCreativeModTabs {
pOutput.accept(ModItems.STRAWBERRY_SEEDS.get());
pOutput.accept(ModItems.CORN.get());
pOutput.accept(ModItems.CORN_SEEDS.get());
pOutput.accept(ModBlocks.SAPPHIRE_BLOCK.get());
pOutput.accept(ModBlocks.RAW_SAPPHIRE_BLOCK.get());

View File

@@ -56,6 +56,11 @@ public class ModItems {
public static final RegistryObject<Item> STRAWBERRY_SEEDS = ITEMS.register("strawberry_seeds",
() -> new ItemNameBlockItem(ModBlocks.STRAWBERRY_CROP.get(), new Item.Properties()));
public static final RegistryObject<Item> CORN_SEEDS = ITEMS.register("corn_seeds",
() -> new ItemNameBlockItem(ModBlocks.CORN_CROP.get(), new Item.Properties()));
public static final RegistryObject<Item> CORN = ITEMS.register("corn",
() -> new Item(new Item.Properties()));
public static void register(IEventBus eventBus) {
ITEMS.register(eventBus);

View File

@@ -20,6 +20,9 @@
"item.tutorialmod.strawberry_seeds": "Strawberry Seeds",
"item.tutorialmod.corn": "Corn",
"item.tutorialmod.corn_seeds": "Corn Seeds",
"block.tutorialmod.sapphire_block": "Block of Sapphire",
"block.tutorialmod.raw_sapphire_block": "Block of Raw Sapphire",

Binary file not shown.

After

Width:  |  Height:  |  Size: 144 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 158 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 188 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 214 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 246 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 237 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 312 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 319 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 331 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 353 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 390 B