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 db07960 commit 3804ccf
Show file tree
Hide file tree
Showing 28 changed files with 549 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// 1.21 2024-08-10T17:07:03.6586838 Loot Tables
// 1.21 2024-08-13T03:55:33.7091711 Loot Tables
032b2242788b8411178136ca48214246ef2af8a9 data/lingshi/loot_table/blocks/chopping_board.json
67cc122cf5e7e5865ff9bc81fec6e8371225b0d6 data/lingshi/loot_table/blocks/skillet.json
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
@@ -1,6 +1,7 @@
// 1.21 2024-08-12T10:19:52.413361 Item Models: lingshi
// 1.21 2024-08-13T04:10:11.5053055 Item Models: lingshi
bad0cb5e093fa42331c2d4a1157d1a7b5b3fc588 assets/lingshi/models/item/chopping_board.json
249957a6811e300efca306db358e468855851d73 assets/lingshi/models/item/iron_knife.json
496d711c2d4af0f851d40f859b102da69188089d assets/lingshi/models/item/rice.json
abe8ae1523c26af167289fe958382b2477d96ea1 assets/lingshi/models/item/rice_of_ear.json
57cfb1f90de649ab0f56f107cb56e1d0d2f87ae6 assets/lingshi/models/item/rice_seedling.json
cff85c127954ba63ac8129929c0d7346bf8f305d assets/lingshi/models/item/skillet.json
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// 1.21 2024-08-11T20:03:29.7270915 Languages: zh_cn for mod: lingshi
ceb883a13057e1c30eaabbc27de7a3819e5e58b5 assets/lingshi/lang/zh_cn.json
// 1.21 2024-08-13T03:55:33.7111786 Languages: zh_cn for mod: lingshi
6691b4e3de41dca51664777d2790f94bd059d1ac assets/lingshi/lang/zh_cn.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// 1.21 2024-08-11T19:15:15.9707849 Tags for minecraft:block mod id lingshi
// 1.21 2024-08-13T03:35:37.9402366 Tags for minecraft:block mod id lingshi
639716446e0ad4bc759f5d086b91d0e4a9215ab7 data/lingshi/tags/block/can_support.json
8f3ae1f87856cf69d686ec0be92f6b700f51bd30 data/lingshi/tags/block/heat_source.json
e00d57f2828f9f55903e8c8c9f4b95dfeca4135d data/minecraft/tags/block/mineable/axe.json
1 change: 1 addition & 0 deletions src/generated/resources/assets/lingshi/lang/zh_cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"block.lingshi.chopping_board": "砧板",
"block.lingshi.rice": "稻米",
"block.lingshi.rice_seedling": "稻苗",
"block.lingshi.skillet": "平底锅",
"block.lingshi.tea_tree": "茶树",
"item.lingshi.iron_knife": "铁菜刀",
"item.lingshi.rice_of_ear": "稻穗",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"parent": "lingshi:block/skillet"
}
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:skillet"
}
],
"rolls": 1.0
}
],
"random_sequence": "lingshi:blocks/skillet"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"values": [
"minecraft:campfire"
]
}
4 changes: 2 additions & 2 deletions src/main/java/mczme/lingshi/client/event/Registry.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package mczme.lingshi.client.event;

