| 1 | package net.minecraft.world.level.block;
|
| 2 |
|
| 3 | import net.minecraft.core.BlockPos;
|
| 4 | import net.minecraft.core.Holder;
|
| 5 | import net.minecraft.core.particles.ParticleTypes;
|
| 6 | import net.minecraft.server.level.ServerLevel;
|
| 7 | import net.minecraft.tags.BlockTags;
|
| 8 | import net.minecraft.util.RandomSource;
|
| 9 | import net.minecraft.world.Difficulty;
|
| 10 | import net.minecraft.world.effect.MobEffect;
|
| 11 | import net.minecraft.world.effect.MobEffectInstance;
|
| 12 | import net.minecraft.world.effect.MobEffects;
|
| 13 | import net.minecraft.world.entity.Entity;
|
| 14 | import net.minecraft.world.entity.InsideBlockEffectApplier;
|
| 15 | import net.minecraft.world.entity.LivingEntity;
|
| 16 | import net.minecraft.world.item.component.SuspiciousStewEffects;
|
| 17 | import net.minecraft.world.level.BlockGetter;
|
| 18 | import net.minecraft.world.level.Level;
|
| 19 | import net.minecraft.world.level.block.state.BlockBehaviour;
|
| 20 | import net.minecraft.world.level.block.state.BlockState;
|
| 21 | import net.minecraft.world.phys.Vec3;
|
| 22 | import net.minecraft.world.phys.shapes.CollisionContext;
|
| 23 | import net.minecraft.world.phys.shapes.VoxelShape;
|
| 24 |
|
| 25 | public class WitherRoseBlock extends FlowerBlock {
|
| 26 | public WitherRoseBlock(final Holder<MobEffect> mobEffect, final float effectSeconds, final BlockBehaviour.Properties properties) {
|
| 27 | this(makeEffectList(mobEffect, effectSeconds), properties);
|
| 28 | }
|
| 29 |
|
| 30 | public WitherRoseBlock(final SuspiciousStewEffects suspiciousStewEffects, final BlockBehaviour.Properties properties) {
|
| 31 | super(suspiciousStewEffects, properties);
|
| 32 | }
|
| 33 |
|
| 34 | @Override
|
| 35 | protected boolean mayPlaceOn(final BlockState state, final BlockGetter level, final BlockPos pos) {
|
| 36 | return state.is(BlockTags.SUPPORTS_WITHER_ROSE);
|
| 37 | }
|
| 38 |
|
| 39 | @Override
|
| 40 | public void animateTick(final BlockState state, final Level level, final BlockPos pos, final RandomSource random) {
|
| 41 | VoxelShape shape = this.getShape(state, level, pos, CollisionContext.empty());
|
| 42 | Vec3 shapeCenter = shape.bounds().getCenter();
|
| 43 | double x = pos.getX() + shapeCenter.x;
|
| 44 | double z = pos.getZ() + shapeCenter.z;
|
| 45 |
|
| 46 | for (int i = 0; i < 3; i++) {
|
| 47 | if (random.nextBoolean()) {
|
| 48 | level.addParticle(
|
| 49 | ParticleTypes.SMOKE, x + random.nextDouble() / 5.0, pos.getY() + (0.5 - random.nextDouble()), z + random.nextDouble() / 5.0, 0.0, 0.0, 0.0
|
| 50 | );
|
| 51 | }
|
| 52 | }
|
| 53 | }
|
| 54 |
|
| 55 | @Override
|
| 56 | protected void entityInside(
|
| 57 | final BlockState state, final Level level, final BlockPos pos, final Entity entity, final InsideBlockEffectApplier effectApplier, final boolean isPrecise
|
| 58 | ) {
|
| 59 | if (level instanceof ServerLevel serverLevel
|
| 60 | && level.getDifficulty() != Difficulty.PEACEFUL
|
| 61 | && entity instanceof LivingEntity livingEntity
|
| 62 | && !livingEntity.isInvulnerableTo(serverLevel, level.damageSources().wither())) {
|
| 63 | livingEntity.addEffect(this.getBeeInteractionEffect());
|
| 64 | }
|
| 65 | }
|
| 66 |
|
| 67 | @Override
|
| 68 | public MobEffectInstance getBeeInteractionEffect() {
|
| 69 | return new MobEffectInstance(MobEffects.WITHER, 40);
|
| 70 | }
|
| 71 | }
|
| 72 |
|