/* * Decompiled with CFR 0.152. * * Could not load the following classes: * com.mojang.serialization.MapCodec */ package net.minecraft.world.level.block; import com.mojang.serialization.MapCodec; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.core.particles.DustParticleOptions; import net.minecraft.util.RandomSource; import net.minecraft.world.InteractionResult; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.context.BlockPlaceContext; import net.minecraft.world.level.Level; import net.minecraft.world.level.LevelReader; import net.minecraft.world.level.ScheduledTickAccess; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.DiodeBlock; 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.BlockStateProperties; import net.minecraft.world.level.block.state.properties.BooleanProperty; import net.minecraft.world.level.block.state.properties.IntegerProperty; import net.minecraft.world.phys.BlockHitResult; public class RepeaterBlock extends DiodeBlock { public static final MapCodec CODEC = RepeaterBlock.simpleCodec(RepeaterBlock::new); public static final BooleanProperty LOCKED = BlockStateProperties.LOCKED; public static final IntegerProperty DELAY = BlockStateProperties.DELAY; public MapCodec codec() { return CODEC; } protected RepeaterBlock(BlockBehaviour.Properties properties) { super(properties); this.registerDefaultState((BlockState)((BlockState)((BlockState)((BlockState)((BlockState)this.stateDefinition.any()).setValue(FACING, Direction.NORTH)).setValue(DELAY, 1)).setValue(LOCKED, false)).setValue(POWERED, false)); } @Override protected InteractionResult useWithoutItem(BlockState state, Level level, BlockPos pos, Player player, BlockHitResult hitResult) { if (!player.getAbilities().mayBuild) { return InteractionResult.PASS; } level.setBlock(pos, (BlockState)state.cycle(DELAY), 3); return InteractionResult.SUCCESS; } @Override protected int getDelay(BlockState state) { return state.getValue(DELAY) * 2; } @Override public BlockState getStateForPlacement(BlockPlaceContext context) { BlockState state = super.getStateForPlacement(context); return (BlockState)state.setValue(LOCKED, this.isLocked(context.getLevel(), context.getClickedPos(), state)); } @Override protected BlockState updateShape(BlockState state, LevelReader level, ScheduledTickAccess ticks, BlockPos pos, Direction directionToNeighbour, BlockPos neighbourPos, BlockState neighbourState, RandomSource random) { if (directionToNeighbour == Direction.DOWN && !this.canSurviveOn(level, neighbourPos, neighbourState)) { return Blocks.AIR.defaultBlockState(); } if (!level.isClientSide() && directionToNeighbour.getAxis() != ((Direction)state.getValue(FACING)).getAxis()) { return (BlockState)state.setValue(LOCKED, this.isLocked(level, pos, state)); } return super.updateShape(state, level, ticks, pos, directionToNeighbour, neighbourPos, neighbourState, random); } @Override public boolean isLocked(LevelReader level, BlockPos pos, BlockState state) { return this.getAlternateSignal(level, pos, state) > 0; } @Override protected boolean sideInputDiodesOnly() { return true; } @Override public void animateTick(BlockState state, Level level, BlockPos pos, RandomSource random) { if (!state.getValue(POWERED).booleanValue()) { return; } Direction direction = (Direction)state.getValue(FACING); double x = (double)pos.getX() + 0.5 + (random.nextDouble() - 0.5) * 0.2; double y = (double)pos.getY() + 0.4 + (random.nextDouble() - 0.5) * 0.2; double z = (double)pos.getZ() + 0.5 + (random.nextDouble() - 0.5) * 0.2; float offset = -5.0f; if (random.nextBoolean()) { offset = state.getValue(DELAY) * 2 - 1; } double xo = (offset /= 16.0f) * (float)direction.getStepX(); double zo = offset * (float)direction.getStepZ(); level.addParticle(DustParticleOptions.REDSTONE, x + xo, y, z + zo, 0.0, 0.0, 0.0); } @Override protected void createBlockStateDefinition(StateDefinition.Builder builder) { builder.add(FACING, DELAY, LOCKED, POWERED); } }