Skip to content

Commit

Permalink
添加:稻米相关方块材质 修复:骨粉催熟时有时水稻无法干旱
Browse files Browse the repository at this point in the history
  • Loading branch information
MCZME committed Aug 12, 2024
1 parent 631ed4b commit ec61a2d
Show file tree
Hide file tree
Showing 13 changed files with 97 additions and 27 deletions.
46 changes: 46 additions & 0 deletions src/main/java/mczme/lingshi/common/block/RiceBlock.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,63 @@
package mczme.lingshi.common.block;

import mczme.lingshi.common.registry.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.BlockStateProperties;
import net.minecraft.world.level.block.state.properties.IntegerProperty;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;
import org.jetbrains.annotations.NotNull;

public class RiceBlock extends CropBlock {

public static final int MAX_AGE = 3;
public static final IntegerProperty AGE = BlockStateProperties.AGE_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, 6.0, 16.0),
Block.box(0.0, 0.0, 0.0, 16.0, 10.0, 16.0),
Block.box(0.0, 0.0, 0.0, 16.0, 14.0, 16.0),
};

public RiceBlock(Properties properties) {
super(properties);
this.registerDefaultState(this.defaultBlockState().setValue(AGE, 0));
}

@Override
protected @NotNull ItemLike getBaseSeedId() {
return ModItems.RICE.get();
}

@Override
protected VoxelShape getShape(BlockState pState, BlockGetter pLevel, BlockPos pPos, CollisionContext pContext) {
return SHAPE_BY_AGE[this.getAge(pState)];
}

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

@Override
public int getAge(BlockState state) {
return state.getValue(this.getAgeProperty());
}

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

@Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> pBuilder) {
pBuilder.add(AGE);
}

}
19 changes: 17 additions & 2 deletions src/main/java/mczme/lingshi/common/block/RiceSeedlingTopBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,24 @@
import mczme.lingshi.common.registry.ModBlocks;
import mczme.lingshi.common.registry.ModItems;
import net.minecraft.core.BlockPos;
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.LevelAccessor;
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.SoundType;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.level.block.state.properties.IntegerProperty;
import net.minecraft.world.level.material.PushReaction;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;

import static mczme.lingshi.common.block.RiceSeedlingBlock.WATERLOGGED;

public class RiceSeedlingTopBlock extends CropBlock {

public static final IntegerProperty AGE = BlockStateProperties.AGE_4;
Expand All @@ -42,6 +44,19 @@ public void destroy(LevelAccessor pLevel, BlockPos pPos, BlockState pState) {
}
}

@Override
public void performBonemeal(ServerLevel pLevel, RandomSource pRandom, BlockPos pPos, BlockState pState) {
int i = this.getAge(pState) + this.getBonemealAgeIncrease(pLevel);
int j = this.getMaxAge();
if (i > j) {
i = j;
}
pLevel.setBlock(pPos, this.getStateForAge(i), 2);
if (i == 4) {
pLevel.setBlockAndUpdate(pPos.below(), pLevel.getBlockState(pPos.below()).setValue(WATERLOGGED, false));
}
}

@Override
public IntegerProperty getAgeProperty() {
return AGE;
Expand Down
20 changes: 4 additions & 16 deletions src/main/resources/assets/lingshi/blockstates/rice.json
Original file line number Diff line number Diff line change
@@ -1,28 +1,16 @@
{
"variants": {
"age=0": {
"model": "lingshi:block/riceseedling_age0"
"model": "lingshi:block/rice0"
},
"age=1": {
"model": "lingshi:block/riceseedling_age0"
"model": "lingshi:block/rice1"
},
"age=2": {
"model": "lingshi:block/riceseedling_age0"
"model": "lingshi:block/rice2"
},
"age=3": {
"model": "lingshi:block/riceseedling_age0"
},
"age=4": {
"model": "lingshi:block/riceseedling_age0"
},
"age=5": {
"model": "lingshi:block/riceseedling_age0"
},
"age=6": {
"model": "lingshi:block/riceseedling_age0"
},
"age=7": {
"model": "lingshi:block/riceseedling_age0"
"model": "lingshi:block/rice3"
}
}
}
7 changes: 0 additions & 7 deletions src/main/resources/assets/lingshi/models/block/rice.json

This file was deleted.

7 changes: 7 additions & 0 deletions src/main/resources/assets/lingshi/models/block/rice0.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"parent": "block/crop",
"render_type": "minecraft:cutout",
"textures": {
"crop": "lingshi:block/rice0"
}
}
7 changes: 7 additions & 0 deletions src/main/resources/assets/lingshi/models/block/rice1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"parent": "block/crop",
"render_type": "minecraft:cutout",
"textures": {
"crop": "lingshi:block/rice1"
}
}
7 changes: 7 additions & 0 deletions src/main/resources/assets/lingshi/models/block/rice2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"parent": "block/crop",
"render_type": "minecraft:cutout",
"textures": {
"crop": "lingshi:block/rice2"
}
}
7 changes: 7 additions & 0 deletions src/main/resources/assets/lingshi/models/block/rice3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"parent": "block/crop",
"render_type": "minecraft:cutout",
"textures": {
"crop": "lingshi:block/rice3"
}
}
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.
4 changes: 2 additions & 2 deletions src/main/resources/data/lingshi/loot_table/blocks/rice.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"condition": "minecraft:block_state_property",
"block": "lingshi:rice",
"properties": {
"age": "7"
"age": "3"
}
}
]
Expand All @@ -36,7 +36,7 @@
"condition": "minecraft:block_state_property",
"block": "lingshi:rice",
"properties": {
"age": "7"
"age": "3"
}
}
}
Expand Down

0 comments on commit ec61a2d

Please sign in to comment.