package com.thebrokenrail.energonrelics.block.forcefield.util; import com.thebrokenrail.energonrelics.EnergonRelics; import com.thebrokenrail.energonrelics.block.forcefield.beam.TractorBeamProjectorBlock; import com.thebrokenrail.energonrelics.config.HardcodedConfig; import net.minecraft.block.BlockState; import net.minecraft.entity.Entity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Direction; import net.minecraft.util.math.Vec3d; import net.minecraft.world.World; public class BeamBlock extends AbstractFieldBlock { private final boolean isRepulsor; public BeamBlock(boolean isRepulsor) { super(false); this.isRepulsor = isRepulsor; } @Override protected BlockState getProjectorBlockState() { return EnergonRelics.Blocks.TRACTOR_BEAM_PROJECTOR.getDefaultState().with(TractorBeamProjectorBlock.IS_REPULSOR, isRepulsor); } @SuppressWarnings("deprecation") @Override public void onEntityCollision(BlockState state, World world, BlockPos pos, Entity entity) { super.onEntityCollision(state, world, pos, entity); if (!(entity instanceof PlayerEntity) || !((PlayerEntity) entity).abilities.flying) { entity.slowMovement(state, new Vec3d(HardcodedConfig.TRACTOR_BEAM_MOVEMENT_MULTIPLIER, HardcodedConfig.TRACTOR_BEAM_MOVEMENT_MULTIPLIER, HardcodedConfig.TRACTOR_BEAM_MOVEMENT_MULTIPLIER)); Direction facing = state.get(FACING); if (!isRepulsor) { facing = facing.getOpposite(); } Vec3d pullForce = Vec3d.of(facing.getVector()).multiply(HardcodedConfig.TRACTOR_BEAM_PULL_FORCE); entity.addVelocity(pullForce.getX(), pullForce.getY(), pullForce.getZ()); } } }