2025-03-08 08:13:56 +08:00
|
|
|
package com.learning.block;
|
|
|
|
|
2025-03-08 13:30:45 +08:00
|
|
|
import java.util.List;
|
2025-03-08 08:13:56 +08:00
|
|
|
|
|
|
|
import net.minecraft.block.AbstractBlock;
|
|
|
|
import net.minecraft.block.Block;
|
|
|
|
import net.minecraft.block.BlockState;
|
|
|
|
import net.minecraft.server.world.ServerWorld;
|
|
|
|
import net.minecraft.util.math.BlockPos;
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
import net.minecraft.entity.Entity;
|
2025-03-08 13:30:45 +08:00
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.item.Item.TooltipContext;
|
|
|
|
import net.minecraft.item.tooltip.TooltipType;
|
|
|
|
import net.minecraft.text.Text;
|
2025-03-08 08:13:56 +08:00
|
|
|
|
|
|
|
public class DamageBlock extends Block {
|
|
|
|
public DamageBlock(AbstractBlock.Settings settings) {
|
|
|
|
super(settings);
|
|
|
|
}
|
2025-03-13 00:25:16 +08:00
|
|
|
|
|
|
|
@Override
|
2025-03-08 08:13:56 +08:00
|
|
|
public void onSteppedOn(World world, BlockPos pos, BlockState state, Entity entity) {
|
2025-03-08 13:30:45 +08:00
|
|
|
if (!world.isClient() && entity.canHit()) {
|
2025-03-08 08:13:56 +08:00
|
|
|
entity.damage((ServerWorld)world, world.getDamageSources().generic(), 6f);
|
|
|
|
}
|
|
|
|
}
|
2025-03-08 13:30:45 +08:00
|
|
|
|
2025-03-13 00:25:16 +08:00
|
|
|
@Override
|
2025-03-08 13:30:45 +08:00
|
|
|
public void appendTooltip(ItemStack stack, TooltipContext context, List<Text> tooltip, TooltipType type) {
|
|
|
|
super.appendTooltip(stack, context, tooltip, type);
|
|
|
|
tooltip.add(Text.translatable("toolTip.learning.damage_block"));
|
|
|
|
}
|
2025-03-08 08:13:56 +08:00
|
|
|
}
|