Skip to content

Commit

Permalink
添加:茶树,茶叶
Browse files Browse the repository at this point in the history
  • Loading branch information
MCZME committed Aug 6, 2024
1 parent 6b82ce1 commit f5d08e8
Show file tree
Hide file tree
Showing 24 changed files with 542 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
// 1.21 2024-08-02T19:21:51.9075616 Loot Tables
// 1.21 2024-08-06T21:56:13.9856387 Loot Tables
c843630bb0739aad37078f0119c9cc31f5316c3a data/lingshi/loot_table/blocks/tea_leaf.json
3cd0ced47f090fec162cddcb8b2f75284fa134cb data/lingshi/loot_table/blocks/tea_tree.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// 1.21 2024-08-06T21:56:13.987637 Languages: zh_cn for mod: lingshi
e555acbe8820b73ef1de654d149cfca34bba5963 assets/lingshi/lang/zh_cn.json
8 changes: 8 additions & 0 deletions src/generated/resources/assets/lingshi/lang/zh_cn.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"block.lingshi.rice": "稻米",
"block.lingshi.tea_tree": "茶树",
"item.lingshi.rice_of_ear": "稻穗",
"item.lingshi.rice_seedling": "稻苗",
"item.lingshi.tea_leaf": "茶叶",
"lingshi.lingshi_tab": "灵食"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"type": "minecraft:block",
"pools": [
{
"bonus_rolls": 0.0,
"conditions": [
{
"condition": "minecraft:survives_explosion"
}
],
"entries": [
{
"type": "minecraft:item",
"name": "lingshi:tea_leaf"
}
],
"rolls": 1.0
}
],
"random_sequence": "lingshi:blocks/tea_leaf"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"type": "minecraft:block",
"pools": [
{
"bonus_rolls": 0.0,
"conditions": [
{
"condition": "minecraft:survives_explosion"
}
],
"entries": [
{
"type": "minecraft:item",
"name": "lingshi:tea_tree"
}
],
"rolls": 1.0
}
],
"random_sequence": "lingshi:blocks/tea_tree"
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
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;
Expand Down
73 changes: 73 additions & 0 deletions src/main/java/mczme/lingshi/common/block/TeaBlock.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
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.world.level.BlockGetter;
import net.minecraft.world.level.ItemLike;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.block.Block;
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 TeaBlock extends CropBlock {
public static final IntegerProperty AGE = BlockStateProperties.AGE_3;
private static final VoxelShape[] SHAPE_BY_AGE = new VoxelShape[]{
Block.box(0, 0.0, 0, 16.0, 2.0, 16.0),
Block.box(0, 0.0, 0, 16.0, 4.0, 16.0),
Block.box(0, 0.0, 0, 16.0, 6.0, 16.0),
Block.box(0, 0.0, 0, 16.0, 8.0, 16.0)
};

public TeaBlock(Properties properties) {
super(properties.randomTicks().noCollission().instabreak().sound(SoundType.CROP).pushReaction(PushReaction.DESTROY));
}

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

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

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

@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.TEA_LEAF.get();
}

@Override
protected boolean mayPlaceOn(BlockState state, BlockGetter level, BlockPos pos) {
return state.is(ModBlocks.TEA_TREE.get());
}

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

}
143 changes: 143 additions & 0 deletions src/main/java/mczme/lingshi/common/block/TeaTreeBlock.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
package mczme.lingshi.common.block;

import com.mojang.serialization.MapCodec;
import mczme.lingshi.common.registry.ModBlocks;
import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.Mth;
import net.minecraft.util.RandomSource;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.level.BlockGetter;
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.BonemealableBlock;
import net.minecraft.world.level.block.BushBlock;
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.Vec3;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;

public class TeaTreeBlock extends BushBlock implements BonemealableBlock {

public static final IntegerProperty AGE = BlockStateProperties.AGE_3;
public static final VoxelShape[] SHAPE = new VoxelShape[]{Block.box(7.0, 0, 7.0, 10, 10, 10),
Shapes.or(Block.box(7.0, 0, 7.0, 10, 8, 10),Block.box(3.5,8,3.5,12.5,14,12.5)),
Shapes.or(Block.box(7.0, 0, 7.0, 10, 6, 10),Block.box(2.0,6,2,14,14,14)),
Shapes.or(Block.box(7.0, 0, 7.0, 10, 5, 10),Block.box(0,5,0,16,16,16))};

public TeaTreeBlock(Properties properties) {
super(properties.randomTicks().noCollission().instabreak().sound(SoundType.CROP).pushReaction(PushReaction.DESTROY));
this.registerDefaultState(this.defaultBlockState().setValue(AGE, 0));
}

@Override
protected MapCodec<? extends BushBlock> codec() {
return null;
}

public IntegerProperty getAgeProperty() {
return AGE;
}

protected int getAge(BlockState state) {
return state.getValue(this.getAgeProperty());
}

public int getMaxAge() {
return 3;
}

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);
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 {
TeaBlock topBlock = ModBlocks.TEA_LEAF.get();
if (topBlock.defaultBlockState().canSurvive(pLevel, pPos.above()) && pLevel.isEmptyBlock(pPos.above())) {
pLevel.setBlockAndUpdate(pPos.above(), topBlock.defaultBlockState());
net.neoforged.neoforge.common.CommonHooks.fireCropGrowPost(pLevel, pPos, pState);
}
}
}
}
}
}

