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

72 lines
2.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 net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.RandomSource;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.RedstoneTorchBlock;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.BooleanProperty;
import net.minecraft.world.level.redstone.Orientation;
import org.jspecify.annotations.Nullable;
public class RedstoneLampBlock
extends Block {
public static final MapCodec<RedstoneLampBlock> CODEC = RedstoneLampBlock.simpleCodec(RedstoneLampBlock::new);
public static final BooleanProperty LIT = RedstoneTorchBlock.LIT;
public MapCodec<RedstoneLampBlock> codec() {
return CODEC;
}
public RedstoneLampBlock(BlockBehaviour.Properties properties) {
super(properties);
this.registerDefaultState((BlockState)this.defaultBlockState().setValue(LIT, false));
}
@Override
public @Nullable BlockState getStateForPlacement(BlockPlaceContext context) {
return (BlockState)this.defaultBlockState().setValue(LIT, context.getLevel().hasNeighborSignal(context.getClickedPos()));
}
@Override
protected void neighborChanged(BlockState state, Level level, BlockPos pos, Block block, @Nullable Orientation orientation, boolean movedByPiston) {
if (level.isClientSide()) {
return;
}
boolean isLit = state.getValue(LIT);
if (isLit != level.hasNeighborSignal(pos)) {
if (isLit) {
level.scheduleTick(pos, this, 4);
} else {
level.setBlock(pos, (BlockState)state.cycle(LIT), 2);
}
}
}
@Override
protected void tick(BlockState state, ServerLevel level, BlockPos pos, RandomSource random) {
if (state.getValue(LIT).booleanValue() && !level.hasNeighborSignal(pos)) {
level.setBlock(pos, (BlockState)state.cycle(LIT), 2);
}
}
@Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
builder.add(LIT);
}
}