generated from NeoForgeMDKs/MDK-1.21-NeoGradle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
MCZME
committed
Aug 7, 2024
1 parent
4105e58
commit ecd0486
Showing
11 changed files
with
185 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
src/generated/resources/.cache/85f12f813aff948f91f5cd129c0ffa86bcb17361
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
// 1.21 2024-08-06T22:30:49.6383033 Languages: zh_cn for mod: lingshi | ||
99918422a5d56dab647af19828bb12044cdf0336 assets/lingshi/lang/zh_cn.json | ||
// 1.21 2024-08-07T23:57:08.977702 Languages: zh_cn for mod: lingshi | ||
79a73567edeeb26224979ad3941587adb9a443e5 assets/lingshi/lang/zh_cn.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
src/main/java/mczme/lingshi/common/block/ChoppingBoardBlock.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package mczme.lingshi.common.block; | ||
|
||
import com.mojang.serialization.MapCodec; | ||
import mczme.lingshi.common.block.entity.ChoppingBoardBlockEntity; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.world.Containers; | ||
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.level.Level; | ||
import net.minecraft.world.level.block.BaseEntityBlock; | ||
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.phys.BlockHitResult; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public class ChoppingBoardBlock extends BaseEntityBlock { | ||
|
||
public ChoppingBoardBlock(Properties properties) { | ||
super(properties); | ||
} | ||
|
||
@Override | ||
protected MapCodec<? extends BaseEntityBlock> codec() { | ||
return null; | ||
} | ||
|
||
@Override | ||
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 (!pLevel.isClientSide) { | ||
ItemStack stack = pStack.consumeAndReturn(1, pPlayer); | ||
if (blockEntity.getTheItem().isEmpty() && !stack.isEmpty()) { | ||
blockEntity.setTheItem(stack); | ||
blockEntity.setChanged(); | ||
return ItemInteractionResult.SUCCESS; | ||
}else { | ||
return ItemInteractionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION; | ||
} | ||
} else { | ||
return ItemInteractionResult.CONSUME; | ||
} | ||
} | ||
return ItemInteractionResult.SKIP_DEFAULT_BLOCK_INTERACTION; | ||
|
||
} | ||
|
||
@Override | ||
protected InteractionResult useWithoutItem(BlockState pState, Level pLevel, BlockPos pPos, Player pPlayer, BlockHitResult pHitResult) { | ||
if (pLevel.getBlockEntity(pPos) instanceof ChoppingBoardBlockEntity blockentity) { | ||
if (!pLevel.isClientSide) { | ||
ItemStack stack = blockentity.getTheItem(); | ||
if (!stack.isEmpty()) { | ||
Containers.dropItemStack(pLevel, pPos.getX(), pPos.getY(), pPos.getZ(), stack); | ||
blockentity.setTheItem(ItemStack.EMPTY); | ||
blockentity.setChanged(); | ||
return InteractionResult.SUCCESS; | ||
} | ||
} | ||
} | ||
return InteractionResult.PASS; | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public BlockEntity newBlockEntity(@NotNull BlockPos pPos, @NotNull BlockState pState) { | ||
return new ChoppingBoardBlockEntity(pPos, pState); | ||
} | ||
|
||
@Override | ||
public RenderShape getRenderShape(BlockState pState) { | ||
return RenderShape.MODEL; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
src/main/java/mczme/lingshi/common/block/entity/ChoppingBoardBlockEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package mczme.lingshi.common.block.entity; | ||
|
||
import mczme.lingshi.common.registry.BlockEntitys; | ||
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.entity.player.Player; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraft.world.level.block.entity.BlockEntity; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
import net.minecraft.world.ticks.ContainerSingleItem; | ||
|
||
public class ChoppingBoardBlockEntity extends BlockEntity implements ContainerSingleItem { | ||
|
||
private ItemStack item = ItemStack.EMPTY; | ||
|
||
public ChoppingBoardBlockEntity( BlockPos pPos, BlockState pBlockState) { | ||
super(BlockEntitys.CHOPPING_BOARD_BLOCKENTITY.get(), pPos, pBlockState); | ||
} | ||
|
||
|
||
|
||
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) { | ||
if (pTag.contains("item", 10)) { | ||
this.item = ItemStack.parse(pRegistries, pTag.getCompound("item")).orElse(ItemStack.EMPTY); | ||
} else { | ||
this.item = ItemStack.EMPTY; | ||
} | ||
} | ||
|
||
@Override | ||
protected void saveAdditional(CompoundTag pTag, HolderLookup.Provider pRegistries) { | ||
super.saveAdditional(pTag, pRegistries); | ||
if(!this.item.isEmpty()){ | ||
pTag.put("item", this.item.save(pRegistries)); | ||
} | ||
} | ||
|
||
@Override | ||
public ItemStack getTheItem() { | ||
return this.item; | ||
} | ||
|
||
@Override | ||
public void setTheItem(ItemStack pItem) { | ||
this.item= pItem; | ||
} | ||
|
||
|
||
@Override | ||
public boolean stillValid(Player pPlayer) { | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
src/main/java/mczme/lingshi/common/registry/BlockEntitys.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package mczme.lingshi.common.registry; | ||
|
||
import mczme.lingshi.common.block.entity.ChoppingBoardBlockEntity; | ||
import mczme.lingshi.lingshi; | ||
import net.minecraft.core.registries.Registries; | ||
import net.minecraft.world.level.block.entity.BlockEntityType; | ||
import net.neoforged.bus.api.IEventBus; | ||
import net.neoforged.neoforge.registries.DeferredRegister; | ||
|
||
import java.util.function.Supplier; | ||
|
||
public class BlockEntitys { | ||
|
||
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, | ||
ModBlocks.CHOPPING_BOARD.get()).build(null)); | ||
|
||
public static void register(IEventBus eventBus) { | ||
BLOCK_ENTITIES.register(eventBus); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters