|
8 | 8 | import net.minecraft.util.StringRepresentable; |
9 | 9 | import net.minecraft.world.InteractionResult; |
10 | 10 | import net.minecraft.world.entity.player.Player; |
11 | | -import net.minecraft.world.item.ItemStack; |
12 | 11 | import net.minecraft.world.item.context.BlockPlaceContext; |
13 | 12 | import net.minecraft.world.level.BlockGetter; |
14 | 13 | import net.minecraft.world.level.Level; |
|
23 | 22 | import net.minecraft.world.level.block.state.StateDefinition.Builder; |
24 | 23 | import net.minecraft.world.level.block.state.properties.EnumProperty; |
25 | 24 | import net.minecraft.world.level.levelgen.structure.BoundingBox; |
| 25 | +import net.minecraft.world.level.material.FluidState; |
26 | 26 | import net.minecraft.world.phys.AABB; |
27 | 27 | import net.minecraft.world.phys.BlockHitResult; |
28 | 28 | import net.minecraft.world.phys.shapes.CollisionContext; |
|
45 | 45 |
|
46 | 46 | import static top.ctnstudio.futurefood.util.BlockEntyUtil.getBlockEntityFromLevel; |
47 | 47 |
|
48 | | -// TODO 破坏不掉落库存物品 |
49 | 48 | public class QedEntityBlock extends DirectionEntityBlock<QedBlockEntity> implements IEntityStorageBlock, SimpleWaterloggedBlock { |
50 | 49 | private static final MapCodec<QedEntityBlock> CODEC = simpleCodec(QedEntityBlock::new); |
51 | 50 | public static final EnumProperty<Activate> ACTIVATE = EnumProperty.create("activate", Activate.class); |
@@ -161,11 +160,22 @@ protected VoxelShape getVisualShape(BlockState state, BlockGetter getter, |
161 | 160 | } |
162 | 161 |
|
163 | 162 | @Override |
164 | | - protected void spawnAfterBreak(BlockState state, ServerLevel level, BlockPos pos, ItemStack stack, |
165 | | - boolean dropExperience) { |
166 | | - final var tile = getBlockEntity(level, pos); |
167 | | - EntityItemUtil.summonLootItems(level, pos, tile.getEnergyItemStack().copy()); |
| 163 | + public boolean onDestroyedByPlayer(BlockState state, Level world, BlockPos pos, Player player, |
| 164 | + boolean willHarvest, FluidState fluid) { |
| 165 | + if (world.isClientSide()) { |
| 166 | + return true; |
| 167 | + } |
| 168 | + |
| 169 | + final ServerLevel serverWorld = (ServerLevel) world; |
| 170 | + final var tile = getBlockEntity(serverWorld, pos); |
| 171 | + if (!(tile instanceof QedBlockEntity)) { |
| 172 | + return true; |
| 173 | + } |
| 174 | + |
| 175 | + EntityItemUtil.summonLootItems(serverWorld, pos, tile.getEnergyItemStack().copy()); |
168 | 176 | tile.clearContent(); |
| 177 | + |
| 178 | + return true; |
169 | 179 | } |
170 | 180 |
|
171 | 181 | @Override |
|
0 commit comments