@Override
public boolean isValidBonemealTarget(LevelReader pLevel, BlockPos pPos, BlockState pState) {
BlockState upperState = pLevel.getBlockState(pPos.above());
if (upperState.getBlock() instanceof TeaBlock) {
return !((TeaBlock) 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), 5);
if (ageGrowth <= this.getMaxAge()) {
pLevel.setBlockAndUpdate(pPos, pState.setValue(AGE, ageGrowth));
} else {
BlockState top = pLevel.getBlockState(pPos.above());
if (top.getBlock() == ModBlocks.TEA_LEAF.get()) {
BonemealableBlock growable = (BonemealableBlock) pLevel.getBlockState(pPos.above()).getBlock();
if (growable.isValidBonemealTarget(pLevel, pPos.above(), top)) {
growable.performBonemeal(pLevel, pLevel.random, pPos.above(), top);
}
} else {
TeaBlock Upper = ModBlocks.TEA_LEAF.get();
int remainingGrowth = ageGrowth - this.getMaxAge() - 1;
if (Upper.defaultBlockState().canSurvive(pLevel, pPos.above()) && pLevel.isEmptyBlock(pPos.above())) {
pLevel.setBlockAndUpdate(pPos, pState.setValue(AGE, this.getMaxAge()));
pLevel.setBlock(pPos.above(), Upper.defaultBlockState().setValue(TeaBlock.AGE, remainingGrowth), 2);
}
}
}
}

@Override
protected void entityInside(BlockState pState, Level pLevel, BlockPos pPos, Entity pEntity) {
if (pEntity instanceof LivingEntity) {
pEntity.makeStuckInBlock(pState, new Vec3(0.8F, 0.75, 0.8F));
}
}

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

@Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> pBuilder) {
pBuilder.add(AGE);
}
}
7 changes: 7 additions & 0 deletions src/main/java/mczme/lingshi/common/data/DataGenerators.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package mczme.lingshi.common.data;

import mczme.lingshi.common.data.lang.ChineseLanguageProvider;
import mczme.lingshi.common.data.loot.BlockLoot;
import mczme.lingshi.lingshi;
import net.minecraft.core.HolderLookup;
Expand Down Expand Up @@ -34,5 +35,11 @@ public static void onGatherData(GatherDataEvent event) {
List.of(new LootTableProvider.SubProviderEntry(BlockLoot::new, LootContextParamSets.BLOCK)),
lookupProvider)
);

// lang datagen
event.getGenerator().addProvider(
event.includeServer(),
new ChineseLanguageProvider(output)
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package mczme.lingshi.common.data.lang;

import mczme.lingshi.common.registry.ModItems;
import net.minecraft.data.PackOutput;
import net.neoforged.neoforge.common.data.LanguageProvider;

import static mczme.lingshi.lingshi.MODID;

public class ChineseLanguageProvider extends LanguageProvider {
public ChineseLanguageProvider(PackOutput output) {
super(output, MODID, "zh_cn");
}

@Override
protected void addTranslations() {
this.add("lingshi.lingshi_tab", "灵食");

this.add(ModItems.RICE.get(), "稻米");
this.add(ModItems.RICE_SEEDLING.get(), "稻苗");
this.add(ModItems.RICE_OF_EAR.get(),"稻穗");

this.add(ModItems.TEA_TREE.get(), "茶树");
this.add(ModItems.TEA_LEAF.get(), "茶叶");
}
}
6 changes: 4 additions & 2 deletions src/main/java/mczme/lingshi/common/data/loot/BlockLoot.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
public class BlockLoot extends BlockLootSubProvider {

public static final Set<Block> BLOCK = Set.of(

ModBlocks.TEA_TREE.get(),
ModBlocks.TEA_LEAF.get()
);

public BlockLoot(HolderLookup.Provider lookupProvider) {
Expand All @@ -22,7 +23,8 @@ public BlockLoot(HolderLookup.Provider lookupProvider) {

@Override
protected void generate() {

dropSelf(ModBlocks.TEA_TREE.get());
dropOther(ModBlocks.TEA_LEAF.get(), ModItems.TEA_LEAF.get());
}

@Override
Expand Down
13 changes: 1 addition & 12 deletions src/main/java/mczme/lingshi/common/item/RiceSeedlingItem.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
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) {
Expand All @@ -19,13 +14,7 @@ public RiceSeedlingItem(Block block, Properties 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;
}
}
Loading

0 comments on commit f5d08e8

Please sign in to comment.