2025-11-24 22:52:51 +03:00

105 lines
4.6 KiB
Java

/*
* Decompiled with CFR 0.152.
*
* Could not load the following classes:
* com.mojang.serialization.MapCodec
* org.jspecify.annotations.Nullable
*/
package net.minecraft.world.level.block;
import com.mojang.serialization.MapCodec;
import java.util.function.BiConsumer;
import net.minecraft.core.BlockPos;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundSource;
import net.minecraft.tags.BlockTags;
import net.minecraft.util.RandomSource;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.entity.projectile.Projectile;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Explosion;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.level.block.state.properties.BooleanProperty;
import net.minecraft.world.level.gameevent.GameEvent;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.Vec3;
import org.jspecify.annotations.Nullable;
public abstract class AbstractCandleBlock
extends Block {
public static final int LIGHT_PER_CANDLE = 3;
public static final BooleanProperty LIT = BlockStateProperties.LIT;
protected abstract MapCodec<? extends AbstractCandleBlock> codec();
protected AbstractCandleBlock(BlockBehaviour.Properties properties) {
super(properties);
}
protected abstract Iterable<Vec3> getParticleOffsets(BlockState var1);
public static boolean isLit(BlockState state) {
return state.hasProperty(LIT) && (state.is(BlockTags.CANDLES) || state.is(BlockTags.CANDLE_CAKES)) && state.getValue(LIT) != false;
}
@Override
protected void onProjectileHit(Level level, BlockState state, BlockHitResult blockHit, Projectile projectile) {
if (!level.isClientSide() && projectile.isOnFire() && this.canBeLit(state)) {
AbstractCandleBlock.setLit(level, state, blockHit.getBlockPos(), true);
}
}
protected boolean canBeLit(BlockState state) {
return state.getValue(LIT) == false;
}
@Override
public void animateTick(BlockState state, Level level, BlockPos pos, RandomSource random) {
if (!state.getValue(LIT).booleanValue()) {
return;
}
this.getParticleOffsets(state).forEach(particlePos -> AbstractCandleBlock.addParticlesAndSound(level, particlePos.add(pos.getX(), pos.getY(), pos.getZ()), random));
}
private static void addParticlesAndSound(Level level, Vec3 pos, RandomSource random) {
float chance = random.nextFloat();
if (chance < 0.3f) {
level.addParticle(ParticleTypes.SMOKE, pos.x, pos.y, pos.z, 0.0, 0.0, 0.0);
if (chance < 0.17f) {
level.playLocalSound(pos.x + 0.5, pos.y + 0.5, pos.z + 0.5, SoundEvents.CANDLE_AMBIENT, SoundSource.BLOCKS, 1.0f + random.nextFloat(), random.nextFloat() * 0.7f + 0.3f, false);
}
}
level.addParticle(ParticleTypes.SMALL_FLAME, pos.x, pos.y, pos.z, 0.0, 0.0, 0.0);
}
public static void extinguish(@Nullable Player player, BlockState state, LevelAccessor level, BlockPos pos) {
AbstractCandleBlock.setLit(level, state, pos, false);
if (state.getBlock() instanceof AbstractCandleBlock) {
((AbstractCandleBlock)state.getBlock()).getParticleOffsets(state).forEach(particlePos -> level.addParticle(ParticleTypes.SMOKE, (double)pos.getX() + particlePos.x(), (double)pos.getY() + particlePos.y(), (double)pos.getZ() + particlePos.z(), 0.0, 0.1f, 0.0));
}
level.playSound(null, pos, SoundEvents.CANDLE_EXTINGUISH, SoundSource.BLOCKS, 1.0f, 1.0f);
level.gameEvent((Entity)player, GameEvent.BLOCK_CHANGE, pos);
}
private static void setLit(LevelAccessor level, BlockState state, BlockPos pos, boolean lit) {
level.setBlock(pos, (BlockState)state.setValue(LIT, lit), 11);
}
@Override
protected void onExplosionHit(BlockState state, ServerLevel level, BlockPos pos, Explosion explosion, BiConsumer<ItemStack, BlockPos> onHit) {
if (explosion.canTriggerBlocks() && state.getValue(LIT).booleanValue()) {
AbstractCandleBlock.extinguish(null, state, level, pos);
}
super.onExplosionHit(state, level, pos, explosion, onHit);
}
}