From 6b82ce141f83e8804686bd322b94cd9ed9457186 Mon Sep 17 00:00:00 2001 From: MCZME <13183052+mczme@user.noreply.gitee.com> Date: Sat, 3 Aug 2024 03:40:00 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=EF=BC=9A=E7=A8=BB=E7=A9=97?= =?UTF-8?q?=EF=BC=8C=E7=A8=BB=E8=8B=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../59eb3dbb5f86130e09b3c62d89b9525ee01cf52d | 3 +- .../data/lingshi/loot_table/blocks/rice.json | 21 -- .../lingshi/common/block/RiceSeedling.java | 56 ----- .../common/block/RiceSeedlingBlock.java | 202 ++++++++++++++++++ .../common/block/RiceSeedlingTopBlock.java | 86 ++++++++ .../lingshi/common/createtab/CreateTabs.java | 6 +- .../lingshi/common/data/DataGenerators.java | 4 +- .../lingshi/common/data/loot/BlockLoot.java | 5 +- .../lingshi/common/item/RiceSeedlingItem.java | 31 +++ .../lingshi/common/registry/ModBlocks.java | 7 +- .../lingshi/common/registry/ModItems.java | 15 +- src/main/java/mczme/lingshi/lingshi.java | 3 +- .../assets/lingshi/blockstates/rice.json | 28 +++ .../lingshi/blockstates/rice_seedling.json | 16 ++ .../blockstates/rice_seedling_top.json | 19 ++ .../resources/assets/lingshi/lang/zh_cn.json | 4 +- .../assets/lingshi/models/block/rice.json | 7 + .../models/block/riceseedling_age0.json | 7 + .../models/block/riceseedling_emerge.json | 7 + .../models/block/riceseedling_top_age0.json | 7 + .../models/block/riceseedling_top_age1.json | 7 + .../models/block/riceseedling_top_age2.json | 7 + .../models/block/riceseedling_top_age3.json | 7 + .../models/block/riceseedling_top_age4.json | 7 + .../textures/block/riceseedling_age0.png | Bin 0 -> 322 bytes .../textures/block/riceseedling_emerge.png | Bin 0 -> 458 bytes .../textures/block/riceseedling_top_age0.png | Bin 0 -> 164 bytes .../textures/block/riceseedling_top_age1.png | Bin 0 -> 412 bytes .../textures/block/riceseedling_top_age3.png | Bin 0 -> 551 bytes .../data/lingshi/loot_table/blocks/rice.json | 46 ++++ .../loot_table/blocks/rice_seedling.json | 26 +++ .../loot_table/blocks/rice_seedling_top.json | 25 +++ 32 files changed, 567 insertions(+), 92 deletions(-) delete mode 100644 src/generated/resources/data/lingshi/loot_table/blocks/rice.json delete mode 100644 src/main/java/mczme/lingshi/common/block/RiceSeedling.java create mode 100644 src/main/java/mczme/lingshi/common/block/RiceSeedlingBlock.java create mode 100644 src/main/java/mczme/lingshi/common/block/RiceSeedlingTopBlock.java create mode 100644 src/main/java/mczme/lingshi/common/item/RiceSeedlingItem.java create mode 100644 src/main/resources/assets/lingshi/blockstates/rice.json create mode 100644 src/main/resources/assets/lingshi/blockstates/rice_seedling.json create mode 100644 src/main/resources/assets/lingshi/blockstates/rice_seedling_top.json create mode 100644 src/main/resources/assets/lingshi/models/block/rice.json create mode 100644 src/main/resources/assets/lingshi/models/block/riceseedling_age0.json create mode 100644 src/main/resources/assets/lingshi/models/block/riceseedling_emerge.json create mode 100644 src/main/resources/assets/lingshi/models/block/riceseedling_top_age0.json create mode 100644 src/main/resources/assets/lingshi/models/block/riceseedling_top_age1.json create mode 100644 src/main/resources/assets/lingshi/models/block/riceseedling_top_age2.json create mode 100644 src/main/resources/assets/lingshi/models/block/riceseedling_top_age3.json create mode 100644 src/main/resources/assets/lingshi/models/block/riceseedling_top_age4.json create mode 100644 src/main/resources/assets/lingshi/textures/block/riceseedling_age0.png create mode 100644 src/main/resources/assets/lingshi/textures/block/riceseedling_emerge.png create mode 100644 src/main/resources/assets/lingshi/textures/block/riceseedling_top_age0.png create mode 100644 src/main/resources/assets/lingshi/textures/block/riceseedling_top_age1.png create mode 100644 src/main/resources/assets/lingshi/textures/block/riceseedling_top_age3.png create mode 100644 src/main/resources/data/lingshi/loot_table/blocks/rice.json create mode 100644 src/main/resources/data/lingshi/loot_table/blocks/rice_seedling.json create mode 100644 src/main/resources/data/lingshi/loot_table/blocks/rice_seedling_top.json diff --git a/src/generated/resources/.cache/59eb3dbb5f86130e09b3c62d89b9525ee01cf52d b/src/generated/resources/.cache/59eb3dbb5f86130e09b3c62d89b9525ee01cf52d index d425272..8304c28 100644 --- a/src/generated/resources/.cache/59eb3dbb5f86130e09b3c62d89b9525ee01cf52d +++ b/src/generated/resources/.cache/59eb3dbb5f86130e09b3c62d89b9525ee01cf52d @@ -1,2 +1 @@ -// 1.21 2024-08-01T22:24:42.609971 Loot Tables -b82daccc5f953aaa0327a61f85766c8394427685 data/lingshi/loot_table/blocks/rice.json +// 1.21 2024-08-02T19:21:51.9075616 Loot Tables diff --git a/src/generated/resources/data/lingshi/loot_table/blocks/rice.json b/src/generated/resources/data/lingshi/loot_table/blocks/rice.json deleted file mode 100644 index 783a9fd..0000000 --- a/src/generated/resources/data/lingshi/loot_table/blocks/rice.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "type": "minecraft:block", - "pools": [ - { - "bonus_rolls": 0.0, - "conditions": [ - { - "condition": "minecraft:survives_explosion" - } - ], - "entries": [ - { - "type": "minecraft:item", - "name": "lingshi:rice" - } - ], - "rolls": 1.0 - } - ], - "random_sequence": "lingshi:blocks/rice" -} \ No newline at end of file diff --git a/src/main/java/mczme/lingshi/common/block/RiceSeedling.java b/src/main/java/mczme/lingshi/common/block/RiceSeedling.java deleted file mode 100644 index 5566664..0000000 --- a/src/main/java/mczme/lingshi/common/block/RiceSeedling.java +++ /dev/null @@ -1,56 +0,0 @@ -package mczme.lingshi.common.block; - -import com.mojang.serialization.MapCodec; -import net.minecraft.core.BlockPos; -import net.minecraft.server.level.ServerLevel; -import net.minecraft.util.RandomSource; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.level.BlockGetter; -import net.minecraft.world.level.Level; -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.BonemealableBlock; -import net.minecraft.world.level.block.BushBlock; -import net.minecraft.world.level.block.LiquidBlockContainer; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.material.Fluid; -import net.minecraft.world.level.material.FluidState; -import org.jetbrains.annotations.Nullable; - -public class RiceSeedling extends BushBlock implements BonemealableBlock, LiquidBlockContainer { - - public RiceSeedling(Properties properties) { - super(properties); - } - - @Override - protected MapCodec codec() { - return null; - } - - @Override - public boolean isValidBonemealTarget(LevelReader pLevel, BlockPos pPos, BlockState pState) { - return false; - } - - @Override - public boolean isBonemealSuccess(Level pLevel, RandomSource pRandom, BlockPos pPos, BlockState pState) { - return false; - } - - @Override - public void performBonemeal(ServerLevel pLevel, RandomSource pRandom, BlockPos pPos, BlockState pState) { - - } - - @Override - public boolean canPlaceLiquid(@Nullable Player pPlayer, BlockGetter pLevel, BlockPos pPos, BlockState pState, Fluid pFluid) { - return false; - } - - @Override - public boolean placeLiquid(LevelAccessor pLevel, BlockPos pPos, BlockState pState, FluidState pFluidState) { - return false; - } -} diff --git a/src/main/java/mczme/lingshi/common/block/RiceSeedlingBlock.java b/src/main/java/mczme/lingshi/common/block/RiceSeedlingBlock.java new file mode 100644 index 0000000..340b3cb --- /dev/null +++ b/src/main/java/mczme/lingshi/common/block/RiceSeedlingBlock.java @@ -0,0 +1,202 @@ +package mczme.lingshi.common.block; + +import com.mojang.serialization.MapCodec; +import mczme.lingshi.common.registry.ModBlocks; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.tags.BlockTags; +import net.minecraft.tags.FluidTags; +import net.minecraft.util.Mth; +import net.minecraft.util.RandomSource; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.context.BlockPlaceContext; +import net.minecraft.world.level.BlockGetter; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.LevelAccessor; +import net.minecraft.world.level.LevelReader; +import net.minecraft.world.level.block.*; +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.BooleanProperty; +import net.minecraft.world.level.block.state.properties.DoubleBlockHalf; +import net.minecraft.world.level.block.state.properties.IntegerProperty; +import net.minecraft.world.level.material.Fluid; +import net.minecraft.world.level.material.FluidState; +import net.minecraft.world.level.material.Fluids; +import net.minecraft.world.level.material.PushReaction; +import net.minecraft.world.phys.shapes.CollisionContext; +import net.minecraft.world.phys.shapes.VoxelShape; +import org.jetbrains.annotations.Nullable; + +public class RiceSeedlingBlock extends BushBlock implements BonemealableBlock, LiquidBlockContainer { + + public static final BooleanProperty EMERGE = BooleanProperty.create("emerge"); + public static final IntegerProperty AGE = BlockStateProperties.AGE_1; + public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED; + public static final VoxelShape[] SHAPE = new VoxelShape[]{ + Block.box(2.0D, 0.0D, 2.0D, 14.0D, 12.0D, 14.0D), + Block.box(2.0D, 0.0D, 2.0D, 14.0D, 16.0D, 14.0D) + }; + + public RiceSeedlingBlock(Properties properties) { + super(properties.noCollission().instabreak().sound(SoundType.CROP).pushReaction(PushReaction.DESTROY).randomTicks()); + this.registerDefaultState(this.defaultBlockState().setValue(EMERGE, false).setValue(AGE, 0).setValue(WATERLOGGED, true)); + } + + public IntegerProperty getAgeProperty() { + return AGE; + } + + protected int getAge(BlockState state) { + return state.getValue(this.getAgeProperty()); + } + + public int getMaxAge() { + return 1; + } + + public BlockState getStateForAge(int pAge) { + return this.defaultBlockState().setValue(this.getAgeProperty(), pAge); + } + + @Override + public void randomTick(BlockState pState, ServerLevel pLevel, BlockPos pPos, RandomSource pRandom) { + super.tick(pState, pLevel, pPos, pRandom); + if (!pLevel.isAreaLoaded(pPos, 1)) return; + if (pLevel.getRawBrightness(pPos.above(), 0) >= 6) { + int age = getAge(pState); + boolean isEmerge = pState.getValue(EMERGE); + if (age <= getMaxAge()) { + float f = 12.0F; + if (net.neoforged.neoforge.common.CommonHooks.canCropGrow(pLevel, pPos, pState, pRandom.nextInt((int) (25.0F / f) + 1) == 0)) { + if (age != getMaxAge()) { + pLevel.setBlock(pPos, this.getStateForAge(age + 1), 2); + net.neoforged.neoforge.common.CommonHooks.fireCropGrowPost(pLevel, pPos, pState); + } else if (!isEmerge) { + RiceSeedlingTopBlock topBlock = ModBlocks.RICE_SEEDING_TOP.get(); + if (topBlock.defaultBlockState().canSurvive(pLevel, pPos.above()) && pLevel.isEmptyBlock(pPos.above())) { + pLevel.setBlockAndUpdate(pPos, pState.setValue(EMERGE, true)); + pLevel.setBlockAndUpdate(pPos.above(), topBlock.defaultBlockState()); + net.neoforged.neoforge.common.CommonHooks.fireCropGrowPost(pLevel, pPos, pState); + } + } else if (pLevel.getBlockState(pPos.above()).is(ModBlocks.RICE_SEEDING_TOP.get())) { + if (pLevel.getBlockState(pPos.above()).getValue(RiceSeedlingTopBlock.AGE) == 4) { + pLevel.setBlockAndUpdate(pPos, pState.setValue(WATERLOGGED, false)); + } + } + } + } + } + } + + @Override + public BlockState updateShape(BlockState pState, Direction pFacing, BlockState pFacingState, LevelAccessor pLevel, BlockPos pCurrentPos, BlockPos pFacingPos) { + if (!pState.canSurvive(pLevel, pCurrentPos)) { + return Blocks.AIR.defaultBlockState(); + } else { + if (pState.getValue(WATERLOGGED)) { + pLevel.scheduleTick(pCurrentPos, Fluids.WATER, Fluids.WATER.getTickDelay(pLevel)); + } + return super.updateShape(pState, pFacing, pFacingState, pLevel, pCurrentPos, pFacingPos); + } + } + + @Override + protected MapCodec codec() { + return null; + } + + @Override + protected VoxelShape getShape(BlockState pState, BlockGetter pLevel, BlockPos pPos, CollisionContext pContext) { + return SHAPE[getAge(pState)]; + } + + @Override + public boolean isValidBonemealTarget(LevelReader pLevel, BlockPos pPos, BlockState pState) { + BlockState upperState = pLevel.getBlockState(pPos.above()); + if (upperState.getBlock() instanceof RiceSeedlingTopBlock) { + return !((RiceSeedlingTopBlock) upperState.getBlock()).isMaxAge(upperState); + } + return true; + } + + @Override + public boolean isBonemealSuccess(Level pLevel, RandomSource pRandom, BlockPos pPos, BlockState pState) { + return true; + } + + protected int getBonemealAgeIncrease(Level level) { + return Mth.nextInt(level.random, 1, 2); + } + + @Override + public void performBonemeal(ServerLevel pLevel, RandomSource pRandom, BlockPos pPos, BlockState pState) { + int ageGrowth = Math.min(this.getAge(pState) + this.getBonemealAgeIncrease(pLevel), 4); + if (ageGrowth <= this.getMaxAge()) { + pLevel.setBlockAndUpdate(pPos, pState.setValue(AGE, ageGrowth)); + } else { + BlockState top = pLevel.getBlockState(pPos.above()); + if (top.getBlock() == ModBlocks.RICE_SEEDING_TOP.get()) { + BonemealableBlock growable = (BonemealableBlock) pLevel.getBlockState(pPos.above()).getBlock(); + if (growable.isValidBonemealTarget(pLevel, pPos.above(), top)) { + growable.performBonemeal(pLevel, pLevel.random, pPos.above(), top); + } + if (pLevel.getBlockState(pPos.above()).getValue(RiceSeedlingTopBlock.AGE) == 4) { + pLevel.setBlockAndUpdate(pPos, pState.setValue(WATERLOGGED, false)); + } + } else { + RiceSeedlingTopBlock riceUpper = ModBlocks.RICE_SEEDING_TOP.get(); + int remainingGrowth = ageGrowth - this.getMaxAge() - 1; + if (riceUpper.defaultBlockState().canSurvive(pLevel, pPos.above()) && pLevel.isEmptyBlock(pPos.above())) { + pLevel.setBlockAndUpdate(pPos, pState.setValue(AGE, this.getMaxAge())); + pLevel.setBlockAndUpdate(pPos, pState.setValue(EMERGE, true)); + pLevel.setBlock(pPos.above(), riceUpper.defaultBlockState().setValue(RiceSeedlingTopBlock.AGE, remainingGrowth), 2); + } + } + } + } + + @Override + protected boolean mayPlaceOn(BlockState state, BlockGetter level, BlockPos pos) { + return super.mayPlaceOn(state, level, pos) || state.is(BlockTags.DIRT); + } + + @Override + public boolean canSurvive(BlockState pState, LevelReader pLevel, BlockPos pPos) { + FluidState fluid = pLevel.getFluidState(pPos); + if (pState.getValue(WATERLOGGED)) { + return super.canSurvive(pState, pLevel, pPos) && fluid.is(FluidTags.WATER) && fluid.getAmount() == 8; + } else { + return super.canSurvive(pState, pLevel, pPos); + } + } + + @Override + @Nullable + public BlockState getStateForPlacement(BlockPlaceContext context) { + FluidState fluid = context.getLevel().getFluidState(context.getClickedPos()); + return fluid.is(FluidTags.WATER) && fluid.getAmount() == 8 ? super.getStateForPlacement(context) : null; + } + + @Override + public boolean canPlaceLiquid(@Nullable Player pPlayer, BlockGetter pLevel, BlockPos pPos, BlockState pState, Fluid pFluid) { + return false; + } + + @Override + public boolean placeLiquid(LevelAccessor pLevel, BlockPos pPos, BlockState pState, FluidState pFluidState) { + return false; + } + + @Override + protected FluidState getFluidState(BlockState pState) { + return pState.getValue(WATERLOGGED) ? Fluids.WATER.getSource(false) : Fluids.EMPTY.defaultFluidState(); + } + + @Override + protected void createBlockStateDefinition(StateDefinition.Builder pBuilder) { + pBuilder.add(EMERGE, AGE, WATERLOGGED); + } +} diff --git a/src/main/java/mczme/lingshi/common/block/RiceSeedlingTopBlock.java b/src/main/java/mczme/lingshi/common/block/RiceSeedlingTopBlock.java new file mode 100644 index 0000000..c1a5e4d --- /dev/null +++ b/src/main/java/mczme/lingshi/common/block/RiceSeedlingTopBlock.java @@ -0,0 +1,86 @@ +package mczme.lingshi.common.block; + +import mczme.lingshi.common.registry.ModBlocks; +import mczme.lingshi.common.registry.ModItems; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +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; + +public class RiceSeedlingTopBlock extends CropBlock { + + public static final IntegerProperty AGE = BlockStateProperties.AGE_4; + private static final VoxelShape[] SHAPE_BY_AGE = new VoxelShape[]{ + Block.box(2, 0.0, 2, 14.0, 8.0, 14.0), + Block.box(2, 0.0, 2, 14.0, 10.0, 14.0), + Block.box(2, 0.0, 2, 14.0, 12.0, 14.0), + Block.box(2, 0.0, 2, 14.0, 14.0, 14.0), + Block.box(2, 0.0, 2, 14.0, 16.0, 14.0) + }; + + public RiceSeedlingTopBlock(Properties properties) { + super(properties.noCollission().instabreak().sound(SoundType.CROP).pushReaction(PushReaction.DESTROY).randomTicks()); + this.registerDefaultState(this.defaultBlockState().setValue(AGE, 0)); + } + + @Override + public void destroy(LevelAccessor pLevel, BlockPos pPos, BlockState pState) { + if (pLevel.getBlockState(pPos.below()).getBlock() instanceof RiceSeedlingBlock) { + pLevel.setBlock(pPos.below(), Blocks.AIR.defaultBlockState(), 2); + } + } + + @Override + public IntegerProperty getAgeProperty() { + return AGE; + } + + @Override + public int getAge(BlockState state) { + return state.getValue(this.getAgeProperty()); + } + + @Override + public int getMaxAge() { + return 4; + } + + @Override + public VoxelShape getShape(BlockState state, BlockGetter level, BlockPos pos, CollisionContext context) { + return SHAPE_BY_AGE[this.getAge(state)]; + } + + + @Override + public boolean canSurvive(BlockState state, LevelReader level, BlockPos pos) { + return (level.getRawBrightness(pos, 0) >= 8 || level.canSeeSky(pos)) && this.mayPlaceOn(level.getBlockState(pos.below()), level, pos); + } + + @Override + protected ItemLike getBaseSeedId() { + return ModItems.RICE_SEEDLING.get(); + } + + @Override + protected boolean mayPlaceOn(BlockState state, BlockGetter level, BlockPos pos) { + return state.is(ModBlocks.RICE_SEEDLING.get()); + } + + @Override + protected void createBlockStateDefinition(StateDefinition.Builder pBuilder) { + pBuilder.add(AGE); + } +} diff --git a/src/main/java/mczme/lingshi/common/createtab/CreateTabs.java b/src/main/java/mczme/lingshi/common/createtab/CreateTabs.java index fe0ab5b..95c7f8e 100644 --- a/src/main/java/mczme/lingshi/common/createtab/CreateTabs.java +++ b/src/main/java/mczme/lingshi/common/createtab/CreateTabs.java @@ -9,17 +9,17 @@ import net.neoforged.neoforge.registries.DeferredHolder; import net.neoforged.neoforge.registries.DeferredRegister; +import static mczme.lingshi.common.registry.ModItems.ITEMS_LIST; import static mczme.lingshi.lingshi.MODID; public class CreateTabs { public static final DeferredRegister CREATIVE_MODE_TABS = DeferredRegister.create(Registries.CREATIVE_MODE_TAB, MODID); public static final DeferredHolder LINGSHI_TAB = CREATIVE_MODE_TABS.register("example_tab", () -> CreativeModeTab.builder() - .title(Component.translatable("lingshi.lingshi_tab")) //The language key for the title of your CreativeModeTab + .title(Component.translatable("lingshi.lingshi_tab")) .withTabsBefore(CreativeModeTabs.COMBAT) .icon(() -> ModItems.RICE.get().getDefaultInstance()) .displayItems((parameters, output) -> { - output.accept(ModItems.RICE.get()); - output.accept(ModItems.RICE_SEEDING.get()); + ITEMS_LIST.forEach(item -> output.accept(item.get())); }).build()); public static void register(IEventBus modEventBus) { diff --git a/src/main/java/mczme/lingshi/common/data/DataGenerators.java b/src/main/java/mczme/lingshi/common/data/DataGenerators.java index 1c6453e..2bfaeb2 100644 --- a/src/main/java/mczme/lingshi/common/data/DataGenerators.java +++ b/src/main/java/mczme/lingshi/common/data/DataGenerators.java @@ -30,7 +30,9 @@ public static void onGatherData(GatherDataEvent event) { // block loot event.getGenerator().addProvider( event.includeServer(), - new LootTableProvider(output, Set.of(), List.of(new LootTableProvider.SubProviderEntry(BlockLoot::new, LootContextParamSets.BLOCK)),lookupProvider) + new LootTableProvider(output, Set.of(), + List.of(new LootTableProvider.SubProviderEntry(BlockLoot::new, LootContextParamSets.BLOCK)), + lookupProvider) ); } } diff --git a/src/main/java/mczme/lingshi/common/data/loot/BlockLoot.java b/src/main/java/mczme/lingshi/common/data/loot/BlockLoot.java index a419d07..6848399 100644 --- a/src/main/java/mczme/lingshi/common/data/loot/BlockLoot.java +++ b/src/main/java/mczme/lingshi/common/data/loot/BlockLoot.java @@ -1,6 +1,7 @@ package mczme.lingshi.common.data.loot; import mczme.lingshi.common.registry.ModBlocks; +import mczme.lingshi.common.registry.ModItems; import net.minecraft.core.HolderLookup; import net.minecraft.data.loot.BlockLootSubProvider; import net.minecraft.world.flag.FeatureFlags; @@ -11,7 +12,7 @@ public class BlockLoot extends BlockLootSubProvider { public static final Set BLOCK = Set.of( - ModBlocks.RICE.get() + ); public BlockLoot(HolderLookup.Provider lookupProvider) { @@ -21,7 +22,7 @@ public BlockLoot(HolderLookup.Provider lookupProvider) { @Override protected void generate() { - this.dropSelf(ModBlocks.RICE.get()); + } @Override diff --git a/src/main/java/mczme/lingshi/common/item/RiceSeedlingItem.java b/src/main/java/mczme/lingshi/common/item/RiceSeedlingItem.java new file mode 100644 index 0000000..990d0a9 --- /dev/null +++ b/src/main/java/mczme/lingshi/common/item/RiceSeedlingItem.java @@ -0,0 +1,31 @@ +package mczme.lingshi.common.item; + +import net.minecraft.core.Direction; +import net.minecraft.tags.BlockTags; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemNameBlockItem; +import net.minecraft.world.item.context.BlockPlaceContext; +import net.minecraft.world.item.context.UseOnContext; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.FarmBlock; +import net.minecraft.world.level.block.state.BlockState; + +public class RiceSeedlingItem extends ItemNameBlockItem { + public RiceSeedlingItem(Block block, Properties properties) { + super(block,properties); + } + + @Override + public InteractionResult useOn(UseOnContext context) { + InteractionResult result = this.place(new BlockPlaceContext(context)); + if (result.equals(InteractionResult.FAIL)) { + Player player = context.getPlayer(); + BlockState targetState = context.getLevel().getBlockState(context.getClickedPos()); + if (player != null && context.getClickedFace().equals(Direction.UP) && (targetState.is(BlockTags.DIRT) || targetState.getBlock() instanceof FarmBlock)) { +// player.displayClientMessage(TextUtils.getTranslation("block.rice.invalid_placement"), true); + } + } + return result; + } +} diff --git a/src/main/java/mczme/lingshi/common/registry/ModBlocks.java b/src/main/java/mczme/lingshi/common/registry/ModBlocks.java index 697fe88..3b13e7d 100644 --- a/src/main/java/mczme/lingshi/common/registry/ModBlocks.java +++ b/src/main/java/mczme/lingshi/common/registry/ModBlocks.java @@ -1,6 +1,7 @@ package mczme.lingshi.common.registry; -import mczme.lingshi.common.block.RiceSeedling; +import mczme.lingshi.common.block.RiceSeedlingBlock; +import mczme.lingshi.common.block.RiceSeedlingTopBlock; import mczme.lingshi.lingshi; import net.minecraft.world.level.block.CropBlock; import net.minecraft.world.level.block.SoundType; @@ -22,7 +23,9 @@ public class ModBlocks { .instabreak() .sound(SoundType.CROP) .pushReaction(PushReaction.DESTROY)); - public static final Supplier RICE_SEEDING = BLOCKS.registerBlock("rice_seeding", RiceSeedling::new, + public static final Supplier RICE_SEEDLING = BLOCKS.registerBlock("rice_seedling", RiceSeedlingBlock::new, + BlockBehaviour.Properties.of()); + public static final Supplier RICE_SEEDING_TOP = BLOCKS.registerBlock("rice_seedling_top", RiceSeedlingTopBlock::new, BlockBehaviour.Properties.of()); public static void register(IEventBus modEventBus) { diff --git a/src/main/java/mczme/lingshi/common/registry/ModItems.java b/src/main/java/mczme/lingshi/common/registry/ModItems.java index 03d834f..9702bdf 100644 --- a/src/main/java/mczme/lingshi/common/registry/ModItems.java +++ b/src/main/java/mczme/lingshi/common/registry/ModItems.java @@ -1,18 +1,29 @@ package mczme.lingshi.common.registry; +import mczme.lingshi.common.item.RiceSeedlingItem; import mczme.lingshi.lingshi; import net.minecraft.world.item.BlockItem; import net.minecraft.world.item.Item; import net.neoforged.bus.api.IEventBus; import net.neoforged.neoforge.registries.DeferredRegister; +import java.util.ArrayList; +import java.util.List; import java.util.function.Supplier; public class ModItems { public static final DeferredRegister.Items ITEMS = DeferredRegister.createItems(lingshi.MODID); + public static final List> ITEMS_LIST = new ArrayList<>(); - public static final Supplier RICE = ITEMS.registerSimpleBlockItem("rice", ModBlocks.RICE, new Item.Properties()); - public static final Supplier RICE_SEEDING =ITEMS.registerSimpleBlockItem("rice_seeding", ModBlocks.RICE_SEEDING, new Item.Properties()); + public static final Supplier RICE = registerWithCreateTab("rice", ()->new BlockItem(ModBlocks.RICE.get(), new Item.Properties())); + public static final Supplier RICE_SEEDLING =registerWithCreateTab("rice_seedling", ()->new RiceSeedlingItem(ModBlocks.RICE_SEEDLING.get(),new Item.Properties())); + public static final Supplier RICE_OF_EAR = registerWithCreateTab("rice_of_ear", () -> new Item(new Item.Properties())); + + private static Supplier registerWithCreateTab(String item_name, Supplier itemSupplier) { + Supplier item = ITEMS.register(item_name, itemSupplier); + ITEMS_LIST.add(item); + return item; + } public static void register(IEventBus modEventBus) { ITEMS.register(modEventBus); diff --git a/src/main/java/mczme/lingshi/lingshi.java b/src/main/java/mczme/lingshi/lingshi.java index f5bf3c5..52e3837 100644 --- a/src/main/java/mczme/lingshi/lingshi.java +++ b/src/main/java/mczme/lingshi/lingshi.java @@ -19,8 +19,7 @@ public class lingshi private static final Logger LOGGER = LogUtils.getLogger(); - // The constructor for the mod class is the first code that is run when your mod is loaded. - // FML will recognize some parameter types like IEventBus or ModContainer and pass them in automatically. + public lingshi(IEventBus modEventBus, ModContainer modContainer) { ModBlocks.register(modEventBus); diff --git a/src/main/resources/assets/lingshi/blockstates/rice.json b/src/main/resources/assets/lingshi/blockstates/rice.json new file mode 100644 index 0000000..b8a6fb9 --- /dev/null +++ b/src/main/resources/assets/lingshi/blockstates/rice.json @@ -0,0 +1,28 @@ +{ + "variants": { + "age=0": { + "model": "lingshi:block/riceseedling_age0" + }, + "age=1": { + "model": "lingshi:block/riceseedling_age0" + }, + "age=2": { + "model": "lingshi:block/riceseedling_age0" + }, + "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" + } + } +} \ No newline at end of file diff --git a/src/main/resources/assets/lingshi/blockstates/rice_seedling.json b/src/main/resources/assets/lingshi/blockstates/rice_seedling.json new file mode 100644 index 0000000..2ec510e --- /dev/null +++ b/src/main/resources/assets/lingshi/blockstates/rice_seedling.json @@ -0,0 +1,16 @@ +{ + "variants": { + "age=0,emerge=false": { + "model": "lingshi:block/riceseedling_age0" + }, + "age=1,emerge=false": { + "model": "lingshi:block/riceseedling_emerge" + }, + "age=0,emerge=true": { + "model": "lingshi:block/riceseedling_emerge" + }, + "age=1,emerge=true": { + "model": "lingshi:block/riceseedling_emerge" + } + } +} \ No newline at end of file diff --git a/src/main/resources/assets/lingshi/blockstates/rice_seedling_top.json b/src/main/resources/assets/lingshi/blockstates/rice_seedling_top.json new file mode 100644 index 0000000..c2b7612 --- /dev/null +++ b/src/main/resources/assets/lingshi/blockstates/rice_seedling_top.json @@ -0,0 +1,19 @@ +{ + "variants": { + "age=0": { + "model": "lingshi:block/riceseedling_top_age0" + }, + "age=1": { + "model": "lingshi:block/riceseedling_top_age1" + }, + "age=2": { + "model": "lingshi:block/riceseedling_top_age2" + }, + "age=3": { + "model": "lingshi:block/riceseedling_top_age3" + }, + "age=4": { + "model": "lingshi:block/riceseedling_top_age4" + } + } +} \ No newline at end of file diff --git a/src/main/resources/assets/lingshi/lang/zh_cn.json b/src/main/resources/assets/lingshi/lang/zh_cn.json index 748e3d9..8e06d42 100644 --- a/src/main/resources/assets/lingshi/lang/zh_cn.json +++ b/src/main/resources/assets/lingshi/lang/zh_cn.json @@ -1,5 +1,7 @@ { "lingshi.lingshi_tab": "灵食", "block.lingshi.rice": "稻米", - "block.lingshi.rice_seeding": "稻苗" + "item.lingshi.rice_seedling": "稻苗", + "item.lingshi.rice_of_ear": "稻穗" + } \ 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 new file mode 100644 index 0000000..e1f6101 --- /dev/null +++ b/src/main/resources/assets/lingshi/models/block/rice.json @@ -0,0 +1,7 @@ +{ + "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/riceseedling_age0.json b/src/main/resources/assets/lingshi/models/block/riceseedling_age0.json new file mode 100644 index 0000000..e1f6101 --- /dev/null +++ b/src/main/resources/assets/lingshi/models/block/riceseedling_age0.json @@ -0,0 +1,7 @@ +{ + "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/riceseedling_emerge.json b/src/main/resources/assets/lingshi/models/block/riceseedling_emerge.json new file mode 100644 index 0000000..90280fc --- /dev/null +++ b/src/main/resources/assets/lingshi/models/block/riceseedling_emerge.json @@ -0,0 +1,7 @@ +{ + "parent": "block/cross", + "render_type": "minecraft:cutout", + "textures": { + "cross": "lingshi:block/riceseedling_emerge" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/lingshi/models/block/riceseedling_top_age0.json b/src/main/resources/assets/lingshi/models/block/riceseedling_top_age0.json new file mode 100644 index 0000000..087728b --- /dev/null +++ b/src/main/resources/assets/lingshi/models/block/riceseedling_top_age0.json @@ -0,0 +1,7 @@ +{ + "parent": "block/cross", + "render_type": "minecraft:cutout", + "textures": { + "cross": "lingshi:block/riceseedling_top_age0" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/lingshi/models/block/riceseedling_top_age1.json b/src/main/resources/assets/lingshi/models/block/riceseedling_top_age1.json new file mode 100644 index 0000000..087728b --- /dev/null +++ b/src/main/resources/assets/lingshi/models/block/riceseedling_top_age1.json @@ -0,0 +1,7 @@ +{ + "parent": "block/cross", + "render_type": "minecraft:cutout", + "textures": { + "cross": "lingshi:block/riceseedling_top_age0" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/lingshi/models/block/riceseedling_top_age2.json b/src/main/resources/assets/lingshi/models/block/riceseedling_top_age2.json new file mode 100644 index 0000000..dc451ff --- /dev/null +++ b/src/main/resources/assets/lingshi/models/block/riceseedling_top_age2.json @@ -0,0 +1,7 @@ +{ + "parent": "block/cross", + "render_type": "minecraft:cutout", + "textures": { + "cross": "lingshi:block/riceseedling_top_age1" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/lingshi/models/block/riceseedling_top_age3.json b/src/main/resources/assets/lingshi/models/block/riceseedling_top_age3.json new file mode 100644 index 0000000..dc451ff --- /dev/null +++ b/src/main/resources/assets/lingshi/models/block/riceseedling_top_age3.json @@ -0,0 +1,7 @@ +{ + "parent": "block/cross", + "render_type": "minecraft:cutout", + "textures": { + "cross": "lingshi:block/riceseedling_top_age1" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/lingshi/models/block/riceseedling_top_age4.json b/src/main/resources/assets/lingshi/models/block/riceseedling_top_age4.json new file mode 100644 index 0000000..c9f8923 --- /dev/null +++ b/src/main/resources/assets/lingshi/models/block/riceseedling_top_age4.json @@ -0,0 +1,7 @@ +{ + "parent": "block/cross", + "render_type": "minecraft:cutout", + "textures": { + "cross": "lingshi:block/riceseedling_top_age3" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/lingshi/textures/block/riceseedling_age0.png b/src/main/resources/assets/lingshi/textures/block/riceseedling_age0.png new file mode 100644 index 0000000000000000000000000000000000000000..003b8083db5840cb697316436c5363913ac72a53 GIT binary patch literal 322 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`jKx9jP7LeL$-D$|SkfJR9T^xl z_H+M9WCij$3p^r=85sBugD~Uq{1quc!Rwwbjv*HQ$r5u8Yzz8rKgHATKpKZ*^F+}V z?U{=-jxC+Z>D7Gj;kVU2C%6)G1pdByXTL$h%E6F<#evIFDsSDca~z^f%q4a_2@(v! z9dB4uZeQHnmdL=-VA7#!+?Z*qo+_fha5u~9%?=D{m;amZKTuOx%(tQO1zW-nhFE2w zvi&wcnb%0(<&KDD2x`e;Sj-`P!$H9J0;>W;(3;4Gb6<@@=xR_so544D=#{ Mr>mdKI;Vst0175?9smFU literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/lingshi/textures/block/riceseedling_emerge.png b/src/main/resources/assets/lingshi/textures/block/riceseedling_emerge.png new file mode 100644 index 0000000000000000000000000000000000000000..6e63793aa7d083ef24a5003c1cb9c329da1e4563 GIT binary patch literal 458 zcmV;*0X6=KP)Px$gh@m}R5*=wlCes|P!xv08zdNtgAigDiyBarDsJM?4!%H#LZ6@@ZoY-9tKbs| z9r^+;9mG{4q7W$xC5^>SA+|%WL%eBn6aVdA&i|eNoO=bpUT0sv-n|Hb-7{BioU9W1 z3*=-DfUr#**I;n~;1fz}vkqLVrP4j%zS}{6ROT0D#79h=Qojs=JbI z&H--wu_%K$u7OHa{~V&r$R4I)V#sz?u;$u`-b0*r@3t%nu#zq8J;b8xyh{#t7*CQr z)qNT!=j(G@dO^f(KVB|TPtpD!BW#nyc$D6In_C5QAwiksWR9>+F4n&oJVm)N(gfG% zw#<&<1yK&tm<{oQqB#Xz-b_TdWl056^Xj9ODff)9+-_r*JXv#XlqOTPss^+jctJ$H zTEQdAb^PxI017j8Tb8U>D-52JJ*+zkpm9_|HV z0GLyAOyCbvR!GT5I^MRVTTLJ;fr7SAm&;T71p~*(AI|NRy#N3J07*qoM6N<$f_V?c Aod5s; literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/lingshi/textures/block/riceseedling_top_age0.png b/src/main/resources/assets/lingshi/textures/block/riceseedling_top_age0.png new file mode 100644 index 0000000000000000000000000000000000000000..36338576017f56ee731a461885d30e8794113605 GIT binary patch literal 164 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`jKx9jP7LeL$-D$|;yhg(Lo9le z6C_vh{ck^_8F4yR;`TGO+U--q2`YA_TOF!PC{x JWt~$(699=>He&z) literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/lingshi/textures/block/riceseedling_top_age1.png b/src/main/resources/assets/lingshi/textures/block/riceseedling_top_age1.png new file mode 100644 index 0000000000000000000000000000000000000000..71f8f6a8bd923a13deb42046dcf686c0d20aefc2 GIT binary patch literal 412 zcmV;N0b~A&P)Px$R!KxbR5*>zlCev}KorKm1Q9c32^9w&JV>csB#SO}$mY~R$kst9bad`NP{FBF zr$R@IQ-ixhUD_p+T3SfO4q`)5L?qgw&!ODqVxpViTXNyu`|kUGcfh}_LN!l+B9e7- zPx$;Ymb6R5*=wld)@BQ51*2`x1mpkkDdF5QGq^Vw%CBTZzyP$!MUoe}Pci$th6i zn8~RWk|Jd5mLQldI%E*CI|Lrja6u5H*oURqa%l?Q4)#9p)AlTncR1%e=lt$D@E^;+ zDj4^_Rm+%uJ7*T-yhX?EyT=9~IP--I$rmL-SF;H5TD6P;=(lsGRm+&q&wfV`x0_~T z9D~?AVUvTdCSQ~^8)H6wdl2hj_gA0JBuyzfgeDZ^QQL?$$i;6WHV+vWx{^3BZ+T_yY+(+e%$KKc&8$?ZBv#{+z&3A%cznCA*uDa+_Z z3R#H@v>H{)(zrXZ8gwsfm5N(mF*;Vb>O+8U+gFb2py&l-_RP_2jJ{5qtNm3WqF&CYsq zyUxzWTI9D&6`c9P7WI{m-$L(72{+g^6VCOpVpr>-SURR)duyp17g#AvGhe!YT;oVh pd6=EKJCk%&U8E9}l0)2NfIpa47a