From ec61a2d8aa7ffc94b7cbe59337527cac2ff54c26 Mon Sep 17 00:00:00 2001 From: MCZME <13183052+mczme@user.noreply.gitee.com> Date: Mon, 12 Aug 2024 12:49:27 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=EF=BC=9A=E7=A8=BB=E7=B1=B3?= =?UTF-8?q?=E7=9B=B8=E5=85=B3=E6=96=B9=E5=9D=97=E6=9D=90=E8=B4=A8=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E9=AA=A8=E7=B2=89=E5=82=AC=E7=86=9F?= =?UTF-8?q?=E6=97=B6=E6=9C=89=E6=97=B6=E6=B0=B4=E7=A8=BB=E6=97=A0=E6=B3=95?= =?UTF-8?q?=E5=B9=B2=E6=97=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mczme/lingshi/common/block/RiceBlock.java | 46 ++++++++++++++++++ .../common/block/RiceSeedlingTopBlock.java | 19 +++++++- .../assets/lingshi/blockstates/rice.json | 20 ++------ .../assets/lingshi/models/block/rice.json | 7 --- .../assets/lingshi/models/block/rice0.json | 7 +++ .../assets/lingshi/models/block/rice1.json | 7 +++ .../assets/lingshi/models/block/rice2.json | 7 +++ .../assets/lingshi/models/block/rice3.json | 7 +++ .../assets/lingshi/textures/block/rice0.png | Bin 0 -> 103 bytes .../assets/lingshi/textures/block/rice1.png | Bin 0 -> 157 bytes .../assets/lingshi/textures/block/rice2.png | Bin 0 -> 257 bytes .../assets/lingshi/textures/block/rice3.png | Bin 0 -> 368 bytes .../data/lingshi/loot_table/blocks/rice.json | 4 +- 13 files changed, 97 insertions(+), 27 deletions(-) delete mode 100644 src/main/resources/assets/lingshi/models/block/rice.json create mode 100644 src/main/resources/assets/lingshi/models/block/rice0.json create mode 100644 src/main/resources/assets/lingshi/models/block/rice1.json create mode 100644 src/main/resources/assets/lingshi/models/block/rice2.json create mode 100644 src/main/resources/assets/lingshi/models/block/rice3.json create mode 100644 src/main/resources/assets/lingshi/textures/block/rice0.png create mode 100644 src/main/resources/assets/lingshi/textures/block/rice1.png create mode 100644 src/main/resources/assets/lingshi/textures/block/rice2.png create mode 100644 src/main/resources/assets/lingshi/textures/block/rice3.png diff --git a/src/main/java/mczme/lingshi/common/block/RiceBlock.java b/src/main/java/mczme/lingshi/common/block/RiceBlock.java index f388241..c3ebd48 100644 --- a/src/main/java/mczme/lingshi/common/block/RiceBlock.java +++ b/src/main/java/mczme/lingshi/common/block/RiceBlock.java @@ -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 pBuilder) { + pBuilder.add(AGE); + } + } diff --git a/src/main/java/mczme/lingshi/common/block/RiceSeedlingTopBlock.java b/src/main/java/mczme/lingshi/common/block/RiceSeedlingTopBlock.java index 0a12db8..32c6170 100644 --- a/src/main/java/mczme/lingshi/common/block/RiceSeedlingTopBlock.java +++ b/src/main/java/mczme/lingshi/common/block/RiceSeedlingTopBlock.java @@ -3,6 +3,8 @@ 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; @@ -10,15 +12,15 @@ 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; @@ -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; diff --git a/src/main/resources/assets/lingshi/blockstates/rice.json b/src/main/resources/assets/lingshi/blockstates/rice.json index b8a6fb9..d5abfd3 100644 --- a/src/main/resources/assets/lingshi/blockstates/rice.json +++ b/src/main/resources/assets/lingshi/blockstates/rice.json @@ -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" } } } \ No newline at end of file diff --git a/src/main/resources/assets/lingshi/models/block/rice.json b/src/main/resources/assets/lingshi/models/block/rice.json deleted file mode 100644 index e1f6101..0000000 --- a/src/main/resources/assets/lingshi/models/block/rice.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "parent": "block/cross", - "render_type": "minecraft:cutout", - "textures": { - "cross": "lingshi:block/riceseedling_age0" - } -} \ No newline at end of file diff --git a/src/main/resources/assets/lingshi/models/block/rice0.json b/src/main/resources/assets/lingshi/models/block/rice0.json new file mode 100644 index 0000000..49574c6 --- /dev/null +++ b/src/main/resources/assets/lingshi/models/block/rice0.json @@ -0,0 +1,7 @@ +{ + "parent": "block/crop", + "render_type": "minecraft:cutout", + "textures": { + "crop": "lingshi:block/rice0" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/lingshi/models/block/rice1.json b/src/main/resources/assets/lingshi/models/block/rice1.json new file mode 100644 index 0000000..2a42842 --- /dev/null +++ b/src/main/resources/assets/lingshi/models/block/rice1.json @@ -0,0 +1,7 @@ +{ + "parent": "block/crop", + "render_type": "minecraft:cutout", + "textures": { + "crop": "lingshi:block/rice1" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/lingshi/models/block/rice2.json b/src/main/resources/assets/lingshi/models/block/rice2.json new file mode 100644 index 0000000..b3c13ad --- /dev/null +++ b/src/main/resources/assets/lingshi/models/block/rice2.json @@ -0,0 +1,7 @@ +{ + "parent": "block/crop", + "render_type": "minecraft:cutout", + "textures": { + "crop": "lingshi:block/rice2" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/lingshi/models/block/rice3.json b/src/main/resources/assets/lingshi/models/block/rice3.json new file mode 100644 index 0000000..e4d7a28 --- /dev/null +++ b/src/main/resources/assets/lingshi/models/block/rice3.json @@ -0,0 +1,7 @@ +{ + "parent": "block/crop", + "render_type": "minecraft:cutout", + "textures": { + "crop": "lingshi:block/rice3" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/lingshi/textures/block/rice0.png b/src/main/resources/assets/lingshi/textures/block/rice0.png new file mode 100644 index 0000000000000000000000000000000000000000..c4dbf6b633cf700e187236de3af451cf0527541e GIT binary patch literal 103 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`dY&$hAr`&K2@%TGSp4I06Kdu-al-M8t|Hw+t$Um{~65Ucv8JaW&m)!iWCkfQa;OXk;vd$@?2>_qC BAzlCg literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/lingshi/textures/block/rice1.png b/src/main/resources/assets/lingshi/textures/block/rice1.png new file mode 100644 index 0000000000000000000000000000000000000000..541e99f51dda01666f6540cc61df1b89acce6f97 GIT binary patch literal 157 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`DV{ElAr`&K2@bP0l+XkK DyHz<9 literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/lingshi/textures/block/rice2.png b/src/main/resources/assets/lingshi/textures/block/rice2.png new file mode 100644 index 0000000000000000000000000000000000000000..3f80590db8589956aaa9178b49b5140ee9069b09 GIT binary patch literal 257 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Cp=voLo9le6C_x#FdM1o{-3PW zC;H*s#UK6W+B+W_b+FD){IhEjkN+8dV<2FLFTSo8DjlE1zflNzcFXpTAh~ z&iWfX2hs%Cb|3#?fBE?o>7Em6|LVVSA9~=%6(93vef@&O4`2D2yEaQmNc_A1uWkC- zd&z(Pr~h?zQ)6ReYn%U7TymnQAala2nH;NB7#J@1CrQno-@5_mCk9VfKbLh*2~7af Cmv7hr literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/lingshi/textures/block/rice3.png b/src/main/resources/assets/lingshi/textures/block/rice3.png new file mode 100644 index 0000000000000000000000000000000000000000..e780e9b54e25b646103fd823f58c3fc0765fa24b GIT binary patch literal 368 zcmV-$0gwKPP)h={Q2V(B=?nD7i*j(&Y+t8~_ojC@mI3B1kJ^Te6qJ zti5qeM8{NbX5PH{(ZGM$)va$VmVY6+7~t(Cuko(}T?K6+0NE8BPBCtmwoni?VzNyf zPB8%6HNyH9TiYxVpRf6G5x{7U=@RT(VKm3cc479>;NcV#L{)w~Q|9q57n6mmbG<}W zN8GLvy+j?28${K(0Mai3*uQHg3uVGURY$blOwjDKSt4u)cRF_+YXacn=FAAcKx95e zsM#zL<5@Lo+kaYVVOP>|iB~ISJ~}ShJse*gK*uHOym=cPS1U}My*UEI^J>