2020-07-28 20:46:34 +00:00
|
|
|
package com.thebrokenrail.energonrelics.block.forcefield.beam;
|
2020-07-28 03:10:16 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2020-07-28 15:53:33 +00:00
|
|
|
import java.util.Objects;
|
2020-07-28 03:10:16 +00:00
|
|
|
import java.util.Random;
|
|
|
|
|
|
|
|
@SuppressWarnings("deprecation")
|
|
|
|
public class TractorBeamProjectorBlock extends FieldProjectorBlock {
|
|
|
|
public static final BooleanProperty IS_REPULSOR = BooleanProperty.of("is_repulsor");
|
|
|
|
|
|
|
|
public TractorBeamProjectorBlock() {
|
2020-08-20 23:03:47 +00:00
|
|
|
super(state -> state.get(IS_REPULSOR) ? EnergonRelics.Blocks.REPULSOR_BEAM : EnergonRelics.Blocks.TRACTOR_BEAM);
|
2020-07-28 03:10:16 +00:00
|
|
|
setDefaultState(getDefaultState().with(IS_REPULSOR, false));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
|
|
|
|
super.appendProperties(builder);
|
|
|
|
builder.add(IS_REPULSOR);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public BlockState getPlacementState(ItemPlacementContext ctx) {
|
2020-07-28 15:53:33 +00:00
|
|
|
return Objects.requireNonNull(super.getPlacementState(ctx)).with(IS_REPULSOR, ctx.getWorld().isReceivingRedstonePower(ctx.getBlockPos()));
|
2020-07-28 03:10:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|