import mczme.lingshi.client.BlockEntityRenderer.ChoppingBoardBER;
import mczme.lingshi.common.registry.BlockEntitys;
import mczme.lingshi.common.registry.BlockEntityTypes;
import mczme.lingshi.lingshi;
import net.neoforged.api.distmarker.Dist;
import net.neoforged.bus.api.SubscribeEvent;
Expand All @@ -12,6 +12,6 @@
public class Registry {
@SubscribeEvent
public static void registerRenderers(EntityRenderersEvent.RegisterRenderers event) {
event.registerBlockEntityRenderer(BlockEntitys.CHOPPING_BOARD_BLOCKENTITY.get(), ChoppingBoardBER::new);
event.registerBlockEntityRenderer(BlockEntityTypes.CHOPPING_BOARD_BLOCKENTITY.get(), ChoppingBoardBER::new);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@ protected MapCodec<? extends BaseEntityBlock> codec() {
}

@Override
public ItemInteractionResult useItemOn(
ItemStack pStack, BlockState pState, Level pLevel, BlockPos pPos, Player pPlayer, InteractionHand pHand, BlockHitResult pHitResult
) {
public ItemInteractionResult useItemOn(ItemStack pStack, BlockState pState, Level pLevel, BlockPos pPos, Player pPlayer, InteractionHand pHand, BlockHitResult pHitResult) {
if (pLevel.getBlockEntity(pPos) instanceof ChoppingBoardBlockEntity blockEntity) {
if (!pStack.isEmpty()) {
if (pStack.is(NeoforgeTags.KNIFE) && !blockEntity.getTheItem().isEmpty()) {
Expand All @@ -71,8 +69,8 @@ public ItemInteractionResult useItemOn(
}
stacks.forEach(itemStack -> Containers.dropItemStack(pLevel, pPos.getX(), pPos.getY(), pPos.getZ(), itemStack));
blockEntity.setTheItem(ItemStack.EMPTY);
if(!pLevel.isClientSide()){
pStack.hurtAndBreak(1, pPlayer, EquipmentSlot.MAINHAND);
if (!pLevel.isClientSide()) {
pStack.hurtAndBreak(1, pPlayer, EquipmentSlot.MAINHAND);
}
blockEntity.setChanged();
return ItemInteractionResult.SUCCESS;
Expand Down
106 changes: 106 additions & 0 deletions src/main/java/mczme/lingshi/common/block/SkilletBlock.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
package mczme.lingshi.common.block;

import com.mojang.serialization.MapCodec;
import mczme.lingshi.common.block.entity.SkilletBlockEntity;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.ItemInteractionResult;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
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.BaseEntityBlock;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.RenderShape;
import net.minecraft.world.level.block.entity.BlockEntity;
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.DirectionProperty;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import static mczme.lingshi.common.tag.ModTags.CAN_SUPPORT;

public class SkilletBlock extends BaseEntityBlock {

public static final BooleanProperty HAS_SUPPORT = BooleanProperty.create("has_support");
public static final DirectionProperty FACING = BlockStateProperties.HORIZONTAL_FACING;
public static final VoxelShape SHAPE = Block.box(1, 0, 1, 15, 3, 15);

public SkilletBlock(Properties pProperties) {
super(pProperties);
this.registerDefaultState(this.defaultBlockState().setValue(FACING, Direction.NORTH).setValue(HAS_SUPPORT, false));
}

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

public ItemInteractionResult useItemOn(ItemStack pStack, BlockState pState, Level pLevel, BlockPos pPos, Player pPlayer, InteractionHand pHand, BlockHitResult pHitResult) {
return ItemInteractionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION;
}

@Override
protected InteractionResult useWithoutItem(BlockState pState, Level pLevel, BlockPos pPos, Player pPlayer, BlockHitResult pHitResult) {
return InteractionResult.PASS;
}

@Nullable
@Override
public BlockEntity newBlockEntity(BlockPos pPos, BlockState pState) {
return new SkilletBlockEntity(pPos, pState);
}

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

@Override
protected @NotNull VoxelShape getCollisionShape(BlockState pState, BlockGetter pLevel, BlockPos pPos, CollisionContext pContext) {
return pState.getValue(HAS_SUPPORT) ? Shapes.or(SHAPE, Block.box(0, -1, 0, 16, 0, 16)) : pState.getShape(pLevel, pPos);
}

@Override
protected boolean canSurvive(BlockState pState, LevelReader pLevel, BlockPos pPos) {
return pLevel.getBlockState(pPos.below()).is(CAN_SUPPORT) || canSupportRigidBlock(pLevel, pPos.below()) || canSupportCenter(pLevel, pPos.below(), Direction.UP);
}

@Override
public BlockState getStateForPlacement(BlockPlaceContext pContext) {
boolean isSupport = pContext.getLevel().getBlockState(pContext.getClickedPos().below()).is(CAN_SUPPORT);
return this.defaultBlockState().setValue(FACING, pContext.getHorizontalDirection()).setValue(HAS_SUPPORT, isSupport);
}

@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();
}
return super.updateShape(pState, pFacing, pFacingState, pLevel, pCurrentPos, pFacingPos);
}

@Override
public RenderShape getRenderShape(BlockState pState) {
return RenderShape.MODEL;
}

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

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package mczme.lingshi.common.block.entity;

import mczme.lingshi.common.recipe.ChoppingBoardRecipe;
import mczme.lingshi.common.registry.BlockEntitys;
import mczme.lingshi.common.registry.BlockEntityTypes;
import mczme.lingshi.common.registry.ModRecipes;
import mczme.lingshi.common.tag.NeoforgeTags;
import net.minecraft.core.BlockPos;
Expand All @@ -24,11 +24,10 @@ public class ChoppingBoardBlockEntity extends BlockEntity implements ContainerSi
private ItemStack item = ItemStack.EMPTY;

public ChoppingBoardBlockEntity( BlockPos pPos, BlockState pBlockState) {
super(BlockEntitys.CHOPPING_BOARD_BLOCKENTITY.get(), pPos, pBlockState);
super(BlockEntityTypes.CHOPPING_BOARD_BLOCKENTITY.get(), pPos, pBlockState);
}



@Override
public ClientboundBlockEntityDataPacket getUpdatePacket() {
return ClientboundBlockEntityDataPacket.create(this);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package mczme.lingshi.common.block.entity;

import mczme.lingshi.common.registry.BlockEntityTypes;
import net.minecraft.core.BlockPos;
import net.minecraft.core.HolderLookup;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;

public class SkilletBlockEntity extends BlockEntity {



public SkilletBlockEntity(BlockPos pPos, BlockState pBlockState) {
super(BlockEntityTypes.SKILLET_BLOCKENTITY.get(), pPos, pBlockState);
}

@Override
public ClientboundBlockEntityDataPacket getUpdatePacket() {
return ClientboundBlockEntityDataPacket.create(this);
}

@Override
public CompoundTag getUpdateTag(HolderLookup.Provider pRegistries) {
return this.saveCustomOnly(pRegistries);
}

@Override
protected void loadAdditional(CompoundTag pTag, HolderLookup.Provider pRegistries) {

}

@Override
protected void saveAdditional(CompoundTag pTag, HolderLookup.Provider pRegistries) {
super.saveAdditional(pTag, pRegistries);
}
}
9 changes: 7 additions & 2 deletions src/main/java/mczme/lingshi/common/data/BlockStates.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import mczme.lingshi.lingshi;
import net.minecraft.data.PackOutput;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.neoforged.neoforge.client.model.generators.BlockStateProvider;
import net.neoforged.neoforge.client.model.generators.ConfiguredModel;
Expand All @@ -21,10 +22,14 @@ public BlockStates(PackOutput output, ExistingFileHelper exFileHelper) {
@Override
protected void registerStatesAndModels() {

VariantBlockStateBuilder variantBuilder = getVariantBuilder(ModBlocks.CHOPPING_BOARD.get());
horizontalBlock(ModBlocks.CHOPPING_BOARD.get(), "block/chopping_board");
}

private void horizontalBlock(Block block, String modelLocation) {
VariantBlockStateBuilder variantBuilder = getVariantBuilder(block);

variantBuilder.forAllStates(state -> ConfiguredModel.builder()
.modelFile(modelFile("block/chopping_board"))
.modelFile(modelFile(modelLocation))
.rotationY((int) state.getValue(BlockStateProperties.HORIZONTAL_FACING).toYRot())
.build());
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/mczme/lingshi/common/data/ItemModels.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ protected void registerModels() {
basicItem(ModItems.RICE_SEEDLING.get());

withExistingParent(String.valueOf(ModItems.CHOPPING_BOARD.get()), modLoc("block/chopping_board"));
withExistingParent(String.valueOf(ModItems.SKILLET.get()), modLoc("block/skillet"));
withExistingParent(String.valueOf(ModItems.IRON_KNIFE.get()),mcLoc("item/handheld")).texture("layer0", modLoc("item/iron_knife"));


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,7 @@ protected void addTranslations() {

this.add(ModItems.CHOPPING_BOARD.get(), "砧板");
this.add(ModItems.IRON_KNIFE.get(), "铁菜刀");

this.add(ModItems.SKILLET.get(), "平底锅");
}
}
4 changes: 3 additions & 1 deletion src/main/java/mczme/lingshi/common/data/loot/BlockLoot.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ public class BlockLoot extends BlockLootSubProvider {
public static final Set<Block> BLOCK = Set.of(
ModBlocks.TEA_TREE.get(),
ModBlocks.TEA_LEAF.get(),
ModBlocks.CHOPPING_BOARD.get()
ModBlocks.CHOPPING_BOARD.get(),
ModBlocks.SKILLET.get()
);

public BlockLoot(HolderLookup.Provider lookupProvider) {
Expand All @@ -27,6 +28,7 @@ protected void generate() {
dropSelf(ModBlocks.TEA_TREE.get());
dropOther(ModBlocks.TEA_LEAF.get(), ModItems.TEA_LEAF.get());
dropSelf(ModBlocks.CHOPPING_BOARD.get());
dropSelf(ModBlocks.SKILLET.get());
}

@Override
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/mczme/lingshi/common/data/tag/BlockTags.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,8 @@ protected void addTags(HolderLookup.@NotNull Provider pProvider) {
// 热源方块
tag(HEAT_SOURCE).add(Blocks.CAMPFIRE,
Blocks.MAGMA_BLOCK);

// 可以支撑方块
tag(CAN_SUPPORT).add(Blocks.CAMPFIRE);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package mczme.lingshi.common.registry;

import mczme.lingshi.common.block.entity.ChoppingBoardBlockEntity;
import mczme.lingshi.common.block.entity.SkilletBlockEntity;
import mczme.lingshi.lingshi;
import net.minecraft.core.registries.Registries;
import net.minecraft.world.level.block.entity.BlockEntityType;
Expand All @@ -9,15 +10,19 @@

import java.util.function.Supplier;

public class BlockEntitys {
public class BlockEntityTypes {

public static final DeferredRegister<BlockEntityType<?>> BLOCK_ENTITIES =
DeferredRegister.create(Registries.BLOCK_ENTITY_TYPE, lingshi.MODID);

public static final Supplier<BlockEntityType<ChoppingBoardBlockEntity>> CHOPPING_BOARD_BLOCKENTITY =
BLOCK_ENTITIES.register("chopping_board_blockentity", () ->
BlockEntityType.Builder.of(ChoppingBoardBlockEntity::new,
BlockEntityType.Builder.of(ChoppingBoardBlockEntity::new,
ModBlocks.CHOPPING_BOARD.get()).build(null));
public static final Supplier<BlockEntityType<SkilletBlockEntity>> SKILLET_BLOCKENTITY =
BLOCK_ENTITIES.register("skillet_blockentity", () ->
BlockEntityType.Builder.of(SkilletBlockEntity::new,
ModBlocks.SKILLET.get()).build(null));

public static void register(IEventBus eventBus) {
BLOCK_ENTITIES.register(eventBus);
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/mczme/lingshi/common/registry/ModBlocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public class ModBlocks {
public static final Supplier<TeaBlock> TEA_LEAF = BLOCKS.registerBlock("tea_leaf", TeaBlock::new,
BlockBehaviour.Properties.of().randomTicks().mapColor(MapColor.PLANT).noCollission().instabreak().sound(SoundType.CROP).pushReaction(PushReaction.DESTROY));

public static final Supplier<SkilletBlock> SKILLET = BLOCKS.registerBlock("skillet", SkilletBlock::new,
BlockBehaviour.Properties.of());
public static final Supplier<ChoppingBoardBlock> CHOPPING_BOARD = BLOCKS.registerBlock("chopping_board", ChoppingBoardBlock::new,
BlockBehaviour.Properties.ofFullCopy(Blocks.OAK_PLANKS));

Expand Down
1 change: 1 addition & 0 deletions src/main/java/mczme/lingshi/common/registry/ModItems.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class ModItems {
public static final Supplier<Item> TEA_TREE = registerWithCreateTab("tea_tree", () -> new BlockItem(ModBlocks.TEA_TREE.get(), new Item.Properties()));
public static final Supplier<Item> TEA_LEAF = registerWithCreateTab("tea_leaf", () -> new Item(new Item.Properties()));

public static final Supplier<Item> SKILLET = registerWithCreateTab("skillet", () -> new BlockItem(ModBlocks.SKILLET.get(),new Item.Properties()));
public static final Supplier<Item> CHOPPING_BOARD = registerWithCreateTab("chopping_board", () -> new BlockItem(ModBlocks.CHOPPING_BOARD.get(), new Item.Properties()));

public static final Supplier<Item> IRON_KNIFE = registerWithCreateTab("iron_knife", () -> new KnifeItem(Tiers.IRON,new Item.Properties().attributes(SwordItem.createAttributes(Tiers.IRON, 3, -2.4F))));
Expand Down
Loading

0 comments on commit 3804ccf

Please sign in to comment.