100 lines
4.8 KiB
Java
100 lines
4.8 KiB
Java
package net.minecraft.world.level.block;
|
|
|
|
import net.minecraft.world.level.block.state.AbstractStateHolder;
|
|
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
|
import net.minecraft.world.level.block.state.StateDefinition;
|
|
import net.minecraft.core.particles.ParticleOptions;
|
|
import net.minecraft.core.particles.DustParticleOptions;
|
|
import java.util.Random;
|
|
import net.minecraft.world.level.LevelAccessor;
|
|
import net.minecraft.world.level.LevelReader;
|
|
import net.minecraft.world.item.BlockPlaceContext;
|
|
import net.minecraft.world.InteractionResult;
|
|
import net.minecraft.world.phys.BlockHitResult;
|
|
import net.minecraft.world.InteractionHand;
|
|
import net.minecraft.world.entity.player.Player;
|
|
import net.minecraft.core.BlockPos;
|
|
import net.minecraft.world.level.Level;
|
|
import net.minecraft.world.level.block.state.properties.Property;
|
|
import net.minecraft.core.Direction;
|
|
import net.minecraft.world.level.block.state.BlockState;
|
|
import net.minecraft.world.level.block.state.properties.IntegerProperty;
|
|
import net.minecraft.world.level.block.state.properties.BooleanProperty;
|
|
|
|
public class RepeaterBlock extends DiodeBlock {
|
|
public static final BooleanProperty LOCKED;
|
|
public static final IntegerProperty DELAY;
|
|
|
|
protected RepeaterBlock(final Properties c) {
|
|
super(c);
|
|
this.registerDefaultState((((((AbstractStateHolder<O, BlockState>)this.stateDefinition.any()).setValue((Property<Comparable>)RepeaterBlock.FACING, Direction.NORTH)).setValue((Property<Comparable>)RepeaterBlock.DELAY, 1)).setValue((Property<Comparable>)RepeaterBlock.LOCKED, false)).<Comparable, Boolean>setValue((Property<Comparable>)RepeaterBlock.POWERED, false));
|
|
}
|
|
|
|
@Override
|
|
public InteractionResult use(final BlockState byg, final Level bjt, final BlockPos fk, final Player ayg, final InteractionHand ajh, final BlockHitResult cvd) {
|
|
if (!ayg.abilities.mayBuild) {
|
|
return InteractionResult.PASS;
|
|
}
|
|
bjt.setBlock(fk, ((AbstractStateHolder<O, BlockState>)byg).<Comparable>cycle((Property<Comparable>)RepeaterBlock.DELAY), 3);
|
|
return InteractionResult.SUCCESS;
|
|
}
|
|
|
|
@Override
|
|
protected int getDelay(final BlockState byg) {
|
|
return byg.<Integer>getValue((Property<Integer>)RepeaterBlock.DELAY) * 2;
|
|
}
|
|
|
|
@Override
|
|
public BlockState getStateForPlacement(final BlockPlaceContext bcn) {
|
|
final BlockState byg3 = super.getStateForPlacement(bcn);
|
|
return ((AbstractStateHolder<O, BlockState>)byg3).<Comparable, Boolean>setValue((Property<Comparable>)RepeaterBlock.LOCKED, this.isLocked(bcn.getLevel(), bcn.getClickedPos(), byg3));
|
|
}
|
|
|
|
@Override
|
|
public BlockState updateShape(final BlockState byg1, final Direction fp, final BlockState byg3, final LevelAccessor bju, final BlockPos fk5, final BlockPos fk6) {
|
|
if (!bju.isClientSide() && fp.getAxis() != byg1.<Direction>getValue((Property<Direction>)RepeaterBlock.FACING).getAxis()) {
|
|
return ((AbstractStateHolder<O, BlockState>)byg1).<Comparable, Boolean>setValue((Property<Comparable>)RepeaterBlock.LOCKED, this.isLocked(bju, fk5, byg1));
|
|
}
|
|
return super.updateShape(byg1, fp, byg3, bju, fk5, fk6);
|
|
}
|
|
|
|
@Override
|
|
public boolean isLocked(final LevelReader bjw, final BlockPos fk, final BlockState byg) {
|
|
return this.getAlternateSignal(bjw, fk, byg) > 0;
|
|
}
|
|
|
|
@Override
|
|
protected boolean isAlternateInput(final BlockState byg) {
|
|
return DiodeBlock.isDiode(byg);
|
|
}
|
|
|
|
@Override
|
|
public void animateTick(final BlockState byg, final Level bjt, final BlockPos fk, final Random random) {
|
|
if (!byg.<Boolean>getValue((Property<Boolean>)RepeaterBlock.POWERED)) {
|
|
return;
|
|
}
|
|
final Direction fp6 = byg.<Direction>getValue((Property<Direction>)RepeaterBlock.FACING);
|
|
final double double7 = fk.getX() + 0.5f + (random.nextFloat() - 0.5f) * 0.2;
|
|
final double double8 = fk.getY() + 0.4f + (random.nextFloat() - 0.5f) * 0.2;
|
|
final double double9 = fk.getZ() + 0.5f + (random.nextFloat() - 0.5f) * 0.2;
|
|
float float13 = -5.0f;
|
|
if (random.nextBoolean()) {
|
|
float13 = (float)(byg.<Integer>getValue((Property<Integer>)RepeaterBlock.DELAY) * 2 - 1);
|
|
}
|
|
float13 /= 16.0f;
|
|
final double double10 = float13 * fp6.getStepX();
|
|
final double double11 = float13 * fp6.getStepZ();
|
|
bjt.addParticle(DustParticleOptions.REDSTONE, double7 + double10, double8, double9 + double11, 0.0, 0.0, 0.0);
|
|
}
|
|
|
|
@Override
|
|
protected void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> a) {
|
|
a.add(RepeaterBlock.FACING, RepeaterBlock.DELAY, RepeaterBlock.LOCKED, RepeaterBlock.POWERED);
|
|
}
|
|
|
|
static {
|
|
LOCKED = BlockStateProperties.LOCKED;
|
|
DELAY = BlockStateProperties.DELAY;
|
|
}
|
|
}
|