package com.thebrokenrail.energonrelics.block.forcefield.beam; import com.thebrokenrail.energonrelics.EnergonRelics; import com.thebrokenrail.energonrelics.block.forcefield.util.FieldProjectorBlock; import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.item.ItemPlacementContext; import net.minecraft.server.world.ServerWorld; import net.minecraft.state.StateManager; import net.minecraft.state.property.BooleanProperty; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import java.util.Objects; import java.util.Random; @SuppressWarnings("deprecation") public class TractorBeamProjectorBlock extends FieldProjectorBlock { public static final BooleanProperty IS_REPULSOR = BooleanProperty.of("is_repulsor"); public TractorBeamProjectorBlock() { super(state -> state.get(IS_REPULSOR) ? EnergonRelics.Blocks.REPULSOR_BEAM : EnergonRelics.Blocks.TRACTOR_BEAM); setDefaultState(getDefaultState().with(IS_REPULSOR, false)); } @Override protected void appendProperties(StateManager.Builder builder) { super.appendProperties(builder); builder.add(IS_REPULSOR); } @Override public BlockState getPlacementState(ItemPlacementContext ctx) { return Objects.requireNonNull(super.getPlacementState(ctx)).with(IS_REPULSOR, ctx.getWorld().isReceivingRedstonePower(ctx.getBlockPos())); } @Override public void neighborUpdate(BlockState state, World world, BlockPos pos, Block block, BlockPos fromPos, boolean notify) { if (!world.isClient()) { boolean bl = state.get(IS_REPULSOR); if (bl != world.isReceivingRedstonePower(pos)) { if (bl) { world.getBlockTickScheduler().schedule(pos, this, 4); } else { world.setBlockState(pos, state.cycle(IS_REPULSOR), 2); } } } } @Override public void scheduledTick(BlockState state, ServerWorld world, BlockPos pos, Random random) { if (state.get(IS_REPULSOR) && !world.isReceivingRedstonePower(pos)) { world.setBlockState(pos, state.cycle(IS_REPULSOR), 2); } } }